Repository: beeware/toga

Issue:
Cocoa Close Window shortcut is incorrect
### Describe the bug

It should be Cmd-W, but the capital W is being translated into Cmd-Shift-W. Close All Windows is also affected.

We should add some shortcut tests to the testbed to cover this kind of thing.

<img width="757" alt="Screenshot 2023-11-08 at 18 53 55" src="https://github.com/beeware/toga/assets/166954/fea4f9c0-a37b-4310-b1ef-b2d2018fbe61">

### Environment

- Operating System: macOS
- Python version: 3.8
- Software versions:
  - Toga: main (536a60fb11)


Discussion:
"Close" is definitely Cmd-W (seen on Numbers, Music, Maps, and Contacts); but those apps are (1) designed to be persistent (i.e, they are either document-based, or they run in the background when the window isn't present), (2) they don't have a "close all" option. 

However, Safari has a "Close Window" and "Close All Windows" (also Close Tab), and the shortcut definitely includes a shift:
<img width="378" alt="Screenshot 2023-11-09 at 5 50 31 am" src="https://github.com/beeware/toga/assets/37345/49f0e05b-aa28-4337-a451-364f53573a09">

So - I'm not sure what the right solution is here. We definitely want consistency... but consistency with *what*? The simple "Close" doesn't entirely make sense on a base Toga app, because the core app *isn't* persistent - there's no difference between "close" and "quit".

I guess another option would be to take out the "Close" altogether, except maybe for DocumentApps. Close *can* be synthesised by an end user, so users could add it back in if they want it - the only complication would be that the shortcut wouldn't necessarily be platform appropriate.
For what it's worth, there are non-persistent apps that use Cmd-w for close as well, such as Calculator, Find My, Dictionary, Clock, and Weather. I think the distinction is less persistent vs. non-persistent and more single-window vs. multi-window (or multi-tab).
Yes, the impression I get is that the default on macOS is for Cmd-W to close the current window, unless the app offers a tab interface, in which case it closes the current tab. Single-window apps offer both Cmd-W and Cmd-Q, but they're the same except possibly for whether they leave the app running in the background.

I don't remember seeing any app in which Cmd-W does *nothing*. So I'm so used to using it, that when it does nothing on Toga, it feels like a big surprise.

Resolving patch:
diff --git a/cocoa/src/toga_cocoa/app.py b/cocoa/src/toga_cocoa/app.py
--- a/cocoa/src/toga_cocoa/app.py
+++ b/cocoa/src/toga_cocoa/app.py
@@ -199,24 +199,23 @@ def _create_app_commands(self):
                 section=sys.maxsize,
             ),
             # ---- File menu ----------------------------------
-            # This is a bit of an oddity. Safari has 2 distinct "Close Window" and
-            # "Close All Windows" menu items (partially to differentiate from "Close
-            # Tab"). Most other Apple HIG apps have a "Close" item that becomes
-            # "Close All" when you press Option (MOD_2). That behavior isn't something
-            # we're currently set up to implement, so we live with a separate menu item
-            # for now.
+            # This is a bit of an oddity. Apple HIG apps that don't have tabs as
+            # part of their interface (so, Preview and Numbers, but not Safari)
+            # have a "Close" item that becomes "Close All" when you press Option
+            # (MOD_2). That behavior isn't something we're currently set up to
+            # implement, so we live with a separate menu item for now.
             toga.Command(
                 self._menu_close_window,
-                "Close Window",
-                shortcut=toga.Key.MOD_1 + "W",
+                "Close",
+                shortcut=toga.Key.MOD_1 + "w",
                 group=toga.Group.FILE,
                 order=1,
                 section=50,
             ),
             toga.Command(
                 self._menu_close_all_windows,
-                "Close All Windows",
-                shortcut=toga.Key.MOD_2 + toga.Key.MOD_1 + "W",
+                "Close All",
+                shortcut=toga.Key.MOD_2 + toga.Key.MOD_1 + "w",
                 group=toga.Group.FILE,
                 order=2,
                 section=50,


Test patch:
diff --git a/cocoa/tests_backend/app.py b/cocoa/tests_backend/app.py
--- a/cocoa/tests_backend/app.py
+++ b/cocoa/tests_backend/app.py
@@ -117,8 +117,8 @@ def assert_system_menus(self):
         self.assert_menu_item(["*", "Show All"], enabled=True)
         self.assert_menu_item(["*", "Quit Toga Testbed"], enabled=True)
 
-        self.assert_menu_item(["File", "Close Window"], enabled=True)
-        self.assert_menu_item(["File", "Close All Windows"], enabled=True)
+        self.assert_menu_item(["File", "Close"], enabled=True)
+        self.assert_menu_item(["File", "Close All"], enabled=True)
 
         self.assert_menu_item(["Edit", "Undo"], enabled=True)
         self.assert_menu_item(["Edit", "Redo"], enabled=True)
@@ -134,10 +134,10 @@ def assert_system_menus(self):
         self.assert_menu_item(["Help", "Visit homepage"], enabled=True)
 
     def activate_menu_close_window(self):
-        self._activate_menu_item(["File", "Close Window"])
+        self._activate_menu_item(["File", "Close"])
 
     def activate_menu_close_all_windows(self):
-        self._activate_menu_item(["File", "Close All Windows"])
+        self._activate_menu_item(["File", "Close All"])
 
     def activate_menu_minimize(self):
         self._activate_menu_item(["Window", "Minimize"])