mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
implement separated dialogs for the Bookmarks and History menu items
This commit is contained in:
parent
e548efc93f
commit
ebb38008e1
14 changed files with 378 additions and 171 deletions
117
src/app/browser/bookmarks.rs
Normal file
117
src/app/browser/bookmarks.rs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
//! Browser bookmarks dialog
|
||||
|
||||
use super::Profile;
|
||||
use crate::app::browser::window::action::{Action as WindowAction, Position};
|
||||
use adw::{
|
||||
ActionRow, PreferencesGroup, PreferencesPage,
|
||||
prelude::{
|
||||
ActionRowExt, AdwDialogExt, ExpanderRowExt, PreferencesDialogExt, PreferencesGroupExt,
|
||||
PreferencesPageExt,
|
||||
},
|
||||
};
|
||||
use gtk::glib::{DateTime, GString, Uri, UriFlags};
|
||||
use std::{collections::HashMap, rc::Rc};
|
||||
|
||||
struct Record {
|
||||
time: DateTime,
|
||||
request: String,
|
||||
title: Option<String>,
|
||||
}
|
||||
|
||||
pub trait Bookmarks {
|
||||
fn bookmarks(window_action: &Rc<WindowAction>, profile: &Rc<Profile>) -> Self;
|
||||
}
|
||||
|
||||
impl Bookmarks for adw::PreferencesDialog {
|
||||
fn bookmarks(window_action: &Rc<WindowAction>, profile: &Rc<Profile>) -> Self {
|
||||
let mut index: HashMap<GString, Vec<Record>> = HashMap::new();
|
||||
for bookmark in profile.bookmark.recent(None) {
|
||||
match Uri::parse(&bookmark.request, UriFlags::NONE) {
|
||||
Ok(uri) => index
|
||||
.entry(match uri.host() {
|
||||
Some(host) => host,
|
||||
None => uri.to_str(),
|
||||
})
|
||||
.or_default()
|
||||
.push(Record {
|
||||
request: bookmark.request,
|
||||
time: bookmark.time,
|
||||
title: bookmark.title,
|
||||
}),
|
||||
Err(_) => continue, // @TODO
|
||||
}
|
||||
}
|
||||
|
||||
let d = adw::PreferencesDialog::builder()
|
||||
.search_enabled(true)
|
||||
.title("Bookmarks")
|
||||
.build();
|
||||
|
||||
d.add(&{
|
||||
let p = PreferencesPage::builder()
|
||||
.icon_name("document-open-recent-symbolic")
|
||||
.title("All")
|
||||
.build();
|
||||
|
||||
for (group, records) in index {
|
||||
p.add(&{
|
||||
let g = PreferencesGroup::new();
|
||||
g.add(&{
|
||||
let e = adw::ExpanderRow::builder()
|
||||
.enable_expansion(true)
|
||||
.expanded(false)
|
||||
.subtitle(
|
||||
records
|
||||
.iter()
|
||||
.max_by_key(|r| r.time.to_unix())
|
||||
.unwrap()
|
||||
.time
|
||||
.format_iso8601()
|
||||
.unwrap(),
|
||||
)
|
||||
.title_selectable(true)
|
||||
.title(group)
|
||||
.build();
|
||||
|
||||
for record in records {
|
||||
e.add_row(&{
|
||||
let a = ActionRow::builder()
|
||||
.activatable(true)
|
||||
// @TODO use button widget to open the links on click
|
||||
//.title_selectable(true)
|
||||
.title(match record.title {
|
||||
Some(title) => title,
|
||||
None => record.time.format_iso8601().unwrap().to_string(),
|
||||
})
|
||||
.subtitle_selectable(true)
|
||||
.subtitle(&record.request)
|
||||
.build();
|
||||
|
||||
a.connect_activated({
|
||||
let a = window_action.clone();
|
||||
let d = d.clone();
|
||||
move |_| {
|
||||
a.append.activate_stateful_once(
|
||||
Position::After,
|
||||
Some(record.request.clone()),
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
d.close();
|
||||
}
|
||||
});
|
||||
a
|
||||
})
|
||||
}
|
||||
e
|
||||
});
|
||||
g
|
||||
});
|
||||
}
|
||||
p
|
||||
});
|
||||
d
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue