]> www.fi.muni.cz Git - evince.git/commitdiff
Implement history dropdowns
authorMarco Pesenti Gritti <marco@gnome.org>
Tue, 11 Jan 2005 11:21:52 +0000 (11:21 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Tue, 11 Jan 2005 11:21:52 +0000 (11:21 +0000)
2005-01-11  Marco Pesenti Gritti  <marco@gnome.org>

        * shell/ev-history.c: (ev_history_get_property),
        (ev_history_set_property), (ev_history_class_init),
        (ev_history_add_page), (ev_history_set_current_index):
        * shell/ev-navigation-action.c: (ev_navigation_action_set_history),
        (activate_menu_item_cb), (new_history_menu_item), (build_menu),
        (ev_navigation_action_finalize):
        * shell/ev-navigation-action.h:
        * shell/ev-view.c: (ev_view_set_document), (ev_view_go_back),
        (ev_view_go_forward), (ev_view_get_find_status_message),
        (history_index_changed_cb), (ev_view_set_history):
        * shell/ev-view.h:
        * shell/ev-window.c: (update_total_pages), (ev_window_open),
        (update_current_page), (register_custom_actions):

        Implement history dropdowns

ChangeLog
shell/ev-history.c
shell/ev-navigation-action.c
shell/ev-navigation-action.h
shell/ev-view.c
shell/ev-view.h
shell/ev-window.c

index da76f704b0f820ec01d29a1260db5c1023db7891..daf46ffd0ec741ed1729b60bd4e53b338f2089df 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2005-01-11  Marco Pesenti Gritti  <marco@gnome.org>
+
+       * shell/ev-history.c: (ev_history_get_property),
+       (ev_history_set_property), (ev_history_class_init),
+       (ev_history_add_page), (ev_history_set_current_index):
+       * shell/ev-navigation-action.c: (ev_navigation_action_set_history),
+       (activate_menu_item_cb), (new_history_menu_item), (build_menu),
+       (ev_navigation_action_finalize):
+       * shell/ev-navigation-action.h:
+       * shell/ev-view.c: (ev_view_set_document), (ev_view_go_back),
+       (ev_view_go_forward), (ev_view_get_find_status_message),
+       (history_index_changed_cb), (ev_view_set_history):
+       * shell/ev-view.h:
+       * shell/ev-window.c: (update_total_pages), (ev_window_open),
+       (update_current_page), (register_custom_actions):
+
+       Implement history dropdowns
+
 2005-01-11  Marco Pesenti Gritti  <marco@gnome.org>
 
        * shell/ev-history.c: (ev_history_init), (ev_history_add_link):
index a1e79543bb4e8a9bd35e97c4fefc495f77d1406d..08e2d1c443ae4371182b169769c451ce8cfa91f3 100644 (file)
@@ -30,6 +30,11 @@ struct _EvHistoryPrivate
        int current_index;
 };
 
+enum {
+       PROP_0,
+       PROP_INDEX
+};
+
 static void ev_history_init       (EvHistory *history);
 static void ev_history_class_init (EvHistoryClass *class);
 
@@ -65,15 +70,67 @@ ev_history_finalize (GObject *object)
        parent_class->finalize (object);
 }
 
+static void
+ev_history_get_property (GObject *object, guint prop_id, GValue *value,
+                        GParamSpec *param_spec)
+{
+       EvHistory *self;
+
+       self = EV_HISTORY (object);
+
+       switch (prop_id) {
+       case PROP_INDEX:
+               g_value_set_int (value, self->priv->current_index);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
+                                                  prop_id,
+                                                  param_spec);
+               break;
+       }
+}
+
+static void
+ev_history_set_property (GObject *object, guint prop_id, const GValue *value,
+                        GParamSpec *param_spec)
+{
+       EvHistory *self;
+       
+       self = EV_HISTORY (object);
+       
+       switch (prop_id) {
+       case PROP_INDEX:
+               ev_history_set_current_index (self, g_value_get_int (value));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
+                                                  prop_id,
+                                                  param_spec);
+               break;
+       }
+}
+
 static void
 ev_history_class_init (EvHistoryClass *class)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (class);
 
        object_class->finalize = ev_history_finalize;
