sfx2/source/appl/shutdowniconaqua.mm | 50 +++++++---------------------------- 1 file changed, 10 insertions(+), 40 deletions(-)
New commits: commit 9d2da58ec93db75d2fcfce3dc001d9db0851e3c6 Author: Neil Roberts <bpee...@yahoo.co.uk> AuthorDate: Tue Sep 2 12:37:56 2025 +0200 Commit: Patrick Luby <guibomac...@gmail.com> CommitDate: Wed Sep 3 23:52:15 2025 +0200 tdf#121253 Remove the default menu new document shortcut keys on MacOS The default menu on MacOS is displayed when there are no windows or on a dialog box with no parent. Previously there were hardcoded shortcut keys to create new documents. As reported in tdf#121253, one of these is ⌘A which ends up being inconvenient because that is commonly used to select all the text in a text box. This had the effect that if you tried to use that shortcut in some dialogs then the dialog would seem to disappear and be replaced by the new database wizard. The hardcoded shortcuts were added in 6efdd1444810 which is a patch from January 2025. Before that the shortcuts were generated based on the menu item title. ⌘A ends up being used for the database because ⌘D is already used for a new Draw document and it just picked the next letter along. These shortcuts were added in 2008 with ba57ba32e8054ec. This patch removes the shortcuts for the default menu in both the copied version of the start center menu and the original default menu generated in code. It seems strange to have shortcuts for these only in the specific case of there being no window or when a few select dialog boxes are focused. If they were generally useful to people then surely it would make sense to add them to the start center menu as well. For people using non-English language packs the patch from January would have effectively changed the shortcut keys. If nobody has complained then it probably means they aren’t used. Change-Id: I6065c3daa4e288caa98d73a3f286935dc5bc07ee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190522 Tested-by: Jenkins Reviewed-by: Patrick Luby <guibomac...@gmail.com> diff --git a/sfx2/source/appl/shutdowniconaqua.mm b/sfx2/source/appl/shutdowniconaqua.mm index 484b0f44416f..ea82d4b7e005 100644 --- a/sfx2/source/appl/shutdowniconaqua.mm +++ b/sfx2/source/appl/shutdowniconaqua.mm @@ -415,24 +415,6 @@ struct RecentMenuEntry static RecentMenuDelegate* pRecentDelegate = nil; -static OUString getShortCut( const OUString& i_rTitle ) -{ - // create shortcut - OUString aKeyEquiv; - for( sal_Int32 nIndex = 0; nIndex < i_rTitle.getLength(); nIndex++ ) - { - OUString aShortcut( i_rTitle.copy( nIndex, 1 ).toAsciiLowerCase() ); - if( aShortcuts.find( aShortcut ) == aShortcuts.end() ) - { - aShortcuts.insert( aShortcut ); - aKeyEquiv = aShortcut; - break; - } - } - - return aKeyEquiv; -} - static void appendMenuItem( NSMenu* i_pMenu, NSMenu* i_pDockMenu, const OUString& i_rTitle, int i_nTag, const OUString& i_rKeyEquiv ) { if( ! i_rTitle.getLength() ) @@ -520,6 +502,12 @@ static void setKeyEquivalent( const vcl::KeyCode &rKeyCode, NSMenuItem *pNSMenuI if ( nModifier & KEY_MOD3 ) nItemModifier |= NSEventModifierFlagControl; + // Don’t allow setting the ⌘N shortcut because it would conflict + // with the “Startcenter” menu item which is added explicitly in + // getNSMenuForVCLMenu + if ( nCommandKey == 'n' && nItemModifier == NSEventModifierFlagCommand ) + return; + OUString aCommandKey( &nCommandKey, 1 ); NSString *pCommandKey = [NSString stringWithCharacters: reinterpret_cast< unichar const* >(aCommandKey.getStr()) length: aCommandKey.getLength()]; [pNSMenuItem setKeyEquivalent: pCommandKey]; @@ -589,21 +577,7 @@ static NSMenu *getNSMenuForVCLMenu( Menu *pMenu ) [pNSMenuItem setTarget: pNSMenuItem]; [pNSMenuItem setCommand: aCommand]; - // Use the default menu's special "open new file" shortcuts - if ( aCommand == WRITER_URL ) - [pNSMenuItem setKeyEquivalent: @"t"]; - else if ( aCommand == CALC_URL ) - [pNSMenuItem setKeyEquivalent: @"s"]; - else if ( aCommand == IMPRESS_WIZARD_URL ) - [pNSMenuItem setKeyEquivalent: @"p"]; - else if ( aCommand == DRAW_URL ) - [pNSMenuItem setKeyEquivalent: @"d"]; - else if ( aCommand == MATH_URL ) - [pNSMenuItem setKeyEquivalent: @"f"]; - else if ( aCommand == BASE_URL ) - [pNSMenuItem setKeyEquivalent: @"a"]; - else - setKeyEquivalent( pMenu->GetAccelKey( nId ), pNSMenuItem ); + setKeyEquivalent( pMenu->GetAccelKey( nId ), pNSMenuItem ); } [pRet addItem: pNSMenuItem]; @@ -763,9 +737,7 @@ void aqua_init_systray() // menu => also let not appear it in the quickstarter continue; - OUString aKeyEquiv( getShortCut( ShutdownIcon::GetUrlDescription( sURL ) ) ); - - appendMenuItem( pMenu, pDockMenu, ShutdownIcon::GetUrlDescription( sURL ), aMenuItems[i].nMenuTag, aKeyEquiv ); + appendMenuItem( pMenu, pDockMenu, ShutdownIcon::GetUrlDescription( sURL ), aMenuItems[i].nMenuTag, "" ); } // insert the remaining menu entries @@ -774,11 +746,9 @@ void aqua_init_systray() appendRecentMenu( pMenu, SfxResId(STR_QUICKSTART_RECENTDOC) ); OUString aTitle( SfxResId(STR_QUICKSTART_FROMTEMPLATE) ); - OUString aKeyEquiv( getShortCut( aTitle ) ); - appendMenuItem( pMenu, pDockMenu, aTitle, MI_TEMPLATE, aKeyEquiv ); + appendMenuItem( pMenu, pDockMenu, aTitle, MI_TEMPLATE, "" ); aTitle = SfxResId(STR_QUICKSTART_FILEOPEN); - aKeyEquiv = getShortCut( aTitle ); - appendMenuItem( pMenu, pDockMenu, aTitle, MI_OPEN, aKeyEquiv ); + appendMenuItem( pMenu, pDockMenu, aTitle, MI_OPEN, "" ); [pDefMenu setSubmenu: pMenu]; resetMenuBar();