[gnome-terminal] Revert "window: Remove menubar visibility options"



commit e3939069bfdff3476e0eb695ff1f974c46f90a2a
Author: Christian Persch <chpe gnome org>
Date:   Sun Aug 5 22:55:51 2012 +0200

    Revert "window: Remove menubar visibility options"
    
    This reverts commit e6d02b3cca15eef864aa9df7d6a46700e3a8d238.
    
    Conflicts:
    
    	src/terminal-gdbus.c
    	src/terminal-window.c

 src/client.c                                      |    3 +
 src/migration.c                                   |    6 ++
 src/org.gnome.Terminal.Preferences.gschema.xml.in |    5 +
 src/terminal-accels.c                             |    2 +
 src/terminal-gdbus.c                              |    4 +
 src/terminal-options.c                            |   91 +++++++++++++++++++--
 src/terminal-options.h                            |    6 ++
 src/terminal-window.c                             |   71 ++++++++++++++++
 src/terminal-window.h                             |    8 ++
 src/terminal.c                                    |    3 +
 src/terminal.xml                                  |    2 +
 11 files changed, 195 insertions(+), 6 deletions(-)
---
diff --git a/src/client.c b/src/client.c
index 758dcc0..af14777 100644
--- a/src/client.c
+++ b/src/client.c
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/wait.h>
 
 #include <glib.h>
 #include <glib/gprintf.h>
@@ -168,6 +169,7 @@ typedef struct
   char       *geometry;
   char       *role;
 
+  gboolean    menubar_state;
   gboolean    start_fullscreen;
   gboolean    start_maximized;
 
@@ -188,6 +190,7 @@ typedef struct
   gboolean wait;
 
   /* Flags */
+  guint menubar_state_set : 1;
   guint zoom_set          : 1;
   guint active            : 1;
 } OptionData;
diff --git a/src/migration.c b/src/migration.c
index 1b9077e..3dd1599 100644
--- a/src/migration.c
+++ b/src/migration.c
@@ -59,6 +59,7 @@ enum {
 #define KEY_CURSOR_BLINK_MODE "cursor_blink_mode"
 #define KEY_CURSOR_SHAPE "cursor_shape"
 #define KEY_CUSTOM_COMMAND "custom_command"
+#define KEY_DEFAULT_SHOW_MENUBAR "default_show_menubar"
 #define KEY_DEFAULT_SIZE_COLUMNS "default_size_columns"
 #define KEY_DEFAULT_SIZE_ROWS "default_size_rows"
 #define KEY_DELETE_BINDING "delete_binding"
@@ -437,6 +438,10 @@ migrate_profiles (GError **error)
     settings = g_settings_new (TERMINAL_SETTING_SCHEMA);
     path = gconf_concat_dir_and_key (GCONF_PROFILES_PREFIX, default_profile);
 
+    migrate_bool (client, path, KEY_DEFAULT_SHOW_MENUBAR,
+                  settings, TERMINAL_SETTING_DEFAULT_SHOW_MENUBAR_KEY,
+                  FALSE);
+
     g_free (path);
     g_object_unref (settings);
   }
@@ -475,6 +480,7 @@ migrate_accels (GError **error)
     { "close_window", "FileCloseWindow"},
     { "copy", "EditCopy" },
     { "paste", "EditPaste" },
+    { "toggle_menubar", "ViewMenubar" },
     { "full_screen", "ViewFullscreen" },
     { "zoom_in", "ViewZoomIn" },
     { "zoom_out", "ViewZoomOut" },
diff --git a/src/org.gnome.Terminal.Preferences.gschema.xml.in b/src/org.gnome.Terminal.Preferences.gschema.xml.in
index 6d28344..6091093 100644
--- a/src/org.gnome.Terminal.Preferences.gschema.xml.in
+++ b/src/org.gnome.Terminal.Preferences.gschema.xml.in
@@ -366,6 +366,11 @@
       <_summary>Whether to ask for confirmation before closing a terminal</_summary>
     </key>
 
