Skip to content

Commit aca603b

Browse files
authored
Merge pull request LykosAI#745 from ionite34/hide-empty-categories
add hide empty categories toggle
2 parents 370f6d7 + 8b6d9d6 commit aca603b

4 files changed

Lines changed: 64 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
88
## v2.12.0-dev.3
99
### Added
1010
- Added Settings option "Console: History Size" to adjust the number of lines stored in the console history when running packages. Defaults to 9001 lines.
11-
- Added "New Directory" and "Delete" options to the context menu of the tree view on the Checkpoints page.
12-
- Added new toggle for dragging and dropping models on the Checkpoints page, when enabled, all selected models will now move together with the dragged model
13-
- Added "File Size" sorting option to the Checkpoints page
11+
#### Checkpoint Manager
12+
- Added "New Directory" and "Delete" options to the context menu of the tree view.
13+
- Added new toggle for drag & drop - when enabled, all selected models will now move together with the dragged model
14+
- Added "File Size" sorting option
15+
- Added "Hide Empty Categories" toggle
16+
- Added "Select All" button to the InfoBar (shown when at least one model is selected)
1417
### Changed
1518
- The "Download Failed" message for model downloads is now persistent until dismissed
1619
### Fixed

StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ ServiceManager<ViewModelBase> dialogFactory
129129
[ObservableProperty]
130130
private bool dragMovesAllSelected = true;
131131

132+
[ObservableProperty]
133+
private bool hideEmptyRootCategories;
134+
132135
public string ClearButtonText =>
133136
SelectedBaseModels.Count == BaseModelOptions.Count
134137
? Resources.Action_ClearSelection
@@ -289,18 +292,25 @@ or nameof(SortConnectedModelsFirst)
289292
x
290293
)
291294
)
292-
.Sort(comparerObservable)
293-
.Bind(Models)
295+
.SortAndBind(Models, comparerObservable)
294296
.WhenPropertyChanged(p => p.IsSelected)
295297
.Throttle(TimeSpan.FromMilliseconds(50))
296298
.Subscribe(_ =>
297299
{
298300
NumItemsSelected = Models.Count(o => o.IsSelected);
299301
});
300302

303+
var categoryFilterPredicate = Observable
304+
.FromEventPattern<PropertyChangedEventArgs>(this, nameof(PropertyChanged))
305+
.Where(x => x.EventArgs.PropertyName is nameof(HideEmptyRootCategories))
306+
.Throttle(TimeSpan.FromMilliseconds(50))
307+
.Select(_ => (Func<CheckpointCategory, bool>)FilterCategories)
308+
.AsObservable();
309+
301310
categoriesCache
302311
.Connect()
303312
.DeferUntilLoaded()
313+
.Filter(categoryFilterPredicate)
304314
.SortAndBind(
305315
Categories,
306316
SortExpressionComparer<CheckpointCategory>
@@ -362,6 +372,13 @@ or nameof(SortConnectedModelsFirst)
362372
true
363373
);
364374

375+
settingsManager.RelayPropertyFor(
376+
this,
377+
vm => vm.HideEmptyRootCategories,
378+
settings => settings.HideEmptyRootCategories,
379+
true
380+
);
381+
365382
// make sure a sort happens
366383
OnPropertyChanged(nameof(SortConnectedModelsFirst));
367384
}
@@ -665,6 +682,12 @@ private async Task DeleteFolderAsync(object? treeViewItem)
665682
RefreshCategories();
666683
}
667684

685+
[RelayCommand]
686+
private void SelectAll()
687+
{
688+
Models.ForEach(x => x.IsSelected = true);
689+
}
690+
668691
public async Task ImportFilesAsync(IEnumerable<string> files, DirectoryPath destinationFolder)
669692
{
670693
if (destinationFolder.FullPath == settingsManager.ModelsDirectory)
@@ -809,6 +832,13 @@ private void RefreshCategories()
809832
)
810833
.ToList();
811834

