FileChooser fixes



In order to use the new file chooser with the gnome-vfs backend i needed
the following fixes:

1) The ~/Desktop directory is not translated
2) A GtkFilePath might not be on a GtkFileSystemVolume (it might be e.g.
ftp://ftp.gnome.org/pub/SOURCES). In this case we use the "topmost"
reachable GtkFilePath as the root for folder mode.
3) Use gtk_file_chooser_set_current_folder instead of _uri to set the
initial directory, since the uri gotten from g_filename_to_uri can be
different than what the gnome-vfs backend gives. (And its less code
anyway).

Index: gtk/gtkfilechooserdefault.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilechooserdefault.c,v
retrieving revision 1.67
diff -u -p -r1.67 gtkfilechooserdefault.c
--- gtk/gtkfilechooserdefault.c	19 Feb 2004 07:43:39 -0000	1.67
+++ gtk/gtkfilechooserdefault.c	19 Feb 2004 10:42:28 -0000
@@ -649,9 +649,7 @@ shortcuts_append_desktop (GtkFileChooser
   char *name;
   GtkFilePath *path;
 
-  /* FIXME: What is the Right Way of finding the desktop directory? */
-
-  name = g_build_filename (g_get_home_dir (), _("Desktop"), NULL);
+  name = g_build_filename (g_get_home_dir (), "Desktop", NULL);
   path = gtk_file_system_filename_to_path (impl->file_system, name);
   g_free (name);
 
@@ -2127,18 +2125,36 @@ static void
 set_tree_model (GtkFileChooserDefault *impl, const GtkFilePath *path)
 {
   GtkFileSystemVolume *volume;
-  GtkFilePath *volume_path;
+  GtkFilePath *base_path, *parent_path;
 
+  base_path = NULL;
+  
   volume = gtk_file_system_get_volume_for_path (impl->file_system,
path);
-  volume_path = gtk_file_system_volume_get_base_path
(impl->file_system, volume);
+  
+  if (volume)
+    base_path = gtk_file_system_volume_get_base_path
(impl->file_system, volume);
+  
+  if (base_path == NULL)
+    {
+      base_path = gtk_file_path_copy (path);
+      while (gtk_file_system_get_parent (impl->file_system,
+					 base_path,
+					 &parent_path,
+					 NULL) &&
+	     parent_path != NULL)
+	{
+	  gtk_file_path_free (base_path);
+	  base_path = parent_path;
+	}
+    }
 
-  if (impl->current_volume_path && gtk_file_path_compare (volume_path,
impl->current_volume_path) == 0)
+  if (impl->current_volume_path && gtk_file_path_compare (base_path,
impl->current_volume_path) == 0)
     goto out;
 
   if (impl->tree_model)
     g_object_unref (impl->tree_model);
 
-  impl->current_volume_path = gtk_file_path_copy (volume_path);
+  impl->current_volume_path = gtk_file_path_copy (base_path);
 
   impl->tree_model = _gtk_file_system_model_new (impl->file_system,
impl->current_volume_path, -1,
 						 GTK_FILE_INFO_DISPLAY_NAME);
@@ -2150,8 +2166,9 @@ set_tree_model (GtkFileChooserDefault *i
 
  out:
 
-  gtk_file_path_free (volume_path);
-  gtk_file_system_volume_free (impl->file_system, volume);
+  gtk_file_path_free (base_path);
+  if (volume) 
+    gtk_file_system_volume_free (impl->file_system, volume);
 }
 
 static void
Index: gtk/gtkfilechooserwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilechooserwidget.c,v
retrieving revision 1.13
diff -u -p -r1.13 gtkfilechooserwidget.c
--- gtk/gtkfilechooserwidget.c	19 Feb 2004 07:43:39 -0000	1.13
+++ gtk/gtkfilechooserwidget.c	19 Feb 2004 10:42:28 -0000
@@ -144,12 +144,7 @@ gtk_file_chooser_widget_constructor (GTy
   gtk_widget_show (priv->impl);
 
   current_folder = g_get_current_dir ();
-  current_folder_uri = g_filename_to_uri (current_folder, NULL, NULL);
-  if (current_folder_uri)
-    {
-      gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER
(priv->impl), current_folder_uri);
-      g_free (current_folder_uri);
-    }
+  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->impl),
current_folder);
   g_free (current_folder);
   
   _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's an immortal guerilla boxer searching for his wife's true killer. She's a 
green-fingered extravagent bounty hunter looking for love in all the wrong 
places. They fight crime! 




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