You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.9 KiB
63 lines
1.9 KiB
1 year ago
|
using Avalonia;
|
||
|
using Avalonia.Controls;
|
||
1 year ago
|
using Avalonia.Controls.Primitives;
|
||
1 year ago
|
using Avalonia.Input;
|
||
1 year ago
|
using AvaloniaEdit;
|
||
1 year ago
|
using AvaloniaEdit.Editing;
|
||
1 year ago
|
using AvaloniaEdit.Utils;
|
||
1 year ago
|
using StabilityMatrix.Avalonia.Helpers;
|
||
1 year ago
|
using StabilityMatrix.Avalonia.Models;
|
||
1 year ago
|
using StabilityMatrix.Core.Attributes;
|
||
1 year ago
|
|
||
|
namespace StabilityMatrix.Avalonia.Controls;
|
||
|
|
||
1 year ago
|
[Transient]
|
||
1 year ago
|
public class PromptCard : TemplatedControl
|
||
|
{
|
||
|
/// <inheritdoc />
|
||
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||
|
{
|
||
|
base.OnApplyTemplate(e);
|
||
|
|
||
|
InitializeEditors(e);
|
||
|
}
|
||
|
|
||
1 year ago
|
private static void InitializeEditors(TemplateAppliedEventArgs e)
|
||
1 year ago
|
{
|
||
1 year ago
|
foreach (
|
||
|
var editor in new[]
|
||
|
{
|
||
|
e.NameScope.Find<TextEditor>("PromptEditor"),
|
||
|
e.NameScope.Find<TextEditor>("NegativePromptEditor")
|
||
|
}
|
||
|
)
|
||
1 year ago
|
{
|
||
|
if (editor is not null)
|
||
|
{
|
||
1 year ago
|
TextEditorConfigs.Configure(editor, TextEditorPreset.Prompt);
|
||
1 year ago
|
editor.TextArea.Margin = new Thickness(0, 0, 4, 0);
|
||
1 year ago
|
|
||
|
if (editor.TextArea.ActiveInputHandler is TextAreaInputHandler inputHandler)
|
||
|
{
|
||
1 year ago
|
// Add some aliases for editor shortcuts
|
||
|
inputHandler.KeyBindings.AddRange(
|
||
|
new KeyBinding[]
|
||
1 year ago
|
{
|
||
1 year ago
|
new()
|
||
|
{
|
||
|
Command = ApplicationCommands.Cut,
|
||
|
Gesture = new KeyGesture(Key.Delete, KeyModifiers.Shift)
|
||
|
},
|
||
|
new()
|
||
|
{
|
||
|
Command = ApplicationCommands.Paste,
|
||
|
Gesture = new KeyGesture(Key.Insert, KeyModifiers.Shift)
|
||
|
}
|
||
1 year ago
|
}
|
||
|
);
|
||
|
}
|
||
1 year ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|