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



Am Montag, den 16.05.2005, 17:26 +0200 schrieb Alexander Larsson:
> On Thu, 2005-05-12 at 14:02 +0200, Christian Neumair wrote:
> > >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
> 
> the NautilusWindow menu only needs updating when the location changes.

Ouch, I've overlooked that. Thanks for pointing it out.

> The right thing to make the spatial window always update the sensitivity
> when you change the location. Fortunately we already track all this for
> the "up" button in navigational mode. So you just need to hook off
> nautilus_window_allow_up().

Nice. Proposed patch #2 attached. Do you like the way the methods are
invoked?

-- 
Christian Neumair <chris gnome-de org>
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	16 May 2005 16:14:15 -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	16 May 2005 16:14:16 -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: 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	16 May 2005 16:14:16 -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;	
@@ -407,6 +412,23 @@
 	}
 }
 
+static void
+real_set_allow_up (NautilusWindow *window, gboolean allow)
+{
+	NautilusSpatialWindow *spatial;
+	GtkAction *action;
+	gboolean has_parent;
+
+	spatial = NAUTILUS_SPATIAL_WINDOW (window);
+	has_parent = (window->details->viewed_file != NULL) &&
+		     nautilus_file_has_parent (window->details->viewed_file);
+
+	action = gtk_action_group_get_action (spatial->details->spatial_action_group,
+					      SPATIAL_ACTION_CLOSE_PARENT_FOLDERS);
+	gtk_action_set_sensitive (action, has_parent);
+
+	NAUTILUS_WINDOW_CLASS (parent_class)->set_allow_up (window, allow);
+}
 
 static void
 location_menu_item_activated_callback (GtkWidget *menu_item,
@@ -660,14 +682,14 @@
 }			   
 
 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) },
 };
@@ -792,7 +814,8 @@
 
 	NAUTILUS_WINDOW_CLASS(class)->set_throbber_active =
 		real_set_throbber_active;
-
+	NAUTILUS_WINDOW_CLASS(class)->set_allow_up =
+		real_set_allow_up;
 
 	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	16 May 2005 16:14:17 -0000
@@ -274,8 +274,9 @@
 	eel_g_list_free_deep (selection);
 }
 
-void
-nautilus_window_allow_up (NautilusWindow *window, gboolean allow)
+static void
+real_set_allow_up (NautilusWindow *window,
+		   gboolean        allow)
 {
 	GtkAction *action;
 	
@@ -290,6 +291,13 @@
 }
 
 void
+nautilus_window_allow_up (NautilusWindow *window, gboolean allow)
+{
+	EEL_CALL_METHOD (NAUTILUS_WINDOW_CLASS, window,
+			 set_allow_up, (window, allow));
+}
+
+void
 nautilus_window_allow_stop (NautilusWindow *window, gboolean allow)
 {
 	GtkAction *action;
@@ -1445,6 +1453,7 @@
 	class->set_title = real_set_title;
 	class->set_content_view_widget = real_set_content_view_widget;
 	class->load_view_as_menu = real_load_view_as_menu;
+	class->set_allow_up = real_set_allow_up;
 
 	g_object_class_install_property (G_OBJECT_CLASS (class),
 					 ARG_APP,
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	16 May 2005 16:14:17 -0000
@@ -72,6 +72,7 @@
                                             NautilusView *new_view);
         void   (* set_throbber_active) (NautilusWindow *window,
                                         gboolean active);
+	void   (* set_allow_up) (NautilusWindow *window, gboolean allow);
         void   (* prompt_for_location) (NautilusWindow *window);
         void   (* get_default_size) (NautilusWindow *window, guint *default_width, guint *default_height);
         void   (* show_window)  (NautilusWindow *window);


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