JS translation vor VBS code NodeName=SDB.MainTree.CurrentNode.Caption

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

Milode
Posts: 2
Joined: Sat Apr 17, 2021 1:36 pm

JS translation vor VBS code NodeName=SDB.MainTree.CurrentNode.Caption

Post by Milode »

Unfortunately I have little experience in programming, but I really want to translate a VB script for MM5.
For the JS I need the implementation for the following VBS section to determine the node name (playlist name) of the selected node in the item tree:

Dim SDB
Set SDB = CreateObject("SongsDB.SDBApplication")
Dim NodeName
NodeName=SDB.MainTree.CurrentNode.Caption

Second question, how can I make the script in the right click menu over the item tree.

Thanks for your help!
drakinite
Posts: 498
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: JS translation vor VBS code NodeName=SDB.MainTree.CurrentNode.Caption

Post by drakinite »

You can explore how the MediaTree operates from within controls/mediaTree.js.

- You can get the currently focused node via '(mediaTree).dataSource.focusedNode' ("mediaTree" is in parentheses because it's not a global variable; more on that in a second.)
- For any "control", you can access the JS object from its HTML element via "(HTML element).controlClass"
- The main media tree is an HTML element with the attribute 'data-id="mediaTree"', and you can query the document for `data-id` via the `qid` command. So to get the HTML element corresponding to the main media tree, you do 'qid("mediaTree")'.
- Putting all this together, you can grab the currently selected node with the following JS statement:

Code: Select all

var node = qid('mediaTree').controlClass.dataSource.focusedNode;
And you can get its name with the following:

Code: Select all

node.title
For your second question, you can find how it works inside viewHandlers.js, where it defines window.nodeUtils._getNodeMenu (around line 3,075). The right-click menu for nodes (on the media tree) is defined there.
This bit of code below checks for the corresponding nodeHandler's "menuAddons", and goes through each item and adds them to the menu list.

Code: Select all

if (handler.menuAddons) {
    forEach(handler.menuAddons, function (itm) {
        var aM;
        if (isFunction(itm))
            aM = itm(node);
        else
            aM = itm;
        if (isArray(aM)) {
            cpy = cpy.concat(aM);
        } else {
            cpy.push(aM);
        }
    });
};
A good example of how to create additional menu items for a media tree node is inside Scripts/exportPlaylists/viewHandlers_add.js. In this case, it adds an "Export playlists" menu item to any Playlist nodes. You can see all of the different nodeHandlers by examining the global "nodeHandlers" variable in the Chromium devtools. Additionally, to see an example of how menu items are formatted, take a look at the global "menus.tracklistMenuItems" variable.

I hope this is helpful; Let me know if there's anything that needs to be clarified, or if you have any additional questions. :slight_smile:
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
Milode
Posts: 2
Joined: Sat Apr 17, 2021 1:36 pm

Re: JS translation vor VBS code NodeName=SDB.MainTree.CurrentNode.Caption

Post by Milode »

Hi drakinite,
thank you very much for all the tips.
I will look at the detail and try to implement the tips.
drakinite
Posts: 498
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: JS translation vor VBS code NodeName=SDB.MainTree.CurrentNode.Caption

Post by drakinite »

Happy to help! :slight_smile:
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
Post Reply