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 if (GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map)
930 GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);
932 /* reloads everything */
933 reload_recent_items (impl);
935 set_default_size (impl);
939 recent_icon_data_func (GtkTreeViewColumn *tree_column,
940 GtkCellRenderer *cell,
945 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
946 GtkRecentInfo *info = NULL;
949 gtk_tree_model_get (model, iter,
950 RECENT_INFO_COLUMN, &info,
952 g_assert (info != NULL);
954 pixbuf = gtk_recent_info_get_icon (info, impl->icon_size);
961 g_object_unref (pixbuf);
963 gtk_recent_info_unref (info);
967 recent_meta_data_func (GtkTreeViewColumn *tree_column,
968 GtkCellRenderer *cell,
973 GtkRecentInfo *info = NULL;
976 gtk_tree_model_get (model, iter,
977 RECENT_DISPLAY_NAME_COLUMN, &name,
978 RECENT_INFO_COLUMN, &info,
980 g_assert (info != NULL);
983 name = gtk_recent_info_get_short_name (info);
985 g_object_set (cell, "text", name, NULL);
988 gtk_recent_info_unref (info);
993 gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser)
995 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
997 g_assert (impl->selection != NULL);
999 if (!impl->select_multiple)
1001 GtkTreeModel *model;
1005 if (!gtk_tree_selection_get_selected (impl->selection, &model, &iter))
1008 gtk_tree_model_get (model, &iter, RECENT_URI_COLUMN, &uri, -1);
1019 guint do_select : 1;
1020 guint do_activate : 1;
1024 GtkRecentChooserDefault *impl;
1028 scan_for_uri_cb (GtkTreeModel *model,
1033 SelectURIData *select_data = (SelectURIData *) user_data;
1039 if (select_data->found)
1042 gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1);
1046 if (strcmp (uri, select_data->uri) == 0)
1048 select_data->found = TRUE;
1050 if (select_data->do_activate)
1051 gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->recent_view),
1053 select_data->impl->meta_column);
1055 if (select_data->do_select)
1056 gtk_tree_selection_select_path (select_data->impl->selection, path);
1058 gtk_tree_selection_unselect_path (select_data->impl->selection, path);
1071 gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
1075 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1076 SelectURIData *data;
1078 data = g_new0 (SelectURIData, 1);
1079 data->uri = g_strdup (uri);
1081 data->found = FALSE;
1082 data->do_activate = TRUE;
1083 data->do_select = TRUE;
1085 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1094 g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1095 GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1096 _("No item for URI '%s' found"),
1108 gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
1112 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1113 SelectURIData *data;
1115 data = g_new0 (SelectURIData, 1);
1116 data->uri = g_strdup (uri);
1118 data->found = FALSE;
1119 data->do_activate = FALSE;
1120 data->do_select = TRUE;
1122 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1131 g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1132 GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1133 _("No item for URI '%s' found"),
1145 gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
1148 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1149 SelectURIData *data;
1151 data = g_new0 (SelectURIData, 1);
1152 data->uri = g_strdup (uri);
1154 data->found = FALSE;
1155 data->do_activate = FALSE;
1156 data->do_select = FALSE;
1158 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1167 gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser)
1169 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1171 if (!impl->select_multiple)
1174 gtk_tree_selection_select_all (impl->selection);
1178 gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser)
1180 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1182 gtk_tree_selection_unselect_all (impl->selection);
1186 gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
1187 GtkRecentSortFunc sort_func,
1189 GDestroyNotify data_destroy)
1191 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1193 if (impl->sort_data_destroy)
1195 impl->sort_data_destroy (impl->sort_data);
1196 impl->sort_data_destroy = NULL;
1199 impl->sort_func = NULL;
1200 impl->sort_data = NULL;
1204 impl->sort_func = sort_func;
1205 impl->sort_data = sort_data;
1206 impl->sort_data_destroy = data_destroy;
1211 gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser)
1213 GtkRecentChooserDefault *impl;
1215 impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1217 return _gtk_recent_chooser_get_items (chooser,
1218 impl->current_filter,
1223 static GtkRecentManager *
1224 gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser)
1226 return GTK_RECENT_CHOOSER_DEFAULT (chooser)->manager;
1230 show_filters (GtkRecentChooserDefault *impl,
1234 gtk_widget_show (impl->filter_combo_hbox);
1236 gtk_widget_hide (impl->filter_combo_hbox);
1240 gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
1241 GtkRecentFilter *filter)
1243 GtkRecentChooserDefault *impl;
1246 impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1248 if (g_slist_find (impl->filters, filter))
1250 g_warning ("gtk_recent_chooser_add_filter() called on filter already in list\n");
1254 g_object_ref_sink (filter);
1255 impl->filters = g_slist_append (impl->filters, filter);
1257 /* display new filter */
1258 name = gtk_recent_filter_get_name (filter);
1260 name = _("Untitled filter");
1262 gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
1264 if (!g_slist_find (impl->filters, impl->current_filter))
1265 set_current_filter (impl, filter);
1267 show_filters (impl, TRUE);
1271 gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
1272 GtkRecentFilter *filter)
1274 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1275 GtkTreeModel *model;
1279 filter_idx = g_slist_index (impl->filters, filter);
1283 g_warning ("gtk_recent_chooser_remove_filter() called on filter not in list\n");
1287 impl->filters = g_slist_remove (impl->filters, filter);
1289 if (filter == impl->current_filter)
1292 set_current_filter (impl, impl->filters->data);
1294 set_current_filter (impl, NULL);
1297 model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
1298 gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_idx);
1299 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1301 g_object_unref (filter);
1304 show_filters (impl, FALSE);
1308 gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser)
1310 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1312 return g_slist_copy (impl->filters);
1316 set_current_filter (GtkRecentChooserDefault *impl,
1317 GtkRecentFilter *filter)
1319 if (impl->current_filter != filter)
1323 filter_idx = g_slist_index (impl->filters, filter);
1324 if (impl->filters && filter && filter_idx < 0)
1327 if (impl->current_filter)
1328 g_object_unref (impl->current_filter);
1330 impl->current_filter = filter;
1332 if (impl->current_filter)
1334 g_object_ref_sink (impl->current_filter);
1338 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
1341 if (impl->recent_store)
1342 reload_recent_items (impl);
1344 g_object_notify (G_OBJECT (impl), "filter");
1349 chooser_set_sort_type (GtkRecentChooserDefault *impl,
1350 GtkRecentSortType sort_type)
1352 if (impl->sort_type != sort_type)
1354 impl->sort_type = sort_type;
1355 reload_recent_items (impl);
1357 g_object_notify (G_OBJECT (impl), "sort-type");
1362 static GtkIconTheme *
1363 get_icon_theme_for_widget (GtkWidget *widget)
1365 if (gtk_widget_has_screen (widget))
1366 return gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
1368 return gtk_icon_theme_get_default ();
1372 get_icon_size_for_widget (GtkWidget *widget,
1373 GtkIconSize icon_size)
1375 GtkSettings *settings;
1378 if (gtk_widget_has_screen (widget))
1379 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
1381 settings = gtk_settings_get_default ();
1383 if (gtk_icon_size_lookup_for_settings (settings, icon_size,
1385 return MAX (width, height);
1387 return FALLBACK_ICON_SIZE;
1391 get_recent_files_limit (GtkWidget *widget)
1393 GtkSettings *settings;
1396 if (gtk_widget_has_screen (widget))
1397 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
1399 settings = gtk_settings_get_default ();
1401 g_object_get (G_OBJECT (settings), "gtk-recent-files-limit", &limit, NULL);
1407 recent_manager_changed_cb (GtkRecentManager *manager,
1410 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1412 reload_recent_items (impl);
1416 selection_changed_cb (GtkTreeSelection *selection,
1419 _gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
1423 row_activated_cb (GtkTreeView *tree_view,
1424 GtkTreePath *tree_path,
1425 GtkTreeViewColumn *tree_column,
1428 _gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
1432 filter_combo_changed_cb (GtkComboBox *combo_box,
1435 GtkRecentChooserDefault *impl;
1437 GtkRecentFilter *filter;
1439 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1441 new_index = gtk_combo_box_get_active (combo_box);
1442 filter = g_slist_nth_data (impl->filters, new_index);
1444 set_current_filter (impl, filter);
1448 get_drag_pixbuf (GtkRecentChooserDefault *impl)
1450 GtkRecentInfo *info;
1454 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1456 info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1460 size = get_icon_size_for_widget (GTK_WIDGET (impl), GTK_ICON_SIZE_DND);
1462 retval = gtk_recent_info_get_icon (info, size);
1463 gtk_recent_info_unref (info);
1469 recent_view_drag_begin_cb (GtkWidget *widget,
1470 GdkDragContext *context,
1473 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1476 pixbuf = get_drag_pixbuf (impl);
1479 gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
1480 g_object_unref (pixbuf);
1483 gtk_drag_set_icon_default (context);
1493 append_uri_to_urilist (GtkTreeModel *model,
1498 DragData *drag_data = (DragData *) user_data;
1499 GtkTreeModel *child_model;
1500 GtkTreeIter child_iter;
1504 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
1505 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
1508 gtk_tree_model_get (child_model, &child_iter,
1509 RECENT_URI_COLUMN, &uri,
1511 g_assert (uri != NULL);
1513 pos = drag_data->next_pos;
1514 drag_data->uri_list[pos] = g_strdup (uri);
1515 drag_data->next_pos = pos + 1;
1519 recent_view_drag_data_get_cb (GtkWidget *widget,
1520 GdkDragContext *context,
1521 GtkSelectionData *selection_data,
1526 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
1530 n_uris = gtk_tree_selection_count_selected_rows (impl->selection);
1534 drag_data.uri_list = g_new0 (gchar *, n_uris + 1);
1535 drag_data.next_pos = 0;
1537 gtk_tree_selection_selected_foreach (impl->selection,
1538 append_uri_to_urilist,
1541 gtk_selection_data_set_uris (selection_data, drag_data.uri_list);
1543 g_strfreev (drag_data.uri_list);
1547 recent_view_query_tooltip_cb (GtkWidget *widget,
1550 gboolean keyboard_tip,
1551 GtkTooltip *tooltip,
1554 GtkRecentChooserDefault *impl = user_data;
1555 GtkTreeView *tree_view;
1557 GtkTreePath *path = NULL;
1558 GtkRecentInfo *info = NULL;
1561 if (!impl->show_tips)
1564 tree_view = GTK_TREE_VIEW (impl->recent_view);
1566 gtk_tree_view_get_tooltip_context (tree_view,
1573 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_store), &iter, path))
1575 gtk_tree_path_free (path);
1579 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_store), &iter,
1580 RECENT_INFO_COLUMN, &info,
1583 uri_display = gtk_recent_info_get_uri_display (info);
1585 gtk_tooltip_set_text (tooltip, uri_display);
1586 gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
1588 g_free (uri_display);
1589 gtk_tree_path_free (path);
1590 gtk_recent_info_unref (info);
1596 remove_selected_from_list (GtkRecentChooserDefault *impl)
1601 if (impl->select_multiple)
1604 uri = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (impl));
1609 if (!gtk_recent_manager_remove_item (impl->manager, uri, &err))
1613 msg = strdup (_("Could not remove item"));
1614 error_message (impl, msg, err->message);
1624 copy_activated_cb (GtkMenuItem *menu_item,
1627 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1628 GtkRecentInfo *info;
1631 info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1635 utf8_uri = gtk_recent_info_get_uri_display (info);
1637 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (impl),
1638 GDK_SELECTION_CLIPBOARD),
1645 remove_all_activated_cb (GtkMenuItem *menu_item,
1648 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1651 gtk_recent_manager_purge_items (impl->manager, &err);
1656 msg = g_strdup (_("Could not clear list"));
1658 error_message (impl, msg, err->message);
1666 remove_item_activated_cb (GtkMenuItem *menu_item,
1669 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1671 remove_selected_from_list (impl);
1675 show_private_toggled_cb (GtkCheckMenuItem *menu_item,
1678 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1680 g_object_set (G_OBJECT (impl),
1681 "show-private", gtk_check_menu_item_get_active (menu_item),
1686 recent_popup_menu_detach_cb (GtkWidget *attach_widget,
1689 GtkRecentChooserDefault *impl;
1691 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkRecentChooserDefault");
1692 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1694 impl->recent_popup_menu = NULL;
1695 impl->recent_popup_menu_remove_item = NULL;
1696 impl->recent_popup_menu_copy_item = NULL;
1697 impl->recent_popup_menu_clear_item = NULL;
1698 impl->recent_popup_menu_show_private_item = NULL;
1702 recent_view_menu_ensure_state (GtkRecentChooserDefault *impl)
1706 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1707 g_assert (impl->recent_popup_menu != NULL);
1712 g_object_get (G_OBJECT (impl->manager), "size", &count, NULL);
1716 gtk_widget_set_sensitive (impl->recent_popup_menu_remove_item, FALSE);
1717 gtk_widget_set_sensitive (impl->recent_popup_menu_copy_item, FALSE);
1718 gtk_widget_set_sensitive (impl->recent_popup_menu_clear_item, FALSE);
1719 gtk_widget_set_sensitive (impl->recent_popup_menu_show_private_item, FALSE);
1724 recent_view_menu_build (GtkRecentChooserDefault *impl)
1728 if (impl->recent_popup_menu)
1730 recent_view_menu_ensure_state (impl);
1735 impl->recent_popup_menu = gtk_menu_new ();
1736 gtk_menu_attach_to_widget (GTK_MENU (impl->recent_popup_menu),
1738 recent_popup_menu_detach_cb);
1740 item = gtk_image_menu_item_new_with_mnemonic (_("Copy _Location"));
1741 impl->recent_popup_menu_copy_item = item;
1742 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1743 gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU));
1744 g_signal_connect (item, "activate",
1745 G_CALLBACK (copy_activated_cb), impl);
1746 gtk_widget_show (item);
1747 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1749 item = gtk_separator_menu_item_new ();
1750 gtk_widget_show (item);
1751 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1753 item = gtk_image_menu_item_new_with_mnemonic (_("_Remove From List"));
1754 impl->recent_popup_menu_remove_item = item;
1755 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1756 gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
1757 g_signal_connect (item, "activate",
1758 G_CALLBACK (remove_item_activated_cb), impl);
1759 gtk_widget_show (item);
1760 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1762 item = gtk_image_menu_item_new_with_mnemonic (_("_Clear List"));
1763 impl->recent_popup_menu_clear_item = item;
1764 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1765 gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
1766 g_signal_connect (item, "activate",
1767 G_CALLBACK (remove_all_activated_cb), impl);
1769 gtk_widget_show (item);
1770 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1772 item = gtk_separator_menu_item_new ();
1773 gtk_widget_show (item);
1774 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1776 item = gtk_check_menu_item_new_with_mnemonic (_("Show _Private Resources"));
1777 impl->recent_popup_menu_show_private_item = item;
1778 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), impl->show_private);
1779 g_signal_connect (item, "toggled",
1780 G_CALLBACK (show_private_toggled_cb), impl);
1781 gtk_widget_show (item);
1782 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1784 recent_view_menu_ensure_state (impl);
1787 /* taken from gtkfilechooserdefault.c */
1789 popup_position_func (GtkMenu *menu,
1795 GtkWidget *widget = GTK_WIDGET (user_data);
1796 GdkScreen *screen = gtk_widget_get_screen (widget);
1799 GdkRectangle monitor;
1801 if (G_UNLIKELY (!GTK_WIDGET_REALIZED (widget)))
1804 gdk_window_get_origin (widget->window, x, y);
1806 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1808 *x += (widget->allocation.width - req.width) / 2;
1809 *y += (widget->allocation.height - req.height) / 2;
1811 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
1812 gtk_menu_set_monitor (menu, monitor_num);
1813 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1815 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
1816 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
1823 recent_view_menu_popup (GtkRecentChooserDefault *impl,
1824 GdkEventButton *event)
1826 recent_view_menu_build (impl);
1829 gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1830 NULL, NULL, NULL, NULL,
1831 event->button, event->time);
1834 gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1836 popup_position_func, impl->recent_view,
1837 0, GDK_CURRENT_TIME);
1838 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->recent_popup_menu),
1844 recent_view_popup_menu_cb (GtkWidget *widget,
1847 recent_view_menu_popup (GTK_RECENT_CHOOSER_DEFAULT (user_data), NULL);
1852 recent_view_button_press_cb (GtkWidget *widget,
1853 GdkEventButton *event,
1856 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1858 if (event->button == 3)
1863 if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (impl->recent_view)))
1866 res = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (impl->recent_view),
1873 /* select the path before creating the popup menu */
1874 gtk_tree_selection_select_path (impl->selection, path);
1875 gtk_tree_path_free (path);
1877 recent_view_menu_popup (impl, event);
1886 set_recent_manager (GtkRecentChooserDefault *impl,
1887 GtkRecentManager *manager)
1891 if (impl->manager_changed_id)
1893 g_signal_handler_disconnect (impl, impl->manager_changed_id);
1894 impl->manager_changed_id = 0;
1897 impl->manager = NULL;
1901 impl->manager = manager;
1903 impl->manager = gtk_recent_manager_get_default ();
1907 impl->manager_changed_id = g_signal_connect (impl->manager, "changed",
1908 G_CALLBACK (recent_manager_changed_cb),
1914 _gtk_recent_chooser_default_new (GtkRecentManager *manager)
1916 return g_object_new (GTK_TYPE_RECENT_CHOOSER_DEFAULT,
1917 "recent-manager", manager,