Skip to content

Commit 43acb8f

Browse files
Cobinjaclefebvre
authored andcommitted
Add zoom reset (#132)
1 parent 2e864b2 commit 43acb8f

File tree

9 files changed

+67
-0
lines changed

9 files changed

+67
-0
lines changed

libview/ev-view.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5653,6 +5653,14 @@ ev_view_zoom_out (EvView *view)
56535653
ev_view_zoom (view, ZOOM_OUT_FACTOR);
56545654
}
56555655

5656+
void
5657+
ev_view_zoom_reset (EvView *view)
5658+
{
5659+
gdouble scale;
5660+
g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
5661+
ev_document_model_set_scale (view->model, 1.0);
5662+
}
5663+
56565664
static double
56575665
zoom_for_size_fit_width (gdouble doc_width,
56585666
gdouble doc_height,

libview/ev-view.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ gboolean ev_view_can_zoom_in (EvView *view);
6767
void ev_view_zoom_in (EvView *view);
6868
gboolean ev_view_can_zoom_out (EvView *view);
6969
void ev_view_zoom_out (EvView *view);
70+
void ev_view_zoom_reset (EvView *view);
7071
void ev_view_zoom (EvView *view,
7172
gdouble factor);
7273

libview/ev-web-view.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,17 @@ ev_web_view_zoom_out(EvWebView *webview)
691691
return TRUE;
692692
}
693693

694+
gboolean
695+
ev_web_view_zoom_reset(EvWebView *webview)
696+
{
697+
if (webview->zoom_level == 1)
698+
return FALSE;
699+
700+
webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(webview),
701+
1.0);
702+
return TRUE;
703+
}
704+
694705
/**
695706
* ev_web_view_disconnect_handlers
696707
* @webview : #EvWebView instance

libview/ev-web-view.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ void ev_web_view_copy (EvWebView *webview);
8383
/* Zoom control */
8484
gboolean ev_web_view_zoom_in (EvWebView *webview);
8585
gboolean ev_web_view_zoom_out (EvWebView *webview);
86+
gboolean ev_web_view_zoom_reset (EvWebView *webview);
8687

8788
/*For safe replacement by an EvView*/
8889
void ev_web_view_disconnect_handlers (EvWebView *webview);

previewer/ev-previewer-window.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ ev_previewer_window_zoom_out (GtkAction *action,
135135
ev_view_zoom_out (window->view);
136136
}
137137

138+
static void
139+
ev_previewer_window_zoom_reset (GtkAction *action,
140+
EvPreviewerWindow *window)
141+
{
142+
ev_document_model_set_sizing_mode (window->model, EV_SIZING_FREE);
143+
ev_view_zoom_reset (window->view);
144+
}
145+
138146
static void
139147
ev_previewer_window_zoom_best_fit (GtkToggleAction *action,
140148
EvPreviewerWindow *window)
@@ -295,6 +303,9 @@ static const GtkActionEntry action_entries[] = {
295303
{ "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
296304
N_("Shrink the document"),
297305
G_CALLBACK (ev_previewer_window_zoom_out) },
306+
{ "ViewZoomReset", GTK_STOCK_ZOOM_100, NULL, "<control>0",
307+
N_("Reset zoom to 100\%"),
308+
G_CALLBACK (ev_previewer_window_zoom_reset) },
298309
#if GTKUNIXPRINT_ENABLED
299310
/* translators: Print document currently shown in the Print Preview window */
300311
{ "PreviewPrint", GTK_STOCK_PRINT, N_("Print"), NULL,

previewer/previewer-ui.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<toolitem name="ViewBestFit" action="ViewBestFit"/>
1010
<toolitem name="ViewZoomOut" action="ViewZoomOut"/>
1111
<toolitem name="ViewZoomIn" action="ViewZoomIn"/>
12+
<toolitem name="ViewZoomReset" action="ViewZoomReset"/>
1213
<separator/>
1314
<toolitem name="PreviewPrint" action="PreviewPrint"/>
1415
</toolbar>

shell/ev-toolbar.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ ev_toolbar_constructed (GObject *object)
219219
ev_toolbar->priv->expand_window_button = create_button (action);
220220
gtk_box_pack_end (GTK_BOX (box), ev_toolbar->priv->expand_window_button, FALSE, FALSE, 0);
221221

222+
action = gtk_action_group_get_action (action_group, "ViewZoomReset");
223+
button = create_button (action);
224+
gtk_box_pack_end (GTK_BOX (box), button, FALSE, FALSE, 0);
225+
gtk_widget_show (GTK_WIDGET (button));
226+
222227
action = gtk_action_group_get_action (action_group, "ViewZoomIn");
223228
button = create_button (action);
224229
gtk_box_pack_end (GTK_BOX (box), button, FALSE, FALSE, 0);

shell/ev-window.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
450450
ev_window_set_action_sensitive (ev_window, "ViewExpandWindow", has_pages && !(document->iswebdocument));
451451
ev_window_set_action_sensitive (ev_window, "ViewZoomIn", has_pages && !(document->iswebdocument));
452452
ev_window_set_action_sensitive (ev_window, "ViewZoomOut", has_pages && !(document->iswebdocument));
453+
ev_window_set_action_sensitive (ev_window, "ViewZoomReset", has_pages && !(document->iswebdocument));
453454
ev_window_set_action_sensitive (ev_window, "ViewPresentation", has_pages && !(document->iswebdocument));
454455

455456
/* Bookmarks menu */
@@ -527,6 +528,9 @@ ev_window_update_actions (EvWindow *ev_window)
527528
has_pages &&
528529
ev_view_can_zoom_out (view) &&
529530
!presentation_mode);
531+
ev_window_set_action_sensitive (ev_window, "ViewZoomReset",
532+
has_pages &&
533+
!presentation_mode);
530534
}
531535
/* Go menu */
532536
if (has_pages) {
@@ -4375,6 +4379,23 @@ ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window)
43754379
}
43764380
}
43774381

