Moved rom deletion to gamelist, fixed halt on removal.

This commit is contained in:
Brent Atkinson 2015-01-12 15:06:11 -05:00
parent c8d62cf881
commit 196449e5c3
4 changed files with 25 additions and 4 deletions

View file

@ -75,10 +75,7 @@ void GuiGamelistOptions::openMetaDataEd()
p.system = file->getSystem();
mWindow->pushGui(new GuiMetaDataEd(mWindow, &file->metadata, file->metadata.getMDD(), p, file->getPath().filename().string(),
std::bind(&IGameListView::onFileChanged, getGamelist(), file, FILE_METADATA_CHANGED), [this, file] {
boost::filesystem::remove(file->getPath()); //actually delete the file on the filesystem
file->getParent()->removeChild(file); //unlink it so list repopulations triggered from onFileChanged won't see it
getGamelist()->onFileChanged(file, FILE_REMOVED); //tell the view
delete file; //free it
getGamelist()->remove(file);
}));
}

View file

@ -86,6 +86,28 @@ void BasicGameListView::launch(FileData* game)
ViewController::get()->launch(game);
}
void BasicGameListView::remove(FileData *game)
{
boost::filesystem::remove(game->getPath()); // actually delete the file on the filesystem
if (getCursor() == game) // Select next element in list, or prev if none
{
std::vector<FileData*> siblings = game->getParent()->getChildren();
auto gameIter = std::find(siblings.begin(), siblings.end(), game);
auto gamePos = std::distance(siblings.begin(), gameIter);
if (gameIter != siblings.end())
{
if ((gamePos + 1) < siblings.size())
{
setCursor(siblings.at(gamePos + 1));
} else if ((gamePos - 1) > 0) {
setCursor(siblings.at(gamePos - 1));
}
}
}
delete game; // remove before repopulating (removes from parent)
onFileChanged(game, FILE_REMOVED); // update the view, with game removed
}
std::vector<HelpPrompt> BasicGameListView::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;

View file

@ -23,6 +23,7 @@ public:
protected:
virtual void populateList(const std::vector<FileData*>& files) override;
virtual void launch(FileData* game) override;
virtual void remove(FileData* game) override;
TextListComponent<FileData*> mList;
};

View file

@ -32,6 +32,7 @@ public:
virtual void setCursor(FileData*) = 0;
virtual bool input(InputConfig* config, Input input) override;
virtual void remove(FileData* game) = 0;
virtual const char* getName() const = 0;