SideBarTools icon indicating copy to clipboard operation
SideBarTools copied to clipboard

"New file" command

Open mandx opened this issue 1 year ago • 8 comments

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: image 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. image

mandx avatar Jul 19 '22 20:07 mandx

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.

braver avatar Jul 20 '22 09:07 braver

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!

mandx avatar Jul 20 '22 15:07 mandx

The change so far:

image

image

mandx avatar Jul 20 '22 19:07 mandx

LGTM. I'll give it a final test run and then merge 🚢

braver avatar Jul 25 '22 18:07 braver

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.

braver avatar Jul 25 '22 18:07 braver

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.

braver avatar Jul 25 '22 18:07 braver

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.

mandx avatar Jul 25 '22 19:07 mandx

Pretty awesome! 💪🏻

braver avatar Aug 02 '22 18:08 braver

Let's ship it!

braver avatar Aug 06 '22 10:08 braver