Skip to content

Commit d0a341a

Browse files
committed
Update instancing selection to use combobox
1 parent cd9f756 commit d0a341a

File tree

7 files changed

+57
-47
lines changed

7 files changed

+57
-47
lines changed

Rubberduck.Core/UI/Converters/ClassInstancingToBooleanConverter.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

Rubberduck.Core/UI/Refactorings/ExtractInterface/ExtractInterfaceView.xaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
</ResourceDictionary.MergedDictionaries>
1414

1515
<BitmapImage x:Key="InvalidInterfaceImage" UriSource="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/cross-circle.png" />
16-
<converters:InvertBoolValueConverter x:Key="InvertBool" />
16+
<converters:BoolToVisibleVisibilityConverter x:Key="BoolToVisibility" />
17+
<converters:BoolToHiddenVisibilityConverter x:Key="BoolToHiddenVisibility" />
1718
</ResourceDictionary>
1819
</UserControl.Resources>
1920
<Grid>
@@ -51,16 +52,17 @@
5152
VerticalAlignment="Top"
5253
Visibility="{Binding IsValidInterfaceName, Converter={StaticResource BoolToHiddenVisibility}}"/>
5354
</StackPanel>
54-
55+
5556
<GroupBox Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ExtractInterface_InstancingGroupBox}"
5657
Grid.Row="1" Margin="5" Padding="5">
57-
<StackPanel Orientation="Vertical">
58-
<RadioButton Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ExtractInterface_PrivateRadioButton}"
59-
IsEnabled="{Binding IsPrivateInterfaceEnabled}"
60-
IsChecked="{Binding IsPublicInterfaceChecked, Converter={StaticResource InvertBool}}" />
61-
<RadioButton Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ExtractInterface_PublicNotCreatableRadioButton}"
62-
IsChecked="{Binding IsPublicInterfaceChecked, Mode=TwoWay}" />
63-
</StackPanel>
58+
<Grid>
59+
<ComboBox ItemsSource="{Binding ClassInstances}"
60+
SelectedValue="{Binding InterfaceInstancing, Mode=TwoWay}"
61+
Visibility="{Binding IsClassInstancingMutable, Converter={StaticResource BoolToVisibility}}">
62+
</ComboBox>
63+
<Label Visibility="{Binding IsClassInstancingMutable, Converter={StaticResource BoolToHiddenVisibility}}"
64+
Content="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ExtractInterface_PublicInstancingMandatedByPublicClass}" />
65+
</Grid>
6466
</GroupBox>
6567

6668
<GroupBox Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=ExtractInterface_MembersGroupBox}"

Rubberduck.Core/UI/Refactorings/ExtractInterface/ExtractInterfaceViewModel.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,29 @@ public bool IsValidInterfaceName
6161
}
6262
}
6363

64-
public bool IsPrivateInterfaceEnabled
64+
public bool IsClassInstancingMutable
6565
{
6666
get
6767
{
68-
return Model.ImplementingClassInstancing != ClassInstancing.PublicNotCreatable;
68+
return Model.ImplementingClassInstancing != ClassInstancing.Public;
69+
}
70+
}
71+
72+
public IEnumerable<ClassInstancing> ClassInstances => Enum.GetValues(typeof(ClassInstancing)).Cast<ClassInstancing>();
73+
74+
public ClassInstancing InterfaceInstancing
75+
{
76+
get => Model.InterfaceInstancing;
77+
78+
set
79+
{
80+
if (value == Model.InterfaceInstancing)
81+
{
82+
return;
83+
}
84+
85+
Model.InterfaceInstancing = value;
86+
OnPropertyChanged();
6987
}
7088
}
7189

@@ -81,7 +99,7 @@ public bool IsPublicInterfaceChecked
8199
}
82100

83101
Model.InterfaceInstancing = value
84-
? ClassInstancing.PublicNotCreatable
102+
? ClassInstancing.Public
85103
: ClassInstancing.Private;
86104
isPublicInterfaceChecked = value;
87105
OnPropertyChanged();

Rubberduck.Refactorings/ExtractInterface/ExtractInterfaceModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace Rubberduck.Refactorings.ExtractInterface
88
{
99
public enum ClassInstancing
1010
{
11-
Private = 0,
12-
PublicNotCreatable,
11+
Public = 0,
12+
Private
1313
}
1414

1515
public class ExtractInterfaceModel : IRefactoringModel
@@ -21,9 +21,9 @@ public class ExtractInterfaceModel : IRefactoringModel
2121
public ObservableCollection<InterfaceMember> Members { get; set; } = new ObservableCollection<InterfaceMember>();
2222
public IEnumerable<InterfaceMember> SelectedMembers => Members.Where(m => m.IsSelected);
2323
public ClassInstancing ImplementingClassInstancing => System.Convert.ToBoolean(TargetDeclaration.Attributes.ExposedAttribute.Values.First())
24-
? ClassInstancing.PublicNotCreatable
24+
? ClassInstancing.Public
2525
: ClassInstancing.Private;
26-
public ClassInstancing InterfaceInstancing { get; set; } = ClassInstancing.PublicNotCreatable;
26+
public ClassInstancing InterfaceInstancing { get; set; } = ClassInstancing.Public;
2727

2828
public static readonly DeclarationType[] MemberTypes =
2929
{

Rubberduck.Refactorings/ExtractInterface/ExtractInterfaceRefactoring.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private void AddInterfaceClass(Declaration implementingClass, string interfaceNa
136136
interfaceModule.InsertLines(1, "'@Interface");
137137
interfaceModule.InsertLines(4, interfaceBody);
138138

139-
if (interfaceInstancing == ClassInstancing.PublicNotCreatable)
139+
if (interfaceInstancing == ClassInstancing.Public)
140140
{
141141
AddExposedAttribute(components, interfaceComponent);
142142
}

Rubberduck.Resources/RubberduckUI.Designer.cs

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/RubberduckUI.resx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,10 +1782,13 @@ Import aborted.</value>
17821782
<data name="ExtractInterface_InstancingGroupBox" xml:space="preserve">
17831783
<value>Instancing</value>
17841784
</data>
1785-
<data name="ExtractInterface_PrivateRadioButton" xml:space="preserve">
1785+
<data name="ExtractInterface_Private" xml:space="preserve">
17861786
<value>Private</value>
17871787
</data>
1788-
<data name="ExtractInterface_PublicNotCreatableRadioButton" xml:space="preserve">
1789-
<value>Public (Not Creatable)</value>
1788+
<data name="ExtractInterface_Public" xml:space="preserve">
1789+
<value>Public</value>
1790+
</data>
1791+
<data name="ExtractInterface_PublicInstancingMandatedByPublicClass" xml:space="preserve">
1792+
<value>'Public' will be chosen. For private instancing make implementing class private also.</value>
17901793
</data>
17911794
</root>

0 commit comments

Comments
 (0)