Skip to content
This repository was archived by the owner on Nov 25, 2023. It is now read-only.
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
23 changes: 15 additions & 8 deletions src/InvvardDev.EZLayoutDisplay.Desktop/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,33 @@
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:ignore="http://www.galasoft.ch/ignore"
xmlns:viewModel="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.ViewModel"
xmlns:converter="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.View.Converter"
ShutdownMode="OnExplicitShutdown"
xmlns:ignore="http://www.galasoft.ch/ignore"
xmlns:viewModel="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.ViewModel"
xmlns:converter="clr-namespace:InvvardDev.EZLayoutDisplay.Desktop.View.Converter"
ShutdownMode="OnExplicitShutdown"
StartupUri="View/MainWindow.xaml"
mc:Ignorable="d ignore">

<Application.Resources>
<ResourceDictionary>
<!--Global View Model Locator-->
<viewModel:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
<converter:KeyCodeToCharConverter x:Key="KeyCodeConverter" />

<BitmapImage x:Key="WindowIcon" UriSource="Skins/Images/tray_base.ico" />
<BitmapImage x:Key="TrayIcon" UriSource="Skins/Images/tray_base.ico" />
<SolidColorBrush x:Key="WindowBackgroundBrush" Color="WhiteSmoke"/>

<SolidColorBrush x:Key="WindowBackgroundBrush" Color="WhiteSmoke" />

<converter:KeyCodeToCharConverter x:Key="KeyCodeConverter" />
<converter:BoolToVisibilityConverter x:Key="BoolToHiddenConverter"
TrueValue="Visible" FalseValue="Hidden" />
<converter:BoolToVisibilityConverter x:Key="BoolToVisibleConverter"
TrueValue="Hidden" FalseValue="Visible" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Skins/KeyboardLayoutSkin.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

</Application.Resources>
</Application>

</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<Compile Include="View\AboutWindow.xaml.cs">
<DependentUpon>AboutWindow.xaml</DependentUpon>
</Compile>
<Compile Include="View\Converter\BoolToVisibilityConverter.cs" />
<Compile Include="View\Converter\KeyCodeToCharConverter.cs" />
<Compile Include="View\SettingsWindow.xaml.cs">
<DependentUpon>SettingsWindow.xaml</DependentUpon>
Expand Down Expand Up @@ -249,6 +250,9 @@
<Resource Include="Skins\Images\github-logo.png" />
<Resource Include="Skins\Images\twitter-logo.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Skins\Images\warning-sign.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace InvvardDev.EZLayoutDisplay.Desktop.View.Converter
{
[ ValueConversion(typeof(bool), typeof(Visibility)) ]
public sealed class BoolToVisibilityConverter : IValueConverter
{
public Visibility TrueValue { get; set; }
public Visibility FalseValue { get; set; }

public BoolToVisibilityConverter()
{
// set defaults
TrueValue = Visibility.Visible;
FalseValue = Visibility.Collapsed;
}

public object Convert(object value,
Type targetType,
object parameter,
CultureInfo culture)
{
if (!(value is bool)) return null;

return (bool) value ? TrueValue : FalseValue;
}

public object ConvertBack(object value,
Type targetType,
object parameter,
CultureInfo culture)
{
if (Equals(value, TrueValue)) return true;
if (Equals(value, FalseValue)) return false;

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
xmlns:command="http://www.galasoft.ch/mvvmlight"
x:Class="InvvardDev.EZLayoutDisplay.Desktop.View.DisplayLayoutWindow"
mc:Ignorable="d" Height="423" Width="1075"
WindowStartupLocation="CenterScreen" Topmost="True"
WindowStartupLocation="CenterScreen" Topmost="{Binding IsTopMost}"
ResizeMode="NoResize" Visibility="Visible" ShowInTaskbar="True"
WindowStyle="None" Background="{StaticResource WindowBackgroundBrush}"
WindowStyle="None" Background="{StaticResource WindowBackgroundBrush}"
Title="{Binding WindowTitle}" Icon="{StaticResource WindowIcon}"
DataContext="{Binding DisplayLayout, Source={StaticResource Locator}}">

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

<ItemsControl ItemsSource="{Binding CurrentLayoutTemplate}"
ItemTemplateSelector="{StaticResource KeyContentTemplateSelector}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Margin="10" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<Grid>
<ItemsControl ItemsSource="{Binding CurrentLayoutTemplate}"
ItemTemplateSelector="{StaticResource KeyContentTemplateSelector}"
Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToVisibleConverter}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Margin="10" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<Grid Visibility="{Binding NoLayoutAvailable, Converter={StaticResource BoolToHiddenConverter}}" Width="350">
<Grid.ColumnDefinitions>
<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="No layout available !"/>
<LineBreak/>
<Run Text="Please, go to the settings and update the layout."/>
</TextBlock>
</Grid>
</Grid>

</Window>
13 changes: 8 additions & 5 deletions src/InvvardDev.EZLayoutDisplay.Desktop/View/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
<TextBox TextWrapping="NoWrap"
Text="{Binding LayoutUrlContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1"
Grid.Row="0" Margin="5,5,0,5" Grid.ColumnSpan="2" />
<Button Content="{Binding CancelCommandLabel}" HorizontalAlignment="Left" Width="75" d:LayoutOverrides="Height"
Grid.Row="1" Command="{Binding CancelSettingsCommand, Mode=OneWay}" />
<Button Content="{Binding ApplyCommandLabel}" Width="75" d:LayoutOverrides="Height" Grid.Row="1"
<Button Content="{Binding CancelCommandLabel}" HorizontalAlignment="Left" Width="75"
Grid.Row="1" Command="{Binding CancelSettingsCommand}" />
<Button Content="{Binding UpdateCommandLabel}" Width="75" Grid.Row="1"
Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,85,0"
Command="{Binding UpdateLayoutCommand}" />
<Button Content="{Binding ApplyCommandLabel}" Width="75" Grid.Row="1"
Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,5,0"
Command="{Binding ApplySettingsCommand, Mode=OneWay}" />
<Button Content="{Binding CloseCommandLabel}" Command="{Binding CloseSettingsCommand, Mode=OneWay}" Width="75"
Command="{Binding ApplySettingsCommand}" />
<Button Content="{Binding CloseCommandLabel}" Command="{Binding CloseSettingsCommand}" Width="75"
HorizontalAlignment="Right" Grid.Row="1" Grid.Column="2" Margin="5,0,0,0" />

</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class DisplayLayoutViewModel : ViewModelBase
private EZLayout _ezLayout;

private string _windowTitle;
private bool _noLayoutAvailable;

#endregion

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

/// <summary>
/// Gets or sets the no layout available indicator.
/// </summary>
public bool NoLayoutAvailable
{
get => _noLayoutAvailable;
set => Set(ref _noLayoutAvailable, value);
}

/// <summary>
/// Gets or sets the layout template.
/// </summary>
Expand Down Expand Up @@ -123,21 +133,24 @@ private async void LoadCompleteLayout()

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

if (IsInDesignModeStatic // in DesignMode, everything is already set
|| _ezLayout?.EZLayers == null
if (_ezLayout?.EZLayers == null
|| !_ezLayout.EZLayers.Any()
|| !_ezLayout.EZLayers.SelectMany(l => l.EZKeys).Any())
{
NoLayoutAvailable = true;
return;
}

NoLayoutAvailable = false;
await PopulateLayoutTemplates();

SwitchLayer();
}

private void LoadDesignTimeModel()
{
NoLayoutAvailable = true;

var json = Encoding.Default.GetString(Resources.layoutDefinition);
var layoutDefinition = JsonConvert.DeserializeObject<IEnumerable<KeyTemplate>>(json) as List<KeyTemplate>;

Expand All @@ -152,10 +165,16 @@ private void LoadDesignTimeModel()
KeyCategory = KeyCategory.DualFunction
};

for (int i = 1 ; i < CurrentLayoutTemplate.Count ; i++)
CurrentLayoutTemplate[1].EZKey = new EZKey {
Label = new KeyLabel("LT \u2192 1"),
DisplayType = KeyDisplayType.SimpleLabel,
KeyCategory = KeyCategory.DualFunction
};

for (int i = 2 ; i < CurrentLayoutTemplate.Count ; i++)
{
CurrentLayoutTemplate[i].EZKey = new EZKey {
Label = new KeyLabel("A \u2192"),
Label = new KeyLabel("E"),
Modifier = new KeyLabel("Left Shift")
};
}
Expand Down Expand Up @@ -191,6 +210,7 @@ private void SwitchLayer()
}
}


#region Delegates

private void LoadCompleteLayout(UpdatedLayoutMessage obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class SettingsViewModel : ViewModelBase

private string _windowTitle;
private string _applyCommandLabel;
private string _updateCommandLabel;
private string _closeCommandLabel;
private string _cancelCommandLabel;
private string _layoutUrlLabel;
Expand Down Expand Up @@ -62,7 +63,7 @@ public class SettingsViewModel : ViewModelBase
/// </summary>
public ICommand UpdateLayoutCommand =>
_updateLayoutCommand
?? (_updateLayoutCommand = new RelayCommand(async () => await UpdateLayout()));
?? (_updateLayoutCommand = new RelayCommand(SaveSettings));

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

public string UpdateCommandLabel
{
get => _updateCommandLabel;
set => Set(ref _updateCommandLabel, value);
}

public string CloseCommandLabel
{
get => _closeCommandLabel;
Expand Down Expand Up @@ -170,6 +177,7 @@ private void SetLabelUi()
WindowTitle = "Settings";
LayoutUrlLabel = "Configurator URL to your layout :";
ApplyCommandLabel = "Apply";
UpdateCommandLabel = "Update";
CloseCommandLabel = "Close";
CancelCommandLabel = "Cancel";
HotkeyTitleLabel = "Hotkey to display layout";
Expand Down