Merge pull request #3539 from Flow-Launcher/program_plugin_delete_logic

Improve Program plugin delete button logic
This commit is contained in:
Jack Ye 2025-05-14 14:40:08 +08:00 committed by GitHub
commit 54c949b3ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 27 deletions

View file

@ -48,6 +48,8 @@
<system:String x:Key="flowlauncher_plugin_program_pls_select_program_source">Please select a program source</system:String> <system:String x:Key="flowlauncher_plugin_program_pls_select_program_source">Please select a program source</system:String>
<system:String x:Key="flowlauncher_plugin_program_delete_program_source">Are you sure you want to delete the selected program sources?</system:String> <system:String x:Key="flowlauncher_plugin_program_delete_program_source">Are you sure you want to delete the selected program sources?</system:String>
<system:String x:Key="flowlauncher_plugin_program_delete_program_source_select_not_user_added">Please select program sources that are not added by you</system:String>
<system:String x:Key="flowlauncher_plugin_program_delete_program_source_select_user_added">Please select program sources that are added by you</system:String>
<system:String x:Key="flowlauncher_plugin_program_duplicate_program_source">Another program source with the same location already exists.</system:String> <system:String x:Key="flowlauncher_plugin_program_duplicate_program_source">Another program source with the same location already exists.</system:String>
<system:String x:Key="flowlauncher_plugin_program_edit_program_source_title">Program Source</system:String> <system:String x:Key="flowlauncher_plugin_program_edit_program_source_title">Program Source</system:String>

View file

@ -203,6 +203,12 @@
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}" Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Click="btnEditProgramSource_OnClick" Click="btnEditProgramSource_OnClick"
Content="{DynamicResource flowlauncher_plugin_program_edit}" /> Content="{DynamicResource flowlauncher_plugin_program_edit}" />
<Button
x:Name="btnDeleteProgramSource"
MinWidth="100"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Click="btnDeleteProgramSource_OnClick"
Content="{DynamicResource flowlauncher_plugin_program_delete}" />
<Button <Button
x:Name="btnAddProgramSource" x:Name="btnAddProgramSource"
MinWidth="100" MinWidth="100"

View file

