2022-10-16 18:36:16 +01:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2022-08-26 18:01:50 +02:00
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class PowerAccentViewModel : Observable
|
|
|
|
|
{
|
|
|
|
|
private GeneralSettings GeneralSettingsConfig { get; set; }
|
|
|
|
|
|
|
|
|
|
private readonly PowerAccentSettings _powerAccentSettings;
|
|
|
|
|
|
|
|
|
|
private readonly ISettingsUtils _settingsUtils;
|
|
|
|
|
|
2022-10-16 18:36:16 +01:00
|
|
|
// These should be in the same order as the ComboBoxItems in PowerAccentPage.xaml
|
|
|
|
|
private readonly string[] _languageOptions =
|
|
|
|
|
{
|
|
|
|
|
"ALL",
|
|
|
|
|
"CUR",
|
|
|
|
|
"CZ",
|
|
|
|
|
"FR",
|
|
|
|
|
"DE",
|
|
|
|
|
"HU",
|
|
|
|
|
"IS",
|
|
|
|
|
"IT",
|
|
|
|
|
"MI",
|
|
|
|
|
"PI",
|
|
|
|
|
"PL",
|
|
|
|
|
"PT",
|
|
|
|
|
"RO",
|
|
|
|
|
"SK",
|
|
|
|
|
"SP",
|
|
|
|
|
"TK",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly string[] _toolbarOptions =
|
|
|
|
|
{
|
|
|
|
|
"Top center",
|
|
|
|
|
"Bottom center",
|
|
|
|
|
"Left",
|
|
|
|
|
"Right",
|
|
|
|
|
"Top right corner",
|
|
|
|
|
"Top left corner",
|
|
|
|
|
"Bottom right corner",
|
|
|
|
|
"Bottom left corner",
|
|
|
|
|
"Center",
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-26 18:01:50 +02:00
|
|
|
private Func<string, int> SendConfigMSG { get; }
|
|
|
|
|
|
|
|
|
|
public PowerAccentViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
|
|
|
|
{
|
|
|
|
|
// To obtain the general settings configurations of PowerToys Settings.
|
|
|
|
|
if (settingsRepository == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(settingsRepository));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
|
|
|
|
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
|
|
|
|
|
|
|
|
|
_isEnabled = GeneralSettingsConfig.Enabled.PowerAccent;
|
|
|
|
|
if (_settingsUtils.SettingsExists(PowerAccentSettings.ModuleName))
|
|
|
|
|
{
|
|
|
|
|
_powerAccentSettings = _settingsUtils.GetSettingsOrDefault<PowerAccentSettings>(PowerAccentSettings.ModuleName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_powerAccentSettings = new PowerAccentSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 16:56:19 +01:00
|
|
|
_inputTimeMs = _powerAccentSettings.Properties.InputTime.Value;
|
|
|
|
|
|
2022-10-16 18:36:16 +01:00
|
|
|
_selectedLangIndex = Array.IndexOf(_languageOptions, _powerAccentSettings.Properties.SelectedLang.Value);
|
2022-08-26 18:01:50 +02:00
|
|
|
|
2022-10-16 18:36:16 +01:00
|
|
|
_toolbarPositionIndex = Array.IndexOf(_toolbarOptions, _powerAccentSettings.Properties.ToolbarPosition.Value);
|
2022-09-29 16:28:14 +02:00
|
|
|
|
2022-08-26 18:01:50 +02:00
|
|
|
// set the callback functions value to hangle outgoing IPC message.
|
|
|
|
|
SendConfigMSG = ipcMSGCallBackFunc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsEnabled
|
|
|
|
|
{
|
|
|
|
|
get => _isEnabled;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_isEnabled != value)
|
|
|
|
|
{
|
|
|
|
|
_isEnabled = value;
|
|
|
|
|
|
|
|
|
|
GeneralSettingsConfig.Enabled.PowerAccent = value;
|
|
|
|
|
OnPropertyChanged(nameof(IsEnabled));
|
|
|
|
|
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
|
|
|
|
SendConfigMSG(outgoing.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int ActivationKey
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (int)_powerAccentSettings.Properties.ActivationKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != (int)_powerAccentSettings.Properties.ActivationKey)
|
|
|
|
|
{
|
|
|
|
|
_powerAccentSettings.Properties.ActivationKey = (PowerAccentActivationKey)value;
|
|
|
|
|
OnPropertyChanged(nameof(ActivationKey));
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 16:56:19 +01:00
|
|
|
private int _inputTimeMs = 200;
|
|
|
|
|
|
|
|
|
|
public int InputTimeMs
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _inputTimeMs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _inputTimeMs)
|
|
|
|
|
{
|
|
|
|
|
_inputTimeMs = value;
|
|
|
|
|
_powerAccentSettings.Properties.InputTime.Value = value;
|
|
|
|
|
OnPropertyChanged(nameof(InputTimeMs));
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 18:01:50 +02:00
|
|
|
private int _toolbarPositionIndex;
|
|
|
|
|
|
|
|
|
|
public int ToolbarPositionIndex
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _toolbarPositionIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_toolbarPositionIndex != value)
|
|
|
|
|
{
|
|
|
|
|
_toolbarPositionIndex = value;
|
2022-10-16 18:36:16 +01:00
|
|
|
_powerAccentSettings.Properties.ToolbarPosition.Value = _toolbarOptions[value];
|
2022-08-26 18:01:50 +02:00
|
|
|
RaisePropertyChanged(nameof(ToolbarPositionIndex));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 16:28:14 +02:00
|
|
|
private int _selectedLangIndex;
|
|
|
|
|
|
|
|
|
|
public int SelectedLangIndex
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _selectedLangIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_selectedLangIndex != value)
|
|
|
|
|
{
|
|
|
|
|
_selectedLangIndex = value;
|
2022-10-16 18:36:16 +01:00
|
|
|
_powerAccentSettings.Properties.SelectedLang.Value = _languageOptions[value];
|
2022-09-29 16:28:14 +02:00
|
|
|
RaisePropertyChanged(nameof(SelectedLangIndex));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 18:01:50 +02:00
|
|
|
private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
// Notify UI of property change
|
|
|
|
|
OnPropertyChanged(propertyName);
|
|
|
|
|
|
|
|
|
|
if (SendConfigMSG != null)
|
|
|
|
|
{
|
|
|
|
|
SndPowerAccentSettings snd = new SndPowerAccentSettings(_powerAccentSettings);
|
|
|
|
|
SndModuleSettings<SndPowerAccentSettings> ipcMessage = new SndModuleSettings<SndPowerAccentSettings>(snd);
|
|
|
|
|
SendConfigMSG(ipcMessage.ToJsonString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _isEnabled;
|
|
|
|
|
}
|
|
|
|
|
}
|