On choosing files and folders

I want to write a Sidebar extension that lets you bookmark any file or folder in your project, and expand/collapse/open them in the extension’s sidebar.

Problem 1: It seems the only way for a user to provide a file or especially a folder to a command is to use nova.workspace.showFileChooser(). It would be very nice if we could put commands in the contextual menu of Files sidebar items, but that doesn’t seem to be an option.

Problem 2: showFileChooser doesn’t seem to actually allow you to choose folders. No matter what combination of other options I try, specifying allowDirectories: true doesn’t put the macOS file picker in the mode that lets you return folders; it’s always in the mode where clicking the OK button with a folder selected navigates into the folder, and with nothing selected the OK button is grayed out.

Would love some pointers toward workarounds or even telling me I’m badly missing something.

1 Like

Response 1: Yes, this is currently not supported. We could consider adding an extension point for file sidebar items, though!

Response 2: It appears our documentation is incorrect. The property is allowFolders, not allowDirectories. I will update the documentation.

1 Like

Ahh, thank you! And yes, consider this a request for that extension point. You could also just Sherlock me and allow multiple project folders in the main Files sidebar if you wanted :sweat_smile:

Another possible showFileChooser issue: The paths it returns aren’t normalized. It returns a path like


…while for instance nova.workspace.path returns

/Volumes/Macintosh HD/Users/lheidbreder/Documents/Workspaces/Bookmarks.novaextension

. If this is on purpose for some reason then that’s cool, since the nova.path.normalize function exists. But perhaps it would be better for it to be normalized by default? I dunno.

This just happens to not normalize the paths currently, as it wasn’t taken into consideration for this API. We can consider making it do so!

I’ve run into issues with /Volumes/Macintosh HD/ a few times. My main problem is that I generally need to strip it, but can’t really guarantee the name of the volume, if someone’s on a custom setup. I think the most reliable thing is to split by /, remove those bits, and rejoin the path. I’d really like it if path.normalize handled either consistently adding it or removing it for me, though.