Browse Source

Move editor flyouts to shared resource dictionary

pull/165/head
Ionite 1 year ago
parent
commit
1ac441e794
No known key found for this signature in database
  1. 1
      StabilityMatrix.Avalonia/App.axaml
  2. 16
      StabilityMatrix.Avalonia/Controls/EditorCommands.cs
  3. 27
      StabilityMatrix.Avalonia/Controls/EditorFlyouts.axaml
  4. 28
      StabilityMatrix.Avalonia/Controls/PromptCard.axaml

1
StabilityMatrix.Avalonia/App.axaml

@ -19,6 +19,7 @@
<ResourceInclude Source="Styles/Card.axaml"/>
<ResourceInclude Source="Controls/CodeCompletion/CompletionListThemes.axaml"/>
<ResourceInclude Source="Styles/ContextMenuStyles.axaml"/>
<ResourceInclude Source="Controls/EditorFlyouts.axaml"/>
</ResourceDictionary.MergedDictionaries>
<idcr:ControlRecycling x:Key="ControlRecyclingKey" />

16
StabilityMatrix.Avalonia/Controls/EditorCommands.cs

@ -0,0 +1,16 @@
using AvaloniaEdit;
using CommunityToolkit.Mvvm.Input;
namespace StabilityMatrix.Avalonia.Controls;
public static class EditorCommands
{
public static RelayCommand<TextEditor> CopyCommand { get; } =
new(editor => editor?.Copy(), editor => editor?.CanCopy ?? false);
public static RelayCommand<TextEditor> CutCommand { get; } =
new(editor => editor?.Cut(), editor => editor?.CanCut ?? false);
public static RelayCommand<TextEditor> PasteCommand { get; } =
new(editor => editor?.Paste(), editor => editor?.CanPaste ?? false);
}

27
StabilityMatrix.Avalonia/Controls/EditorFlyouts.axaml

@ -0,0 +1,27 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:avaloniaEdit="https://github.com/avaloniaui/avaloniaedit"
xmlns:controls="clr-namespace:StabilityMatrix.Avalonia.Controls">
<!-- Context menu for editors -->
<ui:FAMenuFlyout x:Key="EditorContextFlyout">
<ui:MenuFlyoutItem
Text="Paste"
IconSource="Paste"
HotKey="Ctrl+V"
Command="{x:Static controls:EditorCommands.PasteCommand}"
CommandParameter="{Binding $parent[avaloniaEdit:TextEditor]}"/>
<ui:MenuFlyoutItem
Text="Copy"
IconSource="Copy"
HotKey="Ctrl+C"
Command="{x:Static controls:EditorCommands.CopyCommand}"
CommandParameter="{Binding $parent[avaloniaEdit:TextEditor]}"/>
<ui:MenuFlyoutItem
Text="Cut"
IconSource="Cut"
HotKey="Ctrl+X"
Command="{x:Static controls:EditorCommands.CutCommand}"
CommandParameter="{Binding $parent[avaloniaEdit:TextEditor]}"/>
</ui:FAMenuFlyout>
</ResourceDictionary>

28
StabilityMatrix.Avalonia/Controls/PromptCard.axaml

@ -7,7 +7,6 @@
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:icons="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia"
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:vmInference="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Inference"
x:DataType="vmInference:PromptCardViewModel">
<Design.PreviewWith>
@ -21,30 +20,6 @@
<Setter Property="Template">
<ControlTemplate>
<controls:Card Padding="12" HorizontalAlignment="{TemplateBinding HorizontalAlignment}">
<controls:Card.Resources>
<!--<ui:TextCommandBarFlyout x:Key="EditorFlyout"/>-->
<ui:FAMenuFlyout x:Key="EditorFlyout">
<ui:MenuFlyoutItem
Text="Paste"
IconSource="Paste"
HotKey="Ctrl+V"
Command="{Binding EditorPasteCommand}"
CommandParameter="{Binding $parent[avaloniaEdit:TextEditor]}"/>
<ui:MenuFlyoutItem
Text="Copy"
IconSource="Copy"
HotKey="Ctrl+C"
Command="{Binding EditorCopyCommand}"
CommandParameter="{Binding $parent[avaloniaEdit:TextEditor]}"/>
<ui:MenuFlyoutItem
Text="Cut"
IconSource="Cut"
HotKey="Ctrl+X"
Command="{Binding EditorCutCommand}"
CommandParameter="{Binding $parent[avaloniaEdit:TextEditor]}"/>
</ui:FAMenuFlyout>
</controls:Card.Resources>
<controls:Card.Styles>
<Style Selector="avaloniaEdit|TextEditor">
<Setter Property="Margin" Value="0,8,0,8" />
@ -54,8 +29,7 @@
<Setter Property="ShowLineNumbers" Value="True" />
<Setter Property="WordWrap" Value="True" />
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ContextFlyout" Value="{StaticResource EditorFlyout}" />
<!--<Setter Property="Background" Value="{DynamicResource ScrollBarTrackStroke}" />-->
<Setter Property="ContextFlyout" Value="{StaticResource EditorContextFlyout}" />
</Style>
</controls:Card.Styles>

Loading…
Cancel
Save