mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +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:
@@ -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
|
||||
Main._settings
|
||||
.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
|
||||
.Add(
|
||||
new ProgramSource
|
||||
@@ -110,7 +115,7 @@ namespace Wox.Plugin.Program.Views.Commands
|
||||
UniqueIdentifier = x.UniqueIdentifier,
|
||||
Enabled = false
|
||||
}
|
||||
));
|
||||
));
|
||||
}
|
||||
|
||||
internal static void RemoveDisabledFromSettings(this List<ProgramSource> list)
|
||||
@@ -125,5 +130,20 @@ namespace Wox.Plugin.Program.Views.Commands
|
||||
.ToList()
|
||||
.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)
|
||||
{
|
||||
if (AggregatedProgramSourceSelectedItemStatus())
|
||||
var selectedItems = programSourceView
|
||||
.SelectedItems.Cast<ProgramSource>()
|
||||
.ToList();
|
||||
|
||||
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled())
|
||||
{
|
||||
DisableProgramSources();
|
||||
ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, false);
|
||||
|
||||
ProgramSettingDisplayList.StoreDisabledInSettings();
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableProgramSources();
|
||||
}
|
||||
ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, true);
|
||||
|
||||
ProgramSettingDisplayList.RemoveDisabledFromSettings();
|
||||
}
|
||||
|
||||
if (selectedItems.IsReindexRequired())
|
||||
ReIndexing();
|
||||
|
||||
programSourceView.SelectedItems.Clear();
|
||||
|
||||
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)
|
||||
{
|
||||
programSourceView.SelectedItems.Clear();
|
||||
@@ -246,8 +235,7 @@ namespace Wox.Plugin.Program.Views
|
||||
|
||||
private void Sort(string sortBy, ListSortDirection direction)
|
||||
{
|
||||
ICollectionView dataView =
|
||||
CollectionViewSource.GetDefaultView(programSourceView.ItemsSource);
|
||||
var dataView = CollectionViewSource.GetDefaultView(programSourceView.ItemsSource);
|
||||
|
||||
dataView.SortDescriptions.Clear();
|
||||
SortDescription sd = new SortDescription(sortBy, direction);
|
||||
@@ -255,7 +243,7 @@ namespace Wox.Plugin.Program.Views
|
||||
dataView.Refresh();
|
||||
}
|
||||
|
||||
private bool AggregatedProgramSourceSelectedItemStatus()
|
||||
private bool IsSelectedRowStatusEnabledMoreOrEqualThanDisabled()
|
||||
{
|
||||
var selectedItems = programSourceView
|
||||
.SelectedItems.Cast<ProgramSource>()
|
||||
@@ -266,7 +254,7 @@ namespace Wox.Plugin.Program.Views
|
||||
|
||||
private void Row_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (AggregatedProgramSourceSelectedItemStatus())
|
||||
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled())
|
||||
{
|
||||
btnProgramSourceStatus.Content = "Disable";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user