[gnome-terminal/wip/fmuellner/headerbar: 9/14] accels: Add shortcut for toggling the primary menu



commit 47bb520171e328925dea9e7769b17a7d8dfd6e3f
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Nov 5 23:24:50 2018 +0100

    accels: Add shortcut for toggling the primary menu
    
    When the headerbar is enabled, the primary menu is an important
    entry point. Make it more accessible by adding a dedicated
    shortcut.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756798

 src/org.gnome.Terminal.gschema.xml |  4 ++
 src/terminal-accels.c              | 79 +++++++++++++++++++++++---------------
 src/terminal-accels.h              |  5 ++-
 src/terminal-app.c                 |  2 +-
 src/terminal-headerbar.ui          |  1 +
 src/terminal-window.c              |  1 +
 6 files changed, 58 insertions(+), 34 deletions(-)
---
diff --git a/src/org.gnome.Terminal.gschema.xml b/src/org.gnome.Terminal.gschema.xml
index fc1602f2..b9ba2390 100644
--- a/src/org.gnome.Terminal.gschema.xml
+++ b/src/org.gnome.Terminal.gschema.xml
@@ -664,6 +664,10 @@
       <default>'&lt;Ctrl&gt;0'</default>
       <summary>Keyboard shortcut to make font normal-size</summary>
     </key>
+    <key name="header-menu" type="s">
+      <default>'disabled'</default>
+      <summary>Keyboard shortcut to show the primary menu</summary>
+    </key>
   </schema>
 
   <!-- Global settings -->
diff --git a/src/terminal-accels.c b/src/terminal-accels.c
index e412180f..75ac3a1e 100644
--- a/src/terminal-accels.c
+++ b/src/terminal-accels.c
@@ -60,6 +60,7 @@
 #define KEY_FIND_PREV           "find-previous"
 #define KEY_FIND_NEXT           "find-next"
 #define KEY_FULL_SCREEN         "full-screen"
+#define KEY_HEADER_MENU         "header-menu"
 #define KEY_HELP                "help"
 #define KEY_MOVE_TAB_LEFT       "move-tab-left"
 #define KEY_MOVE_TAB_RIGHT      "move-tab-right"
@@ -111,6 +112,7 @@ typedef struct
   KeyEntry *key_entry;
   guint n_elements;
   const char *user_visible_name;
+  gboolean headerbar_only;
 } KeyEntryList;
 
 #define ENTRY_FULL(name, key, action, type, parameter, shadow_name) \
@@ -213,19 +215,24 @@ static KeyEntry help_entries[] = {
   ENTRY (N_("Contents"), KEY_HELP, "help", NULL, NULL)
 };
 
+static KeyEntry global_entries[] = {
+  ENTRY (N_("Show Primary Menu"), KEY_HEADER_MENU, "header-menu", NULL, NULL),
+};
+
 #undef ENTRY_FULL
 #undef ENTRY
 #undef ENTRY_MDI
 
 static KeyEntryList all_entries[] =
 {
-  { file_entries, G_N_ELEMENTS (file_entries), N_("File") },
-  { edit_entries, G_N_ELEMENTS (edit_entries), N_("Edit") },
-  { view_entries, G_N_ELEMENTS (view_entries), N_("View") },
-  { search_entries, G_N_ELEMENTS (search_entries), N_("Search") },
-  { terminal_entries, G_N_ELEMENTS (terminal_entries), N_("Terminal") },
-  { tabs_entries, G_N_ELEMENTS (tabs_entries), N_("Tabs") },
-  { help_entries, G_N_ELEMENTS (help_entries), N_("Help") }
+  { file_entries,     G_N_ELEMENTS (file_entries),     N_("File"),     FALSE },
+  { edit_entries,     G_N_ELEMENTS (edit_entries),     N_("Edit"),     FALSE },
+  { view_entries,     G_N_ELEMENTS (view_entries),     N_("View"),     FALSE },
+  { search_entries,   G_N_ELEMENTS (search_entries),   N_("Search"),   FALSE },
+  { terminal_entries, G_N_ELEMENTS (terminal_entries), N_("Terminal"), FALSE },
+  { tabs_entries,     G_N_ELEMENTS (tabs_entries),     N_("Tabs"),     FALSE },
+  { help_entries,     G_N_ELEMENTS (help_entries),     N_("Help"),     FALSE },
+  { global_entries,   G_N_ELEMENTS (global_entries),   N_("Global"),   TRUE  },
 };
 
 enum
@@ -305,9 +312,37 @@ key_changed_cb (GSettings *settings,
   }
 }
 
