Skip to content

Commit

Permalink
Extract search commands into a pluggable container (in core)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Rondeau committed Sep 1, 2014
1 parent 49bcd42 commit 8533212
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 131 deletions.
16 changes: 16 additions & 0 deletions GoToWindow.Extensibility/Controls/BasicCommandEntry.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<UserControl x:Class="GoToWindow.Extensibility.Controls.BasicCommandEntry"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="48" d:DesignWidth="512"
d:DataContext="{d:DesignData basicViewModel:DesignTimeCommandResult, IsDesignTimeCreatable=True}">
<Grid>
<StackPanel Orientation="Horizontal" Height="Auto">
<TextBlock Margin="16, 16, 0, 16" VerticalAlignment="Center" Foreground="Gray" Text="{Binding BeforeText}"></TextBlock>
<TextBlock Margin="0, 16, 0, 16" VerticalAlignment="Center" Foreground="Black" FontWeight="Bold" Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Margin="0, 16, 0, 16" VerticalAlignment="Center" Foreground="Gray" Text="{Binding AfterText}"></TextBlock>
</StackPanel>
</Grid>
</UserControl>
12 changes: 12 additions & 0 deletions GoToWindow.Extensibility/Controls/BasicCommandEntry.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Windows.Controls;

namespace GoToWindow.Extensibility.Controls
{
public partial class BasicCommandEntry : UserControl
{
public BasicCommandEntry()
{
InitializeComponent();
}
}
}
2 changes: 1 addition & 1 deletion GoToWindow.Extensibility/Controls/BasicListEntry.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="48" d:DesignWidth="512"
d:DataContext="{d:DesignData basicViewModel:IBasicSearchResult}">
d:DataContext="{d:DesignData basicViewModel:DesignTimeSearchResult, IsDesignTimeCreatable=True}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Name="IconColumn" Width="48"/>
Expand Down
10 changes: 10 additions & 0 deletions GoToWindow.Extensibility/GoToWindow.Extensibility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\BasicCommandEntry.xaml.cs">
<DependentUpon>BasicCommandEntry.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\BasicListEntry.xaml.cs">
<DependentUpon>BasicListEntry.xaml</DependentUpon>
</Compile>
Expand All @@ -47,13 +50,20 @@
<Compile Include="IGoToWindowPlugin.cs" />
<Compile Include="ISearchResult.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModel\DesignTimeCommandResult.cs" />
<Compile Include="ViewModel\DesignTimeSearchResult.cs" />
<Compile Include="ViewModel\IBasicCommandResult.cs" />
<Compile Include="ViewModel\IBasicSearchResult.cs" />
<Compile Include="ViewModel\IWindowSearchResult.cs" />
<Compile Include="ViewModel\SearchHelper.cs" />
<Compile Include="ViewModel\SearchResultBase.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Page Include="Controls\BasicCommandEntry.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Controls\BasicListEntry.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
28 changes: 28 additions & 0 deletions GoToWindow.Extensibility/ViewModel/DesignTimeCommandResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Windows.Controls;

namespace GoToWindow.Extensibility.ViewModel
{
public class DesignTimeCommandResult : IBasicCommandResult
{
public UserControl View { get; private set; }
public string BeforeText { get; private set; }
public string Text { get; private set; }
public string AfterText { get; private set; }

public DesignTimeCommandResult()
{
BeforeText = "Execute command '";
Text = "Input Text";
AfterText = "' with something";
}

public void Select()
{
}

public bool IsShown(string searchQuery)
{
return true;
}
}
}
37 changes: 37 additions & 0 deletions GoToWindow.Extensibility/ViewModel/DesignTimeSearchResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using GoToWindow.Extensibility.Controls;

