Skip to content
This repository was archived by the owner on Nov 25, 2023. It is now read-only.
Merged
3 changes: 1 addition & 2 deletions src/InvvardDev.EZLayoutDisplay.Desktop/Model/Revision.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace InvvardDev.EZLayoutDisplay.Desktop.Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<i:EventTrigger EventName="Deactivated">
<command:EventToCommand Command="{Binding LostFocusCommand, Mode=OneWay}" />
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseWheel">
<command:EventToCommand Command="{Binding ScrollLayerCommand, Mode=OneWay}"
PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Window.InputBindings>
<KeyBinding Key="Escape" Command="{Binding HideWindowCommand, Mode=OneWay}" />
Expand All @@ -50,24 +54,27 @@
</StackPanel>

<StackPanel Style="{StaticResource SpControlHintStyle}"
Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToVisibleConverter}}">
<ToggleButton x:Name="ToggleWindowPin" Content="{Binding ToggleBtnPinWindowContent}" ToolTip="{Binding ToggleBtnPinWindowTooltip}"
IsChecked="{Binding IsWindowPinned}" Focusable="False" Style="{StaticResource ToggleButtonPinWindowStyle}" />
Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToVisibleConverter}}">
<ToggleButton x:Name="ToggleWindowPin" Content="{Binding ToggleBtnPinWindowContent}"
ToolTip="{Binding ToggleBtnPinWindowTooltip}"
IsChecked="{Binding IsWindowPinned}" Focusable="False"
Style="{StaticResource ToggleButtonPinWindowStyle}" />
<TextBlock Text="{Binding ControlHintEscapeLabel}" Style="{StaticResource TbControlHintStyle}" />
<TextBlock Text="{Binding ControlHintSpaceLabel}" Style="{StaticResource TbControlHintStyle}" />
<TextBlock Text="{Binding ControlHintSpaceLabel}" Style="{StaticResource TbControlHintStyle}" />
</StackPanel>

<Grid Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToHiddenConverter}}" Width="350">
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".25*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition/>
<ColumnDefinition Width=".25*" />
<ColumnDefinition Width="10" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="../Skins/Images/warning-sign.png"/>
<TextBlock Grid.Column="2" TextWrapping="WrapWithOverflow" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left">
<Run Text="{Binding NoLayoutWarningFirstLine, Mode=OneWay}"/>
<LineBreak/>
<Run Text="{Binding NoLayoutWarningSecondLine, Mode=OneWay}"/>
<Image Grid.Column="0" Source="../Skins/Images/warning-sign.png" />
<TextBlock Grid.Column="2" TextWrapping="WrapWithOverflow" FontSize="18" VerticalAlignment="Center"
HorizontalAlignment="Left">
<Run Text="{Binding NoLayoutWarningFirstLine, Mode=OneWay}" />
<LineBreak />
<Run Text="{Binding NoLayoutWarningSecondLine, Mode=OneWay}" />
</TextBlock>
</Grid>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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:model="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.Model"
mc:Ignorable="d" Background="{StaticResource WindowBackgroundBrush}"
Title="{Binding WindowTitle}" Icon="{StaticResource WindowIcon}"
Width="630" Height="340" MinWidth="630" MinHeight="300"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class DisplayLayoutViewModel : ViewModelBase
private ICommand _lostFocusCommand;
private ICommand _hideWindowCommand;
private ICommand _nextLayerCommand;
private ICommand _scrollLayerCommand;

private List<List<KeyTemplate>> _layoutTemplates;
private ObservableCollection<KeyTemplate> _currentLayoutTemplate;
Expand Down Expand Up @@ -198,6 +199,13 @@ public bool IsWindowPinned
_nextLayerCommand
?? (_nextLayerCommand = new RelayCommand(NextLayer, NextLayerCanExecute));

/// <summary>
/// Next layer command.
/// </summary>
public ICommand ScrollLayerCommand =>
_scrollLayerCommand
?? (_scrollLayerCommand = new RelayCommand<MouseWheelEventArgs>(ScrollLayer));

#endregion

public DisplayLayoutViewModel(IWindowService windowService, ILayoutService layoutService, ISettingsService settingsService)
Expand Down Expand Up @@ -370,16 +378,50 @@ private void LostFocus()
private void NextLayer()
{
Logger.TraceRelayCommand();

VaryLayer(1);
}

private void ScrollLayer(MouseWheelEventArgs e)
{
Logger.TraceRelayCommand();

if (e.Delta < 0)
{
VaryLayer(1);
}

if (e.Delta > 0)
{
VaryLayer(-1);
}
}

