]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilechooserdefault.c
Free volumes not actually put into the shortcut list.
[~andy/gtk] / gtk / gtkfilechooserdefault.c
index 14014180e2325d7efd065df349fb319dc221fc79..8987297667fd8402043ffd0074b524b2b8bfa938 100644 (file)
@@ -138,7 +138,6 @@ struct _GtkFileChooserDefault
 
   GtkFilePath *current_volume_path;
   GtkFilePath *current_folder;
-  GtkFilePath *lowest_folder;
   GtkFilePath *preview_path;
   char *preview_display_name;
 
@@ -1199,6 +1198,10 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
   int start_row;
   GSList *list, *l;
   int n;
+  gboolean old_changing_folders;
+
+  old_changing_folders = impl->changing_folder;
+  impl->changing_folder = TRUE;
 
   start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
   shortcuts_remove_rows (impl, start_row, impl->num_volumes, volume_remove_cb);
@@ -1213,7 +1216,7 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
       GtkFileSystemVolume *volume;
 
       volume = l->data;
-      
+
       if (impl->local_only)
        {
          GtkFilePath *base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
@@ -1221,11 +1224,16 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
          gtk_file_path_free (base_path);
 
          if (!is_local)
-           continue;
+           {
+             gtk_file_system_volume_free (impl->file_system, volume);
+             continue;
+           }
        }
 
-      shortcuts_insert_path (impl, start_row + n, TRUE, volume, NULL, NULL, FALSE, NULL);
-      n++;
+      if (shortcuts_insert_path (impl, start_row + n, TRUE, volume, NULL, NULL, FALSE, NULL))
+       n++;
+      else
+       gtk_file_system_volume_free (impl->file_system, volume);
     }
 
   impl->num_volumes = n;
@@ -1233,6 +1241,8 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
 
   if (impl->shortcuts_filter_model)
     gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model));
+
+  impl->changing_folder = old_changing_folders;
 }
 
 /* Used from shortcuts_remove_rows() */
@@ -1269,6 +1279,10 @@ static void
 shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
 {
   GSList *bookmarks;
+  gboolean old_changing_folders;
+
+  old_changing_folders = impl->changing_folder;
+  impl->changing_folder = TRUE;
 
   if (impl->num_bookmarks > 0)
     {
@@ -1289,6 +1303,8 @@ shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
     }
   if (impl->shortcuts_filter_model)
     gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model));
+
+  impl->changing_folder = old_changing_folders;
 }
 
 /* Appends a separator and a row to the shortcuts list for the current folder */
@@ -1614,42 +1630,30 @@ shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl,
                                  const GtkFilePath     *path,
                                  int                    pos)
 {
-  GtkFileInfo *info;
   GError *error;
-  gboolean result;
 
   if (shortcut_find_position (impl, path) != -1)
     return FALSE;
 
-  result = FALSE;
-
+  /* FIXME: this check really belongs in gtk_file_system_insert_bookmark.  */
   error = NULL;
-  info = get_file_info (impl->file_system, path, FALSE, &error);
-
-  if (!info)
-    error_getting_info_dialog (impl, path, error);
-  else if (!gtk_file_info_get_is_folder (info))
+  if (!check_is_folder (impl->file_system, path, &error))
     {
-      char *msg;
-      char *uri;
-
-      uri = gtk_file_system_path_to_uri (impl->file_system, path);
-      msg = g_strdup_printf (_("Could not add bookmark for %s because it is not a folder."),
-                            uri);
-      error_message (impl, msg);
-      g_free (uri);
-      g_free (msg);
+      error_dialog (impl,
+                   _("Could not add bookmark for %s because it is not a folder."),
+                   path,
+                   error);
+      return FALSE;
     }
-  else
+
+  error = NULL;
+  if (!gtk_file_system_insert_bookmark (impl->file_system, path, pos, &error))
     {
-      error = NULL;
-      if (gtk_file_system_insert_bookmark (impl->file_system, path, pos, &error))
-       result = TRUE;
-      else
-       error_could_not_add_bookmark_dialog (impl, path, error);
+      error_could_not_add_bookmark_dialog (impl, path, error);
+      return FALSE;
     }
 
-  return result;
+  return TRUE;
 }
 
 static void
