Adding support for Enable/Disable Undo/Redo
authorgreg
Mon, 04 May 2009 09:35:17 +0200
changeset 349 96cc6179b918
parent 348 09fdd7616a86
child 350 f7958989e055
Adding support for Enable/Disable Undo/Redo
Bug not updating TypeHierarchy and ElementUsingTree after datatype name changed fixed
PLCControler.py
--- a/PLCControler.py	Mon May 04 09:33:46 2009 +0200
+++ b/PLCControler.py	Mon May 04 09:35:17 2009 +0200
@@ -177,7 +177,9 @@
     # Reset PLCControler internal variables
     def Reset(self):
         self.Project = None
+        self.ProjectBufferEnabled = False
         self.ProjectBuffer = None
+        self.ProjectSaved = False
         self.Buffering = False
         self.FilePath = ""
         self.FileName = ""
@@ -213,7 +215,7 @@
         self.Project.setcontentHeader(properties)
         self.SetFilePath("")
         # Initialize the project buffer
-        self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), False)
+        self.CreateProjectBuffer(False)
         self.ProgramChunks = []
         self.NextCompiledProject = self.Copy(self.Project)
         self.CurrentCompiledProject = None
@@ -265,7 +267,7 @@
     # Return file name and point out if file is up to date
     def GetFilename(self):
         if self.Project is not None:
-            if self.ProjectBuffer.IsCurrentSaved():
+            if self.ProjectIsSaved():
                 return self.FileName
             else:
                 return "~%s~"%self.FileName
@@ -653,6 +655,8 @@
             if datatype is not None:
                 datatype.setname(new_name)
                 self.Project.updateElementName(old_name, new_name)
+                self.Project.RefreshElementUsingTree()
+                self.Project.RefreshDataTypeHierarchy()
                 self.BufferProject()
     
     # Change the name of a pou
@@ -2645,7 +2649,7 @@
                 self.Project.RefreshElementUsingTree()
                 self.Project.RefreshDataTypeHierarchy()
                 self.Project.RefreshCustomBlockTypes()
-                self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), True)
+                self.CreateProjectBuffer(True)
                 self.ProgramChunks = []
                 self.NextCompiledProject = self.Copy(self.Project)
                 self.CurrentCompiledProject = None
@@ -2675,7 +2679,7 @@
                 xmlfile = open(self.FilePath,"w")
             xmlfile.write(text)
             xmlfile.close()
-            self.ProjectBuffer.CurrentSaved()
+            self.ProjectSaved()
             if filepath:
                 self.SetFilePath(filepath)
             return True
@@ -2690,32 +2694,67 @@
     def Copy(self, model):
         return cPickle.loads(cPickle.dumps(model))
 
+    def CreateProjectBuffer(self, saved):
+        if self.ProjectBufferEnabled:
+            self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), saved)
+        else:
+            self.ProjectBuffer = None
+            self.ProjectSaved = saved
+
+    def IsProjectBufferEnabled(self):
+        return self.ProjectBufferEnabled
+
+    def EnableProjectBuffer(self, enable):
+        self.ProjectBufferEnabled = enable
+        if self.Project is not None:
+            if enable:
+                current_saved = self.ProjectSaved
+            else:
+                current_saved = self.ProjectBuffer.IsCurrentSaved()
+            self.CreateProjectBuffer(current_saved)
+
     def BufferProject(self):
-        self.ProjectBuffer.Buffering(self.Copy(self.Project))
+        if self.ProjectBuffer is not None:
+            self.ProjectBuffer.Buffering(self.Copy(self.Project))
+        else:
+            self.ProjectSaved = False
 
     def StartBuffering(self):
-        self.ProjectBuffer.Buffering(self.Project)
-        self.Buffering = True
+        if self.ProjectBuffer is not None:
+            self.ProjectBuffer.Buffering(self.Project)
+            self.Buffering = True
+        else:
+            self.ProjectSaved = False
         
     def EndBuffering(self):
-        if self.Buffering:
+        if self.ProjectBuffer is not None and self.Buffering:
             self.Project = self.Copy(self.Project)
             self.Buffering = False
 
+    def ProjectSaved(self):
+        if self.ProjectBuffer is not None:
+            self.ProjectBuffer.CurrentSaved()
+        else:
+            self.ProjectSaved = True
+    
     # Return if project is saved
     def ProjectIsSaved(self):
         if self.ProjectBuffer is not None:
             return self.ProjectBuffer.IsCurrentSaved()
         else:
-            return True
+            return self.ProjectSaved
 
     def LoadPrevious(self):
-        self.Project = self.Copy(self.ProjectBuffer.Previous())
+        if self.ProjectBuffer is not None:
+            self.Project = self.Copy(self.ProjectBuffer.Previous())
     
     def LoadNext(self):
-        self.Project = self.Copy(self.ProjectBuffer.Next())
+        if self.ProjectBuffer is not None:
+            self.Project = self.Copy(self.ProjectBuffer.Next())
     
     def GetBufferState(self):
-        first = self.ProjectBuffer.IsFirst()
-        last = self.ProjectBuffer.IsLast()
-        return not first, not last
+        if self.ProjectBuffer is not None:
+            first = self.ProjectBuffer.IsFirst()
+            last = self.ProjectBuffer.IsLast()
+            return not first, not last
+        return False, False