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

Commit 4f0d310

Browse files
committed
switch non-Fast Sort search restriction to plugin setting warning
1 parent ab42600 commit 4f0d310

6 files changed

Lines changed: 89 additions & 38 deletions

File tree

Everything/EverythingAPI.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,16 @@ 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+
return fastSortOptionEnabled;
106+
}
107+
96108
/// <summary>
97109
/// Searches the specified key word and reset the everything API afterwards
98110
/// </summary>
@@ -124,12 +136,6 @@ public List<SearchResult> Search(string keyWord, CancellationToken token, SortOp
124136
EverythingApiDllImport.Everything_SetOffset(offset);
125137
EverythingApiDllImport.Everything_SetMax(maxCount);
126138

127-
var fastSortOptionEnabled = EverythingApiDllImport.Everything_IsFastSort(sortOption);
128-
CheckAndThrowExceptionOnError();
129-
130-
if(!fastSortOptionEnabled)
131-
throw new InvalidOperationException(Main._context.API.GetTranslation("flowlauncher_plugin_everything_fastsort_error"));
132-
133139
EverythingApiDllImport.Everything_SetSort(sortOption);
134140

135141
if (token.IsCancellationRequested)

EverythingSettings.xaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:helper="clr-namespace:Flow.Launcher.Plugin.Everything.Helper"
7+
xmlns:vm="clr-namespace:Flow.Launcher.Plugin.Everything.ViewModels"
78
mc:Ignorable="d"
89
Loaded="View_Loaded"
9-
DataContext="{Binding RelativeSource={RelativeSource Self}}"
1010
d:DesignHeight="300" d:DesignWidth="426.4">
1111
<Grid Margin="7,50" VerticalAlignment="Top" >
1212
<Grid.RowDefinitions>
@@ -51,13 +51,15 @@
5151
<TextBox Grid.Row="3" Grid.Column="2" HorizontalAlignment="Right"
5252
ToolTip="{DynamicResource flowlauncher_plugin_everything_customized_args_textbox}"
5353
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"/>
54+
<TextBlock Margin="10 15 10 10" Text="{DynamicResource flowlauncher_plugin_everything_sort_by}" Grid.Row="4"/>
5555

5656
<ComboBox Grid.Row="4"
5757
Grid.Column="1"
58-
Width="200"
59-
SelectedItem="{Binding _settings.SortOption}"
60-
ItemsSource="{Binding _settings.SortOptions, Mode=OneWay}">
58+
Width="200"
59+
Margin="0 10 0 0"
60+
SelectedItem="{Binding SortOption}"
61+
ItemsSource="{Binding GetSortOptions, Mode=OneWay}"
62+
SelectionChanged="onSelectionChange">
6163
<ComboBox.ItemTemplate>
6264
<DataTemplate>
6365
<Grid>
@@ -66,5 +68,10 @@
6668
</DataTemplate>
6769
</ComboBox.ItemTemplate>
6870
</ComboBox>
71+
72+
<TextBlock Name ="tbFastSortWarning" Grid.Row="4" Grid.Column="2" Margin="10 5 10 0" TextAlignment="Left"
73+
Text="{DynamicResource flowlauncher_plugin_everything_nonfastsort_warning}"
74+
Visibility ="{Binding FastSortWarningVisibility}"
75+
Foreground="Orange" TextWrapping="Wrap" />
6976
</Grid>
7077
</UserControl>

EverythingSettings.xaml.cs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,85 @@
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+
tbFastSortWarning.Visibility = vm.FastSortWarningVisibility;
7883
}
7984
}
8085
}

Languages/en.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
<system:String x:Key="flowlauncher_plugin_everything_is_not_running">Everything Service is not running</system:String>
66
<system:String x:Key="flowlauncher_plugin_everything_query_error">Error while querying Everything</system:String>
7-
<system:String x:Key="flowlauncher_plugin_everything_fastsort_error">Fast Sort option not enabled in Flow's Everything plugin settings, it may take a long time to finish the query</system:String>
87
<system:String x:Key="flowlauncher_plugin_everything_copied">Copied</system:String>
98
<system:String x:Key="flowlauncher_plugin_everything_canot_start">Can’t start {0}</system:String>
109
<system:String x:Key="flowlauncher_plugin_everything_open_containing_folder">Open parent folder</system:String>
@@ -44,7 +43,7 @@
4443
<system:String x:Key="flowlauncher_plugin_everything_sort_by_date_run">Date Run</system:String>
4544
<system:String x:Key="flowlauncher_plugin_everything_sort_by_ascending">↑</system:String>
4645
<system:String x:Key="flowlauncher_plugin_everything_sort_by_descending">↓</system:String>
47-
46+
<system:String x:Key="flowlauncher_plugin_everything_nonfastsort_warning">Warning: This is not a Fast Sort option, searches may be slow</system:String>
4847

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

Main.cs

Lines changed: 2 additions & 1 deletion
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;
@@ -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));
380381
}
381382
}
382383
}

ViewModels/SettingsViewModel.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 Settings settings;
11+
public SettingsViewModel(IEverythingApi api, Settings settings)
12+
{
13+
this.api = api;
14+
this.settings = settings;
15+
}
16+
17+
public Visibility FastSortWarningVisibility
18+
{
19+
get => api.IsFastSortOption(settings.SortOption)? Visibility.Hidden : Visibility.Visible;
20+
}
21+
22+
public SortOption[] GetSortOptions
23+
{
24+
get => settings.SortOptions;
25+
}
26+
27+
public SortOption SortOption
28+
{
29+
get => settings.SortOption;
30+
set => settings.SortOption = value;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)