You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
API Request: Function for showing an "Open File" dialog that returns the selected path #13807
Is it possible to add an API function which allows an extension to show an "Open File" dialog which doesn't cause VS Code to open the selected file but instead returns the file path? I'd like to allow the user to easily pick the location of a PowerShell executable to use for their editing session.
I've looked around for a while to find a way to do this without the need for a new API but couldn't find a solution. If you know of a better method, I'd be more than happy to use that :)
Thanks!
Reacted by Denilson das Mercês Amorim, Yusen, Keith Hill, Samuel Magnan, Ed Mackey, Jarrio, Dmytro Kyrychuk, Yassine MADDOURI, Jonas B. Andersen, defr0std and 5 more
I'd like this feature as well. I'm writing an extension that wants to allow the user to select a binary file on disk (one that wouldn't normally open in vscode) and encode it into a data-uri string, and embed it into the current text document. So, I need a "file open" dialog that returns the full path & filename.
In a nutshell, I want to be able to write an extension that will scaffold out a "new project". I want to prompt the user for a new folder, I'll then scaffold code into that folder, and then I will (re) open Code on that folder, or add as a new root folder.
So, I need:
An API that let's me prompt for a new folder
An API for opening or reopening VS Code on a folder. To accomplish this today, I have to invoke the vscode.openFolder command, see the awesome open new instance extension:
// The explorer/context menu contribution receives the URI to the file/folderletcmd1=vscode.commands.registerCommand('extension.openNewInstance',(e: vscode.Uri)=>{vscode.commands.executeCommand("vscode.openFolder",e,true);});
An API for adding a new root level work space folder
Ok, you want a lot more then a file picker dialog. Step by step...
An API that let's me prompt for a new folder
I assume that is outside the current workspace folders and you'd expect the native OS file picker, right? It's unclear to me if picking a file inside the workspace should use our Cmd+P picker... In general there are a few options to this but nothing dramatic.
An API for opening or reopening VS Code on a folder. To accomplish this today, I have to invoke the vscode.openFolder command, see the awesome open new instance extension:
That is a lot more and I am not sure the implication are clear to everyone here. When we open a new or different folder a different extension host comes to life and your current extension host might be shut down (when replacing the current window). In any case you won't be able to talk to that "other" extension host.
An API for adding a new root level work space folder
Similar to above. For API-stability reasons we restart the extension host when going from 0-1, 1-N, (1-0, N-1) workspace folders. That also means that your extension is getting restarted and that you need to keep your state somewhere else.
I assume that is outside the current workspace folder
Yes, that would be my general expectation where the user would pick. However, it seems reasonable that they could pick a folder inside the workspace. Whether or not I reload the workbench seems to be something that is then up to the extension author.
you'd expect the native OS file picker
Yes, very much. I want the easy ability to switch drives, add a new folder, etc. all provided by the OS pickers today.
your current extension host might be shut down
In my scenario I'm perfectly fine with this.
I can live with using the vscode.openFolder command for now, but having a real API for this feels cleaner. For adding a new root level workspace folder i'm assuming there will be a similar vscode.addFolderToWorkspace command I could leverage?
Yes, very much. I want the easy ability to switch drives, add a new folder, etc. all provided by the OS pickers today.
Check, it's pretty much exposing what electron offers to us
I can live with using the vscode.openFolder command for now, but having a real API for this feels cleaner.
Yes and no. To some extend command identifiers are API because folks reference them from the keybindings.json-file and therefore shouldn't change. When exposing this via blessed API I am afraid that people will be confused about the lifecycle... It's rare that you call an method (other than exit) to shutdown yourself.
For adding a new root level workspace folder i'm assuming there will be a similar vscode.addFolderToWorkspace command I could leverage?
Unsure, it has been discussed before. But it's the same concern, having an API that restarts everything feels wrong...
Although, maybe i'm doing something wrong, but I can't get a SaveDialog with anything other dans 'Untitled' in the Save As input box (on Mac). Even with a valid defaultUri.
Yeah, Insiders is behind, the code-sign infrastructure gets an overhaul. In the stable API we have named this thing defaultUri instead of defaultResource but that change was yesterday...
Activity
RainingChain commentedon Mar 5, 2017
So is there any way to do that right now?
Only way I found is to tell the user to open the file and place it in the second column. Then I can get the file with this code:
I'm sure there's a cleaner way to do this...
emackey commentedon Apr 12, 2017
I'd like this feature as well. I'm writing an extension that wants to allow the user to select a binary file on disk (one that wouldn't normally open in vscode) and encode it into a data-uri string, and embed it into the current text document. So, I need a "file open" dialog that returns the full path & filename.
jrieken commentedon Aug 15, 2017
Chris Dias (@chrisdias) Please provide some details about your use-case/scenario
chrisdias commentedon Aug 17, 2017
In a nutshell, I want to be able to write an extension that will scaffold out a "new project". I want to prompt the user for a new folder, I'll then scaffold code into that folder, and then I will (re) open Code on that folder, or add as a new root folder.
So, I need:
An API that let's me prompt for a new folder
An API for opening or reopening VS Code on a folder. To accomplish this today, I have to invoke the
vscode.openFoldercommand, see the awesome open new instance extension:daviwil commentedon Aug 17, 2017
Incidentally the PowerShell extension also needs this API for project templating UI, so it'd be awesome to have this :)
jrieken commentedon Aug 17, 2017
Ok, you want a lot more then a file picker dialog. Step by step...
I assume that is outside the current workspace folders and you'd expect the native OS file picker, right? It's unclear to me if picking a file inside the workspace should use our Cmd+P picker... In general there are a few options to this but nothing dramatic.
That is a lot more and I am not sure the implication are clear to everyone here. When we open a new or different folder a different extension host comes to life and your current extension host might be shut down (when replacing the current window). In any case you won't be able to talk to that "other" extension host.
Similar to above. For API-stability reasons we restart the extension host when going from 0-1, 1-N, (1-0, N-1) workspace folders. That also means that your extension is getting restarted and that you need to keep your state somewhere else.
chrisdias commentedon Aug 17, 2017
Yes, that would be my general expectation where the user would pick. However, it seems reasonable that they could pick a folder inside the workspace. Whether or not I reload the workbench seems to be something that is then up to the extension author.
Yes, very much. I want the easy ability to switch drives, add a new folder, etc. all provided by the OS pickers today.
In my scenario I'm perfectly fine with this.
I can live with using the
vscode.openFoldercommand for now, but having a real API for this feels cleaner. For adding a new root level workspace folder i'm assuming there will be a similarvscode.addFolderToWorkspacecommand I could leverage?jrieken commentedon Aug 18, 2017
Check, it's pretty much exposing what electron offers to us
Yes and no. To some extend command identifiers are API because folks reference them from the
keybindings.json-file and therefore shouldn't change. When exposing this via blessed API I am afraid that people will be confused about the lifecycle... It's rare that you call an method (other thanexit) to shutdown yourself.Unsure, it has been discussed before. But it's the same concern, having an API that restarts everything feels wrong...
chrisdias commentedon Aug 18, 2017
Sorry, maybe I wasn't clear. I can live with using this to reload VS Code:
So I guess the last question is, how will an extension add or remove a root level workspace?
jrieken commentedon Aug 21, 2017
Unsure, it has been discussed before. It's the same problem, when going from 0-1, 1-N a restart is required.
first cut of option-less open, #13807
15 remaining items
fix save dialog options, #13807
add filters, #13807
add jsdoc, #13807
one more comment #13807
move open/save api into stable api, #13807
stef-levesque commentedon Sep 22, 2017
Johannes Rieken (@jrieken) thanks for the feature 👍
Although, maybe i'm doing something wrong, but I can't get a SaveDialog with anything other dans 'Untitled' in the
Save Asinput box (on Mac). Even with a validdefaultUri.I'm on 1.17.0-insider (f7962f0)
jrieken commentedon Sep 22, 2017
Hm, it works for me on master. You mean
undefinedis always the result instead of a meaning fullfileUri?stef-levesque commentedon Sep 22, 2017
No, I mean I can't pre-fill the SaveDialog with a default file.
stef-levesque commentedon Sep 22, 2017
Hum, but it works if I name it
defaultResource. The Insider might be more behind that I though of...jrieken commentedon Sep 22, 2017
Yeah, Insiders is behind, the code-sign infrastructure gets an overhaul. In the stable API we have named this thing
defaultUriinstead of defaultResource but that change was yesterday...stef-levesque commentedon Sep 22, 2017
Thanks, sry for the false-alarm then :)