Skip to content
This repository was archived by the owner on Nov 25, 2023. It is now read-only.

Commit 6f32205

Browse files
authored
Merge pull request #87 from Invvard/feature/change-layer-scrolling
Feature/change layer scrolling
2 parents 2b95e91 + 2db87f7 commit 6f32205

File tree

9 files changed

+157
-63
lines changed

9 files changed

+157
-63
lines changed

src/InvvardDev.EZLayoutDisplay.Desktop/Model/Revision.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using Newtonsoft.Json;
43

54
namespace InvvardDev.EZLayoutDisplay.Desktop.Model

src/InvvardDev.EZLayoutDisplay.Desktop/View/DisplayLayoutWindow.xaml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<i:EventTrigger EventName="Deactivated">
2727
<command:EventToCommand Command="{Binding LostFocusCommand, Mode=OneWay}" />
2828
</i:EventTrigger>
29+
<i:EventTrigger EventName="PreviewMouseWheel">
30+
<command:EventToCommand Command="{Binding ScrollLayerCommand, Mode=OneWay}"
31+
PassEventArgsToCommand="True" />
32+
</i:EventTrigger>
2933
</i:Interaction.Triggers>
3034
<Window.InputBindings>
3135
<KeyBinding Key="Escape" Command="{Binding HideWindowCommand, Mode=OneWay}" />
@@ -50,24 +54,27 @@
5054
</StackPanel>
5155

5256
<StackPanel Style="{StaticResource SpControlHintStyle}"
53-
Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToVisibleConverter}}">
54-
<ToggleButton x:Name="ToggleWindowPin" Content="{Binding ToggleBtnPinWindowContent}" ToolTip="{Binding ToggleBtnPinWindowTooltip}"
55-
IsChecked="{Binding IsWindowPinned}" Focusable="False" Style="{StaticResource ToggleButtonPinWindowStyle}" />
57+
Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToVisibleConverter}}">
58+
<ToggleButton x:Name="ToggleWindowPin" Content="{Binding ToggleBtnPinWindowContent}"
59+
ToolTip="{Binding ToggleBtnPinWindowTooltip}"
60+
IsChecked="{Binding IsWindowPinned}" Focusable="False"
61+
Style="{StaticResource ToggleButtonPinWindowStyle}" />
5662
<TextBlock Text="{Binding ControlHintEscapeLabel}" Style="{StaticResource TbControlHintStyle}" />
57-
<TextBlock Text="{Binding ControlHintSpaceLabel}" Style="{StaticResource TbControlHintStyle}" />
63+
<TextBlock Text="{Binding ControlHintSpaceLabel}" Style="{StaticResource TbControlHintStyle}" />
5864
</StackPanel>
5965

6066
<Grid Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToHiddenConverter}}" Width="350">
6167
<Grid.ColumnDefinitions>
62-
<ColumnDefinition Width=".25*"/>
63-
<ColumnDefinition Width="10"/>
64-
<ColumnDefinition/>
68+
<ColumnDefinition Width=".25*" />
69+
<ColumnDefinition Width="10" />
70+
<ColumnDefinition />
6571
</Grid.ColumnDefinitions>
66-
<Image Grid.Column="0" Source="../Skins/Images/warning-sign.png"/>
67-
<TextBlock Grid.Column="2" TextWrapping="WrapWithOverflow" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left">
68-
<Run Text="{Binding NoLayoutWarningFirstLine, Mode=OneWay}"/>
69-
<LineBreak/>
70-
<Run Text="{Binding NoLayoutWarningSecondLine, Mode=OneWay}"/>
72+
<Image Grid.Column="0" Source="../Skins/Images/warning-sign.png" />
73+
<TextBlock Grid.Column="2" TextWrapping="WrapWithOverflow" FontSize="18" VerticalAlignment="Center"
74+
HorizontalAlignment="Left">
75+
<Run Text="{Binding NoLayoutWarningFirstLine, Mode=OneWay}" />
76+
<LineBreak />
77+
<Run Text="{Binding NoLayoutWarningSecondLine, Mode=OneWay}" />
7178
</TextBlock>
7279
</Grid>
7380
</Grid>

src/InvvardDev.EZLayoutDisplay.Desktop/View/SettingsWindow.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6-
xmlns:model="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.Model"
76
mc:Ignorable="d" Background="{StaticResource WindowBackgroundBrush}"
87
Title="{Binding WindowTitle}" Icon="{StaticResource WindowIcon}"
98
Width="630" Height="340" MinWidth="630" MinHeight="300"

