Skip to content

Commit

Permalink
pre-setting with ini file
Browse files Browse the repository at this point in the history
use ini file to implement the predefined abbreviation
  • Loading branch information
valuex committed Jul 28, 2022
1 parent a152e74 commit 5f6d2ba
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 67 deletions.
3 changes: 2 additions & 1 deletion Core.UnitTests/Core.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Switcheroo.Core.UnitTests</RootNamespace>
<AssemblyName>Switcheroo.Core.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
10 changes: 9 additions & 1 deletion Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Switcheroo.Core</RootNamespace>
<AssemblyName>Switcheroo.Core</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -30,10 +31,16 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="INIFileParser">
<HintPath>..\packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll</HintPath>
</Reference>
<Reference Include="NPinyin">
<HintPath>..\..\..\..\Desktop\OneFlow\NPinyin.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="Switcheroo.Core">
<HintPath>..\packages\Switcheroo.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand All @@ -49,6 +56,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AppWindow.cs" />
<Compile Include="IniFile.cs" />
<Compile Include="IWindowText.cs" />
<Compile Include="KeyboardHelper.cs" />
<Compile Include="WindowFilterer.cs" />
Expand Down
51 changes: 51 additions & 0 deletions Core/IniFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

namespace Switcheroo.Core
{
class IniFile // revision 11
{
string Path;
string EXE = Assembly.GetExecutingAssembly().GetName().Name;

[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);

[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);

public IniFile(string IniPath = null)
{
Path = new FileInfo(IniPath ?? EXE + ".ini").FullName;
}

public string Read(string Key, string Section = null)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path);
return RetVal.ToString();
}

public void Write(string Key, string Value, string Section = null)
{
WritePrivateProfileString(Section ?? EXE, Key, Value, Path);
}

public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? EXE);
}

public void DeleteSection(string Section = null)
{
Write(null, null, Section ?? EXE);
}

public bool KeyExists(string Key, string Section = null)
{
return Read(Key, Section).Length > 0;
}
}
}
35 changes: 11 additions & 24 deletions Core/WindowFilterer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System.Collections.Generic;
using System.Linq;
using Switcheroo.Core.Matchers;
using IniParser;
using IniParser.Model;
using System;

namespace Switcheroo.Core
Expand All @@ -31,40 +33,25 @@ public IEnumerable<FilterResult<T>> Filter<T>(WindowFilterContext<T> context, st
{
var filterText = query;
string processFilterText = null;

var queryParts = query.Split(new [] {'.'}, 2); // . is used to seperate the input string in to two parts, part1--processFilterText, part2--filterText

var parser = new FileIniDataParser();
IniData data = parser.ReadFile("Switcheroo.ini");
string strSpliter = data["config"]["Spliter"];
// . is used to seperate the input string in to two parts, part1--processFilterText, part2--filterText
char charSpliter = strSpliter.ToCharArray()[0];
var queryParts = query.Split(new[] { charSpliter }, 2);

if (queryParts.Length == 2)
{
processFilterText = queryParts[0];
if (processFilterText.Length == 0)
{
processFilterText = context.ForegroundWindowProcessTitle;
}
switch (processFilterText)
{
// set some prefined-text to enable quick filtering
case "e":
processFilterText="excel";
break;
case "f":
processFilterText = "explorer";
break;
case "w":
processFilterText = "word";
break;
case "p":
processFilterText = "powerpnt";
break;

// default:
// processFilterText= processFilterText;
// break;
}
processFilterText = data["config"][queryParts[0]];
filterText = queryParts[1];
}



return context.Windows
.Select(
Expand Down
4 changes: 2 additions & 2 deletions ManagedWinapi/ManagedWinapi.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -15,7 +15,7 @@
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkProfile />
Expand Down
10 changes: 10 additions & 0 deletions Switcheroo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ private void Switch()

HideWindow();
}
private void Preview()
{
this.Topmost = true;
foreach (var item in lb.SelectedItems)
{
var win = (AppWindowViewModel)item;
win.AppWindow.SwitchToLastVisibleActivePopup();
}
}

private void HideWindow()
{
Expand Down Expand Up @@ -657,6 +666,7 @@ private void PreviousItem()
}

ScrollSelectedItemIntoView();
Preview();
}
}

Expand Down
28 changes: 14 additions & 14 deletions Switcheroo/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Switcheroo/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Switcheroo/Switcheroo.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Switcheroo</RootNamespace>
<AssemblyName>switcheroo</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -63,6 +63,9 @@
<StartupObject>Switcheroo.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="INIFileParser, Version=2.5.2.0, Culture=neutral, PublicKeyToken=79af7b307b65cf3c, processorArchitecture=MSIL">
<HintPath>..\packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="PresentationCore" />
<Reference Include="System" />
Expand Down
32 changes: 14 additions & 18 deletions Switcheroo/app.config
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<configSections>
<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Switcheroo.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Switcheroo.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>
<Switcheroo.Properties.Settings>
<setting name="Ctrl" serializeAs="String">
<value>False</value>
Expand Down Expand Up @@ -41,9 +37,9 @@
<setting name="EnableHotKey" serializeAs="String">
<value>True</value>
</setting>
</Switcheroo.Properties.Settings>
</userSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
</Switcheroo.Properties.Settings>
</userSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
1 change: 1 addition & 0 deletions Switcheroo/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ini-parser" version="2.5.2" targetFramework="net48" />
<package id="MSBuildTasks" version="1.4.0.65" targetFramework="net45" />
</packages>

0 comments on commit 5f6d2ba

Please sign in to comment.