[geary/wip/geary-inspector: 15/19] Enable some keyboard shortcuts for the inspector



commit afd2571971cb95063434161b67ee59aba5b273de
Author: Michael Gratton <mike vee net>
Date:   Sun Apr 7 17:49:43 2019 +1000

    Enable some keyboard shortcuts for the inspector

 src/client/application/geary-application.vala   |  1 +
 src/client/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, { "<Ctrl>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, { "<Ctrl>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 <Space> 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 @@
       </row>
     </data>
   </object>
-  <template class="ComponentsInspector" parent="GtkWindow">
+  <template class="ComponentsInspector" parent="GtkApplicationWindow">
     <property name="can_focus">False</property>
     <property name="default_width">750</property>
     <property name="default_height">500</property>
@@ -29,8 +29,8 @@
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
             <property name="tooltip_text" translatable="yes" comments="Tooltip for inspector button">Togggle 
appending new log entries</property>
+            <property name="action_name">win.toggle-play</property>
             <property name="active">True</property>
-            <signal name="toggled" handler="on_logs_play_toggled" swapped="no"/>
             <child>
               <object class="GtkImage">
                 <property name="visible">True</property>
@@ -41,12 +41,12 @@
           </object>
         </child>
         <child>
-          <object class="GtkButton" id="search_button">
+          <object class="GtkToggleButton" id="search_button">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
             <property name="tooltip_text" translatable="yes" comments="Tooltip for inspector button">Search 
fo matching log entries</property>
-            <signal name="clicked" handler="on_search_clicked" swapped="no"/>
+            <property name="action_name">win.toggle-search</property>
             <child>
               <object class="GtkImage">
                 <property name="visible">True</property>
@@ -92,7 +92,7 @@
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
             <property name="tooltip_text" translatable="yes" comments="Tooltip for inspector button">Copy 
selected log entries</property>
-            <signal name="clicked" handler="on_copy_clicked" swapped="no"/>
+            <property name="action_name">win.copy</property>
             <child>
               <object class="GtkImage">
                 <property name="visible">True</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]