Skip to content

Prompt user with dialog if triggering open with on unsaved file - #115264

Closed
Logan Ramos (lramos15) wants to merge 2 commits into
microsoft:mainfrom
lramos15:unsavedOpenWith
Closed

Logan Ramos (lramos15) wants to merge 2 commits into
microsoft:mainfrom
lramos15:unsavedOpenWith

Conversation

@lramos15

Copy link
Copy Markdown
Member

Similar to #114947, my fork got deleted so I had to remake the PR and placing this in editor action offers a solution for both notebooks and custom editors. I would be open to other solutions as it feels weird being prompted before the quickpick is opened. I also think it is a little silly that you get prompted even if you select the same editor that you're in as we shouldn't force the user to take any action in that case.

const options = activeEditorPane.options;
const group = activeEditorPane.group;
// The current editor needs to be saved before it can be triggered with open with
if (activeInput.isDirty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this fire even if you select the default VS Code editor? Also, should it only be fired if you select a custom binary editor since a custom text editor should be able to handle this case correctly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly wondering if it should be moved into the call to openEditorWith instead after you have selected an editor but before it has actually replaced the old editor

@bpasero Benjamin Pasero (bpasero) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic of asking the user for dealing with dirty files should move into the editorOpenWith method which already contains the logic to show a picker etc. The action should simply call that method as before and let the helper deal with it. That way we ensure consistent behaviour in case the method is called from other places.

Besides, we need to make sure that the dialog is consistent with our current dialog when a file is dirty:

image

As you can see, we do not use Abort. The dialog is defined here:

async showSaveConfirm(fileNamesOrResources: (string | URI)[]): Promise<ConfirmResult> {

Ideally you could just use the same dialog for your purpose.

@bpasero

Copy link
Copy Markdown
Contributor

I have added #116272 where I feel we should cleanup editorOpenWith and move its code into respective existing files.

@bpasero

Copy link
Copy Markdown
Contributor

I believe now that with the work in #100281 you do not have to do anything special. If we end up calling IEditorService.replaceEditors, the editor group will take care of prompting the user in case the editor is dirty.

@joaomoreno
João Moreno (joaomoreno) changed the base branch from master to main February 15, 2021 08:51
@bpasero

Copy link
Copy Markdown
Contributor

My comment #115264 (comment) was wrong, but with f294b6f calling replaceEditors will now ask for each dirty editor that get's replaced what to do with it.

@lramos15

Copy link
Copy Markdown
Member Author

Closing as in theory this is obsolete now due to Ben's changes

@github-actions github-actions Bot locked and limited conversation to collaborators Apr 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants