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

Restart without saving #1

Open
justcla opened this issue Apr 14, 2017 · 13 comments
Open

Restart without saving #1

justcla opened this issue Apr 14, 2017 · 13 comments

Comments

@justcla
Copy link

justcla commented Apr 14, 2017

Please give me the option to Restart VS without having to Save All.
Thanks

@yannduran
Copy link
Member

I'm actually having a hard time understand this request. What use case is there where you'd not want to save your work before a restart?

Visual Studio will ask you about unsaved files if I don't automatically save them for you?

@justcla
Copy link
Author

justcla commented Apr 14, 2017

The same scenarios when you'd want to close VS without saving your files or solution.
That's why VS asks if you want to save.
In my case, I often open VS, experiment with some changes, maybe add files to a solution, then decide I don't want to keep those changes, and I want to restart VS to give my solution a good reload, while also configuring extensions I might have just installed.

If Visual Studio will ask about unsaved files anyway, then that sounds like a perfect solution. Can we just let it fall back to prompting for save if/only if VS deems it necessary?

@yannduran
Copy link
Member

OK. Thanks for the explanation Justin. I don't work that way, so I couldn't see why someone would want their documents not to be saved. :-)

I'm certainly happy to add an option to not automatically save, but to err on the side of caution for most people I'd rather have the auto-save be on by default. But that should be fine for you right, as you turn it off once and that's it. And you'd be able to change it back it you change your mind :-P

@justcla
Copy link
Author

justcla commented Apr 14, 2017

Sure. That would be fine.

But couldn't you just remove it altogether?
Doesn't Visual Studio automatically prompt to save all? And it shows you what you'll be saving too.
If we can fall back to normal VS save prompt, that would be ideal. No options required.

@yannduran yannduran self-assigned this Apr 15, 2017
@yannduran
Copy link
Member

As we discussed offline, an option to auto-save or not auto-save will allow people to choose which behavior they want.

I actually wish all 'new and improved' features that Microsoft add would have an option to turn it off!

It was my original intention to add this option, but I forgot to add it to the backlog and forgot about it.

@justcla
Copy link
Author

justcla commented Apr 15, 2017

If we can check for unsaved changes and only offer a restart confirmation box if there are no unsaved changes, then VS will handle the Yes/No/Cancel case when there are unsaved files/projects/solution and will show what items need to be saved.

@yannduran
Copy link
Member

The restart confirmation box will remain, with or without auto-saving. They are two separate things.

The restart confirmation dialog is to prevent accidentally clicking on the Restart button (which I've actually done myself) and setting off an unintended restart..

@justcla
Copy link
Author

justcla commented Apr 15, 2017

The built-in Visual Studio box acts as a confirm box.
Yes/No/Cancel

@yannduran
Copy link
Member

If the auto-save option is enabled the user will never see the built-in dialog.

@justcla
Copy link
Author

justcla commented Apr 15, 2017

That's not good for anyone, right?

@justcla
Copy link
Author

justcla commented Apr 18, 2017

Here's how we can detect if there are any unsaved changes:

(Courtesy of Ryan Molden)
The RDT should contain ALL items that can be edited and are dirty in the IDE.
This code should work (Caveat: Outlook written):

`
using Microsoft.VisualStudio.Shell;

RunningDocumentTable rdt = new RunningDocumentTable(this); // assuming this is an IServiceProvider, such as a Package, or ServiceProvider.GlobalProvider
foreach(RunningDocumentInfo rdi in rdt.Where((r) => r.IsDocumentInitialized))
{
var pdd2 = rdi.DocData as IVsPersistDocData2;
if(pdd2 != null)
{
int dirty = 0;
if(ErrorHandler.Succeeded(ppd2.IsDocDataDirty(out dirty)) && dirty != 0)
{
// this item is dirty and will be prompted for a save
}
}
}

// If we get here no items in the RDT were dirty, there should be no save prompt
`

@justcla
Copy link
Author

justcla commented Apr 18, 2017

And a further tip:

"You should use IVsRunningDocumentTable3.IsDocumentDirty, so you could still enumerate as below but instead of using IVsPersistDocData2 you probably want to call IVsRunningDocumentTable3.IsDocumentDirty passing in the cookie from the RunningDocumentInfo inside the foreach loop. It returns a bool.

AFAIK I is EVERY file/artifact that is open in VS and considered dirty and in need of save. It is how the save dialog is constructed on solution close."

@justcla
Copy link
Author

justcla commented Apr 18, 2017

More advice:
Walk RDT.GetRunningDocumentsEnum and check the dirty flag on each doc. Make sure to skip the doc if the RDT_PendingInitialization flag is set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants