]> granicus.if.org Git - python/commitdiff
If Edit window has not been saved, offer to save if user tries to Run or
authorKurt B. Kaiser <kbk@shore.net>
Thu, 19 Dec 2002 03:25:34 +0000 (03:25 +0000)
committerKurt B. Kaiser <kbk@shore.net>
Thu, 19 Dec 2002 03:25:34 +0000 (03:25 +0000)
Check the module.

Lib/idlelib/ScriptBinding.py

index 1e05f0c0596709c3b2839ece3c989d11f7109760..8ab8e7afcdf7262557edc699f7a985ada2914c0d 100644 (file)
@@ -141,22 +141,29 @@ class ScriptBinding:
         interp.runcode(code)
 
     def getfilename(self):
-        # Logic to make sure we have a saved filename
-        # XXX Better logic would offer to save!
+        """Get source filename.  If not saved, offer to save (or create) file
+
+        The debugger requires a source file.  Make sure there is one, and that
+        the current version of the source buffer has been saved.  If the user
+        declines to save or cancels the Save As dialog, return None.
+        """
         if not self.editwin.get_saved():
-            name = (self.editwin.short_title() or
-                    self.editwin.long_title() or
-                    "Untitled")
-            self.errorbox("Not saved",
-                          "The buffer for %s is not saved.\n" % name +
-                          "Please save it first!")
-            self.editwin.text.focus_set()
-            return
+            msg = """Source Must Be Saved
+     OK to Save?"""
+            mb = tkMessageBox.Message(
+                                title="Save Before Run or Check",
+                                message=msg,
+                                icon=tkMessageBox.QUESTION,
+                                type=tkMessageBox.OKCANCEL,
+                                master=self.editwin.text)
+            reply = mb.show()
+            if reply == "ok":
+                self.editwin.io.save(None)
+            else:
+                return None
+        # filename is None if file doesn't exist
         filename = self.editwin.io.filename
-        if not filename:
-            self.errorbox("No file name",
-                          "This window has no file name")
-            return
+        self.editwin.text.focus_set()
         return filename
 
     def errorbox(self, title, message):