diff options
author | krzycho <krzycho_s@tlen.pl> | 2015-06-21 21:55:47 +0200 |
---|---|---|
committer | krzycho <krzycho_s@tlen.pl> | 2015-06-21 22:23:09 +0200 |
commit | d65455185a2e72bbbf5aaa8943643a49cd811fce (patch) | |
tree | b8feefc40ad5eb0a132ef6204d953925db3941be /core | |
parent | 37af8b413674936518a2ebe180f9e7bfcd5795bb (diff) |
- added GDscript bidings for UndoRedo class mechanizm
- registered UndoRedo
Diffstat (limited to 'core')
-rw-r--r-- | core/undo_redo.cpp | 120 | ||||
-rw-r--r-- | core/undo_redo.h | 7 |
2 files changed, 127 insertions, 0 deletions
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 5e7df3be7e..a93e469f3f 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -339,3 +339,123 @@ UndoRedo::~UndoRedo() { clear_history(); } + +Variant UndoRedo::_add_do_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error) { + + if (p_argcount<1) { + r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument=0; + return Variant(); + } + + if (p_args[0]->get_type()!=Variant::OBJECT) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::OBJECT; + return Variant(); + } + + if (p_args[1]->get_type()!=Variant::STRING) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=1; + r_error.expected=Variant::STRING; + return Variant(); + } + + r_error.error=Variant::CallError::CALL_OK; + + Object* object = *p_args[0]; + String method = *p_args[1]; + + Variant v[VARIANT_ARG_MAX]; + + + for(int i=0;i<MIN(VARIANT_ARG_MAX,p_argcount-2);++i) { + + v[i]=*p_args[i+2]; + } + + add_do_method(object,method,v[0],v[1],v[2],v[3],v[4]); + return Variant(); +} + +Variant UndoRedo::_add_undo_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error) { + + if (p_argcount<1) { + r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument=0; + return Variant(); + } + + if (p_args[0]->get_type()!=Variant::OBJECT) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::OBJECT; + return Variant(); + } + + if (p_args[1]->get_type()!=Variant::STRING) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=1; + r_error.expected=Variant::STRING; + return Variant(); + } + + r_error.error=Variant::CallError::CALL_OK; + + Object* object = *p_args[0]; + String method = *p_args[1]; + + Variant v[VARIANT_ARG_MAX]; + + + for(int i=0;i<MIN(VARIANT_ARG_MAX,p_argcount-2);++i) { + + v[i]=*p_args[i+2]; + } + + add_undo_method(object,method,v[0],v[1],v[2],v[3],v[4]); + return Variant(); +} + +void UndoRedo::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("create_action","name","mergeable"),&UndoRedo::create_action, DEFVAL(false) ); + ObjectTypeDB::bind_method(_MD("commit_action"),&UndoRedo::commit_action); + + //ObjectTypeDB::bind_method(_MD("add_do_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_do_method); + //ObjectTypeDB::bind_method(_MD("add_undo_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_undo_method); + + { + MethodInfo mi; + mi.name="add_do_method"; + mi.arguments.push_back( PropertyInfo( Variant::OBJECT, "object")); + mi.arguments.push_back( PropertyInfo( Variant::STRING, "method")); + Vector<Variant> defargs; + for(int i=0;i<VARIANT_ARG_MAX;++i) { + mi.arguments.push_back( PropertyInfo( Variant::NIL, "arg"+itos(i))); + defargs.push_back(Variant()); + } + + ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"add_do_method",&UndoRedo::_add_do_method,mi,defargs); + } + + { + MethodInfo mi; + mi.name="add_undo_method"; + mi.arguments.push_back( PropertyInfo( Variant::OBJECT, "object")); + mi.arguments.push_back( PropertyInfo( Variant::STRING, "method")); + Vector<Variant> defargs; + for(int i=0;i<VARIANT_ARG_MAX;++i) { + mi.arguments.push_back( PropertyInfo( Variant::NIL, "arg"+itos(i))); + defargs.push_back(Variant()); + } + + ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"add_undo_method",&UndoRedo::_add_undo_method,mi,defargs); + } + + ObjectTypeDB::bind_method(_MD("add_do_property","object", "property", "value"),&UndoRedo::add_do_property); + ObjectTypeDB::bind_method(_MD("add_undo_property","object", "property", "value"),&UndoRedo::add_undo_property); + ObjectTypeDB::bind_method(_MD("add_do_reference","object"),&UndoRedo::add_do_reference); + ObjectTypeDB::bind_method(_MD("add_undo_reference","object"),&UndoRedo::add_undo_reference); +}
\ No newline at end of file diff --git a/core/undo_redo.h b/core/undo_redo.h index d1b2d3de9e..a9187534c1 100644 --- a/core/undo_redo.h +++ b/core/undo_redo.h @@ -38,9 +38,12 @@ class UndoRedo : public Object { OBJ_TYPE(UndoRedo,Object); + OBJ_SAVE_TYPE( UndoRedo ); public: typedef void (*CommitNotifyCallback)(void *p_ud,const String& p_name); + Variant _add_do_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error); + Variant _add_undo_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error); private: struct Operation { @@ -81,6 +84,10 @@ private: CommitNotifyCallback callback; void* callback_ud; + +protected: + static void _bind_methods(); + public: void create_action(const String& p_name="",bool p_mergeable=false); |