From f4c05f6b4ddd426a87492b51aca5147d5def2bc5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 26 Feb 2018 12:47:39 +0100 Subject: [PATCH] in design saving of GraphicObject --- CrowIDE/CrowIDE.csproj | 1 + CrowIDE/src/MembersView.cs | 73 +++++------------- CrowIDE/src/PropertyContainer.cs | 98 ++++++++++++++++++++++++ CrowIDE/ui/IDE.style | 13 ++++ CrowIDE/ui/MembersItem.template | 36 ++++----- CrowIDE/ui/MembersView.template | 2 +- src/GraphicObjects/Container.cs | 12 +++ src/GraphicObjects/GraphicObject.cs | 42 ++++++++++ src/GraphicObjects/Group.cs | 12 +++ src/GraphicObjects/TemplatedContainer.cs | 12 +++ src/GraphicObjects/TemplatedControl.cs | 14 ++++ src/GraphicObjects/TemplatedGroup.cs | 21 +++++ src/Instantiator.cs | 7 +- src/ItemTemplate.cs | 47 +++++++++++- 14 files changed, 310 insertions(+), 80 deletions(-) create mode 100644 CrowIDE/src/PropertyContainer.cs diff --git a/CrowIDE/CrowIDE.csproj b/CrowIDE/CrowIDE.csproj index 566a1e69..322e9bee 100644 --- a/CrowIDE/CrowIDE.csproj +++ b/CrowIDE/CrowIDE.csproj @@ -117,6 +117,7 @@ + diff --git a/CrowIDE/src/MembersView.cs b/CrowIDE/src/MembersView.cs index 48b3e074..79bcf5c4 100644 --- a/CrowIDE/src/MembersView.cs +++ b/CrowIDE/src/MembersView.cs @@ -25,62 +25,10 @@ using System.ComponentModel; using System.Reflection; using System.Collections.Generic; using System.Linq; +using Cairo; namespace Crow.Coding -{ - public class PropertyContainer : IValueChange - { - #region IValueChange implementation - public event EventHandler ValueChanged; - public virtual void NotifyValueChanged(string MemberName, object _value) - { - ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); - } - #endregion - - PropertyInfo pi; - object instance; - - public string Name { get { return pi.Name; }} - public object Value { - get { return pi.GetValue(instance); } - set { - try { - if (!pi.PropertyType.IsAssignableFrom(value.GetType()) && pi.PropertyType != typeof(string)){ - if (pi.PropertyType.IsEnum) { - if (value is string) { - pi.SetValue (instance, Enum.Parse (pi.PropertyType, (string)value)); - }else - pi.SetValue (instance, value); - } else { - MethodInfo me = pi.PropertyType.GetMethod - ("Parse", BindingFlags.Static | BindingFlags.Public, - System.Type.DefaultBinder, new Type [] {typeof (string)},null); - pi.SetValue (instance, me.Invoke (null, new object[] { value }), null); - } - }else - pi.SetValue(instance, value); - } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine ("Error setting property:"+ ex.ToString()); - } - NotifyValueChanged ("Value", value); - } - } - public string Type { get { return pi.PropertyType.IsEnum ? - "System.Enum" - : pi.PropertyType.FullName; }} - public object[] Choices { - get { - return Enum.GetValues (pi.PropertyType).Cast().ToArray(); - } - } - - public PropertyContainer(PropertyInfo prop, object _instance){ - pi = prop; - instance = _instance; - } - - } +{ public class MembersView : ListBox { object instance; @@ -116,11 +64,26 @@ namespace Crow.Coding props.Add (new PropertyContainer (pi, instance)); } } - Data = props.ToArray (); + Data = props.OrderBy(p=>p.Name).ToArray (); } } public MembersView () : base() { } + +// public override void Paint (ref Context ctx) +// { +// base.Paint (ref ctx); +// +// if (SelectedIndex < 0) +// return; +// +// Rectangle r = Parent.ContextCoordinates(Items [SelectedIndex].Slot); +// ctx.SetSourceRGB (0, 0, 1); +// ctx.Rectangle (r); +// ctx.LineWidth = 2; +// ctx.Stroke (); +// } + } } diff --git a/CrowIDE/src/PropertyContainer.cs b/CrowIDE/src/PropertyContainer.cs new file mode 100644 index 00000000..feea6477 --- /dev/null +++ b/CrowIDE/src/PropertyContainer.cs @@ -0,0 +1,98 @@ +// +// PropertyContainer.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2013-2017 Jean-Philippe Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using System.Reflection; +using System.Linq; + +namespace Crow.Coding +{ + public class PropertyContainer : IValueChange + { + #region IValueChange implementation + public event EventHandler ValueChanged; + public virtual void NotifyValueChanged(string MemberName, object _value) + { + ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); + } + #endregion + + PropertyInfo pi; + object instance; + GraphicObject go; + + public string Name { get { return pi.Name; }} + public object Value { + get { return go.design_members.ContainsKey(Name) ? + go.design_members[Name] : pi.GetValue(instance); } + set { + if (go.design_members.ContainsKey (Name)) { + if (go.design_members [Name] == (string)value) + return; + } + go.design_members [Name] = (string)value; +// try { +// if (!pi.PropertyType.IsAssignableFrom(value.GetType()) && pi.PropertyType != typeof(string)){ +// if (pi.PropertyType.IsEnum) { +// if (value is string) { +// pi.SetValue (instance, Enum.Parse (pi.PropertyType, (string)value)); +// }else +// pi.SetValue (instance, value); +// } else { +// MethodInfo me = pi.PropertyType.GetMethod +// ("Parse", BindingFlags.Static | BindingFlags.Public, +// System.Type.DefaultBinder, new Type [] {typeof (string)},null); +// pi.SetValue (instance, me.Invoke (null, new object[] { value }), null); +// } +// }else +// pi.SetValue(instance, value); +// } catch (Exception ex) { +// System.Diagnostics.Debug.WriteLine ("Error setting property:"+ ex.ToString()); +// } + NotifyValueChanged ("Value", value); + } + } + public string Type { get { return pi.PropertyType.IsEnum ? + "System.Enum" + : pi.PropertyType.FullName; }} + public object[] Choices { + get { + return Enum.GetValues (pi.PropertyType).Cast().ToArray(); + } + } + + public Fill LabForeground { + get { return go.design_members.ContainsKey(Name) ? Color.Black : Color.DimGray;} + } + + public PropertyContainer(PropertyInfo prop, object _instance){ + pi = prop; + instance = _instance; + go = instance as GraphicObject; + } + + } +} + diff --git a/CrowIDE/ui/IDE.style b/CrowIDE/ui/IDE.style index 3a0cdcd3..3dce97fa 100644 --- a/CrowIDE/ui/IDE.style +++ b/CrowIDE/ui/IDE.style @@ -2,3 +2,16 @@ Width=14; Height=14; } +MemberViewLabel { + Margin=1; + Height=Fit; + Width=50%; + Background=White; +} +MemberViewHStack { + Focusable=true; + Height=Fit; + Spacing=1; + MouseEnter={Background=UnitedNationsBlue}; + MouseLeave={Background=Transparent}; +} diff --git a/CrowIDE/ui/MembersItem.template b/CrowIDE/ui/MembersItem.template index a3cf670e..5c564061 100644 --- a/CrowIDE/ui/MembersItem.template +++ b/CrowIDE/ui/MembersItem.template @@ -1,25 +1,19 @@  - - - - - -