diff --git a/StabilityMatrix.Avalonia/Behaviors/TextEditorCompletionBehavior.cs b/StabilityMatrix.Avalonia/Behaviors/TextEditorCompletionBehavior.cs index c9c4fd49..0928268f 100644 --- a/StabilityMatrix.Avalonia/Behaviors/TextEditorCompletionBehavior.cs +++ b/StabilityMatrix.Avalonia/Behaviors/TextEditorCompletionBehavior.cs @@ -3,18 +3,15 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Avalonia; using Avalonia.Input; -using Avalonia.Threading; using Avalonia.Xaml.Interactivity; using AvaloniaEdit; using AvaloniaEdit.Document; using AvaloniaEdit.Editing; using NLog; using StabilityMatrix.Avalonia.Controls.CodeCompletion; -using StabilityMatrix.Avalonia.Models; using StabilityMatrix.Avalonia.Models.TagCompletion; using StabilityMatrix.Core.Extensions; using TextMateSharp.Grammars; -using CompletionWindow = StabilityMatrix.Avalonia.Controls.CodeCompletion.CompletionWindow; namespace StabilityMatrix.Avalonia.Behaviors; @@ -27,19 +24,20 @@ public class TextEditorCompletionBehavior : Behavior private CompletionWindow? completionWindow; - public static readonly StyledProperty CompletionProviderProperty = - AvaloniaProperty.Register(nameof(CompletionProvider)); + public static readonly StyledProperty CompletionProviderProperty = + AvaloniaProperty.Register(nameof(CompletionProvider)); - public ICompletionProvider CompletionProvider + public ICompletionProvider? CompletionProvider { get => GetValue(CompletionProviderProperty); set => SetValue(CompletionProviderProperty, value); } - public static readonly StyledProperty TokenizerProviderProperty = AvaloniaProperty.Register( + public static readonly StyledProperty TokenizerProviderProperty = + AvaloniaProperty.Register( "TokenizerProvider"); - public ITokenizerProvider TokenizerProvider + public ITokenizerProvider? TokenizerProvider { get => GetValue(TokenizerProviderProperty); set => SetValue(TokenizerProviderProperty, value); @@ -78,7 +76,7 @@ public class TextEditorCompletionBehavior : Behavior private CompletionWindow CreateCompletionWindow(TextArea textArea) { - var window = new CompletionWindow(textArea, CompletionProvider, TokenizerProvider) + var window = new CompletionWindow(textArea, CompletionProvider!, TokenizerProvider!) { WindowManagerAddShadowHint = false, CloseWhenCaretAtBeginning = true, @@ -189,7 +187,7 @@ public class TextEditorCompletionBehavior : Behavior var caretAbsoluteOffset = caret - line.Offset; // Tokenize - var result = TokenizerProvider.TokenizeLine(lineText); + var result = TokenizerProvider!.TokenizeLine(lineText); var currentTokenIndex = -1; IToken? currentToken = null; diff --git a/StabilityMatrix.Avalonia/Controls/Dock/DockUserControlBase.cs b/StabilityMatrix.Avalonia/Controls/Dock/DockUserControlBase.cs new file mode 100644 index 00000000..9a313f2d --- /dev/null +++ b/StabilityMatrix.Avalonia/Controls/Dock/DockUserControlBase.cs @@ -0,0 +1,48 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Dock.Avalonia.Controls; +using Dock.Model; +using Dock.Model.Avalonia.Json; +using Dock.Model.Core; + +namespace StabilityMatrix.Avalonia.Controls.Dock; + +/// +/// Base for Dock controls +/// Expects a named "Dock" in the XAML +/// +public abstract class DockUserControlBase : UserControlBase +{ + private DockControl _dock = null!; + protected readonly AvaloniaDockSerializer DockSerializer = new(); + protected readonly DockState DockState = new(); + + /// + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + + _dock = this.FindControl("Dock") + ?? throw new NullReferenceException("DockControl not found"); + + if (_dock.Layout is { } layout) + { + DockState.Save(layout); + } + } + + protected virtual void LoadDockLayout(string data) + { + if (DockSerializer.Deserialize(data) is { } layout) + { + _dock.Layout = layout; + DockState.Restore(layout); + } + } + + protected virtual string SaveDockLayout() + { + return DockSerializer.Serialize(_dock.Layout); + } +} diff --git a/StabilityMatrix.Avalonia/Controls/ModelCard.axaml b/StabilityMatrix.Avalonia/Controls/ModelCard.axaml index b78f76a7..7f6af6ef 100644 --- a/StabilityMatrix.Avalonia/Controls/ModelCard.axaml +++ b/StabilityMatrix.Avalonia/Controls/ModelCard.axaml @@ -6,7 +6,9 @@ xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData" x:DataType="inference:ModelCardViewModel"> - + + +