Add dynamic Delete to the Enable/Disable button

This commit is contained in:
Jeremy Wu
2019-10-17 06:43:18 +11:00
parent ac79803f1b
commit 34a3535abe
9 changed files with 47 additions and 33 deletions

View File

@@ -137,7 +137,7 @@ namespace Wox.Plugin.Program.Views.Commands
&& 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,
// ProgramSources 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)

View File

@@ -28,7 +28,7 @@
Drop="programSourceView_Drop" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="PreviewMouseUp" Handler="Row_Click"/>
<EventSetter Event="PreviewMouseUp" Handler="Row_OnClick"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
@@ -63,7 +63,6 @@
<TextBlock Margin="10 0 0 0" Height="20" HorizontalAlignment="Center" Text="{DynamicResource wox_plugin_program_indexing}" />
</StackPanel>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="btnDeleteProgramSource" Click="btnDeleteProgramSource_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_program_delete}"/>
<Button x:Name="btnEditProgramSource" Click="btnEditProgramSource_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_program_edit}"/>
<Button x:Name="btnAddProgramSource" Click="btnAddProgramSource_OnClick" Width="100" Margin="10" Content="{DynamicResource wox_plugin_program_add}"/>
</StackPanel>

View File

@@ -64,24 +64,12 @@ namespace Wox.Plugin.Program.Views
programSourceView.Items.Refresh();
}
private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
private void DeleteProgramSources(List<ProgramSource> itemsToDelete)
{
var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
if (selectedProgramSource != null)
{
string msg = string.Format(context.API.GetTranslation("wox_plugin_program_delete_program_source"), selectedProgramSource.Location);
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
_settings.ProgramSources.Remove(selectedProgramSource);
ReIndexing();
}
}
else
{
string msg = context.API.GetTranslation("wox_plugin_program_pls_select_program_source");
MessageBox.Show(msg);
}
itemsToDelete.ForEach(x => _settings.ProgramSources.Remove(x));
itemsToDelete.ForEach(x => ProgramSettingDisplayList.Remove(x));
ReIndexing();
}
private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
@@ -171,7 +159,29 @@ namespace Wox.Plugin.Program.Views
.SelectedItems.Cast<ProgramSource>()
.ToList();
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled())
if (selectedItems.Count() == 0)
{
string msg = context.API.GetTranslation("wox_plugin_program_pls_select_program_source");
MessageBox.Show(msg);
return;
}
if (selectedItems
.Where(t1 => !_settings
.ProgramSources
.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
.Count() == 0)
{
var msg = string.Format(context.API.GetTranslation("wox_plugin_program_delete_program_source"));
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
{
return;
}
DeleteProgramSources(selectedItems);
}
else if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems))
{
ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, false);
@@ -243,18 +253,28 @@ namespace Wox.Plugin.Program.Views
dataView.Refresh();
}
private bool IsSelectedRowStatusEnabledMoreOrEqualThanDisabled()
private bool IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(List<ProgramSource> selectedItems)
{
return selectedItems.Where(x => x.Enabled).Count() >= selectedItems.Where(x => !x.Enabled).Count();
}
private void Row_OnClick(object sender, RoutedEventArgs e)
{
var selectedItems = programSourceView
.SelectedItems.Cast<ProgramSource>()
.ToList();
return selectedItems.Where(x => x.Enabled).Count() >= selectedItems.Where(x => !x.Enabled).Count();
}
if (selectedItems
.Where(t1 => !_settings
.ProgramSources
.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
.Count() == 0)
{
btnProgramSourceStatus.Content = context.API.GetTranslation("wox_plugin_program_delete");
return;
}
private void Row_Click(object sender, RoutedEventArgs e)
{
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled())
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems))
{
btnProgramSourceStatus.Content = "Disable";
}