From: Marco Pesenti Gritti Date: Wed, 11 May 2005 09:42:22 +0000 (+0000) Subject: Use signals to notify action activation. Hopefully I did not break X-Git-Tag: EVINCE_0_3_1~33 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=39d906d93b5e9e0929fec8d3ef322f9597adee78;p=evince.git Use signals to notify action activation. Hopefully I did not break 2005-05-11 Marco Pesenti Gritti * shell/ev-marshal.list: * shell/ev-page-action.c: (ev_page_action_widget_class_init), (activate_cb), (match_selected_cb), (activate_link_cb), (connect_proxy), (ev_page_action_class_init): * shell/ev-page-action.h: Use signals to notify action activation. Hopefully I did not break completion since I cant test... * shell/ev-window.c: (activate_link_cb), (activate_label_cb), (register_custom_actions): Connect to page selector actions and also grab focus on the view when activated. --- diff --git a/ChangeLog b/ChangeLog index 60e03110..b6707515 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2005-05-11 Marco Pesenti Gritti + + * shell/ev-marshal.list: + * shell/ev-page-action.c: (ev_page_action_widget_class_init), + (activate_cb), (match_selected_cb), (activate_link_cb), + (connect_proxy), (ev_page_action_class_init): + * shell/ev-page-action.h: + + Use signals to notify action activation. Hopefully + I did not break completion since I cant test... + + * shell/ev-window.c: (activate_link_cb), (activate_label_cb), + (register_custom_actions): + + Connect to page selector actions and also grab focus on + the view when activated. + Wed May 11 01:18:29 2005 Jonathan Blandford * pdf/ev-poppler.cc: diff --git a/shell/ev-marshal.list b/shell/ev-marshal.list index c2a026bf..44b8bcbb 100644 --- a/shell/ev-marshal.list +++ b/shell/ev-marshal.list @@ -1,3 +1,4 @@ VOID:NONE VOID:OBJECT,OBJECT VOID:ENUM,BOOLEAN +BOOLEAN:STRING diff --git a/shell/ev-page-action.c b/shell/ev-page-action.c index 2eed3763..864e5e39 100644 --- a/shell/ev-page-action.c +++ b/shell/ev-page-action.c @@ -24,6 +24,7 @@ #include "ev-page-action.h" #include "ev-window.h" #include "ev-document-links.h" +#include "ev-marshal.h" #include #include @@ -49,6 +50,9 @@ struct _EvPageActionWidget struct _EvPageActionWidgetClass { GtkToolItemClass parent_class; + + void (* activate_link) (EvPageActionWidget *page_action, + EvLink *link); }; struct _EvPageActionPrivate @@ -66,6 +70,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 +117,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)) @@ -166,11 +197,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 = @@ -302,7 +336,8 @@ 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, signals[ACTIVATE_LINK], 0, link); return TRUE; } @@ -422,6 +457,12 @@ update_model (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *proxy) } } +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 +470,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 @@ -570,6 +614,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", diff --git a/shell/ev-page-action.h b/shell/ev-page-action.h index 8ac0d54c..c8b30ba6 100644 --- a/shell/ev-page-action.h +++ b/shell/ev-page-action.h @@ -51,8 +51,10 @@ struct _EvPageActionClass { GtkActionClass parent_class; - void (* goto_page) (EvPageAction *page_action, - int page_number); + void (* activate_link) (EvPageAction *page_action, + EvLink *link); + gboolean (*activate_label) (EvPageAction *page_action, + char *label); }; GType ev_page_action_get_type (void); diff --git a/shell/ev-window.c b/shell/ev-window.c index 2475de0a..fc1f0ca7 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -2436,6 +2436,25 @@ drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, } } +static void +activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window) +{ + g_return_if_fail (EV_IS_WINDOW (window)); + + ev_page_cache_set_link (window->priv->page_cache, link); + gtk_widget_grab_focus (window->priv->view); +} + +static gboolean +activate_label_cb (EvPageAction *page_action, char *label, EvWindow *window) +{ + g_return_val_if_fail (EV_IS_WINDOW (window), FALSE); + + gtk_widget_grab_focus (window->priv->view); + + return ev_page_cache_set_page_label (window->priv->page_cache, label); +} + static void register_custom_actions (EvWindow *window, GtkActionGroup *group) { @@ -2447,6 +2466,10 @@ register_custom_actions (EvWindow *window, GtkActionGroup *group) "tooltip", _("Select Page"), "visible_overflown", FALSE, NULL); + g_signal_connect (action, "activate_link", + G_CALLBACK (activate_link_cb), window); + g_signal_connect (action, "activate_label", + G_CALLBACK (activate_label_cb), window); gtk_action_group_add_action (group, action); g_object_unref (action);