From: Jean-Philippe Bruyère Date: Thu, 6 Mar 2025 13:32:54 +0000 (+0100) Subject: exceptions highlight, controled update loop X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=e5d65bbc9bd48b45291eae4279e15beb5a7cd03d;p=jp%2Fcrowedit.git exceptions highlight, controled update loop --- diff --git a/CrowEditBase/src/Compiler/SourceDocument.cs b/CrowEditBase/src/Compiler/SourceDocument.cs index a341853..b7126be 100644 --- a/CrowEditBase/src/Compiler/SourceDocument.cs +++ b/CrowEditBase/src/Compiler/SourceDocument.cs @@ -18,11 +18,12 @@ namespace CrowEditBase } protected SyntaxRootNode root; - public Command CMDRefreshSyntaxTree; + protected override void initCommands() { base.initCommands(); + CMDRefreshSyntaxTree = new ActionCommand ("Reparse", parse, "#icons.refresh.svg", true); } public SyntaxRootNode Root => root; @@ -152,5 +153,13 @@ namespace CrowEditBase //CrowEditBase.App.Log (LogType.Low, $"Syntax Analysis done in {sw.ElapsedMilliseconds}(ms) {sw.ElapsedTicks}(ticks)"); } + public SyntaxException CurrentException { + get => CrowEditBase.App.CurrentException; + set { + CrowEditBase.App.CurrentException = value; + SetLocation(value.Location); + } + } + } } \ No newline at end of file diff --git a/CrowEditBase/src/CrowEditBase.cs b/CrowEditBase/src/CrowEditBase.cs index 9dd7833..8af5540 100644 --- a/CrowEditBase/src/CrowEditBase.cs +++ b/CrowEditBase/src/CrowEditBase.cs @@ -193,6 +193,8 @@ namespace CrowEditBase return false; } + public CommandGroup SyntaxViewCommands => + currentDocument is SourceDocument src ? new CommandGroup (src.CMDRefreshSyntaxTree) : null; public Document CurrentDocument { get => currentDocument; set { @@ -214,6 +216,7 @@ namespace CrowEditBase EditCommands[0] = currentDocument.CMDUndo; EditCommands[1] = currentDocument.CMDRedo; + NotifyValueChanged("SyntaxViewCommands", SyntaxViewCommands); } } public Project CurrentProject { @@ -240,6 +243,16 @@ namespace CrowEditBase EditCommands[4] = currentEditor.CMDPaste; } } + SyntaxException currentException; + public SyntaxException CurrentException { + get => currentException; + set { + if (currentException == value) + return; + currentException = value; + NotifyValueChanged(currentException); + } + } public string CurrentDir { get => Configuration.Global.Get("CurrentDir"); set { @@ -552,7 +565,6 @@ namespace CrowEditBase CurrentEditor?.RegisterForGraphicUpdate (); } } - public bool IndentWithSpace { get => Configuration.Global.Get ("IndentWithSpace", false); set { diff --git a/CrowEditBase/src/LogViewerWidget.cs b/CrowEditBase/src/LogViewerWidget.cs index 835d2f4..898435b 100644 --- a/CrowEditBase/src/LogViewerWidget.cs +++ b/CrowEditBase/src/LogViewerWidget.cs @@ -136,7 +136,7 @@ namespace Crow lock (filteredLinesMutex) { //Console.WriteLine("updatefilteredlines"); lock (logger.LogMutext) - filteredLines = logger.log.Where (l=>((int)l.Type & (int)filter) > 0); + filteredLines = logger.log.Where (l=>((int)l.Type & (int)filter) > 0).ToArray(); MaxScrollY = filteredLines == null ? 0 : filteredLines.Count() - visibleLines; NotifyValueChanged ("ChildHeightRatio", Math.Min (1.0, (double)visibleLines / filteredLines.Count())); } @@ -318,7 +318,7 @@ namespace Crow IEnumerable entries; lock (filteredLinesMutex) { - entries = filteredLines.Skip(ScrollY).Take(visibleLines); + entries = filteredLines.Skip(ScrollY).Take(visibleLines).ToArray(); } //perf.Restart(); diff --git a/CrowEditBase/src/SourceEditor.cs b/CrowEditBase/src/SourceEditor.cs index 8775135..27b4d16 100644 --- a/CrowEditBase/src/SourceEditor.cs +++ b/CrowEditBase/src/SourceEditor.cs @@ -104,7 +104,7 @@ namespace CrowEditBase - + @@ -112,7 +112,6 @@ namespace CrowEditBase @@ -646,6 +645,7 @@ namespace CrowEditBase int printedLines = 0; int linesToSkip = (int)Math.Floor(ScrollY / lineHeight); + IEnumerator foldsEnum = doc.Root.VisibleFoldableNodes.GetEnumerator (); bool notEndOfFolds = foldsEnum.MoveNext(); @@ -659,7 +659,14 @@ namespace CrowEditBase int curLine = linesToSkip; pixY = -(ScrollY % lineHeight); + IEnumerator exceptionLines = doc.Root.GetAllExceptions()?.Select(e=>e.Location.Line).Order().GetEnumerator(); + bool hasExceptions = exceptionLines.MoveNext(); + while (curLine < doc.LinesCount && printedLines < Math.Min(visibleLines, doc.LinesCount)) { + + while (hasExceptions && exceptionLines.Current < curLine) { + hasExceptions = exceptionLines.MoveNext(); + } int encodedChar = 0; TextLine curTxtLine = doc.GetLine (curLine); @@ -722,7 +729,14 @@ namespace CrowEditBase fillHighlight (gr, curLine, hoverNodeStart.Value, hoverNodeEnd.Value, lineRect, new Color(0,0,0.8,0.1));; #endif if (selectionNotEmpty && curLine >= selStart.Line && curLine <= selEnd.Line) - fillHighlight (gr, curLine, selStart, selEnd, lineRect, SelectionBackground); + fillHighlight (gr, curLine, selStart, selEnd, lineRect, SelectionBackground); + if (hasExceptions && exceptionLines.Current == curLine) { + gr.Operator = Operator.DestOver; + gr.SetSource (new Color(1.0,0,0.0,0.3)); + gr.Rectangle (lineRect); + gr.Fill (); + gr.Operator = Operator.Over; + } //Draw line numbering if (printLineNumbers){ diff --git a/CrowEditBase/src/TextDocument.cs b/CrowEditBase/src/TextDocument.cs index 3fa2d66..12fbf26 100644 --- a/CrowEditBase/src/TextDocument.cs +++ b/CrowEditBase/src/TextDocument.cs @@ -56,14 +56,14 @@ namespace CrowEditBase registeredClients.Remove (client); ExitWriteLock(); } - void notifyClients (TextChange tc, object triggeringClient = null) { + protected void notifyClients (TextChange tc, object triggeringClient = null) { object[] clients = registeredClients.Keys.ToArray (); for (int i = 0; i < clients.Length; i++) { if (clients[i] != triggeringClient) notifyClient (clients[i], tc); } } - void notifyClient (object client, TextChange tc) { + protected void notifyClient (object client, TextChange tc) { if (registeredClients[client] == null) registeredClients[client] = new List (); registeredClients[client].Add (tc); diff --git a/CrowEditBase/ui/DockWindow.template b/CrowEditBase/ui/DockWindow.template index befd6e0..6cb14e8 100644 --- a/CrowEditBase/ui/DockWindow.template +++ b/CrowEditBase/ui/DockWindow.template @@ -5,6 +5,7 @@ @@ -13,6 +14,7 @@