diff options
-rw-r--r-- | core/input_map.cpp | 18 | ||||
-rw-r--r-- | core/input_map.h | 3 | ||||
-rw-r--r-- | core/register_core_types.cpp | 2 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 56 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 10 | ||||
-rw-r--r-- | tools/editor/editor_node.cpp | 3 |
6 files changed, 76 insertions, 16 deletions
diff --git a/core/input_map.cpp b/core/input_map.cpp index 296b39350a..9426b0568e 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -31,6 +31,24 @@ InputMap *InputMap::singleton=NULL; +void InputMap::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("has_action","action"),&InputMap::has_action); + ObjectTypeDB::bind_method(_MD("get_action_id","action"),&InputMap::get_action_id); + ObjectTypeDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id); + ObjectTypeDB::bind_method(_MD("add_action","action"),&InputMap::add_action); + ObjectTypeDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action); + + ObjectTypeDB::bind_method(_MD("action_add_event","action","event"),&InputMap::action_add_event); + ObjectTypeDB::bind_method(_MD("action_has_event","action","event"),&InputMap::action_has_event); + ObjectTypeDB::bind_method(_MD("action_erase_event","action","event"),&InputMap::action_erase_event); + ObjectTypeDB::bind_method(_MD("get_action_list","action"),&InputMap::get_action_list); + ObjectTypeDB::bind_method(_MD("event_is_action","event","action"),&InputMap::event_is_action); + ObjectTypeDB::bind_method(_MD("load_from_globals"),&InputMap::load_from_globals); + +} + + void InputMap::add_action(const StringName& p_action) { ERR_FAIL_COND( input_map.has(p_action) ); diff --git a/core/input_map.h b/core/input_map.h index 3a56892585..bf20645b15 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -46,6 +46,9 @@ class InputMap : public Object { List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const; +protected: + + static void _bind_methods(); public: static _FORCE_INLINE_ InputMap *get_singleton() { return singleton; } diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 7e7ce3479f..1bc1d2c1ca 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -50,6 +50,7 @@ #include "io/http_client.h" #include "packed_data_container.h" #include "func_ref.h" +#include "input_map.h" #ifdef XML_ENABLED static ResourceFormatSaverXML *resource_saver_xml=NULL; @@ -193,6 +194,7 @@ void register_core_singletons() { Globals::get_singleton()->add_singleton( Globals::Singleton("TranslationServer",TranslationServer::get_singleton() ) ); Globals::get_singleton()->add_singleton( Globals::Singleton("TS",TranslationServer::get_singleton() ) ); Globals::get_singleton()->add_singleton( Globals::Singleton("Input",Input::get_singleton() ) ); + Globals::get_singleton()->add_singleton( Globals::Singleton("InputMap",InputMap::get_singleton() ) ); } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index d84e9956ba..a6207c5611 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1072,8 +1072,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); + _begin_compex_operation(); _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); _insert_text_at_cursor(txt); + _end_compex_operation(); selection.active=true; selection.from_column=sel_column; selection.from_line=sel_line; @@ -1569,8 +1571,6 @@ void TextEdit::_post_shift_selection() { /**** TEXT EDIT CORE API ****/ - - void TextEdit::_base_insert_text(int p_line, int p_char,const String& p_text,int &r_end_line,int &r_end_column) { //save for undo... @@ -1677,14 +1677,12 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column,int p_to_lin - void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_end_line,int *r_end_column) { if (!setting_text) idle_detect->start(); if (undo_enabled) { - _clear_redo(); } @@ -2496,7 +2494,7 @@ void TextEdit::_clear_redo() { void TextEdit::undo() { - + _push_current_op(); if (undo_stack_pos==NULL) { @@ -2511,8 +2509,13 @@ void TextEdit::undo() { else undo_stack_pos=undo_stack_pos->prev(); - _do_text_op( undo_stack_pos->get(),true); + if(undo_stack_pos->get().chain_backward) { + do { + undo_stack_pos = undo_stack_pos->prev(); + _do_text_op(undo_stack_pos->get(), true); + } while(!undo_stack_pos->get().chain_forward); + } cursor_set_line(undo_stack_pos->get().from_line); cursor_set_column(undo_stack_pos->get().from_column); @@ -2526,8 +2529,13 @@ void TextEdit::redo() { if (undo_stack_pos==NULL) return; //nothing to do. - - _do_text_op( undo_stack_pos->get(),false); + _do_text_op(undo_stack_pos->get(), false); + if(undo_stack_pos->get().chain_forward) { + do { + undo_stack_pos=undo_stack_pos->next(); + _do_text_op(undo_stack_pos->get(), false); + } while(!undo_stack_pos->get().chain_backward); + } cursor_set_line(undo_stack_pos->get().from_line); cursor_set_column(undo_stack_pos->get().from_column); undo_stack_pos=undo_stack_pos->next(); @@ -2539,20 +2547,43 @@ void TextEdit::clear_undo_history() { saved_version=0; current_op.type=TextOperation::TYPE_NONE; undo_stack_pos=NULL; - undo_stack.clear();; + undo_stack.clear(); } +void TextEdit::_begin_compex_operation() { + _push_current_op(); + next_operation_is_complex=true; +} -void TextEdit::_push_current_op() { +void TextEdit::_end_compex_operation() { + + _push_current_op(); + ERR_FAIL_COND(undo_stack.size() == 0); + + if(undo_stack.back()->get().chain_forward) { + undo_stack.back()->get().chain_forward=false; + return; + } + + undo_stack.back()->get().chain_backward=true; +} +void TextEdit::_push_current_op() { + if (current_op.type==TextOperation::TYPE_NONE) return; // do nothing - + + if(next_operation_is_complex) { + current_op.chain_forward=true; + next_operation_is_complex=false; + } + undo_stack.push_back(current_op); current_op.type=TextOperation::TYPE_NONE; current_op.text=""; - + current_op.chain_forward=false; + } void TextEdit::set_draw_tabs(bool p_draw) { @@ -2957,6 +2988,7 @@ TextEdit::TextEdit() { completion_line_ofs=0; tooltip_obj=NULL; line_numbers=false; + next_operation_is_complex=false; } TextEdit::~TextEdit(){ diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index c3bb5823e7..8e9651668b 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -218,6 +218,8 @@ class TextEdit : public Control { Object *tooltip_obj; StringName tooltip_func; Variant tooltip_ud; + + bool next_operation_is_complex; int get_visible_rows() const; @@ -241,11 +243,13 @@ class TextEdit : public Control { void _update_caches(); void _cursor_changed_emit(); void _text_changed_emit(); - + + void _begin_compex_operation(); + void _end_compex_operation(); void _push_current_op(); /* super internal api, undo/redo builds on it */ - + void _base_insert_text(int p_line, int p_column,const String& p_text,int &r_end_line,int &r_end_column); String _base_get_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) const; void _base_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column); @@ -262,7 +266,7 @@ class TextEdit : public Control { protected: virtual String get_tooltip(const Point2& p_pos) const; - + void _insert_text(int p_line, int p_column,const String& p_text,int *r_end_line=NULL,int *r_end_char=NULL); void _remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column); void _insert_text_at_cursor(const String& p_text); diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 4ed565fdc3..f6653ac3d6 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -1982,7 +1982,8 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { confirmation->popup_centered(Size2(300,70)); break; } - + + _menu_option_confirm(RUN_STOP,true); get_scene()->quit(); } break; |