@@ -133,6 +133,7 @@ private void ViewRefresh()
133
133
{
134
134
btnProgramSourceStatus . Visibility = Visibility . Hidden ;
135
135
btnEditProgramSource . Visibility = Visibility . Hidden ;
136
+ btnDeleteProgramSource . Visibility = Visibility . Hidden ;
136
137
}
137
138
138
139
if ( programSourceView . Items . Count > 0
@@ -141,6 +142,7 @@ private void ViewRefresh()
141
142
{
142
143
btnProgramSourceStatus . Visibility = Visibility . Visible ;
143
144
btnEditProgramSource . Visibility = Visibility . Visible ;
145
+ btnDeleteProgramSource . Visibility = Visibility . Visible ;
144
146
}
145
147
146
148
programSourceView . Items . Refresh ( ) ;
@@ -270,8 +272,8 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
270
272
271
273
if ( directoriesToAdd . Count > 0 )
272
274
{
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 ) ;
275
277
276
278
ViewRefresh ( ) ;
277
279
ReIndexing ( ) ;
@@ -296,24 +298,12 @@ private async void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs
296
298
297
299
if ( selectedItems . Count == 0 )
298
300
{
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" ) ;
300
302
context . API . ShowMsgBox ( msg ) ;
301
303
return ;
302
304
}
303
305
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 ) )
317
307
{
318
308
await ProgramSettingDisplay . SetProgramSourcesStatusAsync ( selectedItems , false ) ;
319
309
@@ -341,10 +331,9 @@ private void ProgramSourceView_PreviewMouseRightButtonUp(object sender, MouseBut
341
331
342
332
private void GridViewColumnHeaderClickedHandler ( object sender , RoutedEventArgs e )
343
333
{
344
- var headerClicked = e . OriginalSource as GridViewColumnHeader ;
345
334
ListSortDirection direction ;
346
335
347
- if ( headerClicked != null )
336
+ if ( e . OriginalSource is GridViewColumnHeader headerClicked )
348
337
{
349
338
if ( headerClicked . Role != GridViewColumnHeaderRole . Padding )
350
339
{
@@ -397,11 +386,7 @@ private void programSourceView_SelectionChanged(object sender, SelectionChangedE
397
386
. SelectedItems . Cast < ProgramSource > ( )
398
387
. ToList ( ) ;
399
388
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 ) )
405
390
{
406
391
btnProgramSourceStatus . Content = context . API . GetTranslation ( "flowlauncher_plugin_program_disable" ) ;
407
392
}
@@ -420,15 +405,52 @@ private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventA
420
405
}
421
406
}
422
407
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
+
423
445
private bool IsAllItemsUserAdded ( List < ProgramSource > items )
424
446
{
425
447
return items . All ( x => _settings . ProgramSources . Any ( y => y . UniqueIdentifier == x . UniqueIdentifier ) ) ;
426
448
}
427
449
428
450
private void ListView_SizeChanged ( object sender , SizeChangedEventArgs e )
429
451
{
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 ;
432
454
433
455
var workingWidth =
434
456
listView . ActualWidth - SystemParameters . VerticalScrollBarWidth ; // take into account vertical scrollbar
0 commit comments