mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
#21 Add Disable option for each plugin.
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using Python.Runtime;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.PluginLoader;
|
||||
|
||||
@@ -19,6 +20,13 @@ namespace Wox.Commands
|
||||
PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == q.ActionName);
|
||||
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)
|
||||
{
|
||||
SwitchPythonEnv(thirdPlugin);
|
||||
@@ -29,12 +37,15 @@ namespace Wox.Commands
|
||||
{
|
||||
thirdPlugin.InitContext.PushResults = (qu, r) =>
|
||||
{
|
||||
r.ForEach(o =>
|
||||
if (r != null)
|
||||
{
|
||||
o.PluginDirectory = thirdPlugin.Metadata.PluginDirecotry;
|
||||
o.OriginQuery = qu;
|
||||
});
|
||||
UpdateResultView(r);
|
||||
r.ForEach(o =>
|
||||
{
|
||||
o.PluginDirectory = thirdPlugin.Metadata.PluginDirecotry;
|
||||
o.OriginQuery = qu;
|
||||
});
|
||||
UpdateResultView(r);
|
||||
}
|
||||
};
|
||||
List<Result> results = thirdPlugin.Plugin.Query(q) ?? new List<Result>();
|
||||
thirdPlugin.InitContext.PushResults(q, results);
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.PluginLoader;
|
||||
|
||||
@@ -15,11 +16,11 @@ namespace Wox.Commands
|
||||
foreach (PluginPair pair in Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System))
|
||||
{
|
||||
PluginPair pair1 = pair;
|
||||
|
||||
ThreadPool.QueueUserWorkItem(state =>
|
||||
{
|
||||
pair1.InitContext.PushResults = (q, r) =>
|
||||
{
|
||||
if (r == null || r.Count == 0) return;
|
||||
foreach (Result result in r)
|
||||
{
|
||||
result.PluginDirectory = pair1.Metadata.PluginDirecotry;
|
||||
|
||||
@@ -246,9 +246,9 @@ namespace Wox {
|
||||
// didn't.
|
||||
if (resultCtrl.Dirty) resultCtrl.Clear();
|
||||
}, TimeSpan.FromMilliseconds(100), null);
|
||||
queryHasReturn = false;
|
||||
var q = new Query(lastQuery);
|
||||
CommandFactory.DispatchCommand(q);
|
||||
queryHasReturn = false;
|
||||
if (Plugins.HitThirdpartyKeyword(q)) {
|
||||
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => {
|
||||
if (!queryHasReturn && originQuery == lastQuery) {
|
||||
@@ -455,10 +455,10 @@ namespace Wox {
|
||||
}
|
||||
|
||||
public void OnUpdateResultView(List<Result> list) {
|
||||
if (list == null) return;
|
||||
queryHasReturn = true;
|
||||
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
||||
if (list == null || list.Count == 0) return;
|
||||
|
||||
queryHasReturn = true;
|
||||
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
||||
if (list.Count > 0)
|
||||
{
|
||||
//todo:this should be opened to users, it's their choice to use it or not in their workflows
|
||||
|
||||
@@ -129,7 +129,7 @@
|
||||
<TextBlock Opacity="0.5" x:Name="pluginAuthor"></TextBlock>
|
||||
<TextBlock Opacity="0.5" x:Name="pluginWebsite" HorizontalAlignment="Right"></TextBlock>
|
||||
</DockPanel>
|
||||
<CheckBox Grid.Row="4" x:Name="pluginEnabled">Enable</CheckBox>
|
||||
<CheckBox Grid.Row="4" x:Name="cbDisablePlugin" Click="CbDisablePlugin_OnClick">Disable</CheckBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ContentControl>
|
||||
|
||||
@@ -15,6 +15,7 @@ using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.Helper;
|
||||
using Wox.Plugin.SystemPlugins;
|
||||
using Wox.PluginLoader;
|
||||
using Application = System.Windows.Forms.Application;
|
||||
using File = System.IO.File;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
@@ -422,6 +423,8 @@ namespace Wox
|
||||
{
|
||||
ISettingProvider provider = null;
|
||||
var pair = lbPlugins.SelectedItem as PluginPair;
|
||||
string pluginId = string.Empty;
|
||||
|
||||
if (pair != null)
|
||||
{
|
||||
//third-party plugin
|
||||
@@ -434,6 +437,7 @@ namespace Wox
|
||||
pluginAuthor.Text = "Author: " + pair.Metadata.Author;
|
||||
pluginWebsite.Text = "Website: " + pair.Metadata.Website;
|
||||
pluginSubTitle.Text = pair.Metadata.Description;
|
||||
pluginId = pair.Metadata.ID;
|
||||
SyntaxSugars.CallOrRescueDefault(
|
||||
() =>
|
||||
pluginIcon.Source = (ImageSource)new ImagePathConverter().Convert(
|
||||
@@ -452,6 +456,7 @@ namespace Wox
|
||||
if (sys != null)
|
||||
{
|
||||
pluginTitle.Text = sys.Name;
|
||||
pluginId = sys.ID;
|
||||
pluginSubTitle.Text = sys.Description;
|
||||
pluginAuthor.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)
|
||||
{
|
||||
Control control = null;
|
||||
@@ -482,5 +490,47 @@ namespace Wox
|
||||
// featureControls
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user