Stylecop compliance

This commit is contained in:
Tomas Raies 2020-04-08 00:19:00 -07:00 committed by Tomas Agustin Raies
parent 443b3c8b82
commit a85b84fd56
17 changed files with 260 additions and 183 deletions

View File

@ -180,12 +180,16 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.Test", "src\core\Microsoft.PowerToys.Settings.Test\Microsoft.PowerToys.Settings.Test.csproj", "{6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.Test", "src\core\Microsoft.PowerToys.Settings.Test\Microsoft.PowerToys.Settings.Test.csproj", "{6F2B5799-36AE-4D10-9DCF-B19CD26A5DBC}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.UI.Runner", "src\core\Microsoft.PowerToys.Settings.UI.Runner\Microsoft.PowerToys.Settings.UI.Runner.csproj", "{E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.UI.Runner", "src\core\Microsoft.PowerToys.Settings.UI.Runner\Microsoft.PowerToys.Settings.UI.Runner.csproj", "{E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}"
ProjectSection(ProjectDependencies) = postProject
{F88B6FD1-14BD-48DB-85C2-6C51B8045121} = {F88B6FD1-14BD-48DB-85C2-6C51B8045121}
EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.PowerToys.Settings.TwoWayIPCLib", "src\core\Microsoft.PowerToys.Settings.TwoWayIPCLib\TwoWayIPCLib.vcxproj", "{F88B6FD1-14BD-48DB-85C2-6C51B8045121}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.PowerToys.Settings.TwoWayIPCLib", "src\core\Microsoft.PowerToys.Settings.TwoWayIPCLib\TwoWayIPCLib.vcxproj", "{F88B6FD1-14BD-48DB-85C2-6C51B8045121}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerToys.Settings.UI", "src\core\Microsoft.PowerToys.Settings.UI\Microsoft.PowerToys.Settings.UI.csproj", "{4EB9C181-96E2-4587-AB98-2DB84C1A2310}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerToys.Settings.UI", "src\core\Microsoft.PowerToys.Settings.UI\Microsoft.PowerToys.Settings.UI.csproj", "{4EB9C181-96E2-4587-AB98-2DB84C1A2310}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.PowerToys.Settings.IPCWrapperPS", "src\core\Microsoft.PowerToys.Settings.IPCWrapperPS\Microsoft.PowerToys.Settings.IPCWrapperPS.vcxproj", "{C073B057-B157-40F0-8678-1DCD119D841C}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.PowerToys.Settings.IPCWrapperPS", "src\core\Microsoft.PowerToys.Settings.IPCWrapperPS\Microsoft.PowerToys.Settings.IPCWrapperPS.vcxproj", "{C073B057-B157-40F0-8678-1DCD119D841C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4981CCD1-4CD9-4A49-B240-00AA46493FF8}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4981CCD1-4CD9-4A49-B240-00AA46493FF8}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig .editorconfig = .editorconfig
@ -642,14 +646,22 @@ Global
{C073B057-B157-40F0-8678-1DCD119D841C}.Release|ARM64.ActiveCfg = Release|Win32 {C073B057-B157-40F0-8678-1DCD119D841C}.Release|ARM64.ActiveCfg = Release|Win32
{C073B057-B157-40F0-8678-1DCD119D841C}.Release|x64.ActiveCfg = Release|x64 {C073B057-B157-40F0-8678-1DCD119D841C}.Release|x64.ActiveCfg = Release|x64
{C073B057-B157-40F0-8678-1DCD119D841C}.Release|x86.ActiveCfg = Release|Win32 {C073B057-B157-40F0-8678-1DCD119D841C}.Release|x86.ActiveCfg = Release|Win32
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|ARM.ActiveCfg = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|Any CPU.Build.0 = Debug|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|ARM.Build.0 = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|ARM64.Build.0 = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.ActiveCfg = Debug|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.ActiveCfg = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.Build.0 = Debug|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.Build.0 = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|Any CPU.ActiveCfg = Release|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x86.ActiveCfg = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|Any CPU.Build.0 = Release|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x86.Build.0 = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|ARM.ActiveCfg = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|ARM.Build.0 = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|ARM64.ActiveCfg = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|ARM64.Build.0 = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x86.ActiveCfg = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,5 +1,7 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // 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;
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
@ -7,33 +9,42 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public class HotkeySettings public class HotkeySettings
{ {
public bool win { get; set; } public bool win { get; set; }
public bool ctrl { get; set; } public bool ctrl { get; set; }
public bool alt { get; set; } public bool alt { get; set; }
public bool shift { get; set; } public bool shift { get; set; }
public string key { get; set; } public string key { get; set; }
public int code { get; set; } public int code { get; set; }
public override string ToString() public override string ToString()
{ {
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
if (win) if (this.win)
{ {
output.Append("Win + "); output.Append("Win + ");
} }
if (ctrl)
if (this.ctrl)
{ {
output.Append("Ctrl + "); output.Append("Ctrl + ");
} }
if (alt)
if (this.alt)
{ {
output.Append("Alt + "); output.Append("Alt + ");
} }
if (shift)
if (this.shift)
{ {
output.Append("Shift + "); output.Append("Shift + ");
} }
output.Append(key);
output.Append(this.key);
return output.ToString(); return output.ToString();
} }
} }

View File

@ -0,0 +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.
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class PowerLauncherProperties
{
public bool enable_powerlauncher { get; set; }
public string search_result_preference { get; set; }
public string search_type_preference { get; set; }
public int maximum_number_of_results { get; set; }
public HotkeySettings open_powerlauncher { get; set; }
public HotkeySettings open_file_location { get; set; }
public HotkeySettings copy_path_location { get; set; }
public HotkeySettings open_console { get; set; }
public bool override_win_r_key { get; set; }
public bool override_win_s_key { get; set; }
public PowerLauncherProperties()
{
this.open_powerlauncher = new HotkeySettings();
this.open_file_location = new HotkeySettings();
this.copy_path_location = new HotkeySettings();
this.open_console = new HotkeySettings();
this.search_result_preference = "most_recently_used";
this.search_type_preference = "application_name";
}
}
}

