Skip to content

IDLE: Tweak iomenu.IOBinding.maybesave #112914

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

Merged
merged 3 commits into from
Dec 10, 2023
Merged
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
21 changes: 11 additions & 10 deletions Lib/idlelib/iomenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from tkinter import filedialog
from tkinter import messagebox
from tkinter.simpledialog import askstring
from tkinter.simpledialog import askstring # loadfile encoding.

from idlelib.config import idleConf
from idlelib.util import py_extensions
Expand Down Expand Up @@ -180,24 +180,25 @@ def loadfile(self, filename):
return True

def maybesave(self):
"""Return 'yes', 'no', 'cancel' as appropriate.

Tkinter messagebox.askyesnocancel converts these tk responses
to True, False, None. Convert back, as now expected elsewhere.
"""
if self.get_saved():
return "yes"
message = "Do you want to save %s before closing?" % (
self.filename or "this untitled document")
message = ("Do you want to save "
f"{self.filename or 'this untitled document'}"
" before closing?")
confirm = messagebox.askyesnocancel(
title="Save On Close",
message=message,
default=messagebox.YES,
parent=self.text)
if confirm:
reply = "yes"
self.save(None)
if not self.get_saved():
reply = "cancel"
elif confirm is None:
reply = "cancel"
else:
reply = "no"
reply = "yes" if self.get_saved() else "cancel"
else: reply = "cancel" if confirm is None else "no"
self.text.focus_set()
return reply

Expand Down