Love tasks for desktop lovers

Lukas Sabota punkrockguy318 at comcast.net
Wed Dec 28 20:14:02 GMT 2005


Ah, what a great solution, Alain =D.  This looks like it will make 
everyone happy.  Good work! 

God Bless,
Lukas

Alain Perry wrote:

>Ok, so to please everybody, I modified the patch to take into account
>the environment variable.
>I also added some code to make it work under win32 (though I could not
>test it) so that upstream can take it if they want.
>Here it is attached.
>
>--
>Alain Perry
>  
>
>------------------------------------------------------------------------
>
>--- gtk+-2.8.9.orig/gtk/gtkfilechooserdefault.c	2005-12-06 04:11:51.000000000 +0100
>+++ gtk+-2.8.9/gtk/gtkfilechooserdefault.c	2005-12-28 13:25:32.000000000 +0100
>@@ -222,6 +222,7 @@
> 
>   GtkTooltips *tooltips;
> 
>+  gboolean has_documents;
>   gboolean has_home;
>   gboolean has_desktop;
> 
>@@ -343,6 +344,7 @@
> 
> /* Interesting places in the shortcuts bar */
> typedef enum {
>+  SHORTCUTS_DOCUMENTS,
>   SHORTCUTS_HOME,
>   SHORTCUTS_DESKTOP,
>   SHORTCUTS_VOLUMES,
>@@ -1476,6 +1478,42 @@
>   profile_end ("end", NULL);
> }
> 
>+/* Appends the ~/Documents directory to the shortcuts model */
>+static void
>+shortcuts_append_documents (GtkFileChooserDefault *impl)
>+{
>+  char *name;
>+  const char *home;
>+  GtkFilePath *path;
>+
>+  profile_start ("start", NULL);
>+
>+#ifdef G_OS_WIN32
>+  name = _gtk_file_system_win32_get_documents ();
>+#else
>+  home = g_get_home_dir ();
>+  if (home == NULL)
>+    {
>+      profile_end ("end - no home directory!?", NULL);
>+      return;
>+    }
>+  
>+  name = g_build_filename (home, "Documents", NULL);
>+#endif
>+
>+  path = gtk_file_system_filename_to_path (impl->file_system, name);
>+  g_free (name);
>+
>+  impl->has_documents = shortcuts_insert_path (impl, -1, FALSE, NULL, path, _("Documents"), FALSE, NULL);
>+  /* We do not actually pop up an error dialog if there is no documents directory
>+   * because some people may really not want to have one.
>+   */
>+
>+  gtk_file_path_free (path);
>+
>+  profile_end ("end", NULL);
>+}
>+
> /* Appends a list of GtkFilePath to the shortcuts model; returns how many were inserted */
> static int
> shortcuts_append_paths (GtkFileChooserDefault *impl,
>@@ -1527,6 +1565,11 @@
> 
>   n = 0;
> 
>+  if (where == SHORTCUTS_DOCUMENTS)
>+    goto out;
>+
>+  n += impl->has_documents ? 1 : 0;
>+  
>   if (where == SHORTCUTS_HOME)
>     goto out;
> 
>@@ -1875,6 +1918,7 @@
> 
>   if (impl->file_system)
>     {
>+      shortcuts_append_documents (impl);
>       shortcuts_append_home (impl);
>       shortcuts_append_desktop (impl);
>       shortcuts_add_volumes (impl);
>@@ -4773,7 +4817,9 @@
> gtk_file_chooser_default_map (GtkWidget *widget)
> {
>   GtkFileChooserDefault *impl;
>-  char *current_working_dir;
>+  const gchar* envvar;
>+  gchar* default_dir;
>+  const gchar* home;
> 
>   profile_start ("start", NULL);
> 
>@@ -4784,10 +4830,24 @@
>   switch (impl->reload_state)
>     {
>     case RELOAD_EMPTY:
>-      /* The user didn't explicitly give us a folder to display, so we'll use the cwd */
>-      current_working_dir = g_get_current_dir ();
>-      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), current_working_dir);
>-      g_free (current_working_dir);
>+      /* The user didn't explicitly give us a folder to display, so we'll use
>+       * GTK_DEFAULT_FILECHOOSER_DIR, or ~/Documents, or the cwd */
>+      envvar = g_getenv ("GTK_DEFAULT_FILECHOOSER_DIR");
>+      if (envvar && g_file_test (envvar, G_FILE_TEST_IS_DIR))
>+        {
>+          default_dir = g_strdup (envvar);
>+        }
>+      else if (impl->has_documents)
>+        {
>+          home = g_get_home_dir ();
>+          default_dir = g_build_filename (home, "Documents", NULL);
>+        }
>+      else
>+        {
>+          default_dir = g_get_current_dir ();
>+        }
>+      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), default_dir);
>+      g_free (default_dir);
>       break;
> 
>     case RELOAD_HAS_FOLDER:
>@@ -5443,16 +5503,31 @@
> 
>   if (impl->reload_state == RELOAD_EMPTY)
>     {
>-      char *current_working_dir;
>+      const gchar* envvar;
>+      gchar *default_dir;
>+      const gchar *home;
>       GtkFilePath *path;
> 
>-      /* We are unmapped, or we had an error while loading the last folder.  We'll return
>-       * the $cwd since once we get (re)mapped, we'll load $cwd anyway unless the caller
>-       * explicitly calls set_current_folder() on us.
>+      /* We are unmapped, or we had an error while loading the last folder.  We'll do the
>+       * same as in the map method, since that's what will happen when we get (re)mapped,
>+       * unless the caller explicitly calls set_current_folder() on us.
>        */
>-      current_working_dir = g_get_current_dir ();
>-      path = gtk_file_system_filename_to_path (impl->file_system, current_working_dir);
>-      g_free (current_working_dir);
>+      envvar = g_getenv ("GTK_DEFAULT_FILECHOOSER_DIR");
>+      if (envvar && g_file_test (envvar, G_FILE_TEST_IS_DIR))
>+        {
>+          default_dir = g_strdup (envvar);
>+        }
>+      if (!default_dir && impl->has_documents)
>+        {
>+          home = g_get_home_dir ();
>+          default_dir = g_build_filename (home, "Documents", NULL);
>+        }
>+      else if (!default_dir)
>+        {
>+          default_dir = g_get_current_dir ();
>+        }
>+      path = gtk_file_system_filename_to_path (impl->file_system, default_dir);
>+      g_free (default_dir);
>       return path;
>     }
> 
>--- gtk+-2.8.9.orig/gtk/gtkfilesystemwin32.c	2005-11-12 02:15:22.000000000 +0100
>+++ gtk+-2.8.9/gtk/gtkfilesystemwin32.c	2005-12-28 13:06:42.000000000 +0100
>@@ -361,6 +361,12 @@
>   return get_special_folder (CSIDL_DESKTOPDIRECTORY);
> }
> 
>+gchar *
>+_gtk_file_system_win32_get_documents (void)
>+{
>+  return get_special_folder (CSIDL_PERSONAL);
>+}
>+
> static GSList *
> gtk_file_system_win32_list_volumes (GtkFileSystem *file_system)
> {
>  
>




More information about the ubuntu-desktop mailing list