public override void Execute(object parameter)
        {
            if (Vbe.ActiveCodePane == null) { return; }

            Declaration target;
            if (parameter != null)
            {
                target = parameter as Declaration;
            }
            else
            {
                target = _state.FindSelectedDeclaration(Vbe.ActiveCodePane);
            }

            if (target == null)
            {
                return;
            }

            using (var view = new RenameDialog())
            {
                var factory = new RenamePresenterFactory(Vbe, view, _state, new MessageBox(), _wrapperWrapperFactory);
                var refactoring = new RenameRefactoring(factory, Editor, new MessageBox(), _state);

                refactoring.Refactor(target);
            }
        }
Esempio n. 2
0
        public void Presenter_TargetIsNull()
        {
            //Input
            const string inputCode =
                @"
Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var codePaneMock = new Mock <ICodePane>();

            codePaneMock.Setup(c => c.CodeModule).Returns(component.CodeModule);
            codePaneMock.Setup(c => c.Selection);
            vbe.Setup(v => v.ActiveCodePane).Returns(codePaneMock.Object);

            var vbeWrapper = vbe.Object;
            var factory    = new RenamePresenterFactory(vbeWrapper, null, state, null);

            var presenter = factory.Create();

            Assert.AreEqual(null, presenter.Show());
        }
Esempio n. 3
0
        private void Rename()
        {
            var progress = new ParsingProgressPresenter();
            var result   = progress.Parse(_parser, _vbe.ActiveVBProject);

            var designer = (dynamic)_vbe.SelectedVBComponent.Designer;

            foreach (var control in designer.Controls)
            {
                if (!control.InSelection)
                {
                    continue;
                }

                var controlToRename =
                    result.Declarations.Items
                    .FirstOrDefault(item => item.IdentifierName == control.Name &&
                                    item.ComponentName == _vbe.SelectedVBComponent.Name &&
                                    _vbe.ActiveVBProject.Equals(item.Project));

                using (var view = new RenameDialog())
                {
                    var factory     = new RenamePresenterFactory(_vbe, view, result);
                    var refactoring = new RenameRefactoring(factory);
                    refactoring.Refactor(controlToRename);
                }
            }
        }
        protected override void OnExecute(object parameter)
        {
            Declaration target;

            using (var activePane = Vbe.ActiveCodePane)
            {
                if (activePane == null || activePane.IsWrappingNullReference)
                {
                    return;
                }

                if (parameter != null)
                {
                    target = parameter as Declaration;
                }
                else
                {
                    target = _state.FindSelectedDeclaration(activePane);
                }
            }

            if (target == null || !target.IsUserDefined)
            {
                return;
            }

            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state);
                var refactoring = new RenameRefactoring(Vbe, factory, _messageBox, _state, _state.ProjectsProvider, _rewritingManager);

                refactoring.Refactor(target);
            }
        }
Esempio n. 5
0
        public void Rename_PresenterIsNull()
        {
            //Input
            const string inputCode =
                @"Private Sub Foo()
End Sub";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var codePaneMock = new Mock <ICodePane>();

            codePaneMock.Setup(c => c.CodeModule).Returns(component.CodeModule);
            codePaneMock.Setup(c => c.Selection);
            vbe.Setup(v => v.ActiveCodePane).Returns(codePaneMock.Object);

            var vbeWrapper = vbe.Object;
            var factory    = new RenamePresenterFactory(vbeWrapper, null, state, null);

            var refactoring = new RenameRefactoring(vbeWrapper, factory, null, state);

            refactoring.Refactor();

            Assert.AreEqual(inputCode, component.CodeModule.Content());
        }
