Fixing some issues in c_ext plugin
authorlaurent
Wed, 21 Dec 2011 19:43:40 +0100
changeset 658 94417ab25510
parent 657 340c0b9caeca
child 659 71a824446673
Fixing some issues in c_ext plugin
plugins/c_ext/CFileEditor.py
plugins/c_ext/c_ext.py
--- a/plugins/c_ext/CFileEditor.py	Wed Dec 21 19:42:49 2011 +0100
+++ b/plugins/c_ext/CFileEditor.py	Wed Dec 21 19:43:40 2011 +0100
@@ -210,6 +210,7 @@
                         self.Controler.EndBuffering()
                         self.StartBuffering()
                     self.CurrentAction = ("Add", event.GetPosition())
+                    wx.CallAfter(self.RefreshModel)
                 elif mod_type&wx.stc.STC_MOD_BEFOREDELETE:
                     if self.CurrentAction == None:
                         self.StartBuffering()
@@ -217,6 +218,7 @@
                         self.Controler.EndBuffering()
                         self.StartBuffering()
                     self.CurrentAction = ("Delete", event.GetPosition())
+                    wx.CallAfter(self.RefreshModel)
         event.Skip()
     
     def OnDoDrop(self, event):
@@ -224,13 +226,10 @@
         wx.CallAfter(self.RefreshModel)
         event.Skip()
 
-    def IsViewing(self, name):
-        return self.Name == name
-
     # Buffer the last model state
     def RefreshBuffer(self):
         self.Controler.BufferCFile()
-        if self.ParentWindow:
+        if self.ParentWindow is not None:
             self.ParentWindow.RefreshTitle()
             self.ParentWindow.RefreshFileMenu()
             self.ParentWindow.RefreshEditMenu()
@@ -238,7 +237,7 @@
     
     def StartBuffering(self):
         self.Controler.StartBuffering()
-        if self.ParentWindow:
+        if self.ParentWindow is not None:
             self.ParentWindow.RefreshTitle()
             self.ParentWindow.RefreshFileMenu()
             self.ParentWindow.RefreshEditMenu()
@@ -295,7 +294,6 @@
                 # Images are specified with a appended "?type"
                 self.AutoCompShow(0, " ".join([word + "?1" for word in CPP_KEYWORDS]))
         else:
-            wx.CallAfter(self.RefreshModel)
             event.Skip()
 
     def OnKillFocus(self, event):
@@ -617,19 +615,10 @@
             self.VariablesGrid.SetColSize(col, self.ColSizes[col])
         self.Table.ResetView(self.VariablesGrid)
 
-    def __del__(self):
-        self.Controler.OnCloseEditor()
-
-    def IsViewing(self, name):
-        return name == "Variables"
-
     def RefreshModel(self):
         self.Controler.SetVariables(self.Table.GetData())
         self.RefreshBuffer()
         
-    def ResetBuffer(self):
-        pass
-
     # Buffer the last model state
     def RefreshBuffer(self):
         self.Controler.BufferCFile()
@@ -853,7 +842,7 @@
 class CFileEditor(EditorPanel):
     
     def _init_Editor(self, prnt):
-        self.Editor = wx.Panel(id=-1, parent=prnt, pos=wx.Point(0, 0), 
+        self.Editor = wx.Panel(id=ID_CFILEEDITOR, parent=prnt, pos=wx.Point(0, 0), 
                 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
         
         self.Panels = {}
@@ -892,6 +881,9 @@
         img = wx.Bitmap(self.Controler.GetIconPath("Cfile.png"), wx.BITMAP_TYPE_PNG).ConvertToImage()
         self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16)))
         
+    def __del__(self):
+        self.Controler.OnCloseEditor()
+    
     def GetTitle(self):
         fullname = self.Controler.PlugFullName()
         if not self.Controler.CFileIsSaved():
--- a/plugins/c_ext/c_ext.py	Wed Dec 21 19:42:49 2011 +0100
+++ b/plugins/c_ext/c_ext.py	Wed Dec 21 19:43:40 2011 +0100
@@ -31,9 +31,6 @@
     def __init__(self):
         filepath = self.CFileName()
         
-        self._View = None
-        
-        self.Buffering = False
         self.CFile = CFileClasses["CFile"]()
         if os.path.isfile(filepath):
             xmlfile = open(filepath, 'r')
@@ -43,9 +40,9 @@
             for child in tree.childNodes:
                 if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "CFile":
                     self.CFile.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"])
-                    self.CFileBuffer = UndoBuffer(self.Copy(self.CFile), True)
+                    self.CreateCFileBuffer(True)
         else:
-            self.CFileBuffer = UndoBuffer(self.Copy(self.CFile), False)
+            self.CreateCFileBuffer(False)
             self.OnPlugSave()
 
     def CFileName(self):
@@ -276,7 +273,8 @@
     def Copy(self, model):
         return cPickle.loads(cPickle.dumps(model))
 
-    def CreateConfigBuffer(self, saved):
+    def CreateCFileBuffer(self, saved):
+        self.Buffering = False
         self.CFileBuffer = UndoBuffer(cPickle.dumps(self.CFile), saved)
 
     def BufferCFile(self):
@@ -295,11 +293,8 @@
         self.CFileBuffer.CurrentSaved()
     
     def CFileIsSaved(self):
-        if self.CFileBuffer:
-            return self.CFileBuffer.IsCurrentSaved() and not self.Buffering
-        else:
-            return True
-
+        return self.CFileBuffer.IsCurrentSaved() and not self.Buffering
+        
     def LoadPrevious(self):
         self.EndBuffering()
         self.CFile = cPickle.loads(self.CFileBuffer.Previous())
@@ -308,7 +303,7 @@
         self.CFile = cPickle.loads(self.CFileBuffer.Next())
     
     def GetBufferState(self):
-        first = self.CFileBuffer.IsFirst()
+        first = self.CFileBuffer.IsFirst() and not self.Buffering
         last = self.CFileBuffer.IsLast()
         return not first, not last