From 39cf8bcf168fbce3a7f1fe95efe4cb256342ce78 Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Mon, 9 Jul 2007 20:33:32 +0000 Subject: [PATCH] * src/frontends/LyXView.h: * src/frontends/Toolbars.cpp: * src/frontends/qt4/QLToolbar.cpp: * src/frontends/LyXView.cpp: * src/frontends/Toolbars.h: * src/LyXFunc.cpp: * src/ToolbarBackend.cpp: * src/ToolbarBackend.h: fix toolbar issues: translate toolbar name in user message; check for ill-formed toolbars in UI files; output reasonable error messages in case of erroneous toolbar names git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19018 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXFunc.cpp | 16 ++++--- src/ToolbarBackend.cpp | 27 ++++++------ src/ToolbarBackend.h | 7 ++-- src/frontends/LyXView.cpp | 4 +- src/frontends/LyXView.h | 4 +- src/frontends/Toolbars.cpp | 74 +++++++++++++-------------------- src/frontends/Toolbars.h | 4 +- src/frontends/qt4/QLToolbar.cpp | 22 ++++++---- 8 files changed, 77 insertions(+), 81 deletions(-) diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index f0748f3091..b753551211 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1784,18 +1784,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd) string const name = cmd.getArg(0); bool const allowauto = cmd.getArg(1) == "allowauto"; lyx_view_->toggleToolbarState(name, allowauto); - ToolbarInfo::Flags const flags = - lyx_view_->getToolbarState(name); + ToolbarInfo * tbi = lyx_view_->getToolbarInfo(name); + if (!tbi) { + setMessage(bformat(_("Unknown toolbar \"%1$s\""), + from_utf8(name))); + break; + } docstring state; - if (flags & ToolbarInfo::ON) + if (tbi->flags & ToolbarInfo::ON) state = _("on"); - else if (flags & ToolbarInfo::OFF) + else if (tbi->flags & ToolbarInfo::OFF) state = _("off"); - else if (flags & ToolbarInfo::AUTO) + else if (tbi->flags & ToolbarInfo::AUTO) state = _("auto"); setMessage(bformat(_("Toolbar \"%1$s\" state set to %2$s"), - from_ascii(name), state)); + _(tbi->gui_name), state)); break; } diff --git a/src/ToolbarBackend.cpp b/src/ToolbarBackend.cpp index 9738b0597c..c6f78f61ed 100644 --- a/src/ToolbarBackend.cpp +++ b/src/ToolbarBackend.cpp @@ -328,24 +328,21 @@ void ToolbarBackend::readToolbarSettings(Lexer & lex) } -ToolbarInfo const & ToolbarBackend::getToolbar(string const & name) const +ToolbarInfo const * ToolbarBackend::getDefinedToolbarInfo(string const & name) const { - Toolbars::const_iterator cit = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name)); - if (cit == toolbars.end()) - lyxerr << "No toolbar named " << name << endl; - BOOST_ASSERT(cit != toolbars.end()); - return (*cit); -} - - -ToolbarInfo & ToolbarBackend::getToolbar(string const & name) -{ - Toolbars::iterator it = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name)); + Toolbars::const_iterator it = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name)); if (it == toolbars.end()) - lyxerr << "No toolbar named " << name << endl; - BOOST_ASSERT(it != toolbars.end()); - return (*it); + return 0; + return &(*it); } +ToolbarInfo * ToolbarBackend::getUsedToolbarInfo(string const &name) +{ + Toolbars::iterator it = find_if(usedtoolbars.begin(), usedtoolbars.end(), ToolbarNamesEqual(name)); + if (it == usedtoolbars.end()) + return 0; + return &(*it); +} + } // namespace lyx diff --git a/src/ToolbarBackend.h b/src/ToolbarBackend.h index 4b6169110e..95dc8900b7 100644 --- a/src/ToolbarBackend.h +++ b/src/ToolbarBackend.h @@ -126,13 +126,14 @@ public: /// read ui toolbar settings void readToolbarSettings(Lexer &); + /// - ToolbarInfo const & getToolbar(std::string const & name) const; + ToolbarInfo const * getDefinedToolbarInfo(std::string const & name) const; /// - ToolbarInfo & getToolbar(std::string const & name); + ToolbarInfo * getUsedToolbarInfo(std::string const & name); private: - /// all the toolbars + /// all the defined toolbars Toolbars toolbars; /// toolbars listed diff --git a/src/frontends/LyXView.cpp b/src/frontends/LyXView.cpp index b844156ebd..d02a2d9302 100644 --- a/src/frontends/LyXView.cpp +++ b/src/frontends/LyXView.cpp @@ -417,9 +417,9 @@ void LyXView::updateToolbars() } -ToolbarInfo::Flags LyXView::getToolbarState(string const & name) +ToolbarInfo * LyXView::getToolbarInfo(string const & name) { - return toolbars_->getToolbarState(name); + return toolbars_->getToolbarInfo(name); } diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index ec44c71a59..f2def70078 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -157,8 +157,8 @@ public: /// update the toolbar void updateToolbars(); - /// get toolbar state - ToolbarInfo::Flags getToolbarState(std::string const & name); + /// get toolbar info + ToolbarInfo * getToolbarInfo(std::string const & name); /// toggle toolbar state void toggleToolbarState(std::string const & name, bool allowauto); /// update the menubar diff --git a/src/frontends/Toolbars.cpp b/src/frontends/Toolbars.cpp index 6b34c5b214..51023f5ed9 100644 --- a/src/frontends/Toolbars.cpp +++ b/src/frontends/Toolbars.cpp @@ -169,58 +169,44 @@ void Toolbars::display(string const & name, bool show) } -ToolbarInfo::Flags Toolbars::getToolbarState(string const & name) +ToolbarInfo * Toolbars::getToolbarInfo(string const & name) { - ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin(); - ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end(); - - for (; cit != end; ++cit) { - if (cit->name == name) - return cit->flags; - } - - LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " - << name << endl; - - // return dummy for msvc - return ToolbarInfo::OFF; + return toolbarbackend.getUsedToolbarInfo(name); } void Toolbars::toggleToolbarState(string const & name, bool allowauto) { - ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); - ToolbarBackend::Toolbars::iterator end = toolbarbackend.end(); + ToolbarInfo * tbi = toolbarbackend.getUsedToolbarInfo(name); - for (; cit != end; ++cit) { - if (cit->name == name) { - int flags = cit->flags; - // off -> on - if (flags & ToolbarInfo::OFF) { - TurnOffFlag(OFF); - TurnOnFlag(ON); - // auto -> off - } else if (flags & ToolbarInfo::AUTO) { - TurnOffFlag(AUTO); - TurnOnFlag(OFF); - } else if (allowauto - && ((flags & ToolbarInfo::MATH) - || (flags & ToolbarInfo::TABLE) - || (flags & ToolbarInfo::REVIEW))) { - // for math etc, toggle from on -> auto - TurnOffFlag(ON); - TurnOnFlag(AUTO); - } else { - // for others, toggle from on -> off - TurnOffFlag(ON); - TurnOnFlag(OFF); - } - cit->flags = static_cast(flags); - return; - } + if (!tbi) { + LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " + << name << endl; + return; } - LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " - << name << endl; + + int flags = tbi->flags; + // off -> on + if (flags & ToolbarInfo::OFF) { + TurnOffFlag(OFF); + TurnOnFlag(ON); + // auto -> off + } else if (flags & ToolbarInfo::AUTO) { + TurnOffFlag(AUTO); + TurnOnFlag(OFF); + } else if (allowauto + && ((flags & ToolbarInfo::MATH) + || (flags & ToolbarInfo::TABLE) + || (flags & ToolbarInfo::REVIEW))) { + // for math etc, toggle from on -> auto + TurnOffFlag(ON); + TurnOnFlag(AUTO); + } else { + // for others, toggle from on -> off + TurnOffFlag(ON); + TurnOnFlag(OFF); + } + tbi->flags = static_cast(flags); } #undef TurnOnFlag #undef TurnOffFlag diff --git a/src/frontends/Toolbars.h b/src/frontends/Toolbars.h index d87c4a705b..55ada415f9 100644 --- a/src/frontends/Toolbars.h +++ b/src/frontends/Toolbars.h @@ -90,8 +90,8 @@ public: /// Show/hide the named toolbar. void display(std::string const & name, bool show); - /// get toolbar state (on/off/auto) - ToolbarInfo::Flags getToolbarState(std::string const & name); + /// get toolbar info + ToolbarInfo * getToolbarInfo(std::string const & name); /** toggle the state of toolbars (on/off/auto). Skip "auto" * when allowauto is false. diff --git a/src/frontends/qt4/QLToolbar.cpp b/src/frontends/qt4/QLToolbar.cpp index 8186c7b6ef..f1bab092b5 100644 --- a/src/frontends/qt4/QLToolbar.cpp +++ b/src/frontends/qt4/QLToolbar.cpp @@ -214,9 +214,13 @@ void QLToolbar::add(ToolbarItem const & item) IconPalette * panel = new IconPalette(tb); panel->setWindowTitle(qt_(to_ascii(item.label_))); connect(this, SIGNAL(updated()), panel, SLOT(updateParent())); - ToolbarInfo const & tbinfo = toolbarbackend.getToolbar(item.name_); - ToolbarInfo::item_iterator it = tbinfo.items.begin(); - ToolbarInfo::item_iterator const end = tbinfo.items.end(); + ToolbarInfo const * tbinfo = toolbarbackend.getDefinedToolbarInfo(item.name_); + if (!tbinfo) { + lyxerr << "Unknown toolbar " << item.name_ << endl; + break; + } + ToolbarInfo::item_iterator it = tbinfo->items.begin(); + ToolbarInfo::item_iterator const end = tbinfo->items.end(); for (; it != end; ++it) if (!getStatus(it->func_).unknown()) { Action * action = new Action(owner_, @@ -227,7 +231,7 @@ void QLToolbar::add(ToolbarItem const & item) panel->addButton(action); ActionVector.push_back(action); // use the icon of first action for the toolbar button - if (it == tbinfo.items.begin()) + if (it == tbinfo->items.begin()) tb->setIcon(QPixmap(getIcon(it->func_).c_str())); } tb->setCheckable(true); @@ -251,9 +255,13 @@ void QLToolbar::add(ToolbarItem const & item) m->setWindowTitle(qt_(to_ascii(item.label_))); m->setTearOffEnabled(true); connect(this, SIGNAL(updated()), m, SLOT(updateParent())); - ToolbarInfo const & tbinfo = toolbarbackend.getToolbar(item.name_); - ToolbarInfo::item_iterator it = tbinfo.items.begin(); - ToolbarInfo::item_iterator const end = tbinfo.items.end(); + ToolbarInfo const * tbinfo = toolbarbackend.getDefinedToolbarInfo(item.name_); + if (!tbinfo) { + lyxerr << "Unknown toolbar " << item.name_ << endl; + break; + } + ToolbarInfo::item_iterator it = tbinfo->items.begin(); + ToolbarInfo::item_iterator const end = tbinfo->items.end(); for (; it != end; ++it) if (!getStatus(it->func_).unknown()) { Action * action = new Action(owner_,