feature: add a context menu to copy entire content of SelectableTextBlock (#394)

This commit is contained in:
leo 2024-08-25 15:11:31 +08:00
parent 5dc4ed6f54
commit 7a2722e928
No known key found for this signature in database
6 changed files with 81 additions and 31 deletions

65
src/App.Commands.cs Normal file
View file

@ -0,0 +1,65 @@
using System;
using System.Windows.Input;
using Avalonia.Controls;
namespace SourceGit
{
public partial class App
{
public class SimpleCommand : ICommand
{
public event EventHandler CanExecuteChanged
{
add { }
remove { }
}
public SimpleCommand(Action action)
{
_action = action;
}
public bool CanExecute(object parameter) => _action != null;
public void Execute(object parameter) => _action?.Invoke();
private Action _action = null;
}
public class ParameterCommand : ICommand
{
public event EventHandler CanExecuteChanged
{
add { }
remove { }
}
public ParameterCommand(Action<object> action)
{
_action = action;
}
public bool CanExecute(object parameter) => _action != null;
public void Execute(object parameter) => _action?.Invoke(parameter);
private Action<object> _action = null;
}
public static readonly SimpleCommand OpenPreferenceCommand = new SimpleCommand(() => OpenDialog(new Views.Preference()));
public static readonly SimpleCommand OpenHotkeysCommand = new SimpleCommand(() => OpenDialog(new Views.Hotkeys()));
public static readonly SimpleCommand OpenAppDataDirCommand = new SimpleCommand(() => Native.OS.OpenInFileManager(Native.OS.DataDir));
public static readonly SimpleCommand OpenAboutCommand = new SimpleCommand(() => OpenDialog(new Views.About()));
public static readonly SimpleCommand CheckForUpdateCommand = new SimpleCommand(() => Check4Update(true));
public static readonly SimpleCommand QuitCommand = new SimpleCommand(() => Quit(0));
public static readonly ParameterCommand CopyTextCommand = new ParameterCommand(param =>
{
if (param is TextBlock textBlock)
{
if (textBlock.Inlines is { Count: > 0 } inlines)
CopyText(inlines.Text);
else
CopyText(textBlock.Text);
}
});
}
}