[Xfce4-commits] [apps/xfce4-terminal] 01/01: Fix Alt+n shortcuts when starting with several tabs

noreply at xfce.org noreply at xfce.org
Tue Nov 15 14:11:02 CET 2016


This is an automated email from the git hooks/post-receive script.

f2404 pushed a commit to branch master
in repository apps/xfce4-terminal.

commit cae2ed79c5bf21dce43d3c608dc7976c5fb0b7ad
Author: Igor <f2404 at yandex.ru>
Date:   Tue Nov 15 15:10:56 2016 +0200

    Fix Alt+n shortcuts when starting with several tabs
---
 terminal/terminal-app.c    |  22 +++++--
 terminal/terminal-window.c | 159 +++++++++++++++++++++++----------------------
 terminal/terminal-window.h |   2 +
 3 files changed, 101 insertions(+), 82 deletions(-)

diff --git a/terminal/terminal-app.c b/terminal/terminal-app.c
index e66a84f..8a8f939 100644
--- a/terminal/terminal-app.c
+++ b/terminal/terminal-app.c
@@ -56,6 +56,7 @@
 static void     terminal_app_finalize                 (GObject            *object);
 static void     terminal_app_update_accels            (TerminalApp        *app);
 static void     terminal_app_update_mnemonics         (TerminalApp        *app);
+static void     terminal_app_update_windows_accels    (gpointer            user_data);
 static gboolean terminal_app_accel_map_load           (gpointer            user_data);
 static gboolean terminal_app_accel_map_save           (gpointer            user_data);
 static gboolean terminal_app_unset_urgent_bell        (TerminalWindow     *window,
@@ -143,8 +144,9 @@ terminal_app_init (TerminalApp *app)
   terminal_app_update_accels (app);
   terminal_app_update_mnemonics (app);
 
-  /* schedule accel map load */
-  app->accel_map_load_id = g_idle_add_full (G_PRIORITY_LOW, terminal_app_accel_map_load, app, NULL);
+  /* schedule accel map load and update windows when finished */
+  app->accel_map_load_id = g_idle_add_full (G_PRIORITY_LOW, terminal_app_accel_map_load, app,
+                                            terminal_app_update_windows_accels);
 }
 
 
@@ -228,6 +230,20 @@ terminal_app_update_mnemonics (TerminalApp *app)
 
 
 
