GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1560454-mapdir 
into lp:widelands.

Commit message:
UI improvements for saving maps:
- Maps are now saved in a "My Maps" subdirectory to prevent overwriting of 
official maps
- Show full save path to user
- After creating a new directory, enter it 
- Automatically focus map name editbox when creating new map
- Got rid of blank space in load map screen
- Made show map names/filenames button wide

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1560454 in widelands: "Editor: saving maps deletes shipped map file"
  https://bugs.launchpad.net/widelands/+bug/1560454

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1560454-mapdir/+merge/294725
-- 
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/bug-1560454-mapdir into lp:widelands.
=== modified file 'src/editor/ui_menus/main_menu_load_map.cc'
--- src/editor/ui_menus/main_menu_load_map.cc	2016-04-06 09:23:04 +0000
+++ src/editor/ui_menus/main_menu_load_map.cc	2016-05-15 10:32:12 +0000
@@ -30,7 +30,7 @@
  * Create all the buttons etc...
 */
 MainMenuLoadMap::MainMenuLoadMap(EditorInteractive& parent)
-   : MainMenuLoadOrSaveMap(parent, "load_map_menu", _("Load Map")) {
+   : MainMenuLoadOrSaveMap(parent, 1, "load_map_menu", _("Load Map")) {
 
 	table_.selected.connect(boost::bind(&MainMenuLoadMap::entry_selected, this));
 	table_.double_clicked.connect(boost::bind(&MainMenuLoadMap::clicked_ok, boost::ref(*this)));

=== modified file 'src/editor/ui_menus/main_menu_load_or_save_map.cc'
--- src/editor/ui_menus/main_menu_load_or_save_map.cc	2016-04-20 07:58:14 +0000
+++ src/editor/ui_menus/main_menu_load_or_save_map.cc	2016-05-15 10:32:12 +0000
@@ -32,8 +32,10 @@
 #include "map_io/widelands_map_loader.h"
 
 MainMenuLoadOrSaveMap::MainMenuLoadOrSaveMap(EditorInteractive& parent,
+                                             int no_of_bottom_rows,
                                              const std::string& name,
-                                             const std::string& title)
+                                             const std::string& title,
+                                             const std::string& basedir)
    : UI::Window(&parent, name, 0, 0, parent.get_inner_w() - 40, parent.get_inner_h() - 40, title),
 
      // Values for alignment and size
@@ -42,7 +44,7 @@
      tablex_(padding_),
      tabley_(buth_ + 2 * padding_),
      tablew_(get_inner_w() * 7 / 12),
-     tableh_(get_inner_h() - tabley_ - 3 * buth_ - 2 * padding_),
+     tableh_(get_inner_h() - tabley_ - (no_of_bottom_rows + 1) * buth_ - no_of_bottom_rows * padding_),
      right_column_x_(tablew_ + 2 * padding_),
      butw_((get_inner_w() - right_column_x_ - 2 * padding_) / 2),
 
@@ -68,9 +70,10 @@
              buth_,
 				 g_gr->images().get("images/ui_basic/but1.png"),
              _("Cancel")),
-     basedir_("maps"),
+     basedir_(basedir),
      has_translated_mapname_(false),
      showing_mapames_(false) {
+	g_fs->ensure_directory_exists(basedir_);
 	curdir_ = basedir_;
 
 	UI::Box* vbox = new UI::Box(this, tablex_, padding_, UI::Box::Horizontal, padding_, get_w());
@@ -78,7 +81,7 @@
 	                                "show_mapnames",
 	                                0,
 	                                0,
-	                                butw_,
+	                                2 * butw_,
 	                                buth_,
 											  g_gr->images().get("images/ui_basic/but1.png"),
 	                                _("Show Map Names"));
@@ -151,10 +154,13 @@
 	//  Fill it with all files we find.
 	FilenameSet files = g_fs->list_directory(curdir_);
 
+
 	// If we are not at the top of the map directory hierarchy (we're not talking
 	// about the absolute filesystem top!) we manually add ".."
 	if (curdir_ != basedir_) {
 		maps_data_.push_back(MapData::create_parent_dir(curdir_));
+	} else if (files.empty()) {
+		maps_data_.push_back(MapData::create_empty_dir(curdir_));
 	}
 
 	MapData::DisplayType display_type;

=== modified file 'src/editor/ui_menus/main_menu_load_or_save_map.h'
--- src/editor/ui_menus/main_menu_load_or_save_map.h	2016-04-06 09:23:04 +0000
+++ src/editor/ui_menus/main_menu_load_or_save_map.h	2016-05-15 10:32:12 +0000
@@ -34,8 +34,10 @@
 */
 struct MainMenuLoadOrSaveMap : public UI::Window {
 	MainMenuLoadOrSaveMap(EditorInteractive& parent,
+	                      int no_of_bottom_rows,
 	                      const std::string& name,
-	                      const std::string& title);
+	                      const std::string& title,
+	                      const std::string& basedir = "maps");
 
 protected:
 	virtual void clicked_ok() = 0;

=== modified file 'src/editor/ui_menus/main_menu_save_map.cc'
--- src/editor/ui_menus/main_menu_save_map.cc	2016-05-06 08:27:24 +0000
+++ src/editor/ui_menus/main_menu_save_map.cc	2016-05-15 10:32:12 +0000
@@ -49,7 +49,7 @@
 
 // TODO(GunChleoc): Arabic: Make directory dialog: buttons need more height for Arabic.
 MainMenuSaveMap::MainMenuSaveMap(EditorInteractive& parent)
