[PATCH]: per directory show hidden files preference



This patch began from Fredrik Nilsson's <jymdman home se> original
hidden files patch.  I modified it to support per directory preferences.

It mostly works.  The only known problem is that selecting "Show hidden
and backup files." from the preferences dialog causes View -> Show
Hidden Files to get a check mark but not View -> Show Backup Files.  I
think this is a bug in the new preferences dialog.

Also, if someone wants to submit a patch to rearrange the two new
entries in the View menu and add key bindings that would be helpful.  I
think the View menu may be getting slightly long now.  Perhaps the
entries can be put in a submenu...

 - David
Index: libnautilus-private/nautilus-metadata.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-metadata.h,v
retrieving revision 1.24
diff -u -p -r1.24 nautilus-metadata.h
--- libnautilus-private/nautilus-metadata.h	31 Jan 2001 00:26:57 -0000	1.24
+++ libnautilus-private/nautilus-metadata.h	20 Nov 2002 17:31:25 -0000
@@ -48,6 +48,9 @@
 #define NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR 	"background_color"
 #define NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE 	"background_tile_image"
 
+#define NAUTILUS_METADATA_KEY_SHOW_HIDDEN_FILES			"show_hidden_files"
+#define NAUTILUS_METADATA_KEY_SHOW_BACKUP_FILES			"show_backup_files"
+
 #define NAUTILUS_METADATA_KEY_ICON_VIEW_ZOOM_LEVEL       	"icon_view_zoom_level"
 #define NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT      	"icon_view_auto_layout"
 #define NAUTILUS_METADATA_KEY_ICON_VIEW_TIGHTER_LAYOUT      	"icon_view_tighter_layout"
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.558
diff -u -p -r1.558 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	7 Nov 2002 19:20:40 -0000	1.558
+++ src/file-manager/fm-directory-view.c	20 Nov 2002 17:31:25 -0000
@@ -127,6 +127,8 @@
 #define FM_DIRECTORY_VIEW_COMMAND_CUT_FILES	    			"/commands/Cut Files"
 #define FM_DIRECTORY_VIEW_COMMAND_COPY_FILES				"/commands/Copy Files"
 #define FM_DIRECTORY_VIEW_COMMAND_PASTE_FILES	   			"/commands/Paste Files"
+#define FM_DIRECTORY_VIEW_COMMAND_SHOW_HIDDEN_FILES			"/commands/Show Hidden Files"
+#define FM_DIRECTORY_VIEW_COMMAND_SHOW_BACKUP_FILES			"/commands/Show Backup Files"
 
 #define FM_DIRECTORY_VIEW_MENU_PATH_OPEN_ALTERNATE        		"/menu/File/Open Placeholder/OpenAlternate"
 #define FM_DIRECTORY_VIEW_MENU_PATH_OPEN_WITH				"/menu/File/Open Placeholder/Open With"
@@ -143,7 +145,7 @@
 #define FM_DIRECTORY_VIEW_MENU_PATH_SCRIPTS_SEPARATOR    		"/menu/File/Open Placeholder/Scripts/After Scripts"
 #define FM_DIRECTORY_VIEW_MENU_PATH_CUT_FILES    			"/menu/Edit/Cut"
 #define FM_DIRECTORY_VIEW_MENU_PATH_COPY_FILES		    		"/menu/Edit/Copy"
-#define FM_DIRECTORY_VIEW_MENU_PATH_PASTE_FILES		    		"/menu/File/Paste"
+#define FM_DIRECTORY_VIEW_MENU_PATH_PASTE_FILES				"/menu/Edit/Paste"
 
 #define FM_DIRECTORY_VIEW_POPUP_PATH_BACKGROUND				"/popups/background"
 #define FM_DIRECTORY_VIEW_POPUP_PATH_SELECTION				"/popups/selection"
@@ -159,6 +161,9 @@
 #define FM_DIRECTORY_VIEW_POPUP_PATH_SCRIPTS				"/popups/selection/Open Placeholder/Scripts"
 #define FM_DIRECTORY_VIEW_POPUP_PATH_MIME_ACTIONS			"/popups/selection/Mime Actions"
 
