]> O.S.I.I.S - jp/crowedit.git/commitdiff
exceptions highlight, controled update loop
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 6 Mar 2025 13:32:54 +0000 (14:32 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 6 Mar 2025 13:32:54 +0000 (14:32 +0100)
12 files changed:
CrowEditBase/src/Compiler/SourceDocument.cs
CrowEditBase/src/CrowEditBase.cs
CrowEditBase/src/LogViewerWidget.cs
CrowEditBase/src/SourceEditor.cs
CrowEditBase/src/TextDocument.cs
CrowEditBase/ui/DockWindow.template
plugins/CECrowPlugin/src/DebugInterface.cs
plugins/CECrowPlugin/src/DebugInterfaceWidget.cs
plugins/CECrowPlugin/src/ForeignWidgetContainer.cs
plugins/CECrowPlugin/ui/winProperties.crow
ui/windows/winExceptions.crow
ui/windows/winSyntaxExplorer.crow

index a341853f713a77e9c5635cf65bf379a256fcf3cb..b7126bec3472fbd6db3fc7736169dac5b0a4e8e3 100644 (file)
@@ -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
index 9dd78338ba9799aba41ef4a405cacce9cc1d6414..8af5540ba7b7e8abd3815b37956a75c7cf99cd1d 100644 (file)
@@ -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<string>("CurrentDir");
                        set {
@@ -552,7 +565,6 @@ namespace CrowEditBase
                                CurrentEditor?.RegisterForGraphicUpdate ();
                        }
                }
-
                public bool IndentWithSpace {
                        get => Configuration.Global.Get<bool> ("IndentWithSpace", false);
                        set {
index 835d2f4e85ab5000a5c1287d0b038b19e064b689..898435b4d4b323a20d132c6cd155746c7e71b1d9 100644 (file)
@@ -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<LogEntry> entries;
                        lock (filteredLinesMutex) {
-                               entries = filteredLines.Skip(ScrollY).Take(visibleLines);
+                               entries = filteredLines.Skip(ScrollY).Take(visibleLines).ToArray();
                        }
 
                        //perf.Restart();
index 8775135375cdbcf2dddd376e6c6236d2fb32b87e..27b4d16cb459ff8646e193c409c8c59bb96f4fa4 100644 (file)
@@ -104,7 +104,7 @@ namespace CrowEditBase
                                                                                <!--<Label Text='{Caption}' HorizontalAlignment='Left' Width='Stretched'/>-->
                                                                        </ListItem>
                                                                </ItemTemplate>
-                                                               <ItemTemplate DataType='CrowEditBase.ColorSuggestion'>
+                                                               <ItemTemplate DataType='CECrowPlugin.ColorSuggestion'>
                                                                        <ListItem Height='Fit' Margin='0' Focusable='false' HorizontalAlignment='Left' Width='Stretched'
                                                                                                                                        Selected = '{Background=${ControlHighlight}}'
                                                                                                                                        Unselected = '{Background=Transparent}'>
@@ -112,7 +112,6 @@ namespace CrowEditBase
                                                                                        <Image Margin='6' Path='{Icon}' Width='32' Height='24' Background='{Fill}' CornerRadius='2'/>
                                                                                        <Label Text='{Caption}' HorizontalAlignment='Left' Width='Stretched'/>
                                                                                </HorizontalStack>
-                                                                               <!--<Label Text='{Caption}' HorizontalAlignment='Left' Width='Stretched'/>-->
                                                                        </ListItem>
                                                                </ItemTemplate>
                                                        </ListBox>
@@ -646,6 +645,7 @@ namespace CrowEditBase
                                
                                int printedLines = 0;
                                int linesToSkip = (int)Math.Floor(ScrollY / lineHeight);
+
                                
                                IEnumerator<SyntaxNode> foldsEnum = doc.Root.VisibleFoldableNodes.GetEnumerator ();
                                bool notEndOfFolds = foldsEnum.MoveNext();
@@ -659,7 +659,14 @@ namespace CrowEditBase
                                int curLine = linesToSkip;
                                pixY = -(ScrollY % lineHeight);
 
+                               IEnumerator<int> 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){
index 3fa2d6655b6f253e847ad86a33842b87b37813ef..12fbf263cd9613981977adc68b4292713e6d3bce 100644 (file)
@@ -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<TextChange> ();
                        registeredClients[client].Add (tc);
index befd6e02823f2121e28dcbd0ff5bd5d24c4a2f6b..6cb14e8e1feb0e7b8f7e33cc841ec2717a1b9ac6 100644 (file)
@@ -5,6 +5,7 @@
        <VerticalStack Spacing="0" Name="MoveHandle">
                <HorizontalStack Visible="{./IsDockedInStack}" Height="Fit" Margin="1" Background="Jet" Width="Stretched">
                        <Label  Text="{./Caption}" TextAlignment="Left" Width="Stretched" Foreground="DimGrey" Font="${SmallUIFont}"/>
+                       <ListBox Style="DockWinTitleBarIconMenu" Data="{./AdditionalCommands}"/>
                        <ListBox Style="DockWinTitleBarIconMenu" Data="{./DockCommands}"/>
                        <ListBox Style="DockWinTitleBarIconMenu" Data="{./Commands}"/>
                </HorizontalStack>
@@ -13,6 +14,7 @@
                        <Widget Width="5"/>
                        <Image Margin="1" Width="10" Height="10" Path="{./Icon}"/>
                        <Label Width="Stretched" Foreground="White" Margin="1" TextAlignment="Left" Text="{./Caption}"  />
+                       <ListBox Style="DockWinTitleBarIconMenu" Data="{./AdditionalCommands}"/>
                        <ListBox Style="DockWinTitleBarIconMenu" Data="{./DockCommands}"/>
                        <ListBox Style="DockWinTitleBarIconMenu" Data="{./Commands}"/>
                        <Widget Width="5"/>
index a4f03172f609a0ecaf88a7ca7b05133a51b39018..ff760be36c2f043042ae334c7c2aa02bb4838d96 100644 (file)
@@ -50,11 +50,26 @@ namespace CECrowPlugin
                        t.Start ();
                }
                public bool Terminate;
+               public bool Edition = true;
+               public bool FirstRenderingFinished = false;
                void interfaceThread () {
                        while (!Terminate) {
                                try
                                {
-                                       Update();
+                                       if (Edition) {
+                                               if (FirstRenderingFinished)
+                                                       Thread.Sleep(500);      
+
+                                               int lqiCount;
+                                               lock(LayoutMutex)
+                                                       lqiCount = LayoutingQueue.Count;
+                                               while(lqiCount > 0) {
+                                                       Update();
+                                                       lock(LayoutMutex)
+                                                               lqiCount = LayoutingQueue.Count;
+                                               }
+                                               FirstRenderingFinished = true;
+                                       }
                                }
                                catch (System.Exception ex)
                                {
@@ -79,7 +94,7 @@ namespace CECrowPlugin
                                        delCrowServiceSetCurrentException (ex);
                                        Console.WriteLine ($"[DbgIFace] {ex}");
                                        ClearInterface();
-                                       Thread.Sleep(1000);
+                                       Thread.Sleep(2000);
                                }
 
                                /*if (IsDirty)
@@ -131,6 +146,7 @@ namespace CECrowPlugin
                                                resetInterface ();
                                                if (string.IsNullOrEmpty(source))
                                                        return;
+                                               FirstRenderingFinished = false;
                                                Widget tmp = CreateITorFromIMLFragment (source).CreateInstance();
                                                AddWidget (tmp);
                                                tmp.DataSource = this;
@@ -169,6 +185,7 @@ namespace CECrowPlugin
                }
                public void Resize (int width, int height) {
                        ProcessResize (new Rectangle(0, 0, width, height));
+                       FirstRenderingFinished = false;
                }
         /*public override void ProcessResize(Rectangle bounds) {
                        lock (UpdateMutex) {
index 2f0c73b0e07c4d58fb727e7a7658acf67f39fb5d..6e18918716bf59e340f56d67d8cf0f6e9761be14 100644 (file)
@@ -27,7 +27,8 @@ namespace CECrowPlugin
                                NotifyValueChangedAuto (crowIFaceService);
                        }
                }
-               Command CMDRefresh, CMDZoomIn, CMDZoomOut;
+               
+               Command CMDRefresh, CMDZoomIn, CMDZoomOut, CMDRun;
                public DebugInterfaceWidget () : base () {
                        CMDRefresh = new ActionCommand (this, "Refresh",
                                () => {
@@ -51,6 +52,7 @@ namespace CECrowPlugin
                                                RegisterForGraphicUpdate ();
                                        }
                                }, "#icons.zoom-out.svg");
+                       //CMDRun = new ToggleCommand(this,"Run",,)
 
                        Thread t = new Thread (backgroundThreadFunc);
                        t.IsBackground = true;
@@ -74,12 +76,17 @@ namespace CECrowPlugin
                        }
                }
                void updateIMLSource (TextChange change) {
+                       if (string.IsNullOrEmpty(change.ChangedText) && change.CharDiff == 0)
+                               return;
                        ReadOnlySpan<char> src = imlSource.AsSpan ();
-                       Span<char> tmp = stackalloc char[src.Length + (change.ChangedText.Length - change.Length)];
+                       Span<char> tmp = stackalloc char[src.Length + change.CharDiff];
                        //Console.WriteLine ($"{Text.Length,-4} {change.Start,-4} {change.Length,-4} {change.ChangedText.Length,-4} tmp:{tmp.Length,-4}");
                        src.Slice (0, change.Start).CopyTo (tmp);
-                       change.ChangedText.AsSpan ().CopyTo (tmp.Slice (change.Start));
-                       src.Slice (change.End).CopyTo (tmp.Slice (change.Start + change.ChangedText.Length));
+
+                       if (!string.IsNullOrEmpty(change.ChangedText)) {
+                               change.ChangedText.AsSpan ().CopyTo (tmp.Slice (change.Start));
+                       }
+                       src.Slice (change.End).CopyTo (tmp.Slice (change.End2));
 
                        imlSource = tmp.ToString ();
 
index ddc9ddd7c7a431afea584ab515dbc10a370686b7..bb11241aec3197efb7d2da20ac3ca68dafe00ac5 100644 (file)
@@ -29,7 +29,6 @@ namespace CECrowPlugin
                        delGetName = (Func<string>)Delegate.CreateDelegate(typeof(Func<string>), instance, type.GetProperty("Name").GetGetMethod());
                }
 
-               public string Icon => $"#icons.{type.FullName}.svg";
 
                public IEnumerable<MemberInfo> Members => type.GetMembers (BindingFlags.Public | BindingFlags.Instance).
                                Where (m=>((m is PropertyInfo pi && pi.CanWrite) || (m is EventInfo)) &&
@@ -38,6 +37,10 @@ namespace CECrowPlugin
                public IEnumerable<PropertyContainer> Properties => Members.Where(m=>m.MemberType == MemberTypes.Property).Select(p=> new PropertyContainer(this, p as PropertyInfo));
 
                public string Name => delGetName();
+               public string DesignId => (string)fiWidget_design_id?.GetValue(instance);
+               public string Icon => $"#icons.{type.FullName}.svg";
+
+               public string TypeName => type.FullName;
 
                public IEnumerable<ForeignWidgetContainer> Children  {
                        get {
index 065020af6bd6714b4f28f153442d7377bc38eb27..8b19e3827867021ea8df4fcbf804b70cd439addb 100644 (file)
@@ -4,7 +4,11 @@
         <ListBox Data="{Properties}">
             <Template>
                 <VerticalStack Background="{./Background}">
-                    <Label Text="{Name}"/>
+                    <HorizontalStack Height="Fit" Spacing="10" Margin="10" Background="DimGrey">
+                        <Image Width="40" Height="40" Margin="4" Path="{Icon}" Background="Jet"/>
+                        <Label Text="{TypeName}" Width="Stretched" TextAlignment="Left" />
+                        <Label Font="mono bold, 16" Foreground="PaleGreen" Text="{DesignId}" Width="Fit" Margin="4" />
+                    </HorizontalStack>
                     <HorizontalStack Margin="1">
                         <Scroller Name="ItemsScroller" Margin="2">
                             <VerticalStack Height="Fit" MinimumSize="10,10"
index 15c2eaa363a81120cac7a8f515c1fa3673930fb6..543c678a8f8b06d56d1bf9dc420c650aab1d273d 100644 (file)
@@ -1,6 +1,21 @@
 <?xml version="1.0"?>
 <DockWindow Caption="Exceptions"  Width="40%" Height="20%">
-       <ListBox DataSource="{CurrentDocument}" Data='{Exceptions}' Height='Stretched' Width='Stretched'/>
+       <ListBox DataSource="{CurrentDocument}" Data='{Exceptions}' SelectedItem="{²CurrentException}"
+               Height='Stretched' Width='Stretched'>
+               <Template>
+                       <Scroller  Name="scroller1"  >
+                               <Table Columns="Message,Stretched;Location,Fit"
+                                       Height="Fit" Name="ItemsContainer" VerticalAlignment="Top"/>
+                       </Scroller>
+               </Template>
+               <ItemTemplate>
+                       <TableRow       Selected = "{Background=${ControlHighlight}}"
+                                               Unselected = "{Background=Transparent}">
+                               <Label Text="{Message}" />
+                               <Label Text="{Location}"/>
+                       </TableRow>
+               </ItemTemplate>
+       </ListBox>
 </DockWindow>
 
 
index 0118bf75bb47f5eef9697a972a0b4cf75e480c37..f52acb3f548fd2becf565cf691a4b4a100333b5b 100644 (file)
@@ -1,7 +1,6 @@
 <?xml version="1.0"?>
-<DockWindow Caption="Syntax"  Width="30%">
+<DockWindow Caption="Syntax"  Width="30%" AdditionalCommands="{SyntaxViewCommands}">
        <VerticalStack RootDataLevel="true" Spacing="0" DataSource="{CurrentDocument}">
-               <Button Command="{CMDRefreshSyntaxTree}"/>
                <Label Text="{}"/>
                <Label Text="{SyntaxRootNode}"/>
                <Label Text="{CurrentNode}"/>