-
Notifications
You must be signed in to change notification settings - Fork 295
/
ExtractInterfacePresenterFactory.cs
46 lines (40 loc) · 1.43 KB
/
ExtractInterfacePresenterFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Linq;
using Rubberduck.Parsing.VBA;
using Rubberduck.UI.Refactorings;
using Rubberduck.UI.Refactorings.ExtractInterface;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
namespace Rubberduck.Refactorings.ExtractInterface
{
public class ExtractInterfacePresenterFactory : IRefactoringPresenterFactory<ExtractInterfacePresenter>
{
private readonly IVBE _vbe;
private readonly IRefactoringDialog<ExtractInterfaceViewModel> _view;
private readonly RubberduckParserState _state;
public ExtractInterfacePresenterFactory(IVBE vbe, RubberduckParserState state, IRefactoringDialog<ExtractInterfaceViewModel> view)
{
_vbe = vbe;
_view = view;
_state = state;
}
public ExtractInterfacePresenter Create()
{
var pane = _vbe.ActiveCodePane;
if (pane == null || pane.IsWrappingNullReference)
{
return null;
}
var selection = pane.GetQualifiedSelection();
if (selection == null)
{
return null;
}
var model = new ExtractInterfaceModel(_state, selection.Value);
if (!model.Members.Any())
{
// don't show the UI if there's no member to extract
return null;
}
return new ExtractInterfacePresenter(_view, model);
}
}
}