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

100 lines
3.1 KiB
C#
Raw Normal View History

2021-06-05 08:44:16 +00:00
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
{
/// <summary>
/// Interaction logic for ActionKeywordSetting.xaml
/// </summary>
public partial class ActionKeywordSetting : Window
{
public ActionKeywordModel CurrentActionKeyword { get; set; }
public string ActionKeyword
{
2021-09-01 11:52:32 +00:00
get => actionKeyword;
set
{
// Set Enable to be true if user change ActionKeyword
KeywordEnabled = true;
2021-09-01 11:52:32 +00:00
actionKeyword = value;
}
}
public bool KeywordEnabled { get; set; }
2021-06-05 08:44:16 +00:00
2021-09-01 11:52:32 +00:00
private string actionKeyword;
private readonly IPublicAPI api;
public ActionKeywordSetting(ActionKeywordModel selectedActionKeyword, IPublicAPI api)
{
CurrentActionKeyword = selectedActionKeyword;
this.api = api;
ActionKeyword = selectedActionKeyword.Keyword;
KeywordEnabled = selectedActionKeyword.Enabled;
2021-06-05 08:44:16 +00:00
InitializeComponent();
TxtCurrentActionKeyword.Focus();
}
2021-06-05 08:44:16 +00:00
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 == "")
{
ActionKeyword = "*";
}
2021-08-06 08:52:09 +00:00
if (ActionKeyword == Query.GlobalPluginWildcardSign)
2021-07-30 10:44:29 +00:00
switch (CurrentActionKeyword.KeywordProperty)
{
case Settings.ActionKeyword.FileContentSearchActionKeyword:
MessageBox.Show(api.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
2021-08-06 08:52:09 +00:00
return;
2021-07-30 10:44:29 +00:00
case Settings.ActionKeyword.QuickAccessActionKeyword:
MessageBox.Show(api.GetTranslation("plugin_explorer_quickaccess_globalActionKeywordInvalid"));
2021-08-06 08:52:09 +00:00
return;
2021-07-30 10:44:29 +00:00
}
if (!KeywordEnabled || !api.ActionKeywordAssigned(ActionKeyword))
{
DialogResult = true;
Close();
return;
}
// The keyword is not valid, so show message
MessageBox.Show(api.GetTranslation("newActionKeywordsHasBeenAssigned"));
}
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;
}
}
}
}