+static void
+terminal_app_update_windows_accels (gpointer user_data)
+{
+  TerminalApp *app = TERMINAL_APP (user_data);
+  GSList      *lp;
+
+  for (lp = app->windows; lp != NULL; lp = lp->next)
+    terminal_window_rebuild_tabs_menu (TERMINAL_WINDOW (lp->data));
+
+  app->accel_map_load_id = 0;
+}
+
+
+
 static gboolean
 terminal_app_accel_map_save (gpointer user_data)
 {
@@ -274,8 +290,6 @@ terminal_app_accel_map_load (gpointer user_data)
   gchar        name[50];
   guint        i;
 
-  app->accel_map_load_id = 0;
-
   path = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, ACCEL_MAP_PATH);
   if (G_LIKELY (path != NULL))
     {
diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c
index 4c6e80f..5ad13e5 100644
--- a/terminal/terminal-window.c
+++ b/terminal/terminal-window.c
@@ -93,7 +93,6 @@ static gboolean     terminal_window_accel_activate                (GtkAccelGroup
                                                                    GdkModifierType         accel_mods,
                                                                    TerminalWindow         *window);
 static void         terminal_window_update_actions                (TerminalWindow         *window);
-static void         terminal_window_rebuild_tabs_menu             (TerminalWindow         *window);
 static void         terminal_window_notebook_page_switched        (GtkNotebook            *notebook,
                                                                    GtkWidget              *page,
                                                                    guint                   page_num,
@@ -831,83 +830,6 @@ terminal_window_update_actions (TerminalWindow *window)
 
 
 static void
-terminal_window_rebuild_tabs_menu (TerminalWindow *window)
-{
-  gint            npages, n;
-  GtkWidget      *page;
-  GSList         *group = NULL;
-  GtkRadioAction *radio_action;
-  gchar           name[50];
-  GSList         *lp;
-  GtkAccelKey     key = {0};
-
-  if (window->priv->tabs_menu_merge_id != 0)
-    {
-      /* remove merge id */
-      gtk_ui_manager_remove_ui (window->priv->ui_manager, window->priv->tabs_menu_merge_id);
-
-      /* drop all the old accels from the action group */
-      for (lp = window->priv->tabs_menu_actions; lp != NULL; lp = lp->next)
-        gtk_action_group_remove_action (window->action_group, GTK_ACTION (lp->data));
-
-      g_slist_free (window->priv->tabs_menu_actions);
-      window->priv->tabs_menu_actions = NULL;
-    }
-
-  /* create a new merge id */
-  window->priv->tabs_menu_merge_id = gtk_ui_manager_new_merge_id (window->priv->ui_manager);
-  terminal_assert (window->priv->tabs_menu_actions == NULL);
-
-  /* walk the tabs */
-  npages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook));
-  for (n = 0; n < npages; n++)
-    {
-      page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), n);
-
-      g_snprintf (name, sizeof (name), "goto-tab-%d", n + 1);
-
-      /* create action */
-      radio_action = gtk_radio_action_new (name, NULL, NULL, NULL, n);
-      gtk_action_set_sensitive (GTK_ACTION (radio_action), npages > 1);
-      g_object_bind_property (G_OBJECT (page), "title",
-                              G_OBJECT (radio_action), "label",
-                              G_BINDING_SYNC_CREATE);
-      gtk_radio_action_set_group (radio_action, group);
-      group = gtk_radio_action_get_group (radio_action);
-      gtk_action_group_add_action (window->action_group, GTK_ACTION (radio_action));
-      g_signal_connect (G_OBJECT (radio_action), "activate",
-          G_CALLBACK (terminal_window_action_goto_tab), window->notebook);
-
-      /* connect action to the page so we can active it when a tab is switched */
-      g_object_set_qdata_full (G_OBJECT (page), tabs_menu_action_quark,
-                               radio_action, g_object_unref);
-
-      /* add action in the menu */
-      gtk_ui_manager_add_ui (window->priv->ui_manager, window->priv->tabs_menu_merge_id,
-                             "/main-menu/tabs-menu/placeholder-tab-items",
-                             name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
-
-      if (npages > 1)
-        {
-          /* add to right-click tab menu */
-          gtk_ui_manager_add_ui (window->priv->ui_manager, window->priv->tabs_menu_merge_id,
-                                 "/tab-menu/tabs-menu/placeholder-tab-items",
-                                 name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
-        }
-
-      /* set an accelerator path */
-      g_snprintf (name, sizeof (name), "<Actions>/terminal-window/goto-tab-%d", n + 1);
-      if (gtk_accel_map_lookup_entry (name, &key) && key.accel_key != 0)
-        gtk_action_set_accel_path (GTK_ACTION (radio_action), name);
-
-      /* store */
-      window->priv->tabs_menu_actions = g_slist_prepend (window->priv->tabs_menu_actions, radio_action);
-    }
-}
-
-
-
-static void
 terminal_window_notebook_page_switched (GtkNotebook     *notebook,
                                         GtkWidget       *page,
                                         guint            page_num,
@@ -2535,3 +2457,84 @@ terminal_window_get_preferences_dialog (TerminalWindow *window)
 {
   return window->priv->preferences_dialog;
 }
+
+
+
+/**
+ * terminal_window_rebuild_tabs_menu:
+ * @window  : A #TerminalWindow.
+ **/
+void
+terminal_window_rebuild_tabs_menu (TerminalWindow *window)
+{
+  gint            npages, n;
+  GtkWidget      *page;
+  GSList         *group = NULL;
+  GtkRadioAction *radio_action;
+  gchar           name[50];
+  GSList         *lp;
+  GtkAccelKey     key = {0};
+
+  if (window->priv->tabs_menu_merge_id != 0)
+    {
+      /* remove merge id */
+      gtk_ui_manager_remove_ui (window->priv->ui_manager, window->priv->tabs_menu_merge_id);
+
+      /* drop all the old accels from the action group */
+      for (lp = window->priv->tabs_menu_actions; lp != NULL; lp = lp->next)
+        gtk_action_group_remove_action (window->action_group, GTK_ACTION (lp->data));
+
+      g_slist_free (window->priv->tabs_menu_actions);
+      window->priv->tabs_menu_actions = NULL;
+    }
+
+  /* create a new merge id */
+  window->priv->tabs_menu_merge_id = gtk_ui_manager_new_merge_id (window->priv->ui_manager);
+  terminal_assert (window->priv->tabs_menu_actions == NULL);
+
+  /* walk the tabs */
+  npages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook));
+  for (n = 0; n < npages; n++)
+    {
+      page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), n);
+
+      g_snprintf (name, sizeof (name), "goto-tab-%d", n + 1);
+
+      /* create action */
+      radio_action = gtk_radio_action_new (name, NULL, NULL, NULL, n);
+      gtk_action_set_sensitive (GTK_ACTION (radio_action), npages > 1);
+      g_object_bind_property (G_OBJECT (page), "title",
+                              G_OBJECT (radio_action), "label",
+                              G_BINDING_SYNC_CREATE);
+      gtk_radio_action_set_group (radio_action, group);
+      group = gtk_radio_action_get_group (radio_action);
+      gtk_action_group_add_action (window->action_group, GTK_ACTION (radio_action));
+      g_signal_connect (G_OBJECT (radio_action), "activate",
+          G_CALLBACK (terminal_window_action_goto_tab), window->notebook);
+
+      /* connect action to the page so we can active it when a tab is switched */
+      g_object_set_qdata_full (G_OBJECT (page), tabs_menu_action_quark,
+                               radio_action, g_object_unref);
+
+      /* add action in the menu */
+      gtk_ui_manager_add_ui (window->priv->ui_manager, window->priv->tabs_menu_merge_id,
+                             "/main-menu/tabs-menu/placeholder-tab-items",
+                             name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
+
+      if (npages > 1)
+        {
+          /* add to right-click tab menu */
+          gtk_ui_manager_add_ui (window->priv->ui_manager, window->priv->tabs_menu_merge_id,
+                                 "/tab-menu/tabs-menu/placeholder-tab-items",
+                                 name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
+        }
+
+      /* set an accelerator path */
+      g_snprintf (name, sizeof (name), "<Actions>/terminal-window/goto-tab-%d", n + 1);
+      if (gtk_accel_map_lookup_entry (name, &key) && key.accel_key != 0)
+        gtk_action_set_accel_path (GTK_ACTION (radio_action), name);
+
+      /* store */
+      window->priv->tabs_menu_actions = g_slist_prepend (window->priv->tabs_menu_actions, radio_action);
+    }
+}
diff --git a/terminal/terminal-window.h b/terminal/terminal-window.h
index 5ae7255..aa84bab 100644
--- a/terminal/terminal-window.h
+++ b/terminal/terminal-window.h
@@ -91,6 +91,8 @@ GObject        *terminal_window_get_preferences        (TerminalWindow     *wind
 
 GtkWidget      *terminal_window_get_preferences_dialog (TerminalWindow     *window);
 
+void            terminal_window_rebuild_tabs_menu      (TerminalWindow     *window);
+
 G_END_DECLS
 
 #endif /* !TERMINAL_WINDOW_H */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list