object selectedItemElement = null;
+ public override int SelectedIndex {
+ get {
+ return base.SelectedIndex;
+ }
+ set {
+ base.SelectedIndex = value;
+ }
+ }
public object SelectedItemElement {
get { return selectedItemElement; }
set {
imlVE.ClearInterface();
Instantiator.NextInstantiatorID = 0;
imlVE.Styling = projFile.Project.solution.Styling;
+ imlVE.DefaultValuesLoader.Clear();
imlVE.DefaultTemplates = projFile.Project.solution.DefaultTemplates;
imlVE.Instantiators = new Dictionary<string, Instantiator>();
imlVE.LoadIMLFragment(projFile.Source);
return parameters.OutputAssembly;
}
- public bool GetProjectFileFromPath (string path, out ProjectFile pi){
+ public bool TryGetProjectFileFromAbsolutePath (string absolutePath, out ProjectFile pi){
+ pi = flattenNodes.OfType<ProjectFile> ().FirstOrDefault
+ (pp => pp.AbsolutePath == absolutePath);
+ return pi != null;
+ }
+ public bool TryGetProjectFileFromPath (string path, out ProjectFile pi){
if (path.StartsWith ("#"))
pi = flattenNodes.OfType<ProjectFile> ().FirstOrDefault
(pp => pp.Type == ItemType.EmbeddedResource && pp.ResourceID == path.Substring (1));
Project p = solution.Projects.FirstOrDefault (pp => pp.ProjectGuid == pr.ProjectGUID);
if (p == null)
throw new Exception ("referenced project not found");
- if (p.GetProjectFileFromPath (path, out pi))
+ if (p.TryGetProjectFileFromPath (path, out pi))
return true;
}
//TODO: search referenced assemblies
foreach (ProjectNode pn in childNodes)
pn.SortChilds ();
childNodes = childNodes.OrderBy(c=>c.Type).ThenBy(cn=>cn.DisplayName).ToList();
- }
+ }
+ public override string ToString ()
+ {
+ return DisplayName;
+ }
}
public class ProjectItem : ProjectNode {
#region CTOR
#endregion
public List<Crow.Command> Commands;
+ Command cmdReset, cmdGoToStyle;
PropertyInfo pi;
MembersView mview;
// object instance;
// instance = _instance;
// go = instance as GraphicObject;
- Commands = new List<Crow.Command> (new Crow.Command[] {
- new Crow.Command(new Action(() => Reset())) { Caption = "Reset to default"},
- });
+ cmdReset = new Crow.Command (new Action (() => Reset ())) { Caption = "Reset to default" };
+ cmdGoToStyle = new Crow.Command (new Action (() => GotoStyle ())) { Caption = "Goto style" };
+
+ Commands = new List<Crow.Command> (new Crow.Command[] { cmdReset, cmdGoToStyle });
}
public string Name { get { return pi.Name; }}
}
public Fill LabForeground {
- get { return (mview.ProjectNode.SelectedItem as GraphicObject).design_members.ContainsKey(Name) ? Color.Black : Color.DimGray;}
+ get {
+ GraphicObject go = mview.ProjectNode.SelectedItem as GraphicObject;
+ return go.design_members.ContainsKey (Name) ? Color.Black :
+ go.design_defaults.ContainsKey(Name) ? Color.DarkBlue : Color.DimGray;}
}
/// <summary>
mview.ProjectNode.Instance.HasChanged = true;
//should reinstantiate to get default
}
-
+ public void GotoStyle(){
+ GraphicObject inst = mview.ProjectNode.SelectedItem as GraphicObject;
+ if (!inst.design_defaults.ContainsKey (Name))
+ return;
+ FileLocation fl = inst.design_defaults [Name];
+ ProjectFile pf;
+ if (!mview.ProjectNode.Project.TryGetProjectFileFromPath ("#" + fl.FilePath, out pf))
+ return;
+ Solution s = mview.ProjectNode.Project.solution;
+ if (!s.OpenedItems.Contains (pf))
+ s.OpenedItems.Add (pf);
+ //pf.CurrentLine = fl.Line;
+ //pf.CurrentColumn = fl.Column;
+ }
}
public bool GetProjectFileFromPath (string path, out ProjectFile pi){
pi = null;
return StartupProject == null ? false :
- StartupProject.GetProjectFileFromPath (path, out pi);
+ StartupProject.TryGetProjectFileFromPath (path, out pi);
}
-
public ObservableList<ProjectItem> OpenedItems {
get { return openedItems; }
set {
NotifyValueChanged ("CompilerErrors", CompilerErrors);
}
+ void saveOpenedItemsInUserConfig (){
+ UserConfig.Set ("OpenedItems", openedItems.Select(o => o.AbsolutePath).Aggregate((a,b)=>a + ";" + b));
+ }
+ void reopenItemsSavedInUserConfig () {
+ string tmp = UserConfig.Get<string> ("OpenedItems");
+ string sel = UserConfig.Get<string> ("SelectedProjItems");
+ ProjectFile selItem = null;
+ if (string.IsNullOrEmpty (tmp))
+ return;
+ foreach (string f in tmp.Split(';')) {
+ foreach (Project p in Projects) {
+ ProjectFile pi;
+ if (p.TryGetProjectFileFromAbsolutePath (f, out pi)) {
+ OpenedItems.Add (pi);
+ if (pi.AbsolutePath == sel)
+ selItem = pi;
+ break;
+ }
+ }
+ }
+ SelectedItem = selItem;//BUG: loading in another thread focused last loaded pf
+ }
+
void onSelectedItemChanged (object sender, SelectionChangeEventArgs e){
ProjectItem pi = e.NewValue as ProjectItem;
if (pi != null) {
- if (!openedItems.Contains (pi))
+ if (!openedItems.Contains (pi)) {
openedItems.AddElement (pi);
+ saveOpenedItemsInUserConfig ();
+ }
}
this.SelectedItem = pi;
+ UserConfig.Set ("SelectedProjItems", SelectedItem?.AbsolutePath);
}
public void OnCloseTab (object sender, MouseButtonEventArgs e){
-
+ Console.WriteLine ("OnCloseTab");
openedItems.RemoveElement ((sender as GraphicObject).DataSource as ProjectItem);
+ saveOpenedItemsInUserConfig ();
}
public void CloseItem (ProjectItem pi) {
+ Console.WriteLine ("CloseItem");
openedItems.RemoveElement (pi);
+ saveOpenedItemsInUserConfig ();
}
/// <summary>
/// <summary>
/// Creates new solution.
/// </summary>
- public Solution() { }
+ public Solution() {
+ }
+
#endregion
s.UserConfig = new Configuration (s.path + ".user");
s.ReloadStyling ();
s.ReloadDefaultTemplates ();
+ s.reopenItemsSavedInUserConfig ();
return s;
} //LoadSolution
#endregion
public override void ParseCurrentLine ()
{
- Debug.WriteLine (string.Format("parsing line:{0}", currentLine));
+ //Debug.WriteLine (string.Format("parsing line:{0}", currentLine));
CodeLine cl = buffer [currentLine];
cl.Tokens = new List<Token> ();
using System.Linq;
using System.Text.RegularExpressions;
using System.Diagnostics;
+using System.Threading;
namespace Crow.Coding
{
/// </summary>
public class CodeBuffer
{
- public object EditMutex = new object();
+ public ReaderWriterLockSlim editMutex = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
+
//those events are handled in SourceEditor to help keeping sync between textbuffer,parser and editor.
//modified lines are marked for reparse
#region Events
set {
if (lines [i] == value)
return;
- lock (EditMutex) {
- lines [i] = value;
- LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i));
- }
+ editMutex.EnterWriteLock ();
+ lines [i] = value;
+ LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i));
+ editMutex.ExitWriteLock ();
}
}
public void RemoveAt(int i){
- lock (EditMutex) {
- lines.RemoveAt (i);
- LineRemoveEvent.Raise (this, new CodeBufferEventArgs (i));
- }
+ editMutex.EnterWriteLock ();
+ lines.RemoveAt (i);
+ LineRemoveEvent.Raise (this, new CodeBufferEventArgs (i));
+ editMutex.ExitWriteLock ();
}
public void Insert(int i, string item){
- lock (EditMutex) {
- lines.Insert (i, item);
- LineAdditionEvent.Raise (this, new CodeBufferEventArgs (i));
- }
+ editMutex.EnterWriteLock ();
+ lines.Insert (i, item);
+ LineAdditionEvent.Raise (this, new CodeBufferEventArgs (i));
+ editMutex.ExitWriteLock ();
}
public void Add(CodeLine item){
- lock (EditMutex) {
- lines.Add (item);
- LineAdditionEvent.Raise (this, new CodeBufferEventArgs (lines.Count - 1));
- }
+ editMutex.EnterWriteLock ();
+ lines.Add (item);
+ LineAdditionEvent.Raise (this, new CodeBufferEventArgs (lines.Count - 1));
+ editMutex.ExitWriteLock ();
}
public void AddRange (string[] items){
int start = lines.Count;
- lock (EditMutex) {
- for (int i = 0; i < items.Length; i++)
- lines.Add (items [i]);
- LineAdditionEvent.Raise (this, new CodeBufferEventArgs (start, items.Length));
- }
+ editMutex.EnterWriteLock ();
+ for (int i = 0; i < items.Length; i++)
+ lines.Add (items [i]);
+ LineAdditionEvent.Raise (this, new CodeBufferEventArgs (start, items.Length));
+ editMutex.ExitWriteLock ();
}
public void AddRange (CodeLine[] items){
int start = lines.Count;
- lock (EditMutex) {
- lines.AddRange (items);
- LineAdditionEvent.Raise (this, new CodeBufferEventArgs (start, items.Length));
- }
+ editMutex.EnterWriteLock ();
+ lines.AddRange (items);
+ LineAdditionEvent.Raise (this, new CodeBufferEventArgs (start, items.Length));
+ editMutex.ExitWriteLock ();
}
public void Clear () {
- lock (EditMutex) {
- longestLineCharCount = 0;
- lines.Clear ();
- BufferCleared.Raise (this, null);
- }
+ editMutex.EnterWriteLock ();
+ longestLineCharCount = 0;
+ lines.Clear ();
+ BufferCleared.Raise (this, null);
+ editMutex.ExitWriteLock ();
}
public void UpdateLine(int i, string newContent){
- lock (EditMutex) {
- this [i].Content = newContent;
- LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i));
- }
+ editMutex.EnterWriteLock ();
+ this [i].Content = newContent;
+ LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i));
+ editMutex.ExitWriteLock ();
}
public void AppenedLine(int i, string newContent){
- lock (EditMutex) {
- this [i].Content += newContent;
- LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i));
- }
+ editMutex.EnterWriteLock ();
+ this [i].Content += newContent;
+ LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i));
+ editMutex.ExitWriteLock ();
}
public void ToogleFolding (int line) {
if (!this [line].IsFoldable)
return;
- lock (EditMutex) {
- this [line].IsFolded = !this [line].IsFolded;
- FoldingEvent.Raise (this, new CodeBufferEventArgs (line));
- }
+ editMutex.EnterWriteLock ();
+ this [line].IsFolded = !this [line].IsFolded;
+ FoldingEvent.Raise (this, new CodeBufferEventArgs (line));
+ editMutex.ExitWriteLock ();
}
public void Load(string rawSource, string lineBrkRegex = @"\r\n|\r|\n|\\\n") {
this.Clear();
}
public void DeleteChar()
{
- lock (EditMutex) {
- if (SelectionIsEmpty) {
- if (CurrentColumn == 0) {
- if (CurrentLine == 0)
- return;
- CurrentLine--;
- CurrentColumn = this [CurrentLine].Length;
- AppenedLine (CurrentLine, this [CurrentLine + 1].Content);
- RemoveAt (CurrentLine + 1);
+ editMutex.EnterWriteLock ();
+ if (SelectionIsEmpty) {
+ if (CurrentColumn == 0) {
+ if (CurrentLine == 0) {
+ editMutex.ExitWriteLock ();
return;
}
- CurrentColumn--;
- UpdateLine (CurrentLine, this [CurrentLine].Content.Remove (CurrentColumn, 1));
- } else {
- int linesToRemove = SelectionEnd.Y - SelectionStart.Y + 1;
- int l = SelectionStart.Y;
+ CurrentLine--;
+ CurrentColumn = this [CurrentLine].Length;
+ AppenedLine (CurrentLine, this [CurrentLine + 1].Content);
+ RemoveAt (CurrentLine + 1);
+ editMutex.ExitWriteLock ();
+ return;
+ }
+ CurrentColumn--;
+ UpdateLine (CurrentLine, this [CurrentLine].Content.Remove (CurrentColumn, 1));
+ } else {
+ int linesToRemove = SelectionEnd.Y - SelectionStart.Y + 1;
+ int l = SelectionStart.Y;
- if (linesToRemove > 0) {
- UpdateLine (l, this [l].Content.Remove (SelectionStart.X, this [l].Length - SelectionStart.X) +
- this [SelectionEnd.Y].Content.Substring (SelectionEnd.X, this [SelectionEnd.Y].Length - SelectionEnd.X));
- l++;
- for (int c = 0; c < linesToRemove - 1; c++)
- RemoveAt (l);
- CurrentLine = SelectionStart.Y;
- CurrentColumn = SelectionStart.X;
- } else
- UpdateLine (l, this [l].Content.Remove (SelectionStart.X, SelectionEnd.X - SelectionStart.X));
+ if (linesToRemove > 0) {
+ UpdateLine (l, this [l].Content.Remove (SelectionStart.X, this [l].Length - SelectionStart.X) +
+ this [SelectionEnd.Y].Content.Substring (SelectionEnd.X, this [SelectionEnd.Y].Length - SelectionEnd.X));
+ l++;
+ for (int c = 0; c < linesToRemove - 1; c++)
+ RemoveAt (l);
+ CurrentLine = SelectionStart.Y;
CurrentColumn = SelectionStart.X;
- ResetSelection ();
- }
+ } else
+ UpdateLine (l, this [l].Content.Remove (SelectionStart.X, SelectionEnd.X - SelectionStart.X));
+ CurrentColumn = SelectionStart.X;
+ ResetSelection ();
}
+ editMutex.ExitWriteLock ();
}
/// <summary>
/// Insert new string at caret position, should be sure no line break is inside.
oldSource = projFile.Source;
projFile.RegisteredEditors [this] = true;
}
- if (Monitor.TryEnter (buffer.EditMutex)) {
- string newsrc = "";
- bool wasDirty = false;
- if (isDirty) {
- isDirty = false;
- wasDirty = true;
- newsrc = buffer.FullText;
- }
- Monitor.Exit (buffer.EditMutex);
- if (wasDirty)
- projFile.UpdateSource (this, newsrc);
+ buffer.editMutex.EnterWriteLock ();
+ string newsrc = "";
+ bool wasDirty = false;
+ if (isDirty) {
+ isDirty = false;
+ wasDirty = true;
+ newsrc = buffer.FullText;
}
+ buffer.editMutex.ExitWriteLock ();
+ if (wasDirty)
+ projFile.UpdateSource (this, newsrc);
+
}
Thread.Sleep (100);
}
}
}
void updatePrintedLines () {
- lock (buffer.EditMutex) {
- PrintedLines = new List<CodeLine> ();
- int curL = 0;
- int i = 0;
-
- while (curL < buffer.LineCount && i < ScrollY) {
- if (buffer [curL].IsFolded)
- curL = buffer.GetEndNodeIndex (curL);
- curL++;
- i++;
- }
+ buffer.editMutex.EnterReadLock ();
+ PrintedLines = new List<CodeLine> ();
+ int curL = 0;
+ int i = 0;
- firstPrintedLine = curL;
- i = 0;
- while (i < visibleLines && curL < buffer.LineCount) {
- PrintedLines.Add (buffer [curL]);
+ while (curL < buffer.LineCount && i < ScrollY) {
+ if (buffer [curL].IsFolded)
+ curL = buffer.GetEndNodeIndex (curL);
+ curL++;
+ i++;
+ }
- if (buffer [curL].IsFolded)
- curL = buffer.GetEndNodeIndex (curL);
+ firstPrintedLine = curL;
+ i = 0;
+ while (i < visibleLines && curL < buffer.LineCount) {
+ PrintedLines.Add (buffer [curL]);
- curL++;
- i++;
- }
+ if (buffer [curL].IsFolded)
+ curL = buffer.GetEndNodeIndex (curL);
+
+ curL++;
+ i++;
}
+ buffer.editMutex.ExitReadLock ();
}
void toogleFolding (int line) {
if (parser == null || !foldingEnabled)
Foreground.SetAsSource (gr);
- lock (buffer.EditMutex) {
- #region draw text cursor
- if (buffer.SelectionInProgress){
- selStartCol = getTabulatedColumn (buffer.SelectionStart);
- selEndCol = getTabulatedColumn (buffer.SelectionEnd);
- }else if (HasFocus && printedCurrentLine >= 0){
- gr.LineWidth = 1.0;
- double cursorX = cb.X + (getTabulatedColumn(buffer.CurrentPosition) - ScrollX) * fe.MaxXAdvance + leftMargin;
- gr.MoveTo (0.5 + cursorX, cb.Y + (printedCurrentLine) * (fe.Ascent+fe.Descent));
- gr.LineTo (0.5 + cursorX, cb.Y + (printedCurrentLine + 1) * (fe.Ascent+fe.Descent));
- gr.Stroke();
- }
- #endregion
+ buffer.editMutex.EnterReadLock ();
+ #region draw text cursor
+ if (buffer.SelectionInProgress){
+ selStartCol = getTabulatedColumn (buffer.SelectionStart);
+ selEndCol = getTabulatedColumn (buffer.SelectionEnd);
+ }else if (HasFocus && printedCurrentLine >= 0){
+ gr.LineWidth = 1.0;
+ double cursorX = cb.X + (getTabulatedColumn(buffer.CurrentPosition) - ScrollX) * fe.MaxXAdvance + leftMargin;
+ gr.MoveTo (0.5 + cursorX, cb.Y + (printedCurrentLine) * (fe.Ascent+fe.Descent));
+ gr.LineTo (0.5 + cursorX, cb.Y + (printedCurrentLine + 1) * (fe.Ascent+fe.Descent));
+ gr.Stroke();
+ }
+ #endregion
- if (PrintedLines != null) {
- for (int i = 0; i < visibleLines; i++) {
- if (i + ScrollY >= buffer.UnfoldedLines)//TODO:need optimize
- break;
- drawLine (gr, cb, i);
- }
+ if (PrintedLines != null) {
+ for (int i = 0; i < visibleLines; i++) {
+ if (i + ScrollY >= buffer.UnfoldedLines)//TODO:need optimize
+ break;
+ drawLine (gr, cb, i);
}
}
- //System.Threading.Monitor.Exit (buffer.EditMutex);
+ buffer.editMutex.ExitReadLock ();
+
}
#endregion
public override void ParseCurrentLine ()
{
- Debug.WriteLine (string.Format("parsing line:{0}", currentLine));
+ //Debug.WriteLine (string.Format("parsing line:{0}", currentLine));
CodeLine cl = buffer [currentLine];
cl.Tokens = new List<Token> ();
public override void ParseCurrentLine ()
{
- Debug.WriteLine (string.Format("parsing line:{0}", currentLine));
+ //Debug.WriteLine (string.Format("parsing line:{0}", currentLine));
CodeLine cl = buffer [currentLine];
cl.Tokens = new List<Token> ();
<VerticalStack DataSource="{CurrentSolution}">
<Label Background="Gray" Text="{SelectedItem}" Width="Stretched" TextAlignment="Left"/>
<HorizontalStack Height="80%">
- <EditPane SelectedItem="{SelectedItem}" SelectedItemElement="{²SelectedItemElement}" Data="{OpenedItems}" DataTest="Extension"
+ <EditPane SelectedItem="{²SelectedItem}" SelectedItemElement="{²SelectedItemElement}" Data="{OpenedItems}" DataTest="Extension"
ItemTemplate="#Crow.Coding.ui.EditPaneItems.template"/>
<Splitter/>
<VerticalStack Width="30%">
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));
- }
}
}