#define NUM_LINES 45
#define NUM_CHARS 60
-#define SETTINGS_KEY_LAST_FOLDER_URI "last-folder-uri"
-#define SETTINGS_KEY_LOCATION_MODE "location-mode"
-#define SETTINGS_KEY_SHOW_HIDDEN "show-hidden"
-#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"
-#define SETTINGS_KEY_SIDEBAR_WIDTH "sidebar-width"
-
static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface);
static void gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface);
static void gtk_file_chooser_default_style_updated (GtkWidget *widget);
static void gtk_file_chooser_default_screen_changed (GtkWidget *widget,
GdkScreen *previous_screen);
-static void gtk_file_chooser_default_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
static gboolean gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
GFile *folder,
static void update_cell_renderer_attributes (GtkFileChooserDefault *impl);
-static void load_remove_timer (GtkFileChooserDefault *impl);
+static void load_remove_timer (GtkFileChooserDefault *impl, LoadState new_load_state);
static void browse_files_center_selected_row (GtkFileChooserDefault *impl);
static void location_button_toggled_cb (GtkToggleButton *toggle,
widget_class->hierarchy_changed = gtk_file_chooser_default_hierarchy_changed;
widget_class->style_updated = gtk_file_chooser_default_style_updated;
widget_class->screen_changed = gtk_file_chooser_default_screen_changed;
- widget_class->size_allocate = gtk_file_chooser_default_size_allocate;
signals[LOCATION_POPUP] =
g_signal_new_class_handler (I_("location-popup"),
impl->has_search = TRUE;
}
+static gboolean
+shortcuts_get_recent_enabled (GtkWidget *widget)
+{
+ GtkSettings *settings;
+ gboolean enabled;
+
+ if (gtk_widget_has_screen (widget))
+ settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
+ else
+ settings = gtk_settings_get_default ();
+
+ g_object_get (settings, "gtk-recent-files-enabled", &enabled, NULL);
+ return enabled;
+}
+
static void
shortcuts_append_recent (GtkFileChooserDefault *impl)
{
GdkPixbuf *pixbuf;
GtkTreeIter iter;
+ gboolean enabled;
+
+ enabled = shortcuts_get_recent_enabled (GTK_WIDGET (impl));
+ if (!enabled)
+ return;
pixbuf = render_recent_icon (impl);
if (pixbuf)
g_object_unref (pixbuf);
+
+ impl->has_recent = TRUE;
}
/* Appends an item for the user's home directory to the shortcuts model */
if (where == SHORTCUTS_RECENT)
goto out;
- n += 1; /* we always have the recently-used item */
+ n += impl->has_recent ? 1 : 0;
if (where == SHORTCUTS_RECENT_SEPARATOR)
goto out;
pending_select_files_free (impl);
- /* cancel all pending operations */
- if (impl->pending_cancellables)
- {
- for (l = impl->pending_cancellables; l; l = l->next)
- {
- GCancellable *cancellable = G_CANCELLABLE (l->data);
- g_cancellable_cancel (cancellable);
- }
- g_slist_free (impl->pending_cancellables);
- impl->pending_cancellables = NULL;
- }
-
if (impl->reload_icon_cancellables)
{
for (l = impl->reload_icon_cancellables; l; l = l->next)
impl->should_respond_get_info_cancellable = NULL;
}
+ if (impl->file_exists_get_info_cancellable)
+ {
+ g_cancellable_cancel (impl->file_exists_get_info_cancellable);
+ impl->file_exists_get_info_cancellable = NULL;
+ }
+
if (impl->update_from_entry_cancellable)
{
g_cancellable_cancel (impl->update_from_entry_cancellable);
profile_end ("end", NULL);
}
-static void
-gtk_file_chooser_default_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->size_allocate (widget, allocation);
-}
-
static void
set_sort_column (GtkFileChooserDefault *impl)
{
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)
{
gint sort_column;
GtkSortType sort_order;
gint sidebar_width;
+ GSettings *settings;
- settings_ensure (impl);
+ settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
- 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);
- sidebar_width = g_settings_get_int (impl->settings, SETTINGS_KEY_SIDEBAR_WIDTH);
+ location_mode = g_settings_get_enum (settings, SETTINGS_KEY_LOCATION_MODE);
+ show_hidden = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_HIDDEN);
+ show_size_column = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_SIZE_COLUMN);
+ sort_column = g_settings_get_enum (settings, SETTINGS_KEY_SORT_COLUMN);
+ sort_order = g_settings_get_enum (settings, SETTINGS_KEY_SORT_ORDER);
+ sidebar_width = g_settings_get_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH);
location_mode_set (impl, location_mode, TRUE);
gtk_paned_set_position (GTK_PANED (impl->browse_widgets_hpaned), sidebar_width);
}
-static void
-save_dialog_geometry (GtkFileChooserDefault *impl)
-{
- GtkWindow *toplevel;
- int x, y, width, height;
-
- toplevel = get_toplevel (GTK_WIDGET (impl));
-
- if (!(toplevel && GTK_IS_FILE_CHOOSER_DIALOG (toplevel)))
- return;
-
- gtk_window_get_position (toplevel, &x, &y);
- gtk_window_get_size (toplevel, &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)
{
- char *current_folder_uri;
+ GSettings *settings;
- settings_ensure (impl);
-
- /* Current folder */
-
- if (impl->current_folder)
- current_folder_uri = g_file_get_uri (impl->current_folder);
- else
- current_folder_uri = "";
-
- g_settings_set_string (impl->settings, SETTINGS_KEY_LAST_FOLDER_URI, current_folder_uri);
-
- if (impl->current_folder)
- g_free (current_folder_uri);
+ settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
/* All the other state */
- g_settings_set_enum (impl->settings, SETTINGS_KEY_LOCATION_MODE, impl->location_mode);
- g_settings_set_boolean (impl->settings, SETTINGS_KEY_SHOW_HIDDEN,
+ g_settings_set_enum (settings, SETTINGS_KEY_LOCATION_MODE, impl->location_mode);
+ g_settings_set_boolean (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);
- g_settings_set_int (impl->settings, SETTINGS_KEY_SIDEBAR_WIDTH,
+ g_settings_set_boolean (settings, SETTINGS_KEY_SHOW_SIZE_COLUMN, impl->show_size_column);
+ g_settings_set_enum (settings, SETTINGS_KEY_SORT_COLUMN, impl->sort_column);
+ g_settings_set_enum (settings, SETTINGS_KEY_SORT_ORDER, impl->sort_order);
+ g_settings_set_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH,
gtk_paned_get_position (GTK_PANED (impl->browse_widgets_hpaned)));
- save_dialog_geometry (impl);
-
/* Now apply the settings */
- g_settings_apply (impl->settings);
-
- g_object_unref (impl->settings);
- impl->settings = NULL;
+ g_settings_apply (settings);
}
/* GtkWidget::realize method */
emit_default_size_changed (impl);
}
-static GFile *
-get_file_for_last_folder_opened (GtkFileChooserDefault *impl)
-{
- char *last_folder_uri;
- GFile *file;
-
- settings_ensure (impl);
-
- last_folder_uri = g_settings_get_string (impl->settings, SETTINGS_KEY_LAST_FOLDER_URI);
-
- /* If no last folder is set, we use the user's home directory, since
- * this is the starting point for most documents.
- */
- if (last_folder_uri[0] == '\0')
- file = g_file_new_for_path (g_get_home_dir ());
- else
- file = g_file_new_for_uri (last_folder_uri);
-
- g_free (last_folder_uri);
-
- return file;
-}
-
/* GtkWidget::map method */
static void
gtk_file_chooser_default_map (GtkWidget *widget)
impl->load_state = LOAD_PRELOAD;
}
-/* Removes the load timeout and switches to the LOAD_FINISHED state */
+/* Removes the load timeout; changes the impl->load_state to the specified value. */
static void
-load_remove_timer (GtkFileChooserDefault *impl)
+load_remove_timer (GtkFileChooserDefault *impl, LoadState new_load_state)
{
if (impl->load_timeout_id != 0)
{
g_source_remove (impl->load_timeout_id);
impl->load_timeout_id = 0;
- impl->load_state = LOAD_EMPTY;
}
else
g_assert (impl->load_state == LOAD_EMPTY ||
impl->load_state == LOAD_LOADING ||
impl->load_state == LOAD_FINISHED);
+
+ g_assert (new_load_state == LOAD_EMPTY ||
+ new_load_state == LOAD_LOADING ||
+ new_load_state == LOAD_FINISHED);
+ impl->load_state = new_load_state;
}
/* Selects the first row in the file list */
gboolean selected_a_file;
GSList *walk;
+ g_assert (impl->load_state == LOAD_FINISHED);
+ g_assert (impl->browse_files_model != NULL);
+
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
fsmodel = GTK_FILE_SYSTEM_MODEL (gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view)));
+ g_assert (fsmodel == impl->browse_files_model);
+
enabled_hidden = impl->show_hidden;
removed_filters = (impl->current_filter == NULL);
if (impl->load_state == LOAD_PRELOAD)
{
- load_remove_timer (impl);
+ load_remove_timer (impl, LOAD_FINISHED);
load_set_model (impl);
}
else if (impl->load_state == LOAD_LOADING)
stop_loading_and_clear_list_model (GtkFileChooserDefault *impl,
gboolean remove_from_treeview)
{
- load_remove_timer (impl); /* This changes the state to LOAD_EMPTY */
+ load_remove_timer (impl, LOAD_EMPTY);
if (impl->browse_files_model)
{
impl->operation_mode == OPERATION_MODE_RECENT)
return NULL;
- if (impl->reload_state == RELOAD_EMPTY)
- {
- /* We are unmapped, or we had an error while loading the last folder.
- * We'll return the folder used by the last invocation of the file chooser
- * since once we get (re)mapped, we'll load *that* folder anyway unless
- * the caller explicitly calls set_current_folder() on us.
- */
- return get_file_for_last_folder_opened (impl);
- }
-
if (impl->current_folder)
return g_object_ref (impl->current_folder);
GtkFileChooserDefault *impl;
GtkRequisition req;
int x, y, width, height;
+ GSettings *settings;
impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
- settings_ensure (impl);
+ settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (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);
+ g_settings_get (settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", &x, &y);
+ g_settings_get (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", &width, &height);
if (x >= 0 && y >= 0 && width > 0 && height > 0)
{