Changing ProjectTree contextual menu and EditMenu
authorlbessard
Tue, 29 Jan 2008 18:31:36 +0100
changeset 163 e4949f54c5d6
parent 162 e746ff4aa8be
child 164 0fb64076d3f5
Changing ProjectTree contextual menu and EditMenu
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Tue Jan 29 18:30:47 2008 +0100
+++ b/PLCOpenEditor.py	Tue Jan 29 18:31:36 2008 +0100
@@ -74,9 +74,10 @@
  ID_PLCOPENEDITOREDITMENUITEMS2, ID_PLCOPENEDITOREDITMENUITEMS4, 
  ID_PLCOPENEDITOREDITMENUITEMS5, ID_PLCOPENEDITOREDITMENUITEMS6, 
  ID_PLCOPENEDITOREDITMENUITEMS8, ID_PLCOPENEDITOREDITMENUITEMS9, 
- ID_PLCOPENEDITOREDITMENUITEMS11, ID_PLCOPENEDITOREDITMENUITEMS12, 
- ID_PLCOPENEDITOREDITMENUITEMS14, ID_PLCOPENEDITOREDITMENUITEMS15, 
-] = [wx.NewId() for _init_coll_EditMenu_Items in range(12)]
+ ID_PLCOPENEDITOREDITMENUITEMS10, ID_PLCOPENEDITOREDITMENUITEMS11, 
+ ID_PLCOPENEDITOREDITMENUITEMS12, ID_PLCOPENEDITOREDITMENUITEMS13, 
+ ID_PLCOPENEDITOREDITMENUITEMS14,
+] = [wx.NewId() for _init_coll_EditMenu_Items in range(13)]
 
 [ID_PLCOPENEDITORSFCMENUITEMS0, ID_PLCOPENEDITORSFCMENUITEMS1, 
  ID_PLCOPENEDITORSFCMENUITEMS2, ID_PLCOPENEDITORSFCMENUITEMS3, 
@@ -146,6 +147,8 @@
 class PLCOpenEditor(base_class):
     _custom_classes = {'wx.SashWindow' : ['Viewer']}
     
+    CopyBuffer = None
+    
     if wx.VERSION < (2, 6, 0):
         def Bind(self, event, function, id = None):
             if id is not None:
@@ -168,20 +171,20 @@
         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS6,
               kind=wx.ITEM_NORMAL, text=u'Paste\tCTRL+V')
         parent.AppendSeparator()
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS8,
-              kind=wx.ITEM_NORMAL, text=u'Add Data Type')
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS9,
-              kind=wx.ITEM_NORMAL, text=u'Remove Data Type')
-        parent.AppendSeparator()
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS11,
-              kind=wx.ITEM_NORMAL, text=u'Add POU')
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS12,
-              kind=wx.ITEM_NORMAL, text=u'Remove POU')
-        parent.AppendSeparator()
+        addmenu = wx.Menu(title='')
+        parent.AppendMenu(ID_PLCOPENEDITOREDITMENUITEMS8, "Add Element", addmenu)
+        AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS9,
+              kind=wx.ITEM_NORMAL, text=u'Data Type')
+        AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS10,
+              kind=wx.ITEM_NORMAL, text=u'Function')
+        AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS11,
+              kind=wx.ITEM_NORMAL, text=u'Function Block')
+        AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS12,
+              kind=wx.ITEM_NORMAL, text=u'Program')
+        AppendMenu(addmenu, help='', id=ID_PLCOPENEDITOREDITMENUITEMS13,
+              kind=wx.ITEM_NORMAL, text=u'Configuration')
         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS14,
-              kind=wx.ITEM_NORMAL, text=u'Add Configuration')
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS15,
-              kind=wx.ITEM_NORMAL, text=u'Remove Configuration')
+              kind=wx.ITEM_NORMAL, text=u'Delete')
         self.Bind(wx.EVT_MENU, self.OnRefreshMenu,
               id=ID_PLCOPENEDITOREDITMENUITEMS0)
         self.Bind(wx.EVT_MENU, self.OnUndoMenu,
@@ -195,17 +198,17 @@
         self.Bind(wx.EVT_MENU, self.OnPasteMenu,
               id=ID_PLCOPENEDITOREDITMENUITEMS6)
         self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu,
-              id=ID_PLCOPENEDITOREDITMENUITEMS8)
-        self.Bind(wx.EVT_MENU, self.OnRemoveDataTypeMenu,
               id=ID_PLCOPENEDITOREDITMENUITEMS9)
-        self.Bind(wx.EVT_MENU, self.OnAddPouMenu,
+        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("function"),
+              id=ID_PLCOPENEDITOREDITMENUITEMS10)
+        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("functionBlock"),
               id=ID_PLCOPENEDITOREDITMENUITEMS11)
-        self.Bind(wx.EVT_MENU, self.OnRemovePouMenu,
+        self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction("program"),
               id=ID_PLCOPENEDITOREDITMENUITEMS12)
         self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu,
+              id=ID_PLCOPENEDITOREDITMENUITEMS13)
+        self.Bind(wx.EVT_MENU, self.OnDeleteMenu,
               id=ID_PLCOPENEDITOREDITMENUITEMS14)
-        self.Bind(wx.EVT_MENU, self.OnRemoveConfigurationMenu,
-              id=ID_PLCOPENEDITOREDITMENUITEMS15)
 
     def _init_coll_menuBar1_Menus(self, parent):
         if self.ModeSolo:
@@ -213,16 +216,6 @@
         parent.Append(menu=self.EditMenu, title=u'Edit')
         parent.Append(menu=self.HelpMenu, title=u'Help')
 
-    def _init_coll_ConfigMenu_Items(self, parent):
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS0,
-              kind=wx.ITEM_NORMAL, text=u'Add Resource')
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS1,
-              kind=wx.ITEM_NORMAL, text=u'Remove Resource')
-        self.Bind(wx.EVT_MENU, self.OnAddResourceMenu,
-              id=ID_PLCOPENEDITORCONFIGMENUITEMS0)
-        self.Bind(wx.EVT_MENU, self.OnRemoveResourceMenu,
-              id=ID_PLCOPENEDITORCONFIGMENUITEMS1)
-
     def _init_coll_HelpMenu_Items(self, parent):
         AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS0, 
             kind=wx.ITEM_NORMAL, text=u'PLCOpenEditor\tF1')
@@ -277,24 +270,6 @@
         self.Bind(wx.EVT_MENU, self.OnQuitMenu,
               id=ID_PLCOPENEDITORFILEMENUITEMS11)
 
-    def _init_coll_SFCMenu_Items(self, parent):
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS0,
-              kind=wx.ITEM_NORMAL, text=u'Add Transition')
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS1,
-              kind=wx.ITEM_NORMAL, text=u'Add Action')
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS2,
-              kind=wx.ITEM_NORMAL, text=u'Remove Transition')
-        AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS3,
-              kind=wx.ITEM_NORMAL, text=u'Remove Action')
-        self.Bind(wx.EVT_MENU, self.OnAddPouTransitionMenu,
-              id=ID_PLCOPENEDITORSFCMENUITEMS0)
-        self.Bind(wx.EVT_MENU, self.OnAddPouActionMenu,
-              id=ID_PLCOPENEDITORSFCMENUITEMS1)
-        self.Bind(wx.EVT_MENU, self.OnRemovePouTransitionMenu,
-              id=ID_PLCOPENEDITORSFCMENUITEMS2)
-        self.Bind(wx.EVT_MENU, self.OnRemovePouActionMenu,
-              id=ID_PLCOPENEDITORSFCMENUITEMS3)
-
     def _init_utils(self):
         self.menuBar1 = wx.MenuBar()
 
@@ -304,17 +279,13 @@
             self.FileMenu = None
         self.EditMenu = wx.Menu(title='')
         self.HelpMenu = wx.Menu(title='')
