PLCOpenEditor.py
changeset 712 c11b54730a7b
parent 711 5f6a743dcde5
child 714 131ea7f237b9
--- a/PLCOpenEditor.py	Thu Jun 14 18:13:32 2012 +0200
+++ b/PLCOpenEditor.py	Fri Jun 15 18:02:09 2012 +0200
@@ -1924,8 +1924,11 @@
         item_infos = self.ProjectTree.GetPyData(item)
         
         menu = None
-        if item_infos["type"] in ITEMS_UNEDITABLE:
-            name = UNEDITABLE_NAMES_DICT[name]
+        if item_infos["type"] in ITEMS_UNEDITABLE + [ITEM_PROJECT]:
+            if item_infos["type"] == ITEM_PROJECT:
+                name = "Project"
+            else:
+                name = UNEDITABLE_NAMES_DICT[name]
             
             if name == "Data Types":
                 menu = wx.Menu(title='')
@@ -1933,12 +1936,13 @@
                 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add DataType"))
                 self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, id=new_id)
             
-            elif name in ["Functions", "Function Blocks", "Programs"]:
+            elif name in ["Functions", "Function Blocks", "Programs", "Project"]:
                 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)
+                
+                if name != "Project":
+                    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)
 
                 new_id = wx.NewId()
                 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Paste POU"))
@@ -2449,21 +2453,25 @@
 
     def OnPastePou(self, event):
         selected = self.ProjectTree.GetSelection()
-
-        pou_type = self.ProjectTree.GetItemText(selected)
-        pou_type = UNEDITABLE_NAMES_DICT[pou_type] # one of 'Functions', 'Function Blocks' or 'Programs'
-        pou_type = {'Functions': 'function', 'Function Blocks': 'functionBlock', 'Programs': 'program'}[pou_type]
-
+        
+        if self.ProjectTree.GetPyData(selected)["type"] != ITEM_PROJECT: 
+            pou_type = self.ProjectTree.GetItemText(selected)
+            pou_type = UNEDITABLE_NAMES_DICT[pou_type] # one of 'Functions', 'Function Blocks' or 'Programs'
+            pou_type = {'Functions': 'function', 'Function Blocks': 'functionBlock', 'Programs': 'program'}[pou_type]
+        else:
+            pou_type = None
+        
         pou_xml = self.GetCopyBuffer()
 
         result = self.Controler.PastePou(pou_type, pou_xml)
 
-        if result is not None:
+        if not isinstance(result, TupleType):
             message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
             message.ShowModal()
             message.Destroy()
         else:
             self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
+            self.EditProjectElement(ITEM_POU, result[0])
 
 #-------------------------------------------------------------------------------
 #                        Remove Project Elements Functions