Skip to content

Commit

Permalink
Merge pull request #446 from ablibrary-net/Mouse-ContextFlyout-Commands
Browse files Browse the repository at this point in the history
Mouse ContextFlyout commands fix in AvaloniaEdit.Demo
  • Loading branch information
danipen authored Aug 5, 2024
2 parents f9d50b8 + 9f8d31d commit f35f37a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
12 changes: 11 additions & 1 deletion src/AvaloniaEdit.Demo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
9 changes: 0 additions & 9 deletions src/AvaloniaEdit.Demo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ public MainWindow()
_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;
Expand Down
27 changes: 27 additions & 0 deletions src/AvaloniaEdit.Demo/ViewModels/MainWIndowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using AvaloniaEdit.Editing;
using ReactiveUI;
using TextMateSharp.Grammars;

Expand All @@ -18,4 +19,30 @@ public ThemeViewModel SelectedTheme
_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);
}
}

0 comments on commit f35f37a

Please sign in to comment.