+       object_class->set_property = ev_history_set_property;
+       object_class->get_property = ev_history_get_property;
 
        parent_class = g_type_class_peek_parent (class);
 
+       g_object_class_install_property (object_class,
+                                        PROP_INDEX,
+                                        g_param_spec_int ("index",
+                                                          "Current Index",
+                                                          "The current index",
+                                                           -1,
+                                                           G_MAXINT,
+                                                           0,
+                                                           G_PARAM_READWRITE));
+
        g_type_class_add_private (object_class, sizeof (EvHistoryPrivate));
 }
 
@@ -115,7 +172,7 @@ ev_history_add_page (EvHistory *history, int page)
 
        g_return_if_fail (EV_IS_HISTORY (history));
 
-       title = g_strdup_printf (_("Page %d\n"), page);
+       title = g_strdup_printf (_("Page %d"), page);
        link = ev_link_new_page (title, page);
        g_free (title);
 
@@ -156,6 +213,8 @@ ev_history_set_current_index (EvHistory *history, int index)
        g_return_if_fail (EV_IS_HISTORY (history));
 
        history->priv->current_index = index;
+
+       g_object_notify (G_OBJECT (history), "index");
 }
 
 EvHistory *
index 7b5269a8a5a1af5e727efc61105afb623d58252a..a4a13bcbccf0fd755ba57d29eb9de95626394ae3 100644 (file)
@@ -37,6 +37,7 @@ struct _EvNavigationActionPrivate
        EvWindow *window;
        EvNavigationDirection direction;
        char *arrow_tooltip;
+       EvHistory *history;
 };
 
 enum
@@ -53,15 +54,87 @@ static GObjectClass *parent_class = NULL;
 
 G_DEFINE_TYPE (EvNavigationAction, ev_navigation_action, GTK_TYPE_ACTION)
 
+#define MAX_LABEL_LENGTH 48
+
 #define EV_NAVIGATION_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_NAVIGATION_ACTION, EvNavigationActionPrivate))
 
+void
+ev_navigation_action_set_history (EvNavigationAction *action,
+                                 EvHistory          *history)
+{
+       action->priv->history = history;
+
+       g_object_add_weak_pointer (G_OBJECT (action->priv->history),
+                                  (gpointer *) &action->priv->history);
+}
+
+static void
+activate_menu_item_cb (GtkWidget *widget, EvNavigationAction *action)
+{
+       int index;
+
+       g_return_if_fail (EV_IS_HISTORY (action->priv->history));
+
+       index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "index"));
+       ev_history_set_current_index (action->priv->history, index);
+}
+
+static GtkWidget *
+new_history_menu_item (EvNavigationAction *action,
+                      EvLink             *link,
+                      int                 index)
+{
+       GtkLabel *label;
+       GtkWidget *item;
+       const char *title;
+
+       title = ev_link_get_title (link);
+       item = gtk_image_menu_item_new_with_label (title);
+       g_object_set_data (G_OBJECT (item), "index",
+                          GINT_TO_POINTER (index));
+
+       label = GTK_LABEL (GTK_BIN (item)->child);
+       gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
+       gtk_label_set_max_width_chars (label, MAX_LABEL_LENGTH);
+
+       g_signal_connect (item, "activate",
+                         G_CALLBACK (activate_menu_item_cb),
+                         action);
+
+       gtk_widget_show (item);
+
+       return item;
+}
+
 static GtkWidget *
 build_menu (EvNavigationAction *action)
 {
        GtkMenuShell *menu;
+       EvHistory *history = action->priv->history;
+       int start, end, i;
 
        menu = GTK_MENU_SHELL (gtk_menu_new ());
 
+       if (history == NULL) {
+               return GTK_WIDGET (menu);
+       }
+
+       if (action->priv->direction == EV_NAVIGATION_DIRECTION_BACK) {
+               start = 0;
+               end = ev_history_get_current_index (history);
+       } else {
+               start = ev_history_get_current_index (history) + 1;
+               end = ev_history_get_n_links (history);
+       }
+
+       for (i = start; i < end; i++) {
+               EvLink *link = ev_history_get_link_nth (history, i);
+               GtkWidget *item;
+
+               item = new_history_menu_item (action, link, i);
+               gtk_menu_shell_append (menu, item);
+       }
+
        return GTK_WIDGET (menu);
 }
 
