Example #1
0
    def OnItemRightClick(self, evt):
        if self.node:
            if hasattr(evt, 'GetIndex'):
                index = evt.GetIndex()
            else:
                index = -1
            page = self.pages[self.GetSelection()]
            if not hasattr(evt, 'page'):
                evt.page = page
            if hasattr(page, 'menus'):
                cm = Menu(self)
                menus = page.menus
                for cls in menus:
                    if hasattr(cls, "CheckAvailableOn"
                               ) and not cls.CheckAvailableOn(page):
                        continue
                    cls.OnExecute._classname_ = cls.__name__
                    item = cm.Add(cls.OnExecute, cls.name, cls.help)
                    if hasattr(cls,
                               "CheckEnabled") and not cls.CheckEnabled(page):
                        cm.Enable(item, False)

                if cm.GetMenuItemCount():
                    cm.Popup(evt)

            elif hasattr(self.node, "OnItemRightClick"):
                evt.currentPage = page
                self.node.OnItemRightClick(evt)
            elif hasattr(self.node, "GetItemNode"):
                node = self.node.GetItemNode(evt.page, index)
                if node:
                    node.RefreshVolatile()
                    node.GetProperties()
                    w = adm.GetCurrentFrame(self)
                    cm = w.GetContextMenu(node)
                    w.currentNode = node
                    cm.Popup(evt)
                    w.currentNode = None
Example #2
0
  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