SideBarTools
SideBarTools copied to clipboard
"New file" command
This commands allows file creation anywhere in the filesystem and it will attempt to create all the subdirectories needed to realize the path.
The command will attempt to check if the file exists already and exit early if that's the case; otherwise no other checks are performed: if the operation fails for any reason, a status_message
is emitted with the contents of the error/exception.
Not quite what's in #40, but IMO it's a good starting point. This is how it looks like in my environment: When entering a filename, the full path is editable, but initially, the filename (basename+extension) is pre-selected so one can just start typing to create an empty file (and possibly new directories) in the selected directory.
Nifty. Normally I would defer to either existing functionality (but this clearly is more powerful) or existing packages (but AdvancedNewFile is a bit bloated, old and seemingly unmaintained... not a promising situation).
The command will attempt to check if the file exists already and exit early if that's the case;
I haven't tested yet but would assume that we open the new file as soon as it is created. If the file already exists we could flash a message ("Opening existing file") and open the file.
I haven't tested yet but would assume that we open the new file as soon as it is created.
Yes, that's what it does
If the file already exists we could flash a message ("Opening existing file") and open the file.
It doesn't do that right now, but it's actually a very easy change!
The change so far:
LGTM. I'll give it a final test run and then merge 🚢
Idea:
If you right-click a file in the sidebar, or have file opened and run from the command palette, we could seed the dialog with the selected file instead of "New file". Especially when you right-click a file it feels like that would make sense.
Idea:
If you right-click a file in the sidebar, or have file opened and run from the command palette, we could seed the dialog with the selected file instead of "New file". Especially when you right-click a file it feels like that would make sense.
Huh, I suggested as much in #40:
If the active view has a file name, suggest the new file to be have the same name. Just like the "Move" command we could pre-select the filename so it's easy to change. This is a good starting point for creating e.g. another file of the same type, and it's super easy to create the file in any of the parent directories.
If the active view has a file name, suggest the new file to be have the same name. Just like the "Move" command we could pre-select the filename so it's easy to change. This is a good starting point for creating e.g. another file of the same type, and it's super easy to create the file in any of the parent directories.
Done! I'm also detecting when "New..." was used on a directory, so in this case, the input panel will have the generic New file.txt
path, now the difference is in the selection, when the command is used under a directory, the whole New file.txt
text is selected (including the extension), but if it's used on an existing file, that file's name is used, but the selection will contain only the basename, the extension will be not be pre-selected.
Pretty awesome! 💪🏻
Let's ship it!