835+
foreach (var checkpointCategory in modelCategories.SelectMany(c => c.Flatten()))
836+
{
837+
checkpointCategory.Count = Directory
838+
.EnumerateFileSystemEntries(checkpointCategory.Path, "*", SearchOption.AllDirectories)
839+
.Count(x => LocalModelFile.SupportedCheckpointExtensions.Contains(Path.GetExtension(x)));
840+
}
841+
812842
var rootCategory = new CheckpointCategory
813843
{
814844
Path = settingsManager.ModelsDirectory,
@@ -843,13 +873,6 @@ private void RefreshCategories()
843873
previouslySelectedCategory
844874
?? Categories.FirstOrDefault(x => x.Path == previouslySelectedCategory?.Path)
845875
?? Categories.First();
846-
847-
foreach (var checkpointCategory in Categories.SelectMany(c => c.Flatten()))
848-
{
849-
checkpointCategory.Count = Directory
850-
.EnumerateFileSystemEntries(checkpointCategory.Path, "*", SearchOption.AllDirectories)
851-
.Count(x => LocalModelFile.SupportedCheckpointExtensions.Contains(Path.GetExtension(x)));
852-
}
853876
}
854877

855878
private ObservableCollection<CheckpointCategory> GetSubfolders(string strPath)
@@ -953,4 +976,9 @@ is false
953976
? folderPath.Contains(categoryRelativePath)
954977
: categoryRelativePath.Equals(folderPath);
955978
}
979+
980+
private bool FilterCategories(CheckpointCategory category)
981+
{
982+
return !HideEmptyRootCategories || category is { Count: > 0 };
983+
}
956984
}

StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@
280280
Label="Move All Selected Models"
281281
ToolTip.Tip="When enabled, dragging and dropping a model will also move any selected models to the drop location."
282282
IsChecked="{Binding DragMovesAllSelected, Mode=TwoWay}" />
283+
<ui:CommandBarToggleButton
284+
Label="Hide Empty Categories"
285+
IsChecked="{Binding HideEmptyRootCategories}">
286+
<ui:CommandBarToggleButton.IconSource>
287+
<controls:FASymbolIconSource Symbol="fa-regular fa-eye-slash"/>
288+
</ui:CommandBarToggleButton.IconSource>
289+
</ui:CommandBarToggleButton>
283290
</ui:CommandBar.SecondaryCommands>
284291
</ui:CommandBar>
285292
</Grid>
@@ -619,10 +626,18 @@
619626
</MultiBinding>
620627
</ui:InfoBar.Title>
621628
<ui:InfoBar.ActionButton>
622-
<Button
623-
Classes="danger"
624-
Command="{Binding DeleteCommand}"
625-
Content="{x:Static lang:Resources.Action_Delete}" />
629+
<StackPanel Orientation="Horizontal" Spacing="6">
630+
<Button Classes="accent"
631+
Content="{x:Static lang:Resources.Action_SelectAll}"
632+
Command="{Binding SelectAllCommand}"/>
633+
<Rectangle Width="2"
634+
Margin="4,2"
635+
VerticalAlignment="Stretch"
636+
Fill="Gray"/>
637+
<Button Classes="danger"
638+
Command="{Binding DeleteCommand}"
639+
Content="{x:Static lang:Resources.Action_Delete}" />
640+
</StackPanel>
626641
</ui:InfoBar.ActionButton>
627642
</ui:InfoBar>
628643
</Grid>

StabilityMatrix.Core/Models/Settings/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ public IReadOnlyDictionary<string, string> EnvironmentVariables
194194

195195
public bool DragMovesAllSelected { get; set; } = true;
196196

197+
public bool HideEmptyRootCategories { get; set; } = false;
198+
197199
[JsonIgnore]
198200
public bool IsHolidayModeActive =>
199201
HolidayModeSetting == HolidayMode.Automatic

0 commit comments

Comments
 (0)