+#define ID_SHOW_HIDDEN_FILES						"Show Hidden Files"
+#define ID_SHOW_BACKUP_FILES						"Show Backup Files"
+
 #define MAX_MENU_LEVELS 5
 
 enum {
@@ -182,6 +187,8 @@ static GdkAtom copied_files_atom;
 static gboolean show_delete_command_auto_value;
 static gboolean confirm_trash_auto_value;
 static gboolean use_new_window_auto_value;
+static gboolean default_show_hidden_files_auto_value;
+static gboolean default_show_backup_files_auto_value;
 
 static char *scripts_directory_uri;
 static int scripts_directory_uri_length;
@@ -1283,6 +1290,10 @@ fm_directory_view_init (FMDirectoryView 
 						  &show_delete_command_auto_value);
 		eel_preferences_add_auto_boolean (NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW,
 						  &use_new_window_auto_value);
+		eel_preferences_add_auto_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
+						  &default_show_hidden_files_auto_value);
+		eel_preferences_add_auto_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
+						  &default_show_backup_files_auto_value);
 	}
 
 	view->details = g_new0 (FMDirectoryViewDetails, 1);
@@ -1345,8 +1356,6 @@ fm_directory_view_init (FMDirectoryView 
 
 	gtk_widget_show (GTK_WIDGET (view));
 
-	filtering_changed_callback (view);
-	
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW,
 				      schedule_update_menus_callback, view);
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
@@ -1790,6 +1799,111 @@ reset_background_callback (BonoboUICompo
 }
 
 static void
+show_hidden_files_state_changed_callback (BonoboUIComponent           *component,
+					  const char                  *path,
+					  Bonobo_UIComponent_EventType type,
+					  const char                  *state,
+					  gpointer                     user_data)
+{
+       FMDirectoryView *view;
+       gboolean new_state;
+
+       g_assert (strcmp (path, ID_SHOW_HIDDEN_FILES) == 0);
+       g_assert (FM_IS_DIRECTORY_VIEW (user_data));
+
+       if (strcmp (state, "") == 0) {
+               /* State goes blank when component is removed; ignore this. */
+               return;
+       }
+
+       view = FM_DIRECTORY_VIEW (user_data);
+
+       new_state = strcmp (state, "0") != 0;
+
+       if (new_state != view->details->show_hidden_files) {
+               view->details->show_hidden_files = new_state;
+
+	       nautilus_file_set_boolean_metadata (view->details->directory_as_file,
+	       					   NAUTILUS_METADATA_KEY_SHOW_HIDDEN_FILES,
+						   default_show_hidden_files_auto_value,
+						   new_state);
+
+	       /* Reload the current uri so that the filtering changes take place. */
+	       if (view->details->model != NULL) {
+		       load_directory (view, view->details->model);
+	       }
+       }
+}
+
+static void
+show_backup_files_state_changed_callback (BonoboUIComponent           *component,
+					  const char                  *path,
+					  Bonobo_UIComponent_EventType type,
+					  const char                  *state,
+					  gpointer                     user_data)
+{
+       FMDirectoryView *view;
+       gboolean new_state;
+       
+       g_assert (strcmp (path, ID_SHOW_BACKUP_FILES) == 0);
+       g_assert (FM_IS_DIRECTORY_VIEW (user_data));
+
+       if (strcmp (state, "") == 0) {
+               /* State goes blank when component is removed; ignore this. */
+               return;
+       }
+
+       view = FM_DIRECTORY_VIEW (user_data);
+
+       new_state = strcmp (state, "0") != 0;
+
+       if (new_state != view->details->show_backup_files) {
+               view->details->show_backup_files = new_state;
+
+	       nautilus_file_set_boolean_metadata (view->details->directory_as_file,
+						   NAUTILUS_METADATA_KEY_SHOW_BACKUP_FILES,
+						   default_show_backup_files_auto_value,
+						   new_state);
+
+	       /* Reload the current uri so that the filtering changes take place. */
+	       if (view->details->model != NULL) {
+		       load_directory (view, view->details->model);
+	       }
+       }
+}
+
+static void
+reset_filtering_preferences (FMDirectoryView *view)
+{
+	view->details->show_hidden_files = default_show_hidden_files_auto_value;
+	view->details->show_backup_files = default_show_backup_files_auto_value;
+
+	bonobo_ui_component_freeze (view->details->ui, NULL);
+
+	nautilus_bonobo_set_toggle_state (view->details->ui,
+					  FM_DIRECTORY_VIEW_COMMAND_SHOW_HIDDEN_FILES,
+					  view->details->show_hidden_files);
+
+	nautilus_bonobo_set_toggle_state (view->details->ui,
+					  FM_DIRECTORY_VIEW_COMMAND_SHOW_BACKUP_FILES,
+					  view->details->show_backup_files);
+
+	bonobo_ui_component_thaw (view->details->ui, NULL);
+
+	nautilus_file_set_metadata (view->details->directory_as_file,
+				    NAUTILUS_METADATA_KEY_SHOW_HIDDEN_FILES,
+				    NULL, NULL);
+	nautilus_file_set_metadata (view->details->directory_as_file,
+				    NAUTILUS_METADATA_KEY_SHOW_BACKUP_FILES,
+				    NULL, NULL);
+
+	/* Reload the current uri so that the filtering changes take place. */
+	if (view->details->model != NULL) {
+		load_directory (view, view->details->model);
+	}
+}
+
+static void
 zoomable_zoom_in_callback (BonoboZoomable *zoomable, FMDirectoryView *directory_view)
 {
 	fm_directory_view_bump_zoom_level (directory_view, 1);
@@ -4523,6 +4637,18 @@ real_merge_menus (FMDirectoryView *view)
 						     "nautilus");
 	eel_add_weak_pointer (&view->details->ui);
 
