Adding support for checking that tab content is saved before closing it
authorLaurent Bessard
Tue, 31 Jul 2012 17:45:06 +0200
changeset 733 c4424d8eebb0
parent 732 7991eb6bcb5a
child 734 eeac14463bcf
Adding support for checking that tab content is saved before closing it
PLCOpenEditor.py
controls/EditorPanel.py
--- a/PLCOpenEditor.py	Mon Jul 30 16:06:21 2012 +0200
+++ b/PLCOpenEditor.py	Tue Jul 31 17:45:06 2012 +0200
@@ -1058,12 +1058,17 @@
     def OnPageClose(self, event):
         selected = self.TabsOpened.GetSelection()
         if selected > -1:
-            self.SavePageState(self.TabsOpened.GetPage(selected))
-        
-        # Refresh all window elements that have changed
-        wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
-        wx.CallAfter(self.RefreshTabCtrlEvent)
-        event.Skip()
+            window = self.TabsOpened.GetPage(selected)
+            
+            if window.CheckSaveBeforeClosing():
+                self.SavePageState(window)
+                
+                # Refresh all window elements that have changed
+                wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
+                wx.CallAfter(self.RefreshTabCtrlEvent)
+                event.Skip()
+            else:
+                event.Veto()
 
     def GetCopyBuffer(self):
         data = None
@@ -1166,6 +1171,12 @@
                 self.SaveProject()
             elif answer == wx.ID_CANCEL:
                 return False
+        
+        for idx in xrange(self.TabsOpened.GetPageCount()):
+            window = self.TabsOpened.GetPage(idx)
+            if not window.CheckSaveBeforeClosing():
+                return False
+        
         return True
 
 #-------------------------------------------------------------------------------
--- a/controls/EditorPanel.py	Mon Jul 30 16:06:21 2012 +0200
+++ b/controls/EditorPanel.py	Tue Jul 31 17:45:06 2012 +0200
@@ -106,6 +106,9 @@
     def IsModified(self):
         return False
     
+    def CheckSaveBeforeClosing(self):
+        return True
+    
     def Save(self):
         pass