[PATCH] Only show "Close Parent Windows" if we're not displaying a toplevel URI



>From http://bugzilla.gnome.org/show_bug.cgi?id=149287:


Proposed patch (against HEAD).

- adds nautilus_file_has_parent
- adds nautilus_window_(info_)update_menus, which is called when updating the
menus and implemented by all subclasses of NautilusWindow

-- 
Christian Neumair <chris gnome-de org>
? depcomp
? gmon.out
? nautilus-folder-handler.desktop
? stamp-h1
? src/.nautilus-spatial-window.c.swp
? src/gmon.out
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.364
diff -u -r1.364 nautilus-file.c
--- libnautilus-private/nautilus-file.c	4 Apr 2005 20:55:59 -0000	1.364
+++ libnautilus-private/nautilus-file.c	12 May 2005 11:56:28 -0000
@@ -616,6 +616,18 @@
 	return nautilus_directory_get_corresponding_file (file->details->directory);
 }
 
+gboolean
+nautilus_file_has_parent (NautilusFile *file)
+{
+	g_assert (NAUTILUS_IS_FILE (file));
+
+	if (nautilus_file_is_self_owned (file)) {
+		return FALSE;
+	}
+
+	return file->details->directory != NULL;
+}
+
 struct NautilusUserInfo {
 	uid_t user_id;
 	
Index: libnautilus-private/nautilus-file.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.h,v
retrieving revision 1.105
diff -u -r1.105 nautilus-file.h
--- libnautilus-private/nautilus-file.h	11 Oct 2004 12:55:13 -0000	1.105
+++ libnautilus-private/nautilus-file.h	12 May 2005 11:56:28 -0000
@@ -135,6 +135,7 @@
 NautilusFile *          nautilus_file_get_parent                        (NautilusFile                   *file);
 char *                  nautilus_file_get_parent_uri                    (NautilusFile                   *file);
 char *                  nautilus_file_get_parent_uri_for_display        (NautilusFile                   *file);
+gboolean                nautilus_file_has_parent                        (NautilusFile                   *file);
 GnomeVFSFileSize        nautilus_file_get_size                          (NautilusFile                   *file);
 GnomeVFSFileType        nautilus_file_get_file_type                     (NautilusFile                   *file);
 char *                  nautilus_file_get_guessed_mime_type             (NautilusFile                   *file);
Index: libnautilus-private/nautilus-window-info.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-window-info.c,v
retrieving revision 1.3
diff -u -r1.3 nautilus-window-info.c
--- libnautilus-private/nautilus-window-info.c	22 Mar 2005 09:22:22 -0000	1.3
+++ libnautilus-private/nautilus-window-info.c	12 May 2005 11:56:28 -0000
@@ -267,3 +267,11 @@
 	return (* NAUTILUS_WINDOW_INFO_GET_IFACE (window)->get_ui_manager) (window);
 }
 
+void
+nautilus_window_info_update_menus (NautilusWindowInfo *window)
+{
+	g_return_if_fail (NAUTILUS_IS_WINDOW_INFO (window));
+
+	return (* NAUTILUS_WINDOW_INFO_GET_IFACE (window)->update_menus) (window);
+}
+
Index: libnautilus-private/nautilus-window-info.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-window-info.h,v
retrieving revision 1.3
diff -u -r1.3 nautilus-window-info.h
--- libnautilus-private/nautilus-window-info.h	22 Mar 2005 09:22:22 -0000	1.3
+++ libnautilus-private/nautilus-window-info.h	12 May 2005 11:56:28 -0000
@@ -130,6 +130,8 @@
 	void   (* show_window)        (NautilusWindowInfo *window);
 	void   (* close_window)       (NautilusWindowInfo *window);
 	GtkUIManager *     (* get_ui_manager)   (NautilusWindowInfo *window);
+	/* Update menus for the currently displayed location. */
+	void   (* update_menus)       (NautilusWindowInfo *window);
 };
 
 GType                             nautilus_window_info_get_type                 (void);
@@ -159,7 +161,7 @@
 void                              nautilus_window_info_set_hidden_files_mode    (NautilusWindowInfo                *window,
 										 NautilusWindowShowHiddenFilesMode  mode);
 GtkUIManager *                    nautilus_window_info_get_ui_manager           (NautilusWindowInfo                *window);
-
+void                              nautilus_window_info_update_menus             (NautilusWindowInfo                *window);
 
 G_END_DECLS
 
Index: src/nautilus-navigation-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-navigation-window.c,v
retrieving revision 1.430
diff -u -r1.430 nautilus-navigation-window.c
--- src/nautilus-navigation-window.c	19 Apr 2005 12:01:16 -0000	1.430
+++ src/nautilus-navigation-window.c	12 May 2005 11:56:29 -0000
@@ -1087,6 +1087,11 @@
 }
 
 static void
+real_window_update_menus (NautilusWindow *window)
+{
+}
+
+static void
 nautilus_navigation_window_class_init (NautilusNavigationWindowClass *class)
 {
 	NAUTILUS_WINDOW_CLASS (class)->window_type = NAUTILUS_WINDOW_NAVIGATION;
@@ -1102,4 +1107,5 @@
 	NAUTILUS_WINDOW_CLASS (class)->set_title = real_set_title;
 	NAUTILUS_WINDOW_CLASS(class)->get_default_size = real_get_default_size;
 	NAUTILUS_WINDOW_CLASS (class)->close = real_window_close;
+	NAUTILUS_WINDOW_CLASS (class)->update_menus = real_window_update_menus;
 }
