Page 1 of 1

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

Posted: Sat Apr 17, 2021 4:57 pm
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:

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

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

Thanks for your help!

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

Posted: Sun Apr 18, 2021 9:41 pm
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

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);
            aM = itm;
        if (isArray(aM)) {
            cpy = cpy.concat(aM);
        } else {
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:

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

Posted: Mon Apr 19, 2021 3:27 pm
by Milode
Hi drakinite,
thank you very much for all the tips.
I will look at the detail and try to implement the tips.

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

Posted: Tue Apr 20, 2021 8:51 am
by drakinite
Happy to help! :slight_smile: