Browse Source

Add SearchBox with icons.

pull/1/head
Eusebiu Marcu 14 years ago
parent
commit
df71f32ffa
  1. 121
      ILSpy/Controls/SearchBox.cs
  2. 70
      ILSpy/Controls/SearchBoxStyle.xaml
  3. 7
      ILSpy/ILSpy.csproj
  4. BIN
      ILSpy/Images/ClearSearch.png
  5. BIN
      ILSpy/Images/Search.png
  6. 12
      ILSpy/MainWindow.xaml

121
ILSpy/Controls/SearchBox.cs

@ -0,0 +1,121 @@ @@ -0,0 +1,121 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace ICSharpCode.ILSpy.Controls
{
public class SearchBox : TextBox
{
static SearchBox() {
DefaultStyleKeyProperty.OverrideMetadata(
typeof(SearchBox),
new FrameworkPropertyMetadata(typeof(SearchBox)));
}
#region Dependency properties
public static DependencyProperty WatermarkTextProperty = DependencyProperty.Register("WatermarkText", typeof(string), typeof(SearchBox));
public static DependencyProperty WatermarkColorProperty = DependencyProperty.Register("WatermarkColor", typeof(Brush), typeof(SearchBox));
public static DependencyProperty HasTextProperty = DependencyProperty.Register("HasText", typeof(bool), typeof(SearchBox));
#endregion
#region Public Properties
public string WatermarkText {
get { return (string)GetValue(WatermarkTextProperty); }
set { SetValue(WatermarkTextProperty, value); }
}
public Brush WatermarkColor {
get { return (Brush)GetValue(WatermarkColorProperty); }
set { SetValue(WatermarkColorProperty, value); }
}
public bool HasText {
get { return (bool)GetValue(HasTextProperty); }
private set { SetValue(HasTextProperty, value); }
}
#endregion
#region Handlers
private void IconBorder_MouseLeftButtonUp(object obj, MouseButtonEventArgs e) {
if (this.HasText)
this.Text = string.Empty;
}
#endregion
#region Overrides
protected override void OnTextChanged(TextChangedEventArgs e) {
base.OnTextChanged(e);
HasText = this.Text.Length > 0;
}
protected override void OnLostFocus(RoutedEventArgs e)
{
if (!HasText) {
Label wl = (Label)GetTemplateChild("WatermarkLabel");
wl.Visibility = Visibility.Visible;
}
base.OnLostFocus(e);
}
protected override void OnGotFocus(RoutedEventArgs e)
{
if (!HasText) {
Label wl = (Label)GetTemplateChild("WatermarkLabel");
wl.Visibility = Visibility.Hidden;
}
base.OnGotFocus(e);
}
public override void OnApplyTemplate() {
base.OnApplyTemplate();
Border iconBorder = GetTemplateChild("PART_IconBorder") as Border;
if (iconBorder != null) {
iconBorder.MouseLeftButtonUp += IconBorder_MouseLeftButtonUp;
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Escape) {
this.Text = string.Empty;
} else {
base.OnKeyDown(e);
}
}
#endregion
}
}

70
ILSpy/Controls/SearchBoxStyle.xaml

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.ILSpy.Controls">
<Style x:Key="{x:Type local:SearchBox}" TargetType="{x:Type local:SearchBox}">
<Setter Property="Background" Value="White" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:SearchBox}">
<Border x:Name="Border"
Cursor="IBeam"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid x:Name="LayoutGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualHeight}" />
</Grid.ColumnDefinitions>
<ScrollViewer Margin="2" x:Name="PART_ContentHost" Grid.Column="0" />
<Label x:Name="WatermarkLabel"
Margin="2"
Grid.Column="0"
Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=WatermarkColor}"
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=WatermarkText}"
Padding="2,0,0,0"
FontStyle="Italic" />
<Border x:Name="PART_IconBorder"
Grid.Column="1"
BorderThickness="1"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
BorderBrush="Transparent"
Background="Transparent">
<Image x:Name="SearchIcon"
Cursor="Arrow"
Stretch="None"
Width="12"
Height="12"
HorizontalAlignment="Center"
VerticalAlignment="Center"
ToolTip="Search"
Source="pack://application:,,,/ILSpy;component/images/search.png" />
</Border>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="HasText" Value="True">
<Setter Property="Visibility" TargetName="WatermarkLabel" Value="Hidden" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="HasText" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Source"
TargetName="SearchIcon"
Value="pack://application:,,,/ILSpy;component/images/clearsearch.png" />
<Setter Property="ToolTip" TargetName="SearchIcon" Value="Clear"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

