Skip to content

Commit

Permalink
Merge branch 'contextmenu' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 11, 2023
2 parents 6bf7358 + 2631d76 commit 51bb0cd
Show file tree
Hide file tree
Showing 2 changed files with 244 additions and 1 deletion.
100 changes: 100 additions & 0 deletions src/view/wallet/wallet.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkMenu" id="address_menu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkMenuItem" id="addr_copy_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy _address</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="addr_copy_volume_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy _volume</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="addr_copy_balance_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy _balance</property>
<property name="use-underline">True</property>
</object>
</child>
</object>
<object class="GtkListStore" id="address_store">
<columns>
<!-- column-name address -->
Expand All @@ -27,6 +55,42 @@
<property name="step-increment">0.01</property>
<property name="page-increment">0.10</property>
</object>
<object class="GtkMenu" id="coin_menu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkMenuItem" id="coin_copy_txid_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy t_xid</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="coin_copy_addr_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy _address</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="coin_copy_amount_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy _amount</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="coin_copy_height_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy _height</property>
<property name="use-underline">True</property>
</object>
</child>
</object>
<object class="GtkMenu" id="fiat_menu">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand Down Expand Up @@ -73,6 +137,42 @@
</object>
</child>
</object>
<object class="GtkMenu" id="history_menu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkMenuItem" id="hist_copy_txid_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy t_xid</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="hist_copy_amount_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy _amount</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="hist_copy_balance_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy _balance</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="hist_copy_height_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Copy _height</property>
<property name="use-underline">True</property>
</object>
</child>
</object>
<object class="GtkListStore" id="history_store">
<columns>
<!-- column-name type -->
Expand Down
145 changes: 144 additions & 1 deletion src/view/wallet/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,6 +101,23 @@ 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,

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,
Expand Down Expand Up @@ -152,25 +169,151 @@ 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();
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();
let val: String = model.value(&iter, 0).get().unwrap();
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::<u32>().unwrap().to_string());
}
});

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::<u32>().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,
Expand Down

0 comments on commit 51bb0cd

Please sign in to comment.