[gedit] Move FileClose to separate action group to manage it on OS X



commit c8c988f858bfc54727287de525e53f567c5873fe
Author: Jesse van den Kieboom <jesse icecrew nl>
Date:   Sun Nov 15 13:50:44 2009 +0100

    Move FileClose to separate action group to manage it on OS X
    
    On OS X, File Close should be sensitive even if there are no tabs since
    it will then close the window (but not the app) OS X style

 gedit/gedit-ui.h             |    9 +++++-
 gedit/gedit-window-private.h |    1 +
 gedit/gedit-window.c         |   54 ++++++++++++++++++++++++++---------------
 3 files changed, 42 insertions(+), 22 deletions(-)
---
diff --git a/gedit/gedit-ui.h b/gedit/gedit-ui.h
index e1ef73c..d84288b 100644
--- a/gedit/gedit-ui.h
+++ b/gedit/gedit-ui.h
@@ -91,8 +91,6 @@ static const GtkActionEntry gedit_menu_entries[] =
 	  N_("Print preview"), G_CALLBACK (_gedit_cmd_file_print_preview) },
 	 { "FilePrint", GTK_STOCK_PRINT, N_("_Print..."), "<control>P",
 	  N_("Print the current page"), G_CALLBACK (_gedit_cmd_file_print) },
-	{ "FileClose", GTK_STOCK_CLOSE, NULL, "<control>W",
-	  N_("Close the current file"), G_CALLBACK (_gedit_cmd_file_close) },
 
 	/* Edit menu */
 	{ "EditUndo", GTK_STOCK_UNDO, NULL, "<control>Z",
@@ -147,6 +145,13 @@ static const GtkActionEntry gedit_menu_entries[] =
 	  N_("Move the current document to a new window"), G_CALLBACK (_gedit_cmd_documents_move_to_new_window) }
 };
 
+/* separate group, needs to be sensitive on OS X even when there are no tabs */
+static const GtkActionEntry gedit_close_menu_entries[] =
+{
+	{ "FileClose", GTK_STOCK_CLOSE, NULL, "<control>W",
+	  N_("Close the current file"), G_CALLBACK (_gedit_cmd_file_close) }
+};
+
 /* separate group, should be sensitive even when there are no tabs */
 static const GtkActionEntry gedit_quit_menu_entries[] =
 {
diff --git a/gedit/gedit-window-private.h b/gedit/gedit-window-private.h
index a364874..3b1b9cf 100644
--- a/gedit/gedit-window-private.h
+++ b/gedit/gedit-window-private.h
@@ -71,6 +71,7 @@ struct _GeditWindowPrivate
 	GtkUIManager   *manager;
 	GtkActionGroup *action_group;
 	GtkActionGroup *always_sensitive_action_group;
+	GtkActionGroup *close_action_group;
 	GtkActionGroup *quit_action_group;
 	GtkActionGroup *panes_action_group;
 	GtkActionGroup *languages_action_group;
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 8fb0202..976061a 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -722,7 +722,7 @@ set_sensitivity_according_to_tab (GeditWindow *window,
 				  (state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW)) &&
 				  !(lockdown & GEDIT_LOCKDOWN_PRINTING));
 				  
