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

Commit 12a930c

Browse files
authored
Merge pull request #35 from Flow-Launcher/fix_fastsort_incorrect_error
Fix incorrect error reporting from Fast Sort check
2 parents f26005c + c755435 commit 12a930c

7 files changed

Lines changed: 134 additions & 40 deletions

File tree

Everything/EverythingAPI.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Runtime.InteropServices;
44
using System.Text;
@@ -20,6 +20,8 @@ public interface IEverythingApi
2020
List<SearchResult> Search(string keyWord, CancellationToken token, SortOption sortOption = SortOption.NAME_ASCENDING, int offset = 0, int maxCount = 100);
2121

2222
void Load(string sdkPath);
23+
24+
bool IsFastSortOption(SortOption sortOption);
2325
}
2426

2527
public sealed class EverythingApi : IEverythingApi
@@ -93,6 +95,20 @@ private void Reset()
9395
}
9496
}
9597

98+
/// <summary>
99+
/// Checks whether the sort option is Fast Sort.
100+
/// </summary>
101+
public bool IsFastSortOption(SortOption sortOption)
102+
{
103+
var fastSortOptionEnabled = EverythingApiDllImport.Everything_IsFastSort(sortOption);
104+
105+
// If the Everything service is not running, then this call will incorrectly report
106+
// the state as false. This checks for errors thrown by the api and up to the caller to handle.
107+
CheckAndThrowExceptionOnError();
108+
109+
return fastSortOptionEnabled;
110+
}
111+
96112
/// <summary>
97113
/// Searches the specified key word and reset the everything API afterwards
98114
/// </summary>
@@ -123,11 +139,7 @@ public List<SearchResult> Search(string keyWord, CancellationToken token, SortOp
123139
EverythingApiDllImport.Everything_SetSearchW(keyWord);
124140
EverythingApiDllImport.Everything_SetOffset(offset);
125141
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-
}
142+
131143
EverythingApiDllImport.Everything_SetSort(sortOption);
132144

133145
if (token.IsCancellationRequested)

EverythingSettings.xaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
xmlns:helper="clr-namespace:Flow.Launcher.Plugin.Everything.Helper"
77
mc:Ignorable="d"
88
Loaded="View_Loaded"
9-
DataContext="{Binding RelativeSource={RelativeSource Self}}"
109
d:DesignHeight="300" d:DesignWidth="426.4">
1110
<Grid Margin="7,50" VerticalAlignment="Top" >
1211
<Grid.RowDefinitions>
@@ -51,13 +50,15 @@
5150
<TextBox Grid.Row="3" Grid.Column="2" HorizontalAlignment="Right"
5251
ToolTip="{DynamicResource flowlauncher_plugin_everything_customized_args_textbox}"
5352
Margin="0,0,5,0" Width="80" Height="35" x:Name="CustomizeArgsBox" TextChanged="CustomizeExplorerArgs"></TextBox>
54-
<TextBlock Margin="10" Text="{DynamicResource flowlauncher_plugin_everything_sort_by}" Grid.Row="4"/>
53+
<TextBlock Margin="10 15 10 10" Text="{DynamicResource flowlauncher_plugin_everything_sort_by}" Grid.Row="4"/>
5554

5655
<ComboBox Grid.Row="4"
5756
Grid.Column="1"
58-
Width="200"
59-
SelectedItem="{Binding _settings.SortOption}"
60-
ItemsSource="{Binding _settings.SortOptions, Mode=OneWay}">
57+
Width="200"
58+
Margin="0 10 0 0"
59+
SelectedItem="{Binding SortOption}"
60+
ItemsSource="{Binding GetSortOptions, Mode=OneWay}"
61+
SelectionChanged="onSelectionChange">
6162
<ComboBox.ItemTemplate>
6263
<DataTemplate>
6364
<Grid>
@@ -66,5 +67,10 @@
6667
</DataTemplate>
6768
</ComboBox.ItemTemplate>
6869
</ComboBox>
70+
71+
<TextBlock Name ="tbFastSortWarning" Grid.Row="4" Grid.Column="2" Margin="10 5 10 0" TextAlignment="Left"
72+
Text="{Binding GetSortOptionWarningMessage}"
73+
Visibility ="{Binding FastSortWarningVisibility}"
74+
Foreground="Orange" TextWrapping="Wrap" />
6975
</Grid>
7076
</UserControl>

EverythingSettings.xaml.cs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,88 @@
11
using System.Windows;
22
using System.Windows.Controls;
3-
using Flow.Launcher.Plugin.Everything.Everything;
3+
using Flow.Launcher.Plugin.Everything.ViewModels;
44
using Microsoft.Win32;
55

66
namespace Flow.Launcher.Plugin.Everything
77
{
88
public partial class EverythingSettings : UserControl
99
{
10-
public Settings _settings { get; }
10+
public Settings settings { get; }
1111

12-
public SortOption SortOption { get; set; }
13-
public SortOption[] SortOptions { get; set; }
12+
private SettingsViewModel vm;
1413

15-
public EverythingSettings(Settings settings)
14+
public EverythingSettings(Settings settings, SettingsViewModel vm)
1615
{
17-
_settings = settings;
18-
SortOption = settings.SortOption;
19-
SortOptions = settings.SortOptions;
20-
DataContext = this;
16+
this.settings = settings;
17+
this.vm = vm;
18+
DataContext = vm;
2119
InitializeComponent();
2220
}
2321

2422
private void View_Loaded(object sender, RoutedEventArgs re)
2523
{
26-
UseLocationAsWorkingDir.IsChecked = _settings.UseLocationAsWorkingDir;
24+
UseLocationAsWorkingDir.IsChecked = settings.UseLocationAsWorkingDir;
2725

2826
UseLocationAsWorkingDir.Checked += (o, e) =>
2927
{
30-
_settings.UseLocationAsWorkingDir = true;
28+
settings.UseLocationAsWorkingDir = true;
3129
};
3230

3331
UseLocationAsWorkingDir.Unchecked += (o, e) =>
3432
{
35-
_settings.UseLocationAsWorkingDir = false;
33+
settings.UseLocationAsWorkingDir = false;
3634
};
3735

38-
LaunchHidden.IsChecked = _settings.LaunchHidden;
36+
LaunchHidden.IsChecked = settings.LaunchHidden;
3937

4038
LaunchHidden.Checked += (o, e) =>
4139
{
42-
_settings.LaunchHidden = true;
40+
settings.LaunchHidden = true;
4341
};
4442

4543
LaunchHidden.Unchecked += (o, e) =>
4644
{
47-
_settings.LaunchHidden = false;
45+
settings.LaunchHidden = false;
4846
};
4947

50-
EditorPath.Content = _settings.EditorPath;
51-
CustomizeExplorerBox.Text = _settings.ExplorerPath;
52-
CustomizeArgsBox.Text = _settings.ExplorerArgs;
48+
EditorPath.Content = settings.EditorPath;
49+
CustomizeExplorerBox.Text = settings.ExplorerPath;
50+
CustomizeArgsBox.Text = settings.ExplorerArgs;
5351
}
5452

5553
private void EditorPath_Clicked(object sender, RoutedEventArgs e)
5654
{
5755
OpenFileDialog openFileDialog = new OpenFileDialog();
5856
openFileDialog.Filter = "Executable File(*.exe)| *.exe";
59-
if (!string.IsNullOrEmpty(_settings.EditorPath))
60-
openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(_settings.EditorPath);
57+
if (!string.IsNullOrEmpty(settings.EditorPath))
58+
openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(settings.EditorPath);
6159

6260
if (openFileDialog.ShowDialog() == true)
6361
{
64-
_settings.EditorPath = openFileDialog.FileName;
62+
settings.EditorPath = openFileDialog.FileName;
6563
}
6664

67-
EditorPath.Content = _settings.EditorPath;
65+
EditorPath.Content = settings.EditorPath;
6866
}
6967

7068
private void CustomizeExplorer(object sender, TextChangedEventArgs e)
7169
{
72-
_settings.ExplorerPath = CustomizeExplorerBox.Text;
70+
settings.ExplorerPath = CustomizeExplorerBox.Text;
7371
}
7472

7573
private void CustomizeExplorerArgs(object sender, TextChangedEventArgs e)
7674
{
77-
_settings.ExplorerArgs = CustomizeArgsBox.Text;
75+
settings.ExplorerArgs = CustomizeArgsBox.Text;
76+
}
77+
78+
private void onSelectionChange(object sender, SelectionChangedEventArgs e)
79+
{
80+
// on load, tbFastSortWarning control will not have been loaded yet
81+
if (tbFastSortWarning is not null)
82+
{
83+
tbFastSortWarning.Visibility = vm.FastSortWarningVisibility;
84+
tbFastSortWarning.Text = vm.GetSortOptionWarningMessage;
85+
}
7886
}
7987
}
8088
}

Languages/en.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:system="clr-namespace:System;assembly=mscorlib">
44

