[PATCH] Make list-view use GTK+ typeahead (was: Re: RFC: On-line Content Filtering of directories)



Am Donnerstag, den 28.04.2005, 20:05 +0900 schrieb Ryan McDougall:
> Perhaps he meant it doesn't work as nicely as the typeahead on gtk+
> treeviews (ie the filechooser).

Attached is a patch which makes fm-list-view use the GTK+ builtin
list-view typeahead, which is also used by the file chooser. Result
browsing works through the Up/Down keys.

-- 
Christian Neumair <chris gnome-de org>
Index: src/file-manager/fm-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-view.c,v
retrieving revision 1.241
diff -u -r1.241 fm-list-view.c
--- src/file-manager/fm-list-view.c	19 Apr 2005 12:01:17 -0000	1.241
+++ src/file-manager/fm-list-view.c	28 Apr 2005 13:31:07 -0000
@@ -69,14 +69,6 @@
 #include <libnautilus-private/nautilus-clipboard.h>
 #include <libnautilus-private/nautilus-cell-renderer-pixbuf-emblem.h>
 
-/* Included for the typeselect flush delay */
-#include <libnautilus-private/nautilus-icon-container.h>
-
-typedef struct {
-	char *type_select_pattern;
-	guint64 last_typeselect_time;
-} TypeSelectState;
-
 struct FMListViewDetails {
 	GtkTreeView *tree_view;
 	FMListModel *model;
@@ -108,9 +100,6 @@
 
 	gboolean row_selected_on_button_down;
 
-	/* typeahead selection state */
-	TypeSelectState *type_select_state;
-
 	gboolean menus_ready;
 	
 	GHashTable *columns;
@@ -618,116 +607,6 @@
 }
 
 static gboolean
