summaryrefslogtreecommitdiffstats
path: root/meta/packages/gtk+
diff options
context:
space:
mode:
authorTomas Frydrych <tf@openedhand.com>2007-02-09 13:16:38 +0000
committerTomas Frydrych <tf@openedhand.com>2007-02-09 13:16:38 +0000
commit19d07794eed15aad348bb6c8b4514936b49a421a (patch)
tree01197036b61759006f6dfefdbf4ec347bfb159d7 /meta/packages/gtk+
parent2f9b5a87f732dbe9cabab188596956e919638f47 (diff)
downloadpoky-19d07794eed15aad348bb6c8b4514936b49a421a.tar.gz
simplified filechooser dialog
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@1266 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'meta/packages/gtk+')
-rw-r--r--meta/packages/gtk+/gtk+-2.6.8/filechooser-default.patch5152
-rw-r--r--meta/packages/gtk+/gtk+-2.6.8/filechooser-respect-style.patch77
-rw-r--r--meta/packages/gtk+/gtk+_2.6.8.bb6
3 files changed, 5233 insertions, 2 deletions
diff --git a/meta/packages/gtk+/gtk+-2.6.8/filechooser-default.patch b/meta/packages/gtk+/gtk+-2.6.8/filechooser-default.patch
new file mode 100644
index 0000000000..d4534212a0
--- /dev/null
+++ b/meta/packages/gtk+/gtk+-2.6.8/filechooser-default.patch
@@ -0,0 +1,5152 @@
1--- gtk+-2.6.8/gtk/gtkfilechooserdefault.c.orig 2007-02-09 12:28:31.000000000 +0000
2+++ gtk+-2.6.8/gtk/gtkfilechooserdefault.c 2007-02-09 12:28:31.000000000 +0000
3@@ -31,7 +31,6 @@
4 #include "gtkcombobox.h"
5 #include "gtkentry.h"
6 #include "gtkeventbox.h"
7-#include "gtkexpander.h"
8 #include "gtkfilechooserdefault.h"
9 #include "gtkfilechooserembed.h"
10 #include "gtkfilechooserentry.h"
11@@ -50,7 +49,6 @@
12 #include "gtkmarshalers.h"
13 #include "gtkmenuitem.h"
14 #include "gtkmessagedialog.h"
15-#include "gtkpathbar.h"
16 #include "gtkprivate.h"
17 #include "gtkscrolledwindow.h"
18 #include "gtkseparatormenuitem.h"
19@@ -79,18 +77,23 @@
20 #include <string.h>
21 #include <time.h>
22
23+#define DEFAULT_SPACING 5
24+
25+#define GTK26
26 typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass;
27
28 #define GTK_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
29 #define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT))
30 #define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
31
32+#ifdef GTK26
33 typedef enum {
34 LOAD_EMPTY, /* There is no model */
35 LOAD_PRELOAD, /* Model is loading and a timer is running; model isn't inserted into the tree yet */
36 LOAD_LOADING, /* Timeout expired, model is inserted into the tree, but not fully loaded yet */
37 LOAD_FINISHED /* Model is fully loaded and inserted into the tree */
38 } LoadState;
39+#endif
40
41 #define MAX_LOADING_TIME 500
42
43@@ -109,63 +112,33 @@
44
45 /* Save mode widgets */
46 GtkWidget *save_widgets;
47-
48 GtkWidget *save_file_name_entry;
49- GtkWidget *save_folder_label;
50- GtkWidget *save_folder_combo;
51- GtkWidget *save_expander;
52
53 /* The file browsing widgets */
54 GtkWidget *browse_widgets;
55- GtkWidget *browse_shortcuts_tree_view;
56- GtkWidget *browse_shortcuts_add_button;
57- GtkWidget *browse_shortcuts_remove_button;
58 GtkWidget *browse_files_tree_view;
59- GtkWidget *browse_files_popup_menu;
60- GtkWidget *browse_files_popup_menu_add_shortcut_item;
61- GtkWidget *browse_files_popup_menu_hidden_files_item;
62 GtkWidget *browse_new_folder_button;
63- GtkWidget *browse_path_bar;
64-
65+ GtkWidget *bar;
66+ GtkWidget * up_button;
67+
68 GtkFileSystemModel *browse_files_model;
69
70- GtkWidget *filter_combo_hbox;
71- GtkWidget *filter_combo;
72- GtkWidget *preview_box;
73- GtkWidget *preview_label;
74- GtkWidget *preview_widget;
75- GtkWidget *extra_align;
76- GtkWidget *extra_widget;
77-
78- GtkListStore *shortcuts_model;
79- GtkTreeModel *shortcuts_filter_model;
80-
81 GtkTreeModelSort *sort_model;
82
83 LoadState load_state;
84 guint load_timeout_id;
85
86 GSList *pending_select_paths;
87-
88- GtkFileFilter *current_filter;
89- GSList *filters;
90-
91+ GSList * path_history;
92+
93 GtkTooltips *tooltips;
94
95- gboolean has_home;
96- gboolean has_desktop;
97-
98 int num_volumes;
99- int num_shortcuts;
100- int num_bookmarks;
101
102 gulong volumes_changed_id;
103- gulong bookmarks_changed_id;
104
105 GtkFilePath *current_volume_path;
106 GtkFilePath *current_folder;
107- GtkFilePath *preview_path;
108- char *preview_display_name;
109
110 GtkTreeViewColumn *list_name_column;
111 GtkCellRenderer *list_name_renderer;
112@@ -179,25 +152,15 @@
113 gulong toplevel_set_focus_id;
114 GtkWidget *toplevel_last_focus_widget;
115
116-#if 0
117- GdkDragContext *shortcuts_drag_context;
118- GSource *shortcuts_drag_outside_idle;
119-#endif
120-
121+ gchar * root_folder;
122+
123 /* Flags */
124
125 guint local_only : 1;
126- guint preview_widget_active : 1;
127- guint use_preview_label : 1;
128 guint select_multiple : 1;
129 guint show_hidden : 1;
130 guint list_sort_ascending : 1;
131 guint changing_folder : 1;
132- guint shortcuts_current_folder_active : 1;
133-
134-#if 0
135- guint shortcuts_drag_outside : 1;
136-#endif
137 };
138
139 /* Signal IDs */
140@@ -211,17 +174,6 @@
141
142 static guint signals[LAST_SIGNAL] = { 0 };
143
144-/* Column numbers for the shortcuts tree. Keep these in sync with shortcuts_model_create() */
145-enum {
146- SHORTCUTS_COL_PIXBUF,
147- SHORTCUTS_COL_NAME,
148- SHORTCUTS_COL_DATA,
149- SHORTCUTS_COL_IS_VOLUME,
150- SHORTCUTS_COL_REMOVABLE,
151- SHORTCUTS_COL_PIXBUF_VISIBLE,
152- SHORTCUTS_COL_NUM_COLUMNS
153-};
154-
155 /* Column numbers for the file list */
156 enum {
157 FILE_LIST_COL_NAME,
158@@ -236,23 +188,6 @@
159 TEXT_URI_LIST
160 };
161
162-/* Target types for dragging from the shortcuts list */
163-static const GtkTargetEntry shortcuts_source_targets[] = {
164- { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW }
165-};
166-
167-static const int num_shortcuts_source_targets = (sizeof (shortcuts_source_targets)
168- / sizeof (shortcuts_source_targets[0]));
169-
170-/* Target types for dropping into the shortcuts list */
171-static const GtkTargetEntry shortcuts_dest_targets[] = {
172- { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW },
173- { "text/uri-list", 0, TEXT_URI_LIST }
174-};
175-
176-static const int num_shortcuts_dest_targets = (sizeof (shortcuts_dest_targets)
177- / sizeof (shortcuts_dest_targets[0]));
178-
179 /* Target types for DnD from the file list */
180 static const GtkTargetEntry file_list_source_targets[] = {
181 { "text/uri-list", 0, TEXT_URI_LIST }
182@@ -261,22 +196,10 @@
183 static const int num_file_list_source_targets = (sizeof (file_list_source_targets)
184 / sizeof (file_list_source_targets[0]));
185
186-/* Interesting places in the shortcuts bar */
187-typedef enum {
188- SHORTCUTS_HOME,
189- SHORTCUTS_DESKTOP,
190- SHORTCUTS_VOLUMES,
191- SHORTCUTS_SHORTCUTS,
192- SHORTCUTS_BOOKMARKS_SEPARATOR,
193- SHORTCUTS_BOOKMARKS,
194- SHORTCUTS_CURRENT_FOLDER_SEPARATOR,
195- SHORTCUTS_CURRENT_FOLDER
196-} ShortcutsIndex;
197-
198 /* Icon size for if we can't get it from the theme */
199 #define FALLBACK_ICON_SIZE 16
200
201-#define PREVIEW_HBOX_SPACING 12
202+#define LIST_HBOX_SPACING DEFAULT_SPACING
203 #define NUM_LINES 40
204 #define NUM_CHARS 60
205
206@@ -335,7 +258,6 @@
207 const GtkFilePath *path,
208 GError **error);
209 static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser);
210-
211 static void gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
212 gint *default_width,
213 gint *default_height);
214@@ -352,37 +274,6 @@
215 static void home_folder_handler (GtkFileChooserDefault *impl);
216 static void update_appearance (GtkFileChooserDefault *impl);
217
218-static void set_current_filter (GtkFileChooserDefault *impl,
219- GtkFileFilter *filter);
220-static void check_preview_change (GtkFileChooserDefault *impl);
221-
222-static void filter_combo_changed (GtkComboBox *combo_box,
223- GtkFileChooserDefault *impl);
224-static void shortcuts_row_activated_cb (GtkTreeView *tree_view,
225- GtkTreePath *path,
226- GtkTreeViewColumn *column,
227- GtkFileChooserDefault *impl);
228-
229-static gboolean shortcuts_key_press_event_cb (GtkWidget *widget,
230- GdkEventKey *event,
231- GtkFileChooserDefault *impl);
232-
233-static gboolean shortcuts_select_func (GtkTreeSelection *selection,
234- GtkTreeModel *model,
235- GtkTreePath *path,
236- gboolean path_currently_selected,
237- gpointer data);
238-static gboolean shortcuts_get_selected (GtkFileChooserDefault *impl,
239- GtkTreeIter *iter);
240-static void shortcuts_activate_iter (GtkFileChooserDefault *impl,
241- GtkTreeIter *iter);
242-static int shortcuts_get_index (GtkFileChooserDefault *impl,
243- ShortcutsIndex where);
244-static int shortcut_find_position (GtkFileChooserDefault *impl,
245- const GtkFilePath *path);
246-
247-static void bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl);
248-
249 static gboolean list_select_func (GtkTreeSelection *selection,
250 GtkTreeModel *model,
251 GtkTreePath *path,
252@@ -401,16 +292,6 @@
253 GtkTreeIter *iter,
254 gpointer user_data);
255
256-static void path_bar_clicked (GtkPathBar *path_bar,
257- GtkFilePath *file_path,
258- gboolean child_is_hidden,
259- GtkFileChooserDefault *impl);
260-
261-static void add_bookmark_button_clicked_cb (GtkButton *button,
262- GtkFileChooserDefault *impl);
263-static void remove_bookmark_button_clicked_cb (GtkButton *button,
264- GtkFileChooserDefault *impl);
265-
266 static void list_icon_data_func (GtkTreeViewColumn *tree_column,
267 GtkCellRenderer *cell,
268 GtkTreeModel *tree_model,
269@@ -441,36 +322,6 @@
270
271 static GObjectClass *parent_class;
272
273-
274-
275-/* Drag and drop interface declarations */
276-
277-typedef struct {
278- GtkTreeModelFilter parent;
279-
280- GtkFileChooserDefault *impl;
281-} ShortcutsModelFilter;
282-
283-typedef struct {
284- GtkTreeModelFilterClass parent_class;
285-} ShortcutsModelFilterClass;
286-
287-#define SHORTCUTS_MODEL_FILTER_TYPE (_shortcuts_model_filter_get_type ())
288-#define SHORTCUTS_MODEL_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUTS_MODEL_FILTER_TYPE, ShortcutsModelFilter))
289-
290-static void shortcuts_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface);
291-
292-G_DEFINE_TYPE_WITH_CODE (ShortcutsModelFilter,
293- _shortcuts_model_filter,
294- GTK_TYPE_TREE_MODEL_FILTER,
295- G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
296- shortcuts_model_filter_drag_source_iface_init));
297-
298-static GtkTreeModel *shortcuts_model_filter_new (GtkFileChooserDefault *impl,
299- GtkTreeModel *child_model,
300- GtkTreePath *root);
301-
302-
303
304 GType
305 _gtk_file_chooser_default_get_type (void)
306@@ -520,6 +371,11 @@
307 return file_chooser_default_type;
308 }
309
310+enum
311+{
312+ GTK_FILE_CHOOSER_PROP_ROOT_FOLDER = GTK_FILE_CHOOSER_PROP_LAST + 1,
313+};
314+
315 static void
316 gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
317 {
318@@ -617,6 +473,14 @@
319 "home-folder",
320 0);
321
322+ g_object_class_install_property (gobject_class,
323+ GTK_FILE_CHOOSER_PROP_ROOT_FOLDER,
324+ g_param_spec_string ("root-folder",
325+ P_("File System Root"),
326+ P_("Root folder for the file system below which the user should not be able to switch"),
327+ NULL,
328+ G_PARAM_WRITABLE));
329+
330 _gtk_file_chooser_install_properties (gobject_class);
331
332 gtk_settings_install_property (g_param_spec_string ("gtk-file-chooser-backend",
333@@ -634,17 +498,19 @@
334 iface->select_all = gtk_file_chooser_default_select_all;
335 iface->unselect_all = gtk_file_chooser_default_unselect_all;
336 iface->get_paths = gtk_file_chooser_default_get_paths;
337- iface->get_preview_path = gtk_file_chooser_default_get_preview_path;
338 iface->get_file_system = gtk_file_chooser_default_get_file_system;
339 iface->set_current_folder = gtk_file_chooser_default_set_current_folder;
340 iface->get_current_folder = gtk_file_chooser_default_get_current_folder;
341 iface->set_current_name = gtk_file_chooser_default_set_current_name;
342+
343+ /* these are only stubs */
344+ iface->get_preview_path = gtk_file_chooser_default_get_preview_path;
345 iface->add_filter = gtk_file_chooser_default_add_filter;
346 iface->remove_filter = gtk_file_chooser_default_remove_filter;
347 iface->list_filters = gtk_file_chooser_default_list_filters;
348 iface->add_shortcut_folder = gtk_file_chooser_default_add_shortcut_folder;
349 iface->remove_shortcut_folder = gtk_file_chooser_default_remove_shortcut_folder;
350- iface->list_shortcut_folders = gtk_file_chooser_default_list_shortcut_folders;
351+
352 }
353
354 static void
355@@ -659,71 +525,22 @@
356 gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
357 {
358 impl->local_only = TRUE;
359- impl->preview_widget_active = TRUE;
360- impl->use_preview_label = TRUE;
361 impl->select_multiple = FALSE;
362 impl->show_hidden = FALSE;
363 impl->icon_size = FALLBACK_ICON_SIZE;
364 impl->load_state = LOAD_EMPTY;
365 impl->pending_select_paths = NULL;
366-
367+ impl->path_history = NULL;
368+
369 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (impl), TRUE);
370- gtk_box_set_spacing (GTK_BOX (impl), 12);
371+ gtk_box_set_spacing (GTK_BOX (impl), DEFAULT_SPACING);
372
373 impl->tooltips = gtk_tooltips_new ();
374 g_object_ref (impl->tooltips);
375 gtk_object_sink (GTK_OBJECT (impl->tooltips));
376-}
377-
378-/* Frees the data columns for the specified iter in the shortcuts model*/
379-static void
380-shortcuts_free_row_data (GtkFileChooserDefault *impl,
381- GtkTreeIter *iter)
382-{
383- gpointer col_data;
384- gboolean is_volume;
385-
386- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
387- SHORTCUTS_COL_DATA, &col_data,
388- SHORTCUTS_COL_IS_VOLUME, &is_volume,
389- -1);
390- if (!col_data)
391- return;
392-
393- if (is_volume)
394- {
395- GtkFileSystemVolume *volume;
396-
397- volume = col_data;
398- gtk_file_system_volume_free (impl->file_system, volume);
399- }
400- else
401- {
402- GtkFilePath *path;
403-
404- path = col_data;
405- gtk_file_path_free (path);
406- }
407-}
408-
409-/* Frees all the data columns in the shortcuts model */
410-static void
411-shortcuts_free (GtkFileChooserDefault *impl)
412-{
413- GtkTreeIter iter;
414-
415- if (!impl->shortcuts_model)
416- return;
417-
418- if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
419- do
420- {
421- shortcuts_free_row_data (impl, &iter);
422- }
423- while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter));
424
425- g_object_unref (impl->shortcuts_model);
426- impl->shortcuts_model = NULL;
427+ if (!impl->root_folder)
428+ impl->root_folder = g_strdup ("/");
429 }
430
431 static void
432@@ -743,6 +560,7 @@
433 impl->pending_select_paths = NULL;
434 }
435
436+
437 static void
438 pending_select_paths_add (GtkFileChooserDefault *impl,
439 const GtkFilePath *path)
440@@ -782,45 +600,40 @@
441 }
442
443 static void
444-gtk_file_chooser_default_finalize (GObject *object)
445+path_history_free (GtkFileChooserDefault *impl)
446 {
447- GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
448 GSList *l;
449
450- if (impl->shortcuts_filter_model)
451- g_object_unref (impl->shortcuts_filter_model);
452+ for (l = impl->path_history; l; l = l->next)
453+ {
454+ GtkFilePath *path;
455+
456+ path = l->data;
457+ gtk_file_path_free (path);
458+ }
459+
460+ g_slist_free (impl->path_history);
461+ impl->path_history = NULL;
462+}
463
464- shortcuts_free (impl);
465+static void
466+gtk_file_chooser_default_finalize (GObject *object)
467+{
468+ GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
469
470 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
471 impl->volumes_changed_id = 0;
472- g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
473- impl->bookmarks_changed_id = 0;
474 g_object_unref (impl->file_system);
475
476- for (l = impl->filters; l; l = l->next)
477- {
478- GtkFileFilter *filter;
479-
480- filter = GTK_FILE_FILTER (l->data);
481- g_object_unref (filter);
482- }
483- g_slist_free (impl->filters);
484-
485- if (impl->current_filter)
486- g_object_unref (impl->current_filter);
487-
488 if (impl->current_volume_path)
489 gtk_file_path_free (impl->current_volume_path);
490
491 if (impl->current_folder)
492 gtk_file_path_free (impl->current_folder);
493
494- if (impl->preview_path)
495- gtk_file_path_free (impl->preview_path);
496-
497 pending_select_paths_free (impl);
498-
499+ path_history_free (impl);
500+
501 load_remove_timer (impl);
502
503 /* Free all the Models we have */
504@@ -830,12 +643,12 @@
505 if (impl->sort_model)
506 g_object_unref (impl->sort_model);
507
508- g_free (impl->preview_display_name);
509-
510 g_free (impl->edited_new_text);
511
512 g_object_unref (impl->tooltips);
513
514+ g_free (impl->root_folder);
515+
516 G_OBJECT_CLASS (parent_class)->finalize (object);
517 }
518
519@@ -916,28 +729,6 @@
520 path, error);
521 }
522
523-/* Shows an error dialog about not being able to add a bookmark */
524-static void
525-error_adding_bookmark_dialog (GtkFileChooserDefault *impl,
526- const GtkFilePath *path,
527- GError *error)
528-{
529- error_dialog (impl,
530- _("Could not add a bookmark"),
531- path, error);
532-}
533-
534-/* Shows an error dialog about not being able to remove a bookmark */
535-static void
536-error_removing_bookmark_dialog (GtkFileChooserDefault *impl,
537- const GtkFilePath *path,
538- GError *error)
539-{
540- error_dialog (impl,
541- _("Could not remove bookmark"),
542- path, error);
543-}
544-
545 /* Shows an error dialog about not being able to create a folder */
546 static void
547 error_creating_folder_dialog (GtkFileChooserDefault *impl,
548@@ -949,21 +740,6 @@
549 path, error);
550 }
551
552-/* Shows an error about not being able to create a folder because a file with
553- * the same name is already there.
554- */
555-static void
556-error_creating_folder_over_existing_file_dialog (GtkFileChooserDefault *impl,
557- const GtkFilePath *path,
558- GError *error)
559-{
560- error_dialog (impl,
561- _("The folder could not be created, as a file with the same name "
562- "already exists. Try using a different name for the folder, "
563- "or rename the file first."),
564- path, error);
565-}
566-
567 /* Shows an error dialog about not being able to create a filename */
568 static void
569 error_building_filename_dialog (GtkFileChooserDefault *impl,
570@@ -993,6 +769,7 @@
571 GError *error;
572 gboolean result;
573 GtkFilePath *path_copy;
574+ gchar * file_name;
575
576 /* We copy the path because of this case:
577 *
578@@ -1005,6 +782,29 @@
579
580 path_copy = gtk_file_path_copy (path);
581
582+ file_name = gtk_file_system_path_to_filename (impl->file_system, path_copy);
583+
584+ /* refuse to change below the root */
585+ if (file_name && impl->root_folder &&
586+ strcmp (file_name, impl->root_folder) &&
587+ !strncmp (file_name, impl->root_folder, strlen (file_name)))
588+ {
589+
590+ gtk_file_path_free (path_copy);
591+ g_free (file_name);
592+ return 0;
593+ }
594+ else if (file_name && impl->root_folder &&
595+ !strcmp (file_name, impl->root_folder))
596+ {
597+ gtk_widget_set_sensitive (impl->up_button, FALSE);
598+ }
599+ else
600+ {
601+ gtk_widget_set_sensitive (impl->up_button, TRUE);
602+ }
603+
604+
605 error = NULL;
606 result = _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), path_copy, &error);
607
608@@ -1012,2009 +812,234 @@
609 error_changing_folder_dialog (impl, path_copy, error);
610
611 gtk_file_path_free (path_copy);
612-
613+ g_free (file_name);
614+
615 return result;
616 }
617
618-static void
619-update_preview_widget_visibility (GtkFileChooserDefault *impl)
620-{
621- if (impl->use_preview_label)
622- {
623- if (!impl->preview_label)
624- {
625- impl->preview_label = gtk_label_new (impl->preview_display_name);
626- gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_label, FALSE, FALSE, 0);
627- gtk_box_reorder_child (GTK_BOX (impl->preview_box), impl->preview_label, 0);
628- gtk_label_set_ellipsize (GTK_LABEL (impl->preview_label), PANGO_ELLIPSIZE_MIDDLE);
629- gtk_widget_show (impl->preview_label);
630- }
631- }
632- else
633- {
634- if (impl->preview_label)
635- {
636- gtk_widget_destroy (impl->preview_label);
637- impl->preview_label = NULL;
638- }
639- }
640-
641- if (impl->preview_widget_active && impl->preview_widget)
642- gtk_widget_show (impl->preview_box);
643- else
644- gtk_widget_hide (impl->preview_box);
645-
646- g_signal_emit_by_name (impl, "default-size-changed");
647-}
648
649-static void
650-set_preview_widget (GtkFileChooserDefault *impl,
651- GtkWidget *preview_widget)
652+/* Returns whether a path is a folder */
653+static gboolean
654+check_is_folder (GtkFileSystem *file_system,
655+ const GtkFilePath *path,
656+ GError **error)
657 {
658- if (preview_widget == impl->preview_widget)
659- return;
660-
661- if (impl->preview_widget)
662- gtk_container_remove (GTK_CONTAINER (impl->preview_box),
663- impl->preview_widget);
664-
665- impl->preview_widget = preview_widget;
666- if (impl->preview_widget)
667- {
668- gtk_widget_show (impl->preview_widget);
669- gtk_box_pack_start (GTK_BOX (impl->preview_box), impl->preview_widget, TRUE, TRUE, 0);
670- gtk_box_reorder_child (GTK_BOX (impl->preview_box),
671- impl->preview_widget,
672- (impl->use_preview_label && impl->preview_label) ? 1 : 0);
673- }
674+ GtkFileFolder *folder;
675+#ifdef GTK26
676+ folder = gtk_file_system_get_folder (file_system, path, 0, error);
677+#else
678+ folder = gtk_file_system_get_folder (file_system, path, 0, NULL, NULL);
679+#endif
680+ if (!folder)
681+ return FALSE;
682
683- update_preview_widget_visibility (impl);
684+ g_object_unref (folder);
685+ return TRUE;
686 }
687
688-/* Re-reads all the icons for the shortcuts, used when the theme changes */
689+
690+/* Callback used when the "New Folder" button is clicked */
691 static void
692-shortcuts_reload_icons (GtkFileChooserDefault *impl)
693+new_folder_button_clicked (GtkButton *button,
694+ GtkFileChooserDefault *impl)
695 {
696 GtkTreeIter iter;
697+ GtkTreePath *path;
698
699- if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
700- return;
701+ if (!impl->browse_files_model)
702+ return; /* FIXME: this sucks. Disable the New Folder button or something. */
703
704- do {
705- gpointer data;
706- gboolean is_volume;
707- gboolean pixbuf_visible;
708- GdkPixbuf *pixbuf;
709-
710- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
711- SHORTCUTS_COL_DATA, &data,
712- SHORTCUTS_COL_IS_VOLUME, &is_volume,
713- SHORTCUTS_COL_PIXBUF_VISIBLE, &pixbuf_visible,
714- -1);
715+ /* Prevent button from being clicked twice */
716+ gtk_widget_set_sensitive (impl->browse_new_folder_button, FALSE);
717
718- if (pixbuf_visible && data)
719- {
720- if (is_volume)
721- {
722- GtkFileSystemVolume *volume;
723+ _gtk_file_system_model_add_editable (impl->browse_files_model, &iter);
724
725- volume = data;
726- pixbuf = gtk_file_system_volume_render_icon (impl->file_system, volume, GTK_WIDGET (impl),
727- impl->icon_size, NULL);
728- }
729- else
730- {
731- const GtkFilePath *path;
732+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->browse_files_model), &iter);
733+ gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_files_tree_view),
734+ path, impl->list_name_column,
735+ FALSE, 0.0, 0.0);
736
737- path = data;
738- pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl),
739- impl->icon_size, NULL);
740- }
741+ g_object_set (impl->list_name_renderer, "editable", TRUE, NULL);
742+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view),
743+ path,
744+ impl->list_name_column,
745+ TRUE);
746
747- gtk_list_store_set (impl->shortcuts_model, &iter,
748- SHORTCUTS_COL_PIXBUF, pixbuf,
749- -1);
750- if (pixbuf)
751- g_object_unref (pixbuf);
752- }
753- } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model),&iter));
754+ gtk_tree_path_free (path);
755 }
756
757-static void
758-shortcuts_find_folder (GtkFileChooserDefault *impl,
759- GtkFilePath *folder)
760+/* Idle handler for creating a new folder after editing its name cell, or for
761+ * canceling the editing.
762+ */
763+static gboolean
764+edited_idle_cb (GtkFileChooserDefault *impl)
765 {
766- GtkTreeSelection *selection;
767- int pos;
768- GtkTreePath *path;
769+ GDK_THREADS_ENTER ();
770+
771+ g_source_destroy (impl->edited_idle);
772+ impl->edited_idle = NULL;
773+
774+ _gtk_file_system_model_remove_editable (impl->browse_files_model);
775+ g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
776
777- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
778+ gtk_widget_set_sensitive (impl->browse_new_folder_button, TRUE);
779
780- g_assert (folder != NULL);
781- pos = shortcut_find_position (impl, folder);
782- if (pos == -1)
783+ if (impl->edited_new_text) /* not cancelled? */
784 {
785- gtk_tree_selection_unselect_all (selection);
786- return;
787- }
788-
789- path = gtk_tree_path_new_from_indices (pos, -1);
790- gtk_tree_selection_select_path (selection, path);
791- gtk_tree_path_free (path);
792-}
793+ GError *error;
794+ GtkFilePath *file_path;
795
796-/* If a shortcut corresponds to the current folder, selects it */
797-static void
798-shortcuts_find_current_folder (GtkFileChooserDefault *impl)
799-{
800- shortcuts_find_folder (impl, impl->current_folder);
801-}
802+ error = NULL;
803+ file_path = gtk_file_system_make_path (impl->file_system, impl->current_folder, impl->edited_new_text,
804+ &error);
805+ if (file_path)
806+ {
807+ error = NULL;
808+#ifdef GTK26
809+ if (gtk_file_system_create_folder (impl->file_system, file_path, &error))
810+#else
811+ if (gtk_file_system_create_folder (impl->file_system, file_path, NULL, NULL))
812+#endif
813+ change_folder_and_display_error (impl, file_path);
814+ else
815+ error_creating_folder_dialog (impl, file_path, error);
816
817-/* Convenience function to get the display name and icon info for a path */
818-static GtkFileInfo *
819-get_file_info (GtkFileSystem *file_system,
820- const GtkFilePath *path,
821- gboolean name_only,
822- GError **error)
823-{
824- GtkFilePath *parent_path;
825- GtkFileFolder *parent_folder;
826- GtkFileInfo *info;
827- GError *tmp = NULL;
828-
829- parent_path = NULL;
830- info = NULL;
831-
832- if (!gtk_file_system_get_parent (file_system, path, &parent_path, &tmp))
833- goto out;
834-
835- parent_folder = gtk_file_system_get_folder (file_system, parent_path ? parent_path : path,
836- GTK_FILE_INFO_DISPLAY_NAME
837- | (name_only ? 0 : GTK_FILE_INFO_IS_FOLDER),
838- &tmp);
839- if (!parent_folder)
840- goto out;
841-
842- info = gtk_file_folder_get_info (parent_folder, parent_path ? path : NULL, &tmp);
843- g_object_unref (parent_folder);
844-
845- out:
846- if (parent_path)
847- gtk_file_path_free (parent_path);
848+ gtk_file_path_free (file_path);
849+ }
850+ else
851+ error_creating_folder_dialog (impl, file_path, error);
852
853- if (tmp)
854- {
855- g_set_error (error,
856- GTK_FILE_CHOOSER_ERROR,
857- GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
858- _("Could not get information about '%s': %s"),
859- gtk_file_path_get_string (path),
860- tmp->message);
861- g_error_free (tmp);
862+ g_free (impl->edited_new_text);
863+ impl->edited_new_text = NULL;
864 }
865
866- return info;
867+ GDK_THREADS_LEAVE ();
868+
869+ return FALSE;
870 }
871
872-/* Returns whether a path is a folder */
873-static gboolean
874-check_is_folder (GtkFileSystem *file_system,
875- const GtkFilePath *path,
876- GError **error)
877-{
878- GtkFileFolder *folder;
879-
880- folder = gtk_file_system_get_folder (file_system, path, 0, error);
881- if (!folder)
882- return FALSE;
883-
884- g_object_unref (folder);
885- return TRUE;
886-}
887-
888-/* Inserts a path in the shortcuts tree, making a copy of it; alternatively,
889- * inserts a volume. A position of -1 indicates the end of the tree.
890- */
891-static gboolean
892-shortcuts_insert_path (GtkFileChooserDefault *impl,
893- int pos,
894- gboolean is_volume,
895- GtkFileSystemVolume *volume,
896- const GtkFilePath *path,
897- const char *label,
898- gboolean removable,
899- GError **error)
900-{
901- char *label_copy;
902- GdkPixbuf *pixbuf;
903- gpointer data;
904- GtkTreeIter iter;
905-
906- if (is_volume)
907- {
908- data = volume;
909- label_copy = gtk_file_system_volume_get_display_name (impl->file_system, volume);
910- pixbuf = gtk_file_system_volume_render_icon (impl->file_system, volume, GTK_WIDGET (impl),
911- impl->icon_size, NULL);
912- }
913- else
914- {
915- if (!check_is_folder (impl->file_system, path, error))
916- return FALSE;
917-
918- if (label)
919- label_copy = g_strdup (label);
920- else
921- {
922- GtkFileInfo *info = get_file_info (impl->file_system, path, TRUE, error);
923-
924- if (!info)
925- return FALSE;
926-
927- label_copy = g_strdup (gtk_file_info_get_display_name (info));
928- gtk_file_info_free (info);
929- }
930-
931- data = gtk_file_path_copy (path);
932- pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl),
933- impl->icon_size, NULL);
934- }
935-
936- if (pos == -1)
937- gtk_list_store_append (impl->shortcuts_model, &iter);
938- else
939- gtk_list_store_insert (impl->shortcuts_model, &iter, pos);
940-
941- gtk_list_store_set (impl->shortcuts_model, &iter,
942- SHORTCUTS_COL_PIXBUF, pixbuf,
943- SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
944- SHORTCUTS_COL_NAME, label_copy,
945- SHORTCUTS_COL_DATA, data,
946- SHORTCUTS_COL_IS_VOLUME, is_volume,
947- SHORTCUTS_COL_REMOVABLE, removable,
948- -1);
949-
950- g_free (label_copy);
951-
952- if (pixbuf)
953- g_object_unref (pixbuf);
954-
955- return TRUE;
956-}
957-
958-/* Appends an item for the user's home directory to the shortcuts model */
959-static void
960-shortcuts_append_home (GtkFileChooserDefault *impl)
961-{
962- const char *home;
963- GtkFilePath *home_path;
964- GError *error;
965-
966- home = g_get_home_dir ();
967- if (home == NULL)
968- return;
969-
970- home_path = gtk_file_system_filename_to_path (impl->file_system, home);
971-
972- error = NULL;
973- impl->has_home = shortcuts_insert_path (impl, -1, FALSE, NULL, home_path, _("Home"), FALSE, &error);
974- if (!impl->has_home)
975- error_getting_info_dialog (impl, home_path, error);
976-
977- gtk_file_path_free (home_path);
978-}
979-
980-/* Appends the ~/Desktop directory to the shortcuts model */
981-static void
982-shortcuts_append_desktop (GtkFileChooserDefault *impl)
983-{
984- char *name;
985- GtkFilePath *path;
986-
987-#ifdef G_OS_WIN32
988- name = _gtk_file_system_win32_get_desktop ();
989-#else
990- const char *home = g_get_home_dir ();
991- if (home == NULL)
992- return;
993-
994- name = g_build_filename (home, "Desktop", NULL);
995-#endif
996-
997- path = gtk_file_system_filename_to_path (impl->file_system, name);
998- g_free (name);
999-
1000- impl->has_desktop = shortcuts_insert_path (impl, -1, FALSE, NULL, path, _("Desktop"), FALSE, NULL);
1001- /* We do not actually pop up an error dialog if there is no desktop directory
1002- * because some people may really not want to have one.
1003- */
1004-
1005- gtk_file_path_free (path);
1006-}
1007-
1008-/* Appends a list of GtkFilePath to the shortcuts model; returns how many were inserted */
1009-static int
1010-shortcuts_append_paths (GtkFileChooserDefault *impl,
1011- GSList *paths)
1012-{
1013- int start_row;
1014- int num_inserted;
1015-
1016- /* As there is no separator now, we want to start there.
1017- */
1018- start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
1019- num_inserted = 0;
1020-
1021- for (; paths; paths = paths->next)
1022- {
1023- GtkFilePath *path;
1024- GError *error;
1025-
1026- path = paths->data;
1027- error = NULL;
1028-
1029- if (impl->local_only &&
1030- !gtk_file_system_path_is_local (impl->file_system, path))
1031- continue;
1032-
1033- /* NULL GError, but we don't really want to show error boxes here */
1034- if (shortcuts_insert_path (impl, start_row + num_inserted, FALSE, NULL, path, NULL, TRUE, NULL))
1035- num_inserted++;
1036- }
1037-
1038- return num_inserted;
1039-}
1040-
1041-/* Returns the index for the corresponding item in the shortcuts bar */
1042-static int
1043-shortcuts_get_index (GtkFileChooserDefault *impl,
1044- ShortcutsIndex where)
1045-{
1046- int n;
1047-
1048- n = 0;
1049-
1050- if (where == SHORTCUTS_HOME)
1051- goto out;
1052-
1053- n += impl->has_home ? 1 : 0;
1054-
1055- if (where == SHORTCUTS_DESKTOP)
1056- goto out;
1057-
1058- n += impl->has_desktop ? 1 : 0;
1059-
1060- if (where == SHORTCUTS_VOLUMES)
1061- goto out;
1062-
1063- n += impl->num_volumes;
1064-
1065- if (where == SHORTCUTS_SHORTCUTS)
1066- goto out;
1067-
1068- n += impl->num_shortcuts;
1069-
1070- if (where == SHORTCUTS_BOOKMARKS_SEPARATOR)
1071- goto out;
1072-
1073- /* If there are no bookmarks there won't be a separator */
1074- n += (impl->num_bookmarks > 0) ? 1 : 0;
1075-
1076- if (where == SHORTCUTS_BOOKMARKS)
1077- goto out;
1078-
1079- n += impl->num_bookmarks;
1080-
1081- if (where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR)
1082- goto out;
1083-
1084- n += 1;
1085-
1086- if (where == SHORTCUTS_CURRENT_FOLDER)
1087- goto out;
1088-
1089- g_assert_not_reached ();
1090-
1091- out:
1092-
1093- return n;
1094-}
1095-
1096-/* Removes the specified number of rows from the shortcuts list */
1097-static void
1098-shortcuts_remove_rows (GtkFileChooserDefault *impl,
1099- int start_row,
1100- int n_rows)
1101-{
1102- GtkTreePath *path;
1103-
1104- path = gtk_tree_path_new_from_indices (start_row, -1);
1105-
1106- for (; n_rows; n_rows--)
1107- {
1108- GtkTreeIter iter;
1109-
1110- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
1111- g_assert_not_reached ();
1112-
1113- shortcuts_free_row_data (impl, &iter);
1114- gtk_list_store_remove (impl->shortcuts_model, &iter);
1115- }
1116-
1117- gtk_tree_path_free (path);
1118-}
1119-
1120-/* Adds all the file system volumes to the shortcuts model */
1121-static void
1122-shortcuts_add_volumes (GtkFileChooserDefault *impl)
1123-{
1124- int start_row;
1125- GSList *list, *l;
1126- int n;
1127- gboolean old_changing_folders;
1128-
1129- old_changing_folders = impl->changing_folder;
1130- impl->changing_folder = TRUE;
1131-
1132- start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
1133- shortcuts_remove_rows (impl, start_row, impl->num_volumes);
1134- impl->num_volumes = 0;
1135-
1136- list = gtk_file_system_list_volumes (impl->file_system);
1137-
1138- n = 0;
1139-
1140- for (l = list; l; l = l->next)
1141- {
1142- GtkFileSystemVolume *volume;
1143-
1144- volume = l->data;
1145-
1146- if (impl->local_only)
1147- {
1148- GtkFilePath *base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
1149- gboolean is_local = gtk_file_system_path_is_local (impl->file_system, base_path);
1150- gtk_file_path_free (base_path);
1151-
1152- if (!is_local)
1153- {
1154- gtk_file_system_volume_free (impl->file_system, volume);
1155- continue;
1156- }
1157- }
1158-
1159- if (shortcuts_insert_path (impl, start_row + n, TRUE, volume, NULL, NULL, FALSE, NULL))
1160- n++;
1161- else
1162- gtk_file_system_volume_free (impl->file_system, volume);
1163- }
1164-
1165- impl->num_volumes = n;
1166- g_slist_free (list);
1167-
1168- if (impl->shortcuts_filter_model)
1169- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model));
1170-
1171- impl->changing_folder = old_changing_folders;
1172-}
1173-
1174-/* Inserts a separator node in the shortcuts list */
1175-static void
1176-shortcuts_insert_separator (GtkFileChooserDefault *impl,
1177- ShortcutsIndex where)
1178-{
1179- GtkTreeIter iter;
1180-
1181- g_assert (where == SHORTCUTS_BOOKMARKS_SEPARATOR || where == SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1182-
1183- gtk_list_store_insert (impl->shortcuts_model, &iter,
1184- shortcuts_get_index (impl, where));
1185- gtk_list_store_set (impl->shortcuts_model, &iter,
1186- SHORTCUTS_COL_PIXBUF, NULL,
1187- SHORTCUTS_COL_PIXBUF_VISIBLE, FALSE,
1188- SHORTCUTS_COL_NAME, NULL,
1189- SHORTCUTS_COL_DATA, NULL,
1190- -1);
1191-}
1192-
1193-/* Updates the list of bookmarks */
1194-static void
1195-shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
1196-{
1197- GSList *bookmarks;
1198- gboolean old_changing_folders;
1199- GtkTreeIter iter;
1200- GtkFilePath *list_selected = NULL;
1201- GtkFilePath *combo_selected = NULL;
1202- gboolean is_volume;
1203- gpointer col_data;
1204-
1205- old_changing_folders = impl->changing_folder;
1206- impl->changing_folder = TRUE;
1207-
1208- if (shortcuts_get_selected (impl, &iter))
1209- {
1210- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
1211- &iter,
1212- SHORTCUTS_COL_DATA, &col_data,
1213- SHORTCUTS_COL_IS_VOLUME, &is_volume,
1214- -1);
1215-
1216- if (col_data && !is_volume)
1217- list_selected = gtk_file_path_copy (col_data);
1218- }
1219-
1220- if (impl->save_folder_combo &&
1221- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (impl->save_folder_combo),
1222- &iter))
1223- {
1224- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model),
1225- &iter,
1226- SHORTCUTS_COL_DATA, &col_data,
1227- SHORTCUTS_COL_IS_VOLUME, &is_volume,
1228- -1);
1229-
1230- if (col_data && !is_volume)
1231- combo_selected = gtk_file_path_copy (col_data);
1232- }
1233-
1234- if (impl->num_bookmarks > 0)
1235- shortcuts_remove_rows (impl,
1236- shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR),
1237- impl->num_bookmarks + 1);
1238-
1239- bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
1240- impl->num_bookmarks = shortcuts_append_paths (impl, bookmarks);
1241- gtk_file_paths_free (bookmarks);
1242-
1243- if (impl->num_bookmarks > 0)
1244- shortcuts_insert_separator (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
1245-
1246- if (impl->shortcuts_filter_model)
1247- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model));
1248-
1249- if (list_selected)
1250- {
1251- shortcuts_find_folder (impl, list_selected);
1252- gtk_file_path_free (list_selected);
1253- }
1254-
1255- if (combo_selected)
1256- {
1257- gint pos;
1258-
1259- pos = shortcut_find_position (impl, combo_selected);
1260- if (pos != -1)
1261- gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo),
1262- pos);
1263- gtk_file_path_free (combo_selected);
1264- }
1265-
1266- impl->changing_folder = old_changing_folders;
1267-}
1268-
1269-/* Appends a separator and a row to the shortcuts list for the current folder */
1270-static void
1271-shortcuts_add_current_folder (GtkFileChooserDefault *impl)
1272-{
1273- int pos;
1274- gboolean success;
1275-
1276- g_assert (!impl->shortcuts_current_folder_active);
1277-
1278- success = TRUE;
1279-
1280- g_assert (impl->current_folder != NULL);
1281-
1282- pos = shortcut_find_position (impl, impl->current_folder);
1283- if (pos == -1)
1284- {
1285- GtkFileSystemVolume *volume;
1286- GtkFilePath *base_path;
1287-
1288- /* Separator */
1289-
1290- shortcuts_insert_separator (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1291-
1292- /* Item */
1293-
1294- pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER);
1295-
1296- volume = gtk_file_system_get_volume_for_path (impl->file_system, impl->current_folder);
1297- if (volume)
1298- base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
1299- else
1300- base_path = NULL;
1301-
1302- if (base_path &&
1303- strcmp (gtk_file_path_get_string (base_path), gtk_file_path_get_string (impl->current_folder)) == 0)
1304- {
1305- success = shortcuts_insert_path (impl, pos, TRUE, volume, NULL, NULL, FALSE, NULL);
1306- if (success)
1307- volume = NULL;
1308- }
1309- else
1310- success = shortcuts_insert_path (impl, pos, FALSE, NULL, impl->current_folder, NULL, FALSE, NULL);
1311-
1312- if (volume)
1313- gtk_file_system_volume_free (impl->file_system, volume);
1314-
1315- if (base_path)
1316- gtk_file_path_free (base_path);
1317-
1318- if (!success)
1319- shortcuts_remove_rows (impl, pos - 1, 1); /* remove the separator */
1320-
1321- impl->shortcuts_current_folder_active = success;
1322- }
1323-
1324- if (success)
1325- gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos);
1326-}
1327-
1328-/* Updates the current folder row in the shortcuts model */
1329-static void
1330-shortcuts_update_current_folder (GtkFileChooserDefault *impl)
1331-{
1332- int pos;
1333-
1334- pos = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1335-
1336- if (impl->shortcuts_current_folder_active)
1337- {
1338- shortcuts_remove_rows (impl, pos, 2);
1339- impl->shortcuts_current_folder_active = FALSE;
1340- }
1341-
1342- shortcuts_add_current_folder (impl);
1343-}
1344-
1345-/* Filter function used for the shortcuts filter model */
1346-static gboolean
1347-shortcuts_filter_cb (GtkTreeModel *model,
1348- GtkTreeIter *iter,
1349- gpointer data)
1350-{
1351- GtkFileChooserDefault *impl;
1352- GtkTreePath *path;
1353- int pos;
1354-
1355- impl = GTK_FILE_CHOOSER_DEFAULT (data);
1356-
1357- path = gtk_tree_model_get_path (model, iter);
1358- if (!path)
1359- return FALSE;
1360-
1361- pos = *gtk_tree_path_get_indices (path);
1362- gtk_tree_path_free (path);
1363-
1364- return (pos < shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR));
1365-}
1366-
1367-/* Creates the list model for shortcuts */
1368-static void
1369-shortcuts_model_create (GtkFileChooserDefault *impl)
1370-{
1371- /* Keep this order in sync with the SHORCUTS_COL_* enum values */
1372- impl->shortcuts_model = gtk_list_store_new (SHORTCUTS_COL_NUM_COLUMNS,
1373- GDK_TYPE_PIXBUF, /* pixbuf */
1374- G_TYPE_STRING, /* name */
1375- G_TYPE_POINTER, /* path or volume */
1376- G_TYPE_BOOLEAN, /* is the previous column a volume? */
1377- G_TYPE_BOOLEAN, /* removable */
1378- G_TYPE_BOOLEAN); /* pixbuf cell visibility */
1379-
1380- if (impl->file_system)
1381- {
1382- shortcuts_append_home (impl);
1383- shortcuts_append_desktop (impl);
1384- shortcuts_add_volumes (impl);
1385- shortcuts_add_bookmarks (impl);
1386- }
1387-
1388- impl->shortcuts_filter_model = shortcuts_model_filter_new (impl,
1389- GTK_TREE_MODEL (impl->shortcuts_model),
1390- NULL);
1391-
1392- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model),
1393- shortcuts_filter_cb,
1394- impl,
1395- NULL);
1396-}
1397-
1398-/* Callback used when the "New Folder" button is clicked */
1399-static void
1400-new_folder_button_clicked (GtkButton *button,
1401- GtkFileChooserDefault *impl)
1402-{
1403- GtkTreeIter iter;
1404- GtkTreePath *path;
1405-
1406- if (!impl->browse_files_model)
1407- return; /* FIXME: this sucks. Disable the New Folder button or something. */
1408-
1409- /* Prevent button from being clicked twice */
1410- gtk_widget_set_sensitive (impl->browse_new_folder_button, FALSE);
1411-
1412- _gtk_file_system_model_add_editable (impl->browse_files_model, &iter);
1413-
1414- path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->browse_files_model), &iter);
1415- gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_files_tree_view),
1416- path, impl->list_name_column,
1417- FALSE, 0.0, 0.0);
1418-
1419- g_object_set (impl->list_name_renderer, "editable", TRUE, NULL);
1420- gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view),
1421- path,
1422- impl->list_name_column,
1423- TRUE);
1424-
1425- gtk_tree_path_free (path);
1426-}
1427-
1428-/* Idle handler for creating a new folder after editing its name cell, or for
1429- * canceling the editing.
1430- */
1431-static gboolean
1432-edited_idle_cb (GtkFileChooserDefault *impl)
1433-{
1434- GDK_THREADS_ENTER ();
1435-
1436- g_source_destroy (impl->edited_idle);
1437- impl->edited_idle = NULL;
1438-
1439- _gtk_file_system_model_remove_editable (impl->browse_files_model);
1440- g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
1441-
1442- gtk_widget_set_sensitive (impl->browse_new_folder_button, TRUE);
1443-
1444- if (impl->edited_new_text) /* not cancelled? */
1445- {
1446- GError *error;
1447- GtkFilePath *file_path;
1448-
1449- error = NULL;
1450- file_path = gtk_file_system_make_path (impl->file_system, impl->current_folder, impl->edited_new_text,
1451- &error);
1452- if (file_path)
1453- {
1454- error = NULL;
1455- if (gtk_file_system_create_folder (impl->file_system, file_path, &error))
1456- change_folder_and_display_error (impl, file_path);
1457- else
1458- error_creating_folder_dialog (impl, file_path, error);
1459-
1460- gtk_file_path_free (file_path);
1461- }
1462- else
1463- error_creating_folder_dialog (impl, file_path, error);
1464-
1465- g_free (impl->edited_new_text);
1466- impl->edited_new_text = NULL;
1467- }
1468-
1469- GDK_THREADS_LEAVE ();
1470-
1471- return FALSE;
1472-}
1473-
1474-static void
1475-queue_edited_idle (GtkFileChooserDefault *impl,
1476- const gchar *new_text)
1477-{
1478- /* We create the folder in an idle handler so that we don't modify the tree
1479- * just now.
1480- */
1481-
1482- g_assert (!impl->edited_idle);
1483- g_assert (!impl->edited_new_text);
1484-
1485- impl->edited_idle = g_idle_source_new ();
1486- g_source_set_closure (impl->edited_idle,
1487- g_cclosure_new_object (G_CALLBACK (edited_idle_cb),
1488- G_OBJECT (impl)));
1489- g_source_attach (impl->edited_idle, NULL);
1490-
1491- if (new_text)
1492- impl->edited_new_text = g_strdup (new_text);
1493-}
1494-
1495-/* Callback used from the text cell renderer when the new folder is named */
1496-static void
1497-renderer_edited_cb (GtkCellRendererText *cell_renderer_text,
1498- const gchar *path,
1499- const gchar *new_text,
1500- GtkFileChooserDefault *impl)
1501-{
1502- /* work around bug #154921 */
1503- g_object_set (cell_renderer_text,
1504- "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
1505- queue_edited_idle (impl, new_text);
1506-}
1507-
1508-/* Callback used from the text cell renderer when the new folder edition gets
1509- * canceled.
1510- */
1511-static void
1512-renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text,
1513- GtkFileChooserDefault *impl)
1514-{
1515- /* work around bug #154921 */
1516- g_object_set (cell_renderer_text,
1517- "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
1518- queue_edited_idle (impl, NULL);
1519-}
1520-
1521-/* Creates the widgets for the filter combo box */
1522-static GtkWidget *
1523-filter_create (GtkFileChooserDefault *impl)
1524-{
1525- impl->filter_combo = gtk_combo_box_new_text ();
1526- gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
1527-
1528- g_signal_connect (impl->filter_combo, "changed",
1529- G_CALLBACK (filter_combo_changed), impl);
1530-
1531- return impl->filter_combo;
1532-}
1533-
1534-static GtkWidget *
1535-button_new (GtkFileChooserDefault *impl,
1536- const char *text,
1537- const char *stock_id,
1538- gboolean sensitive,
1539- gboolean show,
1540- GCallback callback)
1541-{
1542- GtkWidget *button;
1543- GtkWidget *hbox;
1544- GtkWidget *widget;
1545- GtkWidget *align;
1546-
1547- button = gtk_button_new ();
1548- hbox = gtk_hbox_new (FALSE, 2);
1549- align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
1550-
1551- gtk_container_add (GTK_CONTAINER (button), align);
1552- gtk_container_add (GTK_CONTAINER (align), hbox);
1553- widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
1554-
1555- gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1556-
1557- widget = gtk_label_new_with_mnemonic (text);
1558- gtk_label_set_mnemonic_widget (GTK_LABEL (widget), GTK_WIDGET (button));
1559- gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1560-
1561- gtk_widget_set_sensitive (button, sensitive);
1562- g_signal_connect (button, "clicked", callback, impl);
1563-
1564- gtk_widget_show_all (align);
1565-
1566- if (show)
1567- gtk_widget_show (button);
1568-
1569- return button;
1570-}
1571-
1572-/* Looks for a path among the shortcuts; returns its index or -1 if it doesn't exist */
1573-static int
1574-shortcut_find_position (GtkFileChooserDefault *impl,
1575- const GtkFilePath *path)
1576-{
1577- GtkTreeIter iter;
1578- int i;
1579- int current_folder_separator_idx;
1580-
1581- if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
1582- return -1;
1583-
1584- current_folder_separator_idx = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
1585-
1586- for (i = 0; i < current_folder_separator_idx; i++)
1587- {
1588- gpointer col_data;
1589- gboolean is_volume;
1590-
1591- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1592- SHORTCUTS_COL_DATA, &col_data,
1593- SHORTCUTS_COL_IS_VOLUME, &is_volume,
1594- -1);
1595-
1596- if (col_data)
1597- {
1598- if (is_volume)
1599- {
1600- GtkFileSystemVolume *volume;
1601- GtkFilePath *base_path;
1602- gboolean exists;
1603-
1604- volume = col_data;
1605- base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
1606-
1607- exists = strcmp (gtk_file_path_get_string (path),
1608- gtk_file_path_get_string (base_path)) == 0;
1609- g_free (base_path);
1610-
1611- if (exists)
1612- return i;
1613- }
1614- else
1615- {
1616- GtkFilePath *model_path;
1617-
1618- model_path = col_data;
1619-
1620- if (model_path && gtk_file_path_compare (model_path, path) == 0)
1621- return i;
1622- }
1623- }
1624-
1625- gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
1626- }
1627-
1628- return -1;
1629-}
1630-
1631-/* Tries to add a bookmark from a path name */
1632-static gboolean
1633-shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl,
1634- const GtkFilePath *path,
1635- int pos)
1636-{
1637- GError *error;
1638-
1639- if (shortcut_find_position (impl, path) != -1)
1640- return FALSE;
1641-
1642- /* FIXME: this check really belongs in gtk_file_system_insert_bookmark. */
1643- error = NULL;
1644- if (!check_is_folder (impl->file_system, path, &error))
1645- {
1646- error_adding_bookmark_dialog (impl, path, error);
1647- return FALSE;
1648- }
1649-
1650- error = NULL;
1651- if (!gtk_file_system_insert_bookmark (impl->file_system, path, pos, &error))
1652- {
1653- error_adding_bookmark_dialog (impl, path, error);
1654- return FALSE;
1655- }
1656-
1657- return TRUE;
1658-}
1659-
1660-static void
1661-add_bookmark_foreach_cb (GtkTreeModel *model,
1662- GtkTreePath *path,
1663- GtkTreeIter *iter,
1664- gpointer data)
1665-{
1666- GtkFileChooserDefault *impl;
1667- GtkFileSystemModel *fs_model;
1668- GtkTreeIter child_iter;
1669- const GtkFilePath *file_path;
1670-
1671- impl = (GtkFileChooserDefault *) data;
1672-
1673- fs_model = impl->browse_files_model;
1674- gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, iter);
1675-
1676- file_path = _gtk_file_system_model_get_path (fs_model, &child_iter);
1677- shortcuts_add_bookmark_from_path (impl, file_path, -1);
1678-}
1679-
1680-/* Adds a bookmark from the currently selected item in the file list */
1681-static void
1682-bookmarks_add_selected_folder (GtkFileChooserDefault *impl)
1683-{
1684- GtkTreeSelection *selection;
1685-
1686- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
1687-
1688- if (gtk_tree_selection_count_selected_rows (selection) == 0)
1689- shortcuts_add_bookmark_from_path (impl, impl->current_folder, -1);
1690- else
1691- gtk_tree_selection_selected_foreach (selection,
1692- add_bookmark_foreach_cb,
1693- impl);
1694-}
1695-
1696-/* Callback used when the "Add bookmark" button is clicked */
1697-static void
1698-add_bookmark_button_clicked_cb (GtkButton *button,
1699- GtkFileChooserDefault *impl)
1700-{
1701- bookmarks_add_selected_folder (impl);
1702-}
1703-
1704-/* Returns TRUE plus an iter in the shortcuts_model if a row is selected;
1705- * returns FALSE if no shortcut is selected.
1706- */
1707-static gboolean
1708-shortcuts_get_selected (GtkFileChooserDefault *impl,
1709- GtkTreeIter *iter)
1710-{
1711- GtkTreeSelection *selection;
1712- GtkTreeIter parent_iter;
1713-
1714- if (!impl->browse_shortcuts_tree_view)
1715- return FALSE;
1716-
1717- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
1718-
1719- if (!gtk_tree_selection_get_selected (selection, NULL, &parent_iter))
1720- return FALSE;
1721-
1722- gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model),
1723- iter,
1724- &parent_iter);
1725- return TRUE;
1726-}
1727-
1728-/* Removes the selected bookmarks */
1729-static void
1730-remove_selected_bookmarks (GtkFileChooserDefault *impl)
1731-{
1732- GtkTreeIter iter;
1733- gpointer col_data;
1734- GtkFilePath *path;
1735- gboolean removable;
1736- GError *error;
1737-
1738- if (!shortcuts_get_selected (impl, &iter))
1739- return;
1740-
1741- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1742- SHORTCUTS_COL_DATA, &col_data,
1743- SHORTCUTS_COL_REMOVABLE, &removable,
1744- -1);
1745- g_assert (col_data != NULL);
1746-
1747- if (!removable)
1748- return;
1749-
1750- path = col_data;
1751-
1752- error = NULL;
1753- if (!gtk_file_system_remove_bookmark (impl->file_system, path, &error))
1754- error_removing_bookmark_dialog (impl, path, error);
1755-}
1756-
1757-/* Callback used when the "Remove bookmark" button is clicked */
1758-static void
1759-remove_bookmark_button_clicked_cb (GtkButton *button,
1760- GtkFileChooserDefault *impl)
1761-{
1762- remove_selected_bookmarks (impl);
1763-}
1764-
1765-struct selection_check_closure {
1766- GtkFileChooserDefault *impl;
1767- int num_selected;
1768- gboolean all_files;
1769- gboolean all_folders;
1770-};
1771-
1772-/* Used from gtk_tree_selection_selected_foreach() */
1773-static void
1774-selection_check_foreach_cb (GtkTreeModel *model,
1775- GtkTreePath *path,
1776- GtkTreeIter *iter,
1777- gpointer data)
1778-{
1779- struct selection_check_closure *closure;
1780- GtkTreeIter child_iter;
1781- const GtkFileInfo *info;
1782- gboolean is_folder;
1783-
1784- closure = data;
1785- closure->num_selected++;
1786-
1787- gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
1788-
1789- info = _gtk_file_system_model_get_info (closure->impl->browse_files_model, &child_iter);
1790- is_folder = info ? gtk_file_info_get_is_folder (info) : FALSE;
1791-
1792- closure->all_folders = closure->all_folders && is_folder;
1793- closure->all_files = closure->all_files && !is_folder;
1794-}
1795-
1796-/* Checks whether the selected items in the file list are all files or all folders */
1797-static void
1798-selection_check (GtkFileChooserDefault *impl,
1799- gint *num_selected,
1800- gboolean *all_files,
1801- gboolean *all_folders)
1802-{
1803- struct selection_check_closure closure;
1804- GtkTreeSelection *selection;
1805-
1806- closure.impl = impl;
1807- closure.num_selected = 0;
1808- closure.all_files = TRUE;
1809- closure.all_folders = TRUE;
1810-
1811- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
1812- gtk_tree_selection_selected_foreach (selection,
1813- selection_check_foreach_cb,
1814- &closure);
1815-
1816- g_assert (closure.num_selected == 0 || !(closure.all_files && closure.all_folders));
1817-
1818- if (num_selected)
1819- *num_selected = closure.num_selected;
1820-
1821- if (all_files)
1822- *all_files = closure.all_files;
1823-
1824- if (all_folders)
1825- *all_folders = closure.all_folders;
1826-}
1827-
1828-struct get_selected_path_closure {
1829- GtkFileChooserDefault *impl;
1830- const GtkFilePath *path;
1831-};
1832-
1833-static void
1834-get_selected_path_foreach_cb (GtkTreeModel *model,
1835- GtkTreePath *path,
1836- GtkTreeIter *iter,
1837- gpointer data)
1838-{
1839- struct get_selected_path_closure *closure;
1840- GtkTreeIter child_iter;
1841-
1842- closure = data;
1843-
1844- gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
1845- closure->path = _gtk_file_system_model_get_path (closure->impl->browse_files_model, &child_iter);
1846-}
1847-
1848-/* Returns a selected path from the file list */
1849-static const GtkFilePath *
1850-get_selected_path (GtkFileChooserDefault *impl)
1851-{
1852- struct get_selected_path_closure closure;
1853- GtkTreeSelection *selection;
1854-
1855- closure.impl = impl;
1856- closure.path = NULL;
1857-
1858- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
1859- gtk_tree_selection_selected_foreach (selection,
1860- get_selected_path_foreach_cb,
1861- &closure);
1862-
1863- return closure.path;
1864-}
1865-
1866-typedef struct {
1867- GtkFileChooserDefault *impl;
1868- gchar *tip;
1869-} UpdateTooltipData;
1870-
1871-static void
1872-update_tooltip (GtkTreeModel *model,
1873- GtkTreePath *path,
1874- GtkTreeIter *iter,
1875- gpointer data)
1876-{
1877- UpdateTooltipData *udata = data;
1878- GtkTreeIter child_iter;
1879- const GtkFileInfo *info;
1880-
1881- if (udata->tip == NULL)
1882- {
1883- gtk_tree_model_sort_convert_iter_to_child_iter (udata->impl->sort_model,
1884- &child_iter,
1885- iter);
1886-
1887- info = _gtk_file_system_model_get_info (udata->impl->browse_files_model, &child_iter);
1888- udata->tip = g_strdup_printf (_("Add the folder '%s' to the bookmarks"),
1889- gtk_file_info_get_display_name (info));
1890- }
1891-}
1892-
1893-
1894-/* Sensitize the "add bookmark" button if all the selected items are folders, or
1895- * if there are no selected items *and* the current folder is not in the
1896- * bookmarks list. De-sensitize the button otherwise.
1897- */
1898-static void
1899-bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl)
1900-{
1901- gint num_selected;
1902- gboolean all_folders;
1903- gboolean active;
1904- gchar *tip;
1905-
1906- selection_check (impl, &num_selected, NULL, &all_folders);
1907-
1908- if (num_selected == 0)
1909- active = (impl->current_folder != NULL) && (shortcut_find_position (impl, impl->current_folder) == -1);
1910- else if (num_selected == 1)
1911- {
1912- const GtkFilePath *path;
1913-
1914- path = get_selected_path (impl);
1915- active = all_folders && (shortcut_find_position (impl, path) == -1);
1916- }
1917- else
1918- active = all_folders;
1919-
1920- gtk_widget_set_sensitive (impl->browse_shortcuts_add_button, active);
1921-
1922- if (impl->browse_files_popup_menu_add_shortcut_item)
1923- gtk_widget_set_sensitive (impl->browse_files_popup_menu_add_shortcut_item,
1924- (num_selected == 0) ? FALSE : active);
1925-
1926- if (active)
1927- {
1928- if (num_selected == 0)
1929- tip = g_strdup_printf (_("Add the current folder to the bookmarks"));
1930- else if (num_selected > 1)
1931- tip = g_strdup_printf (_("Add the selected folders to the bookmarks"));
1932- else
1933- {
1934- GtkTreeSelection *selection;
1935- UpdateTooltipData data;
1936-
1937- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
1938- data.impl = impl;
1939- data.tip = NULL;
1940- gtk_tree_selection_selected_foreach (selection, update_tooltip, &data);
1941- tip = data.tip;
1942-
1943- }
1944- gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_add_button, tip, NULL);
1945- g_free (tip);
1946- }
1947-}
1948-
1949-/* Sets the sensitivity of the "remove bookmark" button depending on whether a
1950- * bookmark row is selected in the shortcuts tree.
1951- */
1952-static void
1953-bookmarks_check_remove_sensitivity (GtkFileChooserDefault *impl)
1954-{
1955- GtkTreeIter iter;
1956- gboolean removable = FALSE;
1957- gchar *name = NULL;
1958-
1959- if (shortcuts_get_selected (impl, &iter))
1960- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
1961- SHORTCUTS_COL_REMOVABLE, &removable,
1962- SHORTCUTS_COL_NAME, &name,
1963- -1);
1964-
1965- gtk_widget_set_sensitive (impl->browse_shortcuts_remove_button, removable);
1966-
1967- if (removable)
1968- {
1969- gchar *tip;
1970-
1971- tip = g_strdup_printf (_("Remove the bookmark '%s'"), name);
1972- gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_remove_button,
1973- tip, NULL);
1974- g_free (tip);
1975- }
1976-
1977- g_free (name);
1978-}
1979-
1980-/* GtkWidget::drag-begin handler for the shortcuts list. */
1981-static void
1982-shortcuts_drag_begin_cb (GtkWidget *widget,
1983- GdkDragContext *context,
1984- GtkFileChooserDefault *impl)
1985-{
1986-#if 0
1987- impl->shortcuts_drag_context = g_object_ref (context);
1988-#endif
1989-}
1990-
1991-#if 0
1992-/* Removes the idle handler for outside drags */
1993-static void
1994-shortcuts_cancel_drag_outside_idle (GtkFileChooserDefault *impl)
1995-{
1996- if (!impl->shortcuts_drag_outside_idle)
1997- return;
1998-
1999- g_source_destroy (impl->shortcuts_drag_outside_idle);
2000- impl->shortcuts_drag_outside_idle = NULL;
2001-}
2002-#endif
2003-
2004-/* GtkWidget::drag-end handler for the shortcuts list. */
2005-static void
2006-shortcuts_drag_end_cb (GtkWidget *widget,
2007- GdkDragContext *context,
2008- GtkFileChooserDefault *impl)
2009-{
2010-#if 0
2011- g_object_unref (impl->shortcuts_drag_context);
2012-
2013- shortcuts_cancel_drag_outside_idle (impl);
2014-
2015- if (!impl->shortcuts_drag_outside)
2016- return;
2017-
2018- gtk_button_clicked (GTK_BUTTON (impl->browse_shortcuts_remove_button));
2019-
2020- impl->shortcuts_drag_outside = FALSE;
2021-#endif
2022-}
2023-
2024-/* GtkWidget::drag-data-delete handler for the shortcuts list. */
2025-static void
2026-shortcuts_drag_data_delete_cb (GtkWidget *widget,
2027- GdkDragContext *context,
2028- GtkFileChooserDefault *impl)
2029-{
2030- g_signal_stop_emission_by_name (widget, "drag-data-delete");
2031-}
2032-
2033-#if 0
2034-/* Creates a suitable drag cursor to indicate that the selected bookmark will be
2035- * deleted or not.
2036- */
2037 static void
2038-shortcuts_drag_set_delete_cursor (GtkFileChooserDefault *impl,
2039- gboolean delete)
2040-{
2041- GtkTreeView *tree_view;
2042- GtkTreeIter iter;
2043- GtkTreePath *path;
2044- GdkPixmap *row_pixmap;
2045- GdkBitmap *mask;
2046- int row_pixmap_y;
2047- int cell_y;
2048-
2049- tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
2050-
2051- /* Find the selected path and get its drag pixmap */
2052-
2053- if (!shortcuts_get_selected (impl, &iter))
2054- g_assert_not_reached ();
2055-
2056- path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
2057-
2058- row_pixmap = gtk_tree_view_create_row_drag_icon (tree_view, path);
2059- gtk_tree_path_free (path);
2060-
2061- mask = NULL;
2062- row_pixmap_y = 0;
2063-
2064- if (delete)
2065- {
2066- GdkPixbuf *pixbuf;
2067-
2068- pixbuf = gtk_widget_render_icon (impl->browse_shortcuts_tree_view,
2069- GTK_STOCK_DELETE,
2070- GTK_ICON_SIZE_DND,
2071- NULL);
2072- if (pixbuf)
2073- {
2074- GdkPixmap *composite;
2075- int row_pixmap_width, row_pixmap_height;
2076- int pixbuf_width, pixbuf_height;
2077- int composite_width, composite_height;
2078- int pixbuf_x, pixbuf_y;
2079- GdkGC *gc, *mask_gc;
2080- GdkColor color;
2081- GdkBitmap *pixbuf_mask;
2082-
2083- /* Create pixmap and mask for composite image */
2084-
2085- gdk_drawable_get_size (row_pixmap, &row_pixmap_width, &row_pixmap_height);
2086- pixbuf_width = gdk_pixbuf_get_width (pixbuf);
2087- pixbuf_height = gdk_pixbuf_get_height (pixbuf);
2088-
2089- composite_width = MAX (row_pixmap_width, pixbuf_width);
2090- composite_height = MAX (row_pixmap_height, pixbuf_height);
2091-
2092- row_pixmap_y = (composite_height - row_pixmap_height) / 2;
2093-
2094- if (gtk_widget_get_direction (impl->browse_shortcuts_tree_view) == GTK_TEXT_DIR_RTL)
2095- pixbuf_x = 0;
2096- else
2097- pixbuf_x = composite_width - pixbuf_width;
2098-
2099- pixbuf_y = (composite_height - pixbuf_height) / 2;
2100-
2101- composite = gdk_pixmap_new (row_pixmap, composite_width, composite_height, -1);
2102- gc = gdk_gc_new (composite);
2103-
2104- mask = gdk_pixmap_new (row_pixmap, composite_width, composite_height, 1);
2105- mask_gc = gdk_gc_new (mask);
2106- color.pixel = 0;
2107- gdk_gc_set_foreground (mask_gc, &color);
2108- gdk_draw_rectangle (mask, mask_gc, TRUE, 0, 0, composite_width, composite_height);
2109-
2110- color.red = 0xffff;
2111- color.green = 0xffff;
2112- color.blue = 0xffff;
2113- gdk_gc_set_rgb_fg_color (gc, &color);
2114- gdk_draw_rectangle (composite, gc, TRUE, 0, 0, composite_width, composite_height);
2115-
2116- /* Composite the row pixmap and the pixbuf */
2117-
2118- gdk_pixbuf_render_pixmap_and_mask_for_colormap
2119- (pixbuf,
2120- gtk_widget_get_colormap (impl->browse_shortcuts_tree_view),
2121- NULL, &pixbuf_mask, 128);
2122- gdk_draw_drawable (mask, mask_gc, pixbuf_mask,
2123- 0, 0,
2124- pixbuf_x, pixbuf_y,
2125- pixbuf_width, pixbuf_height);
2126- g_object_unref (pixbuf_mask);
2127-
2128- gdk_draw_drawable (composite, gc, row_pixmap,
2129- 0, 0,
2130- 0, row_pixmap_y,
2131- row_pixmap_width, row_pixmap_height);
2132- color.pixel = 1;
2133- gdk_gc_set_foreground (mask_gc, &color);
2134- gdk_draw_rectangle (mask, mask_gc, TRUE, 0, row_pixmap_y, row_pixmap_width, row_pixmap_height);
2135-
2136- gdk_draw_pixbuf (composite, gc, pixbuf,
2137- 0, 0,
2138- pixbuf_x, pixbuf_y,
2139- pixbuf_width, pixbuf_height,
2140- GDK_RGB_DITHER_MAX,
2141- 0, 0);
2142-
2143- g_object_unref (pixbuf);
2144- g_object_unref (row_pixmap);
2145-
2146- row_pixmap = composite;
2147- }
2148- }
2149-
2150- /* The hotspot offsets here are copied from gtk_tree_view_drag_begin(), ugh */
2151-
2152- gtk_tree_view_get_path_at_pos (tree_view,
2153- tree_view->priv->press_start_x,
2154- tree_view->priv->press_start_y,
2155- NULL,
2156- NULL,
2157- NULL,
2158- &cell_y);
2159-
2160- gtk_drag_set_icon_pixmap (impl->shortcuts_drag_context,
2161- gdk_drawable_get_colormap (row_pixmap),
2162- row_pixmap,
2163- mask,
2164- tree_view->priv->press_start_x + 1,
2165- row_pixmap_y + cell_y + 1);
2166-
2167- g_object_unref (row_pixmap);
2168- if (mask)
2169- g_object_unref (mask);
2170-}
2171-
2172-/* We set the delete cursor and the shortcuts_drag_outside flag in an idle
2173- * handler so that we can tell apart the drag_leave event that comes right
2174- * before a drag_drop, from a normal drag_leave. We don't want to set the
2175- * cursor nor the flag in the latter case.
2176- */
2177-static gboolean
2178-shortcuts_drag_outside_idle_cb (GtkFileChooserDefault *impl)
2179+queue_edited_idle (GtkFileChooserDefault *impl,
2180+ const gchar *new_text)
2181 {
2182- GDK_THREADS_ENTER ();
2183-
2184- shortcuts_drag_set_delete_cursor (impl, TRUE);
2185- impl->shortcuts_drag_outside = TRUE;
2186-
2187- shortcuts_cancel_drag_outside_idle (impl);
2188-
2189- GDK_THREADS_LEAVE ();
2190-
2191- return FALSE;
2192-}
2193-#endif
2194+ /* We create the folder in an idle handler so that we don't modify the tree
2195+ * just now.
2196+ */
2197
2198-/* GtkWidget::drag-leave handler for the shortcuts list. We unhighlight the
2199- * drop position.
2200- */
2201-static void
2202-shortcuts_drag_leave_cb (GtkWidget *widget,
2203- GdkDragContext *context,
2204- guint time_,
2205- GtkFileChooserDefault *impl)
2206-{
2207-#if 0
2208- if (gtk_drag_get_source_widget (context) == widget && !impl->shortcuts_drag_outside_idle)
2209- {
2210- impl->shortcuts_drag_outside_idle = g_idle_source_new ();
2211- g_source_set_closure (impl->shortcuts_drag_outside_idle,
2212- g_cclosure_new_object (G_CALLBACK (shortcuts_drag_outside_idle_cb),
2213- G_OBJECT (impl)));
2214- g_source_attach (impl->shortcuts_drag_outside_idle, NULL);
2215- }
2216-#endif
2217+ g_assert (!impl->edited_idle);
2218+ g_assert (!impl->edited_new_text);
2219
2220- gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
2221- NULL,
2222- GTK_TREE_VIEW_DROP_BEFORE);
2223+ impl->edited_idle = g_idle_source_new ();
2224+ g_source_set_closure (impl->edited_idle,
2225+ g_cclosure_new_object (G_CALLBACK (edited_idle_cb),
2226+ G_OBJECT (impl)));
2227+ g_source_attach (impl->edited_idle, NULL);
2228
2229- g_signal_stop_emission_by_name (widget, "drag-leave");
2230+ if (new_text)
2231+ impl->edited_new_text = g_strdup (new_text);
2232 }
2233
2234-/* Computes the appropriate row and position for dropping */
2235+/* Callback used from the text cell renderer when the new folder is named */
2236 static void
2237-shortcuts_compute_drop_position (GtkFileChooserDefault *impl,
2238- int x,
2239- int y,
2240- GtkTreePath **path,
2241- GtkTreeViewDropPosition *pos)
2242+renderer_edited_cb (GtkCellRendererText *cell_renderer_text,
2243+ const gchar *path,
2244+ const gchar *new_text,
2245+ GtkFileChooserDefault *impl)
2246 {
2247- GtkTreeView *tree_view;
2248- GtkTreeViewColumn *column;
2249- int cell_y;
2250- GdkRectangle cell;
2251- int row;
2252- int bookmarks_index;
2253-
2254- tree_view = GTK_TREE_VIEW (impl->browse_shortcuts_tree_view);
2255-
2256- bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
2257-
2258- if (!gtk_tree_view_get_path_at_pos (tree_view,
2259- x,
2260- y - TREE_VIEW_HEADER_HEIGHT (tree_view),
2261- path,
2262- &column,
2263- NULL,
2264- &cell_y))
2265- {
2266- row = bookmarks_index + impl->num_bookmarks - 1;
2267- *path = gtk_tree_path_new_from_indices (row, -1);
2268- *pos = GTK_TREE_VIEW_DROP_AFTER;
2269- return;
2270- }
2271-
2272- row = *gtk_tree_path_get_indices (*path);
2273- gtk_tree_view_get_background_area (tree_view, *path, column, &cell);
2274- gtk_tree_path_free (*path);
2275-
2276- if (row < bookmarks_index)
2277- {
2278- row = bookmarks_index;
2279- *pos = GTK_TREE_VIEW_DROP_BEFORE;
2280- }
2281- else if (row > bookmarks_index + impl->num_bookmarks - 1)
2282- {
2283- row = bookmarks_index + impl->num_bookmarks - 1;
2284- *pos = GTK_TREE_VIEW_DROP_AFTER;
2285- }
2286- else
2287- {
2288- if (cell_y < cell.height / 2)
2289- *pos = GTK_TREE_VIEW_DROP_BEFORE;
2290- else
2291- *pos = GTK_TREE_VIEW_DROP_AFTER;
2292- }
2293-
2294- *path = gtk_tree_path_new_from_indices (row, -1);
2295+ /* work around bug #154921 */
2296+ g_object_set (cell_renderer_text,
2297+ "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
2298+ queue_edited_idle (impl, new_text);
2299 }
2300
2301-/* GtkWidget::drag-motion handler for the shortcuts list. We basically
2302- * implement the destination side of DnD by hand, due to limitations in
2303- * GtkTreeView's DnD API.
2304+/* Callback used from the text cell renderer when the new folder edition gets
2305+ * canceled.
2306 */
2307-static gboolean
2308-shortcuts_drag_motion_cb (GtkWidget *widget,
2309- GdkDragContext *context,
2310- gint x,
2311- gint y,
2312- guint time_,
2313- GtkFileChooserDefault *impl)
2314-{
2315- GtkTreePath *path;
2316- GtkTreeViewDropPosition pos;
2317- GdkDragAction action;
2318-
2319-#if 0
2320- if (gtk_drag_get_source_widget (context) == widget)
2321- {
2322- shortcuts_cancel_drag_outside_idle (impl);
2323-
2324- if (impl->shortcuts_drag_outside)
2325- {
2326- shortcuts_drag_set_delete_cursor (impl, FALSE);
2327- impl->shortcuts_drag_outside = FALSE;
2328- }
2329- }
2330-#endif
2331-
2332- if (context->suggested_action == GDK_ACTION_COPY || (context->actions & GDK_ACTION_COPY) != 0)
2333- action = GDK_ACTION_COPY;
2334- else if (context->suggested_action == GDK_ACTION_MOVE || (context->actions & GDK_ACTION_MOVE) != 0)
2335- action = GDK_ACTION_MOVE;
2336- else
2337- {
2338- action = 0;
2339- goto out;
2340- }
2341-
2342- shortcuts_compute_drop_position (impl, x, y, &path, &pos);
2343- gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), path, pos);
2344- gtk_tree_path_free (path);
2345-
2346- out:
2347-
2348- g_signal_stop_emission_by_name (widget, "drag-motion");
2349-
2350- if (action != 0)
2351- {
2352- gdk_drag_status (context, action, time_);
2353- return TRUE;
2354- }
2355- else
2356- return FALSE;
2357-}
2358-
2359-/* GtkWidget::drag-drop handler for the shortcuts list. */
2360-static gboolean
2361-shortcuts_drag_drop_cb (GtkWidget *widget,
2362- GdkDragContext *context,
2363- gint x,
2364- gint y,
2365- guint time_,
2366- GtkFileChooserDefault *impl)
2367-{
2368-#if 0
2369- shortcuts_cancel_drag_outside_idle (impl);
2370-#endif
2371-
2372- g_signal_stop_emission_by_name (widget, "drag-drop");
2373- return TRUE;
2374-}
2375-
2376-/* Parses a "text/uri-list" string and inserts its URIs as bookmarks */
2377-static void
2378-shortcuts_drop_uris (GtkFileChooserDefault *impl,
2379- const char *data,
2380- int position)
2381-{
2382- gchar **uris;
2383- gint i;
2384-
2385- uris = g_uri_list_extract_uris (data);
2386-
2387- for (i = 0; uris[i]; i++)
2388- {
2389- char *uri;
2390- GtkFilePath *path;
2391-
2392- uri = uris[i];
2393- path = gtk_file_system_uri_to_path (impl->file_system, uri);
2394-
2395- if (path)
2396- {
2397- if (shortcuts_add_bookmark_from_path (impl, path, position))
2398- position++;
2399-
2400- gtk_file_path_free (path);
2401- }
2402- else
2403- {
2404- GError *error;
2405-
2406- g_set_error (&error,
2407- GTK_FILE_CHOOSER_ERROR,
2408- GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
2409- _("Could not add a bookmark for '%s' "
2410- "because it is an invalid path name."),
2411- uri);
2412- error_adding_bookmark_dialog (impl, path, error);
2413- }
2414- }
2415-
2416- g_strfreev (uris);
2417-}
2418-
2419-/* Reorders the selected bookmark to the specified position */
2420 static void
2421-shortcuts_reorder (GtkFileChooserDefault *impl,
2422- int new_position)
2423+renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text,
2424+ GtkFileChooserDefault *impl)
2425 {
2426- GtkTreeIter iter;
2427- gpointer col_data;
2428- gboolean is_volume;
2429- GtkTreePath *path;
2430- int old_position;
2431- int bookmarks_index;
2432- const GtkFilePath *file_path;
2433- GtkFilePath *file_path_copy;
2434- GError *error;
2435-
2436- /* Get the selected path */
2437-
2438- if (!shortcuts_get_selected (impl, &iter))
2439- g_assert_not_reached ();
2440-
2441- path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
2442- old_position = *gtk_tree_path_get_indices (path);
2443- gtk_tree_path_free (path);
2444-
2445- bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
2446- old_position -= bookmarks_index;
2447- g_assert (old_position >= 0 && old_position < impl->num_bookmarks);
2448-
2449- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
2450- SHORTCUTS_COL_DATA, &col_data,
2451- SHORTCUTS_COL_IS_VOLUME, &is_volume,
2452- -1);
2453- g_assert (col_data != NULL);
2454- g_assert (!is_volume);
2455-
2456- file_path = col_data;
2457- file_path_copy = gtk_file_path_copy (file_path); /* removal below will free file_path, so we need a copy */
2458-
2459- /* Remove the path from the old position and insert it in the new one */
2460-
2461- if (new_position > old_position)
2462- new_position--;
2463-
2464- if (old_position == new_position)
2465- goto out;
2466-
2467- error = NULL;
2468- if (gtk_file_system_remove_bookmark (impl->file_system, file_path_copy, &error))
2469- shortcuts_add_bookmark_from_path (impl, file_path_copy, new_position);
2470- else
2471- error_adding_bookmark_dialog (impl, file_path_copy, error);
2472-
2473- out:
2474-
2475- gtk_file_path_free (file_path_copy);
2476+ /* work around bug #154921 */
2477+ g_object_set (cell_renderer_text,
2478+ "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
2479+ queue_edited_idle (impl, NULL);
2480 }
2481
2482-/* Callback used when we get the drag data for the bookmarks list. We add the
2483- * received URIs as bookmarks if they are folders.
2484- */
2485-static void
2486-shortcuts_drag_data_received_cb (GtkWidget *widget,
2487- GdkDragContext *context,
2488- gint x,
2489- gint y,
2490- GtkSelectionData *selection_data,
2491- guint info,
2492- guint time_,
2493- gpointer data)
2494-{
2495+struct selection_check_closure {
2496 GtkFileChooserDefault *impl;
2497- GtkTreePath *tree_path;
2498- GtkTreeViewDropPosition tree_pos;
2499- int position;
2500- int bookmarks_index;
2501-
2502- impl = GTK_FILE_CHOOSER_DEFAULT (data);
2503-
2504- /* Compute position */
2505-
2506- bookmarks_index = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS);
2507-
2508- shortcuts_compute_drop_position (impl, x, y, &tree_path, &tree_pos);
2509- position = *gtk_tree_path_get_indices (tree_path);
2510- gtk_tree_path_free (tree_path);
2511-
2512- if (tree_pos == GTK_TREE_VIEW_DROP_AFTER)
2513- position++;
2514-
2515- g_assert (position >= bookmarks_index);
2516- position -= bookmarks_index;
2517-
2518- if (selection_data->target == gdk_atom_intern ("text/uri-list", FALSE))
2519- shortcuts_drop_uris (impl, selection_data->data, position);
2520- else if (selection_data->target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
2521- shortcuts_reorder (impl, position);
2522-
2523- g_signal_stop_emission_by_name (widget, "drag-data-received");
2524-}
2525-
2526-/* Callback used when the selection in the shortcuts tree changes */
2527-static void
2528-shortcuts_selection_changed_cb (GtkTreeSelection *selection,
2529- GtkFileChooserDefault *impl)
2530-{
2531- bookmarks_check_remove_sensitivity (impl);
2532-}
2533-
2534-static gboolean
2535-shortcuts_row_separator_func (GtkTreeModel *model,
2536- GtkTreeIter *iter,
2537- gpointer data)
2538-{
2539- gint column = GPOINTER_TO_INT (data);
2540- gchar *text;
2541-
2542- gtk_tree_model_get (model, iter, column, &text, -1);
2543-
2544- if (!text)
2545- return TRUE;
2546-
2547- g_free (text);
2548-
2549- return FALSE;
2550-}
2551-
2552-/* Since GtkTreeView has a keybinding attached to '/', we need to catch
2553- * keypresses before the TreeView gets them.
2554- */
2555-static gboolean
2556-tree_view_keybinding_cb (GtkWidget *tree_view,
2557- GdkEventKey *event,
2558- GtkFileChooserDefault *impl)
2559-{
2560- if (event->keyval == GDK_slash &&
2561- ! (event->state & (~GDK_SHIFT_MASK & gtk_accelerator_get_default_mod_mask ())))
2562- {
2563- location_popup_handler (impl, "/");
2564- return TRUE;
2565- }
2566-
2567- return FALSE;
2568-}
2569-
2570-
2571-/* Creates the widgets for the shortcuts and bookmarks tree */
2572-static GtkWidget *
2573-shortcuts_list_create (GtkFileChooserDefault *impl)
2574-{
2575- GtkWidget *swin;
2576- GtkTreeSelection *selection;
2577- GtkTreeViewColumn *column;
2578- GtkCellRenderer *renderer;
2579-
2580- /* Scrolled window */
2581-
2582- swin = gtk_scrolled_window_new (NULL, NULL);
2583- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
2584- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2585- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin),
2586- GTK_SHADOW_IN);
2587- gtk_widget_show (swin);
2588-
2589- /* Tree */
2590-
2591- impl->browse_shortcuts_tree_view = gtk_tree_view_new ();
2592- g_signal_connect (impl->browse_shortcuts_tree_view, "key-press-event",
2593- G_CALLBACK (tree_view_keybinding_cb), impl);
2594- atk_object_set_name (gtk_widget_get_accessible (impl->browse_shortcuts_tree_view), _("Shortcuts"));
2595- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), FALSE);
2596-
2597- gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), impl->shortcuts_filter_model);
2598-
2599- gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
2600- GDK_BUTTON1_MASK,
2601- shortcuts_source_targets,
2602- num_shortcuts_source_targets,
2603- GDK_ACTION_MOVE);
2604-
2605- gtk_drag_dest_set (impl->browse_shortcuts_tree_view,
2606- GTK_DEST_DEFAULT_ALL,
2607- shortcuts_dest_targets,
2608- num_shortcuts_dest_targets,
2609- GDK_ACTION_COPY | GDK_ACTION_MOVE);
2610-
2611- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
2612- gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
2613- gtk_tree_selection_set_select_function (selection,
2614- shortcuts_select_func,
2615- impl, NULL);
2616-
2617- g_signal_connect (selection, "changed",
2618- G_CALLBACK (shortcuts_selection_changed_cb), impl);
2619-
2620- g_signal_connect (impl->browse_shortcuts_tree_view, "row-activated",
2621- G_CALLBACK (shortcuts_row_activated_cb), impl);
2622-
2623- g_signal_connect (impl->browse_shortcuts_tree_view, "key-press-event",
2624- G_CALLBACK (shortcuts_key_press_event_cb), impl);
2625-
2626- g_signal_connect (impl->browse_shortcuts_tree_view, "drag-begin",
2627- G_CALLBACK (shortcuts_drag_begin_cb), impl);
2628- g_signal_connect (impl->browse_shortcuts_tree_view, "drag-end",
2629- G_CALLBACK (shortcuts_drag_end_cb), impl);
2630- g_signal_connect (impl->browse_shortcuts_tree_view, "drag-data-delete",
2631- G_CALLBACK (shortcuts_drag_data_delete_cb), impl);
2632-
2633- g_signal_connect (impl->browse_shortcuts_tree_view, "drag-leave",
2634- G_CALLBACK (shortcuts_drag_leave_cb), impl);
2635- g_signal_connect (impl->browse_shortcuts_tree_view, "drag-motion",
2636- G_CALLBACK (shortcuts_drag_motion_cb), impl);
2637- g_signal_connect (impl->browse_shortcuts_tree_view, "drag-drop",
2638- G_CALLBACK (shortcuts_drag_drop_cb), impl);
2639- g_signal_connect (impl->browse_shortcuts_tree_view, "drag-data-received",
2640- G_CALLBACK (shortcuts_drag_data_received_cb), impl);
2641-
2642- gtk_container_add (GTK_CONTAINER (swin), impl->browse_shortcuts_tree_view);
2643- gtk_widget_show (impl->browse_shortcuts_tree_view);
2644-
2645- /* Column */
2646+ int num_selected;
2647+ gboolean all_files;
2648+ gboolean all_folders;
2649+};
2650
2651- column = gtk_tree_view_column_new ();
2652- gtk_tree_view_column_set_title (column, _("Folder"));
2653+/* Used from gtk_tree_selection_selected_foreach() */
2654+static void
2655+selection_check_foreach_cb (GtkTreeModel *model,
2656+ GtkTreePath *path,
2657+ GtkTreeIter *iter,
2658+ gpointer data)
2659+{
2660+ struct selection_check_closure *closure;
2661+ GtkTreeIter child_iter;
2662+ const GtkFileInfo *info;
2663+ gboolean is_folder;
2664
2665- renderer = gtk_cell_renderer_pixbuf_new ();
2666- gtk_tree_view_column_pack_start (column, renderer, FALSE);
2667- gtk_tree_view_column_set_attributes (column, renderer,
2668- "pixbuf", SHORTCUTS_COL_PIXBUF,
2669- "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
2670- NULL);
2671+ closure = data;
2672+ closure->num_selected++;
2673
2674- renderer = gtk_cell_renderer_text_new ();
2675- gtk_tree_view_column_pack_start (column, renderer, TRUE);
2676- gtk_tree_view_column_set_attributes (column, renderer,
2677- "text", SHORTCUTS_COL_NAME,
2678- NULL);
2679-
2680- gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
2681- shortcuts_row_separator_func,
2682- GINT_TO_POINTER (SHORTCUTS_COL_NAME),
2683- NULL);
2684+ gtk_tree_model_sort_convert_iter_to_child_iter (closure->impl->sort_model, &child_iter, iter);
2685
2686- gtk_tree_view_append_column (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), column);
2687+ info = _gtk_file_system_model_get_info (closure->impl->browse_files_model, &child_iter);
2688+ is_folder = info ? gtk_file_info_get_is_folder (info) : FALSE;
2689
2690- return swin;
2691+ closure->all_folders = closure->all_folders && is_folder;
2692+ closure->all_files = closure->all_files && !is_folder;
2693 }
2694
2695-/* Creates the widgets for the shortcuts/bookmarks pane */
2696-static GtkWidget *
2697-shortcuts_pane_create (GtkFileChooserDefault *impl,
2698- GtkSizeGroup *size_group)
2699+/* Checks whether the selected items in the file list are all files or all folders */
2700+static void
2701+selection_check (GtkFileChooserDefault *impl,
2702+ gint *num_selected,
2703+ gboolean *all_files,
2704+ gboolean *all_folders)
2705 {
2706- GtkWidget *vbox;
2707- GtkWidget *hbox;
2708- GtkWidget *widget;
2709+ struct selection_check_closure closure;
2710+ GtkTreeSelection *selection;
2711
2712- vbox = gtk_vbox_new (FALSE, 6);
2713- gtk_widget_show (vbox);
2714+ closure.impl = impl;
2715+ closure.num_selected = 0;
2716+ closure.all_files = TRUE;
2717+ closure.all_folders = TRUE;
2718+
2719+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
2720+ gtk_tree_selection_selected_foreach (selection,
2721+ selection_check_foreach_cb,
2722+ &closure);
2723
2724- /* Shortcuts tree */
2725+ g_assert (closure.num_selected == 0 || !(closure.all_files && closure.all_folders));
2726
2727- widget = shortcuts_list_create (impl);
2728- gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
2729+ if (num_selected)
2730+ *num_selected = closure.num_selected;
2731
2732- /* Box for buttons */
2733+ if (all_files)
2734+ *all_files = closure.all_files;
2735
2736- hbox = gtk_hbox_new (TRUE, 6);
2737- gtk_size_group_add_widget (size_group, hbox);
2738- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
2739- gtk_widget_show (hbox);
2740+ if (all_folders)
2741+ *all_folders = closure.all_folders;
2742+}
2743
2744- /* Add bookmark button */
2745+struct get_selected_path_closure {
2746+ GtkFileChooserDefault *impl;
2747+ const GtkFilePath *path;
2748+};
2749
2750- impl->browse_shortcuts_add_button = button_new (impl,
2751- _("_Add"),
2752- GTK_STOCK_ADD,
2753- FALSE,
2754- TRUE,
2755- G_CALLBACK (add_bookmark_button_clicked_cb));
2756- gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_add_button, TRUE, TRUE, 0);
2757- gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_add_button,
2758- _("Add the selected folder to the bookmarks"), NULL);
2759-
2760- /* Remove bookmark button */
2761-
2762- impl->browse_shortcuts_remove_button = button_new (impl,
2763- _("_Remove"),
2764- GTK_STOCK_REMOVE,
2765- FALSE,
2766- TRUE,
2767- G_CALLBACK (remove_bookmark_button_clicked_cb));
2768- gtk_box_pack_start (GTK_BOX (hbox), impl->browse_shortcuts_remove_button, TRUE, TRUE, 0);
2769- gtk_tooltips_set_tip (impl->tooltips, impl->browse_shortcuts_remove_button,
2770- _("Remove the selected bookmark"), NULL);
2771+/* Returns a selected path from the file list */
2772+
2773+typedef struct {
2774+ GtkFileChooserDefault *impl;
2775+ gchar *tip;
2776+} UpdateTooltipData;
2777
2778- return vbox;
2779-}
2780
2781 /* Handles key press events on the file list, so that we can trap Enter to
2782 * activate the default button on our own. Also, checks to see if '/' has been
2783@@ -3026,14 +1051,11 @@
2784 gpointer data)
2785 {
2786 GtkFileChooserDefault *impl;
2787- int modifiers;
2788
2789 impl = (GtkFileChooserDefault *) data;
2790-
2791- modifiers = gtk_accelerator_get_default_mod_mask ();
2792
2793 if (event->keyval == GDK_slash &&
2794- ! (event->state & (~GDK_SHIFT_MASK & modifiers)))
2795+ ! (event->state & (~GDK_SHIFT_MASK & gtk_accelerator_get_default_mod_mask ())))
2796 {
2797 location_popup_handler (impl, "/");
2798 return TRUE;
2799@@ -3043,7 +1065,6 @@
2800 || event->keyval == GDK_ISO_Enter
2801 || event->keyval == GDK_KP_Enter
2802 || event->keyval == GDK_space)
2803- && ((event->state && modifiers) == 0)
2804 && !(impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
2805 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
2806 {
2807@@ -3063,37 +1084,7 @@
2808 return FALSE;
2809 }
2810
2811-/* Callback used when the file list's popup menu is detached */
2812-static void
2813-popup_menu_detach_cb (GtkWidget *attach_widget,
2814- GtkMenu *menu)
2815-{
2816- GtkFileChooserDefault *impl;
2817-
2818- impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
2819- g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
2820-
2821- impl->browse_files_popup_menu = NULL;
2822- impl->browse_files_popup_menu_add_shortcut_item = NULL;
2823- impl->browse_files_popup_menu_hidden_files_item = NULL;
2824-}
2825-
2826-/* Callback used when the "Add to Shortcuts" menu item is activated */
2827-static void
2828-add_to_shortcuts_cb (GtkMenuItem *item,
2829- GtkFileChooserDefault *impl)
2830-{
2831- bookmarks_add_selected_folder (impl);
2832-}
2833-
2834-/* Callback used when the "Open Location" menu item is activated */
2835-static void
2836-open_location_cb (GtkMenuItem *item,
2837- GtkFileChooserDefault *impl)
2838-{
2839- location_popup_handler (impl, "");
2840-}
2841-
2842+#if 0
2843 /* Callback used when the "Show Hidden Files" menu item is toggled */
2844 static void
2845 show_hidden_toggled_cb (GtkCheckMenuItem *item,
2846@@ -3103,145 +1094,7 @@
2847 "show-hidden", gtk_check_menu_item_get_active (item),
2848 NULL);
2849 }
2850-
2851-/* Constructs the popup menu for the file list if needed */
2852-static void
2853-file_list_build_popup_menu (GtkFileChooserDefault *impl)
2854-{
2855- GtkWidget *item;
2856-
2857- if (impl->browse_files_popup_menu)
2858- return;
2859-
2860- impl->browse_files_popup_menu = gtk_menu_new ();
2861- gtk_menu_attach_to_widget (GTK_MENU (impl->browse_files_popup_menu),
2862- impl->browse_files_tree_view,
2863- popup_menu_detach_cb);
2864-
2865- item = gtk_image_menu_item_new_with_mnemonic (_("_Add to Shortcuts"));
2866- impl->browse_files_popup_menu_add_shortcut_item = item;
2867- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
2868- gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
2869- gtk_widget_set_sensitive (item, FALSE);
2870- g_signal_connect (item, "activate",
2871- G_CALLBACK (add_to_shortcuts_cb), impl);
2872- gtk_widget_show (item);
2873- gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
2874-
2875- item = gtk_image_menu_item_new_with_mnemonic (_("Open _Location"));
2876- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
2877- gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
2878- g_signal_connect (item, "activate",
2879- G_CALLBACK (open_location_cb), impl);
2880- gtk_widget_show (item);
2881- gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
2882-
2883- item = gtk_separator_menu_item_new ();
2884- gtk_widget_show (item);
2885- gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
2886-
2887- item = gtk_check_menu_item_new_with_mnemonic (_("Show _Hidden Files"));
2888- impl->browse_files_popup_menu_hidden_files_item = item;
2889- g_signal_connect (item, "toggled",
2890- G_CALLBACK (show_hidden_toggled_cb), impl);
2891- gtk_widget_show (item);
2892- gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
2893-}
2894-
2895-/* Updates the popup menu for the file list, creating it if necessary */
2896-static void
2897-file_list_update_popup_menu (GtkFileChooserDefault *impl)
2898-{
2899- file_list_build_popup_menu (impl);
2900-
2901- /* The sensitivity of the Add to Shortcuts item is set in
2902- * bookmarks_check_add_sensitivity()
2903- */
2904-
2905- g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item,
2906- G_CALLBACK (show_hidden_toggled_cb), impl);
2907- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_hidden_files_item),
2908- impl->show_hidden);
2909- g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_hidden_files_item,
2910- G_CALLBACK (show_hidden_toggled_cb), impl);
2911-}
2912-
2913-static void
2914-popup_position_func (GtkMenu *menu,
2915- gint *x,
2916- gint *y,
2917- gboolean *push_in,
2918- gpointer user_data)
2919-{
2920- GtkWidget *widget = GTK_WIDGET (user_data);
2921- GdkScreen *screen = gtk_widget_get_screen (widget);
2922- GtkRequisition req;
2923- gint monitor_num;
2924- GdkRectangle monitor;
2925-
2926- g_return_if_fail (GTK_WIDGET_REALIZED (widget));
2927-
2928- gdk_window_get_origin (widget->window, x, y);
2929-
2930- gtk_widget_size_request (GTK_WIDGET (menu), &req);
2931-
2932- *x += (widget->allocation.width - req.width) / 2;
2933- *y += (widget->allocation.height - req.height) / 2;
2934-
2935- monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
2936- gtk_menu_set_monitor (menu, monitor_num);
2937- gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2938-
2939- *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
2940- *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
2941-
2942- *push_in = FALSE;
2943-}
2944-
2945-static void
2946-file_list_popup_menu (GtkFileChooserDefault *impl,
2947- GdkEventButton *event)
2948-{
2949- file_list_update_popup_menu (impl);
2950- if (event)
2951- gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
2952- NULL, NULL, NULL, NULL,
2953- event->button, event->time);
2954- else
2955- {
2956- gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
2957- NULL, NULL,
2958- popup_position_func, impl->browse_files_tree_view,
2959- 0, GDK_CURRENT_TIME);
2960- gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_files_popup_menu),
2961- FALSE);
2962- }
2963-
2964-}
2965-
2966-/* Callback used for the GtkWidget::popup-menu signal of the file list */
2967-static gboolean
2968-list_popup_menu_cb (GtkWidget *widget,
2969- GtkFileChooserDefault *impl)
2970-{
2971- file_list_popup_menu (impl, NULL);
2972- return TRUE;
2973-}
2974-
2975-/* Callback used when a button is pressed on the file list. We trap button 3 to
2976- * bring up a popup menu.
2977- */
2978-static gboolean
2979-list_button_press_event_cb (GtkWidget *widget,
2980- GdkEventButton *event,
2981- GtkFileChooserDefault *impl)
2982-{
2983- if (event->button != 3)
2984- return FALSE;
2985-
2986- file_list_popup_menu (impl, event);
2987- return TRUE;
2988-}
2989+#endif
2990
2991 /* Creates the widgets for the file list */
2992 static GtkWidget *
2993@@ -3272,11 +1125,7 @@
2994 G_CALLBACK (list_row_activated), impl);
2995 g_signal_connect (impl->browse_files_tree_view, "key-press-event",
2996 G_CALLBACK (trap_activate_cb), impl);
2997- g_signal_connect (impl->browse_files_tree_view, "popup-menu",
2998- G_CALLBACK (list_popup_menu_cb), impl);
2999- g_signal_connect (impl->browse_files_tree_view, "button-press-event",
3000- G_CALLBACK (list_button_press_event_cb), impl);
3001-
3002+
3003 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
3004 gtk_tree_selection_set_select_function (selection,
3005 list_select_func,
3006@@ -3346,70 +1195,158 @@
3007 return swin;
3008 }
3009
3010-static GtkWidget *
3011-create_path_bar (GtkFileChooserDefault *impl)
3012+static void
3013+up_button_clicked_cb (GtkButton *button, gpointer data)
3014 {
3015- GtkWidget *path_bar;
3016-
3017- path_bar = g_object_new (GTK_TYPE_PATH_BAR, NULL);
3018- _gtk_path_bar_set_file_system (GTK_PATH_BAR (path_bar), impl->file_system);
3019-
3020- return path_bar;
3021+ GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (data);
3022+ up_folder_handler (impl);
3023 }
3024
3025 static void
3026-set_filter_tooltip (GtkWidget *widget,
3027- gpointer data)
3028+volume_button_clicked_cb (GtkButton *button, gpointer data)
3029 {
3030- GtkTooltips *tooltips = (GtkTooltips *)data;
3031-
3032- if (GTK_IS_BUTTON (widget))
3033- gtk_tooltips_set_tip (tooltips, widget,
3034- _("Select which types of files are shown"),
3035- NULL);
3036+ GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (data);
3037+ GtkFilePath * path = g_object_get_data (G_OBJECT (button), "file-path");
3038+
3039+ change_folder_and_display_error (impl, path);
3040 }
3041
3042-static void
3043-realize_filter_combo (GtkWidget *combo,
3044- gpointer data)
3045+static GtkWidget *
3046+create_bar (GtkFileChooserDefault *impl)
3047 {
3048- GtkFileChooserDefault *impl = (GtkFileChooserDefault *)data;
3049+ GSList *list, *l;
3050+ int n;
3051+ GtkWidget *bar = gtk_hbox_new (FALSE, DEFAULT_SPACING);
3052+ GtkWidget *img;
3053+
3054+ /* first the Up button */
3055+ img = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_BUTTON);
3056+ gtk_widget_show (img);
3057+
3058+ impl->up_button = gtk_button_new ();
3059+ gtk_container_add (GTK_CONTAINER (impl->up_button), img);
3060+ gtk_widget_show (impl->up_button);
3061+ gtk_widget_set_sensitive (impl->up_button, FALSE);
3062+ gtk_button_set_focus_on_click (GTK_BUTTON (impl->up_button), FALSE);
3063+
3064+ g_signal_connect (impl->up_button, "clicked",
3065+ G_CALLBACK (up_button_clicked_cb), impl);
3066+ gtk_box_pack_start (GTK_BOX(bar), impl->up_button, FALSE, FALSE, 0);
3067+
3068+ impl->num_volumes = 0;
3069+ list = gtk_file_system_list_volumes (impl->file_system);
3070+
3071+ n = 0;
3072+
3073+ for (l = list; l; l = l->next, n++)
3074+ {
3075+ GtkFileSystemVolume *volume;
3076+ GdkPixbuf *pixbuf;
3077+ GtkWidget *button;
3078+ GtkWidget *image;
3079+ GtkFilePath *base_path;
3080+ gchar * file_name = NULL;
3081+
3082+ volume = l->data;
3083+ base_path =
3084+ gtk_file_system_volume_get_base_path (impl->file_system, volume);
3085+
3086+ if (impl->local_only)
3087+ {
3088+ gboolean is_local =
3089+ gtk_file_system_path_is_local (impl->file_system, base_path);
3090+
3091+ if (!is_local)
3092+ {
3093+ gtk_file_path_free (base_path);
3094+ gtk_file_system_volume_free (impl->file_system, volume);
3095+ continue;
3096+ }
3097+ }
3098+
3099+#if 0
3100+ label_copy =
3101+ gtk_file_system_volume_get_display_name (impl->file_system, volume);
3102+#endif
3103+ pixbuf =
3104+ gtk_file_system_volume_render_icon (impl->file_system, volume,
3105+ GTK_WIDGET (impl),
3106+ impl->icon_size, NULL);
3107+
3108+ button = gtk_button_new ();
3109+ image = gtk_image_new_from_pixbuf (pixbuf);
3110+ g_object_unref (G_OBJECT (pixbuf));
3111+ gtk_container_add (GTK_CONTAINER (button), image);
3112+ gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
3113+
3114+ file_name =
3115+ gtk_file_system_path_to_filename (impl->file_system, base_path);
3116+
3117+ if (file_name && impl->root_folder &&
3118+ strcmp (file_name, impl->root_folder) &&
3119+ !strncmp (file_name, impl->root_folder, strlen (file_name)))
3120+ {
3121+ /* The base path is below the root folder; we replace it with
3122+ * the root folder
3123+ */
3124+ gtk_file_path_free (base_path);
3125+ base_path = gtk_file_system_filename_to_path (impl->file_system,
3126+ impl->root_folder);
3127+ }
3128+
3129+ g_free (file_name);
3130+
3131+ gtk_widget_show_all (button);
3132+
3133+ g_object_set_data (G_OBJECT (button), "file-path", base_path);
3134+
3135+ g_signal_connect (button, "clicked",
3136+ G_CALLBACK (volume_button_clicked_cb), impl);
3137+
3138+ gtk_box_pack_start (GTK_BOX(bar), button, FALSE, FALSE, 0);
3139+ }
3140
3141- gtk_container_forall (GTK_CONTAINER (combo),
3142- set_filter_tooltip,
3143- impl->tooltips);
3144+ impl->num_volumes = n;
3145+ g_slist_free (list);
3146+
3147+ gtk_widget_show (bar);
3148+
3149+ return bar;
3150 }
3151
3152 /* Creates the widgets for the files/folders pane */
3153 static GtkWidget *
3154-file_pane_create (GtkFileChooserDefault *impl,
3155- GtkSizeGroup *size_group)
3156+file_pane_create (GtkFileChooserDefault *impl)
3157 {
3158 GtkWidget *vbox;
3159 GtkWidget *hbox;
3160 GtkWidget *widget;
3161-
3162- vbox = gtk_vbox_new (FALSE, 6);
3163+ vbox = gtk_vbox_new (FALSE, DEFAULT_SPACING);
3164 gtk_widget_show (vbox);
3165
3166- /* The path bar and 'Create Folder' button */
3167- hbox = gtk_hbox_new (FALSE, 12);
3168+ /* The volume bar and 'Create Folder' button */
3169+ hbox = gtk_hbox_new (FALSE, DEFAULT_SPACING);
3170 gtk_widget_show (hbox);
3171- impl->browse_path_bar = create_path_bar (impl);
3172- g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl);
3173- gtk_widget_show_all (impl->browse_path_bar);
3174- gtk_box_pack_start (GTK_BOX (hbox), impl->browse_path_bar, TRUE, TRUE, 0);
3175+ impl->bar = create_bar (impl);
3176+ gtk_widget_show_all (impl->bar);
3177+ gtk_box_pack_start (GTK_BOX (hbox), impl->bar, TRUE, TRUE, 0);
3178
3179 /* Create Folder */
3180- impl->browse_new_folder_button = gtk_button_new_with_mnemonic (_("Create Fo_lder"));
3181+ widget = gtk_image_new_from_icon_name ("folder-new", GTK_ICON_SIZE_BUTTON);
3182+ gtk_widget_show (widget);
3183+ impl->browse_new_folder_button = gtk_button_new ();
3184+ gtk_container_add (GTK_CONTAINER (impl->browse_new_folder_button), widget);
3185+ gtk_button_set_focus_on_click (GTK_BUTTON (impl->browse_new_folder_button),
3186+ FALSE);
3187+
3188 g_signal_connect (impl->browse_new_folder_button, "clicked",
3189 G_CALLBACK (new_folder_button_clicked), impl);
3190 gtk_box_pack_end (GTK_BOX (hbox), impl->browse_new_folder_button, FALSE, FALSE, 0);
3191 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
3192
3193- /* Box for lists and preview */
3194+ /* Box for lists */
3195
3196- hbox = gtk_hbox_new (FALSE, PREVIEW_HBOX_SPACING);
3197+ hbox = gtk_hbox_new (FALSE, LIST_HBOX_SPACING);
3198 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
3199 gtk_widget_show (hbox);
3200
3201@@ -3418,157 +1355,37 @@
3202 widget = create_file_list (impl);
3203 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
3204
3205- /* Preview */
3206-
3207- impl->preview_box = gtk_vbox_new (FALSE, 12);
3208- gtk_box_pack_start (GTK_BOX (hbox), impl->preview_box, FALSE, FALSE, 0);
3209- /* Don't show preview box initially */
3210-
3211- /* Filter combo */
3212-
3213- impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
3214-
3215- widget = filter_create (impl);
3216-
3217- g_signal_connect (widget, "realize",
3218- G_CALLBACK (realize_filter_combo), impl);
3219-
3220- gtk_widget_show (widget);
3221- gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox), widget, FALSE, FALSE, 0);
3222-
3223- gtk_size_group_add_widget (size_group, impl->filter_combo_hbox);
3224- gtk_box_pack_end (GTK_BOX (vbox), impl->filter_combo_hbox, FALSE, FALSE, 0);
3225-
3226 return vbox;
3227 }
3228-/* Callback used when the "Browse for more folders" expander is toggled */
3229-static void
3230-expander_changed_cb (GtkExpander *expander,
3231- GParamSpec *pspec,
3232- GtkFileChooserDefault *impl)
3233-{
3234- update_appearance (impl);
3235-}
3236-
3237-/* Callback used when the selection changes in the save folder combo box */
3238-static void
3239-save_folder_combo_changed_cb (GtkComboBox *combo,
3240- GtkFileChooserDefault *impl)
3241-{
3242- GtkTreeIter iter;
3243-
3244- if (impl->changing_folder)
3245- return;
3246-
3247- if (gtk_combo_box_get_active_iter (combo, &iter))
3248- shortcuts_activate_iter (impl, &iter);
3249-}
3250-
3251-/* Creates the combo box with the save folders */
3252-static GtkWidget *
3253-save_folder_combo_create (GtkFileChooserDefault *impl)
3254-{
3255- GtkWidget *combo;
3256- GtkCellRenderer *cell;
3257-
3258- combo = g_object_new (GTK_TYPE_COMBO_BOX,
3259- "model", impl->shortcuts_model,
3260- "focus-on-click", FALSE,
3261- NULL);
3262- gtk_widget_show (combo);
3263-
3264- cell = gtk_cell_renderer_pixbuf_new ();
3265- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, FALSE);
3266- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
3267- "pixbuf", SHORTCUTS_COL_PIXBUF,
3268- "visible", SHORTCUTS_COL_PIXBUF_VISIBLE,
3269- "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
3270- NULL);
3271-
3272- cell = gtk_cell_renderer_text_new ();
3273- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
3274- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
3275- "text", SHORTCUTS_COL_NAME,
3276- "sensitive", SHORTCUTS_COL_PIXBUF_VISIBLE,
3277- NULL);
3278-
3279- gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
3280- shortcuts_row_separator_func,
3281- GINT_TO_POINTER (SHORTCUTS_COL_NAME),
3282- NULL);
3283-
3284- g_signal_connect (combo, "changed",
3285- G_CALLBACK (save_folder_combo_changed_cb), impl);
3286-
3287- return combo;
3288-}
3289
3290 /* Creates the widgets specific to Save mode */
3291 static GtkWidget *
3292 save_widgets_create (GtkFileChooserDefault *impl)
3293 {
3294 GtkWidget *vbox;
3295- GtkWidget *table;
3296+ GtkWidget *hbox;
3297 GtkWidget *widget;
3298- GtkWidget *alignment;
3299-
3300- vbox = gtk_vbox_new (FALSE, 12);
3301-
3302- table = gtk_table_new (2, 2, FALSE);
3303- gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
3304- gtk_widget_show (table);
3305- gtk_table_set_row_spacings (GTK_TABLE (table), 12);
3306- gtk_table_set_col_spacings (GTK_TABLE (table), 12);
3307-
3308- /* Name entry */
3309
3310- widget = gtk_label_new_with_mnemonic (_("_Name:"));
3311+ vbox = gtk_vbox_new (FALSE, 0);
3312+ hbox = gtk_hbox_new (FALSE, DEFAULT_SPACING);
3313+
3314+ widget = gtk_label_new (_("Name:"));
3315 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
3316- gtk_table_attach (GTK_TABLE (table), widget,
3317- 0, 1, 0, 1,
3318- GTK_FILL, GTK_FILL,
3319- 0, 0);
3320+ gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
3321 gtk_widget_show (widget);
3322
3323 impl->save_file_name_entry = _gtk_file_chooser_entry_new (TRUE);
3324 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
3325 impl->file_system);
3326- gtk_entry_set_width_chars (GTK_ENTRY (impl->save_file_name_entry), 45);
3327+/* gtk_entry_set_width_chars (GTK_ENTRY (impl->save_file_name_entry), 45); */
3328 gtk_entry_set_activates_default (GTK_ENTRY (impl->save_file_name_entry), TRUE);
3329- gtk_table_attach (GTK_TABLE (table), impl->save_file_name_entry,
3330- 1, 2, 0, 1,
3331- GTK_EXPAND | GTK_FILL, 0,
3332- 0, 0);
3333+ gtk_box_pack_start (GTK_BOX (hbox), impl->save_file_name_entry,
3334+ TRUE, TRUE, 0);
3335 gtk_widget_show (impl->save_file_name_entry);
3336- gtk_label_set_mnemonic_widget (GTK_LABEL (widget), impl->save_file_name_entry);
3337-
3338- /* Folder combo */
3339- impl->save_folder_label = gtk_label_new (NULL);
3340- gtk_misc_set_alignment (GTK_MISC (impl->save_folder_label), 0.0, 0.5);
3341- gtk_table_attach (GTK_TABLE (table), impl->save_folder_label,
3342- 0, 1, 1, 2,
3343- GTK_FILL, GTK_FILL,
3344- 0, 0);
3345- gtk_widget_show (impl->save_folder_label);
3346-
3347- impl->save_folder_combo = save_folder_combo_create (impl);
3348- gtk_table_attach (GTK_TABLE (table), impl->save_folder_combo,
3349- 1, 2, 1, 2,
3350- GTK_EXPAND | GTK_FILL, GTK_FILL,
3351- 0, 0);
3352- gtk_label_set_mnemonic_widget (GTK_LABEL (impl->save_folder_label), impl->save_folder_combo);
3353-
3354- /* Expander */
3355- alignment = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
3356- gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
3357-
3358- impl->save_expander = gtk_expander_new_with_mnemonic (_("_Browse for other folders"));
3359- gtk_container_add (GTK_CONTAINER (alignment), impl->save_expander);
3360- g_signal_connect (impl->save_expander, "notify::expanded",
3361- G_CALLBACK (expander_changed_cb),
3362- impl);
3363- gtk_widget_show_all (alignment);
3364
3365+ gtk_widget_show (hbox);
3366+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
3367+
3368 return vbox;
3369 }
3370
3371@@ -3576,29 +1393,11 @@
3372 static GtkWidget *
3373 browse_widgets_create (GtkFileChooserDefault *impl)
3374 {
3375- GtkWidget *vbox;
3376- GtkWidget *hpaned;
3377 GtkWidget *widget;
3378- GtkSizeGroup *size_group;
3379-
3380- /* size group is used by the [+][-] buttons and the filter combo */
3381- size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
3382- vbox = gtk_vbox_new (FALSE, 12);
3383-
3384- /* Paned widget */
3385- hpaned = gtk_hpaned_new ();
3386- gtk_widget_show (hpaned);
3387- gtk_paned_set_position (GTK_PANED (hpaned), 200); /* FIXME: this sucks */
3388- gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
3389-
3390- widget = shortcuts_pane_create (impl, size_group);
3391- gtk_paned_pack1 (GTK_PANED (hpaned), widget, FALSE, FALSE);
3392- widget = file_pane_create (impl, size_group);
3393- gtk_paned_pack2 (GTK_PANED (hpaned), widget, TRUE, FALSE);
3394
3395- g_object_unref (size_group);
3396+ widget = file_pane_create (impl);
3397
3398- return vbox;
3399+ return widget;
3400 }
3401
3402 static GObject*
3403@@ -3618,54 +1417,18 @@
3404
3405 gtk_widget_push_composite_child ();
3406
3407- /* Shortcuts model */
3408-
3409- shortcuts_model_create (impl);
3410-
3411- /* Widgets for Save mode */
3412- impl->save_widgets = save_widgets_create (impl);
3413- gtk_box_pack_start (GTK_BOX (impl), impl->save_widgets, FALSE, FALSE, 0);
3414-
3415 /* The browse widgets */
3416 impl->browse_widgets = browse_widgets_create (impl);
3417 gtk_box_pack_start (GTK_BOX (impl), impl->browse_widgets, TRUE, TRUE, 0);
3418
3419- /* Alignment to hold extra widget */
3420- impl->extra_align = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
3421- gtk_box_pack_start (GTK_BOX (impl), impl->extra_align, FALSE, FALSE, 0);
3422-
3423- gtk_widget_pop_composite_child ();
3424- update_appearance (impl);
3425-
3426- return object;
3427-}
3428-
3429-/* Sets the extra_widget by packing it in the appropriate place */
3430-static void
3431-set_extra_widget (GtkFileChooserDefault *impl,
3432- GtkWidget *extra_widget)
3433-{
3434- if (extra_widget)
3435- {
3436- g_object_ref (extra_widget);
3437- /* FIXME: is this right ? */
3438- gtk_widget_show (extra_widget);
3439- }
3440-
3441- if (impl->extra_widget)
3442- {
3443- gtk_container_remove (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
3444- g_object_unref (impl->extra_widget);
3445- }
3446+ /* Widgets for Save mode */
3447+ impl->save_widgets = save_widgets_create (impl);
3448+ gtk_box_pack_start (GTK_BOX (impl), impl->save_widgets, FALSE, FALSE, 0);
3449+
3450+ gtk_widget_pop_composite_child ();
3451+ update_appearance (impl);
3452
3453- impl->extra_widget = extra_widget;
3454- if (impl->extra_widget)
3455- {
3456- gtk_container_add (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
3457- gtk_widget_show (impl->extra_align);
3458- }
3459- else
3460- gtk_widget_hide (impl->extra_align);
3461+ return object;
3462 }
3463
3464 static void
3465@@ -3676,12 +1439,6 @@
3466 {
3467 impl->local_only = local_only;
3468
3469- if (impl->shortcuts_model && impl->file_system)
3470- {
3471- shortcuts_add_volumes (impl);
3472- shortcuts_add_bookmarks (impl);
3473- }
3474-
3475 if (local_only &&
3476 !gtk_file_system_path_is_local (impl->file_system, impl->current_folder))
3477 {
3478@@ -3708,18 +1465,7 @@
3479 volumes_changed_cb (GtkFileSystem *file_system,
3480 GtkFileChooserDefault *impl)
3481 {
3482- shortcuts_add_volumes (impl);
3483-}
3484-
3485-/* Callback used when the set of bookmarks changes in the file system */
3486-static void
3487-bookmarks_changed_cb (GtkFileSystem *file_system,
3488- GtkFileChooserDefault *impl)
3489-{
3490- shortcuts_add_bookmarks (impl);
3491-
3492- bookmarks_check_add_sensitivity (impl);
3493- bookmarks_check_remove_sensitivity (impl);
3494+ /* FIXME -- not needed */
3495 }
3496
3497 /* Sets the file chooser to multiple selection mode */
3498@@ -3741,8 +1487,6 @@
3499
3500 impl->select_multiple = select_multiple;
3501 g_object_notify (G_OBJECT (impl), "select-multiple");
3502-
3503- check_preview_change (impl);
3504 }
3505
3506 static void
3507@@ -3753,8 +1497,6 @@
3508 {
3509 g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
3510 impl->volumes_changed_id = 0;
3511- g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
3512- impl->bookmarks_changed_id = 0;
3513 g_object_unref (impl->file_system);
3514 }
3515
3516@@ -3790,9 +1532,6 @@
3517 impl->volumes_changed_id = g_signal_connect (impl->file_system, "volumes-changed",
3518 G_CALLBACK (volumes_changed_cb),
3519 impl);
3520- impl->bookmarks_changed_id = g_signal_connect (impl->file_system, "bookmarks-changed",
3521- G_CALLBACK (bookmarks_changed_cb),
3522- impl);
3523 }
3524 }
3525
3526@@ -3807,30 +1546,8 @@
3527 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
3528 impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
3529 {
3530- const char *text;
3531-
3532 gtk_widget_show (impl->save_widgets);
3533-
3534- if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
3535- text = _("Save in _folder:");
3536- else
3537- text = _("Create in _folder:");
3538-
3539- gtk_label_set_text_with_mnemonic (GTK_LABEL (impl->save_folder_label), text);
3540-
3541- if (gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)))
3542- {
3543- gtk_widget_set_sensitive (impl->save_folder_label, FALSE);
3544- gtk_widget_set_sensitive (impl->save_folder_combo, FALSE);
3545- gtk_widget_show (impl->browse_widgets);
3546- }
3547- else
3548- {
3549- gtk_widget_set_sensitive (impl->save_folder_label, TRUE);
3550- gtk_widget_set_sensitive (impl->save_folder_combo, TRUE);
3551- gtk_widget_hide (impl->browse_widgets);
3552- }
3553-
3554+ gtk_widget_show (impl->browse_widgets);
3555 gtk_widget_show (impl->browse_new_folder_button);
3556
3557 if (impl->select_multiple)
3558@@ -3844,6 +1561,7 @@
3559 impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
3560 {
3561 gtk_widget_hide (impl->save_widgets);
3562+ gtk_widget_hide (impl->browse_new_folder_button);
3563 gtk_widget_show (impl->browse_widgets);
3564 }
3565
3566@@ -3876,12 +1594,9 @@
3567 {
3568 gtk_file_chooser_default_unselect_all (GTK_FILE_CHOOSER (impl));
3569
3570- if ((action == GTK_FILE_CHOOSER_ACTION_SAVE || action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
3571- && impl->select_multiple)
3572+ if (action == GTK_FILE_CHOOSER_ACTION_SAVE && impl->select_multiple)
3573 {
3574- g_warning ("Tried to change the file chooser action to SAVE or CREATE_FOLDER, but "
3575- "this is not allowed in multiple selection mode. Resetting the file chooser "
3576- "to single selection mode.");
3577+ g_warning ("Multiple selection mode is not allowed in Save mode");
3578 set_select_multiple (impl, FALSE, TRUE);
3579 }
3580 impl->action = action;
3581@@ -3896,35 +1611,15 @@
3582 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
3583 set_file_system_backend (impl, g_value_get_string (value));
3584 break;
3585- case GTK_FILE_CHOOSER_PROP_FILTER:
3586- set_current_filter (impl, g_value_get_object (value));
3587- break;
3588 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
3589 set_local_only (impl, g_value_get_boolean (value));
3590 break;
3591- case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
3592- set_preview_widget (impl, g_value_get_object (value));
3593- break;
3594- case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
3595- impl->preview_widget_active = g_value_get_boolean (value);
3596- update_preview_widget_visibility (impl);
3597- break;
3598- case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
3599- impl->use_preview_label = g_value_get_boolean (value);
3600- update_preview_widget_visibility (impl);
3601- break;
3602- case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
3603- set_extra_widget (impl, g_value_get_object (value));
3604- break;
3605 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
3606 {
3607 gboolean select_multiple = g_value_get_boolean (value);
3608- if ((impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
3609- && select_multiple)
3610+ if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE && select_multiple)
3611 {
3612- g_warning ("Tried to set the file chooser to multiple selection mode, but this is "
3613- "not allowed in SAVE or CREATE_FOLDER modes. Ignoring the change and "
3614- "leaving the file chooser in single selection mode.");
3615+ g_warning ("Multiple selection mode is not allowed in Save mode");
3616 return;
3617 }
3618
3619@@ -3943,6 +1638,11 @@
3620 }
3621 }
3622 break;
3623+ case GTK_FILE_CHOOSER_PROP_ROOT_FOLDER:
3624+ {
3625+ impl->root_folder = g_strdup (g_value_get_string (value));
3626+ }
3627+ break;
3628 default:
3629 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3630 break;
3631@@ -3962,30 +1662,18 @@
3632 case GTK_FILE_CHOOSER_PROP_ACTION:
3633 g_value_set_enum (value, impl->action);
3634 break;
3635- case GTK_FILE_CHOOSER_PROP_FILTER:
3636- g_value_set_object (value, impl->current_filter);
3637- break;
3638 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
3639 g_value_set_boolean (value, impl->local_only);
3640 break;
3641- case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
3642- g_value_set_object (value, impl->preview_widget);
3643- break;
3644- case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
3645- g_value_set_boolean (value, impl->preview_widget_active);
3646- break;
3647- case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
3648- g_value_set_boolean (value, impl->use_preview_label);
3649- break;
3650- case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
3651- g_value_set_object (value, impl->extra_widget);
3652- break;
3653 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
3654 g_value_set_boolean (value, impl->select_multiple);
3655 break;
3656 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
3657 g_value_set_boolean (value, impl->show_hidden);
3658 break;
3659+ case GTK_FILE_CHOOSER_PROP_ROOT_FOLDER:
3660+ g_value_set_string (value, impl->root_folder);
3661+ break;
3662 default:
3663 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3664 break;
3665@@ -4013,12 +1701,6 @@
3666 {
3667 GtkFileChooserDefault *impl = (GtkFileChooserDefault *) object;
3668
3669- if (impl->extra_widget)
3670- {
3671- g_object_unref (impl->extra_widget);
3672- impl->extra_widget = NULL;
3673- }
3674-
3675 remove_settings_signal (impl, gtk_widget_get_screen (GTK_WIDGET (impl)));
3676
3677 G_OBJECT_CLASS (parent_class)->dispose (object);
3678@@ -4031,12 +1713,7 @@
3679 static void
3680 gtk_file_chooser_default_show_all (GtkWidget *widget)
3681 {
3682- GtkFileChooserDefault *impl = (GtkFileChooserDefault *) widget;
3683-
3684 gtk_widget_show (widget);
3685-
3686- if (impl->extra_widget)
3687- gtk_widget_show_all (impl->extra_widget);
3688 }
3689
3690 /* Handler for GtkWindow::set-focus; this is where we save the last-focused
3691@@ -4095,7 +1772,6 @@
3692 else
3693 impl->icon_size = FALLBACK_ICON_SIZE;
3694
3695- shortcuts_reload_icons (impl);
3696 gtk_widget_queue_resize (impl->browse_files_tree_view);
3697 }
3698
3699@@ -4169,53 +1845,6 @@
3700 g_signal_emit_by_name (widget, "default-size-changed");
3701 }
3702
3703-static gboolean
3704-get_is_file_filtered (GtkFileChooserDefault *impl,
3705- const GtkFilePath *path,
3706- GtkFileInfo *file_info)
3707-{
3708- GtkFileFilterInfo filter_info;
3709- GtkFileFilterFlags needed;
3710- gboolean result;
3711-
3712- if (!impl->current_filter)
3713- return FALSE;
3714-
3715- filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
3716-
3717- needed = gtk_file_filter_get_needed (impl->current_filter);
3718-
3719- filter_info.display_name = gtk_file_info_get_display_name (file_info);
3720- filter_info.mime_type = gtk_file_info_get_mime_type (file_info);
3721-
3722- if (needed & GTK_FILE_FILTER_FILENAME)
3723- {
3724- filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
3725- if (filter_info.filename)
3726- filter_info.contains |= GTK_FILE_FILTER_FILENAME;
3727- }
3728- else
3729- filter_info.filename = NULL;
3730-
3731- if (needed & GTK_FILE_FILTER_URI)
3732- {
3733- filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
3734- if (filter_info.uri)
3735- filter_info.contains |= GTK_FILE_FILTER_URI;
3736- }
3737- else
3738- filter_info.uri = NULL;
3739-
3740- result = gtk_file_filter_filter (impl->current_filter, &filter_info);
3741-
3742- if (filter_info.filename)
3743- g_free ((gchar *)filter_info.filename);
3744- if (filter_info.uri)
3745- g_free ((gchar *)filter_info.uri);
3746-
3747- return !result;
3748-}
3749-
3750 /* GtkWidget::map method */
3751 static void
3752 gtk_file_chooser_default_map (GtkWidget *widget)
3753@@ -4231,50 +1860,8 @@
3754 pending_select_paths_store_selection (impl);
3755 change_folder_and_display_error (impl, impl->current_folder);
3756 }
3757-
3758- bookmarks_changed_cb (impl->file_system, impl);
3759-}
3760-
3761-static gboolean
3762-list_model_filter_func (GtkFileSystemModel *model,
3763- GtkFilePath *path,
3764- const GtkFileInfo *file_info,
3765- gpointer user_data)
3766-{
3767- GtkFileChooserDefault *impl = user_data;
3768-
3769- if (!impl->current_filter)
3770- return TRUE;
3771-
3772- if (gtk_file_info_get_is_folder (file_info))
3773- return TRUE;
3774-
3775- return !get_is_file_filtered (impl, path, (GtkFileInfo *) file_info);
3776 }
3777
3778-static void
3779-install_list_model_filter (GtkFileChooserDefault *impl)
3780-{
3781- GtkFileSystemModelFilter filter;
3782- gpointer data;
3783-
3784- g_assert (impl->browse_files_model != NULL);
3785-
3786- if (impl->current_filter)
3787- {
3788- filter = list_model_filter_func;
3789- data = impl;
3790- }
3791- else
3792- {
3793- filter = NULL;
3794- data = NULL;
3795- }
3796-
3797- _gtk_file_system_model_set_filter (impl->browse_files_model,
3798- filter,
3799- data);
3800-}
3801
3802 #define COMPARE_DIRECTORIES \
3803 GtkFileChooserDefault *impl = user_data; \
3804@@ -4519,18 +2106,21 @@
3805 GtkFileFolder *folder;
3806 gboolean success;
3807 gboolean have_hidden;
3808- gboolean have_filtered;
3809
3810 if (!only_one_path && !paths)
3811 return TRUE;
3812
3813+#ifdef GTK26
3814 folder = gtk_file_system_get_folder (impl->file_system, parent_path, GTK_FILE_INFO_IS_HIDDEN, error);
3815+#else
3816+ folder = gtk_file_system_get_folder (impl->file_system, parent_path, GTK_FILE_INFO_IS_HIDDEN, NULL, NULL);
3817+#endif
3818+
3819 if (!folder)
3820 return FALSE;
3821
3822 success = FALSE;
3823 have_hidden = FALSE;
3824- have_filtered = FALSE;
3825
3826 if (only_one_path)
3827 {
3828@@ -4541,7 +2131,6 @@
3829 {
3830 success = TRUE;
3831 have_hidden = gtk_file_info_get_is_hidden (info);
3832- have_filtered = get_is_file_filtered (impl, only_one_path, info);
3833 gtk_file_info_free (info);
3834 }
3835 }
3836@@ -4563,12 +2152,9 @@
3837 if (!have_hidden)
3838 have_hidden = gtk_file_info_get_is_hidden (info);
3839
3840- if (!have_filtered)
3841- have_filtered = get_is_file_filtered (impl, path, info);
3842-
3843 gtk_file_info_free (info);
3844
3845- if (have_hidden && have_filtered)
3846+ if (have_hidden)
3847 break; /* we now have all the information we need */
3848 }
3849 }
3850@@ -4584,9 +2170,6 @@
3851 if (have_hidden)
3852 g_object_set (impl, "show-hidden", TRUE, NULL);
3853
3854- if (have_filtered)
3855- set_current_filter (impl, NULL);
3856-
3857 if (only_one_path)
3858 _gtk_file_system_model_path_do (impl->browse_files_model, only_one_path, select_func, impl);
3859 else
3860@@ -4629,13 +2212,11 @@
3861 * that case, the chooser's selection should be what the caller expects,
3862 * as the user can't see that something else got selected. See bug #165264.
3863 *
3864- * Also, we don't select the first file if we are not in OPEN mode. Doing
3865- * so would change the contents of the filename entry for SAVE or
3866- * CREATE_FOLDER, which is undesired; in SELECT_FOLDER, we don't want to
3867- * select a *different* folder from the one into which the user just
3868- * navigated.
3869+ * Also, we don't select the first file if we are in SAVE or CREATE_FOLDER
3870+ * modes. Doing so would change the contents of the filename entry.
3871 */
3872- if (GTK_WIDGET_MAPPED (impl) && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
3873+ if (GTK_WIDGET_MAPPED (impl)
3874+ && !(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
3875 browse_files_select_first_row (impl);
3876 }
3877
3878@@ -4713,8 +2294,6 @@
3879
3880 _gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
3881
3882- install_list_model_filter (impl);
3883-
3884 return TRUE;
3885 }
3886
3887@@ -4725,19 +2304,15 @@
3888 const GtkFileInfo *info;
3889 GtkTreeIter iter;
3890 GtkTreeIter child_iter;
3891- gboolean change_entry;
3892
3893- if (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
3894+ if (impl->action != GTK_FILE_CHOOSER_ACTION_SAVE)
3895 return;
3896
3897 g_assert (!impl->select_multiple);
3898 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
3899
3900 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
3901- {
3902- _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry), "");
3903- return;
3904- }
3905+ return;
3906
3907 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
3908 &child_iter,
3909@@ -4745,12 +2320,7 @@
3910
3911 info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
3912
3913- if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
3914- change_entry = !gtk_file_info_get_is_folder (info); /* We don't want the name to change when clicking on a folder... */
3915- else
3916- change_entry = TRUE; /* ... unless we are in CREATE_FOLDER mode */
3917-
3918- if (change_entry)
3919+ if (!gtk_file_info_get_is_folder (info))
3920 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
3921 gtk_file_info_get_display_name (info));
3922 }
3923@@ -4780,9 +2350,6 @@
3924 if (!check_is_folder (impl->file_system, path, error))
3925 return FALSE;
3926
3927- if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), path, error))
3928- return FALSE;
3929-
3930 if (impl->current_folder != path)
3931 {
3932 if (impl->current_folder)
3933@@ -4791,17 +2358,6 @@
3934 impl->current_folder = gtk_file_path_copy (path);
3935 }
3936
3937- /* Update the widgets that may trigger a folder change themselves. */
3938-
3939- if (!impl->changing_folder)
3940- {
3941- impl->changing_folder = TRUE;
3942-
3943- shortcuts_update_current_folder (impl);
3944-
3945- impl->changing_folder = FALSE;
3946- }
3947-
3948 /* Set the folder on the save entry */
3949
3950 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
3951@@ -4815,13 +2371,7 @@
3952
3953 /* Refresh controls */
3954
3955- shortcuts_find_current_folder (impl);
3956-
3957 g_signal_emit_by_name (impl, "current-folder-changed", 0);
3958-
3959- check_preview_change (impl);
3960- bookmarks_check_add_sensitivity (impl);
3961-
3962 g_signal_emit_by_name (impl, "selection-changed", 0);
3963
3964 return result;
3965@@ -4844,7 +2394,6 @@
3966 g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
3967 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
3968
3969- pending_select_paths_free (impl);
3970 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry), name);
3971 }
3972
3973@@ -4983,24 +2532,13 @@
3974 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
3975
3976 gtk_tree_selection_unselect_all (selection);
3977- pending_select_paths_free (impl);
3978 }
3979
3980-/* Checks whether the filename entry for the Save modes contains a well-formed filename.
3981- *
3982- * is_well_formed_ret - whether what the user typed passes gkt_file_system_make_path()
3983- *
3984- * is_empty_ret - whether the file entry is totally empty
3985- *
3986- * is_file_part_empty_ret - whether the file part is empty (will be if user types "foobar/", and
3987- * the path will be "$cwd/foobar")
3988- */
3989-static void
3990+/* Checks whether the filename entry for the Save modes contains a valid filename */
3991+static GtkFilePath *
3992 check_save_entry (GtkFileChooserDefault *impl,
3993- GtkFilePath **path_ret,
3994- gboolean *is_well_formed_ret,
3995- gboolean *is_empty_ret,
3996- gboolean *is_file_part_empty_ret)
3997+ gboolean *is_valid,
3998+ gboolean *is_empty)
3999 {
4000 GtkFileChooserEntry *chooser_entry;
4001 const GtkFilePath *current_folder;
4002@@ -5013,31 +2551,17 @@
4003
4004 chooser_entry = GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry);
4005
4006- if (strlen (gtk_entry_get_text (GTK_ENTRY (chooser_entry))) == 0)
4007- {
4008- *path_ret = NULL;
4009- *is_well_formed_ret = TRUE;
4010- *is_empty_ret = TRUE;
4011- *is_file_part_empty_ret = TRUE;
4012-
4013- return;
4014- }
4015-
4016- *is_empty_ret = FALSE;
4017-
4018 current_folder = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
4019 file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
4020
4021 if (!file_part || file_part[0] == '\0')
4022 {
4023- *path_ret = gtk_file_path_copy (current_folder);
4024- *is_well_formed_ret = TRUE;
4025- *is_file_part_empty_ret = TRUE;
4026-
4027- return;
4028+ *is_valid = FALSE;
4029+ *is_empty = TRUE;
4030+ return NULL;
4031 }
4032
4033- *is_file_part_empty_ret = FALSE;
4034+ *is_empty = FALSE;
4035
4036 error = NULL;
4037 path = gtk_file_system_make_path (impl->file_system, current_folder, file_part, &error);
4038@@ -5045,14 +2569,12 @@
4039 if (!path)
4040 {
4041 error_building_filename_dialog (impl, current_folder, file_part, error);
4042- *path_ret = NULL;
4043- *is_well_formed_ret = FALSE;
4044-
4045- return;
4046+ *is_valid = FALSE;
4047+ return NULL;
4048 }
4049
4050- *path_ret = path;
4051- *is_well_formed_ret = TRUE;
4052+ *is_valid = TRUE;
4053+ return path;
4054 }
4055
4056 struct get_paths_closure {
4057@@ -5098,21 +2620,11 @@
4058 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
4059 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
4060 {
4061- gboolean is_well_formed, is_empty, is_file_part_empty;
4062-
4063- check_save_entry (impl, &info.path_from_entry, &is_well_formed, &is_empty, &is_file_part_empty);
4064+ gboolean is_valid, is_empty;
4065
4066- if (!is_well_formed)
4067+ info.path_from_entry = check_save_entry (impl, &is_valid, &is_empty);
4068+ if (!is_valid && !is_empty)
4069 return NULL;
4070-
4071- if (!is_empty)
4072- {
4073- if (is_file_part_empty && impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
4074- {
4075- gtk_file_path_free (info.path_from_entry);
4076- return NULL;
4077- }
4078- }
4079 }
4080
4081 if (!info.path_from_entry || impl->select_multiple)
4082@@ -5137,243 +2649,12 @@
4083 return g_slist_reverse (info.result);
4084 }
4085
4086-static GtkFilePath *
4087-gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser)
4088-{
4089- GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
4090-
4091- if (impl->preview_path)
4092- return gtk_file_path_copy (impl->preview_path);
4093- else
4094- return NULL;
4095-}
4096-
4097-static GtkFileSystem *
4098-gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser)
4099-{
4100- GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
4101-
4102- return impl->file_system;
4103-}
4104-
4105-/* Shows or hides the filter widgets */
4106-static void
4107-show_filters (GtkFileChooserDefault *impl,
4108- gboolean show)
4109-{
4110- if (show)
4111- gtk_widget_show (impl->filter_combo_hbox);
4112- else
4113- gtk_widget_hide (impl->filter_combo_hbox);
4114-}
4115-
4116-static void
4117-gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
4118- GtkFileFilter *filter)
4119-{
4120- GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
4121- const gchar *name;
4122-
4123- if (g_slist_find (impl->filters, filter))
4124- {
4125- g_warning ("gtk_file_chooser_add_filter() called on filter already in list\n");
4126- return;
4127- }
4128-
4129- g_object_ref (filter);
4130- gtk_object_sink (GTK_OBJECT (filter));
4131- impl->filters = g_slist_append (impl->filters, filter);
4132-
4133- name = gtk_file_filter_get_name (filter);
4134- if (!name)
4135- name = "Untitled filter"; /* Place-holder, doesn't need to be marked for translation */
4136-
4137- gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
4138-
4139- if (!g_slist_find (impl->filters, impl->current_filter))
4140- set_current_filter (impl, filter);
4141-
4142- show_filters (impl, TRUE);
4143-}
4144-
4145-static void
4146-gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
4147- GtkFileFilter *filter)
4148-{
4149- GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
4150- GtkTreeModel *model;
4151- GtkTreeIter iter;
4152- gint filter_index;
4153-
4154- filter_index = g_slist_index (impl->filters, filter);
4155-
4156- if (filter_index < 0)
4157- {
4158- g_warning ("gtk_file_chooser_remove_filter() called on filter not in list\n");
4159- return;
4160- }
4161-
4162- impl->filters = g_slist_remove (impl->filters, filter);
4163-
4164- if (filter == impl->current_filter)
4165- {
4166- if (impl->filters)
4167- set_current_filter (impl, impl->filters->data);
4168- else
4169- set_current_filter (impl, NULL);
4170- }
4171-
4172- /* Remove row from the combo box */
4173- model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
4174- gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_index);
4175- gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
4176-
4177- g_object_unref (filter);
4178-
4179- if (!impl->filters)
4180- show_filters (impl, FALSE);
4181-}
4182-
4183-static GSList *
4184-gtk_file_chooser_default_list_filters (GtkFileChooser *chooser)
4185-{
4186- GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
4187-
4188- return g_slist_copy (impl->filters);
4189-}
4190-
4191-/* Returns the position in the shortcuts tree where the nth specified shortcut would appear */
4192-static int
4193-shortcuts_get_pos_for_shortcut_folder (GtkFileChooserDefault *impl,
4194- int pos)
4195-{
4196- return pos + shortcuts_get_index (impl, SHORTCUTS_SHORTCUTS);
4197-}
4198-
4199-static gboolean
4200-gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
4201- const GtkFilePath *path,
4202- GError **error)
4203-{
4204- GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
4205- gboolean result;
4206- int pos;
4207-
4208- /* Test validity of path here. */
4209- if (!check_is_folder (impl->file_system, path, error))
4210- return FALSE;
4211-
4212- pos = shortcuts_get_pos_for_shortcut_folder (impl, impl->num_shortcuts);
4213-
4214- result = shortcuts_insert_path (impl, pos, FALSE, NULL, path, NULL, FALSE, error);
4215-
4216- if (result)
4217- impl->num_shortcuts++;
4218-
4219- if (impl->shortcuts_filter_model)
4220- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model));
4221-
4222- return result;
4223-}
4224-
4225-static gboolean
4226-gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
4227- const GtkFilePath *path,
4228- GError **error)
4229-{
4230- GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
4231- int pos;
4232- GtkTreeIter iter;
4233- char *uri;
4234- int i;
4235-
4236- if (impl->num_shortcuts == 0)
4237- goto out;
4238-
4239- pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
4240- if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
4241- g_assert_not_reached ();
4242-
4243- for (i = 0; i < impl->num_shortcuts; i++)
4244- {
4245- gpointer col_data;
4246- gboolean is_volume;
4247- GtkFilePath *shortcut;
4248-
4249- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
4250- SHORTCUTS_COL_DATA, &col_data,
4251- SHORTCUTS_COL_IS_VOLUME, &is_volume,
4252- -1);
4253- g_assert (col_data != NULL);
4254- g_assert (!is_volume);
4255-
4256- shortcut = col_data;
4257- if (gtk_file_path_compare (shortcut, path) == 0)
4258- {
4259- shortcuts_remove_rows (impl, pos + i, 1);
4260- impl->num_shortcuts--;
4261- return TRUE;
4262- }
4263-
4264- if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
4265- g_assert_not_reached ();
4266- }
4267-
4268- out:
4269-
4270- uri = gtk_file_system_path_to_uri (impl->file_system, path);
4271- g_set_error (error,
4272- GTK_FILE_CHOOSER_ERROR,
4273- GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
4274- _("Shortcut %s does not exist"),
4275- uri);
4276- g_free (uri);
4277-
4278- return FALSE;
4279-}
4280-
4281-static GSList *
4282-gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser)
4283-{
4284- GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
4285- int pos;
4286- GtkTreeIter iter;
4287- int i;
4288- GSList *list;
4289-
4290- if (impl->num_shortcuts == 0)
4291- return NULL;
4292-
4293- pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
4294- if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
4295- g_assert_not_reached ();
4296-
4297- list = NULL;
4298-
4299- for (i = 0; i < impl->num_shortcuts; i++)
4300- {
4301- gpointer col_data;
4302- gboolean is_volume;
4303- GtkFilePath *shortcut;
4304-
4305- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
4306- SHORTCUTS_COL_DATA, &col_data,
4307- SHORTCUTS_COL_IS_VOLUME, &is_volume,
4308- -1);
4309- g_assert (col_data != NULL);
4310- g_assert (!is_volume);
4311-
4312- shortcut = col_data;
4313- list = g_slist_prepend (list, gtk_file_path_copy (shortcut));
4314-
4315- if (i != impl->num_shortcuts - 1)
4316- {
4317- if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
4318- g_assert_not_reached ();
4319- }
4320- }
4321+static GtkFileSystem *
4322+gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser)
4323+{
4324+ GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
4325
4326- return g_slist_reverse (list);
4327+ return impl->file_system;
4328 }
4329
4330 /* Guesses a size based upon font sizes */
4331@@ -5386,7 +2667,6 @@
4332 gint default_width, default_height;
4333 int font_size;
4334 GtkRequisition req;
4335- GtkRequisition preview_req;
4336
4337 g_assert (widget->style != NULL);
4338 impl = GTK_FILE_CHOOSER_DEFAULT (widget);
4339@@ -5400,12 +2680,7 @@
4340 /* Use at least the requisition size not including the preview widget */
4341 gtk_widget_size_request (widget, &req);
4342
4343- if (impl->preview_widget_active && impl->preview_widget)
4344- gtk_widget_size_request (impl->preview_box, &preview_req);
4345- else
4346- preview_req.width = 0;
4347-
4348- default_width = MAX (default_width, (req.width - (preview_req.width + PREVIEW_HBOX_SPACING)));
4349+ default_width = MAX (default_width, (req.width - (LIST_HBOX_SPACING)));
4350 default_height = MAX (default_height, req.height);
4351
4352 *width = default_width;
4353@@ -5423,8 +2698,6 @@
4354
4355 find_good_size_from_style (GTK_WIDGET (chooser_embed), default_width, default_height);
4356
4357- if (impl->preview_widget_active && impl->preview_widget)
4358- *default_width += impl->preview_box->requisition.width + PREVIEW_HBOX_SPACING;
4359 }
4360
4361 static void
4362@@ -5441,16 +2714,6 @@
4363
4364 *resize_horizontally = TRUE;
4365 *resize_vertically = TRUE;
4366-
4367- if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
4368- impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
4369- {
4370- if (! gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)))
4371- {
4372- *resize_horizontally = FALSE;
4373- *resize_vertically = FALSE;
4374- }
4375- }
4376 }
4377
4378 struct switch_folder_closure {
4379@@ -5517,84 +2780,49 @@
4380
4381 if (current_focus == impl->browse_files_tree_view)
4382 {
4383- /* The following array encodes what we do based on the impl->action and the
4384- * number of files selected.
4385- */
4386- typedef enum {
4387- NOOP, /* Do nothing (don't respond) */
4388- RESPOND, /* Respond immediately */
4389- RESPOND_OR_SWITCH, /* Respond immediately if the selected item is a file; switch to it if it is a folder */
4390- ALL_FILES, /* Respond only if everything selected is a file */
4391- ALL_FOLDERS, /* Respond only if everything selected is a folder */
4392- SAVE_ENTRY, /* Go to the code for handling the save entry */
4393- NOT_REACHED /* Sanity check */
4394- } ActionToTake;
4395- static const ActionToTake what_to_do[4][3] = {
4396- /* 0 selected 1 selected many selected */
4397- /* ACTION_OPEN */ { NOOP, RESPOND_OR_SWITCH, ALL_FILES },
4398- /* ACTION_SAVE */ { SAVE_ENTRY, RESPOND_OR_SWITCH, NOT_REACHED },
4399- /* ACTION_SELECT_FOLDER */ { RESPOND, ALL_FOLDERS, ALL_FOLDERS },
4400- /* ACTION_CREATE_FOLDER */ { SAVE_ENTRY, ALL_FOLDERS, NOT_REACHED }
4401- };
4402-
4403 int num_selected;
4404 gboolean all_files, all_folders;
4405- int k;
4406- ActionToTake action;
4407
4408 file_list:
4409
4410- g_assert (impl->action >= GTK_FILE_CHOOSER_ACTION_OPEN && impl->action <= GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
4411-
4412 selection_check (impl, &num_selected, &all_files, &all_folders);
4413
4414- if (num_selected > 2)
4415- k = 2;
4416- else
4417- k = num_selected;
4418-
4419- action = what_to_do [impl->action] [k];
4420-
4421- switch (action)
4422+ if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
4423 {
4424- case NOOP:
4425- return FALSE;
4426-
4427- case RESPOND:
4428- return TRUE;
4429-
4430- case RESPOND_OR_SWITCH:
4431- g_assert (num_selected == 1);
4432-
4433- if (all_folders)
4434+ if (num_selected != 1)
4435+ return TRUE; /* zero means current folder; more than one means use the whole selection */
4436+ else if (current_focus != impl->browse_files_tree_view)
4437 {
4438- switch_to_selected_folder (impl);
4439- return FALSE;
4440+ /* a single folder is selected and a button was clicked */
4441+ switch_to_selected_folder (impl);
4442+ return TRUE;
4443 }
4444- else
4445- return TRUE;
4446-
4447- case ALL_FILES:
4448- return all_files;
4449-
4450- case ALL_FOLDERS:
4451- return all_folders;
4452+ }
4453
4454- case SAVE_ENTRY:
4455- goto save_entry;
4456+ if (num_selected == 0)
4457+ {
4458+ if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
4459+ || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
4460+ goto save_entry; /* it makes sense to use the typed name */
4461+ else
4462+ return FALSE;
4463+ }
4464
4465- default:
4466- g_assert_not_reached ();
4467+ if (num_selected == 1 && all_folders)
4468+ {
4469+ switch_to_selected_folder (impl);
4470+ return FALSE;
4471 }
4472+ else
4473+ return all_files;
4474 }
4475 else if (current_focus == impl->save_file_name_entry)
4476 {
4477 GtkFilePath *path;
4478- gboolean is_well_formed, is_empty, is_file_part_empty;
4479+ gboolean is_valid, is_empty;
4480 gboolean is_folder;
4481 gboolean retval;
4482- GtkFileChooserEntry *entry;
4483- GError *error;
4484+ GtkFileChooserEntry *entry;
4485
4486 save_entry:
4487
4488@@ -5602,103 +2830,39 @@
4489 || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
4490
4491 entry = GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry);
4492- check_save_entry (impl, &path, &is_well_formed, &is_empty, &is_file_part_empty);
4493+ path = check_save_entry (impl, &is_valid, &is_empty);
4494
4495- if (is_empty || !is_well_formed)
4496+ if (!is_empty && !is_valid)
4497 return FALSE;
4498
4499- g_assert (path != NULL);
4500-
4501- error = NULL;
4502- is_folder = check_is_folder (impl->file_system, path, &error);
4503+ if (is_empty)
4504+ path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
4505+
4506+ is_folder = check_is_folder (impl->file_system, path, NULL);
4507 if (is_folder)
4508 {
4509- if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
4510- {
4511- _gtk_file_chooser_entry_set_file_part (entry, "");
4512- change_folder_and_display_error (impl, path);
4513- retval = FALSE;
4514- }
4515- else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
4516- {
4517- /* The folder already exists, so we do not need to create it.
4518- * Just respond to terminate the dialog.
4519- */
4520- retval = TRUE;
4521- }
4522+ _gtk_file_chooser_entry_set_file_part (entry, "");
4523+ change_folder_and_display_error (impl, path);
4524+ retval = FALSE;
4525 }
4526 else
4527 {
4528- if (impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
4529- && g_error_matches (error, GTK_FILE_SYSTEM_ERROR, GTK_FILE_SYSTEM_ERROR_NOT_FOLDER))
4530+ /* check that everything up to the last component exists */
4531+ gtk_file_path_free (path);
4532+ path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
4533+ is_folder = check_is_folder (impl->file_system, path, NULL);
4534+ if (!is_folder)
4535 {
4536- /* Oops, the user typed the name of an existing path which is not a folder */
4537- error_creating_folder_over_existing_file_dialog (impl, path, error);
4538- error = NULL; /* as it will be freed below for the general case */
4539+ change_folder_and_display_error (impl, path);
4540 retval = FALSE;
4541 }
4542 else
4543- {
4544- GtkFilePath *parent_path;
4545-
4546- /* check that everything up to the last component exists */
4547-
4548- parent_path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
4549- is_folder = check_is_folder (impl->file_system, parent_path, NULL);
4550- if (is_folder)
4551- {
4552- if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
4553- retval = TRUE;
4554- else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
4555- {
4556- GError *create_error;
4557-
4558- create_error = NULL;
4559- if (gtk_file_system_create_folder (impl->file_system, path, &create_error))
4560- retval = TRUE;
4561- else
4562- {
4563- error_creating_folder_dialog (impl, path, create_error);
4564- retval = FALSE;
4565- }
4566- }
4567- }
4568- else
4569- {
4570- /* This will display an error, which is what we want */
4571- change_folder_and_display_error (impl, parent_path);
4572- retval = FALSE;
4573- }
4574-
4575- gtk_file_path_free (parent_path);
4576- }
4577-
4578- if (error != NULL)
4579- g_error_free (error);
4580+ retval = TRUE;
4581 }
4582
4583 gtk_file_path_free (path);
4584 return retval;
4585 }
4586- else if (impl->toplevel_last_focus_widget == impl->browse_shortcuts_tree_view)
4587- {
4588- /* The focus is on a dialog's action area button, *and* the widget that
4589- * was focused immediately before it is the shortcuts list. Switch to the
4590- * selected shortcut and tell the caller not to respond.
4591- */
4592- GtkTreeIter iter;
4593-
4594- if (shortcuts_get_selected (impl, &iter))
4595- {
4596- shortcuts_activate_iter (impl, &iter);
4597-
4598- gtk_widget_grab_focus (impl->browse_files_tree_view);
4599- }
4600- else
4601- goto file_list;
4602-
4603- return FALSE;
4604- }
4605 else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
4606 {
4607 /* The focus is on a dialog's action area button, *and* the widget that
4608@@ -5742,242 +2906,6 @@
4609 gtk_widget_grab_focus (widget);
4610 }
4611
4612-static void
4613-set_current_filter (GtkFileChooserDefault *impl,
4614- GtkFileFilter *filter)
4615-{
4616- if (impl->current_filter != filter)
4617- {
4618- int filter_index;
4619-
4620- /* NULL filters are allowed to reset to non-filtered status
4621- */
4622- filter_index = g_slist_index (impl->filters, filter);
4623- if (impl->filters && filter && filter_index < 0)
4624- return;
4625-
4626- if (impl->current_filter)
4627- g_object_unref (impl->current_filter);
4628- impl->current_filter = filter;
4629- if (impl->current_filter)
4630- {
4631- g_object_ref (impl->current_filter);
4632- gtk_object_sink (GTK_OBJECT (filter));
4633- }
4634-
4635- if (impl->filters)
4636- gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
4637- filter_index);
4638-
4639- if (impl->browse_files_model)
4640- install_list_model_filter (impl);
4641-
4642- g_object_notify (G_OBJECT (impl), "filter");
4643- }
4644-}
4645-
4646-static void
4647-filter_combo_changed (GtkComboBox *combo_box,
4648- GtkFileChooserDefault *impl)
4649-{
4650- gint new_index = gtk_combo_box_get_active (combo_box);
4651- GtkFileFilter *new_filter = g_slist_nth_data (impl->filters, new_index);
4652-
4653- set_current_filter (impl, new_filter);
4654-}
4655-
4656-static void
4657-check_preview_change (GtkFileChooserDefault *impl)
4658-{
4659- GtkTreePath *cursor_path;
4660- const GtkFilePath *new_path;
4661- const GtkFileInfo *new_info;
4662-
4663- gtk_tree_view_get_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), &cursor_path, NULL);
4664- if (cursor_path && impl->sort_model)
4665- {
4666- GtkTreeIter iter;
4667- GtkTreeIter child_iter;
4668-
4669- gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, cursor_path);
4670- gtk_tree_path_free (cursor_path);
4671-
4672- gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
4673-
4674- new_path = _gtk_file_system_model_get_path (impl->browse_files_model, &child_iter);
4675- new_info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
4676- }
4677- else
4678- {
4679- new_path = NULL;
4680- new_info = NULL;
4681- }
4682-
4683- if (new_path != impl->preview_path &&
4684- !(new_path && impl->preview_path &&
4685- gtk_file_path_compare (new_path, impl->preview_path) == 0))
4686- {
4687- if (impl->preview_path)
4688- {
4689- gtk_file_path_free (impl->preview_path);
4690- g_free (impl->preview_display_name);
4691- }
4692-
4693- if (new_path)
4694- {
4695- impl->preview_path = gtk_file_path_copy (new_path);
4696- impl->preview_display_name = g_strdup (gtk_file_info_get_display_name (new_info));
4697- }
4698- else
4699- {
4700- impl->preview_path = NULL;
4701- impl->preview_display_name = NULL;
4702- }
4703-
4704- if (impl->use_preview_label && impl->preview_label)
4705- gtk_label_set_text (GTK_LABEL (impl->preview_label), impl->preview_display_name);
4706-
4707- g_signal_emit_by_name (impl, "update-preview");
4708- }
4709-}
4710-
4711-/* Activates a volume by mounting it if necessary and then switching to its
4712- * base path.
4713- */
4714-static void
4715-shortcuts_activate_volume (GtkFileChooserDefault *impl,
4716- GtkFileSystemVolume *volume)
4717-{
4718- GtkFilePath *path;
4719-
4720- /* We ref the file chooser since volume_mount() may run a main loop, and the
4721- * user could close the file chooser window in the meantime.
4722- */
4723- g_object_ref (impl);
4724-
4725- if (!gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
4726- {
4727- GError *error;
4728- gboolean result;
4729-
4730- set_busy_cursor (impl, TRUE);
4731-
4732- error = NULL;
4733- result = gtk_file_system_volume_mount (impl->file_system, volume, &error);
4734-
4735- if (!result)
4736- {
4737- char *msg;
4738-
4739- msg = g_strdup_printf (_("Could not mount %s"),
4740- gtk_file_system_volume_get_display_name (impl->file_system, volume));
4741- error_message (impl, msg, error->message);
4742- g_free (msg);
4743- g_error_free (error);
4744- }
4745-
4746- set_busy_cursor (impl, FALSE);
4747-
4748- if (!result)
4749- goto out;
4750- }
4751-
4752- path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
4753- change_folder_and_display_error (impl, path);
4754- gtk_file_path_free (path);
4755-
4756- out:
4757-
4758- g_object_unref (impl);
4759-}
4760-
4761-/* Opens the folder or volume at the specified iter in the shortcuts model */
4762-static void
4763-shortcuts_activate_iter (GtkFileChooserDefault *impl,
4764- GtkTreeIter *iter)
4765-{
4766- gpointer col_data;
4767- gboolean is_volume;
4768-
4769- gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
4770- SHORTCUTS_COL_DATA, &col_data,
4771- SHORTCUTS_COL_IS_VOLUME, &is_volume,
4772- -1);
4773-
4774- if (!col_data)
4775- return; /* We are on a separator */
4776-
4777- if (is_volume)
4778- {
4779- GtkFileSystemVolume *volume;
4780-
4781- volume = col_data;
4782-
4783- shortcuts_activate_volume (impl, volume);
4784- }
4785- else
4786- {
4787- const GtkFilePath *file_path;
4788-
4789- file_path = col_data;
4790- change_folder_and_display_error (impl, file_path);
4791- }
4792-}
4793-
4794-/* Callback used when a row in the shortcuts list is activated */
4795-static void
4796-shortcuts_row_activated_cb (GtkTreeView *tree_view,
4797- GtkTreePath *path,
4798- GtkTreeViewColumn *column,
4799- GtkFileChooserDefault *impl)
4800-{
4801- GtkTreeIter iter;
4802- GtkTreeIter child_iter;
4803-
4804- if (!gtk_tree_model_get_iter (impl->shortcuts_filter_model, &iter, path))
4805- return;
4806-
4807- gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model),
4808- &child_iter,
4809- &iter);
4810- shortcuts_activate_iter (impl, &child_iter);
4811-
4812- gtk_widget_grab_focus (impl->browse_files_tree_view);
4813-}
4814-
4815-/* Handler for GtkWidget::key-press-event on the shortcuts list */
4816-static gboolean
4817-shortcuts_key_press_event_cb (GtkWidget *widget,
4818- GdkEventKey *event,
4819- GtkFileChooserDefault *impl)
4820-{
4821- guint modifiers;
4822-
4823- modifiers = gtk_accelerator_get_default_mod_mask ();
4824-
4825- if ((event->keyval == GDK_BackSpace
4826- || event->keyval == GDK_Delete
4827- || event->keyval == GDK_KP_Delete)
4828- && (event->state & modifiers) == 0)
4829- {
4830- remove_selected_bookmarks (impl);
4831- return TRUE;
4832- }
4833-
4834- return FALSE;
4835-}
4836-
4837-static gboolean
4838-shortcuts_select_func (GtkTreeSelection *selection,
4839- GtkTreeModel *model,
4840- GtkTreePath *path,
4841- gboolean path_currently_selected,
4842- gpointer data)
4843-{
4844- GtkFileChooserDefault *impl = data;
4845-
4846- return (*gtk_tree_path_get_indices (path) != shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR));
4847-}
4848
4849 static gboolean
4850 list_select_func (GtkTreeSelection *selection,
4851@@ -6022,7 +2950,7 @@
4852 g_assert (!impl->select_multiple);
4853 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
4854 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
4855- goto out; /* normal processing */
4856+ return;
4857
4858 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
4859 &child_iter,
4860@@ -6033,11 +2961,7 @@
4861 return; /* We are on the editable row for New Folder */
4862 }
4863
4864- out:
4865-
4866 update_chooser_entry (impl);
4867- check_preview_change (impl);
4868- bookmarks_check_add_sensitivity (impl);
4869
4870 g_signal_emit_by_name (impl, "selection-changed", 0);
4871 }
4872@@ -6074,23 +2998,6 @@
4873 g_signal_emit_by_name (impl, "file-activated");
4874 }
4875
4876-static void
4877-path_bar_clicked (GtkPathBar *path_bar,
4878- GtkFilePath *file_path,
4879- gboolean child_is_hidden,
4880- GtkFileChooserDefault *impl)
4881-{
4882- if (!change_folder_and_display_error (impl, file_path))
4883- return;
4884-
4885- /* Say we have "/foo/bar/[.baz]" and the user clicks on "bar". We should then
4886- * show hidden files so that ".baz" appears in the file list, as it will still
4887- * be shown in the path bar: "/foo/[bar]/.baz"
4888- */
4889- if (child_is_hidden)
4890- g_object_set (impl, "show-hidden", TRUE, NULL);
4891-}
4892-
4893 static const GtkFileInfo *
4894 get_list_file_info (GtkFileChooserDefault *impl,
4895 GtkTreeIter *iter)
4896@@ -6257,33 +3164,31 @@
4897
4898 time_mtime = gtk_file_info_get_modification_time (info);
4899
4900- if (time_mtime == 0)
4901- strcpy (buf, _("Unknown"));
4902- else
4903- {
4904- g_date_set_time (&mtime, (GTime) time_mtime);
4905+#ifdef GTK26
4906+ g_date_set_time (&mtime, (GTime) time_mtime);
4907+#else
4908+ g_date_set_time_t (&mtime, time_mtime);
4909+#endif
4910+ time_now = (GTime ) time (NULL);
4911+ g_date_set_time (&now, (GTime) time_now);
4912
4913- time_now = (GTime ) time (NULL);
4914- g_date_set_time (&now, (GTime) time_now);
4915+ days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
4916
4917- days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
4918+ if (days_diff == 0)
4919+ strcpy (buf, _("Today"));
4920+ else if (days_diff == 1)
4921+ strcpy (buf, _("Yesterday"));
4922+ else
4923+ {
4924+ char *format;
4925
4926- if (days_diff == 0)
4927- strcpy (buf, _("Today"));
4928- else if (days_diff == 1)
4929- strcpy (buf, _("Yesterday"));
4930+ if (days_diff > 1 && days_diff < 7)
4931+ format = "%A"; /* Days from last week */
4932 else
4933- {
4934- char *format;
4935-
4936- if (days_diff > 1 && days_diff < 7)
4937- format = "%A"; /* Days from last week */
4938- else
4939- format = "%x"; /* Any other date */
4940+ format = "%x"; /* Any other date */
4941
4942- if (g_date_strftime (buf, sizeof (buf), format, &mtime) == 0)
4943- strcpy (buf, _("Unknown"));
4944- }
4945+ if (g_date_strftime (buf, sizeof (buf), format, &mtime) == 0)
4946+ strcpy (buf, _("Unknown"));
4947 }
4948
4949 if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
4950@@ -6376,8 +3281,11 @@
4951 */
4952
4953 error = NULL;
4954+#ifdef GTK26
4955 folder = gtk_file_system_get_folder (impl->file_system, folder_path, GTK_FILE_INFO_IS_FOLDER, &error);
4956-
4957+#else
4958+ folder = gtk_file_system_get_folder (impl->file_system, folder_path, GTK_FILE_INFO_IS_FOLDER, NULL, NULL);
4959+#endif
4960 if (!folder)
4961 {
4962 error_getting_info_dialog (impl, folder_path, error);
4963@@ -6487,8 +3395,8 @@
4964 accept_stock, GTK_RESPONSE_ACCEPT,
4965 NULL);
4966 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, -1);
4967- gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
4968- gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
4969+ gtk_container_set_border_width (GTK_CONTAINER (dialog), DEFAULT_SPACING);
4970+ gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), DEFAULT_SPACING);
4971 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
4972
4973 gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
4974@@ -6496,17 +3404,16 @@
4975 GTK_RESPONSE_CANCEL,
4976 -1);
4977
4978- hbox = gtk_hbox_new (FALSE, 12);
4979+ hbox = gtk_hbox_new (FALSE, DEFAULT_SPACING);
4980 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
4981 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
4982
4983- label = gtk_label_new_with_mnemonic (_("_Location:"));
4984+ label = gtk_label_new (_("Location:"));
4985 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4986
4987 entry = location_entry_create (impl, path);
4988
4989 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
4990- gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
4991
4992 /* Run */
4993
4994@@ -6555,115 +3462,86 @@
4995 static void
4996 up_folder_handler (GtkFileChooserDefault *impl)
4997 {
4998+ GtkFilePath * parent;
4999 pending_select_paths_add (impl, impl->current_folder);
5000- _gtk_path_bar_up (GTK_PATH_BAR (impl->browse_path_bar));
5001+
5002+ if (gtk_file_system_get_parent (impl->file_system, impl->current_folder,
5003+ &parent, NULL) && parent)
5004+ {
5005+ impl->path_history = g_slist_prepend (impl->path_history,
5006+ gtk_file_path_copy (impl->current_folder));
5007+
5008+ change_folder_and_display_error (impl, parent);
5009+ gtk_file_path_free (parent);
5010+ }
5011 }
5012
5013 /* Handler for the "down-folder" keybinding signal */
5014 static void
5015 down_folder_handler (GtkFileChooserDefault *impl)
5016 {
5017- _gtk_path_bar_down (GTK_PATH_BAR (impl->browse_path_bar));
5018+ if (impl->path_history)
5019+ {
5020+ const GtkFilePath * path = impl->path_history->data;
5021+
5022+ change_folder_and_display_error (impl, path);
5023+ impl->path_history = g_slist_remove (impl->path_history, path);
5024+ gtk_file_path_free (path);
5025+ }
5026 }
5027
5028 /* Handler for the "home-folder" keybinding signal */
5029 static void
5030 home_folder_handler (GtkFileChooserDefault *impl)
5031 {
5032- int pos;
5033- GtkTreeIter iter;
5034-
5035- if (!impl->has_home)
5036- return; /* Should we put up an error dialog? */
5037-
5038- pos = shortcuts_get_index (impl, SHORTCUTS_HOME);
5039- if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
5040- g_assert_not_reached ();
5041-
5042- shortcuts_activate_iter (impl, &iter);
5043 }
5044
5045-
5046-
5047-/* Drag and drop interfaces */
5048+static GtkFilePath *
5049+gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser)
5050+{
5051+ return NULL;
5052+}
5053
5054 static void
5055-_shortcuts_model_filter_class_init (ShortcutsModelFilterClass *class)
5056+gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
5057+ GtkFileFilter *filter)
5058 {
5059 }
5060
5061 static void
5062-_shortcuts_model_filter_init (ShortcutsModelFilter *model)
5063+gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
5064+ GtkFileFilter *filter)
5065 {
5066- model->impl = NULL;
5067 }
5068
5069-/* GtkTreeDragSource::row_draggable implementation for the shortcuts filter model */
5070-static gboolean
5071-shortcuts_model_filter_row_draggable (GtkTreeDragSource *drag_source,
5072- GtkTreePath *path)
5073+static GSList *
5074+gtk_file_chooser_default_list_filters (GtkFileChooser *chooser)
5075 {
5076- ShortcutsModelFilter *model;
5077- int pos;
5078- int bookmarks_pos;
5079-
5080- model = SHORTCUTS_MODEL_FILTER (drag_source);
5081-
5082- pos = *gtk_tree_path_get_indices (path);
5083- bookmarks_pos = shortcuts_get_index (model->impl, SHORTCUTS_BOOKMARKS);
5084-
5085- return (pos >= bookmarks_pos && pos < bookmarks_pos + model->impl->num_bookmarks);
5086+ return NULL;
5087 }
5088
5089-/* GtkTreeDragSource::drag_data_get implementation for the shortcuts filter model */
5090 static gboolean
5091-shortcuts_model_filter_drag_data_get (GtkTreeDragSource *drag_source,
5092- GtkTreePath *path,
5093- GtkSelectionData *selection_data)
5094+gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
5095+ const GtkFilePath *path,
5096+ GError **error)
5097 {
5098- ShortcutsModelFilter *model;
5099-
5100- model = SHORTCUTS_MODEL_FILTER (drag_source);
5101-
5102- /* FIXME */
5103-
5104- return FALSE;
5105+ return FALSE;
5106 }
5107
5108-/* Fill the GtkTreeDragSourceIface vtable */
5109-static void
5110-shortcuts_model_filter_drag_source_iface_init (GtkTreeDragSourceIface *iface)
5111+static gboolean
5112+gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
5113+ const GtkFilePath *path,
5114+ GError **error)
5115 {
5116- iface->row_draggable = shortcuts_model_filter_row_draggable;
5117- iface->drag_data_get = shortcuts_model_filter_drag_data_get;
5118+ return TRUE;
5119 }
5120
5121-#if 0
5122-/* Fill the GtkTreeDragDestIface vtable */
5123-static void
5124-shortcuts_model_filter_drag_dest_iface_init (GtkTreeDragDestIface *iface)
5125+static GSList *
5126+gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser)
5127 {
5128- iface->drag_data_received = shortcuts_model_filter_drag_data_received;
5129- iface->row_drop_possible = shortcuts_model_filter_row_drop_possible;
5130+ return NULL;
5131 }
5132-#endif
5133
5134-static GtkTreeModel *
5135-shortcuts_model_filter_new (GtkFileChooserDefault *impl,
5136- GtkTreeModel *child_model,
5137- GtkTreePath *root)
5138-{
5139- ShortcutsModelFilter *model;
5140-
5141- model = g_object_new (SHORTCUTS_MODEL_FILTER_TYPE,
5142- "child_model", child_model,
5143- "virtual_root", root,
5144- NULL);
5145-
5146- model->impl = impl;
5147-
5148- return GTK_TREE_MODEL (model);
5149-}
5150
5151 #define __GTK_FILE_CHOOSER_DEFAULT_C__
5152 #include "gtkaliasdef.c"
diff --git a/meta/packages/gtk+/gtk+-2.6.8/filechooser-respect-style.patch b/meta/packages/gtk+/gtk+-2.6.8/filechooser-respect-style.patch
new file mode 100644
index 0000000000..76c66a7d2a
--- /dev/null
+++ b/meta/packages/gtk+/gtk+-2.6.8/filechooser-respect-style.patch
@@ -0,0 +1,77 @@
1--- gtk+-2.6.8/gtk/gtkfilechooserdialog.c.orig 2007-02-09 12:18:25.000000000 +0000
2+++ gtk+-2.6.8/gtk/gtkfilechooserdialog.c 2007-02-09 12:18:25.000000000 +0000
3@@ -62,8 +62,6 @@
4
5 static void gtk_file_chooser_dialog_map (GtkWidget *widget);
6 static void gtk_file_chooser_dialog_unmap (GtkWidget *widget);
7-static void gtk_file_chooser_dialog_style_set (GtkWidget *widget,
8- GtkStyle *previous_style);
9
10 static void response_cb (GtkDialog *dialog,
11 gint response_id);
12@@ -122,7 +120,6 @@
13
14 widget_class->map = gtk_file_chooser_dialog_map;
15 widget_class->unmap = gtk_file_chooser_dialog_unmap;
16- widget_class->style_set = gtk_file_chooser_dialog_style_set;
17
18 _gtk_file_chooser_install_properties (gobject_class);
19
20@@ -135,13 +132,19 @@
21 GtkFileChooserDialogPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
22 GTK_TYPE_FILE_CHOOSER_DIALOG,
23 GtkFileChooserDialogPrivate);
24+
25+ GtkDialog *fc_dialog = GTK_DIALOG (dialog);
26+
27 dialog->priv = priv;
28 dialog->priv->default_width = -1;
29 dialog->priv->default_height = -1;
30 dialog->priv->resize_horizontally = TRUE;
31 dialog->priv->resize_vertically = TRUE;
32
33- gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
34+ gtk_dialog_set_has_separator (fc_dialog, FALSE);
35+ gtk_container_set_border_width (GTK_CONTAINER (fc_dialog), 5);
36+ gtk_box_set_spacing (GTK_BOX (fc_dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
37+ gtk_container_set_border_width (GTK_CONTAINER (fc_dialog->action_area), 5);
38
39 /* We do a signal connection here rather than overriding the method in
40 * class_init because GtkDialog::response is a RUN_LAST signal. We want *our*
41@@ -394,6 +397,7 @@
42 g_signal_connect (priv->widget, "default-size-changed",
43 G_CALLBACK (file_chooser_widget_default_size_changed), object);
44
45+ gtk_container_set_border_width (GTK_CONTAINER (priv->widget), 5);
46 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (object)->vbox), priv->widget, TRUE, TRUE, 0);
47
48 gtk_widget_show (priv->widget);
49@@ -522,28 +526,6 @@
50 gtk_widget_unmap (priv->widget);
51 }
52
53-static void
54-gtk_file_chooser_dialog_style_set (GtkWidget *widget,
55- GtkStyle *previous_style)
56-{
57- GtkDialog *dialog;
58-
59- if (GTK_WIDGET_CLASS (parent_class)->style_set)
60- GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
61-
62- dialog = GTK_DIALOG (widget);
63-
64- /* Override the style properties with HIG-compliant spacings. Ugh.
65- * http://developer.gnome.org/projects/gup/hig/1.0/layout.html#layout-dialogs
66- * http://developer.gnome.org/projects/gup/hig/1.0/windows.html#alert-spacing
67- */
68-
69- gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), 12);
70- gtk_box_set_spacing (GTK_BOX (dialog->vbox), 24);
71-
72- gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 0);
73- gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
74-}
75
76 /* GtkDialog::response handler */
77 static void
diff --git a/meta/packages/gtk+/gtk+_2.6.8.bb b/meta/packages/gtk+/gtk+_2.6.8.bb
index 50990f14b9..9fa6700a55 100644
--- a/meta/packages/gtk+/gtk+_2.6.8.bb
+++ b/meta/packages/gtk+/gtk+_2.6.8.bb
@@ -5,7 +5,7 @@ HOMEPAGE = "http://www.gtk.org"
5SECTION = "libs" 5SECTION = "libs"
6PRIORITY = "optional" 6PRIORITY = "optional"
7DEPENDS = "glib-2.0 pango atk jpeg libpng libxext libxcursor gtk-doc libgcrypt" 7DEPENDS = "glib-2.0 pango atk jpeg libpng libxext libxcursor gtk-doc libgcrypt"
8PR = "r3" 8PR = "r4"
9 9
10SRC_URI = "ftp://ftp.gtk.org/pub/gtk/v2.6/gtk+-${PV}.tar.bz2 \ 10SRC_URI = "ftp://ftp.gtk.org/pub/gtk/v2.6/gtk+-${PV}.tar.bz2 \
11 file://no-demos.patch;patch=1 \ 11 file://no-demos.patch;patch=1 \
@@ -19,7 +19,9 @@ SRC_URI = "ftp://ftp.gtk.org/pub/gtk/v2.6/gtk+-${PV}.tar.bz2 \
19 file://scroll-timings.patch;patch=1 \ 19 file://scroll-timings.patch;patch=1 \
20 file://no-deprecation.patch;patch=1 \ 20 file://no-deprecation.patch;patch=1 \
21 file://filesystem-volumes.patch;patch=1 \ 21 file://filesystem-volumes.patch;patch=1 \
22 file://smaller-filechooser.patch;patch=1" 22 file://filechooser-respect-style.patch;patch=1 \
23 file://filechooser-default.patch;patch=1 \
24 "
23 25
24inherit autotools pkgconfig 26inherit autotools pkgconfig
25 27