-
Notifications
You must be signed in to change notification settings - Fork 29.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Request: Function for showing an "Open File" dialog that returns the selected path #13807
Comments
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... |
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. |
@chrisdias Please provide some details about your use-case/scenario |
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:
// The explorer/context menu contribution receives the URI to the file/folder
let cmd1 = vscode.commands.registerCommand('extension.openNewInstance', (e: vscode.Uri) => {
vscode.commands.executeCommand("vscode.openFolder", e, true);
});
|
Incidentally the PowerShell extension also needs this API for project templating UI, so it'd be awesome to have this :) |
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. |
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 |
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
Unsure, it has been discussed before. But it's the same concern, having an API that restarts everything feels wrong... |
Sorry, maybe I wasn't clear. I can live with using this to reload VS Code: vscode.commands.executeCommand("vscode.openFolder", e, true); So I guess the last question is, how will an extension add or remove a root level workspace? |
Unsure, it has been discussed before. It's the same problem, when going from 0-1, 1-N a restart is required. |
This is the current proposed API: export interface OpenDialogOptions {
uri?: Uri;
openFiles?: boolean;
openFolders?: boolean;
openMany?: boolean;
}
export namespace window {
export function showOpenDialog(options: OpenDialogOptions): Thenable<Uri[]>;
} |
API is proposed, awaiting feedback, making it final in September |
Any way we could have the same for 'showSaveDialog' ? Some of my extensions need a way to save/export into new files. I'm currently using |
Yeah, I like. Will be similar to the open-api. I'll let know when I have something |
Sorry for the delay, new API looks good to me! Looking forward to trying it out. |
Yeah, looks good. This plus the save dialog would be very handy.
…On Wed, Sep 6, 2017 at 10:49 AM, David Wilson ***@***.***> wrote:
Sorry for the delay, new API looks good to me! Looking forward to trying
it out.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#13807 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFpqzfnE-xYbT0Bb_gsyOEHfWR_94wVgks5sfqL2gaJpZM4KXxQs>
.
|
I have pushed a change that also adds a save dialog export interface OpenDialogOptions {
defaultResource?: Uri;
openLabel?: string;
openFiles?: boolean;
openFolders?: boolean;
openMany?: boolean;
}
export interface SaveDialogOptions {
defaultResource?: Uri;
saveLabel?: string;
}
export namespace window {
export function showOpenDialog(options: OpenDialogOptions): Thenable<Uri[]>;
export function showSaveDialog(options: SaveDialogOptions): Thenable<Uri>;
} |
Is it easy to add a filter list for these? |
@jrieken did you intend to use SaveDialogOptions on the showSaveDialog method? Thanks for adding that one also, this is going to be really helpful! |
Doh, I am a copy&paste programmer....
Yeah, it's not there yet but the underlying electron API has it. Unsure yet how it will look like, may some sort of object like |
@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 const filepath = getPhysicalPath(d.uri);
const defaultUri = vscode.Uri.file(filepath);
const option: vscode.SaveDialogOptions = { defaultUri, filters: {} };
vscode.window.showSaveDialog( option ).then(fileUri => {
console.log(fileUri ? fileUri.toString() : 'undefined');
}); I'm on 1.17.0-insider (f7962f0) |
Hm, it works for me on master. You mean |
No, I mean I can't pre-fill the SaveDialog with a default file. |
Hum, but it works if I name it |
Yeah, Insiders is behind, the code-sign infrastructure gets an overhaul. In the stable API we have named this thing |
Thanks, sry for the false-alarm then :) |
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!
The text was updated successfully, but these errors were encountered: