The attached patch is simple but I have not made a change like this
before so I wanted to check on the list.

Scott
From 3afb01f8b005bbd28109dec80de3a9d368de9003 Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <skost...@lyx.org>
Date: Fri, 7 Oct 2016 23:18:54 -0400
Subject: [PATCH] Factor out magic zoom minimum to a const member

The limit of 10% is used in both getStatus() and dispatch() to set a
minimum zoom level. Having it centralized makes the code more
readable and makes changing the minimum less error-prone.
---
 src/frontends/qt4/GuiView.cpp | 10 ++++++----
 src/frontends/qt4/GuiView.h   |  3 +++
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index fdc05a9..35fb6d0 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -2034,8 +2034,10 @@ bool GuiView::getStatus(FuncRequest const & cmd, 
FuncStatus & flag)
                bool const neg_zoom =
                        convert<int>(cmd.argument()) < 0 ||
                        (cmd.action() == LFUN_BUFFER_ZOOM_OUT && 
cmd.argument().empty());
-               if (lyxrc.zoom <= 10 && neg_zoom) {
-                       flag.message(_("Zoom level cannot be less than 10%."));
+               if (lyxrc.zoom <= ZOOM_MIN && neg_zoom) {
+                       docstring const msg =
+                               bformat(_("Zoom level cannot be less than 
%1$d%."), ZOOM_MIN);
+                       flag.message(msg);
                        enable = false;
                } else
                        enable = doc_buffer;
@@ -3979,8 +3981,8 @@ void GuiView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
                        } else
                                zoom += convert<int>(cmd.argument());
 
-                       if (zoom < 10)
-                               zoom = 10;
+                       if (zoom < static_cast<int>(ZOOM_MIN))
+                               zoom = ZOOM_MIN;
                        lyxrc.zoom = zoom;
 
                        dr.setMessage(bformat(_("Zoom level is now %1$d%"), 
lyxrc.zoom));
diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h
index c7c2699..7d1a198 100644
--- a/src/frontends/qt4/GuiView.h
+++ b/src/frontends/qt4/GuiView.h
@@ -461,6 +461,9 @@ private:
        /// Statusbar widget that shows version control status
        QLabel * version_control_;
 
+       /// Minimum zoom percentage
+       unsigned int const ZOOM_MIN = 10;
+
 };
 
 } // namespace frontend
-- 
2.7.4

Attachment: signature.asc
Description: PGP signature

Reply via email to