public TreeViewModel BuildCodeMapTree(CodeMapWindowViewModel windowViewModel, bool expandRoots, bool expandChildren, CancellationToken cancellation)
        {
            windowViewModel.ThrowOnNull(nameof(windowViewModel));
            cancellation.ThrowIfCancellationRequested();

            TreeViewModel codeMapTree = CreateEmptyCodeMapTree(windowViewModel);

            if (codeMapTree == null)
            {
                return(null);
            }

            cancellation.ThrowIfCancellationRequested();
            var roots = CreateRoots(codeMapTree, expandRoots, cancellation)?.Where(root => root != null).ToList();

            if (roots.IsNullOrEmpty())
            {
                return(codeMapTree);
            }

            cancellation.ThrowIfCancellationRequested();

            foreach (TreeNodeViewModel root in roots)
            {
                root.AcceptBuilder(this, expandChildren, cancellation);
            }

            var rootsToAdd = roots.Where(root => root.Children.Count > 0 || root.DisplayNodeWithoutChildren);

            codeMapTree.RootItems.AddRange(rootsToAdd);
            return(codeMapTree);
        }
        protected override async Task <CodeMapWindow> OpenToolWindowAsync()
        {
            CodeMapWindow codeMapWindow = await base.OpenToolWindowAsync();

            if (codeMapWindow?.CodeMapWPFControl == null)
            {
                return(codeMapWindow);
            }

            CodeMapWindowViewModel codeMapViewModel = codeMapWindow.CodeMapWPFControl.DataContext as CodeMapWindowViewModel;
            IWpfTextView           textView         = await ServiceProvider.GetWpfTextViewAsync();

            Document document = textView?.TextSnapshot?.GetOpenDocumentInCurrentContextWithChanges();

            if (document == null)
            {
                return(codeMapWindow);
            }
            else if (CheckIfSameDocumentWasReOpened(codeMapViewModel, document))               //Return window in case of re-openning of the same doc
            {
                codeMapWindow.CodeMapWPFControl.DataContext = CodeMapWindowViewModel.InitCodeMap(textView, document);
                return(codeMapWindow);
            }
            else if (codeMapViewModel != null)                              //Cancel operations in case of another doc and dispose of the old view model
            {
                codeMapViewModel.CancelCodeMapBuilding();
                codeMapViewModel.Dispose();
            }

            codeMapWindow.CodeMapWPFControl.DataContext = CodeMapWindowViewModel.InitCodeMap(textView, document);
            return(codeMapWindow);
        }
Beispiel #3
0
            public CodeMapDteEventsObserver(CodeMapWindowViewModel codeMapViewModel)
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                _codeMapViewModel = codeMapViewModel;
                _vsEventsAdapter  = VSEventsAdapter.CreateAndSubscribe();

                SubscribeCodeMapOnVisualStudioEvents();
            }
        private bool CheckIfSameDocumentWasReOpened(CodeMapWindowViewModel codeMapViewModel, Document openedDocument)
        {
            if (codeMapViewModel == null)
            {
                return(false);
            }

            return(codeMapViewModel.Document.FilePath == openedDocument.FilePath);
        }
Beispiel #5
0
        protected TreeViewModel?BuildCodeMapTree(CodeMapWindowViewModel windowViewModel, bool expandRoots, bool expandChildren)
        {
            Cancellation.ThrowIfCancellationRequested();

            TreeViewModel codeMapTree = CreateEmptyCodeMapTree(windowViewModel);

            if (codeMapTree == null)
            {
                return(null);
            }

            Cancellation.ThrowIfCancellationRequested();
            List <TreeNodeViewModel> roots;

            try
            {
                ExpandCreatedNodes = expandRoots;
                roots = CreateRoots(codeMapTree).Where(root => root != null).ToList();
            }
            finally
            {
                ExpandCreatedNodes = false;
            }

            if (roots.IsNullOrEmpty())
            {
                return(codeMapTree);
            }

            Cancellation.ThrowIfCancellationRequested();

            try
            {
                ExpandCreatedNodes = expandChildren;

                foreach (TreeNodeViewModel root in roots)
                {
                    BuildSubTree(root);
                }
            }
            finally
            {
                ExpandCreatedNodes = false;
            }

            var rootsToAdd = roots.Where(root => root.Children.Count > 0 || root.DisplayNodeWithoutChildren);

            codeMapTree.FillCodeMapTree(rootsToAdd);
            return(codeMapTree);
        }
Beispiel #6
0
        public TreeViewModel?BuildCodeMapTree(CodeMapWindowViewModel windowViewModel, bool expandRoots, bool expandChildren, CancellationToken cancellation)
        {
            windowViewModel.ThrowOnNull(nameof(windowViewModel));

            try
            {
                Cancellation = cancellation;
                return(BuildCodeMapTree(windowViewModel, expandRoots, expandChildren));
            }
            finally
            {
                Cancellation = CancellationToken.None;
            }
        }
Beispiel #7
0
        public override async void OnToolWindowCreated()
        {
            base.OnToolWindowCreated();

            // Set the text that will appear in the title bar of the tool window. Note that because we need access to the package for localization,
            // we have to wait to do this here. If we used a constant string, we could do this in the constructor.
            this.Caption = VSIXResource.CodeMap_WindowTitle;

            if (CodeMapWPFControl == null)
            {
                return;
            }

            IAsyncServiceProvider serviceProvider = AcuminatorVSPackage.Instance ?? AsyncServiceProvider.GlobalProvider;

            if (serviceProvider == null)
            {
                return;
            }

            Workspace?workspace = await AcuminatorVSPackage.Instance.GetVSWorkspaceAsync();

            if (workspace == null)
            {
                return;
            }

            IWpfTextView?textView = await ThreadHelper.JoinableTaskFactory.RunAsync(serviceProvider.GetWpfTextViewAsync);

            Document?document = textView?.TextSnapshot?.GetOpenDocumentInCurrentContextWithChanges();

            if (CodeMapWPFControl.DataContext is CodeMapWindowViewModel codeMapViewModel)
            {
                await codeMapViewModel.RefreshCodeMapOnWindowOpeningAsync(textView, document);
            }
            else
            {
                CodeMapWPFControl.DataContext = CodeMapWindowViewModel.InitCodeMap(workspace, textView, document);
            }
        }
Beispiel #8
0
 public virtual TreeViewModel CreateEmptyCodeMapTree(CodeMapWindowViewModel windowViewModel) => new TreeViewModel(windowViewModel);
 public CodeMapDocChangesClassifier(CodeMapWindowViewModel codeMapWindowViewModel)
 {
     _codeMapViewModel = codeMapWindowViewModel.CheckIfNull(nameof(codeMapWindowViewModel));
 }