Confirm a copy with a toast and close the row menu
Copying the public key from a row's menu left the popover open and gave no sign that anything happened. A plain GtkPopover full of buttons does not close when one is clicked — only menu items do — so close it after any action, and confirm the copy with an AdwToast "Copied to clipboard" (libadwaita's own wording for a copy). The Connect dialog's connection-string copy button gets the same toast. Each view gains an AdwToastOverlay to raise it, wrapped around its content.
This commit is contained in:
2 files changed
+35
-3
No files matched your search
+9
-1
@@ -49,6 +49,7 @@ pub struct ConnectDialog {
|
||||
reveal: adw::ExpanderRow,
|
||||
uri: adw::ActionRow,
|
||||
picture: gtk::Picture,
|
||||
overlay: adw::ToastOverlay,
|
||||
}
|
||||
|
||||
impl ConnectDialog {
|
||||
@@ -128,9 +129,12 @@ impl ConnectDialog {
|
||||
|
||||
let header = adw::HeaderBar::new();
|
||||
header.set_title_widget(Some(&adw::WindowTitle::new("Connect an app", "")));
|
||||
// The copy action reports itself with a toast, as in the identities window.
|
||||
let overlay = adw::ToastOverlay::new();
|
||||
overlay.set_child(Some(&scrolled));
|
||||
let toolbar = adw::ToolbarView::new();
|
||||
toolbar.add_top_bar(&header);
|
||||
toolbar.set_content(Some(&scrolled));
|
||||
toolbar.set_content(Some(&overlay));
|
||||
// Pin the width on the dialog's child, not via `content_width`: with
|
||||
// `follows_content_size` below, libadwaita ignores `content_width` and
|
||||
// would use the content's natural width instead (229px, measured).
|
||||
@@ -157,6 +161,7 @@ impl ConnectDialog {
|
||||
reveal,
|
||||
uri,
|
||||
picture,
|
||||
overlay,
|
||||
});
|
||||
|
||||
// The page changes with the selected identity and with the signer's
|
||||
@@ -209,6 +214,9 @@ impl ConnectDialog {
|
||||
window.clipboard().set_text(&uri);
|
||||
}
|
||||
}
|
||||
listener
|
||||
.overlay
|
||||
.add_toast(adw::Toast::new("Copied to clipboard"));
|
||||
});
|
||||
}
|
||||
{
|
||||
|
||||
+26
-2
@@ -30,6 +30,8 @@ use crate::ui::{approval, plain};
|
||||
struct Handles {
|
||||
stack: gtk::Stack,
|
||||
list: adw::PreferencesGroup,
|
||||
/// Raises the "copied" toast from a row's menu.
|
||||
overlay: adw::ToastOverlay,
|
||||
}
|
||||
|
||||
/// The rows currently in the list, so a reload can remove exactly them.
|
||||
@@ -102,9 +104,17 @@ impl KeysView {
|
||||
page.add(&add_group);
|
||||
stack.add_named(&page, Some("loaded"));
|
||||
|
||||
let handles = Handles { stack, list };
|
||||
// The copy action reports itself with a toast; the overlay is the view's
|
||||
// widget, so the toast sits over the whole window.
|
||||
let overlay = adw::ToastOverlay::new();
|
||||
overlay.set_child(Some(&stack));
|
||||
let handles = Handles {
|
||||
stack,
|
||||
list,
|
||||
overlay: overlay.clone(),
|
||||
};
|
||||
let rows: Rows = Rc::new(RefCell::new(Vec::new()));
|
||||
let widget: gtk::Widget = handles.stack.clone().upcast();
|
||||
let widget: gtk::Widget = overlay.upcast();
|
||||
|
||||
for button in [&create_button, &create] {
|
||||
let (state, handles) = (Rc::clone(&state), handles.clone());
|
||||
@@ -204,6 +214,9 @@ fn key_row(
|
||||
if let Some(window) = toplevel(&handles) {
|
||||
window.clipboard().set_text(&npub);
|
||||
}
|
||||
handles
|
||||
.overlay
|
||||
.add_toast(adw::Toast::new("Copied to clipboard"));
|
||||
});
|
||||
}
|
||||
menu.append(©);
|
||||
@@ -226,6 +239,17 @@ fn key_row(
|
||||
menu.append(&remove);
|
||||
}
|
||||
|
||||
// A plain popover does not close when a button inside it is clicked — only
|
||||
// menu items do — so close it after any action.
|
||||
let mut child = menu.first_child();
|
||||
while let Some(widget) = child {
|
||||
if let Some(button) = widget.downcast_ref::<gtk::Button>() {
|
||||
let popover = popover.clone();
|
||||
button.connect_clicked(move |_| popover.popdown());
|
||||
}
|
||||
child = widget.next_sibling();
|
||||
}
|
||||
|
||||
let button = gtk::MenuButton::builder()
|
||||
.icon_name("view-more-symbolic")
|
||||
.popover(&popover)
|
||||
|
||||
Reference in new issue
Block a user