]> O.S.I.I.S - jp/crow.git/commitdiff
CrowIDE wip, removed key repeat already handled by otk
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 2 Mar 2018 06:53:54 +0000 (07:53 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 2 Mar 2018 06:53:54 +0000 (07:53 +0100)
src/Configuration.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/TemplatedGroup.cs
src/Interface.cs
src/ParsingException.cs
src/Style.cs
src/StyleReader.cs

index a6b0f0b0b5e4d75ba9c0d8bb8f8d1c05a509df77..a6328c0a0bb6212a278a983e6a6f1902cfbbd1e8 100644 (file)
@@ -169,7 +169,8 @@ namespace Crow
                                using (StreamWriter sw = new StreamWriter (s)) {
                                        lock (items) {
                                                foreach (string key in items.Keys) {
-                                                       sw.WriteLine (key + "=" + (string)items [key].curVal.ToString ());
+                                                       if (items [key].curVal != null)
+                                                               sw.WriteLine (key + "=" + (string)items [key].curVal.ToString ());
                                                }
                                        }
                                }
index f5a1a224efe78fe022742c328f68d6cc7ffc201d..adb29e54fb5f71ec618f72eac090e62a29e1102e 100644 (file)
@@ -52,12 +52,22 @@ namespace Crow
                internal ReaderWriterLockSlim parentRWLock = new ReaderWriterLockSlim();
 
                #if DESIGN_MODE
+               static MethodInfo miDesignAddDefLoc = typeof(GraphicObject).GetMethod("design_add_default_location",
+                       BindingFlags.Instance | BindingFlags.NonPublic);
                public volatile bool HasChanged = false;
                public string design_id;
                public int design_line;
                public int design_column;
                public string design_imlPath;
                public Dictionary<string,string> design_members = new Dictionary<string, string>();
+               public Dictionary<string,FileLocation> design_defaults = new Dictionary<string, FileLocation>();
+               internal void design_add_default_location (string memberName, string path, int line, int col) {
+                       if (design_defaults.ContainsKey(memberName)){
+                               Console.WriteLine ("default value localtion already set for {0}{1}.{2}", this.GetType().Name, this.design_id, memberName);
+                               return;
+                       }
+                       design_defaults.Add(memberName, new FileLocation(path,line,col));
+               }
                public bool design_isTGItem = false;
 
                public virtual bool FindByDesignID(string designID, out GraphicObject go){
@@ -932,16 +942,12 @@ namespace Crow
                                        IFace.DefaultValuesLoader [Style] (this);
                                        return;
                                }
-                       } else {
-                               if (IFace.DefaultValuesLoader.ContainsKey (thisType.FullName)) {
-                                       IFace.DefaultValuesLoader [thisType.FullName] (this);
-                                       return;
-                               } else if (!IFace.Styling.ContainsKey (thisType.FullName)) {
-                                       if (IFace.DefaultValuesLoader.ContainsKey (thisType.Name)) {
-                                               IFace.DefaultValuesLoader [thisType.Name] (this);
-                                               return;
-                                       }
-                               }
+                       } else if (IFace.DefaultValuesLoader.ContainsKey (thisType.FullName)) {
+                               IFace.DefaultValuesLoader [thisType.FullName] (this);
+                               return;
+                       } else  if (IFace.DefaultValuesLoader.ContainsKey (thisType.Name)) {
+                               IFace.DefaultValuesLoader [thisType.Name] (this);
+                               return;
                        }
 
                        List<Style> styling = new List<Style>();
@@ -971,7 +977,6 @@ namespace Crow
                        if (string.IsNullOrEmpty (styleKey))
                                styleKey = thisType.FullName;
 
-
                        //Reflexion being very slow compared to dyn method or delegates,
                        //I compile the initial values coded in the CustomAttribs of the class,
                        //all other instance of this type would not longer use reflexion to init properly
