Skip to content

Commit

Permalink
Merge pull request #152 from ionite34/model-file-selector
Browse files Browse the repository at this point in the history
Model file selector
  • Loading branch information
mohnjiles authored Jul 7, 2023
2 parents ad9ce67 + 22063cd commit 20413f4
Show file tree
Hide file tree
Showing 18 changed files with 560 additions and 116 deletions.
20 changes: 16 additions & 4 deletions StabilityMatrix/CheckpointBrowserPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<BooleanToVisibilityConverter />
</converters:ValueConverterGroup>

<converters:BoolNegationConverter x:Key="BoolNegationConverter"/>
<BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />

<DataTemplate DataType="{x:Type viewModels:CheckpointBrowserCardViewModel}" x:Key="CivitModelTemplate">
Expand Down Expand Up @@ -85,12 +86,12 @@
HorizontalAlignment="Stretch"
Margin="0,8,0,8"
VerticalAlignment="Stretch"
Visibility="{Binding ImportCommand.IsRunning, Converter={StaticResource BoolToVisibilityConverter}}" />
Visibility="{Binding IsImporting, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Hidden}" />
<StackPanel
HorizontalAlignment="Stretch"
Orientation="Vertical"
VerticalAlignment="Center"
Visibility="{Binding ImportCommand.IsRunning, Converter={StaticResource BoolToVisibilityConverter}}">
Visibility="{Binding IsImporting, Converter={StaticResource BoolToVisibilityConverter}}">
<ui:ProgressRing
HorizontalAlignment="Center"
IsIndeterminate="False"
Expand All @@ -106,20 +107,31 @@
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ui:Button
Appearance="Primary"
Command="{Binding ImportCommand}"
CommandParameter="{Binding CivitModel}"
IsEnabled="{Binding IsImporting, Converter={StaticResource BoolNegationConverter}}"
HorizontalAlignment="Stretch"
Margin="0,8,0,0">
<ui:Button.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Import - "/>
<TextBlock Text="{Binding CivitModel.FullFilesSize}"/>
<TextBlock Text="Import Latest -"/>
<TextBlock Margin="4,0,0,0"
Text="{Binding CivitModel.FullFilesSize}"/>
</StackPanel>
</ui:Button.Content>
</ui:Button>

<ui:Button Grid.Column="1"
Margin="8,8,0,0"
Appearance="Primary"
IsEnabled="{Binding IsImporting, Converter={StaticResource BoolNegationConverter}}"
Command="{Binding ShowVersionDialogCommand}"
CommandParameter="{Binding CivitModel}"
Content="All Versions"/>
</Grid>
</StackPanel>
</ui:Card>
Expand Down
208 changes: 120 additions & 88 deletions StabilityMatrix/CheckpointManagerPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Loaded="CheckpointManagerPage_OnLoaded"
d:DataContext="{d:DesignInstance Type=designData:MockCheckpointManagerViewModel,
IsDesignTimeCreatable=True}"
d:DesignHeight="1000"
d:DesignWidth="650"
d:DesignHeight="650"
d:DesignWidth="1000"
mc:Ignorable="d"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Expand All @@ -14,6 +14,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:designData="clr-namespace:StabilityMatrix.DesignData"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:ci="clr-namespace:StabilityMatrix.Interactions"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="clr-namespace:StabilityMatrix.Models"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
Expand Down Expand Up @@ -270,93 +271,112 @@
Header="{Binding Title}"
IsExpanded="True"
Margin="8"
Padding="8,8,8,16"
Padding="8,8,8,8"
Visibility="{Binding IsCategoryEnabled, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Visible}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewDragEnter">
<i:InvokeCommandAction Command="{Binding OnPreviewDragEnterCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="PreviewDragLeave">
<i:InvokeCommandAction Command="{Binding OnPreviewDragLeaveCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="PreviewDrop">
<i:InvokeCommandAction Command="{Binding PreviewDropCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<ui:VirtualizingItemsControl
ItemTemplate="{StaticResource CheckpointFileDataTemplate}"
ItemsSource="{Binding CheckpointFiles}"
Padding="5"
PreviewMouseWheel="VirtualizingGridView_OnPreviewMouseWheel" />
<Border
CornerRadius="8"
Grid.RowSpan="4"
IsEnabled="False"
Name="OnDragBlurBorder"
Visibility="{Binding IsDragBlurEnabled, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
<Border.Background>
<SolidColorBrush Color="#EE202020" />
</Border.Background>
</Border>
<Border
BorderThickness="1,1,1,1"
CornerRadius="8"
Grid.RowSpan="4"
IsEnabled="False"
Name="OnDragDashBorder"
Visibility="{Binding IsCurrentDragTarget, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
<Border.BorderBrush>
<DrawingBrush
TileMode="Tile"
Viewport="0,0,8,8"
ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="White">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,50,50" />
<RectangleGeometry Rect="50,50,50,50" />
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.BorderBrush>
</Border>
<VirtualizingStackPanel
Margin="0,8"
Orientation="Vertical"
VerticalAlignment="Center">
<TextBlock
Effect="{StaticResource TextDropShadowEffect}"
FontSize="24"
HorizontalAlignment="Center"
Name="OnDragText"
Text="Drop a file here to import"
VerticalAlignment="Center"
Visibility="{Binding IsCurrentDragTarget, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Visible}" />
<TextBlock
Effect="{StaticResource TextDropShadowEffect}"
FontSize="18"
HorizontalAlignment="Center"
Name="ImportProgressText"
Text="{Binding Progress.Text, FallbackValue=Importing checkpoint.safetensors}"
VerticalAlignment="Center"
Visibility="{Binding Progress.TextVisibility}" />
<ProgressBar
Effect="{StaticResource TextDropShadowEffect}"
<Expander.ContextMenu>
<ContextMenu>
<!-- ReSharper disable once Xaml.RedundantResource -->
<MenuItem Header="Show in Explorer"
Command="{Binding ShowInExplorerCommand}"
CommandParameter="{Binding DirectoryPath}"/>
</ContextMenu>
</Expander.ContextMenu>
<StackPanel Orientation="Vertical">
<!-- Subfolders -->
<StackPanel Orientation="Vertical">
<ItemsControl
HorizontalAlignment="Stretch"
IsIndeterminate="{Binding Progress.IsIndeterminate, FallbackValue=False}"
Margin="64,8"
Name="ImportProgressBar"
VerticalAlignment="Center"
Visibility="{Binding Progress.ProgressVisibility, FallbackValue=Visible}"
controls:ProgressBarSmoother.SmoothValue="{Binding Progress.Value, FallbackValue=20}" />
</VirtualizingStackPanel>
</Grid>
ItemTemplate="{DynamicResource CheckpointFolderGridDataTemplate}"
ItemsSource="{Binding SubFolders, Mode=OneWay}"
Margin="8,0,8,8" />
</StackPanel>
<!-- Files -->
<Grid>
<i:Interaction.Triggers>
<ci:EventTriggerWithoutPropagation EventName="PreviewDragEnter">
<i:InvokeCommandAction Command="{Binding OnPreviewDragEnterCommand}" />
</ci:EventTriggerWithoutPropagation>
<ci:EventTriggerWithoutPropagation EventName="PreviewDragLeave">
<i:InvokeCommandAction Command="{Binding OnPreviewDragLeaveCommand}" />
</ci:EventTriggerWithoutPropagation>
<ci:EventTriggerWithoutPropagation EventName="PreviewDrop">
<i:InvokeCommandAction Command="{Binding PreviewDropCommand}" PassEventArgsToCommand="True" />
</ci:EventTriggerWithoutPropagation>
</i:Interaction.Triggers>
<ui:VirtualizingItemsControl
ItemTemplate="{StaticResource CheckpointFileDataTemplate}"
ItemsSource="{Binding CheckpointFiles}"
Padding="5"
PreviewMouseWheel="VirtualizingGridView_OnPreviewMouseWheel" />
<Border
CornerRadius="8"
Grid.RowSpan="4"
IsEnabled="False"
Name="OnDragBlurBorder"
Visibility="{Binding IsDragBlurEnabled, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
<Border.Background>
<SolidColorBrush Color="#EE202020" />
</Border.Background>
</Border>
<Border
BorderThickness="1,1,1,1"
CornerRadius="8"
Grid.RowSpan="4"
IsEnabled="False"
Name="OnDragDashBorder"
Visibility="{Binding IsCurrentDragTarget, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
<Border.BorderBrush>
<DrawingBrush
TileMode="Tile"
Viewport="0,0,8,8"
ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="White">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,50,50" />
<RectangleGeometry Rect="50,50,50,50" />
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.BorderBrush>
</Border>
<VirtualizingStackPanel
Margin="0,8"
Orientation="Vertical"
VerticalAlignment="Center">
<TextBlock
Effect="{StaticResource TextDropShadowEffect}"
FontSize="24"
HorizontalAlignment="Center"
Name="OnDragText"
Text="Drop a file here to import"
VerticalAlignment="Center"
Visibility="{Binding IsCurrentDragTarget, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Visible}" />
<TextBlock
Effect="{StaticResource TextDropShadowEffect}"
FontSize="18"
HorizontalAlignment="Center"
Name="ImportProgressText"
Text="{Binding Progress.Text, FallbackValue=Importing checkpoint.safetensors}"
VerticalAlignment="Center"
Visibility="{Binding Progress.TextVisibility}" />
<ProgressBar
Effect="{StaticResource TextDropShadowEffect}"
HorizontalAlignment="Stretch"
IsIndeterminate="{Binding Progress.IsIndeterminate, FallbackValue=False}"
Margin="64,8"
Name="ImportProgressBar"
VerticalAlignment="Center"
Visibility="{Binding Progress.ProgressVisibility, FallbackValue=Visible}"
controls:ProgressBarSmoother.SmoothValue="{Binding Progress.Value, FallbackValue=20}" />
</VirtualizingStackPanel>
</Grid>
</StackPanel>
</Expander>
</DataTemplate>