@@ -122,6 +195,11 @@ ev_navigation_action_finalize (GObject *object)
 {
        EvNavigationAction *action = EV_NAVIGATION_ACTION (object);
 
+       if (action->priv->history) {
+               g_object_add_weak_pointer (G_OBJECT (action->priv->history),
+                                          (gpointer *) &action->priv->history);
+       }
+
        g_free (action->priv->arrow_tooltip);
 
        parent_class->finalize (object);
index 8bb7943e29073012afc320a3a303ad8da1013674..fe9b9d73094b969a0d7552ac3adea68f0563396c 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <gtk/gtkaction.h>
 
+#include "ev-history.h"
+
 G_BEGIN_DECLS
 
 #define EV_TYPE_NAVIGATION_ACTION            (ev_navigation_action_get_type ())
@@ -56,7 +58,9 @@ struct _EvNavigationActionClass
        GtkActionClass parent_class;
 };
 
-GType ev_navigation_action_get_type (void);
+GType  ev_navigation_action_get_type           (void);
+void   ev_navigation_action_set_history        (EvNavigationAction *action,
+                                                EvHistory          *history);
 
 G_END_DECLS
 
index cf2c4695c7c0280476af8c300d003a20da278f9b..4750b4d282ab3953169b132b9ee69f74eab78dbd 100644 (file)
@@ -28,7 +28,6 @@
 #include "ev-marshal.h"
 #include "ev-view.h"
 #include "ev-document-find.h"
-#include "ev-history.h"
 
 #define EV_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_VIEW, EvViewClass))
 #define EV_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_VIEW))
@@ -905,12 +904,6 @@ ev_view_set_document (EvView     *view,
                
                if (old_page != ev_view_get_page (view))
                        g_signal_emit (view, page_changed_signal, 0);
-
-               if (view->history) {
-                       g_object_unref (view->history);
-               }
-               view->history = ev_history_new ();
-               ev_history_add_page (view->history, ev_view_get_page (view));
        }
 }
 
@@ -975,7 +968,6 @@ ev_view_go_back     (EvView *view)
        if (n > 0) {
                index = MAX (0, index - 1);
                ev_history_set_current_index (view->history, index);
-               go_to_index (view, index);
        }
 }
 
@@ -992,7 +984,6 @@ ev_view_go_forward (EvView *view)
        if (n > 0) {
                index = MIN (n - 1, index + 1);
                ev_history_set_current_index (view->history, index);
-               go_to_index (view, index);
        }
 }
 
@@ -1117,3 +1108,30 @@ ev_view_get_find_status_message (EvView *view)
                                        view->results_on_this_page);
        }
 }
+
+static void
+history_index_changed_cb (EvHistory  *history,
+                         GParamSpec *pspec,
+                         EvView     *view)
+{
+       int index;
+
+       index = ev_history_get_current_index (history);
+       go_to_index (view, index);
+}
+
+void
+ev_view_set_history (EvView     *view,
+                    EvHistory  *history)
+{
+       if (view->history) {
+               g_object_unref (view->history);
+       }
+
+       view->history = g_object_ref (history);
+       ev_history_add_page (view->history, ev_view_get_page (view));
+
+       g_signal_connect (view->history, "notify::index",
+                         G_CALLBACK (history_index_changed_cb),
+                         view);
+}
index 93902637141910f10727993a8316ce9965631d0b..97eb983631903ae00372ecfc070892e707b0a3a9 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "ev-document.h"
 #include "ev-link.h"
+#include "ev-history.h"
 
 G_BEGIN_DECLS
 
@@ -39,6 +40,8 @@ GType         ev_view_get_type        (void) G_GNUC_CONST;
 GtkWidget*     ev_view_new             (void);
 void           ev_view_set_document    (EvView     *view,
                                         EvDocument *document);
+void           ev_view_set_history     (EvView     *view,
+                                        EvHistory  *history);
 
 /* Clipboard */
 void           ev_view_copy            (EvView     *view);
index 64b80c33abdd79d5002eea9572012af1d383b783..443fff08abb116ba115f1aef625d1b7829308824 100644 (file)
@@ -75,13 +75,16 @@ struct _EvWindowPrivate {
        guint help_message_cid;
        GtkWidget *exit_fullscreen_popup;
        char *uri;
-       GtkAction *page_action;
 
        EvDocument *document;
 
        gboolean fullscreen_mode;
 };
 
