Ejemplo n.º 1
0
        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);
                }
            }
        }