Skip to content

Commit a514ec9

Browse files
committed
Dry the code explorer's menu system
1 parent cc2c6b6 commit a514ec9

File tree

1 file changed

+70
-101
lines changed

1 file changed

+70
-101
lines changed

Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 70 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,71 @@
112112
</Style.Triggers>
113113
</Style>
114114

115+
<CompositeCollection x:Key="AddModuleCommands">
116+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddTestModuleText}"
117+
Command="{Binding AddTestModuleCommand}"
118+
CommandParameter="{Binding SelectedItem}">
119+
<MenuItem.Icon>
120+
<Image Height="16" Source="{StaticResource AddTestModuleImage}" />
121+
</MenuItem.Icon>
122+
</MenuItem>
123+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddTestModuleWithStubsText}"
124+
Command="{Binding AddTestModuleWithStubsCommand}"
125+
CommandParameter="{Binding SelectedItem}">
126+
<MenuItem.Icon>
127+
<Image Height="16" Source="{StaticResource AddTestModuleImage}" />
128+
</MenuItem.Icon>
129+
</MenuItem>
130+
<Separator />
131+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddStdModuleText}"
132+
Command="{Binding AddStdModuleCommand}"
133+
CommandParameter="{Binding SelectedItem}">
134+
<MenuItem.Icon>
135+
<Image Height="16" Source="{StaticResource AddStdModuleImage}" />
136+
</MenuItem.Icon>
137+
</MenuItem>
138+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddClassModuleText}"
139+
Command="{Binding AddClassModuleCommand}"
140+
CommandParameter="{Binding SelectedItem}">
141+
<MenuItem.Icon>
142+
<Image Height="16" Source="{StaticResource AddClassModuleImage}" />
143+
</MenuItem.Icon>
144+
</MenuItem>
145+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddFormText}"
146+
Command="{Binding AddUserFormCommand}"
147+
CommandParameter="{Binding SelectedItem}">
148+
<MenuItem.Icon>
149+
<Image Height="16" Source="{StaticResource AddUserFormImage}" />
150+
</MenuItem.Icon>
151+
</MenuItem>
152+
<Separator />
153+
<MenuItem Header="Templates">
154+
<MenuItem.ItemsSource>
155+
<CompositeCollection>
156+
<CollectionContainer Collection="{Binding Source={StaticResource BuiltInTemplatesViewSource}}" />
157+
</CompositeCollection>
158+
</MenuItem.ItemsSource>
159+
<MenuItem.ItemContainerStyle>
160+
<Style TargetType="MenuItem">
161+
<Setter Property="MenuItem.Command" Value="{Binding DataContext.AddTemplateCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
162+
<Setter Property="MenuItem.Header" Value="{Binding Caption}" />
163+
<Setter Property="MenuItem.ToolTip" Value="{Binding Description}" />
164+
<Setter Property="MenuItem.CommandParameter">
165+
<Setter.Value>
166+
<MultiBinding Converter="{StaticResource TemplateCommandParameterToTuple}">
167+
<Binding Path="Name" />
168+
<Binding Path="DataContext.SelectedItem" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" />
169+
</MultiBinding>
170+
</Setter.Value>
171+
</Setter>
172+
</Style>
173+
</MenuItem.ItemContainerStyle>
174+
<MenuItem.Icon>
175+
<Image Height="16" Source="{StaticResource AddClassModuleImage}" />
176+
</MenuItem.Icon>
177+
</MenuItem>
178+
</CompositeCollection>
179+
115180
<HierarchicalDataTemplate x:Key="CodeExplorerTemplate"
116181
DataType="codeExplorer:CodeExplorerProjectViewModel"
117182
ItemsSource="{Binding Items}">
@@ -155,72 +220,11 @@
155220
Command="{Binding OpenProjectPropertiesCommand}"
156221
CommandParameter="{Binding SelectedItem}" />
157222
<Separator />
158-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddModule}">
223+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddModule}"
224+
ItemsSource="{StaticResource AddModuleCommands}">
159225
<MenuItem.Icon>
160226
<Image Height="16" Source="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/plus-circle.png" />
161227
</MenuItem.Icon>
162-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddTestModuleText}"
163-
Command="{Binding AddTestModuleCommand}"
164-
CommandParameter="{Binding SelectedItem}">
165-
<MenuItem.Icon>
166-
<Image Height="16" Source="{StaticResource AddTestModuleImage}" />
167-
</MenuItem.Icon>
168-
</MenuItem>
169-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddTestModuleWithStubsText}"
170-
Command="{Binding AddTestModuleWithStubsCommand}"
171-
CommandParameter="{Binding SelectedItem}">
172-
<MenuItem.Icon>
173-
<Image Height="16" Source="{StaticResource AddTestModuleImage}" />
174-
</MenuItem.Icon>
175-
</MenuItem>
176-
<Separator />
177-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddStdModuleText}"
178-
Command="{Binding AddStdModuleCommand}"
179-
CommandParameter="{Binding SelectedItem}">
180-
<MenuItem.Icon>
181-
<Image Height="16" Source="{StaticResource AddStdModuleImage}" />
182-
</MenuItem.Icon>
183-
</MenuItem>
184-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddClassModuleText}"
185-
Command="{Binding AddClassModuleCommand}"
186-
CommandParameter="{Binding SelectedItem}">
187-
<MenuItem.Icon>
188-
<Image Height="16" Source="{StaticResource AddClassModuleImage}" />
189-
</MenuItem.Icon>
190-
</MenuItem>
191-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddFormText}"
192-
Command="{Binding AddUserFormCommand}"
193-
CommandParameter="{Binding SelectedItem}">
194-
<MenuItem.Icon>
195-
<Image Height="16" Source="{StaticResource AddUserFormImage}" />
196-
</MenuItem.Icon>
197-
</MenuItem>
198-
<Separator />
199-
<MenuItem Header="Templates">
200-
<MenuItem.ItemsSource>
201-
<CompositeCollection>
202-
<CollectionContainer Collection="{Binding Source={StaticResource BuiltInTemplatesViewSource}}" />
203-
</CompositeCollection>
204-
</MenuItem.ItemsSource>
205-
<MenuItem.ItemContainerStyle>
206-
<Style TargetType="MenuItem">
207-
<Setter Property="MenuItem.Command" Value="{Binding DataContext.AddTemplateCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
208-
<Setter Property="MenuItem.Header" Value="{Binding Caption}" />
209-
<Setter Property="MenuItem.ToolTip" Value="{Binding Description}" />
210-
<Setter Property="MenuItem.CommandParameter">
211-
<Setter.Value>
212-
<MultiBinding Converter="{StaticResource TemplateCommandParameterToTuple}">
213-
<Binding Path="Name" />
214-
<Binding Path="DataContext.SelectedItem" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" />
215-
</MultiBinding>
216-
</Setter.Value>
217-
</Setter>
218-
</Style>
219-
</MenuItem.ItemContainerStyle>
220-
<MenuItem.Icon>
221-
<Image Height="16" Source="{StaticResource AddClassModuleImage}" />
222-
</MenuItem.Icon>
223-
</MenuItem>
224228
</MenuItem>
225229
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=Find}">
226230
<MenuItem.Icon>
@@ -392,47 +396,12 @@
392396
<Separator />
393397

394398
<Menu>
395-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Add}" VerticalContentAlignment="Center">
399+
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_Add}"
400+
ItemsSource="{StaticResource AddModuleCommands}"
401+
VerticalContentAlignment="Center">
396402
<MenuItem.Icon>
397403
<Image Height="16" Source="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/plus-circle.png" />
398404
</MenuItem.Icon>
399-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddTestModuleText}"
400-
Command="{Binding AddTestModuleCommand}"
401-
CommandParameter="{Binding SelectedItem}">
402-
<MenuItem.Icon>
403-
<Image Height="16" Source="{StaticResource AddTestModuleImage}" />
404-
</MenuItem.Icon>
405-
</MenuItem>
406-
<Separator />
407-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddStdModuleText}"
408-
Command="{Binding AddStdModuleCommand}"
409-
CommandParameter="{Binding SelectedItem}">
410-
<MenuItem.Icon>
411-
<Image Height="16" Source="{StaticResource AddStdModuleImage}" />
412-
</MenuItem.Icon>
413-
</MenuItem>
414-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddClassModuleText}"
415-
Command="{Binding AddClassModuleCommand}"
416-
CommandParameter="{Binding SelectedItem}">
417-
<MenuItem.Icon>
418-
<Image Height="16" Source="{StaticResource AddClassModuleImage}" />
419-
</MenuItem.Icon>
420-
</MenuItem>
421-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddFormText}"
422-
Command="{Binding AddUserFormCommand}"
423-
CommandParameter="{Binding SelectedItem}">
424-
<MenuItem.Icon>
425-
<Image Height="16" Source="{StaticResource AddUserFormImage}" />
426-
</MenuItem.Icon>
427-
</MenuItem>
428-
<Separator />
429-
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddPredeclaredClassModuleText}"
430-
Command="{Binding AddPredeclaredClassModuleCommand}"
431-
CommandParameter="{Binding SelectedItem}">
432-
<MenuItem.Icon>
433-
<Image Height="16" Source="{StaticResource AddClassModuleImage}" />
434-
</MenuItem.Icon>
435-
</MenuItem>
436405
</MenuItem>
437406
</Menu>
438407

0 commit comments

Comments
 (0)