#21 Add Disable option for each plugin.

This commit is contained in:
qianlifeng 2014-07-01 22:19:46 +08:00
parent 6352408d87
commit e275ce6063
20 changed files with 174 additions and 13 deletions

View File

@ -15,6 +15,14 @@ namespace Wox.Infrastructure.Storage
private static object locker = new object(); private static object locker = new object();
private static T storage; private static T storage;
public event Action<T> AfterLoadConfig;
protected virtual void OnAfterLoadConfig(T obj)
{
Action<T> handler = AfterLoadConfig;
if (handler != null) handler(obj);
}
protected abstract string ConfigName { get; } protected abstract string ConfigName { get; }
public static T Instance public static T Instance
@ -53,6 +61,7 @@ namespace Wox.Infrastructure.Storage
try try
{ {
storage = JsonConvert.DeserializeObject<T>(json); storage = JsonConvert.DeserializeObject<T>(json);
OnAfterLoadConfig(storage);
} }
catch (Exception) catch (Exception)
{ {

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.Infrastructure.Storage.UserSettings
{
public class CustomizedPluginConfig
{
public string ID { get; set; }
public string Name { get; set; }
public string Actionword { get; set; }
public bool Disabled { get; set; }
}
}

View File

@ -56,6 +56,8 @@ namespace Wox.Infrastructure.Storage.UserSettings
[JsonProperty] [JsonProperty]
public List<FolderLink> FolderLinks { get; set; } //Aaron public List<FolderLink> FolderLinks { get; set; } //Aaron
public List<CustomizedPluginConfig> CustomizedPluginConfigs { get; set; }
[JsonProperty] [JsonProperty]
public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; } public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; }
@ -147,6 +149,7 @@ namespace Wox.Infrastructure.Storage.UserSettings
ReplaceWinR = true; ReplaceWinR = true;
WebSearches = LoadDefaultWebSearches(); WebSearches = LoadDefaultWebSearches();
ProgramSources = LoadDefaultProgramSources(); ProgramSources = LoadDefaultProgramSources();
CustomizedPluginConfigs = new List<CustomizedPluginConfig>();
Hotkey = "Alt + Space"; Hotkey = "Alt + Space";
QueryBoxFont = FontFamily.GenericSansSerif.Name; QueryBoxFont = FontFamily.GenericSansSerif.Name;
ResultItemFont = FontFamily.GenericSansSerif.Name; ResultItemFont = FontFamily.GenericSansSerif.Name;
@ -156,6 +159,13 @@ namespace Wox.Infrastructure.Storage.UserSettings
HideWhenDeactive = false; HideWhenDeactive = false;
} }
protected override void OnAfterLoadConfig(UserSettingStorage storage)
{
if (storage.CustomizedPluginConfigs == null)
{
storage.CustomizedPluginConfigs = new List<CustomizedPluginConfig>();
}
}
} }
public enum OpacityMode public enum OpacityMode

View File

@ -50,6 +50,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="PeHeaderReader.cs" /> <Compile Include="PeHeaderReader.cs" />
<Compile Include="Storage\UserSettings\CustomizedPluginConfig.cs" />
<Compile Include="Storage\UserSettings\FolderLink.cs" /> <Compile Include="Storage\UserSettings\FolderLink.cs" />
<Compile Include="Unidecoder.Characters.cs" /> <Compile Include="Unidecoder.Characters.cs" />
<Compile Include="ChineseToPinYin.cs" /> <Compile Include="ChineseToPinYin.cs" />

View File

