Am Mittwoch, dem 01.11.2023 um 05:14 +0000 schrieb Isaac Oscar Gariano:
> If I have time later, I may modify the code that does the > 50​ check
> to actually count properly, as it's counting context menu items that
> don't even show up.

Yes, this would be the way to go, the current check is too dumb.

Attached is a patch that does this, considering not only hidden entries
but also the dynamic entries that are only expanded in expand() (such
as spelling suggestions). As far as I can see the result is correct.

Note, however, that this will result in shortcut conflicts with items
moved from sub- to main menu, so this effectively causes string
changes. Since string freeze that is lurking around the corner for some
time now, I am not sure if this is good to go in.

> Or you could just make the number much larger than 50​. I've
> personally not had a context menu in LyX that was too long, but users
> with higher DPI's/lower resolutions might have problems. (for example
> if I right click the menu bar I get a context menu with 49 items! but
> my screen could probably fit 6 more).

On my small laptop without HiDPI, 50 is not too short.

-- 
Jürgen
diff --git a/src/frontends/qt/Menus.cpp b/src/frontends/qt/Menus.cpp
index a3fc5a7ce1..a2b5681673 100644
--- a/src/frontends/qt/Menus.cpp
+++ b/src/frontends/qt/Menus.cpp
@@ -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,
@@ -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);
 }
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to