1 /*
2  * Copyright (C) 2002-2020 by the Widelands Development Team
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19 
20 #ifndef WL_EDITOR_UI_MENUS_MAIN_MENU_SAVE_MAP_H
21 #define WL_EDITOR_UI_MENUS_MAIN_MENU_SAVE_MAP_H
22 
23 #include <memory>
24 
25 #include "editor/editorinteractive.h"
26 #include "editor/ui_menus/main_menu_load_or_save_map.h"
27 #include "editor/ui_menus/main_menu_map_options.h"
28 #include "logic/note_map_options.h"
29 #include "ui_basic/button.h"
30 #include "ui_basic/editbox.h"
31 #include "ui_basic/textarea.h"
32 
33 /**
34  * Choose a filename and save your brand new created map
35  */
36 struct MainMenuSaveMap : public MainMenuLoadOrSaveMap {
37 	explicit MainMenuSaveMap(EditorInteractive& parent,
38 	                         UI::UniqueWindow::Registry& registry,
39 	                         UI::UniqueWindow::Registry& map_options_registry);
40 
41 protected:
42 	// Sets the current dir and updates labels.
43 	void set_current_directory(const std::string& filename) override;
44 	void layout() override;
45 
46 private:
47 	EditorInteractive& eia();
48 	Registry& map_options_registry_;
49 
50 	void clicked_ok() override;
51 	void clicked_make_directory();
52 	void clicked_edit_options();
53 	void clicked_item();
54 	void double_clicked_item();
55 	void edit_box_changed();
56 	/// Resets the map's filename in the editbox. If mapname didn't change, die().
57 	void reset_editbox_or_die(const std::string& current_filename);
58 
59 	void update_map_options();
60 
61 	bool save_map(std::string, bool);
62 
63 	UI::Button edit_options_;
64 
65 	UI::Textarea editbox_label_;
66 	UI::EditBox editbox_;
67 	UI::Button make_directory_;
68 
69 	const std::string illegal_filename_tooltip_;
70 
71 	std::unique_ptr<Notifications::Subscriber<NoteMapOptions>> subscriber_;
72 };
73 
74 #endif  // end of include guard: WL_EDITOR_UI_MENUS_MAIN_MENU_SAVE_MAP_H
75