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

@@ -21,7 +21,6 @@
<system:String x:Key="wox_plugin_program_max_search_depth">Maximale Suchtiefe (-1 ist unlimitiert):</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">Bitte wähle eine Programmquelle</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">Willst du wirklich {0} löschen?</system:String>
<system:String x:Key="wox_plugin_program_update">Aktualisieren</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox indexiert nur Datien mit folgenden Endungen:</system:String>

View File

@@ -21,7 +21,7 @@
<system:String x:Key="wox_plugin_program_max_search_depth">Maximum Search Depth (-1 is unlimited):</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">Please select a program source</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">Are you sure you want to delete {0}?</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">Are you sure you want to delete the selected program sources?</system:String>
<system:String x:Key="wox_plugin_program_update">Update</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox will only index files that end with the following suffixes:</system:String>

View File

@@ -21,7 +21,6 @@
<system:String x:Key="wox_plugin_program_max_search_depth">Maksymalna głębokość wyszukiwania (-1 to nieograniczona):</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">Musisz wybrać katalog programu</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">Czy jesteś pewien że chcesz usunąć {0}?</system:String>
<system:String x:Key="wox_plugin_program_update">Aktualizuj</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox będzie indeksował tylko te pliki z podanymi rozszerzeniami:</system:String>

View File

@@ -21,7 +21,6 @@
<system:String x:Key="wox_plugin_program_max_search_depth">Maksimum Arama Derinliği (Limitsiz için -1):</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">İşlem yapmak istediğiniz klasörü seçin.</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">{0} klasörünü silmek istediğinize emin misiniz?</system:String>
<system:String x:Key="wox_plugin_program_update">Güncelle</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox yalnızca aşağıdaki uzantılara sahip dosyaları indeksleyecektir:</system:String>

View File

@@ -21,7 +21,6 @@
<system:String x:Key="wox_plugin_program_max_search_depth">最大搜索深度(-1是无限的</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">请先选择一项</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">你确定要删除{0}吗?</system:String>
<system:String x:Key="wox_plugin_program_update">更新</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox仅索引下列后缀的文件</system:String>

View File

@@ -21,7 +21,6 @@
<system:String x:Key="wox_plugin_program_max_search_depth">最大搜尋深度(-1是無限的</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">請先選擇一項</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">你確定要刪除{0}嗎?</system:String>
<system:String x:Key="wox_plugin_program_update">更新</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox 僅索引下列副檔名的檔案:</system:String>

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";
}