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();
@ -433,63 +448,77 @@ namespace SpriteLibrary
private void btnFwd_Click(object sender, EventArgs e) private void btnFwd_Click(object sender, EventArgs e)
{ {
if (SpriteInformation.Count == 0) return; //nothing to do if (PromptToApplyChangesAndContinue())
CurrentSIIndex++; {
if (CurrentSIIndex >= SpriteInformation.Count) CurrentSIIndex = 0; if (SpriteInformation.Count == 0) return; //nothing to do
if (TempInformation == null) TempInformation = new SpriteInfo(); CurrentSIIndex++;
WeHaveNewItem(); if (CurrentSIIndex >= SpriteInformation.Count) CurrentSIIndex = 0;
if (TempInformation == null) TempInformation = new SpriteInfo();
WeHaveNewItem();
}
} }
private void btnBack_Click(object sender, EventArgs e) private void btnBack_Click(object sender, EventArgs e)
{ {
if (SpriteInformation.Count == 0) return; //nothing to do if (PromptToApplyChangesAndContinue())
CurrentSIIndex--; {
if (CurrentSIIndex < 0) CurrentSIIndex = SpriteInformation.Count - 1; if (SpriteInformation.Count == 0) return; //nothing to do
if (TempInformation == null) TempInformation = new SpriteInfo(); CurrentSIIndex--;
WeHaveNewItem(); if (CurrentSIIndex < 0) CurrentSIIndex = SpriteInformation.Count - 1;
if (TempInformation == null) TempInformation = new SpriteInfo();
WeHaveNewItem();
}
} }
private void btnNewSprite_Click(object sender, EventArgs e) private void btnNewSprite_Click(object sender, EventArgs e)
{ {
TempInformation = null; if (PromptToApplyChangesAndContinue())
CurrentSIIndex = -1; {
TempInformation = null;
CurrentSIIndex = -1;
SetUpEmptyInfo(); SetUpEmptyInfo();
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(); {
TempInformation.Animations.Add(AI); AnimationInfo AI = TempInformation.Animations[CurrentSIAnimation].Clone();
CurrentSIAnimation++; TempInformation.Animations.Add(AI);
SpriteInformationToForm(); CurrentSIAnimation++;
UpdateMenu(); SpriteInformationToForm();
UpdateMenu();
}
} }
private void btnAnimBack_Click(object sender, EventArgs e) private void btnAnimBack_Click(object sender, EventArgs e)
{ {
ApplyChanges(); if (PromptToApplyChangesAndContinue())
CurrentSIAnimation--; {
if (CurrentSIAnimation < 0) CurrentSIAnimation--;
CurrentSIAnimation = TempInformation.Animations.Count - 1; if (CurrentSIAnimation < 0)
CurrentSIAnimation = TempInformation.Animations.Count - 1;
SpriteInformationToForm(); SpriteInformationToForm();
UpdateMenu(); UpdateMenu();
}
} }
private void btnAnimFwd_Click(object sender, EventArgs e) private void btnAnimFwd_Click(object sender, EventArgs e)
{ {
ApplyChanges(); if (PromptToApplyChangesAndContinue())
CurrentSIAnimation++; {
if (CurrentSIAnimation >=TempInformation.Animations.Count) CurrentSIAnimation++;
CurrentSIAnimation = 0; if (CurrentSIAnimation >= TempInformation.Animations.Count)
CurrentSIAnimation = 0;
SpriteInformationToForm();
UpdateMenu();
SpriteInformationToForm();
UpdateMenu();
}
} }
private void btnPreview_Click(object sender, EventArgs e) private void btnPreview_Click(object sender, EventArgs e)