Skip to content

Commit

Permalink
Use a GtkEntry with an arrow icon instead of a GtkComboBox for zoom s…
Browse files Browse the repository at this point in the history
…elector

This allows us to use our own custom menu with toggle and non-toggle
menu items. Fit-page and fit-width options are toggle menu items, so
that it's possible to know which mode is currently in use. The code is
simpler now too and zoom selector actions are handled like all other
chrome actions.
  • Loading branch information
Carlos Garcia Campos committed Jul 26, 2013
1 parent 0143fc8 commit 1648495
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 246 deletions.
1 change: 0 additions & 1 deletion po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,5 @@ shell/ev-sidebar-thumbnails.c
shell/ev-utils.c
shell/ev-window.c
shell/ev-window-title.c
shell/ev-zoom-action-widget.c
shell/main.c
[type: gettext/glade]shell/evince-appmenu.ui
125 changes: 100 additions & 25 deletions shell/ev-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ struct _EvWindowPrivate {
GtkActionGroup *action_group;
GtkActionGroup *view_popup_action_group;
GtkActionGroup *attachment_popup_action_group;
GtkActionGroup *zoom_selector_popup_action_group;
GtkRecentManager *recent_manager;
GtkActionGroup *recent_action_group;
guint recent_ui_id;
Expand Down Expand Up @@ -474,8 +475,6 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
ev_window_set_action_sensitive (ev_window, "ViewContinuous", has_pages);
ev_window_set_action_sensitive (ev_window, "ViewDual", has_pages);
ev_window_set_action_sensitive (ev_window, "ViewDualOddLeft", has_pages);
ev_window_set_action_sensitive (ev_window, "ViewFitPage", has_pages);
ev_window_set_action_sensitive (ev_window, "ViewFitWidth", has_pages);
ev_window_set_action_sensitive (ev_window, "ViewReload", has_pages);
ev_window_set_action_sensitive (ev_window, "ViewAutoscroll", has_pages);
ev_window_set_action_sensitive (ev_window, "ViewInvertedColors", has_pages);
Expand Down Expand Up @@ -597,7 +596,7 @@ update_chrome_flag (EvWindow *window, EvChrome flag, gboolean active)
static void
update_sizing_buttons (EvWindow *window)
{
GtkActionGroup *action_group = window->priv->action_group;
GtkActionGroup *action_group = window->priv->zoom_selector_popup_action_group;
GtkAction *action;
gboolean fit_page, fit_width;

Expand Down Expand Up @@ -3852,6 +3851,26 @@ ev_window_cmd_fit_width (GtkAction *action, EvWindow *ev_window)
ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FIT_WIDTH);
}

static void
ev_window_cmd_view_zoom_activate (GtkAction *action,
EvWindow *ev_window)
{
const char *action_name = gtk_action_get_name (action);
gdouble zoom = 0;
guint i;

for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++) {
if (strcmp (action_name, zoom_levels[i].name) == 0) {
zoom = zoom_levels[i].level;
break;
}
}
g_assert (zoom > 0);

ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
ev_document_model_set_scale (ev_window->priv->model,
zoom * get_screen_dpi (ev_window) / 72.0);
}

static void
ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window)
Expand Down Expand Up @@ -4766,15 +4785,24 @@ ev_window_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *
}

static void
ev_window_max_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *window)
ev_window_setup_zoom_actions_visibility (EvWindow *window,
gdouble max_scale)
{
GtkAction *action;
gdouble max_scale;
GtkActionGroup *action_group = window->priv->zoom_selector_popup_action_group;
guint i;

max_scale = ev_document_model_get_max_scale (model);
action = gtk_action_group_get_action (window->priv->action_group,
ZOOM_CONTROL_ACTION);
ev_zoom_action_set_max_zoom_level (EV_ZOOM_ACTION (action), max_scale);
for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++) {
GtkAction *action;

action = gtk_action_group_get_action (action_group, zoom_levels[i].name);
gtk_action_set_visible (action, zoom_levels[i].level <= max_scale);
}
}

static void
ev_window_max_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *window)
{
ev_window_setup_zoom_actions_visibility (window, ev_document_model_get_max_scale (model));
}

