Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/overlay control #278

Merged
merged 10 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions FluentTerminal.App.ViewModels/OverlayViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using FluentTerminal.App.Services;
using GalaSoft.MvvmLight;
using System;

namespace FluentTerminal.App.ViewModels
{
public class OverlayViewModel : ViewModelBase
{
private readonly IDispatcherTimer _overlayTimer;
private bool _showOverlay;
private string _overlayContent;

public OverlayViewModel(IDispatcherTimer dispatcherTimer)
{
_overlayTimer = dispatcherTimer;
_overlayTimer.Interval = new TimeSpan(0, 0, 2);
_overlayTimer.Tick += OnResizeOverlayTimerFinished;
}

public bool ShowOverlay
{
get => _showOverlay;
set => Set(ref _showOverlay, value);
}

public string OverlayContent
{
get => _overlayContent;
set => Set(ref _overlayContent, value);
}

public void Show(string message)
{
OverlayContent = message;
ShowOverlay = true;

if (_overlayTimer.IsEnabled)
{
_overlayTimer.Stop();
}
_overlayTimer.Start();
}

private void OnResizeOverlayTimerFinished(object sender, object e)
{
_overlayTimer.Stop();
ShowOverlay = false;
}

}
}
15 changes: 15 additions & 0 deletions FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ public bool BoldText
}
}

public bool ShowTextCopied
{
get => _terminalOptions.ShowTextCopied;
set
{
if (_terminalOptions.ShowTextCopied != value)
{
_terminalOptions.ShowTextCopied = value;
_settingsService.SaveTerminalOptions(_terminalOptions);
RaisePropertyChanged();
}
}
}

public IEnumerable<FontInfo> Fonts { get; }

public int FontSize
Expand Down Expand Up @@ -223,6 +237,7 @@ private async Task RestoreDefaults()
BoldText = defaults.BoldText;
BackgroundOpacity = defaults.BackgroundOpacity;
ScrollBackLimit = defaults.ScrollBackLimit.ToString();
ShowTextCopied = defaults.ShowTextCopied;
}
}

Expand Down
52 changes: 14 additions & 38 deletions FluentTerminal.App.ViewModels/TerminalViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ namespace FluentTerminal.App.ViewModels
public class TerminalViewModel : ViewModelBase
{
private readonly IKeyboardCommandService _keyboardCommandService;
private readonly IDispatcherTimer _resizeOverlayTimer;
private bool _isSelected;
private bool _hasNewOutput;
private string _resizeOverlayContent;
private string _searchText;
private bool _showResizeOverlay;
private bool _showSearchPanel;
private TabTheme _tabTheme;
private TerminalTheme _terminalTheme;
private TerminalOptions _terminalOptions;
private string _tabTitle;
private string _shellTitle;
private bool _hasCustomTitle;
Expand All @@ -38,6 +36,8 @@ public TerminalViewModel(ISettingsService settingsService, ITrayProcessCommunica
SettingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
SettingsService.KeyBindingsChanged += OnKeyBindingsChanged;

_terminalOptions = SettingsService.GetTerminalOptions();

TrayProcessCommunicationService = trayProcessCommunicationService;

DialogService = dialogService;
Expand All @@ -52,10 +52,6 @@ public TerminalViewModel(ISettingsService settingsService, ITrayProcessCommunica
TabThemes = new ObservableCollection<TabTheme>(SettingsService.GetTabThemes());
TabTheme = TabThemes.FirstOrDefault(t => t.Id == ShellProfile.TabThemeId);

_resizeOverlayTimer = dispatcherTimer;
_resizeOverlayTimer.Interval = new TimeSpan(0, 0, 2);
_resizeOverlayTimer.Tick += OnResizeOverlayTimerFinished;

CloseCommand = new RelayCommand(async () => await TryClose().ConfigureAwait(false));
FindNextCommand = new RelayCommand(FindNext);
FindPreviousCommand = new RelayCommand(FindPrevious);
Expand All @@ -69,6 +65,9 @@ public TerminalViewModel(ISettingsService settingsService, ITrayProcessCommunica
Terminal.SizeChanged += Terminal_SizeChanged;
Terminal.TitleChanged += Terminal_TitleChanged;
Terminal.Closed += Terminal_Closed;

Overlay = new OverlayViewModel(dispatcherTimer);

}

public event EventHandler Activated;
Expand Down Expand Up @@ -135,12 +134,6 @@ public bool HasNewOutput
set => Set(ref _hasNewOutput, value);
}

public string ResizeOverlayContent
{
get => _resizeOverlayContent;
set => Set(ref _resizeOverlayContent, value);
}

public string SearchText
{
get => _searchText;
Expand All @@ -153,23 +146,6 @@ public string SearchText

public ShellProfile ShellProfile { get; }

public bool ShowResizeOverlay
{
get => _showResizeOverlay;
set
{
Set(ref _showResizeOverlay, value);
if (value)
{
if (_resizeOverlayTimer.IsEnabled)
{
_resizeOverlayTimer.Stop();
}
_resizeOverlayTimer.Start();
}
}
}

public bool ShowSearchPanel
{
get => _showSearchPanel;
Expand All @@ -191,6 +167,8 @@ public TabTheme TabTheme

public Terminal Terminal { get; private set; }

public OverlayViewModel Overlay { get; private set; }

public TerminalTheme TerminalTheme
{
get => _terminalTheme;
Expand Down Expand Up @@ -306,14 +284,9 @@ private async void OnKeyBindingsChanged(object sender, EventArgs e)
await ApplicationView.RunOnDispatcherThread(() => KeyBindingsChanged?.Invoke(this, EventArgs.Empty));
}

private void OnResizeOverlayTimerFinished(object sender, object e)
{
_resizeOverlayTimer.Stop();
ShowResizeOverlay = false;
}

private async void OnTerminalOptionsChanged(object sender, TerminalOptions e)
{
_terminalOptions = e;
await ApplicationView.RunOnDispatcherThread(() => OptionsChanged?.Invoke(this, e));
}

Expand All @@ -335,6 +308,10 @@ private async void Terminal_KeyboardCommandReceived(object sender, string e)
{
var selection = await Terminal.GetSelectedText().ConfigureAwait(true);
ClipboardService.SetText(selection);
if(_terminalOptions.ShowTextCopied)
{
Overlay.Show("Text copied");
}
break;
}
case nameof(Command.Paste):
Expand Down Expand Up @@ -384,8 +361,7 @@ private void Terminal_OutputReceived(object sender, byte[] e)

private void Terminal_SizeChanged(object sender, TerminalSize e)
{
ResizeOverlayContent = $"{e.Columns} x {e.Rows}";
ShowResizeOverlay = true;
Overlay.Show($"{e.Columns} x {e.Rows}");
}

private void Terminal_TitleChanged(object sender, string e)
Expand Down
Loading