mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Simplify menus when there is only one caption type
This removes the submenu indirection in Insert and the type changer in
contextual menu. Interestingly, the code was there, but it did not
work at all.
(cherry picked from commit e7a33cacf1
and made compatible with C++98)
This commit is contained in:
parent
bbeb3773a1
commit
9e44cd672a
@ -1617,47 +1617,42 @@ void MenuDefinition::expandCaptions(Buffer const * buf, bool switchcap)
|
|||||||
if (!buf)
|
if (!buf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vector<docstring> caps;
|
|
||||||
DocumentClass const & dc = buf->params().documentClass();
|
DocumentClass const & dc = buf->params().documentClass();
|
||||||
|
typedef vector< pair<docstring, FuncRequest> > Caps;
|
||||||
|
Caps caps;
|
||||||
TextClass::InsetLayouts::const_iterator lit = dc.insetLayouts().begin();
|
TextClass::InsetLayouts::const_iterator lit = dc.insetLayouts().begin();
|
||||||
TextClass::InsetLayouts::const_iterator len = dc.insetLayouts().end();
|
TextClass::InsetLayouts::const_iterator len = dc.insetLayouts().end();
|
||||||
for (; lit != len; ++lit) {
|
for (; lit != len; ++lit) {
|
||||||
if (prefixIs(lit->first, from_ascii("Caption:")))
|
docstring instype;
|
||||||
caps.push_back(lit->first);
|
docstring const type = split(lit->first, instype, ':');
|
||||||
|
if (instype == "Caption") {
|
||||||
|
// skip forbidden caption types
|
||||||
|
FuncRequest const cmd = switchcap
|
||||||
|
? FuncRequest(LFUN_INSET_MODIFY, from_ascii("changetype ") + type)
|
||||||
|
: FuncRequest(LFUN_CAPTION_INSERT, type);
|
||||||
|
if (getStatus(cmd).enabled())
|
||||||
|
caps.push_back(make_pair(type, cmd));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (caps.empty() || (switchcap && caps.size() == 1))
|
if (caps.empty() || (switchcap && caps.size() == 1))
|
||||||
return;
|
return;
|
||||||
if (caps.size() == 1) {
|
if (caps.size() == 1) {
|
||||||
docstring dummy;
|
add(MenuItem(MenuItem::Command, qt_("Caption"), caps.front().second));
|
||||||
docstring const type = split(*caps.begin(), dummy, ':');
|
|
||||||
add(MenuItem(MenuItem::Command, qt_("Caption"),
|
|
||||||
FuncRequest(LFUN_CAPTION_INSERT, translateIfPossible(type))));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuDefinition captions;
|
MenuDefinition captions;
|
||||||
|
Caps::const_iterator cit = caps.begin();
|
||||||
vector<docstring>::const_iterator cit = caps.begin();
|
Caps::const_iterator end = caps.end();
|
||||||
vector<docstring>::const_iterator end = caps.end();
|
for ( ; cit != end; ++cit) {
|
||||||
|
docstring const type = cit->first;
|
||||||
for (int ii = 1; cit != end; ++cit, ++ii) {
|
|
||||||
docstring dummy;
|
|
||||||
docstring const type = split(*cit, dummy, ':');
|
|
||||||
docstring const trtype = translateIfPossible(type);
|
docstring const trtype = translateIfPossible(type);
|
||||||
docstring const cmitem = bformat(_("Caption (%1$s)"), trtype);
|
docstring const cmitem = bformat(_("Caption (%1$s)"), trtype);
|
||||||
// make menu item optional, otherwise we would also see
|
|
||||||
// forbidden caption types
|
|
||||||
if (switchcap)
|
if (switchcap)
|
||||||
addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cmitem),
|
add(MenuItem(MenuItem::Command, toqstr(cmitem), cit->second));
|
||||||
FuncRequest(LFUN_INSET_MODIFY,
|
|
||||||
from_ascii("changetype ")
|
|
||||||
+ type), QString(), true));
|
|
||||||
else
|
else
|
||||||
captions.addWithStatusCheck(MenuItem(MenuItem::Command,
|
captions.add(MenuItem(MenuItem::Command, toqstr(trtype), cit->second));
|
||||||
toqstr(trtype),
|
|
||||||
FuncRequest(LFUN_CAPTION_INSERT,
|
|
||||||
type), QString(), true));
|
|
||||||
}
|
}
|
||||||
if (!captions.empty()) {
|
if (!captions.empty()) {
|
||||||
MenuItem item(MenuItem::Submenu, qt_("Caption"));
|
MenuItem item(MenuItem::Submenu, qt_("Caption"));
|
||||||
|
@ -27,6 +27,9 @@ What's new
|
|||||||
- Names containing @ are now recognised by the syntax highlighter in the
|
- Names containing @ are now recognised by the syntax highlighter in the
|
||||||
preamble.
|
preamble.
|
||||||
|
|
||||||
|
- Replace Insert>Caption submenu by a normal entry when there is only one
|
||||||
|
caption type.
|
||||||
|
|
||||||
|
|
||||||
* DOCUMENTATION AND LOCALIZATION
|
* DOCUMENTATION AND LOCALIZATION
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user