diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-09-15 19:26:39 +0000 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-09-15 19:26:39 +0000 |
| commit | 8b343e10f1a65b07988e15ea76596b16a03adadc (patch) | |
| tree | fc12eee11de644d429e6fb67516c46be82669377 /Samples/common/src/Editor.cs | |
| parent | 5dcfd372592d5d21193d1dc5a58c385b2e8a6a7c (diff) | |
hosted command
Diffstat (limited to 'Samples/common/src/Editor.cs')
| -rw-r--r-- | Samples/common/src/Editor.cs | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/Samples/common/src/Editor.cs b/Samples/common/src/Editor.cs index c093d345..e56914f8 100644 --- a/Samples/common/src/Editor.cs +++ b/Samples/common/src/Editor.cs @@ -19,7 +19,7 @@ namespace Crow XmlSource source; object TokenMutex = new object(); - void parse () { + void parse () { XmlSource tmp = new XmlSource(_text); lock(TokenMutex) source = tmp; @@ -41,7 +41,7 @@ namespace Crow if (suggestions == null || suggestions.Count == 0) hideOverlay (); else - showOverlay (); + showOverlay (); } } bool suggestionsActive => overlay != null && overlay.IsVisible; @@ -58,9 +58,9 @@ namespace Crow m.GetCustomAttribute<XmlIgnoreAttribute>() == null); } MemberInfo getCrowTypeMember (string crowTypeName, string memberName) { - Type crowType = IML.Instantiator.GetWidgetTypeFromName (crowTypeName); + Type crowType = IML.Instantiator.GetWidgetTypeFromName (crowTypeName); return crowType.GetMember (memberName, BindingFlags.Public | BindingFlags.Instance).FirstOrDefault (); - } + } public override void OnTextChanged(object sender, TextChangeEventArgs e) { @@ -68,7 +68,7 @@ namespace Crow //Task.Run(()=>parse()); parse(); - + if (!disableSuggestions && HasFocus) tryGetSuggestions (); @@ -77,7 +77,7 @@ namespace Crow void tryGetSuggestions () { if (!currentLoc.HasValue) return; - int pos = lines.GetAbsolutePosition (CurrentLoc.Value); + int pos = lines.GetAbsolutePosition (CurrentLoc.Value); currentToken = source.FindTokenIncludingPosition (pos); currentNode = source.FindNodeIncludingPosition (pos); Console.WriteLine ($"Current Token: {currentToken} Current Node: {currentNode}"); @@ -109,7 +109,7 @@ namespace Crow else if (pi.PropertyType == typeof (Measure)) Suggestions = (new string[] {"Stretched", "Fit"}). Where (s => s.StartsWith (currentToken.AsString (_text), StringComparison.OrdinalIgnoreCase)).ToList (); - else if (pi.PropertyType == typeof (Fill)) + else if (pi.PropertyType == typeof (Fill)) Suggestions = EnumsNET.Enums.GetValues<Colors> () .Where (s => s.ToString().StartsWith (currentToken.AsString (_text), StringComparison.OrdinalIgnoreCase)).ToList (); } @@ -123,7 +123,7 @@ namespace Crow Suggestions = Enum.GetNames (pi.PropertyType).ToList (); else if (pi.PropertyType == typeof(bool)) Suggestions = new List<string> (new string[] {"true", "false"}); - else if (pi.PropertyType == typeof (Fill)) + else if (pi.PropertyType == typeof (Fill)) Suggestions = EnumsNET.Enums.GetValues<Colors> ().ToList (); else if (pi.PropertyType == typeof (Measure)) Suggestions = new List<string> (new string[] {"Stretched", "Fit"}); @@ -131,10 +131,10 @@ namespace Crow } } } - } - } else if (currentToken.Type != TokenType.AttributeValueClose && - currentToken.Type != TokenType.EmptyElementClosing && - currentToken.Type != TokenType.ClosingSign && + } + } else if (currentToken.Type != TokenType.AttributeValueClose && + currentToken.Type != TokenType.EmptyElementClosing && + currentToken.Type != TokenType.ClosingSign && currentNode is ElementStartTagSyntax eltStartTag) { if (currentToken.Type == TokenType.AttributeName) Suggestions = getAllCrowTypeMembers (eltStartTag.NameToken.Value.AsString (_text)) @@ -157,39 +157,39 @@ namespace Crow overlay = IFace.LoadIMLFragment<ListBox>(@" <ListBox Style='suggestionsListBox' Data='{Suggestions}' UseLoadingThread='False' > <ItemTemplate> - <ListItem Height='Fit' Margin='0' Focusable='false' HorizontalAlignment='Left' + <ListItem Height='Fit' Margin='0' Focusable='false' HorizontalAlignment='Left' Selected = '{Background=${ControlHighlight}}' Unselected = '{Background=Transparent}'> <Label Text='{}' HorizontalAlignment='Left' /> - </ListItem> + </ListItem> </ItemTemplate> <ItemTemplate DataType='System.Reflection.MemberInfo'> - <ListItem Height='Fit' Margin='0' Focusable='false' HorizontalAlignment='Left' + <ListItem Height='Fit' Margin='0' Focusable='false' HorizontalAlignment='Left' Selected = '{Background=${ControlHighlight}}' Unselected = '{Background=Transparent}'> <HorizontalStack> <Image Picture='{GetIcon}' Width='16' Height='16'/> <Label Text='{Name}' HorizontalAlignment='Left' /> </HorizontalStack> - </ListItem> - </ItemTemplate> + </ListItem> + </ItemTemplate> <ItemTemplate DataType='Colors'> - <ListItem Height='Fit' Margin='0' Focusable='false' HorizontalAlignment='Left' + <ListItem Height='Fit' Margin='0' Focusable='false' HorizontalAlignment='Left' Selected = '{Background=${ControlHighlight}}' Unselected = '{Background=Transparent}'> <HorizontalStack> <Widget Background='{}' Width='20' Height='14'/> <Label Text='{}' HorizontalAlignment='Left' /> </HorizontalStack> - </ListItem> + </ListItem> </ItemTemplate> </ListBox> "); overlay.DataSource = this; - overlay.Loaded += (sender, arg) => (sender as ListBox).SelectedIndex = 0; + overlay.Loaded += (sender, arg) => (sender as ListBox).SelectedIndex = 0; } else overlay.IsVisible = true; - overlay.RegisterForLayouting(LayoutingType.Sizing); + overlay.RegisterForLayouting(LayoutingType.Sizing); } } void hideOverlay () { @@ -197,7 +197,7 @@ namespace Crow return; overlay.IsVisible = false; } - void completeToken () { + void completeToken () { string selectedSugg = overlay.SelectedItem is MemberInfo mi ? mi.Name : overlay.SelectedItem?.ToString (); if (selectedSugg == null) @@ -208,15 +208,15 @@ namespace Crow update (new TextChange (currentToken.End, 0, selectedSugg)); else if (currentToken.Type == TokenType.AttributeName && currentNode is AttributeSyntax attrib) { if (attrib.ValueToken.HasValue) { - TextChange tc = new TextChange (currentToken.Start, currentToken.Length, selectedSugg); + TextChange tc = new TextChange (currentToken.Start, currentToken.Length, selectedSugg); update (tc); selectionStart = lines.GetLocation (attrib.ValueToken.Value.Start + tc.CharDiff + 1); CurrentLoc = lines.GetLocation (attrib.ValueToken.Value.End + tc.CharDiff - 1); } else { update (new TextChange (currentToken.Start, currentToken.Length, selectedSugg + "=\"\"")); MoveLeft (); - } - } else + } + } else update (new TextChange (currentToken.Start, currentToken.Length, selectedSugg)); hideOverlay (); } @@ -224,7 +224,7 @@ namespace Crow hideOverlay (); base.onMouseDown (sender, e); } - + public override void onKeyDown(object sender, KeyEventArgs e) { TextSpan selection = Selection; @@ -264,7 +264,7 @@ namespace Crow disableSuggestions = true; if (IFace.Shift) { - for (int l = lineStart; l <= lineEnd; l++) { + for (int l = lineStart; l <= lineEnd; l++) { if (Text[lines[l].Start] == '\t') update (new TextChange (lines[l].Start, 1, "")); else if (Char.IsWhiteSpace (Text[lines[l].Start])) { @@ -276,10 +276,10 @@ namespace Crow } }else{ - for (int l = lineStart; l <= lineEnd; l++) - update (new TextChange (lines[l].Start, 0, "\t")); + for (int l = lineStart; l <= lineEnd; l++) + update (new TextChange (lines[l].Start, 0, "\t")); } - + selectionStart = new CharLocation (lineStart, 0); CurrentLoc = new CharLocation (lineEnd, lines[lineEnd].Length); @@ -288,7 +288,7 @@ namespace Crow return; } base.onKeyDown(sender, e); - } + } protected override void drawContent (Context gr) { try { @@ -297,7 +297,7 @@ namespace Crow base.drawContent (gr); return; } - + Rectangle cb = ClientRectangle; fe = gr.FontExtents; double lineHeight = fe.Ascent + fe.Descent; @@ -359,7 +359,7 @@ namespace Crow TextExtents extents; int tokPtr = 0; Token tok = source.Tokens[tokPtr]; - bool multilineToken = false; + bool multilineToken = false; ReadOnlySpan<char> buff = sourceBytes; @@ -369,7 +369,7 @@ namespace Crow if (multilineToken) { if (tok.End < lines[i].End) {//last incomplete line of multiline token - buff = sourceBytes.Slice (lines[i].Start, tok.End - lines[i].Start); + buff = sourceBytes.Slice (lines[i].Start, tok.End - lines[i].Start); } else {//print full line buff = sourceBytes.Slice (lines[i].Start, lines[i].Length); } @@ -399,7 +399,7 @@ namespace Crow gr.SetSource(Colors.DarkSlateBlue); }else { gr.SetSource(Colors.Red); - } + } } int size = buff.Length * 4 + 1; @@ -414,7 +414,7 @@ namespace Crow gr.MoveTo (pixX, lineHeight * y + fe.Ascent); gr.ShowText (bytes.Slice (0, encodedBytes)); pixX += extents.XAdvance; - x += buff.Length; + x += buff.Length; } if (multilineToken) { @@ -432,7 +432,7 @@ namespace Crow if (HasFocus && selectionNotEmpty) { RectangleD lineRect = new RectangleD (cb.X, lineHeight * y + cb.Top, pixX, lineHeight); RectangleD selRect = lineRect; - + if (i >= selStart.Line && i <= selEnd.Line) { if (selStart.Line == selEnd.Line) { selRect.X = selStart.VisualCharXPosition + cb.X; @@ -478,7 +478,7 @@ namespace Crow x = 0; pixX = 0; - + y++; @@ -492,13 +492,13 @@ namespace Crow continue; } else if (tok2.Type == TokenType.WhiteSpace) { x += tok2.Length; - pixX += spacePixelWidth * tok2.Length;*/ - } + pixX += spacePixelWidth * tok2.Length;*/ + } //gr.Translate (ScrollX, ScrollY); } } catch { - + } - } + } } }
\ No newline at end of file |