← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1696063-editor-save-map into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1696063-editor-save-map into lp:widelands.

Commit message:
Fixed keyboard navigation with escape and enter for save map and save game screens. If the editbox is focused, eccape will reset the text if changed, and close the window if unchanged.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1696063 in widelands: "Bugs in Save Map window"
  https://bugs.launchpad.net/widelands/+bug/1696063

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1696063-editor-save-map/+merge/345375
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1696063-editor-save-map into lp:widelands.
=== modified file 'src/editor/ui_menus/main_menu_save_map.cc'
--- src/editor/ui_menus/main_menu_save_map.cc	2018-04-07 16:59:00 +0000
+++ src/editor/ui_menus/main_menu_save_map.cc	2018-05-10 17:19:23 +0000
@@ -78,18 +78,23 @@
 	table_.selected.connect(boost::bind(&MainMenuSaveMap::clicked_item, boost::ref(*this)));
 	table_.double_clicked.connect(
 	   boost::bind(&MainMenuSaveMap::double_clicked_item, boost::ref(*this)));
+	table_.cancel.connect(boost::bind(&MainMenuSaveMap::die, this));
+	table_.set_can_focus(true);
 
 	editbox_ =
 	   new UI::EditBox(this, editbox_label_.get_x() + editbox_label_.get_w() + padding_,
 	                   editbox_label_.get_y(), tablew_ - editbox_label_.get_w() - padding_ + 1,
 	                   buth_, 2, g_gr->images().get("images/ui_basic/but1.png"));
-
 	editbox_->set_text(parent.egbase().map().get_name());
+
 	editbox_->changed.connect(boost::bind(&MainMenuSaveMap::edit_box_changed, this));
 	edit_box_changed();
+	editbox_->ok.connect(boost::bind(&MainMenuSaveMap::clicked_ok, boost::ref(*this)));
+	editbox_->cancel.connect(boost::bind(&MainMenuSaveMap::reset_editbox_or_die, boost::ref(*this), parent.egbase().map().get_name()));
 
 	ok_.sigclicked.connect(boost::bind(&MainMenuSaveMap::clicked_ok, boost::ref(*this)));
 	cancel_.sigclicked.connect(boost::bind(&MainMenuSaveMap::die, boost::ref(*this)));
+
 	make_directory_.sigclicked.connect(
 	   boost::bind(&MainMenuSaveMap::clicked_make_directory, boost::ref(*this)));
 	edit_options_.sigclicked.connect(
@@ -139,6 +144,8 @@
 		}
 		if (save_map(filename, !g_options.pull_section("global").get_bool("nozip", false))) {
 			die();
+		} else {
+			table_.focus();
 		}
 	}
 }
@@ -217,6 +224,14 @@
 	ok_.set_enabled(LayeredFileSystem::is_legal_filename(editbox_->text()));
 }
 
+void MainMenuSaveMap::reset_editbox_or_die(const std::string& current_filename) {
+	if (editbox_->text() == current_filename) {
+		die();
+	} else {
+		editbox_->set_text(current_filename);
+	}
+}
+
 void MainMenuSaveMap::set_current_directory(const std::string& filename) {
 	curdir_ = filename;
 	directory_info_.set_text(
@@ -253,7 +268,7 @@
 		    FileSystem::fs_filename(filename.c_str()))
 		      .str();
 		UI::WLMessageBox mbox(
-		   &eia(), _("Error Saving Map!"), s, UI::WLMessageBox::MBoxType::kOkCancel);
+		   this, _("Error Saving Map!"), s, UI::WLMessageBox::MBoxType::kOkCancel);
 		if (mbox.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kBack)
 			return false;
 	}

=== modified file 'src/editor/ui_menus/main_menu_save_map.h'
--- src/editor/ui_menus/main_menu_save_map.h	2018-04-07 16:59:00 +0000
+++ src/editor/ui_menus/main_menu_save_map.h	2018-05-10 17:19:23 +0000
@@ -46,6 +46,8 @@
 	void clicked_item();
 	void double_clicked_item();
 	void edit_box_changed();
+	/// Resets the map's filename in the editbox. If mapname didn't change, die().
+	void reset_editbox_or_die(const std::string& current_filename);
 
 	bool save_map(std::string, bool);
 

