Browse Source

Settings config for tag csv source

pull/165/head
Ionite 1 year ago
parent
commit
537d0ffad3
No known key found for this signature in database
  1. 6
      StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionList.cs
  2. 22
      StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionListThemes.axaml
  3. 77
      StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs
  4. 51
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml
  5. 6
      StabilityMatrix.Core/Models/Settings/InferenceSettings.cs
  6. 8
      StabilityMatrix.Core/Models/Settings/Settings.cs

6
StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionList.cs

@ -263,9 +263,14 @@ public class CompletionList : TemplatedControl
public void SelectItem(string text) public void SelectItem(string text)
{ {
if (text == _currentText) if (text == _currentText)
{
return; return;
}
if (_listBox == null) if (_listBox == null)
{
ApplyTemplate(); ApplyTemplate();
}
if (IsFiltering) if (IsFiltering)
{ {
@ -275,6 +280,7 @@ public class CompletionList : TemplatedControl
{ {
SelectItemWithStart(text); SelectItemWithStart(text);
} }
_currentText = text; _currentText = text;
} }

22
StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionListThemes.axaml

@ -16,6 +16,10 @@
</Design.PreviewWith> </Design.PreviewWith>
<models:IconData
x:Key="PlaceHolderIcon"
FAIcon="fa-solid fa-question"/>
<!-- ReSharper disable once Xaml.StaticResourceNotResolved --> <!-- ReSharper disable once Xaml.StaticResourceNotResolved -->
<ControlTheme <ControlTheme
x:Key="{x:Type cc:CompletionListBox}" x:Key="{x:Type cc:CompletionListBox}"
@ -166,16 +170,14 @@
Source="{Binding Image}" /> Source="{Binding Image}" />
<!-- Icon --> <!-- Icon -->
<Panel Grid.Column="0" <icons:Icon
IsVisible="{Binding Converter={x:Static ObjectConverters.IsNotNull}}" Grid.Column="0"
DataContext="{Binding Icon}"> Margin="0,0,4,0"
<icons:Icon DataContext="{Binding Icon, TargetNullValue={StaticResource PlaceHolderIcon}}"
Margin="0,0,4,0" FontSize="{Binding FontSize, TargetNullValue=12}"
FontSize="{Binding FontSize, TargetNullValue=12}" Foreground="{Binding Foreground, TargetNullValue=Red, FallbackValue=Red}"
Foreground="{Binding Foreground, TargetNullValue=Red, FallbackValue=Red}" IsVisible="{Binding FAIcon, Converter={x:Static ObjectConverters.IsNotNull}}"
IsVisible="{Binding FAIcon, Converter={x:Static ObjectConverters.IsNotNull}}" Value="{Binding FAIcon}" />
Value="{Binding FAIcon}" />
</Panel>
<!-- Main text --> <!-- Main text -->
<TextBlock <TextBlock

77
StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs

@ -3,12 +3,14 @@ using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Notifications; using Avalonia.Controls.Notifications;
@ -92,6 +94,13 @@ public partial class SettingsViewModel : PageViewModelBase
// Shared folder options // Shared folder options
[ObservableProperty] private bool removeSymlinksOnShutdown; [ObservableProperty] private bool removeSymlinksOnShutdown;
// Inference UI section
[ObservableProperty]
private IReadOnlyList<string> availableTagCompletionCsvs = Array.Empty<string>();
[ObservableProperty]
private string? selectedTagCompletionCsv;
// Integrations section // Integrations section
[ObservableProperty] private bool isDiscordRichPresenceEnabled; [ObservableProperty] private bool isDiscordRichPresenceEnabled;
@ -136,10 +145,24 @@ public partial class SettingsViewModel : PageViewModelBase
vm => vm.IsDiscordRichPresenceEnabled, vm => vm.IsDiscordRichPresenceEnabled,
settings => settings.IsDiscordRichPresenceEnabled); settings => settings.IsDiscordRichPresenceEnabled);
DebugThrowAsyncExceptionCommand.WithNotificationErrorHandler(notificationService, LogLevel.Warn);
settingsManager.RelayPropertyFor(this, settingsManager.RelayPropertyFor(this,
vm => vm.SelectedAnimationScale, vm => vm.SelectedAnimationScale,
settings => settings.AnimationScale); settings => settings.AnimationScale);
settingsManager.RelayPropertyFor(this,
vm => vm.SelectedTagCompletionCsv,
settings => settings.TagCompletionCsv);
DebugThrowAsyncExceptionCommand.WithNotificationErrorHandler(notificationService, LogLevel.Warn);
ImportTagCsvCommand.WithNotificationErrorHandler(notificationService, LogLevel.Warn);
}
/// <inheritdoc />
public override void OnLoaded()
{
base.OnLoaded();
UpdateAvailableTagCompletionCsvs();
} }
partial void OnSelectedThemeChanged(string? value) partial void OnSelectedThemeChanged(string? value)
@ -237,6 +260,58 @@ public partial class SettingsViewModel : PageViewModelBase
#endregion #endregion
#region Inference UI
private void UpdateAvailableTagCompletionCsvs()
{
var tagsDir = settingsManager.TagsDirectory;
if (!tagsDir.Exists) return;
var csvFiles = tagsDir.Info.EnumerateFiles("*.csv");
AvailableTagCompletionCsvs = csvFiles.Select(f => f.Name).ToImmutableArray();
// Set selected to current if exists
var settingsCsv = settingsManager.Settings.TagCompletionCsv;
if (settingsCsv is not null && AvailableTagCompletionCsvs.Contains(settingsCsv))
{
SelectedTagCompletionCsv = settingsCsv;
}
}
[RelayCommand(FlowExceptionsToTaskScheduler = true)]
private async Task ImportTagCsv()
{
var storage = App.StorageProvider;
var files = await storage.OpenFilePickerAsync(new FilePickerOpenOptions
{
FileTypeFilter = new List<FilePickerFileType>
{
new("CSV")
{
Patterns = new[] {"*.csv"},
}
}
});
if (files.Count == 0) return;
var sourceFile = new FilePath(files[0].TryGetLocalPath()!);
var tagsDir = settingsManager.TagsDirectory;
tagsDir.Create();
// Copy to tags directory
await sourceFile.CopyToAsync(tagsDir.JoinFile(sourceFile.Name));
// Update index
UpdateAvailableTagCompletionCsvs();
notificationService.Show($"Imported {sourceFile.Name}",
$"The {sourceFile.Name} file has been imported.", NotificationType.Success);
}
#endregion
#region System #region System
/// <summary> /// <summary>

