Add option to always show original shell title in window title (#237)

This commit is contained in:
Felix authored and GitHub committed 2019-03-21 23:40:59 +01:00
1 parent 14e1e0e3d3
commit 44b306ac20
8 files changed
+90 -6

No files matched your search

@@ -25,6 +25,7 @@ namespace FluentTerminal.App.ViewModels
private double _backgroundOpacity;
private TerminalViewModel _selectedTerminal;
private TabsPosition _tabsPosition;
private string _windowTitle;
public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
@@ -117,6 +118,18 @@ namespace FluentTerminal.App.ViewModels
public RelayCommand AddTerminalCommand { get; }
public string WindowTitle
{
get => _windowTitle;
set
{
if (Set(ref _windowTitle, value))
{
ApplicationView.Title = value;
}
}
}
public bool ShowTabsOnTop
{
get => TabsPosition == TabsPosition.Top && (Terminals.Count > 1 || _applicationSettings.AlwaysShowTabs);
@@ -154,6 +167,14 @@ namespace FluentTerminal.App.ViewModels
if (SelectedTerminal != null)
{
SelectedTerminal.IsSelected = true;
if (_applicationSettings.ShowCustomTitleInTitlebar)
{
WindowTitle = SelectedTerminal.TabTitle;
}
else
{
WindowTitle = SelectedTerminal.ShellTitle;
}
}
}
}
@@ -212,17 +233,47 @@ namespace FluentTerminal.App.ViewModels
var terminal = new TerminalViewModel(_settingsService, _trayProcessCommunicationService, _dialogService, _keyboardCommandService,
_applicationSettings, profile, ApplicationView, _dispatcherTimer, _clipboardService);
terminal.Closed += OnTerminalClosed;
terminal.ShellTitleChanged += Terminal_ShellTitleChanged;
terminal.CustomTitleChanged += Terminal_CustomTitleChanged;
Terminals.Add(terminal);
SelectedTerminal = terminal;
});
}
private void Terminal_CustomTitleChanged(object sender, string e)
{
if (sender is TerminalViewModel terminal)
{
if (terminal.IsSelected && _applicationSettings.ShowCustomTitleInTitlebar)
{
if (string.IsNullOrWhiteSpace(e))
{
WindowTitle = terminal.ShellTitle;
}
else
{
WindowTitle = e;
}
}
}
}
private void Terminal_ShellTitleChanged(object sender, string e)
{
if (sender is TerminalViewModel terminal && terminal.IsSelected && !_applicationSettings.ShowCustomTitleInTitlebar)
{
WindowTitle = e;
}
}
public async Task CloseAllTerminals()
{
foreach (var terminal in Terminals)
{
terminal.Closed -= OnTerminalClosed;
terminal.ShellTitleChanged -= Terminal_ShellTitleChanged;
terminal.CustomTitleChanged -= Terminal_CustomTitleChanged;
await terminal.Close();
}
}
@@ -250,6 +301,15 @@ namespace FluentTerminal.App.ViewModels
TabsPosition = e.TabsPosition;
RaisePropertyChanged(nameof(ShowTabsOnTop));
RaisePropertyChanged(nameof(ShowTabsOnBottom));
if (e.ShowCustomTitleInTitlebar)
{
WindowTitle = SelectedTerminal?.TabTitle;
}
else
{
WindowTitle = SelectedTerminal?.ShellTitle;
}
});
}
@@ -68,6 +68,20 @@ namespace FluentTerminal.App.ViewModels.Settings
}
}
public bool ShowCustomTitleInTitlebar
{
get => _applicationSettings.ShowCustomTitleInTitlebar;
set
{
if (_applicationSettings.ShowCustomTitleInTitlebar != value)
{
_applicationSettings.ShowCustomTitleInTitlebar = value;
_settingsService.SaveApplicationSettings(_applicationSettings);
RaisePropertyChanged();
}
}
}
public bool EnableTrayIcon
{
get => _applicationSettings.EnableTrayIcon;
@@ -281,6 +295,7 @@ namespace FluentTerminal.App.ViewModels.Settings
AlwaysUseWinPty = defaults.AlwaysUseWinPty;
ShowNewOutputIndicator = defaults.ShowNewOutputIndicator;
EnableTrayIcon = defaults.EnableTrayIcon;
ShowCustomTitleInTitlebar = defaults.ShowCustomTitleInTitlebar;
}
}
@@ -79,6 +79,8 @@ namespace FluentTerminal.App.ViewModels
public event EventHandler<TerminalOptions> OptionsChanged;
public event EventHandler SearchStarted;
public event EventHandler<TerminalTheme> ThemeChanged;
public event EventHandler<string> ShellTitleChanged;
public event EventHandler<string> CustomTitleChanged;
public ApplicationSettings ApplicationSettings { get; private set; }
@@ -116,7 +118,6 @@ namespace FluentTerminal.App.ViewModels
{
if (IsSelected)
{
ApplicationView.Title = ShellTitle ?? string.Empty;
HasNewOutput = false;
}
RaisePropertyChanged(nameof(IsUnderlined));
@@ -201,9 +202,9 @@ namespace FluentTerminal.App.ViewModels
get => _tabTitle;
set
{
if (Set(ref _tabTitle, value) && IsSelected)
if (Set(ref _tabTitle, value))
{
ApplicationView.Title = value;
CustomTitleChanged?.Invoke(this, value);
}
}
}
@@ -390,6 +391,7 @@ namespace FluentTerminal.App.ViewModels
private void Terminal_TitleChanged(object sender, string e)
{
ShellTitle = e;
ShellTitleChanged?.Invoke(this, e);
}
private async Task TryClose()