Author: ilor
Date: Wed Jul 16 00:25:29 2008
New Revision: 28048

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28048&view=rev
Log:
Editor2 quit and quit do desktop features, confirm quit message different if 
map was modified

Modified:
    trunk/data/core/editor2-hotkeys.cfg
    trunk/data/themes/editor2.cfg
    trunk/src/editor2/editor_controller.cpp
    trunk/src/editor2/editor_controller.hpp
    trunk/src/editor2/editor_main.cpp
    trunk/src/hotkeys.cpp
    trunk/src/hotkeys.hpp

Modified: trunk/data/core/editor2-hotkeys.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/editor2-hotkeys.cfg?rev=28048&r1=28047&r2=28048&view=diff
==============================================================================
--- trunk/data/core/editor2-hotkeys.cfg (original)
+++ trunk/data/core/editor2-hotkeys.cfg Wed Jul 16 00:25:29 2008
@@ -7,6 +7,13 @@
        ctrl=yes
 #endif
 #enddef
+
+[hotkey]
+       command="editor-quit-to-desktop"
+       key="q"
+       shift=yes
+       {IF_APPLE_CMD_ELSE_CTRL}
+[/hotkey]
 
 [hotkey]
        command="editor-map-save"

Modified: trunk/data/themes/editor2.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/themes/editor2.cfg?rev=28048&r1=28047&r2=28048&view=diff
==============================================================================
--- trunk/data/themes/editor2.cfg (original)
+++ trunk/data/themes/editor2.cfg Wed Jul 16 00:25:29 2008
@@ -119,7 +119,7 @@
             id=menu-editor-file
             title= _ "File"
             image=lite
-            
items=editor-map-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,preferences,editor-quit
+            
items=editor-map-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,preferences,quit,editor-quit-to-desktop
             ref=top-panel
             rect="=+3,=+1,+100,=-4"
             xanchor=fixed

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28048&r1=28047&r2=28048&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Wed Jul 16 00:25:29 2008
@@ -37,7 +37,7 @@
 : controller_base(SDL_GetTicks(), game_config, video)
 , mouse_handler_base(map_)
 , map_(editor_map::new_map(game_config, 44, 33, t_translation::GRASS_LAND))
-, gui_(NULL)
+, gui_(NULL), actions_since_save_(0), do_quit_(false), quit_mode_(EXIT_ERROR)
 {
        hotkey::deactivate_all_scopes();
        hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
@@ -87,10 +87,25 @@
        delete prefs_disp_manager_;
 }
 
