diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index 6ad383f460c7ee..280fd6336c69df 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -1110,18 +1110,18 @@ def close_event(self, event): self.close() return "break" - def maybesave(self): + def maybesave(self, force=False): if self.io: if not self.get_saved(): if self.top.state()!='normal': self.top.deiconify() self.top.lower() self.top.lift() - return self.io.maybesave() + return self.io.maybesave(force=force) - def close(self): + def close(self, force=False): try: - reply = self.maybesave() + reply = self.maybesave(force=force) if str(reply) != "cancel": self._close() return reply diff --git a/Lib/idlelib/filelist.py b/Lib/idlelib/filelist.py index e27e5d32a0ff63..d3ac94fb6d362c 100644 --- a/Lib/idlelib/filelist.py +++ b/Lib/idlelib/filelist.py @@ -49,13 +49,16 @@ def gotofileline(self, filename, lineno=None): def new(self, filename=None): return self.EditorWindow(self, filename) - def close_all_callback(self, *args, **kwds): + def close_all_callback(self, *args, force=False, **kwds): for edit in list(self.inversedict): - reply = edit.close() + reply = edit.close(force=force) if reply == "cancel": break return "break" + def close_all_force_callback(self, *args, **kwds): + return self.close_all_callback(*args, force=True, **kwds) + def unregister_maybe_terminate(self, edit): try: key = self.inversedict[edit] diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index 464126e2df0668..f7e0b2581db41a 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -179,7 +179,7 @@ def loadfile(self, filename): self.updaterecentfileslist(filename) return True - def maybesave(self): + def maybesave(self, force=False): """Return 'yes', 'no', 'cancel' as appropriate. Tkinter messagebox.askyesnocancel converts these tk responses @@ -190,15 +190,19 @@ def maybesave(self): message = ("Do you want to save " f"{self.filename or 'this untitled document'}" " before closing?") - confirm = messagebox.askyesnocancel( + makemsgbox = messagebox.askyesno if force else messagebox.askyesnocancel + confirm = makemsgbox( title="Save On Close", message=message, default=messagebox.YES, parent=self.text) + reply = "no" if force else "cancel" if confirm: self.save(None) - reply = "yes" if self.get_saved() else "cancel" - else: reply = "cancel" if confirm is None else "no" + if self.get_saved(): + reply = "yes" + elif confirm is not None: + reply = "no" self.text.focus_set() return reply diff --git a/Lib/idlelib/macosx.py b/Lib/idlelib/macosx.py index 332952f4572cbd..866bd7bdcae78f 100644 --- a/Lib/idlelib/macosx.py +++ b/Lib/idlelib/macosx.py @@ -221,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('::tk::mac::Quit', flist.close_all_callback) + root.createcommand('::tk::mac::Quit', flist.close_all_force_callback) if isCarbonTk(): # for Carbon AquaTk, replace the default Tk apple menu diff --git a/Misc/NEWS.d/next/IDLE/2023-12-12-10-34-07.gh-issue-112898.ta3N4t.rst b/Misc/NEWS.d/next/IDLE/2023-12-12-10-34-07.gh-issue-112898.ta3N4t.rst new file mode 100644 index 00000000000000..262e0e06f9fa12 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2023-12-12-10-34-07.gh-issue-112898.ta3N4t.rst @@ -0,0 +1,2 @@ +Remove the "Cancel" button in the "Save On Close" message box on macOS when +the user has no option to cancel quiting.