]> git.lyx.org Git - features.git/commitdiff
Simplify the code for "auto" toolbars handling
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2015 13:30:44 +0000 (15:30 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2015 13:51:53 +0000 (15:51 +0200)
Instaead of passing a number of booleans, it make more sense to pass
the relevant visibility values in a single flag.

src/frontends/qt4/GuiToolbar.cpp
src/frontends/qt4/GuiToolbar.h
src/frontends/qt4/GuiView.cpp

index 15fe640a8b524ab5c827e4979860b5f0af51dedb..11413a680633247e898ff9424429cc3b31869d84 100644 (file)
@@ -321,17 +321,10 @@ void GuiToolbar::add(ToolbarItem const & item)
 }
 
 
-void GuiToolbar::update(bool in_math, bool in_table, bool in_review, 
-       bool in_mathmacrotemplate, bool in_ipa)
+void GuiToolbar::update(int context)
 {
-       if (visibility_ & Toolbars::AUTO) {
-               bool show_it = (in_math && (visibility_ & Toolbars::MATH))
-                       || (in_table && (visibility_ & Toolbars::TABLE))
-                       || (in_review && (visibility_ & Toolbars::REVIEW))
-                       || (in_mathmacrotemplate && (visibility_ & Toolbars::MATHMACROTEMPLATE))
-                       || (in_ipa && (visibility_ & Toolbars::IPA));
-               setVisible(show_it);
-       }
+       if (visibility_ & Toolbars::AUTO)
+               setVisible(visibility_ & context & Toolbars::ALLOWAUTO);
 
        // update visible toolbars only
        if (!isVisible())
index 37ebd8c294a9ce08ebb85dbf6656b35ebfd70094..caad355bd8c401a0d95f9db9c83924730c5734b2 100644 (file)
@@ -92,8 +92,7 @@ public:
        bool isRestored() const;
 
        /// Refresh the contents of the bar.
-       void update(bool in_math, bool in_table, bool review,
-               bool in_mathmacrotemplate, bool in_ipa);
+       void update(int context = 0);
 
        ///
        void toggle();
index 3ebfdb1914fbb29165bac0843dcf01c36b47139a..9a8664d39367dedb37321ef47b93dbb2e6269f5b 100644 (file)
@@ -1534,24 +1534,25 @@ void GuiView::updateToolbars()
 {
        ToolbarMap::iterator end = d.toolbars_.end();
        if (d.current_work_area_) {
-               bool const math =
-                       d.current_work_area_->bufferView().cursor().inMathed()
-                       && !d.current_work_area_->bufferView().cursor().inRegexped();
-               bool const table =
-                       lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
-               bool const review =
-                       lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
-                       lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onOff(true);
-               bool const mathmacrotemplate =
-                       lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled();
-               bool const ipa =
-                       lyx::getStatus(FuncRequest(LFUN_IN_IPA)).enabled();
+               int context = 0;
+               if (d.current_work_area_->bufferView().cursor().inMathed()
+                       && !d.current_work_area_->bufferView().cursor().inRegexped())
+                       context |= Toolbars::MATH;
+               if (lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled())
+                       context |= Toolbars::TABLE;
+               if (lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled()
+                       && lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onOff(true))
+                       context |= Toolbars::REVIEW;
+               if (lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled())
+                       context |= Toolbars::MATHMACROTEMPLATE;
+               if (lyx::getStatus(FuncRequest(LFUN_IN_IPA)).enabled())
+                       context |= Toolbars::IPA;
 
                for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-                       it->second->update(math, table, review, mathmacrotemplate, ipa);
+                       it->second->update(context);
        } else
                for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-                       it->second->update(false, false, false, false, false);
+                       it->second->update();
 }