Re: [Patch] Interactive search (aka typeahead) enhancement patch



I found some things to improve so here's a new patch, changes from
previous are:

 - Remove unnecessary FMDirectoryView code as it is not needed to
implement NautilusView methods.
 - Use CTRL-J as shortcut, this time I verified it against HIG
shortcuts[1] and nautilus.
 - Remove commented code left by mistake in previous patch.

[1] http://developer.gnome.org/projects/gup/hig/1.0/userinput.html

Also, I think the ui action callback can be implemented in
nautilus-window.c so it'll cover both spatial and navigation windows,
and so, no need to implement it separately for nautilus-spatial-window.c
and nautilus-navigation-window.c. If you think this is the correct way
then I'll update the patch.
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.406
diff -p -u -r1.406 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c	12 Dec 2005 16:59:10 -0000	1.406
+++ libnautilus-private/nautilus-icon-container.c	29 Jan 2006 17:05:35 -0000
@@ -3861,8 +3861,7 @@ nautilus_icon_container_search_iter (Nau
 			continue;
 		}
 		
-		if (strncmp (case_normalized_key, case_normalized_name,
-			     strlen (case_normalized_key)) == 0) {
+		if (strstr (case_normalized_name, case_normalized_key)) {
 			count++;
 		}
 
Index: libnautilus-private/nautilus-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-view.c,v
retrieving revision 1.3
diff -p -u -r1.3 nautilus-view.c
--- libnautilus-private/nautilus-view.c	17 May 2005 13:27:29 -0000	1.3
+++ libnautilus-private/nautilus-view.c	29 Jan 2006 17:05:36 -0000
@@ -260,3 +260,13 @@ nautilus_view_pop_up_location_context_me
 		(* NAUTILUS_VIEW_GET_IFACE (view)->pop_up_location_context_menu) (view, event);
 	}
 }
+
+void
+nautilus_view_start_interactive_search (NautilusView   *view)
+{
+	g_return_if_fail (NAUTILUS_IS_VIEW (view));
+
+	if (NAUTILUS_VIEW_GET_IFACE (view)->start_interactive_search != NULL) {
+		(* NAUTILUS_VIEW_GET_IFACE (view)->start_interactive_search) (view);
+	}
+}
Index: libnautilus-private/nautilus-view.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-view.h,v
retrieving revision 1.3
diff -p -u -r1.3 nautilus-view.h
--- libnautilus-private/nautilus-view.h	17 May 2005 13:27:29 -0000	1.3
+++ libnautilus-private/nautilus-view.h	29 Jan 2006 17:05:36 -0000
@@ -115,6 +115,9 @@ struct _NautilusViewIface 
 	void           (* pop_up_location_context_menu) (NautilusView   *view,
 							 GdkEventButton *event);
 
+	/* Request popup the interactive search dialog (aka typeahead) */
+	void           (* start_interactive_search) (NautilusView        *view);
+
 	/* Padding for future expansion */
 	void (*_reserved1) (void);
 	void (*_reserved2) (void);
@@ -151,6 +154,7 @@ gboolean          nautilus_view_can_zoom
 NautilusZoomLevel nautilus_view_get_zoom_level             (NautilusView      *view);
 void              nautilus_view_pop_up_location_context_menu (NautilusView    *view,
 							      GdkEventButton  *event);
+void              nautilus_view_start_interactive_search   (NautilusView      *view);
 
 G_END_DECLS
 
Index: src/nautilus-spatial-window-ui.xml
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window-ui.xml,v
retrieving revision 1.17
diff -p -u -r1.17 nautilus-spatial-window-ui.xml
--- src/nautilus-spatial-window-ui.xml	15 Dec 2005 14:25:58 -0000	1.17
+++ src/nautilus-spatial-window-ui.xml	29 Jan 2006 17:05:36 -0000
@@ -10,6 +10,11 @@
 			<menuitem name="Close All Folders" action="Close All Folders"/>
 		</placeholder>
 	</menu>
+	<menu action="Edit">
+		<placeholder name="Select Items">
+			<menuitem name="Find" action="Interactive Search"/>
+		</placeholder>
+	</menu>
         <placeholder name="Other Menus">
 	        <menu action="Places">
 		      <menuitem name="Home" action="Home"/>
