Skip to content
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

[Question] How to programatically access New Unsaved File #17003

Closed
jongeller opened this issue Dec 9, 2016 · 10 comments
Closed

[Question] How to programatically access New Unsaved File #17003

jongeller opened this issue Dec 9, 2016 · 10 comments
Assignees
Labels
api *question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@jongeller
Copy link

Hi all, trying to get access through the vscode namespace to a new tab (unsaved) editor in the active window.

I would like to create a new document, but it needs to remain unsaved. I cannot find a way to programmatically set the content of this document while it is in a unsaved state.
I have used: commands.executeCommand("workbench.action.files.newUntitledFile") but there seems to be no way focus on that new editor window (until saved) to then add content to the document.
When I create a new temp file and open it with: workspace.openTextDocument(path) The file is already saved.

Thanks!

@mjbvz mjbvz added api *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Dec 9, 2016
@mjbvz
Copy link
Collaborator

mjbvz commented Dec 9, 2016

I believe I just answered your question over on StackOverflow

Please let me know if that is what you are looking for or if anything is unclear.

Thanks.

@mjbvz mjbvz closed this as completed Dec 9, 2016
@jongeller
Copy link
Author

@mjbvz - thanks! That is what I was looking for, I'll follow if I have any questions.

@jongeller
Copy link
Author

@mjbvz is there any way to do this without providing a path to save the unsaved file to? I'd like force the prompt for a save location when a user tries to save the file, instead of forcing one to be provided.

@jongeller
Copy link
Author

@mjbvz - just pinging again, incase this got lost over the weekend.

@mjbvz mjbvz reopened this Dec 12, 2016
@mjbvz
Copy link
Collaborator

mjbvz commented Dec 12, 2016

I'm not sure if we have a good api story for that flow.

@jrieken Do you have any thoughts on how he could accomplish this using the existing apis?

@jongeller
Copy link
Author

Just to add a bit more. Is there anyway to leverage "workbench.action.files.newUntitledFile"? I've been trying to discern what parameters may exist, but no luck yet.

@jrieken
Copy link
Member

jrieken commented Dec 13, 2016

@jongeller You can call openTextDocument with an URI using the untitled-scheme. That will create a new document, like so:

return workspace.openTextDocument(Uri.parse('untitled:c:/test/files.js').then(doc => {
	assert.equal(doc.uri.scheme, 'untitled');
	assert.ok(doc.isDirty);
});

@jrieken jrieken closed this as completed Dec 13, 2016
@jongeller
Copy link
Author

@jrieken right, which was what @mjbvz showed me over on stackoverflow, however, I was asking if it was possible to use the API to open a new tab, populate it, but not pre-set a save path. This way, on save, the user is prompted to provide a path.

@jongeller
Copy link
Author

looks like these two items were added to open issues internally and externally, but haven't been addressed in a couple months:
#12283
and
hoovercj/vscode-octo#11

@jrieken
Copy link
Member

jrieken commented Dec 13, 2016

Yes #12283 is what you want

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api *question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

3 participants