Prettier view->toolbars menu.

* src/lyxfunc.C: better handle LFUN_TOOLBAR_TOGGLE_STATE
	* src/frontends/LyXView.h/C: add getToolbarState
	* src/frontends/Toolbars.h/C: add getToolbarState
	* src/MenuBackend.C: change display of menu item.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15692 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2006-11-02 18:59:33 +00:00
parent eaa33dca6d
commit b084ac0a4a
6 changed files with 45 additions and 12 deletions

View File

@ -768,17 +768,16 @@ void expandToolbars(Menu & tomenu, Buffer const * buf)
int i = 1;
for (; cit != end; ++cit, ++i) {
docstring label = convert<docstring>(i) + ". " + _(cit->name);
// frontend does not update ToolbarBackend::flags when it changes toolbar
// Therefore, I can not tell from the flags if the toolbar is on or off
// it is then less confusing to say:
// this is: always on/off/auto
// frontend toolbar change is temporary.
// frontends are not supposed to turn on/off toolbars, if they can not
// update ToolbarBackend::flags. That is to say, ToolbarsBackend::flags
// should reflect the true state of toolbars.
//
if (cit->flags & ToolbarBackend::ON)
label += _(" (always on)");
else if (cit->flags & ToolbarBackend::OFF)
label += _(" (always off)");
else if (cit->flags & ToolbarBackend::AUTO)
// menu is displayed as
// on/off review
// and
// review (auto)
// in the case of auto.
if (cit->flags & ToolbarBackend::AUTO)
label += _(" (auto)");
label += char_type('|') + convert<docstring>(i);
tomenu.add(MenuItem(MenuItem::Command, label,

View File

@ -305,6 +305,12 @@ void LyXView::updateToolbars()
}
ToolbarBackend::Flags LyXView::getToolbarState(string const & name)
{
return toolbars_->getToolbarState(name);
}
void LyXView::toggleToolbarState(string const & name)
{
// it is possible to get current toolbar status like this,...

View File

@ -136,6 +136,8 @@ public:
/// update the toolbar
void updateToolbars();
/// get toolbar state
ToolbarBackend::Flags getToolbarState(std::string const & name);
/// toggle toolbar state
void toggleToolbarState(std::string const & name);
/// update the menubar

View File

@ -129,6 +129,21 @@ void Toolbars::display(string const & name, bool show)
}
ToolbarBackend::Flags Toolbars::getToolbarState(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;
}
void Toolbars::toggleToolbarState(string const & name)
{
ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
@ -154,9 +169,11 @@ void Toolbars::toggleToolbarState(string const & name)
TurnOnFlag(ON);
}
cit->flags = static_cast<lyx::ToolbarBackend::Flags>(flags);
break;
return;
}
}
lyxerr[Debug::GUI] << "Toolbar::display: no toolbar named "
<< name << endl;
}
#undef TurnOnFlag
#undef TurnOffFlag

View File

@ -88,6 +88,9 @@ public:
/// Show/hide the named toolbar.
void display(std::string const & name, bool show);
/// get toolbar state (on/off/auto)
ToolbarBackend::Flags getToolbarState(std::string const & name);
/// toggle the state of toolbars (on/off/auto)
void toggleToolbarState(std::string const & name);

View File

@ -573,6 +573,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
break;
}
case LFUN_TOOLBAR_TOGGLE_STATE: {
ToolbarBackend::Flags flags = lyx_view_->getToolbarState(to_utf8(cmd.argument()));
if (!(flags & ToolbarBackend::AUTO))
flag.setOnOff(flags & ToolbarBackend::ON);
break;
}
// this one is difficult to get right. As a half-baked
// solution, we consider only the first action of the sequence
case LFUN_COMMAND_SEQUENCE: {
@ -635,7 +642,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
case LFUN_BUFFER_PREVIOUS:
case LFUN_WINDOW_NEW:
case LFUN_WINDOW_CLOSE:
case LFUN_TOOLBAR_TOGGLE_STATE:
// these are handled in our dispatch()
break;