Skip to content

gh-112898: Remove the false "Cancel" button in the "Save On Close" msgbox #112994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions Lib/idlelib/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 8 additions & 4 deletions Lib/idlelib/iomenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Lib/idlelib/macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.