commit 89b423a8c67da2116f66571fa341c8fddbb621aa
Author: Koji Yokota <[email protected]>
Date: Fri Oct 23 21:49:57 2026 +0900
Supplement to commit abb138b6
---
src/frontends/qt/MenusMacOS.mm | 75 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/src/frontends/qt/MenusMacOS.mm b/src/frontends/qt/MenusMacOS.mm
new file mode 100644
index 0000000000..7f2a9b9627
--- /dev/null
+++ b/src/frontends/qt/MenusMacOS.mm
@@ -0,0 +1,75 @@
+/**
+ * \file MenusMacOS.mm
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Koji Yokota
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include <QAction>
+#include <QKeySequence>
+#include <QList>
+#include <QMenu>
+#include <QString>
+
+#import <AppKit/AppKit.h>
+
+
+namespace lyx {
+namespace frontend {
+
+// Mimic the original macOS menu style so that shortcuts are presented as
+// a greyed-out color
+void greyOutBindings(QMenu * qmenu)
+{
+ NSMenu * nsmenu = qmenu->toNSMenu();
+ if (!nsmenu)
+ return;
+ // The native menu may contain items added by macOS itself (e.g. in the
+ // Edit menu), so we cannot rely on the native items and the Qt actions
+ // matching one to one. Look for the binding suffixes in the titles
instead.
+ NSMutableArray<NSString *> * suffixes = [NSMutableArray array];
+ for (QAction * act : qmenu->actions()) {
+ if (QMenu * sub = act->menu())
+ greyOutBindings(sub);
+ QString const binding = act->property("lyx_binding").toString();
+ if (binding.isEmpty())
+ continue;
+ // Qt parses the text after '\t' of the label. A single key is
+ // registered as a native key equivalent and drawn by AppKit,
while
+ // a longer sequence is appended to the title as " (...)"
+ // (see QCocoaMenuItem::sync())
+ QKeySequence const seq(binding, QKeySequence::NativeText);
+ if (seq.count() > 1)
+ [suffixes addObject:(" (" +
seq.toString(QKeySequence::NativeText)
+ + ')').toNSString()];
+ }
+ if (suffixes.count == 0)
+ return;
+ for (NSMenuItem * item in nsmenu.itemArray) {
+ NSString * title = item.title;
+ NSString * suffix = nil;
+ for (NSString * s in suffixes)
+ if ([title hasSuffix:s]) {
+ suffix = s;
+ break;
+ }
+ if (!suffix)
+ continue;
+ NSMutableAttributedString * str = [[NSMutableAttributedString
alloc]
+ initWithString:title
+ attributes:@{NSFontAttributeName : [NSFont
menuFontOfSize:0]}];
+ [str addAttribute:NSForegroundColorAttributeName
+ value:[NSColor disabledControlTextColor]
+ range:NSMakeRange(title.length - suffix.length,
suffix.length)];
+ item.attributedTitle = str;
+ [str release];
+ }
+}
+
+} // namespace frontend
+} // namespace lyx
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs