Skip to content
This repository was archived by the owner on Jul 18, 2023. It is now read-only.

Commit e9f4be4

Browse files
authored
Merge pull request #30 from Flow-Launcher/refactor
Add Sort Option Translation & disable sort that is not fast sort
2 parents d62b569 + 592ec2f commit e9f4be4

9 files changed

Lines changed: 102 additions & 6 deletions

Everything/EverythingAPI.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,18 @@ public List<SearchResult> Search(string keyWord, CancellationToken token, SortOp
123123
EverythingApiDllImport.Everything_SetSearchW(keyWord);
124124
EverythingApiDllImport.Everything_SetOffset(offset);
125125
EverythingApiDllImport.Everything_SetMax(maxCount);
126+
127+
if(!EverythingApiDllImport.Everything_IsFastSort(sortOption))
128+
{
129+
throw new InvalidOperationException("The Sort Option is not Fast Sort, it may take a long time to finish the query");
130+
}
126131
EverythingApiDllImport.Everything_SetSort(sortOption);
127132

128133
if (token.IsCancellationRequested)
129134
{
130135
return null;
131136
}
132-
137+
133138

134139
if (!EverythingApiDllImport.Everything_QueryW(true))
135140
{

Everything/EverythingApiDllImport.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public sealed class EverythingApiDllImport
9595
[DllImport(Main.DLL)]
9696
public static extern void Everything_SetSort(SortOption dwSortType);
9797
[DllImport(Main.DLL)]
98+
public static extern bool Everything_IsFastSort(SortOption dwSortType);
99+
[DllImport(Main.DLL)]
98100
public static extern SortOption Everything_GetSort();
99101
[DllImport(Main.DLL)]
100102
public static extern uint Everything_GetResultListSort();

EverythingSettings.xaml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:helper="clr-namespace:Flow.Launcher.Plugin.Everything.Helper"
67
mc:Ignorable="d"
78
Loaded="View_Loaded"
89
DataContext="{Binding RelativeSource={RelativeSource Self}}"
@@ -20,6 +21,9 @@
2021
<ColumnDefinition />
2122
<ColumnDefinition />
2223
</Grid.ColumnDefinitions>
24+
<Grid.Resources>
25+
<helper:EnumNameConverter x:Key="enumNameConverter"/>
26+
</Grid.Resources>
2327
<CheckBox Grid.Row="0" Grid.ColumnSpan="3" x:Name="UseLocationAsWorkingDir" Content="{DynamicResource
2428
flowlauncher_plugin_everything_use_location_as_working_dir}"
2529
Margin="10" HorizontalAlignment="Left" />
@@ -47,7 +51,20 @@
4751
<TextBox Grid.Row="3" Grid.Column="2" HorizontalAlignment="Right"
4852
ToolTip="{DynamicResource flowlauncher_plugin_everything_customized_args_textbox}"
4953
Margin="0,0,5,0" Width="80" Height="35" x:Name="CustomizeArgsBox" TextChanged="CustomizeExplorerArgs"></TextBox>
50-
<TextBlock Margin="10" Text="{Binding SortText}" Grid.Row="4"/>
51-
<ComboBox Grid.Row="4" Grid.Column="1" Width="200" SelectedItem="{Binding _settings.SortOption}" ItemsSource="{Binding _settings.SortOptions, Mode=OneWay}"/>
54+
<TextBlock Margin="10" Text="{DynamicResource flowlauncher_plugin_everything_sort_by}" Grid.Row="4"/>
55+
56+
<ComboBox Grid.Row="4"
57+
Grid.Column="1"
58+
Width="200"
59+
SelectedItem="{Binding _settings.SortOption}"
60+
ItemsSource="{Binding _settings.SortOptions, Mode=OneWay}">
61+
<ComboBox.ItemTemplate>
62+
<DataTemplate>
63+
<Grid>
64+
<TextBlock Text="{Binding Converter={StaticResource enumNameConverter}}"/>
65+
</Grid>
66+
</DataTemplate>
67+
</ComboBox.ItemTemplate>
68+
</ComboBox>
5269
</Grid>
5370
</UserControl>

EverythingSettings.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public partial class EverythingSettings : UserControl
1212
public SortOption SortOption { get; set; }
1313
public SortOption[] SortOptions { get; set; }
1414

15-
public string SortText { get; set; } = "SortBy";
16-
1715
public EverythingSettings(Settings settings)
1816
{
1917
_settings = settings;

Helper/EnumNameConverter.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Flow.Launcher.Plugin.Everything.Everything;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows.Data;
9+
10+
namespace Flow.Launcher.Plugin.Everything.Helper
11+
{
12+
class EnumNameConverter : IValueConverter
13+
{
14+
private Dictionary<string, SortOption> translationRecord = new Dictionary<string, SortOption>();
15+
16+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
17+
{
18+
return value is SortOption option ? option.GetTranslatedName() : value;
19+
}
20+
21+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
22+
{
23+
throw new NotImplementedException();
24+
}
25+
}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Flow.Launcher.Plugin.Everything.Everything;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Flow.Launcher.Plugin.Everything.Helper
10+
{
11+
public static class SortOptionTranlationHelper
12+
{
13+
public static IPublicAPI API { get; internal set; }
14+
15+
public static string GetTranslatedName(this SortOption sortOption)
16+
{
17+
const string prefix = "flowlauncher_plugin_everything_sort_by_";
18+
19+
var enumName = Enum.GetName(sortOption);
20+
var splited = enumName.Split('_');
21+
var name = string.Join('_', splited[..^1]);
22+
var direction = splited[^1];
23+
24+
return $"{API.GetTranslation(prefix + name.ToLower())} {API.GetTranslation(prefix + direction.ToLower())}";
25+
}
26+
}
27+
}

Languages/en.xaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@
2727
<system:String x:Key="flowlauncher_plugin_everything_customized_args_tooltip">Enter the customized args you want to add for customized explorer. %s represent directory path (parent directory for file or directory itself). %f represent file path (only work for file).</system:String>
2828
<system:String x:Key="flowlauncher_plugin_everything_customized_args_textbox">%s represent directory path (parent directory for file or directory itself). %f represent file path (only work for file).</system:String>
2929

30+
<system:String x:Key="flowlauncher_plugin_everything_sort_by">Sort By</system:String>
31+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_name">Name</system:String>
32+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_path">Path</system:String>
33+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_size">Size</system:String>
34+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_extension">Extension</system:String>
35+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_type_name">Type Name</system:String>
36+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_created">Date Created</system:String>
37+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_modified">Date Modified</system:String>
38+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_attributes">Attributes</system:String>
39+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_file_list_filename">File List FileName</system:String>
40+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_run_count">Run Count</system:String>
41+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_recently_changed">Date Recently Changed</system:String>
42+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_accessed">Date Accessed</system:String>
43+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_run">Date Run</system:String>
44+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_ascending">↑</system:String>
45+
<system:String x:Key="flowlauncher_plugin_everything_sort_by_descending">↓</system:String>
46+
47+
3048
<system:String x:Key="flowlauncher_plugin_everything_installing_title">Everything Installation</system:String>
3149
<system:String x:Key="flowlauncher_plugin_everything_installing_subtitle">Installing Everything service. Please wait...</system:String>
3250
<system:String x:Key="flowlauncher_plugin_everything_installationsuccess_subtitle">Successfully installed Everything service</system:String>

Main.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Droplex;
22
using Flow.Launcher.Plugin.Everything.Everything;
3+
using Flow.Launcher.Plugin.Everything.Helper;
34
using Flow.Launcher.Plugin.SharedCommands;
45
using System;
56
using System.Collections.Generic;
@@ -188,6 +189,8 @@ public void Init(PluginInitContext context)
188189
{
189190
_context = context;
190191
_settings = context.API.LoadSettingJsonStorage<Settings>();
192+
SortOptionTranlationHelper.API = context.API;
193+
191194
if (_settings.MaxSearchCount <= 0)
192195
_settings.MaxSearchCount = Settings.DefaultMaxSearchCount;
193196

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "Everything",
55
"Description": "Search Everything",
66
"Author": "qianlifeng,orzfly",
7-
"Version": "1.5.0",
7+
"Version": "1.5.1",
88
"Language": "csharp",
99
"Website": "https://github.com/Flow-Launcher/Flow.Launcher.Plugin.Everything",
1010
"IcoPath": "Images\\find.png",

0 commit comments

Comments
 (0)