mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #3539 from Flow-Launcher/program_plugin_delete_logic
Improve Program plugin delete button logic
This commit is contained in:
commit
54c949b3ca
3 changed files with 54 additions and 27 deletions
|
|
@ -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_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_edit_program_source_title">Program Source</system:String>
|
||||
|
|
|
|||
|
|
@ -203,6 +203,12 @@
|
|||
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
|
||||
Click="btnEditProgramSource_OnClick"
|
||||
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
|
||||
x:Name="btnAddProgramSource"
|
||||
MinWidth="100"
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
{
|
||||
btnProgramSourceStatus.Visibility = Visibility.Hidden;
|
||||
btnEditProgramSource.Visibility = Visibility.Hidden;
|
||||
btnDeleteProgramSource.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
if (programSourceView.Items.Count > 0
|
||||
|
|
@ -141,6 +142,7 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
{
|
||||
btnProgramSourceStatus.Visibility = Visibility.Visible;
|
||||
btnEditProgramSource.Visibility = Visibility.Visible;
|
||||
btnDeleteProgramSource.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
programSourceView.Items.Refresh();
|
||||
|
|
@ -270,8 +272,8 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
|
||||
if (directoriesToAdd.Count > 0)
|
||||
{
|
||||
directoriesToAdd.ForEach(x => _settings.ProgramSources.Add(x));
|
||||
directoriesToAdd.ForEach(x => ProgramSettingDisplayList.Add(x));
|
||||
directoriesToAdd.ForEach(_settings.ProgramSources.Add);
|
||||
directoriesToAdd.ForEach(ProgramSettingDisplayList.Add);
|
||||
|
||||
ViewRefresh();
|
||||
ReIndexing();
|
||||
|
|
@ -296,24 +298,11 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
|
||||
if (selectedItems.Count == 0)
|
||||
{
|
||||
string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
|
||||
context.API.ShowMsgBox(msg);
|
||||
context.API.ShowMsgBox(context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsAllItemsUserAdded(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))
|
||||
if (HasMoreOrEqualEnabledItems(selectedItems))
|
||||
{
|
||||
await ProgramSettingDisplay.SetProgramSourcesStatusAsync(selectedItems, false);
|
||||
|
||||
|
|
@ -341,10 +330,9 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
|
||||
private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var headerClicked = e.OriginalSource as GridViewColumnHeader;
|
||||
ListSortDirection direction;
|
||||
|
||||
if (headerClicked != null)
|
||||
if (e.OriginalSource is GridViewColumnHeader headerClicked)
|
||||
{
|
||||
if (headerClicked.Role != GridViewColumnHeaderRole.Padding)
|
||||
{
|
||||
|
|
@ -380,7 +368,7 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
var dataView = CollectionViewSource.GetDefaultView(programSourceView.ItemsSource);
|
||||
|
||||
dataView.SortDescriptions.Clear();
|
||||
SortDescription sd = new SortDescription(sortBy, direction);
|
||||
var sd = new SortDescription(sortBy, direction);
|
||||
dataView.SortDescriptions.Add(sd);
|
||||
dataView.Refresh();
|
||||
}
|
||||
|
|
@ -397,11 +385,7 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
.SelectedItems.Cast<ProgramSource>()
|
||||
.ToList();
|
||||
|
||||
if (IsAllItemsUserAdded(selectedItems))
|
||||
{
|
||||
btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_delete");
|
||||
}
|
||||
else if (HasMoreOrEqualEnabledItems(selectedItems))
|
||||
if (HasMoreOrEqualEnabledItems(selectedItems))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
ListView listView = sender as ListView;
|
||||
GridView gView = listView.View as GridView;
|
||||
var listView = sender as ListView;
|
||||
var gView = listView.View as GridView;
|
||||
|
||||
var workingWidth =
|
||||
listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar
|
||||
|
|
|
|||
Loading…
Reference in a new issue