-void editor_controller::main_loop()
-{
-       for(;;) {
+EXIT_STATUS editor_controller::main_loop()
+{
+       while (!do_quit_) {
                play_slice();
+       }
+       return quit_mode_;
+}
+
+void editor_controller::quit_confirm(EXIT_STATUS mode)
+{
+       std::string message = _("Do you really want to quit?");
+       if (actions_since_save_ != 0) {
+               message += " ";
+               message += _("There are unsaved changes in the map.");
+       }
+       int res = gui::dialog(gui(),_("Quit"),message,gui::YES_NO).show();
+       if (res == 0) {
+               do_quit_ = true;
+               quit_mode_ = mode;
        }
 }
 
@@ -128,6 +143,7 @@
        map_ = map;
        clear_stack(undo_stack_);
        clear_stack(redo_stack_);
+       actions_since_save_ = 0;
        refresh_all();
 }
 
@@ -146,12 +162,13 @@
                case HOTKEY_MUTE:
                case HOTKEY_PREFERENCES:
                case HOTKEY_HELP:
+               case HOTKEY_QUIT_GAME:
                        return true; //general hotkeys we can always do
                case HOTKEY_UNDO:
                        return can_undo();
                case HOTKEY_REDO:
                        return can_redo();
-               case HOTKEY_EDITOR_QUIT:
+               case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
                case HOTKEY_EDITOR_MAP_NEW:
                case HOTKEY_EDITOR_MAP_LOAD:
                case HOTKEY_EDITOR_MAP_SAVE_AS:
@@ -194,6 +211,12 @@
        SCOPE_ED;
        using namespace hotkey;
        switch (command) {
+               case HOTKEY_QUIT_GAME:
+                       quit_confirm(EXIT_NORMAL);
+                       return true;
+               case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
+                       quit_confirm(EXIT_QUIT_TO_DESKTOP);
+                       return true;
                case HOTKEY_EDITOR_TOOL_PAINT:
                        set_mouse_action(mouse_actions_["paint"]);
                        return true;
@@ -247,6 +270,13 @@
        SCOPE_ED;
        LOG_ED << "Performing action " << action.get_id() << ", actions count 
is " << action.get_instance_count() << "\n";
        editor_action* undo = action.perform(map_);
+       if (actions_since_save_ < 0) {
+               //set to a value that will make it impossible to get to zero, 
as at this point
+               //it is no longer possible to get back the original map state 
using undo/redo
+               actions_since_save_ = undo_stack_.size() + 1;
+       } else {
+               ++actions_since_save_;
+       }
        undo_stack_.push_back(undo);
        trim_stack(undo_stack_);
        clear_stack(redo_stack_);
@@ -303,12 +333,22 @@
 
 void editor_controller::undo()
 {
-       perform_action_between_stacks(undo_stack_, redo_stack_);
+       if (can_undo()) {
+               perform_action_between_stacks(undo_stack_, redo_stack_);
+               --actions_since_save_;
+       } else {
+               ERR_ED << "undo() called with an empty undo stack";
+       }
 }
 
 void editor_controller::redo()
 {
-       perform_action_between_stacks(redo_stack_, undo_stack_);
+       if (can_redo()) {
+               perform_action_between_stacks(redo_stack_, undo_stack_);
+               ++actions_since_save_;
+       } else {
+               ERR_ED << "redo() called with an empty redo stack";
+       }
 }
 
 void editor_controller::perform_action_between_stacks(action_stack& from, 
action_stack& to)

Modified: trunk/src/editor2/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28048&r1=28047&r2=28048&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Wed Jul 16 00:25:29 2008
@@ -19,6 +19,7 @@
 #include "editor_common.hpp"
 #include "editor_display.hpp"
 #include "editor_map.hpp"
+#include "editor_main.hpp"
 #include "editor_mouse_handler.hpp"
 #include "editor_mode.hpp"
 
@@ -42,7 +43,9 @@
        public:
                editor_controller(const config &game_config, CVideo& video);
                ~editor_controller();
-               void main_loop();
+               EXIT_STATUS main_loop();
+               void hotkey_quit();
+               void quit_confirm(EXIT_STATUS status);
                void load_map_dialog();
                void load_map(const std::string& filename);
                void set_map(const editor_map& map);
@@ -148,6 +151,11 @@
                 */
                static const int max_action_stack_size_;
                
+               int actions_since_save_;
+               
+               bool do_quit_;
+               EXIT_STATUS quit_mode_;
+               
                std::vector<brush> brushes_;
                std::map<std::string, mouse_action*> mouse_actions_;
 };

Modified: trunk/src/editor2/editor_main.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_main.cpp?rev=28048&r1=28047&r2=28048&view=diff
==============================================================================
--- trunk/src/editor2/editor_main.cpp (original)
+++ trunk/src/editor2/editor_main.cpp Wed Jul 16 00:25:29 2008
@@ -16,22 +16,12 @@
 #include "editor_common.hpp"
 #include "editor_controller.hpp"
 
-#include "config.hpp"
-#include "filesystem.hpp"
-#include "game_preferences.hpp"
-#include "gamestatus.hpp"
-#include "log.hpp"
-#include "wml_exception.hpp"
-#include "serialization/parser.hpp"
-#include "serialization/preprocessor.hpp"
-#include "serialization/string_utils.hpp"
 namespace editor2 {
 
 EXIT_STATUS start(config& game_conf, CVideo& video)
 {
        editor_controller editor(game_conf, video);
-       editor.main_loop();
-       return EXIT_ERROR;
+       return editor.main_loop();
 }
 
 } //end namespace editor2

Modified: trunk/src/hotkeys.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.cpp?rev=28048&r1=28047&r2=28048&view=diff
==============================================================================
--- trunk/src/hotkeys.cpp (original)
+++ trunk/src/hotkeys.cpp Wed Jul 16 00:25:29 2008
@@ -131,7 +131,7 @@
        { hotkey::HOTKEY_EDIT_UPDATE, "editupdate", N_("Update transitions"), 
true, hotkey::SCOPE_GENERAL },
 
 #ifdef USE_EDITOR2
-       { hotkey::HOTKEY_EDITOR_QUIT, "editor-quit", N_("Quit Editor"), false, 
hotkey::SCOPE_EDITOR },
+       { hotkey::HOTKEY_EDITOR_QUIT_TO_DESKTOP, "editor-quit-to-desktop", 
N_("Quit to Desktop"), false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_MAP_NEW, "editor-map-new", N_("New Map"), 
false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_MAP_LOAD, "editor-map-load", N_("Load Map"), 
false, hotkey::SCOPE_EDITOR },
        { hotkey::HOTKEY_EDITOR_MAP_SAVE, "editor-map-save", N_("Save Map"), 
false, hotkey::SCOPE_EDITOR },
@@ -198,6 +198,7 @@
 hotkey::hotkey_item null_hotkey_;
 
 const std::string scope_strings_[] = {"general", "game", "editor"};
+const std::string scope_labels_[] = {"Common", "Game", "Editor"};
 bool scope_active_[hotkey::SCOPE_COUNT] = {true, false};
 }
 
@@ -224,6 +225,11 @@
 const std::string& get_scope_string(scope s)
 {
        return scope_strings_[s];
+}
+
+const std::string& get_scope_label(scope s)
+{
+       return scope_labels_[s];
 }
 
 static void key_event_execute(display& disp, const SDL_KeyboardEvent& event, 
command_executor* executor);

Modified: trunk/src/hotkeys.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.hpp?rev=28048&r1=28047&r2=28048&view=diff
==============================================================================
--- trunk/src/hotkeys.hpp (original)
+++ trunk/src/hotkeys.hpp Wed Jul 16 00:25:29 2008
@@ -71,7 +71,7 @@
        HOTKEY_EDIT_REFRESH, HOTKEY_EDIT_UPDATE, HOTKEY_EDIT_AUTO_UPDATE,
        
 #ifdef USE_EDITOR2
-       HOTKEY_EDITOR_QUIT,
+       HOTKEY_EDITOR_QUIT_TO_DESKTOP,
        HOTKEY_EDITOR_MAP_NEW, HOTKEY_EDITOR_MAP_LOAD, HOTKEY_EDITOR_MAP_SAVE,
        HOTKEY_EDITOR_MAP_SAVE_AS, HOTKEY_EDITOR_MAP_REVERT,
        HOTKEY_EDITOR_TOOL_NEXT, HOTKEY_EDITOR_TOOL_PAINT, 
HOTKEY_EDITOR_TOOL_FILL,
@@ -103,6 +103,7 @@
 void set_scope_active(scope s, bool set = true);
 bool is_scope_active(scope s);
 const std::string& get_scope_string(scope s);
+const std::string& get_scope_label(scope s);
 
 class hotkey_item {
 public:


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to