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

Commit f165ea2

Browse files
authored
Merge pull request #32 from Invvard/feature/no-layout-loaded-mode
Feature/no layout loaded mode
2 parents 3607477 + 701ee0d commit f165ea2

File tree

8 files changed

+129
-28
lines changed

8 files changed

+129
-28
lines changed

src/InvvardDev.EZLayoutDisplay.Desktop/App.xaml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,33 @@
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:ignore="http://www.galasoft.ch/ignore"
7-
xmlns:viewModel="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.ViewModel"
8-
xmlns:converter="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.View.Converter"
9-
ShutdownMode="OnExplicitShutdown"
6+
xmlns:ignore="http://www.galasoft.ch/ignore"
7+
xmlns:viewModel="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.ViewModel"
8+
xmlns:converter="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.View.Converter"
9+
ShutdownMode="OnExplicitShutdown"
1010
StartupUri="View/MainWindow.xaml"
1111
mc:Ignorable="d ignore">
1212

1313
<Application.Resources>
1414
<ResourceDictionary>
1515
<!--Global View Model Locator-->
1616
<viewModel:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
17-
<converter:KeyCodeToCharConverter x:Key="KeyCodeConverter" />
17+
1818
<BitmapImage x:Key="WindowIcon" UriSource="Skins/Images/tray_base.ico" />
1919
<BitmapImage x:Key="TrayIcon" UriSource="Skins/Images/tray_base.ico" />
20-
<SolidColorBrush x:Key="WindowBackgroundBrush" Color="WhiteSmoke"/>
20+
21+
<SolidColorBrush x:Key="WindowBackgroundBrush" Color="WhiteSmoke" />
22+
23+
<converter:KeyCodeToCharConverter x:Key="KeyCodeConverter" />
24+
<converter:BoolToVisibilityConverter x:Key="BoolToHiddenConverter"
25+
TrueValue="Visible" FalseValue="Hidden" />
26+
<converter:BoolToVisibilityConverter x:Key="BoolToVisibleConverter"
27+
TrueValue="Hidden" FalseValue="Visible" />
2128
<ResourceDictionary.MergedDictionaries>
2229
<ResourceDictionary Source="Skins/KeyboardLayoutSkin.xaml" />
2330
</ResourceDictionary.MergedDictionaries>
2431
</ResourceDictionary>
2532

2633
</Application.Resources>
27-
28-
</Application>
34+
35+
</Application>

src/InvvardDev.EZLayoutDisplay.Desktop/InvvardDev.EZLayoutDisplay.Desktop.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<Compile Include="View\AboutWindow.xaml.cs">
153153
<DependentUpon>AboutWindow.xaml</DependentUpon>
154154
</Compile>
155+
<Compile Include="View\Converter\BoolToVisibilityConverter.cs" />
155156
<Compile Include="View\Converter\KeyCodeToCharConverter.cs" />
156157
<Compile Include="View\SettingsWindow.xaml.cs">
157158
<DependentUpon>SettingsWindow.xaml</DependentUpon>
@@ -249,6 +250,9 @@
249250
<Resource Include="Skins\Images\github-logo.png" />
250251
<Resource Include="Skins\Images\twitter-logo.png" />
251252
</ItemGroup>
253+
<ItemGroup>
254+
<Resource Include="Skins\Images\warning-sign.png" />
255+
</ItemGroup>
252256
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
253257
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
254258
Other similar extension points exist, see Microsoft.Common.targets.
24.5 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace InvvardDev.EZLayoutDisplay.Desktop.View.Converter
7+
{
8+
[ ValueConversion(typeof(bool), typeof(Visibility)) ]
9+
public sealed class BoolToVisibilityConverter : IValueConverter
10+
{
11+
public Visibility TrueValue { get; set; }
12+
public Visibility FalseValue { get; set; }
13+
14+
public BoolToVisibilityConverter()
15+
{
16+
// set defaults
17+
TrueValue = Visibility.Visible;
18+
FalseValue = Visibility.Collapsed;
19+
}
20+
21+
public object Convert(object value,
22+
Type targetType,
23+
object parameter,
24+
CultureInfo culture)
25+
{
26+
if (!(value is bool)) return null;
27+
28+
return (bool) value ? TrueValue : FalseValue;
29+
}
30+
31+
public object ConvertBack(object value,
32+
Type targetType,
33+
object parameter,
34+
CultureInfo culture)
35+
{
36+
if (Equals(value, TrueValue)) return true;
37+
if (Equals(value, FalseValue)) return false;
38+
39+
return null;
40+
}
41+
}
42+
}

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
xmlns:command="http://www.galasoft.ch/mvvmlight"
88
x:Class="InvvardDev.EZLayoutDisplay.Desktop.View.DisplayLayoutWindow"
99
mc:Ignorable="d" Height="423" Width="1075"
10-
WindowStartupLocation="CenterScreen" Topmost="True"
10+
WindowStartupLocation="CenterScreen" Topmost="{Binding IsTopMost}"
1111
ResizeMode="NoResize" Visibility="Visible" ShowInTaskbar="True"
12-
WindowStyle="None" Background="{StaticResource WindowBackgroundBrush}"
12+
WindowStyle="None" Background="{StaticResource WindowBackgroundBrush}"
1313
Title="{Binding WindowTitle}" Icon="{StaticResource WindowIcon}"
1414
DataContext="{Binding DisplayLayout, Source={StaticResource Locator}}">
1515

@@ -23,12 +23,29 @@
2323
<KeyBinding Key="Space" Command="{Binding NextLayerCommand, Mode=OneWay}" />
2424
</Window.InputBindings>
2525

26-
<ItemsControl ItemsSource="{Binding CurrentLayoutTemplate}"
27-
ItemTemplateSelector="{StaticResource KeyContentTemplateSelector}">
28-
<ItemsControl.ItemsPanel>
29-
<ItemsPanelTemplate>
30-
<Canvas Margin="10" />
31-
</ItemsPanelTemplate>
32-
</ItemsControl.ItemsPanel>
33-
</ItemsControl>
26+
<Grid>
27+
<ItemsControl ItemsSource="{Binding CurrentLayoutTemplate}"
28+
ItemTemplateSelector="{StaticResource KeyContentTemplateSelector}"
29+
Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToVisibleConverter}}">
30+
<ItemsControl.ItemsPanel>
31+
<ItemsPanelTemplate>
32+
<Canvas Margin="10" />
33+
</ItemsPanelTemplate>
34+
</ItemsControl.ItemsPanel>
35+
</ItemsControl>
36+
<Grid Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToHiddenConverter}}" Width="350">
37+
<Grid.ColumnDefinitions>
38+
<ColumnDefinition Width=".25*"/>
39+
<ColumnDefinition Width="10"/>
40+
<ColumnDefinition/>
41+
</Grid.ColumnDefinitions>
42+
<Image Grid.Column="0" Source="../Skins/Images/warning-sign.png"/>
43+
<TextBlock Grid.Column="2" TextWrapping="WrapWithOverflow" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left">
44+
<Run Text="No layout available !"/>
45+
<LineBreak/>
46+
<Run Text="Please, go to the settings and update the layout."/>
47+
</TextBlock>
48+
</Grid>
49+
</Grid>
50+
3451
</Window>

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525
<TextBox TextWrapping="NoWrap"
2626
Text="{Binding LayoutUrlContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1"
2727
Grid.Row="0" Margin="5,5,0,5" Grid.ColumnSpan="2" />
28-
<Button Content="{Binding CancelCommandLabel}" HorizontalAlignment="Left" Width="75" d:LayoutOverrides="Height"
29-
Grid.Row="1" Command="{Binding CancelSettingsCommand, Mode=OneWay}" />
30-
<Button Content="{Binding ApplyCommandLabel}" Width="75" d:LayoutOverrides="Height" Grid.Row="1"
28+
<Button Content="{Binding CancelCommandLabel}" HorizontalAlignment="Left" Width="75"
29+
Grid.Row="1" Command="{Binding CancelSettingsCommand}" />
30+
<Button Content="{Binding UpdateCommandLabel}" Width="75" Grid.Row="1"
31+
Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,85,0"
32+
Command="{Binding UpdateLayoutCommand}" />
33+
<Button Content="{Binding ApplyCommandLabel}" Width="75" Grid.Row="1"
3134
Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,5,0"
32-
Command="{Binding ApplySettingsCommand, Mode=OneWay}" />
33-
<Button Content="{Binding CloseCommandLabel}" Command="{Binding CloseSettingsCommand, Mode=OneWay}" Width="75"
35+
Command="{Binding ApplySettingsCommand}" />
36+
<Button Content="{Binding CloseCommandLabel}" Command="{Binding CloseSettingsCommand}" Width="75"
3437
HorizontalAlignment="Right" Grid.Row="1" Grid.Column="2" Margin="5,0,0,0" />
3538

3639
</Grid>

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class DisplayLayoutViewModel : ViewModelBase
3535
private EZLayout _ezLayout;
3636

3737
private string _windowTitle;
38+
private bool _noLayoutAvailable;
3839

3940
#endregion
4041

@@ -49,6 +50,15 @@ public string WindowTitle
4950
set => Set(ref _windowTitle, value);
5051
}
5152

53+
/// <summary>
54+
/// Gets or sets the no layout available indicator.
55+
/// </summary>
56+
public bool NoLayoutAvailable
57+
{
58+
get => _noLayoutAvailable;
59+
set => Set(ref _noLayoutAvailable, value);
60+
}
61+
5262
/// <summary>
5363
/// Gets or sets the layout template.
5464
/// </summary>
@@ -123,21 +133,24 @@ private async void LoadCompleteLayout()
123133

124134
_layoutTemplates = new List<List<KeyTemplate>>();
125135

126-
if (IsInDesignModeStatic // in DesignMode, everything is already set
127-
|| _ezLayout?.EZLayers == null
136+
if (_ezLayout?.EZLayers == null
128137
|| !_ezLayout.EZLayers.Any()
129138
|| !_ezLayout.EZLayers.SelectMany(l => l.EZKeys).Any())
130139
{
140+
NoLayoutAvailable = true;
131141
return;
132142
}
133143

144+
NoLayoutAvailable = false;
134145
await PopulateLayoutTemplates();
135146

136147
SwitchLayer();
137148
}
138149

139150
private void LoadDesignTimeModel()
140151
{
152+
NoLayoutAvailable = true;
153+
141154
var json = Encoding.Default.GetString(Resources.layoutDefinition);
142155
var layoutDefinition = JsonConvert.DeserializeObject<IEnumerable<KeyTemplate>>(json) as List<KeyTemplate>;
143156

@@ -152,10 +165,16 @@ private void LoadDesignTimeModel()
152165
KeyCategory = KeyCategory.DualFunction
153166
};
154167

155-
for (int i = 1 ; i < CurrentLayoutTemplate.Count ; i++)
168+
CurrentLayoutTemplate[1].EZKey = new EZKey {
169+
Label = new KeyLabel("LT \u2192 1"),
170+
DisplayType = KeyDisplayType.SimpleLabel,
171+
KeyCategory = KeyCategory.DualFunction
172+
};
173+
174+
for (int i = 2 ; i < CurrentLayoutTemplate.Count ; i++)
156175
{
157176
CurrentLayoutTemplate[i].EZKey = new EZKey {
158-
Label = new KeyLabel("A \u2192"),
177+
Label = new KeyLabel("E"),
159178
Modifier = new KeyLabel("Left Shift")
160179
};
161180
}
@@ -191,6 +210,7 @@ private void SwitchLayer()
191210
}
192211
}
193212

213+
194214
#region Delegates
195215

196216
private void LoadCompleteLayout(UpdatedLayoutMessage obj)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class SettingsViewModel : ViewModelBase
2727

2828
private string _windowTitle;
2929
private string _applyCommandLabel;
30+
private string _updateCommandLabel;
3031
private string _closeCommandLabel;
3132
private string _cancelCommandLabel;
3233
private string _layoutUrlLabel;
@@ -62,7 +63,7 @@ public class SettingsViewModel : ViewModelBase
6263
/// </summary>
6364
public ICommand UpdateLayoutCommand =>
6465
_updateLayoutCommand
65-
?? (_updateLayoutCommand = new RelayCommand(async () => await UpdateLayout()));
66+
?? (_updateLayoutCommand = new RelayCommand(SaveSettings));
6667

6768
/// <summary>
6869
/// Closes the settings window.
@@ -87,6 +88,12 @@ public string ApplyCommandLabel
8788
set => Set(ref _applyCommandLabel, value);
8889
}
8990

91+
public string UpdateCommandLabel
92+
{
93+
get => _updateCommandLabel;
94+
set => Set(ref _updateCommandLabel, value);
95+
}
96+
9097
public string CloseCommandLabel
9198
{
9299
get => _closeCommandLabel;
@@ -170,6 +177,7 @@ private void SetLabelUi()
170177
WindowTitle = "Settings";
171178
LayoutUrlLabel = "Configurator URL to your layout :";
172179
ApplyCommandLabel = "Apply";
180+
UpdateCommandLabel = "Update";
173181
CloseCommandLabel = "Close";
174182
CancelCommandLabel = "Cancel";
175183
HotkeyTitleLabel = "Hotkey to display layout";

0 commit comments

Comments
 (0)