Expand Down Expand Up @@ -424,7 +444,7 @@

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
Expand All @@ -444,6 +464,18 @@
HorizontalAlignment="Right"
Margin="16,0"
Orientation="Horizontal">
<ui:Button
VerticalAlignment="Stretch"
Command="{Binding OpenModelsFolderCommand}"
Height="46"
Margin="8,0">
<ui:Button.Icon>
<ui:SymbolIcon Symbol="FolderOpen24"/>
</ui:Button.Icon>
<ui:Button.Content>
<TextBlock Text="Open Models Folder"/>
</ui:Button.Content>
</ui:Button>
<ComboBox
HorizontalAlignment="Right"
ItemsSource="{Binding CheckpointFolders}"
Expand Down
6 changes: 3 additions & 3 deletions StabilityMatrix/DesignData/MockCheckpointBrowserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace StabilityMatrix.DesignData;
[DesignOnly(true)]
public class MockCheckpointBrowserViewModel : CheckpointBrowserViewModel
{
public MockCheckpointBrowserViewModel() : base(null!, null!, null!, null!, null!)
public MockCheckpointBrowserViewModel() : base(null!, null!, null!, null!, null!, null!)
{
ModelCards = new ObservableCollection<CheckpointBrowserCardViewModel>
{
new(null!, null!, null!, null!,
new(null!, null!, null!, null!, null!,
fixedImage: new BitmapImage(new Uri("https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/01bb1e4b-f88b-441a-b2bf-c1ec0bd91727/width=450/00015-1007989405.jpeg")))
{
CivitModel = new CivitModel
Expand All @@ -40,7 +40,7 @@ public MockCheckpointBrowserViewModel() : base(null!, null!, null!, null!, null!
}
},
},
new(null!, null!, null!, null!,
new(null!, null!, null!, null!, null!,
fixedImage: new BitmapImage(new Uri("https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/fcb56b61-2cd6-40f4-a75d-e9448c0822d6/width=1152/29933-2136606019-masterpiece.jpeg")))
{
CivitModel = new CivitModel
Expand Down
Loading

0 comments on commit 20413f4

Please sign in to comment.