Merge pull request #28 from joolswills/fix-halt-on-delete

Moved rom deletion to gamelist, fixed halt on removal.
This commit is contained in:
Jools Wills 2016-01-31 19:10:18 +00:00
commit e7cba01be1
4 changed files with 25 additions and 4 deletions

View file

@ -76,10 +76,7 @@ void GuiGamelistOptions::openMetaDataEd()
p.system = file->getSystem(); p.system = file->getSystem();
mWindow->pushGui(new GuiMetaDataEd(mWindow, &file->metadata, file->metadata.getMDD(), p, file->getPath().filename().string(), 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] { std::bind(&IGameListView::onFileChanged, getGamelist(), file, FILE_METADATA_CHANGED), [this, file] {
boost::filesystem::remove(file->getPath()); //actually delete the file on the filesystem getGamelist()->remove(file);
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
})); }));
} }

View file

@ -86,6 +86,28 @@ void BasicGameListView::launch(FileData* game)
ViewController::get()->launch(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> BasicGameListView::getHelpPrompts()
{ {
std::vector<HelpPrompt> prompts; std::vector<HelpPrompt> prompts;

View file

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

View file

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