added stylecop (#1933)

* added stylecop

* removed xml documentation

* used common stylecop file
This commit is contained in:
Lavius Motileng
2020-04-07 10:19:14 -07:00
parent 89b44f5126
commit cea6b7067a
53 changed files with 626 additions and 536 deletions

View File

@@ -194,8 +194,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.UI.Lib", "src\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj", "{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Settings.UI.Lib", "src\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj", "{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "src\core\Test\Test.csproj", "{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM Debug|ARM = Debug|ARM
@@ -652,14 +650,6 @@ Global
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|Any CPU.Build.0 = Release|Any CPU {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|Any CPU.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
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Debug|x64.ActiveCfg = Debug|Any CPU
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Debug|x64.Build.0 = Debug|Any CPU
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Release|Any CPU.Build.0 = Release|Any CPU
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Release|x64.ActiveCfg = Release|Any CPU
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -709,7 +699,6 @@ Global
{4EB9C181-96E2-4587-AB98-2DB84C1A2310} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {4EB9C181-96E2-4587-AB98-2DB84C1A2310} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{C073B057-B157-40F0-8678-1DCD119D841C} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {C073B057-B157-40F0-8678-1DCD119D841C} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}

View File

@@ -1,15 +1,20 @@
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.
using System.Text.Json; using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
public abstract class BasePTModuleSettings public abstract class BasePTModuleSettings
{ {
// Gets or sets name of the powertoy module.
public string name { get; set; } public string name { get; set; }
// Gets or sets the powertoys version.
public string version { get; set; } public string version { get; set; }
// converts the current to a json string.
public virtual string ToJsonString() public virtual string ToJsonString()
{ {
return JsonSerializer.Serialize(this); return JsonSerializer.Serialize(this);

View File

@@ -1,4 +1,8 @@
using System; // 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.Collections.Generic;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@@ -14,14 +18,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
return JsonSerializer.Serialize(this); return JsonSerializer.Serialize(this);
} }
} }
public class IntProperty
{
public int value { get; set; }
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
} }

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class Contributor
{
public string Name { get; set; }
public string Link { get; set; }
}
}

View File

@@ -1,27 +1,40 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
public class GeneralSettings public class GeneralSettings
{ {
public bool packaged { get; set; } // Gets or sets a value indicating whether packaged.
public bool Packaged { get; set; }
// Gets or sets a value indicating whether run powertoys on start-up.
public bool startup { get; set; } public bool startup { get; set; }
// Gets or sets a value indicating whether the powertoy elevated.
public bool is_elevated { get; set; } public bool is_elevated { get; set; }
// Gets or sets a value indicating whether powertoys should run elevated.
public bool run_elevated { get; set; } public bool run_elevated { get; set; }
// Gets or sets a value indicating whether is admin.
public bool is_admin { get; set; } public bool is_admin { get; set; }
// Gets or sets theme Name.
public string theme { get; set; } public string theme { get; set; }
// Gets or sets system theme name.
public string system_theme { get; set; } public string system_theme { get; set; }
// Gets or sets powertoys version number.
public string powertoys_version { get; set; } public string powertoys_version { get; set; }
public GeneralSettings() public GeneralSettings()
{ {
this.packaged = false; this.Packaged = false;
this.startup = false; this.startup = false;
this.is_admin = false; this.is_admin = false;
this.is_elevated = false; this.is_elevated = false;
@@ -30,29 +43,10 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
this.powertoys_version = "v0.15.3"; this.powertoys_version = "v0.15.3";
} }
// converts the current to a json string.
public string ToJsonString() public string ToJsonString()
{ {
return JsonSerializer.Serialize(this); return JsonSerializer.Serialize(this);
} }
} }
public class OutGoingGeneralSettings
{
public GeneralSettings general { get; set; }
public OutGoingGeneralSettings()
{
this.general = null;
}
public OutGoingGeneralSettings(GeneralSettings generalSettings)
{
this.general = generalSettings;
}
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
} }

View File

@@ -0,0 +1,10 @@
// 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.
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Element should not begin with upper-case letter to keep backward compatibilty with old settings.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Identifiers should contain underscores to keep backward compatibilty with old settings.")]

View File

@@ -1,4 +1,8 @@
using System; // 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.Collections.Generic;
using System.Text; using System.Text;
@@ -7,7 +11,9 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public interface IPowerToySettings public interface IPowerToySettings
{ {
string name { get; set; } string name { get; set; }
string version { get; set; } string version { get; set; }
string ToJsonString(); string ToJsonString();
} }
} }

View File

@@ -0,0 +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.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
// Represents the configuration property of the settings that store Integer type.
public class IntProperty
{
// Gets or sets the integer value of the settings configuration.
public int value { get; set; }
// Returns a JSON version of the class settings configuration class.
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -5,6 +5,16 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json" Link="StyleCop.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="4.7.1" /> <PackageReference Include="System.Text.Json" Version="4.7.1" />
</ItemGroup> </ItemGroup>

View File

@@ -0,0 +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;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class OutGoingGeneralSettings
{
public GeneralSettings general { get; set; }
public OutGoingGeneralSettings()
{
this.general = null;
}
public OutGoingGeneralSettings(GeneralSettings generalSettings)
{
this.general = generalSettings;
}
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -0,0 +1,30 @@
// 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 PowerPreviewProperties
{
public BoolProperty IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; }
public BoolProperty PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; }
public PowerPreviewProperties()
{
this.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL = new BoolProperty();
this.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID = new BoolProperty();
}
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -1,4 +1,8 @@
using System; // 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.Collections.Generic;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@@ -29,37 +33,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
return JsonSerializer.Serialize(this); return JsonSerializer.Serialize(this);
} }
} }
public class PowerPreviewProperties
{
public BoolProperty IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; }
public BoolProperty PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; }
public PowerPreviewProperties()
{
this.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL = new BoolProperty();
this.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID = new BoolProperty();
}
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
public class SndPowerPreviewSettings
{
[JsonPropertyName("File Explorer Preview")]
public PowerPreviewSettings File_Explorer_Preview { get; set; }
public SndPowerPreviewSettings(PowerPreviewSettings settings)
{
this.File_Explorer_Preview = settings;
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
} }

View File

@@ -0,0 +1,29 @@
// 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 PowerRenameProperties
{
public PowerRenameProperties()
{
this.bool_persist_input = new BoolProperty();
this.bool_mru_enabled = new BoolProperty();
this.int_max_mru_size = new IntProperty();
this.bool_show_icon_on_menu = new BoolProperty();
this.bool_show_extended_menu = new BoolProperty();
}
public BoolProperty bool_persist_input { get; set; }
public BoolProperty bool_mru_enabled { get; set; }
public IntProperty int_max_mru_size { get; set; }
public BoolProperty bool_show_icon_on_menu { get; set; }
public BoolProperty bool_show_extended_menu { get; set; }
}
}

View File

