whitespace forced changes (#6002)

This commit is contained in:
Clint Rutkas
2020-08-17 10:00:56 -07:00
committed by GitHub
parent 649e7e103d
commit d055ba1c3b
129 changed files with 14175 additions and 14175 deletions

View File

@@ -1,27 +1,27 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class BoolPropertyJsonConverter : JsonConverter<bool>
{
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var boolProperty = JsonSerializer.Deserialize<BoolProperty>(ref reader, options);
return boolProperty.Value;
}
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
var boolProperty = new BoolProperty(value);
JsonSerializer.Serialize(writer, boolProperty, options);
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class BoolPropertyJsonConverter : JsonConverter<bool>
{
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var boolProperty = JsonSerializer.Deserialize<BoolProperty>(ref reader, options);
return boolProperty.Value;
}
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
var boolProperty = new BoolProperty(value);
JsonSerializer.Serialize(writer, boolProperty, options);
}
}
}

View File

@@ -1,17 +1,17 @@
// Copyright (c) Microsoft Corporation
// 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.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
{
public class CustomActionDataModel
{
[JsonPropertyName("action_name")]
public string Name { get; set; }
[JsonPropertyName("value")]
public string Value { get; set; }
}
}
// Copyright (c) Microsoft Corporation
// 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.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
{
public class CustomActionDataModel
{
[JsonPropertyName("action_name")]
public string Name { get; set; }
[JsonPropertyName("value")]
public string Value { get; set; }
}
}

View File

