@@ -133,6 +133,7 @@ private void ViewRefresh()
133133 {
134134 btnProgramSourceStatus . Visibility = Visibility . Hidden ;
135135 btnEditProgramSource . Visibility = Visibility . Hidden ;
136+ btnDeleteProgramSource . Visibility = Visibility . Hidden ;
136137 }
137138
138139 if ( programSourceView . Items . Count > 0
@@ -141,6 +142,7 @@ private void ViewRefresh()
141142 {
142143 btnProgramSourceStatus . Visibility = Visibility . Visible ;
143144 btnEditProgramSource . Visibility = Visibility . Visible ;
145+ btnDeleteProgramSource . Visibility = Visibility . Visible ;
144146 }
145147
146148 programSourceView . Items . Refresh ( ) ;
@@ -270,8 +272,8 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
270272
271273 if ( directoriesToAdd . Count > 0 )
272274 {
273- directoriesToAdd . ForEach ( x => _settings . ProgramSources . Add ( x ) ) ;
274- directoriesToAdd . ForEach ( x => ProgramSettingDisplayList . Add ( x ) ) ;
275+ directoriesToAdd . ForEach ( _settings . ProgramSources . Add ) ;
276+ directoriesToAdd . ForEach ( ProgramSettingDisplayList . Add ) ;
275277
276278 ViewRefresh ( ) ;
277279 ReIndexing ( ) ;
@@ -296,24 +298,11 @@ private async void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs
296298
297299 if ( selectedItems . Count == 0 )
298300 {
299- string msg = context . API . GetTranslation ( "flowlauncher_plugin_program_pls_select_program_source" ) ;
300- context . API . ShowMsgBox ( msg ) ;
301+ context . API . ShowMsgBox ( context . API . GetTranslation ( "flowlauncher_plugin_program_pls_select_program_source" ) ) ;
301302 return ;
302303 }
303304
304- if ( IsAllItemsUserAdded ( selectedItems ) )
305- {
306- var msg = string . Format (
307- context . API . GetTranslation ( "flowlauncher_plugin_program_delete_program_source" ) ) ;
308-
309- if ( context . API . ShowMsgBox ( msg , string . Empty , MessageBoxButton . YesNo ) == MessageBoxResult . No )
310- {
311- return ;
312- }
313-
314- DeleteProgramSources ( selectedItems ) ;
315- }
316- else if ( HasMoreOrEqualEnabledItems ( selectedItems ) )
305+ if ( HasMoreOrEqualEnabledItems ( selectedItems ) )
317306 {
318307 await ProgramSettingDisplay . SetProgramSourcesStatusAsync ( selectedItems , false ) ;
319308
@@ -341,10 +330,9 @@ private void ProgramSourceView_PreviewMouseRightButtonUp(object sender, MouseBut
341330
342331 private void GridViewColumnHeaderClickedHandler ( object sender , RoutedEventArgs e )
343332 {
344- var headerClicked = e . OriginalSource as GridViewColumnHeader ;
345333 ListSortDirection direction ;
346334
347- if ( headerClicked != null )
335+ if ( e . OriginalSource is GridViewColumnHeader headerClicked )
348336 {
349337 if ( headerClicked . Role != GridViewColumnHeaderRole . Padding )
350338 {
@@ -380,7 +368,7 @@ private void Sort(string sortBy, ListSortDirection direction)
380368 var dataView = CollectionViewSource . GetDefaultView ( programSourceView . ItemsSource ) ;
381369
382370 dataView . SortDescriptions . Clear ( ) ;
383- SortDescription sd = new SortDescription ( sortBy , direction ) ;
371+ var sd = new SortDescription ( sortBy , direction ) ;
384372 dataView . SortDescriptions . Add ( sd ) ;
385373 dataView . Refresh ( ) ;
386374 }
@@ -397,11 +385,7 @@ private void programSourceView_SelectionChanged(object sender, SelectionChangedE
397385 . SelectedItems . Cast < ProgramSource > ( )
398386 . ToList ( ) ;
399387
400- if ( IsAllItemsUserAdded ( selectedItems ) )
401- {
402- btnProgramSourceStatus . Content = context . API . GetTranslation ( "flowlauncher_plugin_program_delete" ) ;
403- }
404- else if ( HasMoreOrEqualEnabledItems ( selectedItems ) )
388+ if ( HasMoreOrEqualEnabledItems ( selectedItems ) )
405389 {
406390 btnProgramSourceStatus . Content = context . API . GetTranslation ( "flowlauncher_plugin_program_disable" ) ;
407391 }
@@ -420,15 +404,50 @@ private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventA
420404 }
421405 }
422406
407+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Usage" , "VSTHRD100:Avoid async void methods" , Justification = "<Pending>" ) ]
408+ private async void btnDeleteProgramSource_OnClick ( object sender , RoutedEventArgs e )
409+ {
410+ var selectedItems = programSourceView
411+ . SelectedItems . Cast < ProgramSource > ( )
412+ . ToList ( ) ;
413+
414+ if ( selectedItems . Count == 0 )
415+ {
416+ context . API . ShowMsgBox ( context . API . GetTranslation ( "flowlauncher_plugin_program_pls_select_program_source" ) ) ;
417+ return ;
418+ }
419+
420+ if ( ! IsAllItemsUserAdded ( selectedItems ) )
421+ {
422+ context . API . ShowMsgBox ( context . API . GetTranslation ( "flowlauncher_plugin_program_delete_program_source_select_user_added" ) ) ;
423+ return ;
424+ }
425+
426+ if ( context . API . ShowMsgBox ( context . API . GetTranslation ( "flowlauncher_plugin_program_delete_program_source" ) ,
427+ string . Empty , MessageBoxButton . YesNo ) == MessageBoxResult . No )
428+ {
429+ return ;
430+ }
431+
432+ DeleteProgramSources ( selectedItems ) ;
433+
434+ if ( await selectedItems . IsReindexRequiredAsync ( ) )
435+ ReIndexing ( ) ;
436+
437+ programSourceView . SelectedItems . Clear ( ) ;
438+
439+ ViewRefresh ( ) ;
440+ }
441+
423442 private bool IsAllItemsUserAdded ( List < ProgramSource > items )
424443 {
425444 return items . All ( x => _settings . ProgramSources . Any ( y => y . UniqueIdentifier == x . UniqueIdentifier ) ) ;
426445 }
427446
428447 private void ListView_SizeChanged ( object sender , SizeChangedEventArgs e )
429448 {
430- ListView listView = sender as ListView ;
431- GridView gView = listView . View as GridView ;
449+ var listView = sender as ListView ;
450+ var gView = listView . View as GridView ;
432451
433452 var workingWidth =
434453 listView . ActualWidth - SystemParameters . VerticalScrollBarWidth ; // take into account vertical scrollbar
0 commit comments