Author: ilor
Date: Sun Jul 13 23:12:58 2008
New Revision: 28022
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28022&view=rev
Log:
wire in undo/redo. Note that there's an issue with mouseup doing actions twice,
and undo fill is broken.
Modified:
trunk/data/themes/editor2.cfg
trunk/src/controller_base.cpp
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/editor_controller.hpp
Modified: trunk/data/themes/editor2.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/themes/editor2.cfg?rev=28022&r1=28021&r2=28022&view=diff
==============================================================================
--- trunk/data/themes/editor2.cfg (original)
+++ trunk/data/themes/editor2.cfg Sun Jul 13 23:12:58 2008
@@ -130,7 +130,7 @@
id=menu-editor-edit
title= _ "Edit"
image=lite
-
items=editor-undo,editor-redo,editor-cut,editor-copy,editor-paste,editor-select-all,editor-selection-rotate,editor-selection-flip,editor-selection-generate,editor-selection-randomize
+
items=undo,redo,editor-cut,editor-copy,editor-paste,editor-select-all,editor-selection-rotate,editor-selection-flip,editor-selection-generate,editor-selection-randomize
rect="+2,=,+100,="
xanchor=fixed
yanchor=fixed
Modified: trunk/src/controller_base.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/controller_base.cpp?rev=28022&r1=28021&r2=28022&view=diff
==============================================================================
--- trunk/src/controller_base.cpp (original)
+++ trunk/src/controller_base.cpp Sun Jul 13 23:12:58 2008
@@ -211,12 +211,15 @@
hotkey::HOTKEY_COMMAND command;
std::vector<std::string>::iterator i = items.begin();
while(i != items.end()) {
+ std::cerr << hotkey::get_hotkey(*i).get_command();
command = hotkey::get_hotkey(*i).get_id();
if(!can_execute_command(command)
|| (context_menu && !in_context_menu(command))) {
+ std::cerr << " - erasing\n";
i = items.erase(i);
continue;
}
+ std::cerr << "\n";
++i;
}
if(items.empty())
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28022&r1=28021&r2=28022&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Sun Jul 13 23:12:58 2008
@@ -96,6 +96,10 @@
case HOTKEY_PREFERENCES:
case HOTKEY_HELP:
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_MAP_NEW:
case HOTKEY_EDITOR_MAP_LOAD:
@@ -180,6 +184,11 @@
undo_stack_.push_back(undo);
trim_stack(undo_stack_);
clear_stack(redo_stack_);
+ refresh_after_action(action);
+}
+
+void editor_controller::refresh_after_action(const editor_action& /*action*/)
+{
//TODO rebuild and ivalidate only what's really needed
gui().rebuild_all();
gui().invalidate_all();
@@ -204,22 +213,28 @@
bool editor_controller::can_undo() const
{
+ std::cerr << "\ncan_undo" << undo_stack_.size() << "\n";
return !undo_stack_.empty();
}
bool editor_controller::can_redo() const
{
+ std::cerr << "\ncan_redo" << redo_stack_.size() << "\n";
return !redo_stack_.empty();
}
void editor_controller::undo()
{
+ std::cerr << "\npreundo : " << undo_stack_.size() << redo_stack_.size()
<< "\n";
perform_action_between_stacks(undo_stack_, redo_stack_);
+ std::cerr << "\nupostndo : " << undo_stack_.size() <<
redo_stack_.size() << "\n";
}
void editor_controller::redo()
{
+ std::cerr << "\npreredo : " << undo_stack_.size() << redo_stack_.size()
<< "\n";
perform_action_between_stacks(redo_stack_, undo_stack_);
+ std::cerr << "\npostredo : " << undo_stack_.size() <<
redo_stack_.size() << "\n";
}
void editor_controller::perform_action_between_stacks(action_stack& from,
action_stack& to)
@@ -230,6 +245,7 @@
editor_action* reverse_action = action->perform(map_);
to.push_back(reverse_action);
trim_stack(to);
+ refresh_after_action(*action);
}
void editor_controller::mouse_motion(int x, int y, const bool browse, bool
update)
@@ -258,7 +274,10 @@
{
if (mouse_handler_base::left_click(x, y, browse)) return true;
LOG_ED << "Left click, after generic handling\n";
+ gamemap::location hex_clicked = gui().hex_clicked_on(x, y);
+ if (!map_.on_board_with_border(hex_clicked)) return true;
if (get_mouse_action() != NULL) {
+ LOG_ED << "Left click action " << hex_clicked.x << " " <<
hex_clicked.y << "\n";
editor_action* a = get_mouse_action()->click(*gui_, x, y);
if (a != NULL) {
perform_action(*a);
Modified: trunk/src/editor2/editor_controller.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=28022&r1=28021&r2=28022&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Sun Jul 13 23:12:58 2008
@@ -72,6 +72,8 @@
* the undo stack. The redo stack is cleared.
*/
void perform_action(const editor_action& action);
+
+ void refresh_after_action(const editor_action& action);
/**
* Checks if an action stack reached its capacity and removes
the front element if so.
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits