1 /* GTK - The GIMP Toolkit
2 * gtkrecentchooserdefault.c
3 * Copyright (C) 2005-2006, Emmanuele Bassi
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
26 #include <sys/types.h>
33 #include "gtkicontheme.h"
34 #include "gtkiconfactory.h"
35 #include "gtksettings.h"
36 #include "gtktreeview.h"
37 #include "gtkliststore.h"
38 #include "gtkbutton.h"
39 #include "gtkcelllayout.h"
40 #include "gtkcellrendererpixbuf.h"
41 #include "gtkcellrenderertext.h"
42 #include "gtkcheckmenuitem.h"
43 #include "gtkclipboard.h"
44 #include "gtkcombobox.h"
46 #include "gtkeventbox.h"
47 #include "gtkexpander.h"
50 #include "gtkhpaned.h"
52 #include "gtkimagemenuitem.h"
55 #include "gtkmenuitem.h"
56 #include "gtkmessagedialog.h"
57 #include "gtkscrolledwindow.h"
58 #include "gtkseparatormenuitem.h"
59 #include "gtksizegroup.h"
61 #include "gtktreemodelsort.h"
62 #include "gtktreemodelfilter.h"
63 #include "gtktreeselection.h"
64 #include "gtktreestore.h"
65 #include "gtktooltip.h"
66 #include "gtktypebuiltins.h"
69 #include "gtkrecentmanager.h"
70 #include "gtkrecentfilter.h"
71 #include "gtkrecentchooser.h"
72 #include "gtkrecentchooserprivate.h"
73 #include "gtkrecentchooserutils.h"
74 #include "gtkrecentchooserdefault.h"
76 #include "gtkprivate.h"
81 struct _GtkRecentChooserDefault
83 GtkVBox parent_instance;
85 GtkRecentManager *manager;
86 gulong manager_changed_id;
87 guint local_manager : 1;
91 /* RecentChooser properties */
93 GtkRecentSortType sort_type;
94 guint show_private : 1;
95 guint show_not_found : 1;
96 guint select_multiple : 1;
104 GtkRecentFilter *current_filter;
105 GtkWidget *filter_combo_hbox;
106 GtkWidget *filter_combo;
108 GtkRecentSortFunc sort_func;
110 GDestroyNotify sort_data_destroy;
112 GtkIconTheme *icon_theme;
114 GtkWidget *recent_view;
115 GtkListStore *recent_store;
116 GtkTreeViewColumn *icon_column;
117 GtkTreeViewColumn *meta_column;
118 GtkCellRenderer *meta_renderer;
119 GtkTreeSelection *selection;
121 GtkWidget *recent_popup_menu;
122 GtkWidget *recent_popup_menu_copy_item;
123 GtkWidget *recent_popup_menu_remove_item;
124 GtkWidget *recent_popup_menu_clear_item;
125 GtkWidget *recent_popup_menu_show_private_item;
134 typedef struct _GtkRecentChooserDefaultClass
136 GtkVBoxClass parent_class;
137 } GtkRecentChooserDefaultClass;
141 RECENT_DISPLAY_NAME_COLUMN,
148 LOAD_EMPTY, /* initial state: the model is empty */
149 LOAD_PRELOAD, /* the model is loading and not inserted in the tree yet */
150 LOAD_LOADING, /* the model is fully loaded but not inserted */
151 LOAD_FINISHED /* the model is fully loaded and inserted */
154 /* Icon size for if we can't get it from the theme */
155 #define FALLBACK_ICON_SIZE 48
156 #define FALLBACK_ITEM_LIMIT 20
164 static void _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass);
165 static void _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl);
166 static GObject *gtk_recent_chooser_default_constructor (GType type,
167 guint n_construct_prop,
168 GObjectConstructParam *construct_params);
169 static void gtk_recent_chooser_default_finalize (GObject *object);
170 static void gtk_recent_chooser_default_dispose (GObject *object);
171 static void gtk_recent_chooser_default_set_property (GObject *object,
175 static void gtk_recent_chooser_default_get_property (GObject *object,
180 /* GtkRecentChooserIface */
181 static void gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface);
182 static gboolean gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
185 static gchar * gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser);
186 static gboolean gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
189 static void gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
191 static void gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser);
192 static void gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser);
193 static GList * gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser);
194 static GtkRecentManager *gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser);
195 static void gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
196 GtkRecentSortFunc sort_func,
198 GDestroyNotify data_destroy);
199 static void gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
200 GtkRecentFilter *filter);
201 static void gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
202 GtkRecentFilter *filter);
203 static GSList * gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser);
206 static void gtk_recent_chooser_default_map (GtkWidget *widget);
207 static void gtk_recent_chooser_default_show_all (GtkWidget *widget);
209 static void set_current_filter (GtkRecentChooserDefault *impl,
210 GtkRecentFilter *filter);
212 static GtkIconTheme *get_icon_theme_for_widget (GtkWidget *widget);
213 static gint get_icon_size_for_widget (GtkWidget *widget,
214 GtkIconSize icon_size);
215 static gint get_recent_files_limit (GtkWidget *widget);
217 static void reload_recent_items (GtkRecentChooserDefault *impl);
218 static void chooser_set_model (GtkRecentChooserDefault *impl);
220 static void set_recent_manager (GtkRecentChooserDefault *impl,
221 GtkRecentManager *manager);
223 static void chooser_set_sort_type (GtkRecentChooserDefault *impl,
224 GtkRecentSortType sort_type);
226 static void recent_manager_changed_cb (GtkRecentManager *manager,
228 static void recent_icon_data_func (GtkTreeViewColumn *tree_column,
229 GtkCellRenderer *cell,
233 static void recent_meta_data_func (GtkTreeViewColumn *tree_column,
234 GtkCellRenderer *cell,
239 static void selection_changed_cb (GtkTreeSelection *z,
241 static void row_activated_cb (GtkTreeView *tree_view,
242 GtkTreePath *tree_path,
243 GtkTreeViewColumn *tree_column,
245 static void filter_combo_changed_cb (GtkComboBox *combo_box,
248 static void remove_all_activated_cb (GtkMenuItem *menu_item,
250 static void remove_item_activated_cb (GtkMenuItem *menu_item,
252 static void show_private_toggled_cb (GtkCheckMenuItem *menu_item,
255 static gboolean recent_view_popup_menu_cb (GtkWidget *widget,
257 static gboolean recent_view_button_press_cb (GtkWidget *widget,
258 GdkEventButton *event,
261 static void recent_view_drag_begin_cb (GtkWidget *widget,
262 GdkDragContext *context,
264 static void recent_view_drag_data_get_cb (GtkWidget *widget,
265 GdkDragContext *context,
266 GtkSelectionData *selection_data,
270 static gboolean recent_view_query_tooltip_cb (GtkWidget *widget,
273 gboolean keyboard_tip,
279 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDefault,
280 _gtk_recent_chooser_default,
282 G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
283 gtk_recent_chooser_iface_init))
289 gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
291 iface->set_current_uri = gtk_recent_chooser_default_set_current_uri;
292 iface->get_current_uri = gtk_recent_chooser_default_get_current_uri;
293 iface->select_uri = gtk_recent_chooser_default_select_uri;
294 iface->unselect_uri = gtk_recent_chooser_default_unselect_uri;
295 iface->select_all = gtk_recent_chooser_default_select_all;
296 iface->unselect_all = gtk_recent_chooser_default_unselect_all;
297 iface->get_items = gtk_recent_chooser_default_get_items;
298 iface->get_recent_manager = gtk_recent_chooser_default_get_recent_manager;
299 iface->set_sort_func = gtk_recent_chooser_default_set_sort_func;
300 iface->add_filter = gtk_recent_chooser_default_add_filter;
301 iface->remove_filter = gtk_recent_chooser_default_remove_filter;
302 iface->list_filters = gtk_recent_chooser_default_list_filters;
306 _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
308 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
309 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
311 gobject_class->constructor = gtk_recent_chooser_default_constructor;
312 gobject_class->set_property = gtk_recent_chooser_default_set_property;
313 gobject_class->get_property = gtk_recent_chooser_default_get_property;
314 gobject_class->dispose = gtk_recent_chooser_default_dispose;
315 gobject_class->finalize = gtk_recent_chooser_default_finalize;
317 widget_class->map = gtk_recent_chooser_default_map;
318 widget_class->show_all = gtk_recent_chooser_default_show_all;
320 _gtk_recent_chooser_install_properties (gobject_class);
324 _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
326 gtk_box_set_spacing (GTK_BOX (impl), 6);
328 /* by default, we use the global manager */
329 impl->local_manager = FALSE;
331 impl->limit = FALLBACK_ITEM_LIMIT;
332 impl->sort_type = GTK_RECENT_SORT_NONE;
334 impl->show_icons = TRUE;
335 impl->show_private = FALSE;
336 impl->show_not_found = TRUE;
337 impl->show_tips = FALSE;
338 impl->select_multiple = FALSE;
339 impl->local_only = TRUE;
341 impl->icon_size = FALLBACK_ICON_SIZE;
342 impl->icon_theme = NULL;
344 impl->current_filter = NULL;
346 impl->recent_items = NULL;
347 impl->n_recent_items = 0;
348 impl->loaded_items = 0;
350 impl->load_state = LOAD_EMPTY;
354 gtk_recent_chooser_default_constructor (GType type,
356 GObjectConstructParam *params)
358 GObjectClass *parent_class;
359 GtkRecentChooserDefault *impl;
362 GtkCellRenderer *renderer;
364 parent_class = G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class);
365 object = parent_class->constructor (type, n_params, params);
366 impl = GTK_RECENT_CHOOSER_DEFAULT (object);
368 g_assert (impl->manager);
370 gtk_widget_push_composite_child ();
372 impl->limit = get_recent_files_limit (GTK_WIDGET (impl));
374 scrollw = gtk_scrolled_window_new (NULL, NULL);
375 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollw),
377 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollw),
378 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
379 gtk_box_pack_start (GTK_BOX (impl), scrollw, TRUE, TRUE, 0);
380 gtk_widget_show (scrollw);
382 impl->recent_view = gtk_tree_view_new ();
383 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->recent_view), FALSE);
384 g_signal_connect (impl->recent_view, "row-activated",
385 G_CALLBACK (row_activated_cb), impl);
386 g_signal_connect (impl->recent_view, "popup-menu",
387 G_CALLBACK (recent_view_popup_menu_cb), impl);
388 g_signal_connect (impl->recent_view, "button-press-event",
389 G_CALLBACK (recent_view_button_press_cb), impl);
390 g_signal_connect (impl->recent_view, "drag-begin",
391 G_CALLBACK (recent_view_drag_begin_cb), impl);
392 g_signal_connect (impl->recent_view, "drag-data-get",
393 G_CALLBACK (recent_view_drag_data_get_cb), impl);
395 g_object_set (impl->recent_view, "has-tooltip", TRUE, NULL);
396 g_signal_connect (impl->recent_view, "query-tooltip",
397 G_CALLBACK (recent_view_query_tooltip_cb), impl);
399 g_object_set_data (G_OBJECT (impl->recent_view),
400 "GtkRecentChooserDefault", impl);
402 gtk_container_add (GTK_CONTAINER (scrollw), impl->recent_view);
403 gtk_widget_show (impl->recent_view);
405 impl->icon_column = gtk_tree_view_column_new ();
406 gtk_tree_view_column_set_expand (impl->icon_column, FALSE);
407 gtk_tree_view_column_set_resizable (impl->icon_column, FALSE);
409 renderer = gtk_cell_renderer_pixbuf_new ();
410 gtk_tree_view_column_pack_start (impl->icon_column, renderer, FALSE);
411 gtk_tree_view_column_set_cell_data_func (impl->icon_column,
413 recent_icon_data_func,
416 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->recent_view),
419 impl->meta_column = gtk_tree_view_column_new ();
420 gtk_tree_view_column_set_expand (impl->meta_column, TRUE);
421 gtk_tree_view_column_set_resizable (impl->meta_column, FALSE);
423 impl->meta_renderer = gtk_cell_renderer_text_new ();
424 g_object_set (G_OBJECT (impl->meta_renderer),
425 "ellipsize", PANGO_ELLIPSIZE_END,
427 gtk_tree_view_column_pack_start (impl->meta_column, impl->meta_renderer, TRUE);
428 gtk_tree_view_column_set_cell_data_func (impl->meta_column,
430 recent_meta_data_func,
433 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->recent_view),
436 impl->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->recent_view));
437 gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_SINGLE);
438 g_signal_connect (impl->selection, "changed", G_CALLBACK (selection_changed_cb), impl);
441 gtk_drag_source_set (impl->recent_view,
445 gtk_drag_source_add_uri_targets (impl->recent_view);
447 impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
449 impl->filter_combo = gtk_combo_box_new_text ();
450 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
451 g_signal_connect (impl->filter_combo, "changed",
452 G_CALLBACK (filter_combo_changed_cb), impl);
453 gtk_widget_set_tooltip_text (impl->filter_combo,
454 _("Select which type of documents are shown"));
456 gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox),
459 gtk_widget_show (impl->filter_combo);
461 gtk_box_pack_end (GTK_BOX (impl), impl->filter_combo_hbox, FALSE, FALSE, 0);
463 gtk_widget_pop_composite_child ();
465 impl->recent_store = gtk_list_store_new (N_RECENT_COLUMNS,
466 G_TYPE_STRING, /* uri */
467 G_TYPE_STRING, /* display_name */
468 GTK_TYPE_RECENT_INFO /* info */);
474 gtk_recent_chooser_default_set_property (GObject *object,
479 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
483 case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
484 set_recent_manager (impl, g_value_get_object (value));
486 case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
487 impl->show_private = g_value_get_boolean (value);
488 if (impl->recent_popup_menu_show_private_item)
490 GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (impl->recent_popup_menu_show_private_item);
491 g_signal_handlers_block_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
492 gtk_check_menu_item_set_active (item, impl->show_private);
493 g_signal_handlers_unblock_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
495 reload_recent_items (impl);
497 case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
498 impl->show_not_found = g_value_get_boolean (value);
499 reload_recent_items (impl);
501 case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
502 impl->show_tips = g_value_get_boolean (value);
504 case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
505 impl->show_icons = g_value_get_boolean (value);
506 gtk_tree_view_column_set_visible (impl->icon_column, impl->show_icons);
508 case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
509 impl->select_multiple = g_value_get_boolean (value);
511 if (impl->select_multiple)
512 gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_MULTIPLE);
514 gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_SINGLE);
516 case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
517 impl->local_only = g_value_get_boolean (value);
518 reload_recent_items (impl);
520 case GTK_RECENT_CHOOSER_PROP_LIMIT:
521 impl->limit = g_value_get_int (value);
522 impl->limit_set = TRUE;
523 reload_recent_items (impl);
525 case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
526 chooser_set_sort_type (impl, g_value_get_enum (value));
528 case GTK_RECENT_CHOOSER_PROP_FILTER:
529 set_current_filter (impl, g_value_get_object (value));
532 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
538 gtk_recent_chooser_default_get_property (GObject *object,
543 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
547 case GTK_RECENT_CHOOSER_PROP_LIMIT:
548 g_value_set_int (value, impl->limit);
550 case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
551 g_value_set_enum (value, impl->sort_type);
553 case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
554 g_value_set_boolean (value, impl->show_private);
556 case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
557 g_value_set_boolean (value, impl->show_icons);
559 case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
560 g_value_set_boolean (value, impl->show_not_found);
562 case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
563 g_value_set_boolean (value, impl->show_tips);
565 case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
566 g_value_set_boolean (value, impl->local_only);
568 case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
569 g_value_set_boolean (value, impl->select_multiple);
571 case GTK_RECENT_CHOOSER_PROP_FILTER:
572 g_value_set_object (value, impl->current_filter);
575 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
581 gtk_recent_chooser_default_dispose (GObject *object)
583 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
587 g_source_remove (impl->load_id);
588 impl->load_state = LOAD_EMPTY;
592 if (impl->recent_items)
594 g_list_foreach (impl->recent_items, (GFunc) gtk_recent_info_unref, NULL);
595 g_list_free (impl->recent_items);
596 impl->recent_items = NULL;
599 if (impl->manager && impl->manager_changed_id)
601 g_signal_handler_disconnect (impl->manager, impl->manager_changed_id);
602 impl->manager_changed_id = 0;
607 g_slist_foreach (impl->filters, (GFunc) g_object_unref, NULL);
608 g_slist_free (impl->filters);
609 impl->filters = NULL;
612 if (impl->current_filter)
614 g_object_unref (impl->current_filter);
615 impl->current_filter = NULL;
618 if (impl->recent_store)
620 g_object_unref (impl->recent_store);
621 impl->recent_store = NULL;
624 G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->dispose (object);
628 gtk_recent_chooser_default_finalize (GObject *object)
630 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
632 impl->manager = NULL;
634 if (impl->sort_data_destroy)
636 impl->sort_data_destroy (impl->sort_data);
637 impl->sort_data_destroy = NULL;
640 impl->sort_data = NULL;
641 impl->sort_func = NULL;
643 G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->finalize (object);
646 /* override GtkWidget::show_all since we have internal widgets we wish to keep
647 * hidden unless we decide otherwise, like the filter combo box.
650 gtk_recent_chooser_default_show_all (GtkWidget *widget)
652 gtk_widget_show (widget);
657 /* Shows an error dialog set as transient for the specified window */
659 error_message_with_parent (GtkWindow *parent,
665 dialog = gtk_message_dialog_new (parent,
666 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
671 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
675 gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
677 gtk_dialog_run (GTK_DIALOG (dialog));
678 gtk_widget_destroy (dialog);
681 /* Returns a toplevel GtkWindow, or NULL if none */
683 get_toplevel (GtkWidget *widget)
687 toplevel = gtk_widget_get_toplevel (widget);
688 if (!GTK_WIDGET_TOPLEVEL (toplevel))
691 return GTK_WINDOW (toplevel);
694 /* Shows an error dialog for the file chooser */
696 error_message (GtkRecentChooserDefault *impl,
700 error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
704 set_busy_cursor (GtkRecentChooserDefault *impl,
705 gboolean show_busy_cursor)
711 toplevel = get_toplevel (GTK_WIDGET (impl));
712 if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
715 display = gtk_widget_get_display (GTK_WIDGET (toplevel));
718 if (show_busy_cursor)
719 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
721 gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
722 gdk_display_flush (display);
725 gdk_cursor_unref (cursor);
729 chooser_set_model (GtkRecentChooserDefault *impl)
731 g_assert (impl->recent_store != NULL);
732 g_assert (impl->load_state == LOAD_LOADING);
734 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->recent_view),
735 GTK_TREE_MODEL (impl->recent_store));
736 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->recent_view));
737 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->recent_view), TRUE);
738 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->recent_view),
739 RECENT_DISPLAY_NAME_COLUMN);
741 impl->load_state = LOAD_FINISHED;
745 load_recent_items (gpointer user_data)
747 GtkRecentChooserDefault *impl;
750 const gchar *uri, *name;
753 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
755 g_assert ((impl->load_state == LOAD_EMPTY) ||
756 (impl->load_state == LOAD_PRELOAD));
758 /* store the items for multiple runs */
759 if (!impl->recent_items)
761 impl->recent_items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (impl));
762 if (!impl->recent_items)
764 impl->load_state = LOAD_FINISHED;
769 impl->n_recent_items = g_list_length (impl->recent_items);
770 impl->loaded_items = 0;
771 impl->load_state = LOAD_PRELOAD;
774 info = (GtkRecentInfo *) g_list_nth_data (impl->recent_items,
778 uri = gtk_recent_info_get_uri (info);
779 name = gtk_recent_info_get_display_name (info);
781 /* at this point, everything goes inside the model; operations on the
782 * visualization of items inside the model are done in the cell data
783 * funcs (remember that there are two of those: one for the icon and
784 * one for the text), while the filtering is done only when a filter
785 * is actually loaded. */
786 gtk_list_store_append (impl->recent_store, &iter);
787 gtk_list_store_set (impl->recent_store, &iter,
788 RECENT_URI_COLUMN, uri, /* uri */
789 RECENT_DISPLAY_NAME_COLUMN, name, /* display_name */
790 RECENT_INFO_COLUMN, info, /* info */
793 impl->loaded_items += 1;
795 if (impl->loaded_items == impl->n_recent_items)
797 /* we have finished loading, so we remove the items cache */
798 impl->load_state = LOAD_LOADING;
800 g_list_foreach (impl->recent_items,
801 (GFunc) gtk_recent_info_unref,
803 g_list_free (impl->recent_items);
805 impl->recent_items = NULL;
806 impl->n_recent_items = 0;
807 impl->loaded_items = 0;
809 /* load the filled up model */
810 chooser_set_model (impl);
816 /* we did not finish, so continue loading */
824 cleanup_after_load (gpointer user_data)
826 GtkRecentChooserDefault *impl;
828 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
830 if (impl->load_id != 0)
832 g_assert ((impl->load_state == LOAD_EMPTY) ||
833 (impl->load_state == LOAD_PRELOAD) ||
834 (impl->load_state == LOAD_LOADING) ||
835 (impl->load_state == LOAD_FINISHED));
837 /* we have officialy finished loading all the items,
838 * so we can reset the state machine
840 g_source_remove (impl->load_id);
842 impl->load_state = LOAD_EMPTY;
845 g_assert ((impl->load_state == LOAD_EMPTY) ||
846 (impl->load_state == LOAD_LOADING) ||
847 (impl->load_state == LOAD_FINISHED));
849 set_busy_cursor (impl, FALSE);
852 /* clears the current model and reloads the recently used resources */
854 reload_recent_items (GtkRecentChooserDefault *impl)
858 /* reload is already in progress - do not disturb */
862 widget = GTK_WIDGET (impl);
864 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->recent_view), NULL);
865 gtk_list_store_clear (impl->recent_store);
867 if (!impl->icon_theme)
868 impl->icon_theme = get_icon_theme_for_widget (widget);
870 impl->icon_size = get_icon_size_for_widget (widget,
871 GTK_ICON_SIZE_BUTTON);
873 if (!impl->limit_set)
874 impl->limit = get_recent_files_limit (widget);
876 set_busy_cursor (impl, TRUE);
878 impl->load_state = LOAD_EMPTY;
879 impl->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
885 /* taken form gtkfilechooserdialog.c */
887 set_default_size (GtkRecentChooserDefault *impl)
895 GdkRectangle monitor;
897 widget = GTK_WIDGET (impl);
899 /* Size based on characters and the icon size */
900 font_size = pango_font_description_get_size (widget->style->font_desc);
901 font_size = PANGO_PIXELS (font_size);
903 width = impl->icon_size + font_size * NUM_CHARS;
904 height = (impl->icon_size + font_size) * NUM_LINES;
906 /* Use at least the requisition size... */
907 gtk_widget_size_request (widget, &req);
908 width = MAX (width, req.width);
909 height = MAX (height, req.height);
911 /* ... but no larger than the monitor */
912 screen = gtk_widget_get_screen (widget);
913 monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
915 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
917 width = MIN (width, monitor.width * 3 / 4);
918 height = MIN (height, monitor.height * 3 / 4);
921 gtk_widget_set_size_request (impl->recent_view, width, height);
925 gtk_recent_chooser_default_map (GtkWidget *widget)
927 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (widget);
929 GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);
931 /* reloads everything */
932 reload_recent_items (impl);
934 set_default_size (impl);
938 recent_icon_data_func (GtkTreeViewColumn *tree_column,
939 GtkCellRenderer *cell,
944 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
945 GtkRecentInfo *info = NULL;
948 gtk_tree_model_get (model, iter,
949 RECENT_INFO_COLUMN, &info,
951 g_assert (info != NULL);
953 pixbuf = gtk_recent_info_get_icon (info, impl->icon_size);
960 g_object_unref (pixbuf);
962 gtk_recent_info_unref (info);
966 recent_meta_data_func (GtkTreeViewColumn *tree_column,
967 GtkCellRenderer *cell,
972 GtkRecentInfo *info = NULL;
975 gtk_tree_model_get (model, iter,
976 RECENT_DISPLAY_NAME_COLUMN, &name,
977 RECENT_INFO_COLUMN, &info,
979 g_assert (info != NULL);
982 name = gtk_recent_info_get_short_name (info);
984 g_object_set (cell, "text", name, NULL);
987 gtk_recent_info_unref (info);
992 gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser)
994 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
996 g_assert (impl->selection != NULL);
998 if (!impl->select_multiple)
1000 GtkTreeModel *model;
1004 if (!gtk_tree_selection_get_selected (impl->selection, &model, &iter))
1007 gtk_tree_model_get (model, &iter, RECENT_URI_COLUMN, &uri, -1);
1018 guint do_select : 1;
1019 guint do_activate : 1;
1023 GtkRecentChooserDefault *impl;
1027 scan_for_uri_cb (GtkTreeModel *model,
1032 SelectURIData *select_data = (SelectURIData *) user_data;
1038 if (select_data->found)
1041 gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1);
1045 if (strcmp (uri, select_data->uri) == 0)
1047 select_data->found = TRUE;
1049 if (select_data->do_activate)
1050 gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->recent_view),
1052 select_data->impl->meta_column);
1054 if (select_data->do_select)
1055 gtk_tree_selection_select_path (select_data->impl->selection, path);
1057 gtk_tree_selection_unselect_path (select_data->impl->selection, path);
1070 gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
1074 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1075 SelectURIData *data;
1077 data = g_new0 (SelectURIData, 1);
1078 data->uri = g_strdup (uri);
1080 data->found = FALSE;
1081 data->do_activate = TRUE;
1082 data->do_select = TRUE;
1084 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1093 g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1094 GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1095 _("No item for URI '%s' found"),
1107 gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
1111 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1112 SelectURIData *data;
1114 data = g_new0 (SelectURIData, 1);
1115 data->uri = g_strdup (uri);
1117 data->found = FALSE;
1118 data->do_activate = FALSE;
1119 data->do_select = TRUE;
1121 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1130 g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1131 GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1132 _("No item for URI '%s' found"),
1144 gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
1147 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1148 SelectURIData *data;
1150 data = g_new0 (SelectURIData, 1);
1151 data->uri = g_strdup (uri);
1153 data->found = FALSE;
1154 data->do_activate = FALSE;
1155 data->do_select = FALSE;
1157 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1166 gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser)
1168 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1170 if (!impl->select_multiple)
1173 gtk_tree_selection_select_all (impl->selection);
1177 gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser)
1179 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1181 gtk_tree_selection_unselect_all (impl->selection);
1185 gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
1186 GtkRecentSortFunc sort_func,
1188 GDestroyNotify data_destroy)
1190 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1192 if (impl->sort_data_destroy)
1194 impl->sort_data_destroy (impl->sort_data);
1195 impl->sort_data_destroy = NULL;
1198 impl->sort_func = NULL;
1199 impl->sort_data = NULL;
1203 impl->sort_func = sort_func;
1204 impl->sort_data = sort_data;
1205 impl->sort_data_destroy = data_destroy;
1210 gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser)
1212 GtkRecentChooserDefault *impl;
1214 impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1216 return _gtk_recent_chooser_get_items (chooser,
1217 impl->current_filter,
1222 static GtkRecentManager *
1223 gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser)
1225 return GTK_RECENT_CHOOSER_DEFAULT (chooser)->manager;
1229 show_filters (GtkRecentChooserDefault *impl,
1233 gtk_widget_show (impl->filter_combo_hbox);
1235 gtk_widget_hide (impl->filter_combo_hbox);
1239 gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
1240 GtkRecentFilter *filter)
1242 GtkRecentChooserDefault *impl;
1245 impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1247 if (g_slist_find (impl->filters, filter))
1249 g_warning ("gtk_recent_chooser_add_filter() called on filter already in list\n");
1253 g_object_ref_sink (filter);
1254 impl->filters = g_slist_append (impl->filters, filter);
1256 /* display new filter */
1257 name = gtk_recent_filter_get_name (filter);
1259 name = _("Untitled filter");
1261 gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
1263 if (!g_slist_find (impl->filters, impl->current_filter))
1264 set_current_filter (impl, filter);
1266 show_filters (impl, TRUE);
1270 gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
1271 GtkRecentFilter *filter)
1273 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1274 GtkTreeModel *model;
1278 filter_idx = g_slist_index (impl->filters, filter);
1282 g_warning ("gtk_recent_chooser_remove_filter() called on filter not in list\n");
1286 impl->filters = g_slist_remove (impl->filters, filter);
1288 if (filter == impl->current_filter)
1291 set_current_filter (impl, impl->filters->data);
1293 set_current_filter (impl, NULL);
1296 model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
1297 gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_idx);
1298 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1300 g_object_unref (filter);
1303 show_filters (impl, FALSE);
1307 gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser)
1309 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1311 return g_slist_copy (impl->filters);
1315 set_current_filter (GtkRecentChooserDefault *impl,
1316 GtkRecentFilter *filter)
1318 if (impl->current_filter != filter)
1322 filter_idx = g_slist_index (impl->filters, filter);
1323 if (impl->filters && filter && filter_idx < 0)
1326 if (impl->current_filter)
1327 g_object_unref (impl->current_filter);
1329 impl->current_filter = filter;
1331 if (impl->current_filter)
1333 g_object_ref_sink (impl->current_filter);
1337 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
1340 if (impl->recent_store)
1341 reload_recent_items (impl);
1343 g_object_notify (G_OBJECT (impl), "filter");
1348 chooser_set_sort_type (GtkRecentChooserDefault *impl,
1349 GtkRecentSortType sort_type)
1351 if (impl->sort_type != sort_type)
1353 impl->sort_type = sort_type;
1354 reload_recent_items (impl);
1356 g_object_notify (G_OBJECT (impl), "sort-type");
1361 static GtkIconTheme *
1362 get_icon_theme_for_widget (GtkWidget *widget)
1364 if (gtk_widget_has_screen (widget))
1365 return gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
1367 return gtk_icon_theme_get_default ();
1371 get_icon_size_for_widget (GtkWidget *widget,
1372 GtkIconSize icon_size)
1374 GtkSettings *settings;
1377 if (gtk_widget_has_screen (widget))
1378 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
1380 settings = gtk_settings_get_default ();
1382 if (gtk_icon_size_lookup_for_settings (settings, icon_size,
1384 return MAX (width, height);
1386 return FALLBACK_ICON_SIZE;
1390 get_recent_files_limit (GtkWidget *widget)
1392 GtkSettings *settings;
1395 if (gtk_widget_has_screen (widget))
1396 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
1398 settings = gtk_settings_get_default ();
1400 g_object_get (G_OBJECT (settings), "gtk-recent-files-limit", &limit, NULL);
1406 recent_manager_changed_cb (GtkRecentManager *manager,
1409 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1411 reload_recent_items (impl);
1415 selection_changed_cb (GtkTreeSelection *selection,
1418 _gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
1422 row_activated_cb (GtkTreeView *tree_view,
1423 GtkTreePath *tree_path,
1424 GtkTreeViewColumn *tree_column,
1427 _gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
1431 filter_combo_changed_cb (GtkComboBox *combo_box,
1434 GtkRecentChooserDefault *impl;
1436 GtkRecentFilter *filter;
1438 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1440 new_index = gtk_combo_box_get_active (combo_box);
1441 filter = g_slist_nth_data (impl->filters, new_index);
1443 set_current_filter (impl, filter);
1447 get_drag_pixbuf (GtkRecentChooserDefault *impl)
1449 GtkRecentInfo *info;
1453 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1455 info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1459 size = get_icon_size_for_widget (GTK_WIDGET (impl), GTK_ICON_SIZE_DND);
1461 retval = gtk_recent_info_get_icon (info, size);
1462 gtk_recent_info_unref (info);
1468 recent_view_drag_begin_cb (GtkWidget *widget,
1469 GdkDragContext *context,
1472 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1475 pixbuf = get_drag_pixbuf (impl);
1478 gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
1479 g_object_unref (pixbuf);
1482 gtk_drag_set_icon_default (context);
1492 append_uri_to_urilist (GtkTreeModel *model,
1497 DragData *drag_data = (DragData *) user_data;
1498 GtkTreeModel *child_model;
1499 GtkTreeIter child_iter;
1503 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
1504 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
1507 gtk_tree_model_get (child_model, &child_iter,
1508 RECENT_URI_COLUMN, &uri,
1510 g_assert (uri != NULL);
1512 pos = drag_data->next_pos;
1513 drag_data->uri_list[pos] = g_strdup (uri);
1514 drag_data->next_pos = pos + 1;
1518 recent_view_drag_data_get_cb (GtkWidget *widget,
1519 GdkDragContext *context,
1520 GtkSelectionData *selection_data,
1525 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
1529 n_uris = gtk_tree_selection_count_selected_rows (impl->selection);
1533 drag_data.uri_list = g_new0 (gchar *, n_uris + 1);
1534 drag_data.next_pos = 0;
1536 gtk_tree_selection_selected_foreach (impl->selection,
1537 append_uri_to_urilist,
1540 gtk_selection_data_set_uris (selection_data, drag_data.uri_list);
1542 g_strfreev (drag_data.uri_list);
1546 recent_view_query_tooltip_cb (GtkWidget *widget,
1549 gboolean keyboard_tip,
1550 GtkTooltip *tooltip,
1553 GtkRecentChooserDefault *impl = user_data;
1554 GtkTreeView *tree_view;
1556 GtkTreePath *path = NULL;
1557 GtkRecentInfo *info = NULL;
1560 if (!impl->show_tips)
1563 tree_view = GTK_TREE_VIEW (impl->recent_view);
1565 gtk_tree_view_get_tooltip_context (tree_view,
1572 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_store), &iter, path))
1574 gtk_tree_path_free (path);
1578 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_store), &iter,
1579 RECENT_INFO_COLUMN, &info,
1582 uri_display = gtk_recent_info_get_uri_display (info);
1584 gtk_tooltip_set_text (tooltip, uri_display);
1585 gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
1587 g_free (uri_display);
1588 gtk_tree_path_free (path);
1589 gtk_recent_info_unref (info);
1595 remove_selected_from_list (GtkRecentChooserDefault *impl)
1600 if (impl->select_multiple)
1603 uri = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (impl));
1608 if (!gtk_recent_manager_remove_item (impl->manager, uri, &err))
1612 msg = strdup (_("Could not remove item"));
1613 error_message (impl, msg, err->message);
1623 copy_activated_cb (GtkMenuItem *menu_item,
1626 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1627 GtkRecentInfo *info;
1630 info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1634 utf8_uri = gtk_recent_info_get_uri_display (info);
1636 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (impl),
1637 GDK_SELECTION_CLIPBOARD),
1644 remove_all_activated_cb (GtkMenuItem *menu_item,
1647 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1650 gtk_recent_manager_purge_items (impl->manager, &err);
1655 msg = g_strdup (_("Could not clear list"));
1657 error_message (impl, msg, err->message);
1665 remove_item_activated_cb (GtkMenuItem *menu_item,
1668 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1670 remove_selected_from_list (impl);
1674 show_private_toggled_cb (GtkCheckMenuItem *menu_item,
1677 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1679 g_object_set (G_OBJECT (impl),
1680 "show-private", gtk_check_menu_item_get_active (menu_item),
1685 recent_popup_menu_detach_cb (GtkWidget *attach_widget,
1688 GtkRecentChooserDefault *impl;
1690 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkRecentChooserDefault");
1691 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1693 impl->recent_popup_menu = NULL;
1694 impl->recent_popup_menu_remove_item = NULL;
1695 impl->recent_popup_menu_copy_item = NULL;
1696 impl->recent_popup_menu_clear_item = NULL;
1697 impl->recent_popup_menu_show_private_item = NULL;
1701 recent_view_menu_ensure_state (GtkRecentChooserDefault *impl)
1705 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1706 g_assert (impl->recent_popup_menu != NULL);
1711 g_object_get (G_OBJECT (impl->manager), "size", &count, NULL);
1715 gtk_widget_set_sensitive (impl->recent_popup_menu_remove_item, FALSE);
1716 gtk_widget_set_sensitive (impl->recent_popup_menu_copy_item, FALSE);
1717 gtk_widget_set_sensitive (impl->recent_popup_menu_clear_item, FALSE);
1718 gtk_widget_set_sensitive (impl->recent_popup_menu_show_private_item, FALSE);
1723 recent_view_menu_build (GtkRecentChooserDefault *impl)
1727 if (impl->recent_popup_menu)
1729 recent_view_menu_ensure_state (impl);
1734 impl->recent_popup_menu = gtk_menu_new ();
1735 gtk_menu_attach_to_widget (GTK_MENU (impl->recent_popup_menu),
1737 recent_popup_menu_detach_cb);
1739 item = gtk_image_menu_item_new_with_mnemonic (_("Copy _Location"));
1740 impl->recent_popup_menu_copy_item = item;
1741 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1742 gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU));
1743 g_signal_connect (item, "activate",
1744 G_CALLBACK (copy_activated_cb), impl);
1745 gtk_widget_show (item);
1746 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1748 item = gtk_separator_menu_item_new ();
1749 gtk_widget_show (item);
1750 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1752 item = gtk_image_menu_item_new_with_mnemonic (_("_Remove From List"));
1753 impl->recent_popup_menu_remove_item = item;
1754 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1755 gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
1756 g_signal_connect (item, "activate",
1757 G_CALLBACK (remove_item_activated_cb), impl);
1758 gtk_widget_show (item);
1759 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1761 item = gtk_image_menu_item_new_with_mnemonic (_("_Clear List"));
1762 impl->recent_popup_menu_clear_item = item;
1763 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1764 gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
1765 g_signal_connect (item, "activate",
1766 G_CALLBACK (remove_all_activated_cb), impl);
1768 gtk_widget_show (item);
1769 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1771 item = gtk_separator_menu_item_new ();
1772 gtk_widget_show (item);
1773 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1775 item = gtk_check_menu_item_new_with_mnemonic (_("Show _Private Resources"));
1776 impl->recent_popup_menu_show_private_item = item;
1777 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), impl->show_private);
1778 g_signal_connect (item, "toggled",
1779 G_CALLBACK (show_private_toggled_cb), impl);
1780 gtk_widget_show (item);
1781 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1783 recent_view_menu_ensure_state (impl);
1786 /* taken from gtkfilechooserdefault.c */
1788 popup_position_func (GtkMenu *menu,
1794 GtkWidget *widget = GTK_WIDGET (user_data);
1795 GdkScreen *screen = gtk_widget_get_screen (widget);
1798 GdkRectangle monitor;
1800 if (G_UNLIKELY (!GTK_WIDGET_REALIZED (widget)))
1803 gdk_window_get_origin (widget->window, x, y);
1805 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1807 *x += (widget->allocation.width - req.width) / 2;
1808 *y += (widget->allocation.height - req.height) / 2;
1810 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
1811 gtk_menu_set_monitor (menu, monitor_num);
1812 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1814 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
1815 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
1822 recent_view_menu_popup (GtkRecentChooserDefault *impl,
1823 GdkEventButton *event)
1825 recent_view_menu_build (impl);
1828 gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1829 NULL, NULL, NULL, NULL,
1830 event->button, event->time);
1833 gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1835 popup_position_func, impl->recent_view,
1836 0, GDK_CURRENT_TIME);
1837 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->recent_popup_menu),
1843 recent_view_popup_menu_cb (GtkWidget *widget,
1846 recent_view_menu_popup (GTK_RECENT_CHOOSER_DEFAULT (user_data), NULL);
1851 recent_view_button_press_cb (GtkWidget *widget,
1852 GdkEventButton *event,
1855 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1857 if (event->button == 3)
1862 if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (impl->recent_view)))
1865 res = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (impl->recent_view),
1872 /* select the path before creating the popup menu */
1873 gtk_tree_selection_select_path (impl->selection, path);
1874 gtk_tree_path_free (path);
1876 recent_view_menu_popup (impl, event);
1885 set_recent_manager (GtkRecentChooserDefault *impl,
1886 GtkRecentManager *manager)
1890 if (impl->manager_changed_id)
1892 g_signal_handler_disconnect (impl, impl->manager_changed_id);
1893 impl->manager_changed_id = 0;
1896 impl->manager = NULL;
1900 impl->manager = manager;
1902 impl->manager = gtk_recent_manager_get_default ();
1906 impl->manager_changed_id = g_signal_connect (impl->manager, "changed",
1907 G_CALLBACK (recent_manager_changed_cb),
1913 _gtk_recent_chooser_default_new (GtkRecentManager *manager)
1915 return g_object_new (GTK_TYPE_RECENT_CHOOSER_DEFAULT,
1916 "recent-manager", manager,