#include "gtkfilechooserdefault.h"
-#include "gdk/gdkkeysyms.h"
#include "gtkalignment.h"
#include "gtkbindings.h"
#include "gtkcelllayout.h"
#include "gtksizerequest.h"
#include "gtkstock.h"
#include "gtktable.h"
+#include "gtktoolbar.h"
+#include "gtktoolbutton.h"
#include "gtktooltip.h"
#include "gtktreednd.h"
#include "gtktreeprivate.h"
static void gtk_file_chooser_default_unmap (GtkWidget *widget);
static void gtk_file_chooser_default_hierarchy_changed (GtkWidget *widget,
GtkWidget *previous_toplevel);
-static void gtk_file_chooser_default_style_set (GtkWidget *widget,
- GtkStyle *previous_style);
+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,
G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER_EMBED,
gtk_file_chooser_embed_default_iface_init));
+
+static void
+add_normal_and_shifted_binding (GtkBindingSet *binding_set,
+ guint keyval,
+ GdkModifierType modifiers,
+ const gchar *signal_name)
+{
+ gtk_binding_entry_add_signal (binding_set,
+ keyval, modifiers,
+ signal_name, 0);
+
+ gtk_binding_entry_add_signal (binding_set,
+ keyval, modifiers | GDK_SHIFT_MASK,
+ signal_name, 0);
+}
+
static void
_gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
{
widget_class->map = gtk_file_chooser_default_map;
widget_class->unmap = gtk_file_chooser_default_unmap;
widget_class->hierarchy_changed = gtk_file_chooser_default_hierarchy_changed;
- widget_class->style_set = gtk_file_chooser_default_style_set;
+ 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;
GDK_KEY_v, GDK_CONTROL_MASK,
"location-popup-on-paste",
0);
- gtk_binding_entry_add_signal (binding_set,
- GDK_KEY_Up, GDK_MOD1_MASK,
- "up-folder",
- 0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_BackSpace, 0,
"up-folder",
0);
- gtk_binding_entry_add_signal (binding_set,
- GDK_KEY_KP_Up, GDK_MOD1_MASK,
- "up-folder",
- 0);
- gtk_binding_entry_add_signal (binding_set,
- GDK_KEY_Down, GDK_MOD1_MASK,
- "down-folder",
- 0);
- gtk_binding_entry_add_signal (binding_set,
- GDK_KEY_KP_Down, GDK_MOD1_MASK,
- "down-folder",
- 0);
+ add_normal_and_shifted_binding (binding_set,
+ GDK_KEY_Up, GDK_MOD1_MASK,
+ "up-folder");
+
+ add_normal_and_shifted_binding (binding_set,
+ GDK_KEY_KP_Up, GDK_MOD1_MASK,
+ "up-folder");
+
+ add_normal_and_shifted_binding (binding_set,
+ GDK_KEY_Down, GDK_MOD1_MASK,
+ "down-folder");
+ add_normal_and_shifted_binding (binding_set,
+ GDK_KEY_KP_Down, GDK_MOD1_MASK,
+ "down-folder");
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_Home, GDK_MOD1_MASK,
file, error);
}
+static void
+error_with_file_under_nonfolder (GtkFileChooserDefault *impl,
+ GFile *parent_file)
+{
+ GError *error;
+
+ error = NULL;
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY,
+ _("You need to choose a valid filename."));
+
+ error_dialog (impl,
+ _("Cannot create a file under %s as it is not a folder"),
+ parent_file, error);
+}
+
/* Shows an error about not being able to select a folder because a file with
* the same name is already there.
*/
static GdkPixbuf *
render_search_icon (GtkFileChooserDefault *impl)
{
- return gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL);
+ return gtk_widget_render_icon_pixbuf (GTK_WIDGET (impl), GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
}
static GdkPixbuf *
/* fallback */
if (!retval)
- retval = gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
+ retval = gtk_widget_render_icon_pixbuf (GTK_WIDGET (impl), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
return retval;
}
pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->impl), data->impl->icon_size);
path = gtk_tree_row_reference_get_path (data->row_ref);
- gtk_tree_model_get_iter (GTK_TREE_MODEL (data->impl->shortcuts_model), &iter, path);
- gtk_list_store_set (data->impl->shortcuts_model, &iter,
- SHORTCUTS_COL_PIXBUF, pixbuf,
- -1);
- gtk_tree_path_free (path);
+ if (path)
+ {
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (data->impl->shortcuts_model), &iter, path);
+ gtk_list_store_set (data->impl->shortcuts_model, &iter,
+ SHORTCUTS_COL_PIXBUF, pixbuf,
+ -1);
+ gtk_tree_path_free (path);
+ }
if (pixbuf)
g_object_unref (pixbuf);
g_object_unref (combo_selected);
}
-
+
impl->changing_folder = old_changing_folders;
profile_end ("end", NULL);
shortcuts_add_current_folder (GtkFileChooserDefault *impl)
{
int pos;
- gboolean success;
g_assert (!impl->shortcuts_current_folder_active);
- success = TRUE;
-
g_assert (impl->current_folder != NULL);
pos = shortcut_find_position (impl, impl->current_folder);
GFile *base_file;
/* Separator */
-
shortcuts_insert_separator (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
/* Item */
-
pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER);
volume = _gtk_file_system_get_volume_for_file (impl->file_system, impl->current_folder);
if (volume)
- base_file = _gtk_file_system_volume_get_root (volume);
+ base_file = _gtk_file_system_volume_get_root (volume);
else
- base_file = NULL;
+ base_file = NULL;
if (base_file && g_file_equal (base_file, impl->current_folder))
- shortcuts_insert_file (impl, pos, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
+ shortcuts_insert_file (impl, pos, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
else
- shortcuts_insert_file (impl, pos, SHORTCUT_TYPE_FILE, NULL, impl->current_folder, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
+ shortcuts_insert_file (impl, pos, SHORTCUT_TYPE_FILE, NULL, impl->current_folder, NULL, FALSE, SHORTCUTS_CURRENT_FOLDER);
if (base_file)
- g_object_unref (base_file);
+ g_object_unref (base_file);
}
else if (impl->save_folder_combo != NULL)
{
gtk_tree_path_free (path);
}
+static GSource *
+add_idle_while_impl_is_alive (GtkFileChooserDefault *impl, GCallback callback)
+{
+ GSource *source;
+
+ source = g_idle_source_new ();
+ g_source_set_closure (source,
+ g_cclosure_new_object (callback, G_OBJECT (impl)));
+ g_source_attach (source, NULL);
+
+ return source;
+}
+
/* Idle handler for creating a new folder after editing its name cell, or for
* canceling the editing.
*/
*/
if (!impl->edited_idle)
- {
- impl->edited_idle = g_idle_source_new ();
- g_source_set_closure (impl->edited_idle,
- g_cclosure_new_object (G_CALLBACK (edited_idle_cb),
- G_OBJECT (impl)));
- g_source_attach (impl->edited_idle, NULL);
- }
+ impl->edited_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (edited_idle_cb));
g_free (impl->edited_new_text);
impl->edited_new_text = g_strdup (new_text);
}
static GtkWidget *
-button_new (GtkFileChooserDefault *impl,
- const char *text,
- const char *stock_id,
- gboolean sensitive,
- gboolean show,
- GCallback callback)
+toolbutton_new (GtkFileChooserDefault *impl,
+ GIcon *icon,
+ gboolean sensitive,
+ gboolean show,
+ GCallback callback)
{
- GtkWidget *button;
+ GtkToolItem *item;
GtkWidget *image;
- button = gtk_button_new_with_mnemonic (text);
- image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (button), image);
+ item = gtk_tool_button_new (NULL, NULL);
+ image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_SMALL_TOOLBAR);
+ gtk_widget_show (image);
+ gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
- gtk_widget_set_sensitive (button, sensitive);
- g_signal_connect (button, "clicked", callback, impl);
+ gtk_widget_set_sensitive (GTK_WIDGET (item), sensitive);
+ g_signal_connect (item, "clicked", callback, impl);
if (show)
- gtk_widget_show (button);
+ gtk_widget_show (GTK_WIDGET (item));
- return button;
+ return GTK_WIDGET (item);
}
/* Looks for a path among the shortcuts; returns its index or -1 if it doesn't exist */
#if 0
if (gtk_drag_get_source_widget (context) == widget && !impl->shortcuts_drag_outside_idle)
{
- impl->shortcuts_drag_outside_idle = g_idle_source_new ();
- g_source_set_closure (impl->shortcuts_drag_outside_idle,
- g_cclosure_new_object (G_CALLBACK (shortcuts_drag_outside_idle_cb),
- G_OBJECT (impl)));
- g_source_attach (impl->shortcuts_drag_outside_idle, NULL);
+ impl->shortcuts_drag_outside_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (shortcuts_drag_outside_idle_cb));
}
#endif
GdkRectangle cell;
int row;
int bookmarks_index;
+ int header_height = 0;
tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
+ if (gtk_tree_view_get_headers_visible (tree_view))
+ header_height = _gtk_tree_view_get_header_height (tree_view);
+
bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
if (!gtk_tree_view_get_path_at_pos (tree_view,
x,
- y - TREE_VIEW_HEADER_HEIGHT (tree_view),
+ y - header_height,
path,
&column,
NULL,
}
#endif
- if (context->suggested_action == GDK_ACTION_COPY ||
- (context->actions & GDK_ACTION_COPY) != 0)
+ if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_COPY ||
+ (gdk_drag_context_get_actions (context) & GDK_ACTION_COPY) != 0)
action = GDK_ACTION_COPY;
- else if (context->suggested_action == GDK_ACTION_MOVE ||
- (context->actions & GDK_ACTION_MOVE) != 0)
+ else if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_MOVE ||
+ (gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
action = GDK_ACTION_MOVE;
else
{
GtkFileChooserDefault *impl;
GtkTreePath *tree_path;
GtkTreeViewDropPosition tree_pos;
+ GdkAtom target;
int position;
int bookmarks_index;
g_assert (position >= bookmarks_index);
position -= bookmarks_index;
- if (gtk_targets_include_uri (&selection_data->target, 1))
+ target = gtk_selection_data_get_target (selection_data);
+
+ if (gtk_targets_include_uri (&target, 1))
shortcuts_drop_uris (impl, selection_data, position);
- else if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
+ else if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
shortcuts_reorder (impl, position);
g_signal_stop_emission_by_name (widget, "drag-data-received");
NULL);
renderer = gtk_cell_renderer_text_new ();
- g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
- g_signal_connect (renderer, "edited",
+ g_object_set (renderer,
+ "width-chars", 12,
+ "ellipsize", PANGO_ELLIPSIZE_END,
+ NULL);
+ g_signal_connect (renderer, "edited",
G_CALLBACK (shortcuts_edited), impl);
- g_signal_connect (renderer, "editing-canceled",
+ g_signal_connect (renderer, "editing-canceled",
G_CALLBACK (shortcuts_editing_canceled), impl);
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_set_attributes (column, renderer,
GtkSizeGroup *size_group)
{
GtkWidget *vbox;
- GtkWidget *hbox;
+ GtkWidget *toolbar;
GtkWidget *widget;
+ GtkStyleContext *context;
+ GIcon *icon;
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_show (vbox);
/* Shortcuts tree */
widget = shortcuts_list_create (impl);
+
+ gtk_size_group_add_widget (size_group, widget);
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
+
gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
/* Box for buttons */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
- gtk_size_group_add_widget (size_group, hbox);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
- gtk_widget_show (hbox);
+ toolbar = gtk_toolbar_new ();
+ gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU);
- /* Add bookmark button */
+ context = gtk_widget_get_style_context (toolbar);
+ gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR);
+
+ gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
+ gtk_widget_show (toolbar);
- impl->browse_shortcuts_add_button = button_new (impl,
- _("_Add"),
- GTK_STOCK_ADD,
- FALSE,
- TRUE,
- G_CALLBACK (add_bookmark_button_clicked_cb));
- gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_add_button, TRUE, TRUE, 0);
+ /* Add bookmark button */
+ icon = g_themed_icon_new_with_default_fallbacks ("list-add-symbolic");
+ impl->browse_shortcuts_add_button = toolbutton_new (impl,
+ icon,
+ FALSE,
+ TRUE,
+ G_CALLBACK (add_bookmark_button_clicked_cb));
+ g_object_unref (icon);
+
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (impl->browse_shortcuts_add_button), 0);
gtk_widget_set_tooltip_text (impl->browse_shortcuts_add_button,
_("Add the selected folder to the Bookmarks"));
/* Remove bookmark button */
-
- impl->browse_shortcuts_remove_button = button_new (impl,
- _("_Remove"),
- GTK_STOCK_REMOVE,
- FALSE,
- TRUE,
- G_CALLBACK (remove_bookmark_button_clicked_cb));
- gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_remove_button, TRUE, TRUE, 0);
+ icon = g_themed_icon_new_with_default_fallbacks ("list-remove-symbolic");
+ impl->browse_shortcuts_remove_button = toolbutton_new (impl,
+ icon,
+ FALSE,
+ TRUE,
+ G_CALLBACK (remove_bookmark_button_clicked_cb));
+ g_object_unref (icon);
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (impl->browse_shortcuts_remove_button), 1);
gtk_widget_set_tooltip_text (impl->browse_shortcuts_remove_button,
_("Remove the selected bookmark"));
}
static void
-file_list_drag_data_received_cb (GtkWidget *widget,
- GdkDragContext *context,
- gint x,
- gint y,
- GtkSelectionData *selection_data,
- guint info,
- guint time_,
- gpointer data)
+file_list_drag_data_received_cb (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time_,
+ gpointer data)
{
GtkFileChooserDefault *impl;
- GtkFileChooser *chooser;
gchar **uris;
char *uri;
GFile *file;
impl = GTK_FILE_CHOOSER_DEFAULT (data);
- chooser = GTK_FILE_CHOOSER (data);
/* Allow only drags from other widgets; see bug #533891. */
if (gtk_drag_get_source_widget (context) == widget)
data->file = file;
if (impl->file_list_drag_data_received_cancellable)
- g_cancellable_cancel (impl->file_list_drag_data_received_cancellable);
+ g_cancellable_cancel (impl->file_list_drag_data_received_cancellable);
impl->file_list_drag_data_received_cancellable =
- _gtk_file_system_get_info (impl->file_system, file,
- "standard::type",
- file_list_drag_data_received_get_info_cb,
- data);
+ _gtk_file_system_get_info (impl->file_system, file,
+ "standard::type",
+ file_list_drag_data_received_get_info_cb,
+ data);
}
g_signal_stop_emission_by_name (widget, "drag-data-received");
GtkFileChooserDefault *impl)
{
static gboolean in_press = FALSE;
- gboolean handled;
if (in_press)
return FALSE;
return FALSE;
in_press = TRUE;
- handled = gtk_widget_event (impl->browse_files_tree_view, (GdkEvent *) event);
+ gtk_widget_event (impl->browse_files_tree_view, (GdkEvent *) event);
in_press = FALSE;
file_list_popup_menu (impl, event);
widget = create_file_list (impl);
gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
+ gtk_size_group_add_widget (size_group, widget);
/* Preview */
gtk_widget_show (widget);
gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox), widget, FALSE, FALSE, 0);
- gtk_size_group_add_widget (size_group, impl->filter_combo_hbox);
gtk_box_pack_end (GTK_BOX (vbox), impl->filter_combo_hbox, FALSE, FALSE, 0);
return vbox;
GtkWidget *widget;
GtkSizeGroup *size_group;
- /* size group is used by the [+][-] buttons and the filter combo */
+ /* size group is used by the scrolled windows of the panes */
size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_label, FALSE, FALSE, 0);
/* Paned widget */
+
hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_show (hpaned);
gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
gtk_paned_pack1 (GTK_PANED (hpaned), widget, FALSE, FALSE);
widget = file_pane_create (impl, size_group);
gtk_paned_pack2 (GTK_PANED (hpaned), widget, TRUE, FALSE);
-
+ gtk_paned_set_position (GTK_PANED (hpaned), 148);
g_object_unref (size_group);
return vbox;
GtkWidget *toplevel;
impl = GTK_FILE_CHOOSER_DEFAULT (widget);
+ toplevel = gtk_widget_get_toplevel (widget);
- if (previous_toplevel)
+ if (previous_toplevel &&
+ impl->toplevel_set_focus_id != 0)
{
- g_assert (impl->toplevel_set_focus_id != 0);
g_signal_handler_disconnect (previous_toplevel,
impl->toplevel_set_focus_id);
impl->toplevel_set_focus_id = 0;
impl->toplevel_last_focus_widget = NULL;
}
- else
- g_assert (impl->toplevel_set_focus_id == 0);
- toplevel = gtk_widget_get_toplevel (widget);
- if (GTK_IS_WINDOW (toplevel))
+ if (gtk_widget_is_toplevel (toplevel))
{
+ g_assert (impl->toplevel_set_focus_id == 0);
impl->toplevel_set_focus_id = g_signal_connect (toplevel, "set-focus",
G_CALLBACK (toplevel_set_focus_cb), impl);
impl->toplevel_last_focus_widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
}
static void
-gtk_file_chooser_default_style_set (GtkWidget *widget,
- GtkStyle *previous_style)
+gtk_file_chooser_default_style_updated (GtkWidget *widget)
{
GtkFileChooserDefault *impl;
impl = GTK_FILE_CHOOSER_DEFAULT (widget);
- profile_msg (" parent class style_set start", NULL);
- GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->style_set (widget, previous_style);
- profile_msg (" parent class style_set end", NULL);
+ profile_msg (" parent class style_udpated start", NULL);
+ GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->style_updated (widget);
+ profile_msg (" parent class style_updated end", NULL);
if (gtk_widget_has_screen (GTK_WIDGET (impl)))
change_icon_theme (impl);
static void
gtk_file_chooser_default_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+ GtkAllocation *allocation)
{
- GtkFileChooserDefault *impl;
-
- impl = GTK_FILE_CHOOSER_DEFAULT (widget);
-
GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->size_allocate (widget, allocation);
}
GtkTreeSortable *sortable;
sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view)));
+
/* can happen when we're still populating the model */
if (sortable == NULL)
return;
gdk_display_flush (display);
if (cursor)
- gdk_cursor_unref (cursor);
+ g_object_unref (cursor);
}
/* Creates a sort model to wrap the file system model and sets it on the tree view */
{
GtkTreeSelection *selection;
GtkFileSystemModel *fsmodel;
- gboolean can_have_hidden, can_have_filtered, selected_a_file;
+ gboolean enabled_hidden, removed_filters;
+ gboolean selected_a_file;
GSList *walk;
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)));
- can_have_hidden = !impl->show_hidden;
- can_have_filtered = impl->current_filter != NULL;
+
+ enabled_hidden = impl->show_hidden;
+ removed_filters = (impl->current_filter == NULL);
+
selected_a_file = FALSE;
- for (walk = files; walk && (can_have_hidden || can_have_filtered); walk = walk->next)
+ for (walk = files; walk; walk = walk->next)
{
GFile *file = walk->data;
GtkTreeIter iter;
+ /* Is it a hidden file? */
+
if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
continue;
{
GFileInfo *info = _gtk_file_system_model_get_info (fsmodel, &iter);
- if (can_have_hidden &&
+ if (!enabled_hidden &&
(g_file_info_get_is_hidden (info) ||
g_file_info_get_is_backup (info)))
{
g_object_set (impl, "show-hidden", TRUE, NULL);
- can_have_hidden = FALSE;
- }
-
- if (can_have_filtered)
- {
- set_current_filter (impl, NULL);
- can_have_filtered = FALSE;
+ enabled_hidden = TRUE;
}
}
+
+ /* Is it a filtered file? */
+
+ if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
+ continue; /* re-get the iter as it may change when the model refilters */
+
+ if (!_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
+ {
+ /* Maybe we should have a way to ask the fsmodel if it had filtered a file */
+ if (!removed_filters)
+ {
+ set_current_filter (impl, NULL);
+ removed_filters = TRUE;
+ }
+ }
+
+ /* Okay, can we select the file now? */
+ if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
+ continue;
+
if (_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
{
GtkTreePath *path;
{
GtkTreeSelection *selection;
struct update_chooser_entry_selected_foreach_closure closure;
- const char *file_part;
/* no need to update the file chooser's entry if there's no entry */
if (impl->operation_mode == OPERATION_MODE_SEARCH ||
return;
if (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
- || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
- || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
- || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
- && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)))
+ || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
+ || ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
+ || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+ && impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)))
return;
g_assert (impl->location_entry != NULL);
closure.num_selected = 0;
gtk_tree_selection_selected_foreach (selection, update_chooser_entry_selected_foreach, &closure);
- file_part = NULL;
-
if (closure.num_selected == 0)
{
goto maybe_clear_entry;
info = _gtk_file_system_model_get_info (impl->browse_files_model, &closure.first_selected_iter);
- /* If the cursor moved to the row of the newly created folder,
+ /* If the cursor moved to the row of the newly created folder,
* retrieving info will return NULL.
*/
if (!info)
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
- impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
- {
- /* We don't want the name to change when clicking on a folder... */
- change_entry = (! _gtk_file_info_consider_as_directory (info));
- }
+ impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
+ {
+ /* Don't change the name when clicking on a folder... */
+ change_entry = (! _gtk_file_info_consider_as_directory (info));
+ }
else
- change_entry = TRUE; /* ... unless we are in SELECT_FOLDER mode */
+ change_entry = TRUE; /* ... unless we are in SELECT_FOLDER mode */
if (change_entry)
{
else
{
g_assert (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
- impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER));
+ impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER));
/* Multiple selection, so just clear the entry. */
-
g_free (impl->browse_files_last_selected_name);
impl->browse_files_last_selected_name = NULL;
entry_text = gtk_entry_get_text (GTK_ENTRY (impl->location_entry));
len = strlen (entry_text);
if (len != 0)
- {
- /* The file chooser entry may have appended a "/" to its text. So
- * take it out, and compare the result to the old selection.
- */
- if (entry_text[len - 1] == G_DIR_SEPARATOR)
- {
- char *tmp;
+ {
+ /* The file chooser entry may have appended a "/" to its text.
+ * So take it out, and compare the result to the old selection.
+ */
+ if (entry_text[len - 1] == G_DIR_SEPARATOR)
+ {
+ gchar *tmp;
- tmp = g_strndup (entry_text, len - 1);
- clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, tmp) == 0);
- g_free (tmp);
- }
- else
- clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, entry_text) == 0);
- }
+ tmp = g_strndup (entry_text, len - 1);
+ clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, tmp) == 0);
+ g_free (tmp);
+ }
+ else
+ clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, entry_text) == 0);
+ }
else
- clear_entry = FALSE;
+ clear_entry = FALSE;
if (clear_entry)
- _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
+ _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), "");
}
}
/* Guesses a size based upon font sizes */
static void
find_good_size_from_style (GtkWidget *widget,
- gint *width,
- gint *height)
+ gint *width,
+ gint *height)
{
- GtkFileChooserDefault *impl;
- GtkStyle *style;
+ GtkStyleContext *context;
+ GtkStateFlags state;
int font_size;
GdkScreen *screen;
double resolution;
- style = gtk_widget_get_style (widget);
-
- g_assert (style != NULL);
- impl = GTK_FILE_CHOOSER_DEFAULT (widget);
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
screen = gtk_widget_get_screen (widget);
if (screen)
{
resolution = gdk_screen_get_resolution (screen);
if (resolution < 0.0) /* will be -1 if the resolution is not defined in the GdkScreen */
- resolution = 96.0;
+ resolution = 96.0;
}
else
resolution = 96.0; /* wheeee */
- font_size = pango_font_description_get_size (style->font_desc);
+ font_size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
font_size = PANGO_PIXELS (font_size) * resolution / 72.0;
*width = font_size * NUM_CHARS;
if (parent_is_folder)
{
- if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+ if (data->impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
+ {
+ g_signal_emit_by_name (data->impl, "response-requested"); /* even if the file doesn't exist, apps can make good use of that (e.g. Emacs) */
+ }
+ else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
{
if (data->file_exists_and_is_not_folder)
{
else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
|| data->impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
{
- GError *error = NULL;
+ GError *mkdir_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);
+ g_file_make_directory (data->file, NULL, &mkdir_error);
set_busy_cursor (data->impl, FALSE);
- if (!error)
+ if (!mkdir_error)
g_signal_emit_by_name (data->impl, "response-requested");
else
- error_creating_folder_dialog (data->impl, data->file, error);
+ error_creating_folder_dialog (data->impl, data->file, mkdir_error);
}
else
g_assert_not_reached ();
}
else
{
- /* This will display an error, which is what we want */
- change_folder_and_display_error (data->impl, data->parent_file, FALSE);
+ if (info)
+ {
+ /* The parent exists, but it's not a folder! Someone probably typed existing_file.txt/subfile.txt */
+ error_with_file_under_nonfolder (data->impl, data->parent_file);
+ }
+ else
+ {
+ GError *error_copy;
+
+ /* The parent folder is not readable for some reason */
+
+ error_copy = g_error_copy (error);
+ error_changing_folder_dialog (data->impl, data->parent_file, error_copy);
+ }
}
out:
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
gboolean file_exists;
gboolean is_folder;
- gboolean needs_file_type_check = FALSE;
+ gboolean needs_parent_check = FALSE;
struct FileExistsData *data = user_data;
if (cancellable != data->impl->file_exists_get_info_cancellable)
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");
+ if (file_exists)
+ g_signal_emit_by_name (data->impl, "response-requested"); /* user typed an existing filename; we are done */
+ else
+ needs_parent_check = TRUE; /* file doesn't exist; see if its parent exists */
}
}
else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
}
else
{
- needs_file_type_check = TRUE;
+ needs_parent_check = TRUE;
}
}
else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
{
if (!file_exists)
{
- needs_file_type_check = TRUE;
+ needs_parent_check = TRUE;
}
else
{
if (is_folder)
change_folder_and_display_error (data->impl, data->file, TRUE);
else
- needs_file_type_check = TRUE;
+ needs_parent_check = TRUE;
}
else
{
g_assert_not_reached();
}
- if (needs_file_type_check) {
- /* check that everything up to the last component exists */
+ if (needs_parent_check) {
+ /* check that everything up to the last path component exists (i.e. the parent) */
data->file_exists_and_is_not_folder = file_exists && !is_folder;
data_ownership_taken = TRUE;
search_start_query (impl, text);
}
+static gboolean
+focus_entry_idle_cb (GtkFileChooserDefault *impl)
+{
+ GDK_THREADS_ENTER ();
+
+ g_source_destroy (impl->focus_entry_idle);
+ impl->focus_entry_idle = NULL;
+
+ if (impl->search_entry)
+ gtk_widget_grab_focus (impl->search_entry);
+
+ GDK_THREADS_LEAVE ();
+
+ return FALSE;
+}
+
+static void
+focus_search_entry_in_idle (GtkFileChooserDefault *impl)
+{
+ /* bgo#634558 - When the user clicks on the Search entry in the shortcuts
+ * pane, we get a selection-changed signal and we set up the search widgets.
+ * However, gtk_tree_view_button_press() focuses the treeview *after* making
+ * the change to the selection. So, we need to re-focus the search entry
+ * after the treeview has finished doing its work; we'll do that in an idle
+ * handler.
+ */
+
+ if (!impl->focus_entry_idle)
+ impl->focus_entry_idle = add_idle_while_impl_is_alive (impl, G_CALLBACK (focus_entry_idle_cb));
+}
+
/* Hides the path bar and creates the search entry */
static void
search_setup_widgets (GtkFileChooserDefault *impl)
gtk_widget_hide (impl->location_entry_box);
}
- gtk_widget_grab_focus (impl->search_entry);
+ focus_search_entry_in_idle (impl);
/* FMQ: hide the filter combo? */
}
if (impl->operation_mode == OPERATION_MODE_SEARCH)
{
- gtk_widget_grab_focus (impl->search_entry);
+ focus_search_entry_in_idle (impl);
return;
}
recent_clear_model (GtkFileChooserDefault *impl,
gboolean remove_from_treeview)
{
- GtkTreeModel *model;
-
if (!impl->recent_model)
return;
- model = GTK_TREE_MODEL (impl->recent_model);
-
if (remove_from_treeview)
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
g_signal_emit_by_name (impl, "update-preview");
}
+ else
+ {
+ if (new_file)
+ g_object_unref (new_file);
+
+ g_free (new_display_name);
+ }
}
static void
return (pos >= bookmarks_pos && pos < bookmarks_pos + model->impl->num_bookmarks);
}
-/* GtkTreeDragSource::drag_data_get implementation for the shortcuts filter model */
+/* GtkTreeDragSource::drag_data_get implementation for the shortcuts
+ * filter model
+ */
static gboolean
shortcuts_pane_model_filter_drag_data_get (GtkTreeDragSource *drag_source,
- GtkTreePath *path,
- GtkSelectionData *selection_data)
+ GtkTreePath *path,
+ GtkSelectionData *selection_data)
{
- ShortcutsPaneModelFilter *model;
-
- model = SHORTCUTS_PANE_MODEL_FILTER (drag_source);
-
/* FIXME */
return FALSE;