@@ -1,6 +1,7 @@
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.
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@@ -29,39 +30,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
return JsonSerializer.Serialize(this); return JsonSerializer.Serialize(this);
} }
} }
}
public class PowerRenameProperties
{
public PowerRenameProperties()
{
this.bool_persist_input = new BoolProperty();
this.bool_mru_enabled = new BoolProperty();
this.int_max_mru_size = new IntProperty();
this.bool_show_icon_on_menu = new BoolProperty();
this.bool_show_extended_menu = new BoolProperty();
}
public BoolProperty bool_persist_input { get; set; }
public BoolProperty bool_mru_enabled { get; set; }
public IntProperty int_max_mru_size { get; set; }
public BoolProperty bool_show_icon_on_menu { get; set; }
public BoolProperty bool_show_extended_menu { get; set; }
}
public class SndPowerRenameSettings
{
[JsonPropertyName("PowerRename")]
public PowerRenameSettings PowerRename { get; set; }
public SndPowerRenameSettings(PowerRenameSettings settings)
{
this.PowerRename = settings;
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -8,45 +8,34 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
public static class SettingsUtils public static class SettingsUtils
{ {
/// <summary> // Get path to the json settings file.
/// Get path to the json settings file.
/// </summary>
/// <returns>string path.</returns>
public static string GetSettingsPath(string powertoy) public static string GetSettingsPath(string powertoy)
{ {
if(string.IsNullOrWhiteSpace(powertoy)) if (string.IsNullOrWhiteSpace(powertoy))
{ {
return Path.Combine( return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
$"Microsoft\\PowerToys\\settings.json"); $"Microsoft\\PowerToys\\settings.json");
} }
return Path.Combine( return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
$"Microsoft\\PowerToys\\{powertoy}\\settings.json"); $"Microsoft\\PowerToys\\{powertoy}\\settings.json");
} }
/// <summary> // Get a Deserialized object of the json settings string.
/// Get a Deserialized object of the json settings string.
/// </summary>
/// <returns>Deserialized json settings object.</returns>
public static T GetSettings<T>(string powertoy) public static T GetSettings<T>(string powertoy)
{ {
var jsonSettingsString = System.IO.File.ReadAllText(SettingsUtils.GetSettingsPath(powertoy)); var jsonSettingsString = System.IO.File.ReadAllText(SettingsUtils.GetSettingsPath(powertoy));
return JsonSerializer.Deserialize<T>(jsonSettingsString); return JsonSerializer.Deserialize<T>(jsonSettingsString);
} }
/// <summary> // Save settings to a json file.
/// Save settings to a json file. public static void SaveSettings(string moduleJsonSettings, string powertoyModuleName)
/// </summary>
/// <param name="settings">dynamic json settings object.</param>
public static void SaveSettings(string jsonSettings, string powertoy)
{ {
if(jsonSettings != null) System.IO.File.WriteAllText(
{ SettingsUtils.GetSettingsPath(powertoyModuleName),
System.IO.File.WriteAllText( moduleJsonSettings);
SettingsUtils.GetSettingsPath(powertoy),
jsonSettings.ToString());
}
} }
} }
} }

View File

@@ -1,15 +1,19 @@
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.
using System.Text.Json; using System.Text.Json;
#pragma warning disable SA1649 // File name should match first type name
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
public class SndModuleSettings<S> // Represents a powertoys module settings setnt to the runner.
public class SndModuleSettings<T>
{ {
public S powertoys { get; set; } public T powertoys { get; set; }
public SndModuleSettings(S settings) public SndModuleSettings(T settings)
{ {
this.powertoys = settings; this.powertoys = settings;
} }

View File

@@ -0,0 +1,29 @@
// 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 SndPowerPreviewSettings
{
[JsonPropertyName("File Explorer Preview")]
public PowerPreviewSettings File_Explorer_Preview { get; set; }
public SndPowerPreviewSettings(PowerPreviewSettings settings)
{
this.File_Explorer_Preview = settings;
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -0,0 +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 SndPowerRenameSettings
{
[JsonPropertyName("PowerRename")]
public PowerRenameSettings PowerRename { get; set; }
public SndPowerRenameSettings(PowerRenameSettings settings)
{
this.PowerRename = settings;
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -5,7 +5,7 @@
using System; using System;
using System.Windows; using System.Windows;
using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.PowerToys.Settings.UI.Views;
using System.Threading; using Microsoft.Toolkit.Wpf.UI.XamlHost;
namespace Microsoft.PowerToys.Settings.UI.Runner namespace Microsoft.PowerToys.Settings.UI.Runner
{ {
@@ -26,16 +26,10 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
if (shellPage != null) if (shellPage != null)
{ {
// send IPC Message // send IPC Message
shellPage.SetDefaultSndMessageCallback(delegate (string msg) shellPage.SetDefaultSndMessageCallback(msg =>
{ {
Program.ipcmanager.SendMessage(msg); Program.GetTwoWayIPCManager().SendMessage(msg);
}); });
}
}
if (shellPage != null)
{
} }
} }
} }

View File

@@ -46,6 +46,10 @@
</COMReference> </COMReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json" Link="StyleCop.json" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\settingsui\Assets\logo.png"> <None Include="..\settingsui\Assets\logo.png">
<Pack>True</Pack> <Pack>True</Pack>

View File

@@ -16,20 +16,20 @@ namespace Microsoft.PowerToys.Settings.UI.Activation
internal abstract class ActivationHandler<T> : ActivationHandler internal abstract class ActivationHandler<T> : ActivationHandler
where T : class where T : class
{ {
// Override this method to add the activation logic in your activation handler
protected abstract Task HandleInternalAsync(T args);
public override async Task HandleAsync(object args) public override async Task HandleAsync(object args)
{ {
await HandleInternalAsync(args as T); await this.HandleInternalAsync(args as T);
} }
public override bool CanHandle(object args) public override bool CanHandle(object args)
{ {
// CanHandle checks the args is of type you have configured // CanHandle checks the args is of type you have configured
return args is T && CanHandleInternal(args as T); return args is T && this.CanHandleInternal(args as T);
} }
// Override this method to add the activation logic in your activation handler
protected abstract Task HandleInternalAsync(T args);
// You can override this method to add extra validation on activation args // You can override this method to add extra validation on activation args
// to determine if your ActivationHandler should handle this activation args // to determine if your ActivationHandler should handle this activation args
protected virtual bool CanHandleInternal(T args) protected virtual bool CanHandleInternal(T args)

View File

@@ -1,19 +1,21 @@
using System; // 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.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.PowerToys.Settings.UI.Services; using Microsoft.PowerToys.Settings.UI.Services;
using Windows.ApplicationModel.Activation; using Windows.ApplicationModel.Activation;
namespace Microsoft.PowerToys.Settings.UI.Activation namespace Microsoft.PowerToys.Settings.UI.Activation
{ {
internal class DefaultActivationHandler : ActivationHandler<IActivatedEventArgs> internal class DefaultActivationHandler : ActivationHandler<IActivatedEventArgs>
{ {
private readonly Type _navElement; private readonly Type navElement;
public DefaultActivationHandler(Type navElement) public DefaultActivationHandler(Type navElement)
{ {
_navElement = navElement; this.navElement = navElement;
} }
protected override async Task HandleInternalAsync(IActivatedEventArgs args) protected override async Task HandleInternalAsync(IActivatedEventArgs args)
@@ -26,14 +28,14 @@ namespace Microsoft.PowerToys.Settings.UI.Activation
arguments = launchArgs.Arguments; arguments = launchArgs.Arguments;
} }
NavigationService.Navigate(_navElement, arguments); NavigationService.Navigate(this.navElement, arguments);
await Task.CompletedTask; await Task.CompletedTask;
} }
protected override bool CanHandleInternal(IActivatedEventArgs args) protected override bool CanHandleInternal(IActivatedEventArgs args)
{ {
// None of the ActivationHandlers has handled the app activation // None of the ActivationHandlers has handled the app activation
return NavigationService.Frame.Content == null && _navElement != null; return NavigationService.Frame.Content == null && this.navElement != null;
} }
} }
} }

View File

@@ -11,18 +11,18 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
{ {
public class NavigationViewHeaderBehavior : Behavior<WinUI.NavigationView> public class NavigationViewHeaderBehavior : Behavior<WinUI.NavigationView>
{ {
private static NavigationViewHeaderBehavior _current; private static NavigationViewHeaderBehavior current;
private Page _currentPage; private Page currentPage;
public DataTemplate DefaultHeaderTemplate { get; set; } public DataTemplate DefaultHeaderTemplate { get; set; }
public object DefaultHeader public object DefaultHeader
{ {
get { return GetValue(DefaultHeaderProperty); } get { return this.GetValue(DefaultHeaderProperty); }
set { SetValue(DefaultHeaderProperty, value); } set { this.SetValue(DefaultHeaderProperty, value); }
} }
public static readonly DependencyProperty DefaultHeaderProperty = DependencyProperty.Register("DefaultHeader", typeof(object), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(null, (d, e) => _current.UpdateHeader())); public static readonly DependencyProperty DefaultHeaderProperty = DependencyProperty.Register("DefaultHeader", typeof(object), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(null, (d, e) => current.UpdateHeader()));
public static NavigationViewHeaderMode GetHeaderMode(Page item) public static NavigationViewHeaderMode GetHeaderMode(Page item)
{ {
@@ -35,7 +35,7 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
} }
public static readonly DependencyProperty HeaderModeProperty = public static readonly DependencyProperty HeaderModeProperty =
DependencyProperty.RegisterAttached("HeaderMode", typeof(bool), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(NavigationViewHeaderMode.Always, (d, e) => _current.UpdateHeader())); DependencyProperty.RegisterAttached("HeaderMode", typeof(bool), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(NavigationViewHeaderMode.Always, (d, e) => current.UpdateHeader()));
public static object GetHeaderContext(Page item) public static object GetHeaderContext(Page item)
{ {
@@ -48,7 +48,7 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
} }
public static readonly DependencyProperty HeaderContextProperty = public static readonly DependencyProperty HeaderContextProperty =
DependencyProperty.RegisterAttached("HeaderContext", typeof(object), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(null, (d, e) => _current.UpdateHeader())); DependencyProperty.RegisterAttached("HeaderContext", typeof(object), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(null, (d, e) => current.UpdateHeader()));
public static DataTemplate GetHeaderTemplate(Page item) public static DataTemplate GetHeaderTemplate(Page item)
{ {
@@ -61,19 +61,19 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
} }
public static readonly DependencyProperty HeaderTemplateProperty = public static readonly DependencyProperty HeaderTemplateProperty =
DependencyProperty.RegisterAttached("HeaderTemplate", typeof(DataTemplate), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(null, (d, e) => _current.UpdateHeaderTemplate())); DependencyProperty.RegisterAttached("HeaderTemplate", typeof(DataTemplate), typeof(NavigationViewHeaderBehavior), new PropertyMetadata(null, (d, e) => current.UpdateHeaderTemplate()));
protected override void OnAttached() protected override void OnAttached()
{ {
base.OnAttached(); base.OnAttached();
_current = this; current = this;
NavigationService.Navigated += OnNavigated; NavigationService.Navigated += this.OnNavigated;
} }
protected override void OnDetaching() protected override void OnDetaching()
{ {
base.OnDetaching(); base.OnDetaching();
NavigationService.Navigated -= OnNavigated; NavigationService.Navigated -= this.OnNavigated;
} }
private void OnNavigated(object sender, NavigationEventArgs e) private void OnNavigated(object sender, NavigationEventArgs e)
@@ -81,42 +81,42 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
var frame = sender as Frame; var frame = sender as Frame;
if (frame.Content is Page page) if (frame.Content is Page page)
{ {
_currentPage = page; this.currentPage = page;
UpdateHeader(); this.UpdateHeader();
UpdateHeaderTemplate(); this.UpdateHeaderTemplate();
} }
} }
private void UpdateHeader() private void UpdateHeader()
{ {
if (_currentPage != null) if (this.currentPage != null)
{ {
var headerMode = GetHeaderMode(_currentPage); var headerMode = GetHeaderMode(this.currentPage);
if (headerMode == NavigationViewHeaderMode.Never) if (headerMode == NavigationViewHeaderMode.Never)
{ {
AssociatedObject.Header = null; this.AssociatedObject.Header = null;
AssociatedObject.AlwaysShowHeader = false; this.AssociatedObject.AlwaysShowHeader = false;
} }
else else
{ {
var headerFromPage = GetHeaderContext(_currentPage); var headerFromPage = GetHeaderContext(this.currentPage);
if (headerFromPage != null) if (headerFromPage != null)
{ {
AssociatedObject.Header = headerFromPage; this.AssociatedObject.Header = headerFromPage;
} }
else else
{ {
AssociatedObject.Header = DefaultHeader; this.AssociatedObject.Header = this.DefaultHeader;
} }
if (headerMode == NavigationViewHeaderMode.Always) if (headerMode == NavigationViewHeaderMode.Always)
{ {
AssociatedObject.AlwaysShowHeader = true; this.AssociatedObject.AlwaysShowHeader = true;
} }
else else
{ {
AssociatedObject.AlwaysShowHeader = false; this.AssociatedObject.AlwaysShowHeader = false;
} }
} }
} }
@@ -124,10 +124,10 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
private void UpdateHeaderTemplate() private void UpdateHeaderTemplate()
{ {
if (_currentPage != null) if (this.currentPage != null)
{ {
var headerTemplate = GetHeaderTemplate(_currentPage); var headerTemplate = GetHeaderTemplate(this.currentPage);
AssociatedObject.HeaderTemplate = headerTemplate ?? DefaultHeaderTemplate; this.AssociatedObject.HeaderTemplate = headerTemplate ?? this.DefaultHeaderTemplate;
} }
} }
} }

View File

@@ -4,6 +4,6 @@
{ {
Always, Always,
Never, Never,
Minimal Minimal,
} }
} }

View File

@@ -1,24 +0,0 @@
<UserControl
x:Class="Microsoft.PowerToys.Settings.UI.Controls.DummyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<NavigationView x:Name="nvSample" PaneDisplayMode="Left">
<NavigationView.MenuItems>
<NavigationViewItem Icon="Play" Content="Menu Item1" Tag="SamplePage1" />
<NavigationViewItem Icon="Save" Content="Menu Item2" Tag="SamplePage2" />
<NavigationViewItem Icon="Refresh" Content="Menu Item3" Tag="SamplePage3" />
<NavigationViewItem Icon="Download" Content="Menu Item4" Tag="SamplePage4" />
</NavigationView.MenuItems>
<Frame x:Name="contentFrame"/>
</NavigationView>
</Grid>
</UserControl>

View File

@@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
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;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace Microsoft.PowerToys.Settings.UI.Controls
{
public sealed partial class DummyUserControl : UserControl
{
public string XamlIslandMessage { get; set; }
public DummyUserControl()
{
this.InitializeComponent();
}
}
}

View File

@@ -0,0 +1,6 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Classes contain the same name and creating a separate file would result in a new with '1 appended")]

View File

@@ -1,7 +1,9 @@
using System; // 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.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Windows.UI.Xaml; using Windows.UI.Xaml;
namespace Microsoft.PowerToys.Settings.UI.Helpers namespace Microsoft.PowerToys.Settings.UI.Helpers

View File

@@ -16,9 +16,9 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
} }
storage = value; storage = value;
OnPropertyChanged(propertyName); this.OnPropertyChanged(propertyName);
} }
protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); protected void OnPropertyChanged(string propertyName) => this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
} }

View File

@@ -5,9 +5,9 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
{ {
public class RelayCommand : ICommand public class RelayCommand : ICommand
{ {
private readonly Action _execute; private readonly Action execute;
private readonly Func<bool> _canExecute; private readonly Func<bool> canExecute;
public event EventHandler CanExecuteChanged; public event EventHandler CanExecuteChanged;
@@ -18,22 +18,22 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
public RelayCommand(Action execute, Func<bool> canExecute) public RelayCommand(Action execute, Func<bool> canExecute)
{ {
_execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
_canExecute = canExecute; this.canExecute = canExecute;
} }
public bool CanExecute(object parameter) => _canExecute == null || _canExecute(); public bool CanExecute(object parameter) => this.canExecute == null || this.canExecute();
public void Execute(object parameter) => _execute(); public void Execute(object parameter) => this.execute();
public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty); public void OnCanExecuteChanged() => this.CanExecuteChanged?.Invoke(this, EventArgs.Empty);
} }
public class RelayCommand<T> : ICommand public class RelayCommand<T> : ICommand
{ {
private readonly Action<T> _execute; private readonly Action<T> execute;
private readonly Func<T, bool> _canExecute; private readonly Func<T, bool> canExecute;
public event EventHandler CanExecuteChanged; public event EventHandler CanExecuteChanged;
@@ -44,14 +44,14 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
public RelayCommand(Action<T> execute, Func<T, bool> canExecute) public RelayCommand(Action<T> execute, Func<T, bool> canExecute)
{ {
_execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
_canExecute = canExecute; this.canExecute = canExecute;
} }
public bool CanExecute(object parameter) => _canExecute == null || _canExecute((T)parameter); public bool CanExecute(object parameter) => this.canExecute == null || this.canExecute((T)parameter);
public void Execute(object parameter) => _execute((T)parameter); public void Execute(object parameter) => this.execute((T)parameter);
public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty); public void OnCanExecuteChanged() => this.CanExecuteChanged?.Invoke(this, EventArgs.Empty);
} }
} }

View File

@@ -1,4 +1,8 @@
using System; // 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.Runtime.InteropServices; using System.Runtime.InteropServices;
using Windows.ApplicationModel.Resources; using Windows.ApplicationModel.Resources;
@@ -7,11 +11,11 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
{ {
internal static class ResourceExtensions internal static class ResourceExtensions
{ {
private static ResourceLoader _resLoader = new ResourceLoader(); private static readonly ResourceLoader ResLoader = new ResourceLoader();
public static string GetLocalized(this string resourceKey) public static string GetLocalized(this string resourceKey)
{ {
return _resLoader.GetString(resourceKey); return ResLoader.GetString(resourceKey);
} }
} }
} }

View File

@@ -123,9 +123,7 @@
</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\DummyUserControl.xaml.cs"> <Compile Include="GlobalSuppressions.cs" />
<DependentUpon>DummyUserControl.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\NavHelper.cs" /> <Compile Include="Helpers\NavHelper.cs" />
<Compile Include="Helpers\Observable.cs" /> <Compile Include="Helpers\Observable.cs" />
<Compile Include="Helpers\RelayCommand.cs" /> <Compile Include="Helpers\RelayCommand.cs" />
@@ -197,15 +195,16 @@
<PackageReference Include="Newtonsoft.Json"> <PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version> <Version>12.0.3</Version>
</PackageReference> </PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PRIResource Include="Strings\en-us\Resources.resw" /> <PRIResource Include="Strings\en-us\Resources.resw" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Include="Controls\DummyUserControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</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>
@@ -269,6 +268,11 @@
<Name>Microsoft.PowerToys.Settings.UI.Lib</Name> <Name>Microsoft.PowerToys.Settings.UI.Lib</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' "> <PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion> <VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup> </PropertyGroup>

View File

