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 ());
}
}
}
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){
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>();
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
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);
}
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){
: items.Children;
}
}
- [XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{
+ [XmlAttributeAttribute][DefaultValue(-1)]public virtual int SelectedIndex{
get { return _selectedIndex; }
set {
if (value == _selectedIndex)
}
}
}
- 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];
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;
}
_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>
{
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)
{}
}
}
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()
{
}
+
}
}
States curState = States.init;
- string resourceId;
int column = 1;
int line = 1;
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> ();
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;
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;
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) {
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))
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();
column++;
return tmp;
}
-
- void throwParserException(string message){
- throw new Exception (string.Format ("Style Reader Exception ({0},{1}): {2} in {3}.",
- line, column, message, resourceId));
- }
}
}