Browse Source

Optimized main window navigation and texteditor syntax apply for faster load time

pull/240/head
Ionite 1 year ago
parent
commit
72df801d30
No known key found for this signature in database
  1. 1
      CHANGELOG.md
  2. 3
      StabilityMatrix.Avalonia/Controls/PromptCard.axaml.cs
  3. 2
      StabilityMatrix.Avalonia/DialogHelper.cs
  4. 37
      StabilityMatrix.Avalonia/Helpers/TextEditorConfigs.cs
  5. 3
      StabilityMatrix.Avalonia/Models/TextEditorPreset.cs
  6. 29
      StabilityMatrix.Avalonia/Views/LaunchPageView.axaml.cs
  7. 25
      StabilityMatrix.Avalonia/Views/MainWindow.axaml.cs

1
CHANGELOG.md

@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
- Update will occur the next time the package is updated, or on a fresh install
- Note: CUDA 12.1 is only available on Maxwell (GTX 900 series) and newer GPUs
- Improved Model Browser download stability with automatic retries for download errors
- Optimized page navigation and syntax formatting configurations to improve startup time
### Fixed
- Fixed crash when clicking Inference gallery image after the image is deleted externally in file explorer
- Fixed Inference popup Install button not working on One-Click Installer

3
StabilityMatrix.Avalonia/Controls/PromptCard.axaml.cs

@ -6,6 +6,7 @@ using AvaloniaEdit;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Utils;
using StabilityMatrix.Avalonia.Helpers;
using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Core.Attributes;
namespace StabilityMatrix.Avalonia.Controls;
@ -33,7 +34,7 @@ public class PromptCard : TemplatedControl
{
if (editor is not null)
{
TextEditorConfigs.ConfigForPrompt(editor);
TextEditorConfigs.Configure(editor, TextEditorPreset.Prompt);
editor.TextArea.Margin = new Thickness(0, 0, 4, 0);
if (editor.TextArea.ActiveInputHandler is TextAreaInputHandler inputHandler)

2
StabilityMatrix.Avalonia/DialogHelper.cs

@ -424,7 +424,7 @@ public static class DialogHelper
AllowScrollBelowDocument = false
}
};
TextEditorConfigs.ConfigForPrompt(textEditor);
TextEditorConfigs.Configure(textEditor, TextEditorPreset.Prompt);
textEditor.Document.Text = errorLineFormatted;
textEditor.TextArea.Caret.Offset = textEditor.Document.Lines[0].EndOffset;

37
StabilityMatrix.Avalonia/Helpers/TextEditorConfigs.cs

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using Avalonia.Media;
using AvaloniaEdit;
using AvaloniaEdit.TextMate;
@ -17,13 +18,22 @@ public static class TextEditorConfigs
{
public static void Configure(TextEditor editor, TextEditorPreset preset)
{
if (preset == TextEditorPreset.Prompt)
switch (preset)
{
ConfigForPrompt(editor);
case TextEditorPreset.Prompt:
ConfigForPrompt(editor);
break;
case TextEditorPreset.Console:
ConfigForConsole(editor);
break;
case TextEditorPreset.None:
break;
default:
throw new ArgumentOutOfRangeException(nameof(preset), preset, null);
}
}
public static void ConfigForPrompt(TextEditor editor)
private static void ConfigForPrompt(TextEditor editor)
{
const ThemeName themeName = ThemeName.DimmedMonokai;
var registryOptions = new RegistryOptions(themeName);
@ -57,6 +67,25 @@ public static class TextEditorConfigs
installation.SetTheme(theme);
}
private static void ConfigForConsole(TextEditor editor)
{
var registryOptions = new RegistryOptions(ThemeName.DarkPlus);
// Config hyperlinks
editor.TextArea.Options.EnableHyperlinks = true;
editor.TextArea.Options.RequireControlModifierForHyperlinkClick = false;
editor.TextArea.TextView.LinkTextForegroundBrush = Brushes.Coral;
var textMate = editor.InstallTextMate(registryOptions);
var scope = registryOptions.GetScopeByLanguageId("log");
if (scope is null)
throw new InvalidOperationException("Scope is null");
textMate.SetGrammar(scope);
textMate.SetTheme(registryOptions.LoadTheme(ThemeName.DarkPlus));
}
private static IRawTheme GetThemeFromStream(Stream stream)
{
using var reader = new StreamReader(stream);

3
StabilityMatrix.Avalonia/Models/TextEditorPreset.cs

@ -3,5 +3,6 @@
public enum TextEditorPreset
{
None,
Prompt
Prompt,
Console
}

29
StabilityMatrix.Avalonia/Views/LaunchPageView.axaml.cs

@ -1,14 +1,14 @@
using System;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Threading;
using AvaloniaEdit;
using AvaloniaEdit.TextMate;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Helpers;
using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Helper;
using TextMateSharp.Grammars;
namespace StabilityMatrix.Avalonia.Views;
@ -20,25 +20,14 @@ public partial class LaunchPageView : UserControlBase
public LaunchPageView()
{
InitializeComponent();
var editor = this.FindControl<TextEditor>("Console");
if (editor is not null)
{
var options = new RegistryOptions(ThemeName.DarkPlus);
// Config hyperlinks
editor.TextArea.Options.EnableHyperlinks = true;
editor.TextArea.Options.RequireControlModifierForHyperlinkClick = false;
editor.TextArea.TextView.LinkTextForegroundBrush = Brushes.Coral;
var textMate = editor.InstallTextMate(options);
var scope = options.GetScopeByLanguageId("log");
}
if (scope is null)
throw new InvalidOperationException("Scope is null");
/// <inheritdoc />
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
textMate.SetGrammar(scope);
textMate.SetTheme(options.LoadTheme(ThemeName.DarkPlus));
}
TextEditorConfigs.Configure(Console, TextEditorPreset.Console);
}
protected override void OnUnloaded(RoutedEventArgs e)

25
StabilityMatrix.Avalonia/Views/MainWindow.axaml.cs

@ -87,14 +87,6 @@ public partial class MainWindow : AppWindowBase
navigationService.SetFrame(
FrameView ?? throw new NullReferenceException("Frame not found")
);
// Navigate to first page
if (DataContext is not MainWindowViewModel vm)
{
throw new NullReferenceException("DataContext is not MainWindowViewModel");
}
navigationService.NavigateTo(vm.Pages[0], new DrillInNavigationTransitionInfo());
}
protected override void OnOpened(EventArgs e)
@ -133,8 +125,23 @@ public partial class MainWindow : AppWindowBase
loader.LoadFailed += OnImageLoadFailed;
}
if (DataContext is not MainWindowViewModel vm)
return;
// Navigate to first page
Dispatcher.UIThread.Post(
() =>
navigationService.NavigateTo(
vm.Pages[0],
new BetterSlideNavigationTransition
{
Effect = SlideNavigationTransitionEffect.FromBottom
}
)
);
// Check show update teaching tip
if (DataContext is MainWindowViewModel { UpdateViewModel.IsUpdateAvailable: true } vm)
if (vm.UpdateViewModel.IsUpdateAvailable)
{
OnUpdateAvailable(this, vm.UpdateViewModel.UpdateInfo);
}

Loading…
Cancel
Save