]> www.fi.muni.cz Git - evince.git/commitdiff
Add an expander to the open toolbar item which pops up a dropdown menu
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 28 Oct 2007 18:34:23 +0000 (18:34 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Sun, 28 Oct 2007 18:34:23 +0000 (18:34 +0000)
2007-10-29  Carlos Garcia Campos  <carlosgc@gnome.org>
* data/evince-toolbar.xml:
* shell/Makefile.am:
* shell/ev-application.c: (ev_application_init):
* shell/ev-open-recent-action.[ch]:
* shell/ev-window.c:
(ev_window_open_recent_action_item_activated),
(register_custom_actions):
Add an expander to the open toolbar item which pops up a dropdown
menu with the recently used documents. Fixes bug #487215.

svn path=/trunk/; revision=2731

ChangeLog
data/evince-toolbar.xml
shell/Makefile.am
shell/ev-application.c
shell/ev-open-recent-action.c [new file with mode: 0644]
shell/ev-open-recent-action.h [new file with mode: 0644]
shell/ev-window.c

index 70a034a3986bdf53940d3eeeb4d3edd3d84637b7..61763a00c5b1222515ac593b7624f4f133f8ccb4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-10-29  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * data/evince-toolbar.xml:
+       * shell/Makefile.am:
+       * shell/ev-application.c: (ev_application_init):
+       * shell/ev-open-recent-action.[ch]:
+       * shell/ev-window.c:
+       (ev_window_open_recent_action_item_activated),
+       (register_custom_actions):
+
+       Add an expander to the open toolbar item which pops up a dropdown
+       menu with the recently used documents. Fixes bug #487215.
+       
 2007-10-29  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-window.c: (ev_window_open_uri),
index 71b06390a005a3f0c13ef5980fb865ff885cbc9a..53215712c33006dd4cc74573d2b88c90d85865f3 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <toolbars version="1.0">
 <available>
-    <toolitem name="FileOpen"/>
+    <toolitem name="FileOpenRecent"/>
     <toolitem name="FilePrint"/>
     <toolitem name="ViewContinuous"/>
     <toolitem name="ViewDual"/>
index 6964029d0df098fa7d0d397df829f38297126b82..34dc0ffc5758335159a729f3aab169073dea9879 100644 (file)
@@ -51,6 +51,8 @@ evince_SOURCES=                               \
        ev-properties-dialog.h          \
        ev-properties-fonts.c           \
        ev-properties-fonts.h           \
+       ev-open-recent-action.c         \
+       ev-open-recent-action.h         \
        ev-utils.c                      \
        ev-utils.h                      \
        ev-view-accessible.c            \
index 2567a8bee41c816bc40f8ab0c00b966d99adb0f0..deac0ed5529221e7b16cd665a843c985e84d9acd 100644 (file)
@@ -664,6 +664,8 @@ ev_application_class_init (EvApplicationClass *ev_application_class)
 static void
 ev_application_init (EvApplication *ev_application)
 {
+       gint i;
+       
 #if WITH_GNOME
        init_session (ev_application);
 #endif
@@ -682,8 +684,24 @@ ev_application_init (EvApplication *ev_application)
                                                  DATADIR"/evince-toolbar.xml");
        }
 
+       /* Open item doesn't exist anymore,
+        * convert it to OpenRecent for compatibility
+        */
+       for (i = 0; i < egg_toolbars_model_n_items (ev_application->toolbars_model, 0); i++) {
+               const gchar *item;
+               
+               item = egg_toolbars_model_item_nth (ev_application->toolbars_model, 0, i);
+               if (g_ascii_strcasecmp (item, "FileOpen") == 0) {
+                       egg_toolbars_model_remove_item (ev_application->toolbars_model, 0, i);
+                       egg_toolbars_model_add_item (ev_application->toolbars_model, 0, i,
+                                                    "FileOpenRecent");
+                       ev_application_save_toolbars_model (ev_application);
+                       break;
+               }
+       }
+
        egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
