Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2597)

Unified Diff: chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm

Issue 898543008: Fixed "Close Window" shortcut in File Menu for Hosted/Packaged apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Close window menu item only added at beginning Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm
diff --git a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm
index f0f47f94f444978e94891a56b8c2e7bf473ffd40..7b545e8926f6a467e2450faba71e7fc04c4aba6f 100644
--- a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm
+++ b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm
@@ -298,15 +298,15 @@ void SetItemWithTagVisible(NSMenuItem* top_level_item,
[[fileMenuItem_ submenu] addItem:[newDoppelganger_ menuItem]];
[[fileMenuItem_ submenu] addItem:[openDoppelganger_ menuItem]];
[[fileMenuItem_ submenu] addItem:[NSMenuItem separatorItem]];
- AddDuplicateItem(fileMenuItem_, IDC_FILE_MENU, IDC_CLOSE_WINDOW);
- // Set the expected key equivalent explicitly here because
- // -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:] sets it to
- // "W" (Cmd+Shift+w) when a tabbed window has focus; it will change it back
- // to Cmd+w when a non-tabbed window has focus.
- NSMenuItem* closeWindowMenuItem =
- [[fileMenuItem_ submenu] itemWithTag:IDC_CLOSE_WINDOW];
- [closeWindowMenuItem setKeyEquivalent:@"w"];
- [closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
+
+ // Since the "Close Window" menu item will have the same shortcut as "Close
+ // Tab" on the Chrome menu, we need to swap out these modifier keys
+ // depending on the current menu we're displaying.
+ closeWindowDuplicateMenuItem_.reset(
+ [GetItemByTag(IDC_FILE_MENU, IDC_CLOSE_WINDOW) copy]);
+ closeTabSourceMenuItem_.reset(
+ [GetItemByTag(IDC_FILE_MENU, IDC_CLOSE_TAB) retain]);
+ [[fileMenuItem_ submenu] addItem:closeWindowDuplicateMenuItem_];
// Edit menu. We copy the menu because the last two items, "Start Dictation"
// and "Special Characters" are added by OSX, so we can't copy them
@@ -411,6 +411,17 @@ void SetItemWithTagVisible(NSMenuItem* top_level_item,
[appMenuItem_ setTitle:appId];
[[appMenuItem_ submenu] setTitle:title];
+ // Remove the "Close Tab" key equivalent in the main menu first, then set
+ // the key equivalent for our copy.
+ [closeTabSourceMenuItem_ setKeyEquivalent:@""];
tapted 2015/02/04 05:02:49 this logic is pretty close to what DoppelgangerMen
jackhou1 2015/02/04 05:46:28 The "Close Window" item kind of has two source ite
mitchellj 2015/02/04 22:33:40 Good idea, this seems cleaner. Do you think the fu
+
+ // Set the expected key equivalent explicitly here because it may have been
+ // either Cmd+Shift+w or Cmd+w.
+ // See -[AppControllerMac adjustCloseWindowMenuItemKeyEquivalent:].
+ [closeWindowDuplicateMenuItem_ setKeyEquivalent:@"w"];
+ [closeWindowDuplicateMenuItem_
+ setKeyEquivalentModifierMask:NSCommandKeyMask];
+
[mainMenu addItem:appMenuItem_];
[mainMenu addItem:fileMenuItem_];
@@ -434,6 +445,11 @@ void SetItemWithTagVisible(NSMenuItem* top_level_item,
appId_.reset();
+ // Restore the "Close Tab" key equivalent in the main menu.
+ [closeWindowDuplicateMenuItem_ setKeyEquivalent:@""];
+ [closeTabSourceMenuItem_ setKeyEquivalent:@"w"];
+ [closeTabSourceMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
+
NSMenu* mainMenu = [NSApp mainMenu];
[mainMenu removeItem:appMenuItem_];
[mainMenu removeItem:fileMenuItem_];

Powered by Google App Engine
This is Rietveld 408576698