Fix bug 3799.

* src/LyXAction.cpp:
	* src/lfuns.h: remove LFUN_TOOLBAR_TOGGLE_STATE.

	* src/LyXFunc.cpp (getStatus, dispatch): merge LFUN_TOOLBAR_TOGGLE
	and LFUN_TOOLBAR_TOGGLE_STATE. Add an informational message after 
	dispatch.

	* src/frontends/LyXView.cpp (toggleToolbarState):
	* src/frontends/Toolbars.cpp (toggleToolbarState): add allowauto 
	parameter. 

	* src/MenuBackend.cpp (expandToolbars): adapt.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18690 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2007-06-06 13:52:31 +00:00
parent 087e9eb578
commit 36481c2744
8 changed files with 34 additions and 32 deletions

View File

@ -364,7 +364,6 @@ void LyXAction::init()
{ LFUN_WINDOW_NEW, "window-new", NoBuffer }, { LFUN_WINDOW_NEW, "window-new", NoBuffer },
{ LFUN_WINDOW_CLOSE, "window-close", NoBuffer }, { LFUN_WINDOW_CLOSE, "window-close", NoBuffer },
{ LFUN_UNICODE_INSERT, "unicode-insert", Noop }, { LFUN_UNICODE_INSERT, "unicode-insert", Noop },
{ LFUN_TOOLBAR_TOGGLE_STATE, "", NoBuffer },
{ LFUN_TOOLBAR_TOGGLE, "toolbar-toggle", NoBuffer }, { LFUN_TOOLBAR_TOGGLE, "toolbar-toggle", NoBuffer },
{ LFUN_NOMENCL_INSERT, "nomencl-insert", Noop }, { LFUN_NOMENCL_INSERT, "nomencl-insert", Noop },
{ LFUN_NOMENCL_PRINT, "nomencl-print", Noop }, { LFUN_NOMENCL_PRINT, "nomencl-print", Noop },

View File

@ -617,19 +617,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
enable = LyX::ref().session().bookmarks().size() > 0; enable = LyX::ref().session().bookmarks().size() > 0;
break; break;
case LFUN_TOOLBAR_TOGGLE_STATE: {
ToolbarInfo::Flags flags = lyx_view_->getToolbarState(to_utf8(cmd.argument()));
if (!(flags & ToolbarInfo::AUTO))
flag.setOnOff(flags & ToolbarInfo::ON);
break;
}
case LFUN_TOOLBAR_TOGGLE: { case LFUN_TOOLBAR_TOGGLE: {
bool const current = lyx_view_->getToolbars().visible(cmd.getArg(0)); bool const current = lyx_view_->getToolbars().visible(cmd.getArg(0));
flag.setOnOff(current); flag.setOnOff(current);
break; break;
} }
case LFUN_WINDOW_CLOSE: { case LFUN_WINDOW_CLOSE: {
enable = (theApp()->gui().viewIds().size() > 1); enable = (theApp()->gui().viewIds().size() > 1);
break; break;
@ -1763,15 +1755,23 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
LyX::ref().session().bookmarks().clear(); LyX::ref().session().bookmarks().clear();
break; break;
case LFUN_TOOLBAR_TOGGLE_STATE:
lyx_view_->toggleToolbarState(argument);
break;
case LFUN_TOOLBAR_TOGGLE: { case LFUN_TOOLBAR_TOGGLE: {
BOOST_ASSERT(lyx_view_); BOOST_ASSERT(lyx_view_);
string const name = to_utf8(cmd.argument()); string const name = cmd.getArg(0);
bool const current = lyx_view_->getToolbars().visible(name); bool const allowauto = cmd.getArg(1) == "allowauto";
lyx_view_->getToolbars().display(name, !current); lyx_view_->toggleToolbarState(name, allowauto);
ToolbarInfo::Flags const flags =
lyx_view_->getToolbarState(name);
docstring state;
if (flags & ToolbarInfo::ON)
state = _("on");
else if (flags & ToolbarInfo::OFF)
state = _("off");
else if (flags & ToolbarInfo::AUTO)
state = _("auto");
setMessage(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
from_ascii(name), state));
break; break;
} }

View File

@ -789,9 +789,10 @@ void expandToolbars(Menu & tomenu)
for (; cit != end; ++cit) { for (; cit != end; ++cit) {
docstring label = _(cit->gui_name); docstring label = _(cit->gui_name);
// frontends are not supposed to turn on/off toolbars, if they cannot // frontends are not supposed to turn on/off toolbars,
// update ToolbarBackend::flags. That is to say, ToolbarsBackend::flags // if they cannot update ToolbarBackend::flags. That
// should reflect the true state of toolbars. // is to say, ToolbarsBackend::flags should reflect
// the true state of toolbars.
// //
// menu is displayed as // menu is displayed as
// on/off review // on/off review
@ -801,7 +802,7 @@ void expandToolbars(Menu & tomenu)
if (cit->flags & ToolbarInfo::AUTO) if (cit->flags & ToolbarInfo::AUTO)
label += _(" (auto)"); label += _(" (auto)");
tomenu.add(MenuItem(MenuItem::Command, label, tomenu.add(MenuItem(MenuItem::Command, label,
FuncRequest(LFUN_TOOLBAR_TOGGLE_STATE, cit->name))); FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name + " allowauto")));
} }
} }

View File

