commit 8b36c090b7f8850aca539dff867a194a942d48c2
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Thu Jun 18 15:30:44 2015 +0200

    Simplify the code for "auto" toolbars handling
    
    Instaead of passing a number of booleans, it make more sense to pass
    the relevant visibility values in a single flag.

diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp
index 15fe640..11413a6 100644
--- a/src/frontends/qt4/GuiToolbar.cpp
+++ b/src/frontends/qt4/GuiToolbar.cpp
@@ -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())
diff --git a/src/frontends/qt4/GuiToolbar.h b/src/frontends/qt4/GuiToolbar.h
index 37ebd8c..caad355 100644
--- a/src/frontends/qt4/GuiToolbar.h
+++ b/src/frontends/qt4/GuiToolbar.h
@@ -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();
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 3ebfdb1..9a8664d 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -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();
 }
 
 

Reply via email to