mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Add Enable program source to Program plugin view
This commit is contained in:
@@ -55,22 +55,22 @@ namespace Wox.Plugin.Program.Views.Commands
|
||||
);
|
||||
}
|
||||
|
||||
internal static void DisableProgramSources(this List<ProgramSource> list, List<ProgramSource> selectedprogramSourcesToDisable)
|
||||
internal static void SetProgramSourcesStatus(this List<ProgramSource> list, List<ProgramSource> selectedProgramSourcesToDisable, bool status)
|
||||
{
|
||||
ProgramSetting.ProgramSettingDisplayList
|
||||
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled))
|
||||
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
||||
.ToList()
|
||||
.ForEach(t1 => t1.Enabled = false);
|
||||
.ForEach(t1 => t1.Enabled = status);
|
||||
|
||||
Main._win32s
|
||||
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled))
|
||||
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
||||
.ToList()
|
||||
.ForEach(t1 => t1.Enabled = false);
|
||||
.ForEach(t1 => t1.Enabled = status);
|
||||
|
||||
Main._uwps
|
||||
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled))
|
||||
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
||||
.ToList()
|
||||
.ForEach(t1 => t1.Enabled = false);
|
||||
.ForEach(t1 => t1.Enabled = status);
|
||||
}
|
||||
|
||||
internal static void StoreDisabledInSettings(this List<ProgramSource> list)
|
||||
@@ -82,11 +82,11 @@ namespace Wox.Plugin.Program.Views.Commands
|
||||
|
||||
ProgramSetting.ProgramSettingDisplayList
|
||||
.Where(t1 => !t1.Enabled
|
||||
&& !Main._settings.ProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
|
||||
&& !Main._settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
||||
.ToList()
|
||||
.ForEach(x => Main._settings.ProgramSources
|
||||
.ForEach(x => Main._settings.DisabledProgramSources
|
||||
.Add(
|
||||
new Settings.ProgramSource
|
||||
new Settings.DisabledProgramSource
|
||||
{
|
||||
Name = x.Name,
|
||||
Location = x.Location,
|
||||
@@ -95,5 +95,18 @@ namespace Wox.Plugin.Program.Views.Commands
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
internal static void RemoveDisabledFromSettings(this List<ProgramSource> list)
|
||||
{
|
||||
Main._settings.ProgramSources
|
||||
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
|
||||
.ToList()
|
||||
.ForEach(t1 => t1.Enabled = true);
|
||||
|
||||
Main._settings.DisabledProgramSources
|
||||
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
|
||||
.ToList()
|
||||
.ForEach(x => Main._settings.DisabledProgramSources.Remove(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,17 @@
|
||||
<Button Height="30" HorizontalAlignment="Right" Margin="0,10" x:Name="btnProgramSuffixes" Width="100" Click="BtnProgramSuffixes_OnClick" Content="{DynamicResource wox_plugin_program_suffixes}" />
|
||||
<Button Height="30" HorizontalAlignment="Right" Margin="10 0 0 0" x:Name="btnReindex" Width="100" Click="btnReindex_Click" Content="{DynamicResource wox_plugin_program_reindex}" />
|
||||
<Button Height="30" HorizontalAlignment="Right" Margin="10 0 0 0" x:Name="btnLoadAllProgramSource" Click="btnLoadAllProgramSource_OnClick" Width="100" Content="All Programs" />
|
||||
<Button Height="30" HorizontalAlignment="Right" Margin="10 0 0 0" x:Name="btnDisableProgramSource" Click="btnDisableProgramSource_OnClick" Width="100" Content="Disable" />
|
||||
<Button Height="30" HorizontalAlignment="Right" Margin="10 0 0 0" x:Name="btnProgramSourceStatus" Click="btnProgramSourceStatus_OnClick" Width="100" Content="Disable" />
|
||||
</StackPanel>
|
||||
<ListView x:Name="programSourceView" Grid.Row="1" AllowDrop="True" SelectionMode="Extended" GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler"
|
||||
PreviewMouseRightButtonUp="ProgramSourceView_PreviewMouseRightButtonUp"
|
||||
PreviewMouseRightButtonUp="ProgramSourceView_PreviewMouseRightButtonUp"
|
||||
DragEnter="programSourceView_DragEnter"
|
||||
Drop="programSourceView_Drop" >
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<EventSetter Event="PreviewMouseUp" Handler="Row_Click"/>
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="Name" Width="150">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -165,18 +165,42 @@ namespace Wox.Plugin.Program.Views
|
||||
programSourceView.Items.Refresh();
|
||||
}
|
||||
|
||||
private void btnDisableProgramSource_OnClick(object sender, RoutedEventArgs e)
|
||||
private void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ProgramSettingDisplayList
|
||||
.DisableProgramSources(programSourceView
|
||||
.SelectedItems.Cast<ProgramSource>()
|
||||
.ToList());
|
||||
|
||||
ProgramSettingDisplayList.StoreDisabledInSettings();
|
||||
if (AggregatedProgramSourceSelectedItemStatus())
|
||||
{
|
||||
DisableProgramSources();
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableProgramSources();
|
||||
}
|
||||
|
||||
programSourceView.SelectedItems.Clear();
|
||||
|
||||
programSourceView.Items.Refresh();
|
||||
programSourceView.Items.Refresh();
|
||||
}
|
||||
|
||||
public void DisableProgramSources()
|
||||
{
|
||||
ProgramSettingDisplayList
|
||||
.SetProgramSourcesStatus(programSourceView
|
||||
.SelectedItems.Cast<ProgramSource>()
|
||||
.ToList(),
|
||||
false);
|
||||
|
||||
ProgramSettingDisplayList.StoreDisabledInSettings();
|
||||
}
|
||||
|
||||
public void EnableProgramSources()
|
||||
{
|
||||
ProgramSettingDisplayList
|
||||
.SetProgramSourcesStatus(programSourceView
|
||||
.SelectedItems.Cast<ProgramSource>()
|
||||
.ToList(),
|
||||
true);
|
||||
|
||||
ProgramSettingDisplayList.RemoveDisabledFromSettings();
|
||||
}
|
||||
|
||||
private void ProgramSourceView_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
||||
@@ -230,5 +254,26 @@ namespace Wox.Plugin.Program.Views
|
||||
dataView.SortDescriptions.Add(sd);
|
||||
dataView.Refresh();
|
||||
}
|
||||
|
||||
private bool AggregatedProgramSourceSelectedItemStatus()
|
||||
{
|
||||
var selectedItems = programSourceView
|
||||
.SelectedItems.Cast<ProgramSource>()
|
||||
.ToList();
|
||||
|
||||
return selectedItems.Where(x => x.Enabled).Count() >= selectedItems.Where(x => !x.Enabled).Count();
|
||||
}
|
||||
|
||||
private void Row_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (AggregatedProgramSourceSelectedItemStatus())
|
||||
{
|
||||
btnProgramSourceStatus.Content = "Disable";
|
||||
}
|
||||
else
|
||||
{
|
||||
btnProgramSourceStatus.Content = "Enable";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user