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>
32 #include <gdk/gdkscreen.h>
35 #include "gtkicontheme.h"
36 #include "gtkiconfactory.h"
37 #include "gtksettings.h"
38 #include "gtktreeview.h"
39 #include "gtkliststore.h"
40 #include "gtkbutton.h"
41 #include "gtkcelllayout.h"
42 #include "gtkcellrendererpixbuf.h"
43 #include "gtkcellrenderertext.h"
44 #include "gtkcheckmenuitem.h"
45 #include "gtkclipboard.h"
46 #include "gtkcombobox.h"
48 #include "gtkeventbox.h"
49 #include "gtkexpander.h"
52 #include "gtkhpaned.h"
54 #include "gtkimagemenuitem.h"
57 #include "gtkmenuitem.h"
58 #include "gtkmessagedialog.h"
59 #include "gtkscrolledwindow.h"
60 #include "gtkseparatormenuitem.h"
61 #include "gtksizegroup.h"
63 #include "gtktreemodelsort.h"
64 #include "gtktreemodelfilter.h"
65 #include "gtktreeselection.h"
66 #include "gtktreestore.h"
67 #include "gtktooltip.h"
68 #include "gtktypebuiltins.h"
71 #include "gtkrecentmanager.h"
72 #include "gtkrecentfilter.h"
73 #include "gtkrecentchooser.h"
74 #include "gtkrecentchooserprivate.h"
75 #include "gtkrecentchooserutils.h"
76 #include "gtkrecentchooserdefault.h"
78 #include "gtkprivate.h"
83 struct _GtkRecentChooserDefault
85 GtkVBox parent_instance;
87 GtkRecentManager *manager;
88 gulong manager_changed_id;
89 guint local_manager : 1;
93 /* RecentChooser properties */
95 GtkRecentSortType sort_type;
96 guint show_private : 1;
97 guint show_not_found : 1;
98 guint select_multiple : 1;
100 guint show_icons : 1;
101 guint local_only : 1;
106 GtkRecentFilter *current_filter;
107 GtkWidget *filter_combo_hbox;
108 GtkWidget *filter_combo;
110 GtkRecentSortFunc sort_func;
112 GDestroyNotify sort_data_destroy;
114 GtkIconTheme *icon_theme;
116 GtkWidget *recent_view;
117 GtkListStore *recent_store;
118 GtkTreeViewColumn *icon_column;
119 GtkTreeViewColumn *meta_column;
120 GtkCellRenderer *meta_renderer;
121 GtkTreeSelection *selection;
123 GtkWidget *recent_popup_menu;
124 GtkWidget *recent_popup_menu_copy_item;
125 GtkWidget *recent_popup_menu_remove_item;
126 GtkWidget *recent_popup_menu_clear_item;
127 GtkWidget *recent_popup_menu_show_private_item;
136 typedef struct _GtkRecentChooserDefaultClass
138 GtkVBoxClass parent_class;
139 } GtkRecentChooserDefaultClass;
143 RECENT_DISPLAY_NAME_COLUMN,
150 LOAD_EMPTY, /* initial state: the model is empty */
151 LOAD_PRELOAD, /* the model is loading and not inserted in the tree yet */
152 LOAD_LOADING, /* the model is fully loaded but not inserted */
153 LOAD_FINISHED /* the model is fully loaded and inserted */
160 /* Target types for DnD from the file list */
161 static const GtkTargetEntry recent_list_source_targets[] = {
162 { "text/uri-list", 0, TEXT_URI_LIST }
165 /* Icon size for if we can't get it from the theme */
166 #define FALLBACK_ICON_SIZE 48
167 #define FALLBACK_ITEM_LIMIT 20
175 static void _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass);
176 static void _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl);
177 static GObject *gtk_recent_chooser_default_constructor (GType type,
178 guint n_construct_prop,
179 GObjectConstructParam *construct_params);
180 static void gtk_recent_chooser_default_finalize (GObject *object);
181 static void gtk_recent_chooser_default_dispose (GObject *object);
182 static void gtk_recent_chooser_default_set_property (GObject *object,
186 static void gtk_recent_chooser_default_get_property (GObject *object,
191 /* GtkRecentChooserIface */
192 static void gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface);
193 static gboolean gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
196 static gchar * gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser);
197 static gboolean gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
200 static void gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
202 static void gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser);
203 static void gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser);
204 static GList * gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser);
205 static GtkRecentManager *gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser);
206 static void gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
207 GtkRecentSortFunc sort_func,
209 GDestroyNotify data_destroy);
210 static void gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
211 GtkRecentFilter *filter);
212 static void gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
213 GtkRecentFilter *filter);
214 static GSList * gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser);
217 static void gtk_recent_chooser_default_map (GtkWidget *widget);
218 static void gtk_recent_chooser_default_show_all (GtkWidget *widget);
220 static void set_current_filter (GtkRecentChooserDefault *impl,
221 GtkRecentFilter *filter);
223 static GtkIconTheme *get_icon_theme_for_widget (GtkWidget *widget);
224 static gint get_icon_size_for_widget (GtkWidget *widget,
225 GtkIconSize icon_size);
226 static gint get_recent_files_limit (GtkWidget *widget);
228 static void reload_recent_items (GtkRecentChooserDefault *impl);
229 static void chooser_set_model (GtkRecentChooserDefault *impl);
231 static void set_recent_manager (GtkRecentChooserDefault *impl,
232 GtkRecentManager *manager);
234 static void chooser_set_sort_type (GtkRecentChooserDefault *impl,
235 GtkRecentSortType sort_type);
237 static void recent_manager_changed_cb (GtkRecentManager *manager,
239 static void recent_icon_data_func (GtkTreeViewColumn *tree_column,
240 GtkCellRenderer *cell,
244 static void recent_meta_data_func (GtkTreeViewColumn *tree_column,
245 GtkCellRenderer *cell,
250 static void selection_changed_cb (GtkTreeSelection *z,
252 static void row_activated_cb (GtkTreeView *tree_view,
253 GtkTreePath *tree_path,
254 GtkTreeViewColumn *tree_column,
256 static void filter_combo_changed_cb (GtkComboBox *combo_box,
259 static void remove_all_activated_cb (GtkMenuItem *menu_item,
261 static void remove_item_activated_cb (GtkMenuItem *menu_item,
263 static void show_private_toggled_cb (GtkCheckMenuItem *menu_item,
266 static gboolean recent_view_popup_menu_cb (GtkWidget *widget,
268 static gboolean recent_view_button_press_cb (GtkWidget *widget,
269 GdkEventButton *event,
272 static void recent_view_drag_begin_cb (GtkWidget *widget,
273 GdkDragContext *context,
275 static void recent_view_drag_data_get_cb (GtkWidget *widget,
276 GdkDragContext *context,
277 GtkSelectionData *selection_data,
281 static gboolean recent_view_query_tooltip_cb (GtkWidget *widget,
284 gboolean keyboard_tip,
290 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDefault,
291 _gtk_recent_chooser_default,
293 G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
294 gtk_recent_chooser_iface_init))
300 gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
302 iface->set_current_uri = gtk_recent_chooser_default_set_current_uri;
303 iface->get_current_uri = gtk_recent_chooser_default_get_current_uri;
304 iface->select_uri = gtk_recent_chooser_default_select_uri;
305 iface->unselect_uri = gtk_recent_chooser_default_unselect_uri;
306 iface->select_all = gtk_recent_chooser_default_select_all;
307 iface->unselect_all = gtk_recent_chooser_default_unselect_all;
308 iface->get_items = gtk_recent_chooser_default_get_items;
309 iface->get_recent_manager = gtk_recent_chooser_default_get_recent_manager;
310 iface->set_sort_func = gtk_recent_chooser_default_set_sort_func;
311 iface->add_filter = gtk_recent_chooser_default_add_filter;
312 iface->remove_filter = gtk_recent_chooser_default_remove_filter;
313 iface->list_filters = gtk_recent_chooser_default_list_filters;
317 _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
319 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
320 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
322 gobject_class->constructor = gtk_recent_chooser_default_constructor;
323 gobject_class->set_property = gtk_recent_chooser_default_set_property;
324 gobject_class->get_property = gtk_recent_chooser_default_get_property;
325 gobject_class->dispose = gtk_recent_chooser_default_dispose;
326 gobject_class->finalize = gtk_recent_chooser_default_finalize;
328 widget_class->map = gtk_recent_chooser_default_map;
329 widget_class->show_all = gtk_recent_chooser_default_show_all;
331 _gtk_recent_chooser_install_properties (gobject_class);
335 _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
337 gtk_box_set_spacing (GTK_BOX (impl), 6);
339 /* by default, we use the global manager */
340 impl->local_manager = FALSE;
342 impl->limit = FALLBACK_ITEM_LIMIT;
343 impl->sort_type = GTK_RECENT_SORT_NONE;
345 impl->show_icons = TRUE;
346 impl->show_private = FALSE;
347 impl->show_not_found = TRUE;
348 impl->show_tips = TRUE;
349 impl->select_multiple = FALSE;
350 impl->local_only = TRUE;
352 impl->icon_size = FALLBACK_ICON_SIZE;
353 impl->icon_theme = NULL;
355 impl->current_filter = NULL;
357 impl->recent_items = NULL;
358 impl->n_recent_items = 0;
359 impl->loaded_items = 0;
361 impl->load_state = LOAD_EMPTY;
365 gtk_recent_chooser_default_constructor (GType type,
367 GObjectConstructParam *params)
369 GObjectClass *parent_class;
370 GtkRecentChooserDefault *impl;
373 GtkCellRenderer *renderer;
375 parent_class = G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class);
376 object = parent_class->constructor (type, n_params, params);
377 impl = GTK_RECENT_CHOOSER_DEFAULT (object);
379 g_assert (impl->manager);
381 gtk_widget_push_composite_child ();
383 impl->limit = get_recent_files_limit (GTK_WIDGET (impl));
385 scrollw = gtk_scrolled_window_new (NULL, NULL);
386 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollw),
388 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollw),
389 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
390 gtk_box_pack_start (GTK_BOX (impl), scrollw, TRUE, TRUE, 0);
391 gtk_widget_show (scrollw);
393 impl->recent_view = gtk_tree_view_new ();
394 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->recent_view), FALSE);
395 g_signal_connect (impl->recent_view, "row-activated",
396 G_CALLBACK (row_activated_cb), impl);
397 g_signal_connect (impl->recent_view, "popup-menu",
398 G_CALLBACK (recent_view_popup_menu_cb), impl);
399 g_signal_connect (impl->recent_view, "button-press-event",
400 G_CALLBACK (recent_view_button_press_cb), impl);
401 g_signal_connect (impl->recent_view, "drag_begin",
402 G_CALLBACK (recent_view_drag_begin_cb), impl);
403 g_signal_connect (impl->recent_view, "drag_data_get",
404 G_CALLBACK (recent_view_drag_data_get_cb), impl);
406 g_object_set (impl->recent_view, "has-tooltip", TRUE, NULL);
407 g_signal_connect (impl->recent_view, "query-tooltip",
408 G_CALLBACK (recent_view_query_tooltip_cb), impl);
410 g_object_set_data (G_OBJECT (impl->recent_view),
411 "GtkRecentChooserDefault", impl);
413 gtk_container_add (GTK_CONTAINER (scrollw), impl->recent_view);
414 gtk_widget_show (impl->recent_view);
416 impl->icon_column = gtk_tree_view_column_new ();
417 gtk_tree_view_column_set_expand (impl->icon_column, FALSE);
418 gtk_tree_view_column_set_resizable (impl->icon_column, FALSE);
420 renderer = gtk_cell_renderer_pixbuf_new ();
421 gtk_tree_view_column_pack_start (impl->icon_column, renderer, FALSE);
422 gtk_tree_view_column_set_cell_data_func (impl->icon_column,
424 recent_icon_data_func,
427 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->recent_view),
430 impl->meta_column = gtk_tree_view_column_new ();
431 gtk_tree_view_column_set_expand (impl->meta_column, TRUE);
432 gtk_tree_view_column_set_resizable (impl->meta_column, FALSE);
434 impl->meta_renderer = gtk_cell_renderer_text_new ();
435 g_object_set (G_OBJECT (impl->meta_renderer),
436 "ellipsize", PANGO_ELLIPSIZE_END,
438 gtk_tree_view_column_pack_start (impl->meta_column, impl->meta_renderer, TRUE);
439 gtk_tree_view_column_set_cell_data_func (impl->meta_column,
441 recent_meta_data_func,
444 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->recent_view),
447 impl->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->recent_view));
448 gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_SINGLE);
449 g_signal_connect (impl->selection, "changed", G_CALLBACK (selection_changed_cb), impl);
452 gtk_drag_source_set (impl->recent_view,
454 recent_list_source_targets,
455 G_N_ELEMENTS (recent_list_source_targets),
458 impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
460 impl->filter_combo = gtk_combo_box_new_text ();
461 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
462 g_signal_connect (impl->filter_combo, "changed",
463 G_CALLBACK (filter_combo_changed_cb), impl);
464 gtk_widget_set_tooltip_text (impl->filter_combo,
465 _("Select which type of documents are shown"));
467 gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox),
470 gtk_widget_show (impl->filter_combo);
472 gtk_box_pack_end (GTK_BOX (impl), impl->filter_combo_hbox, FALSE, FALSE, 0);
474 gtk_widget_pop_composite_child ();
476 impl->recent_store = gtk_list_store_new (N_RECENT_COLUMNS,
477 G_TYPE_STRING, /* uri */
478 G_TYPE_STRING, /* display_name */
479 GTK_TYPE_RECENT_INFO /* info */);
485 gtk_recent_chooser_default_set_property (GObject *object,
490 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
494 case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
495 set_recent_manager (impl, g_value_get_object (value));
497 case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
498 impl->show_private = g_value_get_boolean (value);
499 if (impl->recent_popup_menu_show_private_item)
501 GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (impl->recent_popup_menu_show_private_item);
502 g_signal_handlers_block_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
503 gtk_check_menu_item_set_active (item, impl->show_private);
504 g_signal_handlers_unblock_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
506 reload_recent_items (impl);
508 case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
509 impl->show_not_found = g_value_get_boolean (value);
510 reload_recent_items (impl);
512 case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
513 impl->show_tips = g_value_get_boolean (value);
515 case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
516 impl->show_icons = g_value_get_boolean (value);
517 gtk_tree_view_column_set_visible (impl->icon_column, impl->show_icons);
519 case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
520 impl->select_multiple = g_value_get_boolean (value);
522 if (impl->select_multiple)
523 gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_MULTIPLE);
525 gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_SINGLE);
527 case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
528 impl->local_only = g_value_get_boolean (value);
529 reload_recent_items (impl);
531 case GTK_RECENT_CHOOSER_PROP_LIMIT:
532 impl->limit = g_value_get_int (value);
533 impl->limit_set = TRUE;
534 reload_recent_items (impl);
536 case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
537 chooser_set_sort_type (impl, g_value_get_enum (value));
539 case GTK_RECENT_CHOOSER_PROP_FILTER:
540 set_current_filter (impl, g_value_get_object (value));
543 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
549 gtk_recent_chooser_default_get_property (GObject *object,
554 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
558 case GTK_RECENT_CHOOSER_PROP_LIMIT:
559 g_value_set_int (value, impl->limit);
561 case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
562 g_value_set_enum (value, impl->sort_type);
564 case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
565 g_value_set_boolean (value, impl->show_private);
567 case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
568 g_value_set_boolean (value, impl->show_icons);
570 case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
571 g_value_set_boolean (value, impl->show_not_found);
573 case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
574 g_value_set_boolean (value, impl->show_tips);
576 case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
577 g_value_set_boolean (value, impl->local_only);
579 case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
580 g_value_set_boolean (value, impl->select_multiple);
582 case GTK_RECENT_CHOOSER_PROP_FILTER:
583 g_value_set_object (value, impl->current_filter);
586 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
592 gtk_recent_chooser_default_dispose (GObject *object)
594 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
598 g_source_remove (impl->load_id);
599 impl->load_state = LOAD_EMPTY;
603 if (impl->recent_items)
605 g_list_foreach (impl->recent_items, (GFunc) gtk_recent_info_unref, NULL);
606 g_list_free (impl->recent_items);
607 impl->recent_items = NULL;
610 if (impl->manager && impl->manager_changed_id)
612 g_signal_handler_disconnect (impl->manager, impl->manager_changed_id);
613 impl->manager_changed_id = 0;
618 g_slist_foreach (impl->filters, (GFunc) g_object_unref, NULL);
619 g_slist_free (impl->filters);
620 impl->filters = NULL;
623 if (impl->current_filter)
625 g_object_unref (impl->current_filter);
626 impl->current_filter = NULL;
629 if (impl->recent_store)
631 g_object_unref (impl->recent_store);
632 impl->recent_store = NULL;
635 G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->dispose (object);
639 gtk_recent_chooser_default_finalize (GObject *object)
641 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
643 impl->manager = NULL;
645 if (impl->sort_data_destroy)
647 impl->sort_data_destroy (impl->sort_data);
648 impl->sort_data_destroy = NULL;
651 impl->sort_data = NULL;
652 impl->sort_func = NULL;
654 G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->finalize (object);
657 /* override GtkWidget::show_all since we have internal widgets we wish to keep
658 * hidden unless we decide otherwise, like the filter combo box.
661 gtk_recent_chooser_default_show_all (GtkWidget *widget)
663 gtk_widget_show (widget);
668 /* Shows an error dialog set as transient for the specified window */
670 error_message_with_parent (GtkWindow *parent,
676 dialog = gtk_message_dialog_new (parent,
677 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
682 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
686 gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
688 gtk_dialog_run (GTK_DIALOG (dialog));
689 gtk_widget_destroy (dialog);
692 /* Returns a toplevel GtkWindow, or NULL if none */
694 get_toplevel (GtkWidget *widget)
698 toplevel = gtk_widget_get_toplevel (widget);
699 if (!GTK_WIDGET_TOPLEVEL (toplevel))
702 return GTK_WINDOW (toplevel);
705 /* Shows an error dialog for the file chooser */
707 error_message (GtkRecentChooserDefault *impl,
711 error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
715 set_busy_cursor (GtkRecentChooserDefault *impl,
716 gboolean show_busy_cursor)
722 toplevel = get_toplevel (GTK_WIDGET (impl));
723 if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
726 display = gtk_widget_get_display (GTK_WIDGET (toplevel));
729 if (show_busy_cursor)
730 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
732 gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
733 gdk_display_flush (display);
736 gdk_cursor_unref (cursor);
740 chooser_set_model (GtkRecentChooserDefault *impl)
742 g_assert (impl->recent_store != NULL);
743 g_assert (impl->load_state == LOAD_LOADING);
745 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->recent_view),
746 GTK_TREE_MODEL (impl->recent_store));
747 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->recent_view));
748 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->recent_view), TRUE);
749 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->recent_view),
750 RECENT_DISPLAY_NAME_COLUMN);
752 impl->load_state = LOAD_FINISHED;
756 load_recent_items (gpointer user_data)
758 GtkRecentChooserDefault *impl;
761 const gchar *uri, *name;
764 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
766 g_assert ((impl->load_state == LOAD_EMPTY) ||
767 (impl->load_state == LOAD_PRELOAD));
769 /* store the items for multiple runs */
770 if (!impl->recent_items)
772 impl->recent_items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (impl));
773 if (!impl->recent_items)
775 impl->load_state = LOAD_FINISHED;
780 impl->n_recent_items = g_list_length (impl->recent_items);
781 impl->loaded_items = 0;
782 impl->load_state = LOAD_PRELOAD;
785 info = (GtkRecentInfo *) g_list_nth_data (impl->recent_items,
789 uri = gtk_recent_info_get_uri (info);
790 name = gtk_recent_info_get_display_name (info);
792 /* at this point, everything goes inside the model; operations on the
793 * visualization of items inside the model are done in the cell data
794 * funcs (remember that there are two of those: one for the icon and
795 * one for the text), while the filtering is done only when a filter
796 * is actually loaded. */
797 gtk_list_store_append (impl->recent_store, &iter);
798 gtk_list_store_set (impl->recent_store, &iter,
799 RECENT_URI_COLUMN, uri, /* uri */
800 RECENT_DISPLAY_NAME_COLUMN, name, /* display_name */
801 RECENT_INFO_COLUMN, info, /* info */
804 impl->loaded_items += 1;
806 if (impl->loaded_items == impl->n_recent_items)
808 /* we have finished loading, so we remove the items cache */
809 impl->load_state = LOAD_LOADING;
811 g_list_foreach (impl->recent_items,
812 (GFunc) gtk_recent_info_unref,
814 g_list_free (impl->recent_items);
816 impl->recent_items = NULL;
817 impl->n_recent_items = 0;
818 impl->loaded_items = 0;
820 /* load the filled up model */
821 chooser_set_model (impl);
827 /* we did not finish, so continue loading */
835 cleanup_after_load (gpointer user_data)
837 GtkRecentChooserDefault *impl;
839 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
841 if (impl->load_id != 0)
843 g_assert ((impl->load_state == LOAD_EMPTY) ||
844 (impl->load_state == LOAD_PRELOAD) ||
845 (impl->load_state == LOAD_LOADING) ||
846 (impl->load_state == LOAD_FINISHED));
848 /* we have officialy finished loading all the items,
849 * so we can reset the state machine
851 g_source_remove (impl->load_id);
853 impl->load_state = LOAD_EMPTY;
856 g_assert ((impl->load_state == LOAD_EMPTY) ||
857 (impl->load_state == LOAD_LOADING) ||
858 (impl->load_state == LOAD_FINISHED));
860 set_busy_cursor (impl, FALSE);
863 /* clears the current model and reloads the recently used resources */
865 reload_recent_items (GtkRecentChooserDefault *impl)
869 /* reload is already in progress - do not disturb */
873 widget = GTK_WIDGET (impl);
875 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->recent_view), NULL);
876 gtk_list_store_clear (impl->recent_store);
878 if (!impl->icon_theme)
879 impl->icon_theme = get_icon_theme_for_widget (widget);
881 impl->icon_size = get_icon_size_for_widget (widget,
882 GTK_ICON_SIZE_BUTTON);
884 if (!impl->limit_set)
885 impl->limit = get_recent_files_limit (widget);
887 set_busy_cursor (impl, TRUE);
889 impl->load_state = LOAD_EMPTY;
890 impl->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
896 /* taken form gtkfilechooserdialog.c */
898 set_default_size (GtkRecentChooserDefault *impl)
906 GdkRectangle monitor;
908 widget = GTK_WIDGET (impl);
910 /* Size based on characters and the icon size */
911 font_size = pango_font_description_get_size (widget->style->font_desc);
912 font_size = PANGO_PIXELS (font_size);
914 width = impl->icon_size + font_size * NUM_CHARS;
915 height = (impl->icon_size + font_size) * NUM_LINES;
917 /* Use at least the requisition size... */
918 gtk_widget_size_request (widget, &req);
919 width = MAX (width, req.width);
920 height = MAX (height, req.height);
922 /* ... but no larger than the monitor */
923 screen = gtk_widget_get_screen (widget);
924 monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
926 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
928 width = MIN (width, monitor.width * 3 / 4);
929 height = MIN (height, monitor.height * 3 / 4);
932 gtk_widget_set_size_request (impl->recent_view, width, height);
936 gtk_recent_chooser_default_map (GtkWidget *widget)
938 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (widget);
940 if (GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map)
941 GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);
943 /* reloads everything */
944 reload_recent_items (impl);
946 set_default_size (impl);
950 recent_icon_data_func (GtkTreeViewColumn *tree_column,
951 GtkCellRenderer *cell,
956 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
957 GtkRecentInfo *info = NULL;
960 gtk_tree_model_get (model, iter,
961 RECENT_INFO_COLUMN, &info,
963 g_assert (info != NULL);
965 pixbuf = gtk_recent_info_get_icon (info, impl->icon_size);
972 g_object_unref (pixbuf);
974 gtk_recent_info_unref (info);
978 recent_meta_data_func (GtkTreeViewColumn *tree_column,
979 GtkCellRenderer *cell,
984 GtkRecentInfo *info = NULL;
987 gtk_tree_model_get (model, iter,
988 RECENT_DISPLAY_NAME_COLUMN, &name,
989 RECENT_INFO_COLUMN, &info,
991 g_assert (info != NULL);
994 name = gtk_recent_info_get_short_name (info);
996 g_object_set (cell, "text", name, NULL);
999 gtk_recent_info_unref (info);
1004 gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser)
1006 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1008 g_assert (impl->selection != NULL);
1010 if (!impl->select_multiple)
1012 GtkTreeModel *model;
1016 if (!gtk_tree_selection_get_selected (impl->selection, &model, &iter))
1019 gtk_tree_model_get (model, &iter, RECENT_URI_COLUMN, &uri, -1);
1030 guint do_select : 1;
1031 guint do_activate : 1;
1035 GtkRecentChooserDefault *impl;
1039 scan_for_uri_cb (GtkTreeModel *model,
1044 SelectURIData *select_data = (SelectURIData *) user_data;
1050 if (select_data->found)
1053 gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1);
1057 if (strcmp (uri, select_data->uri) == 0)
1059 select_data->found = TRUE;
1061 if (select_data->do_activate)
1062 gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->recent_view),
1064 select_data->impl->meta_column);
1066 if (select_data->do_select)
1067 gtk_tree_selection_select_path (select_data->impl->selection, path);
1069 gtk_tree_selection_unselect_path (select_data->impl->selection, path);
1082 gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
1086 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1087 SelectURIData *data;
1089 data = g_new0 (SelectURIData, 1);
1090 data->uri = g_strdup (uri);
1092 data->found = FALSE;
1093 data->do_activate = TRUE;
1094 data->do_select = TRUE;
1096 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1105 g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1106 GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1107 _("No item for URI '%s' found"),
1119 gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
1123 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1124 SelectURIData *data;
1126 data = g_new0 (SelectURIData, 1);
1127 data->uri = g_strdup (uri);
1129 data->found = FALSE;
1130 data->do_activate = FALSE;
1131 data->do_select = TRUE;
1133 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1142 g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1143 GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1144 _("No item for URI '%s' found"),
1156 gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
1159 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1160 SelectURIData *data;
1162 data = g_new0 (SelectURIData, 1);
1163 data->uri = g_strdup (uri);
1165 data->found = FALSE;
1166 data->do_activate = FALSE;
1167 data->do_select = FALSE;
1169 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1178 gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser)
1180 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1182 if (!impl->select_multiple)
1185 gtk_tree_selection_select_all (impl->selection);
1189 gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser)
1191 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1193 gtk_tree_selection_unselect_all (impl->selection);
1197 gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
1198 GtkRecentSortFunc sort_func,
1200 GDestroyNotify data_destroy)
1202 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1204 if (impl->sort_data_destroy)
1206 impl->sort_data_destroy (impl->sort_data);
1207 impl->sort_data_destroy = NULL;
1210 impl->sort_func = NULL;
1211 impl->sort_data = NULL;
1215 impl->sort_func = sort_func;
1216 impl->sort_data = sort_data;
1217 impl->sort_data_destroy = data_destroy;
1222 gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser)
1224 GtkRecentChooserDefault *impl;
1226 impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1228 return _gtk_recent_chooser_get_items (chooser,
1229 impl->current_filter,
1234 static GtkRecentManager *
1235 gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser)
1237 return GTK_RECENT_CHOOSER_DEFAULT (chooser)->manager;
1241 show_filters (GtkRecentChooserDefault *impl,
1245 gtk_widget_show (impl->filter_combo_hbox);
1247 gtk_widget_hide (impl->filter_combo_hbox);
1251 gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
1252 GtkRecentFilter *filter)
1254 GtkRecentChooserDefault *impl;
1257 impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1259 if (g_slist_find (impl->filters, filter))
1261 g_warning ("gtk_recent_chooser_add_filter() called on filter already in list\n");
1265 g_object_ref_sink (filter);
1266 impl->filters = g_slist_append (impl->filters, filter);
1268 /* display new filter */
1269 name = gtk_recent_filter_get_name (filter);
1271 name = _("Untitled filter");
1273 gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
1275 if (!g_slist_find (impl->filters, impl->current_filter))
1276 set_current_filter (impl, filter);
1278 show_filters (impl, TRUE);
1282 gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
1283 GtkRecentFilter *filter)
1285 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1286 GtkTreeModel *model;
1290 filter_idx = g_slist_index (impl->filters, filter);
1294 g_warning ("gtk_recent_chooser_remove_filter() called on filter not in list\n");
1298 impl->filters = g_slist_remove (impl->filters, filter);
1300 if (filter == impl->current_filter)
1303 set_current_filter (impl, impl->filters->data);
1305 set_current_filter (impl, NULL);
1308 model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
1309 gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_idx);
1310 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1312 g_object_unref (filter);
1315 show_filters (impl, FALSE);
1319 gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser)
1321 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1323 return g_slist_copy (impl->filters);
1327 set_current_filter (GtkRecentChooserDefault *impl,
1328 GtkRecentFilter *filter)
1330 if (impl->current_filter != filter)
1334 filter_idx = g_slist_index (impl->filters, filter);
1335 if (impl->filters && filter && filter_idx < 0)
1338 if (impl->current_filter)
1339 g_object_unref (impl->current_filter);
1341 impl->current_filter = filter;
1343 if (impl->current_filter)
1345 g_object_ref_sink (impl->current_filter);
1349 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
1352 if (impl->recent_store)
1353 reload_recent_items (impl);
1355 g_object_notify (G_OBJECT (impl), "filter");
1360 chooser_set_sort_type (GtkRecentChooserDefault *impl,
1361 GtkRecentSortType sort_type)
1363 if (impl->sort_type != sort_type)
1365 impl->sort_type = sort_type;
1366 reload_recent_items (impl);
1368 g_object_notify (G_OBJECT (impl), "sort-type");
1373 static GtkIconTheme *
1374 get_icon_theme_for_widget (GtkWidget *widget)
1376 if (gtk_widget_has_screen (widget))
1377 return gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
1379 return gtk_icon_theme_get_default ();
1383 get_icon_size_for_widget (GtkWidget *widget,
1384 GtkIconSize icon_size)
1386 GtkSettings *settings;
1389 if (gtk_widget_has_screen (widget))
1390 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
1392 settings = gtk_settings_get_default ();
1394 if (gtk_icon_size_lookup_for_settings (settings, icon_size,
1396 return MAX (width, height);
1398 return FALLBACK_ICON_SIZE;
1402 get_recent_files_limit (GtkWidget *widget)
1404 GtkSettings *settings;
1407 if (gtk_widget_has_screen (widget))
1408 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
1410 settings = gtk_settings_get_default ();
1412 g_object_get (G_OBJECT (settings), "gtk-recent-files-limit", &limit, NULL);
1418 recent_manager_changed_cb (GtkRecentManager *manager,
1421 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1423 reload_recent_items (impl);
1427 selection_changed_cb (GtkTreeSelection *selection,
1430 _gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
1434 row_activated_cb (GtkTreeView *tree_view,
1435 GtkTreePath *tree_path,
1436 GtkTreeViewColumn *tree_column,
1439 _gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
1443 filter_combo_changed_cb (GtkComboBox *combo_box,
1446 GtkRecentChooserDefault *impl;
1448 GtkRecentFilter *filter;
1450 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1452 new_index = gtk_combo_box_get_active (combo_box);
1453 filter = g_slist_nth_data (impl->filters, new_index);
1455 set_current_filter (impl, filter);
1459 get_drag_pixbuf (GtkRecentChooserDefault *impl)
1461 GtkRecentInfo *info;
1465 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1467 info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1471 size = get_icon_size_for_widget (GTK_WIDGET (impl), GTK_ICON_SIZE_DND);
1473 retval = gtk_recent_info_get_icon (info, size);
1474 gtk_recent_info_unref (info);
1480 recent_view_drag_begin_cb (GtkWidget *widget,
1481 GdkDragContext *context,
1484 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1487 pixbuf = get_drag_pixbuf (impl);
1490 gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
1491 g_object_unref (pixbuf);
1494 gtk_drag_set_icon_default (context);
1504 append_uri_to_urilist (GtkTreeModel *model,
1509 DragData *drag_data = (DragData *) user_data;
1510 GtkTreeModel *child_model;
1511 GtkTreeIter child_iter;
1515 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
1516 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
1519 gtk_tree_model_get (child_model, &child_iter,
1520 RECENT_URI_COLUMN, &uri,
1522 g_assert (uri != NULL);
1524 pos = drag_data->next_pos;
1525 drag_data->uri_list[pos] = g_strdup (uri);
1526 drag_data->next_pos = pos + 1;
1530 recent_view_drag_data_get_cb (GtkWidget *widget,
1531 GdkDragContext *context,
1532 GtkSelectionData *selection_data,
1537 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
1538 DragData *drag_data;
1541 n_uris = gtk_tree_selection_count_selected_rows (impl->selection);
1545 drag_data = g_new (DragData, 1);
1546 drag_data->uri_list = g_new0 (gchar *, n_uris + 1);
1547 drag_data->next_pos = 0;
1549 gtk_tree_selection_selected_foreach (impl->selection,
1550 append_uri_to_urilist,
1553 gtk_selection_data_set_uris (selection_data, drag_data->uri_list);
1555 g_strfreev (drag_data->uri_list);
1560 recent_view_query_tooltip_cb (GtkWidget *widget,
1563 gboolean keyboard_tip,
1564 GtkTooltip *tooltip,
1567 GtkRecentChooserDefault *impl = user_data;
1568 GtkTreeView *tree_view;
1570 GtkTreePath *path = NULL;
1571 GtkRecentInfo *info = NULL;
1574 if (!impl->show_tips)
1577 tree_view = GTK_TREE_VIEW (impl->recent_view);
1579 gtk_tree_view_get_tooltip_context (tree_view,
1586 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_store), &iter, path))
1588 gtk_tree_path_free (path);
1592 gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_store), &iter,
1593 RECENT_INFO_COLUMN, &info,
1596 uri_display = gtk_recent_info_get_uri_display (info);
1598 gtk_tooltip_set_text (tooltip, uri_display);
1599 gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
1601 g_free (uri_display);
1602 gtk_tree_path_free (path);
1603 gtk_recent_info_unref (info);
1609 remove_selected_from_list (GtkRecentChooserDefault *impl)
1614 if (impl->select_multiple)
1617 uri = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (impl));
1622 if (!gtk_recent_manager_remove_item (impl->manager, uri, &err))
1626 msg = strdup (_("Could not remove item"));
1627 error_message (impl, msg, err->message);
1637 copy_activated_cb (GtkMenuItem *menu_item,
1640 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1641 GtkRecentInfo *info;
1644 info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1648 utf8_uri = gtk_recent_info_get_uri_display (info);
1650 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (impl),
1651 GDK_SELECTION_CLIPBOARD),
1658 remove_all_activated_cb (GtkMenuItem *menu_item,
1661 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1664 gtk_recent_manager_purge_items (impl->manager, &err);
1669 msg = g_strdup (_("Could not clear list"));
1671 error_message (impl, msg, err->message);
1679 remove_item_activated_cb (GtkMenuItem *menu_item,
1682 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1684 remove_selected_from_list (impl);
1688 show_private_toggled_cb (GtkCheckMenuItem *menu_item,
1691 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1693 g_object_set (G_OBJECT (impl),
1694 "show-private", gtk_check_menu_item_get_active (menu_item),
1699 recent_popup_menu_detach_cb (GtkWidget *attach_widget,
1702 GtkRecentChooserDefault *impl;
1704 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkRecentChooserDefault");
1705 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1707 impl->recent_popup_menu = NULL;
1708 impl->recent_popup_menu_remove_item = NULL;
1709 impl->recent_popup_menu_copy_item = NULL;
1710 impl->recent_popup_menu_clear_item = NULL;
1711 impl->recent_popup_menu_show_private_item = NULL;
1715 recent_view_menu_ensure_state (GtkRecentChooserDefault *impl)
1719 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1720 g_assert (impl->recent_popup_menu != NULL);
1725 g_object_get (G_OBJECT (impl->manager), "size", &count, NULL);
1729 gtk_widget_set_sensitive (impl->recent_popup_menu_remove_item, FALSE);
1730 gtk_widget_set_sensitive (impl->recent_popup_menu_copy_item, FALSE);
1731 gtk_widget_set_sensitive (impl->recent_popup_menu_clear_item, FALSE);
1732 gtk_widget_set_sensitive (impl->recent_popup_menu_show_private_item, FALSE);
1737 recent_view_menu_build (GtkRecentChooserDefault *impl)
1741 if (impl->recent_popup_menu)
1743 recent_view_menu_ensure_state (impl);
1748 impl->recent_popup_menu = gtk_menu_new ();
1749 gtk_menu_attach_to_widget (GTK_MENU (impl->recent_popup_menu),
1751 recent_popup_menu_detach_cb);
1753 item = gtk_image_menu_item_new_with_mnemonic (_("Copy _Location"));
1754 impl->recent_popup_menu_copy_item = item;
1755 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1756 gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU));
1757 g_signal_connect (item, "activate",
1758 G_CALLBACK (copy_activated_cb), impl);
1759 gtk_widget_show (item);
1760 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1762 item = gtk_separator_menu_item_new ();
1763 gtk_widget_show (item);
1764 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1766 item = gtk_image_menu_item_new_with_mnemonic (_("_Remove From List"));
1767 impl->recent_popup_menu_remove_item = item;
1768 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1769 gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
1770 g_signal_connect (item, "activate",
1771 G_CALLBACK (remove_item_activated_cb), impl);
1772 gtk_widget_show (item);
1773 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1775 item = gtk_image_menu_item_new_with_mnemonic (_("_Clear List"));
1776 impl->recent_popup_menu_clear_item = item;
1777 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1778 gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
1779 g_signal_connect (item, "activate",
1780 G_CALLBACK (remove_all_activated_cb), impl);
1782 gtk_widget_show (item);
1783 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1785 item = gtk_separator_menu_item_new ();
1786 gtk_widget_show (item);
1787 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1789 item = gtk_check_menu_item_new_with_mnemonic (_("Show _Private Resources"));
1790 impl->recent_popup_menu_show_private_item = item;
1791 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), impl->show_private);
1792 g_signal_connect (item, "toggled",
1793 G_CALLBACK (show_private_toggled_cb), impl);
1794 gtk_widget_show (item);
1795 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1797 recent_view_menu_ensure_state (impl);
1800 /* taken from gtkfilechooserdefault.c */
1802 popup_position_func (GtkMenu *menu,
1808 GtkWidget *widget = GTK_WIDGET (user_data);
1809 GdkScreen *screen = gtk_widget_get_screen (widget);
1812 GdkRectangle monitor;
1814 if (G_UNLIKELY (!GTK_WIDGET_REALIZED (widget)))
1817 gdk_window_get_origin (widget->window, x, y);
1819 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1821 *x += (widget->allocation.width - req.width) / 2;
1822 *y += (widget->allocation.height - req.height) / 2;
1824 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
1825 gtk_menu_set_monitor (menu, monitor_num);
1826 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1828 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
1829 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
1836 recent_view_menu_popup (GtkRecentChooserDefault *impl,
1837 GdkEventButton *event)
1839 recent_view_menu_build (impl);
1842 gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1843 NULL, NULL, NULL, NULL,
1844 event->button, event->time);
1847 gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1849 popup_position_func, impl->recent_view,
1850 0, GDK_CURRENT_TIME);
1851 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->recent_popup_menu),
1857 recent_view_popup_menu_cb (GtkWidget *widget,
1860 recent_view_menu_popup (GTK_RECENT_CHOOSER_DEFAULT (user_data), NULL);
1865 recent_view_button_press_cb (GtkWidget *widget,
1866 GdkEventButton *event,
1869 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1871 if (event->button == 3)
1876 if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (impl->recent_view)))
1879 res = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (impl->recent_view),
1886 /* select the path before creating the popup menu */
1887 gtk_tree_selection_select_path (impl->selection, path);
1888 gtk_tree_path_free (path);
1890 recent_view_menu_popup (impl, event);
1899 set_recent_manager (GtkRecentChooserDefault *impl,
1900 GtkRecentManager *manager)
1904 if (impl->manager_changed_id)
1906 g_signal_handler_disconnect (impl, impl->manager_changed_id);
1907 impl->manager_changed_id = 0;
1910 impl->manager = NULL;
1914 impl->manager = manager;
1916 impl->manager = gtk_recent_manager_get_default ();
1920 impl->manager_changed_id = g_signal_connect (impl->manager, "changed",
1921 G_CALLBACK (recent_manager_changed_cb),
1927 _gtk_recent_chooser_default_new (GtkRecentManager *manager)
1929 return g_object_new (GTK_TYPE_RECENT_CHOOSER_DEFAULT,
1930 "recent-manager", manager,