Improve usability of F5 in editor.

Now auto save all opened maps and reopen them after the cache reloading.

Note that, if not named yet, it names them window_N, to prevent
interupting save dialogs (where window_0 is the first one, etc.. as in
editor menu)
This commit is contained in:
Ali El Gariani 2010-09-17 18:56:03 +00:00
parent f9b21ca7ae
commit 2f91fe43c9
2 changed files with 37 additions and 6 deletions

View file

@ -45,6 +45,10 @@
#include <boost/bind.hpp>
namespace {
static std::vector<std::string> saved_windows_;
}
namespace editor {
/**
@ -327,8 +331,16 @@ int editor_controller::add_map_context(map_context* mc)
void editor_controller::create_default_context()
{
map_context* mc = new map_context(editor_map(game_config_, 44, 33, t_translation::GRASS_LAND));
add_map_context(mc);
if(saved_windows_.empty()) {
map_context* mc = new map_context(editor_map(game_config_, 44, 33, t_translation::GRASS_LAND));
add_map_context(mc);
} else {
foreach(const std::string& filename, saved_windows_) {
map_context* mc = new map_context(game_config_, filename);
add_map_context(mc);
}
saved_windows_.clear();
}
}
void editor_controller::close_current_context()
@ -613,11 +625,22 @@ void editor_controller::resize_map_dialog()
}
}
void editor_controller::save_all_maps()
void editor_controller::save_all_maps(bool auto_save_windows)
{
int current = current_context_index_;
saved_windows_.clear();
for(size_t i = 0; i < map_contexts_.size(); ++i) {
switch_context(i);
std::string name = get_map_context().get_filename();
if(auto_save_windows) {
if(name.empty() || is_directory(name)) {
std::ostringstream s;
s << default_dir_ << "/" << "window_" << i;
name = s.str();
get_map_context().set_filename(name);
}
}
saved_windows_.push_back(name);
save_map();
}
switch_context(current);
@ -937,7 +960,7 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
quit_confirm(EXIT_QUIT_TO_DESKTOP);
return true;
case TITLE_SCREEN__RELOAD_WML:
save_all_maps();
save_all_maps(true);
do_quit_ = true;
quit_mode_ = EXIT_RELOAD_DATA;
return true;

View file

@ -122,7 +122,10 @@ class editor_controller : public controller_base,
*/
int add_map_context(map_context* mc);
/** Creates a default map context object, used to ensure there is always at least one. */
/**
* Creates a default map context object, used to ensure there is always at least one.
* Except when we saved windows, in which case reopen them
*/
void create_default_context();
/** Closes the active map context. Switches to a valid context afterward or creates a dummy one. */
@ -155,7 +158,12 @@ class editor_controller : public controller_base,
/** Display a load map dialog and process user input. */
void resize_map_dialog();
void save_all_maps();
/**
* Save all maps, open dialog if not named yet, except when using
* auto_save_windows which will name unnamed maps "windows_N".
* Also record all filenames for future reopening.
*/
void save_all_maps(bool auto_save_windows = false);
/** Save the map, open dialog if not named yet. */
void save_map();