@@ -1023,10 +1028,51 @@ namespace Crow
                        foreach (PropertyInfo pi in thisType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
                                if (pi.GetSetMethod () == null)
                                        continue;
-                               object defaultValue;
-                               if (!getDefaultValue (pi, styling, out defaultValue))
+                               XmlIgnoreAttribute xia = (XmlIgnoreAttribute)pi.GetCustomAttribute (typeof(XmlIgnoreAttribute));
+                               if (xia != null)
                                        continue;
 
+                               object defaultValue;
+                               string name = "";
+                               XmlAttributeAttribute xaa = (XmlAttributeAttribute)pi.GetCustomAttribute (typeof(XmlAttributeAttribute));
+                               if (xaa != null) {
+                                       if (string.IsNullOrEmpty (xaa.AttributeName))
+                                               name = pi.Name;
+                                       else
+                                               name = xaa.AttributeName;
+                               }
+                               int styleIndex = -1;
+                               if (styling.Count > 0){
+                                       for (int i = 0; i < styling.Count; i++) {
+                                               if (styling[i].ContainsKey (name)){
+                                                       styleIndex = i;
+                                                       break;
+                                               }
+                                       }
+                               }
+                               if (styleIndex >= 0){
+                                       if (pi.PropertyType.IsEnum)//maybe should be in parser..
+                                               defaultValue = Enum.Parse(pi.PropertyType, (string)styling[styleIndex] [name], true);
+                                       else
+                                               defaultValue = styling[styleIndex] [name];
+
+                                       #if DESIGN_MODE
+                                       FileLocation fl = styling[styleIndex].Locations[name];
+                                       il.Emit (OpCodes.Ldloc_0);
+                                       il.Emit (OpCodes.Ldstr, name);
+                                       il.Emit (OpCodes.Ldstr, fl.FilePath);
+                                       il.Emit (OpCodes.Ldc_I4, fl.Line);
+                                       il.Emit (OpCodes.Ldc_I4, fl.Column);
+                                       il.Emit (OpCodes.Call, miDesignAddDefLoc);
+                                       #endif
+
+                               }else {
+                                       DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute));
+                                       if (dv == null)
+                                               continue;
+                                       defaultValue = dv.Value;
+                               }
+
                                CompilerServices.EmitSetValue (il, pi, defaultValue);
                        }
                        il.Emit(OpCodes.Ret);
@@ -1052,51 +1098,6 @@ namespace Crow
                        }
                        return false;
                }
-               /// <summary>
-               /// Gets the default value of the widget's property from either the style, or from xml default
-               /// </summary>
-               /// <returns><c>true</c>, if default value is defined, <c>false</c> otherwise.</returns>
-               /// <param name="pi">PropertyInfo</param>
-               /// <param name="styling">Styling informations</param>
-               /// <param name="defaultValue">output of Default value, null if not found</param>
-               bool getDefaultValue(PropertyInfo pi, List<Style> styling,
-                       out object defaultValue){
-                       defaultValue = null;
-                       string name = "";
-
-                       XmlIgnoreAttribute xia = (XmlIgnoreAttribute)pi.GetCustomAttribute (typeof(XmlIgnoreAttribute));
-                       if (xia != null)
-                               return false;
-                       XmlAttributeAttribute xaa = (XmlAttributeAttribute)pi.GetCustomAttribute (typeof(XmlAttributeAttribute));
-                       if (xaa != null) {
-                               if (string.IsNullOrEmpty (xaa.AttributeName))
-                                       name = pi.Name;
-                               else
-                                       name = xaa.AttributeName;
-                       }
-
-                       int styleIndex = -1;
-                       if (styling.Count > 0){
-                               for (int i = 0; i < styling.Count; i++) {
-                                       if (styling[i].ContainsKey (name)){
-                                               styleIndex = i;
-                                               break;
-                                       }
-                               }
-                       }
-                       if (styleIndex >= 0){
-                               if (pi.PropertyType.IsEnum)//maybe should be in parser..
-                                       defaultValue = Enum.Parse(pi.PropertyType, (string)styling[styleIndex] [name], true);
-                               else
-                                       defaultValue = styling[styleIndex] [name];
-                       }else {
-                               DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute));
-                               if (dv == null)
-                                       return false;
-                               defaultValue = dv.Value;
-                       }
-                       return true;
-               }
                #endregion
 
                public virtual GraphicObject FindByName(string nameToFind){
index a5cd2dd6b5d70a4239ab9156c553b16138f6e0a1..42ffa51cd27ed804b622dd4f28a849ba0d5d4b69 100644 (file)
@@ -148,7 +148,7 @@ namespace Crow
                                : items.Children;
                        }
                }
