Skip to content

Commit

Permalink
Merge pull request #3 from paulcbetts/haacked/add-filtering
Browse files Browse the repository at this point in the history
Add ability to filter keys
  • Loading branch information
Paul Betts committed Jul 19, 2014
2 parents 8a85f61 + a1908c4 commit d2f72fa
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 10 deletions.
6 changes: 5 additions & 1 deletion AkavacheExplorer/AkavacheExplorer.csproj
Expand Up @@ -119,6 +119,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Controls\PromptTextBox.cs" />
<Compile Include="Models\ReadonlyAkavacheCache.cs" />
<Compile Include="ViewModels\AppBootstrapper.cs" />
<Compile Include="ViewModels\CacheViewModel.cs" />
Expand Down Expand Up @@ -151,6 +152,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Styles\PromptTextBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\CacheView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -199,7 +204,6 @@
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\" />
<Folder Include="SampleData\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
6 changes: 5 additions & 1 deletion AkavacheExplorer/App.xaml
Expand Up @@ -3,6 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AkavacheExplorer;component/Styles/PromptTextBox.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
20 changes: 20 additions & 0 deletions AkavacheExplorer/Controls/PromptTextBox.cs
@@ -0,0 +1,20 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;

namespace AkavacheExplorer.Controls
{
public class PromptTextBox : TextBox
{
public static readonly DependencyProperty PromptTextProperty =
DependencyProperty.Register("PromptText", typeof(string), typeof(PromptTextBox), new UIPropertyMetadata(""));

[Localizability(LocalizationCategory.Text)]
[DefaultValue("")]
public string PromptText
{
get { return (string)GetValue(PromptTextProperty); }
set { SetValue(PromptTextProperty, value); }
}
}
}
69 changes: 69 additions & 0 deletions AkavacheExplorer/Styles/PromptTextBox.xaml
@@ -0,0 +1,69 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:AkavacheExplorer.Controls">
<SolidColorBrush x:Key="TextBoxMouseOverBorderBrush" Color="#FFA9A9A9" />
<!-- The blue accent color used through-out the app -->
<Color x:Key="AccentColor">#4ea6ea</Color>
<SolidColorBrush x:Key="AccentBrush" Color="{StaticResource AccentColor}" />

<Style TargetType="{x:Type ui:PromptTextBox}">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="#D1D1D1"/>
<Setter Property="Foreground" Value="#333333"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Height" Value="24" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ui:PromptTextBox}">
<Grid>
<Border x:Name="Bd" CornerRadius="2" ClipToBounds="True" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Border CornerRadius="0" BorderBrush="Black" BorderThickness="0,1,0,0" Margin="2,-2,2,0" Opacity="0.4">
<Border.Effect>
<DropShadowEffect Direction="270" ShadowDepth="0" BlurRadius="4" Opacity="1" />
</Border.Effect>
</Border>
</Border>

<Grid Margin="1,0,0,0">
<ScrollViewer x:Name="PART_ContentHost" Padding="{TemplateBinding Padding}" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" VerticalAlignment="Top" Margin="0"/>
<Label x:Name="PromptLabel" HorizontalAlignment="Left"
FontSize="{TemplateBinding FontSize}" Margin="2,0,0,0" Padding="{TemplateBinding Padding}" Opacity="0"
Target="{Binding ElementName=Bd}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Focusable="False" IsHitTestVisible="False"
VerticalAlignment="Top">
<TextBlock Text="{TemplateBinding PromptText}" TextTrimming="CharacterEllipsis" />
</Label>
</Grid>
</Grid>

<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" TargetName="Bd"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource TextBoxMouseOverBorderBrush}" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource GitHubAccentBrush}" />
</Trigger>
<DataTrigger Binding="{Binding Text.Length, RelativeSource={RelativeSource Self}}" Value="0">
<Setter Property="Opacity" TargetName="PromptLabel" Value="0.7" />
<Setter Property="Foreground" Value="Transparent" />
</DataTrigger>
</ControlTemplate.Triggers>

</ControlTemplate>