@ -1,4 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.SystemPlugins namespace Wox.Plugin.SystemPlugins
{ {
@ -6,6 +8,8 @@ namespace Wox.Plugin.SystemPlugins
public abstract class BaseSystemPlugin : ISystemPlugin public abstract class BaseSystemPlugin : ISystemPlugin
{ {
public string PluginDirectory { get; set; } public string PluginDirectory { get; set; }
public abstract string ID { get; }
public virtual string Name { get { return "System workflow"; } } public virtual string Name { get { return "System workflow"; } }
public virtual string Description { get { return "System workflow"; } } public virtual string Description { get { return "System workflow"; } }
public virtual string IcoPath { get { return null; } } public virtual string IcoPath { get { return null; } }
@ -17,6 +21,11 @@ namespace Wox.Plugin.SystemPlugins
public List<Result> Query(Query query) public List<Result> Query(Query query)
{ {
if (string.IsNullOrEmpty(query.RawQuery)) return new List<Result>(); if (string.IsNullOrEmpty(query.RawQuery)) return new List<Result>();
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == ID);
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
{
return new List<Result>();
}
return QueryInternal(query); return QueryInternal(query);
} }

View File

@ -148,6 +148,11 @@ namespace Wox.Plugin.SystemPlugins.CMD
this.context = context; this.context = context;
} }
public override string ID
{
get { return "D409510CD0D2481F853690A07E6DC426"; }
}
public override string Name public override string Name
{ {
get { return "Shell"; } get { return "Shell"; }

View File

@ -85,6 +85,11 @@ namespace Wox.Plugin.SystemPlugins
this.context = context; this.context = context;
} }
public override string ID
{
get { return "CEA0FDFC6D3B4085823D60DC76F28855"; }
}
public override string Name public override string Name
{ {
get { return "Calculator"; } get { return "Calculator"; }

View File

@ -101,6 +101,11 @@ namespace Wox.Plugin.SystemPlugins
return string.Format("{0}{1}.png", ColorsDirectory.FullName, name.Substring(1)); return string.Format("{0}{1}.png", ColorsDirectory.FullName, name.Substring(1));
} }
public override string ID
{
get { return "9B36CE6181FC47FBB597AA2C29CD9B0A"; }
}
public override string Name public override string Name
{ {
get { return "Colors"; } get { return "Colors"; }

View File

@ -23,6 +23,11 @@ namespace Wox.Plugin.SystemPlugins.Folder {
} }
} }
public override string ID
{
get { return "B4D3B69656E14D44865C8D818EAE47C4"; }
}
public override string Name { get { return "Folder"; } } public override string Name { get { return "Folder"; } }
public override string IcoPath { get { return @"Images\folder.png"; } } public override string IcoPath { get { return @"Images\folder.png"; } }

View File

