MM4: Custom Menu Items on Treenode [#7366 #7699]

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

Moderators: Gurus, Addon Administrators

Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

MM4: Custom Menu Items on Treenode [#7366 #7699]

Post by Melloware »

OK so my MonkeyTunes has been heavily tested on MM3. I am now trying it out on MM4 alpha release to make sure my plugin is compatible from day 1.

The problem I am having is I create a custom tree node and then I added right click menu items to that tree node. The tree node IS getting created but the right click options are not. Here is my code ...

// create the menu items and tree node

Code: Select all

LOG.Debug("Adding TreeNode To TreeView");
                SDBTree tree = this.MediaMonkey.MainTree;
                TreeNodeMT = tree.CreateNode;
                TreeNodeMT.Caption = this.GetApplicationName() + " (" + ipAddress + ")";
                TreeNodeMT.IconIndex = 54;
                TreeNodeMT.CustomNodeId = MENU_MONKEYTUNES;
                TreeNodeMT.CustomDataId = MENU_MONKEYTUNES;
                tree.AddNode(tree.Node_Web, TreeNodeMT, EnumTreeNodePos.NodePos_InsertAfter);
                MediaMonkey.set_Objects(GetApplicationName(), TreeNodeMT);

                LOG.Debug("Adding MenuItems To TreeNode");
                SDBMenuItem mnuPairing = MediaMonkey.UI.AddMenuItem(MediaMonkey.UI.Menu_Pop_Tree, -1, 1);
                mnuPairing.Caption = "&Pair Device...";
                mnuPairing.IconIndex = 68;
                mnuPairing.Visible = false;
                mnuPairing.Enabled = true;
                mnuPairing.Hint = "Opens the dialog to complete pairing device";
                MediaMonkey.set_Objects(MENU_PAIRING, mnuPairing);

                SDBMenuItem mnuLogFile = MediaMonkey.UI.AddMenuItem(MediaMonkey.UI.Menu_Pop_Tree, -1, 2);
                mnuLogFile.Caption = "&View Log File...";
                mnuLogFile.IconIndex = 43;
                mnuLogFile.Visible = false;
                mnuLogFile.Enabled = true;
                mnuLogFile.Hint = "Opens the MonkeyTunes Log File in Notepad";
                MediaMonkey.set_Objects(MENU_VIEW_LOG, mnuLogFile);

                SDBMenuItem mnuRefreshCache = MediaMonkey.UI.AddMenuItem(MediaMonkey.UI.Menu_Pop_Tree, -1, 3);
                mnuRefreshCache.Caption = "&Refresh Cache";
                mnuRefreshCache.IconIndex = 6;
                mnuRefreshCache.Visible = false;
                mnuRefreshCache.Enabled = true;
                mnuRefreshCache.Hint = "Refreshes the cached objects in MonkeyTunes";
                MediaMonkey.set_Objects(MENU_REFRESH_CACHE, mnuRefreshCache);

                SDBMenuItem mnuSupport = MediaMonkey.UI.AddMenuItem(MediaMonkey.UI.Menu_Pop_Tree, -1, 4);
                mnuSupport.Caption = "&Support Forum...";
                mnuSupport.IconIndex = 34;
                mnuSupport.Visible = false;
                mnuSupport.Enabled = true;
                mnuSupport.Hint = "MonkeyTunes Support Forum";
                MediaMonkey.set_Objects(MENU_SUPPORT, mnuSupport);

                SDBMenuItem mnuWebsite = MediaMonkey.UI.AddMenuItem(MediaMonkey.UI.Menu_Pop_Tree, -1, 5);
                mnuWebsite.Caption = "&MonkeyTunes Website...";
                mnuWebsite.IconIndex = 55;
                mnuWebsite.Visible = false;
                mnuWebsite.Enabled = true;
                mnuWebsite.Hint = "MonkeyTunes Support Forum";
                MediaMonkey.set_Objects(MENU_WEBSITE, mnuWebsite);

                SDBMenuItem mnuAbout = MediaMonkey.UI.AddMenuItem(MediaMonkey.UI.Menu_Pop_Tree, -1, 6);
                mnuAbout.Caption = "&About MonkeyTunes...";
                mnuAbout.IconIndex = 44;
                mnuAbout.Visible = false;
                mnuAbout.Enabled = true;
                mnuAbout.Hint = "About MonkeyTunes";
                MediaMonkey.set_Objects(MENU_ABOUT, mnuAbout);

                MediaMonkey.OnChangedSelection += new ISDBApplicationEvents_OnChangedSelectionEventHandler(MediaMonkey_MenuVisible);
Then this event shows and hides the menu options based on the selection in the tree.

Code: Select all

/// <summary>
        /// Event Called whenever the Treeview selection is changed.
        /// </summary>
        void MediaMonkey_MenuVisible() {
            SDBTreeNode node = MediaMonkey.MainTree.CurrentNode;
            bool visible = (node.CustomNodeId == MENU_MONKEYTUNES);
            SDBMenuItem menu = (SDBMenuItem)MediaMonkey.get_Objects(MENU_VIEW_LOG);
            menu.Visible = visible;
            menu = (SDBMenuItem)MediaMonkey.get_Objects(MENU_REFRESH_CACHE);
            menu.Visible = visible;
            menu = (SDBMenuItem)MediaMonkey.get_Objects(MENU_SUPPORT);
            menu.Visible = visible;
            menu = (SDBMenuItem)MediaMonkey.get_Objects(MENU_WEBSITE);
            menu.Visible = visible;
            menu = (SDBMenuItem)MediaMonkey.get_Objects(MENU_ABOUT);
            menu.Visible = visible;
            menu = (SDBMenuItem)MediaMonkey.get_Objects(MENU_PAIRING);
            menu.Visible = visible;
        }

Anyone else having similar issues?
Last edited by Melloware on Thu Mar 24, 2011 7:13 am, edited 1 time in total.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: MM4: Custom Menu Items on Treenode

Post by Melloware »

Also I create a custom treenode underneath of my main tree node dynamically as a new iPhone or Android device is detected but that custom tree node is also not being created at runtime.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: MM4: Custom Menu Items on Treenode

Post by Melloware »

Melloware wrote:Also I create a custom treenode underneath of my main tree node dynamically as a new iPhone or Android device is detected but that custom tree node is also not being created at runtime.
OK with MM4 1355 my custom treenode is now being created underneath the main treenode like it was in MM3. My last issue is getting the menu options to show and hide.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Ludek
Posts: 5080
Joined: Fri Mar 09, 2007 9:00 am

Re: MM4: Custom Menu Items on Treenode

Post by Ludek »

I tested your MoneyTunes script from here: http://melloware.biz/download/warez/monkeytunes-mm4.zip and I see all the custom nodes (Pair Device ... About Monkey Tunes) with both skinned and skinless version (tested with build 1355)
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: MM4: Custom Menu Items on Treenode

Post by Melloware »

Ludek,

When I install MM4 1355 and run this is what the right click shows for me on the MOnkeyTunes Treenode.

Image

It should show the View Log File..., About MonkeyTunes, etc menu items.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Ludek
Posts: 5080
Joined: Fri Mar 09, 2007 9:00 am

Re: MM4: Custom Menu Items on Treenode

Post by Ludek »

You are right, I actually tested current sources instead of 1355, so it will be fixed in 1356:
Image
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: MM4: Custom Menu Items on Treenode

Post by Melloware »

Excellent! Thank you for the fix!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: [FIXED] MM4: Custom Menu Items on Treenode

Post by Melloware »

I am using 13557 and I did see my menu options once but now they are gone again.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Ludek
Posts: 5080
Joined: Fri Mar 09, 2007 9:00 am

Re: [FIXED] MM4: Custom Menu Items on Treenode

Post by Ludek »

I would like to confirm, but my MonkeyTunes has expired, please PM me if there is a cheat.
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: [FIXED] MM4: Custom Menu Items on Treenode

Post by Melloware »

Just sent you a PM....
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Peke
Posts: 18169
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: [FIXED] MM4: Custom Menu Items on Treenode

Post by Peke »

Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: MM4: Custom Menu Items on Treenode [#7366]

Post by Melloware »

Ludek, It appears to be fixed in the latest .1364 version of MM4 so thank you!

I have a new issue though reported by some users.

http://forum.melloware.com/viewtopic.php?f=16&t=9202

They report that if they don't install MM3 before installing MM4 they get a COM error when I try to add a child treenode. Could it be possibly the COM object for MM4 is missing this certain API call that happens to be in the MM3 COM API? That is why installing 3 before 4 works?

Code: Select all

2011-04-17 16:36:08,726 [ERROR] - (12) - Error filling treenode...
System.InvalidCastException: Unable to cast COM object of type 'SongsDB.SDBApplicationClass' to interface type 'SongsDB.ISDBApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{1FAF02F8-A7D3-41F1-9210-A3B12046F136}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at SongsDB.SDBApplicationClass.get_MainTree()
   at Melloware.MonkeyTunes.MonkeyTunesServer.CJynqUKX3h8mBRSYKJY(Object )
   at Melloware.MonkeyTunes.MonkeyTunesServer.Un2KIghXy(SDBTreeNode )
Here is the code where I fill the treenode:

Code: Select all

/// <summary>
        /// Event fired when the MonkeyTunes + is clicked on to expand the treeview.
        /// </summary>
        /// <param name="node">the node to fill the children for</param>
        void MediaMonkey_OnFillChildren(SDBTreeNode node) {
        	try {
        		LOG.Info("MonkeyTunes Filling Treenode");
        		SDBTree tree = this.MediaMonkey.MainTree;

        		// delete all old children
        		node.HasChildren = false;

        		foreach (KeyValuePair<string, NetService> pair in PairingServer.Services) {
        			string deviceName;
        			NetService service = pair.Value;
        			try {
        				byte[] txt = service.TXTRecordData;
        				IDictionary dict = NetService.DictionaryFromTXTRecordData(txt);
        				byte[] value = (byte[])dict["DvNm"];
        				deviceName = Encoding.UTF8.GetString(value);

        			} catch (Exception) {
        				deviceName = "Unknown Device";
        			}
        			LOG.InfoFormat("TreeNode Device Name = {0}", deviceName);
        			SDBTreeNode deviceNode = tree.CreateNode;
        			deviceNode.Caption = deviceName;
        			deviceNode.CustomData = service.Name;
        			deviceNode.IconIndex = 54;
        			deviceNode.OnNodeFocused += new ISDBTreeNodeEvents_OnNodeFocusedEventHandler(MediaMonkey_OnNodeFocused);
        			tree.AddNode(node, deviceNode, EnumTreeNodePos.NodePos_AddChildLast);
        		}
        		node.Expanded = true;
        		LOG.Info("MonkeyTunes Filled Treenode successfully");
        	} catch (Exception ex) {
        		LOG.Error("Error filling treenode...", ex);
        	}
        }
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Ludek
Posts: 5080
Joined: Fri Mar 09, 2007 9:00 am

Re: MM4: Custom Menu Items on Treenode [#7366]

Post by Ludek »

Hi,
1FAF02F8-A7D3-41F1-9210-A3B12046F136 is GUID of ISDBApplication interface (same as in MM3) so I don't see a reason why it should fail in MM4.

How did you define MediaMonkey object? Something like this:

'Dim MediaMonkey
'Set MediaMonkey = CreateObject("SongsDB.SDBApplication")
?

You can access it simply via
SDB.MainTree
and it should work
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: MM4: Custom Menu Items on Treenode [#7366]

Post by Melloware »

Yes that is what I am doing but what is really interesting is I am using the COM object fine and it only fails when calling the above method. Meaning other SDB calls are working fine so the COM object is there it is just when adding this child node it throws this error. Then when users install MM3 and then MM4 this error is corrected.

It is very strange.

I am actually passing the running COM object into my application through VBS like this.... So I create my COM .NET app and then pass the SDB instance into it. This is the only way in C# to catch the OnPlay, OnStop, events.

Code: Select all

Set monkeytunes = CreateObject("Melloware.MonkeyTunes.MonkeyTunesServer")
monkeytunes.Init(SDB)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: MM4: Custom Menu Items on Treenode [#7366]

Post by Melloware »

Another user has confirmed this. A clean MM4 install on Win 7 64 bit the COM object fails. If they install MM3 then MM4 all works...

http://forum.melloware.com/viewtopic.ph ... 294#p25293
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Post Reply