@@ -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,11 @@ 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" ) ;
300
- context . API . ShowMsgBox ( msg ) ;
301
+ context . API . ShowMsgBox ( context . API . GetTranslation ( "flowlauncher_plugin_program_pls_select_program_source" ) ) ;
301
302
return ;
302
303
}
303
304
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 ) )
317
306
{
318
307
await ProgramSettingDisplay . SetProgramSourcesStatusAsync ( selectedItems , false ) ;
319
308
@@ -341,10 +330,9 @@ private void ProgramSourceView_PreviewMouseRightButtonUp(object sender, MouseBut
341
330
342
331
private void GridViewColumnHeaderClickedHandler ( object sender , RoutedEventArgs e )
343
332
{
344
- var headerClicked = e . OriginalSource as GridViewColumnHeader ;
345
333
ListSortDirection direction ;
346
334
347
- if ( headerClicked != null )
335
+ if ( e . OriginalSource is GridViewColumnHeader headerClicked )
348
336
{
349
337
if ( headerClicked . Role != GridViewColumnHeaderRole . Padding )
350
338
{
@@ -380,7 +368,7 @@ private void Sort(string sortBy, ListSortDirection direction)
380
368
var dataView = CollectionViewSource . GetDefaultView ( programSourceView . ItemsSource ) ;
381
369
382
370
dataView . SortDescriptions . Clear ( ) ;
383
- SortDescription sd = new SortDescription ( sortBy , direction ) ;
371
+ var sd = new SortDescription ( sortBy , direction ) ;
384
372
dataView . SortDescriptions . Add ( sd ) ;
385
373
dataView . Refresh ( ) ;
386
374
}
@@ -397,11 +385,7 @@ private void programSourceView_SelectionChanged(object sender, SelectionChangedE
397
385
. SelectedItems . Cast < ProgramSource > ( )
398
386
. ToList ( ) ;
399
387
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 ) )
405
389
{
406
390
btnProgramSourceStatus . Content = context . API . GetTranslation ( "flowlauncher_plugin_program_disable" ) ;
407
391
}
@@ -420,15 +404,50 @@ private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventA
420
404
}
421
405
}
422
406
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
+
423
442
private bool IsAllItemsUserAdded ( List < ProgramSource > items )
424
443
{
425
444
return items . All ( x => _settings . ProgramSources . Any ( y => y . UniqueIdentifier == x . UniqueIdentifier ) ) ;
426
445
}
427
446
428
447
private void ListView_SizeChanged ( object sender , SizeChangedEventArgs e )
429
448
{
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 ;
432
451
433
452
var workingWidth =
434
453
listView . ActualWidth - SystemParameters . VerticalScrollBarWidth ; // take into account vertical scrollbar
0 commit comments