mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Refactor Plugins.Program
This commit is contained in:
@@ -9,6 +9,7 @@ using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin.Program.Programs;
|
||||
using Wox.Plugin.Program.Views;
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
@@ -135,32 +136,11 @@ namespace Wox.Plugin.Program
|
||||
var t2 = Task.Run(() => { IndexUWPPrograms(); });
|
||||
|
||||
Task.WaitAll(t1, t2);
|
||||
}
|
||||
|
||||
public static void AddLoadedApplicationsToSettings()
|
||||
{
|
||||
_win32s
|
||||
.Where(t1 => !_settings.ProgramSources.Any(x => x.Name == t1.Name))
|
||||
.ToList()
|
||||
.ForEach(t1 => _settings.ProgramSources.Add(new Settings.ProgramSource (){Name = t1.Name, Location = t1.ParentDirectory }));
|
||||
|
||||
_uwps
|
||||
.Where(t1 => !_settings.ProgramSources.Any(x => x.Name == t1.DisplayName))
|
||||
.ToList()
|
||||
.ForEach(t1 => _settings.ProgramSources.Add(new Settings.ProgramSource() { Name = t1.DisplayName, Location = t1.Package.Location }));
|
||||
}
|
||||
|
||||
public static void DisableProgramSources(List<Settings.ProgramSource> programSourcesToDisable)
|
||||
{
|
||||
_settings.ProgramSources
|
||||
.Where(t1 => programSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.Location && t1.Enabled))
|
||||
.ToList()
|
||||
.ForEach(t1 => t1.Enabled = false);
|
||||
}
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return new ProgramSetting(_context, _settings);
|
||||
return new ProgramSetting(_context, _settings, _win32s, _uwps);
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginTitle()
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Wox.Plugin.Program.Views.Models;
|
||||
|
||||
namespace Wox.Plugin.Program.Views.Commands
|
||||
{
|
||||
internal static class ProgramSettingDisplay
|
||||
{
|
||||
internal static List<ProgramSource> LoadProgramSources(this List<Settings.ProgramSource> programSources)
|
||||
{
|
||||
var list = new List<ProgramSource>();
|
||||
|
||||
programSources.ForEach(x => list.Add(new ProgramSource { Enabled = x.Enabled, Location = x.Location, Name = x.Name }));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
internal static void LoadAllApplications(this List<ProgramSource> listToUpdate)
|
||||
{
|
||||
Main._win32s
|
||||
.ToList()
|
||||
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource { Name = t1.Name, Location = t1.ParentDirectory, Enabled = t1.Enabled }));
|
||||
|
||||
Main._uwps
|
||||
.ToList()
|
||||
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource { Name = t1.DisplayName, Location = t1.Package.Location, Enabled = t1.Enabled }));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<UserControl x:Class="Wox.Plugin.Program.ProgramSetting"
|
||||
<UserControl x:Class="Wox.Plugin.Program.Views.ProgramSetting"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
@@ -6,9 +6,11 @@ using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Wox.Plugin.Program.Views.Models;
|
||||
using Wox.Plugin.Program.Views.Commands;
|
||||
using Wox.Plugin.Program.Programs;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
namespace Wox.Plugin.Program.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ProgramSetting.xaml
|
||||
@@ -17,8 +19,9 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
private PluginInitContext context;
|
||||
private Settings _settings;
|
||||
internal static List<ProgramSource> ProgramSettingDisplayList { get; set; }
|
||||
|
||||
public ProgramSetting(PluginInitContext context, Settings settings)
|
||||
public ProgramSetting(PluginInitContext context, Settings settings, Win32[] win32s, UWP.Application[] uwps)
|
||||
{
|
||||
this.context = context;
|
||||
InitializeComponent();
|
||||
@@ -28,7 +31,9 @@ namespace Wox.Plugin.Program
|
||||
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
programSourceView.ItemsSource = _settings.ProgramSources;
|
||||
ProgramSettingDisplayList = _settings.ProgramSources.LoadProgramSources();
|
||||
programSourceView.ItemsSource = ProgramSettingDisplayList;
|
||||
|
||||
StartMenuEnabled.IsChecked = _settings.EnableStartMenuSource;
|
||||
RegistryEnabled.IsChecked = _settings.EnableRegistrySource;
|
||||
}
|
||||
@@ -151,14 +156,17 @@ namespace Wox.Plugin.Program
|
||||
|
||||
private void btnLoadAllProgramSource_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Main.AddLoadedApplicationsToSettings();
|
||||
ProgramSettingDisplayList.LoadAllApplications();
|
||||
|
||||
programSourceView.Items.Refresh();
|
||||
}
|
||||
|
||||
private void btnDisableProgramSource_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Main.DisableProgramSources(programSourceView.SelectedItems.Cast<Settings.ProgramSource>().ToList());
|
||||
ProgramSettingDisplayList
|
||||
.DisableProgramSources(programSourceView
|
||||
.SelectedItems.Cast<ProgramSource>()
|
||||
.ToList());
|
||||
|
||||
programSourceView.SelectedItems.Clear();
|
||||
|
||||
@@ -71,13 +71,15 @@
|
||||
<Compile Include="AddProgramSource.xaml.cs">
|
||||
<DependentUpon>AddProgramSource.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\Commands\ProgramSettingDisplay.cs" />
|
||||
<Compile Include="FileChangeWatcher.cs" />
|
||||
<Compile Include="Views\Models\ProgramSource.cs" />
|
||||
<Compile Include="Programs\IProgram.cs" />
|
||||
<Compile Include="Programs\UWP.cs" />
|
||||
<Compile Include="Programs\Win32.cs" />
|
||||
<Compile Include="SuffixesConverter.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="ProgramSetting.xaml.cs">
|
||||
<Compile Include="Views\ProgramSetting.xaml.cs">
|
||||
<DependentUpon>ProgramSetting.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Settings.cs" />
|
||||
@@ -130,7 +132,7 @@
|
||||
<SubType>Designer</SubType>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Page Include="ProgramSetting.xaml">
|
||||
<Page Include="Views\ProgramSetting.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
|
||||
Reference in New Issue
Block a user