-        self.SFCMenu = wx.Menu(title='')
-        self.ConfigMenu = wx.Menu(title='')
-
+        
         self._init_coll_menuBar1_Menus(self.menuBar1)
         if self.ModeSolo:
             self._init_coll_FileMenu_Items(self.FileMenu)
         self._init_coll_EditMenu_Items(self.EditMenu)
         self._init_coll_HelpMenu_Items(self.HelpMenu)
-        self._init_coll_SFCMenu_Items(self.SFCMenu)
-        self._init_coll_ConfigMenu_Items(self.ConfigMenu)
-
+        
     def _init_ctrls(self, prnt):
         if wx.VERSION >= (2, 8, 0):
             wx.aui.AuiMDIParentFrame.__init__(self, winid=ID_PLCOPENEDITOR, name=u'PLCOpenEditor', 
@@ -451,7 +422,6 @@
         self.CurrentToolBar = []
         self.CurrentLanguage = ""
         self.SelectedItem = None
-        self.CopyBuffer = None
         self.DrawingMode = FREEDRAWING_MODE
         #self.DrawingMode = DRIVENDRAWING_MODE
         
@@ -466,79 +436,6 @@
     def ResetSelectedItem(self):
         self.SelectedItem = None
 
-    def GetPageCount(self):
-        if wx.VERSION >= (2, 8, 0):
-            notebook = self.GetNotebook()
-            if notebook is not None:
-                return notebook.GetPageCount()
-            else:
-                return 0
-        else:
-            return self.TabsOpened.GetPageCount()
-    
-    def GetPage(self, idx):
-        if wx.VERSION >= (2, 8, 0):
-            notebook = self.GetNotebook()
-            if notebook is not None:
-                return notebook.GetPage(idx).GetViewer()
-            else:
-                return None
-        else:
-            return self.TabsOpened.GetPage(idx)
-
-    def GetPageSelection(self):
-        if wx.VERSION >= (2, 8, 0):
-            notebook = self.GetNotebook()
-            if notebook is not None:
-                return notebook.GetSelection()
-            else:
-                return -1
-        else:
-            return self.TabsOpened.GetSelection()
-
-    def SetPageSelection(self, idx):
-        if wx.VERSION >= (2, 8, 0):
-            notebook = self.GetNotebook()
-            if notebook is not None:
-                notebook.SetSelection(idx)
-        else:
-            self.TabsOpened.SetSelection(idx)
-
-    def DeletePage(self, idx):
-        if wx.VERSION >= (2, 8, 0):
-            notebook = self.GetNotebook()
-            if notebook is not None:
-                notebook.DeletePage(idx)
-        else:
-            self.TabsOpened.DeletePage(idx)
-
-    def DeleteAllPages(self):
-        if wx.VERSION >= (2, 8, 0):
-            notebook = self.GetNotebook()
-            if notebook is not None:
-                for idx in xrange(notebook.GetPageCount()):
-                    notebook.DeletePage(0)
-        else:
-            self.TabsOpened.DeleteAllPages()
-
-    def SetPageText(self, idx, text):
-        if wx.VERSION >= (2, 8, 0):
-            notebook = self.GetNotebook()
-            if notebook is not None:
-                return notebook.SetPageText(idx, text)
-        else:
-            return self.TabsOpened.SetPageText(idx, text)
-
-    def GetPageText(self, idx):
-        if wx.VERSION >= (2, 8, 0):
-            notebook = self.GetNotebook()
-            if notebook is not None:
-                return notebook.GetPageText(idx)
-            else:
-                return ""
-        else:
-            return self.TabsOpened.GetPageText(idx)
-
     def OnPageClose(self, event):
         selected = self.GetPageSelection()
         if selected >= 0:
@@ -556,10 +453,10 @@
         event.Skip()
 
     def GetCopyBuffer(self):
-        return self.CopyBuffer
+        return PLCOpenEditor.CopyBuffer
     
     def SetCopyBuffer(self, element):
-        self.CopyBuffer = element
+        PLCOpenEditor.CopyBuffer = element
         self.RefreshEditMenu()
 
     def GetDrawingMode(self):
@@ -571,72 +468,6 @@
         else:
             self.SetTitle("PLCOpenEditor")
 
-    def RefreshFileMenu(self):
-        if self.FileMenu:
-            if self.Controler.HasOpenedProject():
-                if self.GetPageCount() > 0:
-                    self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, True)
-                else:
-                    self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, True)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, True)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, True)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, True)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, True)
-            else:
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, False)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, False)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, False)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, False)
-                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, False)
-
-    def RefreshEditMenu(self):
-        if self.EditMenu:
-            if self.Controler.HasOpenedProject():
-                undo, redo = self.Controler.GetBufferState()
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, undo)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, redo)
-            else:
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, False)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, False)
-            if self.Controler.HasOpenedProject():
-                if self.GetPageCount() > 0:
-                    self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, True)
-                else:
-                    self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, True)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS9, True)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS11, True)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS12, True)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS14, True)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS15, True)
-            else:
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, False)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS9, False)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS11, False)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS12, False)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS14, False)
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS15, False)
-            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS4, True)
-            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS5, True)
-            if self.CopyBuffer is not None:
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, True)
-            else:
-                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, False)
-
-    def RefreshEditor(self, variablepanel = True):
-        selected = self.GetPageSelection()
-        if selected != -1:
-            window = self.GetPage(selected)
-            window.RefreshView()
-            if variablepanel:
-                self.RefreshVariablePanel(window.GetTagName())
-
-    def RefreshVariablePanel(self, tagname):
-        self.VariablePanelIndexer.RefreshVariablePanel(tagname)
-
     def ShowProperties(self):
         old_values = self.Controler.GetProjectProperties()
         dialog = ProjectDialog(self)
@@ -677,6 +508,108 @@
         else:
             event.Skip()
 
+#-------------------------------------------------------------------------------
+#                            Notebook Unified Functions
+#-------------------------------------------------------------------------------
+
+    def GetPageCount(self):
+        if wx.VERSION >= (2, 8, 0):
+            notebook = self.GetNotebook()
+            if notebook is not None:
+                return notebook.GetPageCount()
+            else:
+                return 0
+        else:
+            return self.TabsOpened.GetPageCount()
+    
+    def GetPage(self, idx):
+        if wx.VERSION >= (2, 8, 0):
+            notebook = self.GetNotebook()
+            if notebook is not None:
+                return notebook.GetPage(idx).GetViewer()
+            else:
+                return None
+        else:
+            return self.TabsOpened.GetPage(idx)
+
+    def GetPageSelection(self):
+        if wx.VERSION >= (2, 8, 0):
+            notebook = self.GetNotebook()
+            if notebook is not None:
+                return notebook.GetSelection()
+            else:
+                return -1
+        else:
+            return self.TabsOpened.GetSelection()
+
+    def SetPageSelection(self, idx):
+        if wx.VERSION >= (2, 8, 0):
+            notebook = self.GetNotebook()
+            if notebook is not None:
+                notebook.SetSelection(idx)
+        else:
+            self.TabsOpened.SetSelection(idx)
+
+    def DeletePage(self, idx):
+        if wx.VERSION >= (2, 8, 0):
+            notebook = self.GetNotebook()
+            if notebook is not None:
+                notebook.DeletePage(idx)
+        else:
+            self.TabsOpened.DeletePage(idx)
+
+    def DeleteAllPages(self):
+        if wx.VERSION >= (2, 8, 0):
+            notebook = self.GetNotebook()
+            if notebook is not None:
+                for idx in xrange(notebook.GetPageCount()):
+                    notebook.DeletePage(0)
+        else:
+            self.TabsOpened.DeleteAllPages()
+
+    def SetPageText(self, idx, text):
+        if wx.VERSION >= (2, 8, 0):
+            notebook = self.GetNotebook()
+            if notebook is not None:
+                return notebook.SetPageText(idx, text)
+        else:
+            return self.TabsOpened.SetPageText(idx, text)
+
+    def GetPageText(self, idx):
+        if wx.VERSION >= (2, 8, 0):
+            notebook = self.GetNotebook()
+            if notebook is not None:
+                return notebook.GetPageText(idx)
+            else:
+                return ""
+        else:
+            return self.TabsOpened.GetPageText(idx)
+
+
+#-------------------------------------------------------------------------------
+#                            File Menu Functions
+#-------------------------------------------------------------------------------
+
+    def RefreshFileMenu(self):
+        if self.FileMenu:
+            if self.Controler.HasOpenedProject():
+                if self.GetPageCount() > 0:
+                    self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, True)
+                else:
+                    self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, True)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, True)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, True)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, True)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, True)
+            else:
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, False)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, False)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, False)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, False)
+                self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, False)
+
     def OnNewProjectMenu(self, event):
         dialog = ProjectDialog(self)
         if dialog.ShowModal() == wx.ID_OK:
@@ -822,154 +755,184 @@
         self.Close()
         event.Skip()
 
-    def ResetCurrentMode(self):
+
+#-------------------------------------------------------------------------------
+#                          Edit Project Menu Functions
+#-------------------------------------------------------------------------------
+
+    def RefreshEditMenu(self):
+        if self.EditMenu:
+            if self.Controler.HasOpenedProject():
+                undo, redo = self.Controler.GetBufferState()
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, undo)
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, redo)
+            else:
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, False)
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, False)
+            if self.Controler.HasOpenedProject():
+                if self.GetPageCount() > 0:
+                    self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, True)
+                else:
+                    self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False)
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, True)
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS14, True)
+            else:
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False)
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, False)
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS14, False)
+            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS4, True)
+            self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS5, True)
+            if self.CopyBuffer is not None:
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, True)
+            else:
+                self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, False)
+
+    def OnRefreshMenu(self, event):
         selected = self.GetPageSelection()
         if selected != -1:
             window = self.GetPage(selected)
-            window.SetMode(MODE_SELECTION)
-        if wx.VERSION < (2, 8, 0):
-            ToolBar = self.ToolBar
-        else:
-            ToolBar = self.Panes["ToolBar"]
-        if ToolBar:
-            ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True)
-        
-    def ResetToolToggle(self, id):
-        if wx.VERSION < (2, 8, 0):
-            tool = self.ToolBar.FindById(id)
-        else:
-            tool = self.Panes["ToolBar"].FindById(id)
-        tool.SetToggle(False)
-
-    def OnSelectionTool(self, event):
+            window.RefreshView()
+            self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName())
+        event.Skip()
+
+    def OnUndoMenu(self, event):
+        self.Controler.LoadPrevious()
+        idxs = range(self.GetPageCount())
+        idxs.reverse()
+        for idx in idxs:
+            tagname = self.GetPage(idx).GetTagName()
+            if self.Controler.GetEditedElement(tagname) is None:
+                self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+                self.DeletePage(idx)
+        selected = self.GetPageSelection()        
+        if selected != -1:
+            window = self.GetPage(selected)
+            window.RefreshView()
+            self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName())
+        self.RefreshTitle()
+        self.RefreshEditMenu()
+        self.RefreshProjectTree()
+        event.Skip()
+    
+    def OnRedoMenu(self, event):
+        self.Controler.LoadNext()
+        idxs = range(self.GetPageCount())
+        idxs.reverse()
+        for idx in idxs:
+            tagname = self.GetPage(idx).GetTagName()
+            if self.Controler.GetEditedElement(tagname) is None:
+                self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+                self.DeletePage(idx)
         selected = self.GetPageSelection()
         if selected != -1:
-            self.GetPage(selected).SetMode(MODE_SELECTION)
-        event.Skip()
-    
-    def OnCommentTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOMMENT)
+            window = self.GetPage(selected)
+            window.RefreshView()
+            self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName())
+        self.RefreshTitle()
+        self.RefreshEditMenu()
+        self.RefreshProjectTree()
+        event.Skip()
+
+    def OnCutMenu(self, event):
         selected = self.GetPageSelection()
         if selected != -1:
-            self.GetPage(selected).SetMode(MODE_COMMENT)
-        event.Skip()
-    
-    def OnVariableTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARVARIABLE)
+            try:
+                self.GetPage(selected).Cut()
+            except:
+                pass
+        event.Skip()
+    
+    def OnCopyMenu(self, event):
         selected = self.GetPageSelection()
         if selected != -1:
-            self.GetPage(selected).SetMode(MODE_VARIABLE)
-        event.Skip()
-    
-    def OnBlockTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARBLOCK)
+            try:
+                self.GetPage(selected).Copy()
+            except:
+                pass
+        event.Skip()
+    
+    def OnPasteMenu(self, event):
         selected = self.GetPageSelection()
         if selected != -1:
-            self.GetPage(selected).SetMode(MODE_BLOCK)
-        event.Skip()
-        
-    def OnConnectionTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONNECTION)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            self.GetPage(selected).SetMode(MODE_CONNECTION)
-        event.Skip()
-
-    def OnPowerRailTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARPOWERRAIL)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            self.GetPage(selected).SetMode(MODE_POWERRAIL)
-        event.Skip()
-
-    def OnRungTool(self, event):
-        selected = self.GetPageSelection()
-        if selected != -1:
-            self.GetPage(selected).AddLadderRung()
-        event.Skip()
-    
-    def OnCoilTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOIL)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            self.GetPage(selected).SetMode(MODE_COIL)
-        event.Skip()
-    
-    def OnContactTool(self, event):
-        if self.DrawingMode == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONTACT)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            if self.DrawingMode == FREEDRAWING_MODE:
-                self.GetPage(selected).SetMode(MODE_CONTACT)
-            else:
-                self.GetPage(selected).AddLadderContact()
-        event.Skip()
-    
-    def OnBranchTool(self, event): 
-        selected = self.GetPageSelection()
-        if selected != -1:
-            self.GetPage(selected).AddLadderBranch()
-        event.Skip()    
-    
-    def OnInitialStepTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARINITIALSTEP)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            self.GetPage(selected).SetMode(MODE_INITIALSTEP)
-        event.Skip()
-    
-    def OnStepTool(self, event):
-        if self.GetDrawingMode() == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARSTEP)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            if self.GetDrawingMode() == FREEDRAWING_MODE:
-                self.GetPage(selected).SetMode(MODE_STEP)
-            else:
-                self.GetPage(selected).AddStep()
-        event.Skip()
-
-    def OnActionBlockTool(self, event):
-        if self.GetDrawingMode() == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARACTIONBLOCK)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            if self.GetDrawingMode() == FREEDRAWING_MODE:
-                self.GetPage(selected).SetMode(MODE_ACTION)
-            else:
-                self.GetPage(selected).AddStepAction()
-        event.Skip()
-
-    def OnTransitionTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARTRANSITION)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            self.GetPage(selected).SetMode(MODE_TRANSITION)
-        event.Skip()
-
-    def OnDivergenceTool(self, event):
-        if self.GetDrawingMode() == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARDIVERGENCE)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            if self.GetDrawingMode() == FREEDRAWING_MODE:
-                self.GetPage(selected).SetMode(MODE_DIVERGENCE)
-            else:
-                self.GetPage(selected).AddDivergence()
-        event.Skip()
-    
-    def OnJumpTool(self, event):
-        if self.GetDrawingMode() == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARJUMP)
-        selected = self.GetPageSelection()
-        if selected != -1:
-            if self.GetDrawingMode() == FREEDRAWING_MODE:
-                self.GetPage(selected).SetMode(MODE_JUMP)
-            else:
-                self.GetPage(selected).AddJump()
-        event.Skip()
-        
+            try:
+                self.GetPage(selected).Paste()
+            except:
+                pass
+        event.Skip()
+    
+    def OnDeleteMenu(self, event):
+        window = self.FindFocus()
+        if window == self.ProjectTree:
+            selected = self.ProjectTree.GetSelection()
+            if selected.IsOk():
+                type = self.ProjectTree.GetPyData(selected)
+                tagname = ""
+                if type == ITEM_DATATYPE:
+                    name = self.ProjectTree.GetItemText(selected)
+                    if not self.Controler.DataTypeIsUsed(name):
+                        self.Controler.ProjectRemoveDataType(name)
+                        tagname = self.Controler.ComputeDataTypeName(name)
+                    else:
+                        message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
+                        message.ShowModal()
+                        message.Destroy()
+                elif type == ITEM_POU:
+                    name = self.ProjectTree.GetItemText(selected)
+                    if not self.Controler.DataTypeIsUsed(name):
+                        self.Controler.ProjectRemoveDataType(name)
+                        tagname = self.Controler.ComputeDataTypeName(name)
+                    else:
+                        message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
+                        message.ShowModal()
+                        message.Destroy()
+                elif type in [ITEM_TRANSITION, ITEM_ACTION]:
+                    item = self.ProjectTree.GetItemParent(selected)
+                    item_type = self.ProjectTree.GetPyData(item)
+                    while item_type != ITEM_POU:
+                        item = self.ProjectTree.GetItemParent(item)
+                        item_type = self.ProjectTree.GetPyData(item)
+                    pou_name = self.ProjectTree.GetItemText(item)
+                    if type == ITEM_TRANSITION:
+                        transition = self.ProjectTree.GetItemText(selected)
+                        self.Controler.ProjectRemovePouTransition(pou_name, transition)
+                        tagname = self.Controler.ComputePouTransitionName(pou_name, transition)
+                    elif type == ITEM_ACTION:
+                        action = self.ProjectTree.GetItemText(selected)
+                        self.Controler.ProjectRemovePouAction(pou_name, action)
+                        tagname = self.Controler.ComputePouActionName(pou_name, action)
+                elif type == ITEM_CONFIGURATION:
+                    name = self.ProjectTree.GetItemText(selected)
+                    self.Controler.ProjectRemoveConfiguration(name)
+                    tagname = self.Controler.ComputeConfigurationName(name)
+                elif type == ITEM_RESOURCE:
+                    resource = self.ProjectTree.GetItemText(selected)
+                    item = self.ProjectTree.GetItemParent(selected)
+                    item_type = self.ProjectTree.GetPyData(item)
+                    while item_type != ITEM_CONFIGURATION:
+                        item = self.ProjectTree.GetItemParent(item)
+                        item_type = self.ProjectTree.GetPyData(item)
+                    config_name = self.ProjectTree.GetItemText(item)
+                    self.Controler.ProjectRemoveConfigurationResource(config_name, resource)
+                    tagname = self.Controler.ComputeConfigurationResourceName(config_name, selected)
+                idx = self.IsOpened(tagname)
+                if idx is not None:
+                    self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+                    self.DeletePage(idx)
+                self.RefreshTitle()
+                self.RefreshEditMenu()
+                self.RefreshProjectTree()
+                self.RefreshToolBar()
+        elif isinstance(window, (Viewer, TextViewer)):
+            event = wx.KeyEvent(wx.EVT_CHAR._getEvtType())
+            event.m_keyCode = wx.WXK_DELETE
+            window.ProcessEvent(event)
+        event.Skip()
+
+
+#-------------------------------------------------------------------------------
+#                      Project Editor Panels Management Functions
+#-------------------------------------------------------------------------------
+    
     def OnPouSelectedChanged(self, event):
         if wx.VERSION < (2, 8, 0) or event.GetActive():
             old_selected = self.GetPageSelection()
@@ -1004,6 +967,72 @@
                 self.RefreshToolBar()
         event.Skip()
 
+    def RefreshEditor(self, variablepanel = True):
+        selected = self.GetPageSelection()
+        if selected != -1:
+            window = self.GetPage(selected)
+            window.RefreshView()
+            if variablepanel:
+                self.RefreshVariablePanel(window.GetTagName())
+
+    def RefreshVariablePanel(self, tagname):
+        self.VariablePanelIndexer.RefreshVariablePanel(tagname)
+
+    def RefreshEditorNames(self, old_tagname, new_tagname):
+        for i in xrange(self.GetPageCount()):
+            editor = self.GetPage(i)
+            if editor.GetTagName() == old_tagname:
+                editor.SetTagName(new_tagname)
+        self.VariablePanelIndexer.UpdateVariablePanelTagName(old_tagname, new_tagname)
+
+    def IsOpened(self, tagname):
+        for idx in xrange(self.GetPageCount()):
+            if self.GetPage(idx).IsViewing(tagname):
+                return idx
+        return None
+
+    def RefreshPageTitles(self):
+        for idx in xrange(self.GetPageCount()):
+            window = self.GetPage(idx)
+            words = window.GetTagName().split("::")
+            self.SetPageText(idx, "-".join(words[1:]))
+
+
+#-------------------------------------------------------------------------------
+#                         Project Tree Management Functions
+#-------------------------------------------------------------------------------
+
+    def RefreshProjectTree(self):
+        infos = self.Controler.GetProjectInfos()
+        root = self.ProjectTree.GetRootItem()
+        if not root.IsOk():
+            root = self.ProjectTree.AddRoot(infos["name"])
+        self.GenerateTreeBranch(root, infos)
+        self.ProjectTree.Expand(self.ProjectTree.GetRootItem())
+
+    def GenerateTreeBranch(self, root, infos):
+        to_delete = []
+        self.ProjectTree.SetItemText(root, infos["name"])
+        self.ProjectTree.SetPyData(root, infos["type"])
+        if infos["type"] == ITEM_POU and wx.Platform != '__WXMSW__':
+            self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"])))
+        if wx.VERSION >= (2, 6, 0):
+            item, root_cookie = self.ProjectTree.GetFirstChild(root)
+        else:
+            item, root_cookie = self.ProjectTree.GetFirstChild(root, 0)
+        for values in infos["values"]:
+            if not item.IsOk():
+                item = self.ProjectTree.AppendItem(root, "")
+                if wx.Platform != '__WXMSW__':
+                    item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
+            self.GenerateTreeBranch(item, values)
+            item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
+        while item.IsOk():
+            to_delete.append(item)
+            item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
+        for item in to_delete:
+            self.ProjectTree.Delete(item)
+
     def SelectProjectTreeItem(self, root, items):
         found = False
         if self.ProjectTree:
@@ -1038,12 +1067,12 @@
                 dragSource.DoDragDrop()
             self.ResetSelectedItem()
 
-    def RefreshEditorNames(self, old_tagname, new_tagname):
-        for i in xrange(self.GetPageCount()):
-            editor = self.GetPage(i)
-            if editor.GetTagName() == old_tagname:
-                editor.SetTagName(new_tagname)
-        self.VariablePanelIndexer.UpdateVariablePanelTagName(old_tagname, new_tagname)
+    def OnProjectTreeItemBeginEdit(self, event):
+        selected = event.GetItem()
+        if self.ProjectTree.GetPyData(selected) == ITEM_UNEDITABLE:
+            event.Veto()
+        else:
+            event.Skip()
 
     def OnProjectTreeItemEndEdit(self, event):
         message = None
@@ -1173,13 +1202,6 @@
                 if selected != -1:
                     self.GetPage(selected).RefreshView()
                 event.Skip()
-
-    def OnProjectTreeItemBeginEdit(self, event):
-        selected = event.GetItem()
-        if self.ProjectTree.GetPyData(selected) == ITEM_UNEDITABLE:
-            event.Veto()
-        else:
-            event.Skip()
     
     def OnProjectTreeItemActivated(self, event):
         selected = event.GetItem()
