X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-navigation-action.c;h=bedadfe90ab9370359f90f0d4a061d262ee75035;hb=4e908aee85146f7e1a9c6f4286a4539eb923f094;hp=a4a13bcbccf0fd755ba57d29eb9de95626394ae3;hpb=dbe299f7b2412d318f0eda7c401feba68c8663e3;p=evince.git diff --git a/shell/ev-navigation-action.c b/shell/ev-navigation-action.c index a4a13bcb..bedadfe9 100644 --- a/shell/ev-navigation-action.c +++ b/shell/ev-navigation-action.c @@ -16,12 +16,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Id$ */ #include "config.h" #include "ev-navigation-action.h" +#include "ev-navigation-action-widget.h" #include "ev-window.h" #include @@ -31,27 +31,17 @@ #include #include #include +#include struct _EvNavigationActionPrivate { EvWindow *window; - EvNavigationDirection direction; - char *arrow_tooltip; EvHistory *history; }; -enum -{ - PROP_0, - PROP_ARROW_TOOLTIP, - PROP_DIRECTION -}; - static void ev_navigation_action_init (EvNavigationAction *action); static void ev_navigation_action_class_init (EvNavigationActionClass *class); -static GObjectClass *parent_class = NULL; - G_DEFINE_TYPE (EvNavigationAction, ev_navigation_action, GTK_TYPE_ACTION) #define MAX_LABEL_LENGTH 48 @@ -68,6 +58,13 @@ ev_navigation_action_set_history (EvNavigationAction *action, (gpointer *) &action->priv->history); } +void +ev_navigation_action_set_window (EvNavigationAction *action, + EvWindow *window) +{ + action->priv->window = window; +} + static void activate_menu_item_cb (GtkWidget *widget, EvNavigationAction *action) { @@ -77,6 +74,18 @@ activate_menu_item_cb (GtkWidget *widget, EvNavigationAction *action) index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "index")); ev_history_set_current_index (action->priv->history, index); + + if (action->priv->window) { + EvLink *link; + EvLinkAction *link_action; + EvLinkDest *dest; + + link = ev_history_get_link_nth (action->priv->history, index); + link_action = ev_link_get_action (link); + dest = ev_link_action_get_dest (link_action); + + ev_window_goto_dest (action->priv->window, dest); + } } static GtkWidget * @@ -106,31 +115,40 @@ new_history_menu_item (EvNavigationAction *action, return item; } +static GtkWidget * +new_empty_history_menu_item (EvNavigationAction *action) +{ + GtkWidget *item; + + item = gtk_image_menu_item_new_with_label (_("Empty")); + gtk_widget_set_sensitive (item, FALSE); + gtk_widget_show (item); + + return item; +} + static GtkWidget * build_menu (EvNavigationAction *action) { GtkMenuShell *menu; + GtkWidget *item; + EvLink *link; EvHistory *history = action->priv->history; int start, end, i; menu = GTK_MENU_SHELL (gtk_menu_new ()); - if (history == NULL) { + if (history == NULL || ev_history_get_n_links (history) <= 0) { + item = new_empty_history_menu_item (action); + gtk_menu_shell_append (menu, item); 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); - } + start = 0; + end = ev_history_get_n_links (history); for (i = start; i < end; i++) { - EvLink *link = ev_history_get_link_nth (history, i); - GtkWidget *item; - + link = ev_history_get_link_nth (history, i); item = new_history_menu_item (action, link, i); gtk_menu_shell_append (menu, item); } @@ -139,49 +157,39 @@ build_menu (EvNavigationAction *action) } static void -menu_activated_cb (GtkMenuToolButton *button, +menu_activated_cb (EvNavigationActionWidget *button, EvNavigationAction *action) { GtkWidget *menu; menu = build_menu (action); - gtk_menu_tool_button_set_menu (button, menu); -} - -static gboolean -set_tooltip_cb (GtkMenuToolButton *proxy, - GtkTooltips *tooltips, - const char *tip, - const char *tip_private, - EvNavigationAction *action) -{ - gtk_menu_tool_button_set_arrow_tooltip (proxy, tooltips, - action->priv->arrow_tooltip, - NULL); - - /* don't stop emission */ - return FALSE; + ev_navigation_action_widget_set_menu (button, menu); } static void connect_proxy (GtkAction *action, GtkWidget *proxy) { - if (GTK_IS_MENU_TOOL_BUTTON (proxy)) - { - GtkWidget *menu; + GtkWidget *menu; - /* set dummy menu so the arrow gets sensitive */ - menu = gtk_menu_new (); - gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (proxy), menu); + /* set dummy menu so the arrow gets sensitive */ + menu = gtk_menu_new (); + ev_navigation_action_widget_set_menu (EV_NAVIGATION_ACTION_WIDGET (proxy), menu); - g_signal_connect (proxy, "show-menu", - G_CALLBACK (menu_activated_cb), action); + g_signal_connect (proxy, "show-menu", + G_CALLBACK (menu_activated_cb), action); - g_signal_connect (proxy, "set-tooltip", - G_CALLBACK (set_tooltip_cb), action); - } + GTK_ACTION_CLASS (ev_navigation_action_parent_class)->connect_proxy (action, proxy); +} - GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy); +static GtkWidget * +create_tool_item (GtkAction *action) +{ + EvNavigationActionWidget *proxy; + + proxy = g_object_new (EV_TYPE_NAVIGATION_ACTION_WIDGET, NULL); + gtk_widget_show (GTK_WIDGET (proxy)); + + return GTK_WIDGET (proxy); } static void @@ -200,48 +208,7 @@ ev_navigation_action_finalize (GObject *object) (gpointer *) &action->priv->history); } - g_free (action->priv->arrow_tooltip); - - parent_class->finalize (object); -} - -static void -ev_navigation_action_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EvNavigationAction *nav = EV_NAVIGATION_ACTION (object); - - switch (prop_id) - { - case PROP_ARROW_TOOLTIP: - nav->priv->arrow_tooltip = g_value_dup_string (value); - g_object_notify (object, "tooltip"); - break; - case PROP_DIRECTION: - nav->priv->direction = g_value_get_int (value); - break; - } -} - -static void -ev_navigation_action_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EvNavigationAction *nav = EV_NAVIGATION_ACTION (object); - - switch (prop_id) - { - case PROP_ARROW_TOOLTIP: - g_value_set_string (value, nav->priv->arrow_tooltip); - break; - case PROP_DIRECTION: - g_value_set_int (value, nav->priv->direction); - break; - } + G_OBJECT_CLASS (ev_navigation_action_parent_class)->finalize (object); } static void @@ -251,31 +218,10 @@ ev_navigation_action_class_init (EvNavigationActionClass *class) GtkActionClass *action_class = GTK_ACTION_CLASS (class); object_class->finalize = ev_navigation_action_finalize; - object_class->set_property = ev_navigation_action_set_property; - object_class->get_property = ev_navigation_action_get_property; - parent_class = g_type_class_peek_parent (class); - - action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON; + action_class->toolbar_item_type = GTK_TYPE_TOOL_ITEM; + action_class->create_tool_item = create_tool_item; action_class->connect_proxy = connect_proxy; - g_object_class_install_property (object_class, - PROP_ARROW_TOOLTIP, - g_param_spec_string ("arrow-tooltip", - "Arrow Tooltip", - "Arrow Tooltip", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_DIRECTION, - g_param_spec_int ("direction", - "Direction", - "Direction", - 0, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - g_type_class_add_private (object_class, sizeof (EvNavigationActionPrivate)); }