From dce9ecfbac5b78476550bfe1fc76a8bdbb3d930b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Fri, 9 Feb 2018 20:44:48 +0100 Subject: [PATCH] made SeletedItem of templatedGroup writable --- Crow.OpenTK.nuspec | 12 +++++++----- Crow.sln | 4 ---- Tests/Tests.csproj | 2 +- src/ExtensionsMethods.cs | 8 ++++++++ src/GraphicObjects/TemplatedGroup.cs | 13 ++++++++++++- src/Instantiator.cs | 3 +++ 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Crow.OpenTK.nuspec b/Crow.OpenTK.nuspec index e336b178..9d49b0a4 100644 --- a/Crow.OpenTK.nuspec +++ b/Crow.OpenTK.nuspec @@ -2,7 +2,7 @@ Crow.OpenTK - 0.6.0-pre1 + 0.6.0 C# Rapid Open Widget Toolkit JP Bruyere Grand Tetras Software @@ -21,13 +21,15 @@ Crow.OpenTK is the OpenTK ready version. - Bug fix #36 - group item templates in single file - instantiation from code clarification - - Only run on mono >= 5.0 - Cairo mesh patterns support. - - Image resources sharing among controls. + - Image resources sharing among controls. + - Some small api changes (LoadInterface replaced by AddWidget overload + - Documentations + - Tooltip for GraphicObject class - Copyright 2013-2017 + Copyright 2013-2018 - + Crow OpenTK OpenGL Widget Interface GUI C# .Net Mono diff --git a/Crow.sln b/Crow.sln index 70736ea4..5fc9079f 100644 --- a/Crow.sln +++ b/Crow.sln @@ -16,17 +16,13 @@ Global EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {42C73BD8-51F5-4BB7-8EE9-9F0BE2D80A2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {42C73BD8-51F5-4BB7-8EE9-9F0BE2D80A2C}.Debug|Any CPU.Build.0 = Debug|Any CPU {42C73BD8-51F5-4BB7-8EE9-9F0BE2D80A2C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {42C73BD8-51F5-4BB7-8EE9-9F0BE2D80A2C}.Release|Any CPU.Build.0 = Release|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Any CPU.Build.0 = Release|Any CPU {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Debug|Any CPU.Build.0 = Debug|Any CPU {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Release|Any CPU.Build.0 = Release|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Any CPU.Build.0 = Debug|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 75969d9b..7fd3f6ed 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,7 +8,7 @@ Exe Tests Tests - Tests.BasicTests + Tests.Showcase v4.5 AnyCPU 0.5 diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index 6198dee6..6697be62 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -125,6 +125,14 @@ namespace Crow { return c == '\t' || c == '\r' || c == '\n' || char.IsWhiteSpace (c); } + public static object GetDefaultValue(this object obj) + { + Type t = obj.GetType (); + if (t.IsValueType) + return Activator.CreateInstance (t); + + return null; + } } } diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index c32b2c44..34d57727 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -148,7 +148,18 @@ namespace Crow } } [XmlIgnore]public virtual object SelectedItem{ - get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; } + get { return data == null ? null : _selectedIndex < 0 ? data.GetDefaultValue() : data[_selectedIndex]; } + set { + if (data == null) { + SelectedIndex = -1; + return; + } + //TODO:double check if value type will be notified to binding sys + if (value == SelectedItem) + return; + + SelectedIndex = data.IndexOf (value); + } } [XmlIgnore]public bool HasItems { get { return Items.Count > 0; } diff --git a/src/Instantiator.cs b/src/Instantiator.cs index 297337ed..b3f070e7 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -890,6 +890,9 @@ namespace Crow.IML CompilerServices.emitConvert (il, piSource.PropertyType); + if (!piSource.CanWrite) + throw new Exception ("Source member of bindind is read only:" + piSource.ToString()); + il.Emit (OpCodes.Callvirt, piSource.GetSetMethod ()); il.MarkLabel (endMethod); -- 2.47.3