diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs index 7d96587f8..d7e588f1f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs @@ -1,5 +1,4 @@ -using Flow.Launcher.Core.Plugin; -using Flow.Launcher.Infrastructure.Storage; +#nullable enable using Flow.Launcher.Plugin.Explorer.Search; using Flow.Launcher.Plugin.Explorer.Search.Everything; using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions; @@ -11,7 +10,6 @@ using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; -using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; using System.Windows.Input; @@ -90,9 +88,9 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels ContentIndexSearchEngines = EnumBindingModel.CreateList(); PathEnumerationEngines = EnumBindingModel.CreateList(); - SelectedIndexSearchEngine = IndexSearchEngines.FirstOrDefault(x => x.Value == Settings.IndexSearchEngine); - _selectedContentSearchEngine = ContentIndexSearchEngines.FirstOrDefault(x => x.Value == Settings.ContentSearchEngine); - _selectedPathEnumerationEngine = PathEnumerationEngines.FirstOrDefault(x => x.Value == Settings.PathEnumerationEngine); + SelectedIndexSearchEngine = IndexSearchEngines.First(x => x.Value == Settings.IndexSearchEngine); + SelectedContentSearchEngine = ContentIndexSearchEngines.First(x => x.Value == Settings.ContentSearchEngine); + SelectedPathEnumerationEngine = PathEnumerationEngines.First(x => x.Value == Settings.PathEnumerationEngine); } #endregion @@ -120,13 +118,13 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels public IReadOnlyList ActionKeywordsModels { get; set; } - public ActionKeywordModel SelectedActionKeyword { get; set; } + public ActionKeywordModel? SelectedActionKeyword { get; set; } public ICommand EditActionKeywordCommand => new RelayCommand(EditActionKeyword); private void EditActionKeyword(object obj) { - if (SelectedActionKeyword is not ActionKeywordModel actionKeyword) + if (SelectedActionKeyword is not { } actionKeyword) { ShowUnselectedMessage(); return; @@ -150,7 +148,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels Context.API.AddActionKeyword(Context.CurrentPluginMetadata.ID, actionKeywordWindow.ActionKeyword); break; case (false, true): - Context.API.AddActionKeyword(Context.CurrentPluginMetadata.ID, actionKeyword.Keyword); + Context.API.AddActionKeyword(Context.CurrentPluginMetadata.ID, actionKeywordWindow.ActionKeyword); break; case (false, false): throw new ArgumentException( @@ -165,8 +163,8 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels #region AccessLinks - public AccessLink SelectedQuickAccessLink { get; set; } - public AccessLink SelectedIndexSearchExcludedPath { get; set; } + public AccessLink? SelectedQuickAccessLink { get; set; } + public AccessLink? SelectedIndexSearchExcludedPath { get; set; } @@ -187,7 +185,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels private void EditLink(object commandParameter) { - (AccessLink selectedLink, ObservableCollection collection) = commandParameter switch + var (selectedLink, collection) = commandParameter switch { "QuickAccessLink" => (SelectedQuickAccessLink, Settings.QuickAccessLinks), "IndexSearchExcludedPaths" => (SelectedIndexSearchExcludedPath, Settings.IndexSearchExcludedSubdirectoryPaths), @@ -266,9 +264,9 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels #endregion - private string? PromptUserSelectPath(ResultType type, string initialDirectory = null) + private string? PromptUserSelectPath(ResultType type, string? initialDirectory = null) { - string path = null; + string? path = null; if (type is ResultType.Folder) { diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml index 677ba5342..d42505348 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml @@ -77,8 +77,6 @@ Text="{DynamicResource plugin_explorer_actionkeyword_current}" /> diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs index 918adb527..6ee4faad8 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs @@ -2,7 +2,9 @@ using Flow.Launcher.Plugin.Explorer.ViewModels; using ICSharpCode.SharpZipLib.Zip; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; +using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Input; @@ -11,9 +13,9 @@ namespace Flow.Launcher.Plugin.Explorer.Views /// /// Interaction logic for ActionKeywordSetting.xaml /// - public partial class ActionKeywordSetting : Window + public partial class ActionKeywordSetting : INotifyPropertyChanged { - public ActionKeywordModel CurrentActionKeyword { get; set; } + private ActionKeywordModel CurrentActionKeyword { get; } public string ActionKeyword { @@ -22,14 +24,19 @@ namespace Flow.Launcher.Plugin.Explorer.Views { // Set Enable to be true if user change ActionKeyword KeywordEnabled = true; - actionKeyword = value; + _ = SetField(ref actionKeyword, value); } } - public bool KeywordEnabled { get; set; } + public bool KeywordEnabled + { + get => _keywordEnabled; + set => SetField(ref _keywordEnabled, value); + } private string actionKeyword; private readonly IPublicAPI api; + private bool _keywordEnabled; public ActionKeywordSetting(ActionKeywordModel selectedActionKeyword, IPublicAPI api) { @@ -55,18 +62,13 @@ namespace Flow.Launcher.Plugin.Explorer.Views return; } - if (ActionKeyword == "") - { - ActionKeyword = "*"; - } - if (ActionKeyword == Query.GlobalPluginWildcardSign) - switch (CurrentActionKeyword.KeywordProperty) + switch (CurrentActionKeyword.KeywordProperty, KeywordEnabled) { - case Settings.ActionKeyword.FileContentSearchActionKeyword: + case (Settings.ActionKeyword.FileContentSearchActionKeyword, true): MessageBox.Show(api.GetTranslation("plugin_explorer_globalActionKeywordInvalid")); return; - case Settings.ActionKeyword.QuickAccessActionKeyword: + case (Settings.ActionKeyword.QuickAccessActionKeyword, true): MessageBox.Show(api.GetTranslation("plugin_explorer_quickaccess_globalActionKeywordInvalid")); return; } @@ -96,5 +98,18 @@ namespace Flow.Launcher.Plugin.Explorer.Views e.Handled = true; } } + public event PropertyChangedEventHandler PropertyChanged; + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + private bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(field, value)) + return false; + field = value; + OnPropertyChanged(propertyName); + return true; + } } -} \ No newline at end of file +}