1215 |
1215 |
1216 def OnDeleteMenu(self, event): |
1216 def OnDeleteMenu(self, event): |
1217 window = self.FindFocus() |
1217 window = self.FindFocus() |
1218 if window == self.ProjectTree or window is None: |
1218 if window == self.ProjectTree or window is None: |
1219 selected = self.ProjectTree.GetSelection() |
1219 selected = self.ProjectTree.GetSelection() |
1220 if selected.IsOk(): |
1220 if selected is not None and selected.IsOk(): |
1221 function = self.DeleteFunctions.get(self.ProjectTree.GetPyData(selected)["type"], None) |
1221 function = self.DeleteFunctions.get(self.ProjectTree.GetPyData(selected)["type"], None) |
1222 if function is not None: |
1222 if function is not None: |
1223 function(self, selected) |
1223 function(self, selected) |
1224 self.CloseTabsWithoutModel() |
1224 self.CloseTabsWithoutModel() |
1225 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, |
1225 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, |
1427 #------------------------------------------------------------------------------- |
1427 #------------------------------------------------------------------------------- |
1428 # Types Tree Management Functions |
1428 # Types Tree Management Functions |
1429 #------------------------------------------------------------------------------- |
1429 #------------------------------------------------------------------------------- |
1430 |
1430 |
1431 def RefreshProjectTree(self): |
1431 def RefreshProjectTree(self): |
1432 if wx.Platform == '__WXMSW__': |
|
1433 self.ProjectTree.SetEvtHandlerEnabled(False) |
|
1434 |
|
1435 # Extract current selected item tagname |
1432 # Extract current selected item tagname |
1436 selected = self.ProjectTree.GetSelection() |
1433 selected = self.ProjectTree.GetSelection() |
1437 if selected is not None and selected.IsOk(): |
1434 if selected is not None and selected.IsOk(): |
1438 item_infos = self.ProjectTree.GetPyData(selected) |
1435 item_infos = self.ProjectTree.GetPyData(selected) |
1439 tagname = item_infos.get("tagname", None) |
1436 tagname = item_infos.get("tagname", None) |
1449 self.ProjectTree.Expand(root) |
1446 self.ProjectTree.Expand(root) |
1450 |
1447 |
1451 # Select new item corresponding to previous selected item |
1448 # Select new item corresponding to previous selected item |
1452 if tagname is not None: |
1449 if tagname is not None: |
1453 self.SelectProjectTreeItem(tagname) |
1450 self.SelectProjectTreeItem(tagname) |
1454 elif wx.Platform == '__WXMSW__': |
|
1455 self.ProjectTree.SetEvtHandlerEnabled(True) |
|
1456 |
1451 |
1457 def ResetSelectedItem(self): |
1452 def ResetSelectedItem(self): |
1458 self.SelectedItem = None |
1453 self.SelectedItem = None |
1459 |
1454 |
1460 def GenerateProjectTreeBranch(self, root, infos, item_alone=False): |
1455 def GenerateProjectTreeBranch(self, root, infos, item_alone=False): |
1485 item, root_cookie = self.ProjectTree.GetFirstChild(root) |
1480 item, root_cookie = self.ProjectTree.GetFirstChild(root) |
1486 for values in infos["values"]: |
1481 for values in infos["values"]: |
1487 if values["type"] not in ITEMS_UNEDITABLE or len(values["values"]) > 0: |
1482 if values["type"] not in ITEMS_UNEDITABLE or len(values["values"]) > 0: |
1488 if item is None or not item.IsOk(): |
1483 if item is None or not item.IsOk(): |
1489 item = self.ProjectTree.AppendItem(root, "") |
1484 item = self.ProjectTree.AppendItem(root, "") |
1490 if wx.Platform != '__WXMSW__': |
1485 item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
1491 item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
|
1492 self.GenerateProjectTreeBranch(item, values) |
1486 self.GenerateProjectTreeBranch(item, values) |
1493 item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
1487 item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
1494 while item is not None and item.IsOk(): |
1488 while item is not None and item.IsOk(): |
1495 to_delete.append(item) |
1489 to_delete.append(item) |
1496 item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
1490 item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
1497 for item in to_delete: |
1491 for item in to_delete: |
1498 self.ProjectTree.Delete(item) |
1492 self.ProjectTree.Delete(item) |
1499 |
1493 |
|
1494 TagNamePartsItemTypes = { |
|
1495 "D": [ITEM_DATATYPE], |
|
1496 "P": [ITEM_POU], |
|
1497 "T": [ITEM_POU, ITEM_TRANSITION], |
|
1498 "A": [ITEM_POU, ITEM_ACTION], |
|
1499 "C": [ITEM_CONFIGURATION], |
|
1500 "R": [ITEM_CONFIGURATION, ITEM_RESOURCE]} |
|
1501 |
1500 def SelectProjectTreeItem(self, tagname): |
1502 def SelectProjectTreeItem(self, tagname): |
1501 self.ProjectTree.SetEvtHandlerEnabled(False) |
|
1502 result = False |
1503 result = False |
1503 if self.ProjectTree is not None: |
1504 if self.ProjectTree is not None: |
1504 root = self.ProjectTree.GetRootItem() |
1505 root = self.ProjectTree.GetRootItem() |
1505 if root.IsOk(): |
1506 if root is not None and root.IsOk(): |
1506 words = tagname.split("::") |
1507 words = tagname.split("::") |
1507 if words[0] == "D": |
1508 result = self.RecursiveProjectTreeItemSelection(root, |
1508 result = self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_DATATYPE)]) |
1509 zip(words[1:], self.TagNamePartsItemTypes.get(words[0], []))) |
1509 elif words[0] == "P": |
|
1510 result = self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_POU)]) |
|
1511 elif words[0] == "T": |
|
1512 result = self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_POU), (words[2], ITEM_TRANSITION)]) |
|
1513 elif words[0] == "A": |
|
1514 result = self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_POU), (words[2], ITEM_ACTION)]) |
|
1515 elif words[0] == "C": |
|
1516 result = self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_CONFIGURATION)]) |
|
1517 elif words[0] == "R": |
|
1518 result = self.RecursiveProjectTreeItemSelection(root, [(words[1], ITEM_CONFIGURATION), (words[2], ITEM_RESOURCE)]) |
|
1519 self.ProjectTree.SetEvtHandlerEnabled(True) |
|
1520 return result |
1510 return result |
1521 |
1511 |
1522 def RecursiveProjectTreeItemSelection(self, root, items): |
1512 def RecursiveProjectTreeItemSelection(self, root, items): |
1523 found = False |
1513 found = False |
1524 item, root_cookie = self.ProjectTree.GetFirstChild(root) |
1514 item, root_cookie = self.ProjectTree.GetFirstChild(root) |