mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
- Fix (false, false) case in EditActionKeyword to break gracefully instead of throwing ArgumentException. This handles the valid scenario where the user changes a disabled keyword's text but keeps it disabled. - Fix GetActiveActionKeywords to return an empty dictionary instead of null when actionKeywordStr is null/empty, preventing NullReferenceException. - Fix ActionKeyword setter to only auto-enable when the value actually changes, preventing unintended side-effects during construction. - Initialize ActionKeywordSetting backing fields directly in constructor to avoid the auto-enable triggering during initialization. - Change TextBox binding to UpdateSourceTrigger=PropertyChanged so the checkbox auto-enables as the user types (before they click the checkbox), fixing the checkbox toggle issue caused by LostFocus timing. Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com>
116 lines
3.8 KiB
C#
116 lines
3.8 KiB
C#
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Flow.Launcher.Plugin.Explorer.ViewModels;
|
|
|
|
namespace Flow.Launcher.Plugin.Explorer.Views
|
|
{
|
|
[INotifyPropertyChanged]
|
|
public partial class ActionKeywordSetting
|
|
{
|
|
private ActionKeywordModel CurrentActionKeyword { get; }
|
|
|
|
public string ActionKeyword
|
|
{
|
|
get => actionKeyword;
|
|
set
|
|
{
|
|
// Set Enable to be true only when the ActionKeyword value actually changes
|
|
if (SetProperty(ref actionKeyword, value))
|
|
KeywordEnabled = true;
|
|
}
|
|
}
|
|
|
|
public bool KeywordEnabled
|
|
{
|
|
get => _keywordEnabled;
|
|
set => _ = SetProperty(ref _keywordEnabled, value);
|
|
}
|
|
|
|
private string actionKeyword;
|
|
private bool _keywordEnabled;
|
|
|
|
public ActionKeywordSetting(ActionKeywordModel selectedActionKeyword)
|
|
{
|
|
CurrentActionKeyword = selectedActionKeyword;
|
|
// Initialize backing fields directly to avoid triggering the auto-enable side-effect
|
|
actionKeyword = selectedActionKeyword.Keyword;
|
|
_keywordEnabled = selectedActionKeyword.Enabled;
|
|
|
|
InitializeComponent();
|
|
|
|
TxtCurrentActionKeyword.Focus();
|
|
}
|
|
|
|
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(ActionKeyword))
|
|
ActionKeyword = Query.GlobalPluginWildcardSign;
|
|
|
|
if (CurrentActionKeyword.Keyword == ActionKeyword && CurrentActionKeyword.Enabled == KeywordEnabled)
|
|
{
|
|
DialogResult = false;
|
|
Close();
|
|
return;
|
|
}
|
|
|
|
if (ActionKeyword == Query.GlobalPluginWildcardSign)
|
|
switch (CurrentActionKeyword.KeywordProperty, KeywordEnabled)
|
|
{
|
|
case (Settings.ActionKeyword.FileContentSearchActionKeyword, true):
|
|
Main.Context.API.ShowMsgBox(Localize.plugin_explorer_globalActionKeywordInvalid());
|
|
return;
|
|
case (Settings.ActionKeyword.QuickAccessActionKeyword, true):
|
|
Main.Context.API.ShowMsgBox(Localize.plugin_explorer_quickaccess_globalActionKeywordInvalid());
|
|
return;
|
|
}
|
|
|
|
if (!KeywordEnabled || !Main.Context.API.ActionKeywordAssigned(ActionKeyword))
|
|
{
|
|
DialogResult = true;
|
|
Close();
|
|
return;
|
|
}
|
|
|
|
// The keyword is not valid, so show message
|
|
Main.Context.API.ShowMsgBox(Localize.plugin_explorer_new_action_keyword_assigned());
|
|
}
|
|
|
|
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
DialogResult = false;
|
|
Close();
|
|
}
|
|
|
|
private void TxtCurrentActionKeyword_OnKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Enter)
|
|
{
|
|
DownButton.Focus();
|
|
OnDoneButtonClick(sender, e);
|
|
e.Handled = true;
|
|
}
|
|
if (e.Key == Key.Space)
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|