+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):
int current_index;
};
+enum {
+ PROP_0,
+ PROP_INDEX
+};
+
static void ev_history_init (EvHistory *history);
static void ev_history_class_init (EvHistoryClass *class);
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));
}
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);
g_return_if_fail (EV_IS_HISTORY (history));
history->priv->current_index = index;
+
+ g_object_notify (G_OBJECT (history), "index");
}
EvHistory *
EvWindow *window;
EvNavigationDirection direction;
char *arrow_tooltip;
+ EvHistory *history;
};
enum
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);
}
{
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);
#include <gtk/gtkaction.h>
+#include "ev-history.h"
+
G_BEGIN_DECLS
#define EV_TYPE_NAVIGATION_ACTION (ev_navigation_action_get_type ())
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
#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))
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));
}
}
if (n > 0) {
index = MAX (0, index - 1);
ev_history_set_current_index (view->history, index);
- go_to_index (view, index);
}
}
if (n > 0) {
index = MIN (n - 1, index + 1);
ev_history_set_current_index (view->history, index);
- go_to_index (view, index);
}
}
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);
+}
#include "ev-document.h"
#include "ev-link.h"
+#include "ev-history.h"
G_BEGIN_DECLS
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);
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 };
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
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);
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
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"),
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"),
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);
}