You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.9 KiB
57 lines
1.9 KiB
// <file> |
|
// <copyright see="prj:///doc/copyright.txt"/> |
|
// <license see="prj:///doc/license.txt"/> |
|
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/> |
|
// <version>$Revision$</version> |
|
// </file> |
|
|
|
using System; |
|
using System.Windows.Forms; |
|
using ICSharpCode.Core; |
|
using ICSharpCode.NRefactory.PrettyPrinter; |
|
using ICSharpCode.SharpDevelop; |
|
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
|
using ICSharpCode.SharpDevelop.Editor; |
|
using ICSharpCode.SharpDevelop.Refactoring; |
|
using SharpRefactoring.Forms; |
|
|
|
namespace SharpRefactoring |
|
{ |
|
public class ExtractMethodCommand : AbstractRefactoringCommand |
|
{ |
|
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); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
MethodExtractorBase GetCurrentExtractor(ITextEditor editor) |
|
{ |
|
switch (ProjectBindingService.GetCodonPerCodeFileName(editor.FileName).Language) { |
|
case "C#": |
|
return new CSharpMethodExtractor(editor); |
|
default: |
|
MessageService.ShowError(string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.ExtractMethodNotSupported}"), ProjectBindingService.GetCodonPerCodeFileName(editor.FileName).Language)); |
|
return null; |
|
} |
|
} |
|
} |
|
}
|
|
|