Skip to content

Commit b44372b

Browse files
gh-112898: Remove the false "Cancel" button in the "Save On Close" dialog
On macOS, when it is asked just before quiting the application, the user has no option to cancel quiting.
1 parent e0fb700 commit b44372b

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

Lib/idlelib/editor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,18 +1110,18 @@ def close_event(self, event):
11101110
self.close()
11111111
return "break"
11121112

1113-
def maybesave(self):
1113+
def maybesave(self, force=False):
11141114
if self.io:
11151115
if not self.get_saved():
11161116
if self.top.state()!='normal':
11171117
self.top.deiconify()
11181118
self.top.lower()
11191119
self.top.lift()
1120-
return self.io.maybesave()
1120+
return self.io.maybesave(force=force)
11211121

1122-
def close(self):
1122+
def close(self, force=False):
11231123
try:
1124-
reply = self.maybesave()
1124+
reply = self.maybesave(force=force)
11251125
if str(reply) != "cancel":
11261126
self._close()
11271127
return reply

Lib/idlelib/filelist.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ def gotofileline(self, filename, lineno=None):
4949
def new(self, filename=None):
5050
return self.EditorWindow(self, filename)
5151

52-
def close_all_callback(self, *args, **kwds):
52+
def close_all_callback(self, *args, force=False, **kwds):
5353
for edit in list(self.inversedict):
54-
reply = edit.close()
54+
reply = edit.close(force=force)
5555
if reply == "cancel":
5656
break
5757
return "break"
5858

59+
def close_all_force_callback(self, *args, **kwds):
60+
return self.close_all_callback(*args, force=True, **kwds)
61+
5962
def unregister_maybe_terminate(self, edit):
6063
try:
6164
key = self.inversedict[edit]

Lib/idlelib/iomenu.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def loadfile(self, filename):
179179
self.updaterecentfileslist(filename)
180180
return True
181181

182-
def maybesave(self):
182+
def maybesave(self, force=False):
183183
"""Return 'yes', 'no', 'cancel' as appropriate.
184184
185185
Tkinter messagebox.askyesnocancel converts these tk responses
@@ -190,15 +190,19 @@ def maybesave(self):
190190
message = ("Do you want to save "
191191
f"{self.filename or 'this untitled document'}"
192192
" before closing?")
193-
confirm = messagebox.askyesnocancel(
193+
makemsgbox = messagebox.askyesno if force else messagebox.askyesnocancel
194+
confirm = makemsgbox(
194195
title="Save On Close",
195196
message=message,
196197
default=messagebox.YES,
197198
parent=self.text)
199+
reply = "no" if force else "cancel"
198200
if confirm:
199201
self.save(None)
200-
reply = "yes" if self.get_saved() else "cancel"
201-
else: reply = "cancel" if confirm is None else "no"
202+
if self.get_saved():
203+
reply = "yes"
204+
elif confirm is not None:
205+
reply = "no"
202206
self.text.focus_set()
203207
return reply
204208

Lib/idlelib/macosx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def help_dialog(event=None):
221221
# The binding above doesn't reliably work on all versions of Tk
222222
# on macOS. Adding command definition below does seem to do the
223223
# right thing for now.
224-
root.createcommand('::tk::mac::Quit', flist.close_all_callback)
224+
root.createcommand('::tk::mac::Quit', flist.close_all_force_callback)
225225

226226
if isCarbonTk():
227227
# for Carbon AquaTk, replace the default Tk apple menu
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove the "Cancel" button in the "Save On Close" message box on macOS when
2+
the user has no option to cancel quiting.

0 commit comments

Comments
 (0)