csharp: Fix event registration in constructor.

Summary:
The binding user should be able to register to events inside the initialization callback given to the constructor.

Fixes T7346

Reviewers: segfaultxavi, felipealmeida, vitor.sousa

Reviewed By: segfaultxavi, vitor.sousa

Subscribers: cedric, #reviewers, #committers, zmike

Tags: #efl

Maniphest Tasks: T7346

Differential Revision: https://phab.enlightenment.org/D6908
This commit is contained in:
Lauro Moura 2018-08-24 11:33:46 -03:00 committed by Vitor Sousa
parent 4a808834d0
commit a9efc38885
2 changed files with 17 additions and 2 deletions

View File

@ -198,11 +198,11 @@ struct klass
<< scope_tab << scope_tab << "if(parent != null)\n"
<< scope_tab << scope_tab << scope_tab << "parent_ptr = parent.raw_handle;\n"
<< scope_tab << scope_tab << "handle = efl.eo.Globals._efl_add_internal_start(\"file\", 0, klass, parent_ptr, 1, 0);\n"
<< scope_tab << scope_tab << "register_event_proxies();\n"
<< scope_tab << scope_tab << "if (init_cb != null) {\n"
<< scope_tab << scope_tab << scope_tab << "init_cb(this);\n"
<< scope_tab << scope_tab << "}\n"
<< scope_tab << scope_tab << "handle = efl.eo.Globals._efl_add_end(handle, 1, 0);\n" // replace handle with the actual final handle
<< scope_tab << scope_tab << "register_event_proxies();\n"
<< scope_tab << scope_tab << "eina.Error.RaiseIfOccurred();\n"
<< scope_tab << "}\n"
<< (class_type == "class" ? "" : "*/")
@ -312,12 +312,12 @@ struct klass
<< scope_tab << scope_tab << scope_tab << "}\n"
<< scope_tab << scope_tab << "}\n"
<< scope_tab << scope_tab << "handle = efl.eo.Globals.instantiate_start(klass, parent);\n"
<< scope_tab << scope_tab << "register_event_proxies();\n"
<< scope_tab << scope_tab << "if (init_cb != null) {\n"
<< scope_tab << scope_tab << scope_tab << "init_cb(this);\n"
<< scope_tab << scope_tab << "}\n"
<< scope_tab << scope_tab << "handle = efl.eo.Globals.instantiate_end(handle);\n"
<< scope_tab << scope_tab << "efl.eo.Globals.data_set(this);\n"
<< scope_tab << scope_tab << "register_event_proxies();\n"
<< scope_tab << scope_tab << "eina.Error.RaiseIfOccurred();\n"
<< scope_tab << "}\n"
<< scope_tab << "///<summary>Destructor.</summary>\n"

View File

@ -149,5 +149,20 @@ class TestEoEvents
Test.AssertEquals(sent_struct.Fstring, received_struct.Fstring);
}
public static void event_in_init_callback()
{
int received = 0;
int sent = 42;
test.ITesting obj = new test.Testing(null, (test.ITesting t) => {
t.EvtWithIntEvt += (object sender, EvtWithIntEvt_Args e) => {
received = e.arg;
};
});
obj.EmitEventWithInt(sent);
Test.AssertEquals(sent, received);
}
}
}