Skip to content

Commit

Permalink
Merge pull request LykosAI#745 from ionite34/hide-empty-categories
Browse files Browse the repository at this point in the history
add hide empty categories toggle
  • Loading branch information
mohnjiles authored Aug 2, 2024
2 parents 370f6d7 + 8b6d9d6 commit aca603b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
## v2.12.0-dev.3
### Added
- Added Settings option "Console: History Size" to adjust the number of lines stored in the console history when running packages. Defaults to 9001 lines.
- Added "New Directory" and "Delete" options to the context menu of the tree view on the Checkpoints page.
- 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
- Added "File Size" sorting option to the Checkpoints page
#### Checkpoint Manager
- Added "New Directory" and "Delete" options to the context menu of the tree view.
- Added new toggle for drag & drop - when enabled, all selected models will now move together with the dragged model
- Added "File Size" sorting option
- Added "Hide Empty Categories" toggle
- Added "Select All" button to the InfoBar (shown when at least one model is selected)
### Changed
- The "Download Failed" message for model downloads is now persistent until dismissed
### Fixed
Expand Down
46 changes: 37 additions & 9 deletions StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ ServiceManager<ViewModelBase> dialogFactory
[ObservableProperty]
private bool dragMovesAllSelected = true;

[ObservableProperty]
private bool hideEmptyRootCategories;

public string ClearButtonText =>
SelectedBaseModels.Count == BaseModelOptions.Count
? Resources.Action_ClearSelection
Expand Down Expand Up @@ -289,18 +292,25 @@ or nameof(SortConnectedModelsFirst)
x
)
)
.Sort(comparerObservable)
.Bind(Models)
.SortAndBind(Models, comparerObservable)
.WhenPropertyChanged(p => p.IsSelected)
.Throttle(TimeSpan.FromMilliseconds(50))
.Subscribe(_ =>
{
NumItemsSelected = Models.Count(o => o.IsSelected);
});

var categoryFilterPredicate = Observable
.FromEventPattern<PropertyChangedEventArgs>(this, nameof(PropertyChanged))
.Where(x => x.EventArgs.PropertyName is nameof(HideEmptyRootCategories))
.Throttle(TimeSpan.FromMilliseconds(50))
.Select(_ => (Func<CheckpointCategory, bool>)FilterCategories)
.AsObservable();

categoriesCache
.Connect()
.DeferUntilLoaded()
.Filter(categoryFilterPredicate)
.SortAndBind(
Categories,
SortExpressionComparer<CheckpointCategory>
Expand Down Expand Up @@ -362,6 +372,13 @@ or nameof(SortConnectedModelsFirst)
true
);

settingsManager.RelayPropertyFor(
this,
vm => vm.HideEmptyRootCategories,
settings => settings.HideEmptyRootCategories,
true
);

// make sure a sort happens
OnPropertyChanged(nameof(SortConnectedModelsFirst));
}
Expand Down Expand Up @@ -665,6 +682,12 @@ private async Task DeleteFolderAsync(object? treeViewItem)
RefreshCategories();
}

[RelayCommand]
private void SelectAll()
{
Models.ForEach(x => x.IsSelected = true);
}

public async Task ImportFilesAsync(IEnumerable<string> files, DirectoryPath destinationFolder)
{
if (destinationFolder.FullPath == settingsManager.ModelsDirectory)
Expand Down Expand Up @@ -809,6 +832,13 @@ private void RefreshCategories()
)
.ToList();

foreach (var checkpointCategory in modelCategories.SelectMany(c => c.Flatten()))
{
checkpointCategory.Count = Directory
.EnumerateFileSystemEntries(checkpointCategory.Path, "*", SearchOption.AllDirectories)
.Count(x => LocalModelFile.SupportedCheckpointExtensions.Contains(Path.GetExtension(x)));
}

var rootCategory = new CheckpointCategory
{
Path = settingsManager.ModelsDirectory,
Expand Down Expand Up @@ -843,13 +873,6 @@ private void RefreshCategories()
previouslySelectedCategory
?? Categories.FirstOrDefault(x => x.Path == previouslySelectedCategory?.Path)
?? Categories.First();

foreach (var checkpointCategory in Categories.SelectMany(c => c.Flatten()))
{
checkpointCategory.Count = Directory
.EnumerateFileSystemEntries(checkpointCategory.Path, "*", SearchOption.AllDirectories)
.Count(x => LocalModelFile.SupportedCheckpointExtensions.Contains(Path.GetExtension(x)));
}
}

private ObservableCollection<CheckpointCategory> GetSubfolders(string strPath)
Expand Down Expand Up @@ -953,4 +976,9 @@ is false
? folderPath.Contains(categoryRelativePath)
: categoryRelativePath.Equals(folderPath);
}

private bool FilterCategories(CheckpointCategory category)
{
return !HideEmptyRootCategories || category is { Count: > 0 };
}
}
23 changes: 19 additions & 4 deletions StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@
Label="Move All Selected Models"
ToolTip.Tip="When enabled, dragging and dropping a model will also move any selected models to the drop location."
IsChecked="{Binding DragMovesAllSelected, Mode=TwoWay}" />
<ui:CommandBarToggleButton
Label="Hide Empty Categories"
IsChecked="{Binding HideEmptyRootCategories}">
<ui:CommandBarToggleButton.IconSource>
<controls:FASymbolIconSource Symbol="fa-regular fa-eye-slash"/>
</ui:CommandBarToggleButton.IconSource>
</ui:CommandBarToggleButton>
</ui:CommandBar.SecondaryCommands>
</ui:CommandBar>
</Grid>
Expand Down Expand Up @@ -619,10 +626,18 @@
</MultiBinding>
</ui:InfoBar.Title>
<ui:InfoBar.ActionButton>
<Button
Classes="danger"
Command="{Binding DeleteCommand}"
Content="{x:Static lang:Resources.Action_Delete}" />
<StackPanel Orientation="Horizontal" Spacing="6">
<Button Classes="accent"
Content="{x:Static lang:Resources.Action_SelectAll}"
Command="{Binding SelectAllCommand}"/>
<Rectangle Width="2"
Margin="4,2"
VerticalAlignment="Stretch"
Fill="Gray"/>
<Button Classes="danger"
Command="{Binding DeleteCommand}"
Content="{x:Static lang:Resources.Action_Delete}" />
</StackPanel>
</ui:InfoBar.ActionButton>
</ui:InfoBar>
</Grid>
Expand Down
2 changes: 2 additions & 0 deletions StabilityMatrix.Core/Models/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public IReadOnlyDictionary<string, string> EnvironmentVariables

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

public bool HideEmptyRootCategories { get; set; } = false;

[JsonIgnore]
public bool IsHolidayModeActive =>
HolidayModeSetting == HolidayMode.Automatic
Expand Down

0 comments on commit aca603b

Please sign in to comment.