Getting TreeItem as command parameter

Trying to build my first extension and running into some issues, but here I’ll look at a specific one.

I’ve built a rudimentary sidebar view to list some data, and each item is going to be assigned the same command. What I’d like to be able to do is receive the TreeItem (or some identifying piece of data) in the command so that I can operate on it, but I don’t seem to be able to do that. All I’ve done is register the command with nova.commands.register() and specified the command name in getTreeItem using item.command = "".

The documentation doesn’t mention any other way to assign this command, but am I missing something? How do you retrieve the selected TreeItem when running a command?

Hey I’ve been working on a sidebar extension too. If you create your extension using the sidebar template you would have had this in there already:

nova.commands.register("mysidebar.remove", () => {
    // Invoked when the "remove" header button is clicked
    let selection = treeView.selection;
    console.log("Remove: " + selection.map((e) => e.name));
});

It’s the let selection = treeView.selection; that gets the currently selected treeitem, where treeView is what you set new TreeView("mysidebar") to.

Let me know if you have other questions, I’ve been figuring out a lot of stuff about treeviews in the past few weeks.

1 Like

Fantastic, that’s just what I needed. I’m just finding my way through the API and getting there slowly, so thanks for this.