[patch] select pattern



Hello,

I've implemented the glob selection stuff that Dave describes in the
convenient nautilus-snacks list.  Patch attached.  The UI for the dialog
is pretty lame, suggestions appreciated.

Thanks,
James
? nautilus-snap-2.patch
? nautilus_jwillcox_emblem_refresh_v1.diff
? nautilus_jwillcox_select_pattern_v1.diff
? libnautilus-private/.nautilus-directory.c.swp
? libnautilus-private/nautilus-dot-hidden.diff
? src/file-manager/.fm-directory-view.c.swp
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.5926.2.2
diff -u -r1.5926.2.2 ChangeLog
--- ChangeLog	18 Sep 2003 19:11:15 -0000	1.5926.2.2
+++ ChangeLog	21 Sep 2003 01:01:30 -0000
@@ -1,3 +1,15 @@
+2003-09-20  James Willcox  <jwillcox gnome org>
+
+	* libnautilus-private/nautilus-directory.c:
+	(nautilus_directory_match_glob):
+	* libnautilus-private/nautilus-directory.h:
+	* src/file-manager/fm-directory-view.c: (get_pattern_selection),
+	(bonobo_menu_select_pattern_callback), (real_merge_menus):
+	* src/file-manager/nautilus-directory-view-ui.xml:
+	* src/nautilus-shell-ui.xml:
+
+	Add a "Edit->Select Pattern" menu entry
+
 2003-09-18  Dave Camp  <dcamp novell com>
 
 	* libnautilus-private/nautilus-global-preferences.c:
Index: libnautilus-private/nautilus-directory.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory.c,v
retrieving revision 1.249
diff -u -r1.249 nautilus-directory.c
--- libnautilus-private/nautilus-directory.c	29 Aug 2003 12:03:52 -0000	1.249
+++ libnautilus-private/nautilus-directory.c	21 Sep 2003 01:01:31 -0000
@@ -1630,6 +1630,30 @@
 	return non_tentative_files;
 }
 
+GList *
+nautilus_directory_match_glob (NautilusDirectory *directory, const char *glob)
+{
+	GList *files, *l, *ret;
+	GPatternSpec *spec;
+
+
+	ret = NULL;
+	spec = g_pattern_spec_new (glob);
+	
+	files = nautilus_directory_get_file_list (directory);
+	for (l = files; l; l = l->next) {
+		NautilusFile *file = l->data;
+		char *name = nautilus_file_get_display_name (file);
+
+		if (g_pattern_match_string (spec, name))
+			ret = g_list_append(ret, nautilus_file_ref (file));	
+	}
+
+	nautilus_file_list_free (files);
+
+	return ret;
+}
+
 /**
  * nautilus_directory_list_ref
  *
Index: libnautilus-private/nautilus-directory.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory.h,v
retrieving revision 1.65
diff -u -r1.65 nautilus-directory.h
--- libnautilus-private/nautilus-directory.h	29 Aug 2003 12:03:52 -0000	1.65
+++ libnautilus-private/nautilus-directory.h	21 Sep 2003 01:01:31 -0000
@@ -188,6 +188,10 @@
 /* Get a list of all files currently known in the directory. */
 GList *            nautilus_directory_get_file_list            (NautilusDirectory         *directory);
 
+GList *            nautilus_directory_match_glob              (NautilusDirectory         *directory,
+							       const char *glob);
+
+
 /* Return true if the directory has information about all the files.
  * This will be false until the directory has been read at least once.
  */
Index: src/nautilus-shell-ui.xml
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-shell-ui.xml,v
retrieving revision 1.107.6.1
diff -u -r1.107.6.1 nautilus-shell-ui.xml
--- src/nautilus-shell-ui.xml	15 Sep 2003 02:46:00 -0000	1.107.6.1
+++ src/nautilus-shell-ui.xml	21 Sep 2003 01:01:31 -0000
@@ -19,6 +19,7 @@
 	<cmd name="Stop"
 	 _tip="Stop loading this location"/>
 	<cmd name="Select All" accel="*Control*a" sensitive="0"/>
+	<cmd name="Select Pattern"/>
         <cmd name="Cut" accel="*Control*x" sensitive="0"/>
         <cmd name="Copy" accel="*Control*c" sensitive="0"/>
         <cmd name="Paste" accel="*Control*v" sensitive="0"/>
@@ -120,6 +121,10 @@
 		<menuitem name="Select All"
 			  _label="Select _All" 
 			  verb="Select All"/>
