#include "config.h"
+#include "gtkfilechooserdefault.h"
+
#include "gdk/gdkkeysyms.h"
#include "gtkalignment.h"
#include "gtkbindings.h"
#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 "gtkfilechooserdefault.h"
#include "gtkfilechooserdialog.h"
#include "gtkfilechooserembed.h"
#include "gtkfilechooserentry.h"
-#include "gtkfilechoosersettings.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooser.h"
#include "gtkfilesystem.h"
#include "gtkscrolledwindow.h"
#include "gtkseparatormenuitem.h"
#include "gtksizegroup.h"
+#include "gtksizerequest.h"
#include "gtkstock.h"
#include "gtktable.h"
#include "gtktooltip.h"
#include "gtkvbox.h"
#include "gtkintl.h"
-#include "gtkalias.h"
-
#include <errno.h>
#include <string.h>
#include <time.h>
MODEL_COL_NUM_COLUMNS
};
-/* Column numbers for the search model.
- * Keep this in sync with search_setup_model()
- */
-enum {
- SEARCH_MODEL_COL_CANCELLABLE = MODEL_COL_NUM_COLUMNS,
- SEARCH_MODEL_COL_MIME_TYPE,
- SEARCH_MODEL_COL_NUM_COLUMNS
-};
-
-enum {
- RECENT_MODEL_COL_CANCELLABLE = MODEL_COL_NUM_COLUMNS,
- RECENT_MODEL_COL_INFO,
- RECENT_MODEL_COL_NUM_COLUMNS
-};
+/* This list of types is passed to _gtk_file_system_model_new*() */
+#define MODEL_COLUMN_TYPES \
+ MODEL_COL_NUM_COLUMNS, \
+ G_TYPE_STRING, /* MODEL_COL_NAME */ \
+ G_TYPE_INT64, /* MODEL_COL_SIZE */ \
+ G_TYPE_LONG, /* MODEL_COL_MTIME */ \
+ G_TYPE_FILE, /* MODEL_COL_FILE */ \
+ G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */ \
+ G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */ \
+ GDK_TYPE_PIXBUF, /* MODEL_COL_PIXBUF */ \
+ G_TYPE_STRING, /* MODEL_COL_SIZE_TEXT */ \
+ G_TYPE_STRING, /* MODEL_COL_MTIME_TEXT */ \
+ PANGO_TYPE_ELLIPSIZE_MODE /* MODEL_COL_ELLIPSIZE */
/* Identifiers for target types */
enum {
GTK_TREE_MODEL_ROW,
};
-static gboolean
-search_is_possible (GtkFileChooserDefault *impl)
-{
- if (impl->search_engine == NULL)
- impl->search_engine = _gtk_search_engine_new ();
-
- return impl->search_engine != NULL;
-}
-
/* Interesting places in the shortcuts bar */
typedef enum {
SHORTCUTS_SEARCH,
#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);
GtkTreeViewColumn *column,
GtkFileChooserDefault *impl);
-static void select_func (GtkFileSystemModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data);
-
static void path_bar_clicked (GtkPathBar *path_bar,
GFile *file,
GFile *child,
GtkFileChooserDefault *impl);
static void location_switch_to_path_bar (GtkFileChooserDefault *impl);
+static void stop_loading_and_clear_list_model (GtkFileChooserDefault *impl,
+ gboolean remove_from_treeview);
static void search_stop_searching (GtkFileChooserDefault *impl,
gboolean remove_query);
-static void search_clear_model_row (GtkTreeModel *model,
- GtkTreeIter *iter);
static void search_clear_model (GtkFileChooserDefault *impl,
gboolean remove_from_treeview);
static gboolean search_should_respond (GtkFileChooserDefault *impl);
static void search_entry_activate_cb (GtkEntry *entry,
gpointer data);
static void settings_load (GtkFileChooserDefault *impl);
-static void search_get_valid_child_iter (GtkFileChooserDefault *impl,
- GtkTreeIter *child_iter,
- GtkTreeIter *iter);
static void recent_stop_loading (GtkFileChooserDefault *impl);
static void recent_clear_model (GtkFileChooserDefault *impl,
static gboolean recent_should_respond (GtkFileChooserDefault *impl);
static void recent_switch_to_browse_mode (GtkFileChooserDefault *impl);
static GSList * recent_get_selected_files (GtkFileChooserDefault *impl);
-static void recent_get_valid_child_iter (GtkFileChooserDefault *impl,
- GtkTreeIter *child_iter,
- GtkTreeIter *iter);
static void set_file_system_backend (GtkFileChooserDefault *impl);
static void unset_file_system_backend (GtkFileChooserDefault *impl);
GtkTreeModel *child_model,
GtkTreePath *root);
-
-typedef struct {
- GtkTreeModelSort parent;
-
- GtkFileChooserDefault *impl;
-} RecentModelSort;
-
-typedef struct {
- GtkTreeModelSortClass parent_class;
-} RecentModelSortClass;
-
-#define RECENT_MODEL_SORT_TYPE (_recent_model_sort_get_type ())
-#define RECENT_MODEL_SORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RECENT_MODEL_SORT_TYPE, RecentModelSort))
-
-static void recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (RecentModelSort,
- _recent_model_sort,
- GTK_TYPE_TREE_MODEL_SORT,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
- recent_model_sort_drag_source_iface_init));
-
-static GtkTreeModel *recent_model_sort_new (GtkFileChooserDefault *impl,
- GtkTreeModel *child_model);
-
-
-typedef struct {
- GtkTreeModelSort parent;
-
- GtkFileChooserDefault *impl;
-} SearchModelSort;
-
-typedef struct {
- GtkTreeModelSortClass parent_class;
-} SearchModelSortClass;
-
-#define SEARCH_MODEL_SORT_TYPE (_search_model_sort_get_type ())
-#define SEARCH_MODEL_SORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEARCH_MODEL_SORT_TYPE, SearchModelSort))
-
-static void search_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (SearchModelSort,
- _search_model_sort,
- GTK_TYPE_TREE_MODEL_SORT,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
- search_model_sort_drag_source_iface_init));
-
-static GtkTreeModel *search_model_sort_new (GtkFileChooserDefault *impl,
- GtkTreeModel *child_model);
-
\f
G_DEFINE_TYPE_WITH_CODE (GtkFileChooserDefault, _gtk_file_chooser_default, GTK_TYPE_VBOX,
_gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
{
static const guint quick_bookmark_keyvals[10] = {
- GDK_1, GDK_2, GDK_3, GDK_4, GDK_5, GDK_6, GDK_7, GDK_8, GDK_9, GDK_0
+ GDK_KEY_1, GDK_KEY_2, GDK_KEY_3, GDK_KEY_4, GDK_KEY_5, GDK_KEY_6, GDK_KEY_7, GDK_KEY_8, GDK_KEY_9, GDK_KEY_0
};
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
binding_set = gtk_binding_set_by_class (class);
gtk_binding_entry_add_signal (binding_set,
- GDK_l, GDK_CONTROL_MASK,
+ GDK_KEY_l, GDK_CONTROL_MASK,
"location-toggle-popup",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_slash, 0,
+ GDK_KEY_slash, 0,
"location-popup",
1, G_TYPE_STRING, "/");
gtk_binding_entry_add_signal (binding_set,
- GDK_KP_Divide, 0,
+ GDK_KEY_KP_Divide, 0,
"location-popup",
1, G_TYPE_STRING, "/");
#ifdef G_OS_UNIX
gtk_binding_entry_add_signal (binding_set,
- GDK_asciitilde, 0,
+ GDK_KEY_asciitilde, 0,
"location-popup",
1, G_TYPE_STRING, "~");
#endif
gtk_binding_entry_add_signal (binding_set,
- GDK_v, GDK_CONTROL_MASK,
+ GDK_KEY_v, GDK_CONTROL_MASK,
"location-popup-on-paste",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_Up, GDK_MOD1_MASK,
+ GDK_KEY_Up, GDK_MOD1_MASK,
"up-folder",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_BackSpace, 0,
+ GDK_KEY_BackSpace, 0,
"up-folder",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_KP_Up, GDK_MOD1_MASK,
+ GDK_KEY_KP_Up, GDK_MOD1_MASK,
"up-folder",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_Down, GDK_MOD1_MASK,
+ GDK_KEY_Down, GDK_MOD1_MASK,
"down-folder",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_KP_Down, GDK_MOD1_MASK,
+ GDK_KEY_KP_Down, GDK_MOD1_MASK,
"down-folder",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_Home, GDK_MOD1_MASK,
+ GDK_KEY_Home, GDK_MOD1_MASK,
"home-folder",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_KP_Home, GDK_MOD1_MASK,
+ GDK_KEY_KP_Home, GDK_MOD1_MASK,
"home-folder",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_d, GDK_MOD1_MASK,
+ GDK_KEY_d, GDK_MOD1_MASK,
"desktop-folder",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_h, GDK_CONTROL_MASK,
+ GDK_KEY_h, GDK_CONTROL_MASK,
"show-hidden",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_s, GDK_MOD1_MASK,
+ GDK_KEY_s, GDK_MOD1_MASK,
"search-shortcut",
0);
gtk_binding_entry_add_signal (binding_set,
- GDK_r, GDK_MOD1_MASK,
+ GDK_KEY_r, GDK_MOD1_MASK,
"recent-shortcut",
0);
GtkFileSystemVolume *volume;
volume = col_data;
- _gtk_file_system_volume_free (volume);
+ _gtk_file_system_volume_unref (volume);
}
- else
+ if (shortcut_type == SHORTCUT_TYPE_FILE)
{
GFile *file;
- g_assert (shortcut_type == SHORTCUT_TYPE_FILE);
-
file = col_data;
g_object_unref (file);
}
g_slist_prepend (impl->pending_select_files, g_object_ref (file));
}
-/* Used from gtk_tree_selection_selected_foreach() */
-static void
-store_selection_foreach (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer data)
-{
- GtkFileChooserDefault *impl;
- GFile *file;
-
- impl = GTK_FILE_CHOOSER_DEFAULT (data);
-
- file = _gtk_file_system_model_get_file (GTK_FILE_SYSTEM_MODEL (model), iter);
- pending_select_files_add (impl, file);
-}
-
-/* Stores the current selection in the list of paths to select; this is used to
- * preserve the selection when reloading the current folder.
- */
-static void
-pending_select_files_store_selection (GtkFileChooserDefault *impl)
-{
- GtkTreeSelection *selection;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
- gtk_tree_selection_selected_foreach (selection, store_selection_foreach, impl);
-}
-
static void
gtk_file_chooser_default_finalize (GObject *object)
{
if (impl->browse_path_bar_size_group)
g_object_unref (impl->browse_path_bar_size_group);
- load_remove_timer (impl);
-
/* Free all the Models we have */
- if (impl->browse_files_model)
- g_object_unref (impl->browse_files_model);
-
+ stop_loading_and_clear_list_model (impl, FALSE);
search_clear_model (impl, FALSE);
recent_clear_model (impl, FALSE);
+ /* stopping the load above should have cleared this */
+ g_assert (impl->load_timeout_id == 0);
+
g_free (impl->preview_display_name);
g_free (impl->edited_new_text);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", detail);
- if (parent && parent->group)
- gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
+ if (parent && gtk_window_has_group (parent))
+ gtk_window_group_add_window (gtk_window_get_group (parent),
+ GTK_WINDOW (dialog));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (widget);
- if (!GTK_WIDGET_TOPLEVEL (toplevel))
+ if (!gtk_widget_is_toplevel (toplevel))
return NULL;
else
return GTK_WINDOW (toplevel);
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,
else
gtk_widget_hide (impl->preview_box);
- if (!GTK_WIDGET_MAPPED (impl))
+ if (!gtk_widget_get_mapped (GTK_WIDGET (impl)))
emit_default_size_changed (impl);
}
}
}
- shortcuts_insert_file (impl, start_row + n, SHORTCUT_TYPE_VOLUME, volume, NULL, NULL, FALSE, SHORTCUTS_VOLUMES);
+ shortcuts_insert_file (impl,
+ start_row + n,
+ SHORTCUT_TYPE_VOLUME,
+ _gtk_file_system_volume_ref (volume),
+ NULL,
+ NULL,
+ FALSE,
+ SHORTCUTS_VOLUMES);
n++;
}
G_TYPE_BOOLEAN, /* pixbuf cell visibility */
G_TYPE_POINTER); /* GCancellable */
- if (search_is_possible (impl))
- {
- shortcuts_append_search (impl);
- }
+ shortcuts_append_search (impl);
if (impl->recent_manager)
{
static GtkWidget *
filter_create (GtkFileChooserDefault *impl)
{
- impl->filter_combo = gtk_combo_box_new_text ();
+ GtkCellRenderer *cell;
+ GList *cells;
+
+ 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 */
+ cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (impl->filter_combo));
+ g_assert (cells);
+ cell = cells->data;
+
+ g_object_set (G_OBJECT (cell),
+ "ellipsize", PANGO_ELLIPSIZE_END,
+ NULL);
+
+ g_list_free (cells);
+
g_signal_connect (impl->filter_combo, "changed",
G_CALLBACK (filter_combo_changed), impl);
{
struct selection_check_closure *closure;
gboolean is_folder;
-
- closure = data;
- closure->num_selected++;
+ GFile *file;
gtk_tree_model_get (model, iter,
+ MODEL_COL_FILE, &file,
MODEL_COL_IS_FOLDER, &is_folder,
-1);
+ if (file == NULL)
+ return;
+
+ g_object_unref (file);
+
+ closure = data;
+ closure->num_selected++;
+
closure->all_folders = closure->all_folders && is_folder;
closure->all_files = closure->all_files && !is_folder;
}
{
struct get_selected_file_closure *closure = data;
+ if (closure->file)
+ {
+ /* Just in case this function gets run more than once with a multiple selection; we only care about one file */
+ g_object_unref (closure->file);
+ closure->file = NULL;
+ }
+
gtk_tree_model_get (model, iter,
- MODEL_COL_FILE, &closure->file,
+ MODEL_COL_FILE, &closure->file, /* this will give us a reffed file */
-1);
- if (closure->file)
- g_object_unref (closure->file);
}
/* Returns a selected path from the file list */
GFile *file;
file = get_selected_file (impl);
- active = all_folders && (shortcut_find_position (impl, file) == -1);
+ active = file && all_folders && (shortcut_find_position (impl, file) == -1);
+ if (file)
+ g_object_unref (file);
}
else
active = all_folders;
g_signal_stop_emission_by_name (widget, "drag-data-delete");
}
-#if 0
-/* Creates a suitable drag cursor to indicate that the selected bookmark will be
- * deleted or not.
- */
-static void
-shortcuts_drag_set_delete_cursor (GtkFileChooserDefault *impl,
- gboolean delete)
-{
- GtkTreeView *tree_view;
- GtkTreeIter iter;
- GtkTreePath *path;
- GdkPixmap *row_pixmap;
- GdkBitmap *mask;
- int row_pixmap_y;
- int cell_y;
-
- tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
-
- /* Find the selected path and get its drag pixmap */
-
- if (!shortcuts_get_selected (impl, &iter))
- g_assert_not_reached ();
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
-
- row_pixmap = gtk_tree_view_create_row_drag_icon (tree_view, path);
- gtk_tree_path_free (path);
-
- mask = NULL;
- row_pixmap_y = 0;
-
- if (delete)
- {
- GdkPixbuf *pixbuf;
-
- pixbuf = gtk_widget_render_icon (impl->browse_shortcuts_tree_view,
- GTK_STOCK_DELETE,
- GTK_ICON_SIZE_DND,
- NULL);
- if (pixbuf)
- {
- GdkPixmap *composite;
- int row_pixmap_width, row_pixmap_height;
- int pixbuf_width, pixbuf_height;
- int composite_width, composite_height;
- int pixbuf_x, pixbuf_y;
- GdkGC *gc, *mask_gc;
- GdkColor color;
- GdkBitmap *pixbuf_mask;
-
- /* Create pixmap and mask for composite image */
-
- gdk_drawable_get_size (row_pixmap, &row_pixmap_width, &row_pixmap_height);
- pixbuf_width = gdk_pixbuf_get_width (pixbuf);
- pixbuf_height = gdk_pixbuf_get_height (pixbuf);
-
- composite_width = MAX (row_pixmap_width, pixbuf_width);
- composite_height = MAX (row_pixmap_height, pixbuf_height);
-
- row_pixmap_y = (composite_height - row_pixmap_height) / 2;
-
- if (gtk_widget_get_direction (impl->browse_shortcuts_tree_view) == GTK_TEXT_DIR_RTL)
- pixbuf_x = 0;
- else
- pixbuf_x = composite_width - pixbuf_width;
-
- pixbuf_y = (composite_height - pixbuf_height) / 2;
-
- composite = gdk_pixmap_new (row_pixmap, composite_width, composite_height, -1);
- gc = gdk_gc_new (composite);
-
- mask = gdk_pixmap_new (row_pixmap, composite_width, composite_height, 1);
- mask_gc = gdk_gc_new (mask);
- color.pixel = 0;
- gdk_gc_set_foreground (mask_gc, &color);
- gdk_draw_rectangle (mask, mask_gc, TRUE, 0, 0, composite_width, composite_height);
-
- color.red = 0xffff;
- color.green = 0xffff;
- color.blue = 0xffff;
- gdk_gc_set_rgb_fg_color (gc, &color);
- gdk_draw_rectangle (composite, gc, TRUE, 0, 0, composite_width, composite_height);
-
- /* Composite the row pixmap and the pixbuf */
-
- gdk_pixbuf_render_pixmap_and_mask_for_colormap
- (pixbuf,
- gtk_widget_get_colormap (impl->browse_shortcuts_tree_view),
- NULL, &pixbuf_mask, 128);
- gdk_draw_drawable (mask, mask_gc, pixbuf_mask,
- 0, 0,
- pixbuf_x, pixbuf_y,
- pixbuf_width, pixbuf_height);
- g_object_unref (pixbuf_mask);
-
- gdk_draw_drawable (composite, gc, row_pixmap,
- 0, 0,
- 0, row_pixmap_y,
- row_pixmap_width, row_pixmap_height);
- color.pixel = 1;
- gdk_gc_set_foreground (mask_gc, &color);
- gdk_draw_rectangle (mask, mask_gc, TRUE, 0, row_pixmap_y, row_pixmap_width, row_pixmap_height);
-
- gdk_draw_pixbuf (composite, gc, pixbuf,
- 0, 0,
- pixbuf_x, pixbuf_y,
- pixbuf_width, pixbuf_height,
- GDK_RGB_DITHER_MAX,
- 0, 0);
-
- g_object_unref (pixbuf);
- g_object_unref (row_pixmap);
-
- row_pixmap = composite;
- }
- }
-
- /* The hotspot offsets here are copied from gtk_tree_view_drag_begin(), ugh */
-
- gtk_tree_view_get_path_at_pos (tree_view,
- tree_view->priv->press_start_x,
- tree_view->priv->press_start_y,
- NULL,
- NULL,
- NULL,
- &cell_y);
-
- gtk_drag_set_icon_pixmap (impl->shortcuts_drag_context,
- gdk_drawable_get_colormap (row_pixmap),
- row_pixmap,
- mask,
- tree_view->priv->press_start_x + 1,
- row_pixmap_y + cell_y + 1);
-
- g_object_unref (row_pixmap);
- if (mask)
- g_object_unref (mask);
-}
-
-/* We set the delete cursor and the shortcuts_drag_outside flag in an idle
- * handler so that we can tell apart the drag_leave event that comes right
- * before a drag_drop, from a normal drag_leave. We don't want to set the
- * cursor nor the flag in the latter case.
- */
-static gboolean
-shortcuts_drag_outside_idle_cb (GtkFileChooserDefault *impl)
-{
- GDK_THREADS_ENTER ();
-
- shortcuts_drag_set_delete_cursor (impl, TRUE);
- impl->shortcuts_drag_outside = TRUE;
-
- shortcuts_cancel_drag_outside_idle (impl);
-
- GDK_THREADS_LEAVE ();
-
- return FALSE;
-}
-#endif
-
/* GtkWidget::drag-leave handler for the shortcuts list. We unhighlight the
* drop position.
*/
if (shortcut_type == SHORTCUT_TYPE_SEPARATOR)
return FALSE;
else if (shortcut_type == SHORTCUT_TYPE_VOLUME)
- {
- return FALSE;
- }
+ return FALSE;
else if (shortcut_type == SHORTCUT_TYPE_FILE)
{
GFile *file;
GtkWidget *entry;
/* don't screw up focus switching with Tab */
- if (event->keyval == GDK_Tab
- || event->keyval == GDK_KP_Tab
- || event->keyval == GDK_ISO_Left_Tab
+ if (event->keyval == GDK_KEY_Tab
+ || event->keyval == GDK_KEY_KP_Tab
+ || event->keyval == GDK_KEY_ISO_Left_Tab
|| event->length < 1)
return FALSE;
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);
modifiers = gtk_accelerator_get_default_mod_mask ();
- return ((event->keyval == GDK_Right
- || event->keyval == GDK_KP_Right
- || event->keyval == GDK_Left
- || event->keyval == GDK_KP_Left)
+ return ((event->keyval == GDK_KEY_Right
+ || event->keyval == GDK_KEY_KP_Right
+ || event->keyval == GDK_KEY_Left
+ || event->keyval == GDK_KEY_KP_Left)
&& (event->state & modifiers) == 0);
}
modifiers = gtk_accelerator_get_default_mod_mask ();
- if ((event->keyval == GDK_slash
- || event->keyval == GDK_KP_Divide
+ if ((event->keyval == GDK_KEY_slash
+ || event->keyval == GDK_KEY_KP_Divide
#ifdef G_OS_UNIX
- || event->keyval == GDK_asciitilde
+ || event->keyval == GDK_KEY_asciitilde
#endif
) && ! (event->state & (~GDK_SHIFT_MASK & modifiers)))
{
return TRUE;
}
- if ((event->keyval == GDK_Return
- || event->keyval == GDK_ISO_Enter
- || event->keyval == GDK_KP_Enter
- || event->keyval == GDK_space
- || event->keyval == GDK_KP_Space)
+ if ((event->keyval == GDK_KEY_Return
+ || event->keyval == GDK_KEY_ISO_Enter
+ || event->keyval == GDK_KEY_KP_Enter
+ || event->keyval == GDK_KEY_space
+ || event->keyval == GDK_KEY_KP_Space)
&& ((event->state & modifiers) == 0)
&& !(impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
GtkWindow *window;
window = get_toplevel (widget);
- if (window
- && widget != window->default_widget
- && !(widget == window->focus_widget &&
- (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
- {
- gtk_window_activate_default (window);
- return TRUE;
- }
+ if (window)
+ {
+ GtkWidget *default_widget, *focus_widget;
+
+ default_widget = gtk_window_get_default_widget (window);
+ focus_widget = gtk_window_get_focus (window);
+
+ if (widget != default_widget &&
+ !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
+ {
+ gtk_window_activate_default (window);
+
+ return TRUE;
+ }
+ }
}
return FALSE;
{
impl->show_size_column = gtk_check_menu_item_get_active (item);
- if (impl->list_size_column)
- gtk_tree_view_column_set_visible (impl->list_size_column,
- impl->show_size_column);
+ gtk_tree_view_column_set_visible (impl->list_size_column,
+ impl->show_size_column);
}
/* Shows an error dialog about not being able to select a dragged file */
gboolean *push_in,
gpointer user_data)
{
+ GtkAllocation allocation;
GtkWidget *widget = GTK_WIDGET (user_data);
GdkScreen *screen = gtk_widget_get_screen (widget);
GtkRequisition req;
gint monitor_num;
GdkRectangle monitor;
- g_return_if_fail (GTK_WIDGET_REALIZED (widget));
+ g_return_if_fail (gtk_widget_get_realized (widget));
- gdk_window_get_origin (widget->window, x, y);
+ gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
- gtk_widget_size_request (GTK_WIDGET (menu), &req);
+ gtk_widget_get_preferred_size (GTK_WIDGET (menu),
+ &req, NULL);
- *x += (widget->allocation.width - req.width) / 2;
- *y += (widget->allocation.height - req.height) / 2;
+ gtk_widget_get_allocation (widget, &allocation);
+ *x += (allocation.width - req.width) / 2;
+ *y += (allocation.height - req.height) / 2;
monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
gtk_menu_set_monitor (menu, monitor_num);
return TRUE;
}
+static void
+set_icon_cell_renderer_fixed_size (GtkFileChooserDefault *impl, GtkCellRenderer *renderer)
+{
+ gint xpad, ypad;
+
+ gtk_cell_renderer_get_padding (renderer, &xpad, &ypad);
+ gtk_cell_renderer_set_fixed_size (renderer,
+ xpad * 2 + impl->icon_size,
+ ypad * 2 + impl->icon_size);
+}
+
/* Creates the widgets for the file list */
static GtkWidget *
create_file_list (GtkFileChooserDefault *impl)
g_signal_connect (selection, "changed",
G_CALLBACK (list_selection_changed), impl);
+ /* Keep the column order in sync with update_cell_renderer_attributes() */
+
/* Filename column */
impl->list_name_column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (impl->list_name_column, _("Name"));
renderer = gtk_cell_renderer_pixbuf_new ();
- /* We set a fixed size so that we get an emoty row even if no icons are loaded yet */
- gtk_cell_renderer_set_fixed_size (renderer,
- renderer->xpad * 2 + impl->icon_size,
- renderer->ypad * 2 + impl->icon_size);
+ /* We set a fixed size so that we get an empty slot even if no icons are loaded yet */
+ set_icon_cell_renderer_fixed_size (impl, renderer);
gtk_tree_view_column_pack_start (impl->list_name_column, renderer, FALSE);
impl->list_name_renderer = gtk_cell_renderer_text_new ();
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);
}
else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
{
- if (GTK_WIDGET_HAS_FOCUS (impl->location_entry))
+ if (gtk_widget_has_focus (impl->location_entry))
{
location_mode_set (impl, LOCATION_MODE_PATH_BAR, TRUE);
}
impl->location_button = g_object_new (GTK_TYPE_TOGGLE_BUTTON,
"image", image,
NULL);
-
- gtk_size_group_add_widget (impl->browse_path_bar_size_group, impl->location_button);
g_signal_connect (impl->location_button, "toggled",
G_CALLBACK (location_button_toggled_cb), impl);
/* 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);
location_button_create (impl);
gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->location_button, FALSE, FALSE, 0);
+ gtk_size_group_add_widget (impl->browse_path_bar_size_group, impl->location_button);
/* Path bar */
g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl);
gtk_widget_show_all (impl->browse_path_bar);
gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->browse_path_bar, TRUE, TRUE, 0);
+ gtk_size_group_add_widget (impl->browse_path_bar_size_group, impl->browse_path_bar);
/* Create Folder */
impl->browse_new_folder_button = gtk_button_new_with_mnemonic (_("Create Fo_lder"));
/* 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);
}
break;
- case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
- /* Ignore property */
- break;
-
case GTK_FILE_CHOOSER_PROP_FILTER:
set_current_filter (impl, g_value_get_object (value));
break;
impl->update_current_folder_cancellable = NULL;
}
- if (impl->show_and_select_files_cancellable)
- {
- g_cancellable_cancel (impl->show_and_select_files_cancellable);
- impl->show_and_select_files_cancellable = NULL;
- }
-
if (impl->should_respond_get_info_cancellable)
{
g_cancellable_cancel (impl->should_respond_get_info_cancellable);
cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (
gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 0)));
renderer = GTK_CELL_RENDERER (cells->data);
- gtk_cell_renderer_set_fixed_size (renderer,
- renderer->xpad * 2 + impl->icon_size,
- renderer->ypad * 2 + impl->icon_size);
+ set_icon_cell_renderer_fixed_size (impl, renderer);
g_list_free (cells);
if (impl->browse_files_model)
_gtk_file_system_model_clear_cache (impl->browse_files_model, MODEL_COL_PIXBUF);
GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->size_allocate (widget, allocation);
}
-static gboolean
-get_is_file_filtered (GtkFileChooserDefault *impl,
- GFile *file,
- GFileInfo *file_info)
-{
- GtkFileFilterInfo filter_info;
- GtkFileFilterFlags needed;
- gboolean result;
-
- if (!impl->current_filter)
- return FALSE;
-
- filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
-
- needed = gtk_file_filter_get_needed (impl->current_filter);
-
- filter_info.display_name = g_file_info_get_display_name (file_info);
- filter_info.mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (file_info));
-
- if (needed & GTK_FILE_FILTER_FILENAME)
- {
- filter_info.filename = g_file_get_path (file);
- if (filter_info.filename)
- filter_info.contains |= GTK_FILE_FILTER_FILENAME;
- }
- else
- filter_info.filename = NULL;
-
- if (needed & GTK_FILE_FILTER_URI)
- {
- filter_info.uri = g_file_get_uri (file);
- if (filter_info.uri)
- filter_info.contains |= GTK_FILE_FILTER_URI;
- }
- else
- filter_info.uri = NULL;
-
- result = gtk_file_filter_filter (impl->current_filter, &filter_info);
-
- g_free ((gchar *)filter_info.filename);
- g_free ((gchar *)filter_info.uri);
- g_free ((gchar *)filter_info.mime_type);
-
- return !result;
-}
-
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)
{
- GtkFileChooserSettings *settings;
LocationMode location_mode;
gboolean show_hidden;
gboolean expand_folders;
gint sort_column;
GtkSortType sort_order;
- settings = _gtk_file_chooser_settings_new ();
+ settings_ensure (impl);
- 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);
-
- 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);
gtk_expander_set_expanded (GTK_EXPANDER (impl->save_expander), expand_folders);
impl->show_size_column = show_size_column;
- if (impl->list_size_column)
- gtk_tree_view_column_set_visible (impl->list_size_column, show_size_column);
+ gtk_tree_view_column_set_visible (impl->list_size_column, show_size_column);
impl->sort_column = sort_column;
impl->sort_order = sort_order;
}
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 = _gtk_file_chooser_settings_new ();
+ settings_ensure (impl);
- _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);
+ 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);
- save_dialog_geometry (impl, settings);
+ save_dialog_geometry (impl);
- /* NULL GError */
- _gtk_file_chooser_settings_save (settings, NULL);
+ /* Now apply the settings */
+ g_settings_apply (impl->settings);
- g_object_unref (settings);
+ g_object_unref (impl->settings);
+ impl->settings = NULL;
}
/* GtkWidget::realize method */
*/
break;
- case RELOAD_WAS_UNMAPPED:
- /* Just reload the current folder; else continue
- * the pending load.
- */
- if (impl->current_folder)
- {
- pending_select_files_store_selection (impl);
- change_folder_and_display_error (impl, impl->current_folder, FALSE);
- }
- break;
-
default:
g_assert_not_reached ();
}
settings_save (impl);
GTK_WIDGET_CLASS (_gtk_file_chooser_default_parent_class)->unmap (widget);
-
- impl->reload_state = RELOAD_WAS_UNMAPPED;
-}
-
-static gboolean
-list_model_filter_func (GtkFileSystemModel *model,
- GFile *file,
- GFileInfo *file_info,
- gpointer user_data)
-{
- GtkFileChooserDefault *impl = user_data;
-
- if (!impl->current_filter)
- return TRUE;
-
- if (_gtk_file_info_consider_as_directory (file_info))
- return TRUE;
-
- return !get_is_file_filtered (impl, file, file_info);
}
static void
install_list_model_filter (GtkFileChooserDefault *impl)
{
- GtkFileSystemModelFilter filter;
- gpointer data;
-
- g_assert (impl->browse_files_model != NULL);
-
- if (impl->current_filter)
- {
- filter = list_model_filter_func;
- data = impl;
- }
- else
- {
- filter = NULL;
- data = NULL;
- }
-
_gtk_file_system_model_set_filter (impl->browse_files_model,
- filter,
- data);
+ impl->current_filter);
}
#define COMPARE_DIRECTORIES \
GtkFileChooserDefault *impl = user_data; \
+ GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model); \
gboolean dir_a, dir_b; \
\
- gtk_tree_model_get (model, a, MODEL_COL_IS_FOLDER, &dir_a, -1); \
- gtk_tree_model_get (model, b, MODEL_COL_IS_FOLDER, &dir_b, -1); \
+ dir_a = g_value_get_boolean (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_IS_FOLDER)); \
+ dir_b = g_value_get_boolean (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_IS_FOLDER)); \
\
if (dir_a != dir_b) \
return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
COMPARE_DIRECTORIES;
else
{
- gchar *key_a, *key_b;
+ const char *key_a, *key_b;
gint result;
- gtk_tree_model_get (model, a, MODEL_COL_NAME_COLLATED, &key_a, -1);
- gtk_tree_model_get (model, b, MODEL_COL_NAME_COLLATED, &key_b, -1);
+ key_a = g_value_get_string (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_NAME_COLLATED));
+ key_b = g_value_get_string (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_NAME_COLLATED));
if (key_a && key_b)
result = strcmp (key_a, key_b);
else if (key_a)
- return 1;
+ result = 1;
else if (key_b)
- return -1;
+ result = -1;
else
- return 0;
-
- g_free (key_a);
- g_free (key_b);
+ result = 0;
return result;
}
{
gint64 size_a, size_b;
- gtk_tree_model_get (model, a, MODEL_COL_SIZE, &size_a, -1);
- gtk_tree_model_get (model, b, MODEL_COL_SIZE, &size_b, -1);
+ size_a = g_value_get_int64 (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_SIZE));
+ size_b = g_value_get_int64 (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_SIZE));
- return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1);
+ return size_a < size_b ? -1 : (size_a == size_b ? 0 : 1);
}
}
{
glong ta, tb;
- gtk_tree_model_get (model, a, MODEL_COL_MTIME, &ta, -1);
- gtk_tree_model_get (model, b, MODEL_COL_MTIME, &tb, -1);
+ ta = g_value_get_long (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_MTIME));
+ tb = g_value_get_long (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_MTIME));
- return ta > tb ? -1 : (ta == tb ? 0 : 1);
+ return ta < tb ? -1 : (ta == tb ? 0 : 1);
}
}
set_busy_cursor (GtkFileChooserDefault *impl,
gboolean busy)
{
+ GtkWidget *widget;
GtkWindow *toplevel;
GdkDisplay *display;
GdkCursor *cursor;
toplevel = get_toplevel (GTK_WIDGET (impl));
- if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
+ widget = GTK_WIDGET (toplevel);
+ if (!toplevel || !gtk_widget_get_realized (widget))
return;
- display = gtk_widget_get_display (GTK_WIDGET (toplevel));
+ display = gtk_widget_get_display (widget);
if (busy)
cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
else
cursor = NULL;
- gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
+ gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
gdk_display_flush (display);
if (cursor)
GtkTreeIter dummy_iter;
GtkTreeModel *tree_model;
- path = gtk_tree_path_new_from_indices (0, -1);
tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view));
if (!tree_model)
return;
+ path = gtk_tree_path_new_from_indices (0, -1);
+
/* If the list is empty, do nothing. */
if (gtk_tree_model_get_iter (tree_model, &dummy_iter, path))
gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), path, NULL, FALSE);
gtk_tree_selection_selected_foreach (selection, center_selected_row_foreach_cb, &closure);
}
-struct ShowAndSelectPathsData
+static gboolean
+show_and_select_files (GtkFileChooserDefault *impl,
+ GSList *files)
{
- GtkFileChooserDefault *impl;
- GSList *files;
-};
-
-static void
-show_and_select_files_finished_loading (GtkFolder *folder,
- gpointer user_data)
-{
- gboolean have_hidden;
- gboolean have_filtered;
- GSList *l;
- struct ShowAndSelectPathsData *data = user_data;
-
- have_hidden = FALSE;
- have_filtered = FALSE;
-
- for (l = data->files; l; l = l->next)
- {
- GFile *file;
- GFileInfo *info;
-
- file = l->data;
-
- info = _gtk_folder_get_info (folder, file);
- if (info)
- {
- if (!have_hidden)
- have_hidden = g_file_info_get_is_hidden (info)
- || g_file_info_get_is_backup (info);
-
- if (!have_filtered)
- have_filtered = (! _gtk_file_info_consider_as_directory (info)) &&
- get_is_file_filtered (data->impl, file, info);
-
- g_object_unref (info);
-
- if (have_hidden && have_filtered)
- break; /* we now have all the information we need */
- }
- }
-
- g_signal_handlers_disconnect_by_func (folder,
- show_and_select_files_finished_loading,
- user_data);
-
- if (have_hidden)
- g_object_set (data->impl, "show-hidden", TRUE, NULL);
+ GtkTreeSelection *selection;
+ GtkFileSystemModel *fsmodel;
+ gboolean can_have_hidden, can_have_filtered, selected_a_file;
+ GSList *walk;
- if (have_filtered)
- set_current_filter (data->impl, 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)));
+ can_have_hidden = !impl->show_hidden;
+ can_have_filtered = impl->current_filter != NULL;
+ selected_a_file = FALSE;
- for (l = data->files; l; l = l->next)
+ for (walk = files; walk && (can_have_hidden || can_have_filtered); walk = walk->next)
{
- GFile *file;
- GtkTreePath *path;
+ GFile *file = walk->data;
GtkTreeIter iter;
- file = l->data;
- if (!_gtk_file_system_model_get_iter_for_file (data->impl->browse_files_model,
- &iter,
- file))
- return;
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (data->impl->browse_files_model), &iter);
- select_func (data->impl->browse_files_model, path, &iter, data->impl);
- gtk_tree_path_free (path);
- }
-
- browse_files_center_selected_row (data->impl);
-
- g_object_unref (data->impl);
- g_slist_foreach (data->files, (GFunc) g_object_unref, NULL);
- g_slist_free (data->files);
- g_free (data);
-}
-
-static void
-show_and_select_files_get_folder_cb (GCancellable *cancellable,
- GtkFolder *folder,
- const GError *error,
- gpointer user_data)
-{
- gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- struct ShowAndSelectPathsData *data = user_data;
-
- if (data->impl->show_and_select_files_cancellable != cancellable)
- goto out;
-
- data->impl->show_and_select_files_cancellable = NULL;
-
- if (cancelled || error)
- goto out;
-
- g_object_unref (cancellable);
-
- if (_gtk_folder_is_finished_loading (folder))
- show_and_select_files_finished_loading (folder, user_data);
- else
- g_signal_connect (folder, "finished-loading",
- G_CALLBACK (show_and_select_files_finished_loading),
- user_data);
+ if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
+ continue;
- return;
+ if (!_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
+ {
+ GFileInfo *info = _gtk_file_system_model_get_info (fsmodel, &iter);
-out:
- g_object_unref (data->impl);
- g_slist_foreach (data->files, (GFunc) g_object_unref, NULL);
- g_slist_free (data->files);
- g_free (data);
+ if (can_have_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;
+ }
- g_object_unref (cancellable);
-}
+ if (can_have_filtered)
+ {
+ set_current_filter (impl, NULL);
+ can_have_filtered = FALSE;
+ }
+ }
+
+ if (_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
+ {
+ GtkTreePath *path;
-static gboolean
-show_and_select_files (GtkFileChooserDefault *impl,
- GFile *parent_file,
- GSList *files,
- GError **error)
-{
- struct ShowAndSelectPathsData *info;
+ gtk_tree_selection_select_iter (selection, &iter);
- profile_start ("start", NULL);
+ 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);
- if (!files)
- {
- profile_end ("end", NULL);
- return TRUE;
+ selected_a_file = TRUE;
+ }
}
- info = g_new (struct ShowAndSelectPathsData, 1);
- info->impl = g_object_ref (impl);
- info->files = g_slist_copy (files);
- g_slist_foreach (info->files, (GFunc) g_object_ref, NULL);
-
- if (impl->show_and_select_files_cancellable)
- g_cancellable_cancel (impl->show_and_select_files_cancellable);
+ browse_files_center_selected_row (impl);
- impl->show_and_select_files_cancellable =
- _gtk_file_system_get_folder (impl->file_system, parent_file,
- "standard::is-hidden,standard::is-backup,standard::type,standard::name,standard::content-type",
- show_and_select_files_get_folder_cb, info);
-
- profile_end ("end", NULL);
- return TRUE;
+ return selected_a_file;
}
/* Processes the pending operation when a folder is finished loading */
if (impl->pending_select_files)
{
- /* NULL GError */
- show_and_select_files (impl, impl->current_folder, impl->pending_select_files, NULL);
+ show_and_select_files (impl, impl->pending_select_files);
pending_select_files_free (impl);
browse_files_center_selected_row (impl);
}
* that case, the chooser's selection should be what the caller expects,
* as the user can't see that something else got selected. See bug #165264.
*/
- if (GTK_WIDGET_MAPPED (impl) && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
+ if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN &&
+ gtk_widget_get_mapped (GTK_WIDGET (impl)))
browse_files_select_first_row (impl);
}
g_assert (impl->pending_select_files == NULL);
}
+static void
+show_error_on_reading_current_folder (GtkFileChooserDefault *impl, GError *error)
+{
+ GFileInfo *info;
+ char *msg;
+
+ info = g_file_query_info (impl->current_folder,
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ if (info)
+ {
+ msg = g_strdup_printf (_("Could not read the contents of %s"), g_file_info_get_display_name (info));
+ g_object_unref (info);
+ }
+ else
+ msg = g_strdup (_("Could not read the contents of the folder"));
+
+ error_message (impl, msg, error->message);
+ g_free (msg);
+}
+
/* Callback used when the file system model finishes loading */
static void
browse_files_model_finished_loading_cb (GtkFileSystemModel *model,
{
profile_start ("start", NULL);
+ if (error)
+ show_error_on_reading_current_folder (impl, error);
+
if (impl->load_state == LOAD_PRELOAD)
{
load_remove_timer (impl);
}
static void
-stop_loading_and_clear_list_model (GtkFileChooserDefault *impl)
+stop_loading_and_clear_list_model (GtkFileChooserDefault *impl,
+ gboolean remove_from_treeview)
{
load_remove_timer (impl); /* This changes the state to LOAD_EMPTY */
impl->browse_files_model = NULL;
}
- gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
+ if (remove_from_treeview)
+ gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
}
static char *
gchar *locale_format = NULL;
gchar buf[256];
char *date_str = NULL;
+#ifdef G_OS_WIN32
+ const char *locale, *dot = NULL;
+ gint64 codepage = -1;
+ char charset[20];
+#endif
time_mtime = secs;
localtime_r ((time_t *) &time_mtime, &tm_mtime);
#else
{
- struct tm *ptm = localtime ((time_t *) &timeval.tv_sec);
+ struct tm *ptm = localtime ((time_t *) &time_mtime);
if (!ptm)
{
return date_str;
}
-#define copy_attribute(to, from, attribute) G_STMT_START { \
- GFileAttributeType type; \
- gpointer value; \
-\
- if (g_file_info_get_attribute_data (from, attribute, &type, &value, NULL)) \
- g_file_info_set_attribute (to, attribute, type, value); \
-}G_STMT_END
+static void
+copy_attribute (GFileInfo *to, GFileInfo *from, const char *attribute)
+{
+ GFileAttributeType type;
+ gpointer value;
+
+ if (g_file_info_get_attribute_data (from, attribute, &type, &value, NULL))
+ g_file_info_set_attribute (to, attribute, type, value);
+}
static void
file_system_model_got_thumbnail (GObject *object, GAsyncResult *res, gpointer data)
if (tree_model != GTK_TREE_MODEL (model))
return FALSE;
- if (!_gtk_file_system_model_get_iter_for_file (impl->browse_files_model,
- &iter,
- file))
+ if (!_gtk_file_system_model_get_iter_for_file (model,
+ &iter,
+ file))
g_assert_not_reached ();
if (!gtk_tree_view_get_visible_range (GTK_TREE_VIEW (impl->browse_files_tree_view), &start, &end))
return FALSE;
G_FILE_ATTRIBUTE_THUMBNAIL_PATH ","
G_FILE_ATTRIBUTE_THUMBNAILING_FAILED ","
G_FILE_ATTRIBUTE_STANDARD_ICON,
- 0,
+ G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
_gtk_file_system_model_get_cancellable (model),
file_system_model_got_thumbnail,
profile_start ("start", NULL);
- stop_loading_and_clear_list_model (impl);
+ stop_loading_and_clear_list_model (impl, TRUE);
set_busy_cursor (impl, TRUE);
- gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
impl->browse_files_model =
- _gtk_file_system_model_new (impl->current_folder,
- MODEL_ATTRIBUTES,
- file_system_model_set,
- impl,
- MODEL_COL_NUM_COLUMNS,
- G_TYPE_STRING,
- G_TYPE_INT64,
- G_TYPE_LONG,
- G_TYPE_FILE,
- G_TYPE_STRING,
- G_TYPE_BOOLEAN,
- GDK_TYPE_PIXBUF,
- G_TYPE_STRING,
- G_TYPE_STRING,
- PANGO_TYPE_ELLIPSIZE_MODE);
+ _gtk_file_system_model_new_for_directory (impl->current_folder,
+ MODEL_ATTRIBUTES,
+ file_system_model_set,
+ impl,
+ MODEL_COLUMN_TYPES);
_gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
_gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), name);
}
-static void
-select_func (GtkFileSystemModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- GtkFileChooserDefault *impl = user_data;
- GtkTreeSelection *selection;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
-
- gtk_tree_selection_select_iter (selection, iter);
-}
-
static gboolean
gtk_file_chooser_default_select_file (GtkFileChooser *chooser,
GFile *file,
files.data = (gpointer) file;
files.next = NULL;
- result = show_and_select_files (impl, parent_file, &files, error);
+ result = show_and_select_files (impl, &files);
g_object_unref (parent_file);
return result;
}
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);
gint *height)
{
GtkFileChooserDefault *impl;
+ GtkStyle *style;
int font_size;
GdkScreen *screen;
double resolution;
- g_assert (widget->style != NULL);
+ style = gtk_widget_get_style (widget);
+
+ g_assert (style != NULL);
impl = GTK_FILE_CHOOSER_DEFAULT (widget);
screen = gtk_widget_get_screen (widget);
else
resolution = 96.0; /* wheeee */
- font_size = pango_font_description_get_size (widget->style->font_desc);
+ font_size = pango_font_description_get_size (style->font_desc);
font_size = PANGO_PIXELS (font_size) * resolution / 72.0;
*width = font_size * NUM_CHARS;
|| 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)
{
if (impl->preview_widget_active &&
impl->preview_widget &&
- GTK_WIDGET_VISIBLE (impl->preview_widget))
+ gtk_widget_get_visible (impl->preview_widget))
{
- gtk_widget_size_request (impl->preview_box, &req);
+ gtk_widget_get_preferred_size (impl->preview_box,
+ &req, NULL);
*default_width += PREVIEW_HBOX_SPACING + req.width;
}
if (impl->extra_widget &&
- GTK_WIDGET_VISIBLE (impl->extra_widget))
+ gtk_widget_get_visible (impl->extra_widget))
{
- gtk_widget_size_request (impl->extra_align, &req);
- *default_height += GTK_BOX (chooser_embed)->spacing + req.height;
+ gtk_widget_get_preferred_size (impl->extra_align,
+ &req, NULL);
+ *default_height += gtk_box_get_spacing (GTK_BOX (chooser_embed)) + req.height;
}
}
else
{
- gtk_widget_size_request (GTK_WIDGET (impl), &req);
+ gtk_widget_get_preferred_size (GTK_WIDGET (impl),
+ &req, NULL);
*default_width = req.width;
*default_height = req.height;
}
GtkWidget *button;
button = gtk_button_new_with_mnemonic (mnemonic_label);
- GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+ gtk_widget_set_can_default (button, TRUE);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
gtk_widget_show (button);
-1);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
- if (toplevel->group)
- gtk_window_group_add_window (toplevel->group, GTK_WINDOW (dialog));
+ if (gtk_window_has_group (toplevel))
+ gtk_window_group_add_window (gtk_window_get_group (toplevel),
+ GTK_WINDOW (dialog));
response = gtk_dialog_run (GTK_DIALOG (dialog));
};
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();
+ }
+
+ if (needs_file_type_check) {
+ /* check that everything up to the last component exists */
- data->file_exists_and_is_not_folder = file_exists_and_is_not_folder;
- data_ownership_taken = TRUE;
+ 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);
+ 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);
}
entry = GTK_FILE_CHOOSER_ENTRY (impl->location_entry);
check_save_entry (impl, &file, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
- if (is_empty || !is_well_formed)
- return FALSE;
+ if (!is_well_formed)
+ return FALSE;
+
+ if (is_empty)
+ {
+ if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+ return FALSE;
+
+ goto file_list;
+ }
g_assert (file != NULL);
{
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);
return (gtk_tree_selection_count_selected_rows (selection) != 0);
}
-struct SearchHitInsertRequest
-{
- GtkFileChooserDefault *impl;
- GFile *file;
- GtkTreeRowReference *row_ref;
-};
-
-static void
-search_hit_get_info_cb (GCancellable *cancellable,
- GFileInfo *info,
- const GError *error,
- gpointer data)
-{
- gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- GdkPixbuf *pixbuf = NULL;
- GtkTreePath *path;
- GtkTreeIter iter;
- GCancellable *model_cancellable;
- gboolean is_folder = FALSE;
- GTimeVal mtime;
- goffset size;
- char *mime_type, *size_text, *mtime_text;
- char *display_name, *collated_name;
- struct SearchHitInsertRequest *request = data;
-
- if (!request->impl->search_model)
- goto out;
-
- path = gtk_tree_row_reference_get_path (request->row_ref);
- if (!path)
- goto out;
-
- gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->search_model),
- &iter, path);
- gtk_tree_path_free (path);
-
- gtk_tree_model_get (GTK_TREE_MODEL (request->impl->search_model), &iter,
- SEARCH_MODEL_COL_CANCELLABLE, &model_cancellable,
- -1);
- if (cancellable != model_cancellable)
- goto out;
-
- /* set the cancellable to NULL in the model */
- gtk_list_store_set (request->impl->search_model, &iter,
- SEARCH_MODEL_COL_CANCELLABLE, NULL,
- -1);
-
- if (cancelled)
- goto out;
-
- if (!info)
- {
- search_clear_model_row (GTK_TREE_MODEL (request->impl->search_model), &iter);
- gtk_list_store_remove (request->impl->search_model, &iter);
- goto out;
- }
-
- display_name = g_strdup (g_file_info_get_display_name (info));
- if (display_name)
- collated_name = g_utf8_collate_key_for_filename (display_name, -1);
- else
- collated_name = NULL;
- mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (info));
- is_folder = _gtk_file_info_consider_as_directory (info);
- g_file_info_get_modification_time (info, &mtime);
- size = g_file_info_get_size (info);
- size_text = is_folder ? NULL : g_format_size_for_display (size);
- mtime_text = mtime.tv_sec ? my_g_format_time_for_display (mtime.tv_sec) : g_strdup (_("Unknown"));
- pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (request->impl),
- request->impl->icon_size);
-
- gtk_list_store_set (request->impl->search_model, &iter,
- MODEL_COL_NAME, display_name,
- MODEL_COL_NAME_COLLATED, collated_name,
- MODEL_COL_IS_FOLDER, is_folder,
- MODEL_COL_PIXBUF, pixbuf,
- MODEL_COL_SIZE, size,
- MODEL_COL_SIZE_TEXT, size_text,
- MODEL_COL_MTIME, mtime.tv_sec,
- MODEL_COL_MTIME_TEXT, mtime_text,
- SEARCH_MODEL_COL_MIME_TYPE, mime_type,
- -1);
-
- if (pixbuf)
- g_object_unref (pixbuf);
- g_free (display_name);
- g_free (collated_name);
- g_free (mime_type);
- g_free (size_text);
- g_free (mtime_text);
-
-out:
- g_object_unref (request->impl);
- g_object_unref (request->file);
- gtk_tree_row_reference_free (request->row_ref);
- g_free (request);
-
- g_object_unref (cancellable);
-}
-
/* Adds one hit from the search engine to the search_model */
static void
search_add_hit (GtkFileChooserDefault *impl,
gchar *uri)
{
GFile *file;
- GtkTreeIter iter;
- GtkTreePath *p;
- GCancellable *cancellable;
- struct SearchHitInsertRequest *request;
file = g_file_new_for_uri (uri);
if (!file)
return;
}
- request = g_new0 (struct SearchHitInsertRequest, 1);
- request->impl = g_object_ref (impl);
- request->file = g_object_ref (file);
-
- gtk_list_store_append (impl->search_model, &iter);
- p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->search_model), &iter);
-
- request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->search_model), p);
- gtk_tree_path_free (p);
-
- cancellable = _gtk_file_system_get_info (impl->file_system, file,
- "standard::type,"
- "standard::icon,"
- "standard::content-type,"
- "standard::display-name,"
- "time::modified,"
- "standard::size",
- search_hit_get_info_cb,
- request);
-
- gtk_list_store_set (impl->search_model, &iter,
- MODEL_COL_FILE, file,
- MODEL_COL_ELLIPSIZE, PANGO_ELLIPSIZE_END,
- SEARCH_MODEL_COL_CANCELLABLE, cancellable,
- -1);
+ _gtk_file_system_model_add_and_query_file (impl->search_model,
+ file,
+ MODEL_ATTRIBUTES);
g_object_unref (file);
- g_object_unref (cancellable);
}
/* Callback used from GtkSearchEngine when we get new hits */
* but it'll make the search look like blocked.
*/
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
- GTK_TREE_MODEL (impl->search_model_filter));
+ GTK_TREE_MODEL (impl->search_model));
#endif
/* FMQ: if search was empty, say that we got no hits */
set_busy_cursor (impl, FALSE);
}
-static void
-search_clear_model_row (GtkTreeModel *model,
- GtkTreeIter *iter)
-{
- GCancellable *cancellable;
-
- gtk_tree_model_get (model, iter,
- SEARCH_MODEL_COL_CANCELLABLE, &cancellable,
- -1);
-
- if (cancellable)
- {
- g_cancellable_cancel (cancellable);
- g_object_unref (cancellable);
- }
-}
-
/* Frees the data in the search_model */
static void
search_clear_model (GtkFileChooserDefault *impl,
gboolean remove_from_treeview)
{
- GtkTreeModel *model;
- GtkTreeIter iter;
-
if (!impl->search_model)
return;
- model = GTK_TREE_MODEL (impl->search_model);
-
- if (gtk_tree_model_get_iter_first (model, &iter))
- do
- {
- search_clear_model_row (model, &iter);
- }
- while (gtk_tree_model_iter_next (model, &iter));
-
g_object_unref (impl->search_model);
impl->search_model = NULL;
- g_object_unref (impl->search_model_filter);
- impl->search_model_filter = NULL;
-
- g_object_unref (impl->search_model_sort);
- impl->search_model_sort = NULL;
-
if (remove_from_treeview)
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
}
file_list_set_sort_column_ids (impl);
}
-static gboolean
-search_get_is_filtered (GtkFileChooserDefault *impl,
- GFile *file,
- const gchar *display_name,
- const gchar *mime_type)
+/* Creates the search_model and puts it in the tree view */
+static void
+search_setup_model (GtkFileChooserDefault *impl)
{
- GtkFileFilterInfo filter_info;
- GtkFileFilterFlags needed;
- gboolean result;
+ g_assert (impl->search_model == NULL);
- if (!impl->current_filter)
- return FALSE;
+ impl->search_model = _gtk_file_system_model_new (file_system_model_set,
+ impl,
+ MODEL_COLUMN_TYPES);
- filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
- needed = gtk_file_filter_get_needed (impl->current_filter);
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model),
+ MODEL_COL_NAME,
+ name_sort_func,
+ impl, NULL);
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model),
+ MODEL_COL_MTIME,
+ mtime_sort_func,
+ impl, NULL);
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model),
+ MODEL_COL_SIZE,
+ size_sort_func,
+ impl, NULL);
+ set_sort_column (impl);
- filter_info.display_name = display_name;
- filter_info.mime_type = mime_type;
-
- if (needed & GTK_FILE_FILTER_FILENAME)
- {
- filter_info.filename = g_file_get_path (file);
- if (filter_info.filename)
- filter_info.contains |= GTK_FILE_FILTER_FILENAME;
- }
- else
- filter_info.filename = NULL;
-
- if (needed & GTK_FILE_FILTER_URI)
- {
- filter_info.uri = g_file_get_uri (file);
- if (filter_info.uri)
- filter_info.contains |= GTK_FILE_FILTER_URI;
- }
- else
- filter_info.uri = NULL;
-
- result = gtk_file_filter_filter (impl->current_filter, &filter_info);
-
- if (filter_info.filename)
- g_free ((gchar *) filter_info.filename);
- if (filter_info.uri)
- g_free ((gchar *) filter_info.uri);
-
- return !result;
-
-}
-
-/* Visibility function for the recent filter model */
-static gboolean
-search_model_visible_func (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- GtkFileChooserDefault *impl = user_data;
- GFile *file;
- gchar *display_name, *mime_type;
- gboolean is_folder, result;
-
- if (!impl->current_filter)
- return TRUE;
-
- gtk_tree_model_get (model, iter,
- MODEL_COL_FILE, &file,
- MODEL_COL_IS_FOLDER, &is_folder,
- MODEL_COL_NAME, &display_name,
- SEARCH_MODEL_COL_MIME_TYPE, &mime_type,
- -1);
-
- if (!display_name)
- result = TRUE;
- else if (is_folder)
- result = TRUE;
- else
- result = !search_get_is_filtered (impl, file, display_name, mime_type);
-
- g_free (display_name);
- g_free (mime_type);
-
- return result;
-}
-
-/* Creates the search_model and puts it in the tree view */
-static void
-search_setup_model (GtkFileChooserDefault *impl)
-{
- g_assert (impl->search_model == NULL);
- g_assert (impl->search_model_filter == NULL);
- g_assert (impl->search_model_sort == NULL);
-
- impl->search_model = gtk_list_store_new (SEARCH_MODEL_COL_NUM_COLUMNS,
- G_TYPE_STRING, /* MODEL_COL_NAME */
- G_TYPE_INT64, /* MODEL_COL_SIZE */
- G_TYPE_LONG, /* MODEL_COL_MTIME */
- G_TYPE_FILE, /* MODEL_COL_FILE */
- G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */
- G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */
- GDK_TYPE_PIXBUF, /* MODEL_COL_PIXBUF */
- G_TYPE_STRING, /* MODEL_COL_SIZE_TEXT */
- G_TYPE_STRING, /* MODEL_COL_MTIME_TEXT */
- PANGO_TYPE_ELLIPSIZE_MODE, /* MODEL_COL_ELLIPSIZE */
- G_TYPE_CANCELLABLE, /* SEARCH_MODEL_COL_CANCELLABLE */
- G_TYPE_STRING /* SEARCH_MODEL_COL_MIME_TYPE */
- );
-
- impl->search_model_filter =
- GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->search_model), NULL));
- gtk_tree_model_filter_set_visible_func (impl->search_model_filter,
- search_model_visible_func,
- impl, NULL);
-
- impl->search_model_sort =
- GTK_TREE_MODEL_SORT (search_model_sort_new (impl, GTK_TREE_MODEL (impl->search_model_filter)));
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model_sort),
- MODEL_COL_NAME,
- name_sort_func,
- impl, NULL);
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model_sort),
- MODEL_COL_MTIME,
- mtime_sort_func,
- impl, NULL);
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->search_model_sort),
- MODEL_COL_SIZE,
- size_sort_func,
- impl, NULL);
- set_sort_column (impl);
-
- /* EB: setting the model here will make the hits list update feel
- * more "alive" than setting the model at the end of the search
- * run
- */
- gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
- GTK_TREE_MODEL (impl->search_model_sort));
-}
-
-static void
-search_get_valid_child_iter (GtkFileChooserDefault *impl,
- GtkTreeIter *child_iter,
- GtkTreeIter *iter)
-{
- GtkTreeIter middle;
-
- if (!impl->search_model)
- return;
-
- if (!impl->search_model_filter || !impl->search_model_sort)
- return;
-
- /* pass 1: get the iterator in the filter model */
- gtk_tree_model_sort_convert_iter_to_child_iter (impl->search_model_sort,
- &middle, iter);
-
- /* pass 2: get the iterator in the real model */
- gtk_tree_model_filter_convert_iter_to_child_iter (impl->search_model_filter,
- child_iter, &middle);
-}
+ /* EB: setting the model here will make the hits list update feel
+ * more "alive" than setting the model at the end of the search
+ * run
+ */
+ gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
+ GTK_TREE_MODEL (impl->search_model));
+}
/* Creates a new query with the specified text and launches it */
static void
GtkWidget *image;
gchar *tmp;
- impl->search_hbox = gtk_hbox_new (FALSE, 12);
+ impl->search_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 12);
/* Image */
image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_BUTTON);
- gtk_size_group_add_widget (GTK_SIZE_GROUP (impl->browse_path_bar_size_group), image);
gtk_box_pack_start (GTK_BOX (impl->search_hbox), image, FALSE, FALSE, 5);
/* Label */
/* Box for search widgets */
gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->search_hbox, TRUE, TRUE, 0);
gtk_widget_show_all (impl->search_hbox);
+ gtk_size_group_add_widget (GTK_SIZE_GROUP (impl->browse_path_bar_size_group), impl->search_hbox);
/* Hide the location widgets temporarily */
switch (mode)
{
case OPERATION_MODE_BROWSE:
- stop_loading_and_clear_list_model (impl);
+ stop_loading_and_clear_list_model (impl, TRUE);
break;
case OPERATION_MODE_SEARCH:
g_assert (impl->search_hbox == NULL);
g_assert (impl->search_entry == NULL);
g_assert (impl->search_model == NULL);
- g_assert (impl->search_model_filter == NULL);
search_setup_widgets (impl);
file_list_set_sort_column_ids (impl);
gboolean remove_from_treeview)
{
GtkTreeModel *model;
- GtkTreeIter iter;
if (!impl->recent_model)
return;
if (remove_from_treeview)
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
- if (gtk_tree_model_get_iter_first (model, &iter))
- {
- do
- {
- GFile *file;
- GCancellable *cancellable;
- GtkRecentInfo *recent_info;
- gchar *display_name;
-
- gtk_tree_model_get (model, &iter,
- MODEL_COL_NAME, &display_name,
- MODEL_COL_FILE, &file,
- RECENT_MODEL_COL_CANCELLABLE, &cancellable,
- RECENT_MODEL_COL_INFO, &recent_info,
- -1);
-
- if (cancellable)
- g_cancellable_cancel (cancellable);
-
- g_object_unref (file);
- gtk_recent_info_unref (recent_info);
- g_free (display_name);
- }
- while (gtk_tree_model_iter_next (model, &iter));
- }
-
g_object_unref (impl->recent_model);
impl->recent_model = NULL;
-
- g_object_unref (impl->recent_model_filter);
- impl->recent_model_filter = NULL;
-
- g_object_unref (impl->recent_model_sort);
- impl->recent_model_sort = NULL;
}
/* Stops any ongoing loading of the recent files list; does
file_list_set_sort_column_ids (impl);
}
-static gboolean
-recent_get_is_filtered (GtkFileChooserDefault *impl,
- GFile *file,
- GtkRecentInfo *recent_info)
-{
- GtkFileFilterInfo filter_info;
- GtkFileFilterFlags needed;
- gboolean result;
-
- if (!impl->current_filter)
- return FALSE;
-
- filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
- needed = gtk_file_filter_get_needed (impl->current_filter);
-
- filter_info.display_name = gtk_recent_info_get_display_name (recent_info);
- filter_info.mime_type = gtk_recent_info_get_mime_type (recent_info);
-
- if (needed & GTK_FILE_FILTER_FILENAME)
- {
- filter_info.filename = g_file_get_path (file);
- if (filter_info.filename)
- filter_info.contains |= GTK_FILE_FILTER_FILENAME;
- }
- else
- filter_info.filename = NULL;
-
- if (needed & GTK_FILE_FILTER_URI)
- {
- filter_info.uri = g_file_get_uri (file);
- if (filter_info.uri)
- filter_info.contains |= GTK_FILE_FILTER_URI;
- }
- else
- filter_info.uri = NULL;
-
- result = gtk_file_filter_filter (impl->current_filter, &filter_info);
-
- if (filter_info.filename)
- g_free ((gchar *) filter_info.filename);
- if (filter_info.uri)
- g_free ((gchar *) filter_info.uri);
-
- return !result;
-}
-
-/* Visibility function for the recent filter model */
-static gboolean
-recent_model_visible_func (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- GtkFileChooserDefault *impl = user_data;
- GFile *file;
- GtkRecentInfo *recent_info;
- gboolean is_folder;
-
- if (!impl->current_filter)
- return TRUE;
-
- gtk_tree_model_get (model, iter,
- RECENT_MODEL_COL_INFO, &recent_info,
- MODEL_COL_FILE, &file,
- MODEL_COL_IS_FOLDER, &is_folder,
- -1);
-
- if (!recent_info)
- return TRUE;
-
- if (is_folder)
- return TRUE;
-
- return !recent_get_is_filtered (impl, file, recent_info);
-}
-
static void
recent_setup_model (GtkFileChooserDefault *impl)
{
g_assert (impl->recent_model == NULL);
- g_assert (impl->recent_model_filter == NULL);
- g_assert (impl->recent_model_sort == NULL);
-
- impl->recent_model = gtk_list_store_new (RECENT_MODEL_COL_NUM_COLUMNS,
- G_TYPE_STRING, /* MODEL_COL_NAME */
- G_TYPE_INT64, /* MODEL_COL_SIZE */
- G_TYPE_LONG, /* MODEL_COL_MTIME */
- G_TYPE_FILE, /* MODEL_COL_FILE */
- G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */
- G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */
- GDK_TYPE_PIXBUF, /* MODEL_COL_PIXBUF */
- G_TYPE_STRING, /* MODEL_COL_SIZE_TEXT */
- G_TYPE_STRING, /* MODEL_COL_MTIME_TEXT */
- PANGO_TYPE_ELLIPSIZE_MODE, /* MODEL_COL_ELLIPSIZE */
- G_TYPE_CANCELLABLE, /* RECENT_MODEL_COL_CANCELLABLE */
- G_TYPE_POINTER /* RECENT_MODEL_COL_INFO */
- );
-
- impl->recent_model_filter =
- GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL (impl->recent_model), NULL));
- gtk_tree_model_filter_set_visible_func (impl->recent_model_filter,
- recent_model_visible_func,
- impl,
- NULL);
-
- /* this is the model that will actually be added to
- * the browse_files_tree_view widget; remember: we are
- * stuffing the real model into a filter model and then
- * into a sort model; this means we'll have to translate
- * the child iterator *twice* to get from a path or an
- * iterator coming from the tree view widget to the
- * real data inside the model.
- */
- impl->recent_model_sort =
- GTK_TREE_MODEL_SORT (recent_model_sort_new (impl, GTK_TREE_MODEL (impl->recent_model_filter)));
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
+
+ impl->recent_model = _gtk_file_system_model_new (file_system_model_set,
+ impl,
+ MODEL_COLUMN_TYPES);
+
+ _gtk_file_system_model_set_filter (impl->recent_model,
+ impl->current_filter);
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model),
MODEL_COL_NAME,
name_sort_func,
impl, NULL);
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model),
MODEL_COL_SIZE,
size_sort_func,
impl, NULL);
- gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort),
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model),
MODEL_COL_MTIME,
mtime_sort_func,
impl, NULL);
GtkFileChooserDefault *impl = load_data->impl;
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
- GTK_TREE_MODEL (impl->recent_model_sort));
+ GTK_TREE_MODEL (impl->recent_model));
set_busy_cursor (impl, FALSE);
g_free (load_data);
}
-struct RecentItemInsertRequest
-{
- GtkFileChooserDefault *impl;
- GFile *file;
- GtkTreeRowReference *row_ref;
-};
-
-static void
-recent_item_get_info_cb (GCancellable *cancellable,
- GFileInfo *info,
- const GError *error,
- gpointer data)
-{
- gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- GtkTreePath *path;
- GtkTreeIter iter;
- GCancellable *model_cancellable;
- gboolean is_folder = FALSE;
- struct RecentItemInsertRequest *request = data;
- char *size_text;
- gint64 size;
-
- if (!request->impl->recent_model)
- goto out;
-
- path = gtk_tree_row_reference_get_path (request->row_ref);
- if (!path)
- goto out;
-
- gtk_tree_model_get_iter (GTK_TREE_MODEL (request->impl->recent_model),
- &iter, path);
- gtk_tree_path_free (path);
-
- gtk_tree_model_get (GTK_TREE_MODEL (request->impl->recent_model), &iter,
- RECENT_MODEL_COL_CANCELLABLE, &model_cancellable,
- -1);
- g_object_unref (model_cancellable);
- if (cancellable != model_cancellable)
- goto out;
-
- gtk_list_store_set (request->impl->recent_model, &iter,
- RECENT_MODEL_COL_CANCELLABLE, NULL,
- -1);
-
- if (cancelled)
- goto out;
-
- if (!info)
- {
- gtk_list_store_remove (request->impl->recent_model, &iter);
- goto out;
- }
-
- is_folder = _gtk_file_info_consider_as_directory (info);
- size = g_file_info_get_size (info);
- size_text = is_folder ? g_format_size_for_display (size) : g_strdup ("");
-
- gtk_list_store_set (request->impl->recent_model, &iter,
- MODEL_COL_IS_FOLDER, is_folder,
- MODEL_COL_SIZE, size,
- MODEL_COL_SIZE_TEXT, size_text,
- -1);
-
- g_free (size_text);
-
-out:
- g_object_unref (request->impl);
- g_object_unref (request->file);
- gtk_tree_row_reference_free (request->row_ref);
- g_free (request);
-
- g_object_unref (cancellable);
-}
-
static gint
recent_sort_mru (gconstpointer a,
gconstpointer b)
{
RecentLoadData *load_data = data;
GtkFileChooserDefault *impl = load_data->impl;
- GtkTreeIter iter;
- GtkTreePath *p;
- GtkRecentInfo *info;
- const gchar *uri, *display_name, *mtime_text, *collated_name;
- glong mtime;
+ GList *walk;
GFile *file;
- GCancellable *cancellable;
- struct RecentItemInsertRequest *request;
if (!impl->recent_manager)
return FALSE;
return TRUE;
}
- info = g_list_nth_data (load_data->items, load_data->n_loaded_items);
- g_assert (info != NULL);
-
- uri = gtk_recent_info_get_uri (info);
- display_name = gtk_recent_info_get_display_name (info);
- file = g_file_new_for_uri (uri);
-
- gtk_list_store_append (impl->recent_model, &iter);
- p = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->recent_model), &iter);
-
- request = g_new0 (struct RecentItemInsertRequest, 1);
- request->impl = g_object_ref (impl);
- request->file = g_object_ref (file);
- request->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->recent_model), p);
- gtk_tree_path_free (p);
-
- cancellable = _gtk_file_system_get_info (impl->file_system, file,
- "standard::type,standard::size",
- recent_item_get_info_cb,
- request);
-
- collated_name = g_utf8_collate_key_for_filename (gtk_recent_info_get_display_name (info), -1);
- mtime = gtk_recent_info_get_modified (info);
- mtime_text = mtime ? my_g_format_time_for_display (mtime) : g_strdup (_("Unknown"));
-
- gtk_list_store_set (impl->recent_model, &iter,
- MODEL_COL_FILE, file,
- MODEL_COL_NAME, gtk_recent_info_get_display_name (info),
- MODEL_COL_NAME_COLLATED, collated_name,
- MODEL_COL_PIXBUF, gtk_recent_info_get_icon (info, impl->icon_size),
- MODEL_COL_MTIME, mtime,
- MODEL_COL_MTIME_TEXT, mtime_text,
- MODEL_COL_ELLIPSIZE, PANGO_ELLIPSIZE_END,
- RECENT_MODEL_COL_CANCELLABLE, cancellable,
- RECENT_MODEL_COL_INFO, gtk_recent_info_ref (info),
- -1);
-
- load_data->n_loaded_items += 1;
-
/* finished loading items */
- if (load_data->n_loaded_items == load_data->n_items)
+ for (walk = load_data->items; walk; walk = walk->next)
{
- g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
- g_list_free (load_data->items);
- load_data->items = NULL;
+ GtkRecentInfo *info = walk->data;
+ file = g_file_new_for_uri (gtk_recent_info_get_uri (info));
- return FALSE;
+ _gtk_file_system_model_add_and_query_file (impl->recent_model,
+ file,
+ MODEL_ATTRIBUTES);
+ gtk_recent_info_unref (walk->data);
+ g_object_unref (file);
}
- return TRUE;
+ g_list_free (load_data->items);
+ load_data->items = NULL;
+
+ return FALSE;
}
static void
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);
- gtk_size_group_add_widget (impl->browse_path_bar_size_group, image);
gtk_box_pack_start (GTK_BOX (impl->recent_hbox), image, FALSE, FALSE, 5);
/* Label */
/* Box for recent widgets */
gtk_box_pack_start (GTK_BOX (impl->browse_path_bar_hbox), impl->recent_hbox, TRUE, TRUE, 0);
+ gtk_size_group_add_widget (impl->browse_path_bar_size_group, impl->recent_hbox);
gtk_widget_show_all (impl->recent_hbox);
/* Hide the location widgets temporarily */
recent_hide_entry (impl);
- /* hide the file size column if it's visible */
- gtk_tree_view_column_set_visible (impl->list_size_column, FALSE);
-
file_list_set_sort_column_ids (impl);
recent_start_loading (impl);
}
-/* convert an iterator coming from the model bound to
- * browse_files_tree_view to an interator inside the
- * real recent_model
- */
-static void
-recent_get_valid_child_iter (GtkFileChooserDefault *impl,
- GtkTreeIter *child_iter,
- GtkTreeIter *iter)
-{
- GtkTreeIter middle;
-
- if (!impl->recent_model)
- return;
-
- if (!impl->recent_model_filter || !impl->recent_model_sort)
- return;
-
- /* pass 1: get the iterator in the filter model */
- gtk_tree_model_sort_convert_iter_to_child_iter (impl->recent_model_sort,
- &middle, iter);
-
- /* pass 2: get the iterator in the real model */
- gtk_tree_model_filter_convert_iter_to_child_iter (impl->recent_model_filter,
- child_iter,
- &middle);
-}
-
-
static void
set_current_filter (GtkFileChooserDefault *impl,
GtkFileFilter *filter)
if (impl->browse_files_model)
install_list_model_filter (impl);
- if (impl->operation_mode == OPERATION_MODE_SEARCH &&
- impl->search_model_filter != NULL)
- gtk_tree_model_filter_refilter (impl->search_model_filter);
+ if (impl->search_model)
+ _gtk_file_system_model_set_filter (impl->search_model, filter);
- /* we want to have all the matching results, and not just a
- * filter of the previous model
- */
- if (impl->operation_mode == OPERATION_MODE_RECENT)
- recent_start_loading (impl);
+ if (impl->recent_model)
+ _gtk_file_system_model_set_filter (impl->recent_model, filter);
g_object_notify (G_OBJECT (impl), "filter");
}
_gtk_file_system_get_info (data->impl->file_system, data->file,
"standard::type",
shortcuts_activate_get_info_cb, data);
+
+ if (volume)
+ _gtk_file_system_volume_unref (volume);
}
static void
return TRUE;
}
- if ((event->keyval == GDK_BackSpace
- || event->keyval == GDK_Delete
- || event->keyval == GDK_KP_Delete)
+ if ((event->keyval == GDK_KEY_BackSpace
+ || event->keyval == GDK_KEY_Delete
+ || event->keyval == GDK_KEY_KP_Delete)
&& (event->state & modifiers) == 0)
{
remove_selected_bookmarks (impl);
return TRUE;
}
- if ((event->keyval == GDK_F2)
+ if ((event->keyval == GDK_KEY_F2)
&& (event->state & modifiers) == 0)
{
rename_selected_bookmark (impl);
always_sensitive = impl->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER &&
impl->action != GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
+ /* Keep the following column numbers in sync with create_file_list() */
+
/* name */
column = gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 0);
list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
return GTK_TREE_MODEL (model);
}
-\f
-
-static gboolean
-recent_model_sort_row_draggable (GtkTreeDragSource *drag_source,
- GtkTreePath *path)
-{
- RecentModelSort *model;
- GtkTreeIter iter, child_iter;
- gboolean is_folder;
-
- model = RECENT_MODEL_SORT (drag_source);
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
- return FALSE;
-
- recent_get_valid_child_iter (model->impl, &child_iter, &iter);
- gtk_tree_model_get (GTK_TREE_MODEL (model->impl->recent_model), &child_iter,
- MODEL_COL_IS_FOLDER, &is_folder,
- -1);
-
- return is_folder;
-}
-
-static gboolean
-recent_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
- GtkTreePath *path,
- GtkSelectionData *selection_data)
-{
- RecentModelSort *model;
- GtkTreeIter iter, child_iter;
- GFile *file;
- gchar *uris[2];
-
- model = RECENT_MODEL_SORT (drag_source);
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
- return FALSE;
-
- recent_get_valid_child_iter (model->impl, &child_iter, &iter);
- gtk_tree_model_get (GTK_TREE_MODEL (model->impl->recent_model), &child_iter,
- MODEL_COL_FILE, &file,
- -1);
- g_assert (file != NULL);
-
- uris[0] = g_file_get_uri (file);
- uris[1] = NULL;
-
- gtk_selection_data_set_uris (selection_data, uris);
-
- g_free (uris[0]);
- g_object_unref (file);
-
- return TRUE;
-}
-
-static void
-recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface)
-{
- iface->row_draggable = recent_model_sort_row_draggable;
- iface->drag_data_get = recent_model_sort_drag_data_get;
-}
-
-static void
-_recent_model_sort_class_init (RecentModelSortClass *klass)
-{
-
-}
-
-static void
-_recent_model_sort_init (RecentModelSort *model)
-{
- model->impl = NULL;
-}
-
-static GtkTreeModel *
-recent_model_sort_new (GtkFileChooserDefault *impl,
- GtkTreeModel *child_model)
-{
- RecentModelSort *model;
-
- model = g_object_new (RECENT_MODEL_SORT_TYPE,
- "model", child_model,
- NULL);
- model->impl = impl;
-
- return GTK_TREE_MODEL (model);
-}
-
-\f
-
-static gboolean
-search_model_sort_row_draggable (GtkTreeDragSource *drag_source,
- GtkTreePath *path)
-{
- SearchModelSort *model;
- GtkTreeIter iter, child_iter;
- gboolean is_folder;
-
- model = SEARCH_MODEL_SORT (drag_source);
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
- return FALSE;
-
- search_get_valid_child_iter (model->impl, &child_iter, &iter);
- gtk_tree_model_get (GTK_TREE_MODEL (model->impl->search_model), &child_iter,
- MODEL_COL_IS_FOLDER, &is_folder,
- -1);
-
- return is_folder;
-}
-
-static gboolean
-search_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
- GtkTreePath *path,
- GtkSelectionData *selection_data)
-{
- SearchModelSort *model;
- GtkTreeIter iter, child_iter;
- GFile *file;
- gchar *uris[2];
-
- model = SEARCH_MODEL_SORT (drag_source);
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
- return FALSE;
-
- search_get_valid_child_iter (model->impl, &child_iter, &iter);
- gtk_tree_model_get (GTK_TREE_MODEL (model->impl->search_model), &child_iter,
- MODEL_COL_FILE, &file,
- -1);
- g_assert (file != NULL);
-
- uris[0] = g_file_get_uri (file);
- uris[1] = NULL;
-
- gtk_selection_data_set_uris (selection_data, uris);
-
- g_free (uris[0]);
- g_object_unref (file);
-
- return TRUE;
-}
-
-static void
-search_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface)
-{
- iface->row_draggable = search_model_sort_row_draggable;
- iface->drag_data_get = search_model_sort_drag_data_get;
-}
-
-static void
-_search_model_sort_class_init (SearchModelSortClass *klass)
-{
-
-}
-
-static void
-_search_model_sort_init (SearchModelSort *model)
-{
- model->impl = NULL;
-}
-
-static GtkTreeModel *
-search_model_sort_new (GtkFileChooserDefault *impl,
- GtkTreeModel *child_model)
-{
- SearchModelSort *model;
-
- model = g_object_new (SEARCH_MODEL_SORT_TYPE,
- "model", child_model,
- NULL);
- model->impl = impl;
-
- return GTK_TREE_MODEL (model);
-}