From d4aadd7dd44df8fd4d7fb3183edf08db956edb3a Mon Sep 17 00:00:00 2001 From: FelixSe Date: Mon, 7 Jan 2019 22:35:14 +0100 Subject: [PATCH] Added option to change the title of a tab --- .../Dialogs/IInputDialog.cs | 10 ++++++ FluentTerminal.App.Services/IDialogService.cs | 1 + .../Implementation/DialogService.cs | 12 ++++++- .../TerminalViewModel.cs | 13 ++++++++ FluentTerminal.App/App.xaml.cs | 1 + FluentTerminal.App/Dialogs/InputDialog.xaml | 12 +++++++ .../Dialogs/InputDialog.xaml.cs | 32 +++++++++++++++++++ FluentTerminal.App/FluentTerminal.App.csproj | 7 ++++ FluentTerminal.App/Views/TabBar.xaml | 3 +- 9 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 FluentTerminal.App.Services/Dialogs/IInputDialog.cs create mode 100644 FluentTerminal.App/Dialogs/InputDialog.xaml create mode 100644 FluentTerminal.App/Dialogs/InputDialog.xaml.cs diff --git a/FluentTerminal.App.Services/Dialogs/IInputDialog.cs b/FluentTerminal.App.Services/Dialogs/IInputDialog.cs new file mode 100644 index 0000000..a8ddfbd --- /dev/null +++ b/FluentTerminal.App.Services/Dialogs/IInputDialog.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; + +namespace FluentTerminal.App.Services.Dialogs +{ + public interface IInputDialog + { + void SetTitle(string title); + Task GetInput(); + } +} diff --git a/FluentTerminal.App.Services/IDialogService.cs b/FluentTerminal.App.Services/IDialogService.cs index 0bff70f..2b6c18b 100644 --- a/FluentTerminal.App.Services/IDialogService.cs +++ b/FluentTerminal.App.Services/IDialogService.cs @@ -16,5 +16,6 @@ namespace FluentTerminal.App.Services Task ShowProfileSelectionDialogAsync(); Task ShowCreateKeyBindingDialog(); + Task ShowInputDialogAsync(string title); } } \ No newline at end of file diff --git a/FluentTerminal.App.Services/Implementation/DialogService.cs b/FluentTerminal.App.Services/Implementation/DialogService.cs index 99ef024..8e84606 100644 --- a/FluentTerminal.App.Services/Implementation/DialogService.cs +++ b/FluentTerminal.App.Services/Implementation/DialogService.cs @@ -10,12 +10,14 @@ namespace FluentTerminal.App.Services.Implementation private readonly Func _shellProfileSelectionDialogFactory; private readonly Func _messageDialogFactory; private readonly Func _createKeyBindingDialogFactory; + private readonly Func _inputDialogFactory; - public DialogService(Func shellProfileSelectionDialogFactory, Func messageDialogFactory, Func createKeyBindingDialogFactory) + public DialogService(Func shellProfileSelectionDialogFactory, Func messageDialogFactory, Func createKeyBindingDialogFactory, Func inputDialogFactory) { _shellProfileSelectionDialogFactory = shellProfileSelectionDialogFactory; _messageDialogFactory = messageDialogFactory; _createKeyBindingDialogFactory = createKeyBindingDialogFactory; + _inputDialogFactory = inputDialogFactory; } public Task ShowCreateKeyBindingDialog() @@ -54,6 +56,14 @@ namespace FluentTerminal.App.Services.Implementation return dialog.ShowAsync(); } + public Task ShowInputDialogAsync(string title) + { + var dialog = _inputDialogFactory.Invoke(); + dialog.SetTitle(title); + + return dialog.GetInput(); + } + public Task ShowProfileSelectionDialogAsync() { var dialog = _shellProfileSelectionDialogFactory(); diff --git a/FluentTerminal.App.ViewModels/TerminalViewModel.cs b/FluentTerminal.App.ViewModels/TerminalViewModel.cs index 09ba556..74f5cda 100644 --- a/FluentTerminal.App.ViewModels/TerminalViewModel.cs +++ b/FluentTerminal.App.ViewModels/TerminalViewModel.cs @@ -1,5 +1,6 @@ using Fleck; using FluentTerminal.App.Services; +using FluentTerminal.App.ViewModels.Infrastructure; using FluentTerminal.Models; using FluentTerminal.Models.Enums; using GalaSoft.MvvmLight; @@ -77,6 +78,7 @@ namespace FluentTerminal.App.ViewModels FindPreviousCommand = new RelayCommand(async () => await FindPrevious().ConfigureAwait(false)); CloseSearchPanelCommand = new RelayCommand(CloseSearchPanel); SelectTabThemeCommand = new RelayCommand(SelectTabTheme); + EditTitleCommand = new AsyncCommand(EditTitle); } public event EventHandler Closed; @@ -108,6 +110,8 @@ namespace FluentTerminal.App.ViewModels public RelayCommand FindPreviousCommand { get; } + public IAsyncCommand EditTitleCommand { get; } + public bool Initialized { get; private set; } public bool IsSelected @@ -402,6 +406,15 @@ namespace FluentTerminal.App.ViewModels TabTheme = TabThemes.FirstOrDefault(t => t.Name == name); } + private async Task EditTitle() + { + var result = await _dialogService.ShowInputDialogAsync("Edit Title"); + if (result != null) + { + Title = result; + } + } + private async Task TryClose() { if (ApplicationSettings.ConfirmClosingTabs) diff --git a/FluentTerminal.App/App.xaml.cs b/FluentTerminal.App/App.xaml.cs index 49124a4..246977a 100644 --- a/FluentTerminal.App/App.xaml.cs +++ b/FluentTerminal.App/App.xaml.cs @@ -75,6 +75,7 @@ namespace FluentTerminal.App builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().InstancePerDependency(); builder.RegisterType().As().InstancePerDependency(); + builder.RegisterType().As().InstancePerDependency(); builder.RegisterType().As().InstancePerDependency(); builder.RegisterType().As().InstancePerDependency(); builder.RegisterType().As().InstancePerDependency(); diff --git a/FluentTerminal.App/Dialogs/InputDialog.xaml b/FluentTerminal.App/Dialogs/InputDialog.xaml new file mode 100644 index 0000000..0e8011f --- /dev/null +++ b/FluentTerminal.App/Dialogs/InputDialog.xaml @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/FluentTerminal.App/Dialogs/InputDialog.xaml.cs b/FluentTerminal.App/Dialogs/InputDialog.xaml.cs new file mode 100644 index 0000000..184f14f --- /dev/null +++ b/FluentTerminal.App/Dialogs/InputDialog.xaml.cs @@ -0,0 +1,32 @@ +using FluentTerminal.App.Services.Dialogs; +using System.Threading.Tasks; +using Windows.UI.Xaml.Controls; +using System; + +namespace FluentTerminal.App.Dialogs +{ + public sealed partial class InputDialog : ContentDialog, IInputDialog + { + public string Input { get; private set; } + + public InputDialog() + { + this.InitializeComponent(); + } + + public async Task GetInput() + { + var result = await ShowAsync(); + if (result == ContentDialogResult.Primary) + { + return Input; + } + return null; + } + + public void SetTitle(string title) + { + Title = title; + } + } +} diff --git a/FluentTerminal.App/FluentTerminal.App.csproj b/FluentTerminal.App/FluentTerminal.App.csproj index da0bbd2..7508257 100644 --- a/FluentTerminal.App/FluentTerminal.App.csproj +++ b/FluentTerminal.App/FluentTerminal.App.csproj @@ -125,6 +125,9 @@ + + InputDialog.xaml + ShellProfileSelectionDialog.xaml @@ -275,6 +278,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/FluentTerminal.App/Views/TabBar.xaml b/FluentTerminal.App/Views/TabBar.xaml index 376648f..b89e7eb 100644 --- a/FluentTerminal.App/Views/TabBar.xaml +++ b/FluentTerminal.App/Views/TabBar.xaml @@ -151,6 +151,7 @@ + @@ -176,7 +177,7 @@