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 "gtktooltips.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;
104 GtkRecentFilter *current_filter;
105 GtkWidget *filter_combo_hbox;
106 GtkWidget *filter_combo;
108 GtkRecentSortFunc sort_func;
110 GDestroyNotify sort_data_destroy;
112 GtkTooltips *tooltips;
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);
227 static void reload_recent_items (GtkRecentChooserDefault *impl);
228 static void chooser_set_model (GtkRecentChooserDefault *impl);
230 static void set_recent_manager (GtkRecentChooserDefault *impl,
231 GtkRecentManager *manager);
233 static void chooser_set_sort_type (GtkRecentChooserDefault *impl,
234 GtkRecentSortType sort_type);
236 static void recent_manager_changed_cb (GtkRecentManager *manager,
238 static void recent_icon_data_func (GtkTreeViewColumn *tree_column,
239 GtkCellRenderer *cell,
243 static void recent_meta_data_func (GtkTreeViewColumn *tree_column,
244 GtkCellRenderer *cell,
249 static void selection_changed_cb (GtkTreeSelection *z,
251 static void row_activated_cb (GtkTreeView *tree_view,
252 GtkTreePath *tree_path,
253 GtkTreeViewColumn *tree_column,
255 static void filter_combo_changed_cb (GtkComboBox *combo_box,
258 static void remove_all_activated_cb (GtkMenuItem *menu_item,
260 static void remove_item_activated_cb (GtkMenuItem *menu_item,
262 static void show_private_toggled_cb (GtkCheckMenuItem *menu_item,
265 static gboolean recent_view_popup_menu_cb (GtkWidget *widget,
267 static gboolean recent_view_button_press_cb (GtkWidget *widget,
268 GdkEventButton *event,
271 static void recent_view_drag_begin_cb (GtkWidget *widget,
272 GdkDragContext *context,
274 static void recent_view_drag_data_get_cb (GtkWidget *widget,
275 GdkDragContext *context,
276 GtkSelectionData *selection_data,
281 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDefault,
282 _gtk_recent_chooser_default,
284 G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
285 gtk_recent_chooser_iface_init))
291 gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
293 iface->set_current_uri = gtk_recent_chooser_default_set_current_uri;
294 iface->get_current_uri = gtk_recent_chooser_default_get_current_uri;
295 iface->select_uri = gtk_recent_chooser_default_select_uri;
296 iface->unselect_uri = gtk_recent_chooser_default_unselect_uri;
297 iface->select_all = gtk_recent_chooser_default_select_all;
298 iface->unselect_all = gtk_recent_chooser_default_unselect_all;
299 iface->get_items = gtk_recent_chooser_default_get_items;
300 iface->get_recent_manager = gtk_recent_chooser_default_get_recent_manager;
301 iface->set_sort_func = gtk_recent_chooser_default_set_sort_func;
302 iface->add_filter = gtk_recent_chooser_default_add_filter;
303 iface->remove_filter = gtk_recent_chooser_default_remove_filter;
304 iface->list_filters = gtk_recent_chooser_default_list_filters;
308 _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
310 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
311 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
313 gobject_class->constructor = gtk_recent_chooser_default_constructor;
314 gobject_class->set_property = gtk_recent_chooser_default_set_property;
315 gobject_class->get_property = gtk_recent_chooser_default_get_property;
316 gobject_class->dispose = gtk_recent_chooser_default_dispose;
317 gobject_class->finalize = gtk_recent_chooser_default_finalize;
319 widget_class->map = gtk_recent_chooser_default_map;
320 widget_class->show_all = gtk_recent_chooser_default_show_all;
322 _gtk_recent_chooser_install_properties (gobject_class);
326 _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
328 gtk_box_set_spacing (GTK_BOX (impl), 6);
330 /* by default, we use the global manager */
331 impl->local_manager = FALSE;
333 impl->limit = FALLBACK_ITEM_LIMIT;
334 impl->sort_type = GTK_RECENT_SORT_NONE;
336 impl->show_icons = TRUE;
337 impl->show_private = FALSE;
338 impl->show_not_found = TRUE;
339 impl->show_tips = TRUE;
340 impl->select_multiple = FALSE;
341 impl->local_only = TRUE;
343 impl->icon_size = FALLBACK_ICON_SIZE;
344 impl->icon_theme = NULL;
346 impl->current_filter = NULL;
348 impl->tooltips = gtk_tooltips_new ();
349 g_object_ref_sink (impl->tooltips);
351 impl->recent_items = NULL;
352 impl->n_recent_items = 0;
353 impl->loaded_items = 0;
355 impl->load_state = LOAD_EMPTY;
359 gtk_recent_chooser_default_constructor (GType type,
361 GObjectConstructParam *params)
363 GObjectClass *parent_class;
364 GtkRecentChooserDefault *impl;
367 GtkCellRenderer *renderer;
369 parent_class = G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class);
370 object = parent_class->constructor (type, n_params, params);
371 impl = GTK_RECENT_CHOOSER_DEFAULT (object);
373 g_assert (impl->manager);
375 gtk_widget_push_composite_child ();
377 scrollw = gtk_scrolled_window_new (NULL, NULL);
378 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollw),
380 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollw),
381 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
382 gtk_box_pack_start (GTK_BOX (impl), scrollw, TRUE, TRUE, 0);
383 gtk_widget_show (scrollw);
385 impl->recent_view = gtk_tree_view_new ();
386 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->recent_view), FALSE);
387 g_signal_connect (impl->recent_view, "row-activated",
388 G_CALLBACK (row_activated_cb), impl);
389 g_signal_connect (impl->recent_view, "popup-menu",
390 G_CALLBACK (recent_view_popup_menu_cb), impl);
391 g_signal_connect (impl->recent_view, "button-press-event",
392 G_CALLBACK (recent_view_button_press_cb), impl);
393 g_signal_connect (impl->recent_view, "drag_begin",
394 G_CALLBACK (recent_view_drag_begin_cb), impl);
395 g_signal_connect (impl->recent_view, "drag_data_get",
396 G_CALLBACK (recent_view_drag_data_get_cb), impl);
398 g_object_set_data (G_OBJECT (impl->recent_view),
399 "GtkRecentChooserDefault", impl);
401 gtk_container_add (GTK_CONTAINER (scrollw), impl->recent_view);
402 gtk_widget_show (impl->recent_view);
404 impl->icon_column = gtk_tree_view_column_new ();
405 gtk_tree_view_column_set_expand (impl->icon_column, FALSE);
406 gtk_tree_view_column_set_resizable (impl->icon_column, FALSE);
408 renderer = gtk_cell_renderer_pixbuf_new ();
409 gtk_tree_view_column_pack_start (impl->icon_column, renderer, FALSE);
410 gtk_tree_view_column_set_cell_data_func (impl->icon_column,
412 recent_icon_data_func,
415 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->recent_view),
418 impl->meta_column = gtk_tree_view_column_new ();
419 gtk_tree_view_column_set_expand (impl->meta_column, TRUE);
420 gtk_tree_view_column_set_resizable (impl->meta_column, FALSE);
422 impl->meta_renderer = gtk_cell_renderer_text_new ();
423 g_object_set (G_OBJECT (impl->meta_renderer),
424 "ellipsize", PANGO_ELLIPSIZE_END,
426 gtk_tree_view_column_pack_start (impl->meta_column, impl->meta_renderer, TRUE);
427 gtk_tree_view_column_set_cell_data_func (impl->meta_column,
429 recent_meta_data_func,
432 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->recent_view),
435 impl->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->recent_view));
436 gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_SINGLE);
437 g_signal_connect (impl->selection, "changed", G_CALLBACK (selection_changed_cb), impl);
440 gtk_drag_source_set (impl->recent_view,
442 recent_list_source_targets,
443 G_N_ELEMENTS (recent_list_source_targets),
446 impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
448 impl->filter_combo = gtk_combo_box_new_text ();
449 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
450 g_signal_connect (impl->filter_combo, "changed",
451 G_CALLBACK (filter_combo_changed_cb), impl);
452 gtk_tooltips_set_tip (impl->tooltips,
454 _("Select which type of documents are shown"),
457 gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox),
460 gtk_widget_show (impl->filter_combo);
462 gtk_box_pack_end (GTK_BOX (impl), impl->filter_combo_hbox, FALSE, FALSE, 0);
464 gtk_widget_pop_composite_child ();
466 impl->recent_store = gtk_list_store_new (N_RECENT_COLUMNS,
467 G_TYPE_STRING, /* uri */
468 G_TYPE_STRING, /* display_name */
469 GTK_TYPE_RECENT_INFO /* info */);
475 gtk_recent_chooser_default_set_property (GObject *object,
480 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
484 case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
485 set_recent_manager (impl, g_value_get_object (value));
487 case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
488 impl->show_private = g_value_get_boolean (value);
489 if (impl->recent_popup_menu_show_private_item)
491 GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (impl->recent_popup_menu_show_private_item);
492 g_signal_handlers_block_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
493 gtk_check_menu_item_set_active (item, impl->show_private);
494 g_signal_handlers_unblock_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
496 reload_recent_items (impl);
498 case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
499 impl->show_not_found = g_value_get_boolean (value);
500 reload_recent_items (impl);
502 case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
503 impl->show_tips = g_value_get_boolean (value);
506 gtk_tooltips_enable (impl->tooltips);
508 gtk_tooltips_disable (impl->tooltips);
510 case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
511 impl->show_icons = g_value_get_boolean (value);
512 gtk_tree_view_column_set_visible (impl->icon_column, impl->show_icons);
514 case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
515 impl->select_multiple = g_value_get_boolean (value);
517 if (impl->select_multiple)
518 gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_MULTIPLE);
520 gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_SINGLE);
522 case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
523 impl->local_only = g_value_get_boolean (value);
524 reload_recent_items (impl);
526 case GTK_RECENT_CHOOSER_PROP_LIMIT:
527 impl->limit = g_value_get_int (value);
528 reload_recent_items (impl);
530 case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
531 chooser_set_sort_type (impl, g_value_get_enum (value));
533 case GTK_RECENT_CHOOSER_PROP_FILTER:
534 set_current_filter (impl, g_value_get_object (value));
537 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
543 gtk_recent_chooser_default_get_property (GObject *object,
548 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
552 case GTK_RECENT_CHOOSER_PROP_LIMIT:
553 g_value_set_int (value, impl->limit);
555 case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
556 g_value_set_enum (value, impl->sort_type);
558 case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
559 g_value_set_boolean (value, impl->show_private);
561 case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
562 g_value_set_boolean (value, impl->show_icons);
564 case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
565 g_value_set_boolean (value, impl->show_not_found);
567 case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
568 g_value_set_boolean (value, impl->show_tips);
570 case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
571 g_value_set_boolean (value, impl->local_only);
573 case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
574 g_value_set_boolean (value, impl->select_multiple);
576 case GTK_RECENT_CHOOSER_PROP_FILTER:
577 g_value_set_object (value, impl->current_filter);
580 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
586 gtk_recent_chooser_default_dispose (GObject *object)
588 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
592 g_source_remove (impl->load_id);
596 if (impl->recent_items)
598 g_list_foreach (impl->recent_items, (GFunc) gtk_recent_info_unref, NULL);
599 g_list_free (impl->recent_items);
600 impl->recent_items = NULL;
603 if (impl->manager_changed_id)
605 g_signal_handler_disconnect (impl->manager, impl->manager_changed_id);
606 impl->manager_changed_id = 0;
611 g_slist_foreach (impl->filters, (GFunc) g_object_unref, NULL);
612 g_slist_free (impl->filters);
613 impl->filters = NULL;
616 if (impl->current_filter)
618 g_object_unref (impl->current_filter);
619 impl->current_filter = NULL;
622 if (impl->recent_store)
624 g_object_unref (impl->recent_store);
625 impl->recent_store = NULL;
630 g_object_unref (impl->tooltips);
631 impl->tooltips = NULL;
634 G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->dispose (object);
638 gtk_recent_chooser_default_finalize (GObject *object)
640 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
642 impl->manager = NULL;
644 if (impl->sort_data_destroy)
646 impl->sort_data_destroy (impl->sort_data);
647 impl->sort_data_destroy = NULL;
650 impl->sort_data = NULL;
651 impl->sort_func = NULL;
653 G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->finalize (object);
656 /* override GtkWidget::show_all since we have internal widgets we wish to keep
657 * hidden unless we decide otherwise, like the filter combo box.
660 gtk_recent_chooser_default_show_all (GtkWidget *widget)
662 gtk_widget_show (widget);
667 /* Shows an error dialog set as transient for the specified window */
669 error_message_with_parent (GtkWindow *parent,
675 dialog = gtk_message_dialog_new (parent,
676 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
681 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
685 gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
687 gtk_dialog_run (GTK_DIALOG (dialog));
688 gtk_widget_destroy (dialog);
691 /* Returns a toplevel GtkWindow, or NULL if none */
693 get_toplevel (GtkWidget *widget)
697 toplevel = gtk_widget_get_toplevel (widget);
698 if (!GTK_WIDGET_TOPLEVEL (toplevel))
701 return GTK_WINDOW (toplevel);
704 /* Shows an error dialog for the file chooser */
706 error_message (GtkRecentChooserDefault *impl,
710 error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
714 set_busy_cursor (GtkRecentChooserDefault *impl,
715 gboolean show_busy_cursor)
721 toplevel = get_toplevel (GTK_WIDGET (impl));
722 if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
725 display = gtk_widget_get_display (GTK_WIDGET (toplevel));
728 if (show_busy_cursor)
729 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
731 gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
732 gdk_display_flush (display);
735 gdk_cursor_unref (cursor);
739 chooser_set_model (GtkRecentChooserDefault *impl)
741 g_assert (impl->recent_store != NULL);
742 g_assert (impl->load_state == LOAD_LOADING);
744 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->recent_view),
745 GTK_TREE_MODEL (impl->recent_store));
746 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->recent_view));
747 gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->recent_view), TRUE);
748 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->recent_view),
749 RECENT_DISPLAY_NAME_COLUMN);
751 impl->load_state = LOAD_FINISHED;
755 load_recent_items (gpointer user_data)
757 GtkRecentChooserDefault *impl;
760 const gchar *uri, *name;
763 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
765 g_assert ((impl->load_state == LOAD_EMPTY) ||
766 (impl->load_state == LOAD_PRELOAD));
768 /* store the items for multiple runs */
769 if (!impl->recent_items)
771 impl->recent_items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (impl));
772 if (!impl->recent_items)
774 impl->load_state = LOAD_FINISHED;
779 impl->n_recent_items = g_list_length (impl->recent_items);
780 impl->loaded_items = 0;
781 impl->load_state = LOAD_PRELOAD;
784 info = (GtkRecentInfo *) g_list_nth_data (impl->recent_items,
788 uri = gtk_recent_info_get_uri (info);
789 name = gtk_recent_info_get_display_name (info);
791 /* at this point, everything goes inside the model; operations on the
792 * visualization of items inside the model are done in the cell data
793 * funcs (remember that there are two of those: one for the icon and
794 * one for the text), while the filtering is done only when a filter
795 * is actually loaded. */
796 gtk_list_store_append (impl->recent_store, &iter);
797 gtk_list_store_set (impl->recent_store, &iter,
798 RECENT_URI_COLUMN, uri, /* uri */
799 RECENT_DISPLAY_NAME_COLUMN, name, /* display_name */
800 RECENT_INFO_COLUMN, info, /* info */
803 impl->loaded_items += 1;
805 if (impl->loaded_items == impl->n_recent_items)
807 /* we have finished loading, so we remove the items cache */
808 impl->load_state = LOAD_LOADING;
810 g_list_foreach (impl->recent_items,
811 (GFunc) gtk_recent_info_unref,
813 g_list_free (impl->recent_items);
815 impl->recent_items = NULL;
816 impl->n_recent_items = 0;
817 impl->loaded_items = 0;
819 /* load the filled up model */
820 chooser_set_model (impl);
826 /* we did not finish, so continue loading */
834 cleanup_after_load (gpointer user_data)
836 GtkRecentChooserDefault *impl;
838 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
840 if (impl->load_id != 0)
842 g_assert ((impl->load_state == LOAD_PRELOAD) ||
843 (impl->load_state == LOAD_LOADING) ||
844 (impl->load_state == LOAD_FINISHED));
846 /* we have officialy finished loading all the items,
847 * so we can reset the state machine
849 g_source_remove (impl->load_id);
851 impl->load_state = LOAD_EMPTY;
854 g_assert ((impl->load_state == LOAD_EMPTY) ||
855 (impl->load_state == LOAD_LOADING) ||
856 (impl->load_state == LOAD_FINISHED));
858 set_busy_cursor (impl, FALSE);
861 /* clears the current model and reloads the recently used resources */
863 reload_recent_items (GtkRecentChooserDefault *impl)
865 /* reload is already in progress - do not disturb */
869 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->recent_view), NULL);
870 gtk_list_store_clear (impl->recent_store);
872 if (!impl->icon_theme)
873 impl->icon_theme = get_icon_theme_for_widget (GTK_WIDGET (impl));
875 impl->icon_size = get_icon_size_for_widget (GTK_WIDGET (impl),
876 GTK_ICON_SIZE_BUTTON);
878 set_busy_cursor (impl, TRUE);
880 impl->load_state = LOAD_EMPTY;
881 impl->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
887 /* taken form gtkfilechooserdialog.c */
889 set_default_size (GtkRecentChooserDefault *impl)
897 GdkRectangle monitor;
899 widget = GTK_WIDGET (impl);
901 /* Size based on characters and the icon size */
902 font_size = pango_font_description_get_size (widget->style->font_desc);
903 font_size = PANGO_PIXELS (font_size);
905 width = impl->icon_size + font_size * NUM_CHARS;
906 height = (impl->icon_size + font_size) * NUM_LINES;
908 /* Use at least the requisition size... */
909 gtk_widget_size_request (widget, &req);
910 width = MAX (width, req.width);
911 height = MAX (height, req.height);
913 /* ... but no larger than the monitor */
914 screen = gtk_widget_get_screen (widget);
915 monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
917 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
919 width = MIN (width, monitor.width * 3 / 4);
920 height = MIN (height, monitor.height * 3 / 4);
923 gtk_widget_set_size_request (impl->recent_view, width, height);
927 gtk_recent_chooser_default_map (GtkWidget *widget)
929 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (widget);
931 if (GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map)
932 GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);
934 /* reloads everything */
935 reload_recent_items (impl);
937 set_default_size (impl);
941 recent_icon_data_func (GtkTreeViewColumn *tree_column,
942 GtkCellRenderer *cell,
947 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
948 GtkRecentInfo *info = NULL;
951 gtk_tree_model_get (model, iter,
952 RECENT_INFO_COLUMN, &info,
954 g_assert (info != NULL);
956 pixbuf = gtk_recent_info_get_icon (info, impl->icon_size);
963 g_object_unref (pixbuf);
967 recent_meta_data_func (GtkTreeViewColumn *tree_column,
968 GtkCellRenderer *cell,
973 GtkRecentInfo *info = NULL;
978 data = g_string_new (NULL);
980 gtk_tree_model_get (model, iter,
981 RECENT_DISPLAY_NAME_COLUMN, &name,
982 RECENT_INFO_COLUMN, &info,
984 g_assert (info != NULL);
986 uri = gtk_recent_info_get_uri_display (info);
989 name = gtk_recent_info_get_short_name (info);
991 g_string_append_printf (data,
993 "<small>Location: %s</small>",
1001 g_string_free (data, TRUE);
1004 gtk_recent_info_unref (info);
1009 gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser)
1011 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1013 g_assert (impl->selection != NULL);
1015 if (!impl->select_multiple)
1017 GtkTreeModel *model;
1021 if (!gtk_tree_selection_get_selected (impl->selection, &model, &iter))
1024 gtk_tree_model_get (model, &iter, RECENT_URI_COLUMN, &uri, -1);
1035 guint do_select : 1;
1036 guint do_activate : 1;
1040 GtkRecentChooserDefault *impl;
1044 scan_for_uri_cb (GtkTreeModel *model,
1049 SelectURIData *select_data = (SelectURIData *) user_data;
1055 if (select_data->found)
1058 gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1);
1062 if (strcmp (uri, select_data->uri) == 0)
1064 select_data->found = TRUE;
1066 if (select_data->do_activate)
1067 gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->recent_view),
1069 select_data->impl->meta_column);
1071 if (select_data->do_select)
1072 gtk_tree_selection_select_path (select_data->impl->selection, path);
1074 gtk_tree_selection_unselect_path (select_data->impl->selection, path);
1087 gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
1091 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1092 SelectURIData *data;
1094 data = g_new0 (SelectURIData, 1);
1095 data->uri = g_strdup (uri);
1097 data->found = FALSE;
1098 data->do_activate = TRUE;
1099 data->do_select = TRUE;
1101 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1110 g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1111 GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1112 _("No item for URI '%s' found"),
1124 gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
1128 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1129 SelectURIData *data;
1131 data = g_new0 (SelectURIData, 1);
1132 data->uri = g_strdup (uri);
1134 data->found = FALSE;
1135 data->do_activate = FALSE;
1136 data->do_select = TRUE;
1138 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1147 g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1148 GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1149 _("No item for URI '%s' found"),
1161 gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
1164 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1165 SelectURIData *data;
1167 data = g_new0 (SelectURIData, 1);
1168 data->uri = g_strdup (uri);
1170 data->found = FALSE;
1171 data->do_activate = FALSE;
1172 data->do_select = FALSE;
1174 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1183 gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser)
1185 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1187 if (!impl->select_multiple)
1190 gtk_tree_selection_select_all (impl->selection);
1194 gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser)
1196 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1198 gtk_tree_selection_unselect_all (impl->selection);
1202 gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
1203 GtkRecentSortFunc sort_func,
1205 GDestroyNotify data_destroy)
1207 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1209 if (impl->sort_data_destroy)
1211 impl->sort_data_destroy (impl->sort_data);
1212 impl->sort_data_destroy = NULL;
1215 impl->sort_func = NULL;
1216 impl->sort_data = NULL;
1220 impl->sort_func = sort_func;
1221 impl->sort_data = sort_data;
1222 impl->sort_data_destroy = data_destroy;
1227 gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser)
1229 GtkRecentChooserDefault *impl;
1231 impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1233 return _gtk_recent_chooser_get_items (chooser,
1234 impl->current_filter,
1239 static GtkRecentManager *
1240 gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser)
1242 return GTK_RECENT_CHOOSER_DEFAULT (chooser)->manager;
1246 show_filters (GtkRecentChooserDefault *impl,
1250 gtk_widget_show (impl->filter_combo_hbox);
1252 gtk_widget_hide (impl->filter_combo_hbox);
1256 gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
1257 GtkRecentFilter *filter)
1259 GtkRecentChooserDefault *impl;
1262 impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1264 if (g_slist_find (impl->filters, filter))
1266 g_warning ("gtk_recent_chooser_add_filter() called on filter already in list\n");
1270 g_object_ref_sink (filter);
1271 impl->filters = g_slist_append (impl->filters, filter);
1273 /* display new filter */
1274 name = gtk_recent_filter_get_name (filter);
1276 name = "Untitled filter";
1278 gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
1280 if (!g_slist_find (impl->filters, impl->current_filter))
1281 set_current_filter (impl, filter);
1283 show_filters (impl, TRUE);
1287 gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
1288 GtkRecentFilter *filter)
1290 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1291 GtkTreeModel *model;
1295 filter_idx = g_slist_index (impl->filters, filter);
1299 g_warning ("gtk_recent_chooser_remove_filter() called on filter not in list\n");
1303 impl->filters = g_slist_remove (impl->filters, filter);
1305 if (filter == impl->current_filter)
1308 set_current_filter (impl, impl->filters->data);
1310 set_current_filter (impl, NULL);
1313 model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
1314 gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_idx);
1315 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1317 g_object_unref (filter);
1320 show_filters (impl, FALSE);
1324 gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser)
1326 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1328 return g_slist_copy (impl->filters);
1332 set_current_filter (GtkRecentChooserDefault *impl,
1333 GtkRecentFilter *filter)
1335 if (impl->current_filter != filter)
1339 filter_idx = g_slist_index (impl->filters, filter);
1340 if (impl->filters && filter && filter_idx < 0)
1343 if (impl->current_filter)
1344 g_object_unref (impl->current_filter);
1346 impl->current_filter = filter;
1348 if (impl->current_filter)
1350 g_object_ref_sink (impl->current_filter);
1354 gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
1357 if (impl->recent_store)
1358 reload_recent_items (impl);
1360 g_object_notify (G_OBJECT (impl), "filter");
1365 chooser_set_sort_type (GtkRecentChooserDefault *impl,
1366 GtkRecentSortType sort_type)
1368 if (impl->sort_type != sort_type)
1370 impl->sort_type = sort_type;
1371 reload_recent_items (impl);
1373 g_object_notify (G_OBJECT (impl), "sort-type");
1378 static GtkIconTheme *
1379 get_icon_theme_for_widget (GtkWidget *widget)
1381 if (gtk_widget_has_screen (widget))
1382 return gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
1384 return gtk_icon_theme_get_default ();
1388 get_icon_size_for_widget (GtkWidget *widget,
1389 GtkIconSize icon_size)
1391 GtkSettings *settings;
1394 if (gtk_widget_has_screen (widget))
1395 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
1397 settings = gtk_settings_get_default ();
1399 if (gtk_icon_size_lookup_for_settings (settings, icon_size,
1401 return MAX (width, height);
1403 return FALLBACK_ICON_SIZE;
1408 recent_manager_changed_cb (GtkRecentManager *manager,
1411 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1413 reload_recent_items (impl);
1417 selection_changed_cb (GtkTreeSelection *selection,
1420 _gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
1424 row_activated_cb (GtkTreeView *tree_view,
1425 GtkTreePath *tree_path,
1426 GtkTreeViewColumn *tree_column,
1429 _gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
1433 filter_combo_changed_cb (GtkComboBox *combo_box,
1436 GtkRecentChooserDefault *impl;
1438 GtkRecentFilter *filter;
1440 impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1442 new_index = gtk_combo_box_get_active (combo_box);
1443 filter = g_slist_nth_data (impl->filters, new_index);
1445 set_current_filter (impl, filter);
1449 get_drag_pixbuf (GtkRecentChooserDefault *impl)
1451 GtkRecentInfo *info;
1455 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1457 info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1461 size = get_icon_size_for_widget (GTK_WIDGET (impl), GTK_ICON_SIZE_DND);
1463 retval = gtk_recent_info_get_icon (info, size);
1464 gtk_recent_info_unref (info);
1470 recent_view_drag_begin_cb (GtkWidget *widget,
1471 GdkDragContext *context,
1474 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1477 pixbuf = get_drag_pixbuf (impl);
1480 gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
1481 g_object_unref (pixbuf);
1484 gtk_drag_set_icon_default (context);
1494 append_uri_to_urilist (GtkTreeModel *model,
1499 DragData *drag_data = (DragData *) user_data;
1500 GtkTreeModel *child_model;
1501 GtkTreeIter child_iter;
1505 child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
1506 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
1509 gtk_tree_model_get (child_model, &child_iter,
1510 RECENT_URI_COLUMN, &uri,
1512 g_assert (uri != NULL);
1514 pos = drag_data->next_pos;
1515 drag_data->uri_list[pos] = g_strdup (uri);
1516 drag_data->next_pos = pos + 1;
1520 recent_view_drag_data_get_cb (GtkWidget *widget,
1521 GdkDragContext *context,
1522 GtkSelectionData *selection_data,
1527 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
1528 DragData *drag_data;
1531 n_uris = gtk_tree_selection_count_selected_rows (impl->selection);
1535 drag_data = g_new (DragData, 1);
1536 drag_data->uri_list = g_new0 (gchar *, n_uris + 1);
1537 drag_data->next_pos = 0;
1539 gtk_tree_selection_selected_foreach (impl->selection,
1540 append_uri_to_urilist,
1543 gtk_selection_data_set_uris (selection_data, drag_data->uri_list);
1545 g_strfreev (drag_data->uri_list);
1552 remove_selected_from_list (GtkRecentChooserDefault *impl)
1557 if (impl->select_multiple)
1560 uri = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (impl));
1565 if (!gtk_recent_manager_remove_item (impl->manager, uri, &err))
1569 msg = strdup (_("Could not remove item"));
1570 error_message (impl, msg, err->message);
1580 copy_activated_cb (GtkMenuItem *menu_item,
1583 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1584 GtkRecentInfo *info;
1587 info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1591 utf8_uri = gtk_recent_info_get_uri_display (info);
1593 gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (impl),
1594 GDK_SELECTION_CLIPBOARD),
1601 remove_all_activated_cb (GtkMenuItem *menu_item,
1604 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1607 gtk_recent_manager_purge_items (impl->manager, &err);
1612 msg = g_strdup (_("Could not clear list"));
1614 error_message (impl, msg, err->message);
1622 remove_item_activated_cb (GtkMenuItem *menu_item,
1625 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1627 remove_selected_from_list (impl);
1631 show_private_toggled_cb (GtkCheckMenuItem *menu_item,
1634 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1636 g_object_set (G_OBJECT (impl),
1637 "show-private", gtk_check_menu_item_get_active (menu_item),
1642 recent_popup_menu_detach_cb (GtkWidget *attach_widget,
1645 GtkRecentChooserDefault *impl;
1647 impl = g_object_get_data (G_OBJECT (attach_widget), "GtkRecentChooserDefault");
1648 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1650 impl->recent_popup_menu = NULL;
1651 impl->recent_popup_menu_remove_item = NULL;
1652 impl->recent_popup_menu_copy_item = NULL;
1653 impl->recent_popup_menu_clear_item = NULL;
1654 impl->recent_popup_menu_show_private_item = NULL;
1658 recent_view_menu_ensure_state (GtkRecentChooserDefault *impl)
1662 g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1663 g_assert (impl->recent_popup_menu != NULL);
1668 g_object_get (G_OBJECT (impl->manager), "size", &count, NULL);
1672 gtk_widget_set_sensitive (impl->recent_popup_menu_remove_item, FALSE);
1673 gtk_widget_set_sensitive (impl->recent_popup_menu_copy_item, FALSE);
1674 gtk_widget_set_sensitive (impl->recent_popup_menu_clear_item, FALSE);
1675 gtk_widget_set_sensitive (impl->recent_popup_menu_show_private_item, FALSE);
1680 recent_view_menu_build (GtkRecentChooserDefault *impl)
1684 if (impl->recent_popup_menu)
1686 recent_view_menu_ensure_state (impl);
1691 impl->recent_popup_menu = gtk_menu_new ();
1692 gtk_menu_attach_to_widget (GTK_MENU (impl->recent_popup_menu),
1694 recent_popup_menu_detach_cb);
1696 item = gtk_image_menu_item_new_with_mnemonic (_("Copy _Location"));
1697 impl->recent_popup_menu_copy_item = item;
1698 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1699 gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU));
1700 g_signal_connect (item, "activate",
1701 G_CALLBACK (copy_activated_cb), impl);
1702 gtk_widget_show (item);
1703 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1705 item = gtk_separator_menu_item_new ();
1706 gtk_widget_show (item);
1707 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1709 item = gtk_image_menu_item_new_with_mnemonic (_("_Remove From List"));
1710 impl->recent_popup_menu_remove_item = item;
1711 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1712 gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
1713 g_signal_connect (item, "activate",
1714 G_CALLBACK (remove_item_activated_cb), impl);
1715 gtk_widget_show (item);
1716 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1718 item = gtk_image_menu_item_new_with_mnemonic (_("_Clear List"));
1719 impl->recent_popup_menu_clear_item = item;
1720 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1721 gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
1722 g_signal_connect (item, "activate",
1723 G_CALLBACK (remove_all_activated_cb), impl);
1725 gtk_widget_show (item);
1726 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1728 item = gtk_separator_menu_item_new ();
1729 gtk_widget_show (item);
1730 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1732 item = gtk_check_menu_item_new_with_mnemonic (_("Show _Private Resources"));
1733 impl->recent_popup_menu_show_private_item = item;
1734 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), impl->show_private);
1735 g_signal_connect (item, "toggled",
1736 G_CALLBACK (show_private_toggled_cb), impl);
1737 gtk_widget_show (item);
1738 gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1740 recent_view_menu_ensure_state (impl);
1743 /* taken from gtkfilechooserdefault.c */
1745 popup_position_func (GtkMenu *menu,
1751 GtkWidget *widget = GTK_WIDGET (user_data);
1752 GdkScreen *screen = gtk_widget_get_screen (widget);
1755 GdkRectangle monitor;
1757 if (G_UNLIKELY (!GTK_WIDGET_REALIZED (widget)))
1760 gdk_window_get_origin (widget->window, x, y);
1762 gtk_widget_size_request (GTK_WIDGET (menu), &req);
1764 *x += (widget->allocation.width - req.width) / 2;
1765 *y += (widget->allocation.height - req.height) / 2;
1767 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
1768 gtk_menu_set_monitor (menu, monitor_num);
1769 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1771 *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
1772 *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
1779 recent_view_menu_popup (GtkRecentChooserDefault *impl,
1780 GdkEventButton *event)
1782 recent_view_menu_build (impl);
1785 gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1786 NULL, NULL, NULL, NULL,
1787 event->button, event->time);
1790 gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1792 popup_position_func, impl->recent_view,
1793 0, GDK_CURRENT_TIME);
1794 gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->recent_popup_menu),
1800 recent_view_popup_menu_cb (GtkWidget *widget,
1803 recent_view_menu_popup (GTK_RECENT_CHOOSER_DEFAULT (user_data), NULL);
1808 recent_view_button_press_cb (GtkWidget *widget,
1809 GdkEventButton *event,
1812 GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1814 if (event->button == 3)
1819 if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (impl->recent_view)))
1822 res = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (impl->recent_view),
1829 /* select the path before creating the popup menu */
1830 gtk_tree_selection_select_path (impl->selection, path);
1831 gtk_tree_path_free (path);
1833 recent_view_menu_popup (impl, event);
1842 set_recent_manager (GtkRecentChooserDefault *impl,
1843 GtkRecentManager *manager)
1847 g_signal_handler_disconnect (impl, impl->manager_changed_id);
1848 impl->manager_changed_id = 0;
1850 impl->manager = NULL;
1854 impl->manager = manager;
1856 impl->manager = gtk_recent_manager_get_default ();
1859 impl->manager_changed_id = g_signal_connect (impl->manager, "changed",
1860 G_CALLBACK (recent_manager_changed_cb),
1865 _gtk_recent_chooser_default_new (GtkRecentManager *manager)
1867 return g_object_new (GTK_TYPE_RECENT_CHOOSER_DEFAULT,
1868 "recent-manager", manager,