@@ -1,4 +1,8 @@
using System; // 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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -15,48 +19,48 @@ namespace Microsoft.PowerToys.Settings.UI.Services
// https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md // https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md
internal class ActivationService internal class ActivationService
{ {
private readonly App _app; private readonly App app;
private readonly Type _defaultNavItem; private readonly Type defaultNavItem;
private Lazy<UIElement> _shell; private Lazy<UIElement> shell;
private object _lastActivationArgs; private object lastActivationArgs;
public ActivationService(App app, Type defaultNavItem, Lazy<UIElement> shell = null) public ActivationService(App app, Type defaultNavItem, Lazy<UIElement> shell = null)
{ {
_app = app; this.app = app;
_shell = shell; this.shell = shell;
_defaultNavItem = defaultNavItem; this.defaultNavItem = defaultNavItem;
} }
public async Task ActivateAsync(object activationArgs) public async Task ActivateAsync(object activationArgs)
{ {
if (IsInteractive(activationArgs)) if (this.IsInteractive(activationArgs))
{ {
// Initialize services that you need before app activation // Initialize services that you need before app activation
// take into account that the splash screen is shown while this code runs. // take into account that the splash screen is shown while this code runs.
await InitializeAsync(); await this.InitializeAsync();
// Do not repeat app initialization when the Window already has content, // Do not repeat app initialization when the Window already has content,
// just ensure that the window is active // just ensure that the window is active
if (Window.Current.Content == null) if (Window.Current.Content == null)
{ {
// Create a Shell or Frame to act as the navigation context // Create a Shell or Frame to act as the navigation context
Window.Current.Content = _shell?.Value ?? new Frame(); Window.Current.Content = this.shell?.Value ?? new Frame();
} }
} }
// Depending on activationArgs one of ActivationHandlers or DefaultActivationHandler // Depending on activationArgs one of ActivationHandlers or DefaultActivationHandler
// will navigate to the first page // will navigate to the first page
await HandleActivationAsync(activationArgs); await this.HandleActivationAsync(activationArgs);
_lastActivationArgs = activationArgs; this.lastActivationArgs = activationArgs;
if (IsInteractive(activationArgs)) if (this.IsInteractive(activationArgs))
{ {
// Ensure the current window is active // Ensure the current window is active
Window.Current.Activate(); Window.Current.Activate();
// Tasks after activation // Tasks after activation
await StartupAsync(); await this.StartupAsync();
} }
} }
@@ -67,7 +71,7 @@ namespace Microsoft.PowerToys.Settings.UI.Services
private async Task HandleActivationAsync(object activationArgs) private async Task HandleActivationAsync(object activationArgs)
{ {
var activationHandler = GetActivationHandlers() var activationHandler = this.GetActivationHandlers()
.FirstOrDefault(h => h.CanHandle(activationArgs)); .FirstOrDefault(h => h.CanHandle(activationArgs));
if (activationHandler != null) if (activationHandler != null)
@@ -75,9 +79,9 @@ namespace Microsoft.PowerToys.Settings.UI.Services
await activationHandler.HandleAsync(activationArgs); await activationHandler.HandleAsync(activationArgs);
} }
if (IsInteractive(activationArgs)) if (this.IsInteractive(activationArgs))
{ {
var defaultHandler = new DefaultActivationHandler(_defaultNavItem); var defaultHandler = new DefaultActivationHandler(this.defaultNavItem);
if (defaultHandler.CanHandle(activationArgs)) if (defaultHandler.CanHandle(activationArgs))
{ {
await defaultHandler.HandleAsync(activationArgs); await defaultHandler.HandleAsync(activationArgs);

View File

@@ -1,5 +1,8 @@
using System; // 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 Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation; using Windows.UI.Xaml.Media.Animation;
@@ -13,26 +16,26 @@ namespace Microsoft.PowerToys.Settings.UI.Services
public static event NavigationFailedEventHandler NavigationFailed; public static event NavigationFailedEventHandler NavigationFailed;
private static Frame _frame; private static Frame frame;
private static object _lastParamUsed; private static object lastParamUsed;
public static Frame Frame public static Frame Frame
{ {
get get
{ {
if (_frame == null) if (frame == null)
{ {
_frame = Window.Current.Content as Frame; frame = Window.Current.Content as Frame;
RegisterFrameEvents(); RegisterFrameEvents();
} }
return _frame; return frame;
} }
set set
{ {
UnregisterFrameEvents(); UnregisterFrameEvents();
_frame = value; frame = value;
RegisterFrameEvents(); RegisterFrameEvents();
} }
} }
@@ -57,12 +60,12 @@ namespace Microsoft.PowerToys.Settings.UI.Services
public static bool Navigate(Type pageType, object parameter = null, NavigationTransitionInfo infoOverride = null) public static bool Navigate(Type pageType, object parameter = null, NavigationTransitionInfo infoOverride = null)
{ {
// Don't open the same page multiple times // Don't open the same page multiple times
if (Frame.Content?.GetType() != pageType || (parameter != null && !parameter.Equals(_lastParamUsed))) if (Frame.Content?.GetType() != pageType || (parameter != null && !parameter.Equals(lastParamUsed)))
{ {
var navigationResult = Frame.Navigate(pageType, parameter, infoOverride); var navigationResult = Frame.Navigate(pageType, parameter, infoOverride);
if (navigationResult) if (navigationResult)
{ {
_lastParamUsed = parameter; lastParamUsed = parameter;
} }
return navigationResult; return navigationResult;
@@ -79,19 +82,19 @@ namespace Microsoft.PowerToys.Settings.UI.Services
private static void RegisterFrameEvents() private static void RegisterFrameEvents()
{ {
if (_frame != null) if (frame != null)
{ {
_frame.Navigated += Frame_Navigated; frame.Navigated += Frame_Navigated;
_frame.NavigationFailed += Frame_NavigationFailed; frame.NavigationFailed += Frame_NavigationFailed;
} }
} }
private static void UnregisterFrameEvents() private static void UnregisterFrameEvents()
{ {
if (_frame != null) if (frame != null)
{ {
_frame.Navigated -= Frame_Navigated; frame.Navigated -= Frame_Navigated;
_frame.NavigationFailed -= Frame_NavigationFailed; frame.NavigationFailed -= Frame_NavigationFailed;
} }
} }

View File

@@ -1,4 +1,6 @@
using System; // 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.Helpers; using Microsoft.PowerToys.Settings.UI.Helpers;

View File

@@ -1,5 +1,7 @@
using System; // Copyright (c) Microsoft Corporation
using System.IO; // 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.Helpers; using Microsoft.PowerToys.Settings.UI.Helpers;
namespace Microsoft.PowerToys.Settings.UI.ViewModels namespace Microsoft.PowerToys.Settings.UI.ViewModels

View File

@@ -1,4 +1,6 @@
using System; // 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.Helpers; using Microsoft.PowerToys.Settings.UI.Helpers;

View File

@@ -1,4 +1,6 @@
using System; // 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.Helpers; using Microsoft.PowerToys.Settings.UI.Helpers;

View File

@@ -1,4 +1,6 @@
using System; // 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.Helpers; using Microsoft.PowerToys.Settings.UI.Helpers;

View File

@@ -1,50 +1,50 @@
// <copyright file="ShellViewModel.cs" company="Microsoft Corp"> // Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corp. All rights reserved. // The Microsoft Corporation licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Services;
using Windows.System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using WinUI = Microsoft.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.ViewModels namespace Microsoft.PowerToys.Settings.UI.ViewModels
{ {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Services;
using Windows.System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using WinUI = Microsoft.UI.Xaml.Controls;
public class ShellViewModel : Observable public class ShellViewModel : Observable
{ {
private readonly KeyboardAccelerator _altLeftKeyboardAccelerator = BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu); private readonly KeyboardAccelerator altLeftKeyboardAccelerator = BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu);
private readonly KeyboardAccelerator _backKeyboardAccelerator = BuildKeyboardAccelerator(VirtualKey.GoBack); private readonly KeyboardAccelerator backKeyboardAccelerator = BuildKeyboardAccelerator(VirtualKey.GoBack);
private bool _isBackEnabled; private bool isBackEnabled;
private IList<KeyboardAccelerator> _keyboardAccelerators; private IList<KeyboardAccelerator> keyboardAccelerators;
private WinUI.NavigationView _navigationView; private WinUI.NavigationView navigationView;
private WinUI.NavigationViewItem _selected; private WinUI.NavigationViewItem selected;
private ICommand _loadedCommand; private ICommand loadedCommand;
private ICommand _itemInvokedCommand; private ICommand itemInvokedCommand;
public bool IsBackEnabled public bool IsBackEnabled
{ {
get { return _isBackEnabled; } get { return this.isBackEnabled; }
set { Set(ref _isBackEnabled, value); } set { this.Set(ref this.isBackEnabled, value); }
} }
public WinUI.NavigationViewItem Selected public WinUI.NavigationViewItem Selected
{ {
get { return _selected; } get { return this.selected; }
set { Set(ref _selected, value); } set { this.Set(ref this.selected, value); }
} }
public ICommand LoadedCommand => _loadedCommand ?? (_loadedCommand = new RelayCommand(OnLoaded)); public ICommand LoadedCommand => this.loadedCommand ?? (this.loadedCommand = new RelayCommand(this.OnLoaded));
public ICommand ItemInvokedCommand => _itemInvokedCommand ?? (_itemInvokedCommand = new RelayCommand<WinUI.NavigationViewItemInvokedEventArgs>(OnItemInvoked)); public ICommand ItemInvokedCommand => this.itemInvokedCommand ?? (this.itemInvokedCommand = new RelayCommand<WinUI.NavigationViewItemInvokedEventArgs>(this.OnItemInvoked));
public ShellViewModel() public ShellViewModel()
{ {
@@ -52,54 +52,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public void Initialize(Frame frame, WinUI.NavigationView navigationView, IList<KeyboardAccelerator> keyboardAccelerators) public void Initialize(Frame frame, WinUI.NavigationView navigationView, IList<KeyboardAccelerator> keyboardAccelerators)
{ {
_navigationView = navigationView; this.navigationView = navigationView;
_keyboardAccelerators = keyboardAccelerators; this.keyboardAccelerators = keyboardAccelerators;
NavigationService.Frame = frame; NavigationService.Frame = frame;
NavigationService.NavigationFailed += Frame_NavigationFailed; NavigationService.NavigationFailed += this.Frame_NavigationFailed;
NavigationService.Navigated += Frame_Navigated; NavigationService.Navigated += this.Frame_Navigated;
_navigationView.BackRequested += OnBackRequested; this.navigationView.BackRequested += this.OnBackRequested;
}
private async void OnLoaded()
{
// Keyboard accelerators are added here to avoid showing 'Alt + left' tooltip on the page.
// More info on tracking issue https://github.com/Microsoft/microsoft-ui-xaml/issues/8
_keyboardAccelerators.Add(_altLeftKeyboardAccelerator);
_keyboardAccelerators.Add(_backKeyboardAccelerator);
await Task.CompletedTask;
}
private void OnItemInvoked(WinUI.NavigationViewItemInvokedEventArgs args)
{
var item = _navigationView.MenuItems
.OfType<WinUI.NavigationViewItem>()
.First(menuItem => (string)menuItem.Content == (string)args.InvokedItem);
var pageType = item.GetValue(NavHelper.NavigateToProperty) as Type;
NavigationService.Navigate(pageType);
}
private void OnBackRequested(WinUI.NavigationView sender, WinUI.NavigationViewBackRequestedEventArgs args)
{
NavigationService.GoBack();
}
private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw e.Exception;
}
private void Frame_Navigated(object sender, NavigationEventArgs e)
{
IsBackEnabled = NavigationService.CanGoBack;
Selected = _navigationView.MenuItems
.OfType<WinUI.NavigationViewItem>()
.FirstOrDefault(menuItem => IsMenuItemForPageType(menuItem, e.SourcePageType));
}
private bool IsMenuItemForPageType(WinUI.NavigationViewItem menuItem, Type sourcePageType)
{
var pageType = menuItem.GetValue(NavHelper.NavigateToProperty) as Type;
return pageType == sourcePageType;
} }
private static KeyboardAccelerator BuildKeyboardAccelerator(VirtualKey key, VirtualKeyModifiers? modifiers = null) private static KeyboardAccelerator BuildKeyboardAccelerator(VirtualKey key, VirtualKeyModifiers? modifiers = null)
@@ -119,5 +77,47 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
var result = NavigationService.GoBack(); var result = NavigationService.GoBack();
args.Handled = result; args.Handled = result;
} }
private async void OnLoaded()
{
// Keyboard accelerators are added here to avoid showing 'Alt + left' tooltip on the page.
// More info on tracking issue https://github.com/Microsoft/microsoft-ui-xaml/issues/8
this.keyboardAccelerators.Add(this.altLeftKeyboardAccelerator);
this.keyboardAccelerators.Add(this.backKeyboardAccelerator);
await Task.CompletedTask;
}
private void OnItemInvoked(WinUI.NavigationViewItemInvokedEventArgs args)
{
var item = this.navigationView.MenuItems
.OfType<WinUI.NavigationViewItem>()
.First(menuItem => (string)menuItem.Content == (string)args.InvokedItem);
var pageType = item.GetValue(NavHelper.NavigateToProperty) as Type;
NavigationService.Navigate(pageType);
}
private void OnBackRequested(WinUI.NavigationView sender, WinUI.NavigationViewBackRequestedEventArgs args)
{
NavigationService.GoBack();
}
private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw e.Exception;
}
private void Frame_Navigated(object sender, NavigationEventArgs e)
{
this.IsBackEnabled = NavigationService.CanGoBack;
this.Selected = this.navigationView.MenuItems
.OfType<WinUI.NavigationViewItem>()
.FirstOrDefault(menuItem => this.IsMenuItemForPageType(menuItem, e.SourcePageType));
}
private bool IsMenuItemForPageType(WinUI.NavigationViewItem menuItem, Type sourcePageType)
{
var pageType = menuItem.GetValue(NavHelper.NavigateToProperty) as Type;
return pageType == sourcePageType;
}
} }
} }

View File

@@ -1,4 +1,7 @@
using System; // 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.Helpers; using Microsoft.PowerToys.Settings.UI.Helpers;
namespace Microsoft.PowerToys.Settings.UI.ViewModels namespace Microsoft.PowerToys.Settings.UI.ViewModels

View File

@@ -1,9 +1,13 @@
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 System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime; using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.Foundation; using Windows.Foundation;
using Windows.Foundation.Collections; using Windows.Foundation.Collections;
using Windows.UI.Xaml; using Windows.UI.Xaml;

View File

@@ -1,19 +1,19 @@
// <copyright file="GeneralPage.xaml.cs" company="Microsoft Corp"> // Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corp. All rights reserved. // The Microsoft Corporation licenses this file to you under the MIT license.
// </copyright> // See the LICENSE file in the project root for more information.
using System;
using System.IO;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.System;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace Microsoft.PowerToys.Settings.UI.Views namespace Microsoft.PowerToys.Settings.UI.Views
{ {
using System;
using System.IO;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.System;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
/// <summary> /// <summary>
/// General Settings Page. /// General Settings Page.
/// </summary> /// </summary>
@@ -32,7 +32,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{ {
this.InitializeComponent(); this.InitializeComponent();
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedTo(NavigationEventArgs e)
{ {
@@ -42,17 +42,19 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{ {
// get settings file if they exist. // get settings file if they exist.
settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty); settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
// load and apply theme settings // load and apply theme settings
this.ReLoadTheme(settings.theme); this.ReLoadTheme(settings.theme);
// load run on start-up settings value and update the ui state. // load run on start-up settings value and update the ui state.
this.ToggleSwitch_RunAtStartUp.IsOn = settings.startup; this.ToggleSwitch_RunAtStartUp.IsOn = settings.startup;
} }
catch (Exception exp) catch
{ {
// create settings file if one is not found. // create settings file if one is not found.
settings = new GeneralSettings(); settings = new GeneralSettings();
SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty); SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty);
// load and apply theme settings // load and apply theme settings
this.ReLoadTheme(settings.theme); this.ReLoadTheme(settings.theme);
@@ -106,9 +108,9 @@ namespace Microsoft.PowerToys.Settings.UI.Views
SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty); SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty);
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings); OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
if (ShellPage.Default_SndMSG_Callback != null) if (ShellPage.DefaultSndMSGCallback != null)
{ {
ShellPage.Default_SndMSG_Callback(outsettings.ToString()); ShellPage.DefaultSndMSGCallback(outsettings.ToString());
} }
} }
} }
@@ -119,9 +121,9 @@ namespace Microsoft.PowerToys.Settings.UI.Views
settings.run_elevated = true; settings.run_elevated = true;
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings); OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
if (ShellPage.Default_SndMSG_Callback != null) if (ShellPage.DefaultSndMSGCallback != null)
{ {
ShellPage.Default_SndMSG_Callback(outsettings.ToString()); ShellPage.DefaultSndMSGCallback(outsettings.ToString());
} }
} }

View File

@@ -1,9 +1,13 @@
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 System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime; using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.Foundation; using Windows.Foundation;
using Windows.Foundation.Collections; using Windows.Foundation.Collections;
using Windows.UI.Xaml; using Windows.UI.Xaml;

View File

@@ -1,9 +1,13 @@
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 System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime; using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.Foundation; using Windows.Foundation;
using Windows.Foundation.Collections; using Windows.Foundation.Collections;
using Windows.UI.Xaml; using Windows.UI.Xaml;

View File

@@ -1,23 +1,13 @@
using Microsoft.PowerToys.Settings.UI.Lib; // 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;
using System.Collections.Generic; using Microsoft.PowerToys.Settings.UI.Lib;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.ServiceModel.Channels;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
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.Media;
using Windows.UI.Xaml.Navigation; using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace Microsoft.PowerToys.Settings.UI.Views namespace Microsoft.PowerToys.Settings.UI.Views
{ {
/// <summary> /// <summary>
@@ -40,15 +30,15 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{ {
base.OnNavigatedTo(e); base.OnNavigatedTo(e);
settings = SettingsUtils.GetSettings<PowerPreviewSettings>(POWERTOY_NAME); settings = SettingsUtils.GetSettings<PowerPreviewSettings>(POWERTOY_NAME);
ToggleSwitch_Preview_SVG.IsOn = settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.value; this.ToggleSwitch_Preview_SVG.IsOn = settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.value;
ToggleSwitch_Preview_MD.IsOn = settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.value; this.ToggleSwitch_Preview_MD.IsOn = settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.value;
} }
catch(Exception exp) catch
{ {
settings = new PowerPreviewSettings(POWERTOY_NAME); settings = new PowerPreviewSettings(POWERTOY_NAME);
SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOY_NAME); SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOY_NAME);
ToggleSwitch_Preview_SVG.IsOn = settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.value; this.ToggleSwitch_Preview_SVG.IsOn = settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.value;
ToggleSwitch_Preview_MD.IsOn = settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.value; this.ToggleSwitch_Preview_MD.IsOn = settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.value;
} }
} }
@@ -61,11 +51,11 @@ namespace Microsoft.PowerToys.Settings.UI.Views
PowerPreviewSettings settings = SettingsUtils.GetSettings<PowerPreviewSettings>(POWERTOY_NAME); PowerPreviewSettings settings = SettingsUtils.GetSettings<PowerPreviewSettings>(POWERTOY_NAME);
settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.value = swt.IsOn; settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.value = swt.IsOn;
if (ShellPage.Default_SndMSG_Callback != null) if (ShellPage.DefaultSndMSGCallback != null)
{ {
SndPowerPreviewSettings snd = new SndPowerPreviewSettings(settings); SndPowerPreviewSettings snd = new SndPowerPreviewSettings(settings);
SndModuleSettings<SndPowerPreviewSettings> ipcMessage = new SndModuleSettings<SndPowerPreviewSettings>(snd); SndModuleSettings<SndPowerPreviewSettings> ipcMessage = new SndModuleSettings<SndPowerPreviewSettings>(snd);
ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
} }
} }
} }
@@ -79,11 +69,11 @@ namespace Microsoft.PowerToys.Settings.UI.Views
PowerPreviewSettings settings = SettingsUtils.GetSettings<PowerPreviewSettings>(POWERTOY_NAME); PowerPreviewSettings settings = SettingsUtils.GetSettings<PowerPreviewSettings>(POWERTOY_NAME);
settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.value = swt.IsOn; settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.value = swt.IsOn;
if (ShellPage.Default_SndMSG_Callback != null) if (ShellPage.DefaultSndMSGCallback != null)
{ {
SndPowerPreviewSettings snd = new SndPowerPreviewSettings(settings); SndPowerPreviewSettings snd = new SndPowerPreviewSettings(settings);
SndModuleSettings<SndPowerPreviewSettings> ipcMessage = new SndModuleSettings<SndPowerPreviewSettings>(snd); SndModuleSettings<SndPowerPreviewSettings> ipcMessage = new SndModuleSettings<SndPowerPreviewSettings>(snd);
ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
} }
} }
} }

