]> 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)
19 files changed:
CrowIDE/src/EditPane.cs
CrowIDE/src/ImlVisualEditor.cs
CrowIDE/src/Project.cs
CrowIDE/src/ProjectNodes.cs
CrowIDE/src/PropertyContainer.cs
CrowIDE/src/Solution.cs
CrowIDE/src/SourceEditor/CSharpParser.cs
CrowIDE/src/SourceEditor/CodeBuffer.cs
CrowIDE/src/SourceEditor/SourceEditor.cs
CrowIDE/src/SourceEditor/StyleParser.cs
CrowIDE/src/SourceEditor/XMLParser.cs
CrowIDE/ui/CrowIDE.crow
src/Configuration.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/TemplatedGroup.cs
src/Interface.cs
src/ParsingException.cs
src/Style.cs
src/StyleReader.cs

index 780e86d5150be09bf42fb71676096d09ffeb60db..a75522f0664acf3a315e90e774df205f19914937 100644 (file)
@@ -35,6 +35,14 @@ namespace Crow.Coding
 
                object selectedItemElement = null;
 
+               public override int SelectedIndex {
+                       get {
+                               return base.SelectedIndex;
+                       }
+                       set {
+                               base.SelectedIndex = value;
+                       }
+               }
                public object SelectedItemElement {
                        get { return selectedItemElement; }
                        set {
index 7989936adad180005988f5ed3e10fe1026a4a87f..69ae551533dad7ac54a382e394b9e92559e792ee 100644 (file)
@@ -147,6 +147,7 @@ namespace Crow.Coding
                                                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);
index 0da5dc198f60e3d4e81524dba8dc754fe0202698..ff3469de759db5395727be4c4d0c120766e9d788 100644 (file)
@@ -377,7 +377,12 @@ namespace Crow.Coding
                        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));
@@ -391,7 +396,7 @@ namespace Crow.Coding
                                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
index 4f24060f1c9b7abef9d7d8f2bf516a144df7eeac..c334826674e7883efbb2d191dc03796ae59e8a6f 100644 (file)
@@ -95,7 +95,11 @@ namespace Crow.Coding
                        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
index 298dcd157e1b2c9fb1c578eae4568fdb6d6fd30f..c89273cc02305fd4b678413d253e92ae402bc364 100644 (file)
@@ -42,6 +42,7 @@ namespace Crow.Coding
                #endregion
 
                public List<Crow.Command> Commands;
+               Command cmdReset, cmdGoToStyle;
                PropertyInfo pi;
                MembersView mview;
 //             object instance;
@@ -53,9 +54,10 @@ namespace Crow.Coding
 //                     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; }}
@@ -128,7 +130,10 @@ namespace Crow.Coding
                }
 
                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>
@@ -143,7 +148,20 @@ namespace Crow.Coding
                        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;
+               }
 
 
        }
index 9874fd4a8aad21407b48f7b067667d319069da1e..7ed6b7800d8141c296457876ebba2810ad91659f 100644 (file)
@@ -66,10 +66,9 @@ namespace Crow.Coding{
                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 {
@@ -139,20 +138,49 @@ namespace Crow.Coding{
                        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>
@@ -243,7 +271,9 @@ namespace Crow.Coding{
            /// <summary>
            /// Creates new solution.
            /// </summary>
-           public Solution() { }
+           public Solution() { 
+               }
+
                #endregion
 
 
@@ -412,6 +442,7 @@ namespace Crow.Coding{
                        s.UserConfig = new Configuration (s.path + ".user");
                        s.ReloadStyling ();
                        s.ReloadDefaultTemplates ();
+                       s.reopenItemsSavedInUserConfig ();
                return s;
            } //LoadSolution
                #endregion
index 23aef43e362a00b52264da9aa03a99c37891a526..d7f15a7aa939c8d34d733df37c483beacce94fc1 100644 (file)
@@ -150,7 +150,7 @@ namespace Crow.Coding
 
                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> ();
 
index 55d8897856d5e74049c7b52c5251724e429aef15..66c24857ca810b771dfbdac999bf8200db2aef57 100644 (file)
@@ -23,6 +23,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text.RegularExpressions;
 using System.Diagnostics;
+using System.Threading;
 
 namespace Crow.Coding
 {
@@ -31,7 +32,8 @@ 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
@@ -65,72 +67,72 @@ namespace Crow.Coding
                        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();
@@ -410,37 +412,40 @@ namespace Crow.Coding
                }
                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.
index 6480af189d0584292267672ac7643906a16eb7c7..b0e8a35fb90d57202a7c349c2ed1a27c411cde84 100644 (file)
@@ -93,18 +93,18 @@ namespace Crow.Coding
                                                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);
                        }
@@ -187,30 +187,30 @@ namespace Crow.Coding
                        }
                }                       
                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)
@@ -786,29 +786,29 @@ namespace Crow.Coding
 
                        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
 
index 13c94d90d0adaf39201d9edeb5390bd975a91ff9..2aba68480ba989f9423ebd122f1540cf1c0eb79f 100644 (file)
@@ -36,7 +36,7 @@ namespace Crow.Coding
 
                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> ();
 
index ada055124a34ade5e03f80419dca4520388e3bbb..6f00158705a5089324581b26b54f15999c38b419 100644 (file)
@@ -90,7 +90,7 @@ namespace Crow.Coding
 
                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> ();
 
index 9e2694f99deaed4657c818730fffa45eeaba1039..395503f5f701f10b829eb690893a39001df3d93f 100644 (file)
@@ -34,7 +34,7 @@
                <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%">
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));
-               }
        }
 }