@@ -54,11 +54,9 @@ public partial class OutputsPageViewModel : PageViewModelBase
54
54
private readonly ILogger < OutputsPageViewModel > logger ;
55
55
public override string Title => Resources . Label_OutputsPageTitle ;
56
56
57
- public override IconSource IconSource =>
58
- new SymbolIconSource { Symbol = Symbol . Grid , IsFilled = true } ;
57
+ public override IconSource IconSource => new SymbolIconSource { Symbol = Symbol . Grid , IsFilled = true } ;
59
58
60
- public SourceCache < LocalImageFile , string > OutputsCache { get ; } =
61
- new ( file => file . AbsolutePath ) ;
59
+ public SourceCache < LocalImageFile , string > OutputsCache { get ; } = new ( file => file . AbsolutePath ) ;
62
60
63
61
public IObservableCollection < OutputImageViewModel > Outputs { get ; set ; } =
64
62
new ObservableCollectionExtended < OutputImageViewModel > ( ) ;
@@ -88,8 +86,7 @@ public partial class OutputsPageViewModel : PageViewModelBase
88
86
[ ObservableProperty ]
89
87
private bool isConsolidating ;
90
88
91
- public bool CanShowOutputTypes =>
92
- SelectedCategory ? . Name ? . Equals ( "Shared Output Folder" ) ?? false ;
89
+ public bool CanShowOutputTypes => SelectedCategory ? . Name ? . Equals ( "Shared Output Folder" ) ?? false ;
93
90
94
91
public string NumImagesSelected =>
95
92
NumItemsSelected == 1
@@ -138,7 +135,7 @@ ILogger<OutputsPageViewModel> logger
138
135
delay : TimeSpan . FromMilliseconds ( 250 )
139
136
) ;
140
137
141
- RefreshCategories ( ) ;
138
+ RefreshCategories ( false ) ;
142
139
}
143
140
144
141
public override void OnLoaded ( )
@@ -163,10 +160,7 @@ public override void OnLoaded()
163
160
GetOutputs ( path ) ;
164
161
}
165
162
166
- partial void OnSelectedCategoryChanged (
167
- PackageOutputCategory ? oldValue ,
168
- PackageOutputCategory ? newValue
169
- )
163
+ partial void OnSelectedCategoryChanged ( PackageOutputCategory ? oldValue , PackageOutputCategory ? newValue )
170
164
{
171
165
if ( oldValue == newValue || newValue == null )
172
166
return ;
@@ -223,8 +217,8 @@ public async Task ShowImageDialog(OutputImageViewModel item)
223
217
)
224
218
. Subscribe ( ctx =>
225
219
{
226
- Dispatcher . UIThread
227
- . InvokeAsync ( async ( ) =>
220
+ Dispatcher
221
+ . UIThread . InvokeAsync ( async ( ) =>
228
222
{
229
223
var sender = ( ImageViewerViewModel ) ctx . Sender ! ;
230
224
var newIndex = currentIndex + ( ctx . EventArgs . IsNext ? 1 : - 1 ) ;
@@ -261,7 +255,7 @@ public Task CopyImage(string imagePath)
261
255
262
256
public void Refresh ( )
263
257
{
264
- Dispatcher . UIThread . Post ( RefreshCategories ) ;
258
+ Dispatcher . UIThread . Post ( ( ) => RefreshCategories ( ) ) ;
265
259
Dispatcher . UIThread . Post ( OnLoaded ) ;
266
260
}
267
261
@@ -430,9 +424,7 @@ public async Task ConsolidateImages()
430
424
431
425
Directory . CreateDirectory ( settingsManager . ConsolidatedImagesDirectory ) ;
432
426
433
- foreach (
434
- var category in stackPanel . Children . OfType < CheckBox > ( ) . Where ( c => c . IsChecked == true )
435
- )
427
+ foreach ( var category in stackPanel . Children . OfType < CheckBox > ( ) . Where ( c => c . IsChecked == true ) )
436
428
{
437
429
if (
438
430
string . IsNullOrWhiteSpace ( category . Tag ? . ToString ( ) )
@@ -442,13 +434,7 @@ var category in stackPanel.Children.OfType<CheckBox>().Where(c => c.IsChecked ==
442
434
443
435
var directory = category . Tag . ToString ( ) ;
444
436
445
- foreach (
446
- var path in Directory . EnumerateFiles (
447
- directory ,
448
- "*.png" ,
449
- SearchOption . AllDirectories
450
- )
451
- )
437
+ foreach ( var path in Directory . EnumerateFiles ( directory , "*.png" , SearchOption . AllDirectories ) )
452
438
{
453
439
try
454
440
{
@@ -524,7 +510,7 @@ private void GetOutputs(string directory)
524
510
}
525
511
}
526
512
527
- private void RefreshCategories ( )
513
+ private void RefreshCategories ( bool updateProperty = true )
528
514
{
529
515
if ( Design . IsDesignMode )
530
516
return ;
@@ -534,15 +520,11 @@ private void RefreshCategories()
534
520
535
521
var previouslySelectedCategory = SelectedCategory ;
536
522
537
- var packageCategories = settingsManager . Settings . InstalledPackages
538
- . Where ( x => ! x . UseSharedOutputFolder )
523
+ var packageCategories = settingsManager
524
+ . Settings . InstalledPackages . Where ( x => ! x . UseSharedOutputFolder )
539
525
. Select ( packageFactory . GetPackagePair )
540
526
. WhereNotNull ( )
541
- . Where (
542
- p =>
543
- p . BasePackage . SharedOutputFolders != null
544
- && p . BasePackage . SharedOutputFolders . Any ( )
545
- )
527
+ . Where ( p => p . BasePackage . SharedOutputFolders != null && p . BasePackage . SharedOutputFolders . Any ( ) )
546
528
. Select (
547
529
pair =>
548
530
new PackageOutputCategory
@@ -567,16 +549,22 @@ private void RefreshCategories()
567
549
568
550
packageCategories . Insert (
569
551
1 ,
570
- new PackageOutputCategory
571
- {
572
- Path = settingsManager . ImagesInferenceDirectory ,
573
- Name = "Inference"
574
- }
552
+ new PackageOutputCategory { Path = settingsManager . ImagesInferenceDirectory , Name = "Inference" }
575
553
) ;
576
554
577
555
Categories = new ObservableCollection < PackageOutputCategory > ( packageCategories ) ;
578
- SelectedCategory =
579
- Categories . FirstOrDefault ( x => x . Name == previouslySelectedCategory ? . Name )
580
- ?? Categories . First ( ) ;
556
+
557
+ if ( updateProperty )
558
+ {
559
+ SelectedCategory =
560
+ Categories . FirstOrDefault ( x => x . Name == previouslySelectedCategory ? . Name )
561
+ ?? Categories . First ( ) ;
562
+ }
563
+ else
564
+ {
565
+ selectedCategory =
566
+ Categories . FirstOrDefault ( x => x . Name == previouslySelectedCategory ? . Name )
567
+ ?? Categories . First ( ) ;
568
+ }
581
569
}
582
570
}
0 commit comments