using FluentTerminal.App.Services.Dialogs; using FluentTerminal.Models; using System; using System.Threading.Tasks; namespace FluentTerminal.App.Services.Implementation { public class DialogService : IDialogService { private readonly Func _messageDialogFactory; private readonly Func _createKeyBindingDialogFactory; private readonly Func _inputDialogFactory; private readonly Func _sshConnectionInfoDialogFactory; private readonly Func _customCommandDialogFactory; private readonly Func _aboutDialogFactory; public DialogService(Func messageDialogFactory, Func createKeyBindingDialogFactory, Func inputDialogFactory, Func sshConnectionInfoDialogFactory, Func customCommandDialogFactory, Func aboutDialogFactory) { _messageDialogFactory = messageDialogFactory; _createKeyBindingDialogFactory = createKeyBindingDialogFactory; _inputDialogFactory = inputDialogFactory; _sshConnectionInfoDialogFactory = sshConnectionInfoDialogFactory; _customCommandDialogFactory = customCommandDialogFactory; _aboutDialogFactory = aboutDialogFactory; } public Task ShowCreateKeyBindingDialog() { var dialog = _createKeyBindingDialogFactory(); return dialog.CreateKeyBinding(); } public Task ShowMessageDialogAsync(string title, string content, params DialogButton[] buttons) { if (string.IsNullOrWhiteSpace(title)) { throw new ArgumentNullException(nameof(title)); } if (string.IsNullOrWhiteSpace(content)) { throw new ArgumentNullException(nameof(content)); } if (buttons.Length == 0) { throw new ArgumentException("Must not be empty", nameof(buttons)); } var dialog = _messageDialogFactory(); dialog.Content = content; dialog.Title = title; foreach (var button in buttons) { dialog.AddButton(button); } return dialog.ShowAsync(); } public Task ShowInputDialogAsync(string title) { var dialog = _inputDialogFactory.Invoke(); dialog.SetTitle(title); return dialog.GetInput(); } public Task ShowSshConnectionInfoDialogAsync(SshProfile input = null) => _sshConnectionInfoDialogFactory().GetSshConnectionInfoAsync(input); public Task ShowCustomCommandDialogAsync(ShellProfile input = null) => _customCommandDialogFactory().GetCustomCommandAsync(input); public Task ShowAboutDialogAsync() { var dialog = _aboutDialogFactory(); return dialog.ShowAsync(); } } }