From 33bf66b8f4e2d719c847af1c177c71b5173b49aa Mon Sep 17 00:00:00 2001 From: Nickolay V. Shmyrev Date: Wed, 09 May 2007 15:02:09 +0000 Subject: Make navigation action unsensitive instead of showing menu with 2007-05-09 Nickolay V. Shmyrev * shell/ev-history.c: (ev_history_class_init), (ev_history_add_link): * shell/ev-history.h: * shell/ev-navigation-action.c: (ev_navigation_action_history_changed), (ev_navigation_action_set_history), (build_menu), (ev_navigation_action_finalize): * shell/ev-window.c: (ev_window_setup_action_sensitivity): Make navigation action unsensitive instead of showing menu with unsensitive word. svn path=/trunk/; revision=2443 --- diff --git a/ChangeLog b/ChangeLog index 0a6a405..de28131 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-05-09 Nickolay V. Shmyrev + + * shell/ev-history.c: (ev_history_class_init), + (ev_history_add_link): + * shell/ev-history.h: + * shell/ev-navigation-action.c: + (ev_navigation_action_history_changed), + (ev_navigation_action_set_history), (build_menu), + (ev_navigation_action_finalize): + * shell/ev-window.c: (ev_window_setup_action_sensitivity): + + Make navigation action unsensitive instead of showing + menu with unsensitive word. + 2007-05-08 Carlos Garcia Campos * shell/ev-application.[ch]: (ev_application_shutdown), diff --git a/shell/ev-history.c b/shell/ev-history.c index c06fa25..cb015cc 100644 --- a/shell/ev-history.c +++ b/shell/ev-history.c @@ -24,6 +24,15 @@ #include "ev-history.h" + +enum +{ + HISTORY_CHANGED, + N_SIGNALS +}; + +static guint signals[N_SIGNALS] = {0, }; + struct _EvHistoryPrivate { GList *links; @@ -68,6 +77,15 @@ ev_history_class_init (EvHistoryClass *class) object_class->finalize = ev_history_finalize; + signals[HISTORY_CHANGED] = + g_signal_new ("changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EvHistoryClass, changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + g_type_class_add_private (object_class, sizeof (EvHistoryPrivate)); } @@ -98,6 +116,8 @@ ev_history_add_link (EvHistory *history, EvLink *link) history->priv->links = g_list_delete_link (history->priv->links, history->priv->links); } + + g_signal_emit (G_OBJECT (history), signals[HISTORY_CHANGED], 0); } EvLink * diff --git a/shell/ev-history.h b/shell/ev-history.h index 2d27bda..55eeb7c 100644 --- a/shell/ev-history.h +++ b/shell/ev-history.h @@ -48,6 +48,8 @@ struct _EvHistory struct _EvHistoryClass { GObjectClass parent_class; + + void (*changed) (EvHistory *history); }; GType ev_history_get_type (void); diff --git a/shell/ev-navigation-action.c b/shell/ev-navigation-action.c index dd4e38e..9da89f9 100644 --- a/shell/ev-navigation-action.c +++ b/shell/ev-navigation-action.c @@ -54,6 +54,17 @@ G_DEFINE_TYPE (EvNavigationAction, ev_navigation_action, GTK_TYPE_ACTION) #define EV_NAVIGATION_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_NAVIGATION_ACTION, EvNavigationActionPrivate)) +static void +ev_navigation_action_history_changed (EvHistory *history, + gpointer data) +{ + EvNavigationAction *action = EV_NAVIGATION_ACTION (data); + + gtk_action_set_sensitive (action, ev_history_get_n_links (history) > 0); + + return; +} + void ev_navigation_action_set_history (EvNavigationAction *action, EvHistory *history) @@ -62,6 +73,10 @@ ev_navigation_action_set_history (EvNavigationAction *action, g_object_add_weak_pointer (G_OBJECT (action->priv->history), (gpointer) &action->priv->history); + + g_signal_connect_object (history, "changed", + ev_navigation_action_history_changed, + action, 0); } static void @@ -111,18 +126,6 @@ new_history_menu_item (EvNavigationAction *action, } 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; @@ -133,9 +136,7 @@ build_menu (EvNavigationAction *action) menu = GTK_MENU_SHELL (gtk_menu_new ()); - if (history == NULL || ev_history_get_n_links (history) <= 0) { - item = new_empty_history_menu_item (action); - gtk_menu_shell_append (menu, item); + if (history == NULL) { return GTK_WIDGET (menu); } @@ -218,8 +219,9 @@ 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_object_remove_weak_pointer (G_OBJECT (action->priv->history), + (gpointer) &action->priv->history); + action->priv->history = NULL; } G_OBJECT_CLASS (ev_navigation_action_parent_class)->finalize (object); diff --git a/shell/ev-window.c b/shell/ev-window.c index c428643..939f510 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -391,7 +391,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window) /* Toolbar-specific actions: */ ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages); ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages); - ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, has_pages); + ev_window_set_action_sensitive (ev_window, NAVIGATION_ACTION, FALSE); ev_window_update_actions (ev_window); } -- cgit v0.9.1