@@ -3144,8 +3148,7 @@ update_appearance (GtkFileChooserDefault *impl)
        _gtk_file_system_model_set_show_files (impl->browse_files_model, TRUE);
     }
 
-  if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
-      || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+  if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
     gtk_widget_hide (impl->browse_new_folder_button);
   else
     gtk_widget_show (impl->browse_new_folder_button);
@@ -3417,11 +3420,14 @@ check_icon_theme (GtkFileChooserDefault *impl)
   if (impl->settings_signal_id)
     return;
 
-  settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
-  impl->settings_signal_id = g_signal_connect (settings, "notify",
-                                              G_CALLBACK (settings_notify_cb), impl);
+  if (gtk_widget_has_screen (GTK_WIDGET (impl)))
+    {
+      settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
+      impl->settings_signal_id = g_signal_connect (settings, "notify",
+                                                  G_CALLBACK (settings_notify_cb), impl);
 
-  change_icon_theme (impl);
+      change_icon_theme (impl);
+    }
 }
 
 static void
@@ -3689,7 +3695,7 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser    *chooser,
                   GTK_FILE_SYSTEM_ERROR,
                   GTK_FILE_SYSTEM_ERROR_FAILED,
                   _("Can't change to folder because it isn't local"));
-      
+
       return FALSE;
     }
 
@@ -3746,7 +3752,8 @@ gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
 {
   GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
 
-  g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE);
+  g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
+                   || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
 
   gtk_entry_set_text (GTK_ENTRY (impl->save_file_name_entry), name);
 }
@@ -3901,6 +3908,8 @@ get_paths_foreach (GtkTreeModel *model,
   gtk_tree_model_sort_convert_iter_to_child_iter (info->impl->sort_model, &sel_iter, iter);
 
   file_path = _gtk_file_system_model_get_path (GTK_FILE_SYSTEM_MODEL (fs_model), &sel_iter);
+  if (!file_path)
+    return; /* We are on the editable row */
 
   if (!info->path_from_entry
       || gtk_file_path_compare (info->path_from_entry, file_path) != 0)
@@ -4940,11 +4949,17 @@ update_from_entry (GtkFileChooserDefault *impl,
 
       if (!info)
        {
-#if 0
-         if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
-           return;
-#endif
-         error_getting_info_dialog (impl, subfolder_path, error);
+         if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
+             || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
+           {
+             if (!change_folder_and_display_error (impl, folder_path))
+               goto out;
+
+             gtk_file_chooser_default_set_current_name (GTK_FILE_CHOOSER (impl), file_part);
+           }
+         else
+           error_getting_info_dialog (impl, subfolder_path, error);
+
          goto out;
        }
 
@@ -4987,6 +5002,7 @@ location_popup_handler (GtkFileChooserDefault *impl)
   GtkWidget *label;
   GtkWidget *entry;
   gboolean refocus;
+  char *title;
 
   /* Create dialog */
 
@@ -4994,7 +5010,19 @@ location_popup_handler (GtkFileChooserDefault *impl)
   if (!GTK_WIDGET_TOPLEVEL (toplevel))
     toplevel = NULL;
 
-  dialog = gtk_dialog_new_with_buttons (_("Open Location"),
+  if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
+      || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+    {
+      title = _("Open Location");
+    }
+  else
+    {
+      g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
+               || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
+      title = ""; /* FIXME: #137272, fix for 2.4.1 */
+    }
+
+  dialog = gtk_dialog_new_with_buttons (title,
                                        GTK_WINDOW (toplevel),
                                        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
@@ -5026,7 +5054,17 @@ location_popup_handler (GtkFileChooserDefault *impl)
     {
       if (update_from_entry (impl, GTK_WINDOW (dialog), GTK_FILE_CHOOSER_ENTRY (entry)))
        {
-         gtk_widget_grab_focus (impl->browse_files_tree_view);
+         if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
+             || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+           {
+             gtk_widget_grab_focus (impl->browse_files_tree_view);
+           }
+         else
+           {
+             g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
+                       || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
+             gtk_widget_grab_focus (impl->save_file_name_entry);
+           }
          refocus = FALSE;
        }
     }