[nautilus] navigation-window: integrate the back/forward actions with the state



commit de4b00057e06fdc675d640c65c9a459f9fdb2725
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Feb 16 11:30:40 2011 -0500

    navigation-window: integrate the back/forward actions with the state
    
    So that the current back.forward state propagates to menus.

 src/nautilus-navigation-window-menus.c |   68 +++++++++++++++++++++++++++++++-
 src/nautilus-navigation-window-pane.c  |   10 ++++-
 src/nautilus-navigation-window-pane.h  |    3 +-
 src/nautilus-navigation-window.c       |   19 ++++-----
 src/nautilus-window-private.h          |    3 +
 5 files changed, 88 insertions(+), 15 deletions(-)
---
diff --git a/src/nautilus-navigation-window-menus.c b/src/nautilus-navigation-window-menus.c
index 20e5f98..d440c8c 100644
--- a/src/nautilus-navigation-window-menus.c
+++ b/src/nautilus-navigation-window-menus.c
@@ -684,6 +684,64 @@ static const GtkRadioActionEntry navigation_radio_entries[] = {
 	  SIDEBAR_TREE }
 };
 
+GtkActionGroup *
+nautilus_navigation_window_create_toolbar_action_group (NautilusNavigationWindow *window)
+{
+	GtkActionGroup *action_group;
+	GtkAction *action;
+
+	action_group = gtk_action_group_new ("ToolbarActions");
+	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
+
+	action = g_object_new (NAUTILUS_TYPE_NAVIGATION_ACTION,
+			       "name", NAUTILUS_ACTION_BACK,
+			       "label", _("_Back"),
+			       "stock_id", GTK_STOCK_GO_BACK,
+			       "tooltip", _("Go to the previous visited location"),
+			       "arrow-tooltip", _("Back history"),
+			       "window", window,
+			       "direction", NAUTILUS_NAVIGATION_DIRECTION_BACK,
+			       NULL);
+	g_signal_connect (action, "activate",
+			  G_CALLBACK (action_back_callback), window);
+	gtk_action_group_add_action (action_group, action);
+
+	g_object_unref (action);
+
+	action = g_object_new (NAUTILUS_TYPE_NAVIGATION_ACTION,
+			       "name", NAUTILUS_ACTION_FORWARD,
+			       "label", _("_Forward"),
+			       "stock_id", GTK_STOCK_GO_FORWARD,
+			       "tooltip", _("Go to the next visited location"),
+			       "arrow-tooltip", _("Forward history"),
+			       "window", window,
+			       "direction", NAUTILUS_NAVIGATION_DIRECTION_FORWARD,
+			       NULL);
+	g_signal_connect (action, "activate",
+			  G_CALLBACK (action_forward_callback), window);
+	gtk_action_group_add_action (action_group, action);
+
+	g_object_unref (action);
+
+	action = GTK_ACTION
+		(gtk_toggle_action_new ("Search",
+					_("Search"),
+					_("Search documents and folders by name"),
+					NULL));
+	g_signal_connect (action, "activate",
+			  G_CALLBACK (action_show_hide_search_callback), window);
+	gtk_action_group_add_action (action_group, action);
+	gtk_action_set_icon_name (GTK_ACTION (action), "edit-find-symbolic");
+	gtk_action_set_is_important (GTK_ACTION (action), TRUE);
+
+	g_object_unref (action);
+
+	nautilus_navigation_state_add_group (window->details->nav_state,
+					     action_group);
+
+	return action_group;
+}
+
 void 
 nautilus_navigation_window_initialize_actions (NautilusNavigationWindow *window)
 {
@@ -692,6 +750,9 @@ nautilus_navigation_window_initialize_actions (NautilusNavigationWindow *window)
 	GtkAction *action;
 	int i;
 	const char *ui;
+	const gchar *nav_state_actions[] = {
+		NAUTILUS_ACTION_BACK, NAUTILUS_ACTION_FORWARD, NULL
+	};
 
 	ui_manager = nautilus_window_get_ui_manager (NAUTILUS_WINDOW (window));
 
@@ -714,7 +775,7 @@ nautilus_navigation_window_initialize_actions (NautilusNavigationWindow *window)
 					    window);
 
 	action = g_object_new (NAUTILUS_TYPE_NAVIGATION_ACTION,
-			       "name", "Back",
+			       "name", NAUTILUS_ACTION_BACK,
 			       "label", _("_Back"),
 			       "stock_id", GTK_STOCK_GO_BACK,
 			       "tooltip", _("Go to the previous visited location"),
@@ -730,7 +791,7 @@ nautilus_navigation_window_initialize_actions (NautilusNavigationWindow *window)
 	g_object_unref (action);
 
 	action = g_object_new (NAUTILUS_TYPE_NAVIGATION_ACTION,
-			       "name", "Forward",
+			       "name", NAUTILUS_ACTION_FORWARD,
 			       "label", _("_Forward"),
 			       "stock_id", GTK_STOCK_GO_FORWARD,
 			       "tooltip", _("Go to the next visited location"),
@@ -798,6 +859,9 @@ nautilus_navigation_window_initialize_actions (NautilusNavigationWindow *window)
 	action = gtk_action_group_get_action (action_group, "ShowSearch");
 	gtk_action_set_sensitive (action, TRUE);
 
+	window->details->nav_state = nautilus_navigation_state_new (action_group,
+								    nav_state_actions);
+
 	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
 	g_object_unref (action_group); /* owned by ui_manager */
 
diff --git a/src/nautilus-navigation-window-pane.c b/src/nautilus-navigation-window-pane.c
index 2e8ca5c..0cf5973 100644
--- a/src/nautilus-navigation-window-pane.c
+++ b/src/nautilus-navigation-window-pane.c
@@ -615,6 +615,7 @@ nautilus_navigation_window_pane_setup (NautilusNavigationWindowPane *pane)
 	NautilusEntry *entry;
 	GtkSizeGroup *header_size_group;
 	NautilusNavigationWindow *window;
+	GtkActionGroup *action_group;
 
 	pane->widget = gtk_vbox_new (FALSE, 0);
 	window = NAUTILUS_NAVIGATION_WINDOW (NAUTILUS_WINDOW_PANE (pane)->window);
@@ -622,7 +623,10 @@ nautilus_navigation_window_pane_setup (NautilusNavigationWindowPane *pane)
 	header_size_group = window->details->header_size_group;
 
 	/* build the toolbar */
-	pane->tool_bar = nautilus_toolbar_new (window->details->navigation_action_group);
+	action_group = nautilus_navigation_window_create_toolbar_action_group (window);
+	pane->tool_bar = nautilus_toolbar_new (action_group);
+	pane->action_group = action_group;
+
 	gtk_box_pack_start (GTK_BOX (pane->widget),
 			    pane->tool_bar,
 			    FALSE, FALSE, 0);
@@ -697,6 +701,9 @@ nautilus_navigation_window_pane_setup (NautilusNavigationWindowPane *pane)
 	gtk_widget_show (pane->notebook);
 	gtk_container_set_border_width (GTK_CONTAINER (pane->notebook), 0);
 
+	/* start as non-active */
+	real_set_active (NAUTILUS_WINDOW_PANE (pane), FALSE);
+
 	/* Ensure that the view has some minimal size and that other parts
 	 * of the UI (like location bar and tabs) don't request more and
 	 * thus affect the default position of the split view paned.
@@ -795,6 +802,7 @@ nautilus_navigation_window_pane_dispose (GObject *object)
 	NautilusNavigationWindowPane *pane = NAUTILUS_NAVIGATION_WINDOW_PANE (object);
 
 	gtk_widget_destroy (pane->widget);
+	g_clear_object (&pane->action_group);
 
 	G_OBJECT_CLASS (nautilus_navigation_window_pane_parent_class)->dispose (object);
 }
diff --git a/src/nautilus-navigation-window-pane.h b/src/nautilus-navigation-window-pane.h
index f56132f..952b4d7 100644
--- a/src/nautilus-navigation-window-pane.h
+++ b/src/nautilus-navigation-window-pane.h
@@ -61,8 +61,7 @@ struct _NautilusNavigationWindowPane {
 	/* notebook */
 	GtkWidget *notebook;
 
-	/* split view */
-	GtkWidget *split_view_hpane;
+	GtkActionGroup *action_group;
 };
 
 #include "nautilus-toolbar.h"
diff --git a/src/nautilus-navigation-window.c b/src/nautilus-navigation-window.c
index 9d5b3c6..906871e 100644
--- a/src/nautilus-navigation-window.c
+++ b/src/nautilus-navigation-window.c
@@ -308,6 +308,7 @@ nautilus_navigation_window_finalize (GObject *object)
 	window = NAUTILUS_NAVIGATION_WINDOW (object);
 
 	g_free (window->details->sidebar_id);
+	g_clear_object (&window->details->nav_state);
 
 	g_signal_handlers_disconnect_by_func (nautilus_preferences,
 					      always_use_browser_changed,
@@ -337,9 +338,9 @@ nautilus_navigation_window_allow_back (NautilusNavigationWindow *window, gboolea
 {
 	GtkAction *action;
 
-	action = gtk_action_group_get_action (window->details->navigation_action_group,
+	action = gtk_action_group_get_action (nautilus_navigation_state_get_master (window->details->nav_state),
 					      NAUTILUS_ACTION_BACK);
-	
+
 	gtk_action_set_sensitive (action, allow);
 }
 
@@ -348,9 +349,9 @@ nautilus_navigation_window_allow_forward (NautilusNavigationWindow *window, gboo
 {
 	GtkAction *action;
 
-	action = gtk_action_group_get_action (window->details->navigation_action_group,
+	action = gtk_action_group_get_action (nautilus_navigation_state_get_master (window->details->nav_state),
 					      NAUTILUS_ACTION_FORWARD);
-	
+
 	gtk_action_set_sensitive (action, allow);
 }
 
@@ -803,12 +804,6 @@ nautilus_navigation_window_init (NautilusNavigationWindow *window)
 
 	nautilus_navigation_window_initialize_menus (window);
 
-	/* Set initial sensitivity of some buttons & menu items
-	 * now that they're all created.
-	 */
-	nautilus_navigation_window_allow_back (window, FALSE);
-	nautilus_navigation_window_allow_forward (window, FALSE);
-
 	g_signal_connect_swapped (nautilus_preferences,
 				  "changed::" NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER,
 				  G_CALLBACK(always_use_browser_changed),
@@ -965,6 +960,10 @@ nautilus_navigation_window_split_view_off (NautilusNavigationWindow *window)
 		}
 	}
 
+	nautilus_window_set_active_pane (win, active_pane);
+	nautilus_navigation_state_set_master (window->details->nav_state,
+					      NAUTILUS_NAVIGATION_WINDOW_PANE (active_pane)->action_group);
+
 	nautilus_navigation_window_update_show_hide_menu_items (window);
 	nautilus_navigation_window_update_split_view_actions_sensitivity (window);
 
diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h
index 2082ff1..dc2db4c 100644
--- a/src/nautilus-window-private.h
+++ b/src/nautilus-window-private.h
@@ -32,6 +32,7 @@
 #include "nautilus-window-slot.h"
 #include "nautilus-window-pane.h"
 #include "nautilus-spatial-window.h"
+#include "nautilus-navigation-state.h"
 #include "nautilus-navigation-window.h"
 #include "nautilus-bookmark-list.h"
 
@@ -95,6 +96,7 @@ struct _NautilusNavigationWindowDetails {
         GtkWidget *content_paned;
         GtkWidget *content_box;
         GtkActionGroup *navigation_action_group; /* owned by ui_manager */
+        NautilusNavigationState *nav_state;
 
         GtkSizeGroup *header_size_group;
         
@@ -213,6 +215,7 @@ void nautilus_window_sync_title            (NautilusWindow *window,
 void nautilus_window_sync_zoom_widgets     (NautilusWindow *window);
 
 /* Navigation window menus */
+GtkActionGroup *nautilus_navigation_window_create_toolbar_action_group (NautilusNavigationWindow *window);
 void               nautilus_navigation_window_initialize_actions                    (NautilusNavigationWindow    *window);
 void               nautilus_navigation_window_initialize_menus                      (NautilusNavigationWindow    *window);
 void               nautilus_navigation_window_remove_bookmarks_menu_callback        (NautilusNavigationWindow    *window);



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