@@ -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,12 @@ 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" ) ;
301+ var msg = context . API . GetTranslation ( "flowlauncher_plugin_program_pls_select_program_source" ) ;
300302 context . API . ShowMsgBox ( msg ) ;
301303 return ;
302304 }
303305
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 ) )
306+ if ( HasMoreOrEqualEnabledItems ( selectedItems ) )
317307 {
318308 await ProgramSettingDisplay . SetProgramSourcesStatusAsync ( selectedItems , false ) ;
319309
@@ -341,10 +331,9 @@ private void ProgramSourceView_PreviewMouseRightButtonUp(object sender, MouseBut
341331
342332 private void GridViewColumnHeaderClickedHandler ( object sender , RoutedEventArgs e )
343333 {
344- var headerClicked = e . OriginalSource as GridViewColumnHeader ;
345334 ListSortDirection direction ;
346335
347- if ( headerClicked != null )
336+ if ( e . OriginalSource is GridViewColumnHeader headerClicked )
348337 {
349338 if ( headerClicked . Role != GridViewColumnHeaderRole . Padding )
350339 {
@@ -397,11 +386,7 @@ private void programSourceView_SelectionChanged(object sender, SelectionChangedE
397386 . SelectedItems . Cast < ProgramSource > ( )
398387 . ToList ( ) ;
399388
400- if ( IsAllItemsUserAdded ( selectedItems ) )
401- {
402- btnProgramSourceStatus . Content = context . API . GetTranslation ( "flowlauncher_plugin_program_delete" ) ;
403- }
404- else if ( HasMoreOrEqualEnabledItems ( selectedItems ) )
389+ if ( HasMoreOrEqualEnabledItems ( selectedItems ) )
405390 {
406391 btnProgramSourceStatus . Content = context . API . GetTranslation ( "flowlauncher_plugin_program_disable" ) ;
407392 }
@@ -420,15 +405,52 @@ private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventA
420405 }
421406 }
422407
408+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Usage" , "VSTHRD100:Avoid async void methods" , Justification = "<Pending>" ) ]
409+ private async void btnDeleteProgramSource_OnClick ( object sender , RoutedEventArgs e )
410+ {
411+ var selectedItems = programSourceView
412+ . SelectedItems . Cast < ProgramSource > ( )
413+ . ToList ( ) ;
414+
415+ if ( selectedItems . Count == 0 )
416+ {
417+ var msg = context . API . GetTranslation ( "flowlauncher_plugin_program_pls_select_program_source" ) ;
418+ context . API . ShowMsgBox ( msg ) ;
419+ return ;
420+ }
421+
422+ if ( ! IsAllItemsUserAdded ( selectedItems ) )
423+ {
424+ var msg1 = context . API . GetTranslation ( "flowlauncher_plugin_program_delete_program_source_not_user_added" ) ;
425+ context . API . ShowMsgBox ( msg1 ) ;
426+ return ;
427+ }
428+
429+ var msg2 = context . API . GetTranslation ( "flowlauncher_plugin_program_delete_program_source" ) ;
430+ if ( context . API . ShowMsgBox ( msg2 , string . Empty , MessageBoxButton . YesNo ) == MessageBoxResult . No )
431+ {
432+ return ;
433+ }
434+
435+ DeleteProgramSources ( selectedItems ) ;
436+
437+ if ( await selectedItems . IsReindexRequiredAsync ( ) )
438+ ReIndexing ( ) ;
439+
440+ programSourceView . SelectedItems . Clear ( ) ;
441+
442+ ViewRefresh ( ) ;
443+ }
444+
423445 private bool IsAllItemsUserAdded ( List < ProgramSource > items )
424446 {
425447 return items . All ( x => _settings . ProgramSources . Any ( y => y . UniqueIdentifier == x . UniqueIdentifier ) ) ;
426448 }
427449
428450 private void ListView_SizeChanged ( object sender , SizeChangedEventArgs e )
429451 {
430- ListView listView = sender as ListView ;
431- GridView gView = listView . View as GridView ;
452+ var listView = sender as ListView ;
453+ var gView = listView . View as GridView ;
432454
433455 var workingWidth =
434456 listView . ActualWidth - SystemParameters . VerticalScrollBarWidth ; // take into account vertical scrollbar
0 commit comments