Esempio n. 6
0
        protected override void OnExecute(object parameter)
        {
            var factory     = new RenamePresenterFactory(_vbe, _view, _state);
            var refactoring = new RenameRefactoring(_vbe, factory, _msgBox, _state);

            refactoring.Refactor(((ICodeExplorerDeclarationViewModel)parameter).Declaration);
        }
        protected override void ExecuteImpl(object parameter)
        {
            if (Vbe.ActiveCodePane == null)
            {
                return;
            }

            Declaration target;

            if (parameter != null)
            {
                target = parameter as Declaration;
            }
            else
            {
                target = _state.FindSelectedDeclaration(Vbe.ActiveCodePane);
            }

            if (target == null)
            {
                return;
            }

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state, new MessageBox());
                var refactoring = new RenameRefactoring(Vbe, factory, new MessageBox(), _state);

                refactoring.Refactor(target);
            }
        }
Esempio n. 8
0
        protected override void OnExecute(object parameter)
        {
            if (Vbe.ActiveCodePane == null)
            {
                return;
            }

            Declaration target;

            if (parameter != null)
            {
                target = parameter as Declaration;
            }
            else
            {
                target = _state.FindSelectedDeclaration(Vbe.ActiveCodePane);
            }

            if (target == null || !target.IsUserDefined)
            {
                return;
            }

            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state);
                var refactoring = new RenameRefactoring(Vbe, factory, _messageBox, _state);

                refactoring.Refactor(target);
            }
        }
Esempio n. 9
0
        private void Rename()
        {
            var progress = new ParsingProgressPresenter();
            var result = progress.Parse(_parser, _vbe.ActiveVBProject);

            var designer = (dynamic) _vbe.SelectedVBComponent.Designer;

            foreach (var control in designer.Controls)
            {
                if (!control.InSelection) { continue; }

                var controlToRename =
                    result.Declarations.Items
                        .FirstOrDefault(item => item.IdentifierName == control.Name
                                                && item.ComponentName == _vbe.SelectedVBComponent.Name
                                                && _vbe.ActiveVBProject.Equals(item.Project));

                using (var view = new RenameDialog())
                {
                    var factory = new RenamePresenterFactory(_vbe, view, result);
                    var refactoring = new RenameRefactoring(factory);
                    refactoring.Refactor(controlToRename);
                }
            }
        }
Esempio n. 10
0
 //The rewriteSession is optional since it is not used in this particular quickfix because it is a refactoring quickfix.
 public override void Fix(IInspectionResult result, IRewriteSession rewriteSession = null)
 {
     using (var view = new RenameDialog(new RenameViewModel(_state)))
     {
         var factory     = new RenamePresenterFactory(_vbe, view, _state);
         var refactoring = new RenameRefactoring(_vbe, factory, _messageBox, _state, _state.ProjectsProvider, _rewritingManager);
         refactoring.Refactor(result.Target);
     }
 }
Esempio n. 11
0
 public override void Fix(IInspectionResult result)
 {
     using (var view = new RenameDialog(new RenameViewModel(_state)))
     {
         var factory     = new RenamePresenterFactory(_vbe, view, _state);
         var refactoring = new RenameRefactoring(_vbe, factory, _messageBox, _state);
         refactoring.Refactor(result.Target);
     }
 }
        private void RenameProject()
        {
            var vbe = QualifiedSelection.QualifiedName.Project.VBE;

            using (var view = new RenameDialog())
            {
                var factory = new RenamePresenterFactory(vbe, view, _parseResult);
                var refactoring = new RenameRefactoring(factory);
                refactoring.Refactor(Target);
            }
        }
Esempio n. 13
0
        private void RenameProject()
        {
            var vbe = QualifiedSelection.QualifiedName.Project.VBE;

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(vbe, view, _parseResult);
                var refactoring = new RenameRefactoring(factory);
                refactoring.Refactor(Target);
            }
        }
        public override void Fix()
        {
            var vbe = Selection.QualifiedName.Project.VBE;

            using (var view = new RenameDialog())
            {
                var factory = new RenamePresenterFactory(vbe, view, _state, _messageBox, _wrapperFactory);
                var refactoring = new RenameRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory), _messageBox, _state);
                refactoring.Refactor(_target);
                IsCancelled = view.DialogResult == DialogResult.Cancel;
            }
        }
