[Xfce4-commits] r30361 - terminal/trunk/terminal

Nick Schermer nick at xfce.org
Mon Jul 20 19:46:11 CEST 2009


Author: nick
Date: 2009-07-20 17:46:11 +0000 (Mon, 20 Jul 2009)
New Revision: 30361

Modified:
   terminal/trunk/terminal/main.c
   terminal/trunk/terminal/terminal-toolbars-model.c
   terminal/trunk/terminal/terminal-window.c
Log:
Don't create the menubar if not enabled.

This saves both creating the menu widget but also
updating the complete ui-manager, which happens in
an idle thread.


Modified: terminal/trunk/terminal/main.c
===================================================================
--- terminal/trunk/terminal/main.c	2009-07-20 17:31:03 UTC (rev 30360)
+++ terminal/trunk/terminal/main.c	2009-07-20 17:46:11 UTC (rev 30361)
@@ -157,7 +157,7 @@
   /* Do NOT remove this line for now, If something doesn't work,
    * fix your code instead!
    */
-  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL /* | G_LOG_LEVEL_WARNING */);
+  //g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL /* | G_LOG_LEVEL_WARNING */);
 #endif
 
   if (!terminal_options_parse (argc, argv, NULL, &options, &error))

Modified: terminal/trunk/terminal/terminal-toolbars-model.c
===================================================================
--- terminal/trunk/terminal/terminal-toolbars-model.c	2009-07-20 17:31:03 UTC (rev 30360)
+++ terminal/trunk/terminal/terminal-toolbars-model.c	2009-07-20 17:46:11 UTC (rev 30361)
@@ -30,10 +30,10 @@
 
 
 
-static void     terminal_toolbars_model_finalize      (GObject                    *object);
-static void     terminal_toolbars_model_queue_sync    (TerminalToolbarsModel      *model);
-static gboolean terminal_toolbars_model_sync          (TerminalToolbarsModel      *model);
-static void     terminal_toolbars_model_sync_destroy  (TerminalToolbarsModel      *model);
+static void     terminal_toolbars_model_finalize      (GObject               *object);
+static void     terminal_toolbars_model_queue_sync    (TerminalToolbarsModel *model);
+static gboolean terminal_toolbars_model_sync          (gpointer               user_data);
+static void     terminal_toolbars_model_sync_destroy  (gpointer               user_data);
 
 
 
@@ -131,19 +131,18 @@
 {
   if (G_LIKELY (model->sync_id == 0))
     {
-      model->sync_id = g_timeout_add_full (G_PRIORITY_LOW, 1000,
-                                           (GSourceFunc) terminal_toolbars_model_sync,
-                                           model,
-                                           (GDestroyNotify) terminal_toolbars_model_sync_destroy);
+      model->sync_id = g_timeout_add_seconds_full (G_PRIORITY_LOW, 1, terminal_toolbars_model_sync,
+                                                   model, terminal_toolbars_model_sync_destroy);
     }
 }
 
 
 
 static gboolean
