<Compile Include="src\SourceEditor\Token.cs" />
<Compile Include="src\SourceEditor\XMLParser.cs" />
<Compile Include="src\SourceEditor\StyleParser.cs" />
+ <Compile Include="src\PropertyContainer.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="ui\" />
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<ValueChangeEventArgs> 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<object>().ToArray();
- }
- }
-
- public PropertyContainer(PropertyInfo prop, object _instance){
- pi = prop;
- instance = _instance;
- }
-
- }
+{
public class MembersView : ListBox
{
object instance;
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 ();
+// }
+
}
}
--- /dev/null
+//
+// PropertyContainer.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// 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<ValueChangeEventArgs> 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<object>().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;
+ }
+
+ }
+}
+
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};
+}
<?xml version="1.0"?>
<ItemTemplate>
- <HorizontalStack Focusable="true" Height="Fit" Spacing="0"
- MouseEnter="{Background=UnitedNationsBlue}"
- MouseLeave="{Background=Transparent}" >
- <Label Margin="1" Text="{Name}" Height="Fit" Width="50%"/>
- <TextBox Margin="1" Text="{²Value}" Height="Fit" Width="50%"/>
+ <HorizontalStack Style="MemberViewHStack" >
+ <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
+ <TextBox Margin="1" Text="{²Value}" Height="Fit" Foreground = "{LabForeground}"/>
</HorizontalStack>
</ItemTemplate>
<ItemTemplate DataType="System.Boolean">
- <HorizontalStack Focusable="true" Height="Fit" Spacing="0"
- MouseEnter="{Background=UnitedNationsBlue}"
- MouseLeave="{Background=Transparent}" >
- <Label Margin="1" Text="{Name}" Height="Fit" Width="50%"/>
- <CheckBox Background="White" Height="Stretched" Caption="" IsChecked="{²Value}"/>
+ <HorizontalStack Style="MemberViewHStack" >
+ <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
+ <CheckBox Background="White" Foreground = "{LabForeground}" Height="Stretched" Caption="" IsChecked="{²Value}"/>
</HorizontalStack>
</ItemTemplate>
<ItemTemplate DataType="System.Enum">
- <HorizontalStack Focusable="true" Height="Fit" Spacing="0"
- MouseEnter="{Background=UnitedNationsBlue}"
- MouseLeave="{Background=Transparent}" >
- <Label Margin="1" Text="{Name}" Height="Fit" Width="50%"/>
+ <HorizontalStack Style="MemberViewHStack" >
+ <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
<ComboBox Margin="0" Height="Stretched" Width="50%" Data="{Choices}"
SelectedItem="{²Value}">
<Template>
<Template>
<Border CornerRadius="0" Foreground="LightGray" Background="White">
<HorizontalStack Margin="0" Spacing="1">
- <Label Width="Stretched" MinimumSize="80,10" Margin="1" Foreground="Black" Background="White"
+ <Label Width="Stretched" MinimumSize="80,10" Margin="1" Foreground = "{LabForeground}" Background="White"
Text="{../../../../../SelectedItem}"/>
<Button Width="12" Height="12" Focusable="false"
Template="#Crow.Templates.ArrowBut.template">
</HorizontalStack>
</ItemTemplate>
<ItemTemplate DataType="Crow.Fill">
- <HorizontalStack Focusable="true" Height="Fit" Spacing="0"
- MouseEnter="{Background=UnitedNationsBlue}"
- MouseLeave="{Background=Transparent}" >
- <Label Margin="1" Text="{Name}" Height="Fit" Width="50%"/>
+ <HorizontalStack Style="MemberViewHStack" >
+ <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
<Popper Background="White" Margin="0" Height="Stretched" Caption="{Value}">
<Template>
- <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}" Foreground="{./Foreground}" Background="{./Background}">
+ <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}" Background="{./Background}">
<Template>
<HorizontalStack Spacing="3" Height="Fit" Background="{./Background}">
- <Border Foreground="Black" Width="16" Height="10" CornerRadius="3"
+ <Border Foreground="{LabForeground}" Width="16" Height="10" CornerRadius="3"
Background="{Value}">
</Border>
- <Label Text="{./Caption}" Foreground="Black"/>
+ <Label Text="{./Caption}" Foreground="{LabForeground}"/>
</HorizontalStack>
</Template>
</CheckBox>
<Scroller Name="scroller1" Margin="1" VerticalScrolling="true"
Background="{./Background}"
ScrollY="{../scrollbar1.Value}">
- <VerticalStack
+ <VerticalStack Spacing="1"
Height="Fit" Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/>
</Scroller>
<ScrollBar
/// </summary>
public class Container : PrivateContainer
{
+ #if DESIGN_MODE
+ public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem)
+ {
+ if (this.design_isTGItem)
+ return;
+ base.getIML (doc, parentElem);
+ if (child == null)
+ return;
+ child.getIML (doc, parentElem.LastChild);
+ }
+ #endif
+
#region CTOR
protected Container() : base(){}
public Container (Interface iface) : base(iface){}
using Crow.IML;
using System.Threading;
+
+#if DESIGN_MODE
+using System.Xml;
+using System.IO;
+#endif
+
namespace Crow
{
/// <summary>
public int design_column;
public string design_imlPath;
public Dictionary<string,string> design_members = new Dictionary<string, string>();
+ public bool design_isTGItem = false;
+
+ public string GetIML(){
+ XmlDocument doc = new XmlDocument( );
+
+ using (StringWriter sw = new StringWriter ()) {
+ XmlWriterSettings settings = new XmlWriterSettings {
+ Indent = true,
+ IndentChars = "\t",
+ };
+ using (XmlWriter xtw = XmlWriter.Create (sw, settings)) {
+ //(1) the xml declaration is recommended, but not mandatory
+ XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration ("1.0", "UTF-8", null);
+ doc.InsertBefore (xmlDeclaration, null);
+ getIML (doc, (XmlNode)doc);
+ doc.WriteTo (xtw);
+ }
+ return sw.ToString ();
+ }
+ }
+
+ public virtual void getIML(XmlDocument doc, XmlNode parentElem) {
+ if (this.design_isTGItem)
+ return;
+
+ XmlElement xe = doc.CreateElement(this.GetType().Name);
+
+ foreach (KeyValuePair<string,string> kv in design_members) {
+ XmlAttribute xa = doc.CreateAttribute (kv.Key);
+ xa.Value = kv.Value;
+ xe.Attributes.Append (xa);
+ }
+
+ parentElem.AppendChild (xe);
+ }
+
#endif
#region IDisposable implementation
{
public class Group : GraphicObject
{
+ #if DESIGN_MODE
+ public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem)
+ {
+ if (this.design_isTGItem)
+ return;
+ base.getIML (doc, parentElem);
+ foreach (GraphicObject g in Children) {
+ g.getIML (doc, parentElem.LastChild);
+ }
+ }
+ #endif
+
protected ReaderWriterLockSlim childrenRWLock = new ReaderWriterLockSlim();
#region CTOR
/// </summary>
public class TemplatedContainer : TemplatedControl
{
+ #if DESIGN_MODE
+ public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem)
+ {
+ if (this.design_isTGItem)
+ return;
+ base.getIML (doc, parentElem);
+ if (!HasContent)
+ return;
+ Content.getIML (doc, parentElem.LastChild);
+ }
+ #endif
+
#region CTOR
protected TemplatedContainer() : base(){}
public TemplatedContainer (Interface iface) : base(iface){}
/// </summary>
public abstract class TemplatedControl : PrivateContainer
{
+ #if DESIGN_MODE
+ public bool design_inlineTemplate = false;
+ public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem)
+ {
+ if (this.design_isTGItem)
+ return;
+ base.getIML (doc, parentElem);
+ if (child == null || !design_inlineTemplate)
+ return;
+ XmlElement xe = doc.CreateElement("Template");
+ child.getIML (doc, xe);
+ parentElem.LastChild.AppendChild (xe);
+ }
+ #endif
#region CTOR
protected TemplatedControl() : base(){}
public TemplatedControl (Interface iface) : base(iface){}
{
public abstract class TemplatedGroup : TemplatedControl
{
+ #if DESIGN_MODE
+ public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem)
+ {
+ if (this.design_isTGItem)
+ return;
+ base.getIML (doc, parentElem);
+
+ if (string.IsNullOrEmpty(_itemTemplate)) {
+ foreach (ItemTemplate it in ItemTemplates.Values)
+ it.getIML (doc, parentElem.LastChild);
+ }
+
+ foreach (GraphicObject g in Items) {
+ g.getIML (doc, parentElem.LastChild);
+ }
+ }
+ #endif
+
#region CTOR
protected TemplatedGroup() : base(){}
public TemplatedGroup (Interface iface) : base(iface){}
lock (IFace.LayoutMutex) {
g = iTemp.CreateInstance();
+ #if DESIGN_MODE
+ g.design_isTGItem = true;
+ #endif
page.AddChild (g);
// if (isPaged)
g.LogicalParent = this;
itemTmpID += path+dataType+datas;
if (!iface.Instantiators.ContainsKey (itemTmpID))
iface.Instantiators [itemTmpID] =
- new ItemTemplate (iface, Interface.GetStreamFromPath (path), dataTest, dataType, datas);
+ new ItemTemplate (iface, path, dataTest, dataType, datas);
}
return new string [] { dataType, itemTmpID, datas, dataTest };
}
continue;
if (reader.Name == "Template") {
inlineTemplate = true;
+ #if DESIGN_MODE
+ ctx.il.Emit (OpCodes.Ldloc_0);
+ ctx.il.Emit (OpCodes.Ldc_I4_1);
+ ctx.il.Emit (OpCodes.Stfld, typeof(TemplatedControl).GetField("design_inlineTemplate"));
+ #endif
reader.Read ();
readChildren (reader, ctx, -1);
} else if (reader.Name == "ItemTemplate")
///
/// </summary>
public class ItemTemplate : Instantiator {
+ #if DESIGN_MODE
+ public void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem){
+ if (sourcePath == "#Crow.DefaultItem.template")
+ return;
+
+ XmlElement xe = doc.CreateElement("ItemTemplate");
+ XmlAttribute xa = null;
+
+ if (string.IsNullOrEmpty (sourcePath)) {
+ //inline item template
+ using (GraphicObject go = this.CreateInstance())
+ go.getIML (doc, xe);
+ } else {
+ xa = doc.CreateAttribute ("Path");
+ xa.Value = sourcePath;
+ xe.Attributes.Append (xa);
+ }
+
+ if (strDataType != "default") {
+ xa = doc.CreateAttribute ("DataType");
+ xa.Value = strDataType;
+ xe.Attributes.Append (xa);
+
+ if (dataTest != "TypeOf"){
+ xa = doc.CreateAttribute ("DataTest");
+ xa.Value = dataTest;
+ xe.Attributes.Append (xa);
+ }
+ }
+
+ if (!string.IsNullOrEmpty(fetchMethodName)){
+ xa = doc.CreateAttribute ("Data");
+ xa.Value = fetchMethodName;
+ xe.Attributes.Append (xa);
+ }
+
+ parentElem.AppendChild (xe);
+
+
+ }
+ #endif
+
public EventHandler Expand;
public BooleanTestOnInstance HasSubItems;
string strDataType;
/// <param name="path">IML file to parse</param>
/// <param name="_dataType">type this item will be choosen for, or member of the data item</param>
/// <param name="_fetchDataMethod">for hierarchical data, method to call for children fetching</param>
- public ItemTemplate(Interface _iface, string path, string _dataTest = "TypeOf", string _dataType = null, string _fetchDataMethod = null)
+ public ItemTemplate(Interface _iface, string path, string _dataTest = "TypeOf", string _dataType = "default", string _fetchDataMethod = null)
: base(_iface, path) {
strDataType = _dataType;
fetchMethodName = _fetchDataMethod;
il.Emit (OpCodes.Callvirt, miGetDatas);
}
+
+
+
}
}