minor feature patch for gtkfilesel.c



(from the README, at http://incandescent.mp3revolution.net/gtk+/)

filesel_memory.diff - Minor patch to gtk+-1.2.9, that allows it's
        GtkFileSelection widget to remember which directory it came
        from, when moving up parent directories, and position the
        dir_list somewhere close to that child directory.

        In other words; if you have 300 subdirectories, and go into
        one of them, and then leave it (by double-clicking ".."),
        instead of being dropped at the first directory in the
        entire list, you're put someplace close to the directory
        you just came from.  This is nice for things like xmms,
        when you've got directories like "Artist-Album", and want
        to click through a couple directories of the same artist.

        I liken this to how (decent) browsers treat web pages.  You
        click on a link, then go back, and the browser returns you
        to the link, not to the top of the page.  I don't know
        how most browsers behave when using file:// urls on your
        hard drive, but I do know mozilla (m18) returns you to
        the top of a directory listing (blech, broken imo), and
        both links and lynx return you to somewhere close to
        where you originated (proper behavior ;).

I haven't had the chance to thoroughly test this patch; as long
as something similar goes into gtk, I'd be happy.  This behavior
has annoyed me for a long time, I just got around to fixing
it tonight (I originally made a patch for xmms:
http://home.vh.net/~aas/util.c.diff , but was informed that this
is the sort of thing that should be in gtk+ itself).

-- 
"... being a Linux user is sort of like living in a house inhabited
by a large family of carpenters and architects. Every morning when
you wake up, the house is a little different. Maybe there is a new
turret, or some walls have moved. Or perhaps someone has temporarily
removed the floor under your bed." - Unix for Dummies, 2nd Edition
        -- found in the .sig of Rob Riggs, rriggs tesser com
diff -urN gtk+-1.2.9.orig/gtk/gtkfilesel.c gtk+-1.2.9/gtk/gtkfilesel.c
--- gtk+-1.2.9.orig/gtk/gtkfilesel.c	Thu Feb 15 23:36:19 2001
+++ gtk+-1.2.9/gtk/gtkfilesel.c	Fri Mar 23 03:43:23 2001
@@ -1315,6 +1315,8 @@
   gchar* rem_path = rel_path;
   gchar* sel_text;
   gchar* text[2];
+  gchar* position_dir = NULL;
+  gint position_row = 0;
   gint did_recurse = FALSE;
   gint possible_count = 0;
   gint selection_index = -1;
@@ -1325,11 +1327,20 @@
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
   
   cmpl_state = (CompletionState*) fs->cmpl_state;
+
+  /* if moving up to a parent directory, remember old child dir */
+  if ((strcmp(rel_path, "../") == 0) && (cmpl_state_okay (cmpl_state)))
+    {
+      gchar* d = g_basename (cmpl_reference_position (cmpl_state));
+      position_dir = g_strconcat (d, "/", NULL);
+    }
+
   poss = cmpl_completion_matches (rel_path, &rem_path, cmpl_state);
 
   if (!cmpl_state_okay (cmpl_state))
     {
       /* Something went wrong. */
+      g_free (position_dir);
       gtk_file_selection_abort (fs);
       return;
     }
@@ -1373,6 +1384,10 @@
 		  int width = gdk_string_width(fs->dir_list->style->font,
 					       filename);
 		  row = gtk_clist_append (GTK_CLIST (fs->dir_list), text);
+
+		  if ((position_dir != NULL) && (strcmp (filename, position_dir) == 0))
+		    position_row = row;
+
 		  if(width > dir_list_width)
 		    {
 		      dir_list_width = width;
@@ -1400,6 +1415,14 @@
 
   gtk_clist_thaw (GTK_CLIST (fs->dir_list));
   gtk_clist_thaw (GTK_CLIST (fs->file_list));
+
+  if (position_dir != NULL)
+    {
+      /* remember which directory we came from, and position user near there. */
+      if (position_row > 5)
+        gtk_clist_moveto (GTK_CLIST (fs->dir_list), position_row - 5, 0, 0, 0);
+      g_free (position_dir);
+    }
 
   /* File lists are set. */
 


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