diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs
index 0fed15fc4..77ec5457b 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs
@@ -44,30 +44,10 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
internal void UpdateActionKeyword(Settings.ActionKeyword modifiedActionKeyword, string newActionKeyword, string oldActionKeyword)
{
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
-
- switch (modifiedActionKeyword)
- {
- case Settings.ActionKeyword.SearchActionKeyword:
- Settings.SearchActionKeyword = newActionKeyword;
- break;
- case Settings.ActionKeyword.PathSearchActionKeyword:
- Settings.PathSearchActionKeyword = newActionKeyword;
- break;
- case Settings.ActionKeyword.FileContentSearchActionKeyword:
- Settings.FileContentSearchActionKeyword = newActionKeyword;
- break;
- case Settings.ActionKeyword.IndexSearchActionKeyword:
- Settings.IndexSearchActionKeyword = newActionKeyword;
- break;
- }
}
- internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword, string oldActionKeyword)
+ internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword)
{
- // PluginManager.ActionKeywordRegistered does not check global action keyword ('*'), so use this logic instead
- if (newActionKeyword == Query.GlobalPluginWildcardSign)
- return newActionKeyword == oldActionKeyword;
-
return PluginManager.ActionKeywordRegistered(newActionKeyword);
}
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml
index af67f1727..19ff624b0 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml
@@ -25,13 +25,15 @@
Margin="10" Grid.Row="0" Width="105" Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left"
- Text="{Binding CurrentActionKeyword.Keyword}" />
+ Text="{Binding ActionKeyword}"
+ PreviewKeyDown="TxtCurrentActionKeyword_OnKeyDown"/>
-
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs
index 24b00f956..5b733fe5c 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs
@@ -1,7 +1,10 @@
using Flow.Launcher.Plugin.Explorer.ViewModels;
+using ICSharpCode.SharpZipLib.Zip;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
+using System.Windows.Input;
namespace Flow.Launcher.Plugin.Explorer.Views
{
@@ -14,16 +17,28 @@ namespace Flow.Launcher.Plugin.Explorer.Views
public ActionKeywordView CurrentActionKeyword { get; set; }
- private string oldActionKeyword;
+ public string ActionKeyword
+ {
+ get => _actionKeyword;
+ set
+ {
+ // Set Enable to be true if user change ActionKeyword
+ if (Enabled is not null)
+ Enabled = true;
+ _actionKeyword = value;
+ }
+ }
+
+ public bool? Enabled { get; set; }
- private List actionKeywordListView;
private Settings settings;
+ private string _actionKeyword;
- public Visibility Visible => CurrentActionKeyword.Enabled is not null ? Visibility.Visible : Visibility.Collapsed;
+ public Visibility Visible =>
+ CurrentActionKeyword.Enabled is not null ? Visibility.Visible : Visibility.Collapsed;
public ActionKeywordSetting(SettingsViewModel settingsViewModel,
- List actionKeywordListView,
ActionKeywordView selectedActionKeyword, Settings settings)
{
this.settingsViewModel = settingsViewModel;
@@ -32,21 +47,31 @@ namespace Flow.Launcher.Plugin.Explorer.Views
CurrentActionKeyword = selectedActionKeyword;
- oldActionKeyword = selectedActionKeyword.Keyword;
+ ActionKeyword = selectedActionKeyword.Keyword;
+ Enabled = selectedActionKeyword.Enabled;
- this.actionKeywordListView = actionKeywordListView;
-
InitializeComponent();
+ TxtCurrentActionKeyword.Focus();
}
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
{
- if (string.IsNullOrEmpty(CurrentActionKeyword.Keyword))
- return;
+ if (string.IsNullOrEmpty(ActionKeyword))
+ ActionKeyword = Query.GlobalPluginWildcardSign;
- if (settingsViewModel.IsNewActionKeywordGlobal(CurrentActionKeyword.Keyword)
- && CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.FileContentSearchActionKeyword)
+ if (CurrentActionKeyword.Keyword == ActionKeyword && CurrentActionKeyword.Enabled == Enabled)
+ {
+ Close();
+ return;
+ }
+
+
+ if (CurrentActionKeyword is
+ {
+ Keyword: Query.GlobalPluginWildcardSign,
+ KeywordProperty: Settings.ActionKeyword.FileContentSearchActionKeyword
+ })
{
MessageBox.Show(
settingsViewModel.Context.API.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
@@ -54,38 +79,46 @@ namespace Flow.Launcher.Plugin.Explorer.Views
return;
}
- if (!settingsViewModel.IsActionKeywordAlreadyAssigned(CurrentActionKeyword.Keyword, oldActionKeyword))
+ var oldActionKeyword = CurrentActionKeyword.Keyword;
+
+
+ // == because of nullable
+ if (Enabled == false || !settingsViewModel.IsActionKeywordAlreadyAssigned(ActionKeyword))
{
- settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty, CurrentActionKeyword.Keyword, oldActionKeyword);
+ // Update View Data
+ CurrentActionKeyword.Keyword = ActionKeyword;
+ CurrentActionKeyword.Enabled = Enabled;
- actionKeywordListView.FirstOrDefault(x => x.Description == CurrentActionKeyword.Description).Keyword =
- CurrentActionKeyword.Keyword;
-
- // automatically help users set this to enabled if an action keyword is set and currently disabled
- if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.IndexSearchActionKeyword
- && !settings.EnabledIndexOnlySearchKeyword)
- settings.EnabledIndexOnlySearchKeyword = true;
-
- if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.PathSearchActionKeyword
- && !settings.EnabledPathSearchKeyword)
- settings.EnabledPathSearchKeyword = true;
-
- if (CurrentActionKeyword.KeywordProperty == Settings.ActionKeyword.SearchActionKeyword
- && !settings.EnableSearchActionKeyword)
- settings.EnableSearchActionKeyword = true;
+ switch (Enabled)
+ {
+ // reset to global so it does not take up an action keyword when disabled
+ // not for null Enable plugin
+ case false when oldActionKeyword != Query.GlobalPluginWildcardSign:
+ settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty,
+ Query.GlobalPluginWildcardSign, oldActionKeyword);
+ break;
+ default:
+ settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty,
+ CurrentActionKeyword.Keyword, oldActionKeyword);
+ break;
+ }
Close();
-
return;
}
- // reset to global so it does not take up an action keyword when disabled
- if (CurrentActionKeyword.Enabled is not null && CurrentActionKeyword.Enabled == false && CurrentActionKeyword.Keyword != Query.GlobalPluginWildcardSign)
- settingsViewModel.UpdateActionKeyword(CurrentActionKeyword.KeywordProperty, Query.GlobalPluginWildcardSign, oldActionKeyword);
+ // The keyword is not valid, so show message
+ MessageBox.Show(settingsViewModel.Context.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
+ }
- Close();
-
- return;
+ private void TxtCurrentActionKeyword_OnKeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.Key == Key.Enter)
+ {
+ DownButton.Focus();
+ OnDoneButtonClick(sender, e);
+ e.Handled = true;
+ }
}
}
}
\ No newline at end of file
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs
index 268261659..aa36f4b54 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml.cs
@@ -192,7 +192,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
{
var selectedActionKeyword = lbxActionKeywords.SelectedItem as ActionKeywordView;
- var actionKeywordWindow = new ActionKeywordSetting(viewModel, actionKeywordsListView,
+ var actionKeywordWindow = new ActionKeywordSetting(viewModel,
selectedActionKeyword, viewModel.Settings);
actionKeywordWindow.ShowDialog();