2025-06-17 08:55:23 +00:00
|
|
|
|
using System.Linq;
|
2020-07-18 14:12:11 +00:00
|
|
|
|
using System.Windows;
|
2021-06-06 03:01:50 +00:00
|
|
|
|
using System.Windows.Input;
|
2025-06-17 08:55:23 +00:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
using Flow.Launcher.Plugin.Explorer.ViewModels;
|
2020-07-18 14:12:11 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Flow.Launcher.Plugin.Explorer.Views
|
|
|
|
|
|
{
|
2025-06-17 08:55:23 +00:00
|
|
|
|
[INotifyPropertyChanged]
|
|
|
|
|
|
public partial class ActionKeywordSetting
|
2020-07-18 14:12:11 +00:00
|
|
|
|
{
|
2022-12-04 07:47:48 +00:00
|
|
|
|
private ActionKeywordModel CurrentActionKeyword { get; }
|
2020-07-18 14:12:11 +00:00
|
|
|
|
|
2021-06-06 03:01:50 +00:00
|
|
|
|
public string ActionKeyword
|
|
|
|
|
|
{
|
2021-09-01 11:52:32 +00:00
|
|
|
|
get => actionKeyword;
|
2021-06-06 03:01:50 +00:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2026-03-10 05:40:25 +00:00
|
|
|
|
// Set Enable to be true only when the ActionKeyword value actually changes
|
|
|
|
|
|
if (SetProperty(ref actionKeyword, value))
|
|
|
|
|
|
KeywordEnabled = true;
|
2021-06-06 03:01:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-04 07:47:48 +00:00
|
|
|
|
public bool KeywordEnabled
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _keywordEnabled;
|
2025-06-17 08:55:23 +00:00
|
|
|
|
set => _ = SetProperty(ref _keywordEnabled, value);
|
2022-12-04 07:47:48 +00:00
|
|
|
|
}
|
2021-06-05 08:44:16 +00:00
|
|
|
|
|
2021-09-01 11:52:32 +00:00
|
|
|
|
private string actionKeyword;
|
2022-12-04 07:47:48 +00:00
|
|
|
|
private bool _keywordEnabled;
|
2021-06-02 01:10:24 +00:00
|
|
|
|
|
2025-09-21 03:50:51 +00:00
|
|
|
|
public ActionKeywordSetting(ActionKeywordModel selectedActionKeyword)
|
2020-07-18 14:12:11 +00:00
|
|
|
|
{
|
2021-06-02 01:10:24 +00:00
|
|
|
|
CurrentActionKeyword = selectedActionKeyword;
|
2026-03-10 05:40:25 +00:00
|
|
|
|
// Initialize backing fields directly to avoid triggering the auto-enable side-effect
|
|
|
|
|
|
actionKeyword = selectedActionKeyword.Keyword;
|
|
|
|
|
|
_keywordEnabled = selectedActionKeyword.Enabled;
|
2021-06-05 08:44:16 +00:00
|
|
|
|
|
2021-06-02 01:10:24 +00:00
|
|
|
|
InitializeComponent();
|
2021-05-30 09:28:18 +00:00
|
|
|
|
|
2021-06-06 03:01:50 +00:00
|
|
|
|
TxtCurrentActionKeyword.Focus();
|
2020-07-18 14:12:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-05 08:44:16 +00:00
|
|
|
|
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
|
2020-07-18 14:12:11 +00:00
|
|
|
|
{
|
2021-06-06 03:01:50 +00:00
|
|
|
|
if (string.IsNullOrEmpty(ActionKeyword))
|
|
|
|
|
|
ActionKeyword = Query.GlobalPluginWildcardSign;
|
|
|
|
|
|
|
2022-07-01 04:56:15 +00:00
|
|
|
|
if (CurrentActionKeyword.Keyword == ActionKeyword && CurrentActionKeyword.Enabled == KeywordEnabled)
|
2021-06-06 03:01:50 +00:00
|
|
|
|
{
|
2022-07-01 04:56:15 +00:00
|
|
|
|
DialogResult = false;
|
2021-06-06 03:01:50 +00:00
|
|
|
|
Close();
|
2020-07-18 14:12:11 +00:00
|
|
|
|
return;
|
2021-06-06 03:01:50 +00:00
|
|
|
|
}
|
2020-07-18 14:12:11 +00:00
|
|
|
|
|
2021-08-06 08:52:09 +00:00
|
|
|
|
if (ActionKeyword == Query.GlobalPluginWildcardSign)
|
2022-12-04 07:47:48 +00:00
|
|
|
|
switch (CurrentActionKeyword.KeywordProperty, KeywordEnabled)
|
2021-07-30 10:44:29 +00:00
|
|
|
|
{
|
2022-12-04 07:47:48 +00:00
|
|
|
|
case (Settings.ActionKeyword.FileContentSearchActionKeyword, true):
|
2025-09-21 03:50:51 +00:00
|
|
|
|
Main.Context.API.ShowMsgBox(Localize.plugin_explorer_globalActionKeywordInvalid());
|
2021-08-06 08:52:09 +00:00
|
|
|
|
return;
|
2022-12-04 07:47:48 +00:00
|
|
|
|
case (Settings.ActionKeyword.QuickAccessActionKeyword, true):
|
2025-09-21 03:50:51 +00:00
|
|
|
|
Main.Context.API.ShowMsgBox(Localize.plugin_explorer_quickaccess_globalActionKeywordInvalid());
|
2021-08-06 08:52:09 +00:00
|
|
|
|
return;
|
2021-07-30 10:44:29 +00:00
|
|
|
|
}
|
2020-08-25 22:06:10 +00:00
|
|
|
|
|
2025-09-21 03:50:51 +00:00
|
|
|
|
if (!KeywordEnabled || !Main.Context.API.ActionKeywordAssigned(ActionKeyword))
|
2021-06-06 03:01:50 +00:00
|
|
|
|
{
|
2022-07-01 04:56:15 +00:00
|
|
|
|
DialogResult = true;
|
2020-07-18 14:12:11 +00:00
|
|
|
|
Close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-06 03:01:50 +00:00
|
|
|
|
// The keyword is not valid, so show message
|
2025-09-21 03:50:51 +00:00
|
|
|
|
Main.Context.API.ShowMsgBox(Localize.plugin_explorer_new_action_keyword_assigned());
|
2021-06-06 03:01:50 +00:00
|
|
|
|
}
|
2020-07-18 14:12:11 +00:00
|
|
|
|
|
2021-12-06 02:59:21 +00:00
|
|
|
|
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2022-07-01 04:56:15 +00:00
|
|
|
|
DialogResult = false;
|
2021-12-06 02:59:21 +00:00
|
|
|
|
Close();
|
|
|
|
|
|
}
|
2025-04-17 03:37:30 +00:00
|
|
|
|
|
2021-06-06 03:01:50 +00:00
|
|
|
|
private void TxtCurrentActionKeyword_OnKeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.Key == Key.Enter)
|
|
|
|
|
|
{
|
|
|
|
|
|
DownButton.Focus();
|
|
|
|
|
|
OnDoneButtonClick(sender, e);
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
|
}
|
2025-04-11 04:23:17 +00:00
|
|
|
|
if (e.Key == Key.Space)
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-17 03:37:30 +00:00
|
|
|
|
|
2025-04-11 04:23:17 +00:00
|
|
|
|
private void TextBox_Pasting(object sender, DataObjectPastingEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.DataObject.GetDataPresent(DataFormats.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
string text = e.DataObject.GetData(DataFormats.Text) as string;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(text) && text.Any(char.IsWhiteSpace))
|
|
|
|
|
|
{
|
|
|
|
|
|
e.CancelCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
e.CancelCommand();
|
|
|
|
|
|
}
|
2020-07-18 14:12:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-12-04 07:47:48 +00:00
|
|
|
|
}
|