View File

@@ -1,21 +1,13 @@
using Microsoft.PowerToys.Settings.UI.Lib; // 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 Microsoft.PowerToys.Settings.UI.ViewModels; using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.ServiceModel.Channels;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
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.Media;
using Windows.UI.Xaml.Navigation; using Windows.UI.Xaml.Navigation;
namespace Microsoft.PowerToys.Settings.UI.Views namespace Microsoft.PowerToys.Settings.UI.Views
@@ -23,7 +15,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
public sealed partial class PowerRenamePage : Page public sealed partial class PowerRenamePage : Page
{ {
public PowerRenameViewModel ViewModel { get; } = new PowerRenameViewModel(); public PowerRenameViewModel ViewModel { get; } = new PowerRenameViewModel();
private const string POWERTOY_NAME = "PowerRename";
private const string POWERTOYNAME = "PowerRename";
public PowerRenamePage() public PowerRenamePage()
{ {
@@ -37,18 +30,17 @@ namespace Microsoft.PowerToys.Settings.UI.Views
PowerRenameSettings settings; PowerRenameSettings settings;
try try
{ {
settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME); settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
UpdateView(settings); this.UpdateView(settings);
} }
catch (Exception exp) catch
{ {
settings = new PowerRenameSettings(POWERTOY_NAME); settings = new PowerRenameSettings(POWERTOYNAME);
SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOY_NAME); SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOYNAME);
UpdateView(settings); this.UpdateView(settings);
} }
} }
private void UpdateView(PowerRenameSettings settings) private void UpdateView(PowerRenameSettings settings)
{ {
this.Toggle_PowerRename_Enable.IsOn = settings.properties.bool_mru_enabled.value; this.Toggle_PowerRename_Enable.IsOn = settings.properties.bool_mru_enabled.value;
@@ -64,32 +56,32 @@ namespace Microsoft.PowerToys.Settings.UI.Views
if (swt != null) if (swt != null)
{ {
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME); PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
settings.properties.bool_mru_enabled.value = swt.IsOn; settings.properties.bool_mru_enabled.value = swt.IsOn;
if (ShellPage.Default_SndMSG_Callback != null) if (ShellPage.DefaultSndMSGCallback != null)
{ {
SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndPowerRenameSettings snd = new SndPowerRenameSettings(settings);
SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd); SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd);
ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
} }
} }
} }
private void Toggle_PowerRename_EnableOnContextMenu_Toggled(object sender, RoutedEventArgs e) private void Toggle_PowerRename_EnableOnContextMenu_Toggled(object sender, RoutedEventArgs e)
{ {
ToggleSwitch swt = sender as ToggleSwitch; ToggleSwitch swt = sender as ToggleSwitch;
if (swt != null) if (swt != null)
{ {
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME); PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
settings.properties.bool_show_icon_on_menu.value = swt.IsOn; settings.properties.bool_show_icon_on_menu.value = swt.IsOn;
if (ShellPage.Default_SndMSG_Callback != null) if (ShellPage.DefaultSndMSGCallback != null)
{ {
SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndPowerRenameSettings snd = new SndPowerRenameSettings(settings);
SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd); SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd);
ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
} }
} }
} }
@@ -100,14 +92,14 @@ namespace Microsoft.PowerToys.Settings.UI.Views
if (swt != null) if (swt != null)
{ {
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME); PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
settings.properties.bool_show_extended_menu.value = swt.IsOn; settings.properties.bool_show_extended_menu.value = swt.IsOn;
if (ShellPage.Default_SndMSG_Callback != null) if (ShellPage.DefaultSndMSGCallback != null)
{ {
SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndPowerRenameSettings snd = new SndPowerRenameSettings(settings);
SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd); SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd);
ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
} }
} }
} }
@@ -118,14 +110,14 @@ namespace Microsoft.PowerToys.Settings.UI.Views
if (swt != null) if (swt != null)
{ {
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME); PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
settings.properties.bool_persist_input.value = swt.IsOn; settings.properties.bool_persist_input.value = swt.IsOn;
if (ShellPage.Default_SndMSG_Callback != null) if (ShellPage.DefaultSndMSGCallback != null)
{ {
SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndPowerRenameSettings snd = new SndPowerRenameSettings(settings);
SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd); SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd);
ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
} }
} }
} }
@@ -134,14 +126,14 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{ {
if (sender != null) if (sender != null)
{ {
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME); PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
settings.properties.int_max_mru_size.value = Convert.ToInt32(sender.Value); settings.properties.int_max_mru_size.value = Convert.ToInt32(sender.Value);
if (ShellPage.Default_SndMSG_Callback != null) if (ShellPage.DefaultSndMSGCallback != null)
{ {
SndPowerRenameSettings snd = new SndPowerRenameSettings(settings); SndPowerRenameSettings snd = new SndPowerRenameSettings(settings);
SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd); SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd);
ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString()); ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
} }
} }
} }