@@ -1267,12 +1289,6 @@
         else:
             event.Skip()
     
-    def IsOpened(self, tagname):
-        for idx in xrange(self.GetPageCount()):
-            if self.GetPage(idx).IsViewing(tagname):
-                return idx
-        return None
-    
     def EditProjectElement(self, elementtype, tagname, onlyopened = False):
         openedidx = self.IsOpened(tagname)
         if openedidx is not None:
@@ -1372,49 +1388,106 @@
     
     def OnProjectTreeRightUp(self, event):
         if wx.Platform == '__WXMSW__':
-            cursor_pos = event.GetPoint()
-        else:
-            cursor_pos = event.GetPosition()
-        selected = self.ProjectTree.GetSelection()
-        if self.ProjectTree.GetPyData(selected) == ITEM_POU:
-            name = self.ProjectTree.GetItemText(selected)
+            item = event.GetItem()
+        else:
+            item = self.ProjectTree.GetSelection()
+        name = self.ProjectTree.GetItemText(item)
+        type = self.ProjectTree.GetPyData(item)
+        if type == ITEM_POU:
+            menu = wx.Menu(title='')
             if self.Controler.GetPouBodyType(name) == "SFC":
-                self.PopupMenuXY(self.SFCMenu, cursor_pos.x, cursor_pos.y)
-        elif self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION:
-            self.PopupMenu(self.ConfigMenu)
-        event.Skip()
-
-    def RefreshProjectTree(self):
-        infos = self.Controler.GetProjectInfos()
-        root = self.ProjectTree.GetRootItem()
-        if not root.IsOk():
-            root = self.ProjectTree.AddRoot(infos["name"])
-        self.GenerateTreeBranch(root, infos)
-        self.ProjectTree.Expand(self.ProjectTree.GetRootItem())
-
-    def GenerateTreeBranch(self, root, infos):
-        to_delete = []
-        self.ProjectTree.SetItemText(root, infos["name"])
-        self.ProjectTree.SetPyData(root, infos["type"])
-        if infos["type"] == ITEM_POU and wx.Platform != '__WXMSW__':
-            self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"])))
-        if wx.VERSION >= (2, 5, 0):
-            item, root_cookie = self.ProjectTree.GetFirstChild(root)
-        else:
-            item, root_cookie = self.ProjectTree.GetFirstChild(root, 0)
-        for values in infos["values"]:
-            if not item.IsOk():
-                item = self.ProjectTree.AppendItem(root, "")
-                if wx.Platform != '__WXMSW__':
-                    item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
-            self.GenerateTreeBranch(item, values)
-            item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
-        while item.IsOk():
-            to_delete.append(item)
-            item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie)
-        for item in to_delete:
-            self.ProjectTree.Delete(item)
-    
+                new_id = wx.NewId()
+                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Transition")
+                self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(name), id=new_id)
+                new_id = wx.NewId()
+                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Action")
+                self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(name), id=new_id)
+                menu.AppendSeparator()
+            new_id = wx.NewId()
+            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Delete")
+            self.Bind(wx.EVT_MENU, self.OnRemovePouMenu, id=new_id)
+            self.PopupMenu(menu)
+        elif type == ITEM_CONFIGURATION:
+            menu = wx.Menu(title='')
+            new_id = wx.NewId()
+            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Resource")
+            self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(name), id=new_id)
+            new_id = wx.NewId()
+            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Delete")
+            self.Bind(wx.EVT_MENU, self.OnRemoveConfigurationMenu, id=new_id)
+            self.PopupMenu(menu)
+        elif type in [ITEM_DATATYPE, ITEM_TRANSITION, ITEM_ACTION, ITEM_RESOURCE]:
+            menu = wx.Menu(title='')
+            new_id = wx.NewId()
+            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Delete")
+            if type == ITEM_DATATYPE:
+                self.Bind(wx.EVT_MENU, self.OnRemoveDataTypeMenu, id=new_id)
+            elif type == ITEM_TRANSITION:
+                self.Bind(wx.EVT_MENU, self.OnRemoveTransitionMenu, id=new_id)
+            elif type == ITEM_ACTION:
+                self.Bind(wx.EVT_MENU, self.OnRemoveActionMenu, id=new_id)
+            elif type == ITEM_RESOURCE:
+                self.Bind(wx.EVT_MENU, self.OnRemoveResourceMenu, id=new_id)
+            self.PopupMenu(menu)
+        elif type == ITEM_UNEDITABLE:
+            if name == "Data Types":
+                menu = wx.Menu(title='')
+                new_id = wx.NewId()
+                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add DataType")
+                self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, id=new_id)
+                self.PopupMenu(menu)
+            elif name in ["Functions", "Function Blocks", "Programs"]:
+                menu = wx.Menu(title='')
+                new_id = wx.NewId()
+                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Pou")
+                self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction({"Functions" : "function", "Function Blocks" : "functionBlock", "Programs" : "program"}[name]), id=new_id)
+                self.PopupMenu(menu)
+            elif name == "Configurations":
+                menu = wx.Menu(title='')
+                new_id = wx.NewId()
+                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Configuration")
+                self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, id=new_id)
+                self.PopupMenu(menu)
+            elif name == "Transitions":
+                menu = wx.Menu(title='')
+                new_id = wx.NewId()
+                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Transition")
+                parent = self.ProjectTree.GetItemParent(item)
+                parent_type = self.ProjectTree.GetPyData(parent)
+                while parent_type != ITEM_POU:
+                    parent = self.ProjectTree.GetItemParent(parent)
+                    parent_type = self.ProjectTree.GetPyData(parent)
+                self.Bind(wx.EVT_MENU, self.GenerateAddTransitionFunction(self.ProjectTree.GetItemText(parent)), id=new_id)
+                self.PopupMenu(menu)
+            elif name == "Actions":
+                menu = wx.Menu(title='')
+                new_id = wx.NewId()
+                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Action")
+                parent = self.ProjectTree.GetItemParent(item)
+                parent_type = self.ProjectTree.GetPyData(parent)
+                while parent_type != ITEM_POU:
+                    parent = self.ProjectTree.GetItemParent(parent)
+                    parent_type = self.ProjectTree.GetPyData(parent)
+                self.Bind(wx.EVT_MENU, self.GenerateAddActionFunction(self.ProjectTree.GetItemText(parent)), id=new_id)
+                self.PopupMenu(menu)
+            elif name == "Resources":
+                menu = wx.Menu(title='')
+                new_id = wx.NewId()
+                AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Add Resource")
+                parent = self.ProjectTree.GetItemParent(item)
+                parent_type = self.ProjectTree.GetPyData(parent)
+                while parent_type != ITEM_CONFIGURATION:
+                    parent = self.ProjectTree.GetItemParent(parent)
+                    parent_type = self.ProjectTree.GetPyData(parent)
+                self.Bind(wx.EVT_MENU, self.GenerateAddResourceFunction(self.ProjectTree.GetItemText(parent)), id=new_id)
+                self.PopupMenu(menu)
+        event.Skip()
+
+
+#-------------------------------------------------------------------------------
+#                          ToolBar Management Functions
+#-------------------------------------------------------------------------------
+
     def ResetToolBar(self):
         for item in self.CurrentToolBar:
             if wx.VERSION >= (2, 6, 0):
@@ -1465,71 +1538,164 @@
             self.CurrentLanguage = language
         self.ResetCurrentMode()
 
-    def RefreshPageTitles(self):
-        for idx in xrange(self.GetPageCount()):
-            window = self.GetPage(idx)
-            words = window.GetTagName().split("::")
-            self.SetPageText(idx, "-".join(words[1:]))
-    
-    def OnRefreshMenu(self, event):
+
+#-------------------------------------------------------------------------------
+#                           Tool Bar Items Functions
+#-------------------------------------------------------------------------------
+
+    def ResetCurrentMode(self):
         selected = self.GetPageSelection()
         if selected != -1:
             window = self.GetPage(selected)