+    <key name="default-show-menubar" type="b">
+      <default>true</default>
+      <_summary>Whether to show the menubar in new windows</_summary>
+    </key>
+
     <!--
     <child name="profiles:" schema="org.gnome.Terminal.Profiles" >
       <child name="profile0" schema="org.gnome.Terminal.Profile">
diff --git a/src/terminal-accels.c b/src/terminal-accels.c
index 1069b69..a7420c3 100644
--- a/src/terminal-accels.c
+++ b/src/terminal-accels.c
@@ -38,6 +38,7 @@
 #define ACCEL_CLOSE_WINDOW         "FileCloseWindow"
 #define ACCEL_COPY                 "EditCopy"
 #define ACCEL_PASTE                "EditPaste"
+#define ACCEL_TOGGLE_MENUBAR       "ViewMenubar"
 #define ACCEL_FULL_SCREEN          "ViewFullscreen"
 #define ACCEL_RESET                "TerminalReset"
 #define ACCEL_RESET_AND_CLEAR      "TerminalResetClear"
@@ -100,6 +101,7 @@ static KeyEntry edit_entries[] =
 
 static KeyEntry view_entries[] =
 {
+  { N_("Hide and Show menubar"), ACCEL_TOGGLE_MENUBAR },
   { N_("Full Screen"), ACCEL_FULL_SCREEN },
   { N_("Zoom In"), ACCEL_ZOOM_IN },
   { N_("Zoom Out"), ACCEL_ZOOM_OUT },
diff --git a/src/terminal-gdbus.c b/src/terminal-gdbus.c
index f2b9f59..e039415 100644
--- a/src/terminal-gdbus.c
+++ b/src/terminal-gdbus.c
@@ -360,6 +360,7 @@ terminal_factory_impl_create_instance (TerminalFactory *factory,
   gboolean zoom_set = FALSE;
   gdouble zoom = 1.0;
   guint window_id;
+  gboolean show_menubar;
   gboolean active = TRUE;
   gboolean have_new_window, present_window, present_window_set;
 
@@ -412,6 +413,9 @@ terminal_factory_impl_create_instance (TerminalFactory *factory,
     if (g_variant_lookup (options, "role", "&s", &role))
       gtk_window_set_role (GTK_WINDOW (window), role);
 
+    if (g_variant_lookup (options, "show-menubar", "b", &show_menubar))
+      terminal_window_set_menubar_visible (window, show_menubar);
+
     if (g_variant_lookup (options, "fullscreen-window", "b", &start_fullscreen) &&
         start_fullscreen) {
       gtk_window_fullscreen (GTK_WINDOW (window));
diff --git a/src/terminal-options.c b/src/terminal-options.c
index df9835f..7a2fa52 100644
--- a/src/terminal-options.c
+++ b/src/terminal-options.c
@@ -142,6 +142,14 @@ apply_defaults (TerminalOptions *options,
   if (iw->geometry == NULL)
     iw->geometry = g_strdup (options->default_geometry);
 
+  if (options->default_window_menubar_forced)
+    {
+      iw->force_menubar_state = TRUE;
+      iw->menubar_state = options->default_window_menubar_state;
+
+      options->default_window_menubar_forced = FALSE;
+    }
+
   iw->start_fullscreen |= options->default_fullscreen;
   iw->start_maximized |= options->default_maximize;
 }
@@ -401,6 +409,70 @@ option_role_callback (const gchar *option_name,
 }
 
 static gboolean
+option_show_menubar_callback (const gchar *option_name,
+                              const gchar *value,
+                              gpointer     data,
+                              GError     **error)
+{
+  TerminalOptions *options = data;
+  InitialWindow *iw;
+
+  if (options->initial_windows)
+    {
+      iw = g_list_last (options->initial_windows)->data;
+      if (iw->force_menubar_state && iw->menubar_state == TRUE)
+        {
+          g_printerr (_("\"%s\" option given twice for the same window\n"),
+                        "--show-menubar");
+
+          return TRUE;
+        }
+
+      iw->force_menubar_state = TRUE;
+      iw->menubar_state = TRUE;
+    }
+  else
+    {
+      options->default_window_menubar_forced = TRUE;
+      options->default_window_menubar_state = TRUE;
+    }
+
+  return TRUE;
+}
+
+static gboolean
+option_hide_menubar_callback (const gchar *option_name,
+                              const gchar *value,
+                              gpointer     data,
+                              GError     **error)
+{
+  TerminalOptions *options = data;
+  InitialWindow *iw;
+
+  if (options->initial_windows)
+    {
+      iw = g_list_last (options->initial_windows)->data;
+
+      if (iw->force_menubar_state && iw->menubar_state == FALSE)
+        {
+          g_printerr (_("\"%s\" option given twice for the same window\n"),
+                        "--hide-menubar");
+          return TRUE;
+        }
+
+      iw->force_menubar_state = TRUE;
+      iw->menubar_state = FALSE;
+    }
+  else
+    {
+      options->default_window_menubar_forced = TRUE;
+      options->default_window_menubar_state = FALSE;
+    }
+
+  return TRUE;
+}
+
+static gboolean
 option_maximize_callback (const gchar *option_name,
                           const gchar *value,
                           gpointer     data,
@@ -684,6 +756,8 @@ terminal_options_parse (const char *working_directory,
   options = g_slice_new0 (TerminalOptions);
 
   options->remote_arguments = FALSE;
+  options->default_window_menubar_forced = FALSE;
+  options->default_window_menubar_state = TRUE;
   options->default_fullscreen = FALSE;
   options->default_maximize = FALSE;
   options->execute = FALSE;
@@ -813,6 +887,11 @@ terminal_options_merge_config (TerminalOptions *options,
       iw->geometry = g_key_file_get_string (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_GEOMETRY, NULL);
       iw->start_fullscreen = g_key_file_get_boolean (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_FULLSCREEN, NULL);
       iw->start_maximized = g_key_file_get_boolean (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_MAXIMIZED, NULL);
+      if (g_key_file_has_key (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_MENUBAR_VISIBLE, NULL))
+        {
+          iw->force_menubar_state = TRUE;
+          iw->menubar_state = g_key_file_get_boolean (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_MENUBAR_VISIBLE, NULL);
+        }
 
       for (j = 0; tab_groups[j]; ++j)
         {
@@ -970,19 +1049,19 @@ get_goption_context (TerminalOptions *options)
     {
       "show-menubar",
       0,
-      G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN,
+      G_OPTION_FLAG_NO_ARG,
       G_OPTION_ARG_CALLBACK,
-      unsupported_option_callback,
-      NULL,
+      option_show_menubar_callback,
+      N_("Turn on the menubar"),
       NULL
     },
     {
       "hide-menubar",
       0,
-      G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN,
+      G_OPTION_FLAG_NO_ARG,
       G_OPTION_ARG_CALLBACK,
-      unsupported_option_callback,
-      NULL,
+      option_hide_menubar_callback,
+      N_("Turn off the menubar"),
       NULL
     },
     {
diff --git a/src/terminal-options.h b/src/terminal-options.h
index a4964dc..679c513 100644
--- a/src/terminal-options.h
+++ b/src/terminal-options.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
 #define TERMINAL_CONFIG_WINDOW_PROP_FULLSCREEN       "Fullscreen"
 #define TERMINAL_CONFIG_WINDOW_PROP_GEOMETRY         "Geometry"
 #define TERMINAL_CONFIG_WINDOW_PROP_MAXIMIZED        "Maximized"
+#define TERMINAL_CONFIG_WINDOW_PROP_MENUBAR_VISIBLE  "MenubarVisible"
 #define TERMINAL_CONFIG_WINDOW_PROP_ROLE             "Role"
 #define TERMINAL_CONFIG_WINDOW_PROP_TABS             "Terminals"
 
@@ -63,6 +64,8 @@ typedef struct
   char    *display_name;
   int      screen_number;
   GList   *initial_windows;
+  gboolean default_window_menubar_forced;
+  gboolean default_window_menubar_state;
   gboolean default_fullscreen;
   gboolean default_maximize;
   char    *default_role;
@@ -102,6 +105,9 @@ typedef struct
 
   GList *tabs; /* list of InitialTab */
 
+  gboolean force_menubar_state;
+  gboolean menubar_state;
+
   gboolean start_fullscreen;
   gboolean start_maximized;
 
diff --git a/src/terminal-window.c b/src/terminal-window.c
index bd7c615..97135f4 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -72,6 +72,9 @@ struct _TerminalWindowPrivate
   GtkWidget *confirm_close_dialog;
   GtkWidget *search_find_dialog;
 
+  guint menubar_visible : 1;
+  guint use_default_menubar_visibility : 1;
+
   /* Used to clear stray "demands attention" flashing on our window when we
    * unmap and map it to switch to an ARGB visual.
    */
@@ -171,6 +174,8 @@ static void edit_profiles_callback            (GtkAction *action,
 #endif
 static void edit_current_profile_callback     (GtkAction *action,
                                                TerminalWindow *window);
+static void view_menubar_toggled_callback     (GtkToggleAction *action,
+                                               TerminalWindow *window);
 static void view_fullscreen_toggled_callback  (GtkToggleAction *action,
                                                TerminalWindow *window);
 static void view_zoom_in_callback             (GtkAction *action,
@@ -1807,6 +1812,10 @@ terminal_window_init (TerminalWindow *window)
   const GtkToggleActionEntry toggle_menu_entries[] =
     {
       /* View Menu */
+      { "ViewMenubar", NULL, N_("Show _Menubar"), NULL,
+        NULL,
+        G_CALLBACK (view_menubar_toggled_callback),
+        FALSE },
       { "ViewFullscreen", NULL, N_("_Full Screen"), NULL,
         NULL,
         G_CALLBACK (view_fullscreen_toggled_callback),
@@ -1842,6 +1851,7 @@ terminal_window_init (TerminalWindow *window)
 #endif
 
   priv->active_screen = NULL;
+  priv->menubar_visible = FALSE;
 
   main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (window), main_vbox);
@@ -1942,6 +1952,9 @@ terminal_window_init (TerminalWindow *window)
   g_signal_connect (app, "encoding-list-changed",
                     G_CALLBACK (terminal_window_encoding_list_changed_cb), window);
 
+  terminal_window_set_menubar_visible (window, TRUE);
+  priv->use_default_menubar_visibility = TRUE;
+
   terminal_window_update_size_to_menu (window);
 
   /* We have to explicitly call this, since screen-changed is NOT
@@ -2270,6 +2283,47 @@ terminal_window_list_screen_containers (TerminalWindow *window)
   return terminal_mdi_container_list_screen_containers (priv->mdi_container);
 }
 
+void
+terminal_window_set_menubar_visible (TerminalWindow *window,
+                                     gboolean        setting)
+{
+  TerminalWindowPrivate *priv = window->priv;
+  GtkAction *action;
+
+  /* it's been set now, so don't override when adding a screen.
+   * this side effect must happen before we short-circuit below.
+   */
+  priv->use_default_menubar_visibility = FALSE;
+  
+  if (setting == priv->menubar_visible)
+    return;
+
+  priv->menubar_visible = setting;
+
+  action = gtk_action_group_get_action (priv->action_group, "ViewMenubar");
+  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), setting);
+  
+  g_object_set (priv->menubar, "visible", setting, NULL);
+
+  /* FIXMEchpe: use gtk_widget_get_realized instead? */
+  if (priv->active_screen)
+    {
+      _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY,
+                             "[window %p] setting size after toggling menubar visibility\n",
+                             window);
+
+      terminal_window_set_size (window, priv->active_screen);
+    }
+}
+
+gboolean
+terminal_window_get_menubar_visible (TerminalWindow *window)
+{
+  TerminalWindowPrivate *priv = window->priv;
+  
+  return priv->menubar_visible;
+}
+
 GtkWidget *
 terminal_window_get_mdi_container (TerminalWindow *window)
 {
@@ -2423,6 +2477,16 @@ mdi_screen_switched_cb (TerminalMdiContainer *container,
 
   priv->active_screen = screen;
 
+  /* Override menubar setting if it wasn't restored from session */
+  if (priv->use_default_menubar_visibility)
+    {
+      gboolean setting =
+        g_settings_get_boolean (terminal_app_get_global_settings (terminal_app_get ()),
+                                TERMINAL_SETTING_DEFAULT_SHOW_MENUBAR_KEY);
+
+      terminal_window_set_menubar_visible (window, setting);
+    }
+
   sync_screen_icon_title_set (screen, NULL, window);
   sync_screen_icon_title (screen, NULL, window);
   sync_screen_title (screen, NULL, window);
@@ -3112,6 +3176,13 @@ edit_profiles_callback (GtkAction *action,
 #endif
 
 static void
+view_menubar_toggled_callback (GtkToggleAction *action,
+                               TerminalWindow *window)
+{
+  terminal_window_set_menubar_visible (window, gtk_toggle_action_get_active (action));
+}
+
+static void
 view_fullscreen_toggled_callback (GtkToggleAction *action,
                                   TerminalWindow *window)
 {
diff --git a/src/terminal-window.h b/src/terminal-window.h
index f64b863..f734ef9 100644
--- a/src/terminal-window.h
+++ b/src/terminal-window.h
@@ -68,6 +68,14 @@ void terminal_window_move_screen (TerminalWindow *source_window,
                                   TerminalScreen *screen,
                                   int dest_position);
 
+/* Menubar visibility is part of session state, except that
+ * if it isn't restored from session, the window gets the setting
+ * from the profile of the first screen added to the window
+ */
+void terminal_window_set_menubar_visible     (TerminalWindow *window,
+                                              gboolean        setting);
+gboolean terminal_window_get_menubar_visible (TerminalWindow *window);
+
 void            terminal_window_switch_screen (TerminalWindow *window,
                                                TerminalScreen *screen);
 TerminalScreen* terminal_window_get_active (TerminalWindow *window);
diff --git a/src/terminal.c b/src/terminal.c
index 7075d15..036104e 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -116,6 +116,9 @@ handle_options (TerminalFactory *factory,
           if (options->zoom_set || it->zoom_set)
             g_variant_builder_add (&builder, "{sv}",
                                    "zoom", g_variant_new_double (it->zoom_set ? it->zoom : options->zoom));
+          if (iw->force_menubar_state)
+            g_variant_builder_add (&builder, "{sv}",
+                                   "show-menubar", g_variant_new_boolean (iw->menubar_state));
 #if 0
           if (it->active)
             terminal_window_switch_screen (window, screen);
diff --git a/src/terminal.xml b/src/terminal.xml
index d9da26e..0888ea7 100644
--- a/src/terminal.xml
+++ b/src/terminal.xml
@@ -24,6 +24,7 @@
       <menuitem action="EditCurrentProfile" />
     </menu>
     <menu action="View">
+      <menuitem action="ViewMenubar" />
       <menuitem action="ViewFullscreen" />
       <separator />
       <menuitem action="ViewZoomIn" />
@@ -99,6 +100,7 @@
         <separator />
         <menuitem action="EditCurrentProfile" />
     </menu>
+    <menuitem action="ViewMenubar" />
     <menuitem action="PopupLeaveFullscreen" />
     <separator />
     <menuitem action="PopupInputMethods" />



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