View File

@ -1,13 +1,13 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Text; // See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
public class PowerLauncherSettings : BasePTModuleSettings public class PowerLauncherSettings : BasePTModuleSettings
{ {
public PowerLauncherProperties properties { get; set; } public PowerLauncherProperties properties { get; set; }
public PowerLauncherSettings() public PowerLauncherSettings()
{ {
this.properties = new PowerLauncherProperties(); this.properties = new PowerLauncherProperties();
@ -15,28 +15,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
this.name = "_unset_"; this.name = "_unset_";
} }
} }
public class PowerLauncherProperties
{
public bool enable_powerlauncher { get; set; }
public string search_result_preference { get; set; }
public string search_type_preference { get; set; }
public int maximum_number_of_results { get; set; }
public HotkeySettings open_powerlauncher { get; set; }
public HotkeySettings open_file_location { get; set; }
public HotkeySettings copy_path_location { get; set; }
public HotkeySettings open_console { get; set; }
public bool override_win_r_key { get; set; }
public bool override_win_s_key { get; set; }
public PowerLauncherProperties()
{
open_powerlauncher = new HotkeySettings();
open_file_location = new HotkeySettings();
copy_path_location = new HotkeySettings();
open_console = new HotkeySettings();
search_result_preference = "most_recently_used";
search_type_preference = "application_name";
}
}
} }

View File

@ -10,10 +10,10 @@ using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
public class PowerPreviewProperties public class PowerPreviewProperties
{ {
public BoolProperty IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; } public BoolProperty IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; }
public BoolProperty PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; } public BoolProperty PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; }
public PowerPreviewProperties() public PowerPreviewProperties()

