[Python-checkins] r65416 - in sandbox/trunk/ttk-gsoc/src/idlelib: EditorWindow.py editorpage.py

guilherme.polo python-checkins at python.org
Sat Aug 2 20:11:59 CEST 2008


Author: guilherme.polo
Date: Sat Aug  2 20:11:59 2008
New Revision: 65416

Log:
Moved maybesave from EditorWindow to editorpage;
Removed own dependency of self.io in EditorWindow;
Updated EditorWindow _close to properly close all the tabs (right now it tries
to save even PyShell -- to fix).


Modified:
   sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py
   sandbox/trunk/ttk-gsoc/src/idlelib/editorpage.py

Modified: sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py	Sat Aug  2 20:11:59 2008
@@ -112,8 +112,6 @@
         self.top.focused_widget = self.text
         self.text_notebook.pack(fill=BOTH, expand=True)
 
-        self.io = self.current_page.io
-
         # The following "width" attribute is used by PyShell, so keep it here
         self.width = idleConf.GetOption('main', 'EditorPage', 'width')
 
@@ -122,7 +120,6 @@
         self.top.protocol("WM_DELETE_WINDOW", self.close)
         self.top.bind("<<close-window>>", self.close_event)
 
-        # XXX This need to be done per tab too
         if flist:
             flist.inversedict[self] = key
             if key:
@@ -453,7 +450,7 @@
                                  underline=0)
 
     def get_saved(self):
-        return self.current_page.undo.get_saved() # XXX Pretty wrong
+        return self.current_page.undo.get_saved() # XXX check this!
 
     def get_geometry(self):
         "Return (width, height, x, y)"
@@ -465,27 +462,37 @@
     def close_event(self, event):
         self.close()
 
-    def maybesave(self):
-        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()
-
     def close(self):
-        reply = self.maybesave()
-        if str(reply) != "cancel":
-            self._close()
-        return reply
-
-    def _close(self): # XXX There should be one like this per EditorPage
-        if self.io.filename:
-            self.update_recent_files_list(new_file=self.io.filename)
+        # XXX need to skip a possible PyShell tab
+        replies = []
+        to_check = self.text_notebook.pages.copy()
+        while to_check:
+            curr_tab = self.text_notebook.select()
+            if TTK:
+                page_name = self.text_notebook.tab(curr_tab)['text']
+            else:
+                page_name = curr_tab
+
+            page = to_check.pop(page_name)
+            editpage = page.editpage
+            reply = str(editpage.maybesave())
+            replies.append(reply)
+            if reply != "cancel":
+                if editpage.io.filename:
+                    self.update_recent_files_list(new_file=editpage.io.filename)
+                editpage.close()
+                self.text_notebook.remove_page(page_name)
+
+        for reply in replies:
+            if reply == "cancel":
+                break
+        else:
+             self._close()
+        return replies
+
+    def _close(self):
         WindowList.unregister_callback(self.postwindowsmenu)
-        self.unload_extensions() # XXX maybe this should be done per tab
-        self.text = None
+        self.unload_extensions()
         self.tkinter_vars = None
 
         for page in self.text_notebook.pages.itervalues():
@@ -627,7 +634,6 @@
     def _update_controls(self, event):
         print self.short_title(), "<<"
         self.current_page.text.focus_set()
-        self.io = self.current_page.io
         self.set_line_and_column()
 
     def _create_statusbar(self):
@@ -697,7 +703,7 @@
 
     def __recent_file_callback(self, file_name):
         def open_recent_file(fn_closure=file_name):
-            self.io.open(editFile=fn_closure)
+            self.current_page.io.open(editFile=fn_closure)
         return open_recent_file
 
     def __extra_help_callback(self, helpfile):

Modified: sandbox/trunk/ttk-gsoc/src/idlelib/editorpage.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/editorpage.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/editorpage.py	Sat Aug  2 20:11:59 2008
@@ -115,6 +115,7 @@
 
         self.per.close()
         self.per = None
+        self.text = None
 
     # XXX (1) mark where these functions are used
     def saved_change_hook(self):
@@ -185,6 +186,15 @@
     def long_title(self):
         # return unicode string to display non-ASCII chars correctly
         return filename_to_unicode(self.io.filename or "")
+
+    def maybesave(self):
+        if self.io:
+            if not self.get_saved():
+                if self.editwin.top.state()!= 'normal':
+                    self.editiwn.top.deiconify()
+                self.editwin.top.lower()
+                self.editwin.top.lift()
+            return self.io.maybesave()
     # XXX (1) end
 
     def center(self, mark="insert"):


More information about the Python-checkins mailing list