View File

@@ -55,7 +55,7 @@
<!-- TO DO: Update icon --> <!-- TO DO: Update icon -->
<winui:NavigationViewItem x:Uid="Shell_FancyZones" helpers:NavHelper.NavigateTo="views:FancyZonesPage"> <winui:NavigationViewItem x:Uid="Shell_FancyZones" helpers:NavHelper.NavigateTo="views:FancyZonesPage">
<winui:NavigationViewItem.Icon> <winui:NavigationViewItem.Icon>
<FontIcon Glyph="&#xE8AC;"/> <PathIcon Data="M896 0v896H0V0h896zM768 768V128H128v640h640zM0 1920v-896h1920v896H0zm128-768v640h1664v-640H128zM1024 0h896v896h-896V0zm768 768V128h-640v640h640z"></PathIcon>
</winui:NavigationViewItem.Icon> </winui:NavigationViewItem.Icon>
</winui:NavigationViewItem> </winui:NavigationViewItem>
@@ -89,7 +89,7 @@
<!-- TO DO: Update icon --> <!-- TO DO: Update icon -->
<winui:NavigationViewItem x:Uid="Shell_ImageResizer" helpers:NavHelper.NavigateTo="views:ImageResizerPage"> <winui:NavigationViewItem x:Uid="Shell_ImageResizer" helpers:NavHelper.NavigateTo="views:ImageResizerPage">
<winui:NavigationViewItem.Icon> <winui:NavigationViewItem.Icon>
<FontIcon Glyph="&#xEDA7;"/> <PathIcon Data="M0 768h1408v1152H0V768zm128 1024h870l-582-581-288 288v293zm1152 0v-102l-224-223-101 101 223 224h102zM128 896v421l288-287 448 447 192-191 224 224V896H128zm832 256q-26 0-45-19t-19-45q0-26 19-45t45-19q26 0 45 19t19 45q0 26-19 45t-45 19zm960-512V347l-339 338-90-90 338-339h-293V128h512v512h-128zm-768-512h256v128h-256V128zm-128 128H768V128h256v128zm-384 0H384V128h256v128zm-384 0H0V128h256v128zM128 640H0V384h128v256zm1920 128v256h-128V768h128zm-128 384h128v256h-128v-256zm0 384h128v256h-128v-256zm-384 256h256v128h-256v-128z"></PathIcon>
</winui:NavigationViewItem.Icon> </winui:NavigationViewItem.Icon>
</winui:NavigationViewItem> </winui:NavigationViewItem>
</winui:NavigationView.MenuItems> </winui:NavigationView.MenuItems>

