TreeNode.OnShowMenuItem and OnExecMenuItem

Post a reply

Visual Confirmation

To prevent automated access and spam, you are required to confirm that you are human. Please place a check mark next to all images of monkeys or apes. If you cannot see any images, please contact the Board Administrator.

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: TreeNode.OnShowMenuItem and OnExecMenuItem

Re: TreeNode.OnShowMenuItem and OnExecMenuItem

Post by trixmoto » Tue Apr 20, 2010 1:22 pm

Oooops! :oops: I had a node and a subnode and due to some iffy cut/pasting I was registering the events to the node instead of the subnode! :lol:

Re: TreeNode.OnShowMenuItem and OnExecMenuItem

Post by trixmoto » Tue Apr 20, 2010 10:53 am

I tried something like that last night but I couldn't get it to work. :-? I'll have to have another look tonight.

Re: TreeNode.OnShowMenuItem and OnExecMenuItem

Post by ZvezdanD » Tue Apr 20, 2010 6:58 am

Usage is really simple. First, you need to register those events for your custom node:
Code: Select all
        Script.RegisterEvent oCustomNode, "OnExecMenuItem", "OnExecMenuItem"
        Script.RegisterEvent oCustomNode, "OnShowMenuItem", "OnShowMenuItem"


Then you should enable the Remove option in the context menu for that node:
Code: Select all
Function OnShowMenuItem(iItemIndex)
    Select Case iItemIndex
    Case 5
        OnShowMenuItem = True
    Case Else
        OnShowMenuItem = False
    End Select
End Function


Then you should provide a code for removing that node when user click on the Remove option:
Code: Select all
Function OnExecMenuItem(iItemIndex)
    If iItemIndex = 5 Then
        If Not SDB.MainTree.CurrentNode Is Nothing Then
            ' My own function for removing node:
            DeleteNodeWithMask SDB.MainTree.CurrentNode.CustomNodeID
            ' It could contain just:
            ' SDB.MainTree.RemoveNode SDB.MainTree.CurrentNode
        End If
        OnExecMenuItem = True
    Else
        OnExecMenuItem = False
    End If
End Function

Re: TreeNode.OnShowMenuItem and OnExecMenuItem

Post by trixmoto » Tue Apr 20, 2010 4:52 am

Ok thanks, I'll go with that approach then. Would still be nice to understand how it's supposed to work though! :)

Re: TreeNode.OnShowMenuItem and OnExecMenuItem

Post by ZvezdanD » Mon Apr 19, 2010 5:57 pm

Yes, I tried it long time ago with Magic Nodes. If you take a look at its source code, you would find those lines commented. Those events work fine, but I dropped that idea because it wouldn't be consistent with the built-in Remove option which removes tracks from tracklist, not a node itself. For example, if you right-click on some album from the Album node and if you choose Remove option, it will remove tracks, not node. So, I added new Delete Magic Node option to the context menu and implemented my own code for removing MN nodes.

Re: TreeNode.OnShowMenuItem and OnExecMenuItem

Post by Bex » Mon Apr 19, 2010 5:33 pm

I tried to figure out how they worked a couple of years ago but with no success. Perhaps it's easiest to add your own remove menu+command? Or will that result in two remove menus?

TreeNode.OnShowMenuItem and OnExecMenuItem

Post by trixmoto » Mon Apr 19, 2010 5:25 pm

Has anyone tried using these yet? I can't seem to do anything with them. What I'm attempting to do is allow the user to right click and remove a node which has been added by my script. Anyone got any ideas?

The wiki says one of the values of ItemIndex is "4 .. Custom Remove - Does this tree node has its own handling of Remove command?" but how do you make the tree node handle the remove command?

Top