-                                     EGG_TB_MODEL_NOT_REMOVABLE); 
+                                     EGG_TB_MODEL_NOT_REMOVABLE);
 }
 
 /**
diff --git a/shell/ev-open-recent-action.c b/shell/ev-open-recent-action.c
new file mode 100644 (file)
index 0000000..c57138f
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ *  Copyright (C) 2007, Carlos Garcia Campos  <carlosgc@gnome.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include "ev-open-recent-action.h"
+
+enum {
+       ITEM_ACTIVATED,
+       N_SIGNALS
+};
+
+static void ev_open_recent_action_init       (EvOpenRecentAction      *action);
+static void ev_open_recent_action_class_init (EvOpenRecentActionClass *class);
+
+static guint action_signals[N_SIGNALS];
+
+G_DEFINE_TYPE (EvOpenRecentAction, ev_open_recent_action, GTK_TYPE_ACTION)
+
+static void
+recent_chooser_item_activated (GtkRecentChooser *chooser,
+                              GtkAction        *action)
+{
+       gchar *uri;
+
+       uri = gtk_recent_chooser_get_current_uri (chooser);
+       g_signal_emit (action, action_signals[ITEM_ACTIVATED], 0, uri);
+       g_free (uri);
+}
+
+static GtkWidget *
+ev_open_recent_action_create_tool_item (GtkAction *action)
+{
+       GtkWidget       *tool_item;
+       GtkWidget       *toolbar_recent_menu;
+       GtkRecentFilter *filter;
+
+       toolbar_recent_menu = gtk_recent_chooser_menu_new_for_manager (gtk_recent_manager_get_default ());
+       gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (toolbar_recent_menu), FALSE);
+       gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (toolbar_recent_menu), GTK_RECENT_SORT_MRU);
+       gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (toolbar_recent_menu), 5);
+       g_signal_connect (toolbar_recent_menu, "item_activated",
+                         G_CALLBACK (recent_chooser_item_activated),
+                         action);
+
+       filter = gtk_recent_filter_new ();
+       gtk_recent_filter_add_application (filter, g_get_application_name ());
+       gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (toolbar_recent_menu), filter);
+
+       tool_item = GTK_WIDGET (gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN));
+#if GTK_CHECK_VERSION(2,11,6)
+       gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (tool_item),
+                                                    _("Open a recently used document"));
+#endif
+       gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item),
+                                      GTK_WIDGET (toolbar_recent_menu));
+       return tool_item;
+}
+
+static void
+ev_open_recent_action_init (EvOpenRecentAction *action)
+{
+}
+
+static void
+ev_open_recent_action_class_init (EvOpenRecentActionClass *class)
+{
+       GObjectClass   *object_class = G_OBJECT_CLASS (class);
+       GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+       action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
+       action_class->create_tool_item = ev_open_recent_action_create_tool_item;
+
+       action_signals[ITEM_ACTIVATED] =
+               g_signal_new ("item_activated",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                             G_STRUCT_OFFSET (EvOpenRecentActionClass, item_activated),
+                             NULL, NULL,
+                             g_cclosure_marshal_VOID__STRING, 
+                             G_TYPE_NONE, 1,
+                             G_TYPE_STRING);
+}
diff --git a/shell/ev-open-recent-action.h b/shell/ev-open-recent-action.h
new file mode 100644 (file)
index 0000000..70bce0e
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (C) 2007, Carlos Garcia Campos  <carlosgc@gnome.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef EV_OPEN_RECENT_ACTION_H
+#define EV_OPEN_RECENT_ACTION_H
+
+#include <gtk/gtkaction.h>
+#include <gtk/gtkmenutoolbutton.h>
+
+G_BEGIN_DECLS
+
+#define EV_TYPE_OPEN_RECENT_ACTION            (ev_open_recent_action_get_type ())
+#define EV_OPEN_RECENT_ACTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_OPEN_RECENT_ACTION, EvOpenRecentAction))
+#define EV_OPEN_RECENT_ACTION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_OPEN_RECENT_ACTION, EvOpenRecentActionClass))
+#define EV_IS_OPEN_RECENT_ACTION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_OPEN_RECENT_ACTION))
+#define EV_IS_OPEN_RECENT_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EV_TYPE_OPEN_RECENT_ACTION))
+#define EV_OPEN_RECENT_ACTION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), EV_TYPE_OPEN_RECENT_ACTION, EvOpenRecentActionClass))
+
+typedef struct _EvOpenRecentAction      EvOpenRecentAction;
+typedef struct _EvOpenRecentActionClass EvOpenRecentActionClass;
+
+struct _EvOpenRecentAction {
+       GtkAction parent;
+};
+
+struct _EvOpenRecentActionClass {
+       GtkActionClass parent_class;
+
+       void (* item_activated) (EvOpenRecentAction *action,
+                                const gchar        *uri);
+};
+
+GType ev_open_recent_action_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* EV_OPEN_RECENT_ACTION_H */
index 675308d01cf3737194315bb4b5b3c6d39632ae6a..6c15e79146e39985573ee254c542ac72de3c0477 100644 (file)
@@ -32,6 +32,7 @@
 #include "ev-window-title.h"
 #include "ev-navigation-action.h"
 #include "ev-page-action.h"
