mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Support multiple action keywords
This commit is contained in:
parent
e1f1b97b7e
commit
abfeee1423
4 changed files with 39 additions and 16 deletions
|
|
@ -340,7 +340,12 @@ namespace Flow.Launcher.Core.Plugin
|
|||
return results;
|
||||
}
|
||||
|
||||
public static bool ActionKeywordRegistered(string actionKeyword)
|
||||
public static bool ActionKeywordRegistered(IReadOnlyList<string> actionKeywords)
|
||||
{
|
||||
return actionKeywords.Any(ActionKeywordRegistered);
|
||||
}
|
||||
|
||||
private static bool ActionKeywordRegistered(string actionKeyword)
|
||||
{
|
||||
// this method is only checking for action keywords (defined as not '*') registration
|
||||
// hence the actionKeyword != Query.GlobalPluginWildcardSign logic
|
||||
|
|
@ -385,19 +390,31 @@ namespace Flow.Launcher.Core.Plugin
|
|||
if (oldActionkeyword != Query.GlobalPluginWildcardSign)
|
||||
NonGlobalPlugins.Remove(oldActionkeyword);
|
||||
|
||||
|
||||
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
|
||||
}
|
||||
|
||||
public static void ReplaceActionKeyword(string id, string oldActionKeyword, string newActionKeyword)
|
||||
public static void ReplaceActionKeyword(string id, IReadOnlyList<string> oldActionKeyword, IReadOnlyList<string> newActionKeyword)
|
||||
{
|
||||
if (oldActionKeyword != newActionKeyword)
|
||||
if (CheckActionKeywordChanged(oldActionKeyword, newActionKeyword))
|
||||
{
|
||||
AddActionKeyword(id, newActionKeyword);
|
||||
RemoveActionKeyword(id, oldActionKeyword);
|
||||
foreach (var actionKeyword in newActionKeyword)
|
||||
{
|
||||
AddActionKeyword(id, actionKeyword);
|
||||
}
|
||||
foreach (var actionKeyword in oldActionKeyword)
|
||||
{
|
||||
RemoveActionKeyword(id, actionKeyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CheckActionKeywordChanged(IReadOnlyList<string> oldActionKeyword, IReadOnlyList<string> newActionKeyword)
|
||||
{
|
||||
if (oldActionKeyword.Count != newActionKeyword.Count)
|
||||
return true;
|
||||
return oldActionKeyword.Where((t, i) => t != newActionKeyword[i]).Any();
|
||||
}
|
||||
|
||||
private static string GetContainingFolderPathAfterUnzip(string unzippedParentFolderPath)
|
||||
{
|
||||
var unzippedFolderCount = Directory.GetDirectories(unzippedParentFolderPath).Length;
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ namespace Flow.Launcher.Plugin
|
|||
public const string TermSeparator = " ";
|
||||
|
||||
/// <summary>
|
||||
/// User can set multiple action keywords seperated by ';'
|
||||
/// User can set multiple action keywords seperated by whitespace
|
||||
/// </summary>
|
||||
public const string ActionKeywordSeparator = ";";
|
||||
public const string ActionKeywordSeparator = TermSeparator;
|
||||
|
||||
/// <summary>
|
||||
/// Wildcard action keyword. Plugins using this value will be queried on every search.
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using Flow.Launcher.Core.Resource;
|
|||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using Flow.Launcher.Core;
|
||||
using System.Linq;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
|
|
@ -32,13 +33,17 @@ namespace Flow.Launcher
|
|||
|
||||
private void btnDone_OnClick(object sender, RoutedEventArgs _)
|
||||
{
|
||||
var oldActionKeyword = plugin.Metadata.ActionKeywords[0];
|
||||
var newActionKeyword = tbAction.Text.Trim();
|
||||
newActionKeyword = newActionKeyword.Length > 0 ? newActionKeyword : "*";
|
||||
var oldActionKeywords = plugin.Metadata.ActionKeywords;
|
||||
|
||||
var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator).ToList();
|
||||
newActionKeywords.RemoveAll(string.IsNullOrEmpty);
|
||||
newActionKeywords = newActionKeywords.Distinct().ToList();
|
||||
|
||||
newActionKeywords = newActionKeywords.Count > 0 ? newActionKeywords : new() { Query.GlobalPluginWildcardSign };
|
||||
|
||||
if (!PluginViewModel.IsActionKeywordRegistered(newActionKeyword))
|
||||
if (!PluginViewModel.IsActionKeywordRegistered(newActionKeywords))
|
||||
{
|
||||
pluginViewModel.ChangeActionKeyword(newActionKeyword, oldActionKeyword);
|
||||
pluginViewModel.ChangeActionKeyword(newActionKeywords, oldActionKeywords);
|
||||
Close();
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Windows.Controls;
|
|||
using CommunityToolkit.Mvvm.Input;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Resources.Controls;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Flow.Launcher.ViewModel
|
||||
{
|
||||
|
|
@ -109,9 +110,9 @@ namespace Flow.Launcher.ViewModel
|
|||
public int Priority => PluginPair.Metadata.Priority;
|
||||
public Infrastructure.UserSettings.Plugin PluginSettingsObject { get; set; }
|
||||
|
||||
public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword)
|
||||
public void ChangeActionKeyword(IReadOnlyList<string> newActionKeywords, IReadOnlyList<string> oldActionKeywords)
|
||||
{
|
||||
PluginManager.ReplaceActionKeyword(PluginPair.Metadata.ID, oldActionKeyword, newActionKeyword);
|
||||
PluginManager.ReplaceActionKeyword(PluginPair.Metadata.ID, oldActionKeywords, newActionKeywords);
|
||||
OnPropertyChanged(nameof(ActionKeywordsText));
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +151,7 @@ namespace Flow.Launcher.ViewModel
|
|||
PluginManager.API.ShowMainWindow();
|
||||
}
|
||||
|
||||
public static bool IsActionKeywordRegistered(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
|
||||
public static bool IsActionKeywordRegistered(IReadOnlyList<string> newActionKeywords) => PluginManager.ActionKeywordRegistered(newActionKeywords);
|
||||
|
||||
[RelayCommand]
|
||||
private void SetActionKeywords()
|
||||
|
|
|
|||
Loading…
Reference in a new issue