-	action = gtk_action_group_get_action (window->priv->action_group,
+	action = gtk_action_group_get_action (window->priv->close_action_group,
 					      "FileClose");
 
 	gtk_action_set_sensitive (action,
@@ -1476,6 +1476,17 @@ create_menu_bar_and_toolbar (GeditWindow *window,
 	g_object_unref (action_group);
 	window->priv->quit_action_group = action_group;
 
+	action_group = gtk_action_group_new ("GeditCloseWindowActions");
+	gtk_action_group_set_translation_domain (action_group, NULL);
+	gtk_action_group_add_actions (action_group,
+	                              gedit_close_menu_entries,
+	                              G_N_ELEMENTS (gedit_close_menu_entries),
+	                              window);
+
+	gtk_ui_manager_insert_action_group (manager, action_group, 0);
+	g_object_unref (action_group);
+	window->priv->close_action_group = action_group;
+
 	action_group = gtk_action_group_new ("GeditWindowPanesActions");
 	gtk_action_group_set_translation_domain (action_group, NULL);
 	gtk_action_group_add_toggle_actions (action_group,
@@ -2515,6 +2526,9 @@ set_sensitivity_according_to_window_state (GeditWindow *window)
 		if (gtk_action_group_get_sensitive (window->priv->quit_action_group))
 			gtk_action_group_set_sensitive (window->priv->quit_action_group,
 							FALSE);
+		if (gtk_action_group_get_sensitive (window->priv->close_action_group))
+			gtk_action_group_set_sensitive (window->priv->close_action_group,
+							FALSE);
 	}
 	else
 	{
@@ -2524,6 +2538,17 @@ set_sensitivity_according_to_window_state (GeditWindow *window)
 		if (!gtk_action_group_get_sensitive (window->priv->quit_action_group))
 			gtk_action_group_set_sensitive (window->priv->quit_action_group,
 							window->priv->num_tabs > 0);
+		if (!gtk_action_group_get_sensitive (window->priv->close_action_group))
+		{
+#ifdef OS_OSX
+			/* On OS X, File Close is always sensitive */
+			gtk_action_group_set_sensitive (window->priv->close_action_group,
+							TRUE);
+#else
+			gtk_action_group_set_sensitive (window->priv->close_action_group,
+							window->priv->num_tabs > 0);
+#endif
+		}
 	}
 }
 
@@ -3124,7 +3149,7 @@ editable_changed (GeditView  *view,
 }
 
 static void
-update_sensitivity_according_to_tabs (GeditWindow *window)
+update_sensitivity_according_to_open_tabs (GeditWindow *window)
 {
 	GtkAction *action;
 
@@ -3137,22 +3162,11 @@ update_sensitivity_according_to_tabs (GeditWindow *window)
 	gtk_action_set_sensitive (action,
 				  window->priv->num_tabs > 1);
 
-	/* Set sensitivity */
-	if (window->priv->num_tabs == 0)
-	{
-		action = gtk_action_group_get_action (window->priv->action_group,
-						      "ViewHighlightMode");
-		gtk_action_set_sensitive (action, FALSE);
-
-#ifdef OS_OSX
-		/* On OS X we keep the Close action sensitive when there are
-		   no tabs because when there are no active documents it
-		   closes the window (OS X style) */
-		action = gtk_action_group_get_action (window->priv->action_group,
-		                                      "FileClose");
-		gtk_action_set_sensitive (action, TRUE);
+	/* Do not set close action insensitive on OS X */
+#ifndef OS_OSX
+	gtk_action_group_set_sensitive (window->priv->close_action_group,
+	                                window->priv->num_tabs != 0);
 #endif
-	}
 }
 
 static void
@@ -3169,7 +3183,7 @@ notebook_tab_added (GeditNotebook *notebook,
 	
 	++window->priv->num_tabs;
 
-	update_sensitivity_according_to_tabs (window);
+	update_sensitivity_according_to_open_tabs (window);
 
 	view = gedit_tab_get_view (tab);
 	doc = gedit_tab_get_document (tab);
@@ -3335,7 +3349,7 @@ notebook_tab_removed (GeditNotebook *notebook,
 		}
 	}
 
-	update_sensitivity_according_to_tabs (window);
+	update_sensitivity_according_to_open_tabs (window);
 
 	if (window->priv->num_tabs == 0)
 	{
@@ -3931,7 +3945,7 @@ gedit_window_init (GeditWindow *window)
 	 * This needs to be done after plugins activatation */
 	init_panels_visibility (window);
 
-	update_sensitivity_according_to_tabs (window);
+	update_sensitivity_according_to_open_tabs (window);
 
 	gedit_debug_message (DEBUG_WINDOW, "END");
 }



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