Index: src/nautilus-spatial-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window.c,v
retrieving revision 1.439
diff -u -r1.439 nautilus-spatial-window.c
--- src/nautilus-spatial-window.c	17 Apr 2005 16:55:23 -0000	1.439
+++ src/nautilus-spatial-window.c	12 May 2005 11:56:29 -0000
@@ -81,6 +81,11 @@
 
 #define MAX_TITLE_LENGTH 180
 
+#define SPATIAL_ACTION_PLACES               "Places"
+#define SPATIAL_ACTION_GO_TO_LOCATION       "Go to Location"
+#define SPATIAL_ACTION_CLOSE_PARENT_FOLDERS "Close Parent Folders"
+#define SPATIAL_ACTION_CLOSE_ALL_FOLDERS    "Close All Folders"
+
 struct _NautilusSpatialWindowDetails {
         GtkActionGroup *spatial_action_group; /* owned by ui_manager */
 	char *last_geometry;	
@@ -660,19 +665,35 @@
 }			   
 
 static GtkActionEntry spatial_entries[] = {
-  { "Places", NULL, N_("_Places") },               /* name, stock id, label */
-  { "Go to Location", NULL, N_("Open _Location..."), /* name, stock id, label */
+  { SPATIAL_ACTION_PLACES, NULL, N_("_Places") },               /* name, stock id, label */
+  { SPATIAL_ACTION_GO_TO_LOCATION, NULL, N_("Open _Location..."), /* name, stock id, label */
     "<control>L", N_("Specify a location to open"),
     G_CALLBACK (action_go_to_location_callback) },
-  { "Close Parent Folders", NULL, N_("Close P_arent Folders"), /* name, stock id, label */
+  { SPATIAL_ACTION_CLOSE_PARENT_FOLDERS, NULL, N_("Close P_arent Folders"), /* name, stock id, label */
     "<control><shift>W", N_("Close this folder's parents"),
     G_CALLBACK (action_close_parent_folders_callback) },
-  { "Close All Folders", NULL, N_("Clos_e All Folders"), /* name, stock id, label */
+  { SPATIAL_ACTION_CLOSE_ALL_FOLDERS, NULL, N_("Clos_e All Folders"), /* name, stock id, label */
     "<control>Q", N_("Close all folder windows"),
     G_CALLBACK (action_close_all_folders_callback) },
 };
 
 static void
+real_update_menus (NautilusWindow *window)
+{
+	GtkAction *action;
+
+	gboolean has_parent =
+		(window->details->viewed_file != NULL) &&
+		nautilus_file_has_parent (window->details->viewed_file);
+
+	action = gtk_action_group_get_action (NAUTILUS_SPATIAL_WINDOW (window)->details->spatial_action_group,
+					      SPATIAL_ACTION_CLOSE_PARENT_FOLDERS);
+	gtk_action_set_sensitive (action, has_parent);
+
+	g_warning ("sens: %d", has_parent);
+}
+
+static void
 nautilus_spatial_window_instance_init (NautilusSpatialWindow *window)
 {
 	GtkRcStyle *rc_style;
@@ -793,6 +814,8 @@
 	NAUTILUS_WINDOW_CLASS(class)->set_throbber_active =
 		real_set_throbber_active;
 
+	NAUTILUS_WINDOW_CLASS (class)->update_menus = 
+		real_update_menus;
 
 	binding_set = gtk_binding_set_by_class (class);
 	gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
Index: src/nautilus-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.c,v
retrieving revision 1.445
diff -u -r1.445 nautilus-window.c
--- src/nautilus-window.c	19 Apr 2005 12:01:16 -0000	1.445
+++ src/nautilus-window.c	12 May 2005 11:56:30 -0000
@@ -1167,12 +1167,20 @@
 	nautilus_window_ui_update (window);
 }
 
+static void
+nautilus_window_update_menus (NautilusWindow *window)
+{
+	g_assert (NAUTILUS_IS_WINDOW (window));
+
+	EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window,
+			 update_menus, (window));
+}
+
 GtkUIManager *
 nautilus_window_get_ui_manager (NautilusWindow *window)
 {
 	return window->details->ui_manager;
 }
-
 void
 nautilus_window_set_viewed_file (NautilusWindow *window,
 				 NautilusFile *file)
@@ -1427,6 +1435,7 @@
 	iface->get_selection = nautilus_window_get_selection;
 	iface->get_hidden_files_mode = nautilus_window_get_hidden_files_mode;
 	iface->set_hidden_files_mode = nautilus_window_set_hidden_files_mode;
+	iface->update_menus = nautilus_window_update_menus;
 }
 
 static void
Index: src/nautilus-window.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.h,v
retrieving revision 1.118
diff -u -r1.118 nautilus-window.h
--- src/nautilus-window.h	22 Mar 2005 09:22:23 -0000	1.118
+++ src/nautilus-window.h	12 May 2005 11:56:30 -0000
@@ -76,6 +76,7 @@
         void   (* get_default_size) (NautilusWindow *window, guint *default_width, guint *default_height);
         void   (* show_window)  (NautilusWindow *window);
         void   (* close) (NautilusWindow *window);
+	void   (* update_menus) (NautilusWindow *window);
 
         /* Signals used only for keybindings */
         gboolean (* go_up) (NautilusWindow *window, gboolean close);
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.671
diff -u -r1.671 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	11 May 2005 21:30:39 -0000	1.671
+++ src/file-manager/fm-directory-view.c	12 May 2005 11:56:33 -0000
@@ -7610,6 +7610,8 @@
 		(FM_DIRECTORY_VIEW_CLASS, view,
 		 update_menus, (view));
 
+	nautilus_window_info_update_menus (view->details->window);
+
 	view->details->menu_states_untrustworthy = FALSE;
 }
 


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