Add right click option on query to disable program

This commit is contained in:
Jeremy Wu
2019-10-17 22:47:00 +11:00
parent 12d3ca2d50
commit f8cbe053cc
7 changed files with 55 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -31,10 +31,15 @@
<system:String x:Key="wox_plugin_program_run_as_administrator">Run As Administrator</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">Open containing folder</system:String>
<system:String x:Key="wox_plugin_program_disable_program">Disable this program from displaying</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">Program</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Search programs in Wox</system:String>
<system:String x:Key="wox_plugin_program_invalid_path">Invalid Path</system:String>
<!--Dialogs-->
<system:String x:Key="wox_plugin_program_disable_dlgtitle_success">Success</system:String>
<system:String x:Key="wox_plugin_program_disable_dlgtitle_success_message">Successfully disabled this program from displaying in your query</system:String>
</ResourceDictionary>

View File

@@ -102,8 +102,6 @@ namespace Wox.Plugin.Program
lock (IndexLock)
{
_uwps = support ? UWP.All() : new UWP.Application[] { };
//_uwps = UWP.RetainApplications(allUWPs, _settings.ProgramSources, _settings.EnableProgramSourceOnly);
}
}
@@ -133,16 +131,49 @@ namespace Wox.Plugin.Program
public List<Result> LoadContextMenus(Result selectedResult)
{
var menuOptions = new List<Result>();
var program = selectedResult.ContextData as IProgram;
if (program != null)
{
var menus = program.ContextMenus(_context.API);
return menus;
}
else
{
return new List<Result>();
menuOptions = program.ContextMenus(_context.API);
}
menuOptions.Add(
new Result
{
Title = _context.API.GetTranslation("wox_plugin_program_disable_program"),
Action = c =>
{
DisableProgram(program);
_context.API.ShowMsg(_context.API.GetTranslation("wox_plugin_program_disable_dlgtitle_success"),
_context.API.GetTranslation("wox_plugin_program_disable_dlgtitle_success_message"));
return false;
},
IcoPath = "Images/disable.png"
}
);
return menuOptions;
}
private void DisableProgram(IProgram ProgramToDelete)
{
if(_uwps.Any(x => x.UniqueIdentifier == ProgramToDelete.UniqueIdentifier))
_uwps.Where(x => x.UniqueIdentifier == ProgramToDelete.UniqueIdentifier).FirstOrDefault().Enabled = false;
if (_win32s.Any(x => x.UniqueIdentifier == ProgramToDelete.UniqueIdentifier))
_win32s.Where(x => x.UniqueIdentifier == ProgramToDelete.UniqueIdentifier).FirstOrDefault().Enabled = false;
_settings.DisabledProgramSources
.Add(
new Settings.DisabledProgramSource
{
Name = ProgramToDelete.Name,
Location = ProgramToDelete.Location,
UniqueIdentifier = ProgramToDelete.UniqueIdentifier,
Enabled = false
}
);
}
public static bool StartProcess(ProcessStartInfo info)

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace Wox.Plugin.Program.Programs
{
@@ -10,5 +6,8 @@ namespace Wox.Plugin.Program.Programs
{
List<Result> ContextMenus(IPublicAPI api);
Result Result(string query, IPublicAPI api);
string UniqueIdentifier { get; set; }
string Name { get; }
string Location { get; }
}
}

View File

@@ -241,6 +241,9 @@ namespace Wox.Plugin.Program.Programs
public string UserModelId { get; set; }
public string BackgroundColor { get; set; }
public string Name => DisplayName;
public string Location => Package.Location;
public bool Enabled { get; set; }
public string LogoUri { get; set; }

View File

@@ -26,6 +26,7 @@ namespace Wox.Plugin.Program.Programs
public string Description { get; set; }
public bool Valid { get; set; }
public bool Enabled { get; set; }
public string Location => ParentDirectory;
private const string ShortcutExtension = "lnk";
private const string ApplicationReferenceExtension = "appref-ms";

View File

@@ -105,6 +105,9 @@
<None Include="Images\folder.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Images\disable.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="Languages\en.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>