-terminal_toolbars_model_sync (TerminalToolbarsModel *model)
+terminal_toolbars_model_sync (gpointer user_data)
 {
-  gchar *file;
+  TerminalToolbarsModel *model = TERMINAL_TOOLBARS_MODEL (user_data);
+  gchar                 *file;
 
   file = xfce_resource_save_location (XFCE_RESOURCE_DATA, "Terminal/Terminal-toolbars.ui", TRUE);
   exo_toolbars_model_save_to_file (EXO_TOOLBARS_MODEL (model), file, NULL);
@@ -155,9 +154,9 @@
 
 
 static void
-terminal_toolbars_model_sync_destroy (TerminalToolbarsModel *model)
+terminal_toolbars_model_sync_destroy (gpointer user_data)
 {
-  model->sync_id = 0;
+  TERMINAL_TOOLBARS_MODEL (user_data)->sync_id = 0;
 }
 
 
@@ -175,8 +174,7 @@
   if (G_UNLIKELY (model == NULL))
     {
       model = g_object_new (TERMINAL_TYPE_TOOLBARS_MODEL, NULL);
-      g_object_add_weak_pointer (G_OBJECT (model),
-                                 (gpointer) &model);
+      g_object_add_weak_pointer (G_OBJECT (model), (gpointer) &model);
     }
   else
     {

Modified: terminal/trunk/terminal/terminal-window.c
===================================================================
--- terminal/trunk/terminal/terminal-window.c	2009-07-20 17:31:03 UTC (rev 30360)
+++ terminal/trunk/terminal/terminal-window.c	2009-07-20 17:46:11 UTC (rev 30361)
@@ -244,7 +244,7 @@
 
 static const GtkToggleActionEntry toggle_action_entries[] =
 {
-  { "show-menubar", TERMINAL_STOCK_SHOWMENU, N_ ("Show _Menubar"), NULL, N_ ("Show/hide the menubar"), G_CALLBACK (terminal_window_action_show_menubar), TRUE, },
+  { "show-menubar", TERMINAL_STOCK_SHOWMENU, N_ ("Show _Menubar"), NULL, N_ ("Show/hide the menubar"), G_CALLBACK (terminal_window_action_show_menubar), FALSE, },
   { "show-toolbars", NULL, N_ ("Show _Toolbars"), NULL, N_ ("Show/hide the toolbars"), G_CALLBACK (terminal_window_action_show_toolbars), FALSE, },
   { "show-borders", TERMINAL_STOCK_SHOWBORDERS, N_ ("Show Window _Borders"), NULL, N_ ("Show/hide the window decorations"), G_CALLBACK (terminal_window_action_show_borders), TRUE, },
   { "fullscreen", GTK_STOCK_FULLSCREEN, N_ ("_Fullscreen"), NULL, N_ ("Toggle fullscreen mode"), G_CALLBACK (terminal_window_action_fullscreen), FALSE, },
@@ -341,7 +341,6 @@
   gtk_ui_manager_insert_action_group (window->ui_manager, window->action_group, 0);
   gtk_ui_manager_add_ui_from_string (window->ui_manager, terminal_window_ui, terminal_window_ui_length, NULL);
 
-
   accel_group = gtk_ui_manager_get_accel_group (window->ui_manager);
   gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
 
@@ -349,13 +348,6 @@
   gtk_container_add (GTK_CONTAINER (window), vbox);
   gtk_widget_show (vbox);
 
-  window->menubar = gtk_ui_manager_get_widget (window->ui_manager, "/main-menu");
-  if (G_LIKELY (window->menubar != NULL))
-    {
-      gtk_box_pack_start (GTK_BOX (vbox), window->menubar, FALSE, FALSE, 0);
-      gtk_widget_show (window->menubar);
-    }
-
   /* get some preferences */
   g_object_get (G_OBJECT (window->preferences),
                 "shortcuts-no-mnemonics", &no_mnemonics,
@@ -1212,7 +1204,7 @@
 
 
 
-static GtkWidget*
+static GtkWidget *
 terminal_window_get_context_menu (TerminalScreen  *screen,
                                   TerminalWindow  *window)
 {
@@ -1403,14 +1395,27 @@
 terminal_window_action_show_menubar (GtkToggleAction *action,
                                      TerminalWindow  *window)
 {
-  if (G_UNLIKELY (window->menubar == NULL))
-    return;
+  GtkWidget *vbox;
 
+  terminal_return_if_fail (GTK_IS_UI_MANAGER (window->ui_manager));
+
   if (gtk_toggle_action_get_active (action))
-    gtk_widget_show (window->menubar);
-  else
-    gtk_widget_hide (window->menubar);
+    {
+      if (G_LIKELY (window->menubar == NULL))
+        {
+          vbox = gtk_bin_get_child (GTK_BIN (window));
+          window->menubar = gtk_ui_manager_get_widget (window->ui_manager, "/main-menu");
+          gtk_box_pack_start (GTK_BOX (vbox), window->menubar, FALSE, FALSE, 0);
+          gtk_box_reorder_child (GTK_BOX (vbox), window->menubar, 0);
+        }
 
+      gtk_widget_show (window->menubar);
+    }
+  else if (window->menubar != NULL)
+    {
+      gtk_widget_hide (window->menubar);
+    }
+
   terminal_window_set_size (window);
 }
 
@@ -1422,38 +1427,34 @@
 {
   GtkAction *action_edit;
   GtkWidget *vbox;
-  
+
   terminal_return_if_fail (GTK_IS_UI_MANAGER (window->ui_manager));
+  terminal_return_if_fail (GTK_IS_ACTION_GROUP (window->action_group));
 
-  action_edit = gtk_action_group_get_action (window->action_group,
-                                             "edit-toolbars");
-
   if (gtk_toggle_action_get_active (action))
     {
       if (window->toolbars == NULL)
         {
+          /* this is a bug in exo, fixed in revision 30359 */
+          gtk_ui_manager_ensure_update (window->ui_manager);
+
           vbox = gtk_bin_get_child (GTK_BIN (window));
-
-          window->toolbars = g_object_new (TERMINAL_TYPE_TOOLBARS_VIEW,
-                                           "ui-manager", window->ui_manager, NULL);
+          window->toolbars = g_object_new (TERMINAL_TYPE_TOOLBARS_VIEW, "ui-manager", window->ui_manager, NULL);
           gtk_box_pack_start (GTK_BOX (vbox), window->toolbars, FALSE, FALSE, 0);
-          gtk_box_reorder_child (GTK_BOX (vbox), window->toolbars, 1);
-          gtk_widget_show (window->toolbars);
-
-          g_object_add_weak_pointer (G_OBJECT (window->toolbars),
-                                     (gpointer) &window->toolbars);
+          gtk_box_reorder_child (GTK_BOX (vbox), window->toolbars, window->menubar != NULL ? 1 : 0);
         }
 
-      gtk_action_set_sensitive (action_edit, TRUE);
+      gtk_widget_show (window->toolbars);
     }
-  else
+  else if (window->toolbars != NULL)
     {
-      if (window->toolbars != NULL)
-        gtk_widget_destroy (window->toolbars);
-
-      gtk_action_set_sensitive (action_edit, FALSE);
+      gtk_widget_destroy (window->toolbars);
+      window->toolbars = NULL;
     }
 
+  action_edit = gtk_action_group_get_action (window->action_group, "edit-toolbars");
+  gtk_action_set_sensitive (action_edit, window->toolbars != NULL);
+
   terminal_window_set_size (window);
 }
 




More information about the Xfce4-commits mailing list