View File

@ -20,10 +20,13 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
} }
public BoolProperty bool_persist_input { get; set; } public BoolProperty bool_persist_input { get; set; }
public BoolProperty bool_mru_enabled { get; set; } public BoolProperty bool_mru_enabled { get; set; }
public IntProperty int_max_mru_size { get; set; } public IntProperty int_max_mru_size { get; set; }
public BoolProperty bool_show_icon_on_menu { get; set; } public BoolProperty bool_show_icon_on_menu { get; set; }
public BoolProperty bool_show_extended_menu { get; set; } public BoolProperty bool_show_extended_menu { get; set; }
} }
} }

View File

@ -30,4 +30,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
return JsonSerializer.Serialize(this); return JsonSerializer.Serialize(this);
} }
} }
} }

View File

@ -1,18 +1,15 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // 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.IO; using System.IO;
using System.Text;
using System.Text.Json; using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
public static class SettingsUtils public static class SettingsUtils
{ {
private static string LocalApplicationDataFolder()
{
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
public static bool SettingsFolderExists(string powertoy) public static bool SettingsFolderExists(string powertoy)
{ {
return Directory.Exists(Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}")); return Directory.Exists(Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
@ -59,16 +56,22 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
// Save settings to a json file. // Save settings to a json file.
public static void SaveSettings(string jsonSettings, string powertoy) public static void SaveSettings(string jsonSettings, string powertoy)
{ {
if(jsonSettings != null) if (jsonSettings != null)
{ {
if (!SettingsFolderExists(powertoy)) if (!SettingsFolderExists(powertoy))
{ {
CreateSettingsFolder(powertoy); CreateSettingsFolder(powertoy);
} }
System.IO.File.WriteAllText( System.IO.File.WriteAllText(
SettingsUtils.GetSettingsPath(powertoy), SettingsUtils.GetSettingsPath(powertoy),
jsonSettings); jsonSettings);
} }
} }
private static string LocalApplicationDataFolder()
{
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
} }
} }

View File

@ -10,7 +10,6 @@ using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
public class SndPowerPreviewSettings public class SndPowerPreviewSettings
{ {
[JsonPropertyName("File Explorer Preview")] [JsonPropertyName("File Explorer Preview")]

View File

@ -22,4 +22,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
return JsonSerializer.Serialize(this); return JsonSerializer.Serialize(this);
} }
} }
} }

View File

