using System; using System.Windows.Input; using Avalonia.Controls.ApplicationLifetimes; namespace SourceGit { public partial class App { public class Command : ICommand { public event EventHandler CanExecuteChanged { add { } remove { } } public Command(Action action) { _action = action; } public bool CanExecute(object parameter) => _action != null; public void Execute(object parameter) => _action?.Invoke(parameter); private Action _action = null; } public static bool IsCheckForUpdateCommandVisible { get { #if DISABLE_UPDATE_DETECTION return false; #else return true; #endif } } public static readonly Command OpenPreferencesCommand = new Command(async _ => { if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner }) { var dialog = new Views.Preferences(); await dialog.ShowDialog(owner); } }); public static readonly Command OpenHotkeysCommand = new Command(async _ => { if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner }) { var dialog = new Views.Hotkeys(); await dialog.ShowDialog(owner); } }); public static readonly Command OpenAppConfigDirCommand = new Command(_ => { Native.OS.OpenInFileManager(Native.OS.BasicDirectories.ConfigDir); }); public static readonly Command OpenAppDataDirCommand = new Command(_ => { Native.OS.OpenInFileManager(Native.OS.BasicDirectories.CacheDir); }); public static readonly Command OpenAboutCommand = new Command(async _ => { if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner }) { var dialog = new Views.About(); await dialog.ShowDialog(owner); } }); public static readonly Command CheckForUpdateCommand = new Command(_ => { (Current as App)?.Check4Update(true); }); public static readonly Command QuitCommand = new Command(_ => { Quit(0); }); public static readonly Command HideAppCommand = new Command(_ => { if (OperatingSystem.IsMacOS()) Native.MacOSUtilities.HideSelf(); }); public static readonly Command HideOtherApplicationsCommand = new Command(_ => { if (OperatingSystem.IsMacOS()) Native.MacOSUtilities.HideOtherApplications(); }); public static readonly Command ShowAllApplicationsCommand = new Command(_ => { if (OperatingSystem.IsMacOS()) Native.MacOSUtilities.ShowAllApplications(); }); public static readonly Command OpenSSHKeyHelperCommand = new Command(async _ => { if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner }) { var vm = new ViewModels.SSHKeyHelper(); var dialog = new Views.SSHKeyHelper() { DataContext = vm }; await dialog.ShowDialog(owner); } }); } }