Skip to content

Commit

Permalink
Migrated WindowFilterer to AppWindowViewModel to preserve IsBeingClos…
Browse files Browse the repository at this point in the history
…ed state
  • Loading branch information
HellBrick committed Jan 17, 2015
1 parent 34c7907 commit c4d0dac
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
using System.Text;
using System.Threading.Tasks;
using Caliburn.Micro;
using Switcheroo.Core;

namespace Switcheroo
namespace Switcheroo.Core
{
public class AppWindowViewModel: PropertyChangedBase
{
Expand Down
157 changes: 85 additions & 72 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
@@ -1,79 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B846514D-25BE-4274-972A-0E6E74DD0F8B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Switcheroo.Core</RootNamespace>
<AssemblyName>Switcheroo.Core</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Caching" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppWindow.cs" />
<Compile Include="KeyboardHelper.cs" />
<Compile Include="WindowFilterer.cs" />
<Compile Include="WindowFinder.cs" />
<Compile Include="Matchers\ContainsMatcher.cs" />
<Compile Include="Matchers\IMatcher.cs" />
<Compile Include="Matchers\IndividualCharactersMatcher.cs" />
<Compile Include="Matchers\MatchResult.cs" />
<Compile Include="Matchers\SignificantCharactersMatcher.cs" />
<Compile Include="Matchers\StartsWithMatcher.cs" />
<Compile Include="Matchers\StringPart.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FilterResult.cs" />
<Compile Include="WinApi.cs" />
<Compile Include="WindowIconFinder.cs" />
<Compile Include="XamlHighlighter.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ManagedWinapi\ManagedWinapi.csproj">
<Project>{fbd3ec1e-47e2-4d2d-81c9-d6506125a09a}</Project>
<Name>ManagedWinapi</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B846514D-25BE-4274-972A-0E6E74DD0F8B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Switcheroo.Core</RootNamespace>
<AssemblyName>Switcheroo.Core</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Caliburn.Micro">
<HintPath>..\packages\Caliburn.Micro.Core.2.0.1\lib\net45\Caliburn.Micro.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro.Platform">
<HintPath>..\packages\Caliburn.Micro.2.0.1\lib\net45\Caliburn.Micro.Platform.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Caching" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.2.0.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppWindow.cs" />
<Compile Include="AppWindowViewModel.cs" />
<Compile Include="KeyboardHelper.cs" />
<Compile Include="WindowFilterer.cs" />
<Compile Include="WindowFinder.cs" />
<Compile Include="Matchers\ContainsMatcher.cs" />
<Compile Include="Matchers\IMatcher.cs" />
<Compile Include="Matchers\IndividualCharactersMatcher.cs" />
<Compile Include="Matchers\MatchResult.cs" />
<Compile Include="Matchers\SignificantCharactersMatcher.cs" />
<Compile Include="Matchers\StartsWithMatcher.cs" />
<Compile Include="Matchers\StringPart.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FilterResult.cs" />
<Compile Include="WinApi.cs" />
<Compile Include="WindowIconFinder.cs" />
<Compile Include="XamlHighlighter.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ManagedWinapi\ManagedWinapi.csproj">
<Project>{fbd3ec1e-47e2-4d2d-81c9-d6506125a09a}</Project>
<Name>ManagedWinapi</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>
2 changes: 1 addition & 1 deletion Core/FilterResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Switcheroo.Core
{
public class FilterResult
{
public AppWindow AppWindow { get; set; }
public AppWindowViewModel AppWindow { get; set; }
public IList<MatchResult> WindowTitleMatchResults { get; set; }
public IList<MatchResult> ProcessTitleMatchResults { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions Core/WindowFilterer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace Switcheroo.Core
{
public class WindowFilterer
{
public IEnumerable<FilterResult> Filter(IEnumerable<AppWindow> windows, string filterText)
public IEnumerable<FilterResult> Filter(IEnumerable<AppWindowViewModel> windows, string filterText)
{
return windows
.Select(w => new { Window = w, ResultsTitle = Score(w.Title, filterText), ResultsProcessTitle = Score(w.ProcessTitle, filterText) })
.Select(w => new { Window = w, ResultsTitle = Score(w.AppWindow.Title, filterText), ResultsProcessTitle = Score(w.AppWindow.ProcessTitle, filterText) })
.Where(r => r.ResultsTitle.Any(wt => wt.Matched) || r.ResultsProcessTitle.Any(pt => pt.Matched))
.OrderByDescending(r => r.ResultsTitle.Sum(wt => wt.Score) + r.ResultsProcessTitle.Sum(pt => pt.Score))
.Select(r => new FilterResult { AppWindow = r.Window, WindowTitleMatchResults = r.ResultsTitle, ProcessTitleMatchResults = r.ResultsProcessTitle });
Expand Down
5 changes: 5 additions & 0 deletions Core/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Caliburn.Micro" version="2.0.1" targetFramework="net45" />
<package id="Caliburn.Micro.Core" version="2.0.1" targetFramework="net45" />
</packages>
4 changes: 2 additions & 2 deletions Switcheroo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ private void TextChanged(object sender, TextChangedEventArgs args)
{
var text = tb.Text;

var filterResults = new WindowFilterer().Filter( _windowList.Select( vm => vm.AppWindow ), text ).ToList();
var filterResults = new WindowFilterer().Filter( _windowList, text ).ToList();

foreach (var filterResult in filterResults)
{
filterResult.AppWindow.FormattedTitle = GetFormattedTitleFromBestResult(filterResult.WindowTitleMatchResults);
filterResult.AppWindow.FormattedProcessTitle = GetFormattedTitleFromBestResult(filterResult.ProcessTitleMatchResults);
}

lb.DataContext = new ObservableCollection<AppWindowViewModel>( filterResults.Select( r => new AppWindowViewModel( r.AppWindow ) ) );
lb.DataContext = new ObservableCollection<AppWindowViewModel>( filterResults.Select( r => r.AppWindow ) );
if (lb.Items.Count > 0)
{
lb.SelectedItem = lb.Items[0];
Expand Down
1 change: 0 additions & 1 deletion Switcheroo/Switcheroo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AppWindowViewModel.cs" />
<Compile Include="IconToBitmapConverter.cs" />
<Compile Include="WindowHandleToCachedIconConverter.cs" />
<Compile Include="WindowHandleToIconConverter.cs" />
Expand Down

0 comments on commit c4d0dac

Please sign in to comment.