Exemple #1
0
        protected override void Run(ICSharpCode.TextEditor.TextEditorControl textEditor, ICSharpCode.SharpDevelop.Dom.Refactoring.RefactoringProvider provider)
        {
            if (textEditor.ActiveTextAreaControl.SelectionManager.HasSomethingSelected)
            {
                MethodExtractorBase extractor = GetCurrentExtractor(textEditor);
                if (extractor != null)
                {
                    if (extractor.Extract())
                    {
                        ExtractMethodForm form = new ExtractMethodForm(extractor.ExtractedMethod, new Func <IOutputAstVisitor>(extractor.GetOutputVisitor));

                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            extractor.ExtractedMethod.Name = form.Text;
                            try {
                                textEditor.Document.UndoStack.StartUndoGroup();
                                extractor.InsertAfterCurrentMethod();
                                extractor.InsertCall();
                                textEditor.Document.FormattingStrategy.IndentLines(textEditor.ActiveTextAreaControl.TextArea, 0, textEditor.Document.TotalNumberOfLines - 1);
                            } finally {
                                textEditor.Document.UndoStack.EndUndoGroup();
                            }
                            textEditor.ActiveTextAreaControl.SelectionManager.ClearSelection();
                        }
                    }
                }
            }
        }
Exemple #2
0
        protected override void Run(ITextEditor textEditor, RefactoringProvider provider)
        {
            if (textEditor.SelectionLength > 0)
            {
                MethodExtractorBase extractor = GetCurrentExtractor(textEditor);
                if (extractor != null)
                {
                    if (extractor.Extract())
                    {
                        ExtractMethodForm form = new ExtractMethodForm(extractor.ExtractedMethod, new Func <IOutputAstVisitor>(extractor.GetOutputVisitor));

                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            extractor.ExtractedMethod.Name = form.Text;
                            using (textEditor.Document.OpenUndoGroup()) {
                                extractor.InsertAfterCurrentMethod();
                                extractor.InsertCall();
                                textEditor.Language.FormattingStrategy.IndentLines(textEditor, 0, textEditor.Document.TotalNumberOfLines - 1);
                            }
                            textEditor.Select(textEditor.SelectionStart, 0);
                        }
                    }
                }
            }
        }