Exemplo n.º 1
0
        public ExtractMethodRequest GetExtractionInfo(ExtractedMethodCreator previewer)
        {
            var requestView = new ExtractMethodRequestView(_serviceProvider, previewer);
            var dialog      = new ExtractMethodDialog(requestView);

            bool res = dialog.ShowModal() ?? false;

            if (res)
            {
                return(requestView.GetRequest());
            }

            return(null);
        }
Exemplo n.º 2
0
        private void OnExtractMethodButtonClick(CommandBarButton Ctrl, ref bool CancelDefault)
        {
            if (IDE.ActiveCodePane == null)
            {
                return;
            }
            var selection = IDE.ActiveCodePane.GetSelection();

            if (selection.Selection.StartLine <= IDE.ActiveCodePane.CodeModule.CountOfDeclarationLines)
            {
                return;
            }

            vbext_ProcKind startKind;
            var            startScope = IDE.ActiveCodePane.CodeModule.get_ProcOfLine(selection.Selection.StartLine, out startKind);
            vbext_ProcKind endKind;
            var            endScope = IDE.ActiveCodePane.CodeModule.get_ProcOfLine(selection.Selection.EndLine, out endKind);

            if (startScope != endScope)
            {
                return;
            }

            // if method is a property, GetProcedure(name) can return up to 3 members:
            var method = (_parser.Parse(IDE.ActiveVBProject).Declarations.Items
                          .SingleOrDefault(declaration =>
                                           (declaration.DeclarationType == DeclarationType.Procedure ||
                                            declaration.DeclarationType == DeclarationType.Function ||
                                            declaration.DeclarationType == DeclarationType.PropertyGet ||
                                            declaration.DeclarationType == DeclarationType.PropertyLet ||
                                            declaration.DeclarationType == DeclarationType.PropertySet) &&
                                           declaration.Context.GetSelection().Contains(selection.Selection)));

            if (method == null)
            {
                return;
            }

            var view      = new ExtractMethodDialog();
            var presenter = new ExtractMethodPresenter(IDE, view, method.Context, selection);

            presenter.Show();

            view.Dispose();
        }
        public IExtractMethodPresenter Create()
        {
            var selection = _editor.GetSelection();

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

            ExtractMethodModel model;

            try
            {
                model = new ExtractMethodModel(_editor, _declarations, selection.Value);
            }
            catch (InvalidOperationException)
            {
                return(null);
            }

            var view = new ExtractMethodDialog();

            return(new ExtractMethodPresenter(view, model, _indenter));
        }
Exemplo n.º 4
0
        public IExtractMethodPresenter Create()
        {
            var view = new ExtractMethodDialog();

            return(new ExtractMethodPresenter(view, _indenter));
        }