bool MarkReferences(ReferenceSegment referenceSegment) { if (TextEditor.TextArea.TextView.Document == null) { return(false); } if (previousReferenceSegment == referenceSegment) { return(true); } object reference = referenceSegment.Reference; if (reference == null) { return(false); } ClearMarkedReferences(); previousReferenceSegment = referenceSegment; foreach (var tmp in references) { var r = tmp; if (RefSegEquals(referenceSegment, r)) { var mark = textMarkerService.Create(r.StartOffset, r.Length); mark.ZOrder = TextEditorConstants.ZORDER_SEARCHRESULT; mark.HighlightingColor = () => { return(r.IsLocalTarget ? themeManager.Theme.GetTextColor(ColorType.LocalDefinition).ToHighlightingColor() : themeManager.Theme.GetTextColor(ColorType.LocalReference).ToHighlightingColor()); }; markedReferences.Add(mark); } } return(true); }
static bool RefSegEquals(ReferenceSegment a, ReferenceSegment b) { if (a == b) { return(true); } if (a == null || b == null) { return(false); } if (a.Reference == null || b.Reference == null) { return(false); } if (a.Reference.Equals(b.Reference)) { return(true); } var ma = a.Reference as IMemberRef; var mb = b.Reference as IMemberRef; if (ma != null && mb != null) { ma = Resolve(ma) ?? ma; mb = Resolve(mb) ?? mb; return(new SigComparer(SigComparerOptions.CompareDeclaringTypes | SigComparerOptions.PrivateScopeIsComparable).Equals(ma, mb)); } return(false); }
public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null, ListBox listBox = null) { ReferenceSegment reference; if (textView != null) { reference = textView.GetReferenceSegmentAtMousePosition(); } else if (listBox?.SelectedItem is SearchResult result) { reference = new ReferenceSegment { Reference = result.Member } } ; else { reference = null; } var position = textView != null?textView.GetPositionFromMousePosition() : null; var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null; return(new TextViewContext { TreeView = treeView, SelectedTreeNodes = selectedTreeNodes, TextView = textView, Reference = reference, Position = position }); }
public Context(ReferenceSegment regSeg) { this.ReferenceSegment = regSeg; var node = MainWindow.Instance.FindTreeNode(regSeg.Reference); this.Nodes = node == null ? new ILSpyTreeNode[0] : new ILSpyTreeNode[] { node }; }
public async Task VisitAsync(ODataPath path) { NotFound = false; BadRequest = false; Result = null; ResultType = null; PropertySetter = null; Index = 0; foreach (var segment in path) { await(segment switch { TypeSegment typeSegment => VisitAsync(typeSegment), NavigationPropertySegment navigationPropertySegment => VisitAsync(navigationPropertySegment), EntitySetSegment entitySetSegment => VisitAsync(entitySetSegment), SingletonSegment singletonSegment => VisitAsync(singletonSegment), KeySegment keySegment => VisitAsync(keySegment), PropertySegment propertySegment => VisitAsync(propertySegment), AnnotationSegment annotationSegment => VisitAsync(annotationSegment), OperationImportSegment operationImportSegment => VisitAsync(operationImportSegment), OperationSegment operationSegment => VisitAsync(operationSegment), DynamicPathSegment dynamicPathSegment => VisitAsync(dynamicPathSegment), CountSegment countSegment => VisitAsync(countSegment), FilterSegment filterSegment => VisitAsync(filterSegment), ReferenceSegment referenceSegment => VisitAsync(referenceSegment), EachSegment eachSegment => VisitAsync(eachSegment), NavigationPropertyLinkSegment navigationPropertyLinkSegment => VisitAsync(navigationPropertyLinkSegment), ValueSegment valueSegment => VisitAsync(valueSegment), BatchSegment batchSegment => VisitAsync(batchSegment), BatchReferenceSegment batchReferenceSegment => VisitAsync(batchReferenceSegment), MetadataSegment metadataSegment => VisitAsync(metadataSegment), PathTemplateSegment pathTemplateSegment => VisitAsync(pathTemplateSegment), _ => throw new NotSupportedException() });
public void ReferenceSegmentsWithSameNavigationSourcesShouldBeEqual() { ReferenceSegment referenceSegment1 = new ReferenceSegment(HardCodedTestModel.GetPet1Set()); ReferenceSegment referenceSegment2 = new ReferenceSegment(HardCodedTestModel.GetPet1Set()); Assert.True(referenceSegment1.Equals(referenceSegment2)); Assert.True(referenceSegment2.Equals(referenceSegment1)); }
public void ReferenceSegmentsWithDifferenceNavigationSourcesShouldNotBeEqual() { ReferenceSegment referenceSegment1 = new ReferenceSegment(HardCodedTestModel.GetPeopleSet()); ReferenceSegment referenceSegment2 = new ReferenceSegment(HardCodedTestModel.GetPet1Set()); referenceSegment1.Equals(referenceSegment2).Should().BeFalse(); referenceSegment2.Equals(referenceSegment1).Should().BeFalse(); }
public static ReferenceSegment ShouldBeReferenceSegment(this ODataPathSegment segment, IEdmNavigationSource navigationSource) { Assert.NotNull(segment); ReferenceSegment referenceSegment = Assert.IsType <ReferenceSegment>(segment); Assert.Same(referenceSegment.TargetEdmNavigationSource, navigationSource); return(referenceSegment); }
bool GoToTarget(ReferenceSegment refSeg, bool canJumpToReference, bool canRecordHistory) { if (textEditorHelper == null) { return(false); } return(GoTo(refSeg, false, true, canRecordHistory, canJumpToReference)); }
public static AndConstraint <ReferenceSegment> ShouldBeReferenceSegment(this ODataPathSegment segment, IEdmNavigationSource navigationSource) { segment.Should().BeOfType <ReferenceSegment>(); ReferenceSegment referenceSegment = segment.As <ReferenceSegment>(); referenceSegment.TargetEdmNavigationSource.Should().Be(navigationSource); return(new AndConstraint <ReferenceSegment>(referenceSegment)); }
public void EntityReferenceCanAppearAfterSingleton() { var path = PathFunctionalTestsUtil.RunParsePath("Boss/$ref"); ReferenceSegment referenceSegment = path.LastSegment as ReferenceSegment; Assert.Same(referenceSegment.TargetEdmNavigationSource, HardCodedTestModel.GetBossSingleton()); Assert.True(referenceSegment.SingleResult); }
void ClearMarkedReferences() { foreach (var mark in markedReferences) { textMarkerService.Remove(mark); } markedReferences.Clear(); previousReferenceSegment = null; }
public void ReferenceSegmentWithSingleValuedNavigationSourceConstructsSuccessfully() { ReferenceSegment referenceSegment = new ReferenceSegment(HardCodedTestModel.GetBossSingleton()); Assert.Equal(UriQueryConstants.RefSegment, referenceSegment.Identifier); Assert.True(referenceSegment.SingleResult); Assert.Same(HardCodedTestModel.GetBossSingleton(), referenceSegment.TargetEdmNavigationSource); Assert.Equal(RequestTargetKind.Resource, referenceSegment.TargetKind); Assert.Null(referenceSegment.EdmType); }
public void ReferenceSegmentWithSingleValuedNavigationSourceConstructsSuccessfully() { ReferenceSegment referenceSegment = new ReferenceSegment(HardCodedTestModel.GetBossSingleton()); referenceSegment.Identifier.Should().Be(UriQueryConstants.RefSegment); referenceSegment.SingleResult.Should().BeTrue(); referenceSegment.TargetEdmNavigationSource.Should().Be(HardCodedTestModel.GetBossSingleton()); referenceSegment.TargetKind.Should().Be(RequestTargetKind.Resource); referenceSegment.EdmType.Should().BeNull(); }
bool IsOwnerOf(ReferenceSegment refSeg) { foreach (var r in references) { if (r == refSeg) { return(true); } } return(false); }
void JumpToReference(ReferenceSegment referenceSegment, MouseEventArgs e) { if (textEditorHelper == null) { return; } bool newTab = Keyboard.Modifiers == ModifierKeys.Control; textEditorHelper.SetActive(); textEditorHelper.SetFocus(); TextEditor.GoToMousePosition(); e.Handled = GoTo(referenceSegment, newTab, false, true, true); }
ReferenceSegment FindLocalTarget(ReferenceSegment refSeg) { if (refSeg.IsLocalTarget) { return(refSeg); } foreach (var r in references) { if (r.IsLocalTarget && RefSegEquals(r, refSeg)) { return(r); } } return(null); }
public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null, ListBox listBox = null, TabControl tabControl = null, HexBox hexBox = null, bool openedFromKeyboard = false) { TextViewPosition?position = null; if (textView != null) { position = openedFromKeyboard ? textView.TextEditor.TextArea.Caret.Position : textView.GetPositionFromMousePosition(); } ReferenceSegment reference; if (textView != null) { reference = textView.GetReferenceSegmentAt(position); } else if (listBox != null && listBox.SelectedItem is SearchResult) { reference = new ReferenceSegment { Reference = ((SearchResult)listBox.SelectedItem).MDTokenProvider } } ; else { reference = null; } var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null; return(new TextViewContext { TreeView = treeView, SelectedTreeNodes = selectedTreeNodes, TextView = textView, TabControl = tabControl, HexBox = hexBox, ListBox = listBox, Reference = reference, Position = position, OpenedFromKeyboard = openedFromKeyboard, }); }
public static ContextMenuEntryContext Create(FrameworkElement elem, bool openedFromKeyboard = true) { TextViewPosition?position = null; var textView = elem as DecompilerTextView; var listBox = elem as ListBox; var treeView = elem as SharpTreeView; if (textView != null) { position = openedFromKeyboard ? textView.TextEditor.TextArea.Caret.Position : textView.GetPositionFromMousePosition(); } ReferenceSegment reference; if (textView != null) { reference = textView.GetReferenceSegmentAt(position); } else if (listBox != null && listBox.SelectedItem is SearchResult) { reference = new ReferenceSegment { Reference = ((SearchResult)listBox.SelectedItem).Reference } } ; else { reference = null; } var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null; return(new ContextMenuEntryContext { Element = elem, SelectedTreeNodes = selectedTreeNodes, Reference = reference, Position = position, OpenedFromKeyboard = openedFromKeyboard, }); }
static bool RefSegEquals(ReferenceSegment a, ReferenceSegment b) { if (a == b) { return(true); } if (a == null || b == null) { return(false); } if (a.Reference == null || b.Reference == null) { return(false); } if (a.Reference.Equals(b.Reference)) { return(true); } var ma = a.Reference as IMemberRef; var mb = b.Reference as IMemberRef; if (ma != null && mb != null) { // PERF: Prevent expensive resolves by doing a quick name check if (ma.Name != mb.Name) { return(false); } ma = Resolve(ma) ?? ma; mb = Resolve(mb) ?? mb; return(new SigComparer(SigComparerOptions.CompareDeclaringTypes | SigComparerOptions.PrivateScopeIsComparable).Equals(ma, mb)); } return(false); }
IEnumerable <ReferenceSegment> GetReferenceSegmentsFrom(ReferenceSegment refSeg, bool forward) { if (refSeg == null) { yield break; } var currSeg = refSeg; while (true) { currSeg = forward ? references.GetNextSegment(currSeg) : references.GetPreviousSegment(currSeg); if (currSeg == null) { currSeg = forward ? references.FirstSegment : references.LastSegment; } if (currSeg == refSeg) { break; } yield return(currSeg); } }
/// <summary> /// Creates a visual line text element with the specified length. /// It uses the <see cref="ITextRunConstructionContext.VisualLine"/> and its /// <see cref="VisualLineElement.RelativeTextOffset"/> to find the actual text string. /// </summary> public VisualLineReferenceText(VisualLine parentVisualLine, int length, ReferenceElementGenerator parent, ReferenceSegment referenceSegment) : base(parentVisualLine, length) { this.parent = parent; this.referenceSegment = referenceSegment; }
/// <summary> /// Handle validating a ReferenceSegment /// </summary> /// <param name="segment">The reference segment to valdiate.</param> public override void Handle(ReferenceSegment segment) { ValidateItem(segment); }
public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null, ListBox listBox = null, DataGrid dataGrid = null) { ReferenceSegment reference; if (textView != null) { reference = textView.GetReferenceSegmentAtMousePosition(); } else if (listBox?.SelectedItem is SearchResult result) { reference = new ReferenceSegment { Reference = result.Reference } } ; else if (listBox?.SelectedItem is TreeNodes.IMemberTreeNode provider) { reference = new ReferenceSegment { Reference = provider.Member } } ; else if (listBox?.SelectedItem != null) { reference = new ReferenceSegment { Reference = listBox.SelectedItem } } ; else if (dataGrid?.SelectedItem is TreeNodes.IMemberTreeNode provider2) { reference = new ReferenceSegment { Reference = provider2.Member } } ; else if (dataGrid?.SelectedItem != null) { reference = new ReferenceSegment { Reference = dataGrid.SelectedItem } } ; else { reference = null; } var position = textView != null?textView.GetPositionFromMousePosition() : null; var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null; return(new TextViewContext { ListBox = listBox, DataGrid = dataGrid, TreeView = treeView, SelectedTreeNodes = selectedTreeNodes, TextView = textView, Reference = reference, Position = position, MousePosition = ((Visual)textView ?? treeView ?? (Visual)listBox ?? dataGrid).PointToScreen(Mouse.GetPosition((IInputElement)textView ?? treeView ?? (IInputElement)listBox ?? dataGrid)) }); }
internal void JumpToReference(ReferenceSegment referenceSegment, MouseEventArgs e) { referenceClicked(referenceSegment, e); }
bool GoTo(ReferenceSegment refSeg, bool newTab, bool followLocalRefs, bool canRecordHistory, bool canJumpToReference) { if (refSeg == null) { return(false); } if (newTab) { Debug.Assert(canJumpToReference); if (!canJumpToReference) { return(false); } textEditorHelper.FollowReference(refSeg.ToCodeReference(), newTab); return(true); } if (followLocalRefs) { if (!IsOwnerOf(refSeg)) { if (!canJumpToReference) { return(false); } textEditorHelper.FollowReference(refSeg.ToCodeReference(), newTab); return(true); } var localTarget = FindLocalTarget(refSeg); if (localTarget != null) { refSeg = localTarget; } if (refSeg.IsLocalTarget) { if (canRecordHistory) { if (!canJumpToReference) { return(false); } textEditorHelper.FollowReference(refSeg.ToCodeReference(), newTab); } else { var line = TextEditor.Document.GetLineByOffset(refSeg.StartOffset); int column = refSeg.StartOffset - line.Offset + 1; ScrollAndMoveCaretTo(line.LineNumber, column); } return(true); } if (refSeg.IsLocal) { return(false); } if (!canJumpToReference) { return(false); } textEditorHelper.FollowReference(refSeg.ToCodeReference(), newTab); return(true); } else { var localTarget = FindLocalTarget(refSeg); if (localTarget != null) { refSeg = localTarget; } int pos = -1; if (!refSeg.IsLocal) { if (refSeg.IsLocalTarget) { pos = refSeg.EndOffset; } if (pos < 0 && definitionLookup != null) { pos = definitionLookup.GetDefinitionPosition(refSeg.Reference); } } if (pos >= 0) { if (canRecordHistory) { if (!canJumpToReference) { return(false); } textEditorHelper.FollowReference(refSeg.ToCodeReference(), newTab); } else { MarkReferences(refSeg); textEditorHelper.SetFocus(); TextEditor.Select(pos, 0); TextEditor.ScrollTo(TextEditor.TextArea.Caret.Line, TextEditor.TextArea.Caret.Column); } return(true); } if (refSeg.IsLocal && MarkReferences(refSeg)) { return(false); // Allow another handler to set a new caret position } textEditorHelper.SetFocus(); if (!canJumpToReference) { return(false); } textEditorHelper.FollowReference(refSeg.ToCodeReference(), newTab); return(true); } }
TextEditorLocation GetLocation(ReferenceSegment refSeg) { var loc = TextEditor.Document.GetLocation(refSeg.StartOffset); return(new TextEditorLocation(loc.Line, loc.Column)); }
public RefPos(ReferenceSegment refSeg) { this.ReferenceSegment = refSeg; }