src/InvvardDev.EZLayoutDisplay.Desktop/ViewModel/DisplayLayoutViewModel.cs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class DisplayLayoutViewModel : ViewModelBase
3333
private ICommand _lostFocusCommand;
3434
private ICommand _hideWindowCommand;
3535
private ICommand _nextLayerCommand;
36+
private ICommand _scrollLayerCommand;
3637

3738
private List<List<KeyTemplate>> _layoutTemplates;
3839
private ObservableCollection<KeyTemplate> _currentLayoutTemplate;
@@ -198,6 +199,13 @@ public bool IsWindowPinned
198199
_nextLayerCommand
199200
?? (_nextLayerCommand = new RelayCommand(NextLayer, NextLayerCanExecute));
200201

202+
/// <summary>
203+
/// Next layer command.
204+
/// </summary>
205+
public ICommand ScrollLayerCommand =>
206+
_scrollLayerCommand
207+
?? (_scrollLayerCommand = new RelayCommand<MouseWheelEventArgs>(ScrollLayer));
208+
201209
#endregion
202210

203211
public DisplayLayoutViewModel(IWindowService windowService, ILayoutService layoutService, ISettingsService settingsService)
@@ -370,16 +378,50 @@ private void LostFocus()
370378
private void NextLayer()
371379
{
372380
Logger.TraceRelayCommand();
381+
382+
VaryLayer(1);
383+
}
384+
385+
private void ScrollLayer(MouseWheelEventArgs e)
386+
{
387+
Logger.TraceRelayCommand();
388+
389+
if (e.Delta < 0)
390+
{
391+
VaryLayer(1);
392+
}
393+
394+
if (e.Delta > 0)
395+
{
396+
VaryLayer(-1);
397+
}
398+
}
399+
400+
private void VaryLayer(int variation)
401+
{
402+
Logger.TraceRelayCommand();
403+
373404
var maxLayerIndex = _ezLayout.EZLayers.Count - 1;
374405

375406
switch (CurrentLayerIndex)
376407
{
377-
case var _ when maxLayerIndex == 0:
378-
case var _ when CurrentLayerIndex >= maxLayerIndex:
408+
case var _ when maxLayerIndex <= 0:
409+
CurrentLayerIndex = 0;
410+
411+
break;
412+
case var _ when CurrentLayerIndex <= 0 && variation < 0:
413+
CurrentLayerIndex = maxLayerIndex;
414+
415+
break;
416+
case var _ when CurrentLayerIndex > 0 && variation < 0:
417+
CurrentLayerIndex--;
418+
419+
break;
420+
case var _ when CurrentLayerIndex >= maxLayerIndex && variation > 0:
379421
CurrentLayerIndex = 0;
380422

381423
break;
382-
case var _ when CurrentLayerIndex < maxLayerIndex:
424+
case var _ when CurrentLayerIndex < maxLayerIndex && variation > 0:
383425
CurrentLayerIndex++;
384426

385427
break;

src/InvvardDev.EZLayoutDisplay.Tests/InvvardDev.EZLayoutDisplay.Tests.csproj

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,20 @@
4444
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
4545
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
4646
</Reference>
47-
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
48-
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
49-
</Reference>
50-
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
51-
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
52-
</Reference>
5347
<Reference Include="Moq, Version=4.10.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
5448
<HintPath>..\packages\Moq.4.10.1\lib\net45\Moq.dll</HintPath>
5549
</Reference>
56-
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
57-
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
58-
</Reference>
59-
<Reference Include="NonInvasiveKeyboardHookLibrary, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
60-
<HintPath>..\packages\NonInvasiveKeyboardHookLibrary.1.4.0\lib\net452\NonInvasiveKeyboardHookLibrary.dll</HintPath>
61-
</Reference>
50+
<Reference Include="PresentationCore" />
6251
<Reference Include="PresentationFramework" />
6352
<Reference Include="System" />
64-
<Reference Include="System.Configuration" />
6553
<Reference Include="System.Core" />
6654
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
6755
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
6856
</Reference>
6957
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
7058
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
7159
</Reference>
72-
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
73-
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
74-
</Reference>
60+
<Reference Include="WindowsBase" />
7561
<Reference Include="xunit.assert, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
7662
<HintPath>..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
7763
</Reference>
@@ -81,6 +67,9 @@
8167
<Reference Include="xunit.execution.desktop, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
8268
<HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
8369
</Reference>
70+
<Reference Include="Xunit.StaFact, Version=0.3.0.0, Culture=neutral, PublicKeyToken=593f35978b459a4b, processorArchitecture=MSIL">
71+
<HintPath>..\packages\Xunit.StaFact.0.3.18\lib\net452\Xunit.StaFact.dll</HintPath>
72+
</Reference>
8473
</ItemGroup>
8574
<ItemGroup>
8675
<Compile Include="ContinuousIntegration.Designer.cs">

src/InvvardDev.EZLayoutDisplay.Tests/ViewModel/DisplayLayoutViewModelTest.cs

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Windows.Input;
24
using InvvardDev.EZLayoutDisplay.Desktop.Model;
35
using InvvardDev.EZLayoutDisplay.Desktop.Service.Interface;
46
using InvvardDev.EZLayoutDisplay.Desktop.View;
@@ -10,18 +12,31 @@ namespace InvvardDev.EZLayoutDisplay.Tests.ViewModel
1012
{
1113
public class DisplayLayoutViewModelTest
1214
{
15+
private static EZLayout CreateLayers(int layerNumber)
16+
{
17+
var keyboardLayout = new EZLayout();
18+
19+
for (int i = 0 ; i < layerNumber ; i++)
20+
{
21+
keyboardLayout.EZLayers.Add(new EZLayer {
22+
Index = i,
23+
EZKeys = new List<EZKey> {
24+
new EZKey()
25+
}
26+
});
27+
}
28+
29+
return keyboardLayout;
30+
}
31+
1332
[ Fact ]
1433
public void DisplayLayoutViewModel_Constructor()
1534
{
1635
//Arrange
1736
var mockWindowService = new Mock<IWindowService>();
1837
var mockLayoutService = new Mock<ILayoutService>();
1938
var mockSettingsService = new Mock<ISettingsService>();
20-
mockSettingsService.SetupProperty(s => s.EZLayout,
21-
new EZLayout
22-
{
23-
EZLayers = new List<EZLayer> { new EZLayer { EZKeys = new List<EZKey> { new EZKey { Label = new KeyLabel("A"), Modifier = new KeyLabel("a") } } } }
24-
});
39+
mockSettingsService.SetupProperty(s => s.EZLayout, CreateLayers(1));
2540

2641
//Act
2742
var displayLayoutViewModel = new DisplayLayoutViewModel(mockWindowService.Object, mockLayoutService.Object, mockSettingsService.Object);
@@ -56,8 +71,8 @@ public void LostFocusCommand_Execute()
5671
}
5772

5873
[ Theory ]
59-
[InlineData(true)]
60-
[InlineData(false)]
74+
[ InlineData(true) ]
75+
[ InlineData(false) ]
6176
public void LostFocusCommand_CanExecute(bool isPinned)
6277
{
6378
//Arrange
@@ -82,7 +97,7 @@ public void LostFocusCommand_CanExecute(bool isPinned)
8297
}
8398
}
8499

85-
[Fact]
100+
[ Fact ]
86101
public void HideWindowCommand_Execute()
87102
{
88103
//Arrange
@@ -99,7 +114,7 @@ public void HideWindowCommand_Execute()
99114
mockWindowService.Verify(w => w.CloseWindow<DisplayLayoutWindow>(), Times.Once);
100115
}
101116

102-
[Theory ]
117+
[ Theory ]
103118
[ InlineData(0, 1, true) ]
104119
[ InlineData(1, 2, false) ]
105120
[ InlineData(76, 2, false) ]
@@ -119,7 +134,10 @@ public void LoadCompleteLayout(int numberOfKey, int numberOfLayer, bool noLayout
119134

120135
for (int i = 0 ; i < numberOfLayer ; i++)
121136
{
122-
keyboardLayout.EZLayers.Add(new EZLayer { Index = i, EZKeys = new List<EZKey>(ezKeys) });
137+
keyboardLayout.EZLayers.Add(new EZLayer {
138+
Index = i,
139+
EZKeys = new List<EZKey>(ezKeys)
140+
});
123141
}
124142

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

148-
for (int i = 0 ; i < layerNumber ; i++)
166+
var layoutTemplate = new List<KeyTemplate>();
167+
168+
for (int i = 0 ; i < 1 ; i++)
149169
{
150-
keyboardLayout.EZLayers.Add(new EZLayer { Index = i, EZKeys = new List<EZKey> { new EZKey() } });
170+
layoutTemplate.Add(new KeyTemplate(i, i, 54, 81));
151171
}
152172

173+
var mockLayoutService = new Mock<ILayoutService>();
174+
mockLayoutService.Setup(l => l.GetLayoutTemplate()).ReturnsAsync(layoutTemplate);
175+
var mockWindowService = new Mock<IWindowService>();
176+
var mockSettingsService = new Mock<ISettingsService>();
177+
mockSettingsService.SetupProperty(s => s.EZLayout, keyboardLayout);
178+
179+
//Act
180+
var displayLayoutViewModel = new DisplayLayoutViewModel(mockWindowService.Object, mockLayoutService.Object, mockSettingsService.Object);
181+
182+
//Assert
183+
Assert.Equal(expectedCanExecute, displayLayoutViewModel.NextLayerCommand.CanExecute(null));
184+
}
185+
186+
[ WpfTheory ]
187+
[ InlineData(0, 0, 120) ]
188+
[ InlineData(0, 0, -120) ]
189+
[ InlineData(1, 0, 120) ]
190+
[ InlineData(1, 0, -120) ]
191+
[ InlineData(2, 1, -120) ]
192+
[ InlineData(2, 1, 120) ]
193+
[ InlineData(2, 0, 120, -120) ]
194+
[ InlineData(2, 0, 120, 120) ]
195+
[ InlineData(2, 1, 120, 120, -120) ]
196+
[ InlineData(3, 2, 120) ]
197+
[ InlineData(3, 1, -120) ]
198+
[ InlineData(3, 2, -120, -120) ]
199+
[ InlineData(3, 1, 120, 120) ]
200+
[ InlineData(3, 0, -120, -120, -120) ]
201+
[ InlineData(3, 0, 120, 120, 120) ]
202+
public void ScrollLayerCommand_Execute(int layerNumber, int expectedCurrentLayerIndex, params int[] scrollingValues)
203+
{
204+
//Arrange
205+
var keyboardLayout = CreateLayers(layerNumber);
206+
153207
var layoutTemplate = new List<KeyTemplate>();
154208

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

223+
foreach (var scrollingValue in scrollingValues)
224+
{
225+
displayLayoutViewModel.ScrollLayerCommand.Execute(new MouseWheelEventArgs(Mouse.PrimaryDevice, 0, scrollingValue));
226+
}
227+
169228
//Assert
170-
Assert.Equal(expectedCanExecute, displayLayoutViewModel.NextLayerCommand.CanExecute(null));
229+
Assert.Equal(expectedCurrentLayerIndex, displayLayoutViewModel.CurrentLayerIndex);
171230
}
172231

173232
[ Theory ]
@@ -184,13 +243,7 @@ [ InlineData(3, 3, 0) ]
184243
public void NextLayerCommand_Execute(int layerNumber, int nextLayerHit, int expectedCurrentLayerIndex)
185244
{
186245
//Arrange
187-
var keyboardLayout = new EZLayout();
188-
189-
for (int i = 0 ; i < layerNumber ; i++)
190-
{
191-
keyboardLayout.EZLayers.Add(new EZLayer { Index = i, EZKeys = new List<EZKey> { new EZKey() } });
192-
}
193-
246+
var keyboardLayout = CreateLayers(layerNumber);
194247
var layoutTemplate = new List<KeyTemplate>();
195248

196249
for (int i = 0 ; i < 1 ; i++)
@@ -223,8 +276,7 @@ public void NoLayoutAvailable()
223276
var mockLayoutService = new Mock<ILayoutService>();
224277
var mockWindowService = new Mock<IWindowService>();
225278
var mockSettingsService = new Mock<ISettingsService>();
226-
mockSettingsService.SetupProperty(s => s.EZLayout,
227-
new EZLayout { EZLayers = new List<EZLayer>() });
279+
mockSettingsService.SetupProperty(s => s.EZLayout, CreateLayers(0));
228280

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

src/InvvardDev.EZLayoutDisplay.Tests/ViewModel/SettingsViewModelTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading.Tasks;
5-
using Castle.Components.DictionaryAdapter;
64
using InvvardDev.EZLayoutDisplay.Desktop.Model;
75
using InvvardDev.EZLayoutDisplay.Desktop.Service.Interface;
86
using InvvardDev.EZLayoutDisplay.Desktop.View;
@@ -300,7 +298,7 @@ public void OpenTagSearchCommandExecute_ArgumentNullException()
300298
var mockProcessService = new Mock<IProcessService>();
301299

302300
// Act
303-
var settingsViewModel = new SettingsViewModel(mockSettingsService.Object, mockWindowService.Object, mockLayoutService.Object, mockProcessService.Object);
301+
var _ = new SettingsViewModel(mockSettingsService.Object, mockWindowService.Object, mockLayoutService.Object, mockProcessService.Object);
304302

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

322320
// Act
323-
var settingsViewModel = new SettingsViewModel(mockSettingsService.Object, mockWindowService.Object, mockLayoutService.Object, mockProcessService.Object);
321+
var _settingsViewModel = new SettingsViewModel(mockSettingsService.Object, mockWindowService.Object, mockLayoutService.Object, mockProcessService.Object);
324322

325323
// Assert
326324
mockLayoutService.Verify();

0 commit comments

Comments
 (0)