X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-page-action.c;h=4bb63b2f1bc7c7f660e56e7403a1f86f5b58b551;hb=848665b157185945d190a7a746d054d7f5d5e6e0;hp=2eed3763f13b01b731f08613ad9f1a32156d5c1a;hpb=5112457d6c321bde178c3577eb37bd0ee62bc209;p=evince.git diff --git a/shell/ev-page-action.c b/shell/ev-page-action.c index 2eed3763..4bb63b2f 100644 --- a/shell/ev-page-action.c +++ b/shell/ev-page-action.c @@ -22,8 +22,10 @@ #include "config.h" #include "ev-page-action.h" +#include "ev-page-cache.h" #include "ev-window.h" #include "ev-document-links.h" +#include "ev-marshal.h" #include #include @@ -49,6 +51,9 @@ struct _EvPageActionWidget struct _EvPageActionWidgetClass { GtkToolItemClass parent_class; + + void (* activate_link) (EvPageActionWidget *page_action, + EvLink *link); }; struct _EvPageActionPrivate @@ -66,6 +71,14 @@ static void ev_page_action_widget_class_init (EvPageActionWidgetClass *action_w #define EV_TYPE_PAGE_ACTION_WIDGET (ev_page_action_widget_get_type ()) #define EV_PAGE_ACTION_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_PAGE_ACTION_WIDGET, EvPageActionWidget)) +enum +{ + WIDGET_ACTIVATE_LINK, + WIDGET_N_SIGNALS +}; + +static guint widget_signals[WIDGET_N_SIGNALS] = {0, }; + G_DEFINE_TYPE (EvPageActionWidget, ev_page_action_widget, GTK_TYPE_TOOL_ITEM) static void @@ -105,11 +118,30 @@ ev_page_action_widget_class_init (EvPageActionWidgetClass *class) GObjectClass *object_class = G_OBJECT_CLASS (class); object_class->finalize = ev_page_action_widget_finalize; + + widget_signals[WIDGET_ACTIVATE_LINK] = g_signal_new ("activate_link", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EvPageActionClass, activate_link), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); + } static void ev_page_action_init (EvPageAction *action); static void ev_page_action_class_init (EvPageActionClass *class); +enum +{ + ACTIVATE_LINK, + ACTIVATE_LABEL, + N_SIGNALS +}; + +static guint signals[N_SIGNALS] = {0, }; + G_DEFINE_TYPE (EvPageAction, ev_page_action, GTK_TYPE_ACTION) #define EV_PAGE_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_PAGE_ACTION, EvPageActionPrivate)) @@ -149,10 +181,17 @@ page_changed_cb (EvPageCache *page_cache, g_assert (proxy); if (page_cache != NULL && page >= 0) { - gchar *page_label = ev_page_cache_get_page_label (page_cache, page); + gchar *page_label; + + gtk_entry_set_width_chars (GTK_ENTRY (proxy->entry), + CLAMP (ev_page_cache_get_max_label_chars (page_cache), + 4, 12)); + + page_label = ev_page_cache_get_page_label (page_cache, page); gtk_entry_set_text (GTK_ENTRY (proxy->entry), page_label); gtk_editable_set_position (GTK_EDITABLE (proxy->entry), -1); g_free (page_label); + } else { gtk_entry_set_text (GTK_ENTRY (proxy->entry), ""); } @@ -166,11 +205,14 @@ activate_cb (GtkWidget *entry, GtkAction *action) EvPageAction *page = EV_PAGE_ACTION (action); EvPageCache *page_cache; const char *text; + gboolean changed; text = gtk_entry_get_text (GTK_ENTRY (entry)); page_cache = page->priv->page_cache; - if (! ev_page_cache_set_page_label (page_cache, text)) { + g_signal_emit (action, signals[ACTIVATE_LABEL], 0, text, &changed); + + if (!changed) { /* rest the entry to the current page if we were unable to * change it */ gchar *page_label = @@ -265,6 +307,9 @@ build_new_tree_cb (GtkTreeModel *model, -1); } + if (link) + g_object_unref (link); + return FALSE; } @@ -302,7 +347,13 @@ match_selected_cb (GtkEntryCompletion *completion, gtk_tree_model_get (proxy->model, iter, EV_DOCUMENT_LINKS_COLUMN_LINK, &link, -1); - ev_page_cache_set_link (proxy->page_cache, link); + + g_signal_emit (proxy, widget_signals[WIDGET_ACTIVATE_LINK], 0, link); + + if (link) + g_object_unref (link); + + gtk_tree_iter_free (iter); return TRUE; } @@ -326,6 +377,11 @@ display_completion_text (GtkCellLayout *cell_layout, -1); g_object_set (renderer, "text", ev_link_get_title (link), NULL); + + if (link) + g_object_unref (link); + + gtk_tree_iter_free (iter); } static gboolean @@ -347,8 +403,12 @@ match_completion (GtkEntryCompletion *completion, -1); - if (link) + if (link) { text = ev_link_get_title (link); + g_object_unref (link); + } + + gtk_tree_iter_free (iter); if (text && key ) { gchar *normalized_text; @@ -419,9 +479,18 @@ update_model (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *proxy) (GtkCellLayoutDataFunc) display_completion_text, proxy, NULL); gtk_entry_set_completion (GTK_ENTRY (proxy->entry), completion); + + g_object_unref (completion); + g_object_unref (model); } } +static void +activate_link_cb (EvPageActionWidget *proxy, EvLink *link, EvPageAction *action) +{ + g_signal_emit (action, signals[ACTIVATE_LINK], 0, link); +} + static void connect_proxy (GtkAction *action, GtkWidget *proxy) { @@ -429,6 +498,9 @@ connect_proxy (GtkAction *action, GtkWidget *proxy) g_signal_connect_object (action, "notify::page-cache", G_CALLBACK (update_page_cache), proxy, 0); + g_signal_connect (proxy, "activate_link", + G_CALLBACK (activate_link_cb), + action); update_page_cache (EV_PAGE_ACTION (action), NULL, EV_PAGE_ACTION_WIDGET (proxy)); /* We only go through this whole rigmarole if we can set @@ -519,7 +591,7 @@ ev_page_action_set_document (EvPageAction *page, EvDocument *document) EvPageCache *page_cache = NULL; if (document) - page_cache = ev_document_get_page_cache (document); + page_cache = ev_page_cache_get (document); g_object_set (page, "page-cache", page_cache, @@ -570,6 +642,23 @@ ev_page_action_class_init (EvPageActionClass *class) action_class->create_tool_item = create_tool_item; action_class->connect_proxy = connect_proxy; + signals[ACTIVATE_LINK] = g_signal_new ("activate_link", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EvPageActionClass, activate_link), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); + signals[ACTIVATE_LABEL] = g_signal_new ("activate_label", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EvPageActionClass, activate_link), + NULL, NULL, + ev_marshal_BOOLEAN__STRING, + G_TYPE_BOOLEAN, 1, + G_TYPE_STRING); + g_object_class_install_property (object_class, PROP_PAGE_CACHE, g_param_spec_object ("page-cache",