Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
authorLaurent Bessard
Thu, 18 Oct 2012 12:05:45 +0200
changeset 856 b64e436f000e
parent 855 b30421d07e8c
child 857 9695969796d0
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
dialogs/ConnectionDialog.py
editors/Viewer.py
--- a/dialogs/ConnectionDialog.py	Thu Oct 18 01:22:52 2012 +0200
+++ b/dialogs/ConnectionDialog.py	Thu Oct 18 12:05:45 2012 +0200
@@ -32,7 +32,7 @@
 
 class ConnectionDialog(wx.Dialog):
     
-    def __init__(self, parent, controller):
+    def __init__(self, parent, controller, apply_button=False):
         wx.Dialog.__init__(self, parent,
               size=wx.Size(350, 220), title=_('Connection Properties'))
         
@@ -92,6 +92,13 @@
         main_sizer.AddSizer(button_sizer, border=20, 
               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
         
+        if apply_button:
+            self.ApplyToAllButton = wx.Button(self, label=_("Propagate Name"))
+            self.ApplyToAllButton.SetToolTipString(
+                _("Apply name modification to all continuations with the same name"))
+            self.Bind(wx.EVT_BUTTON, self.OnApplyToAll, self.ApplyToAllButton)
+            button_sizer.AddWindow(self.ApplyToAllButton)
+        
         self.SetSizer(main_sizer)
         
         self.Connection = None
@@ -135,7 +142,7 @@
     def SetPouElementNames(self, element_names):
         self.PouElementNames = [element_name.upper() for element_name in element_names]
     
-    def OnOK(self, event):
+    def TestName(self):
         message = None
         connection_name = self.ConnectionName.GetValue()
         if connection_name == "":
@@ -152,9 +159,17 @@
             dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
             dialog.ShowModal()
             dialog.Destroy()
-        else:
+            return False
+        return True
+        
+    def OnOK(self, event):
+        if self.TestName():
             self.EndModal(wx.ID_OK)
 
+    def OnApplyToAll(self, event):
+        if self.TestName():
+            self.EndModal(wx.ID_YESTOALL)
+
     def OnTypeChanged(self, event):
         self.RefreshPreview()
         event.Skip()
--- a/editors/Viewer.py	Thu Oct 18 01:22:52 2012 +0200
+++ b/editors/Viewer.py	Thu Oct 18 12:05:45 2012 +0200
@@ -2455,14 +2455,16 @@
         dialog.Destroy()
 
     def EditConnectionContent(self, connection):
-        dialog = ConnectionDialog(self.ParentWindow, self.Controler)
+        dialog = ConnectionDialog(self.ParentWindow, self.Controler, True)
         dialog.SetPreviewFont(self.GetFont())
         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
         dialog.SetMinConnectionSize(connection.GetSize())
         values = {"name" : connection.GetName(), "type" : connection.GetType()}
         dialog.SetValues(values)
-        if dialog.ShowModal() == wx.ID_OK:
+        result = dialog.ShowModal()
+        dialog.Destroy()
+        if result in [wx.ID_OK, wx.ID_YESTOALL]:
             old_type = connection.GetType()
             old_name = connection.GetName()
             values = dialog.GetValues()
@@ -2476,17 +2478,16 @@
                 self.Controler.RemoveEditedElementInstance(self.TagName, id)
                 self.Controler.AddEditedElementConnection(self.TagName, id, values["type"])
             self.RefreshConnectionModel(connection)
-            self.RefreshBuffer()
-            if old_name != values["name"]:
+            if old_name != values["name"] and result == wx.ID_YESTOALL:
                 self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_name, values["name"])
                 self.RefreshBuffer()
                 self.RefreshView(selection=({connection.GetId(): True}, {}))
             else:
+                self.RefreshBuffer()
                 self.RefreshScrollBars()
                 self.RefreshVisibleElements()
                 connection.Refresh(rect)
-        dialog.Destroy()
-
+        
     def EditContactContent(self, contact):
         dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact")
         dialog.SetPreviewFont(self.GetFont())