Skip to content

Commit 281f4db

Browse files
committed
fix enable not working at the first time (also refactor a little bit code)
1 parent 435144b commit 281f4db

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Flow.Launcher.Core.Plugin;
2-
using Flow.Launcher.Infrastructure.Storage;
1+
#nullable enable
32
using Flow.Launcher.Plugin.Explorer.Search;
43
using Flow.Launcher.Plugin.Explorer.Search.Everything;
54
using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions;
@@ -11,7 +10,6 @@
1110
using System.Diagnostics;
1211
using System.IO;
1312
using System.Linq;
14-
using System.Threading.Tasks;
1513
using System.Windows;
1614
using System.Windows.Forms;
1715
using System.Windows.Input;
@@ -90,9 +88,9 @@ private void InitializeEngineSelection()
9088
ContentIndexSearchEngines = EnumBindingModel<Settings.ContentIndexSearchEngineOption>.CreateList();
9189
PathEnumerationEngines = EnumBindingModel<Settings.PathEnumerationEngineOption>.CreateList();
9290

93-
SelectedIndexSearchEngine = IndexSearchEngines.FirstOrDefault(x => x.Value == Settings.IndexSearchEngine);
94-
_selectedContentSearchEngine = ContentIndexSearchEngines.FirstOrDefault(x => x.Value == Settings.ContentSearchEngine);
95-
_selectedPathEnumerationEngine = PathEnumerationEngines.FirstOrDefault(x => x.Value == Settings.PathEnumerationEngine);
91+
SelectedIndexSearchEngine = IndexSearchEngines.First(x => x.Value == Settings.IndexSearchEngine);
92+
SelectedContentSearchEngine = ContentIndexSearchEngines.First(x => x.Value == Settings.ContentSearchEngine);
93+
SelectedPathEnumerationEngine = PathEnumerationEngines.First(x => x.Value == Settings.PathEnumerationEngine);
9694
}
9795

9896
#endregion
@@ -120,13 +118,13 @@ private void InitializeActionKeywordModels()
120118

121119
public IReadOnlyList<ActionKeywordModel> ActionKeywordsModels { get; set; }
122120

123-
public ActionKeywordModel SelectedActionKeyword { get; set; }
121+
public ActionKeywordModel? SelectedActionKeyword { get; set; }
124122

125123
public ICommand EditActionKeywordCommand => new RelayCommand(EditActionKeyword);
126124

127125
private void EditActionKeyword(object obj)
128126
{
129-
if (SelectedActionKeyword is not ActionKeywordModel actionKeyword)
127+
if (SelectedActionKeyword is not { } actionKeyword)
130128
{
131129
ShowUnselectedMessage();
132130
return;
@@ -150,7 +148,7 @@ private void EditActionKeyword(object obj)
150148
Context.API.AddActionKeyword(Context.CurrentPluginMetadata.ID, actionKeywordWindow.ActionKeyword);
151149
break;
152150
case (false, true):
153-
Context.API.AddActionKeyword(Context.CurrentPluginMetadata.ID, actionKeyword.Keyword);
151+
Context.API.AddActionKeyword(Context.CurrentPluginMetadata.ID, actionKeywordWindow.ActionKeyword);
154152
break;
155153
case (false, false):
156154
throw new ArgumentException(
@@ -165,8 +163,8 @@ private void EditActionKeyword(object obj)
165163

166164
#region AccessLinks
167165

168-
public AccessLink SelectedQuickAccessLink { get; set; }
169-
public AccessLink SelectedIndexSearchExcludedPath { get; set; }
166+
public AccessLink? SelectedQuickAccessLink { get; set; }
167+
public AccessLink? SelectedIndexSearchExcludedPath { get; set; }
170168

171169

172170

@@ -187,7 +185,7 @@ public void AppendLink(string containerName, AccessLink link)
187185

188186
private void EditLink(object commandParameter)
189187
{
190-
(AccessLink selectedLink, ObservableCollection<AccessLink> collection) = commandParameter switch
188+
var (selectedLink, collection) = commandParameter switch
191189
{
192190
"QuickAccessLink" => (SelectedQuickAccessLink, Settings.QuickAccessLinks),
193191
"IndexSearchExcludedPaths" => (SelectedIndexSearchExcludedPath, Settings.IndexSearchExcludedSubdirectoryPaths),
@@ -266,9 +264,9 @@ private void RemoveLink(object obj)
266264

267265
#endregion
268266

269-
private string? PromptUserSelectPath(ResultType type, string initialDirectory = null)
267+
private string? PromptUserSelectPath(ResultType type, string? initialDirectory = null)
270268
{
271-
string path = null;
269+
string? path = null;
272270

273271
if (type is ResultType.Folder)
274272
{

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@
7777
Text="{DynamicResource plugin_explorer_actionkeyword_current}" />
7878
<TextBox
7979
Name="TxtCurrentActionKeyword"
80-
Grid.Row="0"
81-
Grid.Column="1"
8280
Width="135"
8381
HorizontalAlignment="Left"
8482
VerticalAlignment="Center"
@@ -97,7 +95,7 @@
9795
Name="ChkActionKeywordEnabled"
9896
Width="auto"
9997
VerticalAlignment="Center"
100-
IsChecked="{Binding KeywordEnabled}"
98+
IsChecked="{Binding KeywordEnabled, Mode=TwoWay}"
10199
ToolTip="{DynamicResource plugin_explorer_actionkeyword_enabled_tooltip}" />
102100
</StackPanel>
103101
</StackPanel>

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using ICSharpCode.SharpZipLib.Zip;
33
using System;
44
using System.Collections.Generic;
5+
using System.ComponentModel;
56
using System.Linq;
7+
using System.Runtime.CompilerServices;
68
using System.Windows;
79
using System.Windows.Input;
810

@@ -11,9 +13,9 @@ namespace Flow.Launcher.Plugin.Explorer.Views
1113
/// <summary>
1214
/// Interaction logic for ActionKeywordSetting.xaml
1315
/// </summary>
14-
public partial class ActionKeywordSetting : Window
16+
public partial class ActionKeywordSetting : INotifyPropertyChanged
1517
{
16-
public ActionKeywordModel CurrentActionKeyword { get; set; }
18+
private ActionKeywordModel CurrentActionKeyword { get; }
1719

1820
public string ActionKeyword
1921
{
@@ -22,14 +24,19 @@ public string ActionKeyword
2224
{
2325
// Set Enable to be true if user change ActionKeyword
2426
KeywordEnabled = true;
25-
actionKeyword = value;
27+
_ = SetField(ref actionKeyword, value);
2628
}
2729
}
2830

29-
public bool KeywordEnabled { get; set; }
31+
public bool KeywordEnabled
32+
{
33+
get => _keywordEnabled;
34+
set => SetField(ref _keywordEnabled, value);
35+
}
3036

3137
private string actionKeyword;
3238
private readonly IPublicAPI api;
39+
private bool _keywordEnabled;
3340

3441
public ActionKeywordSetting(ActionKeywordModel selectedActionKeyword, IPublicAPI api)
3542
{
@@ -55,18 +62,13 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
5562
return;
5663
}
5764

58-
if (ActionKeyword == "")
59-
{
60-
ActionKeyword = "*";
61-
}
62-
6365
if (ActionKeyword == Query.GlobalPluginWildcardSign)
64-
switch (CurrentActionKeyword.KeywordProperty)
66+
switch (CurrentActionKeyword.KeywordProperty, KeywordEnabled)
6567
{
66-
case Settings.ActionKeyword.FileContentSearchActionKeyword:
68+
case (Settings.ActionKeyword.FileContentSearchActionKeyword, true):
6769
MessageBox.Show(api.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
6870
return;
69-
case Settings.ActionKeyword.QuickAccessActionKeyword:
71+
case (Settings.ActionKeyword.QuickAccessActionKeyword, true):
7072
MessageBox.Show(api.GetTranslation("plugin_explorer_quickaccess_globalActionKeywordInvalid"));
7173
return;
7274
}
@@ -96,5 +98,18 @@ private void TxtCurrentActionKeyword_OnKeyDown(object sender, KeyEventArgs e)
9698
e.Handled = true;
9799
}
98100
}
101+
public event PropertyChangedEventHandler PropertyChanged;
102+
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
103+
{
104+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
105+
}
106+
private bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
107+
{
108+
if (EqualityComparer<T>.Default.Equals(field, value))
109+
return false;
110+
field = value;
111+
OnPropertyChanged(propertyName);
112+
return true;
113+
}
99114
}
100-
}
115+
}

0 commit comments

Comments
 (0)