Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #783 from Vogel612/Refactorings
Refactorings
- Loading branch information
Showing
7 changed files
with
108 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
RetailCoder.VBE/UI/Command/RefactorExtractMethodCommand.cs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
RetailCoder.VBE/UI/Command/RefactorRemoveParametersCommand.cs
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
RetailCoder.VBE/UI/Command/Refactorings/RefactorCommandBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Microsoft.Vbe.Interop; | ||
using Rubberduck.Parsing; | ||
using Rubberduck.VBEditor; | ||
using Rubberduck.UI.Command; | ||
using System; | ||
|
||
namespace Rubberduck.UI.Command.Refactorings | ||
{ | ||
public abstract class RefactorCommandBase : CommandBase | ||
{ | ||
protected readonly IRubberduckParser _parser; | ||
protected readonly IActiveCodePaneEditor _editor; | ||
protected readonly VBE _ide; | ||
|
||
protected RefactorCommandBase(VBE ide, IRubberduckParser parser, IActiveCodePaneEditor editor) | ||
{ | ||
_ide = ide; | ||
_parser = parser; | ||
_editor = editor; | ||
} | ||
|
||
protected void refactoring_InvalidSelection(object sender, EventArgs e) | ||
{ | ||
System.Windows.Forms.MessageBox.Show(RubberduckUI.ExtractMethod_InvalidSelectionMessage, RubberduckUI.ExtractMethod_Caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); | ||
} | ||
} | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
RetailCoder.VBE/UI/Command/Refactorings/RefactorExtractMethodCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Microsoft.Vbe.Interop; | ||
using System.Runtime.InteropServices; | ||
using Rubberduck.Parsing; | ||
using Rubberduck.Refactorings.ExtractMethod; | ||
using Rubberduck.VBEditor; | ||
|
||
namespace Rubberduck.UI.Command.Refactorings | ||
{ | ||
|
||
[ComVisible(false)] | ||
public class RefactorExtractMethodCommand : RefactorCommandBase | ||
{ | ||
public RefactorExtractMethodCommand (VBE ide, IRubberduckParser parser, IActiveCodePaneEditor editor) | ||
: base (ide, parser, editor) | ||
{ | ||
} | ||
|
||
public override void Execute(object parameter) | ||
{ | ||
var progress = new ParsingProgressPresenter(); | ||
var result = progress.Parse(_parser, _ide.ActiveVBProject); | ||
|
||
var declarations = result.Declarations; | ||
var factory = new ExtractMethodPresenterFactory(_editor, declarations); | ||
var refactoring = new ExtractMethodRefactoring(factory, _editor); | ||
refactoring.InvalidSelection += refactoring_InvalidSelection; | ||
refactoring.Refactor(); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
RetailCoder.VBE/UI/Command/Refactorings/RefactorRemoveParametersCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Microsoft.Vbe.Interop; | ||
using Rubberduck.Parsing; | ||
using Rubberduck.VBEditor; | ||
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane; | ||
using System.Runtime.InteropServices; | ||
using Rubberduck.Refactorings.RemoveParameters; | ||
using Rubberduck.UI.Refactorings; | ||
|
||
namespace Rubberduck.UI.Command.Refactorings | ||
{ | ||
[ComVisible(false)] | ||
public class RefactorRemoveParametersCommand : RefactorCommandBase | ||
{ | ||
private readonly ICodePaneWrapperFactory _wrapperWrapperFactory; | ||
|
||
public RefactorRemoveParametersCommand(VBE ide, IRubberduckParser parser, IActiveCodePaneEditor editor, ICodePaneWrapperFactory wrapperWrapperFactory) | ||
: base (ide, parser, editor) | ||
{ | ||
_wrapperWrapperFactory = wrapperWrapperFactory; | ||
} | ||
|
||
public override void Execute(object parameter) | ||
{ | ||
if (_ide.ActiveCodePane == null) | ||
{ | ||
return; | ||
} | ||
var codePane = _wrapperWrapperFactory.Create(_ide.ActiveCodePane); | ||
var selection = new QualifiedSelection(new QualifiedModuleName(codePane.CodeModule.Parent), codePane.Selection); | ||
// duplicates ReorderParameters Implementation until here... extract common method? | ||
// TryGetQualifiedSelection? | ||
var progress = new ParsingProgressPresenter(); | ||
var result = progress.Parse(_parser, _ide.ActiveVBProject); | ||
|
||
using (var view = new RemoveParametersDialog()) | ||
{ | ||
var factory = new RemoveParametersPresenterFactory(_editor, view, result, new MessageBox()); | ||
var refactoring = new RemoveParametersRefactoring(factory, _editor); | ||
refactoring.Refactor(selection); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters