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 _shellProfileSelectionDialogFactory; private readonly Func _messageDialogFactory; private readonly Func _createKeyBindingDialogFactory; private readonly Func _inputDialogFactory; private readonly Func _sshConnectionInfoDialogFactory; public DialogService(Func shellProfileSelectionDialogFactory, Func messageDialogFactory, Func createKeyBindingDialogFactory, Func inputDialogFactory, Func sshConnectionInfoDialogFactory) { _shellProfileSelectionDialogFactory = shellProfileSelectionDialogFactory; _messageDialogFactory = messageDialogFactory; _createKeyBindingDialogFactory = createKeyBindingDialogFactory; _inputDialogFactory = inputDialogFactory; _sshConnectionInfoDialogFactory = sshConnectionInfoDialogFactory; } public Task ShowCreateKeyBindingDialog() { var dialog = _createKeyBindingDialogFactory(); return dialog.CreateKeyBinding(); } public Task ShowMessageDialogAsnyc(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 ShowProfileSelectionDialogAsync() { var dialog = _shellProfileSelectionDialogFactory(); return dialog.SelectProfile(); } public Task ShowSshConnectionInfoDialogAsync() => _sshConnectionInfoDialogFactory().GetSshConnectionInfoAsync(); } }