51
StabilityMatrix.Avalonia/Views/SettingsPage.axaml

@ -6,6 +6,7 @@
xmlns:ui="using:FluentAvalonia.UI.Controls" xmlns:ui="using:FluentAvalonia.UI.Controls"
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData" xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData"
xmlns:controls="clr-namespace:StabilityMatrix.Avalonia.Controls" xmlns:controls="clr-namespace:StabilityMatrix.Avalonia.Controls"
xmlns:icons="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="700" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="700"
x:DataType="vm:SettingsViewModel" x:DataType="vm:SettingsViewModel"
x:CompileBindings="True" x:CompileBindings="True"
@ -14,7 +15,7 @@
<Grid> <Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto"> <ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto" <Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto"
Margin="8, 16"> Margin="8, 16">
<!-- Theme --> <!-- Theme -->
<Grid Grid.Row="0" RowDefinitions="auto,*"> <Grid Grid.Row="0" RowDefinitions="auto,*">
@ -104,8 +105,42 @@
</ui:SettingsExpander> </ui:SettingsExpander>
</Grid> </Grid>
<!-- Integrations --> <!-- Inference UI -->
<Grid Grid.Row="3" Margin="0,8,0,0" RowDefinitions="auto,*"> <Grid Grid.Row="3" Margin="0,8,0,0" RowDefinitions="auto,*">
<TextBlock
FontWeight="Medium"
Text="Inference UI"
Margin="0,0,0,8" />
<ui:SettingsExpander Grid.Row="1"
Header="Prompt Auto Completion"
Margin="8,0,8,4">
<ui:SettingsExpander.IconSource>
<controls:FASymbolIconSource Symbol="fa-solid fa-wand-magic-sparkles"/>
</ui:SettingsExpander.IconSource>
<ui:SettingsExpanderItem Content="Tag Source"
IconSource="Tag"
Margin="4,0,4,0"
Description="Tags to use for completion in .csv format (Compatible with a1111-sd-webui-tagcomplete)">
<ui:SettingsExpanderItem.Footer>
<UniformGrid Columns="2">
<ui:FAComboBox
ItemsSource="{Binding AvailableTagCompletionCsvs}"
SelectedItem="{Binding SelectedTagCompletionCsv}"/>
<Button
Margin="8,0,0,0"
Padding="12,8"
Command="{Binding ImportTagCsvCommand}"
ToolTip.Tip="Import a .csv file"
icons:Attached.Icon="fa-solid fa-file-import"/>
</UniformGrid>
</ui:SettingsExpanderItem.Footer>
</ui:SettingsExpanderItem>
</ui:SettingsExpander>
</Grid>
<!-- Integrations -->
<Grid Grid.Row="4" Margin="0,8,0,0" RowDefinitions="auto,*">
<TextBlock <TextBlock
FontWeight="Medium" FontWeight="Medium"
Text="Integrations" Text="Integrations"
@ -124,7 +159,7 @@
</Grid> </Grid>
<!-- System Options --> <!-- System Options -->
<Grid Grid.Row="4" Margin="0,8,0,0" RowDefinitions="auto,*"> <Grid Grid.Row="5" Margin="0,8,0,0" RowDefinitions="auto,*">
<TextBlock <TextBlock
FontWeight="Medium" FontWeight="Medium"
Text="System" Text="System"
@ -169,7 +204,7 @@
</Grid> </Grid>
<!-- Debug Options --> <!-- Debug Options -->
<Grid Grid.Row="5" RowDefinitions="auto,*" <Grid Grid.Row="6" RowDefinitions="auto,*"
Margin="0,8,0,0" Margin="0,8,0,0"
IsVisible="{Binding SharedState.IsDebugMode}" > IsVisible="{Binding SharedState.IsDebugMode}" >
<TextBlock <TextBlock
@ -184,14 +219,14 @@
Margin="8, 0,8,4"> Margin="8, 0,8,4">
<ui:SettingsExpanderItem Description="Paths" IconSource="Folder" <ui:SettingsExpanderItem Description="Paths" IconSource="Folder"
Margin="4"> Margin="4,0,4,0">
<SelectableTextBlock Text="{Binding DebugPaths}" <SelectableTextBlock Text="{Binding DebugPaths}"
Foreground="{DynamicResource TextControlPlaceholderForeground}" Foreground="{DynamicResource TextControlPlaceholderForeground}"
TextWrapping="WrapWithOverflow" /> TextWrapping="WrapWithOverflow" />
</ui:SettingsExpanderItem> </ui:SettingsExpanderItem>
<ui:SettingsExpanderItem Description="Compat Info" IconSource="StarFilled" <ui:SettingsExpanderItem Description="Compat Info" IconSource="StarFilled"
Margin="4,0,4,4"> Margin="4,0,4,0">
<SelectableTextBlock Text="{Binding DebugCompatInfo}" <SelectableTextBlock Text="{Binding DebugCompatInfo}"
Foreground="{DynamicResource TextControlPlaceholderForeground}" Foreground="{DynamicResource TextControlPlaceholderForeground}"
TextWrapping="WrapWithOverflow" /> TextWrapping="WrapWithOverflow" />
@ -289,7 +324,7 @@
<!-- TODO: Directories card --> <!-- TODO: Directories card -->
<Grid Grid.Row="6" RowDefinitions="auto,*" Margin="0,4,0,0"> <Grid Grid.Row="7" RowDefinitions="auto,*" Margin="0,4,0,0">
<StackPanel <StackPanel
Grid.Row="1" Grid.Row="1"
HorizontalAlignment="Left" HorizontalAlignment="Left"
@ -336,7 +371,7 @@
</Grid> </Grid>
<!-- Extra space at the bottom --> <!-- Extra space at the bottom -->
<Panel Grid.Row="7" Margin="0,0,0,16" /> <Panel Grid.Row="8" Margin="0,0,0,16" />
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>
</Grid> </Grid>

6
StabilityMatrix.Core/Models/Settings/InferenceSettings.cs

@ -1,6 +0,0 @@
namespace StabilityMatrix.Core.Models.Settings;
public class InferenceSettings
{
}

8
StabilityMatrix.Core/Models/Settings/Settings.cs

@ -1,4 +1,5 @@
using System.Text.Json.Serialization; using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Core.Models.Settings; namespace StabilityMatrix.Core.Models.Settings;
@ -43,6 +44,11 @@ public class Settings
public ModelSearchOptions? ModelSearchOptions { get; set; } public ModelSearchOptions? ModelSearchOptions { get; set; }
/// <summary>
/// Relative path to the tag completion CSV file from 'LibraryDir/Tags'
/// </summary>
public string? TagCompletionCsv { get; set; }
public bool RemoveFolderLinksOnShutdown { get; set; } public bool RemoveFolderLinksOnShutdown { get; set; }
public bool IsDiscordRichPresenceEnabled { get; set; } public bool IsDiscordRichPresenceEnabled { get; set; }

Loading…
Cancel
Save