def OnTreeRightClick(self, evt): item, _flags = self.HitTest(evt.GetPosition()) if item and item != self.GetSelection(): self.SelectItem(item) cm = Menu(self.frame) if item: snippet = self.GetNode(item) if snippet.IsGroup(): cm.Add(self.OnRenameSnippet, xlt("Rename"), xlt(("Rename group"))) item = cm.Add(self.OnDelSnippet, xlt("Delete"), xlt(("Delete group"))) for s in self.snippets.values(): if s.parent == snippet.id: cm.Enable(item, False) break else: cm.Add(self.OnReplaceSnippet, xlt("Replace"), xlt(("Replace snippet text"))) cm.Add(self.OnRenameSnippet, xlt("Rename"), xlt(("Rename snippet"))) item = cm.Add(self.OnRevertSnippet, xlt("Revert"), xlt(("Revert snippet to previous text"))) cm.Enable(item, snippet.prevText != None) cm.Add(self.OnDelSnippet, xlt("Delete"), xlt( ("Delete snippet"))) cm.AppendSeparator() cm.Add(self.OnAddGroup, xlt("Add group"), xlt(("Add group"))) cm.Popup(evt)
def GetContextMenu(self, node): contextMenu=Menu(self) if not len(node.properties): node.GetProperties() newcls=self.getNewClass(node) newmenu=Menu(self) if newcls: newmenu.Add(newcls.New, xlt("New %s") % newcls.shortname, xlt("Create new %s") % newcls.typename) morenew=node.nodeinfo().get('new', []) if isinstance(morenew, list): morenew=list(morenew) # copy else: morenew=[morenew] children=node.nodeinfo().get('children', []) for child in children: childnodeinfo=node.nodeinfo(child) childclass=childnodeinfo['class'] if childclass not in morenew: morenew.append(childclass) childnew=childnodeinfo.get('new', []) if not isinstance(childnew, list): childnew=[childnew] for childclass in childnew: if childclass not in morenew: morenew.append(childclass) for cls in morenew: if cls == newcls: continue if hasattr(cls, "New"): newmenu.Add(cls.New, xlt("New %s") % cls.shortname, xlt("Create new %s") % cls.typename) contextMenu.AppendOneMenu(newmenu, xlt("New Object"), xlt("Creates a new object")) if hasattr(node, "Delete"): if not hasattr(node, "deleteDisable") or not node.deleteDisable: contextMenu.Add(self.OnDelete, xlt("Delete %s") % node.shortname, xlt("Delete %s %s") % (node.typename,node.name)) if hasattr(node, "Disconnect"): contextMenu.Add(self.OnDisconnect, xlt("Disconnect %s") % node.name, xlt("Disconnect %s \"%s\"") % (node.typename,node.name)) if contextMenu.GetMenuItemCount(): contextMenu.AppendSeparator() contextMenu.Add(self.OnRefresh, xlt("Refresh"), xlt("Refresh %s") % node.typename) contextMenu.Add(self.OnDetach, xlt("Detach view"), xlt("Show %s in detached window") % node.typename) needSeparator=True for mi in node.menuinfos(): if self.menuAvailableOnNode(mi, node): if needSeparator: contextMenu.AppendSeparator() needSeparator=False cls=mi['class'] item=contextMenu.Add(cls.OnExecute, cls.name, cls.help) if hasattr(cls, "CheckEnabled") and not cls.CheckEnabled(node): contextMenu.Enable(item, False) if hasattr(node, "Edit"): contextMenu.AppendSeparator() contextMenu.Add(self.OnEdit, xlt("Properties"), xlt("Edit properties of %s") % node.typename) return contextMenu