@ -7,6 +7,7 @@ namespace Wox.Plugin.SystemPlugins
{ {
public interface ISystemPlugin : IPlugin public interface ISystemPlugin : IPlugin
{ {
string ID { get; }
string Name { get; } string Name { get; }
string Description { get; } string Description { get; }
} }

View File

@ -140,6 +140,11 @@ namespace Wox.Plugin.SystemPlugins.Program
} }
public override string ID
{
get { return "791FC278BA414111B8D1886DFE447410"; }
}
public override string Name public override string Name
{ {
get { return "Programs"; } get { return "Programs"; }

View File

@ -118,6 +118,11 @@ namespace Wox.Plugin.SystemPlugins
} }
public override string ID
{
get { return "CEA08895D2544B019B2E9C5009600DF4"; }
}
public override string Name public override string Name
{ {
get { return "System Commands"; } get { return "System Commands"; }

View File

@ -22,6 +22,12 @@ namespace Wox.Plugin.SystemPlugins
if (metadata.ActionKeyword.StartsWith(query.RawQuery)) if (metadata.ActionKeyword.StartsWith(query.RawQuery))
{ {
PluginMetadata metadataCopy = metadata; PluginMetadata metadataCopy = metadata;
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadataCopy.ID);
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
{
continue;
}
Result result = new Result Result result = new Result
{ {
Title = metadata.ActionKeyword, Title = metadata.ActionKeyword,
@ -61,6 +67,11 @@ namespace Wox.Plugin.SystemPlugins
} }
public override string ID
{
get { return "6A122269676E40EB86EB543B945932B9"; }
}
public override string Name public override string Name
{ {
get { return "Third-party Plugin Indicator"; } get { return "Third-party Plugin Indicator"; }

View File

@ -31,6 +31,11 @@ namespace Wox.Plugin.SystemPlugins
return new List<Result>(0); return new List<Result>(0);
} }
public override string ID
{
get { return "0308FD86DE0A4DEE8D62B9B535370992"; }
}
public override string Name { get { return "URL handler"; } } public override string Name { get { return "URL handler"; } }
public override string Description { get { return "Provide Opening the typed URL from Wox."; } } public override string Description { get { return "Provide Opening the typed URL from Wox."; } }
public override string IcoPath { get { return "Images/url2.png"; } } public override string IcoPath { get { return "Images/url2.png"; } }

View File

@ -81,6 +81,11 @@ namespace Wox.Plugin.SystemPlugins
UserSettingStorage.Instance.WebSearches = UserSettingStorage.Instance.LoadDefaultWebSearches(); UserSettingStorage.Instance.WebSearches = UserSettingStorage.Instance.LoadDefaultWebSearches();
} }
public override string ID
{
get { return "565B73353DBF4806919830B9202EE3BF"; }
}
public override string Name public override string Name
{ {
get { return "Web Searches"; } get { return "Web Searches"; }

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using Python.Runtime; using Python.Runtime;
using Wox.Helper; using Wox.Helper;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin; using Wox.Plugin;
using Wox.PluginLoader; using Wox.PluginLoader;
@ -19,6 +20,13 @@ namespace Wox.Commands
PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == q.ActionName); PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == q.ActionName);
if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword)) if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword))
{ {
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == thirdPlugin.Metadata.ID);
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
{
UpdateResultView(null);
return;
}
if (thirdPlugin.Metadata.Language == AllowedLanguage.Python) if (thirdPlugin.Metadata.Language == AllowedLanguage.Python)
{ {
SwitchPythonEnv(thirdPlugin); SwitchPythonEnv(thirdPlugin);
@ -28,6 +36,8 @@ namespace Wox.Commands
try try
{ {
thirdPlugin.InitContext.PushResults = (qu, r) => thirdPlugin.InitContext.PushResults = (qu, r) =>
{
if (r != null)
{ {
r.ForEach(o => r.ForEach(o =>
{ {
@ -35,6 +45,7 @@ namespace Wox.Commands
o.OriginQuery = qu; o.OriginQuery = qu;
}); });
UpdateResultView(r); UpdateResultView(r);
}
}; };
List<Result> results = thirdPlugin.Plugin.Query(q) ?? new List<Result>(); List<Result> results = thirdPlugin.Plugin.Query(q) ?? new List<Result>();
thirdPlugin.InitContext.PushResults(q, results); thirdPlugin.InitContext.PushResults(q, results);

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin; using Wox.Plugin;
using Wox.PluginLoader; using Wox.PluginLoader;
@ -15,11 +16,11 @@ namespace Wox.Commands
foreach (PluginPair pair in Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System)) foreach (PluginPair pair in Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System))
{ {
PluginPair pair1 = pair; PluginPair pair1 = pair;
ThreadPool.QueueUserWorkItem(state => ThreadPool.QueueUserWorkItem(state =>
{ {
pair1.InitContext.PushResults = (q, r) => pair1.InitContext.PushResults = (q, r) =>
{ {
if (r == null || r.Count == 0) return;
foreach (Result result in r) foreach (Result result in r)
{ {
result.PluginDirectory = pair1.Metadata.PluginDirecotry; result.PluginDirectory = pair1.Metadata.PluginDirecotry;

View File

@ -246,9 +246,9 @@ namespace Wox {
// didn't. // didn't.
if (resultCtrl.Dirty) resultCtrl.Clear(); if (resultCtrl.Dirty) resultCtrl.Clear();
}, TimeSpan.FromMilliseconds(100), null); }, TimeSpan.FromMilliseconds(100), null);
queryHasReturn = false;
var q = new Query(lastQuery); var q = new Query(lastQuery);
CommandFactory.DispatchCommand(q); CommandFactory.DispatchCommand(q);
queryHasReturn = false;
if (Plugins.HitThirdpartyKeyword(q)) { if (Plugins.HitThirdpartyKeyword(q)) {
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => { Dispatcher.DelayInvoke("ShowProgressbar", originQuery => {
if (!queryHasReturn && originQuery == lastQuery) { if (!queryHasReturn && originQuery == lastQuery) {
@ -455,10 +455,10 @@ namespace Wox {
} }
public void OnUpdateResultView(List<Result> list) { public void OnUpdateResultView(List<Result> list) {
if (list == null) return;
queryHasReturn = true; queryHasReturn = true;
progressBar.Dispatcher.Invoke(new Action(StopProgress)); progressBar.Dispatcher.Invoke(new Action(StopProgress));
if (list == null || list.Count == 0) return;
if (list.Count > 0) if (list.Count > 0)
{ {
//todo:this should be opened to users, it's their choice to use it or not in their workflows //todo:this should be opened to users, it's their choice to use it or not in their workflows

View File

@ -129,7 +129,7 @@
<TextBlock Opacity="0.5" x:Name="pluginAuthor"></TextBlock> <TextBlock Opacity="0.5" x:Name="pluginAuthor"></TextBlock>
<TextBlock Opacity="0.5" x:Name="pluginWebsite" HorizontalAlignment="Right"></TextBlock> <TextBlock Opacity="0.5" x:Name="pluginWebsite" HorizontalAlignment="Right"></TextBlock>
</DockPanel> </DockPanel>
<CheckBox Grid.Row="4" x:Name="pluginEnabled">Enable</CheckBox> <CheckBox Grid.Row="4" x:Name="cbDisablePlugin" Click="CbDisablePlugin_OnClick">Disable</CheckBox>
</Grid> </Grid>
</Grid> </Grid>
</ContentControl> </ContentControl>

View File

@ -15,6 +15,7 @@ using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin; using Wox.Plugin;
using Wox.Helper; using Wox.Helper;
using Wox.Plugin.SystemPlugins; using Wox.Plugin.SystemPlugins;
using Wox.PluginLoader;
using Application = System.Windows.Forms.Application; using Application = System.Windows.Forms.Application;
using File = System.IO.File; using File = System.IO.File;
using MessageBox = System.Windows.MessageBox; using MessageBox = System.Windows.MessageBox;
@ -422,6 +423,8 @@ namespace Wox
{ {
ISettingProvider provider = null; ISettingProvider provider = null;
var pair = lbPlugins.SelectedItem as PluginPair; var pair = lbPlugins.SelectedItem as PluginPair;
string pluginId = string.Empty;
if (pair != null) if (pair != null)
{ {
//third-party plugin //third-party plugin
@ -434,6 +437,7 @@ namespace Wox
pluginAuthor.Text = "Author: " + pair.Metadata.Author; pluginAuthor.Text = "Author: " + pair.Metadata.Author;
pluginWebsite.Text = "Website: " + pair.Metadata.Website; pluginWebsite.Text = "Website: " + pair.Metadata.Website;
pluginSubTitle.Text = pair.Metadata.Description; pluginSubTitle.Text = pair.Metadata.Description;
pluginId = pair.Metadata.ID;
SyntaxSugars.CallOrRescueDefault( SyntaxSugars.CallOrRescueDefault(
() => () =>
pluginIcon.Source = (ImageSource)new ImagePathConverter().Convert( pluginIcon.Source = (ImageSource)new ImagePathConverter().Convert(
@ -452,6 +456,7 @@ namespace Wox
if (sys != null) if (sys != null)
{ {
pluginTitle.Text = sys.Name; pluginTitle.Text = sys.Name;
pluginId = sys.ID;
pluginSubTitle.Text = sys.Description; pluginSubTitle.Text = sys.Description;
pluginAuthor.Visibility = Visibility.Collapsed; pluginAuthor.Visibility = Visibility.Collapsed;
pluginActionKeyword.Visibility = Visibility.Collapsed; pluginActionKeyword.Visibility = Visibility.Collapsed;
@ -466,7 +471,10 @@ namespace Wox
} }
} }
this.PluginContentPanel.Content = null; var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginId);
cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled;
PluginContentPanel.Content = null;
if (provider != null) if (provider != null)
{ {
Control control = null; Control control = null;
@ -482,5 +490,47 @@ namespace Wox
// featureControls // featureControls
// throw new NotImplementedException(); // throw new NotImplementedException();
} }
private void CbDisablePlugin_OnClick(object sender, RoutedEventArgs e)
{
CheckBox cbDisabled = e.Source as CheckBox;
if (cbDisabled == null) return;
var pair = lbPlugins.SelectedItem as PluginPair;
var id = string.Empty;
var name = string.Empty;
if (pair != null)
{
//third-party plugin
id = pair.Metadata.ID;
name = pair.Metadata.Name;
}
else
{
//system plugin
var sys = lbPlugins.SelectedItem as BaseSystemPlugin;
if (sys != null)
{
id = sys.ID;
name = sys.Name;
}
}
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == id);
if (customizedPluginConfig == null)
{
UserSettingStorage.Instance.CustomizedPluginConfigs.Add(new CustomizedPluginConfig()
{
Disabled = cbDisabled.IsChecked ?? true,
ID = id,
Name = name,
Actionword = string.Empty
});
}
else
{
customizedPluginConfig.Disabled = cbDisabled.IsChecked ?? true;
}
UserSettingStorage.Instance.Save();
}
} }
} }