Skip to content

Commit cad72f7

Browse files
authored
Merge pull request #1860 from Hosch250/Issue1616
Code Explorer Enhancements
2 parents 6b7f1d7 + 7eed583 commit cad72f7

File tree

4 files changed

+77
-47
lines changed

4 files changed

+77
-47
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerItemViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ protected set
164164
}
165165

166166
public bool IsExpanded { get; set; }
167+
public bool IsSelected { get; set; }
167168

168169
public abstract string Name { get; }
169170
public abstract string NameWithSignature { get; }

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ private void FillFolders(IEnumerable<Declaration> declarations)
5353
.GroupBy(item => item.CustomFolder)
5454
.OrderBy(item => item.Key);
5555

56+
// set parent so we can walk up to the project node
57+
// we haven't added the nodes yet, so this cast is valid
58+
// ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
59+
foreach (CodeExplorerCustomFolderViewModel item in _folderTree.Items)
60+
{
61+
item.SetParent(this);
62+
}
63+
5664
foreach (var grouping in groupedItems)
5765
{
5866
AddNodesToTree(_folderTree, items, grouping);
@@ -68,11 +76,6 @@ private bool AddNodesToTree(CodeExplorerCustomFolderViewModel tree, List<Declara
6876
continue;
6977
}
7078

71-
if (folder.Parent.Name == string.Empty)
72-
{
73-
folder.SetParent(this);
74-
}
75-
7679
var parents = grouping.Where(
7780
item => ComponentTypes.Contains(item.DeclarationType) &&
7881
item.CustomFolder.Replace("\"", string.Empty) == folder.FullPath)

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,23 @@ public ObservableCollection<CodeExplorerItemViewModel> Projects
244244
}
245245
}
246246

247+
private Declaration FindNewProjectDeclaration(string id)
248+
{
249+
return _state.AllUserDeclarations.SingleOrDefault(item =>
250+
item.ProjectId == id &&
251+
item.DeclarationType == DeclarationType.Project);
252+
}
253+
254+
private Declaration FindNewDeclaration(Declaration declaration)
255+
{
256+
return _state.AllUserDeclarations.SingleOrDefault(item =>
257+
item.ProjectId == declaration.ProjectId &&
258+
item.ComponentName == declaration.ComponentName &&
259+
item.ParentScope == declaration.ParentScope &&
260+
item.IdentifierName == declaration.IdentifierName &&
261+
item.DeclarationType == declaration.DeclarationType);
262+
}
263+
247264
private void ParserState_StateChanged(object sender, ParserStateEventArgs e)
248265
{
249266
if (Projects == null)
@@ -274,7 +291,7 @@ private void ParserState_StateChanged(object sender, ParserStateEventArgs e)
274291
grouping)).ToList();
275292

276293
UpdateNodes(Projects, newProjects);
277-
294+
278295
Projects = new ObservableCollection<CodeExplorerItemViewModel>(newProjects);
279296
}
280297

@@ -303,6 +320,7 @@ private void UpdateNodes(IEnumerable<CodeExplorerItemViewModel> oldList,
303320
if (oldItem != null)
304321
{
305322
item.IsExpanded = oldItem.IsExpanded;
323+
item.IsSelected = oldItem.IsSelected;
306324

307325
if (oldItem.Items.Any() && item.Items.Any())
308326
{

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<BitmapImage x:Key="RefreshImage" UriSource="../../Resources/arrow-circle-double.png" />
1818
<BitmapImage x:Key="UndoImage" UriSource="../../Resources/arrow-circle-left.png" />
1919
<BitmapImage x:Key="PrintImage" UriSource="../../Resources/printer.png" />
20-
20+
2121
<BooleanToVisibilityConverter x:Key="BoolToVisibility"/>
2222
<converters:BoolToHiddenVisibilityConverter x:Key="BoolToHiddenVisibility" />
2323
<converters:InvertBoolValueConverter x:Key="InvertBoolValue" />
@@ -255,7 +255,7 @@
255255
</Trigger>
256256
</Style.Triggers>
257257
</Style>
258-
258+
259259
<LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" EndPoint="0,1" StartPoint="0,0">
260260
<GradientStop Color="#FFD9F4FF" Offset="0"/>
261261
<GradientStop Color="#FF9BDDFB" Offset="1"/>
@@ -271,6 +271,7 @@
271271
TargetType="{x:Type TreeViewItem}">
272272
<Setter Property="BorderThickness" Value="1.5"/>
273273
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
274+
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
274275
<Setter Property="HorizontalAlignment" Value="Left" />
275276
<EventSetter Event="PreviewMouseRightButtonDown" Handler="OnPreviewMouseRightButtonDown" />
276277
<Style.Triggers>
@@ -291,16 +292,17 @@
291292
</Style>
292293
</Style.Resources>
293294
</Style>
294-
295+
295296
<Style x:Key="IconStyle" TargetType="Image">
296297
<Setter Property="Height" Value="16" />
297298
<Setter Property="Width" Value="16" />
298299
<Setter Property="Margin" Value="2,0,2,0" />
299300
<Setter Property="VerticalAlignment" Value="Top" />
300301
</Style>
301-
302+
302303
<Style x:Key="TreeViewItemStyle" TargetType="TextBlock">
303304
<Setter Property="Text" Value="{Binding Name}" />
305+
<Setter Property="FontSize" Value="10" />
304306
<Setter Property="MaxWidth" Value="200" />
305307
<Setter Property="Margin" Value="2,0,2,0" />
306308
<Setter Property="VerticalAlignment" Value="Center" />
@@ -311,6 +313,7 @@
311313

312314
<Style x:Key="TreeViewItemStyleWithSignatures" TargetType="TextBlock">
313315
<Setter Property="Text" Value="{Binding NameWithSignature}" />
316+
<Setter Property="FontSize" Value="10" />
314317
<Setter Property="MaxWidth" Value="200" />
315318
<Setter Property="Margin" Value="2,0,2,0" />
316319
<Setter Property="VerticalAlignment" Value="Center" />
@@ -337,7 +340,7 @@
337340
<TextBlock Style="{StaticResource TreeViewItemStyleWithSignatures}" Visibility="{Binding ElementName=DisplaySignatures, Path=IsChecked, Converter={StaticResource BoolToVisibility}}" />
338341
</StackPanel>
339342
</HierarchicalDataTemplate>
340-
343+
341344
<HierarchicalDataTemplate x:Key="CodeExplorerTemplate"
342345
DataType="codeExplorer:CodeExplorerProjectViewModel"
343346
ItemsSource="{Binding Items}">
@@ -681,9 +684,9 @@
681684
Command="{Binding SetSelectionSortCommand}"
682685
CommandParameter="{Binding ElementName=SortBySelection, Path=IsChecked}"
683686
IsCheckable="True" />
684-
687+
685688
<Separator />
686-
689+
687690
<MenuItem Style="{DynamicResource MenuItemStyle}" VerticalAlignment="Center"
688691
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SortStyle_ByType}"
689692
IsChecked="{Binding SortByType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
@@ -695,7 +698,7 @@
695698
</ToggleButton>
696699

697700
<Separator />
698-
701+
699702
<Button Command="{Binding OpenDesignerCommand}" CommandParameter="{Binding SelectedItem}">
700703
<Image Height="16" Source="../../Resources/Microsoft/PNG/VSProject_form.png" />
701704
<Button.ToolTip>
@@ -734,39 +737,44 @@
734737

735738
<Border Grid.Row="3" BorderThickness="0,1,0,0" BorderBrush="DimGray">
736739

737-
<StackPanel Orientation="Vertical" MinHeight="48" Background="WhiteSmoke">
738-
739-
<Grid Margin="4" HorizontalAlignment="Stretch">
740-
<Grid.ColumnDefinitions>
741-
<ColumnDefinition Width="20" />
742-
<ColumnDefinition />
743-
</Grid.ColumnDefinitions>
744-
<Image Style="{StaticResource IconStyle}" VerticalAlignment="Top"
745-
Source="{Binding SelectedItem.CollapsedIcon}" Grid.Column="0"/>
746-
<TextBlock Margin="4" Text="{Binding PanelTitle}" FontWeight="Bold"
747-
TextWrapping="WrapWithOverflow" Grid.Column="1"/>
748-
</Grid>
749-
750-
<TextBlock Margin="4" Text="{Binding Description}" FontSize="10" TextWrapping="WrapWithOverflow"/>
751-
752-
<WrapPanel>
753-
<controls:LinkButton Margin="4"
754-
Visibility="{Binding CanExecuteIndenterCommand, Converter={StaticResource BoolToVisibility}, UpdateSourceTrigger=PropertyChanged}"
755-
Command="{Binding IndenterCommand}"
756-
CommandParameter="{Binding SelectedItem}"
757-
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SmartIndenterMenu}" />
758-
<controls:LinkButton Margin="4"
759-
Visibility="{Binding CanExecuteRenameCommand, Converter={StaticResource BoolToVisibility}}"
760-
Command="{Binding RenameCommand}"
761-
CommandParameter="{Binding SelectedItem}"
762-
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Rename}" />
763-
<controls:LinkButton Margin="4"
764-
Visibility="{Binding CanExecuteFindAllReferencesCommand, Converter={StaticResource BoolToVisibility}}"
765-
Command="{Binding FindAllReferencesCommand}"
766-
CommandParameter="{Binding SelectedItem}"
767-
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_FindAllReferencesText}" />
768-
</WrapPanel>
769-
</StackPanel>
740+
<ScrollViewer Background="WhiteSmoke" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
741+
<StackPanel Orientation="Vertical" MinHeight="48" Background="WhiteSmoke">
742+
743+
<Grid Margin="4" HorizontalAlignment="Stretch">
744+
<Grid.ColumnDefinitions>
745+
<ColumnDefinition Width="20" />
746+
<ColumnDefinition />
747+
</Grid.ColumnDefinitions>
748+
<Image Style="{StaticResource IconStyle}"
749+
Source="{Binding SelectedItem.CollapsedIcon}" Grid.Column="0"/>
750+
<TextBox IsReadOnly="True" Margin="4" Text="{Binding PanelTitle, Mode=OneWay}" FontWeight="Bold"
751+
TextWrapping="WrapWithOverflow" Grid.Column="1" FontSize="10"
752+
Background="WhiteSmoke" BorderThickness="0" Foreground="Black" />
753+
</Grid>
754+
755+
<TextBox IsReadOnly="True" Margin="4" Text="{Binding Description, Mode=OneWay}"
756+
BorderThickness="0" Background="WhiteSmoke" Foreground="Black"
757+
FontSize="10" TextWrapping="WrapWithOverflow" />
758+
759+
<WrapPanel>
760+
<controls:LinkButton Margin="4"
761+
Visibility="{Binding CanExecuteIndenterCommand, Converter={StaticResource BoolToVisibility}, UpdateSourceTrigger=PropertyChanged}"
762+
Command="{Binding IndenterCommand}"
763+
CommandParameter="{Binding SelectedItem}"
764+
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SmartIndenterMenu}" />
765+
<controls:LinkButton Margin="4"
766+
Visibility="{Binding CanExecuteRenameCommand, Converter={StaticResource BoolToVisibility}}"
767+
Command="{Binding RenameCommand}"
768+
CommandParameter="{Binding SelectedItem}"
769+
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Rename}" />
770+
<controls:LinkButton Margin="4"
771+
Visibility="{Binding CanExecuteFindAllReferencesCommand, Converter={StaticResource BoolToVisibility}}"
772+
Command="{Binding FindAllReferencesCommand}"
773+
CommandParameter="{Binding SelectedItem}"
774+
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_FindAllReferencesText}" />
775+
</WrapPanel>
776+
</StackPanel>
777+
</ScrollViewer>
770778
</Border>
771779
</Grid>
772780
</UserControl>

0 commit comments

Comments
 (0)