2 * Copyright (C) 2007, Carlos Garcia Campos <carlosgc@gnome.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <glib/gi18n.h>
25 #include "ev-open-recent-action.h"
33 static void ev_open_recent_action_init (EvOpenRecentAction *action);
34 static void ev_open_recent_action_class_init (EvOpenRecentActionClass *class);
36 static guint action_signals[N_SIGNALS];
38 G_DEFINE_TYPE (EvOpenRecentAction, ev_open_recent_action, GTK_TYPE_ACTION)
41 recent_chooser_item_activated (GtkRecentChooser *chooser,
46 uri = gtk_recent_chooser_get_current_uri (chooser);
47 g_signal_emit (action, action_signals[ITEM_ACTIVATED], 0, uri);
52 ev_open_recent_action_create_tool_item (GtkAction *action)
55 GtkWidget *toolbar_recent_menu;
56 GtkRecentFilter *filter;
58 toolbar_recent_menu = gtk_recent_chooser_menu_new_for_manager (gtk_recent_manager_get_default ());
59 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (toolbar_recent_menu), FALSE);
60 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (toolbar_recent_menu), GTK_RECENT_SORT_MRU);
61 gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (toolbar_recent_menu), 5);
62 g_signal_connect (toolbar_recent_menu, "item_activated",
63 G_CALLBACK (recent_chooser_item_activated),
66 filter = gtk_recent_filter_new ();
67 gtk_recent_filter_add_application (filter, g_get_application_name ());
68 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (toolbar_recent_menu), filter);
70 tool_item = GTK_WIDGET (gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN));
71 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (tool_item),
72 _("Open a recently used document"));
73 gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item),
74 GTK_WIDGET (toolbar_recent_menu));
79 ev_open_recent_action_init (EvOpenRecentAction *action)
84 ev_open_recent_action_class_init (EvOpenRecentActionClass *class)
86 GObjectClass *object_class = G_OBJECT_CLASS (class);
87 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
89 action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
90 action_class->create_tool_item = ev_open_recent_action_create_tool_item;
92 action_signals[ITEM_ACTIVATED] =
93 g_signal_new ("item_activated",
94 G_OBJECT_CLASS_TYPE (object_class),
95 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
96 G_STRUCT_OFFSET (EvOpenRecentActionClass, item_activated),
98 g_cclosure_marshal_VOID__STRING,