namespace GoToWindow.Extensibility.ViewModel
{
public class DesignTimeSearchResult : IBasicSearchResult
{
public UserControl View { get; private set; }

public BitmapFrame Icon { get; private set; }
public string Title { get; private set; }
public string ProcessName { get; private set; }

public DesignTimeSearchResult()
: this(null, "process", "Window Title")
{
}

public DesignTimeSearchResult(BitmapFrame icon, string processName, string title)
{
View = new BasicListEntry();
Icon = icon;
ProcessName = processName;
Title = title;
}

public void Select()
{
}

public bool IsShown(string searchQuery)
{
return true;
}
}
}
9 changes: 9 additions & 0 deletions GoToWindow.Extensibility/ViewModel/IBasicCommandResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GoToWindow.Extensibility.ViewModel
{
public interface IBasicCommandResult : ISearchResult
{
string BeforeText { get; }
string Text { get; }
string AfterText { get; }
}
}
2 changes: 1 addition & 1 deletion GoToWindow.Extensibility/ViewModel/IBasicSearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GoToWindow.Extensibility.ViewModel
{
public interface IBasicSearchResult
public interface IBasicSearchResult : ISearchResult
{
BitmapFrame Icon { get; }
string Title { get; }
Expand Down
1 change: 1 addition & 0 deletions GoToWindow.Plugins.Core/CorePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CorePlugin : IGoToWindowPlugin
public void BuildList(List<ISearchResult> list)
{
list.AddRange(WindowsListFactory.Load().Windows.Select(ConvertWindowEntryToSearchResult));
list.Add(new WindowSearchCommandResult());
}

private static ISearchResult ConvertWindowEntryToSearchResult(IWindowEntry entry)
Expand Down
1 change: 1 addition & 0 deletions GoToWindow.Plugins.Core/GoToWindow.Plugins.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="ViewModel\WindowSearchCommandResult.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
57 changes: 57 additions & 0 deletions GoToWindow.Plugins.Core/ViewModel/WindowSearchCommandResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.ComponentModel;
using GoToWindow.Api;
using GoToWindow.Extensibility.Controls;
using GoToWindow.Extensibility.ViewModel;
using log4net;

namespace GoToWindow.Plugins.Core.ViewModel
{
public class WindowSearchCommandResult : SearchResultBase, IBasicCommandResult, INotifyPropertyChanged
{
private static readonly ILog Log = LogManager.GetLogger(typeof(WindowSearchCommandResult).Assembly, "GoToWindow");

private string _text;
private string _query;

public event PropertyChangedEventHandler PropertyChanged;

public string BeforeText { get { return "Search for '"; } }
public string AfterText { get { return "' using Windows Search"; } }

public string Text
{
get { return _text; }
set
{
_text = value;
OnPropertyChanged("Text");
}
}

public WindowSearchCommandResult()
: base(() => new BasicCommandEntry())
{

}

protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}

public void Select()
{
Log.DebugFormat("Launching Windows Search with '{0}'.", _query);
WindowsSearch.Launch(_query);
}

public bool IsShown(string searchQuery)
{
_query = searchQuery;
Text = _query;
return !String.IsNullOrWhiteSpace(searchQuery);
}
}
}
65 changes: 24 additions & 41 deletions GoToWindow/ViewModels/DesignTimeMainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,63 +1,46 @@
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using GoToWindow.Extensibility;
using GoToWindow.Extensibility.Controls;
using GoToWindow.Extensibility.ViewModel;

namespace GoToWindow.ViewModels
{
public class DesignTimeMainViewModel : MainViewModel
{
private class DesignTimeSearchResult : ISearchResult, IBasicSearchResult
{
public UserControl View { get; private set; }

public BitmapFrame Icon { get; private set; }
public string Title { get; private set; }
public string ProcessName { get; private set; }

public DesignTimeSearchResult(string processName, string title)
{
View = new BasicListEntry();
ProcessName = processName;
Title = title;
}

public void Select()
{
}

public bool IsShown(string searchQuery)
{
return true;
}
}

public DesignTimeMainViewModel()
{
IsEmpty = false;
AvailableWindowWidth = 640;
AvailableWindowHeight = 320;
//SearchText = "User Query...";
AvailableWindowHeight = 240;
SearchText = "User Query...";
var icon = ConvertFromIcon(Properties.Resources.AppIcon);
Windows = new CollectionViewSource
{
Source = new List<ISearchResult>
{
new DesignTimeSearchResult("process", "Window Title"),
new DesignTimeSearchResult("very long process name", "Very very long window title that should end up with ellipsis because it is so very long"),
new DesignTimeSearchResult("filler", "Some Window Title"),
new DesignTimeSearchResult("filler", "Some Window Title"),
new DesignTimeSearchResult("filler", "Some Window Title"),
new DesignTimeSearchResult("filler", "Some Window Title"),
new DesignTimeSearchResult("filler", "Some Window Title"),
new DesignTimeSearchResult("filler", "Some Window Title"),
new DesignTimeSearchResult("filler", "Some Window Title"),
new DesignTimeSearchResult("filler", "Some Window Title")
new DesignTimeSearchResult(icon, "process", "Window Title"),
new DesignTimeSearchResult(icon, "very long process name", "Very very long window title that should end up with ellipsis because it is so very long"),
new DesignTimeSearchResult(icon, "filler", "Some Window Title"),
new DesignTimeSearchResult(icon, "filler", "Some Window Title"),
new DesignTimeSearchResult(icon, "filler", "Some Window Title"),
new DesignTimeSearchResult(icon, "filler", "Some Window Title"),
new DesignTimeSearchResult(icon, "filler", "Some Window Title"),
new DesignTimeSearchResult(icon, "filler", "Some Window Title"),
new DesignTimeSearchResult(icon, "filler", "Some Window Title"),
new DesignTimeSearchResult(icon, "filler", "Some Window Title")
}
};
}

private static BitmapFrame ConvertFromIcon(Icon icon)
{
var memoryStream = new MemoryStream();
icon.Save(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
return BitmapFrame.Create(memoryStream);
}
}
}
Loading

0 comments on commit 8533212

Please sign in to comment.