static void
Expand Down Expand Up @@ -5612,6 +5640,8 @@ ev_window_dispose (GObject *object)
priv->attachment_popup_action_group = NULL;
}

g_clear_object (&priv->zoom_selector_popup_action_group);

if (priv->recent_action_group) {
g_object_unref (priv->recent_action_group);
priv->recent_action_group = NULL;
Expand Down Expand Up @@ -5982,20 +6012,13 @@ static const GtkToggleActionEntry toggle_entries[] = {
{ "ViewPresentation", EV_STOCK_RUN_PRESENTATION, N_("Pre_sentation"), "F5",
N_("Run document as a presentation"),
G_CALLBACK (ev_window_cmd_view_presentation) },
{ "ViewFitPage", EV_STOCK_ZOOM_PAGE, N_("Fit Pa_ge"), NULL,
N_("Make the current document fill the window"),
G_CALLBACK (ev_window_cmd_view_fit_page) },
{ "ViewFitWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit _Width"), NULL,
N_("Make the current document fill the window width"),
G_CALLBACK (ev_window_cmd_view_fit_width) },
{ "ViewInvertedColors", EV_STOCK_INVERTED_COLORS, N_("_Inverted Colors"), "<control>I",
N_("Show page contents with the colors inverted"),
G_CALLBACK (ev_window_cmd_view_inverted_colors) },

{ "EditFind", "edit-find-symbolic", N_("_Find…"), "<control>F",
N_("Find a word or phrase in the document"),
G_CALLBACK (ev_window_cmd_toggle_find) },

};

/* Popups specific items */
Expand Down Expand Up @@ -6024,6 +6047,15 @@ static const GtkActionEntry attachment_popup_entries [] = {
NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) },
};

static const GtkToggleActionEntry zoom_selector_popup_actions[] = {
{ "ViewFitPage", EV_STOCK_ZOOM_PAGE, N_("Fit Pa_ge"), NULL,
N_("Make the current document fill the window"),
G_CALLBACK (ev_window_cmd_view_fit_page) },
{ "ViewFitWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit _Width"), NULL,
N_("Make the current document fill the window width"),
G_CALLBACK (ev_window_cmd_view_fit_width) }
};

static void
sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
{
Expand Down Expand Up @@ -6090,6 +6122,36 @@ zoom_action_activated_cb (EvZoomAction *action,
gtk_widget_grab_focus (window->priv->view);
}

static void
ev_window_register_zoom_selector_popup_actions (EvWindow *window)
{
GtkActionGroup *action_group = window->priv->zoom_selector_popup_action_group;
guint i, new_ui_id;

new_ui_id = gtk_ui_manager_new_merge_id (window->priv->ui_manager);

for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++) {
GtkAction *action;

action = gtk_action_new (zoom_levels[i].name,
_(zoom_levels[i].name),
NULL, NULL);
g_signal_connect (action, "activate",
G_CALLBACK (ev_window_cmd_view_zoom_activate),
window);
gtk_action_group_add_action (action_group, action);
g_object_unref (action);

gtk_ui_manager_add_ui (window->priv->ui_manager,
new_ui_id,
"/ZoomSelectorPopup/ViewZoomItems",
_(zoom_levels[i].name),
zoom_levels[i].name,
GTK_UI_MANAGER_MENUITEM,
FALSE);
}
}

static void
register_custom_actions (EvWindow *window, GtkActionGroup *group)
{
Expand Down Expand Up @@ -6117,6 +6179,8 @@ register_custom_actions (EvWindow *window, GtkActionGroup *group)
NULL);
ev_zoom_action_set_model (EV_ZOOM_ACTION (action),
window->priv->model);
ev_zoom_action_set_window (EV_ZOOM_ACTION (action),
window);
g_signal_connect (action, "activated",
G_CALLBACK (zoom_action_activated_cb), window);
gtk_action_group_add_action (group, action);
Expand Down Expand Up @@ -6178,14 +6242,6 @@ set_action_properties (GtkActionGroup *action_group)
/*translators: this is the label for toolbar button*/
g_object_set (action, "short_label", _("Zoom Out"), NULL);

