]> www.fi.muni.cz Git - evince.git/blob - shell/ev-open-recent-action.c
[dualscreen] fix crash on ctrl+w and fix control window closing
[evince.git] / shell / ev-open-recent-action.c
1 /*
2  *  Copyright (C) 2007, Carlos Garcia Campos  <carlosgc@gnome.org>
3  *
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)
7  *  any later version.
8  *
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.
13  *
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.
17  *
18  */
19
20 #include <config.h>
21
22 #include <glib/gi18n.h>
23 #include <gtk/gtk.h>
24
25 #include "ev-open-recent-action.h"
26
27
28 enum {
29         ITEM_ACTIVATED,
30         N_SIGNALS
31 };
32
33 static void ev_open_recent_action_init       (EvOpenRecentAction      *action);
34 static void ev_open_recent_action_class_init (EvOpenRecentActionClass *class);
35
36 static guint action_signals[N_SIGNALS];
37
38 G_DEFINE_TYPE (EvOpenRecentAction, ev_open_recent_action, GTK_TYPE_ACTION)
39
40 static void
41 recent_chooser_item_activated (GtkRecentChooser *chooser,
42                                GtkAction        *action)
43 {
44         gchar *uri;
45
46         uri = gtk_recent_chooser_get_current_uri (chooser);
47         g_signal_emit (action, action_signals[ITEM_ACTIVATED], 0, uri);
48         g_free (uri);
49 }
50
51 static GtkWidget *
52 ev_open_recent_action_create_tool_item (GtkAction *action)
53 {
54         GtkWidget       *tool_item;
55         GtkWidget       *toolbar_recent_menu;
56         GtkRecentFilter *filter;
57
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),
64                           action);
65
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);
69
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));
75         return tool_item;
76 }
77
78 static void
79 ev_open_recent_action_init (EvOpenRecentAction *action)
80 {
81 }
82
83 static void
84 ev_open_recent_action_class_init (EvOpenRecentActionClass *class)
85 {
86         GObjectClass   *object_class = G_OBJECT_CLASS (class);
87         GtkActionClass *action_class = GTK_ACTION_CLASS (class);
88
89         action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
90         action_class->create_tool_item = ev_open_recent_action_create_tool_item;
91
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),
97                               NULL, NULL,
98                               g_cclosure_marshal_VOID__STRING, 
99                               G_TYPE_NONE, 1,
100                               G_TYPE_STRING);
101 }