Skip to content

Commit

Permalink
Added dialog box to save changes before closing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosqlbi committed Jul 23, 2016
1 parent 6e20ae8 commit d31febb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
18 changes: 10 additions & 8 deletions TabularTranslator/Translator.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions TabularTranslator/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel;

namespace TabularTranslator
{
public partial class Translator : Form
{
private ModelTranslations _modelTranslations;
private string _jsonFilename;
private bool _unsavedChanges = false;
private class Culturelist
{
public string Table { get; set; }
Expand Down Expand Up @@ -172,6 +174,7 @@ private void SaveJsonCulturesFile(ModelTranslations translations, string filenam
serializer.Formatting = Formatting.Indented;
serializer.NullValueHandling = NullValueHandling.Ignore;
serializer.Serialize(file, translations);
_unsavedChanges = false;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -382,5 +385,29 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
About about = new About();
about.ShowDialog();
}

private void dgvTranslations_CellValueChanged(object sender, DataGridViewCellEventArgs e) {
_unsavedChanges = true;
}

private void dgvTranslations_CurrentCellDirtyStateChanged(object sender, EventArgs e) {
_unsavedChanges = true;
}
protected override void OnClosing(CancelEventArgs e) {
if (_unsavedChanges) {
var confirm = MessageBox.Show("There are unsaved changes. Do you want to save them?", "Unsaved changes", MessageBoxButtons.YesNoCancel);
switch (confirm) {
case DialogResult.Yes:
SaveJsonCulturesFile(_modelTranslations, _jsonFilename);
break;
case DialogResult.No:
break;
case DialogResult.Cancel:
e.Cancel = true;
break;
}
}
base.OnClosing(e);
}
}
}

0 comments on commit d31febb

Please sign in to comment.