Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved window closing #25

Merged
merged 18 commits into from
Jan 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Core/AppWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ namespace Switcheroo.Core
/// </summary>
public class AppWindow : SystemWindow
{
public string FormattedTitle { get; set; }

public string ProcessTitle
{
get
Expand All @@ -54,10 +52,6 @@ public string ProcessTitle
}
}

public string FormattedProcessTitle { get; set; }



public Icon LargeWindowIcon
{
get { return new WindowIconFinder().Find(this, WindowIconSize.Large); }
Expand Down
145 changes: 73 additions & 72 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
@@ -1,79 +1,80 @@
<?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="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="IWindowText.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" />
<!-- 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>
6 changes: 3 additions & 3 deletions Core/FilterResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
using Switcheroo.Core.Matchers;

namespace Switcheroo.Core
{
public class FilterResult
{
public class FilterResult<T> where T: IWindowText
{
public AppWindow AppWindow { get; set; }
public T AppWindow { get; set; }
public IList<MatchResult> WindowTitleMatchResults { get; set; }
public IList<MatchResult> ProcessTitleMatchResults { get; set; }
}
Expand Down
14 changes: 14 additions & 0 deletions Core/IWindowText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Switcheroo.Core
{
public interface IWindowText
{
string WindowTitle { get; }
string ProcessTitle { get; }
}
}
6 changes: 3 additions & 3 deletions Core/WindowFilterer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ namespace Switcheroo.Core
{
public class WindowFilterer
{
public IEnumerable<FilterResult> Filter(IEnumerable<AppWindow> windows, string filterText)
public IEnumerable<FilterResult<T>> Filter<T>(IEnumerable<T> windows, string filterText) where T: IWindowText
{
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.WindowTitle, filterText), ResultsProcessTitle = Score(w.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 });
.Select(r => new FilterResult<T>() { AppWindow = r.Window, WindowTitleMatchResults = r.ResultsTitle, ProcessTitleMatchResults = r.ResultsProcessTitle });
}

private static List<MatchResult> Score(string title, string filterText)
Expand Down
21 changes: 21 additions & 0 deletions ManagedWinapi/SystemWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,27 @@ public bool Enabled
}
}

private bool _isClosed = false;
public bool IsClosed
{
get
{
_isClosed = _isClosed || GetClassNameFails();
return _isClosed;
}
}

private bool GetClassNameFails()
{
StringBuilder builder = new StringBuilder( 2 );
return GetClassName( HWnd, builder, builder.Capacity ) == 0;
}

public bool IsClosedOrHidden
{
get { return IsClosed || !Visible; }
}

/// <summary>
/// Returns or sets the visibility flag.
/// </summary>
Expand Down
96 changes: 96 additions & 0 deletions Switcheroo/AppWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Switcheroo.Core;

namespace Switcheroo
{
public class AppWindowViewModel: INotifyPropertyChanged, IWindowText
{
public AppWindowViewModel( AppWindow appWindow )
{
AppWindow = appWindow;
}

public AppWindow AppWindow { get; private set; }

#region IWindowText Members

public string WindowTitle
{
get { return AppWindow.Title; }
}

public string ProcessTitle
{
get { return AppWindow.ProcessTitle; }
}

#endregion

#region Bindable properties

public IntPtr HWnd
{
get { return AppWindow.HWnd; }
}

private string _formattedTitle;
public string FormattedTitle
{
get { return _formattedTitle; }
set { _formattedTitle = value; NotifyOfPropertyChange( () => FormattedTitle ); }
}

private string _formattedProcessTitle;
public string FormattedProcessTitle
{
get { return _formattedProcessTitle; }
set { _formattedProcessTitle = value; NotifyOfPropertyChange( () => FormattedProcessTitle ); }
}

private bool _isBeingClosed = false;
public bool IsBeingClosed
{
get { return _isBeingClosed; }
set { _isBeingClosed = value; NotifyOfPropertyChange( () => IsBeingClosed ); }
}

#endregion

#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

private void NotifyOfPropertyChange<T>( Expression<Func<T>> property )
{
var handler = PropertyChanged;
if ( handler != null )
handler( this, new PropertyChangedEventArgs( GetPropertyName( property ) ) );
}

private string GetPropertyName<T>( Expression<Func<T>> property )
{
var lambda = (LambdaExpression) property;

MemberExpression memberExpression;
if ( lambda.Body is UnaryExpression )
{
var unaryExpression = (UnaryExpression) lambda.Body;
memberExpression = (MemberExpression) unaryExpression.Operand;
}
else
{
memberExpression = (MemberExpression) lambda.Body;
}

return memberExpression.Member.Name;
}

#endregion
}
}
39 changes: 39 additions & 0 deletions Switcheroo/BoolToWhateverConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace Switcheroo
{
public class BoolConverter<T>: IValueConverter
{
public T IfTrue { get; set; }
public T IfFalse { get; set; }

#region IValueConverter Members

public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
{
return ( (bool) value ) ? IfTrue : IfFalse;
}

public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
{
throw new NotImplementedException();
}

#endregion
}


public class BoolToDoubleConverter: BoolConverter<double>
{
}

public class BoolToColorConverter: BoolConverter<Color>
{
}
}
Loading