mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-09 09:54:14 +00:00
store entire closed tab item to restore all features
This commit is contained in:
parent
27ee3e8fe9
commit
1a0b31e695
@ -1,4 +1,4 @@
|
|||||||
mod browser;
|
pub mod browser;
|
||||||
mod database;
|
mod database;
|
||||||
|
|
||||||
use browser::Browser;
|
use browser::Browser;
|
||||||
|
@ -2,7 +2,7 @@ mod about;
|
|||||||
mod action;
|
mod action;
|
||||||
mod database;
|
mod database;
|
||||||
mod widget;
|
mod widget;
|
||||||
mod window;
|
pub mod window;
|
||||||
|
|
||||||
use about::About;
|
use about::About;
|
||||||
use action::Action;
|
use action::Action;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
mod action;
|
mod action;
|
||||||
mod database;
|
mod database;
|
||||||
mod header;
|
mod header;
|
||||||
mod tab;
|
pub mod tab;
|
||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
use action::{Action, Position};
|
use action::{Action, Position};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::{BrowserAction, Profile, WindowAction};
|
use super::{BrowserAction, Profile, WindowAction};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{self},
|
gio::{self},
|
||||||
prelude::{ActionExt, ToVariant},
|
prelude::{ActionExt, EditableExt, ToVariant},
|
||||||
Align, MenuButton,
|
Align, MenuButton,
|
||||||
};
|
};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@ -206,13 +206,14 @@ impl Menu {
|
|||||||
|
|
||||||
// History
|
// History
|
||||||
main_history_closed.remove_all();
|
main_history_closed.remove_all();
|
||||||
for request in profile.history.memory.closed.recent(RECENTLY_CLOSED) {
|
for item in profile.history.memory.closed.recent(RECENTLY_CLOSED) {
|
||||||
let menu_item = gio::MenuItem::new(Some(&label(&request, LABEL_MAX_LENGTH)), None);
|
let item_request = item.page.navigation.request.widget.entry.text(); // @TODO restore entire `Item`
|
||||||
|
let menu_item = gio::MenuItem::new(Some(&label(&item_request, LABEL_MAX_LENGTH)), None);
|
||||||
menu_item.set_action_and_target_value(Some(&format!(
|
menu_item.set_action_and_target_value(Some(&format!(
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
window_action.id,
|
window_action.id,
|
||||||
window_action.open.simple_action.name()
|
window_action.open.simple_action.name()
|
||||||
)), Some(&request.to_variant()));
|
)), Some(&item_request.to_variant()));
|
||||||
|
|
||||||
main_history_closed.append_item(&menu_item);
|
main_history_closed.append_item(&menu_item);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ mod menu;
|
|||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use item::Item;
|
pub use item::Item;
|
||||||
use menu::Menu;
|
use menu::Menu;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ use crate::app::browser::{
|
|||||||
use crate::Profile;
|
use crate::Profile;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
glib::{DateTime, GString, Propagation},
|
glib::{DateTime, GString, Propagation},
|
||||||
prelude::{EditableExt, WidgetExt},
|
prelude::WidgetExt,
|
||||||
};
|
};
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||||
@ -104,10 +104,11 @@ impl Tab {
|
|||||||
if let Some(item) = index.borrow_mut().remove(&id) {
|
if let Some(item) = index.borrow_mut().remove(&id) {
|
||||||
// Add history record into profile memory pool
|
// Add history record into profile memory pool
|
||||||
// * this action allows to recover recently closed tab (e.g. from the main menu)
|
// * this action allows to recover recently closed tab (e.g. from the main menu)
|
||||||
profile.history.memory.closed.add(
|
profile
|
||||||
item.page.navigation.request.widget.entry.text(),
|
.history
|
||||||
DateTime::now_local().unwrap().to_unix(),
|
.memory
|
||||||
);
|
.closed
|
||||||
|
.add(item, DateTime::now_local().unwrap().to_unix());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => panic!("Undefined tab index!"),
|
None => panic!("Undefined tab index!"),
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
use gtk::glib::GString;
|
use crate::app::browser::window::tab::Item;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::{cell::RefCell, collections::HashMap};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
/// Reduce disk usage by cache Bookmarks index in memory
|
pub struct Record {
|
||||||
|
pub item: Rc<Item>,
|
||||||
|
pub unix_timestamp: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Recently closed tabs index
|
||||||
pub struct Closed {
|
pub struct Closed {
|
||||||
index: RefCell<HashMap<GString, i64>>,
|
index: RefCell<Vec<Record>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Closed {
|
impl Default for Closed {
|
||||||
@ -19,7 +24,7 @@ impl Closed {
|
|||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
index: RefCell::new(HashMap::new()),
|
index: RefCell::new(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,21 +32,24 @@ impl Closed {
|
|||||||
|
|
||||||
/// Add new record
|
/// Add new record
|
||||||
/// * replace with new one if the record already exist
|
/// * replace with new one if the record already exist
|
||||||
pub fn add(&self, request: GString, unix_timestamp: i64) {
|
pub fn add(&self, item: Rc<Item>, unix_timestamp: i64) {
|
||||||
self.index.borrow_mut().insert(request, unix_timestamp);
|
self.index.borrow_mut().push(Record {
|
||||||
|
item,
|
||||||
|
unix_timestamp,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get recent requests vector sorted by `ID` DESC
|
/// Get recent `Item` vector sorted by time DESC
|
||||||
pub fn recent(&self, limit: usize) -> Vec<GString> {
|
pub fn recent(&self, limit: usize) -> Vec<Rc<Item>> {
|
||||||
let mut recent: Vec<GString> = Vec::new();
|
let mut recent: Vec<Rc<Item>> = Vec::new();
|
||||||
for (request, _) in self
|
for record in self
|
||||||
.index
|
.index
|
||||||
.borrow()
|
.borrow()
|
||||||
.iter()
|
.iter()
|
||||||
.sorted_by(|a, b| Ord::cmp(&b.1, &a.1))
|
.sorted_by(|a, b| Ord::cmp(&b.unix_timestamp, &a.unix_timestamp))
|
||||||
.take(limit)
|
.take(limit)
|
||||||
{
|
{
|
||||||
recent.push(request.clone())
|
recent.push(record.item.clone())
|
||||||
}
|
}
|
||||||
recent
|
recent
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user