* 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
This commit is contained in:
Michael Schmitt 2007-07-09 20:33:32 +00:00
parent 1f2f2892c4
commit 39cf8bcf16
8 changed files with 77 additions and 81 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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<ToolbarInfo::Flags>(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<ToolbarInfo::Flags>(flags);
}
#undef TurnOnFlag
#undef TurnOffFlag

View File

@ -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.

View File

@ -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_,