mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Smarter menu length calculation
It is possible I have missed some shortcut conflicts, so please report
if you find any.
(cherry picked from commit f3a4602c4c
)
This commit is contained in:
parent
ad95503c0b
commit
c92d14e8c9
@ -234,10 +234,10 @@ Menuset
|
||||
Menu "context-note"
|
||||
Item "LyX Note|N" "inset-modify note Note Note"
|
||||
Item "Comment|m" "inset-modify note Note Comment"
|
||||
Item "Greyed Out|G" "inset-modify note Note Greyedout"
|
||||
Item "Greyed Out|y" "inset-modify note Note Greyedout"
|
||||
Separator
|
||||
Item "Open All Notes|A" "inset-forall Note inset-toggle open"
|
||||
Item "Close All Notes|l" "inset-forall Note inset-toggle close"
|
||||
Item "Close All Notes|o" "inset-forall Note inset-toggle close"
|
||||
End
|
||||
|
||||
#
|
||||
@ -383,7 +383,7 @@ Menuset
|
||||
Item "Jump Back to Saved Bookmark|B" "bookmark-goto 0"
|
||||
OptItem "Forward Search|F" "forward-search"
|
||||
Separator
|
||||
Item "Move Paragraph Up|o" "paragraph-move-up"
|
||||
Item "Move Paragraph Up|h" "paragraph-move-up"
|
||||
Item "Move Paragraph Down|v" "paragraph-move-down"
|
||||
Separator
|
||||
EnvironmentSeparatorsContext
|
||||
|
@ -117,7 +117,7 @@ Menuset
|
||||
Item "Find & Replace (Quick)...|F" "dialog-show findreplace"
|
||||
Item "Find & Replace (Advanced)..." "dialog-show findreplaceadv"
|
||||
Separator
|
||||
Item "Move Paragraph Up|o" "paragraph-move-up"
|
||||
Item "Move Paragraph Up|h" "paragraph-move-up"
|
||||
Item "Move Paragraph Down|v" "paragraph-move-down"
|
||||
Separator
|
||||
Item "Paragraph Settings...|P" "layout-paragraph"
|
||||
@ -545,7 +545,7 @@ Menuset
|
||||
Menu "insert_note"
|
||||
Item "LyX Note|N" "note-insert Note"
|
||||
Item "Comment|C" "note-insert Comment"
|
||||
Item "Greyed Out|G" "note-insert Greyedout"
|
||||
Item "Greyed Out|y" "note-insert Greyedout"
|
||||
End
|
||||
|
||||
Menu "insert_branches"
|
||||
|
@ -342,6 +342,8 @@ public:
|
||||
const;
|
||||
///
|
||||
bool hasFunc(FuncRequest const &) const;
|
||||
/// The real size of the menu considering hidden entries
|
||||
int realSize() const;
|
||||
/// Add the menu item unconditionally
|
||||
void add(MenuItem const & item) { items_.push_back(item); }
|
||||
/// Checks the associated FuncRequest status before adding the
|
||||
@ -727,6 +729,23 @@ bool MenuDefinition::hasFunc(FuncRequest const & func) const
|
||||
}
|
||||
|
||||
|
||||
int MenuDefinition::realSize() const
|
||||
{
|
||||
int res = 0;
|
||||
for (auto const & it : *this) {
|
||||
if (it.kind() == MenuItem::Submenu)
|
||||
++res;
|
||||
else if (it.kind() == MenuItem::Command) {
|
||||
FuncStatus status = lyx::getStatus(*it.func());
|
||||
// count only items that are actually displayed
|
||||
if (!status.unknown() && (status.enabled() || !it.optional()))
|
||||
++res;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void MenuDefinition::catSub(docstring const & name)
|
||||
{
|
||||
add(MenuItem(MenuItem::Submenu,
|
||||
@ -867,13 +886,13 @@ void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
|
||||
if (i > 0)
|
||||
add(MenuItem(MenuItem::Separator));
|
||||
docstring const arg = wl.word() + " " + from_ascii(wl.lang()->lang());
|
||||
add(MenuItem(MenuItem::Command, qt_("Add to personal dictionary|n"),
|
||||
add(MenuItem(MenuItem::Command, qt_("Add to personal dictionary|r"),
|
||||
FuncRequest(LFUN_SPELLING_ADD, arg)));
|
||||
add(MenuItem(MenuItem::Command, qt_("Ignore this occurrence|g"),
|
||||
FuncRequest(LFUN_FONT_NO_SPELLCHECK, arg)));
|
||||
add(MenuItem(MenuItem::Command, qt_("Ignore all for this session|I"),
|
||||
add(MenuItem(MenuItem::Command, qt_("Ignore all for this session|l"),
|
||||
FuncRequest(LFUN_SPELLING_IGNORE, arg)));
|
||||
add(MenuItem(MenuItem::Command, qt_("Ignore all in this document|d"),
|
||||
add(MenuItem(MenuItem::Command, qt_("Ignore all in this document|u"),
|
||||
FuncRequest(LFUN_SPELLING_ADD_LOCAL, arg)));
|
||||
}
|
||||
}
|
||||
@ -918,7 +937,7 @@ void MenuDefinition::expandLanguageSelector(Buffer const * buf)
|
||||
buf->masterBuffer()->getLanguages();
|
||||
|
||||
if (languages_buffer.size() < 2) {
|
||||
add(MenuItem(MenuItem::Command, qt_("Switch Language...|L"),
|
||||
add(MenuItem(MenuItem::Command, qt_("Switch Language...|w"),
|
||||
FuncRequest(LFUN_DIALOG_SHOW, "character")));
|
||||
return;
|
||||
}
|
||||
@ -2707,6 +2726,9 @@ void Menus::updateMenu(Menu * qmenu)
|
||||
|
||||
docstring identifier = qstring_to_ucs4(qmenu->d->name);
|
||||
MenuDefinition fromLyxMenu(qmenu->d->name);
|
||||
BufferView * bv = 0;
|
||||
if (qmenu->d->view)
|
||||
bv = qmenu->d->view->currentBufferView();
|
||||
while (!identifier.empty()) {
|
||||
docstring menu_name;
|
||||
identifier = split(identifier, menu_name, ';');
|
||||
@ -2718,10 +2740,14 @@ void Menus::updateMenu(Menu * qmenu)
|
||||
}
|
||||
|
||||
MenuDefinition cat_menu = d->getMenu(toqstr(menu_name));
|
||||
//FIXME: 50 is a wild guess. We should take into account here
|
||||
//the expansion of menu items, disabled optional items etc.
|
||||
// We take into account here the expansion of menu items,
|
||||
// disabled optional items etc.
|
||||
MenuDefinition to_menu;
|
||||
d->expand(fromLyxMenu, to_menu, bv);
|
||||
MenuDefinition to_cat_menu;
|
||||
d->expand(cat_menu, to_cat_menu, bv);
|
||||
bool const in_sub_menu = !fromLyxMenu.empty()
|
||||
&& fromLyxMenu.size() + cat_menu.size() > 50 ;
|
||||
&& to_menu.realSize() + to_cat_menu.realSize() > 50;
|
||||
if (in_sub_menu)
|
||||
fromLyxMenu.catSub(menu_name);
|
||||
else
|
||||
@ -2734,9 +2760,6 @@ void Menus::updateMenu(Menu * qmenu)
|
||||
return;
|
||||
}
|
||||
|
||||
BufferView * bv = 0;
|
||||
if (qmenu->d->view)
|
||||
bv = qmenu->d->view->currentBufferView();
|
||||
d->expand(fromLyxMenu, *qmenu->d->top_level_menu, bv);
|
||||
qmenu->d->populate(qmenu, *qmenu->d->top_level_menu);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user