@ -1,25 +1,14 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.IO; // See the LICENSE file in the project root for more information.
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime; using Microsoft.PowerToys.Settings.UI.Lib;
using System.Text;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core; using Windows.UI.Core;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Microsoft.PowerToys.Settings.UI.Lib;
using System.ComponentModel;
using System.Runtime.CompilerServices;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace Microsoft.PowerToys.Settings.UI.Controls namespace Microsoft.PowerToys.Settings.UI.Controls
{ {
public sealed partial class HotkeySettingsControl : UserControl public sealed partial class HotkeySettingsControl : UserControl
@ -28,30 +17,35 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
public static readonly DependencyProperty HotkeySettingsProperty = public static readonly DependencyProperty HotkeySettingsProperty =
DependencyProperty.Register( DependencyProperty.Register(
"HotkeySettings", "HotkeySettings",
typeof(HotkeySettings), typeof(HotkeySettings),
typeof(HotkeySettingsControl), typeof(HotkeySettingsControl),
null); null);
private HotkeySettings _hotkeySettings; private HotkeySettings hotkeySettings;
public HotkeySettings HotkeySettings
{ public HotkeySettings HotkeySettings
get { return _hotkeySettings; } {
set get
{ {
if (_hotkeySettings != value) return this.hotkeySettings;
}
set
{
if (this.hotkeySettings != value)
{ {
_hotkeySettings = value; this.hotkeySettings = value;
SetValue(HotkeySettingsProperty, value); this.SetValue(HotkeySettingsProperty, value);
HotkeyTextBox.Text = HotkeySettings.ToString(); this.HotkeyTextBox.Text = this.HotkeySettings.ToString();
} }
} }
} }
public HotkeySettingsControl() public HotkeySettingsControl()
{ {
this.InitializeComponent(); this.InitializeComponent();
HotkeyTextBox.PreviewKeyDown += HotkeyTextBox_KeyDown; this.HotkeyTextBox.PreviewKeyDown += this.HotkeyTextBox_KeyDown;
} }
private static bool IsDown(Windows.System.VirtualKey key) private static bool IsDown(Windows.System.VirtualKey key)
@ -67,27 +61,30 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
e.Key == Windows.System.VirtualKey.RightWindows || e.Key == Windows.System.VirtualKey.RightWindows ||
e.Key == Windows.System.VirtualKey.Control || e.Key == Windows.System.VirtualKey.Control ||
e.Key == Windows.System.VirtualKey.Menu || e.Key == Windows.System.VirtualKey.Menu ||
e.Key == Windows.System.VirtualKey.Shift e.Key == Windows.System.VirtualKey.Shift)
)
{ {
return; return;
} }
var settings = new HotkeySettings(); var settings = new HotkeySettings();
// Display HotKey value // Display HotKey value
if (IsDown(Windows.System.VirtualKey.LeftWindows) || if (IsDown(Windows.System.VirtualKey.LeftWindows) ||
IsDown(Windows.System.VirtualKey.RightWindows)) IsDown(Windows.System.VirtualKey.RightWindows))
{ {
settings.win = true; settings.win = true;
} }
if (IsDown(Windows.System.VirtualKey.Control)) if (IsDown(Windows.System.VirtualKey.Control))
{ {
settings.ctrl = true; settings.ctrl = true;
} }
if (IsDown(Windows.System.VirtualKey.Menu)) if (IsDown(Windows.System.VirtualKey.Menu))
{ {
settings.alt = true; settings.alt = true;
} }
if (IsDown(Windows.System.VirtualKey.Shift)) if (IsDown(Windows.System.VirtualKey.Shift))
{ {
settings.shift = true; settings.shift = true;
@ -96,8 +93,8 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
settings.key = e.Key.ToString(); settings.key = e.Key.ToString();
// TODO: Check that e.OriginalKey is the ScanCode. It is not clear from docs. // TODO: Check that e.OriginalKey is the ScanCode. It is not clear from docs.
settings.code = (int) e.OriginalKey; settings.code = (int)e.OriginalKey;
HotkeySettings = settings; this.HotkeySettings = settings;
} }
} }
} }

View File

@ -123,6 +123,9 @@
</Compile> </Compile>
<Compile Include="Behaviors\NavigationViewHeaderBehavior.cs" /> <Compile Include="Behaviors\NavigationViewHeaderBehavior.cs" />
<Compile Include="Behaviors\NavigationViewHeaderMode.cs" /> <Compile Include="Behaviors\NavigationViewHeaderMode.cs" />
<Compile Include="Controls\HotkeySettingsControl.xaml.cs">
<DependentUpon>HotkeySettingsControl.xaml</DependentUpon>
</Compile>
<Compile Include="GlobalSuppressions.cs" /> <Compile Include="GlobalSuppressions.cs" />
<Compile Include="Helpers\NavHelper.cs" /> <Compile Include="Helpers\NavHelper.cs" />
<Compile Include="Helpers\Observable.cs" /> <Compile Include="Helpers\Observable.cs" />
@ -205,6 +208,10 @@
<PRIResource Include="Strings\en-us\Resources.resw" /> <PRIResource Include="Strings\en-us\Resources.resw" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Include="Controls\HotkeySettingsControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Styles\Page.xaml"> <Page Include="Styles\Page.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>

View File

