]> O.S.I.I.S - jp/crow.git/commitdiff
design mode, crowide wip, style parser (nok)
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 26 Feb 2018 01:30:11 +0000 (02:30 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 26 Feb 2018 01:30:11 +0000 (02:30 +0100)
Crow.csproj
Templates/ContextMenu.template
Tests/Showcase.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/TabView.cs
src/IML/IMLContext.cs
src/Instantiator.cs

index 6a4c56b32ea01ac340582882cf0d9837a9a5d4e2..41e556f8d177c724afa5db21c4802191e972f40b 100644 (file)
@@ -32,7 +32,7 @@
     <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
     <Optimize>false</Optimize>
     <OutputPath>$(SolutionDir)build\Debug</OutputPath>
-    <DefineConstants>DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_DISPOSE0;DEBUG_LAYOUTING0;TRACE0;DEBUG;MEASURE_TIME;DEBUG_LOAD;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0</DefineConstants>
+    <DefineConstants>DESIGN_MODE;DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_DISPOSE0;DEBUG_LAYOUTING0;TRACE0;DEBUG;MEASURE_TIME;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <Optimize>true</Optimize>
index 58e71b7ce89f36f5777201301e9f496f1a82f579..45244442849cb6760df18cdc7cd33b33511f5e3c 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<MenuItem MinimumSize="20,20" Fit="true" Caption="Context Menu" Data="{ContextCommands}" Orientation="Vertical"
+<MenuItem MinimumSize="20,20" Height="Fit" Width="160" Caption="Context Menu" Data="{ContextCommands}" Orientation="Vertical"
        IsOpened ="true" Visible="{/IsOpened}" SelectionBackground="Transparent"
        Background="Red">
        <Template>
@@ -11,7 +11,7 @@
                </HorizontalStack>
        </Template>
        <ItemTemplate>
-               <MenuItem Command="{}" Width="150" PopWidth="120" SelectionBackground="Transparent">
+               <MenuItem Command="{}" Width="150" PopWidth="120" SelectionBackground="Transparent" IsEnabled="{CanExecute}">
                        <Template>
                                <Popper Font="{./Font}" Caption="{./Caption}"  Background="{./Background}" PopDirection="{./PopDirection}"
                                        Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseDown="./onMI_Click"
index b21eaafa9feee3ee227348f690b09a1efe271dc8..da9b99dc89b5f4cec7ec40e8c0fcfe3c7092fc1c 100644 (file)
@@ -118,9 +118,9 @@ namespace Tests
                                lock (this.ifaceControl [0].CrowInterface.UpdateMutex) {
                                        Instantiator inst = null;
                                        using (MemoryStream ms = new MemoryStream (Encoding.UTF8.GetBytes (e.Text))){
-                                               inst = new Instantiator (ms);
+                                               inst = new Instantiator (this.ifaceControl [0].CrowInterface, ms);
                                        }
-                                       g = inst.CreateInstance (this.ifaceControl [0].CrowInterface);
+                                       g = inst.CreateInstance ();
                                        crowContainer.SetChild (g);
                                        g.DataSource = this;
                                }
index 8c9afa0e9ddc0daf6abcced3f23e8c9d2e3a01f6..768b5c0759fe0654fedc0d12840e40b742b7b611 100644 (file)
@@ -45,6 +45,13 @@ namespace Crow
        {
                internal ReaderWriterLockSlim parentRWLock = new ReaderWriterLockSlim();
 
+               #if DESIGN_MODE
+               public int design_line;
+               public int design_column;
+               public string design_imlPath;
+               public Dictionary<string,string> design_members = new Dictionary<string, string>();
+               #endif
+
                #region IDisposable implementation
                protected bool disposed = false;
 
index 707e1dcf56ff41f311678cfad5c97df153701954..3b250c0ea9c04ab13b6d0168c98cb576665c1e9b 100644 (file)
@@ -78,6 +78,9 @@ namespace Crow
                public virtual int SelectedTab {
                        get { return selectedTab; }
                        set {
+                               if (value < 0)//prevent TemplatedGroup index binding set to -1
+                                       return;
+                               
                                if (selectedTab < Children.Count && SelectedTab >= 0)
                                        (Children [selectedTab] as TabItem).IsSelected = false;
 
index c8527087f378c59c519e4ab961990ec74b2214b4..b11dfa69dd36a4667dfbc066819111a5c0f55e96 100644 (file)
@@ -42,7 +42,8 @@ namespace Crow.IML
        /// </summary>
        public class IMLContext
        {
-               public XmlTextReader reader = null;
+               public XmlReader reader = null;
+               public int curLine = 0;
                public Type RootType = null;
 
                public DynamicMethod dm = null;
index 82797a607115aee6b43231a54832950a2e54c2dd..5c4b82f3f59d3ce84ee6f98f95597455e9c620ca 100644 (file)
@@ -41,7 +41,7 @@ namespace Crow.IML
        public class InstantiatorException : Exception {
                public string Path;
                public InstantiatorException (string path, Exception innerException)
-                       : base ("ITor exception in " + path, innerException){
+                       : base ("ITor error:" + path, innerException){
                        Path = path;
                }
        }
@@ -129,13 +129,13 @@ namespace Crow.IML
                /// <param name="fragment">IML string</param>
                public static Instantiator CreateFromImlFragment (Interface _iface, string fragment)
                {
-                       try {
+//                     try {
                                using (Stream s = new MemoryStream (Encoding.UTF8.GetBytes (fragment))) {
                                        return new Instantiator (_iface, s);
                                }
-                       } catch (Exception ex) {
-                               throw new Exception ("IML Error: " + ex.Message);
-                       }
+//                     } catch (Exception ex) {
+//                             throw new Exception ("IML Error: " + ex.Message);
+//                     }
                }
                #endregion
 
@@ -213,6 +213,13 @@ namespace Crow.IML
                /// </summary>
                void emitLoader (XmlReader reader, IMLContext ctx)
                {
+                       int curLine = ctx.curLine;
+
+                       #if DESIGN_MODE
+                       IXmlLineInfo li = (IXmlLineInfo)reader;
+                       ctx.curLine += li.LineNumber - 1;
+                       #endif
+
                        string tmpXml = reader.ReadOuterXml ();
 
                        if (ctx.nodesStack.Peek().HasTemplate)
@@ -220,6 +227,7 @@ namespace Crow.IML
 
                        emitGOLoad (ctx, tmpXml);
 
+                       ctx.curLine = curLine;
                        //emitCheckAndBindValueChanged (ctx);
                }
                /// <summary>
@@ -334,7 +342,7 @@ namespace Crow.IML
                                //add the default item template if no default is defined
                                if (!itemTemplateIds.Any(ids=>ids[0] == "default"))
                                        itemTemplateIds.Add (new string [] { "default", "#Crow.DefaultItem.template", "", "TypeOf"});
-                               //copy item templates (review this)
+                               //get item templates 
                                foreach (string [] iTempId in itemTemplateIds) {
                                        ctx.il.Emit (OpCodes.Ldloc_0);//load TempControl ref
                                        ctx.il.Emit (OpCodes.Ldfld, CompilerServices.fldItemTemplates);//load ItemTemplates dic field
@@ -368,6 +376,21 @@ namespace Crow.IML
                        using (XmlTextReader reader = new XmlTextReader (tmpXml, XmlNodeType.Element, null)) {
                                reader.Read ();
 
+                               #if DESIGN_MODE
+                               IXmlLineInfo li = (IXmlLineInfo)reader;
+                               ctx.il.Emit (OpCodes.Ldloc_0);
+                               ctx.il.Emit (OpCodes.Ldc_I4, ctx.curLine + li.LineNumber);
+                               ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_line"));
+                               ctx.il.Emit (OpCodes.Ldloc_0);
+                               ctx.il.Emit (OpCodes.Ldc_I4, li.LinePosition);
+                               ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_column"));
+                               if (!string.IsNullOrEmpty (sourcePath)) {
+                                       ctx.il.Emit (OpCodes.Ldloc_0);
+                                       ctx.il.Emit (OpCodes.Ldstr, sourcePath);
+                                       ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_imlPath"));
+                               }
+                               #endif
+
                                #region Styling and default values loading
                                //first check for Style attribute then trigger default value loading
                                if (reader.HasAttributes) {
@@ -386,6 +409,20 @@ namespace Crow.IML
                                                if (reader.Name == "Style")
                                                        continue;
 
+                                               #if DESIGN_MODE
+                                               //store member value in iml
+                                               ctx.il.Emit (OpCodes.Ldloc_0);
+                                               ctx.il.Emit (OpCodes.Ldfld, typeof(GraphicObject).GetField("design_members"));
+                                               ctx.il.Emit (OpCodes.Ldstr, reader.Name);
+                                               if (string.IsNullOrEmpty (reader.Value))
+                                                       ctx.il.Emit (OpCodes.Ldnull);
+                                               else
+                                                       ctx.il.Emit (OpCodes.Ldstr, reader.Value);
+                                               ctx.il.Emit (OpCodes.Call, 
+                                                       typeof(Dictionary<string, string>).GetMethod ("set_Item", new Type[] { typeof(string), typeof(string) }));
+                                               #endif
+
+
                                                MemberInfo mi = ctx.CurrentNodeType.GetMember (reader.Name).FirstOrDefault ();
                                                if (mi == null)
                                                        throw new Exception ("Member '" + reader.Name + "' not found in " + ctx.CurrentNodeType.Name);