-   : MainMenuLoadOrSaveMap(parent, "save_map_menu", _("Save Map")),
+   : MainMenuLoadOrSaveMap(parent, 3, "save_map_menu", _("Save Map"), "maps/My_Maps"),
 
      make_directory_(this,
                      "make_directory",
@@ -73,6 +73,11 @@
                     butw_,
                     buth_,
                     _("Filename:"),
+                    UI::Align::kLeft),
+     directory_info_(this,
+                    padding_,
+                    tabley_ + tableh_ + buth_ + 4 * padding_,
+                    (boost::format(_("Saving to: %s")) % g_fs->canonicalize_name(curdir_)).str(),
                     UI::Align::kLeft) {
 
 	// Make room for edit_options_ button
@@ -131,7 +136,7 @@
 
 	if (g_fs->is_directory(complete_filename.c_str()) &&
 		 !Widelands::WidelandsMapLoader::is_widelands_map(complete_filename)) {
-		curdir_ = complete_filename;
+		set_current_directory(complete_filename);
 		fill_table();
 	} else {  //  Ok, save this map
 		Widelands::Map& map = eia().egbase().map();
@@ -157,6 +162,7 @@
 		//  create directory
 		std::string fullname = curdir_ + g_fs->file_separator() + md.get_dirname();
 		g_fs->make_directory(fullname);
+		set_current_directory(fullname);
 		fill_table();
 	}
 }
@@ -201,7 +207,7 @@
 	assert(table_.has_selection());
 	const MapData& mapdata = maps_data_[table_.get_selected()];
 	if (mapdata.maptype == MapData::MapType::kDirectory) {
-		curdir_ = mapdata.filename;
+		set_current_directory(mapdata.filename);
 		fill_table();
 	} else {
 		clicked_ok();
@@ -216,6 +222,12 @@
 	ok_.set_enabled(!editbox_->text().empty());
 }
 
+void MainMenuSaveMap::set_current_directory(const std::string& filename) {
+	curdir_ = filename;
+	/** TRANSLATORS: The directory that a file will be saved to. */
+	directory_info_.set_text((boost::format(_("Saving to: %s")) % g_fs->canonicalize_name(curdir_)).str());
+}
+
 /**
  * Save the map in the current directory with
  * the current filename

=== modified file 'src/editor/ui_menus/main_menu_save_map.h'
--- src/editor/ui_menus/main_menu_save_map.h	2016-04-06 09:23:04 +0000
+++ src/editor/ui_menus/main_menu_save_map.h	2016-05-15 10:32:12 +0000
@@ -43,11 +43,14 @@
 	void double_clicked_item();
 	void edit_box_changed();
 
+	// Sets the current dir and updates labels.
+	void set_current_directory(const std::string& filename);
+
 	bool save_map(std::string, bool);
 
 	UI::Button make_directory_, edit_options_;
 
-	UI::Textarea editbox_label_;
+	UI::Textarea editbox_label_, directory_info_;
 	UI::EditBox* editbox_;
 };
 

=== modified file 'src/editor/ui_menus/main_menu_save_map_make_directory.cc'
--- src/editor/ui_menus/main_menu_save_map_make_directory.cc	2016-04-23 08:05:31 +0000
+++ src/editor/ui_menus/main_menu_save_map_make_directory.cc	2016-05-15 10:32:12 +0000
@@ -66,6 +66,7 @@
 						 boost::ref(*this),
 						 UI::Panel::Returncodes::kBack));
 	center_to_parent();
+	edit_.focus();
 }
 
 

=== modified file 'src/wui/mapdata.cc'
--- src/wui/mapdata.cc	2016-04-16 07:10:03 +0000
+++ src/wui/mapdata.cc	2016-05-15 10:32:12 +0000
@@ -131,11 +131,20 @@
 }
 
 // static
+MapData MapData::create_empty_dir(const std::string& current_dir) {
+	/** TRANSLATORS: Empty current folder */
+	return MapData(current_dir, (boost::format("<%s>") % _("empty")).str());
+}
+
+// static
 MapData MapData::create_directory(const std::string& directory) {
 	std::string localized_name;
 	if (boost::equals(directory, "maps/MP_Scenarios")) {
 		/** TRANSLATORS: Directory name for MP Scenarios in map selection */
 		localized_name = _("Multiplayer Scenarios");
+	} else if (boost::equals(directory, "maps/My_Maps")) {
+		/** TRANSLATORS: Directory name for user maps in map selection */
+		localized_name = _("My Maps");
 	} else {
 		localized_name = FileSystem::fs_filename(directory.c_str());
 	}

=== modified file 'src/wui/mapdata.h'
--- src/wui/mapdata.h	2016-02-06 18:58:57 +0000
+++ src/wui/mapdata.h	2016-05-15 10:32:12 +0000
@@ -89,6 +89,9 @@
 	/// Get the ".." directory
 	static MapData create_parent_dir(const std::string& current_dir);
 
+	/// To display if the directory is empty and has no parent
+	static MapData create_empty_dir(const std::string& current_dir);
+
 	/// Create a subdirectory
 	static MapData create_directory(const std::string& directory);
 

=== modified file 'src/wui/maptable.cc'
--- src/wui/maptable.cc	2016-01-29 08:37:22 +0000
+++ src/wui/maptable.cc	2016-05-15 10:32:12 +0000
@@ -34,7 +34,7 @@
 
 	/** TRANSLATORS: Column title for number of players in map list */
 	add_column(35, _("Pl."), _("Number of players"), UI::Align::kHCenter);
-	add_column(get_w() - 35 - 115, "", _("The name of the map or scenario"), UI::Align::kLeft);
+	add_column(get_w() - 35 - 115, _("Filename"), _("The name of the map or scenario"), UI::Align::kLeft);
 	add_column(115, _("Size"), _("The size of the map (Width x Height)"), UI::Align::kLeft);
 	set_sort_column(0);
 }

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to