Added a prompt when you try to close GuiMetaDataEd with unsaved changes.

This commit is contained in:
Aloshi 2014-05-14 20:05:34 -05:00
parent f8355ef8b3
commit b8ebbc84bb
3 changed files with 43 additions and 16 deletions

View file

@ -9,7 +9,7 @@ MetaDataDecl gameDecls[] = {
{"image", MD_IMAGE_PATH, "", false, "image", "enter path to image"},
{"thumbnail", MD_IMAGE_PATH, "", false, "thumbnail", "enter path to thumbnail"},
{"rating", MD_RATING, "0", false, "rating", "enter rating"},
{"releasedate", MD_DATE, "0", false, "release date", "enter release date"},
{"releasedate", MD_DATE, "not-a-date-time", false, "release date", "enter release date"},
{"developer", MD_STRING, "unknown", false, "developer", "enter game developer"},
{"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher"},
{"genre", MD_STRING, "unknown", false, "genre", "enter game genre"},

View file

@ -195,15 +195,41 @@ void GuiMetaDataEd::fetchDone(const ScraperSearchResult& result)
}
}
void GuiMetaDataEd::close()
{
// find out if the user made any changes
bool dirty = false;
for(unsigned int i = 0; i < mEditors.size(); i++)
{
const std::string& key = mMetaDataDecl.at(i).key;
if(mMetaData->get(key) != mEditors.at(i)->getValue())
{
dirty = true;
break;
}
}
if(dirty)
{
// changes were made, ask if the user wants to save them
mWindow->pushGui(new GuiMsgBox(mWindow,
"SAVE CHANGES?",
"YES", [&] { save(); delete this; },
"NO", [&] { delete this; }
));
}else{
delete this;
}
}
bool GuiMetaDataEd::input(InputConfig* config, Input input)
{
if(GuiComponent::input(config, input))
return true;
if(input.value != 0 && config->isMappedTo("b", input))
if(input.value != 0 && (config->isMappedTo("b", input) || config->isMappedTo("start", input)))
{
delete this;
close();
return true;
}
@ -213,7 +239,7 @@ bool GuiMetaDataEd::input(InputConfig* config, Input input)
std::vector<HelpPrompt> GuiMetaDataEd::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "discard"));
prompts.push_back(HelpPrompt("b", "close"));
prompts.push_back(HelpPrompt("start", "close"));
return prompts;
}

View file

@ -21,6 +21,7 @@ private:
void save();
void fetch();
void fetchDone(const ScraperSearchResult& result);
void close();
NinePatchComponent mBackground;
ComponentGrid mGrid;