Index: src/nautilus-spatial-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window.c,v
retrieving revision 1.456
diff -p -u -r1.456 nautilus-spatial-window.c
--- src/nautilus-spatial-window.c	16 Jan 2006 23:48:19 -0000	1.456
+++ src/nautilus-spatial-window.c	29 Jan 2006 17:05:38 -0000
@@ -319,6 +319,16 @@ action_close_all_folders_callback (GtkAc
 	nautilus_application_close_all_spatial_windows ();
 }
 
+void
+action_interactive_search_spatial_callback (GtkAction *action,
+					    gpointer   user_data)
+{	
+	NautilusWindow *window;
+	window = NAUTILUS_WINDOW (user_data);
+
+	nautilus_view_start_interactive_search (window->content_view);
+}
+
 static void
 real_prompt_for_location (NautilusWindow *window,
 			  const char     *initial)
@@ -849,6 +859,9 @@ static const GtkActionEntry spatial_entr
   { "Search", "gtk-find", N_("_Search"), /* name, stock id, label */
     "<control>F", N_("Search for files"),
     G_CALLBACK (action_search_callback) },
+  { "Interactive Search", GTK_STOCK_FIND, N_("_Find in this folder"),
+    "<control>J", N_("Find files in this folder"),
+    G_CALLBACK (action_interactive_search_spatial_callback) },
 };
 
 static void
Index: src/nautilus-spatial-window.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window.h,v
retrieving revision 1.113
diff -p -u -r1.113 nautilus-spatial-window.h
--- src/nautilus-spatial-window.h	11 Jul 2005 10:23:57 -0000	1.113
+++ src/nautilus-spatial-window.h	29 Jan 2006 17:05:38 -0000
@@ -63,6 +63,8 @@ void             nautilus_spatial_window
 void             nautilus_spatial_window_save_show_hidden_files_mode	(NautilusSpatialWindow *window);
 void             nautilus_spatial_window_set_location_button		(NautilusSpatialWindow *window,
 									 const char            *location);
+void             action_interactive_search_spatial_callback		(GtkAction *action, 
+									 gpointer  user_data);
 
 
 #endif
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.318
diff -p -u -r1.318 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	12 Dec 2005 16:59:11 -0000	1.318
+++ src/file-manager/fm-icon-view.c	29 Jan 2006 17:05:42 -0000
@@ -183,6 +183,7 @@ static void                 fm_icon_view
 static void                 fm_icon_view_set_directory_tighter_layout (FMIconView           *icon_view,
 								       NautilusFile         *file,
 								       gboolean              tighter_layout);
+static void                 fm_icon_view_start_interactive_search     (NautilusView         *view);
 static const SortCriterion *get_sort_criterion_by_sort_type           (NautilusFileSortType  sort_type);
 static void                 set_sort_criterion_by_sort_type           (FMIconView           *icon_view,
 								       NautilusFileSortType  sort_type);
@@ -2584,6 +2585,20 @@ icon_view_scroll_to_file (NautilusView *
 	}
 }
 
+static void
+fm_icon_view_start_interactive_search (NautilusView *view)
+{
+	NautilusIconContainer  *icon_container;
+	gboolean ret;
+
+	icon_container = NAUTILUS_ICON_CONTAINER (GTK_BIN (FM_ICON_VIEW (view))->child);
+	if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_container)))
+		gtk_widget_grab_focus (GTK_WIDGET (icon_container));
+
+	ret = EEL_CALL_METHOD_WITH_RETURN_VALUE
+	(NAUTILUS_ICON_CONTAINER_CLASS, icon_container,
+	 start_interactive_search, (icon_container));
+}
 
 static void
 fm_icon_view_class_init (FMIconViewClass *klass)
@@ -2666,6 +2681,7 @@ fm_icon_view_iface_init (NautilusViewIfa
 	iface->get_first_visible_file = icon_view_get_first_visible_file;
 	iface->scroll_to_file = icon_view_scroll_to_file;
 	iface->get_title = NULL;
+	iface->start_interactive_search = fm_icon_view_start_interactive_search;
 }
 
 static void
