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 5 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
54 changes: 54 additions & 0 deletions FluentTerminal.App.ViewModels/OverlayViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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);
if (value)
{
if (_overlayTimer.IsEnabled)
AndrewKralovec marked this conversation as resolved.
Show resolved Hide resolved
{
_overlayTimer.Stop();
}
_overlayTimer.Start();
}
}
}

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

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

}
}
50 changes: 12 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 OverlayViewModel _overlay;
private string _tabTitle;
private string _shellTitle;
private bool _hasCustomTitle;
Expand Down Expand Up @@ -52,10 +50,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 +63,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 +132,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 +144,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 Down Expand Up @@ -197,6 +171,12 @@ public TerminalTheme TerminalTheme
set => Set(ref _terminalTheme, value);
}

public OverlayViewModel Overlay
AndrewKralovec marked this conversation as resolved.
Show resolved Hide resolved
{
get => _overlay;
set => Set(ref _overlay, value);
}

public string TabTitle
{
get => _tabTitle;
Expand Down Expand Up @@ -306,12 +286,6 @@ 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)
{
await ApplicationView.RunOnDispatcherThread(() => OptionsChanged?.Invoke(this, e));
Expand All @@ -335,6 +309,7 @@ private async void Terminal_KeyboardCommandReceived(object sender, string e)
{
var selection = await Terminal.GetSelectedText().ConfigureAwait(true);
ClipboardService.SetText(selection);
Overlay.OverlayContent = "Text copied";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this configurable

Copy link
Contributor Author

@AndrewKralovec AndrewKralovec Apr 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate ? What do you mean by configurable?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not everybody might want to see this. I would add a toggle to the settings to activate/deactivate this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now, yeah that is a good idea, Ill get on that.

Copy link
Contributor Author

@AndrewKralovec AndrewKralovec Apr 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixse , i was thinking about this feature. Instead of just adding a single toggle to the settings, would it be a good idea to create a list of possible overlay settings/events? The idea would be, create a list in the settings page. The list will have the possible overlay notifications (resize & text copied). This list will be bound to the terminal settings. You can toggle them on and off. In the Terminal View Model, we would pass this list to the overlay view model. Then continue to hook up the overlay events to the view, but instead of just sending a string in the show overlay, it would send an object, such as a dictionary of some sorts specifying the text and the settings name. In the overlay model, it would check the settings name to see if its in the list of events that are toggled on.

I was thinking this would make it more extensible, but if this is going to be a small feature, then it over kill.

Example/ proof of the concept.


public Dictionary<string, bool> OverlaySettings;
public TerminalPageViewModel()
{
    ... 
    // Would be moved to default settings
    OverlaySettings.Add("resize", false);
    OverlaySettings.Add("copied", false);
}


<StackPanel Margin="{StaticResource ItemMargin}">
    <TextBlock Margin="0,0,0,8" 
                Text="Overlay Notifications" />
    <ListView x:Name="listView1"
                ItemsSource="{x:Bind ViewModel.OverlaySettings}">
        <ListView.ItemTemplate>
            <DataTemplate >
                <ToggleSwitch
                    Margin="{StaticResource ItemMargin}"
                    Header="{Binding Key}"
                    IsOn="{Binding Value, Mode=TwoWay}" />
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackPanel>

private void Terminal_SizeChanged(object sender, TerminalSize e)
{
    // Or whatever type is decided 
    Overlay.Show("resize", $"{e.Columns} x {e.Rows}");
    Overlay.Show(new { Name = "resize", Value = $"{e.Columns} x {e.Rows}" });
    OverlayEvent.?Invoke(this, $"{e.Columns} x {e.Rows}"); 
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitively possible, but I don't think there will be much more possible overlays. Maybe keep this in mind until a third overlay comes around?

break;
}
case nameof(Command.Paste):
Expand Down Expand Up @@ -384,8 +359,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.OverlayContent = $"{e.Columns} x {e.Rows}";
}

private void Terminal_TitleChanged(object sender, string e)
Expand Down
8 changes: 8 additions & 0 deletions FluentTerminal.App/FluentTerminal.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<Compile Include="Utilities\ColorExtensions.cs" />
<Compile Include="Utilities\ContrastHelper.cs" />
<Compile Include="Utilities\DebouncedAction.cs" />
<Compile Include="Views\IOverlayView.cs" />
<Compile Include="Views\KeyBindingsView.xaml.cs">
<DependentUpon>KeyBindingsView.xaml</DependentUpon>
</Compile>
Expand All @@ -154,6 +155,9 @@
<Compile Include="Dialogs\CreateKeyBindingDialog.xaml.cs">
<DependentUpon>CreateKeyBindingDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\OverlayView.xaml.cs">
<DependentUpon>OverlayView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -320,6 +324,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\OverlayView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SettingsPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
11 changes: 11 additions & 0 deletions FluentTerminal.App/Views/IOverlayView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using FluentTerminal.App.ViewModels;
using FluentTerminal.Models;
using System.Threading.Tasks;

namespace FluentTerminal.App.Views
{
interface IOverlayView
{
Task Initialize(OverlayViewModel viewModel);
}
}
22 changes: 22 additions & 0 deletions FluentTerminal.App/Views/OverlayView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<UserControl
x:Class="FluentTerminal.App.Views.OverlayView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="600"
mc:Ignorable="d"
Visibility="{Binding ShowOverlay, Mode=OneWay, Converter={StaticResource TrueToVisibleConverter}}">
<Grid
Grid.Row="0"
Margin="12"
Padding="6"
HorizontalAlignment="Right"
VerticalAlignment="Bottom">
<Grid.Background>
<SolidColorBrush Color="{ThemeResource SystemAccentColor}" />
</Grid.Background>
<TextBlock Foreground="White" Text="{Binding OverlayContent}" />
</Grid>
</UserControl>
12 changes: 12 additions & 0 deletions FluentTerminal.App/Views/OverlayView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Windows.UI.Xaml.Controls;

namespace FluentTerminal.App.Views
{
public sealed partial class OverlayView : UserControl
{
public OverlayView()
{
InitializeComponent();
}
}
}
2 changes: 2 additions & 0 deletions FluentTerminal.App/Views/TabBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@
VerticalAlignment="Stretch"
Background="Transparent"
ToolTipService.ToolTip="{x:Bind TabTitle, Mode=OneWay}">

<Interactivity:Interaction.Behaviors>
<behaviors:MiddleClickBehavior>
<behaviors:MiddleClickBehavior.Actions>
<core:InvokeCommandAction Command="{x:Bind CloseCommand}" />
</behaviors:MiddleClickBehavior.Actions>
</behaviors:MiddleClickBehavior>
</Interactivity:Interaction.Behaviors>

<RelativePanel.ContextFlyout>
<MenuFlyout>
<MenuFlyoutSubItem Text="Color">
Expand Down
19 changes: 7 additions & 12 deletions FluentTerminal.App/Views/TerminalView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="using:FluentTerminal.App.Views"
d:DesignHeight="300"
d:DesignWidth="600"
mc:Ignorable="d">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid x:Name="TerminalContainer" Grid.Row="0" />
<Grid
Grid.Row="0"
Margin="12"
Padding="6"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Visibility="{x:Bind ViewModel.ShowResizeOverlay, Mode=OneWay, Converter={StaticResource TrueToVisibleConverter}}">
<Grid.Background>
<SolidColorBrush Color="{ThemeResource SystemAccentColor}" />
</Grid.Background>
<TextBlock Foreground="White" Text="{x:Bind ViewModel.ResizeOverlayContent, Mode=OneWay}" />
</Grid>

<views:OverlayView
DataContext="{x:Bind ViewModel.Overlay}">
</views:OverlayView>

<RelativePanel
Grid.Row="1"
Padding="12"
Expand Down