5-
<system:String x:Key="flowlauncher_plugin_everything_is_not_running">Everything Service is not running</system:String>
5+
<system:String x:Key="flowlauncher_plugin_everything_is_not_running">Warning: Everything service is not running</system:String>
66
<system:String x:Key="flowlauncher_plugin_everything_query_error">Error while querying Everything</system:String>
77
<system:String x:Key="flowlauncher_plugin_everything_copied">Copied</system:String>
88
<system:String x:Key="flowlauncher_plugin_everything_canot_start">Can’t start {0}</system:String>
@@ -43,7 +43,7 @@
4343
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_run">Date Run</system:String>
4444
<system:String x:Key="flowlauncher_plugin_everything_sort_by_ascending">↑</system:String>
4545
<system:String x:Key="flowlauncher_plugin_everything_sort_by_descending">↓</system:String>
46-
46+
<system:String x:Key="flowlauncher_plugin_everything_nonfastsort_warning">Warning: This is not a Fast Sort option, searches may be slow</system:String>
4747

4848
<system:String x:Key="flowlauncher_plugin_everything_installing_title">Everything Installation</system:String>
4949
<system:String x:Key="flowlauncher_plugin_everything_installing_subtitle">Installing Everything service. Please wait...</system:String>

Main.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Droplex;
22
using Flow.Launcher.Plugin.Everything.Everything;
33
using Flow.Launcher.Plugin.Everything.Helper;
4+
using Flow.Launcher.Plugin.Everything.ViewModels;
45
using Flow.Launcher.Plugin.SharedCommands;
56
using System;
67
using System.Collections.Generic;
@@ -19,7 +20,7 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu
1920
public const string DLL = "Everything.dll";
2021
private readonly IEverythingApi _api = new EverythingApi();
2122

22-
private PluginInitContext _context;
23+
internal static PluginInitContext _context;
2324

2425
private Settings _settings;
2526
private CancellationTokenSource _cancellationTokenSource;
@@ -376,7 +377,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
376377

377378
public Control CreateSettingPanel()
378379
{
379-
return new EverythingSettings(_settings);
380+
return new EverythingSettings(_settings, new SettingsViewModel(_api, _settings, _context));
380381
}
381382
}
382383
}

ViewModels/SettingsViewModel.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Flow.Launcher.Plugin.Everything.Everything;
2+
using System.Windows;
3+
4+
namespace Flow.Launcher.Plugin.Everything.ViewModels
5+
{
6+
public class SettingsViewModel
7+
{
8+
private readonly IEverythingApi api;
9+
10+
private readonly PluginInitContext context;
11+
12+
private Settings settings;
13+
14+
public SettingsViewModel(IEverythingApi api, Settings settings, PluginInitContext context)
15+
{
16+
this.api = api;
17+
this.settings = settings;
18+
this.context = context;
19+
}
20+
21+
public Visibility FastSortWarningVisibility
22+
{
23+
get
24+
{
25+
try
26+
{
27+
return api.IsFastSortOption(settings.SortOption) ? Visibility.Hidden : Visibility.Visible;
28+
}
29+
catch (IPCErrorException)
30+
{
31+
// this error occurs if the Everything service is not running, in this instance show the warning and
32+
// update the message to let user know in the settings panel.
33+
return Visibility.Visible;
34+
}
35+
}
36+
}
37+
38+
public string GetSortOptionWarningMessage
39+
{
40+
get
41+
{
42+
try
43+
{
44+
// this method is used to determine if Everything service is running because as at Everything v1.4.1
45+
// the sdk does not provide a dedicated interface to determine if it is running.
46+
return api.IsFastSortOption(settings.SortOption) ? string.Empty
47+
: context.API.GetTranslation("flowlauncher_plugin_everything_nonfastsort_warning");
48+
}
49+
catch (IPCErrorException)
50+
{
51+
return context.API.GetTranslation("flowlauncher_plugin_everything_is_not_running");
52+
}
53+
}
54+
}
55+
56+
public SortOption[] GetSortOptions
57+
{
58+
get => settings.SortOptions;
59+
}
60+
61+
public SortOption SortOption
62+
{
63+
get => settings.SortOption;
64+
set => settings.SortOption = value;
65+
}
66+
}
67+
}

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.3",
7+
"Version": "1.5.4",
88
"Language": "csharp",
99
"Website": "https://github.com/Flow-Launcher/Flow.Launcher.Plugin.Everything",
1010
"IcoPath": "Images\\find.png",

0 commit comments

Comments
 (0)