Index: src/file-manager/fm-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-view.c,v
retrieving revision 1.264
diff -p -u -r1.264 fm-list-view.c
--- src/file-manager/fm-list-view.c	26 Jan 2006 21:25:07 -0000	1.264
+++ src/file-manager/fm-list-view.c	29 Jan 2006 17:05:45 -0000
@@ -135,6 +135,12 @@ static NautilusZoomLevel        default_
 static GList *                  default_visible_columns_auto_value;
 static GList *                  default_column_order_auto_value;
 
+static gboolean interactive_search_equal_func (GtkTreeModel  *model,
+						gint 		column,
+						const gchar	*key,
+						GtkTreeIter	*iter,
+						gpointer	search_data);
+static void   fm_list_view_start_interactive_search	   (NautilusView      *view);
 static GList *fm_list_view_get_selection                   (FMDirectoryView   *view);
 static GList *fm_list_view_get_selection_for_file_transfer (FMDirectoryView   *view);
 static void   fm_list_view_set_zoom_level                  (FMListView        *view,
@@ -236,6 +242,80 @@ button_event_modifies_selection (GdkEven
 	return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
 }
 
+static gboolean
+interactive_search_equal_func (GtkTreeModel *model,
+				 gint          column,
+				 const gchar  *key,
+				 GtkTreeIter  *iter,
+				 gpointer      search_data)
+{
+  gboolean retval = TRUE;
+  const gchar *str;
+  gchar *normalized_string;
+  gchar *normalized_key;
+  gchar *case_normalized_string = NULL;
+  gchar *case_normalized_key = NULL;
+  GValue value = {0,};
+  GValue transformed = {0,};
+
+  gtk_tree_model_get_value (model, iter, column, &value);
+
+  g_value_init (&transformed, G_TYPE_STRING);
+
+  if (!g_value_transform (&value, &transformed))
+    {
+      g_value_unset (&value);
+      return TRUE;
+    }
+
+  g_value_unset (&value);
+
+  str = g_value_get_string (&transformed);
+  if (!str)
+    {
+      g_value_unset (&transformed);
+      return TRUE;
+    }
+
+  normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
+  normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
+
+  if (normalized_string && normalized_key)
+    {
+      case_normalized_string = g_utf8_casefold (normalized_string, -1);
+      case_normalized_key = g_utf8_casefold (normalized_key, -1);
+
+      if (strstr (case_normalized_string, case_normalized_key) != NULL)
+	  retval = FALSE;
+    }
+
+  g_value_unset (&transformed);
+  g_free (normalized_key);
+  g_free (normalized_string);
+  g_free (case_normalized_key);
+  g_free (case_normalized_string);
+
+  return retval;
+}
+
+static void
+fm_list_view_start_interactive_search (NautilusView *view)
+{
+	GtkTreeView *tv;
+	gboolean ret;
+	FMListView *listview;
+
+	listview = FM_LIST_VIEW (view);
+	tv = listview->details->tree_view;
+	
+	if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (tv)))
+		gtk_widget_grab_focus (GTK_WIDGET (tv));
+
+	ret = EEL_CALL_METHOD_WITH_RETURN_VALUE
+	(GTK_TREE_VIEW_CLASS, tv,
+	start_interactive_search, (tv));
+}
+
 static void
 fm_list_view_did_not_drag (FMListView *view,
 			   GdkEventButton *event)
@@ -2536,6 +2616,7 @@ fm_list_view_iface_init (NautilusViewIfa
 	iface->get_first_visible_file = fm_list_view_get_first_visible_file;
 	iface->scroll_to_file = list_view_scroll_to_file;
 	iface->get_title = NULL;
+	iface->start_interactive_search = fm_list_view_start_interactive_search;
 }
 
 
@@ -2545,6 +2626,10 @@ fm_list_view_init (FMListView *list_view
 	list_view->details = g_new0 (FMListViewDetails, 1);
 
 	create_and_set_up_tree_view (list_view);
+
+	gtk_tree_view_set_search_equal_func (list_view->details->tree_view,
+					     interactive_search_equal_func,
+					     NULL, NULL);
 
 	eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_SORT_ORDER,
 						  default_sort_order_changed_callback,


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