@ -133,6 +133,7 @@ namespace Flow.Launcher.Plugin.Program.Views
{ {
btnProgramSourceStatus.Visibility = Visibility.Hidden; btnProgramSourceStatus.Visibility = Visibility.Hidden;
btnEditProgramSource.Visibility = Visibility.Hidden; btnEditProgramSource.Visibility = Visibility.Hidden;
btnDeleteProgramSource.Visibility = Visibility.Hidden;
} }
if (programSourceView.Items.Count > 0 if (programSourceView.Items.Count > 0
@ -141,6 +142,7 @@ namespace Flow.Launcher.Plugin.Program.Views
{ {
btnProgramSourceStatus.Visibility = Visibility.Visible; btnProgramSourceStatus.Visibility = Visibility.Visible;
btnEditProgramSource.Visibility = Visibility.Visible; btnEditProgramSource.Visibility = Visibility.Visible;
btnDeleteProgramSource.Visibility = Visibility.Visible;
} }
programSourceView.Items.Refresh(); programSourceView.Items.Refresh();
@ -270,8 +272,8 @@ namespace Flow.Launcher.Plugin.Program.Views
if (directoriesToAdd.Count > 0) if (directoriesToAdd.Count > 0)
{ {
directoriesToAdd.ForEach(x => _settings.ProgramSources.Add(x)); directoriesToAdd.ForEach(_settings.ProgramSources.Add);
directoriesToAdd.ForEach(x => ProgramSettingDisplayList.Add(x)); directoriesToAdd.ForEach(ProgramSettingDisplayList.Add);
ViewRefresh(); ViewRefresh();
ReIndexing(); ReIndexing();
@ -296,24 +298,11 @@ namespace Flow.Launcher.Plugin.Program.Views
if (selectedItems.Count == 0) if (selectedItems.Count == 0)
{ {
string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source"); context.API.ShowMsgBox(context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source"));
context.API.ShowMsgBox(msg);
return; return;
} }
if (IsAllItemsUserAdded(selectedItems)) if (HasMoreOrEqualEnabledItems(selectedItems))
{
var msg = string.Format(
context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source"));
if (context.API.ShowMsgBox(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
{
return;
}
DeleteProgramSources(selectedItems);
}
else if (HasMoreOrEqualEnabledItems(selectedItems))
{ {
await ProgramSettingDisplay.SetProgramSourcesStatusAsync(selectedItems, false); await ProgramSettingDisplay.SetProgramSourcesStatusAsync(selectedItems, false);
@ -341,10 +330,9 @@ namespace Flow.Launcher.Plugin.Program.Views
private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e) private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
{ {
var headerClicked = e.OriginalSource as GridViewColumnHeader;
ListSortDirection direction; ListSortDirection direction;
if (headerClicked != null) if (e.OriginalSource is GridViewColumnHeader headerClicked)
{ {
if (headerClicked.Role != GridViewColumnHeaderRole.Padding) if (headerClicked.Role != GridViewColumnHeaderRole.Padding)
{ {
@ -380,7 +368,7 @@ namespace Flow.Launcher.Plugin.Program.Views
var dataView = CollectionViewSource.GetDefaultView(programSourceView.ItemsSource); var dataView = CollectionViewSource.GetDefaultView(programSourceView.ItemsSource);
dataView.SortDescriptions.Clear(); dataView.SortDescriptions.Clear();
SortDescription sd = new SortDescription(sortBy, direction); var sd = new SortDescription(sortBy, direction);
dataView.SortDescriptions.Add(sd); dataView.SortDescriptions.Add(sd);
dataView.Refresh(); dataView.Refresh();
} }
@ -397,11 +385,7 @@ namespace Flow.Launcher.Plugin.Program.Views
.SelectedItems.Cast<ProgramSource>() .SelectedItems.Cast<ProgramSource>()
.ToList(); .ToList();
if (IsAllItemsUserAdded(selectedItems)) if (HasMoreOrEqualEnabledItems(selectedItems))
{
btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_delete");
}
else if (HasMoreOrEqualEnabledItems(selectedItems))
{ {
btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_disable"); btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_disable");
} }
@ -420,6 +404,41 @@ namespace Flow.Launcher.Plugin.Program.Views
} }
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]
private async void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
{
var selectedItems = programSourceView
.SelectedItems.Cast<ProgramSource>()
.ToList();
if (selectedItems.Count == 0)
{
context.API.ShowMsgBox(context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source"));
return;
}
if (!IsAllItemsUserAdded(selectedItems))
{
context.API.ShowMsgBox(context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source_select_user_added"));
return;
}
if (context.API.ShowMsgBox(context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source"),
string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
{
return;
}
DeleteProgramSources(selectedItems);
if (await selectedItems.IsReindexRequiredAsync())
ReIndexing();
programSourceView.SelectedItems.Clear();
ViewRefresh();
}
private bool IsAllItemsUserAdded(List<ProgramSource> items) private bool IsAllItemsUserAdded(List<ProgramSource> items)
{ {
return items.All(x => _settings.ProgramSources.Any(y => y.UniqueIdentifier == x.UniqueIdentifier)); return items.All(x => _settings.ProgramSources.Any(y => y.UniqueIdentifier == x.UniqueIdentifier));
@ -427,8 +446,8 @@ namespace Flow.Launcher.Plugin.Program.Views
private void ListView_SizeChanged(object sender, SizeChangedEventArgs e) private void ListView_SizeChanged(object sender, SizeChangedEventArgs e)
{ {
ListView listView = sender as ListView; var listView = sender as ListView;
GridView gView = listView.View as GridView; var gView = listView.View as GridView;
var workingWidth = var workingWidth =
listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar