mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement recently closed history tab
This commit is contained in:
parent
9a6c8be37f
commit
6d419f9234
1 changed files with 148 additions and 109 deletions
|
|
@ -3,7 +3,7 @@
|
|||
use super::Profile;
|
||||
use crate::app::browser::window::action::{Action as WindowAction, Position};
|
||||
use adw::{
|
||||
ActionRow, PreferencesGroup, PreferencesPage,
|
||||
ActionRow, ExpanderRow, PreferencesDialog, PreferencesGroup, PreferencesPage,
|
||||
prelude::{
|
||||
ActionRowExt, AdwDialogExt, ExpanderRowExt, PreferencesDialogExt, PreferencesGroupExt,
|
||||
PreferencesPageExt,
|
||||
|
|
@ -32,47 +32,89 @@ pub trait History {
|
|||
fn history(window_action: &Rc<WindowAction>, profile: &Rc<Profile>) -> Self;
|
||||
}
|
||||
|
||||
impl History for adw::PreferencesDialog {
|
||||
impl History for PreferencesDialog {
|
||||
fn history(window_action: &Rc<WindowAction>, profile: &Rc<Profile>) -> Self {
|
||||
let mut visited: IndexMap<GString, Vec<Record>> = IndexMap::new();
|
||||
// @TODO recently closed
|
||||
let d = adw::PreferencesDialog::builder()
|
||||
.search_enabled(true)
|
||||
.title("History")
|
||||
.build();
|
||||
|
||||
for history in profile.history.recently_opened(None) {
|
||||
match Uri::parse(&history.request, UriFlags::NONE) {
|
||||
Ok(uri) => visited
|
||||
d.add(&page(
|
||||
window_action,
|
||||
&d,
|
||||
index(
|
||||
profile
|
||||
.history
|
||||
.recently_opened(None)
|
||||
.into_iter()
|
||||
.map(|i| (i.request, i.title, i.opened.time, i.opened.count))
|
||||
.collect(),
|
||||
),
|
||||
"document-open-recent-symbolic",
|
||||
"Last visit",
|
||||
));
|
||||
|
||||
d.add(&page(
|
||||
window_action,
|
||||
&d,
|
||||
index(
|
||||
profile
|
||||
.history
|
||||
.recently_closed(None)
|
||||
.into_iter()
|
||||
.map(|i| (i.request, i.title, i.opened.time, i.opened.count))
|
||||
.collect(),
|
||||
),
|
||||
"document-revert-symbolic",
|
||||
"Recent close",
|
||||
));
|
||||
d
|
||||
}
|
||||
}
|
||||
|
||||
/// Common index map for all history types
|
||||
/// * @TODO make Profile member public to replace the tuple?
|
||||
fn index(
|
||||
index: Vec<(GString, Option<GString>, DateTime, usize)>,
|
||||
) -> IndexMap<GString, Vec<Record>> {
|
||||
let mut i: IndexMap<GString, Vec<Record>> = IndexMap::new();
|
||||
for (request, title, time, count) in index {
|
||||
match Uri::parse(&request, UriFlags::NONE) {
|
||||
Ok(uri) => i
|
||||
.entry(match uri.host() {
|
||||
Some(host) => host,
|
||||
None => uri.to_str(),
|
||||
})
|
||||
.or_default()
|
||||
.push(Record {
|
||||
event: Event {
|
||||
time: history.opened.time,
|
||||
count: history.opened.count,
|
||||
},
|
||||
request: history.request,
|
||||
title: history.title,
|
||||
event: Event { time, count },
|
||||
request,
|
||||
title,
|
||||
}),
|
||||
Err(_) => continue, // @TODO
|
||||
}
|
||||
}
|
||||
i
|
||||
}
|
||||
|
||||
let d = adw::PreferencesDialog::builder()
|
||||
.search_enabled(true)
|
||||
.title("History")
|
||||
.build();
|
||||
|
||||
d.add(&{
|
||||
/// Common page UI for all widget tabs
|
||||
fn page(
|
||||
window_action: &Rc<WindowAction>,
|
||||
dialog: &PreferencesDialog,
|
||||
index: IndexMap<GString, Vec<Record>>,
|
||||
icon_name: &str,
|
||||
title: &str,
|
||||
) -> PreferencesPage {
|
||||
let p = PreferencesPage::builder()
|
||||
.icon_name("document-open-recent-symbolic")
|
||||
.title("Recently visited")
|
||||
.icon_name(icon_name)
|
||||
.title(title)
|
||||
.build();
|
||||
|
||||
for (group, records) in visited {
|
||||
for (group, records) in index {
|
||||
p.add(&{
|
||||
let g = PreferencesGroup::new();
|
||||
g.add(&{
|
||||
let e = adw::ExpanderRow::builder()
|
||||
let e = ExpanderRow::builder()
|
||||
.enable_expansion(true)
|
||||
.expanded(false)
|
||||
.subtitle(
|
||||
|
|
@ -122,7 +164,7 @@ impl History for adw::PreferencesDialog {
|
|||
.build();
|
||||
b.connect_clicked({
|
||||
let a = window_action.clone();
|
||||
let d = d.clone();
|
||||
let d = dialog.clone();
|
||||
move |_| {
|
||||
a.append.activate_stateful_once(
|
||||
Position::After,
|
||||
|
|
@ -146,9 +188,6 @@ impl History for adw::PreferencesDialog {
|
|||
});
|
||||
}
|
||||
p
|
||||
});
|
||||
d
|
||||
}
|
||||
}
|
||||
|
||||
/// Prevents GTK warnings (`use_markup` has no effect @TODO)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue