Skip to content

Commit 1da6bd2

Browse files
committed
Add search box to CE. Closes #3329
1 parent fed718c commit 1da6bd2

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerItemViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ public bool IsExpanded
190190

191191
public bool IsSelected { get; set; }
192192

193+
private bool _isVisisble = true;
194+
public bool IsVisible
195+
{
196+
get { return _isVisisble; }
197+
set
198+
{
199+
_isVisisble = value;
200+
OnPropertyChanged();
201+
}
202+
}
203+
193204
public abstract string Name { get; }
194205
public abstract string NameWithSignature { get; }
195206
public abstract BitmapImage CollapsedIcon { get; }

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,23 @@ public Visibility EmptyUIRefreshMessageVisibility
574574
}
575575
}
576576

577+
public void Search(IEnumerable<CodeExplorerItemViewModel> nodes, string searchString)
578+
{
579+
foreach (var item in nodes)
580+
{
581+
if (item == null) { continue; }
582+
583+
if (item.Items.Any())
584+
{
585+
Search(item.Items, searchString);
586+
}
587+
588+
item.IsVisible = item.Items.Any(c => c.IsVisible) ||
589+
item.Name.ToLowerInvariant().Contains(searchString.ToLowerInvariant()) ||
590+
string.IsNullOrEmpty(searchString);
591+
}
592+
}
593+
577594
public void Dispose()
578595
{
579596
if (_state != null)
586 Bytes
Loading

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,7 @@
12881288
<Resource Include="Resources\folder-open.png" />
12891289
<Resource Include="Resources\folder.png" />
12901290
<None Include="Resources\RD-300x250-base.png" />
1291+
<Resource Include="Resources\magnifier-medium.png" />
12911292
<Content Include="Resources\Rubberduck\RD-AboutWindow.png" />
12921293
<Content Include="Resources\Rubberduck\RD-InstallBanner.bmp" />
12931294
<Content Include="Resources\Rubberduck\RD-InstallWindow.bmp" />

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<BitmapImage x:Key="AddStdModuleImage" UriSource="../../Resources/Custom/PNG/AddModule.png" />
2929
<BitmapImage x:Key="AddClassModuleImage" UriSource="../../Resources/Custom/PNG/AddClass.png" />
3030
<BitmapImage x:Key="AddUserFormImage" UriSource="../../Resources/Custom/PNG/AddForm.png" />
31+
<BitmapImage x:Key="SearchImage" UriSource="../../Resources/magnifier-medium.png" />
3132

3233
<BooleanToVisibilityConverter x:Key="BoolToVisibility"/>
3334
<converters:BoolToHiddenVisibilityConverter x:Key="BoolToHiddenVisibility" />
@@ -48,6 +49,7 @@
4849
<Setter Property="BorderThickness" Value="1.5"/>
4950
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
5051
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
52+
<Setter Property="Visibility" Value="{Binding IsVisible, Mode=OneWay, Converter={StaticResource BoolToVisibility}}" />
5153
<Setter Property="HorizontalAlignment" Value="Left" />
5254
<EventSetter Event="MouseDoubleClick" Handler="TreeView_OnMouseDoubleClick" />
5355
<EventSetter Event="MouseRightButtonDown" Handler="TreeView_OnMouseRightButtonDown" />
@@ -283,6 +285,7 @@
283285
<Grid UseLayoutRounding="True">
284286
<Grid.RowDefinitions>
285287
<RowDefinition Height="30"/>
288+
<RowDefinition Height="20"/>
286289
<RowDefinition Height="*" MinHeight="64" />
287290
<RowDefinition Height="5"/>
288291
<RowDefinition Height="Auto" MinHeight="48"/>
@@ -424,10 +427,13 @@
424427
</ToolBar>
425428
</ToolBarTray>
426429

427-
<controls:EmptyUIRefresh Grid.Row="1" />
430+
<TextBox Grid.Row="1" TextChanged="SearchBox_OnTextChanged" VerticalContentAlignment="Center" Name="SearchBox"></TextBox>
431+
<Image Grid.Row="1" Source="{StaticResource SearchImage}" HorizontalAlignment="Right" VerticalAlignment="Center" MaxHeight="16" Margin="0,0,1,0" MouseDown="SearchIcon_OnMouseDown" />
432+
433+
<controls:EmptyUIRefresh Grid.Row="2" />
428434

429435
<TreeView x:Name="ProjectTree"
430-
Grid.Row="1"
436+
Grid.Row="2"
431437
Background="White"
432438
ItemContainerStyle="{StaticResource ShinyTreeView}"
433439
HorizontalContentAlignment="Stretch"
@@ -439,11 +445,11 @@
439445
</i:Interaction.Behaviors>
440446
</TreeView>
441447

442-
<controls:BusyIndicator Grid.Row="1" Width="120" Height="120" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibility}}" />
448+
<controls:BusyIndicator Grid.Row="2" Width="120" Height="120" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibility}}" />
443449

444-
<GridSplitter Grid.Row="2" Height="5" ShowsPreview="True" Cursor="SizeNS" HorizontalAlignment="Stretch"/>
450+
<GridSplitter Grid.Row="3" Height="5" ShowsPreview="True" Cursor="SizeNS" HorizontalAlignment="Stretch"/>
445451

446-
<Border Grid.Row="3" BorderThickness="0,1,0,0" BorderBrush="DimGray">
452+
<Border Grid.Row="4" BorderThickness="0,1,0,0" BorderBrush="DimGray">
447453

448454
<ScrollViewer Background="WhiteSmoke" VerticalScrollBarVisibility="Auto">
449455
<WrapPanel Orientation="Vertical" MinHeight="70" Background="WhiteSmoke">

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,15 @@ private void TreeView_OnMouseRightButtonDown(object sender, MouseButtonEventArgs
3030
((TreeViewItem)sender).IsSelected = true;
3131
e.Handled = true;
3232
}
33+
34+
private void SearchBox_OnTextChanged(object sender, TextChangedEventArgs e)
35+
{
36+
ViewModel.Search(ViewModel.Projects, ((TextBox)sender).Text);
37+
}
38+
39+
private void SearchIcon_OnMouseDown(object sender, MouseButtonEventArgs e)
40+
{
41+
SearchBox.Focus();
42+
}
3343
}
3444
}

0 commit comments

Comments
 (0)