-select_matching_name (FMListView *view,
-		      const char *match_name)
-{
-	GtkTreeIter iter;
-	GtkTreePath *path;
-	gboolean match_found;
-	GValue value = { 0 };
-	const gchar *file_name;
-	int match_name_len, file_name_len;
-	
-	match_found = FALSE;
-	
-	if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (view->details->model), &iter)) {
-		return FALSE;
-	}
-
-	match_name_len = strlen (match_name);
-	do {
-		gtk_tree_model_get_value (GTK_TREE_MODEL (view->details->model), &iter, view->details->file_name_column_num, &value);
-		file_name = g_value_get_string (&value);
-		file_name_len = strlen (file_name);
-		match_found = file_name_len >= match_name_len &&
-			g_ascii_strncasecmp (match_name, file_name, MIN (match_name_len, file_name_len)) == 0;
-		g_value_unset (&value);
-
-		if (match_found) {
-			path = gtk_tree_model_get_path (GTK_TREE_MODEL (view->details->model), &iter);
-			gtk_tree_view_set_cursor (view->details->tree_view, path, NULL, FALSE);
-			gtk_tree_view_scroll_to_cell (view->details->tree_view, path, NULL, FALSE, 0, 0);
-			gtk_tree_path_free (path);
-			
-			return TRUE;
-		}
-	} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (view->details->model), &iter));
-	
-	return FALSE;
-}
-
-static void
-fm_list_view_flush_typeselect_state (FMListView *view)
-{
-	if (view->details->type_select_state == NULL) {
-		return;
-	}
-	
-	g_free (view->details->type_select_state->type_select_pattern);
-	g_free (view->details->type_select_state);
-	view->details->type_select_state = NULL;
-}
-
-static gboolean
-handle_typeahead (FMListView *view,
-		  GdkEventKey *event,
-		  gboolean *flush_typeahead)
-{
-	char *new_pattern;
-	gint64 now;
-	gint64 time_delta;
-	guint32 unichar;
-	char unichar_utf8[7];
-	int i;
-
-	unichar = gdk_keyval_to_unicode (event->keyval);
-	i = g_unichar_to_utf8 (unichar, unichar_utf8);
-	unichar_utf8[i] = 0;
-	
-	*flush_typeahead = FALSE;
-
-	if (*event->string == 0) {
-		/* can be an empty string if the modifier was held down, etc. */
-		return FALSE;
-	}
-	
-	if (!g_unichar_isprint (unichar)) {
-		*flush_typeahead = TRUE;
-		return FALSE;
-	}
-	
-	/* lazily allocate the typeahead state */
-	if (view->details->type_select_state == NULL) {
-		view->details->type_select_state = g_new0 (TypeSelectState, 1);
-	}
-
-	/* find out how long since last character was typed */
-	now = eel_get_system_time ();
-	time_delta = now - view->details->type_select_state->last_typeselect_time;
-	if (time_delta < 0 || time_delta > NAUTILUS_ICON_CONTAINER_TYPESELECT_FLUSH_DELAY) {
-		/* the typeselect state is too old, start with a fresh one */
-		g_free (view->details->type_select_state->type_select_pattern);
-		view->details->type_select_state->type_select_pattern = NULL;
-	}
-
-	if (view->details->type_select_state->type_select_pattern != NULL) {
-		new_pattern = g_strconcat
-			(view->details->type_select_state->type_select_pattern,
-			 unichar_utf8, NULL);
-		g_free (view->details->type_select_state->type_select_pattern);
-	} else {
-		new_pattern = g_strdup (unichar_utf8);
-	}
-
-	view->details->type_select_state->type_select_pattern = new_pattern;
-	view->details->type_select_state->last_typeselect_time = now;
-
-	select_matching_name (view, new_pattern);
-
-	return TRUE;
-}
-
-static gboolean
 popup_menu_callback (GtkWidget *widget, gpointer callback_data)
 {
  	FMListView *view;
@@ -745,12 +624,10 @@
 	FMDirectoryView *view;
 	GdkEventButton button_event = { 0 };
 	gboolean handled;
-	gboolean flush_typeahead;
 
 	view = FM_DIRECTORY_VIEW (callback_data);
 	handled = FALSE;
-	flush_typeahead = TRUE;
-	
+
 	switch (event->keyval) {
 	case GDK_F10:
 		if (event->state & GDK_CONTROL_MASK) {
@@ -784,16 +661,7 @@
 		break;
 
 	default:
-		/* Don't use Control or Alt keys for type-selecting, because they
-		 * might be used for menus.
-		 */
-		handled = (event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0 &&
-			handle_typeahead (FM_LIST_VIEW (view), event, &flush_typeahead);
-		break;
-	}
-	if (flush_typeahead) {
-		/* any non-ascii key will force the typeahead state to be forgotten */
-		fm_list_view_flush_typeselect_state (FM_LIST_VIEW (view));
+		handled = FALSE;
 	}
 
 	return handled;
@@ -1018,6 +886,7 @@
 							g_str_equal,
 							(GDestroyNotify)g_free,
 							NULL);
+	gtk_tree_view_set_enable_search (view->details->tree_view, TRUE);
 
 	/* Don't handle backspace key. It's used to open the parent folder. */
 	binding_set = gtk_binding_set_by_class (GTK_WIDGET_GET_CLASS (view->details->tree_view));
@@ -1110,7 +979,9 @@
 			g_hash_table_insert (view->details->columns,
 					     g_strdup ("name"), 
 					     view->details->file_name_column);
-			
+
+			gtk_tree_view_set_search_column (view->details->tree_view, column_num);
+
 			gtk_tree_view_column_set_sort_column_id (view->details->file_name_column, column_num);
 			gtk_tree_view_column_set_title (view->details->file_name_column, _("Name"));
 			gtk_tree_view_column_set_resizable (view->details->file_name_column, TRUE);
@@ -2111,8 +1982,6 @@
 
 	gtk_target_list_unref (list_view->details->source_target_list);
 	
-	fm_list_view_flush_typeselect_state (list_view);
-
 	g_list_free (list_view->details->cells);
 	g_hash_table_destroy (list_view->details->columns);
 
@@ -2306,8 +2175,6 @@
 		 "icons_changed",
 		 G_CALLBACK (icons_changed_callback),
 		 list_view, 0);
-	
-	list_view->details->type_select_state = NULL;
 }
 
 static NautilusView *


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