-            window.RefreshView()
-            self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName())
-        event.Skip()
-
-    def OnUndoMenu(self, event):
-        self.Controler.LoadPrevious()
+            window.SetMode(MODE_SELECTION)
+        if wx.VERSION < (2, 8, 0):
+            ToolBar = self.ToolBar
+        else:
+            ToolBar = self.Panes["ToolBar"]
+        if ToolBar:
+            ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True)
+        
+    def ResetToolToggle(self, id):
+        if wx.VERSION < (2, 8, 0):
+            tool = self.ToolBar.FindById(id)
+        else:
+            tool = self.Panes["ToolBar"].FindById(id)
+        tool.SetToggle(False)
+
+    def OnSelectionTool(self, event):
         selected = self.GetPageSelection()
         if selected != -1:
-            window = self.GetPage(selected)
-            window.RefreshView()
-            self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName())
-        self.RefreshTitle()
-        self.RefreshEditMenu()
-        self.RefreshProjectTree()
-        event.Skip()
-    
-    def OnRedoMenu(self, event):
-        self.Controler.LoadNext()
+            self.GetPage(selected).SetMode(MODE_SELECTION)
+        event.Skip()
+    
+    def OnCommentTool(self, event):
+        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOMMENT)
         selected = self.GetPageSelection()
         if selected != -1:
-            window = self.GetPage(selected)
-            window.RefreshView()
-            self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName())
-        self.RefreshTitle()
-        self.RefreshEditMenu()
-        self.RefreshProjectTree()
-        event.Skip()
-
-    def OnCutMenu(self, event):
+            self.GetPage(selected).SetMode(MODE_COMMENT)
+        event.Skip()
+    
+    def OnVariableTool(self, event):
+        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARVARIABLE)
         selected = self.GetPageSelection()
         if selected != -1:
-            try:
-                self.GetPage(selected).Cut()
-            except:
-                pass
-        event.Skip()
-    
-    def OnCopyMenu(self, event):
+            self.GetPage(selected).SetMode(MODE_VARIABLE)
+        event.Skip()
+    
+    def OnBlockTool(self, event):
+        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARBLOCK)
         selected = self.GetPageSelection()
         if selected != -1:
-            try:
-                self.GetPage(selected).Copy()
-            except:
-                pass
-        event.Skip()
-    
-    def OnPasteMenu(self, event):
+            self.GetPage(selected).SetMode(MODE_BLOCK)
+        event.Skip()
+        
+    def OnConnectionTool(self, event):
+        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONNECTION)
         selected = self.GetPageSelection()
         if selected != -1:
-            try:
-                self.GetPage(selected).Paste()
-            except:
-                pass
-        event.Skip()
-    
+            self.GetPage(selected).SetMode(MODE_CONNECTION)
+        event.Skip()
+
+    def OnPowerRailTool(self, event):
+        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARPOWERRAIL)
+        selected = self.GetPageSelection()
+        if selected != -1:
+            self.GetPage(selected).SetMode(MODE_POWERRAIL)
+        event.Skip()
+
+    def OnRungTool(self, event):
+        selected = self.GetPageSelection()
+        if selected != -1:
+            self.GetPage(selected).AddLadderRung()
+        event.Skip()
+    
+    def OnCoilTool(self, event):
+        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOIL)
+        selected = self.GetPageSelection()
+        if selected != -1:
+            self.GetPage(selected).SetMode(MODE_COIL)
+        event.Skip()
+    
+    def OnContactTool(self, event):
+        if self.DrawingMode == FREEDRAWING_MODE:
+            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONTACT)
+        selected = self.GetPageSelection()
+        if selected != -1:
+            if self.DrawingMode == FREEDRAWING_MODE:
+                self.GetPage(selected).SetMode(MODE_CONTACT)
+            else:
+                self.GetPage(selected).AddLadderContact()
+        event.Skip()
+    
+    def OnBranchTool(self, event): 
+        selected = self.GetPageSelection()
+        if selected != -1:
+            self.GetPage(selected).AddLadderBranch()
+        event.Skip()    
+    
+    def OnInitialStepTool(self, event):
+        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARINITIALSTEP)
+        selected = self.GetPageSelection()
+        if selected != -1:
+            self.GetPage(selected).SetMode(MODE_INITIALSTEP)
+        event.Skip()
+    
+    def OnStepTool(self, event):
+        if self.GetDrawingMode() == FREEDRAWING_MODE:
+            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARSTEP)
+        selected = self.GetPageSelection()
+        if selected != -1:
+            if self.GetDrawingMode() == FREEDRAWING_MODE:
+                self.GetPage(selected).SetMode(MODE_STEP)
+            else:
+                self.GetPage(selected).AddStep()
+        event.Skip()
+
+    def OnActionBlockTool(self, event):
+        if self.GetDrawingMode() == FREEDRAWING_MODE:
+            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARACTIONBLOCK)
+        selected = self.GetPageSelection()
+        if selected != -1:
+            if self.GetDrawingMode() == FREEDRAWING_MODE:
+                self.GetPage(selected).SetMode(MODE_ACTION)
+            else:
+                self.GetPage(selected).AddStepAction()
+        event.Skip()
+
+    def OnTransitionTool(self, event):
+        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARTRANSITION)
+        selected = self.GetPageSelection()
+        if selected != -1:
+            self.GetPage(selected).SetMode(MODE_TRANSITION)
+        event.Skip()
+
+    def OnDivergenceTool(self, event):
+        if self.GetDrawingMode() == FREEDRAWING_MODE:
+            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARDIVERGENCE)
+        selected = self.GetPageSelection()
+        if selected != -1:
+            if self.GetDrawingMode() == FREEDRAWING_MODE:
+                self.GetPage(selected).SetMode(MODE_DIVERGENCE)
+            else:
+                self.GetPage(selected).AddDivergence()
+        event.Skip()
+    
+    def OnJumpTool(self, event):
+        if self.GetDrawingMode() == FREEDRAWING_MODE:
+            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARJUMP)
+        selected = self.GetPageSelection()
+        if selected != -1:
+            if self.GetDrawingMode() == FREEDRAWING_MODE:
+                self.GetPage(selected).SetMode(MODE_JUMP)
+            else:
+                self.GetPage(selected).AddJump()
+        event.Skip()
+
+
+#-------------------------------------------------------------------------------
+#                         Add Project Elements Functions
+#-------------------------------------------------------------------------------
+
     def OnAddDataTypeMenu(self, event):
         dialog = DataTypeDialog(self, "Add a new data type", "Please enter data type name", "", wx.OK|wx.CANCEL)
         dialog.SetDataTypeNames(self.Controler.GetProjectDataTypeNames())
@@ -1540,62 +1706,51 @@
             self.RefreshProjectTree()
         dialog.Destroy()
         event.Skip()
-        
-    def OnRemoveDataTypeMenu(self, event):
-        datatypes = self.Controler.GetProjectDataTypeNames()
-        dialog = wx.SingleChoiceDialog(self, "Select Data Type to remove:", "Data Type Remove", datatypes, wx.OK|wx.CANCEL)
-        if dialog.ShowModal() == wx.ID_OK:
-            selected = dialog.GetStringSelection()
-            if not self.Controler.DataTypeIsUsed(selected):
-                self.Controler.ProjectRemoveDataType(selected)
-                tagname = self.Controler.ComputeDataTypeName(selected)
-                idx = self.IsOpened(tagname)
-                if idx is not None:
-                    self.DeletePage(idx)
+
+    def GenerateAddPouFunction(self, pou_type):
+        def OnAddPouMenu(event):
+            dialog = PouDialog(self, pou_type)
+            dialog.SetPouNames(self.Controler.GetProjectPouNames())
+            dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
+            if dialog.ShowModal() == wx.ID_OK:
+                values = dialog.GetValues()
+                self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
                 self.RefreshTitle()
                 self.RefreshEditMenu()
                 self.RefreshProjectTree()
