From 4ea6ea8ea6025183569e309d7540db99632f987e Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 14 Feb 2016 13:52:16 +0800 Subject: [PATCH] Add confirm dialog when deleting replay file --- .../dialogs/ghost_replay_info_dialog.cpp | 9 ++++--- src/states_screens/ghost_replay_selection.cpp | 25 ++++++++++++++++++- src/states_screens/ghost_replay_selection.hpp | 13 +++++++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/states_screens/dialogs/ghost_replay_info_dialog.cpp b/src/states_screens/dialogs/ghost_replay_info_dialog.cpp index 8428dcb51..36380340e 100644 --- a/src/states_screens/dialogs/ghost_replay_info_dialog.cpp +++ b/src/states_screens/dialogs/ghost_replay_info_dialog.cpp @@ -79,10 +79,11 @@ GUIEngine::EventPropagation } else if(selection == "remove") { - m_self_destroy = true; - if (!file_manager - ->removeFile(file_manager->getReplayDir() + m_rd.m_filename)) - Log::warn("GhostReplayInfoDialog", "Failed to delete file."); + std::string fn = m_rd.m_filename; + ModalDialog::dismiss(); + + dynamic_cast(GUIEngine::getCurrentScreen()) + ->onDeleteReplay(fn); return GUIEngine::EVENT_BLOCK; } else if (selection == "back") diff --git a/src/states_screens/ghost_replay_selection.cpp b/src/states_screens/ghost_replay_selection.cpp index ac9b6b319..5a86ee52c 100644 --- a/src/states_screens/ghost_replay_selection.cpp +++ b/src/states_screens/ghost_replay_selection.cpp @@ -20,11 +20,13 @@ #include "replay/replay_play.hpp" #include "states_screens/dialogs/ghost_replay_info_dialog.hpp" +#include "states_screens/state_manager.hpp" #include "tracks/track.hpp" #include "tracks/track_manager.hpp" -#include "states_screens/state_manager.hpp" #include "utils/translation.hpp" +using namespace GUIEngine; + DEFINE_SCREEN_SINGLETON( GhostReplaySelection ); // ---------------------------------------------------------------------------- @@ -32,6 +34,7 @@ DEFINE_SCREEN_SINGLETON( GhostReplaySelection ); */ GhostReplaySelection::GhostReplaySelection() : Screen("ghost_replay_selection.stkgui") { + m_file_to_be_deleted = ""; } // GhostReplaySelection // ---------------------------------------------------------------------------- @@ -139,3 +142,23 @@ void GhostReplaySelection::eventCallback(GUIEngine::Widget* widget, } // click on replay file } // eventCallback + +// ---------------------------------------------------------------------------- +void GhostReplaySelection::onDeleteReplay(std::string& filename) +{ + m_file_to_be_deleted = filename; + new MessageDialog( _("Are you sure you want to remove '%s'?", + m_file_to_be_deleted.c_str()), MessageDialog::MESSAGE_DIALOG_CONFIRM, + this, false); +} // onDeleteReplay + +// ---------------------------------------------------------------------------- +void GhostReplaySelection::onConfirm() +{ + if (!file_manager + ->removeFile(file_manager->getReplayDir() + m_file_to_be_deleted)) + Log::warn("GhostReplayInfoDialog", "Failed to delete file."); + + ModalDialog::dismiss(); + GhostReplaySelection::getInstance()->refresh(); +} // onConfirm diff --git a/src/states_screens/ghost_replay_selection.hpp b/src/states_screens/ghost_replay_selection.hpp index a2fe0720f..b1795c519 100644 --- a/src/states_screens/ghost_replay_selection.hpp +++ b/src/states_screens/ghost_replay_selection.hpp @@ -21,6 +21,7 @@ #include "guiengine/screen.hpp" #include "guiengine/widgets.hpp" +#include "states_screens/dialogs/message_dialog.hpp" namespace GUIEngine { class Widget; } @@ -30,7 +31,8 @@ namespace GUIEngine { class Widget; } */ class GhostReplaySelection : public GUIEngine::Screen, public GUIEngine::ScreenSingleton, - public GUIEngine::IListWidgetHeaderListener + public GUIEngine::IListWidgetHeaderListener, + public MessageDialog::IConfirmDialogListener { friend class GUIEngine::ScreenSingleton; @@ -39,7 +41,8 @@ private: GhostReplaySelection(); ~GhostReplaySelection(); - GUIEngine::ListWidget * m_replay_list_widget; + GUIEngine::ListWidget* m_replay_list_widget; + std::string m_file_to_be_deleted; public: @@ -48,6 +51,8 @@ public: /** Load the addons into the main list.*/ void loadList(); + void onDeleteReplay(std::string& filename); + /** \brief implement callback from parent class GUIEngine::Screen */ virtual void loadedFromFile() OVERRIDE; @@ -64,8 +69,8 @@ public: virtual void tearDown() OVERRIDE {}; - /** \brief implement callback from parent class GUIEngine::Screen */ - virtual void onUpdate(float dt) OVERRIDE {}; + /** \brief Implement IConfirmDialogListener callback */ + virtual void onConfirm() OVERRIDE; }; // GhostReplaySelection