From 21d7766d0d0dace52de776e219a7cd19cde8221a Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 11 Jul 2023 12:00:45 +0200 Subject: [PATCH 1/2] wallet: add context menu to history with copy options --- src/view/wallet/wallet.glade | 36 +++++++++++++++++++++++++ src/view/wallet/widget.rs | 52 +++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/view/wallet/wallet.glade b/src/view/wallet/wallet.glade index eb64c68..33f72bf 100644 --- a/src/view/wallet/wallet.glade +++ b/src/view/wallet/wallet.glade @@ -73,6 +73,42 @@ + + True + False + + + True + False + Copy t_xid + True + + + + + True + False + Copy _amount + True + + + + + True + False + Copy _balance + True + + + + + True + False + Copy _height + True + + + diff --git a/src/view/wallet/widget.rs b/src/view/wallet/widget.rs index d296987..c7f4ffb 100644 --- a/src/view/wallet/widget.rs +++ b/src/view/wallet/widget.rs @@ -22,7 +22,7 @@ use gtk::gdk_pixbuf::Pixbuf; use gtk::prelude::*; use gtk::{ gdk, Adjustment, ApplicationWindow, Button, CheckButton, Entry, HeaderBar, Image, Label, - ListStore, MenuItem, Popover, RadioMenuItem, SortColumn, SortType, SpinButton, Spinner, + ListStore, Menu, MenuItem, Popover, RadioMenuItem, SortColumn, SortType, SpinButton, Spinner, Statusbar, TreeView, }; use relm::Relm; @@ -101,6 +101,12 @@ pub struct Widgets { utxo_list: TreeView, history_list: TreeView, + history_menu: Menu, + hist_copy_txid_mi: MenuItem, + hist_copy_amount_mi: MenuItem, + hist_copy_balance_mi: MenuItem, + hist_copy_height_mi: MenuItem, + status_bar: Statusbar, status_lbl: Label, balance_lbl: Label, @@ -152,6 +158,20 @@ impl Widgets { ); connect!(relm, self.about_mi, connect_activate(_), Msg::About); + let menu = self.history_menu.clone(); + self.history_list + .connect_button_release_event(move |me, event| { + if event.button() == 3 { + me.emit_popup_menu(); + Inhibit(true) + } else { + Inhibit(false) + } + }); + self.history_list.connect_popup_menu(move |_me| { + menu.popup(None::<&Menu>, None::<&MenuItem>, |_, _, _| false, 0, 0); + true + }); self.history_list.connect_row_activated(|me, path, _| { let model = me.model().unwrap(); let iter = model.iter(path).unwrap(); @@ -171,6 +191,36 @@ impl Widgets { gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(&val); }); + let list = self.history_list.clone(); + self.hist_copy_txid_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 1); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(val.get::<&str>().unwrap()); + } + }); + let list = self.history_list.clone(); + self.hist_copy_amount_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 2); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(val.get::<&str>().unwrap()); + } + }); + let list = self.history_list.clone(); + self.hist_copy_balance_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 3); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(val.get::<&str>().unwrap()); + } + }); + let list = self.history_list.clone(); + self.hist_copy_height_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 6); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD) + .set_text(&val.get::().unwrap().to_string()); + } + }); + connect!( relm, self.fiat_usd, From 2631d76b525650a4192a5380cf3a70666529a036 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 11 Jul 2023 12:34:49 +0200 Subject: [PATCH 2/2] wallet: add context menus with copy ops to address and coin lists --- src/view/wallet/wallet.glade | 64 +++++++++++++++++++++++++ src/view/wallet/widget.rs | 93 ++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) diff --git a/src/view/wallet/wallet.glade b/src/view/wallet/wallet.glade index 33f72bf..8fe2db6 100644 --- a/src/view/wallet/wallet.glade +++ b/src/view/wallet/wallet.glade @@ -2,6 +2,34 @@ + + True + False + + + True + False + Copy _address + True + + + + + True + False + Copy _volume + True + + + + + True + False + Copy _balance + True + + + @@ -27,6 +55,42 @@ 0.01 0.10 + + True + False + + + True + False + Copy t_xid + True + + + + + True + False + Copy _address + True + + + + + True + False + Copy _amount + True + + + + + True + False + Copy _height + True + + + True False diff --git a/src/view/wallet/widget.rs b/src/view/wallet/widget.rs index c7f4ffb..44bf8b9 100644 --- a/src/view/wallet/widget.rs +++ b/src/view/wallet/widget.rs @@ -107,6 +107,17 @@ pub struct Widgets { hist_copy_balance_mi: MenuItem, hist_copy_height_mi: MenuItem, + address_menu: Menu, + addr_copy_mi: MenuItem, + addr_copy_volume_mi: MenuItem, + addr_copy_balance_mi: MenuItem, + + coin_menu: Menu, + coin_copy_txid_mi: MenuItem, + coin_copy_addr_mi: MenuItem, + coin_copy_amount_mi: MenuItem, + coin_copy_height_mi: MenuItem, + status_bar: Statusbar, status_lbl: Label, balance_lbl: Label, @@ -178,12 +189,42 @@ impl Widgets { let val: String = model.value(&iter, 1).get().unwrap(); gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(&val); }); + + let menu = self.coin_menu.clone(); + self.utxo_list + .connect_button_release_event(move |me, event| { + if event.button() == 3 { + me.emit_popup_menu(); + Inhibit(true) + } else { + Inhibit(false) + } + }); + self.utxo_list.connect_popup_menu(move |_me| { + menu.popup(None::<&Menu>, None::<&MenuItem>, |_, _, _| false, 0, 0); + true + }); self.utxo_list.connect_row_activated(|me, path, _| { let model = me.model().unwrap(); let iter = model.iter(path).unwrap(); let val: String = model.value(&iter, 1).get().unwrap(); gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(&val); }); + + let menu = self.address_menu.clone(); + self.address_list + .connect_button_release_event(move |me, event| { + if event.button() == 3 { + me.emit_popup_menu(); + Inhibit(true) + } else { + Inhibit(false) + } + }); + self.address_list.connect_popup_menu(move |_me| { + menu.popup(None::<&Menu>, None::<&MenuItem>, |_, _, _| false, 0, 0); + true + }); self.address_list.connect_row_activated(|me, path, _| { let model = me.model().unwrap(); let iter = model.iter(path).unwrap(); @@ -221,6 +262,58 @@ impl Widgets { } }); + let list = self.utxo_list.clone(); + self.coin_copy_txid_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 1); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(val.get::<&str>().unwrap()); + } + }); + let list = self.utxo_list.clone(); + self.coin_copy_addr_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 0); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(val.get::<&str>().unwrap()); + } + }); + let list = self.utxo_list.clone(); + self.coin_copy_amount_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 2); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(val.get::<&str>().unwrap()); + } + }); + let list = self.utxo_list.clone(); + self.coin_copy_height_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 4); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD) + .set_text(&val.get::().unwrap().to_string()); + } + }); + + let list = self.address_list.clone(); + self.addr_copy_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 0); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(val.get::<&str>().unwrap()); + } + }); + let list = self.address_list.clone(); + self.addr_copy_volume_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 2); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(val.get::<&str>().unwrap()); + } + }); + let list = self.address_list.clone(); + self.addr_copy_balance_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 1); + gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD).set_text(val.get::<&str>().unwrap()); + } + }); + connect!( relm, self.fiat_usd,