aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-08-13 19:54:37 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-08-13 19:54:37 -0300
commit0bb1a6f41049875e79ce7914b87f89d800165607 (patch)
tree2efdf0f023aa03bf96d2f43ceb15b7e624f5cb14
parentcsharp: Update part bind test for new syntax (diff)
downloadefl-devs/lauromoura/mvvm-parts.tar.gz
csharp: New syntax for MVVM bindable partsdevs/lauromoura/mvvm-parts
`factory.PartName().PartProperty().Bind(modelProperty);`
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_definition.hh22
-rw-r--r--src/bin/eolian_mono/eolian/mono/helpers.hh12
-rw-r--r--src/bin/eolian_mono/eolian/mono/part_definition.hh6
-rw-r--r--src/bindings/mono/efl_mono/Bind.cs56
4 files changed, 79 insertions, 17 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh
index cf85f6844d..f010f6dc2f 100644
--- a/src/bin/eolian_mono/eolian/mono/function_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh
@@ -251,8 +251,26 @@ struct property_extension_method_definition_generator
if (property.setter.is_engaged())
{
attributes::type_def prop_type = property.setter->parameters[0].type;
- if (!as_generator("public static Efl.Bindable<" << type(true) << "> " << managed_name << "<T>(this Efl.Ui.ItemFactory<T> fac) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n"
- << scope_tab << scope_tab << "return new Efl.Bindable<" << type(true) << ">(\"" << property.name << "\", fac);\n"
+ if (!as_generator("public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "<T>(this Efl.Ui.ItemFactory<T> fac, Efl.Csharp.ExtensionTag<"
+ << name_helpers::klass_full_concrete_or_interface_name(cls)
+ << ", T>magic = null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n"
+ << scope_tab << scope_tab << "return new Efl.BindableProperty<" << type(true) << ">(\"" << property.name << "\", fac);\n"
+ << scope_tab << "}\n"
+ ).generate(sink, std::make_tuple(prop_type, prop_type), context))
+ return false;
+ }
+
+ // Do we need BindablePart extensions for this class?
+ if (!helpers::inherits_from(cls, "Efl.Ui.LayoutPart"))
+ return true;
+
+ if (property.setter.is_engaged())
+ {
+ attributes::type_def prop_type = property.setter->parameters[0].type;
+ if (!as_generator("public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "<T>(this Efl.BindablePart<T> part, Efl.Csharp.ExtensionTag<"
+ << name_helpers::klass_full_concrete_or_interface_name(cls)
+ << ", T>magic = null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n"
+ << scope_tab << scope_tab << "return new Efl.BindableProperty<" << type(true) << ">(part.PartName, \"" << property.name << "\", part.Binder);\n"
<< scope_tab << "}\n"
).generate(sink, std::make_tuple(prop_type, prop_type), context))
return false;
diff --git a/src/bin/eolian_mono/eolian/mono/helpers.hh b/src/bin/eolian_mono/eolian/mono/helpers.hh
index c3e1114c98..a7c27c4809 100644
--- a/src/bin/eolian_mono/eolian/mono/helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/helpers.hh
@@ -164,6 +164,18 @@ bool has_regular_ancestor(attributes::klass_def const& cls)
}
/*
+ * Sugar for checking if a given class in in the inheritance tree
+ */
+bool inherits_from(attributes::klass_def const& cls, std::string const& name)
+{
+ return std::any_of(cls.inherits.begin(), cls.inherits.end(),
+ [&](attributes::klass_name const& inherit)
+ {
+ return name_helpers::klass_full_concrete_or_interface_name(inherit) == name;
+ });
+}
+
+/*
* Gets all methods that this class should implement (i.e. that come from an unimplemented interface/mixin and the class itself)
*/
template<typename Context>
diff --git a/src/bin/eolian_mono/eolian/mono/part_definition.hh b/src/bin/eolian_mono/eolian/mono/part_definition.hh
index 1506fd502e..ec6ef61551 100644
--- a/src/bin/eolian_mono/eolian/mono/part_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/part_definition.hh
@@ -48,9 +48,11 @@ struct part_extension_method_definition_generator
/* auto klass = get_klass(part.klass, unit); */
if (!as_generator(
- scope_tab << "public static Efl.BindablePart<" << part_klass_name << "> " << name_helpers::managed_part_name(part) << "<T>(this Efl.Ui.ItemFactory<T> fac) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << "\n"
+ scope_tab << "public static Efl.BindablePart<" << part_klass_name << "> " << name_helpers::managed_part_name(part) << "<T>(this Efl.Ui.ItemFactory<T> fac, Efl.Csharp.ExtensionTag<"
+ << name_helpers::klass_full_concrete_or_interface_name(cls)
+ << ", T> x=null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << "\n"
<< scope_tab << "{\n"
- << scope_tab << scope_tab << "return new Efl.BindablePart<" << part_klass_name << ">(fac);\n"
+ << scope_tab << scope_tab << "return new Efl.BindablePart<" << part_klass_name << ">(\"" << part.name << "\" ,fac);\n"
<< scope_tab << "}\n"
).generate(sink, attributes::unused, context))
return false;
diff --git a/src/bindings/mono/efl_mono/Bind.cs b/src/bindings/mono/efl_mono/Bind.cs
index bdad92dd6b..6f5677438a 100644
--- a/src/bindings/mono/efl_mono/Bind.cs
+++ b/src/bindings/mono/efl_mono/Bind.cs
@@ -12,22 +12,41 @@ namespace Efl {
///
/// <para>It is internally instantiated and returned by generated extension methods.</para>
/// </summary>
-public class Bindable<T>
+public class BindableProperty<T>
{
+
/// <summary>Creates a new bindable property with the source name <c>name</c>.</summary>
- public Bindable(string name, Efl.Ui.IPropertyBind binder)
+ public BindableProperty(string name, Efl.Ui.IPropertyBind binder)
+ {
+ this.propertyName = name;
+ this.partName = null;
+ this.binder = binder;
+ }
+
+ /// <summary>Creates a new bindable property for part <c>part</c>.</summary>
+ public BindableProperty(string partName, string partProperty, Efl.Ui.IPropertyBind binder)
{
- this.name = name;
+ this.partName = partName;
+ this.propertyName = partProperty;
this.binder = binder;
}
/// <summary>Binds the model property <c>modelProperty</c> to the property <c>name</c> set in the constructor.</summary>
public void Bind(string modelProperty)
{
- binder.PropertyBind(name, modelProperty);
+ if (this.partName == null)
+ {
+ this.binder.PropertyBind(this.propertyName, modelProperty);
+ }
+ else
+ {
+ // FIXME Part binding goes here
+ Eina.Log.Error($"Binding part {partName}.{propertyName} to {modelProperty}");
+ }
}
- string name;
+ string propertyName;
+ string partName;
Efl.Ui.IPropertyBind binder;
}
@@ -38,18 +57,29 @@ public class Bindable<T>
public class BindablePart<T>
{
/// <summary>Creates a new bindable property with the binder <c>binder</c>.</summary>
- public BindablePart(Efl.Ui.IPropertyBind binder)
+ public BindablePart(string partName, Efl.Ui.IPropertyBind binder)
{
- this.binder = binder;
+ this.PartName = partName;
+ this.Binder = binder;
}
- /// <summary>Binds the model property <c>modelProperty</c> to the part property <c>name</c> set in the constructor.</summary>
- public void Bind(string partProperty, string modelProperty)
- {
- binder.PropertyBind(partProperty, modelProperty);
- }
+ /// <summary>The name of the part this instance wraps.</summary>
+ public string PartName { get; private set; }
+ /// <summary>The binder that will be used to bind the properties.</summary>
+ public Efl.Ui.IPropertyBind Binder { get; private set; }
+}
+
+namespace Csharp
+{
+
+/// <summary>Helper class to differentiate between factory extension methods.
+///
+/// For internal use only.</summary>
+public class ExtensionTag<TBase, TInherited>
+ where TInherited : TBase
+{
+}
- private Efl.Ui.IPropertyBind binder;
}
}