Browse Source

fix drag & drop targets not showing and clean up page selector for civit browser

pull/324/head
JT 12 months ago
parent
commit
bf2a02b5ef
  1. 9
      StabilityMatrix.Avalonia/Languages/Resources.Designer.cs
  2. 3
      StabilityMatrix.Avalonia/Languages/Resources.es.resx
  3. 3
      StabilityMatrix.Avalonia/Languages/Resources.fr-FR.resx
  4. 3
      StabilityMatrix.Avalonia/Languages/Resources.it-it.resx
  5. 3
      StabilityMatrix.Avalonia/Languages/Resources.ja-JP.resx
  6. 3
      StabilityMatrix.Avalonia/Languages/Resources.resx
  7. 3
      StabilityMatrix.Avalonia/Languages/Resources.ru-ru.resx
  8. 3
      StabilityMatrix.Avalonia/Languages/Resources.zh-Hans.resx
  9. 3
      StabilityMatrix.Avalonia/Languages/Resources.zh-Hant.resx
  10. 69
      StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFile.cs
  11. 25
      StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml.cs
  12. 93
      StabilityMatrix.Avalonia/Views/CivitAiBrowserPage.axaml

9
StabilityMatrix.Avalonia/Languages/Resources.Designer.cs generated

@ -788,6 +788,15 @@ namespace StabilityMatrix.Avalonia.Languages {
}
}
/// <summary>
/// Looks up a localized string similar to CivitAI.
/// </summary>
public static string Label_CivitAi {
get {
return ResourceManager.GetString("Label_CivitAi", resourceCulture);
}
}
/// <summary>
/// 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..
/// </summary>

3
StabilityMatrix.Avalonia/Languages/Resources.es.resx

@ -680,4 +680,7 @@
<data name="Action_RestoreDefaultLayout" xml:space="preserve">
<value>Restablecer Diseño Predeterminado</value>
</data>
<data name="Label_CivitAi" xml:space="preserve">
<value>CivitAI</value>
</data>
</root>

3
StabilityMatrix.Avalonia/Languages/Resources.fr-FR.resx

@ -678,4 +678,7 @@
<data name="Action_RestoreDefaultLayout" xml:space="preserve">
<value>Rétablir la présentation par défaut</value>
</data>
<data name="Label_CivitAi" xml:space="preserve">
<value>CivitAI</value>
</data>
</root>

3
StabilityMatrix.Avalonia/Languages/Resources.it-it.resx

@ -680,4 +680,7 @@
<data name="Action_RestoreDefaultLayout" xml:space="preserve">
<value></value>
</data>
<data name="Label_CivitAi" xml:space="preserve">
<value>CivitAI</value>
</data>
</root>

3
StabilityMatrix.Avalonia/Languages/Resources.ja-JP.resx

@ -680,4 +680,7 @@
<data name="Action_RestoreDefaultLayout" xml:space="preserve">
<value>レイアウトを初期状態に戻す</value>
</data>
<data name="Label_CivitAi" xml:space="preserve">
<value>CivitAI</value>
</data>
</root>

3
StabilityMatrix.Avalonia/Languages/Resources.resx

@ -852,4 +852,7 @@
<data name="Label_SystemInformation" xml:space="preserve">
<value>System Information</value>
</data>
<data name="Label_CivitAi" xml:space="preserve">
<value>CivitAI</value>
</data>
</root>

3
StabilityMatrix.Avalonia/Languages/Resources.ru-ru.resx

@ -678,4 +678,7 @@
<data name="Action_RestoreDefaultLayout" xml:space="preserve">
<value>Восстановить вид по умолчанию</value>
</data>
<data name="Label_CivitAi" xml:space="preserve">
<value>CivitAI</value>
</data>
</root>

3
StabilityMatrix.Avalonia/Languages/Resources.zh-Hans.resx

@ -647,4 +647,7 @@
<data name="Label_Branch" xml:space="preserve">
<value>分支</value>
</data>
<data name="Label_CivitAi" xml:space="preserve">
<value>CivitAI</value>
</data>
</root>

3
StabilityMatrix.Avalonia/Languages/Resources.zh-Hant.resx

@ -639,4 +639,7 @@
<data name="Label_Branch" xml:space="preserve">
<value>分支</value>
</data>
<data name="Label_CivitAi" xml:space="preserve">
<value>CivitAI</value>
</data>
</root>

69
StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFile.cs