View File

@@ -1,19 +1,8 @@
// <copyright file="ShellPage.xaml.cs" company="Microsoft Corp"> using Microsoft.PowerToys.Settings.UI.ViewModels;
// Copyright (c) Microsoft Corp. All rights reserved. using Windows.UI.Xaml.Controls;
// </copyright>
namespace Microsoft.PowerToys.Settings.UI.Views namespace Microsoft.PowerToys.Settings.UI.Views
{ {
using System;
using System.Collections.Generic;
using Microsoft.PowerToys.Settings.UI.Activation;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Services;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
/// <summary> /// <summary>
/// Root page. /// Root page.
/// </summary> /// </summary>
@@ -25,21 +14,21 @@ namespace Microsoft.PowerToys.Settings.UI.Views
/// <param name="msg">message.</param> /// <param name="msg">message.</param>
public delegate void IPCMessageCallback(string msg); public delegate void IPCMessageCallback(string msg);
/// <summary>
/// Gets or sets a shell handler to be used to update contents of the shell dynamically from page within the frame.
/// </summary>
public static ShellPage ShellHandler { get; set; }
/// <summary>
/// Gets or sets iPC callback function for run on start up.
/// </summary>
public static IPCMessageCallback DefaultSndMSGCallback { get; set; }
/// <summary> /// <summary>
/// Gets view model. /// Gets view model.
/// </summary> /// </summary>
public ShellViewModel ViewModel { get; } = new ShellViewModel(); public ShellViewModel ViewModel { get; } = new ShellViewModel();
/// <summary>
/// A shell handler to be used to update contents of the shell dynamically from page within the frame.
/// </summary>
public static ShellPage ShellHandler = null;
/// <summary>
/// IPC callback function for run on start up.
/// </summary>
public static IPCMessageCallback Default_SndMSG_Callback = null;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ShellPage"/> class. /// Initializes a new instance of the <see cref="ShellPage"/> class.
/// Shell page constructor. /// Shell page constructor.
@@ -60,7 +49,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
/// <param name="implmentation">delegate function implementation.</param> /// <param name="implmentation">delegate function implementation.</param>
public void SetDefaultSndMessageCallback(IPCMessageCallback implmentation) public void SetDefaultSndMessageCallback(IPCMessageCallback implmentation)
{ {
Default_SndMSG_Callback = implmentation; DefaultSndMSGCallback = implmentation;
} }
} }
} }

View File

@@ -1,18 +1,9 @@
using Microsoft.PowerToys.Settings.UI.ViewModels; // Copyright (c) Microsoft Corporation
using System; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Collections.Generic; // See the LICENSE file in the project root for more information.
using System.IO;
using System.Linq; using Microsoft.PowerToys.Settings.UI.ViewModels;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
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.Media;
using Windows.UI.Xaml.Navigation;
namespace Microsoft.PowerToys.Settings.UI.Views namespace Microsoft.PowerToys.Settings.UI.Views
{ {

View File

@@ -107,6 +107,11 @@
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="HtmlAgilityPack"> <PackageReference Include="HtmlAgilityPack">
@@ -138,5 +143,11 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MarkdownPreviewHandler.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.4.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
</SettingsFile>