private void VaryLayer(int variation)
{
Logger.TraceRelayCommand();

var maxLayerIndex = _ezLayout.EZLayers.Count - 1;

switch (CurrentLayerIndex)
{
case var _ when maxLayerIndex == 0:
case var _ when CurrentLayerIndex >= maxLayerIndex:
case var _ when maxLayerIndex <= 0:
CurrentLayerIndex = 0;

break;
case var _ when CurrentLayerIndex <= 0 && variation < 0:
CurrentLayerIndex = maxLayerIndex;

break;
case var _ when CurrentLayerIndex > 0 && variation < 0:
CurrentLayerIndex--;

break;
case var _ when CurrentLayerIndex >= maxLayerIndex && variation > 0:
CurrentLayerIndex = 0;

break;
case var _ when CurrentLayerIndex < maxLayerIndex:
case var _ when CurrentLayerIndex < maxLayerIndex && variation > 0:
CurrentLayerIndex++;

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,20 @@
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.10.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.10.1\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NonInvasiveKeyboardHookLibrary, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NonInvasiveKeyboardHookLibrary.1.4.0\lib\net452\NonInvasiveKeyboardHookLibrary.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="xunit.assert, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
Expand All @@ -81,6 +67,9 @@
<Reference Include="xunit.execution.desktop, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
<Reference Include="Xunit.StaFact, Version=0.3.0.0, Culture=neutral, PublicKeyToken=593f35978b459a4b, processorArchitecture=MSIL">
<HintPath>..\packages\Xunit.StaFact.0.3.18\lib\net452\Xunit.StaFact.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ContinuousIntegration.Designer.cs">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Windows.Input;
using InvvardDev.EZLayoutDisplay.Desktop.Model;
using InvvardDev.EZLayoutDisplay.Desktop.Service.Interface;
using InvvardDev.EZLayoutDisplay.Desktop.View;
Expand All @@ -10,18 +12,31 @@ namespace InvvardDev.EZLayoutDisplay.Tests.ViewModel
{
public class DisplayLayoutViewModelTest
{
private static EZLayout CreateLayers(int layerNumber)
{
var keyboardLayout = new EZLayout();

for (int i = 0 ; i < layerNumber ; i++)
{
keyboardLayout.EZLayers.Add(new EZLayer {
Index = i,
EZKeys = new List<EZKey> {
new EZKey()
}
});
}

return keyboardLayout;
}

[ Fact ]
public void DisplayLayoutViewModel_Constructor()
{
//Arrange
var mockWindowService = new Mock<IWindowService>();
var mockLayoutService = new Mock<ILayoutService>();
var mockSettingsService = new Mock<ISettingsService>();
mockSettingsService.SetupProperty(s => s.EZLayout,
new EZLayout
{
EZLayers = new List<EZLayer> { new EZLayer { EZKeys = new List<EZKey> { new EZKey { Label = new KeyLabel("A"), Modifier = new KeyLabel("a") } } } }
});
mockSettingsService.SetupProperty(s => s.EZLayout, CreateLayers(1));

//Act
var displayLayoutViewModel = new DisplayLayoutViewModel(mockWindowService.Object, mockLayoutService.Object, mockSettingsService.Object);
Expand Down Expand Up @@ -56,8 +71,8 @@ public void LostFocusCommand_Execute()
}

[ Theory ]
[InlineData(true)]
[InlineData(false)]
[ InlineData(true) ]
[ InlineData(false) ]
public void LostFocusCommand_CanExecute(bool isPinned)
{
//Arrange
Expand All @@ -82,7 +97,7 @@ public void LostFocusCommand_CanExecute(bool isPinned)
}
}

[Fact]
[ Fact ]
public void HideWindowCommand_Execute()
{
//Arrange
Expand All @@ -99,7 +114,7 @@ public void HideWindowCommand_Execute()
mockWindowService.Verify(w => w.CloseWindow<DisplayLayoutWindow>(), Times.Once);
}

[Theory ]
[ Theory ]
[ InlineData(0, 1, true) ]
[ InlineData(1, 2, false) ]
[ InlineData(76, 2, false) ]
Expand All @@ -119,7 +134,10 @@ public void LoadCompleteLayout(int numberOfKey, int numberOfLayer, bool noLayout

for (int i = 0 ; i < numberOfLayer ; i++)
{
keyboardLayout.EZLayers.Add(new EZLayer { Index = i, EZKeys = new List<EZKey>(ezKeys) });
keyboardLayout.EZLayers.Add(new EZLayer {
Index = i,
EZKeys = new List<EZKey>(ezKeys)
});
}

var mockWindowService = new Mock<IWindowService>();
Expand All @@ -143,13 +161,49 @@ [ InlineData(1, true) ]
public void NextLayerCommand_CanExecute(int layerNumber, bool expectedCanExecute)
{
//Arrange
var keyboardLayout = new EZLayout();
var keyboardLayout = CreateLayers(layerNumber);

for (int i = 0 ; i < layerNumber ; i++)
var layoutTemplate = new List<KeyTemplate>();

for (int i = 0 ; i < 1 ; i++)
{
keyboardLayout.EZLayers.Add(new EZLayer { Index = i, EZKeys = new List<EZKey> { new EZKey() } });
layoutTemplate.Add(new KeyTemplate(i, i, 54, 81));
}

var mockLayoutService = new Mock<ILayoutService>();
mockLayoutService.Setup(l => l.GetLayoutTemplate()).ReturnsAsync(layoutTemplate);
var mockWindowService = new Mock<IWindowService>();
var mockSettingsService = new Mock<ISettingsService>();
mockSettingsService.SetupProperty(s => s.EZLayout, keyboardLayout);

//Act
var displayLayoutViewModel = new DisplayLayoutViewModel(mockWindowService.Object, mockLayoutService.Object, mockSettingsService.Object);

//Assert
Assert.Equal(expectedCanExecute, displayLayoutViewModel.NextLayerCommand.CanExecute(null));
}

[ WpfTheory ]
[ InlineData(0, 0, 120) ]
[ InlineData(0, 0, -120) ]
[ InlineData(1, 0, 120) ]
[ InlineData(1, 0, -120) ]
[ InlineData(2, 1, -120) ]
[ InlineData(2, 1, 120) ]
[ InlineData(2, 0, 120, -120) ]
[ InlineData(2, 0, 120, 120) ]
[ InlineData(2, 1, 120, 120, -120) ]
[ InlineData(3, 2, 120) ]
[ InlineData(3, 1, -120) ]
[ InlineData(3, 2, -120, -120) ]
[ InlineData(3, 1, 120, 120) ]
[ InlineData(3, 0, -120, -120, -120) ]
[ InlineData(3, 0, 120, 120, 120) ]
public void ScrollLayerCommand_Execute(int layerNumber, int expectedCurrentLayerIndex, params int[] scrollingValues)
{
//Arrange
var keyboardLayout = CreateLayers(layerNumber);

var layoutTemplate = new List<KeyTemplate>();

for (int i = 0 ; i < 1 ; i++)
Expand All @@ -166,8 +220,13 @@ public void NextLayerCommand_CanExecute(int layerNumber, bool expectedCanExecute
//Act
var displayLayoutViewModel = new DisplayLayoutViewModel(mockWindowService.Object, mockLayoutService.Object, mockSettingsService.Object);

foreach (var scrollingValue in scrollingValues)
{
displayLayoutViewModel.ScrollLayerCommand.Execute(new MouseWheelEventArgs(Mouse.PrimaryDevice, 0, scrollingValue));
}

//Assert
Assert.Equal(expectedCanExecute, displayLayoutViewModel.NextLayerCommand.CanExecute(null));
Assert.Equal(expectedCurrentLayerIndex, displayLayoutViewModel.CurrentLayerIndex);
}

[ Theory ]
Expand All @@ -184,13 +243,7 @@ [ InlineData(3, 3, 0) ]
public void NextLayerCommand_Execute(int layerNumber, int nextLayerHit, int expectedCurrentLayerIndex)
{
//Arrange
var keyboardLayout = new EZLayout();

for (int i = 0 ; i < layerNumber ; i++)
{
keyboardLayout.EZLayers.Add(new EZLayer { Index = i, EZKeys = new List<EZKey> { new EZKey() } });
}

var keyboardLayout = CreateLayers(layerNumber);
var layoutTemplate = new List<KeyTemplate>();

for (int i = 0 ; i < 1 ; i++)
Expand Down Expand Up @@ -223,8 +276,7 @@ public void NoLayoutAvailable()
var mockLayoutService = new Mock<ILayoutService>();
var mockWindowService = new Mock<IWindowService>();
var mockSettingsService = new Mock<ISettingsService>();
mockSettingsService.SetupProperty(s => s.EZLayout,
new EZLayout { EZLayers = new List<EZLayer>() });
mockSettingsService.SetupProperty(s => s.EZLayout, CreateLayers(0));

// Act
var displayLayoutViewModel = new DisplayLayoutViewModel(mockWindowService.Object, mockLayoutService.Object, mockSettingsService.Object);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Castle.Components.DictionaryAdapter;
using InvvardDev.EZLayoutDisplay.Desktop.Model;
using InvvardDev.EZLayoutDisplay.Desktop.Service.Interface;
using InvvardDev.EZLayoutDisplay.Desktop.View;
Expand Down Expand Up @@ -300,7 +298,7 @@ public void OpenTagSearchCommandExecute_ArgumentNullException()
var mockProcessService = new Mock<IProcessService>();

// Act
var settingsViewModel = new SettingsViewModel(mockSettingsService.Object, mockWindowService.Object, mockLayoutService.Object, mockProcessService.Object);
var _ = new SettingsViewModel(mockSettingsService.Object, mockWindowService.Object, mockLayoutService.Object, mockProcessService.Object);

// Assert
mockLayoutService.Verify();
Expand All @@ -320,7 +318,7 @@ public void OpenTagSearchCommandExecute_ArgumentException()
var mockProcessService = new Mock<IProcessService>();

// Act
var settingsViewModel = new SettingsViewModel(mockSettingsService.Object, mockWindowService.Object, mockLayoutService.Object, mockProcessService.Object);
var _settingsViewModel = new SettingsViewModel(mockSettingsService.Object, mockWindowService.Object, mockLayoutService.Object, mockProcessService.Object);

// Assert
mockLayoutService.Verify();
Expand Down
Loading