diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Dialogs/CommitDialog.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Dialogs/CommitDialog.cs index 713788ec63a..d39c7735f49 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Dialogs/CommitDialog.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Dialogs/CommitDialog.cs @@ -127,6 +127,46 @@ protected override void OnResponse (Gtk.ResponseType type) protected void OnButtonCommitClicked (object sender, System.EventArgs e) { + // In case we have local unsaved files with changes, throw a dialog for the user. + System.Collections.Generic.List docList = new System.Collections.Generic.List (); + foreach (var item in IdeApp.Workbench.Documents) { + if (!item.IsDirty) + continue; + docList.Add (item); + } + + if (docList.Count != 0) { + AlertButton response = MessageService.GenericAlert ( + MonoDevelop.Ide.Gui.Stock.Question, + GettextCatalog.GetString ("You are trying to commit files which have unsaved changes."), + GettextCatalog.GetString ("Do you want to save the changes before committing?"), + new AlertButton[] { + AlertButton.Cancel, + new AlertButton ("Don't Save"), + AlertButton.Save + } + ); + + if (response == AlertButton.Cancel) + return; + + if (response == AlertButton.Save) { + // Go through all the items and save them. + foreach (var item in docList) + item.Save (); + + // Check if save failed on any item and abort. + foreach (var item in docList) + if (item.IsDirty) { + MessageService.ShowMessage (GettextCatalog.GetString ( + "Some files could not be saved. Commit operation aborted")); + return; + } + } + + docList.Clear (); + } + // Update the change set ArrayList todel = new ArrayList (); foreach (ChangeSetItem it in changeSet.Items) {