Add confirm dialog when deleting replay file

This commit is contained in:
Benau 2016-02-14 13:52:16 +08:00
parent 52b3d533f5
commit 4ea6ea8ea6
3 changed files with 38 additions and 9 deletions

View File

@ -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<GhostReplaySelection*>(GUIEngine::getCurrentScreen())
->onDeleteReplay(fn);
return GUIEngine::EVENT_BLOCK;
}
else if (selection == "back")

View File

@ -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

View File

@ -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<GhostReplaySelection>,
public GUIEngine::IListWidgetHeaderListener
public GUIEngine::IListWidgetHeaderListener,
public MessageDialog::IConfirmDialogListener
{
friend class GUIEngine::ScreenSingleton<GhostReplaySelection>;
@ -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