- added GDscript bidings for UndoRedo class mechanizm

- registered UndoRedo
This commit is contained in:
krzycho 2015-06-21 21:55:47 +02:00
parent 37af8b4136
commit d65455185a
4 changed files with 129 additions and 1 deletions

View file

@ -339,3 +339,123 @@ UndoRedo::~UndoRedo() {
clear_history(); 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);
}

View file

@ -38,9 +38,12 @@
class UndoRedo : public Object { class UndoRedo : public Object {
OBJ_TYPE(UndoRedo,Object); OBJ_TYPE(UndoRedo,Object);
OBJ_SAVE_TYPE( UndoRedo );
public: public:
typedef void (*CommitNotifyCallback)(void *p_ud,const String& p_name); 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: private:
struct Operation { struct Operation {
@ -81,6 +84,10 @@ private:
CommitNotifyCallback callback; CommitNotifyCallback callback;
void* callback_ud; void* callback_ud;
protected:
static void _bind_methods();
public: public:
void create_action(const String& p_name="",bool p_mergeable=false); void create_action(const String& p_name="",bool p_mergeable=false);

View file

@ -8783,7 +8783,7 @@
</description> </description>
</method> </method>
<method name="get_undo_redo" > <method name="get_undo_redo" >
<return type="Object"> <return type="UndoRedo">
</return> </return>
<description> <description>
</description> </description>

View file

@ -3236,6 +3236,7 @@ void EditorNode::register_editor_types() {
ObjectTypeDB::register_type<EditorScenePostImport>(); ObjectTypeDB::register_type<EditorScenePostImport>();
ObjectTypeDB::register_type<EditorScript>(); ObjectTypeDB::register_type<EditorScript>();
ObjectTypeDB::register_type<EditorFileDialog>(); ObjectTypeDB::register_type<EditorFileDialog>();
ObjectTypeDB::register_type<UndoRedo>();
//ObjectTypeDB::register_type<EditorImporter>(); //ObjectTypeDB::register_type<EditorImporter>();