Esempio n. 15
0
        public override void Fix()
        {
            var vbe = Selection.QualifiedName.Project.VBE;

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(vbe, view, _state, new MessageBox());
                var refactoring = new RenameRefactoring(vbe, factory, new MessageBox(), _state);
                refactoring.Refactor(_target);
                IsCancelled = view.DialogResult == DialogResult.Cancel;
            }
        }
Esempio n. 16
0
        public void Rename(Declaration target)
        {
            var progress = new ParsingProgressPresenter();
            var result   = progress.Parse(_parser, IDE.ActiveVBProject);

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(IDE, view, result);
                var refactoring = new RenameRefactoring(factory);
                refactoring.Refactor(target);
            }
        }
        public override void Fix()
        {
            var vbe = _target.Project.VBE;

            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(vbe, view, _state, _messageBox);
                var refactoring = new RenameRefactoring(vbe, factory, _messageBox, _state);
                refactoring.Refactor(_target);
                IsCancelled = view.DialogResult == DialogResult.Cancel;
            }
        }
Esempio n. 18
0
        protected override void OnExecute(object parameter)
        {
            if (!EvaluateCanExecute(parameter) ||
                !(parameter is CodeExplorerItemViewModel node) ||
                node.Declaration == null)
            {
                return;
            }

            var factory     = new RenamePresenterFactory(_vbe, _view, _state);
            var refactoring = new RenameRefactoring(_vbe, factory, _msgBox, _state, _state.ProjectsProvider, _rewritingManager);

            refactoring.Refactor(node.Declaration);
        }
Esempio n. 19
0
        protected override void OnExecute(object parameter)
        {
            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state);
                var refactoring = new RenameRefactoring(Vbe, factory, _msgBox, _state, _state.ProjectsProvider, _rewritingManager);

                var target = GetTarget();

                if (target != null)
                {
                    refactoring.Refactor(target);
                }
            }
        }
        protected override void ExecuteImpl(object parameter)
        {
            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state, _messageBox);
                var refactoring = new RenameRefactoring(Vbe, factory, _messageBox, _state);

                var target = GetTarget();

                if (target != null)
                {
                    refactoring.Refactor(target);
                }
            }
        }
        public override void Execute(object parameter)
        {
            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state, new MessageBox(), _wrapperWrapperFactory);
                var refactoring = new RenameRefactoring(factory, Editor, new MessageBox(), _state);

                var target = GetTarget();

                if (target != null)
                {
                    refactoring.Refactor(target);
                }
            }
        }
        public override void Execute(object parameter)
        {
            using (var view = new RenameDialog())
            {
                var factory = new RenamePresenterFactory(Vbe, view, _state, new MessageBox(), _wrapperWrapperFactory);
                var refactoring = new RenameRefactoring(factory, Editor, new MessageBox(), _state);

                var target = GetTarget();

                if (target != null)
                {
                    refactoring.Refactor(target);
                }
            }
        }
Esempio n. 23
0
        public override void Execute(object parameter)
        {
            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state, _msgBox);
                var refactoring = new RenameRefactoring(Vbe, factory, _msgBox, _state);

                var target = GetTarget();

                if (target != null)
                {
                    refactoring.Refactor(target);
                }
            }
        }
        private void Rename_Click(CommandBarButton Ctrl, ref bool CancelDefault)
        {
            VBProjectParseResult results;
            var declaration = FindSelectedDeclaration(out results);

            if (declaration == null)
            {
                return;
            }

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(_vbe, view, results);
                var refactoring = new RenameRefactoring(factory);
                refactoring.Refactor(declaration);
            }
        }
