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!
JS translation vor VBS code NodeName=SDB.MainTree.CurrentNode.Caption
Moderators: jiri, drakinite, Addon Administrators
Re: JS translation vor VBS code NodeName=SDB.MainTree.CurrentNode.Caption
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:
And you can get its name with the following:
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.
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.
- 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;
Code: Select all
node.title
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);
}
});
};
I hope this is helpful; Let me know if there's anything that needs to be clarified, or if you have any additional questions.
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Re: JS translation vor VBS code NodeName=SDB.MainTree.CurrentNode.Caption
Hi drakinite,
thank you very much for all the tips.
I will look at the detail and try to implement the tips.
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
Happy to help!
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.