Skip to content

Commit 03971e8

Browse files
committed
Add x to search box
1 parent a43964e commit 03971e8

File tree

5 files changed

+109
-3
lines changed

5 files changed

+109
-3
lines changed

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@
405405
<Compile Include="UI\CodeExplorer\Commands\CommitCommand.cs" />
406406
<Compile Include="UI\CodeExplorer\Commands\AddUserFormCommand.cs" />
407407
<Compile Include="UI\CodeExplorer\Commands\CopyResultsCommand.cs" />
408+
<Compile Include="UI\CodeExplorer\Converters\StringHasNoValueToVisibilityConverter.cs" />
409+
<Compile Include="UI\CodeExplorer\Converters\StringHasValueToVisibilityConverter.cs" />
408410
<Compile Include="UI\Command\ExportAllCommand.cs" />
409411
<Compile Include="UI\CodeExplorer\Commands\OpenProjectPropertiesCommand.cs" />
410412
<Compile Include="UI\CodeExplorer\Commands\RenameCommand.cs" />

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
xmlns:controls="clr-namespace:Rubberduck.UI.Controls"
99
xmlns:themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
1010
xmlns:converters="clr-namespace:Rubberduck.UI.Converters"
11+
xmlns:codeExplorerConverters="clr-namespace:Rubberduck.UI.CodeExplorer.Converters"
1112
ResxExtension.DefaultResxName="Rubberduck.UI.RubberduckUI"
1213
Language="{UICulture}"
1314
Name="CodeExplorer"
@@ -32,6 +33,8 @@
3233

3334
<BooleanToVisibilityConverter x:Key="BoolToVisibility"/>
3435
<converters:BoolToHiddenVisibilityConverter x:Key="BoolToHiddenVisibility" />
36+
<codeExplorerConverters:StringHasValueToVisibilityConverter x:Key="StringHasValueToVisibility" />
37+
<codeExplorerConverters:StringHasNoValueToVisibilityConverter x:Key="StringHasNoValueToVisibility" />
3538

3639
<LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" EndPoint="0,1" StartPoint="0,0">
3740
<GradientStop Color="#FFD9F4FF" Offset="0"/>
@@ -286,6 +289,59 @@
286289
</Setter>
287290
</Style>
288291

292+
<Style x:Key="XButtonStyle" TargetType="Button">
293+
<Setter Property="Background" Value="Transparent"/>
294+
<Setter Property="BorderThickness" Value="0"/>
295+
<Setter Property="HorizontalContentAlignment" Value="Center"/>
296+
<Setter Property="VerticalContentAlignment" Value="Center"/>
297+
<Setter Property="Template">
298+
<Setter.Value>
299+
<ControlTemplate TargetType="Button">
300+
<Grid>
301+
<VisualStateManager.VisualStateGroups>
302+
<VisualStateGroup x:Name="CommonStates">
303+
<VisualState x:Name="Normal"/>
304+
<VisualState x:Name="MouseOver">
305+
<Storyboard>
306+
<ColorAnimation Duration="0" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="PaleGoldenrod"/>
307+
<DoubleAnimation Duration="0" Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="Opacity" To="1"/>
308+
</Storyboard>
309+
</VisualState>
310+
<VisualState x:Name="Pressed">
311+
<Storyboard>
312+
<ColorAnimation Duration="0" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="PaleGoldenrod"/>
313+
<DoubleAnimation Duration="0" Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="Opacity" To="1"/>
314+
</Storyboard>
315+
</VisualState>
316+
</VisualStateGroup>
317+
<VisualStateGroup x:Name="FocusStates">
318+
<VisualState x:Name="Focused">
319+
<Storyboard>
320+
<DoubleAnimation Duration="0" Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" To="1"/>
321+
</Storyboard>
322+
</VisualState>
323+
<VisualState x:Name="Unfocused" />
324+
</VisualStateGroup>
325+
</VisualStateManager.VisualStateGroups>
326+
<Border x:Name="Background" CornerRadius="3" Background="White" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
327+
<Grid Background="{TemplateBinding Background}" Margin="1">
328+
<Border Opacity="0" x:Name="BackgroundAnimation" Background="PaleGoldenrod" />
329+
</Grid>
330+
</Border>
331+
<ContentPresenter
332+
x:Name="contentPresenter"
333+
Content="{TemplateBinding Content}"
334+
ContentTemplate="{TemplateBinding ContentTemplate}"
335+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
336+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
337+
Margin="{TemplateBinding Padding}"/>
338+
<Rectangle x:Name="DisabledVisualElement" RadiusX="3" RadiusY="3" Fill="#FFFFFFFF" Opacity="0" IsHitTestVisible="false" />
339+
<Rectangle x:Name="FocusVisualElement" RadiusX="2" RadiusY="2" Margin="1" Stroke="PaleGoldenrod" StrokeThickness="1" Opacity="0" IsHitTestVisible="false" />
340+
</Grid>
341+
</ControlTemplate>
342+
</Setter.Value>
343+
</Setter>
344+
</Style>
289345
</ResourceDictionary>
290346
</UserControl.Resources>
291347

@@ -435,8 +491,9 @@
435491
</ToolBarTray>
436492

437493
<TextBox Grid.Row="1" TextChanged="SearchBox_OnTextChanged" VerticalContentAlignment="Center" Name="SearchBox"></TextBox>
438-
<Image Grid.Row="1" Source="{StaticResource SearchImage}" HorizontalAlignment="Right" VerticalAlignment="Center" MaxHeight="16" Margin="0,0,1,0" MouseDown="SearchIcon_OnMouseDown" />
439-
494+
<Image Grid.Row="1" Source="{StaticResource SearchImage}" HorizontalAlignment="Right" VerticalAlignment="Center" MaxHeight="16" Margin="0,0,1,0" MouseDown="SearchIcon_OnMouseDown" Visibility="{Binding ElementName=SearchBox, Path=Text.Length, Converter={StaticResource StringHasValueToVisibility}}" />
495+
<Button Grid.Row="1" Style="{StaticResource XButtonStyle}" HorizontalAlignment="Right" VerticalAlignment="Center" Height="18" Width="18" Margin="0,1,1,0" Visibility="{Binding ElementName=SearchBox, Path=Text.Length, Converter={StaticResource StringHasNoValueToVisibility}}" Click="ButtonBase_OnClick">✕</Button>
496+
440497
<controls:EmptyUIRefresh Grid.Row="2" />
441498

442499
<TreeView x:Name="ProjectTree"

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows.Controls;
1+
using System.Windows;
2+
using System.Windows.Controls;
23
using System.Windows.Input;
34
using Rubberduck.Navigation.CodeExplorer;
45

@@ -40,5 +41,11 @@ private void SearchIcon_OnMouseDown(object sender, MouseButtonEventArgs e)
4041
{
4142
SearchBox.Focus();
4243
}
44+
45+
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
46+
{
47+
SearchBox.Text = string.Empty;
48+
SearchBox.Focus();
49+
}
4350
}
4451
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace Rubberduck.UI.CodeExplorer.Converters
7+
{
8+
public class StringHasNoValueToVisibilityConverter : IValueConverter
9+
{
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
return (int)value == 0 ? Visibility.Collapsed : Visibility.Visible;
13+
}
14+
15+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
16+
{
17+
throw new NotImplementedException();
18+
}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace Rubberduck.UI.CodeExplorer.Converters
7+
{
8+
public class StringHasValueToVisibilityConverter : IValueConverter
9+
{
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
return (int)value > 0 ? Visibility.Collapsed : Visibility.Visible;
13+
}
14+
15+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
16+
{
17+
throw new NotImplementedException();
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)