action = gtk_action_group_get_action (action_group, "ViewFitPage");
/*translators: this is the label for toolbar button*/
g_object_set (action, "short_label", _("Fit Page"), NULL);

action = gtk_action_group_get_action (action_group, "ViewFitWidth");
/*translators: this is the label for toolbar button*/
g_object_set (action, "short_label", _("Fit Width"), NULL);

action = gtk_action_group_get_action (action_group, "LeaveFullscreen");
g_object_set (action, "is-important", TRUE, NULL);
}
Expand Down Expand Up @@ -7160,11 +7216,22 @@ ev_window_init (EvWindow *ev_window)
gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
action_group, 0);

action_group = gtk_action_group_new ("ZoomSelectorPopupActions");
ev_window->priv->zoom_selector_popup_action_group = action_group;
gtk_action_group_set_translation_domain (action_group, NULL);
gtk_action_group_add_toggle_actions (action_group, zoom_selector_popup_actions,
G_N_ELEMENTS (zoom_selector_popup_actions),
ev_window);
gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
action_group, 0);

gtk_ui_manager_add_ui_from_resource (ev_window->priv->ui_manager,
"/org/gnome/evince/shell/ui/evince.xml",
&error);
g_assert_no_error (error);

ev_window_register_zoom_selector_popup_actions (ev_window);

css_provider = gtk_css_provider_new ();
_gtk_css_provider_load_from_resource (css_provider,
"/org/gnome/evince/shell/ui/evince.css",
Expand Down Expand Up @@ -7547,3 +7614,11 @@ ev_window_get_main_action_group (EvWindow *ev_window)

return ev_window->priv->action_group;
}

GtkActionGroup *
ev_window_get_zoom_selector_action_group (EvWindow *ev_window)
{
g_return_val_if_fail (EV_WINDOW (ev_window), NULL);

return ev_window->priv->zoom_selector_popup_action_group;
}
41 changes: 21 additions & 20 deletions shell/ev-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,27 @@ struct _EvWindowClass {
GtkApplicationWindowClass base_class;
};

GType ev_window_get_type (void) G_GNUC_CONST;
GtkWidget *ev_window_new (void);
const char *ev_window_get_uri (EvWindow *ev_window);
void ev_window_open_uri (EvWindow *ev_window,
const char *uri,
EvLinkDest *dest,
EvWindowRunMode mode,
const gchar *search_string);
void ev_window_open_document (EvWindow *ev_window,
EvDocument *document,
EvLinkDest *dest,
EvWindowRunMode mode,
const gchar *search_string);
gboolean ev_window_is_empty (const EvWindow *ev_window);
void ev_window_print_range (EvWindow *ev_window,
int first_page,
int last_page);
const gchar *ev_window_get_dbus_object_path (EvWindow *ev_window);
GtkUIManager *ev_window_get_ui_manager (EvWindow *ev_window);
GtkActionGroup *ev_window_get_main_action_group (EvWindow *ev_window);
GType ev_window_get_type (void) G_GNUC_CONST;
GtkWidget *ev_window_new (void);
const char *ev_window_get_uri (EvWindow *ev_window);
void ev_window_open_uri (EvWindow *ev_window,
const char *uri,
EvLinkDest *dest,
EvWindowRunMode mode,
const gchar *search_string);
void ev_window_open_document (EvWindow *ev_window,
EvDocument *document,
EvLinkDest *dest,
EvWindowRunMode mode,
const gchar *search_string);
gboolean ev_window_is_empty (const EvWindow *ev_window);
void ev_window_print_range (EvWindow *ev_window,
int first_page,
int last_page);
const gchar *ev_window_get_dbus_object_path (EvWindow *ev_window);
GtkUIManager *ev_window_get_ui_manager (EvWindow *ev_window);
GtkActionGroup *ev_window_get_main_action_group (EvWindow *ev_window);
GtkActionGroup *ev_window_get_zoom_selector_action_group (EvWindow *ev_window);


G_END_DECLS
Expand Down
Loading

0 comments on commit 1648495

Please sign in to comment.