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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <glib/gi18n.h>
24 #include "ev-open-recent-action.h"
31 static void ev_open_recent_action_init (EvOpenRecentAction *action);
32 static void ev_open_recent_action_class_init (EvOpenRecentActionClass *class);
34 static guint action_signals[N_SIGNALS];
36 G_DEFINE_TYPE (EvOpenRecentAction, ev_open_recent_action, GTK_TYPE_ACTION)
39 recent_chooser_item_activated (GtkRecentChooser *chooser,
44 uri = gtk_recent_chooser_get_current_uri (chooser);
45 g_signal_emit (action, action_signals[ITEM_ACTIVATED], 0, uri);
50 ev_open_recent_action_create_tool_item (GtkAction *action)
53 GtkWidget *toolbar_recent_menu;
54 GtkRecentFilter *filter;
56 toolbar_recent_menu = gtk_recent_chooser_menu_new_for_manager (gtk_recent_manager_get_default ());
57 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (toolbar_recent_menu), FALSE);
58 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (toolbar_recent_menu), GTK_RECENT_SORT_MRU);
59 gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (toolbar_recent_menu), 5);
60 g_signal_connect (toolbar_recent_menu, "item_activated",
61 G_CALLBACK (recent_chooser_item_activated),
64 filter = gtk_recent_filter_new ();
65 gtk_recent_filter_add_application (filter, g_get_application_name ());
66 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (toolbar_recent_menu), filter);
68 tool_item = GTK_WIDGET (gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN));
69 #if GTK_CHECK_VERSION(2,11,6)
70 gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (tool_item),
71 _("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,