+
+		<menuitem name="Select Pattern"
+			  _label="Select Pattern" 
+			  verb="Select Pattern"/>
 				
 		<placeholder name="File Items Placeholder" delimit="top"/>
 		<placeholder name="Dangerous File Items Placeholder" delimit="top"/>
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.580.6.1
diff -u -r1.580.6.1 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	15 Sep 2003 02:46:31 -0000	1.580.6.1
+++ src/file-manager/fm-directory-view.c	21 Sep 2003 01:01:31 -0000
@@ -55,6 +55,8 @@
 #include <gtk/gtksignal.h>
 #include <gtk/gtkstock.h>
 #include <gtk/gtkmessagedialog.h>
+#include <gtk/gtkhbox.h>
+#include <gtk/gtkentry.h>
 #include <libgnome/gnome-i18n.h>
 #include <libgnome/gnome-util.h>
 #include <libgnomeui/gnome-uidefs.h>
@@ -937,6 +939,66 @@
 	fm_directory_view_select_all (callback_data);
 }
 
+static GList *
+get_pattern_selection (FMDirectoryView *view)
+{
+	GtkWidget *dialog;
+	GtkWidget *box;
+	GtkWidget *entry;
+	int response;
+	GList *ret = NULL;
+
+	dialog = gtk_dialog_new_with_buttons (_("Select Pattern"),
+			fm_directory_view_get_containing_window (view),
+			GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+			GTK_STOCK_CANCEL,
+			GTK_RESPONSE_CANCEL,
+			GTK_STOCK_OK,
+			GTK_RESPONSE_OK,
+			NULL);
+	gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+					 GTK_RESPONSE_OK);
+	gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+
+	box = gtk_hbox_new (FALSE, 6);
+	gtk_container_set_border_width (GTK_CONTAINER (box), 6);
+	entry = gtk_entry_new ();
+	gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
+	gtk_box_pack_start_defaults (GTK_BOX (box),
+				     gtk_label_new (_("Pattern:")));
+	gtk_box_pack_start_defaults (GTK_BOX (box), entry);
+	gtk_widget_show_all (box);
+	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), box);
+	response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+	if (response == GTK_RESPONSE_OK) {
+		NautilusDirectory *directory;
+		directory = fm_directory_view_get_model (view);
+		ret = nautilus_directory_match_glob (directory,
+				gtk_entry_get_text (GTK_ENTRY (entry)));
+	}
+
+	gtk_widget_destroy (dialog);
+	return ret;
+}
+
+static void
+bonobo_menu_select_pattern_callback (BonoboUIComponent *component, 
+				 gpointer callback_data, 
+				 const char *verb)
+{
+	GList *selection = NULL;
+
+	g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
+
+	selection = get_pattern_selection(callback_data);
+
+	if (selection) {
+		fm_directory_view_set_selection(callback_data, selection);
+		nautilus_file_list_free (selection);
+	}
+}
+
 static void
 reset_to_defaults_callback (BonoboUIComponent *component, 
 			    gpointer callback_data, 
@@ -4652,6 +4714,7 @@
 		BONOBO_UI_VERB ("Reset Background", reset_background_callback),
 		BONOBO_UI_VERB ("Reset to Defaults", reset_to_defaults_callback),
 		BONOBO_UI_VERB ("Select All", bonobo_menu_select_all_callback),
+		BONOBO_UI_VERB ("Select Pattern", bonobo_menu_select_pattern_callback),
 		BONOBO_UI_VERB ("Properties", open_properties_window_callback),
 		BONOBO_UI_VERB ("Trash", trash_callback),
 		BONOBO_UI_VERB_END
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.53.6.1
diff -u -r1.53.6.1 nautilus-directory-view-ui.xml
--- src/file-manager/nautilus-directory-view-ui.xml	15 Sep 2003 02:46:33 -0000	1.53.6.1
+++ src/file-manager/nautilus-directory-view-ui.xml	21 Sep 2003 01:01:31 -0000
@@ -60,6 +60,9 @@
 	<cmd name="Select All"
          _label="Select _All Files"
 	 _tip="Select all items in this window"/>
+	<cmd name="Select Pattern"
+         _label="Select _Pattern"
+	 _tip="Select items in this window matching a given pattern"/>
 	<cmd name="Properties"
          _label="_Properties"
 	 _tip="View or modify the properties of each selected item"/>
@@ -146,6 +149,8 @@
 		<menuitem name="Select All"
 			  accel="*Control*a"
 			  verb="Select All"/>
+		<menuitem name="Select Pattern"
+			  verb="Select Pattern"/>
 
 		<placeholder name="File Items Placeholder">
 			<menuitem name="Duplicate"


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