PLCOpenEditor.py
changeset 144 b67a5de5a24a
parent 138 9c74d00ce93e
child 145 4fb225afddf4
--- a/PLCOpenEditor.py	Fri Jan 04 17:47:58 2008 +0100
+++ b/PLCOpenEditor.py	Fri Jan 04 17:49:17 2008 +0100
@@ -518,7 +518,7 @@
             notebook = self.GetNotebook()
             if notebook is not None:
                 for idx in xrange(notebook.GetPageCount()):
-                    notebook.DeletePage(idx)
+                    notebook.DeletePage(0)
         else:
             self.TabsOpened.DeleteAllPages()
 
@@ -633,7 +633,10 @@
             window = self.GetPage(selected)
             window.RefreshView()
             if variablepanel:
-                self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName())
+                self.RefreshVariablePanel(window.GetTagName())
+
+    def RefreshVariablePanel(self, tagname):
+        self.VariablePanelIndexer.RefreshVariablePanel(tagname)
 
     def ShowProperties(self):
         old_values = self.Controler.GetProjectProperties()
@@ -684,6 +687,14 @@
         event.Skip()
 
     def OnOpenProjectMenu(self, event):
+        if not self.Controler.ProjectIsSaved():
+            dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
+            answer = dialog.ShowModal()
+            dialog.Destroy()
+            if answer == wx.ID_YES:
+                self.SaveProject()
+            elif answer == wx.ID_CANCEL:
+                return
         filepath = self.Controler.GetFilePath()
         if filepath != "":
             directory = os.path.dirname(filepath)
@@ -693,8 +704,9 @@
         if dialog.ShowModal() == wx.ID_OK:
             filepath = dialog.GetPath()
             if os.path.isfile(filepath):
+                self.DeleteAllPages()
+                self.VariablePanelIndexer.RemoveAllPanels()
                 self.Controler.OpenXMLFile(filepath)
-                self.DeleteAllPages()
                 self.RefreshProjectTree()
             self.RefreshTitle()
             self.RefreshFileMenu()
@@ -721,6 +733,14 @@
         event.Skip()
     
     def OnCloseProjectMenu(self, event):
+        if not self.Controler.ProjectIsSaved():
+            dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
+            answer = dialog.ShowModal()
+            dialog.Destroy()
+            if answer == wx.ID_YES:
+                self.SaveProject()
+            elif answer == wx.ID_CANCEL:
+                return
         self.DeleteAllPages()
         self.VariablePanelIndexer.RemoveAllPanels()
         self.ProjectTree.DeleteAllItems()
@@ -2428,8 +2448,13 @@
         self.PouNames = []
         self.PouElementNames = []
         
-        self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
-        
+        if wx.VERSION >= (2, 8, 0):
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId())
+        elif wx.VERSION >= (2, 6, 0):
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
+        else:
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
+    
     def OnOK(self, event):
         config_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
         if config_name == "":
@@ -2486,8 +2511,13 @@
         self.PouNames = []
         self.PouElementNames = []
         
-        self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
-        
+        if wx.VERSION >= (2, 8, 0):
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId())
+        elif wx.VERSION >= (2, 6, 0):
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
+        else:
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
+
     def OnOK(self, event):
         resource_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
         if resource_name == "":