-                self.RefreshToolBar()
-            else:
-                message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
-                message.ShowModal()
-                message.Destroy()
-        event.Skip()
-    
-    def OnAddPouMenu(self, event):
-        dialog = PouDialog(self)
-        dialog.SetPouNames(self.Controler.GetProjectPouNames())
-        dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
-        if dialog.ShowModal() == wx.ID_OK:
-            values = dialog.GetValues()
-            self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
-            self.RefreshTitle()
-            self.RefreshEditMenu()
-            self.RefreshProjectTree()
-        dialog.Destroy()
-        event.Skip()
-
-    def OnRemovePouMenu(self, event):
-        pous = self.Controler.GetProjectPouNames()
-        dialog = wx.SingleChoiceDialog(self, "Select POU to remove:", "POU Remove", pous, wx.OK|wx.CANCEL)
-        if dialog.ShowModal() == wx.ID_OK:
-            selected = dialog.GetStringSelection()
-            if not self.Controler.PouIsUsed(selected):
-                self.Controler.ProjectRemovePou(selected)
-                tagname = self.Controler.ComputePouName(selected)
-                idx = self.IsOpened(tagname)
-                if idx is not None:
-                    self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName())
-                    self.DeletePage(idx)
+            dialog.Destroy()
+            event.Skip()
+        return OnAddPouMenu
+
+    def GenerateAddTransitionFunction(self, pou_name):
+        def OnAddTransitionMenu(event):
+            dialog = PouTransitionDialog(self)
+            dialog.SetPouNames(self.Controler.GetProjectPouNames())
+            dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name))
+            if dialog.ShowModal() == wx.ID_OK: 
+                values = dialog.GetValues()
+                self.Controler.ProjectAddPouTransition(pou_name, values["transitionName"], values["language"])
                 self.RefreshTitle()
                 self.RefreshEditMenu()
                 self.RefreshProjectTree()
-                self.RefreshToolBar()
-            else:
-                message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
-                message.ShowModal()
-                message.Destroy()
-        event.Skip()
+            dialog.Destroy()
+            event.Skip()
+        return OnAddTransitionMenu
+
+    def GenerateAddActionFunction(self, pou_name):
+        def OnAddActionMenu(event):
+            dialog = PouActionDialog(self)
+            dialog.SetPouNames(self.Controler.GetProjectPouNames())
+            dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name))
+            if dialog.ShowModal() == wx.ID_OK:
+                values = dialog.GetValues()
+                self.Controler.ProjectAddPouAction(pou_name, values["actionName"], values["language"])
+                self.RefreshTitle()
+                self.RefreshEditMenu()
+                self.RefreshProjectTree()
+            dialog.Destroy()
+            event.Skip()
+        return OnAddActionMenu
 
     def OnAddConfigurationMenu(self, event):
         dialog = ConfigurationNameDialog(self, "Please enter configuration name", "Add new configuration")
@@ -1610,136 +1765,143 @@
         dialog.Destroy()
         event.Skip()
 
-    def OnRemoveConfigurationMenu(self, event):
-        configs = self.Controler.GetProjectConfigNames()
-        dialog = wx.SingleChoiceDialog(self, "Please select a configuration", "Remove configuration", configs, wx.OK|wx.CANCEL)
-        if dialog.ShowModal() == wx.ID_OK:
-            selected = dialog.GetStringSelection()
-            self.Controler.ProjectRemoveConfiguration(selected)
-            tagname = self.Controler.ComputeConfigurationName(selected)
-            idx = self.IsOpened(tagname)
-            if idx is not None:
-                self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName())
-                self.DeletePage(idx)
-            self.RefreshTitle()
-            self.RefreshEditMenu()
-            self.RefreshProjectTree()
-        event.Skip()
-
-    def OnAddPouTransitionMenu(self, event):
-        selected = self.ProjectTree.GetSelection()
-        if self.ProjectTree.GetPyData(selected) == ITEM_POU:
-            pouname = self.ProjectTree.GetItemText(selected)
-            if self.Controler.GetPouBodyType(pouname) == "SFC":
-                dialog = PouTransitionDialog(self)
-                dialog.SetPouNames(self.Controler.GetProjectPouNames())
-                dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pouname))
-                if dialog.ShowModal() == wx.ID_OK: 
-                    values = dialog.GetValues()
-                    self.Controler.ProjectAddPouTransition(pouname, values["transitionName"], values["language"])
-                    self.RefreshTitle()
-                    self.RefreshEditMenu()
-                    self.RefreshProjectTree()
-                dialog.Destroy()
-        event.Skip()
-
-    def OnRemovePouTransitionMenu(self, event):
-        selected = self.ProjectTree.GetSelection()
-        if self.ProjectTree.GetPyData(selected) == ITEM_POU:
-            pouname = self.ProjectTree.GetItemText(selected)
-            if self.Controler.GetPouBodyType(pouname) == "SFC":
-                transitions = self.Controler.GetPouTransitions(pouname)
-                dialog = wx.SingleChoiceDialog(self, "Select Transition to remove:", "Remove transition", transitions, wx.OK|wx.CANCEL)
-                if dialog.ShowModal() == wx.ID_OK: 
-                    selected = dialog.GetStringSelection()
-                    self.Controler.ProjectRemovePouTransition(pouname, selected)
-                    tagname = self.Controler.ComputePouTransitionName(pouname, selected)
-                    idx = self.IsOpened(tagname)
-                    if idx is not None:
-                        self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName())
-                        self.DeletePage(idx)
-                    self.RefreshTitle()
-                    self.RefreshEditMenu()
-                    self.RefreshProjectTree()
-                dialog.Destroy()
-        event.Skip()
-
-    def OnAddPouActionMenu(self, event):
-        selected = self.ProjectTree.GetSelection()
-        if self.ProjectTree.GetPyData(selected) == ITEM_POU:
-            pouname = self.ProjectTree.GetItemText(selected)
-            if self.Controler.GetPouBodyType(pouname) == "SFC":
-                dialog = PouActionDialog(self)
-                dialog.SetPouNames(self.Controler.GetProjectPouNames())
-                dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pouname))
-                if dialog.ShowModal() == wx.ID_OK:
-                    values = dialog.GetValues()
-                    self.Controler.ProjectAddPouAction(pouname, values["actionName"], values["language"])
-                    self.RefreshTitle()
-                    self.RefreshEditMenu()
-                    self.RefreshProjectTree()
-                dialog.Destroy()
-        event.Skip()
-
-    def OnRemovePouActionMenu(self, event):
-        selected = self.ProjectTree.GetSelection()
-        if self.ProjectTree.GetPyData(selected) == ITEM_POU:
-            pouname = self.ProjectTree.GetItemText(selected)
-            if self.Controler.GetPouBodyType(pouname) == "SFC":
-                actions = self.Controler.GetPouActions(pouname)
-                dialog = wx.SingleChoiceDialog(self, "Select Action to remove:", "Remove action", actions, wx.OK|wx.CANCEL)
-                if dialog.ShowModal() == wx.ID_OK: 
-                    selected = dialog.GetStringSelection()
-                    self.Controler.ProjectRemovePouAction(pouname, selected)
-                    tagname = self.Controler.ComputePouActionName(pouname, selected)
-                    idx = self.IsOpened(tagname)
-                    if idx is not None:
-                        self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName())
-                        self.DeletePage(idx)
-                    self.RefreshTitle()
-                    self.RefreshEditMenu()
-                    self.RefreshProjectTree()
-                dialog.Destroy()
-        event.Skip()
-
-    def OnAddResourceMenu(self, event):
-        selected = self.ProjectTree.GetSelection()
-        if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION:
-            config_name = self.ProjectTree.GetItemText(selected)
+    def GenerateAddResourceFunction(self, config_name):
+        def OnAddResourceMenu(self, event):
             dialog = ResourceNameDialog(self, "Please enter resource name", "Add new resource")
             dialog.SetPouNames(self.Controler.GetProjectPouNames())
             dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
             if dialog.ShowModal() == wx.ID_OK:
                 value = dialog.GetValue()
                 self.Controler.ProjectAddConfigurationResource(config_name, value)
