-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-plugin-everything'
- Loading branch information
Showing
27 changed files
with
2,516 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Plugins/CurvaLauncher.Plugins.Everything/CurvaLauncher.Plugins.Everything.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<UseWPF>true</UseWPF> | ||
<EnableWindowsTargeting>true</EnableWindowsTargeting> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Platforms>AnyCPU;x64</Platforms> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="EverythingSearchClient\EverythingSearchClient.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\CurvaLauncher.Plugins\CurvaLauncher.Plugins.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="Properties\Resources.Designer.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Update="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
<Target Name="CopyOutput" AfterTargets="Build"> | ||
<Copy SourceFiles="$(OutDir)\$(MSBuildProjectName).dll" DestinationFiles="..\..\CurvaLauncher\bin\$(Configuration)\$(TargetFramework)\Plugins\$(MSBuildProjectName).dll"></Copy> | ||
</Target> | ||
|
||
<Target Name="CopyOutputPdb" AfterTargets="Build" Condition="'$(Configuration)'=='Debug'"> | ||
<Copy SourceFiles="$(OutDir)\$(MSBuildProjectName).pdb" DestinationFiles="..\..\CurvaLauncher\bin\$(Configuration)\$(TargetFramework)\Plugins\$(MSBuildProjectName).pdb"></Copy> | ||
</Target> | ||
|
||
</Project> |
14 changes: 14 additions & 0 deletions
14
src/Plugins/CurvaLauncher.Plugins.Everything/EverythingNotRunningQueryResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Windows.Media; | ||
|
||
namespace CurvaLauncher.Plugins.Everything | ||
{ | ||
public class EverythingNotRunningQueryResult : IQueryResult | ||
{ | ||
public string Title => "Everything"; | ||
public string Description => "Everything is not running now!"; | ||
|
||
public float Weight => 1; | ||
|
||
public ImageSource? Icon => null; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/Plugins/CurvaLauncher.Plugins.Everything/EverythingPlugin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Media; | ||
using CurvaLauncher.Plugins.Everything.Properties; | ||
using EverythingSearchClient; | ||
|
||
namespace CurvaLauncher.Plugins.Everything | ||
{ | ||
public class EverythingPlugin : SyncI18nPlugin | ||
{ | ||
public EverythingPlugin(CurvaLauncherContext context) : base(context) | ||
{ | ||
Icon = context.ImageApi.CreateFromSvg(Resources.IconSvg)!; | ||
} | ||
|
||
public override object NameKey => "StrPluginName"; | ||
public override object DescriptionKey => "StrPluginDescription"; | ||
public override ImageSource Icon { get; } | ||
|
||
|
||
[PluginI18nOption("StrPrefix")] | ||
public string Prefix { get; set; } = "*"; | ||
|
||
[PluginI18nOption("StrResultMaxCount")] | ||
public int ResultMaxCount { get; set; } = 10; | ||
|
||
public override IEnumerable<I18nResourceDictionary> GetI18nResourceDictionaries() | ||
{ | ||
yield return I18nResourceDictionary.Create(new CultureInfo("en-US"), "I18n/EnUs.xaml"); | ||
yield return I18nResourceDictionary.Create(new CultureInfo("zh-Hans"), "I18n/ZhHans.xaml"); | ||
yield return I18nResourceDictionary.Create(new CultureInfo("zh-Hant"), "I18n/ZhHant.xaml"); | ||
yield return I18nResourceDictionary.Create(new CultureInfo("ja-JP"), "I18n/JaJp.xaml"); | ||
yield return I18nResourceDictionary.Create(new CultureInfo("de"), "I18n/De.xaml"); | ||
} | ||
|
||
public override IEnumerable<IQueryResult> Query(string query) | ||
{ | ||
if (!query.StartsWith(Prefix)) | ||
yield break; | ||
query = query.Substring(Prefix.Length); | ||
|
||
if (!SearchClient.IsEverythingAvailable()) | ||
{ | ||
yield return new EverythingNotRunningQueryResult(); | ||
yield break; | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(query)) | ||
{ | ||
yield return new EmptyQueryResult("Everything", "Locate files and folders by name instantly.", 1, null); | ||
yield break; | ||
} | ||
|
||
var client = new SearchClient(); | ||
var result = client.Search(query, (uint)ResultMaxCount); | ||
|
||
float weight = 1; | ||
foreach (var item in result.Items) | ||
{ | ||
yield return new EverythingQueryResult(this, item, weight); | ||
weight -= float.Epsilon; | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Plugins/CurvaLauncher.Plugins.Everything/EverythingQueryResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Windows.Media; | ||
|
||
namespace CurvaLauncher.Plugins.Everything | ||
{ | ||
public class EverythingQueryResult : ISyncQueryResult | ||
{ | ||
private readonly EverythingPlugin _plugin; | ||
private readonly EverythingSearchClient.Result.Item _searchResult; | ||
private readonly string _itemFullPath; | ||
|
||
public EverythingQueryResult(EverythingPlugin plugin, EverythingSearchClient.Result.Item searchResult, float weight) | ||
{ | ||
_plugin = plugin; | ||
_searchResult = searchResult; | ||
_itemFullPath = System.IO.Path.Combine(searchResult.Path, searchResult.Name); | ||
Weight = weight; | ||
|
||
plugin.HostContext.Dispatcher.Invoke(() => | ||
{ | ||
Icon = plugin.HostContext.ImageApi.GetFileIcon(_itemFullPath, plugin.HostContext.RequiredIconSize); | ||
|
||
if (Icon == null) | ||
{ | ||
if (System.IO.Directory.Exists(_itemFullPath)) | ||
Icon = plugin.HostContext.ImageApi.GetDefaultFolderIcon(plugin.HostContext.RequiredIconSize); | ||
else if (System.IO.File.Exists(_itemFullPath)) | ||
Icon = plugin.HostContext.ImageApi.GetDefaultFileIcon(plugin.HostContext.RequiredIconSize); | ||
} | ||
}); | ||
} | ||
|
||
public string Title => _searchResult.Name; | ||
public string Description => _searchResult.Path; | ||
|
||
public float Weight { get; } | ||
|
||
public ImageSource? Icon { get; private set; } | ||
|
||
public void Invoke() | ||
{ | ||
if (_plugin.HostContext.IsAltKeyPressed()) | ||
{ | ||
|
||
} | ||
else if (_plugin.HostContext.IsCtrlKeyPressed()) | ||
{ | ||
|
||
} | ||
else | ||
{ | ||
_plugin.HostContext.Api.Open(_itemFullPath); | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...lugins/CurvaLauncher.Plugins.Everything/EverythingSearchClient/EverythingBusyException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace EverythingSearchClient | ||
{ | ||
public class EverythingBusyException: Exception | ||
{ | ||
public EverythingBusyException() : base("Everything service is busy") { } | ||
} | ||
} |
Oops, something went wrong.