+	nautilus_bonobo_set_toggle_state (view->details->ui,
+					  FM_DIRECTORY_VIEW_COMMAND_SHOW_HIDDEN_FILES,
+					  view->details->show_hidden_files);
+
+	nautilus_bonobo_set_toggle_state (view->details->ui,
+					  FM_DIRECTORY_VIEW_COMMAND_SHOW_BACKUP_FILES,
+					  view->details->show_backup_files);
+  
+	bonobo_ui_component_add_listener (view->details->ui, ID_SHOW_HIDDEN_FILES,
+					  show_hidden_files_state_changed_callback, view);
+	bonobo_ui_component_add_listener (view->details->ui, ID_SHOW_BACKUP_FILES,
+					  show_backup_files_state_changed_callback, view);
 	bonobo_ui_component_add_verb_list_with_data (view->details->ui, verbs, view);
 
 	g_signal_connect_object (fm_directory_view_get_background (view), "settings_changed",
@@ -5326,6 +5452,18 @@ load_directory (FMDirectoryView *view,
 	view->details->file_changed_handler_id = g_signal_connect
 		(view->details->directory_as_file, "changed",
 		 G_CALLBACK (file_changed_callback), view);
+
+	/* This is the earliest place that we can get metadata for this directory,
+	   any earlier and view->details->directory_as_file would not have been
+	   initialized. */
+	view->details->show_hidden_files = nautilus_file_get_boolean_metadata
+		(view->details->directory_as_file,
+		 NAUTILUS_METADATA_KEY_SHOW_HIDDEN_FILES,
+		 default_show_hidden_files_auto_value);
+	view->details->show_backup_files = nautilus_file_get_boolean_metadata
+		(view->details->directory_as_file,
+		 NAUTILUS_METADATA_KEY_SHOW_BACKUP_FILES,
+		 default_show_backup_files_auto_value);
 }
 
 static void
@@ -5544,6 +5682,8 @@ fm_directory_view_reset_to_defaults (FMD
 {
 	g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
 
+	reset_filtering_preferences (view);
+
 	EEL_CALL_METHOD
 		(FM_DIRECTORY_VIEW_CLASS, view,
 		 reset_to_defaults, (view));
@@ -5814,29 +5954,45 @@ schedule_update_menus_callback (gpointer
 static void
 filtering_changed_callback (gpointer callback_data)
 {
-	FMDirectoryView	*directory_view;
-	gboolean new_show_hidden, new_show_backup;
+	FMDirectoryView	*view;
 	gboolean filtering_actually_changed;
+	gboolean show_hidden_files, show_backup_files;
 
-	directory_view = FM_DIRECTORY_VIEW (callback_data);
+	view = FM_DIRECTORY_VIEW (callback_data);
 	filtering_actually_changed = FALSE;
 
-	new_show_hidden = eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
-	if (new_show_hidden != directory_view->details->show_hidden_files) {
+	show_hidden_files = nautilus_file_get_boolean_metadata (view->details->directory_as_file,
+								NAUTILUS_METADATA_KEY_SHOW_HIDDEN_FILES,
+								default_show_hidden_files_auto_value);
+	show_backup_files = nautilus_file_get_boolean_metadata (view->details->directory_as_file,
+								NAUTILUS_METADATA_KEY_SHOW_BACKUP_FILES,
+								default_show_backup_files_auto_value);
+
+	if (show_hidden_files != view->details->show_hidden_files) {
+		/* g_assert (show_hidden_files == default_show_hidden_files_auto_value); */
+
 		filtering_actually_changed = TRUE;
-		directory_view->details->show_hidden_files = new_show_hidden ;
+		view->details->show_hidden_files = show_hidden_files;
+
+		nautilus_bonobo_set_toggle_state (view->details->ui,
+						  FM_DIRECTORY_VIEW_COMMAND_SHOW_HIDDEN_FILES,
+						  view->details->show_hidden_files);
 	}
 
-	new_show_backup = eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES);
-	if (new_show_backup != directory_view->details->show_backup_files) {
+	if (show_backup_files != view->details->show_backup_files) {
+		/* g_assert (show_backup_files == default_show_backup_files_auto_value); */
+
 		filtering_actually_changed = TRUE;
-		directory_view->details->show_backup_files = new_show_backup;
+		view->details->show_backup_files = show_backup_files;
+
+		nautilus_bonobo_set_toggle_state (view->details->ui,
+						  FM_DIRECTORY_VIEW_COMMAND_SHOW_BACKUP_FILES,
+						  view->details->show_backup_files);
 	}
 
 	/* Reload the current uri so that the filtering changes take place. */
-	if (filtering_actually_changed && directory_view->details->model != NULL) {
-		load_directory (directory_view,
-				directory_view->details->model);
+	if (filtering_actually_changed && view->details->model != NULL) {
+		load_directory (view, view->details->model);
 	}
 }
 
@@ -5850,11 +6006,11 @@ fm_directory_view_ignore_hidden_file_pre
 	}
 
 	eel_preferences_remove_callback (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
-					      filtering_changed_callback,
-					      view);
+					 filtering_changed_callback,
+					 view);
 	eel_preferences_remove_callback (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
-					      filtering_changed_callback,
-					      view);
+					 filtering_changed_callback,
+					 view);
 
 	view->details->show_hidden_files = FALSE;
 	view->details->show_backup_files = FALSE;
Index: src/file-manager/nautilus-directory-view-ui.xml
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/nautilus-directory-view-ui.xml,v
retrieving revision 1.50
diff -u -p -r1.50 nautilus-directory-view-ui.xml
--- src/file-manager/nautilus-directory-view-ui.xml	7 Nov 2002 19:20:42 -0000	1.50
+++ src/file-manager/nautilus-directory-view-ui.xml	20 Nov 2002 17:31:25 -0000
@@ -63,6 +63,10 @@
 	<cmd name="Trash"
          _label="Mo_ve to Trash"
 	 _tip="Move each selected item to the Trash"/>
+	<cmd name="Show Hidden Files"
+	 _tip="Toggle show hidden files"/>
+	<cmd name="Show Backup Files"
+	 _tip="Toggle show backup files"/>
 </commands>
 <keybindings>
 	<accel name="*Control*BackSpace" verb="Trash"/>
@@ -168,6 +172,15 @@
 		<placeholder name="View Preferences Placeholder">
 			<menuitem name="Reset to Defaults"
 				  verb="Reset to Defaults"/>
+			<separator/>
+			<menuitem name="Show Hidden Files"
+				 _label="Show Hidden Files"
+				  type="toggle"
+				  id="Show Hidden Files"/>
+			<menuitem name="Show Backup Files"
+				 _label="Show Backup Files"
+				  type="toggle"
+				  id="Show Backup Files"/>
 		</placeholder>
 	</submenu>
 </menu>


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