Make Copy button copy selected log rows, make it less prominent

This commit is contained in:
Michael Gratton 2019-04-06 17:26:14 +11:00 committed by Michael James Gratton
parent 1b121e0a8e
commit 0e4486bbf4
2 changed files with 51 additions and 8 deletions

View file

@ -12,6 +12,9 @@
public class Components.Inspector : Gtk.Window {
private const int COL_MESSAGE = 0;
[GtkChild]
private Gtk.HeaderBar header_bar;
@ -36,6 +39,9 @@ public class Components.Inspector : Gtk.Window {
[GtkChild]
private Gtk.CellRendererText log_renderer;
[GtkChild]
private Gtk.Widget detail_pane;
[GtkChild]
private Gtk.ListBox detail_list;
@ -57,7 +63,7 @@ public class Components.Inspector : Gtk.Window {
while (logs != null) {
Gtk.TreeIter iter;
logs_store.append(out iter);
logs_store.set_value(iter, 0, logs.format());
logs_store.set_value(iter, COL_MESSAGE, logs.format());
logs = logs.get_next();
}
@ -95,7 +101,32 @@ public class Components.Inspector : Gtk.Window {
[GtkCallback]
private void on_copy_clicked() {
get_clipboard(Gdk.SELECTION_CLIPBOARD).set_text(this.details, -1);
string clipboard_value = "";
if (this.stack.visible_child == this.logs_pane) {
StringBuilder rows = new StringBuilder();
Gtk.TreeModel model = this.logs_view.model;
foreach (Gtk.TreePath path in
this.logs_view.get_selection().get_selected_rows(null)) {
Gtk.TreeIter iter;
if (model.get_iter(out iter, path)) {
Value value;
model.get_value(iter, COL_MESSAGE, out value);
string? message = (string) value;
if (message != null) {
rows.append(message);
rows.append_c('\n');
}
}
}
clipboard_value = rows.str;
} else if (this.stack.visible_child == this.detail_pane) {
clipboard_value = this.details;
}
if (!Geary.String.is_empty(clipboard_value)) {
get_clipboard(Gdk.SELECTION_CLIPBOARD).set_text(clipboard_value, -1);
}
}
[GtkCallback]
@ -103,6 +134,11 @@ public class Components.Inspector : Gtk.Window {
this.search_bar.set_search_mode(!this.search_bar.get_search_mode());
}
[GtkCallback]
private void on_logs_selection_changed() {
update_ui();
}
[GtkCallback]
private void on_destroy() {
destroy();

View file

@ -51,14 +51,18 @@
</child>
<child>
<object class="GtkButton" id="copy_button">
<property name="label" translatable="yes">Copy to Clipboard</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_copy_clicked" swapped="no"/>
<style>
<class name="suggested-action"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes" comments="Tooltip for inspector button">Copy selected rows</property>
<property name="icon_name">edit-copy-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</property>
@ -103,7 +107,10 @@
<property name="enable_search">False</property>
<property name="show_expanders">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
<object class="GtkTreeSelection">
<property name="mode">multiple</property>
<signal name="changed" handler="on_logs_selection_changed" swapped="no"/>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="log_column">
@ -131,7 +138,7 @@
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<object class="GtkScrolledWindow" id="detail_pane">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>