MenuItem "OnClick" event ?

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

MenuItem "OnClick" event ?

Post by raybeau528 » Wed Mar 11, 2009 11:11 am

I'm creating menu items to emulate the playlist tree and assigning an "OnClick" event to each menu item. When I right click on the main menu item in the playlist tree and move the cursor to items that don't have sub-items and click that menu item it invokes the event just fine. When I move the cursor to an item that does have sub-items the event is triggered automatically without actually clicking. How can I avoid the event being triggered automatically? Is this a bug?

For example:

item1
item2
item2a
item2b
item3

If I click on item1 or item3 it works fine. But as soon as I land on item2 it triggers the event immediately. This is not desired behavior. I want to be able to click on item1 or item2a etc without automatically triggering the event.

Any ideas?

Thanks!

onenonymous
Posts: 374
Joined: Sat Feb 02, 2008 1:09 pm
Location: Texas

Re: MenuItem "OnClick" event ?

Post by onenonymous » Wed Mar 11, 2009 1:12 pm

couldn't you test for whether item 2 would have sub-items, and if so, not assign the OnClick event?

ZvezdanD
Posts: 3090
Joined: Thu Jun 08, 2006 7:40 pm

Re: MenuItem "OnClick" event ?

Post by ZvezdanD » Wed Mar 11, 2009 1:12 pm

raybeau528 wrote:Is this a bug? ... This is not desired behavior.
Well, I don't think it is a bug and it is desired for me, at least on the first level. I have created same menu with playlists like you and it is constructed dynamically, so I need to be able to recreate it using exactly that event. I am using it like that because I don't know for better way how to detect when some playlist is added/removed, since there not exist OnPlaylistAdded and OnPlaylistRemoved events.

If you have used Windows 3.x or earlier, you know that it was required to click on the main menu to get its sub-menu - with Win95 it was introduced that its is enough just to hover mouse above main menu to get its sub-menu. Obviously, MM follows Win3.x logic ;)
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1 / 5.4  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.7 / 4.0  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.3 / 2.2.2  Inherit Child Playlists 1.0.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: MenuItem "OnClick" event ?

Post by raybeau528 » Wed Mar 11, 2009 4:25 pm

couldn't you test for whether item 2 would have sub-items, and if so, not assign the OnClick event?
I certainly could, though it would be very difficult to 'look ahead' down the tree but that won't help because I need to click on every item whether it has child playlists or not. Consider the "Send To" option - you can click on the parent playlist or a child playlist. That's the behavior I need as well.
better way how to detect when some playlist is added/removed, since there not exist OnPlaylistAdded and OnPlaylistRemoved events
Exactly. I have to rebuild the all the menu items every time. What's really needed is an "onfocus" event to execute for those times when you do want the event automatically triggered but the onclick event should only be triggered when you actually click it. Isn't that what "OnClick" means? I also tried the "OnMouseUP" or "OnMouseDown" events available under SDBUICommon but apparently that doesn't apply to the menu items because they just do the old NOP routine - it doesn't error, it just doesn't do anything.

ZvezdanD
Posts: 3090
Joined: Thu Jun 08, 2006 7:40 pm

Re: MenuItem "OnClick" event ?

Post by ZvezdanD » Wed Mar 11, 2009 6:49 pm

raybeau528 wrote:Isn't that what "OnClick" means?
I don't remember how menu item with sub-menus works within Visual Basic and other programming languages, but I suppose that they have same behavior as MM menu. Similar thing happens with the keyboard events:
when we press a key on some button in Visual Basic (and hold it some time), we have the next order of events:
- OnKeyDown
- OnKeyDown
...
- OnKeyDown
- OnKeyUp
- OnClick

You see? There is an OnClick event, even if you don't touch a mouse, just keyboard!
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1 / 5.4  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.7 / 4.0  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.3 / 2.2.2  Inherit Child Playlists 1.0.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: MenuItem "OnClick" event ?

Post by raybeau528 » Wed Mar 11, 2009 9:01 pm

Bad implementation or working as designed?

But if you right click on a playlist or selection or whatever and you select Send To you get multi-level menu items of which you can follow the tree up and down and in and out without anything happening until you actually click on an item. I guess that's what's meant by "OnClick" ! :) If only the API was implemented the same way.

ZvezdanD
Posts: 3090
Joined: Thu Jun 08, 2006 7:40 pm

Re: MenuItem "OnClick" event ?

Post by ZvezdanD » Thu Mar 12, 2009 3:10 am

raybeau528 wrote:Bad implementation or working as designed?
Which bad implementation? I think you didn't understand, I said this behavior is not exclusive to MM. I just tried Visual Basic and as I supposed it generates OnClick event when you just hover with a mouse above the menu item which has sub-items. And as I explained with the keybard events, OnClick event is obviously generated on many other occasions when you even don't use a mouse.

I don't understand what you want to say with your explanation about the Send To menu. You don't know what is happening internally to MM when a user hover with a mouse above the Send To item. Because nothing is happening, it doesn't mean that OnClick event was not generated in that case. Most probably, MM generates OnClick event in that case, but MM simply ignore it. I am doing the same thing with my playlist menu in the Export M3Us/Create Playlists for Child Nodes and you should do the same thing. I don't know why this is so big deal for you.
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1 / 5.4  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.7 / 4.0  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.3 / 2.2.2  Inherit Child Playlists 1.0.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: MenuItem "OnClick" event ?

Post by raybeau528 » Thu Mar 12, 2009 6:33 pm

Well I disagree. The event is called OnClick and should therefore be triggered once on a mouse click. But apparently that's not the case. Ok, so it's not an ideal world. But since that's the way it is, fine. What I did to try to work around that is still use the onclick event and whenever it got triggered I saved the playlist title to a variable. The problem I'm having is distinguishing a real mouse click from an event triggered from 'hovering'.

ZvezdanD
Posts: 3090
Joined: Thu Jun 08, 2006 7:40 pm

Re: MenuItem "OnClick" event ?

Post by ZvezdanD » Thu Mar 12, 2009 7:57 pm

Your "ideal world" is not ideal for all of us. Anyway, you should send your complains to William Henry Gates III, because he is responsible for such behavior, not MM developers. ;)

A solution is really simple, as onenonymous already explained, you should not assign OnClick event handlers to menu items which have sub-menus. Because you need to have a possibility to select such items as well, you should add one new item on the top of their sub-menus on which you could click instead. If you don't know what I am talking about, just take a look at the Send To / Playlist menu which has Add to ... item on the top of every sub-menu. I am using similar approach in my script and this works just fine.
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1 / 5.4  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.7 / 4.0  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.3 / 2.2.2  Inherit Child Playlists 1.0.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: MenuItem "OnClick" event ?

Post by raybeau528 » Thu Mar 12, 2009 8:30 pm

I did notice the "Add to" on your script but didn't quite understand how that helped - I'll look at it again more closely.
I was also thinking you could check for three situations/conditions where you could consider the OnClick valid:
1. Event triggered on a Node with no children - obvious
2. The same node (with children) was triggered twice in a row (once to expand and the second a mouse click)
3. The node was already expanded

raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: MenuItem "OnClick" event ?

Post by raybeau528 » Thu Mar 12, 2009 10:57 pm

I see why my logic is faulty - you can hover twice or more to expand the child menu items. I do understand your suggestion to push the node down to the next level and set it up as a node with no children.

raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: MenuItem "OnClick" event ?

Post by raybeau528 » Fri Mar 13, 2009 11:37 am

That did the trick. Thanks for your help!

Post Reply