public List<SplitPoint> GetSplitPoints(Scope root, int newScopeStartIndex, int newScopeLength) { List<SplitPoint> splitPoints = new List<SplitPoint>(); if(root.IsFlat) { return splitPoints; } int requestedEndPos = newScopeStartIndex + newScopeLength - 1; Scope innerLeft = root.FindInnerScope(newScopeStartIndex, 1); Scope innerRight = root.FindInnerScope(requestedEndPos, 1); bool isSpillingLeft = (innerLeft.StartPosInRootScope < newScopeStartIndex); bool isSpillingRight = (innerRight.EndPosInRootScope > requestedEndPos); if (isSpillingLeft) { int splitLength = (innerLeft.EndPosInRootScope-newScopeStartIndex)+1; splitPoints.Add(new SplitPoint(newScopeStartIndex, splitLength)); } if (isSpillingRight) { int splitLength = (requestedEndPos-innerRight.StartPosInRootScope)+1; splitPoints.Add(new SplitPoint(innerRight.StartPosInRootScope, splitLength)); // splitPoints.Add(new SplitPoint(requestedEndPos, splitLength)); } return splitPoints; }
private void addScopeLeaf(TreeNode parentTreeNode, string label, Scope scope) { if (scope == null) return; TreeNode newNode = parentTreeNode.Nodes.Add(key(scope),"["+ scope.StartPosInRootScope + "-" + scope.Length +"]" + scope.Text.Replace("\n", "\\n")); newNode.Tag = scope; AddScope(scope, newNode); }
protected internal override void DrawCustomForSingleSurroundingRect(Rectangle rect, Scope scopeToDraw) { startLineIndex = txt.GetLineFromCharIndex(scopeToDraw.StartPosInRootScope); endLineIndex = txt.GetLineFromCharIndex(scopeToDraw.EndPosInRootScope); string text = string.Format("Start:{0},End:{1}",startLineIndex,endLineIndex); txt.FindForm().Text = text; // Font font = new Font(txt.Font.FontFamily,txt.Font.Size*2); // graphics.DrawString(text,font,Brushes.Red,txt.Location); }
private Scope GetFirstNamedParentScopeFor(Scope child) { Scope parent = child.ParentScope; while (parent!=null && parent.Name==string.Empty) { parent = parent.ParentScope; } return parent; }
public void Highlight(Scope s) { HideSelection = false; TreeNode[] found = Nodes.Find(key(s),true); if(found.Length==0) return; TreeNode foundFirst = found[0]; this.SelectedNode = foundFirst; }
private static void doRunAutoScope(RegexAdvisor advisor, Scope root) { ThreadStart start = delegate { advisor.AutoScope(root); }; Thread runner = new Thread(start); runner.Start(); }
public VisualScopeMarker(Graphics g, Scope scopeToDraw, ScopeAwareRichTextBox txt) : base(g, txt, 0,0) { if (scopeToDraw==null) { return; } startIndex = scopeToDraw.StartPosInRootScope; length = scopeToDraw.Length; drawnScope = scopeToDraw; }
public List<Scope> AutoSplit(Scope root, int startIndexForWantedScope, int lengthOfWantedScope, bool isImplicit) { List<Scope> newScopes = new List<Scope>(); List<SplitPoint> splitPoints = GetSplitPoints(root, startIndexForWantedScope, lengthOfWantedScope); foreach (SplitPoint splitPoint in splitPoints) { Scope newInnerScope = Split(root, splitPoint, isImplicit); newScopes.Add(newInnerScope); } return newScopes; }
public void DefineInnerScope_InCombinedParentOfTwoInners_SetsRootScopeOnInner() { Scope root = new Scope("0123456789"); Scope parent = root.DefineInnerScope(5, 4); //5678 Scope combinedParent = root.DefineInnerScope(5, 5);//5678+9 Scope innerChild = root.DefineInnerScope(6, 2);//67 Assert.AreEqual(combinedParent.InnerLeftScope, innerChild.ParentScope); Assert.AreEqual(combinedParent, combinedParent.InnerLeftScope.ParentScope); Assert.AreEqual(combinedParent, combinedParent.InnerRightScope.ParentScope); }
public ScopeRenameAction(Scope scope, ScopeAwareRichTextBox text) : base(text, scope) { titlePrefix = "Rename"; SetTitle(); highlightFillColor = Color.Yellow; highlightFillOpacity = 80; highlightBorderColor = Color.Red; highlightBorderOpacity = 180; highlightBorderWidth = 2; }
public void DefineInnerScope_WithleftMiddleandRightScopesasInner() { Scope root = new Scope("012345"); root.DefineInnerScope(3, 1);//012|3|45 ScopeSplitter splitter = new ScopeSplitter(); splitter.AutoSplit(root, 2, 3, true);//01|(2|3|4)|5 Scope encapsulator = root.DefineInnerScope(2, 3); Assert.AreEqual("2", encapsulator.InnerLeftScope.Text); Assert.AreEqual("3", encapsulator.InnerMiddleScope.Text); Assert.AreEqual("4", encapsulator.InnerRightScope.Text); }
protected internal override void DrawCustomForSingleSurroundingRect(Rectangle rect, Scope scopeToDraw) { if (!IsActive && scopeToDraw.IsFlat && scopeToDraw.Name!=string.Empty) { // new RegexMarker(graphics, scopeToDraw, RTB).DrawCustomForSingleSurroundingRect(rect, scopeToDraw); new GroupNameMarker(graphics, scopeToDraw, RTB).DrawCustomForSingleSurroundingRect(rect, scopeToDraw); return; } // if (scopeToDraw.IsRoot && scopeToDraw.IsImplicit) // { // new VisualScopeInvisible(graphics, scopeToDraw, RTB).DrawCustomForSingleSurroundingRect(rect, scopeToDraw); // return; // } if (IsActive) { Scope namedParent = GetFirstNamedParentScopeFor(scopeToDraw); if (namedParent!=null) { new NamedParentMarker(graphics, namedParent, RTB).DrawCustomForSingleSurroundingRect(rect, namedParent); } new VisualScopeActive(graphics, scopeToDraw, RTB).DrawCustomForSingleSurroundingRect(rect, scopeToDraw); return; } if (drawnScope.IsImplicit && drawnScope.IsFlat) { // new VisualScopeImplicitFlat(graphics, scopeToDraw, RTB).DrawCustomForSingleSurroundingRect(rect, scopeToDraw); return; } // if (drawnScope.IsImplicit && !drawnScope.IsFlat) // { // new NamedParentMarker(graphics, scopeToDraw, RTB).DrawCustomForSingleSurroundingRect(rect, scopeToDraw); // return; // // } if (!IsActive && drawnScope.IsExplicit && drawnScope.IsFlat) { new VisualScopeNonActiveNotImplicitFlat(graphics, scopeToDraw, RTB).DrawCustomForSingleSurroundingRect(rect, scopeToDraw); return; } if (IsActive && drawnScope.IsExplicit && drawnScope.IsFlat) { new VisualScopeActiveNotImplicitFlat(graphics, scopeToDraw, RTB).DrawCustomForSingleSurroundingRect(rect, scopeToDraw); return; } }
protected internal override void DrawCustomForSingleSurroundingRect(Rectangle rect, Scope scopeToDraw) { List<Rectangle> rects = txt.GetSurroundingRects(scopeToDraw.StartPosInRootScope,scopeToDraw.Length); int inflateFactor = 12; if(onMultipleLines(rects)) { inflateFactor = 6; } foreach (Rectangle rec in rects) { Rectangle infaltedRect = GetInflated(true, rec, inflateFactor); txt.drawRectWithColor(infaltedRect,Color.Chocolate, graphics, 220,2); } return; }
public List<Suggestion> GetSuggestions(Scope target) { RegexAdvisor advisor = new RegexAdvisor(); advisor.MaxSuggestionLength = 45; TeachRules(advisor); string selection; if(target!=null) { selection = target.Text; } else { selection = txt.SelectedText; } return advisor.Suggest(selection); }
protected internal override void DrawCustomForSingleSurroundingRect(Rectangle rect, Scope scopeToDraw) { DrawingParameters borderParameters = new DrawingParameters(Color.Empty, graphics, RTB.ImplicitScopeBorderColor, 35, RTB.NonActiveScopeBorderWidth); DrawingParameters fillParameters = new DrawingParameters(Color.Empty, graphics, 35); fillParameters.IsActive = IsActive; borderParameters.IsActive = IsActive; borderParameters.BorderColor = RTB.NonActiveScopeBorderColor; borderParameters.BorderWidth = RTB.NonActiveScopeBorderWidth; fillParameters.FillColor = RTB.NonActiveScopeFillColor; borderParameters.Rect = rect; fillParameters.Rect = rect; DrawBorder(borderParameters); DrawFill(fillParameters); }
public static ScopeActionsInfo GetActions(Scope scope) { ScopeActionsInfo info = new ScopeActionsInfo(); if (scope == null) { AddActionsOnSelectedText(info); AddUserActions(info, scope); AddRuleSuggestions(info, scope); } else { AddUserActions(info, scope); AddRuleSuggestions(info, scope); } return info ; }
private void AddScope(Scope root, TreeNode parentNode) { TreeNode n = null; if (parentNode == null) { n = Nodes.Add(key(root), "Root:" + root.Text.Replace("\n","\\n")); n.Tag = root; } if (parentNode != null) n = parentNode; if (root != null) { addScopeLeaf(n, "Left: ", root.InnerLeftScope); addScopeLeaf(n, "Middle: ", root.InnerMiddleScope); addScopeLeaf(n, "Right: ", root.InnerRightScope); } n.Expand(); }
public void AutoScope(Scope root) { if(autoAdvisor==null) { return; } foreach (Suggestion possibility in autoAdvisor.possibleMatches) { Match match = Regex.Match(root.Text, possibility.RegexText); if (match.Success) { Scope innerScope = root.FindInnerScope(match.Index, match.Length); if (innerScope == null || innerScope.Length!=match.Length) { List<SplitPoint> points = new ScopeSplitter().GetSplitPoints(root, match.Index, match.Length); bool willNewScopeBeInsdeAScopeWithSuggestions = false; if (points.Count>0) { foreach (SplitPoint point in points) { Scope target = root.FindInnerScope(point.StartIndex, point.Length); if(target!=null && target.Suggestions.Count>0) { willNewScopeBeInsdeAScopeWithSuggestions = true; break; } } } if(!willNewScopeBeInsdeAScopeWithSuggestions) innerScope = root.DefineInnerScope(match.Index, match.Length); } if (innerScope!=null) { innerScope.Suggestions.Add(possibility); innerScope.IsExplicit = true; } } } }
protected internal override void DrawCustomForSingleSurroundingRect(Rectangle rect, Scope scopeToDraw) { DrawingParameters borderParameters = new DrawingParameters(Color.Empty, graphics, RTB.ImplicitScopeBorderColor, 255, RTB.NonActiveScopeBorderWidth); DrawingParameters fillParameters = new DrawingParameters(RTB.ActiveScopeFillColor, graphics, 50); fillParameters.IsActive = IsActive; borderParameters.IsActive = IsActive; borderParameters.BorderColor = RTB.ActiveScopeBorderColor; borderParameters.BorderWidth = 1; fillParameters.FillColor = RTB.ActiveScopeFillColor; fillParameters.BorderWidth = 1; visible = true; Rectangle finalRect = GetActiveRectange(IsActive, rect); fillParameters.Rect = finalRect; borderParameters.Rect = finalRect; DrawBorder(borderParameters); DrawFill(fillParameters); }
protected internal override void DrawCustomForSingleSurroundingRect(Rectangle rect, Scope scopeToDraw) { DrawingParameters borderParameters = new DrawingParameters(Color.Empty, graphics, RTB.ImplicitScopeBorderColor, 35, RTB.NonActiveScopeBorderWidth); DrawingParameters fillParameters = new DrawingParameters(Color.Empty, graphics, 35); fillParameters.IsActive = IsActive; borderParameters.IsActive = IsActive; borderParameters.BorderColor = Color.Black; borderParameters.Opacity = 255; borderParameters.BorderWidth = 2; fillParameters.FillColor = Color.LightYellow; fillParameters.Opacity = 255; Rectangle biggerRect = GetHigherRect(rect); fillParameters.Rect = biggerRect; borderParameters.Rect = biggerRect; DrawBorder(borderParameters); DrawFill(fillParameters); if (scopeToDraw.Name == string.Empty) { return; } Font italicFont = new Font(txt.Font.FontFamily, txt.Font.Size - 2, FontStyle.Italic); SizeF nameWidth = graphics.MeasureString(scopeToDraw.Name, italicFont); if(nameWidth.Width> rect.Width) { return; } graphics.DrawString(scopeToDraw.Name, italicFont, new SolidBrush(Color.Black), GetMiddleRect(biggerRect)); }
public void Visit(Scope scope) { if (scope == null) { return; } Visit(scope.InnerLeftScope); Visit(scope.InnerMiddleScope); Visit(scope.InnerRightScope); scope.Suggestions.Clear(); foreach (string category in advisorsPool.Keys) { if (category == scope.MetaData.Category) { IAdvisor advisor = advisorsPool[category]; foreach (Suggestion advice in advisor.Suggest(scope)) { scope.Suggestions.Add(advice); } } } }
public VisualScopeActiveNotImplicitFlat(Graphics g, Scope scopeToDraw, ScopeAwareRichTextBox txt) : base(g, scopeToDraw, txt) { }
public void setup() { scope = new Scope("abc"); }
public void SetInnerScope_WithScopeInTheEnd_SetsInnerRightScopeAsNewScope() { scope = new Scope("abc"); Scope newone = scope.DefineInnerScope(2, 1); Assert.AreSame(newone, scope.InnerRightScope); }
public void SetInnerScope_WithScopeInTheEnd_DoesntSetInnerMiddleScope() { scope = new Scope("abc"); Scope newone = scope.DefineInnerScope(2, 1); Assert.IsNull(scope.InnerMiddleScope); }
public void SetInnerScope_WithScopeInThebeginning_SetsInnerLEftScopeAsNewScope() { scope = new Scope("abc"); Scope newone = scope.DefineInnerScope(0, 1); Assert.AreSame(newone, scope.InnerLeftScope); }
public void SetInnerScope_SetsParentCorrectlyRightScope() { Scope rootScope = new Scope("abc"); rootScope.DefineInnerScope(1, 1); Assert.AreSame(rootScope, rootScope.InnerRightScope.ParentScope); }
public void SetInnerScope_SetsParentCorrectly() { Scope rootScope = new Scope("abc"); Scope inner = rootScope.DefineInnerScope(1, 1); Assert.AreSame(rootScope, inner.ParentScope); }
public void SetInnerScope_SetsInnerRightScopePropertyToRightScope2() { scope = new Scope("defge"); scope.DefineInnerScope(2, 1); Scope rightScopeWithCorrectProperties = new Scope("ge", 3); rightScopeWithCorrectProperties.IsExplicit = false; Assert.IsTrue(rightScopeWithCorrectProperties.Equals(scope.InnerRightScope)); }
public void SetInnerScope_SetsInnerRightScopePropertyToRightScope() { scope = new Scope("abc"); scope.DefineInnerScope(1, 1); Scope rightScopeWithCorrectProperties = new Scope("c", 2, false); Assert.IsTrue(rightScopeWithCorrectProperties.Equals(scope.InnerRightScope)); }