From daa6ac559a3deaa1879467ebce8e522a3e1b0411 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Sun, 10 Dec 2023 20:01:33 +0100 Subject: [PATCH 1/2] gh-112898: warn about unsaved files when quitting IDLE on macOS Implement the TK function ``::tk::mac::Quit`` on macOS to ensure that IDLE asks about saving unsaved files when quitting IDLE. --- Lib/idlelib/macosx.py | 11 +++++++++++ .../2023-12-10-20-01-11.gh-issue-112898.98aWv2.rst | 1 + 2 files changed, 12 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2023-12-10-20-01-11.gh-issue-112898.98aWv2.rst diff --git a/Lib/idlelib/macosx.py b/Lib/idlelib/macosx.py index 2ea02ec04d661a..6af01d452296aa 100644 --- a/Lib/idlelib/macosx.py +++ b/Lib/idlelib/macosx.py @@ -131,6 +131,16 @@ def doOpenFile(*args): # one for every file that should be opened. root.createcommand("::tk::mac::OpenDocument", doOpenFile) +def addQuitSupport(root, flist): + """ + This ensures that the application will respond properly to quit events, + including the "IDLE -> Quit IDLE" menu. + """ + def doQuit(): + flist.close_all_callback() + + root.createcommand("::tk::mac::Quit", doQuit) + def hideTkConsole(root): try: root.tk.call('console', 'hide') @@ -270,6 +280,7 @@ def setupApp(root, flist): hideTkConsole(root) overrideRootMenu(root, flist) addOpenEventSupport(root, flist) + addQuitSupport(root, flist) fixb2context(root) diff --git a/Misc/NEWS.d/next/IDLE/2023-12-10-20-01-11.gh-issue-112898.98aWv2.rst b/Misc/NEWS.d/next/IDLE/2023-12-10-20-01-11.gh-issue-112898.98aWv2.rst new file mode 100644 index 00000000000000..1c20e46b1e5f7b --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2023-12-10-20-01-11.gh-issue-112898.98aWv2.rst @@ -0,0 +1 @@ +Fix processing unsaved files when quitting IDLE on macOS. From 0f6606bb1d74d7832adac4882dc557aa60de74d0 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Sun, 10 Dec 2023 20:05:49 +0100 Subject: [PATCH 2/2] Nicer implementation --- Lib/idlelib/macosx.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Lib/idlelib/macosx.py b/Lib/idlelib/macosx.py index 6af01d452296aa..332952f4572cbd 100644 --- a/Lib/idlelib/macosx.py +++ b/Lib/idlelib/macosx.py @@ -131,16 +131,6 @@ def doOpenFile(*args): # one for every file that should be opened. root.createcommand("::tk::mac::OpenDocument", doOpenFile) -def addQuitSupport(root, flist): - """ - This ensures that the application will respond properly to quit events, - including the "IDLE -> Quit IDLE" menu. - """ - def doQuit(): - flist.close_all_callback() - - root.createcommand("::tk::mac::Quit", doQuit) - def hideTkConsole(root): try: root.tk.call('console', 'hide') @@ -231,7 +221,7 @@ def help_dialog(event=None): # The binding above doesn't reliably work on all versions of Tk # on macOS. Adding command definition below does seem to do the # right thing for now. - root.createcommand('exit', flist.close_all_callback) + root.createcommand('::tk::mac::Quit', flist.close_all_callback) if isCarbonTk(): # for Carbon AquaTk, replace the default Tk apple menu @@ -280,7 +270,6 @@ def setupApp(root, flist): hideTkConsole(root) overrideRootMenu(root, flist) addOpenEventSupport(root, flist) - addQuitSupport(root, flist) fixb2context(root)