-               [XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{
+               [XmlAttributeAttribute][DefaultValue(-1)]public virtual int SelectedIndex{
                        get { return _selectedIndex; }
                        set {
                                if (value == _selectedIndex)
index 5d7f77209038b74049b1ae136e4a908760104373..cdfd24d7a1034a48d2bbf93d51b1efc791662df6 100644 (file)
@@ -524,15 +524,7 @@ namespace Crow
                                        }
                                }
                        }
-                       if (keyboardRepeatCount > 0) {
-                               int mc = keyboardRepeatCount;
-                               keyboardRepeatCount -= mc;
-                               if (_focusedWidget != null) {
-                                       for (int i = 0; i < mc; i++) {
-                                               _focusedWidget.onKeyDown (this, lastKeyDownEvt);
-                                       }
-                               }
-                       }
+
                        CrowThread[] tmpThreads;
                        lock (CrowThreads) {
                                tmpThreads = new CrowThread[CrowThreads.Count];
@@ -1011,9 +1003,9 @@ namespace Crow
                        lastKeyDownEvt.IsRepeat = true;
                        _focusedWidget.onKeyDown (this, e);
 
-                       keyboardRepeatThread = new Thread (keyboardRepeatThreadFunc);
-                       keyboardRepeatThread.IsBackground = true;
-                       keyboardRepeatThread.Start ();
+//                     keyboardRepeatThread = new Thread (keyboardRepeatThreadFunc);
+//                     keyboardRepeatThread.IsBackground = true;
+//                     keyboardRepeatThread.Start ();
 
                        return true;
                }
@@ -1030,11 +1022,11 @@ namespace Crow
 
                        _focusedWidget.onKeyUp (this, e);
 
-                       if (keyboardRepeatThread != null) {
-                               keyboardRepeatOn = false;
-                               keyboardRepeatThread.Abort();
-                               keyboardRepeatThread.Join ();
-                       }
+//                     if (keyboardRepeatThread != null) {
+//                             keyboardRepeatOn = false;
+//                             keyboardRepeatThread.Abort();
+//                             keyboardRepeatThread.Join ();
+//                     }
                        return true;
                }
                /// <summary>
index e3bd51c90b2f2946705a88723010e28f2ad548a1..eb85504dc592fa85e75f3fba1eb0deb6bcd4a6ff 100644 (file)
@@ -6,14 +6,14 @@ namespace Crow.Coding
        {
                public int Line;
                public int Column;
-               public ParserException(int line, int column, string txt)
-                       : base(string.Format("Parser exception ({0},{1}): {2}", line, column, txt))
+               public ParserException(int line, int column, string txt, string source = null)
+                       : base(string.Format("{3}:({0},{1}): {2}", line, column, txt, source))
                {
                        Line = line;
                        Column = column;
                }
-               public ParserException(int line, int column, string txt, Exception innerException)
-                       : base(string.Format("Parser exception ({0},{1}): {2}", line, column, txt), innerException)
+               public ParserException(int line, int column, string txt, Exception innerException, string source = null)
+                       : base(string.Format("{3}:({0},{1}): {2}", line, column, txt, source), innerException)
                {}
        }
 }
index fded0503372fffb8d2328efb0d379b1e77e0aef9..58f09f335797c4a13f0e0278e1dbc3555f1e833d 100644 (file)
@@ -29,12 +29,31 @@ using System.Collections.Generic;
 
 namespace Crow
 {
+       public struct FileLocation {
+               public string FilePath;
+               public int Line;
+               public int Column;
+
+               public FileLocation(string filePath, int line, int column){
+                       FilePath = filePath;
+                       Line = line;
+                       Column = column;
+               }
+               public override string ToString ()
+               {
+                       return string.Format ("{0} ({1},{2})", FilePath, Line, Column);
+               }
+       }
        public class Style : Dictionary<string, object>
        {
-               public Dictionary<string, Style> SubStyles;//TODO:implement substyles for all tags inside a style
+               #if DESIGN_MODE
+               public Dictionary<string, FileLocation> Locations = new Dictionary<string, FileLocation>();
+               #endif
+               //public Dictionary<string, Style> SubStyles;//TODO:implement substyles for all tags inside a style
                public Style () : base()
                {
                }
+
        }
 }
 
index 28eaf7808b0c845657a828559abc73df573424e6..c597abb9cb459185b5f1d4693e5999ab0d31c77d 100644 (file)
@@ -43,7 +43,6 @@ namespace Crow
 
                States curState = States.init;
 
-               string resourceId;
                int column = 1;
                int line = 1;
 
