[PATCH]: More list view work.



This patch adds yet another missing feature to the list view.  Now users
can select a file by pressing the key corresponding to the first letter
in the filename.  The new selection is guaranteed to be in view...  I
believe there was a bug about this somewhere...  I'll look later
tonight.

I also added code to keep the current selection in view when the user
changes the sort order...

 - David
Index: src/file-manager/fm-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-view.c,v
retrieving revision 1.182
diff -u -p -r1.182 fm-list-view.c
--- src/file-manager/fm-list-view.c	6 Nov 2002 10:39:11 -0000	1.182
+++ src/file-manager/fm-list-view.c	19 Nov 2002 22:19:09 -0000
@@ -77,6 +77,8 @@ static NautilusFileSortType	default_sort
 static gboolean			default_sort_reversed_auto_value;
 static NautilusZoomLevel        default_zoom_level_auto_value;
 
+static void                 fm_list_view_set_selection         (FMDirectoryView *view,
+								GList *selection);
 static GList *              fm_list_view_get_selection         (FMDirectoryView *view);
 static void                 fm_list_view_set_zoom_level        (FMListView *view,
 								NautilusZoomLevel new_level,
@@ -217,10 +219,19 @@ button_release_callback (GtkWidget *widg
 }
 
 static gboolean
-key_press_callback (GtkWidget *widget, GdkEventKey *event, gpointer callback_data)
+key_press_callback (GtkWidget   *widget,
+		    GdkEventKey *event,
+		    gpointer     callback_data)
 {
 	FMDirectoryView *view;
+	GtkTreeModel *model;
+	GtkTreePath *path;
+	GtkTreeIter iter;
+	NautilusFile *file;
 	GList *file_list;
+	char *display_name;
+	gboolean valid;
+	guint32 c1, c2;
 
 	view = FM_DIRECTORY_VIEW (callback_data);
 
@@ -237,6 +248,37 @@ key_press_callback (GtkWidget *widget, G
 		break;
 	}
 
+	/* If an alphanumeric key is pressed try to select a file starting with that character. */
+	c1 = gdk_keyval_to_unicode (event->keyval);
+	c1 = g_unichar_tolower (c1);
+	if (g_unichar_isalnum (c1)) {
+		model = GTK_TREE_MODEL (FM_LIST_VIEW (view)->details->model);
+		valid = gtk_tree_model_get_iter_first (model, &iter); 
+
+		while (valid) {
+			gtk_tree_model_get (model, &iter, FM_LIST_MODEL_FILE_COLUMN, &file, -1);
+
+			display_name = nautilus_file_get_display_name (file);
+			c2 = g_unichar_tolower (g_utf8_get_char (display_name));
+			g_free (display_name);
+			if (c1 == c2) {
+				nautilus_file_ref (file);
+				file_list = g_list_append (NULL, file);
+				fm_list_view_set_selection (view, file_list);
+				nautilus_file_list_free (file_list);
+
+				/* Make sure the selection is visible. */
+				path = gtk_tree_model_get_path (model, &iter);
+				gtk_tree_view_scroll_to_cell (FM_LIST_VIEW (view)->details->tree_view,
+							      path, NULL, TRUE, .5, 0);
+				gtk_tree_path_free (path);
+				return TRUE;
+			}
+
+			valid = gtk_tree_model_iter_next (model, &iter);
+		}
+	}
+
 	return FALSE;
 }
 
@@ -249,6 +291,9 @@ sort_column_changed_callback (GtkTreeSor
 	GtkSortType reversed;
 	char *sort_attr, *default_sort_attr;
 	char *reversed_attr, *default_reversed_attr;
+	GtkTreeSelection* selection;
+	GtkTreeModel *model;
+	GList *path_list;
 
 	file = fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (view));
 
@@ -266,6 +311,19 @@ sort_column_changed_callback (GtkTreeSor
 	reversed_attr = (reversed ? "true" : "false");
 	nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
 				    default_reversed_attr, reversed_attr);
+
+	/* Make sure the current selection is still visible. */
+	/* FIXME: Maybe this should only happen if the selection was visible
+	   before the resort? */
+	selection = gtk_tree_view_get_selection (view->details->tree_view);
+	path_list = gtk_tree_selection_get_selected_rows (selection, &model);
+	if (path_list != NULL) {
+		gtk_tree_view_scroll_to_cell (view->details->tree_view,
+					      path_list->data, NULL, FALSE, 0, 0);
+
+		g_list_foreach (path_list, (void *)gtk_tree_path_free, NULL);
+		g_list_free (path_list);
+	}
 }
 
 static void


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