TreeNodeEvents: OnShowMenuItem

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

TreeNodeEvents: OnShowMenuItem

Post by Teknojnky »

Since there doesnt seem to be any explaination @
http://www.mediamonkey.com/wiki/index.p ... owMenuItem

How is this event supposed to be used?

I'm getting 3 menu's when I tried to add 1... it seems to be firing 3 times...

Triggered once: when node left clicked (no menu displayed)

Triggered twice more: when node right clicked (menu displayed with 2x menu items)

so

Code: Select all

  Script.RegisterEvent TestNode, "OnShowMenuItem", "TestMenu"

Sub TestMenu(node)
 Set SDB.Objects("mnuTest") = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,0,0)
 SDB.Objects("mnuTest").Caption = "Test Menu"
End Sub
The 'Test Menu' menu is added 3 times.

Is this a bug or how is this event supposed to work?
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

The event is probably fired every time the menu appears (and thus the menu item is shown). I don't think you should be adding the menu item here, but if you really want to, you should check it doesn't already exist so that you only do it once, like this...

Code: Select all

Sub TestMenu(node)
 Dim itm : Set itm = SDB.Objects("mnuTest")
  If itm Is Nothing Then
    Set SDB.Objects("mnuTest") = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,0,0)
    SDB.Objects("mnuTest").Caption = "Test Menu"
  End If
End Sub
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post by Teknojnky »

trixmoto wrote:The event is probably fired every time the menu appears (and thus the menu item is shown). I don't think you should be adding the menu item here, but if you really want to, you should check it doesn't already exist so that you only do it once, like this...
Well that is just the problem.. the menu is only shown once, but the event is fired 3 times...

trigger1 = left click (select node)
trigger2 & 3 = right click

if you right click the node without selecting it first, you still get 3 events triggered.

try it and see, create an event with a simple msgbox and then right click the tree and you will get the msgbox 3 times.
jiri
Posts: 5397
Joined: Tue Aug 14, 2001 7:00 pm
Location: Czech Republic
Contact:

Post by jiri »

Yes, the documentation was a bit lacking there, so I have updated it with the exact way MediaMonkey currently uses the event. It should made clear the current behaviour.

Jiri
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post by Teknojnky »

Ok, thanks Jiri.. I'm still not understanding why the event is triggered 3 times tho.
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden
Contact:

Post by Bex »

Thanks for the explanation. I've wondered a long time what the purpose was.

Would it be possible to get a OnShowTreeMenu event to easier show/hide custom menus?
Also OnShowMenu_Pop_NP, OnShowMenu_Pop_NP_MainWindow, OnShowMenu_Pop_TrackList, would be nice for the same reason.

The workaround with OnChangedSelection is a bit shaky!

Please!
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post by Teknojnky »

Bex wrote:Would it be possible to get a OnShowTreeMenu event to easier show/hide custom menus?
This was the purpose I was trying to figure out how to use it for, but it appears that isn't really the best way either..
Also OnShowMenu_Pop_NP, OnShowMenu_Pop_NP_MainWindow, OnShowMenu_Pop_TrackList, would be nice for the same reason.

The workaround with OnChangedSelection is a bit shaky!

Please!
Agreed! And I will have to investigate this OnChangedSelection workaround in the meantime! :o
Post Reply