+#include "ev-open-recent-action.h"
 #include "ev-sidebar.h"
 #include "ev-sidebar-links.h"
 #include "ev-sidebar-attachments.h"
@@ -1701,8 +1702,8 @@ ev_window_cmd_file_open_copy (GtkAction *action, EvWindow *window)
 }
 
 static void
-ev_window_cmd_recent_file_activate (GtkAction     *action,
-                                   EvWindow      *window)
+ev_window_cmd_recent_file_activate (GtkAction *action,
+                                   EvWindow  *window)
 {
        GtkRecentInfo *info;
        const gchar   *uri;
@@ -1718,6 +1719,17 @@ ev_window_cmd_recent_file_activate (GtkAction     *action,
                                         GDK_CURRENT_TIME);
 }
 
+static void
+ev_window_open_recent_action_item_activated (EvOpenRecentAction *action,
+                                            const gchar        *uri,
+                                            EvWindow           *window)
+{
+       ev_application_open_uri_at_dest (EV_APP, uri,
+                                        gtk_window_get_screen (GTK_WINDOW (window)),
+                                        NULL, 0, FALSE, NULL, 
+                                        GDK_CURRENT_TIME);
+}
+
 static void
 ev_window_add_recent (EvWindow *window, const char *filename)
 {
@@ -4467,6 +4479,20 @@ register_custom_actions (EvWindow *window, GtkActionGroup *group)
                          G_CALLBACK (navigation_action_activate_link_cb), window);
        gtk_action_group_add_action (group, action);
        g_object_unref (action);
+
+       action = g_object_new (EV_TYPE_OPEN_RECENT_ACTION,
+                              "name", "FileOpenRecent",
+                              "label", _("_Open..."),
+                              "tooltip", _("Open an existing document"),
+                              "stock_id", GTK_STOCK_OPEN,
+                              NULL);
+       g_signal_connect (action, "activate",
+                         G_CALLBACK (ev_window_cmd_file_open), window);
+       g_signal_connect (action, "item_activated",
+                         G_CALLBACK (ev_window_open_recent_action_item_activated),
+                         window);
+       gtk_action_group_add_action (group, action);
+       g_object_unref (action);
 }
 
 static void
@@ -5154,7 +5180,7 @@ ev_window_init (EvWindow *ev_window)
                                  "changed",
                                  G_CALLBACK (ev_window_setup_recent),
                                  ev_window);
-       
+
        ev_window->priv->menubar =
                 gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
                                            "/MainMenu");
@@ -5162,7 +5188,6 @@ ev_window_init (EvWindow *ev_window)
                            ev_window->priv->menubar,
                            FALSE, FALSE, 0);
 
-
        ev_window->priv->toolbar = GTK_WIDGET 
          (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
                         "ui-manager", ev_window->priv->ui_manager,