2020-12-11 19:22:04 +08:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
2020-12-12 23:19:47 +08:00
|
|
|
using System.Windows;
|
2020-12-11 19:22:04 +08:00
|
|
|
using System.Windows.Input;
|
2022-05-16 21:06:49 +08:00
|
|
|
using BililiveRecorder.WPF.Controls;
|
2020-12-11 19:22:04 +08:00
|
|
|
using ModernWpf.Controls;
|
|
|
|
|
2021-02-23 18:03:37 +08:00
|
|
|
#nullable enable
|
2020-12-11 19:22:04 +08:00
|
|
|
namespace BililiveRecorder.WPF.Models
|
|
|
|
{
|
|
|
|
public class Commands : ICommand
|
|
|
|
{
|
|
|
|
#region Static Commands
|
|
|
|
|
|
|
|
public static Commands OpenLink { get; } = new Commands
|
|
|
|
{
|
|
|
|
ExecuteDelegate = o => { try { Process.Start(o.ToString()); } catch (Exception) { } }
|
|
|
|
};
|
|
|
|
|
|
|
|
public static Commands OpenContentDialog { get; } = new Commands
|
|
|
|
{
|
2021-02-23 18:03:37 +08:00
|
|
|
#pragma warning disable VSTHRD101 // Avoid unsupported async delegates
|
2022-05-16 21:06:49 +08:00
|
|
|
ExecuteDelegate = async o => { try { await (o as ContentDialog)!.ShowAndDisableMinimizeToTrayAsync(); } catch (Exception) { } }
|
2021-02-23 18:03:37 +08:00
|
|
|
#pragma warning restore VSTHRD101 // Avoid unsupported async delegates
|
2020-12-11 19:22:04 +08:00
|
|
|
};
|
|
|
|
|
2020-12-12 23:19:47 +08:00
|
|
|
public static Commands Copy { get; } = new Commands
|
|
|
|
{
|
|
|
|
ExecuteDelegate = e => { try { if (e is string str) Clipboard.SetText(str); } catch (Exception) { } }
|
|
|
|
};
|
|
|
|
|
2020-12-11 19:22:04 +08:00
|
|
|
#endregion
|
|
|
|
|
2021-02-23 18:03:37 +08:00
|
|
|
public Predicate<object>? CanExecuteDelegate { get; set; }
|
|
|
|
public Action<object>? ExecuteDelegate { get; set; }
|
2020-12-11 19:22:04 +08:00
|
|
|
|
|
|
|
#region ICommand Members
|
|
|
|
|
2021-01-01 14:46:27 +08:00
|
|
|
public void Execute(object parameter) => this.ExecuteDelegate?.Invoke(parameter);
|
2020-12-11 19:22:04 +08:00
|
|
|
|
2021-01-01 14:46:27 +08:00
|
|
|
public bool CanExecute(object parameter) => this.CanExecuteDelegate switch
|
2020-12-11 19:22:04 +08:00
|
|
|
{
|
|
|
|
null => true,
|
2021-01-01 14:46:27 +08:00
|
|
|
_ => this.CanExecuteDelegate(parameter),
|
2020-12-11 19:22:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
public event EventHandler CanExecuteChanged
|
|
|
|
{
|
|
|
|
add { CommandManager.RequerySuggested += value; }
|
|
|
|
remove { CommandManager.RequerySuggested -= value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|