+#define NAVIGATION_BACK_ACTION "NavigationBack"
+#define NAVIGATION_FORWARD_ACTION "NavigationForward"
+#define PAGE_SELECTOR_ACTION "PageSelector"
+
 #if 0
 /* enable these to add support for signals */
 static guint ev_window_signals [N_SIGNALS] = { 0 };
@@ -282,12 +285,13 @@ update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_windo
 static void
 update_total_pages (EvWindow *ev_window)
 {
-       EvPageAction *page_action;
+       GtkAction *action;
        int pages;
 
        pages = ev_document_get_n_pages (ev_window->priv->document);
-       page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
-       ev_page_action_set_total_pages (page_action, pages);
+       action = gtk_action_group_get_action
+               (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
+       ev_page_action_set_total_pages (EV_PAGE_ACTION (action), pages);
 }
 
 void
@@ -319,14 +323,31 @@ ev_window_open (EvWindow *ev_window, const char *uri)
                                         ev_window, 0);
 
                if (ev_document_load (document, uri, &error)) {
+                       EvHistory *history;
+                       EvView *view = EV_VIEW (ev_window->priv->view);
+                       EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar);
+                       GtkAction *action;
+
                        if (ev_window->priv->document)
                                g_object_unref (ev_window->priv->document);
                        ev_window->priv->document = document;
 
-                       ev_view_set_document (EV_VIEW (ev_window->priv->view),
-                                             document);
-                       ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar),
-                                                document);
+                       ev_view_set_document (view, document);
+                       ev_sidebar_set_document (sidebar, document);
+
+                       history = ev_history_new ();
+                       ev_view_set_history (view, history);
+                       g_object_unref (history);
+
+                       action = gtk_action_group_get_action
+                               (ev_window->priv->action_group, NAVIGATION_BACK_ACTION);
+                       ev_navigation_action_set_history
+                               (EV_NAVIGATION_ACTION (action), history);
+
+                       action = gtk_action_group_get_action
+                               (ev_window->priv->action_group, NAVIGATION_FORWARD_ACTION);
+                       ev_navigation_action_set_history
+                               (EV_NAVIGATION_ACTION (action), history);
 
                        update_total_pages (ev_window);
                        update_action_sensitivity (ev_window);
@@ -1068,12 +1089,14 @@ disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
 static void
 update_current_page (EvWindow *ev_window)
 {
-       EvPageAction *page_action;
        int page;
+       GtkAction *action;
+
+       action = gtk_action_group_get_action
+               (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
 
        page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
-       page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
-       ev_page_action_set_current_page (page_action, page);
+       ev_page_action_set_current_page (EV_PAGE_ACTION (action), page);
 }
 
 static void
@@ -1342,7 +1365,7 @@ register_custom_actions (EvWindow *window, GtkActionGroup *group)
        GtkAction *action;
 
        action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
-                              "name", "NavigationBack",
+                              "name", NAVIGATION_BACK_ACTION,
                               "label", _("Back"),
                               "stock_id", GTK_STOCK_GO_BACK,
                               "tooltip", _("Go back"),
@@ -1356,7 +1379,7 @@ register_custom_actions (EvWindow *window, GtkActionGroup *group)
        g_object_unref (action);
 
        action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
-                              "name", "NavigationForward",
+                              "name", NAVIGATION_FORWARD_ACTION,
                               "label", _("Forward"),
                               "stock_id", GTK_STOCK_GO_FORWARD,
                               "tooltip", _("Go forward"),
@@ -1369,13 +1392,12 @@ register_custom_actions (EvWindow *window, GtkActionGroup *group)
        g_object_unref (action);
 
        action = g_object_new (EV_TYPE_PAGE_ACTION,
-                              "name", "PageSelector",
+                              "name", PAGE_SELECTOR_ACTION,
                               "label", _("Page"),
                               "tooltip", _("Select Page"),
                               NULL);
        g_signal_connect (action, "goto_page",
                          G_CALLBACK (goto_page_cb), window);
-       window->priv->page_action = action;
        gtk_action_group_add_action (group, action);
        g_object_unref (action);
 }