Clean up the menus:

* Two new types of menuitems are introduced: Help and Info
* Help messages make sure that the submenu they are in is enabled.
* Empty lists are now represented by a message in brackets.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28188 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-01-16 20:58:04 +00:00
parent 70ddcfdd0e
commit a5ceef887d

View File

@ -95,6 +95,15 @@ public:
Submenu, Submenu,
/// ///
Separator, Separator,
/** This type of item explains why something is unavailable. If this
menuitem is in a submenu, the submenu is enabled to make sure the
user sees the information. */
Help,
/** This type of item merely shows that there might be a list or
something alike at this position, but the list is still empty.
If this item is in a submenu, the submenu will not always be
enabled. */
Info,
/** This is the list of last opened file, /** This is the list of last opened file,
typically for the File menu. */ typically for the File menu. */
Lastfiles, Lastfiles,
@ -153,7 +162,7 @@ public:
bool optional = false) bool optional = false)
: kind_(kind), label_(label), submenuname_(submenu), optional_(optional) : kind_(kind), label_(label), submenuname_(submenu), optional_(optional)
{ {
LASSERT(kind == Submenu, /**/); LASSERT(kind == Submenu || kind == Help || kind == Info, /**/);
} }
MenuItem(Kind kind, MenuItem(Kind kind,
@ -343,8 +352,10 @@ void MenuDefinition::addWithStatusCheck(MenuItem const & i)
if (i.hasSubmenu()) { if (i.hasSubmenu()) {
for (const_iterator cit = i.submenu().begin(); for (const_iterator cit = i.submenu().begin();
cit != i.submenu().end(); ++cit) { cit != i.submenu().end(); ++cit) {
// Only these kind of items affect the status of the submenu
if ((cit->kind() == MenuItem::Command if ((cit->kind() == MenuItem::Command
|| cit->kind() == MenuItem::Submenu) || cit->kind() == MenuItem::Submenu
|| cit->kind() == MenuItem::Help)
&& cit->status().enabled()) { && cit->status().enabled()) {
enabled = true; enabled = true;
break; break;
@ -688,10 +699,8 @@ void MenuDefinition::expandDocuments()
b = theBufferList().next(b); b = theBufferList().next(b);
++ii; ++ii;
} while (b != first); } while (b != first);
} else { } else
add(MenuItem(MenuItem::Command, qt_("No Documents Open!"), add(MenuItem(MenuItem::Info, qt_("<No documents open>")));
FuncRequest(LFUN_NOACTION)));
}
} }
@ -699,6 +708,7 @@ void MenuDefinition::expandBookmarks()
{ {
lyx::BookmarksSection const & bm = theSession().bookmarks(); lyx::BookmarksSection const & bm = theSession().bookmarks();
bool empty = true;
for (size_t i = 1; i <= bm.size(); ++i) { for (size_t i = 1; i <= bm.size(); ++i) {
if (bm.isValid(i)) { if (bm.isValid(i)) {
string const file = bm.bookmark(i).filename.absFilename(); string const file = bm.bookmark(i).filename.absFilename();
@ -706,19 +716,18 @@ void MenuDefinition::expandBookmarks()
.arg(toqstr(makeDisplayPath(file, 20))).arg(i); .arg(toqstr(makeDisplayPath(file, 20))).arg(i);
add(MenuItem(MenuItem::Command, label, add(MenuItem(MenuItem::Command, label,
FuncRequest(LFUN_BOOKMARK_GOTO, convert<docstring>(i)))); FuncRequest(LFUN_BOOKMARK_GOTO, convert<docstring>(i))));
empty = false;
} }
} }
if (empty)
add(MenuItem(MenuItem::Info, qt_("<No bookmarks saved yet>")));
} }
void MenuDefinition::expandFormats(MenuItem::Kind kind, Buffer const * buf) void MenuDefinition::expandFormats(MenuItem::Kind kind, Buffer const * buf)
{ {
if (!buf && kind != MenuItem::ImportFormats) { if (!buf && kind != MenuItem::ImportFormats)
add(MenuItem(MenuItem::Command,
qt_("No Document Open!"),
FuncRequest(LFUN_NOACTION)));
return; return;
}
typedef vector<Format const *> Formats; typedef vector<Format const *> Formats;
Formats formats; Formats formats;
@ -793,11 +802,8 @@ void MenuDefinition::expandFormats(MenuItem::Kind kind, Buffer const * buf)
void MenuDefinition::expandFloatListInsert(Buffer const * buf) void MenuDefinition::expandFloatListInsert(Buffer const * buf)
{ {
if (!buf) { if (!buf)
add(MenuItem(MenuItem::Command, qt_("No Document Open!"),
FuncRequest(LFUN_NOACTION)));
return; return;
}
FloatList const & floats = buf->params().documentClass().floats(); FloatList const & floats = buf->params().documentClass().floats();
FloatList::const_iterator cit = floats.begin(); FloatList::const_iterator cit = floats.begin();
@ -813,11 +819,8 @@ void MenuDefinition::expandFloatListInsert(Buffer const * buf)
void MenuDefinition::expandFloatInsert(Buffer const * buf) void MenuDefinition::expandFloatInsert(Buffer const * buf)
{ {
if (!buf) { if (!buf)
add(MenuItem(MenuItem::Command, qt_("No Document Open!"),
FuncRequest(LFUN_NOACTION)));
return; return;
}
FloatList const & floats = buf->params().documentClass().floats(); FloatList const & floats = buf->params().documentClass().floats();
FloatList::const_iterator cit = floats.begin(); FloatList::const_iterator cit = floats.begin();
@ -835,11 +838,9 @@ void MenuDefinition::expandFloatInsert(Buffer const * buf)
void MenuDefinition::expandFlexInsert( void MenuDefinition::expandFlexInsert(
Buffer const * buf, InsetLayout::InsetLyXType type) Buffer const * buf, InsetLayout::InsetLyXType type)
{ {
if (!buf) { if (!buf)
add(MenuItem(MenuItem::Command, qt_("No Document Open!"),
FuncRequest(LFUN_NOACTION)));
return; return;
}
TextClass::InsetLayouts const & insetLayouts = TextClass::InsetLayouts const & insetLayouts =
buf->params().documentClass().insetLayouts(); buf->params().documentClass().insetLayouts();
TextClass::InsetLayouts::const_iterator cit = insetLayouts.begin(); TextClass::InsetLayouts::const_iterator cit = insetLayouts.begin();
@ -854,9 +855,7 @@ void MenuDefinition::expandFlexInsert(
} }
// FIXME This is a little clunky. // FIXME This is a little clunky.
if (items_.empty() && type == InsetLayout::CUSTOM) if (items_.empty() && type == InsetLayout::CUSTOM)
add(MenuItem(MenuItem::Command, add(MenuItem(MenuItem::Help, qt_("No custom insets defined!")));
qt_("No custom insets defined!"),
FuncRequest(LFUN_NOACTION)));
} }
@ -924,8 +923,7 @@ void MenuDefinition::expandToc(Buffer const * buf)
// OK, so we avoid this unnecessary overhead (JMarc) // OK, so we avoid this unnecessary overhead (JMarc)
if (!buf) { if (!buf) {
add(MenuItem(MenuItem::Command, qt_("No Document Open!"), add(MenuItem(MenuItem::Info, qt_("<No document open>")));
FuncRequest(LFUN_NOACTION)));
return; return;
} }
@ -980,12 +978,14 @@ void MenuDefinition::expandToc(Buffer const * buf)
// Handle normal TOC // Handle normal TOC
cit = toc_list.find("tableofcontents"); cit = toc_list.find("tableofcontents");
if (cit == end) { if (cit == end)
addWithStatusCheck(MenuItem(MenuItem::Command, LYXERR(Debug::GUI, "No table of contents.");
qt_("No Table of contents"), else {
FuncRequest())); if (cit->second.size() > 0 )
} else
expandToc2(cit->second, 0, cit->second.size(), 0); expandToc2(cit->second, 0, cit->second.size(), 0);
else
add(MenuItem(MenuItem::Info, qt_("<Empty table of contents>")));
}
} }
@ -1028,18 +1028,12 @@ void MenuDefinition::expandToolbars()
void MenuDefinition::expandBranches(Buffer const * buf) void MenuDefinition::expandBranches(Buffer const * buf)
{ {
if (!buf) { if (!buf)
add(MenuItem(MenuItem::Command,
qt_("No Document Open!"),
FuncRequest(LFUN_NOACTION)));
return; return;
}
BufferParams const & params = buf->masterBuffer()->params(); BufferParams const & params = buf->masterBuffer()->params();
if (params.branchlist().empty()) { if (params.branchlist().empty()) {
add(MenuItem(MenuItem::Command, add(MenuItem(MenuItem::Help, qt_("No branches set for document!")));
qt_("No Branch in Document!"),
FuncRequest(LFUN_NOACTION)));
return; return;
} }
@ -1061,12 +1055,8 @@ void MenuDefinition::expandBranches(Buffer const * buf)
void MenuDefinition::expandCiteStyles(BufferView const * bv) void MenuDefinition::expandCiteStyles(BufferView const * bv)
{ {
if (!bv) { if (!bv)
add(MenuItem(MenuItem::Command,
qt_("No Document Open!"),
FuncRequest(LFUN_NOACTION)));
return; return;
}
Inset const * inset = bv->cursor().nextInset(); Inset const * inset = bv->cursor().nextInset();
if (!inset || inset->lyxCode() != CITE_CODE) { if (!inset || inset->lyxCode() != CITE_CODE) {
@ -1410,6 +1400,8 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
} }
break; break;
case MenuItem::Info:
case MenuItem::Help:
case MenuItem::Separator: case MenuItem::Separator:
tomenu.addWithStatusCheck(*cit); tomenu.addWithStatusCheck(*cit);
break; break;