public void Refactor()
        {
            var selection = _vbe.GetActiveSelection();

            if (!selection.HasValue)
            {
                _messageBox.Show(RubberduckUI.PromoteVariable_InvalidSelection, RubberduckUI.IntroduceField_Caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Refactor(selection.Value);
        }
        public void Refactor()
        {
            var selection = _vbe.GetActiveSelection();

            if (!selection.HasValue)
            {
                _messageBox.NotifyWarn(RubberduckUI.PromoteVariable_InvalidSelection, RubberduckUI.IntroduceField_Caption);
                return;
            }

            Refactor(selection.Value);
        }
예제 #3
0
        public void Refactor(QualifiedSelection selection)
        {
            _targetInterface = _state.DeclarationFinder.FindInterface(selection);

            _targetClass = _declarations.SingleOrDefault(d =>
                                                         ImplementingModuleTypes.Contains(d.DeclarationType) &&
                                                         d.QualifiedSelection.QualifiedName.Equals(selection.QualifiedName)) as ClassModuleDeclaration;

            if (_targetClass == null || _targetInterface == null)
            {
                _messageBox.NotifyWarn(RubberduckUI.ImplementInterface_InvalidSelectionMessage, RubberduckUI.ImplementInterface_Caption);
                return;
            }

            var oldSelection = _vbe.GetActiveSelection();

            ImplementMissingMembers(_state.GetRewriter(_targetClass));

            if (oldSelection.HasValue)
            {
                using (var module = _state.ProjectsProvider.Component(oldSelection.Value.QualifiedName).CodeModule)
                {
                    using (var pane = module.CodePane)
                    {
                        pane.Selection = oldSelection.Value.Selection;
                    }
                }
            }

            _state.OnParseRequested(this);
        }
        public RenamePresenter Create()
        {
            var activeSelection    = _vbe.GetActiveSelection();
            var qualifiedSelection = activeSelection.HasValue ? activeSelection.Value : new QualifiedSelection();

            return(new RenamePresenter(_view, new RenameModel(_vbe, _state, qualifiedSelection)));
        }
예제 #5
0
        private static IRefactoring TestRefactoring(IVBE vbe, IRewritingManager rewritingManager, RubberduckParserState state, IRefactoringPresenterFactory factory, IMessageBox msgBox = null)
        {
            var selectionService = MockedSelectionService(vbe.GetActiveSelection());

            if (msgBox == null)
            {
                msgBox = new Mock <IMessageBox>().Object;
            }
            return(new ExtractInterfaceRefactoring(state, state, msgBox, factory, rewritingManager, selectionService));
        }
예제 #6
0
        private static ISelectionService MockedSelectionService(IVBE vbe)
        {
            QualifiedSelection?activeSelection = vbe.GetActiveSelection();
            var selectionServiceMock           = new Mock <ISelectionService>();

            selectionServiceMock.Setup(m => m.ActiveSelection()).Returns(() => activeSelection);
            selectionServiceMock.Setup(m => m.TrySetActiveSelection(It.IsAny <QualifiedSelection>()))
            .Returns(() => true).Callback((QualifiedSelection selection) => activeSelection = selection);
            return(selectionServiceMock.Object);
        }
        private bool SpecialEvaluateCanExecute(object parameter)
        {
            var qualifiedSelection = _vbe.GetActiveSelection();

            if (!qualifiedSelection.HasValue)
            {
                return(false);
            }
            if (_state.IsNewOrModified(qualifiedSelection.Value.QualifiedName))
            {
                return(false);
            }

            var allDeclarations         = _state.AllDeclarations;
            var extractMethodValidation = new ExtractMethodSelectionValidation(allDeclarations);

            var canExecute = extractMethodValidation.withinSingleProcedure(qualifiedSelection.Value);

            return(canExecute);
        }
예제 #8
0
        public void Refactor()
        {
            var qualifiedSelection = _vbe.GetActiveSelection();

            if (qualifiedSelection != null)
            {
                Refactor(_declarations.FindVariable(qualifiedSelection.Value));
            }
            else
            {
                _messageBox.NotifyWarn(RubberduckUI.MoveCloserToUsage_InvalidSelection, RubberduckUI.MoveCloserToUsage_Caption);
            }
        }
        public IReorderParametersPresenter Create()
        {
            var selection = _vbe.GetActiveSelection();

            if (!selection.HasValue)
            {
                return(null);
            }

            var model = new ReorderParametersModel(_state, selection.Value, _messageBox);

            return(new ReorderParametersPresenter(_view, model, _messageBox));
        }
        public EncapsulateFieldPresenter Create()
        {
            var selection = _vbe.GetActiveSelection();

            if (!selection.HasValue)
            {
                return(null);
            }

            var model = new EncapsulateFieldModel(_state, selection.Value);

            return(new EncapsulateFieldPresenter(_view, model));
        }
예제 #11
0
        public ExtractInterfacePresenter Create()
        {
            var selection = _vbe.GetActiveSelection();

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

            var model = new ExtractInterfaceModel(_state, selection.Value);

            // don't show the UI if there's no memeber to extract
            return(model.Members.Any() ? new ExtractInterfacePresenter(_view, model) : null);
        }