@@ -1,24 +1,24 @@
// Copyright (c) Microsoft Corporation
// 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.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
{
public class CustomNamePolicy : JsonNamingPolicy
{
private Func<string, string> convertDelegate;
public CustomNamePolicy(Func<string, string> convertDelegate)
{
this.convertDelegate = convertDelegate;
}
public override string ConvertName(string name)
{
return convertDelegate(name);
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
{
public class CustomNamePolicy : JsonNamingPolicy
{
private Func<string, string> convertDelegate;
public CustomNamePolicy(Func<string, string> convertDelegate)
{
this.convertDelegate = convertDelegate;
}
public override string ConvertName(string name)
{
return convertDelegate(name);
}
}
}

View File

@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
{
public class ModuleCustomAction
{
public CustomActionDataModel ModuleAction { get; set; }
}
}
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
{
public class ModuleCustomAction
{
public CustomActionDataModel ModuleAction { get; set; }
}
}

View File

@@ -1,35 +1,35 @@
// Copyright (c) Microsoft Corporation
// 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.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
{
public class SendCustomAction
{
private readonly string moduleName;
public SendCustomAction(string moduleName)
{
this.moduleName = moduleName;
}
[JsonPropertyName("action")]
public ModuleCustomAction Action { get; set; }
public string ToJsonString()
{
var jsonSerializerOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = new CustomNamePolicy((propertyName) =>
{
return propertyName.Equals("ModuleAction") ? moduleName : propertyName;
}),
};
return JsonSerializer.Serialize(this, jsonSerializerOptions);
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
{
public class SendCustomAction
{
private readonly string moduleName;
public SendCustomAction(string moduleName)
{
this.moduleName = moduleName;
}
[JsonPropertyName("action")]
public ModuleCustomAction Action { get; set; }
public string ToJsonString()
{
var jsonSerializerOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = new CustomNamePolicy((propertyName) =>
{
return propertyName.Equals("ModuleAction") ? moduleName : propertyName;
}),
};
return JsonSerializer.Serialize(this, jsonSerializerOptions);
}
}
}

View File

@@ -1,21 +1,21 @@
// Copyright (c) Microsoft Corporation
// 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.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.Telemetry;
using Microsoft.PowerToys.Telemetry;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class EnabledModules
{
public EnabledModules()
{
}
// Copyright (c) Microsoft Corporation
// 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.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.Telemetry;
using Microsoft.PowerToys.Telemetry;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class EnabledModules
{
public EnabledModules()
{
}
private bool fancyZones = true;
[JsonPropertyName("FancyZones")]
@@ -96,7 +96,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
}
private bool keyboardManager = true;
[JsonPropertyName("Keyboard Manager")]
public bool KeyboardManager
{
@@ -124,38 +124,38 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
LogTelemetryEvent(value);
this.powerLauncher = value;
}
}
}
}
private bool colorPicker = true;
[JsonPropertyName("ColorPicker")]
public bool ColorPicker
{
get => this.colorPicker;
set
{
if (this.colorPicker != value)
{
LogTelemetryEvent(value);
this.colorPicker = value;
}
}
public bool ColorPicker
{
get => this.colorPicker;
set
{
if (this.colorPicker != value)
{
LogTelemetryEvent(value);
this.colorPicker = value;
}
}
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
private void LogTelemetryEvent(bool value, [CallerMemberName] string moduleName = null)
{
var dataEvent = new SettingsEnabledEvent()
{
Value = value,
Name = moduleName,
};
PowerToysTelemetry.Log.WriteEvent(dataEvent);
}
}
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
private void LogTelemetryEvent(bool value, [CallerMemberName] string moduleName = null)
{
var dataEvent = new SettingsEnabledEvent()
{
Value = value,
Name = moduleName,
};
PowerToysTelemetry.Log.WriteEvent(dataEvent);
}
}
}

View File

@@ -1,111 +1,111 @@
// Copyright (c) Microsoft Corporation
// 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.Text;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class HotkeySettings
{
public HotkeySettings()
{
Win = false;
Ctrl = false;
Alt = false;
Shift = false;
Code = 0;
}
/// <summary>
/// Initializes a new instance of the <see cref="HotkeySettings"/> class.
/// </summary>
/// <param name="win">Should Windows key be used</param>
/// <param name="ctrl">Should Ctrl key be used</param>
/// <param name="alt">Should Alt key be used</param>
/// <param name="shift">Should Shift key be used</param>
/// <param name="code">Go to https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes to see list of v-keys</param>
public HotkeySettings(bool win, bool ctrl, bool alt, bool shift, int code)
{
Win = win;
Ctrl = ctrl;
Alt = alt;
Shift = shift;
Code = code;
}
public HotkeySettings Clone()
{
return new HotkeySettings(Win, Ctrl, Alt, Shift, Code);
}
[JsonPropertyName("win")]
public bool Win { get; set; }
[JsonPropertyName("ctrl")]
public bool Ctrl { get; set; }
[JsonPropertyName("alt")]
public bool Alt { get; set; }
[JsonPropertyName("shift")]
public bool Shift { get; set; }
[JsonPropertyName("code")]
public int Code { get; set; }
// This is currently needed for FancyZones, we need to unify these two objects
// see src\common\settings_objects.h
[JsonPropertyName("key")]
public string Key { get; set; } = string.Empty;
public override string ToString()
{
StringBuilder output = new StringBuilder();
if (Win)
{
output.Append("Win + ");
}
if (Ctrl)
{
output.Append("Ctrl + ");
}
if (Alt)
{
output.Append("Alt + ");
}
if (Shift)
{
output.Append("Shift + ");
}
if (Code > 0)
{
var localKey = Helper.GetKeyName((uint)Code);
output.Append(localKey);
}
else if (output.Length >= 2)
{
output.Remove(output.Length - 2, 2);
}
return output.ToString();
}
public bool IsValid()
{
return (Alt || Ctrl || Win || Shift) && Code != 0;
}
public bool IsEmpty()
{
return !Alt && !Ctrl && !Win && !Shift && Code == 0;
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Text;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class HotkeySettings
{
public HotkeySettings()
{
Win = false;
Ctrl = false;
Alt = false;
Shift = false;
Code = 0;
}
/// <summary>
/// Initializes a new instance of the <see cref="HotkeySettings"/> class.
/// </summary>
/// <param name="win">Should Windows key be used</param>
/// <param name="ctrl">Should Ctrl key be used</param>
/// <param name="alt">Should Alt key be used</param>
/// <param name="shift">Should Shift key be used</param>
/// <param name="code">Go to https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes to see list of v-keys</param>
public HotkeySettings(bool win, bool ctrl, bool alt, bool shift, int code)
{
Win = win;
Ctrl = ctrl;
Alt = alt;
Shift = shift;
Code = code;
}
public HotkeySettings Clone()
{
return new HotkeySettings(Win, Ctrl, Alt, Shift, Code);
}
[JsonPropertyName("win")]
public bool Win { get; set; }
[JsonPropertyName("ctrl")]
public bool Ctrl { get; set; }
[JsonPropertyName("alt")]
public bool Alt { get; set; }
[JsonPropertyName("shift")]
public bool Shift { get; set; }
[JsonPropertyName("code")]
public int Code { get; set; }
// This is currently needed for FancyZones, we need to unify these two objects
// see src\common\settings_objects.h
[JsonPropertyName("key")]
public string Key { get; set; } = string.Empty;
public override string ToString()
{
StringBuilder output = new StringBuilder();
if (Win)
{
output.Append("Win + ");
}
if (Ctrl)
{
output.Append("Ctrl + ");
}
if (Alt)
{
output.Append("Alt + ");
}
if (Shift)
{
output.Append("Shift + ");
}
if (Code > 0)
{
var localKey = Helper.GetKeyName((uint)Code);
output.Append(localKey);
}
else if (output.Length >= 2)
{
output.Remove(output.Length - 2, 2);
}
return output.ToString();
}
public bool IsValid()
{
return (Alt || Ctrl || Win || Shift) && Code != 0;
}
public bool IsEmpty()
{
return !Alt && !Ctrl && !Win && !Shift && Code == 0;
}
}
}

View File

@@ -1,24 +1,24 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class KeyboardManagerProfile
{
[JsonPropertyName("remapKeys")]
public RemapKeysDataModel RemapKeys { get; set; }
[JsonPropertyName("remapShortcuts")]
public ShortcutsKeyDataModel RemapShortcuts { get; set; }
public KeyboardManagerProfile()
{
RemapKeys = new RemapKeysDataModel();
RemapShortcuts = new ShortcutsKeyDataModel();
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class KeyboardManagerProfile
{
[JsonPropertyName("remapKeys")]
public RemapKeysDataModel RemapKeys { get; set; }
[JsonPropertyName("remapShortcuts")]
public ShortcutsKeyDataModel RemapShortcuts { get; set; }
public KeyboardManagerProfile()
{
RemapKeys = new RemapKeysDataModel();
RemapShortcuts = new ShortcutsKeyDataModel();
}
}
}

View File

@@ -1,31 +1,31 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class KeyboardManagerProperties
{
[JsonPropertyName("activeConfiguration")]
public GenericProperty<string> ActiveConfiguration { get; set; }
// List of all Keyboard Configurations.
[JsonPropertyName("keyboardConfigurations")]
public GenericProperty<List<string>> KeyboardConfigurations { get; set; }
public KeyboardManagerProperties()
{
KeyboardConfigurations = new GenericProperty<List<string>>(new List<string> { "default", });
ActiveConfiguration = new GenericProperty<string>("default");
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class KeyboardManagerProperties
{
[JsonPropertyName("activeConfiguration")]
public GenericProperty<string> ActiveConfiguration { get; set; }
// List of all Keyboard Configurations.
[JsonPropertyName("keyboardConfigurations")]
public GenericProperty<List<string>> KeyboardConfigurations { get; set; }
public KeyboardManagerProperties()
{
KeyboardConfigurations = new GenericProperty<List<string>>(new List<string> { "default", });
ActiveConfiguration = new GenericProperty<string>("default");
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -1,28 +1,28 @@
// Copyright (c) Microsoft Corporation
// 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.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class KeyboardManagerSettings : BasePTModuleSettings
{
[JsonPropertyName("properties")]
public KeyboardManagerProperties Properties { get; set; }
public KeyboardManagerSettings()
{
Properties = new KeyboardManagerProperties();
Version = "1";
Name = "_unset_";
}
public KeyboardManagerSettings(string ptName)
{
Properties = new KeyboardManagerProperties();
Version = "1";
Name = ptName;
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class KeyboardManagerSettings : BasePTModuleSettings
{
[JsonPropertyName("properties")]
public KeyboardManagerProperties Properties { get; set; }
public KeyboardManagerSettings()
{
Properties = new KeyboardManagerProperties();
Version = "1";
Name = "_unset_";
}
public KeyboardManagerSettings(string ptName)
{
Properties = new KeyboardManagerProperties();
Version = "1";
Name = ptName;
}
}
}

View File

@@ -1,39 +1,39 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class KeysDataModel
{
[JsonPropertyName("originalKeys")]
public string OriginalKeys { get; set; }
[JsonPropertyName("newRemapKeys")]
public string NewRemapKeys { get; set; }
private List<string> MapKeys(string stringOfKeys)
{
return stringOfKeys
.Split(';')
.Select(uint.Parse)
.Select(Helper.GetKeyName)
.ToList();
}
public List<string> GetOriginalKeys()
{
return MapKeys(OriginalKeys);
}
public List<string> GetNewRemapKeys()
{
return MapKeys(NewRemapKeys);
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class KeysDataModel
{
[JsonPropertyName("originalKeys")]
public string OriginalKeys { get; set; }
[JsonPropertyName("newRemapKeys")]
public string NewRemapKeys { get; set; }
private List<string> MapKeys(string stringOfKeys)
{
return stringOfKeys
.Split(';')
.Select(uint.Parse)
.Select(Helper.GetKeyName)
.ToList();
}
public List<string> GetOriginalKeys()
{
return MapKeys(OriginalKeys);
}
public List<string> GetNewRemapKeys()
{
return MapKeys(NewRemapKeys);
}
}
}

View File

@@ -1,35 +1,35 @@
// Copyright (c) Microsoft Corporation
// 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.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class PowerLauncherSettings : BasePTModuleSettings
{
public const string ModuleName = "PowerToys Run";
[JsonPropertyName("properties")]
public PowerLauncherProperties Properties { get; set; }
public PowerLauncherSettings()
{
Properties = new PowerLauncherProperties();
Version = "1";
Name = ModuleName;
}
public virtual void Save()
{
// Save settings to file
var options = new JsonSerializerOptions
{
WriteIndented = true,
};
SettingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class PowerLauncherSettings : BasePTModuleSettings
{
public const string ModuleName = "PowerToys Run";
[JsonPropertyName("properties")]
public PowerLauncherProperties Properties { get; set; }
public PowerLauncherSettings()
{
Properties = new PowerLauncherProperties();
Version = "1";
Name = ModuleName;
}
public virtual void Save()
{
// Save settings to file
var options = new JsonSerializerOptions
{
WriteIndented = true,
};
SettingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
}
}
}

View File

@@ -2,65 +2,65 @@
// 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.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.Telemetry;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Settings.Telemetry;
using Microsoft.PowerToys.Telemetry;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class PowerPreviewProperties
{
private bool enableSvgPreview = true;
[JsonPropertyName("svg-previewer-toggle-setting")]
[JsonConverter(typeof(BoolPropertyJsonConverter))]
public bool EnableSvgPreview
{
get => this.enableSvgPreview;
set
{
if (value != this.enableSvgPreview)
{
LogTelemetryEvent(value);
this.enableSvgPreview = value;
}
}
}
private bool enableSvgThumbnail = true;
[JsonPropertyName("svg-thumbnail-toggle-setting")]
[JsonConverter(typeof(BoolPropertyJsonConverter))]
public bool EnableSvgThumbnail
{
get => this.enableSvgThumbnail;
set
{
if (value != this.enableSvgThumbnail)
{
LogTelemetryEvent(value);
this.enableSvgThumbnail = value;
}
}
}
{
private bool enableSvgPreview = true;
[JsonPropertyName("svg-previewer-toggle-setting")]
[JsonConverter(typeof(BoolPropertyJsonConverter))]
public bool EnableSvgPreview
{
get => this.enableSvgPreview;
set
{
if (value != this.enableSvgPreview)
{
LogTelemetryEvent(value);
this.enableSvgPreview = value;
}
}
}
private bool enableSvgThumbnail = true;
[JsonPropertyName("svg-thumbnail-toggle-setting")]
[JsonConverter(typeof(BoolPropertyJsonConverter))]
public bool EnableSvgThumbnail
{
get => this.enableSvgThumbnail;
set
{
if (value != this.enableSvgThumbnail)
{
LogTelemetryEvent(value);
this.enableSvgThumbnail = value;
}
}
}
private bool enableMdPreview = true;
[JsonPropertyName("md-previewer-toggle-setting")]
[JsonConverter(typeof(BoolPropertyJsonConverter))]
public bool EnableMdPreview
{
get => this.enableMdPreview;
set
{
if (value != this.enableMdPreview)
{
LogTelemetryEvent(value);
this.enableMdPreview = value;
}
}
{
get => this.enableMdPreview;
set
{
if (value != this.enableMdPreview)
{
LogTelemetryEvent(value);
this.enableMdPreview = value;
}
}
}
public PowerPreviewProperties()

View File

@@ -1,20 +1,20 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class RemapKeysDataModel
{
[JsonPropertyName("inProcess")]
public List<KeysDataModel> InProcessRemapKeys { get; set; }
public RemapKeysDataModel()
{
InProcessRemapKeys = new List<KeysDataModel>();
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class RemapKeysDataModel
{
[JsonPropertyName("inProcess")]
public List<KeysDataModel> InProcessRemapKeys { get; set; }
public RemapKeysDataModel()
{
InProcessRemapKeys = new List<KeysDataModel>();
}
}
}

View File

@@ -1,24 +1,24 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ShortcutsKeyDataModel
{
[JsonPropertyName("global")]
public List<KeysDataModel> GlobalRemapShortcuts { get; set; }
[JsonPropertyName("appSpecific")]
public List<AppSpecificKeysDataModel> AppSpecificRemapShortcuts { get; set; }
public ShortcutsKeyDataModel()
{
GlobalRemapShortcuts = new List<KeysDataModel>();
AppSpecificRemapShortcuts = new List<AppSpecificKeysDataModel>();
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ShortcutsKeyDataModel
{
[JsonPropertyName("global")]
public List<KeysDataModel> GlobalRemapShortcuts { get; set; }
[JsonPropertyName("appSpecific")]
public List<AppSpecificKeysDataModel> AppSpecificRemapShortcuts { get; set; }
public ShortcutsKeyDataModel()
{
GlobalRemapShortcuts = new List<KeysDataModel>();
AppSpecificRemapShortcuts = new List<AppSpecificKeysDataModel>();
}
}
}

View File

@@ -1,25 +1,25 @@
// Copyright (c) Microsoft Corporation
// 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.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class SndKeyboardManagerSettings
{
[JsonPropertyName("Keyboard Manager")]
public KeyboardManagerSettings KeyboardManagerSettings { get; }
public SndKeyboardManagerSettings(KeyboardManagerSettings keyboardManagerSettings)
{
KeyboardManagerSettings = keyboardManagerSettings;
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class SndKeyboardManagerSettings
{
[JsonPropertyName("Keyboard Manager")]
public KeyboardManagerSettings KeyboardManagerSettings { get; }
public SndKeyboardManagerSettings(KeyboardManagerSettings keyboardManagerSettings)
{
KeyboardManagerSettings = keyboardManagerSettings;
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -1,18 +1,18 @@
// Copyright (c) Microsoft Corporation
// 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.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace Microsoft.PowerLauncher.Telemetry
{
[EventData]
public class SettingsBootEvent : EventBase, IEvent
{
public double BootTimeMs { get; set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
}
}
// Copyright (c) Microsoft Corporation
// 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.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace Microsoft.PowerLauncher.Telemetry
{
[EventData]
public class SettingsBootEvent : EventBase, IEvent
{
public double BootTimeMs { get; set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
}
}

View File

@@ -1,20 +1,20 @@
// Copyright (c) Microsoft Corporation
// 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.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace Microsoft.PowerToys.Settings.Telemetry
{
[EventData]
public class SettingsEnabledEvent : EventBase, IEvent
{
public string Name { get; set; }
public bool Value { get; set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
}
// Copyright (c) Microsoft Corporation
// 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.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace Microsoft.PowerToys.Settings.Telemetry
{
[EventData]
public class SettingsEnabledEvent : EventBase, IEvent
{
public string Name { get; set; }
public bool Value { get; set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
}

View File

@@ -1,123 +1,123 @@
// Copyright (c) Microsoft Corporation
// 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.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using Microsoft.PowerToys.Settings.UI.Lib.CustomAction;
namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
{
public class Helper
{
public static bool AllowRunnerToForeground()
{
var result = false;
var processes = Process.GetProcessesByName("PowerToys");
if (processes.Length > 0)
{
var pid = processes[0].Id;
result = AllowSetForegroundWindow(pid);
}
return result;
}
public static string GetSerializedCustomAction(string moduleName, string actionName, string actionValue)
{
var customAction = new CustomActionDataModel
{
Name = actionName,
Value = actionValue,
};
var moduleCustomAction = new ModuleCustomAction
{
ModuleAction = customAction,
};
var sendCustomAction = new SendCustomAction(moduleName);
sendCustomAction.Action = moduleCustomAction;
return sendCustomAction.ToJsonString();
}
public static FileSystemWatcher GetFileWatcher(string moduleName, string fileName, Action onChangedCallback)
{
var path = Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{moduleName}");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var watcher = new FileSystemWatcher();
watcher.Path = path;
watcher.Filter = fileName;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += (o, e) => onChangedCallback();
watcher.EnableRaisingEvents = true;
return watcher;
}
private static string LocalApplicationDataFolder()
{
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
[DllImport("user32.dll")]
private static extern bool AllowSetForegroundWindow(int dwProcessId);
private static interop.LayoutMapManaged layoutMap = new interop.LayoutMapManaged();
public static string GetKeyName(uint key)
{
return layoutMap.GetKeyName(key);
}
public static string GetProductVersion()
{
return interop.CommonManaged.GetProductVersion();
}
public static int CompareVersions(string version1, string version2)
{
try
{
// Split up the version strings into int[]
// Example: v10.0.2 -> {10, 0, 2};
var v1 = version1.Substring(1).Split('.').Select(int.Parse).ToArray();
var v2 = version2.Substring(1).Split('.').Select(int.Parse).ToArray();
if (v1.Count() != 3 || v2.Count() != 3)
{
throw new FormatException();
}
if (v1[0] - v2[0] != 0)
{
return v1[0] - v2[0];
}
if (v1[1] - v2[1] != 0)
{
return v1[1] - v2[1];
}
return v1[2] - v2[2];
}
catch (Exception)
{
throw new FormatException("Bad product version format");
}
}
public const uint VirtualKeyWindows = interop.Constants.VK_WIN_BOTH;
}
}
// Copyright (c) Microsoft Corporation
// 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.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using Microsoft.PowerToys.Settings.UI.Lib.CustomAction;
namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
{
public class Helper
{
public static bool AllowRunnerToForeground()
{
var result = false;
var processes = Process.GetProcessesByName("PowerToys");
if (processes.Length > 0)
{
var pid = processes[0].Id;
result = AllowSetForegroundWindow(pid);
}
return result;
}
public static string GetSerializedCustomAction(string moduleName, string actionName, string actionValue)
{
var customAction = new CustomActionDataModel
{
Name = actionName,
Value = actionValue,
};
var moduleCustomAction = new ModuleCustomAction
{
ModuleAction = customAction,
};
var sendCustomAction = new SendCustomAction(moduleName);
sendCustomAction.Action = moduleCustomAction;
return sendCustomAction.ToJsonString();
}
public static FileSystemWatcher GetFileWatcher(string moduleName, string fileName, Action onChangedCallback)
{
var path = Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{moduleName}");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var watcher = new FileSystemWatcher();
watcher.Path = path;
watcher.Filter = fileName;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += (o, e) => onChangedCallback();
watcher.EnableRaisingEvents = true;
return watcher;
}
private static string LocalApplicationDataFolder()
{
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
[DllImport("user32.dll")]
private static extern bool AllowSetForegroundWindow(int dwProcessId);
private static interop.LayoutMapManaged layoutMap = new interop.LayoutMapManaged();
public static string GetKeyName(uint key)
{
return layoutMap.GetKeyName(key);
}
public static string GetProductVersion()
{
return interop.CommonManaged.GetProductVersion();
}
public static int CompareVersions(string version1, string version2)
{
try
{
// Split up the version strings into int[]
// Example: v10.0.2 -> {10, 0, 2};
var v1 = version1.Substring(1).Split('.').Select(int.Parse).ToArray();
var v2 = version2.Substring(1).Split('.').Select(int.Parse).ToArray();
if (v1.Count() != 3 || v2.Count() != 3)
{
throw new FormatException();
}
if (v1[0] - v2[0] != 0)
{
return v1[0] - v2[0];
}
if (v1[1] - v2[1] != 0)
{
return v1[1] - v2[1];
}
return v1[2] - v2[2];
}
catch (Exception)
{
throw new FormatException("Bad product version format");
}
}
public const uint VirtualKeyWindows = interop.Constants.VK_WIN_BOTH;
}
}

View File

@@ -4,9 +4,9 @@
using System;
using System.Windows;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using Windows.UI.Popups;
@@ -18,13 +18,13 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
private bool isOpen = true;
public MainWindow()
{
var bootTime = new System.Diagnostics.Stopwatch();
bootTime.Start();
this.InitializeComponent();
bootTime.Stop();
{
var bootTime = new System.Diagnostics.Stopwatch();
bootTime.Start();
this.InitializeComponent();
bootTime.Stop();
PowerToysTelemetry.Log.WriteEvent(new SettingsBootEvent() { BootTimeMs = bootTime.ElapsedMilliseconds });
}
@@ -62,15 +62,15 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
}
// If the window is open, explicity force it to be shown to solve the blank dialog issue https://github.com/microsoft/PowerToys/issues/3384
if (isOpen)
if (isOpen)
{
Show();
Show();
}
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
isOpen = false;
}
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
isOpen = false;
}
}
}

View File

@@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using interop;
using ManagedCommon;
using ManagedCommon;
using Windows.UI.Popups;
namespace Microsoft.PowerToys.Settings.UI.Runner
@@ -58,8 +58,8 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
IsUserAnAdmin = false;
}
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
{
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
{
Environment.Exit(0);
});

View File

@@ -1,180 +1,180 @@
// Copyright (c) Microsoft Corporation
// 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 Microsoft.PowerToys.Settings.UI.Lib;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Controls
{
public sealed partial class HotkeySettingsControl : UserControl
{
public string Header { get; set; }
public string Keys { get; set; }
public static readonly DependencyProperty IsActiveProperty =
DependencyProperty.Register(
"Enabled",
typeof(bool),
typeof(HotkeySettingsControl),
null);
private bool _enabled = false;
public bool Enabled
{
get
{
return _enabled;
}
set
{
SetValue(IsActiveProperty, value);
_enabled = value;
if (value)
{
HotkeyTextBox.IsEnabled = true;
// TitleText.IsActive = "True";
// TitleGlyph.IsActive = "True";
}
else
{
HotkeyTextBox.IsEnabled = false;
// TitleText.IsActive = "False";
// TitleGlyph.IsActive = "False";
}
}
}
public static readonly DependencyProperty HotkeySettingsProperty =
DependencyProperty.Register(
"HotkeySettings",
typeof(HotkeySettings),
typeof(HotkeySettingsControl),
null);
private HotkeySettings hotkeySettings;
private HotkeySettings internalSettings;
private HotkeySettings lastValidSettings;
private HotkeySettingsControlHook hook;
private bool _isActive;
public HotkeySettings HotkeySettings
{
get
{
return hotkeySettings;
}
set
{
if (hotkeySettings != value)
{
hotkeySettings = value;
SetValue(HotkeySettingsProperty, value);
HotkeyTextBox.Text = HotkeySettings.ToString();
}
}
}
public HotkeySettingsControl()
{
InitializeComponent();
internalSettings = new HotkeySettings();
HotkeyTextBox.GettingFocus += HotkeyTextBox_GettingFocus;
HotkeyTextBox.LosingFocus += HotkeyTextBox_LosingFocus;
HotkeyTextBox.Unloaded += HotkeyTextBox_Unloaded;
hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive);
}
private void HotkeyTextBox_Unloaded(object sender, RoutedEventArgs e)
{
// Dispose the HotkeySettingsControlHook object to terminate the hook threads when the textbox is unloaded
hook.Dispose();
}
private void KeyEventHandler(int key, bool matchValue, int matchValueCode, string matchValueText)
{
switch ((Windows.System.VirtualKey)key)
{
case Windows.System.VirtualKey.LeftWindows:
case Windows.System.VirtualKey.RightWindows:
internalSettings.Win = matchValue;
break;
case Windows.System.VirtualKey.Control:
case Windows.System.VirtualKey.LeftControl:
case Windows.System.VirtualKey.RightControl:
internalSettings.Ctrl = matchValue;
break;
case Windows.System.VirtualKey.Menu:
case Windows.System.VirtualKey.LeftMenu:
case Windows.System.VirtualKey.RightMenu:
internalSettings.Alt = matchValue;
break;
case Windows.System.VirtualKey.Shift:
case Windows.System.VirtualKey.LeftShift:
case Windows.System.VirtualKey.RightShift:
internalSettings.Shift = matchValue;
break;
case Windows.System.VirtualKey.Escape:
internalSettings = new HotkeySettings();
HotkeySettings = new HotkeySettings();
return;
default:
internalSettings.Code = matchValueCode;
break;
}
}
private async void Hotkey_KeyDown(int key)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
KeyEventHandler(key, true, key, Lib.Utilities.Helper.GetKeyName((uint)key));
if (internalSettings.Code > 0)
{
lastValidSettings = internalSettings.Clone();
HotkeyTextBox.Text = lastValidSettings.ToString();
}
});
}
private async void Hotkey_KeyUp(int key)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
KeyEventHandler(key, false, 0, string.Empty);
});
}
private bool Hotkey_IsActive()
{
return _isActive;
}
private void HotkeyTextBox_GettingFocus(object sender, RoutedEventArgs e)
{
_isActive = true;
}
private void HotkeyTextBox_LosingFocus(object sender, RoutedEventArgs e)
{
if (lastValidSettings != null && (lastValidSettings.IsValid() || lastValidSettings.IsEmpty()))
{
HotkeySettings = lastValidSettings.Clone();
}
HotkeyTextBox.Text = hotkeySettings.ToString();
_isActive = false;
}
}
}
// Copyright (c) Microsoft Corporation
// 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 Microsoft.PowerToys.Settings.UI.Lib;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Controls
{
public sealed partial class HotkeySettingsControl : UserControl
{
public string Header { get; set; }
public string Keys { get; set; }
public static readonly DependencyProperty IsActiveProperty =
DependencyProperty.Register(
"Enabled",
typeof(bool),
typeof(HotkeySettingsControl),
null);
private bool _enabled = false;
public bool Enabled
{
get
{
return _enabled;
}
set
{
SetValue(IsActiveProperty, value);
_enabled = value;
if (value)
{
HotkeyTextBox.IsEnabled = true;
// TitleText.IsActive = "True";
// TitleGlyph.IsActive = "True";
}
else
{
HotkeyTextBox.IsEnabled = false;
// TitleText.IsActive = "False";
// TitleGlyph.IsActive = "False";
}
}
}
public static readonly DependencyProperty HotkeySettingsProperty =
DependencyProperty.Register(
"HotkeySettings",
typeof(HotkeySettings),
typeof(HotkeySettingsControl),
null);
private HotkeySettings hotkeySettings;
private HotkeySettings internalSettings;
private HotkeySettings lastValidSettings;
private HotkeySettingsControlHook hook;
private bool _isActive;
public HotkeySettings HotkeySettings
{
get
{
return hotkeySettings;
}
set
{
if (hotkeySettings != value)
{
hotkeySettings = value;
SetValue(HotkeySettingsProperty, value);
HotkeyTextBox.Text = HotkeySettings.ToString();
}
}
}
public HotkeySettingsControl()
{
InitializeComponent();
internalSettings = new HotkeySettings();
HotkeyTextBox.GettingFocus += HotkeyTextBox_GettingFocus;
HotkeyTextBox.LosingFocus += HotkeyTextBox_LosingFocus;
HotkeyTextBox.Unloaded += HotkeyTextBox_Unloaded;
hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive);
}
private void HotkeyTextBox_Unloaded(object sender, RoutedEventArgs e)
{
// Dispose the HotkeySettingsControlHook object to terminate the hook threads when the textbox is unloaded
hook.Dispose();
}
private void KeyEventHandler(int key, bool matchValue, int matchValueCode, string matchValueText)
{
switch ((Windows.System.VirtualKey)key)
{
case Windows.System.VirtualKey.LeftWindows:
case Windows.System.VirtualKey.RightWindows:
internalSettings.Win = matchValue;
break;
case Windows.System.VirtualKey.Control:
case Windows.System.VirtualKey.LeftControl:
case Windows.System.VirtualKey.RightControl:
internalSettings.Ctrl = matchValue;
break;
case Windows.System.VirtualKey.Menu:
case Windows.System.VirtualKey.LeftMenu:
case Windows.System.VirtualKey.RightMenu:
internalSettings.Alt = matchValue;
break;
case Windows.System.VirtualKey.Shift:
case Windows.System.VirtualKey.LeftShift:
case Windows.System.VirtualKey.RightShift:
internalSettings.Shift = matchValue;
break;
case Windows.System.VirtualKey.Escape:
internalSettings = new HotkeySettings();
HotkeySettings = new HotkeySettings();
return;
default:
internalSettings.Code = matchValueCode;
break;
}
}
private async void Hotkey_KeyDown(int key)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
KeyEventHandler(key, true, key, Lib.Utilities.Helper.GetKeyName((uint)key));
if (internalSettings.Code > 0)
{
lastValidSettings = internalSettings.Clone();
HotkeyTextBox.Text = lastValidSettings.ToString();
}
});
}
private async void Hotkey_KeyUp(int key)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
KeyEventHandler(key, false, 0, string.Empty);
});
}
private bool Hotkey_IsActive()
{
return _isActive;
}
private void HotkeyTextBox_GettingFocus(object sender, RoutedEventArgs e)
{
_isActive = true;
}
private void HotkeyTextBox_LosingFocus(object sender, RoutedEventArgs e)
{
if (lastValidSettings != null && (lastValidSettings.IsValid() || lastValidSettings.IsEmpty()))
{
HotkeySettings = lastValidSettings.Clone();
}
HotkeyTextBox.Text = hotkeySettings.ToString();
_isActive = false;
}
}
}

View File

@@ -1,241 +1,241 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Views;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.Xaml;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class KeyboardManagerViewModel : Observable
{
private const string PowerToyName = "Keyboard Manager";
private const string RemapKeyboardActionName = "RemapKeyboard";
private const string RemapKeyboardActionValue = "Open Remap Keyboard Window";
private const string EditShortcutActionName = "EditShortcut";
private const string EditShortcutActionValue = "Open Edit Shortcut Window";
private const string JsonFileType = ".json";
private const string ProfileFileMutexName = "PowerToys.KeyboardManager.ConfigMutex";
private const int ProfileFileMutexWaitTimeoutMilliseconds = 1000;
private readonly CoreDispatcher dispatcher;
private readonly FileSystemWatcher watcher;
private ICommand remapKeyboardCommand;
private ICommand editShortcutCommand;
private KeyboardManagerSettings settings;
private KeyboardManagerProfile profile;
private GeneralSettings generalSettings;
public KeyboardManagerViewModel()
{
dispatcher = Window.Current.Dispatcher;
if (SettingsUtils.SettingsExists(PowerToyName))
{
// Todo: Be more resilient while reading and saving settings.
settings = SettingsUtils.GetSettings<KeyboardManagerSettings>(PowerToyName);
// Load profile.
if (!LoadProfile())
{
profile = new KeyboardManagerProfile();
}
}
else
{
settings = new KeyboardManagerSettings(PowerToyName);
SettingsUtils.SaveSettings(settings.ToJsonString(), PowerToyName);
}
if (SettingsUtils.SettingsExists())
{
generalSettings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
}
else
{
generalSettings = new GeneralSettings();
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
}
watcher = Helper.GetFileWatcher(
PowerToyName,
settings.Properties.ActiveConfiguration.Value + JsonFileType,
OnConfigFileUpdate);
}
public bool Enabled
{
get
{
return generalSettings.Enabled.KeyboardManager;
}
set
{
if (generalSettings.Enabled.KeyboardManager != value)
{
generalSettings.Enabled.KeyboardManager = value;
OnPropertyChanged(nameof(Enabled));
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettings);
ShellPage.DefaultSndMSGCallback(outgoing.ToString());
}
}
}
// store remappings
public List<KeysDataModel> RemapKeys
{
get
{
if (profile != null)
{
return profile.RemapKeys.InProcessRemapKeys;
}
else
{
return new List<KeysDataModel>();
}
}
}
public static List<AppSpecificKeysDataModel> CombineShortcutLists(List<KeysDataModel> globalShortcutList, List<AppSpecificKeysDataModel> appSpecificShortcutList)
{
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).Concat(appSpecificShortcutList).ToList();
}
public List<AppSpecificKeysDataModel> RemapShortcuts
{
get
{
if (profile != null)
{
return CombineShortcutLists(profile.RemapShortcuts.GlobalRemapShortcuts, profile.RemapShortcuts.AppSpecificRemapShortcuts);
}
else
{
return new List<AppSpecificKeysDataModel>();
}
}
}
public ICommand RemapKeyboardCommand => remapKeyboardCommand ?? (remapKeyboardCommand = new RelayCommand(OnRemapKeyboard));
public ICommand EditShortcutCommand => editShortcutCommand ?? (editShortcutCommand = new RelayCommand(OnEditShortcut));
private async void OnRemapKeyboard()
{
await Task.Run(() => OnRemapKeyboardBackground());
}
private async void OnEditShortcut()
{
await Task.Run(() => OnEditShortcutBackground());
}
private async Task OnRemapKeyboardBackground()
{
Helper.AllowRunnerToForeground();
ShellPage.DefaultSndMSGCallback(Helper.GetSerializedCustomAction(PowerToyName, RemapKeyboardActionName, RemapKeyboardActionValue));
await Task.CompletedTask;
}
private async Task OnEditShortcutBackground()
{
Helper.AllowRunnerToForeground();
ShellPage.DefaultSndMSGCallback(Helper.GetSerializedCustomAction(PowerToyName, EditShortcutActionName, EditShortcutActionValue));
await Task.CompletedTask;
}
private async void OnConfigFileUpdate()
{
// Note: FileSystemWatcher raise notification multiple times for single update operation.
// Todo: Handle duplicate events either by somehow suppress them or re-read the configuration everytime since we will be updating the UI only if something is changed.
if (LoadProfile())
{
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
OnPropertyChanged(nameof(RemapKeys));
OnPropertyChanged(nameof(RemapShortcuts));
});
}
}
private bool LoadProfile()
{
var success = true;
try
{
using (var profileFileMutex = Mutex.OpenExisting(ProfileFileMutexName))
{
if (profileFileMutex.WaitOne(ProfileFileMutexWaitTimeoutMilliseconds))
{
// update the UI element here.
try
{
profile = SettingsUtils.GetSettings<KeyboardManagerProfile>(PowerToyName, settings.Properties.ActiveConfiguration.Value + JsonFileType);
FilterRemapKeysList(profile.RemapKeys.InProcessRemapKeys);
}
finally
{
// Make sure to release the mutex.
profileFileMutex.ReleaseMutex();
}
}
else
{
success = false;
}
}
}
catch (Exception)
{
// Failed to load the configuration.
success = false;
}
return success;
}
private void FilterRemapKeysList(List<KeysDataModel> remapKeysList)
{
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftControl, (uint)VirtualKey.RightControl, (uint)VirtualKey.Control);
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftMenu, (uint)VirtualKey.RightMenu, (uint)VirtualKey.Menu);
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftShift, (uint)VirtualKey.RightShift, (uint)VirtualKey.Shift);
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftWindows, (uint)VirtualKey.RightWindows, Helper.VirtualKeyWindows);
}
private void CombineRemappings(List<KeysDataModel> remapKeysList, uint leftKey, uint rightKey, uint combinedKey)
{
KeysDataModel firstRemap = remapKeysList.Find(x => uint.Parse(x.OriginalKeys) == leftKey);
KeysDataModel secondRemap = remapKeysList.Find(x => uint.Parse(x.OriginalKeys) == rightKey);
if (firstRemap != null && secondRemap != null)
{
if (firstRemap.NewRemapKeys == secondRemap.NewRemapKeys)
{
KeysDataModel combinedRemap = new KeysDataModel
{
OriginalKeys = combinedKey.ToString(),
NewRemapKeys = firstRemap.NewRemapKeys,
};
remapKeysList.Insert(remapKeysList.IndexOf(firstRemap), combinedRemap);
remapKeysList.Remove(firstRemap);
remapKeysList.Remove(secondRemap);
}
}
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Views;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.Xaml;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class KeyboardManagerViewModel : Observable
{
private const string PowerToyName = "Keyboard Manager";
private const string RemapKeyboardActionName = "RemapKeyboard";
private const string RemapKeyboardActionValue = "Open Remap Keyboard Window";
private const string EditShortcutActionName = "EditShortcut";
private const string EditShortcutActionValue = "Open Edit Shortcut Window";
private const string JsonFileType = ".json";
private const string ProfileFileMutexName = "PowerToys.KeyboardManager.ConfigMutex";
private const int ProfileFileMutexWaitTimeoutMilliseconds = 1000;
private readonly CoreDispatcher dispatcher;
private readonly FileSystemWatcher watcher;
private ICommand remapKeyboardCommand;
private ICommand editShortcutCommand;
private KeyboardManagerSettings settings;
private KeyboardManagerProfile profile;
private GeneralSettings generalSettings;
public KeyboardManagerViewModel()
{
dispatcher = Window.Current.Dispatcher;
if (SettingsUtils.SettingsExists(PowerToyName))
{
// Todo: Be more resilient while reading and saving settings.
settings = SettingsUtils.GetSettings<KeyboardManagerSettings>(PowerToyName);
// Load profile.
if (!LoadProfile())
{
profile = new KeyboardManagerProfile();
}
}
else
{
settings = new KeyboardManagerSettings(PowerToyName);
SettingsUtils.SaveSettings(settings.ToJsonString(), PowerToyName);
}
if (SettingsUtils.SettingsExists())
{
generalSettings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
}
else
{
generalSettings = new GeneralSettings();
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
}
watcher = Helper.GetFileWatcher(
PowerToyName,
settings.Properties.ActiveConfiguration.Value + JsonFileType,
OnConfigFileUpdate);
}
public bool Enabled
{
get
{
return generalSettings.Enabled.KeyboardManager;
}
set
{
if (generalSettings.Enabled.KeyboardManager != value)
{
generalSettings.Enabled.KeyboardManager = value;
OnPropertyChanged(nameof(Enabled));
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettings);
ShellPage.DefaultSndMSGCallback(outgoing.ToString());
}
}
}
// store remappings
public List<KeysDataModel> RemapKeys
{
get
{
if (profile != null)
{
return profile.RemapKeys.InProcessRemapKeys;
}
else
{
return new List<KeysDataModel>();
}
}
}
public static List<AppSpecificKeysDataModel> CombineShortcutLists(List<KeysDataModel> globalShortcutList, List<AppSpecificKeysDataModel> appSpecificShortcutList)
{
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).Concat(appSpecificShortcutList).ToList();
}
public List<AppSpecificKeysDataModel> RemapShortcuts
{
get
{
if (profile != null)
{
return CombineShortcutLists(profile.RemapShortcuts.GlobalRemapShortcuts, profile.RemapShortcuts.AppSpecificRemapShortcuts);
}
else
{
return new List<AppSpecificKeysDataModel>();
}
}
}
public ICommand RemapKeyboardCommand => remapKeyboardCommand ?? (remapKeyboardCommand = new RelayCommand(OnRemapKeyboard));
public ICommand EditShortcutCommand => editShortcutCommand ?? (editShortcutCommand = new RelayCommand(OnEditShortcut));
private async void OnRemapKeyboard()
{
await Task.Run(() => OnRemapKeyboardBackground());
}
private async void OnEditShortcut()
{
await Task.Run(() => OnEditShortcutBackground());
}
private async Task OnRemapKeyboardBackground()
{
Helper.AllowRunnerToForeground();
ShellPage.DefaultSndMSGCallback(Helper.GetSerializedCustomAction(PowerToyName, RemapKeyboardActionName, RemapKeyboardActionValue));
await Task.CompletedTask;
}
private async Task OnEditShortcutBackground()
{
Helper.AllowRunnerToForeground();
ShellPage.DefaultSndMSGCallback(Helper.GetSerializedCustomAction(PowerToyName, EditShortcutActionName, EditShortcutActionValue));
await Task.CompletedTask;
}
private async void OnConfigFileUpdate()
{
// Note: FileSystemWatcher raise notification multiple times for single update operation.
// Todo: Handle duplicate events either by somehow suppress them or re-read the configuration everytime since we will be updating the UI only if something is changed.
if (LoadProfile())
{
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
OnPropertyChanged(nameof(RemapKeys));
OnPropertyChanged(nameof(RemapShortcuts));
});
}
}
private bool LoadProfile()
{
var success = true;
try
{
using (var profileFileMutex = Mutex.OpenExisting(ProfileFileMutexName))
{
if (profileFileMutex.WaitOne(ProfileFileMutexWaitTimeoutMilliseconds))
{
// update the UI element here.
try
{
profile = SettingsUtils.GetSettings<KeyboardManagerProfile>(PowerToyName, settings.Properties.ActiveConfiguration.Value + JsonFileType);
FilterRemapKeysList(profile.RemapKeys.InProcessRemapKeys);
}
finally
{
// Make sure to release the mutex.
profileFileMutex.ReleaseMutex();
}
}
else
{
success = false;
}
}
}
catch (Exception)
{
// Failed to load the configuration.
success = false;
}
return success;
}
private void FilterRemapKeysList(List<KeysDataModel> remapKeysList)
{
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftControl, (uint)VirtualKey.RightControl, (uint)VirtualKey.Control);
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftMenu, (uint)VirtualKey.RightMenu, (uint)VirtualKey.Menu);
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftShift, (uint)VirtualKey.RightShift, (uint)VirtualKey.Shift);
CombineRemappings(remapKeysList, (uint)VirtualKey.LeftWindows, (uint)VirtualKey.RightWindows, Helper.VirtualKeyWindows);
}
private void CombineRemappings(List<KeysDataModel> remapKeysList, uint leftKey, uint rightKey, uint combinedKey)
{
KeysDataModel firstRemap = remapKeysList.Find(x => uint.Parse(x.OriginalKeys) == leftKey);
KeysDataModel secondRemap = remapKeysList.Find(x => uint.Parse(x.OriginalKeys) == rightKey);
if (firstRemap != null && secondRemap != null)
{
if (firstRemap.NewRemapKeys == secondRemap.NewRemapKeys)
{
KeysDataModel combinedRemap = new KeysDataModel
{
OriginalKeys = combinedKey.ToString(),
NewRemapKeys = firstRemap.NewRemapKeys,
};
remapKeysList.Insert(remapKeysList.IndexOf(firstRemap), combinedRemap);
remapKeysList.Remove(firstRemap);
remapKeysList.Remove(secondRemap);
}
}
}
}
}

