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:
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.
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]
var node = qid('mediaTree').controlClass.dataSource.focusedNode;
[/code]
And you can get its name with the following:
[code]
node.title
[/code]
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]
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);
}
});
};
[/code]
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: