Skip to content

Commit 197a469

Browse files
authored
Merge pull request #2065 from mrkubax10/add_confirmation_message
Show confirmation message when deleting level or world
2 parents 68efb75 + 8bf8254 commit 197a469

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

src/supertux/menu/editor_delete_level_menu.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "supertux/menu/editor_delete_level_menu.hpp"
1818
#include <physfs.h>
19+
#include <boost/format.hpp>
1920
#include "supertux/levelset.hpp"
2021
#include "supertux/level_parser.hpp"
2122
#include "supertux/level.hpp"
@@ -27,6 +28,7 @@
2728
#include "gui/dialog.hpp"
2829
EditorDeleteLevelMenu::EditorDeleteLevelMenu(std::unique_ptr<Levelset>& levelset, EditorLevelSelectMenu* level_select_menu, EditorLevelsetSelectMenu* levelset_select_menu) :
2930
m_level_full_paths(),
31+
m_level_names(),
3032
m_level_select_menu(level_select_menu),
3133
m_levelset_select_menu(levelset_select_menu)
3234
{
@@ -37,7 +39,9 @@ EditorDeleteLevelMenu::EditorDeleteLevelMenu(std::unique_ptr<Levelset>& levelset
3739
std::string filename = levelset->get_level_filename(i);
3840
std::string fullpath = FileSystem::join(Editor::current()->get_world()->get_basedir(),filename);
3941
m_level_full_paths.push_back(fullpath);
40-
add_entry(i, LevelParser::get_level_name(fullpath));
42+
const std::string& level_name = LevelParser::get_level_name(fullpath);
43+
m_level_names.push_back(level_name);
44+
add_entry(i, level_name);
4145
}
4246
add_hl();
4347
add_back(_("Back"));
@@ -53,12 +57,15 @@ EditorDeleteLevelMenu::menu_action(MenuItem& item)
5357
Dialog::show_message(_("You cannot delete level that you are editing!"));
5458
else
5559
{
56-
PHYSFS_delete(m_level_full_paths[id].c_str());
57-
delete_item(id + 2);
58-
m_level_full_paths.erase(m_level_full_paths.begin() + id);
59-
m_level_select_menu->reload_menu();
60-
if (!Editor::current()->is_level_loaded())
61-
m_levelset_select_menu->reload_menu();
60+
Dialog::show_confirmation(str(boost::format(_("You are about to delete level \"%s\". Are you sure?")) % m_level_names[id]), [this, id]()
61+
{
62+
PHYSFS_delete(m_level_full_paths[id].c_str());
63+
delete_item(id + 2);
64+
m_level_full_paths.erase(m_level_full_paths.begin() + id);
65+
m_level_select_menu->reload_menu();
66+
if (!Editor::current()->is_level_loaded())
67+
m_levelset_select_menu->reload_menu();
68+
});
6269
}
6370
}
6471
}

src/supertux/menu/editor_delete_level_menu.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class EditorDeleteLevelMenu final : public Menu
2121
{
2222
private:
2323
std::vector<std::string> m_level_full_paths;
24+
std::vector<std::string> m_level_names;
2425
EditorLevelSelectMenu* m_level_select_menu;
2526
EditorLevelsetSelectMenu* m_levelset_select_menu;
2627
public:

src/supertux/menu/editor_delete_levelset_menu.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
#include "supertux/menu/editor_delete_levelset_menu.hpp"
18-
18+
#include <boost/format.hpp>
1919
#include "editor/editor.hpp"
2020
#include "gui/dialog.hpp"
2121
#include "physfs/util.hpp"
@@ -25,7 +25,8 @@
2525
#include "util/log.hpp"
2626

2727
EditorDeleteLevelsetMenu::EditorDeleteLevelsetMenu(EditorLevelsetSelectMenu* editor_levelset_select_menu) :
28-
m_editor_levelset_select_menu(editor_levelset_select_menu)
28+
m_editor_levelset_select_menu(editor_levelset_select_menu),
29+
m_world_names()
2930
{
3031
refresh();
3132
}
@@ -57,6 +58,7 @@ EditorDeleteLevelsetMenu::refresh()
5758
{
5859
continue;
5960
}
61+
m_world_names.push_back(title);
6062
add_entry(i++, title);
6163
}
6264

@@ -69,17 +71,19 @@ void
6971
EditorDeleteLevelsetMenu::menu_action(MenuItem& item)
7072
{
7173
int id = item.get_id();
72-
74+
const auto& contrib_worlds = m_editor_levelset_select_menu->get_contrib_worlds();
7375
if (id >= 0)
7476
{
75-
std::vector<std::string>& contrib_worlds = m_editor_levelset_select_menu->get_contrib_worlds();
7677
if (Editor::is_active() && Editor::current()->get_world() && Editor::current()->get_world()->get_basedir() == contrib_worlds[id])
7778
Dialog::show_message(_("You cannot delete the world that you are editing"));
7879
else
7980
{
80-
physfsutil::remove_with_content(contrib_worlds[id]);
81-
m_editor_levelset_select_menu->reload_menu();
82-
refresh();
81+
Dialog::show_confirmation(str(boost::format(_("You are about to delete world \"%s\". Are you sure?")) % m_world_names[id]), [this, id, &contrib_worlds]()
82+
{
83+
physfsutil::remove_with_content(contrib_worlds[id]);
84+
m_editor_levelset_select_menu->reload_menu();
85+
refresh();
86+
});
8387
}
8488
}
8589
}

src/supertux/menu/editor_delete_levelset_menu.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class EditorDeleteLevelsetMenu final : public Menu
3232

3333
private:
3434
EditorLevelsetSelectMenu* m_editor_levelset_select_menu;
35+
std::vector<std::string> m_world_names;
3536

3637
private:
3738
EditorDeleteLevelsetMenu(const EditorDeleteLevelsetMenu&) = delete;

0 commit comments

Comments
 (0)