@ -70,15 +70,8 @@ public partial class CheckpointFile : ViewModelBase
public ObservableCollection<string> 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<CheckpointFile> 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<CheckpointFile> FilePathComparer { get; } =
new FilePathEqualityComparer();
public static IEqualityComparer<CheckpointFile> FilePathComparer { get; } = new FilePathEqualityComparer();
}

25
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;
}
}

93
StabilityMatrix.Avalonia/Views/CivitAiBrowserPage.axaml

@ -462,57 +462,52 @@
<TextBlock
Grid.Row="2"
Margin="8,8"
VerticalAlignment="Bottom"
VerticalAlignment="Center"
Text="{x:Static lang:Resources.Label_DataProvidedByCivitAi}" />
<StackPanel
Grid.Row="2"
Margin="8"
HorizontalAlignment="Center"
IsVisible="{Binding HasSearched}"
Orientation="Vertical">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Margin="0,0,0,8">
<TextBlock Margin="0,0,4,0" TextAlignment="Center"
Text="{x:Static lang:Resources.Label_Page}"
VerticalAlignment="Center"/>
<ui:NumberBox Value="{Binding CurrentPageNumber, FallbackValue=1}"
VerticalAlignment="Center"
SpinButtonPlacementMode="Hidden"
TextAlignment="Center"/>
<TextBlock Margin="4,0,0,0" VerticalAlignment="Center">
<Run Text="/"/>
<Run Text="{Binding TotalPages, FallbackValue=5}"/>
</TextBlock>
</StackPanel>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button
Margin="0,0,8,0"
Command="{Binding FirstPage}"
IsEnabled="{Binding CanGoToFirstPage}"
ToolTip.Tip="{x:Static lang:Resources.Label_FirstPage}">
<avalonia:Icon Value="fa-solid fa-backward-fast" />
</Button>
<Button
Margin="0,0,8,0"
Command="{Binding PreviousPage}"
IsEnabled="{Binding CanGoToPreviousPage}"
ToolTip.Tip="{x:Static lang:Resources.Label_PreviousPage}">
<avalonia:Icon Value="fa-solid fa-caret-left" />
</Button>
<Button
Margin="0,0,8,0"
Command="{Binding NextPage}"
IsEnabled="{Binding CanGoToNextPage}"
ToolTip.Tip="{x:Static lang:Resources.Label_NextPage}">
<avalonia:Icon Value="fa-solid fa-caret-right" />
</Button>
<Button
Command="{Binding LastPage}"
IsEnabled="{Binding CanGoToLastPage}"
ToolTip.Tip="{x:Static lang:Resources.Label_LastPage}">
<avalonia:Icon Value="fa-solid fa-forward-fast" />
</Button>
</StackPanel>
<StackPanel Grid.Row="2"
HorizontalAlignment="Center"
IsVisible="{Binding HasSearched}"
Margin="0,8,0,8"
Orientation="Horizontal">
<Button
Margin="0,0,8,0"
Command="{Binding FirstPage}"
IsEnabled="{Binding CanGoToFirstPage}"
ToolTip.Tip="{x:Static lang:Resources.Label_FirstPage}">
<avalonia:Icon Value="fa-solid fa-backward-fast" />
</Button>
<Button
Margin="0,0,16,0"
Command="{Binding PreviousPage}"
IsEnabled="{Binding CanGoToPreviousPage}"
ToolTip.Tip="{x:Static lang:Resources.Label_PreviousPage}">
<avalonia:Icon Value="fa-solid fa-caret-left" />
</Button>
<TextBlock Margin="8,0,4,0" TextAlignment="Center"
Text="{x:Static lang:Resources.Label_Page}"
VerticalAlignment="Center"/>
<ui:NumberBox Value="{Binding CurrentPageNumber, FallbackValue=1}"
VerticalAlignment="Center"
SpinButtonPlacementMode="Hidden"
TextAlignment="Center"/>
<TextBlock Margin="4,0,8,0" VerticalAlignment="Center">
<Run Text="/"/>
<Run Text="{Binding TotalPages, FallbackValue=5}"/>
</TextBlock>
<Button
Margin="16,0,8,0"
Command="{Binding NextPage}"
IsEnabled="{Binding CanGoToNextPage}"
ToolTip.Tip="{x:Static lang:Resources.Label_NextPage}">
<avalonia:Icon Value="fa-solid fa-caret-right" />
</Button>
<Button
Command="{Binding LastPage}"
IsEnabled="{Binding CanGoToLastPage}"
ToolTip.Tip="{x:Static lang:Resources.Label_LastPage}">
<avalonia:Icon Value="fa-solid fa-forward-fast" />
</Button>
</StackPanel>
<TextBlock

Loading…
Cancel
Save