Esempio n. 25
0
        public void Factory_SelectionIsNull()
        {
            //Input
            const string inputCode =
@"Private Sub Foo()
End Sub";

            //Arrange
            var builder = new MockVbeBuilder();
            VBComponent component;
            var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
            var project = vbe.Object.VBProjects.Item(0);
            var module = project.VBComponents.Item(0).CodeModule;
            var codePaneFactory = new CodePaneWrapperFactory();
            var mockHost = new Mock<IHostApplication>();
            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState());

            parser.Parse();
            if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }

            var editor = new Mock<IActiveCodePaneEditor>();
            editor.Setup(e => e.GetSelection()).Returns((QualifiedSelection?)null);

            int startLine, startColumn, endLine, endColumn;

            var codePaneMock = new Mock<CodePane>();
            codePaneMock.Setup(c => c.CodeModule).Returns(module);
            codePaneMock.Setup(c => c.GetSelection(out startLine, out startColumn, out endLine, out endColumn));
            vbe.Setup(v => v.ActiveCodePane).Returns(codePaneMock.Object);

            var factory = new RenamePresenterFactory(vbe.Object, null, parser.State, null, codePaneFactory);

            var presenter = factory.Create();
            Assert.AreEqual(null, presenter.Show());
        }
Esempio n. 26
0
        public void Factory_SelectionIsNotNull_PassInTarget_Accept()
        {
            const string newName = "Goo";

            //Input
            const string inputCode =
@"Private Sub Foo(ByVal arg1 As String)
End Sub";
            var selection = new Selection(1, 25, 1, 25);

            //Arrange
            var builder = new MockVbeBuilder();
            VBComponent component;
            var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
            var project = vbe.Object.VBProjects.Item(0);
            var module = project.VBComponents.Item(0).CodeModule;
            var mockHost = new Mock<IHostApplication>();
            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState());

            parser.Parse();
            if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            var model = new RenameModel(vbe.Object, parser.State, qualifiedSelection, null) { NewName = newName };

            var editor = new Mock<IActiveCodePaneEditor>();
            editor.Setup(e => e.GetSelection()).Returns(qualifiedSelection);

            int startLine, startColumn, endLine, endColumn;

            var codePaneMock = new Mock<CodePane>();
            codePaneMock.Setup(c => c.CodeModule).Returns(module);
            codePaneMock.Setup(c => c.GetSelection(out startLine, out startColumn, out endLine, out endColumn));
            vbe.Setup(v => v.ActiveCodePane).Returns(codePaneMock.Object);

            var rubberduckCodePane = new Mock<ICodePaneWrapper>();
            rubberduckCodePane.Setup(r => r.CodeModule).Returns(module);
            rubberduckCodePane.Setup(r => r.GetSelection(out startLine, out startColumn, out endLine, out endColumn));
            rubberduckCodePane.Setup(r => r.Selection).Returns(selection);

            var codePaneFactoryMock = new Mock<ICodePaneWrapperFactory>();
            codePaneFactoryMock.Setup(c => c.Create(codePaneMock.Object)).Returns(rubberduckCodePane.Object);

            var view = new Mock<IRenameView>();
            view.Setup(v => v.NewName).Returns(newName);
            view.Setup(v => v.ShowDialog()).Returns(DialogResult.OK);

            var factory = new RenamePresenterFactory(vbe.Object, view.Object, parser.State, null, codePaneFactoryMock.Object);

            var presenter = factory.Create();
            Assert.AreEqual(model.NewName, presenter.Show(model.Target).NewName);
        }
Esempio n. 27
0
        public void Rename(Declaration target)
        {
            var progress = new ParsingProgressPresenter();
            var result = progress.Parse(_parser, IDE.ActiveVBProject);

            using (var view = new RenameDialog())
            {
                var factory = new RenamePresenterFactory(IDE, view, result);
                var refactoring = new RenameRefactoring(factory);
                refactoring.Refactor(target);
            }
        }
        private void Rename_Click(CommandBarButton Ctrl, ref bool CancelDefault)
        {
            VBProjectParseResult results;
            var declaration = FindSelectedDeclaration(out results);
            if (declaration == null)
            {
                return;
            }

            using (var view = new RenameDialog())
            {
                var factory = new RenamePresenterFactory(_vbe, view, results);
                var refactoring = new RenameRefactoring(factory);
                refactoring.Refactor(declaration);
            }
        }