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=b34c37892b781ff12573546366c854665cd28af7;hb=054abf70e4d37877fa12d442af5abc4e8170b046;hp=88fe67b6de01bbadca11021d4876aa0568fa9fe5;hpb=72fc0a73ea845307d6a109678952a0d07f6a1af4;p=evince.git diff --git a/shell/ev-navigation-action.c b/shell/ev-navigation-action.c index 88fe67b6..b34c3789 100644 --- a/shell/ev-navigation-action.c +++ b/shell/ev-navigation-action.c @@ -14,23 +14,18 @@ * * 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. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include "config.h" +#include +#include + #include "ev-navigation-action.h" #include "ev-navigation-action-widget.h" -#include -#include -#include -#include -#include -#include -#include -#include enum { @@ -54,6 +49,16 @@ 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 (GTK_ACTION (action), + ev_history_get_n_links (history) > 0); +} + void ev_navigation_action_set_history (EvNavigationAction *action, EvHistory *history) @@ -61,7 +66,11 @@ ev_navigation_action_set_history (EvNavigationAction *action, action->priv->history = history; g_object_add_weak_pointer (G_OBJECT (action->priv->history), - (gpointer *) &action->priv->history); + (gpointer) &action->priv->history); + + g_signal_connect_object (history, "changed", + G_CALLBACK (ev_navigation_action_history_changed), + action, 0); } static void @@ -72,7 +81,6 @@ activate_menu_item_cb (GtkWidget *widget, EvNavigationAction *action) 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); if (action->priv->history) { EvLink *link; @@ -94,10 +102,11 @@ new_history_menu_item (EvNavigationAction *action, title = ev_link_get_title (link); item = gtk_image_menu_item_new_with_label (title); + label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (item))); + gtk_label_set_use_markup (label, TRUE); 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); @@ -110,18 +119,6 @@ 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) { @@ -131,16 +128,14 @@ build_menu (EvNavigationAction *action) EvHistory *history = action->priv->history; int start, end, i; - 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); - return GTK_WIDGET (menu); + return NULL; } - start = MAX (ev_history_get_current_index (action->priv->history) - 5, 0); - end = MIN (ev_history_get_n_links (history), start + 7); + menu = GTK_MENU_SHELL (gtk_menu_new ()); + + start = 0; + end = ev_history_get_n_links (history); for (i = start; i < end; i++) { link = ev_history_get_link_nth (history, i); @@ -166,12 +161,14 @@ connect_proxy (GtkAction *action, GtkWidget *proxy) { GtkWidget *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); + if (GTK_IS_TOOL_ITEM (proxy)) { + /* 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); + } GTK_ACTION_CLASS (ev_navigation_action_parent_class)->connect_proxy (action, proxy); } @@ -187,6 +184,23 @@ create_tool_item (GtkAction *action) return GTK_WIDGET (proxy); } +static GtkWidget * +create_menu_item (GtkAction *action) +{ + GtkWidget *menu; + GtkWidget *menu_item; + + menu = build_menu (EV_NAVIGATION_ACTION (action)); + + menu_item = GTK_ACTION_CLASS (ev_navigation_action_parent_class)->create_menu_item (action); + + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), menu); + + gtk_widget_show (menu_item); + + return menu_item; +} + static void ev_navigation_action_init (EvNavigationAction *action) { @@ -199,8 +213,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); @@ -217,6 +232,7 @@ ev_navigation_action_class_init (EvNavigationActionClass *class) action_class->toolbar_item_type = GTK_TYPE_TOOL_ITEM; action_class->create_tool_item = create_tool_item; action_class->connect_proxy = connect_proxy; + action_class->create_menu_item = create_menu_item; widget_signals[WIDGET_ACTIVATE_LINK] = g_signal_new ("activate_link", G_OBJECT_CLASS_TYPE (object_class),