Filename is now correctly remembered on load and save as
This commit is contained in:
parent
344c5abf78
commit
098f213586
5 changed files with 21 additions and 10 deletions
|
@ -254,9 +254,10 @@ void map_editor::edit_new_map() {
|
|||
}
|
||||
|
||||
void map_editor::edit_load_map() {
|
||||
const std::string map = load_map_dialog(gui_, changed_since_save());
|
||||
std::string fn = "";
|
||||
const std::string map = load_map_dialog(gui_, changed_since_save(), fn);
|
||||
if (map != "") {
|
||||
throw new_map_exception(map);
|
||||
throw new_map_exception(map, fn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -678,6 +679,9 @@ bool map_editor::save_map(const std::string fn, const bool display_confirmation)
|
|||
if (filename == "") {
|
||||
filename = filename_;
|
||||
}
|
||||
else {
|
||||
filename_ = filename;
|
||||
}
|
||||
try {
|
||||
write_file(filename, map_.write());
|
||||
num_operations_since_save_ = 0;
|
||||
|
|
|
@ -131,8 +131,10 @@ public:
|
|||
|
||||
// Exception thrown when new map is to be loaded.
|
||||
struct new_map_exception {
|
||||
new_map_exception(const std::string &new_map) : new_map_(new_map) {}
|
||||
const std::string new_map_;
|
||||
new_map_exception(const std::string &map, const std::string filename="")
|
||||
: new_map(map), new_filename(filename) {}
|
||||
const std::string new_map;
|
||||
const std::string new_filename;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
@ -211,7 +211,8 @@ std::string new_map_dialog(display& disp, gamemap::TERRAIN fill_terrain,
|
|||
}
|
||||
|
||||
|
||||
std::string load_map_dialog(display &disp, bool confirmation_needed) {
|
||||
std::string load_map_dialog(display &disp, bool confirmation_needed,
|
||||
std::string &loaded_file) {
|
||||
const std::string system_path = game_config::path + "/data/maps/";
|
||||
|
||||
std::vector<std::string> files;
|
||||
|
@ -273,6 +274,7 @@ std::string load_map_dialog(display &disp, bool confirmation_needed) {
|
|||
&& !confirm_modification_disposal(disp)) {
|
||||
return "";
|
||||
}
|
||||
loaded_file = filename;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include "../config.hpp"
|
||||
#include "../map.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
#ifndef EDITOR_DIALOGS_H_INCLUDED
|
||||
#define EDITOR_DIALOGS_H_INCLUDED
|
||||
|
||||
|
@ -37,8 +39,10 @@ std::string new_map_dialog(display &disp, gamemap::TERRAIN fill_terrain,
|
|||
/// confirmation_needed is true, the user will be asked if she wants to
|
||||
/// continue even though the changes to the current map is lost. Return
|
||||
/// the string representation of the map that is loaded, or the empty
|
||||
/// string if none was.
|
||||
std::string load_map_dialog(display &disp, bool confirmation_needed);
|
||||
/// string if none was and the filename. loaded_file will be set to the
|
||||
/// filename loaded if the load succeeded.
|
||||
std::string load_map_dialog(display &disp, bool confirmation_needed,
|
||||
std::string &loaded_file);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -101,9 +101,8 @@ int main(int argc, char** argv)
|
|||
done = true;
|
||||
}
|
||||
catch (map_editor::map_editor::new_map_exception &e) {
|
||||
std::cerr << "new map " << e.new_map_ << std::endl;
|
||||
mapdata = e.new_map_;
|
||||
filename = "";
|
||||
mapdata = e.new_map;
|
||||
filename = e.new_filename;
|
||||
}
|
||||
catch (gamemap::incorrect_format_exception) {
|
||||
std::cerr << "The map is not in a correct format, sorry." << std::endl;
|
||||
|
|
Loading…
Add table
Reference in a new issue