4382+
static void
4383+
ev_window_cmd_view_zoom_reset (GtkAction *action, EvWindow *ev_window)
4384+
{
4385+
g_return_if_fail (EV_IS_WINDOW (ev_window));
4386+
4387+
ev_document_model_set_sizing_mode (ev_window->priv->model, EV_SIZING_FREE);
4388+
#if ENABLE_EPUB
4389+
if ( ev_window->priv->document->iswebdocument) {
4390+
ev_web_view_zoom_reset(EV_WEB_VIEW(ev_window->priv->webview));
4391+
}
4392+
else
4393+
#endif
4394+
{
4395+
ev_view_zoom_reset (EV_VIEW (ev_window->priv->view));
4396+
}
4397+
}
4398+
43784399
static void
43794400
ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
43804401
{
@@ -5803,6 +5824,9 @@ static const GtkActionEntry entries[] = {
58035824

58045825

58055826
/* View menu */
5827+
{ "ViewZoomReset", "zoom-original-symbolic", N_("_Reset Zoom"), "<control>0",
5828+
N_("Reset zoom to 100\%"),
5829+
G_CALLBACK (ev_window_cmd_view_zoom_reset) },
58065830
{ "ViewZoomIn", "zoom-in-symbolic", N_("Zoom _In"), "<control>plus",
58075831
N_("Enlarge the document"),
58085832
G_CALLBACK (ev_window_cmd_view_zoom_in) },
@@ -6121,6 +6145,10 @@ set_action_properties (GtkActionGroup *action_group)
61216145
action = gtk_action_group_get_action (action_group, "ViewZoomOut");
61226146
/*translators: this is the label for toolbar button*/
61236147
g_object_set (action, "short_label", _("Zoom Out"), NULL);
6148+
6149+
action = gtk_action_group_get_action (action_group, "ViewZoomReset");
6150+
/*translators: this is the label for toolbar button*/
6151+
g_object_set (action, "short_label", _("Reset Zoom"), NULL);
61246152

61256153
action = gtk_action_group_get_action (action_group, "ViewBestFit");
61266154
/*translators: this is the label for toolbar button*/

shell/xreader-ui.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<separator/>
4545
<menuitem name="ViewZoomInMenu" action="ViewZoomIn"/>
4646
<menuitem name="ViewZoomOutMenu" action="ViewZoomOut"/>
47+
<menuitem name="ViewZoomResetMenu" action="ViewZoomReset"/>
4748
<menuitem name="ViewBestFitMenu" action="ViewBestFit"/>
4849
<menuitem name="ViewPageWidthMenu" action="ViewPageWidth"/>
4950
<menuitem name="ViewExpandWindowMenu" action="ViewExpandWindow"/>

0 commit comments

Comments
 (0)