When createing a new file, folder, class, no option to specify location
Type: Feature Request
When I create a new file, folder or class and so no. I would like to be given a prompt to select an existing location like a folder, package to create in, as well as given an option to type a new name to have a folder, package created for me.
Extension version: 0.21.1 VS Code version: Code - Insiders 1.75.0-insider (11238faea62d570d77afe6edfe05c8b732c44a2b, 2022-12-13T05:22:26.937Z) OS version: Linux x64 6.1.2-1-default Modes: Sandboxed: Yes
Steps:
CTRL+SHIFT + P Java: New Java Class (many other options)
Given a prompt to enter class name, then it just get created somewhere.
VSCode current behaviour to create a new file and folder, works like the following.
- You set focus of the location by going to the "Explorer"
- CTRL+SHIFT+P: New file | folder
The file | folder gets create in the set location.
I suggest the java project manager is context sensitive. If the Explorer has focus, follow the same behavious like vscode (for file, folder). If the focus is somewhere else, like the Editor, then provide a 2nd prompt to select or type the location as I mentioned in my original post.
There is no option to create a java package, even thought it's simply a folder. The dev then needs to type in the package syntax manually, which is a poor experience.
If the Explorer has focus, follow the same behavious like vscode (for file, folder).
When I first implement this feature, there is no way to get the focus of the File explorer, so we get the path of the current active editor and if it's a Java class, create a new class under the same package.
I suggest the java project manager is context sensitive. You can create class/paclages from the the Java Project explorer, have you tried it?

I tired using Java Project, same broken behavior. I create a package, I put click-focus from "Java Project" on the package, then tried to create a new class and interface using CTRL+SHIFT+P. Files are created in the wrong place, and I don't want to be using my mouse and right clicking.
The goal here is developer productivity.
Also it should not matter from the user's perspective what has focus, "Explorer" or "Java Projects", they should expect the same bahaviour.
There are two types of focus:
- Click focus - when you click on an item with the mouse (selected).
- Cursor focus - when you use cursor keys to nagivate
Creating a new file/class/package with CTRL+SHIFT+P, should use the "Cursor focus" for the location (frist).
If you press enter after using the cursor key to make a selection (set focus), it will expand and collapse the tree node and this is a jarring experience.
So I suggest, the coding logic should be
Use cursor focus first for location, if it doesn't exist, use "click/select focus", and then finally current location of editor file. If the API to get this information doesn't exist, you or someone needs to implement this.
The way I am working now. I use a shortcut to set focus to "Java Projects", use the cursor key to select a location and then I have another shortcut configured that when I press CTRL+N, it will do the samething as "CTRL+SHIFT+P > Java New Class".

I would just start simple with fixing this, here are my thoughts.
- User press CTRL+SHIFT > Java New Class
- User is prompted to enter class name (currently implement).
- User is then prompted to enter location.
For step 3, I just do it just like how CTRL+P work.
It will show you a list of files, but you sohuld just so a list of locations. The user can start trying to filter list of available locations and select one, or the user types in a new path which start from the root of the project.
Likewise if the user select from a list of availavle locations, they can then type a new sub-location (folder/package name), hit enter again and the new file/class etc is created there.
Later I focus on a improved "Java Projects" treeview focused functionality.
Creating a new file/class/package with CTRL+SHIFT+P, should use the "Cursor focus" for the location (first).
AFAIK, the current VS Code tree view API does not expose the capability to get the cursor focused node. Correct me if I'm wrong.