From bf2a02b5ef7ad206e4dc91c0f0d16aa30db35981 Mon Sep 17 00:00:00 2001 From: JT Date: Sat, 2 Dec 2023 19:17:32 -0800 Subject: [PATCH] fix drag & drop targets not showing and clean up page selector for civit browser --- .../Languages/Resources.Designer.cs | 9 ++ .../Languages/Resources.es.resx | 3 + .../Languages/Resources.fr-FR.resx | 3 + .../Languages/Resources.it-it.resx | 3 + .../Languages/Resources.ja-JP.resx | 3 + .../Languages/Resources.resx | 3 + .../Languages/Resources.ru-ru.resx | 3 + .../Languages/Resources.zh-Hans.resx | 3 + .../Languages/Resources.zh-Hant.resx | 3 + .../CheckpointManager/CheckpointFile.cs | 69 +++----------- .../Views/CheckpointsPage.axaml.cs | 25 +++-- .../Views/CivitAiBrowserPage.axaml | 93 +++++++++---------- 12 files changed, 107 insertions(+), 113 deletions(-) diff --git a/StabilityMatrix.Avalonia/Languages/Resources.Designer.cs b/StabilityMatrix.Avalonia/Languages/Resources.Designer.cs index 481fceb6..d6961696 100644 --- a/StabilityMatrix.Avalonia/Languages/Resources.Designer.cs +++ b/StabilityMatrix.Avalonia/Languages/Resources.Designer.cs @@ -788,6 +788,15 @@ namespace StabilityMatrix.Avalonia.Languages { } } + /// + /// Looks up a localized string similar to CivitAI. + /// + public static string Label_CivitAi { + get { + return ResourceManager.GetString("Label_CivitAi", resourceCulture); + } + } + /// /// Looks up a localized string similar to You must be logged in to download this checkpoint. Please enter a CivitAI API Key in the settings.. /// diff --git a/StabilityMatrix.Avalonia/Languages/Resources.es.resx b/StabilityMatrix.Avalonia/Languages/Resources.es.resx index 3b586761..46da9160 100644 --- a/StabilityMatrix.Avalonia/Languages/Resources.es.resx +++ b/StabilityMatrix.Avalonia/Languages/Resources.es.resx @@ -680,4 +680,7 @@ Restablecer Diseño Predeterminado + + CivitAI + \ No newline at end of file diff --git a/StabilityMatrix.Avalonia/Languages/Resources.fr-FR.resx b/StabilityMatrix.Avalonia/Languages/Resources.fr-FR.resx index 8623c810..574d80e7 100644 --- a/StabilityMatrix.Avalonia/Languages/Resources.fr-FR.resx +++ b/StabilityMatrix.Avalonia/Languages/Resources.fr-FR.resx @@ -678,4 +678,7 @@ Rétablir la présentation par défaut + + CivitAI + \ No newline at end of file diff --git a/StabilityMatrix.Avalonia/Languages/Resources.it-it.resx b/StabilityMatrix.Avalonia/Languages/Resources.it-it.resx index cadda8ef..dd3bcc3b 100644 --- a/StabilityMatrix.Avalonia/Languages/Resources.it-it.resx +++ b/StabilityMatrix.Avalonia/Languages/Resources.it-it.resx @@ -680,4 +680,7 @@ + + CivitAI + \ No newline at end of file diff --git a/StabilityMatrix.Avalonia/Languages/Resources.ja-JP.resx b/StabilityMatrix.Avalonia/Languages/Resources.ja-JP.resx index 63d37d58..4c5c7495 100644 --- a/StabilityMatrix.Avalonia/Languages/Resources.ja-JP.resx +++ b/StabilityMatrix.Avalonia/Languages/Resources.ja-JP.resx @@ -680,4 +680,7 @@ レイアウトを初期状態に戻す + + CivitAI + \ No newline at end of file diff --git a/StabilityMatrix.Avalonia/Languages/Resources.resx b/StabilityMatrix.Avalonia/Languages/Resources.resx index ea10f569..0565f91f 100644 --- a/StabilityMatrix.Avalonia/Languages/Resources.resx +++ b/StabilityMatrix.Avalonia/Languages/Resources.resx @@ -852,4 +852,7 @@ System Information + + CivitAI + diff --git a/StabilityMatrix.Avalonia/Languages/Resources.ru-ru.resx b/StabilityMatrix.Avalonia/Languages/Resources.ru-ru.resx index 149c0a0b..24716a61 100644 --- a/StabilityMatrix.Avalonia/Languages/Resources.ru-ru.resx +++ b/StabilityMatrix.Avalonia/Languages/Resources.ru-ru.resx @@ -678,4 +678,7 @@ Восстановить вид по умолчанию + + CivitAI + \ No newline at end of file diff --git a/StabilityMatrix.Avalonia/Languages/Resources.zh-Hans.resx b/StabilityMatrix.Avalonia/Languages/Resources.zh-Hans.resx index 99c38fb7..46957dca 100644 --- a/StabilityMatrix.Avalonia/Languages/Resources.zh-Hans.resx +++ b/StabilityMatrix.Avalonia/Languages/Resources.zh-Hans.resx @@ -647,4 +647,7 @@ 分支 + + CivitAI + diff --git a/StabilityMatrix.Avalonia/Languages/Resources.zh-Hant.resx b/StabilityMatrix.Avalonia/Languages/Resources.zh-Hant.resx index 49df915d..1ea14f2f 100644 --- a/StabilityMatrix.Avalonia/Languages/Resources.zh-Hant.resx +++ b/StabilityMatrix.Avalonia/Languages/Resources.zh-Hant.resx @@ -639,4 +639,7 @@ 分支 + + CivitAI + diff --git a/StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFile.cs b/StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFile.cs index 0eb0865f..333a3a02 100644 --- a/StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFile.cs +++ b/StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFile.cs @@ -70,15 +70,8 @@ public partial class CheckpointFile : ViewModelBase public ObservableCollection Badges { get; set; } = new(); - public static readonly string[] SupportedCheckpointExtensions = - { - ".safetensors", - ".pt", - ".ckpt", - ".pth", - ".bin" - }; - private static readonly string[] SupportedImageExtensions = { ".png", ".jpg", ".jpeg" }; + public static readonly string[] SupportedCheckpointExtensions = { ".safetensors", ".pt", ".ckpt", ".pth", ".bin" }; + private static readonly string[] SupportedImageExtensions = { ".png", ".jpg", ".jpeg", ".gif" }; private static readonly string[] SupportedMetadataExtensions = { ".json" }; partial void OnConnectedModelChanged(ConnectedModelInfo? value) @@ -102,9 +95,7 @@ public partial class CheckpointFile : ViewModelBase { if (string.IsNullOrEmpty(FilePath)) { - throw new InvalidOperationException( - "Cannot get connected model info file path when FilePath is empty" - ); + throw new InvalidOperationException("Cannot get connected model info file path when FilePath is empty"); } var modelNameNoExt = Path.GetFileNameWithoutExtension((string?)FilePath); var modelDir = Path.GetDirectoryName((string?)FilePath) ?? ""; @@ -201,10 +192,7 @@ public partial class CheckpointFile : ViewModelBase var cmInfoPath = Path.Combine(parentPath, $"{originalNameNoExt}.cm-info.json"); if (File.Exists(cmInfoPath)) { - File.Move( - cmInfoPath, - Path.Combine(parentPath, $"{nameNoExt}.cm-info.json") - ); + File.Move(cmInfoPath, Path.Combine(parentPath, $"{nameNoExt}.cm-info.json")); } } } @@ -239,10 +227,7 @@ public partial class CheckpointFile : ViewModelBase [RelayCommand] private async Task FindConnectedMetadata(bool forceReimport = false) { - if ( - App.Services.GetService(typeof(IMetadataImportService)) - is not IMetadataImportService importService - ) + if (App.Services.GetService(typeof(IMetadataImportService)) is not IMetadataImportService importService) return; IsLoading = true; @@ -254,11 +239,7 @@ public partial class CheckpointFile : ViewModelBase Progress = report; }); - var cmInfo = await importService.GetMetadataForFile( - FilePath, - progressReport, - forceReimport - ); + var cmInfo = await importService.GetMetadataForFile(FilePath, progressReport, forceReimport); if (cmInfo != null) { ConnectedModel = cmInfo; @@ -297,9 +278,7 @@ public partial class CheckpointFile : ViewModelBase { if ( !SupportedCheckpointExtensions.Any( - ext => - Path.GetExtension(file) - .Equals(ext, StringComparison.InvariantCultureIgnoreCase) + ext => Path.GetExtension(file).Equals(ext, StringComparison.InvariantCultureIgnoreCase) ) ) continue; @@ -310,10 +289,7 @@ public partial class CheckpointFile : ViewModelBase FilePath = Path.Combine(directory, file), }; - var jsonPath = Path.Combine( - directory, - $"{Path.GetFileNameWithoutExtension(file)}.cm-info.json" - ); + var jsonPath = Path.Combine(directory, $"{Path.GetFileNameWithoutExtension(file)}.cm-info.json"); if (File.Exists(jsonPath)) { var json = File.ReadAllText(jsonPath); @@ -322,13 +298,7 @@ public partial class CheckpointFile : ViewModelBase } checkpointFile.PreviewImagePath = SupportedImageExtensions - .Select( - ext => - Path.Combine( - directory, - $"{Path.GetFileNameWithoutExtension(file)}.preview{ext}" - ) - ) + .Select(ext => Path.Combine(directory, $"{Path.GetFileNameWithoutExtension(file)}.preview{ext}")) .Where(File.Exists) .FirstOrDefault(); @@ -345,28 +315,16 @@ public partial class CheckpointFile : ViewModelBase public static IEnumerable GetAllCheckpointFiles(string modelsDirectory) { - foreach ( - var file in Directory.EnumerateFiles( - modelsDirectory, - "*.*", - SearchOption.AllDirectories - ) - ) + foreach (var file in Directory.EnumerateFiles(modelsDirectory, "*.*", SearchOption.AllDirectories)) { if ( !SupportedCheckpointExtensions.Any( - ext => - Path.GetExtension(file) - .Equals(ext, StringComparison.InvariantCultureIgnoreCase) + ext => Path.GetExtension(file).Equals(ext, StringComparison.InvariantCultureIgnoreCase) ) ) continue; - var checkpointFile = new CheckpointFile - { - Title = Path.GetFileNameWithoutExtension(file), - FilePath = file - }; + var checkpointFile = new CheckpointFile { Title = Path.GetFileNameWithoutExtension(file), FilePath = file }; var jsonPath = Path.Combine( Path.GetDirectoryName(file) ?? "", @@ -474,6 +432,5 @@ public partial class CheckpointFile : ViewModelBase } } - public static IEqualityComparer FilePathComparer { get; } = - new FilePathEqualityComparer(); + public static IEqualityComparer FilePathComparer { get; } = new FilePathEqualityComparer(); } diff --git a/StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs b/StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs index 34fcc7aa..b7aec886 100644 --- a/StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs +++ b/StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs @@ -44,8 +44,7 @@ public partial class CheckpointsPage : UserControlBase if (DataContext is CheckpointsPageViewModel vm) { - subscription = vm.WhenPropertyChanged(m => m.ShowConnectedModelImages) - .Subscribe(_ => InvalidateRepeater()); + subscription = vm.WhenPropertyChanged(m => m.ShowConnectedModelImages).Subscribe(_ => InvalidateRepeater()); } } @@ -98,9 +97,14 @@ public partial class CheckpointsPage : UserControlBase private static void OnDragExit(object? sender, DragEventArgs e) { var sourceDataContext = (e.Source as Control)?.DataContext; - if (sourceDataContext is CheckpointFolder folder) + switch (sourceDataContext) { - folder.IsCurrentDragTarget = false; + case CheckpointFolder folder: + folder.IsCurrentDragTarget = false; + break; + case CheckpointFile file: + file.ParentFolder.IsCurrentDragTarget = false; + break; } } @@ -123,7 +127,10 @@ public partial class CheckpointsPage : UserControlBase { folder.IsExpanded = true; if (e.Data.Get("Context") is not CheckpointFile file) - return; + { + folder.IsCurrentDragTarget = true; + break; + } var filePath = new FilePath(file.FilePath); folder.IsCurrentDragTarget = filePath.Directory?.FullPath != folder.DirectoryPath; @@ -132,12 +139,14 @@ public partial class CheckpointsPage : UserControlBase case CheckpointFile file: { if (e.Data.Get("Context") is not CheckpointFile dragFile) - return; + { + file.ParentFolder.IsCurrentDragTarget = true; + break; + } var parentFolder = file.ParentFolder; var dragFilePath = new FilePath(dragFile.FilePath); - parentFolder.IsCurrentDragTarget = - dragFilePath.Directory?.FullPath != parentFolder.DirectoryPath; + parentFolder.IsCurrentDragTarget = dragFilePath.Directory?.FullPath != parentFolder.DirectoryPath; break; } } diff --git a/StabilityMatrix.Avalonia/Views/CivitAiBrowserPage.axaml b/StabilityMatrix.Avalonia/Views/CivitAiBrowserPage.axaml index 36eccf9f..f61fc605 100644 --- a/StabilityMatrix.Avalonia/Views/CivitAiBrowserPage.axaml +++ b/StabilityMatrix.Avalonia/Views/CivitAiBrowserPage.axaml @@ -462,57 +462,52 @@ - - - - - - - - - - - - - - - + + + + + + + + + + +