Exemple #1
0
        public void FindAllReferences(Declaration declaration)
        {
            if (_state.Status != ParserState.Ready)
            {
                return;
            }

            var viewModel = CreateViewModel(declaration);

            if (!viewModel.SearchResults.Any())
            {
                _messageBox.NotifyWarn(string.Format(RubberduckUI.AllReferences_NoneFound, declaration.IdentifierName), RubberduckUI.Rubberduck);
                return;
            }

            if (viewModel.SearchResults.Count == 1)
            {
                _navigateCommand.Execute(viewModel.SearchResults.Single().GetNavigationArgs());
                return;
            }

            _viewModel.AddTab(viewModel);
            _viewModel.SelectedTab = viewModel;

            try
            {
                var presenter = _presenterService.Presenter(_viewModel);
                presenter.Show();
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }
        }
        private void UpdateTab()
        {
            if (_viewModel == null)
            {
                return;
            }

            var vm = CreateViewModel();

            var tab = _viewModel.Tabs.FirstOrDefault(t => t.Header == RubberduckUI.Parser_ParserError);

            if (tab != null)
            {
                if (_state.Status != ParserState.Error)
                {
                    tab.CloseCommand.Execute(null);
                }
                else
                {
                    tab.SearchResults = vm.SearchResults;
                }
            }
            else if (_state.Status == ParserState.Error)
            {
                _viewModel.AddTab(vm);
                _viewModel.SelectedTab = vm;
            }
        }
        public override void Execute(object parameter)
        {
            if (_state.Status != ParserState.Error)
            {
                return;
            }

            var viewModel = CreateViewModel();

            if (_viewModel == null)
            {
                return;
            }

            _viewModel.AddTab(viewModel);
            _viewModel.SelectedTab = viewModel;

            try
            {
                var presenter = _presenterService.Presenter(_viewModel);
                presenter.Show();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        private void UpdateTab()
        {
            try
            {
                if (_viewModel == null)
                {
                    return;
                }

                var vm = CreateViewModel();

                var tab = _viewModel.Tabs.FirstOrDefault(t => t.Header == RubberduckUI.Parser_ParserError);
                if (tab != null)
                {
                    if (_state.Status != ParserState.Error)
                    {
                        tab.CloseCommand.Execute(null);
                    }
                    else
                    {
                        tab.SearchResults = vm.SearchResults;
                    }
                }
                else if (_state.Status == ParserState.Error)
                {
                    _viewModel.AddTab(vm);
                    _viewModel.SelectedTab = vm;
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, "Exception thrown while trying to update the parser errors tab.");
            }
        }
        protected override void OnExecute(object parameter)
        {
            if (_state.Status != ParserState.Ready)
            {
                return;
            }

            var declaration = FindTarget(parameter);

            if (declaration == null)
            {
                return;
            }

            var viewModel = CreateViewModel(declaration);

            if (!viewModel.SearchResults.Any())
            {
                _messageBox.Show(string.Format(RubberduckUI.AllReferences_NoneFound, declaration.IdentifierName), RubberduckUI.Rubberduck, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (viewModel.SearchResults.Count == 1)
            {
                _navigateCommand.Execute(viewModel.SearchResults.Single().GetNavigationArgs());
                return;
            }

            _viewModel.AddTab(viewModel);
            _viewModel.SelectedTab = viewModel;

            try
            {
                var presenter = _presenterService.Presenter(_viewModel);
                presenter.Show();
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
        private void ShowResults(SearchResultsViewModel viewModel)
        {
            if (viewModel.SearchResults.Count == 1)
            {
                viewModel.NavigateCommand.Execute(viewModel.SearchResults[0].GetNavigationArgs());
                return;
            }

            try
            {
                _viewModel.AddTab(viewModel);
                _viewModel.SelectedTab = viewModel;

                var presenter = _presenterService.Presenter(_viewModel);
                presenter.Show();
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }
        }