use prompt for saving when moving around

This commit is contained in:
Tim Young 2017-09-19 13:19:46 -05:00
parent 005c35761c
commit 6e2661a648

View File

@ -410,6 +410,21 @@ namespace SpriteLibrary
UpdateMenu(); UpdateMenu();
} }
/// <summary>
/// Prompt to apply changes. We return true if we continue, or false if we canceled out.
/// </summary>
/// <returns></returns>
bool PromptToApplyChangesAndContinue()
{
if(ValuesDifferFromData())
{
DialogResult Answer = MessageBox.Show("You have unsaved Changes. Would you like to save them before proceeding?","Save?",MessageBoxButtons.YesNoCancel);
if (Answer == DialogResult.Yes) ApplyChanges();
if (Answer == DialogResult.Cancel) return false;
}
return true;
}
private void btnApply_Click(object sender, EventArgs e) private void btnApply_Click(object sender, EventArgs e)
{ {
ApplyChanges(); ApplyChanges();
@ -432,6 +447,8 @@ namespace SpriteLibrary
} }
private void btnFwd_Click(object sender, EventArgs e) private void btnFwd_Click(object sender, EventArgs e)
{
if (PromptToApplyChangesAndContinue())
{ {
if (SpriteInformation.Count == 0) return; //nothing to do if (SpriteInformation.Count == 0) return; //nothing to do
CurrentSIIndex++; CurrentSIIndex++;
@ -439,8 +456,11 @@ namespace SpriteLibrary
if (TempInformation == null) TempInformation = new SpriteInfo(); if (TempInformation == null) TempInformation = new SpriteInfo();
WeHaveNewItem(); WeHaveNewItem();
} }
}
private void btnBack_Click(object sender, EventArgs e) private void btnBack_Click(object sender, EventArgs e)
{
if (PromptToApplyChangesAndContinue())
{ {
if (SpriteInformation.Count == 0) return; //nothing to do if (SpriteInformation.Count == 0) return; //nothing to do
CurrentSIIndex--; CurrentSIIndex--;
@ -448,8 +468,11 @@ namespace SpriteLibrary
if (TempInformation == null) TempInformation = new SpriteInfo(); if (TempInformation == null) TempInformation = new SpriteInfo();
WeHaveNewItem(); WeHaveNewItem();
} }
}
private void btnNewSprite_Click(object sender, EventArgs e) private void btnNewSprite_Click(object sender, EventArgs e)
{
if (PromptToApplyChangesAndContinue())
{ {
TempInformation = null; TempInformation = null;
CurrentSIIndex = -1; CurrentSIIndex = -1;
@ -458,20 +481,24 @@ namespace SpriteLibrary
SpriteInformationToForm(); SpriteInformationToForm();
UpdateMenu(); UpdateMenu();
} }
}
private void btnNewAnimation_Click(object sender, EventArgs e) private void btnNewAnimation_Click(object sender, EventArgs e)
{ {
ApplyChanges(); if (PromptToApplyChangesAndContinue())
{
AnimationInfo AI = TempInformation.Animations[CurrentSIAnimation].Clone(); AnimationInfo AI = TempInformation.Animations[CurrentSIAnimation].Clone();
TempInformation.Animations.Add(AI); TempInformation.Animations.Add(AI);
CurrentSIAnimation++; CurrentSIAnimation++;
SpriteInformationToForm(); SpriteInformationToForm();
UpdateMenu(); UpdateMenu();
} }
}
private void btnAnimBack_Click(object sender, EventArgs e) private void btnAnimBack_Click(object sender, EventArgs e)
{ {
ApplyChanges(); if (PromptToApplyChangesAndContinue())
{
CurrentSIAnimation--; CurrentSIAnimation--;
if (CurrentSIAnimation < 0) if (CurrentSIAnimation < 0)
CurrentSIAnimation = TempInformation.Animations.Count - 1; CurrentSIAnimation = TempInformation.Animations.Count - 1;
@ -479,17 +506,19 @@ namespace SpriteLibrary
SpriteInformationToForm(); SpriteInformationToForm();
UpdateMenu(); UpdateMenu();
} }
}
private void btnAnimFwd_Click(object sender, EventArgs e) private void btnAnimFwd_Click(object sender, EventArgs e)
{ {
ApplyChanges(); if (PromptToApplyChangesAndContinue())
{
CurrentSIAnimation++; CurrentSIAnimation++;
if (CurrentSIAnimation >=TempInformation.Animations.Count) if (CurrentSIAnimation >= TempInformation.Animations.Count)
CurrentSIAnimation = 0; CurrentSIAnimation = 0;
SpriteInformationToForm(); SpriteInformationToForm();
UpdateMenu(); UpdateMenu();
}
} }
private void btnPreview_Click(object sender, EventArgs e) private void btnPreview_Click(object sender, EventArgs e)