+static void
+add_accel_entries (GApplication*application,
+                   KeyEntry *entries,
+                   guint n_entries)
+{
+  guint j;
+
+  for (j = 0; j < n_entries; ++j) {
+    KeyEntry *key_entry = &entries[j];
+    if (key_entry->action_parameter) {
+      GError *err = NULL;
+      key_entry->parameter = g_variant_parse (key_entry->action_parameter_type,
+                                              key_entry->action_parameter,
+                                              NULL, NULL, &err);
+      g_assert_no_error (err);
+
+      g_assert (key_entry->parameter != NULL);
+    }
+
+    g_hash_table_insert (settings_key_to_entry,
+                         (gpointer) key_entry->settings_key,
+                         key_entry);
+
+    key_changed_cb (keybinding_settings, key_entry->settings_key, application);
+  }
+}
+
 void
 terminal_accels_init (GApplication *application,
-                      GSettings *settings)
+                      GSettings *settings,
+                      gboolean use_headerbar)
 {
   guint i, j;
 
@@ -328,30 +363,12 @@ terminal_accels_init (GApplication *application,
       tabs_entries[i].user_visible_name = g_intern_string (name);
     }
 
-  for (i = 0; i < G_N_ELEMENTS (all_entries); ++i)
-    {
-      for (j = 0; j < all_entries[i].n_elements; ++j)
-       {
-         KeyEntry *key_entry;
-
-         key_entry = &(all_entries[i].key_entry[j]);
-          if (key_entry->action_parameter) {
-            GError *err = NULL;
-            key_entry->parameter = g_variant_parse (key_entry->action_parameter_type,
-                                                    key_entry->action_parameter,
-                                                    NULL, NULL, &err);
-            g_assert_no_error (err);
-
-            g_assert (key_entry->parameter != NULL);
-          }
-
-          g_hash_table_insert (settings_key_to_entry,
-                               (gpointer) key_entry->settings_key,
-                               key_entry);
+  for (i = 0; i < G_N_ELEMENTS (all_entries); ++i) {
+    if (!use_headerbar && all_entries[i].headerbar_only)
+      continue;
 
-          key_changed_cb (keybinding_settings, key_entry->settings_key, application);
-       }
-    }
+    add_accel_entries (application, all_entries[i].key_entry, all_entries[i].n_elements);
+  }
 
   g_signal_connect (keybinding_settings, "changed", G_CALLBACK (key_changed_cb), application);
 }
diff --git a/src/terminal-accels.h b/src/terminal-accels.h
index e0a5204f..8c860a35 100644
--- a/src/terminal-accels.h
+++ b/src/terminal-accels.h
@@ -24,8 +24,9 @@
 G_BEGIN_DECLS
 
 void terminal_accels_init (GApplication *application,
-                           GSettings *settings);
- 
+                           GSettings *settings,
+                           gboolean use_headerbar);
+
 void terminal_accels_shutdown (void);
 
 void terminal_accels_fill_treeview (GtkWidget *treeview,
diff --git a/src/terminal-app.c b/src/terminal-app.c
index 6f251abb..6d39f8fc 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -816,7 +816,7 @@ terminal_app_init (TerminalApp *app)
   app->screen_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
   gs_unref_object GSettings *settings = g_settings_get_child (app->global_settings, "keybindings");
-  terminal_accels_init (G_APPLICATION (app), settings);
+  terminal_accels_init (G_APPLICATION (app), settings, app->use_headerbar);
 }
 
 static void
diff --git a/src/terminal-headerbar.ui b/src/terminal-headerbar.ui
index b9268549..c54f1483 100644
--- a/src/terminal-headerbar.ui
+++ b/src/terminal-headerbar.ui
@@ -44,6 +44,7 @@
         <property name="focus_on_click">False</property>
         <property name="can_focus">True</property>
         <property name="receives_default">True</property>
+        <property name="action-name">win.header-menu</property>
         <style>
           <class name="image-button"/>
         </style>
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 10b5a6ac..d197afab 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -2100,6 +2100,7 @@ terminal_window_init (TerminalWindow *window)
     /* Actions with state */
     { "active-tab",          action_active_tab_set_cb,   "i",  "@i 0",    action_active_tab_state_cb      },
     { "encoding",            NULL /* changes state */,   "s",  "'UTF-8'", action_encoding_state_cb        },
+    { "header-menu",         NULL /* toggles state */,   NULL, "false",   NULL },
     { "fullscreen",          NULL /* toggles state */,   NULL, "false",   action_fullscreen_state_cb      },
     { "menubar-visible",     NULL /* toggles state */,   NULL, "true",    action_menubar_visible_state_cb },
     { "profile",             NULL /* changes state */,   "s",  "''",      action_profile_state_cb         },


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