From cef37677f24d7947f899e04295c2365c650afa8d Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 3 Jun 2021 11:10:07 +0200 Subject: [PATCH] Devices - Added option to disable default layouts --- .../Models/Surface/ArtemisDevice.cs | 22 ++++++++++ src/Artemis.Core/Services/RgbService.cs | 17 +++++--- .../Entities/Surface/DeviceEntity.cs | 1 + .../Behaviors/OpenInBrowser.cs | 41 +++++++++++++++++++ .../Device/Tabs/DevicePropertiesTabView.xaml | 34 +++++++++++++-- .../Tabs/DevicePropertiesTabViewModel.cs | 12 +++++- 6 files changed, 117 insertions(+), 10 deletions(-) create mode 100644 src/Artemis.UI.Shared/Behaviors/OpenInBrowser.cs diff --git a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs index 7f4e8dc3d..9dec7f4bc 100644 --- a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs +++ b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs @@ -33,6 +33,8 @@ namespace Artemis.Core BlueScale = 1; IsEnabled = true; + LedIds = new ReadOnlyDictionary(new Dictionary()); + Leds = new ReadOnlyCollection(new List()); InputIdentifiers = new List(); InputMappings = new Dictionary(); Categories = new HashSet(); @@ -51,6 +53,8 @@ namespace Artemis.Core RgbDevice = rgbDevice; DeviceProvider = deviceProvider; + LedIds = new ReadOnlyDictionary(new Dictionary()); + Leds = new ReadOnlyCollection(new List()); InputIdentifiers = new List(); InputMappings = new Dictionary(); Categories = new HashSet(); @@ -258,6 +262,19 @@ namespace Artemis.Core } } + /// + /// Gets or sets a boolean indicating whether falling back to default layouts is enabled or not + /// + public bool DisableDefaultLayout + { + get => DeviceEntity.DisableDefaultLayout; + set + { + DeviceEntity.DisableDefaultLayout = value; + OnPropertyChanged(nameof(DisableDefaultLayout)); + } + } + /// /// Gets or sets the logical layout of the device e.g. DE, UK or US. /// Only applicable to keyboards @@ -532,6 +549,11 @@ namespace Artemis.Core else LogicalLayout = DeviceEntity.LogicalLayout; } + + public void ClearLayout() + { + // TODO + } } /// diff --git a/src/Artemis.Core/Services/RgbService.cs b/src/Artemis.Core/Services/RgbService.cs index ae1ea1fc9..e65b74b4b 100644 --- a/src/Artemis.Core/Services/RgbService.cs +++ b/src/Artemis.Core/Services/RgbService.cs @@ -354,19 +354,26 @@ namespace Artemis.Core.Services } // Finally fall back to a default layout - layout = ArtemisLayout.GetDefaultLayout(device); - if (layout != null) - ApplyDeviceLayout(device, layout); + if (!device.DisableDefaultLayout) + layout = ArtemisLayout.GetDefaultLayout(device); + ApplyDeviceLayout(device, layout); return layout; } - public void ApplyDeviceLayout(ArtemisDevice device, ArtemisLayout layout) + public void ApplyDeviceLayout(ArtemisDevice device, ArtemisLayout? layout) { + if (layout == null) + { + if (device.Layout != null) + device.ClearLayout(); + return; + } + if (layout.Source == LayoutSource.Default) device.ApplyLayout(layout, false, false); else device.ApplyLayout(layout, device.DeviceProvider.CreateMissingLedsSupported, device.DeviceProvider.RemoveExcessiveLedsSupported); - + UpdateLedGroup(); } diff --git a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs index ecacd69dd..6cce72dcc 100644 --- a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs +++ b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs @@ -22,6 +22,7 @@ namespace Artemis.Storage.Entities.Surface public float BlueScale { get; set; } public bool IsEnabled { get; set; } + public bool DisableDefaultLayout { get; set; } public int PhysicalLayout { get; set; } public string LogicalLayout { get; set; } public string CustomLayoutPath { get; set; } diff --git a/src/Artemis.UI.Shared/Behaviors/OpenInBrowser.cs b/src/Artemis.UI.Shared/Behaviors/OpenInBrowser.cs new file mode 100644 index 000000000..e9c980033 --- /dev/null +++ b/src/Artemis.UI.Shared/Behaviors/OpenInBrowser.cs @@ -0,0 +1,41 @@ +using System.Windows.Documents; +using System.Windows.Navigation; +using Artemis.Core; +using Microsoft.Xaml.Behaviors; + +namespace Artemis.UI.Shared +{ + /// + /// Represents a behavior that opens the URI of the hyperlink in the browser when requested + /// + public class OpenInBrowser : Behavior + { + private Hyperlink? _hyperLink; + + /// + protected override void OnAttached() + { + base.OnAttached(); + + _hyperLink = AssociatedObject; + if (_hyperLink == null) + return; + + _hyperLink.RequestNavigate += HyperLinkOnRequestNavigate; + } + + /// + protected override void OnDetaching() + { + if (_hyperLink == null) return; + _hyperLink.RequestNavigate -= HyperLinkOnRequestNavigate; + + base.OnDetaching(); + } + + private void HyperLinkOnRequestNavigate(object sender, RequestNavigateEventArgs e) + { + Utilities.OpenUrl(e.Uri.AbsoluteUri); + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabView.xaml b/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabView.xaml index 890f730ee..344e87fee 100644 --- a/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabView.xaml +++ b/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabView.xaml @@ -7,6 +7,7 @@ xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:s="https://github.com/canton7/Stylet" + xmlns:b="http://schemas.microsoft.com/xaml/behaviors" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:DevicePropertiesTabViewModel}"> @@ -29,7 +30,7 @@ Foreground="{DynamicResource MaterialDesignBodyLight}" TextWrapping="Wrap" TextAlignment="Justify"> - Artemis uses categories to determine where the layers of imported profiles are applied to. + Artemis uses categories to determine where the layers of imported profiles are applied to. You can hover over a category for a more detailed description. @@ -192,15 +193,25 @@ - Custom layout + Layout - Select a custom layout below if you want to change the appearance and/or LEDs of this device. + The device layout is used to determine the position of LEDs and to create the visual representation of the device you see on the left side of this window. + + + + Use default layout if needed + + + + + - Layout path + Custom layout path + + Select a custom layout below if you want to change the appearance and/or LEDs of this device. + For info on how to create layouts, check out + + this wiki article + + + + + . + diff --git a/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabViewModel.cs b/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabViewModel.cs index 6189a6972..4af2c8313 100644 --- a/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabViewModel.cs @@ -134,6 +134,16 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs set => SetCategory(DeviceCategory.Peripherals, value); } + public bool UseDefaultLayout + { + get => !Device.DisableDefaultLayout; + set + { + Device.DisableDefaultLayout = !value; + NotifyOfPropertyChange(nameof(UseDefaultLayout)); + } + } + public void ApplyScaling() { Device.RedScale = RedScale / 100f; @@ -255,7 +265,7 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs private void DeviceOnPropertyChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == nameof(Device.CustomLayoutPath)) + if (e.PropertyName == nameof(Device.CustomLayoutPath) || e.PropertyName == nameof(Device.DisableDefaultLayout)) _rgbService.ApplyBestDeviceLayout(Device); }