mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
reorganize clone semantics, implement recently closed tabs history
This commit is contained in:
parent
3682b5bf3f
commit
ba68019614
17 changed files with 176 additions and 52 deletions
|
|
@ -8,8 +8,9 @@ use std::rc::Rc;
|
|||
|
||||
// Config options
|
||||
|
||||
const RECENT_BOOKMARKS: usize = 50;
|
||||
const LABEL_MAX_LENGTH: usize = 32;
|
||||
const RECENT_BOOKMARKS: usize = 50;
|
||||
const RECENTLY_CLOSED: usize = 50;
|
||||
|
||||
pub struct Menu {
|
||||
pub menu_button: MenuButton,
|
||||
|
|
@ -131,6 +132,16 @@ impl Menu {
|
|||
|
||||
main.append_submenu(Some("Bookmarks"), &main_bookmarks);
|
||||
|
||||
// Main > History
|
||||
let main_history = gio::Menu::new();
|
||||
|
||||
// Main > History > Recently closed
|
||||
// * menu items dynamically generated using profile memory pool and `set_create_popup_func`
|
||||
let main_history_closed = gio::Menu::new();
|
||||
main_history.append_submenu(Some("Closed tabs"), &main_history_closed);
|
||||
|
||||
main.append_submenu(Some("History"), &main_history);
|
||||
|
||||
// Main > Tool
|
||||
let main_tool = gio::Menu::new();
|
||||
|
||||
|
|
@ -176,6 +187,7 @@ impl Menu {
|
|||
let main_bookmarks = main_bookmarks.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |_| {
|
||||
// Bookmarks
|
||||
main_bookmarks.remove_all();
|
||||
for request in profile.bookmark.memory.recent(RECENT_BOOKMARKS) {
|
||||
let menu_item = gio::MenuItem::new(Some(&label(&request, LABEL_MAX_LENGTH)), None);
|
||||
|
|
@ -191,6 +203,19 @@ impl Menu {
|
|||
// if profile.bookmark.memory.total() > RECENT_BOOKMARKS {
|
||||
// @TODO
|
||||
// }
|
||||
|
||||
// History
|
||||
main_history_closed.remove_all();
|
||||
for request in profile.history.memory.closed.recent(RECENTLY_CLOSED) {
|
||||
let menu_item = gio::MenuItem::new(Some(&label(&request, LABEL_MAX_LENGTH)), None);
|
||||
menu_item.set_action_and_target_value(Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.open.simple_action.name()
|
||||
)), Some(&request.to_variant()));
|
||||
|
||||
main_history_closed.append_item(&menu_item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ use crate::app::browser::{
|
|||
};
|
||||
use crate::Profile;
|
||||
use gtk::{
|
||||
glib::{GString, Propagation},
|
||||
prelude::WidgetExt,
|
||||
glib::{DateTime, GString, Propagation},
|
||||
prelude::{EditableExt, WidgetExt},
|
||||
};
|
||||
use sqlite::Transaction;
|
||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||
|
|
@ -92,6 +92,7 @@ impl Tab {
|
|||
|
||||
widget.tab_view.connect_close_page({
|
||||
let index = index.clone();
|
||||
let profile = profile.clone();
|
||||
move |_, item| {
|
||||
// Get index ID by keyword saved
|
||||
match item.keyword() {
|
||||
|
|
@ -100,7 +101,14 @@ impl Tab {
|
|||
panic!("Tab index can not be empty!")
|
||||
}
|
||||
// Cleanup HashMap index
|
||||
index.borrow_mut().remove(&id);
|
||||
if let Some(item) = index.borrow_mut().remove(&id) {
|
||||
// Add history record into profile memory pool
|
||||
// * this action allows to recover recently closed tab (e.g. from the main menu)
|
||||
profile.history.memory.closed.add(
|
||||
item.page.navigation.request.widget.entry.text(),
|
||||
DateTime::now_local().unwrap().to_unix(),
|
||||
);
|
||||
}
|
||||
}
|
||||
None => panic!("Undefined tab index!"),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue