From: Jean-Philippe Bruyère Date: Fri, 7 Mar 2025 10:32:03 +0000 (+0100) Subject: CS syntax, hover and current widget highlight in debugWidget X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=6495fa6b565301e5fc62d0fb299d3408a69e90f1;p=jp%2Fcrowedit.git CS syntax, hover and current widget highlight in debugWidget --- diff --git a/CrowEditBase/src/Compiler/SyntaxNode.cs b/CrowEditBase/src/Compiler/SyntaxNode.cs index 226bdfe..00dd6c7 100644 --- a/CrowEditBase/src/Compiler/SyntaxNode.cs +++ b/CrowEditBase/src/Compiler/SyntaxNode.cs @@ -118,7 +118,7 @@ namespace CrowEditBase public int? LastTokenIndex => lastTokenOfset.HasValue ? TokenIndexBase + lastTokenOfset.Value : null; public int EndLine { - internal set { + set { lineCount = value - StartLine + 1; } get => StartLine + lineCount - 1; diff --git a/CrowEditBase/src/Compiler/SyntaxRootNode.cs b/CrowEditBase/src/Compiler/SyntaxRootNode.cs index af0f9ab..20f683c 100644 --- a/CrowEditBase/src/Compiler/SyntaxRootNode.cs +++ b/CrowEditBase/src/Compiler/SyntaxRootNode.cs @@ -25,6 +25,12 @@ namespace CrowEditBase idx >= 0 && idx < tokens.Length ? GetText(tokens[idx].Span).ToString() : null : null; public Token GetTokenByIndex (int idx) => tokens != null ? idx >= 0 && idx < tokens.Length ? tokens[idx] : default : default; + public int FindTokenIndexIncludingPosition (int pos) { + if (pos == 0 || Tokens.Length == 0) + return default; + int idx = Tokens.BinarySearch(new Token () {Start = pos}); + return idx == 0 ? 0 : idx < 0 ? ~idx - 1 : idx; + } public ReadOnlySpan GetText(TextSpan span) => source.Span.Slice(span.Start, span.Length); public string GetTokenString(Token tok) => diff --git a/CrowEditBase/src/CrowEditComponent.cs b/CrowEditBase/src/CrowEditComponent.cs index 8caff4a..79cbebc 100644 --- a/CrowEditBase/src/CrowEditComponent.cs +++ b/CrowEditBase/src/CrowEditComponent.cs @@ -5,6 +5,7 @@ using System; using Crow; using System.Runtime.CompilerServices; +using System.Diagnostics; namespace CrowEditBase { @@ -34,7 +35,8 @@ namespace CrowEditBase return; isSelected = value; - NotifyValueChanged (isSelected); + //Debug.WriteLine($"{this} selected: {isSelected}"); + NotifyValueChanged (isSelected); } } #endregion diff --git a/plugins/CECrowPlugin/src/CrowService.cs b/plugins/CECrowPlugin/src/CrowService.cs index 6acdeed..54f88e5 100644 --- a/plugins/CECrowPlugin/src/CrowService.cs +++ b/plugins/CECrowPlugin/src/CrowService.cs @@ -48,6 +48,7 @@ namespace CECrowPlugin public Command CMDStartRecording, CMDStopRecording, CMDRefresh; public Command CMDGotoParentEvent, CMDEventHistoryForward, CMDEventHistoryBackward; public CommandGroup LoggerCommands => new CommandGroup (CMDRefresh, CMDStartRecording, CMDStopRecording); + public CommandGroup GraphicTreeCommands => new CommandGroup (CMDRefresh); public CommandGroup EventCommands => new CommandGroup( CMDGotoParentEvent, CMDEventHistoryBackward, CMDEventHistoryForward); public ActionCommand CMDOptions_SelectCrowAssemblyLocation => new ActionCommand ("...", @@ -113,7 +114,7 @@ namespace CECrowPlugin Assembly crowAssembly, thisAssembly; Type dbgIfaceType; IList graphicTree; - ForeignWidgetContainer currentWidget; + ForeignWidgetContainer currentWidget, hoverWidget; public IList GraphicTree { @@ -130,12 +131,71 @@ namespace CECrowPlugin set { if (currentWidget == value) return; + currentWidget = value; + + if (currentWidget == null) + CurrentWidgetDesignId = null; + else { + currentWidget.ExpandToTheTop(); + CurrentWidgetDesignId = currentWidget.DesignId; + } + NotifyValueChanged("CurrentWidget",currentWidget); } } + public string CurrentWidgetDesignId { + get => currentWidget?.DesignId; + set { + if (CurrentWidgetDesignId == value) + return; + if (string.IsNullOrEmpty(value)) + CurrentWidget = null; + else { + bool result = graphicTree[0].TryFindWidgetById(value, out ForeignWidgetContainer tmp); + if (result) + CurrentWidget = tmp; + else + CurrentWidget = null; + //throw new Exception("graphicTree[0].TryFindWidgetById: design id not found");*/ + } + NotifyValueChanged(CurrentWidgetDesignId); + } + } + public ForeignWidgetContainer HoverWidget { + get => hoverWidget; + set { + if (hoverWidget == value) + return; + hoverWidget = value; + if (hoverWidget == null) + HoverWidgetDesignId = null; + else { + HoverWidgetDesignId = hoverWidget.DesignId; + } + + NotifyValueChanged("HoverWidget",hoverWidget); + } + } + public string HoverWidgetDesignId { + get => hoverWidget?.DesignId; + set { + if (HoverWidgetDesignId == value) + return; + if (string.IsNullOrEmpty(value)) + HoverWidget = null; + else { + bool result = graphicTree[0].TryFindWidgetById(value, out ForeignWidgetContainer tmp); + if (result) + HoverWidget = tmp; + else + HoverWidget = null; + } + NotifyValueChanged(HoverWidgetDesignId); + } + } #region dbgIface delegates Func delGetWidgetTypeFromName; Action delResize; @@ -520,6 +580,7 @@ namespace CECrowPlugin fiWidget_design_style_locations = typeWidget.GetField("design_style_locations"); fiWidget_design_iml_values = typeWidget.GetField("design_iml_values"); //*********************************** + fiWidget_slot = typeWidget.GetField("Slot"); fiITor_NextInstantiatorID = crowAssembly.GetType("Crow.IML.Instantiator").GetField("NextInstantiatorID", BindingFlags.Public | BindingFlags.Static); @@ -625,7 +686,8 @@ namespace CECrowPlugin try { mouseScreenPos = _mouseScreenPos;//absolute on screen position. - e.Handled = delMouseMove ((int)(e.X / ZoomFactor), (int)(e.Y / ZoomFactor));//DebugInterface local coordinate for mouse. + //e.Handled = delMouseMove ((int)(e.X / ZoomFactor), (int)(e.Y / ZoomFactor));//DebugInterface local coordinate for mouse. + e.Handled = delMouseMove (e.X, e.Y);//DebugInterface local coordinate for mouse. } catch (System.Exception ex) { @@ -640,7 +702,8 @@ namespace CECrowPlugin if (CurrentState == Status.Running) { try { - e.Handled = delMouseDown (e.Button); + //e.Handled = delMouseDown (e.Button); + CurrentWidget = HoverWidget; } catch (System.Exception ex) { @@ -653,7 +716,7 @@ namespace CECrowPlugin if (CurrentState == Status.Running) { try { - e.Handled = delMouseUp (e.Button); + e.Handled = true;//delMouseUp (e.Button); } catch (System.Exception ex) { @@ -666,7 +729,7 @@ namespace CECrowPlugin if (CurrentState == Status.Running) { try { - e.Handled = delMouseWheelChanged (e.Delta); + e.Handled = true;// delMouseWheelChanged (e.Delta); } catch (System.Exception ex) { @@ -700,8 +763,11 @@ namespace CECrowPlugin void refresh () { if (!IsRunning) Start (); - if (IsRunning) + if (IsRunning) { + fiITor_NextInstantiatorID?.SetValue (null, 0); delReloadIml (); + } + //updateCrowApp(); } void stopRecording () { diff --git a/plugins/CECrowPlugin/src/DebugInterface.cs b/plugins/CECrowPlugin/src/DebugInterface.cs index ff760be..2555bf6 100644 --- a/plugins/CECrowPlugin/src/DebugInterface.cs +++ b/plugins/CECrowPlugin/src/DebugInterface.cs @@ -14,6 +14,7 @@ using IML = Crow.IML; using System.Diagnostics; using Crow.IML; using System.Runtime.Loader; +using Glfw; namespace CECrowPlugin { @@ -23,6 +24,8 @@ namespace CECrowPlugin } public DebugInterface (IntPtr hWin) : base (100, 100, hWin) { + fiWidget_design_id = typeof(Widget).GetField("design_id"); + fiPrivateContainer_child = typeof(PrivateContainer).GetField("child", BindingFlags.Instance | BindingFlags.NonPublic); clientRectangle = new Rectangle (0, 0, 100, 100); } protected override void initBackend() @@ -52,13 +55,30 @@ namespace CECrowPlugin public bool Terminate; public bool Edition = true; public bool FirstRenderingFinished = false; + + bool checkEditHoverWidget() { + if (lastEditHoverWidget != editHoverWidget) { + if (editHoverWidget == null) + delCrowServiceSetHoverDesignId(null); + else { + string id = (string)fiWidget_design_id?.GetValue(editHoverWidget); + delCrowServiceSetHoverDesignId(id); + } + lastEditHoverWidget = editHoverWidget; + return true; + } else + return false; + } void interfaceThread () { while (!Terminate) { try { if (Edition) { - if (FirstRenderingFinished) - Thread.Sleep(500); + if (FirstRenderingFinished) { + Thread.Sleep(100); + checkEditHoverWidget(); + continue; + } int lqiCount; lock(LayoutMutex) @@ -104,16 +124,18 @@ namespace CECrowPlugin } Dispose(); } - string source; + string source; //Action delRegisterForRepaint;//call RegisterForRepaint in the container widget (DebugInterfaceWidget) Action delCrowServiceSetCurrentException; Action delCrowServiceUpdateRootWidget; + Action delCrowServiceSetCurrentDesignId, delCrowServiceSetHoverDesignId; delegate void GetScreenCoordinateDelegateType(out int x, out int y); GetScreenCoordinateDelegateType delCrowServiceGetScreenCoordinate; Func> delCrowServiceGetStyling; Func delCrowServiceGetStreamFromPath; + FieldInfo fiWidget_design_id, fiPrivateContainer_child; public void RegisterDebugInterfaceCallback (object crowService){ @@ -121,6 +143,11 @@ namespace CECrowPlugin //delRegisterForRepaint = (Action)Delegate.CreateDelegate(typeof(Action), w, t.GetMethod("RegisterForRepaint")); delCrowServiceSetCurrentException = (Action)Delegate.CreateDelegate(typeof(Action), crowService, t.GetProperty("CurrentException").GetSetMethod(true)); + delCrowServiceSetCurrentDesignId = (Action)Delegate.CreateDelegate(typeof(Action), crowService, + t.GetProperty("CurrentWidgetDesignId").GetSetMethod(true)); + delCrowServiceSetHoverDesignId = (Action)Delegate.CreateDelegate(typeof(Action), crowService, + t.GetProperty("HoverWidgetDesignId").GetSetMethod(true)); + delCrowServiceUpdateRootWidget = (Action)Delegate.CreateDelegate(typeof(Action), crowService, t.GetMethod("UpdateRootWidget")); @@ -199,15 +226,110 @@ namespace CECrowPlugin RegisterClip (clientRectangle); } }*/ - public override Widget HoverWidget { - get => base.HoverWidget; - set { - base.HoverWidget = value; - } + + Widget lastEditHoverWidget, editHoverWidget, editActiveWidget; + bool checkHoverWidget() { + while (true) { + bool mouseInChildren = false; + foreach(Widget child in GetWidgetChilren(editHoverWidget)) { + if (child.MouseIsIn(MousePosition)) { + editHoverWidget = child; + mouseInChildren = true; + break; + } + } + if (!mouseInChildren) + return true; + /*if (typeof(TemplatedControl).IsAssignableFrom(editHoverWidget.GetType())) { + return true; + } else if (typeof(PrivateContainer).IsAssignableFrom(editHoverWidget.GetType())) { + Widget child = (Widget)fiPrivateContainer_child.GetValue(editHoverWidget); + if (child == null || !child.MouseIsIn(MousePosition)) + return true; + editHoverWidget = child; + } else if (typeof(GroupBase).IsAssignableFrom(editHoverWidget.GetType())) { + bool mouseInChildren = false; + foreach (Widget w in ((GroupBase)editHoverWidget).Children) { + if (w.MouseIsIn(MousePosition)) { + editHoverWidget = w; + mouseInChildren = true; + break; + } + } + if (!mouseInChildren) + return true; + } else + return true;*/ + } } public override bool OnMouseMove(int x, int y) { - return base.OnMouseMove(x, y); + int deltaX = x - base.MousePosition.X; + int deltaY = y - base.MousePosition.Y; + + MousePosition = new Point(x,y); + MouseMoveEventArgs e = new MouseMoveEventArgs (x, y, deltaX, deltaY); + + if (Edition) { + if (editHoverWidget != null) { + //check topmost graphicobject first + Widget topContainer = editHoverWidget; + while (topContainer.LogicalParent is Widget w) + topContainer = w; + + int indexOfTopContainer = GraphicTree.IndexOf (topContainer); + if (indexOfTopContainer != 0) {//0 is topMost + for (int i = 0; i < indexOfTopContainer; i++) {//check all top containers that are at a higher level + //if logical parent of top container is the Interface, that's not a popup. + if (typeof(Interface).IsAssignableFrom(GraphicTree [i].LogicalParent.GetType()) ) { + if (GraphicTree [i].MouseIsIn (MousePosition)) { + editHoverWidget = GraphicTree [i]; + if (checkHoverWidget()) + return true; + } + } + } + } + + if (editHoverWidget.MouseIsIn (MousePosition)) { + return checkHoverWidget(); + } else { + while (editHoverWidget.Parent is Widget parent) { + editHoverWidget = parent; + if (editHoverWidget.MouseIsIn (e.Position)) { + return checkHoverWidget(); + } + } + } + } + + //top level graphic obj's parsing + lock (GraphicTree) { + for (int i = 0; i < GraphicTree.Count; i++) { + Widget g = GraphicTree [i]; + if (g.MouseIsIn (e.Position)) { + editHoverWidget = g; + return checkHoverWidget(); + } + } + } + editHoverWidget = null; + return false; + } else + return base.OnMouseMove(x, y); + } + public override bool OnMouseButtonDown(MouseButton button) + { + if (Edition) { + /*if (editHoverWidget != null) { + editActiveWidget = editHoverWidget; + string id = (string)fiWidget_design_id?.GetValue(editHoverWidget); + delCrowServiceSetCurrentDesignId(id); + return true; + }*/ + return false; + } else + return base.OnMouseButtonDown(button); } public override void ForceMousePosition() diff --git a/plugins/CECrowPlugin/src/DebugInterfaceWidget.cs b/plugins/CECrowPlugin/src/DebugInterfaceWidget.cs index 6e18918..97a6fdb 100644 --- a/plugins/CECrowPlugin/src/DebugInterfaceWidget.cs +++ b/plugins/CECrowPlugin/src/DebugInterfaceWidget.cs @@ -17,19 +17,13 @@ using Crow; namespace CECrowPlugin { public class DebugInterfaceWidget : Widget { - CrowService crowIFaceService; - public CrowService CrowIFaceService { - get => crowIFaceService; - set { - if (crowIFaceService == value) - return; - crowIFaceService = value; - NotifyValueChangedAuto (crowIFaceService); - } - } - - Command CMDRefresh, CMDZoomIn, CMDZoomOut, CMDRun; public DebugInterfaceWidget () : base () { + + CrowIFaceService = App.GetService (); + + if (crowIFaceService != null) + crowIFaceService.ValueChanged += service_ValueChanged; + CMDRefresh = new ActionCommand (this, "Refresh", () => { crowIFaceService?.LoadIML (""); @@ -58,6 +52,86 @@ namespace CECrowPlugin t.IsBackground = true; t.Start (); } + ~DebugInterfaceWidget() { + if (crowIFaceService != null) + crowIFaceService.ValueChanged -= service_ValueChanged; + } + void service_ValueChanged(object instance, ValueChangeEventArgs e) { + if (e.MemberName == "CurrentWidget") { + if (e.NewValue is ForeignWidgetContainer fwc) + CurrentWidget = fwc; + else + CurrentWidget = null; + } else if (e.MemberName == "HoverWidget") { + if (e.NewValue is ForeignWidgetContainer fwc) + HoverWidget = fwc; + else + HoverWidget = null; + } + } + CrowService crowIFaceService; + string imlSource; + ImlDocument document; + ForeignWidgetContainer currentWidget, hoverWidget; + + Command CMDRefresh, CMDZoomIn, CMDZoomOut, CMDRun; + public CommandGroup WindowCommands => new CommandGroup ( + CMDRefresh, //CMDZoomIn, CMDZoomOut, + crowIFaceService.CMDStartRecording, + crowIFaceService.CMDStopRecording, + crowIFaceService.CMDOpenConfig, + (Parent.LogicalParent as DockWindow).CMDClose + ); + public CrowService CrowIFaceService { + get => crowIFaceService; + set { + if (crowIFaceService == value) + return; + crowIFaceService = value; + NotifyValueChangedAuto (crowIFaceService); + } + } + public TextDocument Document { + get => document; + set { + if (document == value) + return; + + if (value is ImlDocument imlDoc) { + document?.UnregisterClient (this); + document = imlDoc; + imlSource = default; + document?.RegisterClient (this, true); + + NotifyValueChangedAuto (document); + RegisterForGraphicUpdate (); + } + } + } + public ForeignWidgetContainer CurrentWidget { + get => currentWidget; + set { + if (!(value?.GetType().Name == "ForeignWidgetContainer")) + return; + if (currentWidget == value) + return; + currentWidget = value; + NotifyValueChanged("CurrentWidget",currentWidget); + RegisterForRepaint (); + } + } + public ForeignWidgetContainer HoverWidget { + get => hoverWidget; + set { + if (!(value?.GetType().Name == "ForeignWidgetContainer")) + return; + if (hoverWidget == value) + return; + hoverWidget = value; + NotifyValueChanged("HoverWidget",hoverWidget); + RegisterForRepaint (); + } + } protected void backgroundThreadFunc () { Stopwatch sw = Stopwatch.StartNew (); int refreshRate = crowIFaceService == null ? 10 : crowIFaceService.RefreshRate; @@ -94,47 +168,11 @@ namespace CECrowPlugin RegisterForRedraw (); } - string imlSource; - - ImlDocument document; - ForeignWidgetContainer currentWidget; - public TextDocument Document { - get => document; - set { - if (document == value) - return; - - if (value is ImlDocument imlDoc) { - document?.UnregisterClient (this); - document = imlDoc; - imlSource = default; - document?.RegisterClient (this, true); - - NotifyValueChangedAuto (document); - RegisterForGraphicUpdate (); - } - } - } - - - public ForeignWidgetContainer CurrentWidget { - get => currentWidget; - set { - if (currentWidget == value) - return; - currentWidget = value; - NotifyValueChanged("CurrentWidget",currentWidget); - RegisterForRepaint (); - } - } - - protected override void onInitialized(object sender, EventArgs e) { base.onInitialized(sender, e); - - CrowIFaceService = App.GetService (); + crowIFaceService?.Start (); } /*public CommandGroup LoggerCommands => @@ -144,13 +182,7 @@ namespace CECrowPlugin new Command("Save to file", () => saveLogToDebugLogFilePath ()), new Command("Load from file", () => loadLogFromDebugLogFilePath ()) );*/ - public CommandGroup WindowCommands => new CommandGroup ( - CMDRefresh, //CMDZoomIn, CMDZoomOut, - crowIFaceService.CMDStartRecording, - crowIFaceService.CMDStopRecording, - crowIFaceService.CMDOpenConfig, - (Parent.LogicalParent as DockWindow).CMDClose - ); + protected override void onDraw(IContext gr) { @@ -171,16 +203,6 @@ namespace CECrowPlugin public override void onMouseUp(object sender, MouseButtonEventArgs e) => crowIFaceService?.onMouseUp(e); public override void onMouseWheel(object sender, MouseWheelEventArgs e) => crowIFaceService?.onMouseWheel(e); - public override bool Paint(IContext ctx) - { - return base.Paint(ctx); - /*crowIFaceService.LockRenderMutex(); - try { - return base.Paint(ctx); - } finally { - crowIFaceService.UnlockRenderMutex(); - }*/ - } protected override void RecreateCache() { if (crowIFaceService != null && crowIFaceService.IsRunning) { @@ -195,6 +217,28 @@ namespace CECrowPlugin if (crowIFaceService != null && crowIFaceService.IsRunning && bmp != null) { //crowIFaceService.LockRenderMutex(); paintCache (ctx, Slot + Parent.ClientRectangle.Position); + if (hoverWidget != null && hoverWidget != currentWidget) { + //currentWidget. + RectangleD r = hoverWidget.GetScreenCoordinate() + Slot.Position + Parent.ClientRectangle.Position; + //ctx.ResetClip(); + ctx.LineWidth = 1; + ctx.SetDash([1,3]); + ctx.Rectangle(r.Inflated(2)); + ctx.SetSource(Colors.Yellow); + ctx.Stroke(); + ctx.SetDash([]); + } + if (currentWidget != null) { + //currentWidget. + RectangleD r = currentWidget.GetScreenCoordinate() + Slot.Position + Parent.ClientRectangle.Position; + //ctx.ResetClip(); + ctx.LineWidth = 1.0; + //ctx.SetDash([2,3]); + ctx.Rectangle(r.Inflated(1)); + ctx.SetSource(Colors.White); + ctx.Stroke(); + //ctx.SetDash([0]); + } //crowIFaceService.UnlockRenderMutex(); crowIFaceService.ResetDirtyState (); } diff --git a/plugins/CECrowPlugin/src/ForeignWidgetContainer.cs b/plugins/CECrowPlugin/src/ForeignWidgetContainer.cs index bb11241..f45ead3 100644 --- a/plugins/CECrowPlugin/src/ForeignWidgetContainer.cs +++ b/plugins/CECrowPlugin/src/ForeignWidgetContainer.cs @@ -8,25 +8,38 @@ using System.Collections.Generic; using System.Linq; using CrowEditBase; using Crow; +using Drawing2D; using static CrowEditBase.CrowEditBase; +using System.Diagnostics; + namespace CECrowPlugin { public class ForeignWidgetContainer : CrowEditComponent { internal static Type typeWidget;//, typeGroup, typeContainer, typeTemplatedContainer, typeTemplatedGroup; //design mode members, present only if crow compiled with DESIGN_MODE enabled - internal static FieldInfo fiWidget_design_id, fiWidget_design_style_values, fiWidget_design_iml_values, fiWidget_design_style_locations; + internal static FieldInfo fiWidget_design_id, fiWidget_design_style_values, fiWidget_design_iml_values, fiWidget_design_style_locations, + fiWidget_slot; Func delGetName; + Func delGetScreenCoordinates; bool isExpanded; Type type; object instance; - public ForeignWidgetContainer(Type widgetType, object instance) { + ForeignWidgetContainer parent; + string designId; + public ForeignWidgetContainer(Type widgetType, object instance, ForeignWidgetContainer parent = null) { type = widgetType; this.instance = instance; + this.parent = parent; delGetName = (Func)Delegate.CreateDelegate(typeof(Func), instance, type.GetProperty("Name").GetGetMethod()); + delGetScreenCoordinates = (Func)Delegate.CreateDelegate(typeof(Func), instance, type.GetMethod("ScreenCoordinates")); + + designId = (string)fiWidget_design_id?.GetValue(instance); + + Console.WriteLine($"new ForeignWidgetContainer: {this} {parent}"); } @@ -36,23 +49,44 @@ namespace CECrowPlugin public IEnumerable 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 Name => delGetName(); + public string DesignId => designId; + public Rectangle GetScreenCoordinate() => delGetScreenCoordinates(Slot); + public Rectangle Slot => (Rectangle)fiWidget_slot?.GetValue(instance); public string TypeName => type.FullName; - public IEnumerable Children { + volatile bool childrenFetched = false; + IList children; + public IList Children { get { var srv = App.GetService (); if (srv == null || !srv.IsRunning) return null; - return srv.GetWidgetChilren(instance)?.Select(c=>new ForeignWidgetContainer(c.GetType(),c)); - } - + if (!childrenFetched) { + children = srv.GetWidgetChilren(instance)?.Select(c => new ForeignWidgetContainer(c.GetType(),c,this)).ToList(); + childrenFetched = true; + } + + return children; + } } - - + public bool TryFindWidgetById (string designId, out ForeignWidgetContainer widgetContainer) { + widgetContainer = null; + if (designId == DesignId) { + widgetContainer = this; + return true; + } + foreach (var child in Children) { + if (child.TryFindWidgetById(designId, out ForeignWidgetContainer childContainer)) { + widgetContainer = childContainer; + return true; + } + } + return false; + } + public object Instance => instance; @@ -70,6 +104,14 @@ namespace CECrowPlugin } } public bool HasChildren => Children?.Count() > 0; + public void ExpandToTheTop() { + ForeignWidgetContainer p = parent; + while(p != null) { + p.IsExpanded = true; + p = p.parent; + } + } - } + public override string ToString() => $"{DesignId}:{Name}"; + } } diff --git a/plugins/CECrowPlugin/src/Parsing/Styling/StyleDocument.cs b/plugins/CECrowPlugin/src/Parsing/Styling/StyleDocument.cs index 8743292..f71c843 100644 --- a/plugins/CECrowPlugin/src/Parsing/Styling/StyleDocument.cs +++ b/plugins/CECrowPlugin/src/Parsing/Styling/StyleDocument.cs @@ -31,6 +31,7 @@ namespace CECrowPlugin.Style Console.ResetColor();*/ return null; } + public override string GetTokenTypeString (TokenType tokenType) => ((StyleTokenType)tokenType).ToString(); public override Color GetColorForToken(TokenType tokType) { StyleTokenType xmlTokType = (StyleTokenType)tokType; diff --git a/plugins/CECrowPlugin/ui/winCrowPreview.crow b/plugins/CECrowPlugin/ui/winCrowPreview.crow index 71b71bf..e0edc44 100644 --- a/plugins/CECrowPlugin/ui/winCrowPreview.crow +++ b/plugins/CECrowPlugin/ui/winCrowPreview.crow @@ -1,9 +1,9 @@  - - + + Document="{CurrentDocument}"/>