@@ -84,8 +83,7 @@ namespace Crow
 
                public StyleReader (Dictionary<string, Style> styling, Stream stream, string resId)
                        : base(stream)
-               {
-                       resourceId = resId;
+               {                       
                        string styleKey = resId.Substring (0, resId.Length - 6);
                        string token = "";
                        List<string> targetsClasses = new List<string> ();
@@ -100,13 +98,13 @@ namespace Crow
                                case '/':
                                        ReadChar ();
                                        if (PeekChar () != '/')
-                                               throw new ParserException (line, column, "Unexpected char '/'");
+                                               throw new ParserException (line, column, "Unexpected char '/'", resId);
                                        ReadLine ();
                                        break;
                                case ',':
                                        ReadChar ();
                                        if (!(curState == States.init || curState == States.classNames) || string.IsNullOrEmpty (token))
-                                               throw new ParserException (line, column, "Unexpected char ','");
+                                               throw new ParserException (line, column, "Unexpected char ','", resId);
                                        targetsClasses.Add (token);
                                        token = "";
                                        curState = States.classNames;
@@ -114,7 +112,7 @@ namespace Crow
                                case '{':
                                        ReadChar ();
                                        if (!(curState == States.init || curState == States.classNames) || string.IsNullOrEmpty (token))
-                                               throw new ParserException (line, column, "Unexpected char '{'");                                        
+                                               throw new ParserException (line, column, "Unexpected char '{'", resId);
                                        targetsClasses.Add (token);
                                        token = "";
                                        curState = States.members;
@@ -122,21 +120,21 @@ namespace Crow
                                case '}':
                                        ReadChar ();
                                        if (curState != States.members)
-                                               throw new ParserException (line, column, "Unexpected char '}'");                                        
+                                               throw new ParserException (line, column, "Unexpected char '}'", resId);
                                        curState = States.classNames;
                                        targetsClasses.Clear ();
                                        break;
                                case '=':
                                        ReadChar ();
                                        if (!(curState == States.init || curState == States.members))
-                                               throw new ParserException (line, column, "Unexpected char '='");
+                                               throw new ParserException (line, column, "Unexpected char '='", resId);
                                        currentProperty = token;
                                        token = "";
                                        curState = States.value;
                                        break;
                                case '"':
                                        if (curState != States.value)
-                                               throw new ParserException (line, column, "Unexpected char '\"'");                                       
+                                               throw new ParserException (line, column, "Unexpected char '\"'", resId);                                        
                                        ReadChar ();
 
                                        while (!EndOfStream) {
@@ -153,7 +151,7 @@ namespace Crow
                                        break;
                                case ';':
                                        if (curState != States.endOfStatement)
-                                               throw new ParserException (line, column, "Unexpected end of statement");                                        
+                                               throw new ParserException (line, column, "Unexpected end of statement", resId);                                 
                                        ReadChar ();
                                        foreach (string tc in targetsClasses) {
                                                if (!styling.ContainsKey (tc))
@@ -161,16 +159,19 @@ namespace Crow
                                                else if (styling [tc].ContainsKey (currentProperty))
                                                        continue;
                                                styling [tc] [currentProperty] = token;
-                                               System.Diagnostics.Debug.WriteLine ("Style: {0}.{1} = {2}", tc, currentProperty, token);
+                                               #if DESIGN_MODE
+                                               styling [tc].Locations[currentProperty] = new FileLocation(resId, line,column);
+                                               #endif
+                                               System.Diagnostics.Debug.WriteLine ("Style: {3} : {0}.{1} = {2}", tc, currentProperty, token, resId);
                                        }
                                        token = "";
                                        curState = States.members;
                                        break;
                                default:
                                        if (curState == States.value)
-                                               throw new ParserException (line, column, "expecting value enclosed in '\"'");
+                                               throw new ParserException (line, column, "expecting value enclosed in '\"'", resId);
                                        if (curState == States.endOfStatement)
-                                               throw new ParserException (line, column, "expecting end of statement");
+                                               throw new ParserException (line, column, "expecting end of statement", resId);
 
                                        if (nextCharIsValidCharStartName) {
                                                token += ReadChar();
@@ -195,10 +196,5 @@ namespace Crow
                                column++;
                        return tmp;
                }
-
-               void throwParserException(string message){
-                       throw new Exception (string.Format ("Style Reader Exception ({0},{1}): {2} in {3}.",
-                               line, column, message, resourceId));
-               }
        }
 }