Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
authorLaurent Bessard
Tue, 14 May 2013 20:16:07 +0200
changeset 1138 cf2a6a7c87e8
parent 1137 c37f8d379ab0
child 1139 f9cf74053b7d
Replaced the 2 tabs variable and code in CodeFileEditor by only one type with SplitterWindow and fixed drag'n drop of variable from variable to code.
c_ext/CFileEditor.py
editors/CodeFileEditor.py
py_ext/PythonEditor.py
--- a/c_ext/CFileEditor.py	Tue May 14 18:43:52 2013 +0200
+++ b/c_ext/CFileEditor.py	Tue May 14 20:16:07 2013 +0200
@@ -36,18 +36,9 @@
 
 class CFileEditor(CodeFileEditor):
     
-    CONFNODEEDITOR_TABS = CodeFileEditor.CONFNODEEDITOR_TABS + [
-        (_("C code"), "_create_CCodeEditor")]
-    
-    def _create_CCodeEditor(self, prnt):
-        self.CCodeEditor = CppEditor(prnt, self.ParentWindow, self.Controler)
-        
-        return self.CCodeEditor
+    CONFNODEEDITOR_TABS = [
+        (_("C code"), "_create_CodePanel")]
+    CODE_EDITOR = CppEditor
 
-    def RefreshView(self):
-        CodeFileEditor.RefreshView(self)
-        
-        self.CCodeEditor.RefreshView()
 
-    def Find(self, direction, search_params):
-        self.CCodeEditor.Find(direction, search_params)
+
--- a/editors/CodeFileEditor.py	Tue May 14 18:43:52 2013 +0200
+++ b/editors/CodeFileEditor.py	Tue May 14 20:16:07 2013 +0200
@@ -172,8 +172,21 @@
         event.Skip()
     
     def OnDoDrop(self, event):
-        self.ResetBuffer()
-        wx.CallAfter(self.RefreshModel)
+        try:
+            values = eval(event.GetDragText())
+        except:
+            values = event.GetDragText()
+        if isinstance(values, tuple):
+            message = None
+            if values[3] == self.Controler.GetCurrentLocation():
+                self.ResetBuffer()
+                event.SetDragText(values[0])
+                wx.CallAfter(self.RefreshModel)
+            else:
+                event.SetDragText("")
+        else:
+            self.ResetBuffer()
+            wx.CallAfter(self.RefreshModel)
         event.Skip()
 
     # Buffer the last model state
@@ -731,9 +744,8 @@
             row = event.GetRow()
             data_type = self.Table.GetValueByName(row, "Type")
             var_name = self.Table.GetValueByName(row, "Name")
-            location = "_".join(map(lambda x:str(x), self.Controler.GetCurrentLocation()))
-            data = wx.TextDataObject(str(("%s_%s" % (var_name, location), 
-                                          "Global", data_type, "")))
+            data = wx.TextDataObject(str((var_name, "Global", data_type, 
+                    self.Controler.GetCurrentLocation())))
             dragSource = wx.DropSource(self.VariablesGrid)
             dragSource.SetData(data)
             dragSource.DoDragDrop()
@@ -747,16 +759,31 @@
 
 class CodeFileEditor(ConfTreeNodeEditor):
     
-    CONFNODEEDITOR_TABS = [
-        (_("Variables"), "_create_VariablesPanel")]
-    
-    def _create_VariablesPanel(self, prnt):
-        self.VariablesPanel = VariablesEditor(prnt, self.ParentWindow, self.Controler)
-        
-        return self.VariablesPanel
+    CONFNODEEDITOR_TABS = []
+    CODE_EDITOR = None
+    
+    def _create_CodePanel(self, prnt):
+        self.CodeEditorPanel = wx.SplitterWindow(prnt)
+        self.CodeEditorPanel.SetMinimumPaneSize(1)
+        
+        self.VariablesPanel = VariablesEditor(self.CodeEditorPanel, 
+                self.ParentWindow, self.Controler)
+        
+        if self.CODE_EDITOR is not None:
+            self.CodeEditor = self.CODE_EDITOR(self.CodeEditorPanel, 
+                        self.ParentWindow, self.Controler)
+            
+            self.CodeEditorPanel.SplitHorizontally(self.VariablesPanel, 
+                    self.CodeEditor, 150)
+        else:
+            self.CodeEditorPanel.Initialize(self.VariablesPanel)
+        
+        return self.CodeEditorPanel
     
     def __init__(self, parent, controler, window):
         ConfTreeNodeEditor.__init__(self, parent, controler, window)
+        
+        wx.CallAfter(self.CodeEditorPanel.SetSashPosition, 150)
     
     def GetBufferState(self):
         return self.Controler.GetBufferState()
@@ -773,4 +800,8 @@
         ConfTreeNodeEditor.RefreshView(self)
         
         self.VariablesPanel.RefreshView()
-            
\ No newline at end of file
+        self.CodeEditor.RefreshView()
+    
+    def Find(self, direction, search_params):
+        self.CodeEditor.Find(direction, search_params)
+        
\ No newline at end of file
--- a/py_ext/PythonEditor.py	Tue May 14 18:43:52 2013 +0200
+++ b/py_ext/PythonEditor.py	Tue May 14 20:16:07 2013 +0200
@@ -53,18 +53,7 @@
 
 class PythonEditor(CodeFileEditor):
     
-    CONFNODEEDITOR_TABS = CodeFileEditor.CONFNODEEDITOR_TABS + [
-        (_("Python code"), "_create_PythonCodeEditor")]
-    
-    def _create_PythonCodeEditor(self, prnt):
-        self.PythonCodeEditor = PythonCodeEditor(prnt, self.ParentWindow, self.Controler)
-        
-        return self.PythonCodeEditor
+    CONFNODEEDITOR_TABS = [
+        (_("Python code"), "_create_CodePanel")]
+    CODE_EDITOR = PythonCodeEditor
 
-    def RefreshView(self):
-        CodeFileEditor.RefreshView(self)
-        
-        self.PythonCodeEditor.RefreshView()
-
-    def Find(self, direction, search_params):
-        self.PythonCodeEditor.Find(direction, search_params)