@ -353,7 +353,7 @@ ToolbarInfo::Flags LyXView::getToolbarState(string const & name)
} }
void LyXView::toggleToolbarState(string const & name) void LyXView::toggleToolbarState(string const & name, bool allowauto)
{ {
// it is possible to get current toolbar status like this,... // it is possible to get current toolbar status like this,...
// but I decide to obey the order of ToolbarBackend::flags // but I decide to obey the order of ToolbarBackend::flags
@ -361,7 +361,7 @@ void LyXView::toggleToolbarState(string const & name)
// toolbars_->saveToolbarInfo(); // toolbars_->saveToolbarInfo();
// //
// toggle state on/off/auto // toggle state on/off/auto
toolbars_->toggleToolbarState(name); toolbars_->toggleToolbarState(name, allowauto);
// update toolbar // update toolbar
updateToolbars(); updateToolbars();
} }

View File

@ -156,7 +156,7 @@ public:
/// get toolbar state /// get toolbar state
ToolbarInfo::Flags getToolbarState(std::string const & name); ToolbarInfo::Flags getToolbarState(std::string const & name);
/// toggle toolbar state /// toggle toolbar state
void toggleToolbarState(std::string const & name); void toggleToolbarState(std::string const & name, bool allowauto);
/// update the menubar /// update the menubar
void updateMenubar(); void updateMenubar();
/// update the status bar /// update the status bar

View File

@ -187,7 +187,7 @@ ToolbarInfo::Flags Toolbars::getToolbarState(string const & name)
} }
void Toolbars::toggleToolbarState(string const & name) void Toolbars::toggleToolbarState(string const & name, bool allowauto)
{ {
ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
ToolbarBackend::Toolbars::iterator end = toolbarbackend.end(); ToolbarBackend::Toolbars::iterator end = toolbarbackend.end();
@ -203,8 +203,10 @@ void Toolbars::toggleToolbarState(string const & name)
} else if (flags & ToolbarInfo::AUTO) { } else if (flags & ToolbarInfo::AUTO) {
TurnOffFlag(AUTO); TurnOffFlag(AUTO);
TurnOnFlag(OFF); TurnOnFlag(OFF);
} else if ((flags & ToolbarInfo::MATH) || (flags & ToolbarInfo::TABLE) } else if (allowauto
|| (flags & ToolbarInfo::REVIEW)) { && ((flags & ToolbarInfo::MATH)
|| (flags & ToolbarInfo::TABLE)
|| (flags & ToolbarInfo::REVIEW))) {
// for math etc, toggle from on -> auto // for math etc, toggle from on -> auto
TurnOffFlag(ON); TurnOffFlag(ON);
TurnOnFlag(AUTO); TurnOnFlag(AUTO);
@ -213,7 +215,7 @@ void Toolbars::toggleToolbarState(string const & name)
TurnOffFlag(ON); TurnOffFlag(ON);
TurnOnFlag(OFF); TurnOnFlag(OFF);
} }
cit->flags = static_cast<lyx::ToolbarInfo::Flags>(flags); cit->flags = static_cast<ToolbarInfo::Flags>(flags);
return; return;
} }
} }

View File

@ -93,8 +93,10 @@ public:
/// get toolbar state (on/off/auto) /// get toolbar state (on/off/auto)
ToolbarInfo::Flags getToolbarState(std::string const & name); ToolbarInfo::Flags getToolbarState(std::string const & name);
/// toggle the state of toolbars (on/off/auto) /** toggle the state of toolbars (on/off/auto). Skip "auto"
void toggleToolbarState(std::string const & name); * when allowauto is false.
*/
void toggleToolbarState(std::string const & name, bool allowauto);
/// Update the state of the toolbars. /// Update the state of the toolbars.
void update(bool in_math, bool in_table, bool review); void update(bool in_math, bool in_table, bool review);

View File

@ -371,15 +371,13 @@ enum kb_action {
LFUN_WINDOW_CLOSE, // Abdel 20061023 LFUN_WINDOW_CLOSE, // Abdel 20061023
LFUN_UNICODE_INSERT, // Lgb 20061022 LFUN_UNICODE_INSERT, // Lgb 20061022
LFUN_BOOKMARK_CLEAR, // bpeng 20061031 LFUN_BOOKMARK_CLEAR, // bpeng 20061031
LFUN_TOOLBAR_TOGGLE_STATE, // bpeng 20061101
LFUN_NOMENCL_INSERT, // Ugras LFUN_NOMENCL_INSERT, // Ugras
// 285
LFUN_NOMENCL_PRINT, // Ugras LFUN_NOMENCL_PRINT, // Ugras
// 285
LFUN_CLEARPAGE_INSERT, // Ugras 20061125 LFUN_CLEARPAGE_INSERT, // Ugras 20061125
LFUN_CLEARDOUBLEPAGE_INSERT, // Ugras 20061125 LFUN_CLEARDOUBLEPAGE_INSERT, // Ugras 20061125
LFUN_LISTING_INSERT, // Herbert 20011110, bpeng 20070502 LFUN_LISTING_INSERT, // Herbert 20011110, bpeng 20070502
LFUN_TOOLBAR_TOGGLE, // Edwin 20070521 LFUN_TOOLBAR_TOGGLE, // Edwin 20070521
//290
LFUN_LASTACTION // end of the table LFUN_LASTACTION // end of the table
}; };