improve history/bookmarks ui responsibility: make text selectable, add suffix widgets to open the links, add visit counter to the history dialog

This commit is contained in:
yggverse 2025-07-26 10:56:04 +03:00
parent 12ace95042
commit d60b46a333
2 changed files with 69 additions and 40 deletions

View File

@ -9,7 +9,10 @@ use adw::{
PreferencesPageExt, PreferencesPageExt,
}, },
}; };
use gtk::glib::{DateTime, GString, Uri, UriFlags}; use gtk::{
glib::{DateTime, GString, Uri, UriFlags},
prelude::ButtonExt,
};
use indexmap::IndexMap; use indexmap::IndexMap;
use std::rc::Rc; use std::rc::Rc;
@ -51,7 +54,7 @@ impl Bookmarks for adw::PreferencesDialog {
d.add(&{ d.add(&{
let p = PreferencesPage::builder() let p = PreferencesPage::builder()
.icon_name("document-open-recent-symbolic") .icon_name("document-open-recent-symbolic")
.title("All") //.title("All")
.build(); .build();
for (group, records) in index { for (group, records) in index {
@ -70,16 +73,14 @@ impl Bookmarks for adw::PreferencesDialog {
.format_iso8601() .format_iso8601()
.unwrap(), .unwrap(),
) )
.title_selectable(true)
.title(group) .title(group)
.build(); .build();
for record in records { for record in records {
e.add_row(&{ e.add_row(&{
let a = ActionRow::builder() let a = ActionRow::builder()
.activatable(true) .activatable(false)
// @TODO use button widget to open the links on click .title_selectable(true)
//.title_selectable(true)
.title(match record.title { .title(match record.title {
Some(title) => title, Some(title) => title,
None => record.time.format_iso8601().unwrap().to_string(), None => record.time.format_iso8601().unwrap().to_string(),
@ -88,20 +89,29 @@ impl Bookmarks for adw::PreferencesDialog {
.subtitle(&record.request) .subtitle(&record.request)
.build(); .build();
a.connect_activated({ a.add_suffix(&{
let a = window_action.clone(); let b = gtk::Button::builder()
let d = d.clone(); .css_classes(["accent", "circular", "flat"])
move |_| { .icon_name("mail-forward-symbolic")
a.append.activate_stateful_once( .tooltip_text("Open in the new tab")
Position::After, .valign(gtk::Align::Center)
Some(record.request.clone()), .build();
false, b.connect_clicked({
true, let a = window_action.clone();
true, let d = d.clone();
true, move |_| {
); a.append.activate_stateful_once(
d.close(); Position::After,
} Some(record.request.clone()),
false,
true,
true,
true,
);
d.close();
}
});
b
}); });
a a
}) })

View File

@ -9,7 +9,11 @@ use adw::{
PreferencesPageExt, PreferencesPageExt,
}, },
}; };
use gtk::glib::{DateTime, GString, Uri, UriFlags, gformat}; use gtk::{
Align, Button,
glib::{DateTime, GString, Uri, UriFlags, gformat},
prelude::ButtonExt,
};
use indexmap::IndexMap; use indexmap::IndexMap;
use std::rc::Rc; use std::rc::Rc;
@ -81,16 +85,14 @@ impl History for adw::PreferencesDialog {
.format_iso8601() .format_iso8601()
.unwrap(), .unwrap(),
) )
.title_selectable(true)
.title(group) .title(group)
.build(); .build();
for record in records { for record in records {
e.add_row(&{ e.add_row(&{
let a = ActionRow::builder() let a = ActionRow::builder()
.activatable(true) .activatable(false)
// @TODO use button widget to open the links on click .title_selectable(true)
//.title_selectable(true)
.title(match record.title { .title(match record.title {
Some(title) => title, Some(title) => title,
None => gformat!( None => gformat!(
@ -99,24 +101,41 @@ impl History for adw::PreferencesDialog {
record.event.count record.event.count
), ),
}) })
.subtitle_selectable(true)
.subtitle(&*record.request) .subtitle(&*record.request)
.subtitle_selectable(true)
.build(); .build();
a.connect_activated({ a.add_prefix(
let a = window_action.clone(); &Button::builder()
let d = d.clone(); .css_classes(["circular", "caption-heading"])
move |_| { .label(record.event.count.to_string())
a.append.activate_stateful_once( .tooltip_text("Visit count")
Position::After, .valign(Align::Center)
Some(record.request.to_string()), .build(),
false, );
true, a.add_suffix(&{
true, let b = Button::builder()
true, .css_classes(["accent", "circular", "flat"])
); .icon_name("mail-forward-symbolic")
d.close(); .tooltip_text("Open in the new tab")
} .valign(Align::Center)
.build();
b.connect_clicked({
let a = window_action.clone();
let d = d.clone();
move |_| {
a.append.activate_stateful_once(
Position::After,
Some(record.request.to_string()),
false,
true,
true,
true,
);
d.close();
}
});
b
}); });
a a
}) })