PLCOpenEditor.py
changeset 428 3b19c34bac04
parent 427 22d16c457d87
child 429 c270d61a671d
--- a/PLCOpenEditor.py	Thu Sep 17 14:17:52 2009 -0600
+++ b/PLCOpenEditor.py	Fri Sep 18 09:41:27 2009 -0600
@@ -1809,9 +1809,14 @@
                 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=_("Create a new POU from"))
             self.Bind(wx.EVT_MENU, self.OnCreatePouFromMenu, id=new_id)
+
+            AppendMenu(menu, help='', id=wx.ID_COPY, kind=wx.ITEM_NORMAL, text=_("Copy"))
+            self.Bind(wx.EVT_MENU, self.OnCopyPou, id=wx.ID_COPY)
+
             pou_type = self.Controler.GetPouType(name, self.Debug)
             if pou_type in ["function", "functionBlock"]:
                 change_menu = wx.Menu(title='')
@@ -1855,9 +1860,17 @@
                 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)
+
+                AppendMenu(menu, help='', id=wx.ID_PASTE, kind=wx.ITEM_NORMAL, text=_("Paste"))
+                self.Bind(wx.EVT_MENU, self.OnPastePou, id=wx.ID_PASTE)
+
+                if self.GetCopyBuffer() is None:
+                    menu.Enable(wx.ID_PASTE, False)
+
                 self.PopupMenu(menu)
             elif name == "Configurations":
                 menu = wx.Menu(title='')
@@ -2478,6 +2491,37 @@
                 self.RefreshToolBar()
         event.Skip()
 
+    def OnCopyPou(self, event):
+        selected = self.TypesTree.GetSelection()
+
+        pou_name = self.TypesTree.GetItemText(selected)
+        pou = self.Controler.Project.getpou(pou_name)
+
+        pou_xml = pou.generateXMLText('pou', 0)
+        self.SetCopyBuffer(pou_xml)
+
+    def OnPastePou(self, event):
+        selected = self.TypesTree.GetSelection()
+
+        pou_type = self.TypesTree.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]
+
+        pou_xml = self.GetCopyBuffer()
+
+        result = self.Controler.PastePou(pou_type, pou_xml)
+
+        if result is not None:
+            message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+        else:
+            self.RefreshTitle()
+            self.RefreshEditMenu()
+            self.RefreshTypesTree()
+            self.RefreshLibraryTree()
+            self.RefreshToolBar()
+
 #-------------------------------------------------------------------------------
 #                        Remove Project Elements Functions
 #-------------------------------------------------------------------------------