mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 13:35:31 +02:00
Add reindex call for enable/disable button
For when program source enable && disable + where program not in cache
This commit is contained in:
@@ -270,6 +270,8 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
|
sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
|
||||||
.SelectMany(s => ProgramPaths(s.Location, suffixes))
|
.SelectMany(s => ProgramPaths(s.Location, suffixes))
|
||||||
.ToList()
|
.ToList()
|
||||||
|
.Where(t1 => !Main._settings.DisabledProgramSources.Any(x => t1 == x.UniqueIdentifier))
|
||||||
|
.ToList()
|
||||||
.ForEach(x => listToAdd.Add(x));
|
.ForEach(x => listToAdd.Add(x));
|
||||||
|
|
||||||
var paths = listToAdd.ToArray();
|
var paths = listToAdd.ToArray();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace Wox.Plugin.Program
|
|||||||
/// Contains user added folder location contents as well as all user disabled applications
|
/// Contains user added folder location contents as well as all user disabled applications
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>Win32 class applications sets UniqueIdentifier using their full path</para>
|
/// <para>Win32 class applications sets UniqueIdentifier using their full file path</para>
|
||||||
/// <para>UWP class applications sets UniqueIdentifier using their Application User Model ID</para>
|
/// <para>UWP class applications sets UniqueIdentifier using their Application User Model ID</para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class ProgramSource
|
public class ProgramSource
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ namespace Wox.Plugin.Program.Views.Commands
|
|||||||
// Even though these are disabled, we still want to display them so users can enable later on
|
// Even though these are disabled, we still want to display them so users can enable later on
|
||||||
Main._settings
|
Main._settings
|
||||||
.DisabledProgramSources
|
.DisabledProgramSources
|
||||||
|
.Where(t1 => !Main._settings
|
||||||
|
.ProgramSources // program sourcces added above already, so exlcude
|
||||||
|
.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
|
||||||
|
.Select(x => x)
|
||||||
|
.ToList()
|
||||||
.ForEach(x => list
|
.ForEach(x => list
|
||||||
.Add(
|
.Add(
|
||||||
new ProgramSource
|
new ProgramSource
|
||||||
@@ -110,7 +115,7 @@ namespace Wox.Plugin.Program.Views.Commands
|
|||||||
UniqueIdentifier = x.UniqueIdentifier,
|
UniqueIdentifier = x.UniqueIdentifier,
|
||||||
Enabled = false
|
Enabled = false
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void RemoveDisabledFromSettings(this List<ProgramSource> list)
|
internal static void RemoveDisabledFromSettings(this List<ProgramSource> list)
|
||||||
@@ -125,5 +130,20 @@ namespace Wox.Plugin.Program.Views.Commands
|
|||||||
.ToList()
|
.ToList()
|
||||||
.ForEach(x => Main._settings.DisabledProgramSources.Remove(x));
|
.ForEach(x => Main._settings.DisabledProgramSources.Remove(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool IsReindexRequired(this List<ProgramSource> selectedItems)
|
||||||
|
{
|
||||||
|
if (selectedItems.Where(t1 => t1.Enabled && !Main._uwps.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Count() > 0
|
||||||
|
&& selectedItems.Where(t1 => t1.Enabled && !Main._win32s.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Count() > 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Program Sources holds list of user added directories,
|
||||||
|
// so when we enable/disable we need to reindex to show/not show the programs
|
||||||
|
// that are found in those directories.
|
||||||
|
if (selectedItems.Where(t1 => Main._settings.ProgramSources.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Count() > 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,42 +167,31 @@ namespace Wox.Plugin.Program.Views
|
|||||||
|
|
||||||
private void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs e)
|
private void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (AggregatedProgramSourceSelectedItemStatus())
|
var selectedItems = programSourceView
|
||||||
|
.SelectedItems.Cast<ProgramSource>()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled())
|
||||||
{
|
{
|
||||||
DisableProgramSources();
|
ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, false);
|
||||||
|
|
||||||
|
ProgramSettingDisplayList.StoreDisabledInSettings();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EnableProgramSources();
|
ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, true);
|
||||||
}
|
|
||||||
|
ProgramSettingDisplayList.RemoveDisabledFromSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedItems.IsReindexRequired())
|
||||||
|
ReIndexing();
|
||||||
|
|
||||||
programSourceView.SelectedItems.Clear();
|
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)
|
private void ProgramSourceView_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
programSourceView.SelectedItems.Clear();
|
programSourceView.SelectedItems.Clear();
|
||||||
@@ -246,8 +235,7 @@ namespace Wox.Plugin.Program.Views
|
|||||||
|
|
||||||
private void Sort(string sortBy, ListSortDirection direction)
|
private void Sort(string sortBy, ListSortDirection direction)
|
||||||
{
|
{
|
||||||
ICollectionView dataView =
|
var dataView = CollectionViewSource.GetDefaultView(programSourceView.ItemsSource);
|
||||||
CollectionViewSource.GetDefaultView(programSourceView.ItemsSource);
|
|
||||||
|
|
||||||
dataView.SortDescriptions.Clear();
|
dataView.SortDescriptions.Clear();
|
||||||
SortDescription sd = new SortDescription(sortBy, direction);
|
SortDescription sd = new SortDescription(sortBy, direction);
|
||||||
@@ -255,7 +243,7 @@ namespace Wox.Plugin.Program.Views
|
|||||||
dataView.Refresh();
|
dataView.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool AggregatedProgramSourceSelectedItemStatus()
|
private bool IsSelectedRowStatusEnabledMoreOrEqualThanDisabled()
|
||||||
{
|
{
|
||||||
var selectedItems = programSourceView
|
var selectedItems = programSourceView
|
||||||
.SelectedItems.Cast<ProgramSource>()
|
.SelectedItems.Cast<ProgramSource>()
|
||||||
@@ -266,7 +254,7 @@ namespace Wox.Plugin.Program.Views
|
|||||||
|
|
||||||
private void Row_Click(object sender, RoutedEventArgs e)
|
private void Row_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (AggregatedProgramSourceSelectedItemStatus())
|
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled())
|
||||||
{
|
{
|
||||||
btnProgramSourceStatus.Content = "Disable";
|
btnProgramSourceStatus.Content = "Disable";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user