aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-03-02 07:53:54 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-03-02 07:53:54 +0100
commit5bcd45c3ccc34edc68188a3acdb09e742b21aef3 (patch)
tree8370f0536cb66b6b32c70199f02d3234985ca0cf /src
parente02ca10075b3441ad25b697db405ccc7d6436404 (diff)
CrowIDE wip, removed key repeat already handled by otk
Diffstat (limited to 'src')
-rw-r--r--src/Configuration.cs3
-rw-r--r--src/GraphicObjects/GraphicObject.cs117
-rw-r--r--src/GraphicObjects/TemplatedGroup.cs2
-rw-r--r--src/Interface.cs26
-rw-r--r--src/ParsingException.cs8
-rw-r--r--src/Style.cs21
-rw-r--r--src/StyleReader.cs32
7 files changed, 109 insertions, 100 deletions
diff --git a/src/Configuration.cs b/src/Configuration.cs
index a6b0f0b0..a6328c0a 100644
--- a/src/Configuration.cs
+++ b/src/Configuration.cs
@@ -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 ());
}
}
}
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index f5a1a224..adb29e54 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -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){
diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs
index a5cd2dd6..42ffa51c 100644
--- a/src/GraphicObjects/TemplatedGroup.cs
+++ b/src/GraphicObjects/TemplatedGroup.cs
@@ -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)
diff --git a/src/Interface.cs b/src/Interface.cs
index 5d7f7720..cdfd24d7 100644
--- a/src/Interface.cs
+++ b/src/Interface.cs
@@ -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>
diff --git a/src/ParsingException.cs b/src/ParsingException.cs
index e3bd51c9..eb85504d 100644
--- a/src/ParsingException.cs
+++ b/src/ParsingException.cs
@@ -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)
{}
}
}
diff --git a/src/Style.cs b/src/Style.cs
index fded0503..58f09f33 100644
--- a/src/Style.cs
+++ b/src/Style.cs
@@ -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()
{
}
+
}
}
diff --git a/src/StyleReader.cs b/src/StyleReader.cs
index 28eaf780..c597abb9 100644
--- a/src/StyleReader.cs
+++ b/src/StyleReader.cs
@@ -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));
- }
}
}