From 8b36c090b7f8850aca539dff867a194a942d48c2 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 18 Jun 2015 15:30:44 +0200 Subject: [PATCH] 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. --- src/frontends/qt4/GuiToolbar.cpp | 13 +++---------- src/frontends/qt4/GuiToolbar.h | 3 +-- src/frontends/qt4/GuiView.cpp | 29 +++++++++++++++-------------- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index 15fe640a8b..11413a6806 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 37ebd8c294..caad355bd8 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 3ebfdb1914..9a8664d393 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(); } -- 2.39.2