-                tagname = self.Controler.ComputeConfigurationResourceName(config_name, selected)
+                self.RefreshTitle()
+                self.RefreshEditMenu()
+                self.RefreshProjectTree()
+            dialog.Destroy()
+            event.Skip()
+        return OnAddResourceMenu
+
+
+#-------------------------------------------------------------------------------
+#                        Remove Project Elements Functions
+#-------------------------------------------------------------------------------
+
+    def OnRemoveDataTypeMenu(self, event):
+        selected = self.ProjectTree.GetSelection()
+        if self.ProjectTree.GetPyData(selected) == ITEM_DATATYPE:
+            name = self.ProjectTree.GetItemText(selected)
+            if not self.Controler.DataTypeIsUsed(name):
+                self.Controler.ProjectRemoveDataType(name)
+                tagname = self.Controler.ComputeDataTypeName(name)
                 idx = self.IsOpened(tagname)
                 if idx is not None:
-                    self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName())
                     self.DeletePage(idx)
                 self.RefreshTitle()
                 self.RefreshEditMenu()
                 self.RefreshProjectTree()
-            dialog.Destroy()
-        event.Skip()
-
-    def OnRemoveResourceMenu(self, event):
+                self.RefreshToolBar()
+            else:
+                message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
+                message.ShowModal()
+                message.Destroy()
+        event.Skip()
+
+    def OnRemovePouMenu(self, event):
         selected = self.ProjectTree.GetSelection()
-        if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION:
-            config_name = self.ProjectTree.GetItemText(selected)
-            infos = self.Controler.GetProjectInfos()
-            resources = []
-            for config in infos["configs"]:
-                if config["name"] == config_name:
-                    resources = config["resources"]
-            dialog = wx.SingleChoiceDialog(self, "Select Resource to remove:", "Remove resource", resources, wx.OK|wx.CANCEL)
-            if dialog.ShowModal() == wx.ID_OK:
-                resource = dialog.GetStringSelection()
-                self.Controler.ProjectRemoveConfigurationResource(config_name, resource)
+        if self.ProjectTree.GetPyData(selected) == ITEM_POU: 
+            name = self.ProjectTree.GetItemText(selected)
+            if not self.Controler.PouIsUsed(name):
+                self.Controler.ProjectRemovePou(name)
+                tagname = self.Controler.ComputePouName(name)
+                idx = self.IsOpened(tagname)
+                if idx is not None:
+                    self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+                    self.DeletePage(idx)
                 self.RefreshTitle()
                 self.RefreshEditMenu()
                 self.RefreshProjectTree()
-            dialog.Destroy()
+                self.RefreshToolBar()
+            else:
+                message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
+                message.ShowModal()
+                message.Destroy()
+        event.Skip()
+
+    def OnRemoveConfigurationMenu(self, event):
+        selected = self.ProjectTree.GetSelection()
+        if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: 
+            name = self.ProjectTree.GetItemText(selected)
+            self.Controler.ProjectRemoveConfiguration(name)
+            tagname = self.Controler.ComputeConfigurationName(name)
+            idx = self.IsOpened(tagname)
+            if idx is not None:
+                self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+                self.DeletePage(idx)
+            self.RefreshTitle()
+            self.RefreshEditMenu()
+            self.RefreshProjectTree()
+        event.Skip()
+
+    def OnRemoveTransitionMenu(self, event):
+        selected = self.ProjectTree.GetSelection()
+        if self.ProjectTree.GetPyData(selected) == ITEM_TRANSITION: 
+            transition = self.ProjectTree.GetItemText(selected)
+            item = self.ProjectTree.GetItemParent(selected)
+            item_type = self.ProjectTree.GetPyData(item)
+            while item_type != ITEM_POU:
+                item = self.ProjectTree.GetItemParent(item)
+                item_type = self.ProjectTree.GetPyData(item)
+            pou_name = self.ProjectTree.GetItemText(item)
+            self.Controler.ProjectRemovePouTransition(pou_name, transition)
+            tagname = self.Controler.ComputePouTransitionName(pou_name, transition)
+            idx = self.IsOpened(tagname)
+            if idx is not None:
+                self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+                self.DeletePage(idx)
+            self.RefreshTitle()
+            self.RefreshEditMenu()
+            self.RefreshProjectTree()
+        event.Skip()
+
+    def OnRemoveActionMenu(self, event):
+        selected = self.ProjectTree.GetSelection()
+        if self.ProjectTree.GetPyData(selected) == ITEM_ACTION: 
+            transition = self.ProjectTree.GetItemText(selected)
+            item = self.ProjectTree.GetItemParent(selected)
+            item_type = self.ProjectTree.GetPyData(item)
+            while item_type != ITEM_POU:
+                item = self.ProjectTree.GetItemParent(item)
+                item_type = self.ProjectTree.GetPyData(item)
+            pou_name = self.ProjectTree.GetItemText(item)
+            self.Controler.ProjectRemovePouAction(pou_name, action)
+            tagname = self.Controler.ComputePouActionName(pou_name, action)
+            idx = self.IsOpened(tagname)
+            if idx is not None:
+                self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+                self.DeletePage(idx)
+            self.RefreshTitle()
+            self.RefreshEditMenu()
+            self.RefreshProjectTree()
+        event.Skip()
+
+    def OnRemoveResourceMenu(self, event):
+        selected = self.ProjectTree.GetSelection()
+        if self.ProjectTree.GetPyData(selected) == ITEM_RESOURCE:
+            resource = self.ProjectTree.GetItemText(selected)
+            item = self.ProjectTree.GetItemParent(selected)
+            item_type = self.ProjectTree.GetPyData(item)
+            while item_type != ITEM_CONFIGURATION:
+                item = self.ProjectTree.GetItemParent(item)
+                item_type = self.ProjectTree.GetPyData(item)
+            config_name = self.ProjectTree.GetItemText(item)
+            self.Controler.ProjectRemoveConfigurationResource(config_name, resource)
+            tagname = self.Controler.ComputeConfigurationResourceName(config_name, selected)
+            idx = self.IsOpened(tagname)
+            if idx is not None:
+                self.VariablePanelIndexer.RemoveVariablePanel(tagname)
+                self.DeletePage(idx)
+            self.RefreshTitle()
+            self.RefreshEditMenu()
+            self.RefreshProjectTree()
         event.Skip()
 
     def OnPLCOpenMenu(self, event):
@@ -1787,7 +1949,7 @@
     def _init_ctrls(self, prnt):
         wx.Panel.__init__(self, id=ID_SCALINGPANEL,
               name='ScalingPanel', parent=prnt, pos=wx.Point(0, 0),
-              size=wx.Size(0, 0), style=0)
+              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
         
         self.staticText1 = wx.StaticText(id=ID_SCALINGPANELSTATICTEXT1,
               label='X Scale:', name='staticText1', parent=self,
@@ -2335,11 +2497,13 @@
             
         self._init_sizers()
 
-    def __init__(self, parent):
+    def __init__(self, parent, pou_type = None):
         self._init_ctrls(parent)
         
-        for option in ["function","functionBlock","program"]:
+        for option in ["function", "functionBlock", "program"]:
             self.PouType.Append(option)
+        if pou_type is not None:
+            self.PouType.SetStringSelection(pou_type)
         self.RefreshLanguage()
 
         self.PouNames = []