Revert "macOS: add default Edit menu items, if not added by AppKit"
This reverts commit d42cfeb84f
.
Trying to help AppKit by adding the dictation and emoji edit menu items
ourselves resulted in sometimes adding the entries twice, when we failed
to detect the existing entries, or AppKit failed to detect our entries
as a reason to not add its own.
In addition, even if the entries we added were detected by AppKit and
AppKit was smart enough to not add its own, our entries were relying
on the developer to provide translation, instead of building on the
translations that AppKit already provides. And the keyboard shortcut
we set for our entries were not following system and user preferences
for which keyboard combination should trigger the entries.
Fixes: QTBUG-104709
Task-number: QTBUG-79565
Pick-to: 6.5
Change-Id: I3fabc41f85df917dbb669253ad441bccea8a5e35
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
4b00aaae9c
commit
9618427ee5
@ -45,14 +45,12 @@ private:
|
||||
|
||||
bool needsImmediateUpdate();
|
||||
bool shouldDisable(QCocoaWindow *active) const;
|
||||
void insertDefaultEditItems(QCocoaMenu *menu);
|
||||
|
||||
NSMenuItem *nativeItemForMenu(QCocoaMenu *menu) const;
|
||||
|
||||
QList<QPointer<QCocoaMenu> > m_menus;
|
||||
NSMenu *m_nativeMenu;
|
||||
QPointer<QCocoaWindow> m_window;
|
||||
QList<QPointer<QCocoaMenuItem>> m_defaultEditMenuItems;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -162,18 +162,6 @@ void QCocoaMenuBar::syncMenu_helper(QPlatformMenu *menu, bool menubarUpdate)
|
||||
for (QCocoaMenuItem *item : cocoaMenu->items())
|
||||
cocoaMenu->syncMenuItem_helper(item, menubarUpdate);
|
||||
|
||||
const QString captionNoAmpersand = QString::fromNSString(cocoaMenu->nsMenu().title)
|
||||
.remove(u'&');
|
||||
if (captionNoAmpersand == QCoreApplication::translate("QCocoaMenu", "Edit")) {
|
||||
// prevent recursion from QCocoaMenu::insertMenuItem - when the menu is visible
|
||||
// it calls syncMenu again. QCocoaMenu::setVisible just sets the bool, which then
|
||||
// gets evaluated in the code after this block.
|
||||
const bool wasVisible = cocoaMenu->isVisible();
|
||||
cocoaMenu->setVisible(false);
|
||||
insertDefaultEditItems(cocoaMenu);
|
||||
cocoaMenu->setVisible(wasVisible);
|
||||
}
|
||||
|
||||
BOOL shouldHide = YES;
|
||||
if (cocoaMenu->isVisible()) {
|
||||
// If the NSMenu has no visible items, or only separators, we should hide it
|
||||
@ -416,48 +404,6 @@ QCocoaWindow *QCocoaMenuBar::cocoaWindow() const
|
||||
return m_window.data();
|
||||
}
|
||||
|
||||
void QCocoaMenuBar::insertDefaultEditItems(QCocoaMenu *menu)
|
||||
{
|
||||
if (menu->items().isEmpty())
|
||||
return;
|
||||
|
||||
NSMenu *nsEditMenu = menu->nsMenu();
|
||||
if ([nsEditMenu itemAtIndex:nsEditMenu.numberOfItems - 1].action
|
||||
== @selector(orderFrontCharacterPalette:)) {
|
||||
for (auto defaultEditMenuItem : std::as_const(m_defaultEditMenuItems)) {
|
||||
if (menu->items().contains(defaultEditMenuItem))
|
||||
menu->removeMenuItem(defaultEditMenuItem);
|
||||
}
|
||||
qDeleteAll(m_defaultEditMenuItems);
|
||||
m_defaultEditMenuItems.clear();
|
||||
} else {
|
||||
if (m_defaultEditMenuItems.isEmpty()) {
|
||||
QCocoaMenuItem *separator = new QCocoaMenuItem;
|
||||
separator->setIsSeparator(true);
|
||||
|
||||
QCocoaMenuItem *dictationItem = new QCocoaMenuItem;
|
||||
dictationItem->setText(QCoreApplication::translate("QCocoaMenuItem", "Start Dictation..."));
|
||||
QObject::connect(dictationItem, &QPlatformMenuItem::activated, this, []{
|
||||
[NSApplication.sharedApplication performSelector:@selector(startDictation:)];
|
||||
});
|
||||
|
||||
QCocoaMenuItem *emojiItem = new QCocoaMenuItem;
|
||||
emojiItem->setText(QCoreApplication::translate("QCocoaMenuItem", "Emoji && Symbols"));
|
||||
emojiItem->setShortcut(QKeyCombination(Qt::MetaModifier|Qt::ControlModifier, Qt::Key_Space));
|
||||
QObject::connect(emojiItem, &QPlatformMenuItem::activated, this, []{
|
||||
[NSApplication.sharedApplication orderFrontCharacterPalette:nil];
|
||||
});
|
||||
|
||||
m_defaultEditMenuItems << separator << dictationItem << emojiItem;
|
||||
}
|
||||
for (auto defaultEditMenuItem : std::as_const(m_defaultEditMenuItems)) {
|
||||
if (menu->items().contains(defaultEditMenuItem))
|
||||
menu->removeMenuItem(defaultEditMenuItem);
|
||||
menu->insertMenuItem(defaultEditMenuItem, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qcocoamenubar.cpp"
|
||||
|
Loading…
Reference in New Issue
Block a user