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. 79
      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)
{
if (text == _currentText)
{
return;
}
if (_listBox == null)
{
ApplyTemplate();
}
if (IsFiltering)
{
@ -275,6 +280,7 @@ public class CompletionList : TemplatedControl
{
SelectItemWithStart(text);
}
_currentText = text;
}

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

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

79
StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs

@ -3,12 +3,14 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
@ -92,6 +94,13 @@ public partial class SettingsViewModel : PageViewModelBase
// Shared folder options
[ObservableProperty] private bool removeSymlinksOnShutdown;
// Inference UI section
[ObservableProperty]
private IReadOnlyList<string> availableTagCompletionCsvs = Array.Empty<string>();
[ObservableProperty]
private string? selectedTagCompletionCsv;
// Integrations section
[ObservableProperty] private bool isDiscordRichPresenceEnabled;
@ -136,12 +145,26 @@ public partial class SettingsViewModel : PageViewModelBase
vm => vm.IsDiscordRichPresenceEnabled,
settings => settings.IsDiscordRichPresenceEnabled);
DebugThrowAsyncExceptionCommand.WithNotificationErrorHandler(notificationService, LogLevel.Warn);
settingsManager.RelayPropertyFor(this,
vm => vm.SelectedAnimationScale,
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)
{
// In case design / tests
@ -237,6 +260,58 @@ public partial class SettingsViewModel : PageViewModelBase
#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
/// <summary>

51
StabilityMatrix.Avalonia/Views/SettingsPage.axaml

@ -6,6 +6,7 @@
xmlns:ui="using:FluentAvalonia.UI.Controls"
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData"
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"
x:DataType="vm:SettingsViewModel"
x:CompileBindings="True"
@ -14,7 +15,7 @@
<Grid>
<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">
<!-- Theme -->
<Grid Grid.Row="0" RowDefinitions="auto,*">
@ -104,8 +105,42 @@
</ui:SettingsExpander>
</Grid>
<!-- Integrations -->
<!-- Inference UI -->
<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
FontWeight="Medium"
Text="Integrations"
@ -124,7 +159,7 @@
</Grid>
<!-- 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
FontWeight="Medium"
Text="System"
@ -169,7 +204,7 @@
</Grid>
<!-- Debug Options -->
<Grid Grid.Row="5" RowDefinitions="auto,*"
<Grid Grid.Row="6" RowDefinitions="auto,*"
Margin="0,8,0,0"
IsVisible="{Binding SharedState.IsDebugMode}" >
<TextBlock
@ -184,14 +219,14 @@
Margin="8, 0,8,4">
<ui:SettingsExpanderItem Description="Paths" IconSource="Folder"
Margin="4">
Margin="4,0,4,0">
<SelectableTextBlock Text="{Binding DebugPaths}"
Foreground="{DynamicResource TextControlPlaceholderForeground}"
TextWrapping="WrapWithOverflow" />
</ui:SettingsExpanderItem>
<ui:SettingsExpanderItem Description="Compat Info" IconSource="StarFilled"
Margin="4,0,4,4">
Margin="4,0,4,0">
<SelectableTextBlock Text="{Binding DebugCompatInfo}"
Foreground="{DynamicResource TextControlPlaceholderForeground}"
TextWrapping="WrapWithOverflow" />
@ -289,7 +324,7 @@
<!-- 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
Grid.Row="1"
HorizontalAlignment="Left"
@ -336,7 +371,7 @@
</Grid>
<!-- Extra space at the bottom -->
<Panel Grid.Row="7" Margin="0,0,0,16" />
<Panel Grid.Row="8" Margin="0,0,0,16" />
</Grid>
</ScrollViewer>
</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;
@ -43,6 +44,11 @@ public class Settings
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 IsDiscordRichPresenceEnabled { get; set; }

Loading…
Cancel
Save