Fix setting for multiple action keywords

1. completed rewrite the action keyword setting logic.
2. Fix setting for multiple action keywords in #352
3. Fix setting for Web Search plugin
This commit is contained in:
bao-qian
2015-11-09 03:20:02 +00:00
parent da5a930e89
commit 8aee2858ea
14 changed files with 1286 additions and 174 deletions

View File

@@ -7,10 +7,10 @@ using System.Threading;
using Wox.Core.i18n;
using Wox.Core.UI;
using Wox.Core.UserSettings;
using Wox.Infrastructure;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace Wox.Core.Plugin
{
@@ -56,7 +56,7 @@ namespace Wox.Core.Plugin
{
Directory.CreateDirectory(pluginDirectory);
}
catch (System.Exception e)
catch (Exception e)
{
Log.Error(e);
}
@@ -196,7 +196,7 @@ namespace Wox.Core.Plugin
pair.AvgQueryTime = pair.QueryCount == 1 ? milliseconds : (pair.AvgQueryTime + milliseconds) / 2;
API.PushResults(query, pair.Metadata, results);
}
catch (System.Exception e)
catch (Exception e)
{
throw new WoxPluginException(pair.Metadata.Name, $"QueryForPlugin failed", e);
}
@@ -240,7 +240,7 @@ namespace Wox.Core.Plugin
{
return plugin.LoadContextMenus(result);
}
catch (System.Exception e)
catch (Exception e)
{
Log.Error(new WoxPluginException(pluginPair.Metadata.Name, $"Couldn't load plugin context menus", e));
}
@@ -248,5 +248,58 @@ namespace Wox.Core.Plugin
return new List<Result>();
}
public static void UpdateActionKeywordForPlugin(PluginPair plugin, string oldActionKeyword, string newActionKeyword)
{
var actionKeywords = plugin.Metadata.ActionKeywords;
if (string.IsNullOrEmpty(newActionKeyword))
{
string msg = InternationalizationManager.Instance.GetTranslation("newActionKeywordsCannotBeEmpty");
throw new WoxPluginException(plugin.Metadata.Name, msg);
}
if (NonGlobalPlugins.ContainsKey(newActionKeyword))
{
string msg = InternationalizationManager.Instance.GetTranslation("newActionKeywordsHasBeenAssigned");
throw new WoxPluginException(plugin.Metadata.Name, msg);
}
// add new action keyword
if (string.IsNullOrEmpty(oldActionKeyword))
{
actionKeywords.Add(newActionKeyword);
if (newActionKeyword == Query.GlobalPluginWildcardSign)
{
GlobalPlugins.Add(plugin);
}
else
{
NonGlobalPlugins[newActionKeyword] = plugin;
}
}
// update existing action keyword
else
{
int index = actionKeywords.IndexOf(oldActionKeyword);
actionKeywords[index] = newActionKeyword;
if (oldActionKeyword == Query.GlobalPluginWildcardSign)
{
GlobalPlugins.Remove(plugin);
}
else
{
NonGlobalPlugins.Remove(oldActionKeyword);
}
if (newActionKeyword == Query.GlobalPluginWildcardSign)
{
GlobalPlugins.Add(plugin);
}
else
{
NonGlobalPlugins[newActionKeyword] = plugin;
}
}
}
}
}

View File

@@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
namespace Wox.Core.UserSettings
{
@@ -118,7 +120,7 @@ namespace Wox.Core.UserSettings
public void IncreaseActivateTimes()
{
ActivateTimes++;
if (ActivateTimes%15 == 0)
if (ActivateTimes % 15 == 0)
{
Save();
}
@@ -162,6 +164,26 @@ namespace Wox.Core.UserSettings
storage.Language = "en";
}
}
public void UpdateActionKeyword(PluginMetadata metadata)
{
var customizedPluginConfig = CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID);
if (customizedPluginConfig == null)
{
CustomizedPluginConfigs.Add(new CustomizedPluginConfig()
{
Disabled = false,
ID = metadata.ID,
Name = metadata.Name,
ActionKeywords = metadata.ActionKeywords
});
}
else
{
customizedPluginConfig.ActionKeywords = metadata.ActionKeywords;
}
Save();
}
}
public enum OpacityMode