=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc	2018-05-02 07:02:18 +0000
+++ src/ui_basic/table.cc	2018-05-10 17:19:23 +0000
@@ -330,6 +330,21 @@
 bool Table<void*>::handle_key(bool down, SDL_Keysym code) {
 	if (down) {
 		switch (code.sym) {
+		case SDLK_ESCAPE:
+			cancel();
+			return true;
+
+		case SDLK_TAB:
+			// Let the panel handle the tab key
+			return get_parent()->handle_key(true, code);
+
+		case SDLK_KP_ENTER:
+		case SDLK_RETURN:
+			if (selection_ != no_selection_index()) {
+				double_clicked(selection_);
+			}
+			return true;
+
 		case SDLK_a:
 			if (is_multiselect_ && (code.mod & KMOD_CTRL) && !empty()) {
 				multiselect_.clear();

=== modified file 'src/ui_basic/table.h'
--- src/ui_basic/table.h	2018-05-02 07:02:18 +0000
+++ src/ui_basic/table.h	2018-05-10 17:19:23 +0000
@@ -62,6 +62,7 @@
 	      TableRows rowtype = TableRows::kSingle);
 	~Table();
 
+	boost::signals2::signal<void()> cancel;
 	boost::signals2::signal<void(uint32_t)> selected;
 	boost::signals2::signal<void(uint32_t)> double_clicked;
 
@@ -122,7 +123,7 @@
 	void draw(RenderTarget&);
 	bool handle_mousepress(uint8_t btn, int32_t x, int32_t y);
 	bool handle_mousewheel(uint32_t which, int32_t x, int32_t y);
-	virtual bool handle_key(bool down, SDL_Keysym code);
+	bool handle_key(bool down, SDL_Keysym code);
 };
 
 template <> class Table<void*> : public Panel {
@@ -179,6 +180,7 @@
 	 */
 	using CompareFn = boost::function<bool(uint32_t, uint32_t)>;
 
+	boost::signals2::signal<void()> cancel;
 	boost::signals2::signal<void(uint32_t)> selected;
 	boost::signals2::signal<void(uint32_t)> double_clicked;
 

=== modified file 'src/wui/game_main_menu_save_game.cc'
--- src/wui/game_main_menu_save_game.cc	2018-04-07 16:59:00 +0000
+++ src/wui/game_main_menu_save_game.cc	2018-05-10 17:19:23 +0000
@@ -106,12 +106,14 @@
 
 	filename_editbox_.changed.connect(boost::bind(&GameMainMenuSaveGame::edit_box_changed, this));
 	filename_editbox_.ok.connect(boost::bind(&GameMainMenuSaveGame::ok, this));
+	filename_editbox_.cancel.connect(boost::bind(&GameMainMenuSaveGame::reset_editbox_or_die, this, parent.game().save_handler().get_cur_filename()));
 
 	ok_.sigclicked.connect(boost::bind(&GameMainMenuSaveGame::ok, this));
 	cancel_.sigclicked.connect(boost::bind(&GameMainMenuSaveGame::die, this));
 
 	load_or_save_.table().selected.connect(boost::bind(&GameMainMenuSaveGame::entry_selected, this));
 	load_or_save_.table().double_clicked.connect(boost::bind(&GameMainMenuSaveGame::ok, this));
+	load_or_save_.table().cancel.connect(boost::bind(&GameMainMenuSaveGame::die, this));
 
 	load_or_save_.fill_table();
 	load_or_save_.select_by_name(parent.game().save_handler().get_cur_filename());
@@ -147,6 +149,15 @@
 	load_or_save_.clear_selections();
 }
 
+void GameMainMenuSaveGame::reset_editbox_or_die(const std::string& current_filename) {
+	if (filename_editbox_.text() == current_filename) {
+		die();
+	} else {
+		filename_editbox_.set_text(current_filename);
+		load_or_save_.select_by_name(current_filename);
+	}
+}
+
 static void dosave(InteractiveGameBase& igbase, const std::string& complete_filename) {
 	Widelands::Game& game = igbase.game();
 

=== modified file 'src/wui/game_main_menu_save_game.h'
--- src/wui/game_main_menu_save_game.h	2018-04-07 16:59:00 +0000
+++ src/wui/game_main_menu_save_game.h	2018-05-10 17:19:23 +0000
@@ -54,6 +54,8 @@
 
 	/// Update buttons and table selection state
 	void edit_box_changed();
+	/// Resets the savegame's name in the editbox. If savegame name didn't change, die().
+	void reset_editbox_or_die(const std::string& current_filename);
 
 	/// Called when the OK button is clicked or the Return key pressed in the edit box.
 	void ok();
@@ -77,9 +79,6 @@
 	UI::Button cancel_, ok_;
 
 	std::string curdir_;
-	std::string parentdir_;
-	std::string filename_;
-	bool overwrite_;
 };
 
 #endif  // end of include guard: WL_WUI_GAME_MAIN_MENU_SAVE_GAME_H


Follow ups