Merge pull request #446 from ablibrary-net/Mouse-ContextFlyout-Commands

Mouse ContextFlyout commands fix in AvaloniaEdit.Demo
This commit is contained in:
Daniel Peñalba 2024-08-05 12:27:54 +02:00 коммит произвёл GitHub
Родитель f9d50b82b8 9f8d31d771
Коммит f35f37a818
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 38 добавлений и 10 удалений

Просмотреть файл

@ -51,6 +51,16 @@
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Visible"
FontWeight="Light"
FontSize="14" />
FontSize="14" >
<AvalonEdit:TextEditor.ContextFlyout>
<MenuFlyout>
<MenuItem Header="Copy" InputGesture="ctrl+C" Command="{Binding CopyMouseCommmand}" CommandParameter="{Binding #Editor.TextArea}"></MenuItem>
<MenuItem Header="Cut" InputGesture="ctrl+X" Command="{Binding CutMouseCommand}" CommandParameter="{Binding #Editor.TextArea}"></MenuItem>
<MenuItem Header="Paste" InputGesture="ctrl+V" Command="{Binding PasteMouseCommmand}" CommandParameter="{Binding #Editor.TextArea}"></MenuItem>
<MenuItem Header="-"/>
<MenuItem Header="Select All" InputGesture="ctrl+A" Command="{Binding SelectAllMouseCommmand}" CommandParameter="{Binding #Editor.TextArea}"></MenuItem>
</MenuFlyout>
</AvalonEdit:TextEditor.ContextFlyout>
</AvalonEdit:TextEditor>
</DockPanel>
</Window>

Просмотреть файл

@ -51,15 +51,6 @@ namespace AvaloniaEdit.Demo
_textEditor.HorizontalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Visible;
_textEditor.Background = Brushes.Transparent;
_textEditor.ShowLineNumbers = true;
_textEditor.ContextMenu = new ContextMenu
{
ItemsSource = new List<MenuItem>
{
new MenuItem { Header = "Copy", InputGesture = new KeyGesture(Key.C, KeyModifiers.Control) },
new MenuItem { Header = "Paste", InputGesture = new KeyGesture(Key.V, KeyModifiers.Control) },
new MenuItem { Header = "Cut", InputGesture = new KeyGesture(Key.X, KeyModifiers.Control) }
}
};
_textEditor.TextArea.Background = this.Background;
_textEditor.TextArea.TextEntered += textEditor_TextArea_TextEntered;
_textEditor.TextArea.TextEntering += textEditor_TextArea_TextEntering;

Просмотреть файл

@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using AvaloniaEdit.Editing;
using ReactiveUI;
using TextMateSharp.Grammars;
@ -18,4 +19,30 @@ public class MainWindowViewModel(TextMate.TextMate.Installation _textMateInstall
_textMateInstallation.SetTheme(_registryOptions.LoadTheme(value.ThemeName));
}
}
public void CopyMouseCommmand(TextArea textArea)
{
ApplicationCommands.Copy.Execute(null, textArea);
}
public void CutMouseCommand(TextArea textArea)
{
ApplicationCommands.Cut.Execute(null, textArea);
}
public void PasteMouseCommmand(TextArea textArea)
{
ApplicationCommands.Paste.Execute(null, textArea);
}
public void SelectAllMouseCommmand(TextArea textArea)
{
ApplicationCommands.SelectAll.Execute(null, textArea);
}
// Undo Status is not given back to disable it's item in ContextFlyout; therefore it's not being used yet.
public void UndoMouseCommmand(TextArea textArea)
{
ApplicationCommands.Undo.Execute(null, textArea);
}
}