Fixing bug integrated plugin editors not closed when removing corresponding plugin
authorlaurent
Tue, 20 Dec 2011 23:37:06 +0100
changeset 656 c1792dfc8c7e
parent 655 5becd66cca02
child 657 340c0b9caeca
Fixing bug integrated plugin editors not closed when removing corresponding plugin
plugger.py
plugins/c_ext/CFileEditor.py
plugins/c_ext/c_ext.py
--- a/plugger.py	Mon Dec 19 01:56:13 2011 +0100
+++ b/plugger.py	Tue Dec 20 23:37:06 2011 +0100
@@ -97,6 +97,7 @@
     PlugMaxCount = None
     PluginMethods = []
     LibraryControler = None
+    EditorType = None
 
     def _AddParamsMembers(self):
         self.PlugParams = None
@@ -115,6 +116,7 @@
         self.MandatoryParams = ("BaseParams", self.BaseParams)
         self._AddParamsMembers()
         self.PluggedChilds = {}
+        self._View = None
         # copy PluginMethods so that it can be later customized
         self.PluginMethods = [dic.copy() for dic in self.PluginMethods]
         self.LoadSTLibrary()
@@ -137,6 +139,12 @@
         return os.path.join(self.PlugParent.PlugPath(),
                             PlugName + NameTypeSeparator + self.PlugType)
     
+    def PlugFullName(self):
+        parent = self.PlugParent.PlugFullName()
+        if parent != "":
+            return parent + "." + self.BaseParams.getName()
+        return self.BaseParams.getName()
+    
     def GetIconPath(self, name):
         return opjimg(name)
     
@@ -484,7 +492,22 @@
             self.GetPlugRoot().logger.write_warning(_("A child with IEC channel %d already exist -> %d\n")%(DesiredChannel,res))
         return res
 
+    def _OpenView(self):
+        if self.EditorType is not None and self._View is None:
+            app_frame = self.GetPlugRoot().AppFrame
+            
+            self._View = self.EditorType(app_frame.TabsOpened, self, app_frame)
+            
+            app_frame.EditProjectElement(self._View, self.GetFilename())
+
+    def OnCloseEditor(self):
+        self._View = None
+
     def OnPlugClose(self):
+        if self._View is not None:
+            app_frame = self.GetPlugRoot().AppFrame
+            if app_frame is not None:
+                app_frame.DeletePage(self._View)
         return True
 
     def _doRemoveChild(self, PlugInstance):
@@ -810,6 +833,9 @@
     def PlugTestModified(self):
          return self.ChangesToSave or not self.ProjectIsSaved()
 
+    def PlugFullName(self):
+        return ""
+
     def GetPlugRoot(self):
         return self
 
--- a/plugins/c_ext/CFileEditor.py	Mon Dec 19 01:56:13 2011 +0100
+++ b/plugins/c_ext/CFileEditor.py	Tue Dec 20 23:37:06 2011 +0100
@@ -477,7 +477,6 @@
                 editor = None
                 renderer = None
                 colname = self.GetColLabelValue(col)
-                grid.SetReadOnly(row, col, False)
                 
                 if colname == "Name":
                     editor = wx.grid.GridCellTextEditor()
@@ -618,6 +617,9 @@
             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"
 
@@ -646,7 +648,7 @@
     
     def OnVariablesGridCellChange(self, event):
         self.RefreshModel()
-        self.RefreshView()
+        wx.CallAfter(self.RefreshView)
         event.Skip()
 
     def OnVariablesGridEditorShown(self, event):
@@ -891,10 +893,10 @@
         self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16)))
         
     def GetTitle(self):
-        filename = self.Controler.GetFilename()
+        fullname = self.Controler.PlugFullName()
         if not self.Controler.CFileIsSaved():
-            return "~%s~" % filename
-        return filename
+            return "~%s~" % fullname
+        return fullname
     
     def GetBufferState(self):
         return self.Controler.GetBufferState()
--- a/plugins/c_ext/c_ext.py	Mon Dec 19 01:56:13 2011 +0100
+++ b/plugins/c_ext/c_ext.py	Tue Dec 20 23:37:06 2011 +0100
@@ -26,9 +26,13 @@
       </xsd:element>
     </xsd:schema>
     """
+    EditorType = CFileEditor
+    
     def __init__(self):
         filepath = self.CFileName()
         
+        self._View = None
+        
         self.Buffering = False
         self.CFile = CFileClasses["CFile"]()
         if os.path.isfile(filepath):
@@ -140,13 +144,6 @@
         elif name == "Publish":
             return self.CFile.publishFunction.gettext()
         return ""
-    
-    def _OpenView(self):
-        app_frame = self.GetPlugRoot().AppFrame
-        
-        cfileeditor = CFileEditor(app_frame.TabsOpened, self, app_frame)
-        
-        app_frame.EditProjectElement(cfileeditor, self.GetFilename())
                 
     PluginMethods = [
         {"bitmap" : os.path.join("images", "EditCfile"),
@@ -267,7 +264,8 @@
         matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath())
         
         return [(Gen_Cfile_path, str(self.CExtension.getCFLAGS() + matiec_flags))],str(self.CExtension.getLDFLAGS()),True
-        
+
+
 #-------------------------------------------------------------------------------
 #                      Current Buffering Management Functions
 #-------------------------------------------------------------------------------