public InvalidReferenceModel(DocumentCompositeNode invalidObjectNode, IPropertyId invalidProperty, string invalidPropertyValue) { DocumentNode node = invalidObjectNode.Properties[invalidProperty]; if (node != null) { DocumentNodeHelper.GetNodeSpan(node); } else { DocumentNodeHelper.GetNodeSpan((DocumentNode)invalidObjectNode); } this.InvalidValueNode = node ?? (DocumentNode)invalidObjectNode; this.InvalidNodeName = invalidObjectNode.Name; this.InvalidNodeType = (ITypeId)invalidObjectNode.Type; this.InvalidProperty = invalidProperty; this.InvalidPropertyValue = invalidPropertyValue; }
public static void GoToXaml(SceneView sceneView, SceneXamlDocument document, List <DocumentNode> targetNodes, bool selectElementNameOnly, bool setFocusToXamlEditor) { ITextRange selectionSpan = TextRange.Null; bool flag = false; ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(document.ProjectContext); if (projectXamlContext == null) { return; } DocumentNode rootNode = document.RootNode; if (rootNode != null && targetNodes != null) { foreach (DocumentNode documentNode in targetNodes) { DocumentNode node = GoToXamlCommand.GetCorrespondingDocumentNode(documentNode, rootNode); if (node != null) { ITextRange nodeSpan; for (nodeSpan = DocumentNodeHelper.GetNodeSpan(node); TextRange.IsNull(nodeSpan) && node != null && node != rootNode; nodeSpan = DocumentNodeHelper.GetNodeSpan(node)) { node = (DocumentNode)node.Parent; } if (!TextRange.IsNull(nodeSpan)) { if (!flag) { flag = true; selectionSpan = nodeSpan; } else { selectionSpan = TextRange.Union(selectionSpan, nodeSpan); } } } } } if (sceneView == null) { sceneView = projectXamlContext.OpenView((IDocumentRoot)document, true); } using (sceneView.DisableSelectionSynchronization()) { sceneView.EnsureXamlEditorVisible(); if (!flag || sceneView.CodeEditor == null) { return; } ITextEditor textEditor = sceneView.CodeEditor; textEditor.ClearSelection(); if (selectElementNameOnly) { selectionSpan = GoToXamlCommand.GetElementNameSelectionSpan((IReadableSelectableTextBuffer)document.TextBuffer, selectionSpan); } textEditor.Select(selectionSpan.Offset, selectionSpan.Length); textEditor.CaretPosition = selectionSpan.Offset + selectionSpan.Length; Action action = (Action)(() => { textEditor.EnsureSpanVisible(selectionSpan.Offset, selectionSpan.Length); textEditor.EnsureCaretVisible(); textEditor.MoveLineToCenterOfView(textEditor.GetLineNumberFromPosition(selectionSpan.Offset)); if (!setFocusToXamlEditor) { return; } textEditor.Focus(); }); if (SceneViewUpdateScheduleTask.Synchronous) { action(); } else { UIThreadDispatcher.Instance.BeginInvoke(DispatcherPriority.Render, action); } } }
public DocumentNode EvaluateResourceAndCollectionPath(DocumentNodePath nodePath, ResourceReferenceType referenceType, DocumentNode keyNode, ICollection <DocumentCompositeNode> resourcesHostNodePath, ICollection <IDocumentRoot> relatedRoots, ICollection <string> warnings, out bool invalidForwardReference) { Uri uri; DocumentNode documentNode; IDocumentRoot applicationRoot; IDocumentRoot documentRoot = nodePath.RootNode.DocumentRoot; if (this.documentRootResolver != null) { applicationRoot = this.documentRootResolver.ApplicationRoot; } else { applicationRoot = null; } IDocumentRoot documentRoot1 = applicationRoot; bool flag = (documentRoot1 == null ? false : documentRoot1.RootNode != null); IDocumentRoot documentRoot2 = null; invalidForwardReference = false; if (referenceType != ResourceReferenceType.Static) { DocumentNode node = nodePath.Node; while (node != null) { if (flag && node.DocumentRoot != null && node == node.DocumentRoot.RootNode && PlatformTypes.ResourceDictionary.IsAssignableFrom(node.Type)) { string documentUrl = node.Context.DocumentUrl; DocumentCompositeNode rootNode = documentRoot1.RootNode as DocumentCompositeNode; if (rootNode != null && Uri.TryCreate(documentUrl, UriKind.Absolute, out uri) && ResourceNodeHelper.FindReferencedDictionaries(rootNode).Contains <Uri>(uri)) { documentRoot2 = node.DocumentRoot; break; } } DocumentNode documentNode1 = this.EvaluateResourceAtSpecificNode(node, keyNode, resourcesHostNodePath, relatedRoots, warnings); if (documentNode1 != null) { return(documentNode1); } node = node.Parent; if (node == null || nodePath == null) { continue; } DocumentNode containerNode = nodePath.ContainerNode; DocumentNode styleForSetter = ExpressionEvaluator.GetStyleForSetter(node); if (styleForSetter == null || styleForSetter != containerNode) { styleForSetter = ExpressionEvaluator.GetStyleForResourceEntry(node); if (styleForSetter == null) { if (node != containerNode) { continue; } nodePath = null; } else { if (styleForSetter == containerNode) { nodePath = null; } node = styleForSetter.Parent; } } else { nodePath = nodePath.GetContainerOwnerPath(); if (nodePath == null) { continue; } node = nodePath.Node; } } } else { DocumentNode documentNode2 = null; for (DocumentNode i = nodePath.Node; i != null; i = i.Parent) { ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(i); if (resourcesCollection != null) { ResourceSite resourceSite = new ResourceSite(i.Context, resourcesCollection); DocumentNode documentNode3 = null; if (ResourceNodeHelper.IsResourceDictionary(resourcesCollection)) { int siteChildIndex = -1; if (documentNode2 != null) { siteChildIndex = documentNode2.SiteChildIndex; } documentNode3 = this.EvaluateResourceAtSpecificSite(resourceSite, keyNode, resourcesHostNodePath, relatedRoots, siteChildIndex, warnings); } else if (ResourceNodeHelper.IsResourceContainer(resourcesCollection, documentNode2)) { documentNode3 = this.EvaluateResourceAtSpecificSite(resourceSite, keyNode, resourcesHostNodePath, relatedRoots, -1, warnings); } if (documentNode3 != null) { if (keyNode != null && keyNode.Parent != null && keyNode.Parent.Parent == i) { ITextRange nodeSpan = DocumentNodeHelper.GetNodeSpan(keyNode.Parent); ITextRange textRange = DocumentNodeHelper.GetNodeSpan(documentNode3); if (!TextRange.IsNull(textRange) && !TextRange.IsNull(nodeSpan) && nodeSpan.Offset < textRange.Offset) { documentNode3 = null; invalidForwardReference = true; } } if (documentNode3 != null) { return(documentNode3); } } } documentNode2 = i; } } if (flag) { DocumentNode documentNode4 = this.EvaluateResourceAtSpecificNode(documentRoot1.RootNode, keyNode, resourcesHostNodePath, relatedRoots, warnings); if (documentNode4 != null) { if (relatedRoots != null && documentNode4.DocumentRoot != documentRoot2) { relatedRoots.Add(documentRoot1); } return(documentNode4); } } if (documentRoot != null) { using (IEnumerator <IDocumentRoot> enumerator = documentRoot.DesignTimeResources.GetEnumerator()) { while (enumerator.MoveNext()) { IDocumentRoot current = enumerator.Current; DocumentNode documentNode5 = this.EvaluateResourceAtSpecificNode(current.RootNode, keyNode, resourcesHostNodePath, relatedRoots, warnings); if (documentNode5 == null) { continue; } if (relatedRoots != null && documentNode5.DocumentRoot != documentRoot2) { relatedRoots.Add(current); } documentNode = documentNode5; return(documentNode); } return(null); } return(documentNode); } return(null); }