Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Bug 512 - Autosave open files when committing. #328

Merged
merged 2 commits into from Jul 11, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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<Document> docList = new System.Collections.Generic.List<Document> ();
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 ();
Copy link
Member

Choose a reason for hiding this comment

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

You should check if IsDirty==false after saving. In some cases the save command may fail (for example, if the save would overwrite changes done outside MD). If a save fails, you should show a message to the user and cancel the commit.


// 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) {
Expand Down