From d87a2b02e05eeb8d1f8daf981a868e32dc88abf4 Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Sun, 7 Apr 2019 17:49:43 +1000 Subject: [PATCH] Enable some keyboard shortcuts for the inspector --- src/client/application/geary-application.vala | 1 + .../components/components-inspector.vala | 78 +++++++++++++++---- ui/components-inspector.ui | 10 +-- 3 files changed, 71 insertions(+), 18 deletions(-) diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala index 75915977..d205a3c3 100644 --- a/src/client/application/geary-application.vala +++ b/src/client/application/geary-application.vala @@ -355,6 +355,7 @@ public class GearyApplication : Gtk.Application { add_window_accelerators(ACTION_UNDO, { "Z" }); ComposerWidget.add_window_accelerators(this); + Components.Inspector.add_window_accelerators(this); yield controller.open_async(null); diff --git a/src/client/components/components-inspector.vala b/src/client/components/components-inspector.vala index 67976d83..e42f5226 100644 --- a/src/client/components/components-inspector.vala +++ b/src/client/components/components-inspector.vala @@ -10,11 +10,31 @@ * A window that displays debugging and development information. */ [GtkTemplate (ui = "/org/gnome/Geary/components-inspector.ui")] -public class Components.Inspector : Gtk.Window { +public class Components.Inspector : Gtk.ApplicationWindow { private const int COL_MESSAGE = 0; + private const string ACTION_CLOSE = "inspector-close"; + private const string ACTION_PLAY_TOGGLE = "toggle-play"; + private const string ACTION_SEARCH_TOGGLE = "toggle-search"; + private const string ACTION_SEARCH_ACTIVATE = "activate-search"; + + private const ActionEntry[] action_entries = { + {GearyApplication.ACTION_CLOSE, on_close }, + {GearyApplication.ACTION_COPY, on_copy_clicked }, + {ACTION_CLOSE, on_close }, + {ACTION_PLAY_TOGGLE, on_logs_play_toggled, null, "true" }, + {ACTION_SEARCH_TOGGLE, on_logs_search_toggled, null, "false" }, + {ACTION_SEARCH_ACTIVATE, on_logs_search_activated }, + }; + + public static void add_window_accelerators(GearyApplication app) { + app.add_window_accelerators(ACTION_CLOSE, { "Escape" } ); + app.add_window_accelerators(ACTION_PLAY_TOGGLE, { "space" } ); + app.add_window_accelerators(ACTION_SEARCH_ACTIVATE, { "F" } ); + } + [GtkChild] private Gtk.HeaderBar header_bar; @@ -72,8 +92,11 @@ public class Components.Inspector : Gtk.Window { public Inspector(GearyApplication app) { + Object(application: app); this.title = this.header_bar.title = _("Inspector"); + add_action_entries(Inspector.action_entries, this); + this.search_bar.connect_entry(this.search_entry); GLib.Settings system = app.config.gnome_interface; @@ -139,7 +162,26 @@ public class Components.Inspector : Gtk.Window { } public override bool key_press_event(Gdk.EventKey event) { - bool ret = this.search_bar.handle_event(event); + bool ret = Gdk.EVENT_PROPAGATE; + + if (this.search_bar.search_mode_enabled && + event.keyval == Gdk.Key.Escape) { + // Manually deactivate search so the button stays in sync + this.search_button.set_active(false); + ret = Gdk.EVENT_STOP; + } + + if (ret == Gdk.EVENT_PROPAGATE) { + ret = this.search_bar.handle_event(event); + } + + if (ret == Gdk.EVENT_PROPAGATE && + this.search_bar.search_mode_enabled) { + // Ensure and others are passed to the search + // entry before getting used as an accelerator. + ret = this.search_entry.key_press_event(event); + } + if (ret == Gdk.EVENT_PROPAGATE) { ret = base.key_press_event(event); } @@ -234,7 +276,6 @@ public class Components.Inspector : Gtk.Window { update_ui(); } - [GtkCallback] private void on_copy_clicked() { string clipboard_value = ""; if (this.stack.visible_child == this.logs_pane) { @@ -292,11 +333,6 @@ public class Components.Inspector : Gtk.Window { } } - [GtkCallback] - private void on_search_clicked() { - this.search_bar.set_search_mode(!this.search_bar.get_search_mode()); - } - [GtkCallback] private void on_logs_size_allocate() { if (this.autoscroll) { @@ -309,11 +345,23 @@ public class Components.Inspector : Gtk.Window { update_ui(); } - [GtkCallback] - private void on_logs_play_toggled(Gtk.ToggleButton button) { - if (this.update_logs != button.active) { - enable_log_updates(button.active); - } + private void on_logs_search_toggled(GLib.SimpleAction action, + GLib.Variant? param) { + bool enabled = !((bool) action.state); + this.search_bar.set_search_mode(enabled); + action.set_state(enabled); + } + + private void on_logs_search_activated() { + this.search_button.set_active(true); + this.search_entry.grab_focus(); + } + + private void on_logs_play_toggled(GLib.SimpleAction action, + GLib.Variant? param) { + bool enabled = !((bool) action.state); + enable_log_updates(enabled); + action.set_state(enabled); } [GtkCallback] @@ -337,6 +385,10 @@ public class Components.Inspector : Gtk.Window { } } + private void on_close() { + destroy(); + } + } diff --git a/ui/components-inspector.ui b/ui/components-inspector.ui index d138ade8..b874fb13 100644 --- a/ui/components-inspector.ui +++ b/ui/components-inspector.ui @@ -14,7 +14,7 @@ -