#include "gtkcellrenderertext.h"
#include "gtkcheckmenuitem.h"
#include "gtkclipboard.h"
-#include "gtkcombobox.h"
+#include "gtkcomboboxtext.h"
#include "gtkentry.h"
#include "gtkexpander.h"
#include "gtkfilechooserprivate.h"
#include "gtkfilechooserdialog.h"
#include "gtkfilechooserembed.h"
#include "gtkfilechooserentry.h"
-#include "gtkfilechoosersettings.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooser.h"
#include "gtkfilesystem.h"
#define NUM_LINES 45
#define NUM_CHARS 60
+#define SETTINGS_KEY_LOCATION_MODE "location-mode"
+#define SETTINGS_KEY_SHOW_HIDDEN "show-hidden"
+#define SETTINGS_KEY_EXPAND_FOLDERS "expand-folders"
+#define SETTINGS_KEY_SHOW_SIZE_COLUMN "show-size-column"
+#define SETTINGS_KEY_SORT_COLUMN "sort-column"
+#define SETTINGS_KEY_SORT_ORDER "sort-order"
+#define SETTINGS_KEY_WINDOW_POSITION "window-position"
+#define SETTINGS_KEY_WINDOW_SIZE "window-size"
+
static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface);
static void gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface);
file, error);
}
+/* Shows an error about not being able to select a folder because a file with
+ * the same name is already there.
+ */
+static void
+error_selecting_folder_over_existing_file_dialog (GtkFileChooserDefault *impl,
+ GFile *file)
+{
+ error_dialog (impl,
+ _("You may only select folders. The item that you selected is not a folder; "
+ "try using a different item."),
+ file, NULL);
+}
+
/* Shows an error dialog about not being able to create a filename */
static void
error_building_filename_dialog (GtkFileChooserDefault *impl,
GtkCellRenderer *cell;
GList *cells;
- impl->filter_combo = gtk_combo_box_new_text ();
+ impl->filter_combo = gtk_combo_box_text_new ();
gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
/* Get the combo's text renderer and set ellipsize parameters */
GtkWidget *hbox;
GtkWidget *widget;
- vbox = gtk_vbox_new (FALSE, 6);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 6);
gtk_widget_show (vbox);
/* Shortcuts tree */
/* Box for buttons */
- hbox = gtk_hbox_new (TRUE, 6);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, TRUE, 6);
gtk_size_group_add_widget (size_group, hbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
- gtk_size_request_get_size (GTK_SIZE_REQUEST (menu),
- &req, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (menu),
+ &req, NULL);
gtk_widget_get_allocation (widget, &allocation);
*x += (allocation.width - req.width) / 2;
GtkWidget *hbox;
GtkWidget *widget;
- vbox = gtk_vbox_new (FALSE, 6);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 6);
gtk_widget_show (vbox);
/* Box for lists and preview */
- hbox = gtk_hbox_new (FALSE, PREVIEW_HBOX_SPACING);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
+ FALSE, PREVIEW_HBOX_SPACING);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
/* Preview */
- impl->preview_box = gtk_vbox_new (FALSE, 12);
+ impl->preview_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 12);
gtk_box_pack_start (GTK_BOX (hbox), impl->preview_box, FALSE, FALSE, 0);
/* Don't show preview box initially */
/* Filter combo */
- impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
+ impl->filter_combo_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 12);
widget = filter_create (impl);
location_switch_to_path_bar (impl);
- vbox = gtk_vbox_new (FALSE, 12);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 12);
table = gtk_table_new (2, 2, FALSE);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
/* size group is used by the [+][-] buttons and the filter combo */
size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
- vbox = gtk_vbox_new (FALSE, 12);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 12);
/* Location widgets */
- impl->browse_path_bar_hbox = gtk_hbox_new (FALSE, 12);
+ impl->browse_path_bar_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 12);
gtk_box_pack_start (GTK_BOX (vbox), impl->browse_path_bar_hbox, FALSE, FALSE, 0);
gtk_widget_show (impl->browse_path_bar_hbox);
/* Box for the location label and entry */
- impl->location_entry_box = gtk_hbox_new (FALSE, 12);
+ impl->location_entry_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 12);
gtk_box_pack_start (GTK_BOX (vbox), impl->location_entry_box, FALSE, FALSE, 0);
impl->location_label = gtk_label_new_with_mnemonic (_("_Location:"));
gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_label, FALSE, FALSE, 0);
/* Paned widget */
- hpaned = gtk_hpaned_new ();
+ hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_show (hpaned);
gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
impl->sort_order);
}
+static void
+settings_ensure (GtkFileChooserDefault *impl)
+{
+ if (impl->settings != NULL)
+ return;
+
+ impl->settings = g_settings_new_with_path ("org.gtk.Settings.FileChooser",
+ "/org/gtk/settings/file-chooser/");
+ g_settings_delay (impl->settings);
+}
+
static void
settings_load (GtkFileChooserDefault *impl)
{
- GtkFileChooserSettings *settings;
LocationMode location_mode;
gboolean show_hidden;
gboolean expand_folders;
gint sort_column;
GtkSortType sort_order;
- settings = _gtk_file_chooser_settings_new ();
-
- location_mode = _gtk_file_chooser_settings_get_location_mode (settings);
- show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings);
- expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings);
- show_size_column = _gtk_file_chooser_settings_get_show_size_column (settings);
- sort_column = _gtk_file_chooser_settings_get_sort_column (settings);
- sort_order = _gtk_file_chooser_settings_get_sort_order (settings);
+ settings_ensure (impl);
- g_object_unref (settings);
+ expand_folders = g_settings_get_boolean (impl->settings, SETTINGS_KEY_EXPAND_FOLDERS);
+ location_mode = g_settings_get_enum (impl->settings, SETTINGS_KEY_LOCATION_MODE);
+ show_hidden = g_settings_get_boolean (impl->settings, SETTINGS_KEY_SHOW_HIDDEN);
+ show_size_column = g_settings_get_boolean (impl->settings, SETTINGS_KEY_SHOW_SIZE_COLUMN);
+ sort_column = g_settings_get_enum (impl->settings, SETTINGS_KEY_SORT_COLUMN);
+ sort_order = g_settings_get_enum (impl->settings, SETTINGS_KEY_SORT_ORDER);
location_mode_set (impl, location_mode, TRUE);
}
static void
-save_dialog_geometry (GtkFileChooserDefault *impl, GtkFileChooserSettings *settings)
+save_dialog_geometry (GtkFileChooserDefault *impl)
{
GtkWindow *toplevel;
int x, y, width, height;
gtk_window_get_position (toplevel, &x, &y);
gtk_window_get_size (toplevel, &width, &height);
- _gtk_file_chooser_settings_set_geometry (settings, x, y, width, height);
+ g_settings_set (impl->settings, "window-position", "(ii)", x, y);
+ g_settings_set (impl->settings, "window-size", "(ii)", width, height);
}
static void
settings_save (GtkFileChooserDefault *impl)
{
- GtkFileChooserSettings *settings;
+ settings_ensure (impl);
- settings = _gtk_file_chooser_settings_new ();
+ g_settings_set_enum (impl->settings, SETTINGS_KEY_LOCATION_MODE, impl->location_mode);
+ g_settings_set_boolean (impl->settings, SETTINGS_KEY_EXPAND_FOLDERS, impl->expand_folders);
+ g_settings_set_boolean (impl->settings, SETTINGS_KEY_SHOW_HIDDEN,
+ gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
+ g_settings_set_boolean (impl->settings, SETTINGS_KEY_SHOW_SIZE_COLUMN, impl->show_size_column);
+ g_settings_set_enum (impl->settings, SETTINGS_KEY_SORT_COLUMN, impl->sort_column);
+ g_settings_set_enum (impl->settings, SETTINGS_KEY_SORT_ORDER, impl->sort_order);
- _gtk_file_chooser_settings_set_location_mode (settings, impl->location_mode);
- _gtk_file_chooser_settings_set_show_hidden (settings, gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
- _gtk_file_chooser_settings_set_expand_folders (settings, impl->expand_folders);
- _gtk_file_chooser_settings_set_show_size_column (settings, impl->show_size_column);
- _gtk_file_chooser_settings_set_sort_column (settings, impl->sort_column);
- _gtk_file_chooser_settings_set_sort_order (settings, impl->sort_order);
+ save_dialog_geometry (impl);
- save_dialog_geometry (impl, settings);
+ /* Now apply the settings */
+ g_settings_apply (impl->settings);
- /* NULL GError */
- _gtk_file_chooser_settings_save (settings, NULL);
-
- g_object_unref (settings);
+ g_object_unref (impl->settings);
+ impl->settings = NULL;
}
/* GtkWidget::realize method */
if (_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
{
+ GtkTreePath *path;
+
gtk_tree_selection_select_iter (selection, &iter);
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (fsmodel), &iter);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view),
+ path, NULL, FALSE);
+ gtk_tree_path_free (path);
+
selected_a_file = TRUE;
}
}
if (!name)
name = "Untitled filter"; /* Place-holder, doesn't need to be marked for translation */
- gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (impl->filter_combo), name);
if (!g_slist_find (impl->filters, impl->current_filter))
set_current_filter (impl, filter);
|| impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
|| impl->expand_folders)
{
- GtkFileChooserSettings *settings;
int x, y, width, height;
- settings = _gtk_file_chooser_settings_new ();
- _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
- g_object_unref (settings);
+ settings_ensure (impl);
+
+ g_settings_get (impl->settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", &x, &y);
+ g_settings_get (impl->settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", &width, &height);
if (x >= 0 && y >= 0 && width > 0 && height > 0)
{
impl->preview_widget &&
gtk_widget_get_visible (impl->preview_widget))
{
- gtk_size_request_get_size (GTK_SIZE_REQUEST (impl->preview_box),
- &req, NULL);
+ gtk_widget_get_preferred_size (impl->preview_box,
+ &req, NULL);
*default_width += PREVIEW_HBOX_SPACING + req.width;
}
if (impl->extra_widget &&
gtk_widget_get_visible (impl->extra_widget))
{
- gtk_size_request_get_size (GTK_SIZE_REQUEST (impl->extra_align),
- &req, NULL);
+ gtk_widget_get_preferred_size (impl->extra_align,
+ &req, NULL);
*default_height += gtk_box_get_spacing (GTK_BOX (chooser_embed)) + req.height;
}
}
else
{
- gtk_size_request_get_size (GTK_SIZE_REQUEST (impl),
- &req, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (impl),
+ &req, NULL);
*default_width = req.width;
*default_height = req.height;
}
};
static void
-save_entry_get_info_cb (GCancellable *cancellable,
- GFileInfo *info,
- const GError *error,
- gpointer user_data)
+name_entry_get_parent_info_cb (GCancellable *cancellable,
+ GFileInfo *info,
+ const GError *error,
+ gpointer user_data)
{
gboolean parent_is_folder;
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
else
g_signal_emit_by_name (data->impl, "response-requested");
}
- else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
+ else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
+ || data->impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
{
GError *error = NULL;
+ /* In both cases (SELECT_FOLDER and CREATE_FOLDER), if you type
+ * "/blah/nonexistent" you *will* want a folder created.
+ */
+
set_busy_cursor (data->impl, TRUE);
g_file_make_directory (data->file, NULL, &error);
set_busy_cursor (data->impl, FALSE);
else
error_creating_folder_dialog (data->impl, data->file, error);
}
+ else
+ g_assert_not_reached ();
}
else
{
{
gboolean data_ownership_taken = FALSE;
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- gboolean file_exists_and_is_not_folder;
+ gboolean file_exists;
+ gboolean is_folder;
+ gboolean needs_file_type_check = FALSE;
struct FileExistsData *data = user_data;
if (cancellable != data->impl->file_exists_get_info_cancellable)
if (cancelled)
goto out;
- file_exists_and_is_not_folder = info && (! _gtk_file_info_consider_as_directory (info));
+ file_exists = (info != NULL);
+ is_folder = (file_exists && _gtk_file_info_consider_as_directory (info));
if (data->impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
- /* user typed a filename; we are done */
- g_signal_emit_by_name (data->impl, "response-requested");
- else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
- && file_exists_and_is_not_folder)
{
- /* Oops, the user typed the name of an existing path which is not
- * a folder
- */
- error_creating_folder_over_existing_file_dialog (data->impl, data->file,
- g_error_copy (error));
+ if (is_folder)
+ change_folder_and_display_error (data->impl, data->file, TRUE);
+ else
+ {
+ /* user typed a filename; we are done */
+ g_signal_emit_by_name (data->impl, "response-requested");
+ }
+ }
+ else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
+ {
+ if (file_exists && !is_folder)
+ {
+ /* Oops, the user typed the name of an existing path which is not
+ * a folder
+ */
+ error_creating_folder_over_existing_file_dialog (data->impl, data->file,
+ g_error_copy (error));
+ }
+ else
+ {
+ needs_file_type_check = TRUE;
+ }
+ }
+ else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+ {
+ if (!file_exists)
+ {
+ needs_file_type_check = TRUE;
+ }
+ else
+ {
+ if (is_folder)
+ {
+ /* User typed a folder; we are done */
+ g_signal_emit_by_name (data->impl, "response-requested");
+ }
+ else
+ error_selecting_folder_over_existing_file_dialog (data->impl, data->file);
+ }
+ }
+ else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+ {
+ if (is_folder)
+ change_folder_and_display_error (data->impl, data->file, TRUE);
+ else
+ needs_file_type_check = TRUE;
}
else
{
- /* check that everything up to the last component exists */
+ g_assert_not_reached();
+ }
- data->file_exists_and_is_not_folder = file_exists_and_is_not_folder;
- data_ownership_taken = TRUE;
+ if (needs_file_type_check) {
+ /* check that everything up to the last component exists */
- if (data->impl->should_respond_get_info_cancellable)
- g_cancellable_cancel (data->impl->should_respond_get_info_cancellable);
+ data->file_exists_and_is_not_folder = file_exists && !is_folder;
+ data_ownership_taken = TRUE;
+
+ if (data->impl->should_respond_get_info_cancellable)
+ g_cancellable_cancel (data->impl->should_respond_get_info_cancellable);
data->impl->should_respond_get_info_cancellable =
_gtk_file_system_get_info (data->impl->file_system,
data->parent_file,
"standard::type",
- save_entry_get_info_cb,
+ name_entry_get_parent_info_cb,
data);
set_busy_cursor (data->impl, TRUE);
}
{
struct FileExistsData *data;
- /* We need to check whether file exists and is not a folder */
+ /* We need to check whether file exists and whether it is a folder -
+ * the GtkFileChooserEntry *does* report is_folder==FALSE as a false
+ * negative (it doesn't know yet if your last path component is a
+ * folder).
+ */
data = g_new0 (struct FileExistsData, 1);
data->impl = g_object_ref (impl);
GtkWidget *image;
gchar *tmp;
- impl->search_hbox = gtk_hbox_new (FALSE, 12);
+ impl->search_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 12);
/* Image */
GtkWidget *image;
gchar *tmp;
- impl->recent_hbox = gtk_hbox_new (FALSE, 12);
+ impl->recent_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 12);
/* Image */
image = gtk_image_new_from_icon_name ("document-open-recent", GTK_ICON_SIZE_BUTTON);