diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2012-03-20 10:22:28 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2012-03-20 10:22:28 -0700 |
commit | 317856501e5689a0688374e770c5f1ccd982a799 (patch) | |
tree | 969d732d3f04fe3478b698d879e68c28605e48e7 /src | |
parent | f33c29445f7b6f2c530d3080962e016c0cdfae40 (diff) |
viewer: Add accelerator to focus page selector
An accelerator group for EvView shortcuts is added with an initial
accelerator to focus the page selector in the toolbar. Since these
accelerators are only intended to be associated with the EvView, we
set them sensitive only when it comes into focus.
Diffstat (limited to 'src')
-rw-r--r-- | src/evbp-viewer.c | 43 | ||||
-rw-r--r-- | src/evbp-viewer.h | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/evbp-viewer.c b/src/evbp-viewer.c index 7ed81e7..7f31e48 100644 --- a/src/evbp-viewer.c +++ b/src/evbp-viewer.c @@ -125,6 +125,28 @@ page_action_link_activated(GtkAction *action, GObject *obj, gpointer user_data) } static void +focus_page_selector(GtkAction *action, EvbpViewer *viewer) +{ + GtkAction *page_action; + + page_action = gtk_action_group_get_action(viewer->action_group, + "PageSelector"); + ev_page_action_grab_focus(EV_PAGE_ACTION(page_action)); +} + +static gboolean +view_focus_changed(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + GdkEventFocus *focus = (GdkEventFocus *)event; + EvbpViewer *viewer = EVBP_VIEWER(user_data); + + if (viewer->accel_group) + gtk_action_group_set_sensitive(viewer->accel_group, focus->in); + + return FALSE; +} + +static void evbp_viewer_dispose(GObject *object) { EvbpViewer *viewer = EVBP_VIEWER(object); @@ -141,6 +163,10 @@ evbp_viewer_dispose(GObject *object) g_object_unref(viewer->action_group); viewer->action_group = NULL; } + if (viewer->accel_group) { + g_object_unref(viewer->accel_group); + viewer->accel_group = NULL; + } if (viewer->ui_manager) { g_object_unref(viewer->ui_manager); viewer->ui_manager = NULL; @@ -199,6 +225,11 @@ static const GtkToggleActionEntry toggle_action_entries[] = { G_CALLBACK(evbp_viewer_toggle_continuous), FALSE }, }; +static const GtkActionEntry accel_entries[] = { + { "FocusPageSelector", NULL, "", "<control>l", NULL, + G_CALLBACK(focus_page_selector) }, +}; + static const gchar ui_string[] = "<ui>\n" " <toolbar name=\"ViewerToolbar\">\n" @@ -211,6 +242,7 @@ static const gchar ui_string[] = " <toolitem name=\"ViewPageWidth\" action=\"ViewPageWidth\"/>\n" " <toolitem name=\"ViewContinuous\" action=\"ViewContinuous\"/>\n" " </toolbar>\n" + " <accelerator name=\"FocusPageSelector\" action=\"FocusPageSelector\"/>\n" "</ui>\n"; static void @@ -247,9 +279,16 @@ evbp_viewer_init(EvbpViewer *viewer) g_object_unref(action); gtk_action_group_set_sensitive(viewer->action_group, FALSE); + viewer->accel_group = gtk_action_group_new("ViewerAccelerators"); + gtk_action_group_add_actions(viewer->accel_group, accel_entries, + G_N_ELEMENTS(accel_entries), viewer); + gtk_action_group_set_sensitive(viewer->accel_group, FALSE); + viewer->ui_manager = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(viewer->ui_manager, viewer->action_group, 0); + gtk_ui_manager_insert_action_group(viewer->ui_manager, + viewer->accel_group, 1); if (!gtk_ui_manager_add_ui_from_string(viewer->ui_manager, ui_string, sizeof(ui_string) - 1, &error)) { g_warning("Failed to load ui from string: %s", error->message); @@ -282,6 +321,10 @@ evbp_viewer_init(EvbpViewer *viewer) gtk_widget_show(viewer->scroll); viewer->view = ev_view_new(); + g_signal_connect(viewer->view, "focus-in-event", + G_CALLBACK(view_focus_changed), viewer); + g_signal_connect(viewer->view, "focus-out-event", + G_CALLBACK(view_focus_changed), viewer); ev_view_set_model(EV_VIEW(viewer->view), viewer->model); ev_view_set_loading(EV_VIEW(viewer->view), TRUE); gtk_widget_show(viewer->view); diff --git a/src/evbp-viewer.h b/src/evbp-viewer.h index bd74c41..08b3503 100644 --- a/src/evbp-viewer.h +++ b/src/evbp-viewer.h @@ -50,6 +50,7 @@ struct _EvbpViewer { EvDocumentModel *model; GtkActionGroup *action_group; + GtkActionGroup *accel_group; GtkUIManager *ui_manager; GtkWidget *scroll; |