Adding Rename item in TypesTree contextual menu
authorlbessard
Wed, 25 Feb 2009 16:05:45 +0100
changeset 311 3e22e53878b8
parent 310 ccb47adebe80
child 312 eab54dae434d
Adding Rename item in TypesTree contextual menu
Bug allowing deletion of FunctionBlock variable definition in VariablePanel fixed
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Wed Feb 25 16:04:26 2009 +0100
+++ b/PLCOpenEditor.py	Wed Feb 25 16:05:45 2009 +0100
@@ -1657,6 +1657,10 @@
                 self.Bind(wx.EVT_MENU, self.GenerateChangePouTypeFunction(name, "program"), id=new_id)
                 menu.AppendMenu(wx.NewId(), "Change POU Type To", change_menu)
             new_id = wx.NewId()
+            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text="Rename")
+            self.Bind(wx.EVT_MENU, self.OnRenamePouMenu, id=new_id)
+            self.PopupMenu(menu)
+            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)
@@ -2212,6 +2216,9 @@
             if dialog.ShowModal() == wx.ID_OK:
                 values = dialog.GetValues()
                 self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
+                selected = self.TabsOpened.GetSelection()
+                if selected != -1:
+                    self.TabsOpened.GetPage(selected).RefreshView()
                 self.RefreshTitle()
                 self.RefreshEditMenu()
                 self.RefreshTypesTree()
@@ -2331,6 +2338,12 @@
                 message.Destroy()
         event.Skip()
 
+    def OnRenamePouMenu(self, event):
+        selected = self.TypesTree.GetSelection()
+        if self.TypesTree.GetPyData(selected) == ITEM_POU: 
+            wx.CallAfter(self.TypesTree.EditLabel, selected)
+        event.Skip()
+
     def OnRemovePouMenu(self, event):
         selected = self.TypesTree.GetSelection()
         if self.TypesTree.GetPyData(selected) == ITEM_POU: 
@@ -4150,11 +4163,14 @@
         if getattr(self, "Table", None):
             table_length = len(self.Table.data)
             row_class = None
-            if table_length and self.PouIsUsed:
+            row_edit = True
+            if table_length > 0:
                 row = self.VariablesGrid.GetGridCursorRow()
-                row_class = self.Table.GetValueByName(row, "Class")
+                row_edit = self.Table.GetValueByName(row, "Edit")
+                if self.PouIsUsed:
+                    row_class = self.Table.GetValueByName(row, "Class")
             self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"])
-            self.DeleteButton.Enable(table_length > 0 and row_class not in ["Input", "Output", "InOut"])
+            self.DeleteButton.Enable(table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"])
             self.UpButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
             self.DownButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])