belkiss / niftyplugins

Simple Perforce integration for Visual Studio 2017 to 2022
MIT License
24 stars 4 forks source link

Feature request: don't save/edit unchanged files #41

Open calonx opened 2 years ago

calonx commented 2 years ago

On Friday I accidentally hit Save on an unmodified document (not even open for edit) and wound up triggering a local rebuild of a decently sized codebase. Any chance we could have the extension bail on saving/editing if there are no pending changes? Or at least an option for enabling this behavior?

Thanks for your effort in offering up this extension! Pre-VS2022, I've just hobbled along with my own homebrew VS extension. That's no longer necessary now that I've got this one. 😁

belkiss commented 2 years ago

Heya! Thanks for the kind words :)

The save part is handled by Visual Studio, we only hook ourselves to the OnBeforeSave event and do a p4 edit beforehand (if you use auto-checkout on save, which is default in this niftyperforce fork).

Afaik, if you trigger a manual save on a specific file (by ctrl+s for instance), then it'll always do the save. We could theoretically skip the p4 edit part, but the write attempt will still occur, and succeed if the file is read-write. And in case the file is still checked in and read-only, you'll get a file write error popup, which isn't great...

Note that the "Save all" should already do what you want, only save dirty files.

calonx commented 2 years ago

Aha! I suppose my homebrew extension was set up as a wholesale replacement for Edit.Save, meant to be bound directly to Ctrl+S. As such, it was the thing calling dte.ActiveDocument.Save() under the right conditions. Side-note: when switching to VS2022, I attempted to port my extension but got stuck in the weeds and abandoned the effort.

I'd be happy to share my approach, but it seems at odds with how this extension is set up. Maybe I'll clone your repo and try my hand at injecting such a feature...

belkiss commented 2 years ago

Ah ok. I guess if we made it a real VCS plugin in Visual Studio, it'd be possible to completely cancel the edit, but I'm not sure it'd be a good move, as Visual tend to do a lot of queries to the VCS plugin, and that would probably slow down the IDE.

Out of curiosity, what roadblock did you meet when porting your own extension to vs2022?