@ -1,181 +1,218 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text.Json; using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib; using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.PowerToys.Settings.UI.Views;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.ViewModels namespace Microsoft.PowerToys.Settings.UI.ViewModels
{ {
public class PowerLauncherViewModel : Observable public class PowerLauncherViewModel : Observable
{ {
public PowerLauncherSettings settings; private const string POWERTOYNAME = "PowerLauncher";
private const string POWERTOY_NAME = "PowerLauncher"; private PowerLauncherSettings settings;
public PowerLauncherViewModel() public PowerLauncherViewModel()
{ {
if (SettingsUtils.SettingsExists(POWERTOY_NAME)) if (SettingsUtils.SettingsExists(POWERTOYNAME))
{ {
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(POWERTOY_NAME); this.settings = SettingsUtils.GetSettings<PowerLauncherSettings>(POWERTOYNAME);
} else }
else
{ {
settings = new PowerLauncherSettings(); this.settings = new PowerLauncherSettings();
} }
} }
private void UpdateSettings([CallerMemberName] string propertyName = null) private void UpdateSettings([CallerMemberName] string propertyName = null)
{ {
// Notify UI of property change // Notify UI of property change
OnPropertyChanged(propertyName); this.OnPropertyChanged(propertyName);
// Save settings to file // Save settings to file
var options = new JsonSerializerOptions var options = new JsonSerializerOptions
{ {
WriteIndented = true WriteIndented = true,
}; };
SettingsUtils.SaveSettings(JsonSerializer.Serialize(settings, options), POWERTOY_NAME); SettingsUtils.SaveSettings(JsonSerializer.Serialize(this.settings, options), POWERTOYNAME);
// Propagate changes to Power Launcher through IPC // Propagate changes to Power Launcher through IPC
var propertiesJson = JsonSerializer.Serialize(settings.properties); var propertiesJson = JsonSerializer.Serialize(this.settings.properties);
ShellPage.Default_SndMSG_Callback( ShellPage.DefaultSndMSGCallback(
string.Format("{{ \"{0}\": {1} }}", POWERTOY_NAME, JsonSerializer.Serialize(settings.properties))); string.Format("{{ \"{0}\": {1} }}", POWERTOYNAME, JsonSerializer.Serialize(this.settings.properties)));
} }
public bool EnablePowerLauncher public bool EnablePowerLauncher
{ {
get { return settings.properties.enable_powerlauncher; } get
set
{ {
if (settings.properties.enable_powerlauncher != value) return this.settings.properties.enable_powerlauncher;
}
set
{
if (this.settings.properties.enable_powerlauncher != value)
{ {
settings.properties.enable_powerlauncher = value; this.settings.properties.enable_powerlauncher = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
public string SearchResultPreference public string SearchResultPreference
{ {
get { return settings.properties.search_result_preference; } get
set
{ {
if (settings.properties.search_result_preference != value) return this.settings.properties.search_result_preference;
}
set
{
if (this.settings.properties.search_result_preference != value)
{ {
settings.properties.search_result_preference = value; this.settings.properties.search_result_preference = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
public string SearchTypePreference public string SearchTypePreference
{ {
get { return settings.properties.search_type_preference; } get
{
return this.settings.properties.search_type_preference;
}
set set
{ {
if (settings.properties.search_type_preference != value) if (this.settings.properties.search_type_preference != value)
{ {
settings.properties.search_type_preference = value; this.settings.properties.search_type_preference = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
public int MaximumNumberOfResults public int MaximumNumberOfResults
{ {
get { return settings.properties.maximum_number_of_results; } get
{
return this.settings.properties.maximum_number_of_results;
}
set set
{ {
if (settings.properties.maximum_number_of_results != value) if (this.settings.properties.maximum_number_of_results != value)
{ {
settings.properties.maximum_number_of_results = value; this.settings.properties.maximum_number_of_results = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
public HotkeySettings OpenPowerLauncher public HotkeySettings OpenPowerLauncher
{ {
get { return settings.properties.open_powerlauncher; } get
{
return this.settings.properties.open_powerlauncher;
}
set set
{ {
if (settings.properties.open_powerlauncher != value) if (this.settings.properties.open_powerlauncher != value)
{ {
settings.properties.open_powerlauncher = value; this.settings.properties.open_powerlauncher = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
public HotkeySettings OpenFileLocation public HotkeySettings OpenFileLocation
{ {
get { return settings.properties.open_file_location; } get
{
return this.settings.properties.open_file_location;
}
set set
{ {
if (settings.properties.open_file_location != value) if (this.settings.properties.open_file_location != value)
{ {
settings.properties.open_file_location = value; this.settings.properties.open_file_location = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
public HotkeySettings CopyPathLocation public HotkeySettings CopyPathLocation
{ {
get { return settings.properties.copy_path_location; } get
{
return this.settings.properties.copy_path_location;
}
set set
{ {
if (settings.properties.copy_path_location != value) if (this.settings.properties.copy_path_location != value)
{ {
settings.properties.copy_path_location = value; this.settings.properties.copy_path_location = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
public HotkeySettings OpenConsole public HotkeySettings OpenConsole
{ {
get { return settings.properties.open_console; } get
{
return this.settings.properties.open_console;
}
set set
{ {
if (settings.properties.open_console != value) if (this.settings.properties.open_console != value)
{ {
settings.properties.open_console = value; this.settings.properties.open_console = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
public bool OverrideWinRKey public bool OverrideWinRKey
{ {
get { return settings.properties.override_win_r_key; } get
{
return this.settings.properties.override_win_r_key;
}
set set
{ {
if (settings.properties.override_win_r_key != value) if (this.settings.properties.override_win_r_key != value)
{ {
settings.properties.override_win_r_key = value; this.settings.properties.override_win_r_key = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
public bool OverrideWinSKey public bool OverrideWinSKey
{ {
get { return settings.properties.override_win_s_key; } get
{
return this.settings.properties.override_win_s_key;
}
set set
{ {
if (settings.properties.override_win_s_key != value) if (this.settings.properties.override_win_s_key != value)
{ {
settings.properties.override_win_s_key = value; this.settings.properties.override_win_s_key = value;
UpdateSettings(); this.UpdateSettings();
} }
} }
} }
} }
} }

View File

@ -56,7 +56,7 @@
<ComboBox x:Uid="PowerLauncher_SearchResultPreference" <ComboBox x:Uid="PowerLauncher_SearchResultPreference"
MinWidth="320" MinWidth="320"
Margin="{StaticResource SmallTopMargin}" Margin="{StaticResource SmallTopMargin}"
ItemsSource="{x:Bind SearchResultPreferencesOptions}" ItemsSource="{x:Bind searchResultPreferencesOptions}"
SelectedItem="{x:Bind Mode=TwoWay, Path=SelectedSearchResultPreference}" SelectedItem="{x:Bind Mode=TwoWay, Path=SelectedSearchResultPreference}"
SelectedValuePath="Item2" SelectedValuePath="Item2"
DisplayMemberPath="Item1" DisplayMemberPath="Item1"
@ -65,7 +65,7 @@
<ComboBox x:Uid="PowerLauncher_SearchTypePreference" <ComboBox x:Uid="PowerLauncher_SearchTypePreference"
MinWidth="320" MinWidth="320"
Margin="{StaticResource SmallTopMargin}" Margin="{StaticResource SmallTopMargin}"
ItemsSource="{x:Bind SearchTypePreferencesOptions}" ItemsSource="{x:Bind searchTypePreferencesOptions}"
SelectedItem="{x:Bind Mode=TwoWay, Path=SelectedSearchTypePreference}" SelectedItem="{x:Bind Mode=TwoWay, Path=SelectedSearchTypePreference}"
SelectedValuePath="Item2" SelectedValuePath="Item2"
DisplayMemberPath="Item1" DisplayMemberPath="Item1"

View File

@ -1,63 +1,50 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.ViewModels;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Microsoft.PowerToys.Settings.UI.Controls;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views namespace Microsoft.PowerToys.Settings.UI.Views
{ {
public sealed partial class PowerLauncherPage : Page public sealed partial class PowerLauncherPage : Page
{ {
public PowerLauncherViewModel ViewModel { get; } = new PowerLauncherViewModel(); public PowerLauncherViewModel ViewModel { get; } = new PowerLauncherViewModel();
ObservableCollection<Tuple<string, string>> SearchResultPreferencesOptions;
ObservableCollection<Tuple<string, string>> SearchTypePreferencesOptions; private readonly ObservableCollection<Tuple<string, string>> searchResultPreferencesOptions;
private readonly ObservableCollection<Tuple<string, string>> searchTypePreferencesOptions;
public PowerLauncherPage() public PowerLauncherPage()
{ {
this.InitializeComponent(); this.InitializeComponent();
var loader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); var loader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
SearchResultPreferencesOptions = new ObservableCollection<Tuple<string, string>>();
SearchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_AlphabeticalOrder"), "alphabetical_order"));
SearchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_MostRecentlyUsed"), "most_recently_used"));
SearchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_RunningProcessesOpenApplications"), "running_processes_open_applications"));
SearchTypePreferencesOptions = new ObservableCollection<Tuple<string, string>>(); this.searchResultPreferencesOptions = new ObservableCollection<Tuple<string, string>>();
SearchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_ApplicationName"), "application_name")); this.searchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_AlphabeticalOrder"), "alphabetical_order"));
SearchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_StringInApplication"), "string_in_application")); this.searchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_MostRecentlyUsed"), "most_recently_used"));
SearchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_ExecutableName"), "executable_name")); this.searchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_RunningProcessesOpenApplications"), "running_processes_open_applications"));
this.searchTypePreferencesOptions = new ObservableCollection<Tuple<string, string>>();
this.searchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_ApplicationName"), "application_name"));
this.searchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_StringInApplication"), "string_in_application"));
this.searchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_ExecutableName"), "executable_name"));
} }
public Tuple<string, string> SelectedSearchResultPreference public Tuple<string, string> SelectedSearchResultPreference
{ {
get get
{ {
return SearchResultPreferencesOptions.First(item => item.Item2 == ViewModel.SearchResultPreference); return this.searchResultPreferencesOptions.First(item => item.Item2 == this.ViewModel.SearchResultPreference);
} }
set set
{ {
if (ViewModel.SearchResultPreference != value.Item2) if (this.ViewModel.SearchResultPreference != value.Item2)
{ {
ViewModel.SearchResultPreference = value.Item2; this.ViewModel.SearchResultPreference = value.Item2;
} }
} }
} }
@ -66,13 +53,14 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{ {
get get
{ {
return SearchTypePreferencesOptions.First(item => item.Item2 == ViewModel.SearchTypePreference); return this.searchTypePreferencesOptions.First(item => item.Item2 == this.ViewModel.SearchTypePreference);
} }
set set
{ {
if (ViewModel.SearchTypePreference != value.Item2) if (this.ViewModel.SearchTypePreference != value.Item2)
{ {
ViewModel.SearchTypePreference = value.Item2; this.ViewModel.SearchTypePreference = value.Item2;
} }
} }
} }

View File

@ -1,4 +1,8 @@
using Microsoft.PowerToys.Settings.UI.ViewModels; // 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; using Windows.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views namespace Microsoft.PowerToys.Settings.UI.Views

View File

@ -18,6 +18,7 @@ namespace WindowWalker.ViewModels
private readonly List<string> _hints = new List<string>() private readonly List<string> _hints = new List<string>()
{ {
"search for running processes or windows...", "search for running processes or windows...",
// "you can reinvoke this app using CTRL + WIN", // "you can reinvoke this app using CTRL + WIN",
}; };