]> www.fi.muni.cz Git - evince.git/blob - shell/ev-open-recent-action.c
Add an expander to the open toolbar item which pops up a dropdown menu
[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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19
20 #include <gtk/gtk.h>
21 #include <glib/gi18n.h>
22
23 #include "ev-open-recent-action.h"
24
25 enum {
26         ITEM_ACTIVATED,
27         N_SIGNALS
28 };
29
30 static void ev_open_recent_action_init       (EvOpenRecentAction      *action);
31 static void ev_open_recent_action_class_init (EvOpenRecentActionClass *class);
32
33 static guint action_signals[N_SIGNALS];
34
35 G_DEFINE_TYPE (EvOpenRecentAction, ev_open_recent_action, GTK_TYPE_ACTION)
36
37 static void
38 recent_chooser_item_activated (GtkRecentChooser *chooser,
39                                GtkAction        *action)
40 {
41         gchar *uri;
42
43         uri = gtk_recent_chooser_get_current_uri (chooser);
44         g_signal_emit (action, action_signals[ITEM_ACTIVATED], 0, uri);
45         g_free (uri);
46 }
47
48 static GtkWidget *
49 ev_open_recent_action_create_tool_item (GtkAction *action)
50 {
51         GtkWidget       *tool_item;
52         GtkWidget       *toolbar_recent_menu;
53         GtkRecentFilter *filter;
54
55         toolbar_recent_menu = gtk_recent_chooser_menu_new_for_manager (gtk_recent_manager_get_default ());
56         gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (toolbar_recent_menu), FALSE);
57         gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (toolbar_recent_menu), GTK_RECENT_SORT_MRU);
58         gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (toolbar_recent_menu), 5);
59         g_signal_connect (toolbar_recent_menu, "item_activated",
60                           G_CALLBACK (recent_chooser_item_activated),
61                           action);
62
63         filter = gtk_recent_filter_new ();
64         gtk_recent_filter_add_application (filter, g_get_application_name ());
65         gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (toolbar_recent_menu), filter);
66
67         tool_item = GTK_WIDGET (gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN));
68 #if GTK_CHECK_VERSION(2,11,6)
69         gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (tool_item),
70                                                      _("Open a recently used document"));
71 #endif
72         gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item),
73                                        GTK_WIDGET (toolbar_recent_menu));
74         return tool_item;
75 }
76
77 static void
78 ev_open_recent_action_init (EvOpenRecentAction *action)
79 {
80 }
81
82 static void
83 ev_open_recent_action_class_init (EvOpenRecentActionClass *class)
84 {
85         GObjectClass   *object_class = G_OBJECT_CLASS (class);
86         GtkActionClass *action_class = GTK_ACTION_CLASS (class);
87
88         action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
89         action_class->create_tool_item = ev_open_recent_action_create_tool_item;
90
91         action_signals[ITEM_ACTIVATED] =
92                 g_signal_new ("item_activated",
93                               G_OBJECT_CLASS_TYPE (object_class),
94                               G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
95                               G_STRUCT_OFFSET (EvOpenRecentActionClass, item_activated),
96                               NULL, NULL,
97                               g_cclosure_marshal_VOID__STRING, 
98                               G_TYPE_NONE, 1,
99                               G_TYPE_STRING);
100 }