View File

@@ -1,290 +1,290 @@
// Copyright (c) Microsoft Corporation
// 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.Runtime.CompilerServices;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Views;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class PowerLauncherViewModel : Observable
{
private PowerLauncherSettings settings;
private GeneralSettings generalSettings;
public delegate void SendCallback(PowerLauncherSettings settings);
private readonly SendCallback callback;
public PowerLauncherViewModel()
{
callback = (PowerLauncherSettings settings) =>
{
// Propagate changes to Power Launcher through IPC
ShellPage.DefaultSndMSGCallback(
string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.ModuleName, JsonSerializer.Serialize(settings)));
};
if (SettingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
{
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
}
else
{
settings = new PowerLauncherSettings();
settings.Properties.OpenPowerLauncher.Alt = true;
settings.Properties.OpenPowerLauncher.Code = (int)Windows.System.VirtualKey.Space;
settings.Properties.MaximumNumberOfResults = 4;
callback(settings);
}
if (SettingsUtils.SettingsExists())
{
generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
}
else
{
generalSettings = new GeneralSettings();
}
}
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
{
this.settings = settings;
this.callback = callback;
}
private void UpdateSettings([CallerMemberName] string propertyName = null)
{
// Notify UI of property change
OnPropertyChanged(propertyName);
callback(settings);
}
public bool EnablePowerLauncher
{
get
{
return generalSettings.Enabled.PowerLauncher;
}
set
{
if (generalSettings.Enabled.PowerLauncher != value)
{
generalSettings.Enabled.PowerLauncher = value;
OnPropertyChanged(nameof(EnablePowerLauncher));
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettings);
ShellPage.DefaultSndMSGCallback(outgoing.ToString());
}
}
}
public string SearchResultPreference
{
get
{
return settings.Properties.SearchResultPreference;
}
set
{
if (settings.Properties.SearchResultPreference != value)
{
settings.Properties.SearchResultPreference = value;
UpdateSettings();
}
}
}
public string SearchTypePreference
{
get
{
return settings.Properties.SearchTypePreference;
}
set
{
if (settings.Properties.SearchTypePreference != value)
{
settings.Properties.SearchTypePreference = value;
UpdateSettings();
}
}
}
public int MaximumNumberOfResults
{
get
{
return settings.Properties.MaximumNumberOfResults;
}
set
{
if (settings.Properties.MaximumNumberOfResults != value)
{
settings.Properties.MaximumNumberOfResults = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenPowerLauncher
{
get
{
return settings.Properties.OpenPowerLauncher;
}
set
{
if (settings.Properties.OpenPowerLauncher != value)
{
settings.Properties.OpenPowerLauncher = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenFileLocation
{
get
{
return settings.Properties.OpenFileLocation;
}
set
{
if (settings.Properties.OpenFileLocation != value)
{
settings.Properties.OpenFileLocation = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenConsole
{
get
{
return settings.Properties.OpenConsole;
}
set
{
if (settings.Properties.OpenConsole != value)
{
settings.Properties.OpenConsole = value;
UpdateSettings();
}
}
}
public HotkeySettings CopyPathLocation
{
get
{
return settings.Properties.CopyPathLocation;
}
set
{
if (settings.Properties.CopyPathLocation != value)
{
settings.Properties.CopyPathLocation = value;
UpdateSettings();
}
}
}
public bool OverrideWinRKey
{
get
{
return settings.Properties.OverrideWinkeyR;
}
set
{
if (settings.Properties.OverrideWinkeyR != value)
{
settings.Properties.OverrideWinkeyR = value;
UpdateSettings();
}
}
}
public bool OverrideWinSKey
{
get
{
return settings.Properties.OverrideWinkeyS;
}
set
{
if (settings.Properties.OverrideWinkeyS != value)
{
settings.Properties.OverrideWinkeyS = value;
UpdateSettings();
}
}
}
public bool IgnoreHotkeysInFullScreen
{
get
{
return settings.Properties.IgnoreHotkeysInFullscreen;
}
set
{
if (settings.Properties.IgnoreHotkeysInFullscreen != value)
{
settings.Properties.IgnoreHotkeysInFullscreen = value;
UpdateSettings();
}
}
}
public bool ClearInputOnLaunch
{
get
{
return settings.Properties.ClearInputOnLaunch;
}
set
{
if (settings.Properties.ClearInputOnLaunch != value)
{
settings.Properties.ClearInputOnLaunch = value;
UpdateSettings();
}
}
}
public bool DisableDriveDetectionWarning
{
get
{
return settings.Properties.DisableDriveDetectionWarning;
}
set
{
if (settings.Properties.DisableDriveDetectionWarning != value)
{
settings.Properties.DisableDriveDetectionWarning = value;
UpdateSettings();
}
}
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Runtime.CompilerServices;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Views;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class PowerLauncherViewModel : Observable
{
private PowerLauncherSettings settings;
private GeneralSettings generalSettings;
public delegate void SendCallback(PowerLauncherSettings settings);
private readonly SendCallback callback;
public PowerLauncherViewModel()
{
callback = (PowerLauncherSettings settings) =>
{
// Propagate changes to Power Launcher through IPC
ShellPage.DefaultSndMSGCallback(
string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.ModuleName, JsonSerializer.Serialize(settings)));
};
if (SettingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
{
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
}
else
{
settings = new PowerLauncherSettings();
settings.Properties.OpenPowerLauncher.Alt = true;
settings.Properties.OpenPowerLauncher.Code = (int)Windows.System.VirtualKey.Space;
settings.Properties.MaximumNumberOfResults = 4;
callback(settings);
}
if (SettingsUtils.SettingsExists())
{
generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
}
else
{
generalSettings = new GeneralSettings();
}
}
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
{
this.settings = settings;
this.callback = callback;
}
private void UpdateSettings([CallerMemberName] string propertyName = null)
{
// Notify UI of property change
OnPropertyChanged(propertyName);
callback(settings);
}
public bool EnablePowerLauncher
{
get
{
return generalSettings.Enabled.PowerLauncher;
}
set
{
if (generalSettings.Enabled.PowerLauncher != value)
{
generalSettings.Enabled.PowerLauncher = value;
OnPropertyChanged(nameof(EnablePowerLauncher));
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettings);
ShellPage.DefaultSndMSGCallback(outgoing.ToString());
}
}
}
public string SearchResultPreference
{
get
{
return settings.Properties.SearchResultPreference;
}
set
{
if (settings.Properties.SearchResultPreference != value)
{
settings.Properties.SearchResultPreference = value;
UpdateSettings();
}
}
}
public string SearchTypePreference
{
get
{
return settings.Properties.SearchTypePreference;
}
set
{
if (settings.Properties.SearchTypePreference != value)
{
settings.Properties.SearchTypePreference = value;
UpdateSettings();
}
}
}
public int MaximumNumberOfResults
{
get
{
return settings.Properties.MaximumNumberOfResults;
}
set
{
if (settings.Properties.MaximumNumberOfResults != value)
{
settings.Properties.MaximumNumberOfResults = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenPowerLauncher
{
get
{
return settings.Properties.OpenPowerLauncher;
}
set
{
if (settings.Properties.OpenPowerLauncher != value)
{
settings.Properties.OpenPowerLauncher = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenFileLocation
{
get
{
return settings.Properties.OpenFileLocation;
}
set
{
if (settings.Properties.OpenFileLocation != value)
{
settings.Properties.OpenFileLocation = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenConsole
{
get
{
return settings.Properties.OpenConsole;
}
set
{
if (settings.Properties.OpenConsole != value)
{
settings.Properties.OpenConsole = value;
UpdateSettings();
}
}
}
public HotkeySettings CopyPathLocation
{
get
{
return settings.Properties.CopyPathLocation;
}
set
{
if (settings.Properties.CopyPathLocation != value)
{
settings.Properties.CopyPathLocation = value;
UpdateSettings();
}
}
}
public bool OverrideWinRKey
{
get
{
return settings.Properties.OverrideWinkeyR;
}
set
{
if (settings.Properties.OverrideWinkeyR != value)
{
settings.Properties.OverrideWinkeyR = value;
UpdateSettings();
}
}
}
public bool OverrideWinSKey
{
get
{
return settings.Properties.OverrideWinkeyS;
}
set
{
if (settings.Properties.OverrideWinkeyS != value)
{
settings.Properties.OverrideWinkeyS = value;
UpdateSettings();
}
}
}
public bool IgnoreHotkeysInFullScreen
{
get
{
return settings.Properties.IgnoreHotkeysInFullscreen;
}
set
{
if (settings.Properties.IgnoreHotkeysInFullscreen != value)
{
settings.Properties.IgnoreHotkeysInFullscreen = value;
UpdateSettings();
}
}
}
public bool ClearInputOnLaunch
{
get
{
return settings.Properties.ClearInputOnLaunch;
}
set
{
if (settings.Properties.ClearInputOnLaunch != value)
{
settings.Properties.ClearInputOnLaunch = value;
UpdateSettings();
}
}
}
public bool DisableDriveDetectionWarning
{
get
{
return settings.Properties.DisableDriveDetectionWarning;
}
set
{
if (settings.Properties.DisableDriveDetectionWarning != value)
{
settings.Properties.DisableDriveDetectionWarning = value;
UpdateSettings();
}
}
}
}
}

View File

@@ -1,23 +1,23 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class KeyboardManagerPage : Page
{
public KeyboardManagerViewModel ViewModel { get; } = new KeyboardManagerViewModel();
public KeyboardManagerPage()
{
InitializeComponent();
DataContext = ViewModel;
}
}
}
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class KeyboardManagerPage : Page
{
public KeyboardManagerViewModel ViewModel { get; } = new KeyboardManagerViewModel();
public KeyboardManagerPage()
{
InitializeComponent();
DataContext = ViewModel;
}
}
}

View File

@@ -1,24 +1,24 @@
// Copyright (c) Microsoft Corporation
// 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.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public class VisibleIfNotEmpty : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (value as IList).Count == 0 ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return null;
}
}
}
// Copyright (c) Microsoft Corporation
// 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.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public class VisibleIfNotEmpty : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (value as IList).Count == 0 ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return null;
}
}
}