7
ILSpy/ILSpy.csproj

@ -79,6 +79,7 @@ @@ -79,6 +79,7 @@
</Compile>
<Compile Include="AssemblyList.cs" />
<Compile Include="AssemblyListManager.cs" />
<Compile Include="Controls\SearchBox.cs" />
<Compile Include="CSharpLanguage.cs" />
<Compile Include="CueBannerService.cs" />
<Compile Include="DecompilationOptions.cs" />
@ -106,6 +107,8 @@ @@ -106,6 +107,8 @@
<Resource Include="Images\ViewCode.png" />
<Resource Include="Images\SaveFile.png" />
<Resource Include="Images\OK.png" />
<Resource Include="Images\ClearSearch.png" />
<Resource Include="Images\Search.png" />
<None Include="Properties\AssemblyInfo.template.cs" />
<Compile Include="Properties\WPFAssemblyInfo.cs" />
<Compile Include="MainWindow.xaml.cs">
@ -137,6 +140,9 @@ @@ -137,6 +140,9 @@
<EmbeddedResource Include="TextView\ILAsm-Mode.xshd" />
</ItemGroup>
<ItemGroup>
<Page Include="Controls\SearchBoxStyle.xaml">
<DependentUpon>SearchBox.cs</DependentUpon>
</Page>
<Page Include="MainWindow.xaml" />
<Page Include="OpenFromGacDialog.xaml" />
<Page Include="TextView\DecompilerTextView.xaml">
@ -207,6 +213,7 @@ @@ -207,6 +213,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Controls" />
<Folder Include="TreeNodes" />
<Folder Include="TextView" />
</ItemGroup>

BIN
ILSpy/Images/ClearSearch.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
ILSpy/Images/Search.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 B

12
ILSpy/MainWindow.xaml

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
x:ClassModifier="internal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:tv="clr-namespace:ICSharpCode.TreeView;assembly=ICSharpCode.TreeView"
xmlns:local="clr-namespace:ICSharpCode.ILSpy" xmlns:textView="clr-namespace:ICSharpCode.ILSpy.TextView"
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
Title="ILSpy"
MinWidth="250"
MinHeight="200"
@ -11,6 +12,13 @@ @@ -11,6 +12,13 @@
TextOptions.TextFormattingMode="Display"
FocusManager.FocusedElement="{Binding ElementName=treeView}"
>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Controls/SearchBoxStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding
Command="Open"
@ -103,7 +111,9 @@ @@ -103,7 +111,9 @@
</Grid.RowDefinitions>
<!-- Left pane: Search bar + Tree View -->
<DockPanel>
<TextBox DockPanel.Dock="Top" local:CueBannerService.CueBanner=" Search" Text="{Binding FilterSettings.SearchTerm, UpdateSourceTrigger=PropertyChanged}" />
<!-- Search bar -->
<controls:SearchBox DockPanel.Dock="Top" WatermarkText="Search" WatermarkColor="Gray" ToolTip="Search"
Text="{Binding FilterSettings.SearchTerm, UpdateSourceTrigger=PropertyChanged}" />
<!-- Tree View of assemblies and classes -->
<tv:SharpTreeView
Name="treeView"

Loading…
Cancel
Save