</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>
16 changes: 15 additions & 1 deletion AkavacheExplorer/ViewModels/CacheViewModel.cs
Expand Up @@ -17,6 +17,7 @@ public interface ICacheViewModel : IRoutableViewModel
public class CacheViewModel : ReactiveObject, ICacheViewModel
{
public ReactiveList<string> Keys { get; protected set; }
public IReactiveDerivedList<string> FilteredKeys { get; protected set; }

string _SelectedKey;
public string SelectedKey {
Expand All @@ -35,7 +36,15 @@ public class CacheViewModel : ReactiveObject, ICacheViewModel
set { this.RaiseAndSetIfChanged(ref _SelectedViewer, value); }
}

ObservableAsPropertyHelper<string> _UrlPathSegment;
string _FilterText;
public string FilterText
{
get { return _FilterText; }
set { this.RaiseAndSetIfChanged(ref _FilterText, value); }
}


readonly ObservableAsPropertyHelper<string> _UrlPathSegment;
public string UrlPathSegment {
get { return _UrlPathSegment.Value; }
}
Expand All @@ -60,6 +69,11 @@ public CacheViewModel(IScreen hostScreen, IAppState appState)
newKeys.ForEach(x => Keys.Add(x));
});

FilteredKeys = Keys.CreateDerivedCollection(
key => key,
key => FilterText == null || key.IndexOf(FilterText, StringComparison.OrdinalIgnoreCase) > -1,
signalReset: this.WhenAny(x => x.FilterText, x => x.Value));

SelectedViewer = "Text";

this.WhenAny(x => x.SelectedKey, x => x.SelectedViewer, (k, v) => k.Value)
Expand Down
2 changes: 2 additions & 0 deletions AkavacheExplorer/Views/CacheView.xaml
Expand Up @@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:rxui="clr-namespace:ReactiveUI.Xaml;assembly=ReactiveUI.Xaml"
xmlns:controls="clr-namespace:AkavacheExplorer.Controls"
mc:Ignorable="d" x:Name="userControl"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
Expand All @@ -22,6 +23,7 @@
<ColumnDefinition Width="0.579*"/>
</Grid.ColumnDefinitions>

<controls:PromptTextBox x:Name="filter" Grid.Row="0" PromptText="filter" />
<ListBox x:Name="Keys" Margin="0,0,6,0" Grid.Row="1" ItemTemplate="{DynamicResource DataTemplate1}" />
<GridSplitter Width="5" HorizontalAlignment="Right" Background="Gray" Grid.RowSpan="2" />

Expand Down
13 changes: 6 additions & 7 deletions AkavacheExplorer/Views/CacheView.xaml.cs
Expand Up @@ -18,16 +18,15 @@ public CacheView()
{
InitializeComponent();

RxApp.MainThreadScheduler.Schedule(() => {
new[] { textRadio, jsonRadio, imageRadio }
.Select(y => y.WhenAny(x => x.IsChecked, x => x).Where(x => x.Value == true).Select(x => x.Sender.Tag))
.Merge()
.Subscribe(x => ViewModel.SelectedViewer = (string)x);
});
RxApp.MainThreadScheduler.Schedule(() => new[] { textRadio, jsonRadio, imageRadio }
.Select(y => y.WhenAny(x => x.IsChecked, x => x).Where(x => x.Value == true).Select(x => x.Sender.Tag))
.Merge()
.Subscribe(x => ViewModel.SelectedViewer = (string)x));

this.OneWayBind(ViewModel, x => x.Keys, x => x.Keys.ItemsSource);
this.OneWayBind(ViewModel, x => x.FilteredKeys, x => x.Keys.ItemsSource);
this.Bind(ViewModel, x => x.SelectedKey, x => x.Keys.SelectedItem);
this.OneWayBind(ViewModel, x => x.SelectedValue, x => x.SelectedValue.ViewModel);
this.Bind(ViewModel, x => x.FilterText, x => x.filter.Text);
}

public CacheViewModel ViewModel {
Expand Down

0 comments on commit d2f72fa

Please sign in to comment.