mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
reorganize history memory model
This commit is contained in:
parent
6526ca85d8
commit
268af30830
14 changed files with 172 additions and 218 deletions
|
|
@ -36,11 +36,6 @@ impl Bookmark {
|
|||
|
||||
// Actions
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn activate(&self) {
|
||||
self.simple_action.activate(None);
|
||||
}
|
||||
|
||||
/// Change action [state](https://docs.gtk.org/gio/method.SimpleAction.set_state.html)
|
||||
/// * set `DEFAULT_STATE` on `None`
|
||||
pub fn change_state(&self, state: Option<i32>) {
|
||||
|
|
|
|||
|
|
@ -36,11 +36,6 @@ impl HistoryBack {
|
|||
|
||||
// Actions
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn activate(&self) {
|
||||
self.simple_action.activate(None);
|
||||
}
|
||||
|
||||
/// Change action [state](https://docs.gtk.org/gio/method.SimpleAction.set_state.html)
|
||||
/// * set `DEFAULT_STATE` on `None`
|
||||
pub fn change_state(&self, state: Option<i32>) {
|
||||
|
|
|
|||
|
|
@ -36,11 +36,6 @@ impl HistoryForward {
|
|||
|
||||
// Actions
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn activate(&self) {
|
||||
self.simple_action.activate(None);
|
||||
}
|
||||
|
||||
/// Change action [state](https://docs.gtk.org/gio/method.SimpleAction.set_state.html)
|
||||
/// * set `DEFAULT_STATE` on `None`
|
||||
pub fn change_state(&self, state: Option<i32>) {
|
||||
|
|
|
|||
|
|
@ -36,11 +36,6 @@ impl Home {
|
|||
|
||||
// Actions
|
||||
|
||||
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||
pub fn activate(&self) {
|
||||
self.simple_action.activate(None);
|
||||
}
|
||||
|
||||
/// Change action [state](https://docs.gtk.org/gio/method.SimpleAction.set_state.html)
|
||||
/// * set `DEFAULT_STATE` on `None`
|
||||
pub fn change_state(&self, state: Option<i32>) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use super::{BrowserAction, Profile, WindowAction};
|
||||
use gtk::{
|
||||
gio::{self},
|
||||
glib::{GString, Uri},
|
||||
glib::{GString, Uri, UriFlags},
|
||||
prelude::{ActionExt, ToVariant},
|
||||
Align, MenuButton,
|
||||
};
|
||||
|
|
@ -220,14 +220,13 @@ impl Menu for MenuButton {
|
|||
|
||||
// Recently closed history
|
||||
main_history_tab.remove_all();
|
||||
for item in profile.history.memory.tab.recent() {
|
||||
let item_request = item.page.navigation.request(); // @TODO restore entire `Item`
|
||||
let menu_item = gio::MenuItem::new(Some(&ellipsize(&item_request, LABEL_MAX_LENGTH)), None);
|
||||
for history in profile.history.recently_closed(None) {
|
||||
let menu_item = gio::MenuItem::new(Some(&ellipsize(&history.request, LABEL_MAX_LENGTH)), None);
|
||||
menu_item.set_action_and_target_value(Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.load.simple_action.name()
|
||||
)), Some(&item_request.to_variant()));
|
||||
)), Some(&history.request.to_variant()));
|
||||
|
||||
main_history_tab.append_item(&menu_item);
|
||||
} // @TODO `menu_item`
|
||||
|
|
@ -238,11 +237,14 @@ impl Menu for MenuButton {
|
|||
main_history_request.remove_all();
|
||||
|
||||
let mut list: IndexMap<GString, Vec<Uri>> = IndexMap::new();
|
||||
for uri in profile.history.memory.request.recent() {
|
||||
list.entry(match uri.host() {
|
||||
Some(host) => host,
|
||||
None => uri.to_str(),
|
||||
}).or_default().push(uri);
|
||||
for history in profile.history.recently_opened(None) {
|
||||
match Uri::parse(&history.request, UriFlags::NONE) {
|
||||
Ok(uri) => list.entry(match uri.host() {
|
||||
Some(host) => host,
|
||||
None => uri.to_str(),
|
||||
}).or_default().push(uri),
|
||||
Err(_) => continue // @TODO
|
||||
}
|
||||
}
|
||||
|
||||
for (group, items) in list {
|
||||
|
|
|
|||
|
|
@ -8,12 +8,7 @@ use crate::Profile;
|
|||
use action::Action;
|
||||
use adw::{TabPage, TabView};
|
||||
use anyhow::Result;
|
||||
use gtk::{
|
||||
gio::Icon,
|
||||
glib::{DateTime, Propagation},
|
||||
prelude::ActionExt,
|
||||
Box, Orientation,
|
||||
};
|
||||
use gtk::{gio::Icon, glib::Propagation, prelude::ActionExt, Box, Orientation};
|
||||
pub use item::Item;
|
||||
use menu::Menu;
|
||||
use sourceview::prelude::IsA;
|
||||
|
|
@ -86,11 +81,7 @@ impl Tab {
|
|||
// keep removed `Item` reference in the memory (to reopen from the main menu)
|
||||
// * skip item with blank request
|
||||
if !item.page.navigation.request().is_empty() {
|
||||
profile
|
||||
.history
|
||||
.memory
|
||||
.tab
|
||||
.add(item, DateTime::now_local().unwrap().to_unix());
|
||||
profile.history.close(&item.page.navigation.request());
|
||||
}
|
||||
}
|
||||
// reassign global actions to active tab
|
||||
|
|
|
|||
|
|
@ -63,13 +63,13 @@ impl Client {
|
|||
Ok(uri) => match uri.scheme().as_str() {
|
||||
"file" => {
|
||||
if is_snap_history {
|
||||
snap_history(&page, Some(&uri));
|
||||
snap_history(&page);
|
||||
}
|
||||
driver.file.handle(uri, feature, cancellable)
|
||||
}
|
||||
"gemini" | "titan" => {
|
||||
if is_snap_history {
|
||||
snap_history(&page, Some(&uri));
|
||||
snap_history(&page);
|
||||
}
|
||||
driver.gemini.handle(uri, feature, cancellable)
|
||||
}
|
||||
|
|
@ -201,23 +201,9 @@ fn search(profile: &Profile, query: &str) -> Uri {
|
|||
}
|
||||
|
||||
/// Make new history record in related components
|
||||
/// * optional [Uri](https://docs.gtk.org/glib/struct.Uri.html) reference wanted only for performance reasons, to not parse it twice
|
||||
fn snap_history(page: &Page, uri: Option<&Uri>) {
|
||||
let request = page.navigation.request();
|
||||
|
||||
// Add new record into the global memory index (used in global menu)
|
||||
// * if the `Uri` is `None`, try parse it from `request`
|
||||
match uri {
|
||||
Some(uri) => page.profile.history.memory.request.set(uri.clone()),
|
||||
None => {
|
||||
// this case especially useful for some routes that contain redirects
|
||||
// maybe some parental optimization wanted @TODO
|
||||
if let Some(uri) = page.navigation.uri() {
|
||||
page.profile.history.memory.request.set(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add new record into the page navigation history
|
||||
page.item_action.history.add(request, true)
|
||||
fn snap_history(page: &Page) {
|
||||
page.item_action
|
||||
.history
|
||||
.add(page.navigation.request(), true);
|
||||
page.profile.history.open(page.navigation.request())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,10 +121,8 @@ impl Page {
|
|||
self.set_needs_attention(record.is_needs_attention);
|
||||
// Restore child components
|
||||
self.navigation.restore(transaction, &record.id)?;
|
||||
// Make initial page history snap using `navigation` values restored
|
||||
if let Some(uri) = self.navigation.uri() {
|
||||
self.profile.history.memory.request.set(uri);
|
||||
}
|
||||
// Make initial page history snap
|
||||
self.profile.history.open(self.navigation.request());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,10 +137,6 @@ impl Navigation {
|
|||
self.request.text()
|
||||
}
|
||||
|
||||
pub fn uri(&self) -> Option<Uri> {
|
||||
self.request.uri()
|
||||
}
|
||||
|
||||
pub fn home(&self) -> Option<Uri> {
|
||||
self.request.home()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue