mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Remove ReplaceActionKeyword api function & Add action keyword same noticification
This commit is contained in:
parent
38402848aa
commit
6e763f0c3b
7 changed files with 57 additions and 77 deletions
|
|
@ -364,8 +364,16 @@ namespace Flow.Launcher.Core.Plugin
|
|||
NonGlobalPlugins[newActionKeyword] = plugin;
|
||||
}
|
||||
|
||||
// Update action keywords in plugin metadata
|
||||
// Update action keywords and action keyword in plugin metadata
|
||||
plugin.Metadata.ActionKeywords.Add(newActionKeyword);
|
||||
if (plugin.Metadata.ActionKeywords.Count > 0)
|
||||
{
|
||||
plugin.Metadata.ActionKeyword = plugin.Metadata.ActionKeywords[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.Metadata.ActionKeyword = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -386,67 +394,15 @@ namespace Flow.Launcher.Core.Plugin
|
|||
if (oldActionkeyword != Query.GlobalPluginWildcardSign)
|
||||
NonGlobalPlugins.Remove(oldActionkeyword);
|
||||
|
||||
// Update action keywords in plugin metadata
|
||||
// Update action keywords and action keyword in plugin metadata
|
||||
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
|
||||
}
|
||||
|
||||
public static void ReplaceActionKeyword(string id, IReadOnlyList<string> oldActionKeywords, IReadOnlyList<string> newActionKeywords)
|
||||
{
|
||||
if (CheckActionKeywordChanged(oldActionKeywords, newActionKeywords))
|
||||
if (plugin.Metadata.ActionKeywords.Count > 0)
|
||||
{
|
||||
// Fix collection modified while iterating exception
|
||||
var oldActionKeywordsClone = oldActionKeywords.ToList();
|
||||
foreach (var actionKeyword in oldActionKeywordsClone)
|
||||
{
|
||||
RemoveActionKeyword(id, actionKeyword);
|
||||
}
|
||||
foreach (var actionKeyword in newActionKeywords)
|
||||
{
|
||||
AddActionKeyword(id, actionKeyword);
|
||||
}
|
||||
|
||||
// Update action keyword in plugin metadata
|
||||
var plugin = GetPluginForId(id);
|
||||
if (newActionKeywords.Count > 0)
|
||||
{
|
||||
plugin.Metadata.ActionKeyword = newActionKeywords[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.Metadata.ActionKeyword = string.Empty;
|
||||
}
|
||||
plugin.Metadata.ActionKeyword = plugin.Metadata.ActionKeywords[0];
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CheckActionKeywordChanged(IReadOnlyList<string> oldActionKeywords, IReadOnlyList<string> newActionKeywords)
|
||||
{
|
||||
if (oldActionKeywords.Count != newActionKeywords.Count)
|
||||
return true;
|
||||
|
||||
var sortedOldActionKeywords = oldActionKeywords.OrderBy(s => s).ToList();
|
||||
var sortedNewActionKeywords = newActionKeywords.OrderBy(s => s).ToList();
|
||||
|
||||
return !sortedOldActionKeywords.SequenceEqual(sortedNewActionKeywords);
|
||||
}
|
||||
|
||||
public static void ReplaceActionKeyword(string id, string oldActionKeyword, string newActionKeyword)
|
||||
{
|
||||
if (oldActionKeyword != newActionKeyword)
|
||||
else
|
||||
{
|
||||
RemoveActionKeyword(id, oldActionKeyword);
|
||||
AddActionKeyword(id, newActionKeyword);
|
||||
|
||||
// Update action keyword in plugin metadata
|
||||
var plugin = GetPluginForId(id);
|
||||
var newActionKeywords = plugin.Metadata.ActionKeywords;
|
||||
if (newActionKeywords.Count > 0)
|
||||
{
|
||||
plugin.Metadata.ActionKeyword = newActionKeywords[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.Metadata.ActionKeyword = string.Empty;
|
||||
}
|
||||
plugin.Metadata.ActionKeyword = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -189,14 +189,14 @@ namespace Flow.Launcher.Plugin
|
|||
Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, Action<double> reportProgress = null, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Add ActionKeyword for specific plugin
|
||||
/// Add ActionKeyword and update action keyword metadata for specific plugin
|
||||
/// </summary>
|
||||
/// <param name="pluginId">ID for plugin that needs to add action keyword</param>
|
||||
/// <param name="newActionKeyword">The actionkeyword that is supposed to be added</param>
|
||||
void AddActionKeyword(string pluginId, string newActionKeyword);
|
||||
|
||||
/// <summary>
|
||||
/// Remove ActionKeyword for specific plugin
|
||||
/// Remove ActionKeyword and update action keyword metadata for specific plugin
|
||||
/// </summary>
|
||||
/// <param name="pluginId">ID for plugin that needs to remove action keyword</param>
|
||||
/// <param name="oldActionKeyword">The actionkeyword that is supposed to be removed</param>
|
||||
|
|
@ -333,13 +333,5 @@ namespace Flow.Launcher.Plugin
|
|||
/// <param name="forceClosed">When user closes the progress box manually by button or esc key, this action will be called.</param>
|
||||
/// <returns>A progress box interface.</returns>
|
||||
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null);
|
||||
|
||||
/// <summary>
|
||||
/// Replace ActionKeyword for specific plugin
|
||||
/// </summary>
|
||||
/// <param name="pluginId">ID for plugin that needs to remove action keyword</param>
|
||||
/// <param name="oldActionKeyword">The actionkeyword that is supposed to be removed</param>
|
||||
/// <param name="newActionKeyword">The actionkeyword that is supposed to be added</param>
|
||||
public void ReplaceActionKeyword(string pluginId, string oldActionKeyword, string newActionKeyword);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,8 +45,24 @@ namespace Flow.Launcher
|
|||
|
||||
if (!newActionKeywords.Except(oldActionKeywords).Any(PluginManager.ActionKeywordRegistered))
|
||||
{
|
||||
pluginViewModel.ChangeActionKeyword(newActionKeywords, oldActionKeywords);
|
||||
Close();
|
||||
if (oldActionKeywords.Count != newActionKeywords.Count)
|
||||
{
|
||||
ReplaceActionKeyword(plugin.Metadata.ID, oldActionKeywords, newActionKeywords);
|
||||
}
|
||||
|
||||
var sortedOldActionKeywords = oldActionKeywords.OrderBy(s => s).ToList();
|
||||
var sortedNewActionKeywords = newActionKeywords.OrderBy(s => s).ToList();
|
||||
|
||||
if (sortedOldActionKeywords.SequenceEqual(sortedNewActionKeywords))
|
||||
{
|
||||
// User just changes the sequence of action keywords
|
||||
var msg = translater.GetTranslation("newActionKeywordsSameAsOld");
|
||||
MessageBoxEx.Show(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReplaceActionKeyword(plugin.Metadata.ID, oldActionKeywords, newActionKeywords);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -54,5 +70,24 @@ namespace Flow.Launcher
|
|||
MessageBoxEx.Show(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReplaceActionKeyword(string id, IReadOnlyList<string> oldActionKeywords, IReadOnlyList<string> newActionKeywords)
|
||||
{
|
||||
// Because add & remove action keyword will change action keyword metadata,
|
||||
// so we need to clone it to fix collection modified while iterating exception
|
||||
var oldActionKeywordsClone = oldActionKeywords.ToList();
|
||||
foreach (var actionKeyword in oldActionKeywordsClone)
|
||||
{
|
||||
PluginManager.RemoveActionKeyword(id, actionKeyword);
|
||||
}
|
||||
foreach (var actionKeyword in newActionKeywords)
|
||||
{
|
||||
PluginManager.AddActionKeyword(id, actionKeyword);
|
||||
}
|
||||
|
||||
// Update action keywords text and close
|
||||
pluginViewModel.OnActionKeywordsChanged();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -333,6 +333,7 @@
|
|||
<system:String x:Key="cannotFindSpecifiedPlugin">Can't find specified plugin</system:String>
|
||||
<system:String x:Key="newActionKeywordsCannotBeEmpty">New Action Keyword can't be empty</system:String>
|
||||
<system:String x:Key="newActionKeywordsHasBeenAssigned">This new Action Keyword is already assigned to another plugin, please choose a different one</system:String>
|
||||
<system:String x:Key="newActionKeywordsSameAsOld">This new Action Keyword is the same as old, please choose a different one</system:String>
|
||||
<system:String x:Key="success">Success</system:String>
|
||||
<system:String x:Key="completedSuccessfully">Completed successfully</system:String>
|
||||
<system:String x:Key="actionkeyword_tips">Enter the action keywords you like to use to start the plugin and use whitespace to divide them. Use * if you don't want to specify any, and the plugin will be triggered without any action keywords.</system:String>
|
||||
|
|
|
|||
|
|
@ -326,8 +326,6 @@ namespace Flow.Launcher
|
|||
|
||||
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action forceClosed = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, forceClosed);
|
||||
|
||||
public void ReplaceActionKeyword(string pluginId, string oldActionKeyword, string newActionKeyword) => PluginManager.ReplaceActionKeyword(pluginId, oldActionKeyword, newActionKeyword);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
|
|
|||
|
|
@ -110,9 +110,8 @@ namespace Flow.Launcher.ViewModel
|
|||
public int Priority => PluginPair.Metadata.Priority;
|
||||
public Infrastructure.UserSettings.Plugin PluginSettingsObject { get; set; }
|
||||
|
||||
public void ChangeActionKeyword(IReadOnlyList<string> newActionKeywords, IReadOnlyList<string> oldActionKeywords)
|
||||
public void OnActionKeywordsChanged()
|
||||
{
|
||||
PluginManager.ReplaceActionKeyword(PluginPair.Metadata.ID, oldActionKeywords, newActionKeywords);
|
||||
OnPropertyChanged(nameof(ActionKeywordsText));
|
||||
}
|
||||
|
||||
|
|
@ -158,5 +157,4 @@ namespace Flow.Launcher.ViewModel
|
|||
changeKeywordsWindow.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
private SearchSourceViewModel _viewModel;
|
||||
private string selectedNewIconImageFullPath;
|
||||
|
||||
|
||||
public SearchSourceSettingWindow(IList<SearchSource> sources, PluginInitContext context, SearchSource old)
|
||||
{
|
||||
_oldSearchSource = old;
|
||||
|
|
@ -102,7 +101,8 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
if (!_context.API.ActionKeywordAssigned(newKeyword) || oldKeyword == newKeyword)
|
||||
{
|
||||
var id = _context.CurrentPluginMetadata.ID;
|
||||
_context.API.ReplaceActionKeyword(id, oldKeyword, newKeyword);
|
||||
_context.API.RemoveActionKeyword(id, oldKeyword);
|
||||
_context.API.AddActionKeyword(id, newKeyword);
|
||||
|
||||
var index = _searchSources.IndexOf(_oldSearchSource);
|
||||
_searchSources[index] = _searchSource;
|
||||
|
|
|
|||
Loading…
Reference in a new issue