mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 14:41:21 +08:00
added stylecop (#1933)
* added stylecop * removed xml documentation * used common stylecop file
This commit is contained in:
parent
89b44f5126
commit
cea6b7067a
@ -194,8 +194,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
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}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "src\core\Test\Test.csproj", "{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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|x64.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -709,7 +699,6 @@ Global
|
||||
{4EB9C181-96E2-4587-AB98-2DB84C1A2310} = {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}
|
||||
{C266BF3A-B9B8-4047-8ADD-E22A6AE1DFFC} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
||||
|
@ -1,15 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
// 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 abstract class BasePTModuleSettings
|
||||
{
|
||||
// Gets or sets name of the powertoy module.
|
||||
public string name { get; set; }
|
||||
|
||||
// Gets or sets the powertoys version.
|
||||
public string version { get; set; }
|
||||
|
||||
// converts the current to a json string.
|
||||
public virtual string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
|
@ -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.Text;
|
||||
using System.Text.Json;
|
||||
@ -14,14 +18,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class IntProperty
|
||||
{
|
||||
public int value { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -1,27 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
// 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 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; }
|
||||
|
||||
// Gets or sets a value indicating whether the powertoy elevated.
|
||||
public bool is_elevated { get; set; }
|
||||
|
||||
// Gets or sets a value indicating whether powertoys should run elevated.
|
||||
public bool run_elevated { get; set; }
|
||||
|
||||
// Gets or sets a value indicating whether is admin.
|
||||
public bool is_admin { get; set; }
|
||||
|
||||
// Gets or sets theme Name.
|
||||
public string theme { get; set; }
|
||||
|
||||
// Gets or sets system theme name.
|
||||
public string system_theme { get; set; }
|
||||
|
||||
// Gets or sets powertoys version number.
|
||||
public string powertoys_version { get; set; }
|
||||
|
||||
public GeneralSettings()
|
||||
{
|
||||
this.packaged = false;
|
||||
this.Packaged = false;
|
||||
this.startup = false;
|
||||
this.is_admin = false;
|
||||
this.is_elevated = false;
|
||||
@ -30,29 +43,10 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
this.powertoys_version = "v0.15.3";
|
||||
}
|
||||
|
||||
// converts the current to a json string.
|
||||
public string ToJsonString()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.")]
|
@ -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.Text;
|
||||
|
||||
@ -7,7 +11,9 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
public interface IPowerToySettings
|
||||
{
|
||||
string name { get; set; }
|
||||
|
||||
string version { get; set; }
|
||||
|
||||
string ToJsonString();
|
||||
}
|
||||
}
|
||||
|
21
src/core/Microsoft.PowerToys.Settings.UI.Lib/IntProperty.cs
Normal file
21
src/core/Microsoft.PowerToys.Settings.UI.Lib/IntProperty.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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.Text;
|
||||
using System.Text.Json;
|
||||
@ -29,37 +33,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
// 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;
|
||||
|
||||
@ -29,39 +30,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -8,45 +8,34 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
{
|
||||
public static class SettingsUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Get path to the json settings file.
|
||||
/// </summary>
|
||||
/// <returns>string path.</returns>
|
||||
// Get path to the json settings file.
|
||||
public static string GetSettingsPath(string powertoy)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(powertoy))
|
||||
if (string.IsNullOrWhiteSpace(powertoy))
|
||||
{
|
||||
return Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
$"Microsoft\\PowerToys\\settings.json");
|
||||
}
|
||||
|
||||
return Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
$"Microsoft\\PowerToys\\{powertoy}\\settings.json");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a Deserialized object of the json settings string.
|
||||
/// </summary>
|
||||
/// <returns>Deserialized json settings object.</returns>
|
||||
// Get a Deserialized object of the json settings string.
|
||||
public static T GetSettings<T>(string powertoy)
|
||||
{
|
||||
var jsonSettingsString = System.IO.File.ReadAllText(SettingsUtils.GetSettingsPath(powertoy));
|
||||
return JsonSerializer.Deserialize<T>(jsonSettingsString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save settings to a json file.
|
||||
/// </summary>
|
||||
/// <param name="settings">dynamic json settings object.</param>
|
||||
public static void SaveSettings(string jsonSettings, string powertoy)
|
||||
// Save settings to a json file.
|
||||
public static void SaveSettings(string moduleJsonSettings, string powertoyModuleName)
|
||||
{
|
||||
if(jsonSettings != null)
|
||||
{
|
||||
System.IO.File.WriteAllText(
|
||||
SettingsUtils.GetSettingsPath(powertoy),
|
||||
jsonSettings.ToString());
|
||||
}
|
||||
System.IO.File.WriteAllText(
|
||||
SettingsUtils.GetSettingsPath(powertoyModuleName),
|
||||
moduleJsonSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
// 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;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using System.Threading;
|
||||
using Microsoft.Toolkit.Wpf.UI.XamlHost;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Runner
|
||||
{
|
||||
@ -26,16 +26,10 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
|
||||
if (shellPage != null)
|
||||
{
|
||||
// send IPC Message
|
||||
shellPage.SetDefaultSndMessageCallback(delegate (string msg)
|
||||
shellPage.SetDefaultSndMessageCallback(msg =>
|
||||
{
|
||||
Program.ipcmanager.SendMessage(msg);
|
||||
Program.GetTwoWayIPCManager().SendMessage(msg);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (shellPage != null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,10 @@
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json" Link="StyleCop.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\settingsui\Assets\logo.png">
|
||||
<Pack>True</Pack>
|
||||
|
@ -16,20 +16,20 @@ namespace Microsoft.PowerToys.Settings.UI.Activation
|
||||
internal abstract class ActivationHandler<T> : ActivationHandler
|
||||
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)
|
||||
{
|
||||
await HandleInternalAsync(args as T);
|
||||
await this.HandleInternalAsync(args as T);
|
||||
}
|
||||
|
||||
public override bool CanHandle(object args)
|
||||
{
|
||||
// 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
|
||||
// to determine if your ActivationHandler should handle this activation args
|
||||
protected virtual bool CanHandleInternal(T args)
|
||||
|
@ -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 Microsoft.PowerToys.Settings.UI.Services;
|
||||
|
||||
using Windows.ApplicationModel.Activation;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Activation
|
||||
{
|
||||
internal class DefaultActivationHandler : ActivationHandler<IActivatedEventArgs>
|
||||
{
|
||||
private readonly Type _navElement;
|
||||
private readonly Type navElement;
|
||||
|
||||
public DefaultActivationHandler(Type navElement)
|
||||
{
|
||||
_navElement = navElement;
|
||||
this.navElement = navElement;
|
||||
}
|
||||
|
||||
protected override async Task HandleInternalAsync(IActivatedEventArgs args)
|
||||
@ -26,14 +28,14 @@ namespace Microsoft.PowerToys.Settings.UI.Activation
|
||||
arguments = launchArgs.Arguments;
|
||||
}
|
||||
|
||||
NavigationService.Navigate(_navElement, arguments);
|
||||
NavigationService.Navigate(this.navElement, arguments);
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected override bool CanHandleInternal(IActivatedEventArgs args)
|
||||
{
|
||||
// None of the ActivationHandlers has handled the app activation
|
||||
return NavigationService.Frame.Content == null && _navElement != null;
|
||||
return NavigationService.Frame.Content == null && this.navElement != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,18 +11,18 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
|
||||
{
|
||||
public class NavigationViewHeaderBehavior : Behavior<WinUI.NavigationView>
|
||||
{
|
||||
private static NavigationViewHeaderBehavior _current;
|
||||
private Page _currentPage;
|
||||
private static NavigationViewHeaderBehavior current;
|
||||
private Page currentPage;
|
||||
|
||||
public DataTemplate DefaultHeaderTemplate { get; set; }
|
||||
|
||||
public object DefaultHeader
|
||||
{
|
||||
get { return GetValue(DefaultHeaderProperty); }
|
||||
set { SetValue(DefaultHeaderProperty, value); }
|
||||
get { return this.GetValue(DefaultHeaderProperty); }
|
||||
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)
|
||||
{
|
||||
@ -35,7 +35,7 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -48,7 +48,7 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -61,19 +61,19 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
base.OnAttached();
|
||||
_current = this;
|
||||
NavigationService.Navigated += OnNavigated;
|
||||
current = this;
|
||||
NavigationService.Navigated += this.OnNavigated;
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
base.OnDetaching();
|
||||
NavigationService.Navigated -= OnNavigated;
|
||||
NavigationService.Navigated -= this.OnNavigated;
|
||||
}
|
||||
|
||||
private void OnNavigated(object sender, NavigationEventArgs e)
|
||||
@ -81,42 +81,42 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
|
||||
var frame = sender as Frame;
|
||||
if (frame.Content is Page page)
|
||||
{
|
||||
_currentPage = page;
|
||||
this.currentPage = page;
|
||||
|
||||
UpdateHeader();
|
||||
UpdateHeaderTemplate();
|
||||
this.UpdateHeader();
|
||||
this.UpdateHeaderTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHeader()
|
||||
{
|
||||
if (_currentPage != null)
|
||||
if (this.currentPage != null)
|
||||
{
|
||||
var headerMode = GetHeaderMode(_currentPage);
|
||||
var headerMode = GetHeaderMode(this.currentPage);
|
||||
if (headerMode == NavigationViewHeaderMode.Never)
|
||||
{
|
||||
AssociatedObject.Header = null;
|
||||
AssociatedObject.AlwaysShowHeader = false;
|
||||
this.AssociatedObject.Header = null;
|
||||
this.AssociatedObject.AlwaysShowHeader = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var headerFromPage = GetHeaderContext(_currentPage);
|
||||
var headerFromPage = GetHeaderContext(this.currentPage);
|
||||
if (headerFromPage != null)
|
||||
{
|
||||
AssociatedObject.Header = headerFromPage;
|
||||
this.AssociatedObject.Header = headerFromPage;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssociatedObject.Header = DefaultHeader;
|
||||
this.AssociatedObject.Header = this.DefaultHeader;
|
||||
}
|
||||
|
||||
if (headerMode == NavigationViewHeaderMode.Always)
|
||||
{
|
||||
AssociatedObject.AlwaysShowHeader = true;
|
||||
this.AssociatedObject.AlwaysShowHeader = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssociatedObject.AlwaysShowHeader = false;
|
||||
this.AssociatedObject.AlwaysShowHeader = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,10 +124,10 @@ namespace Microsoft.PowerToys.Settings.UI.Behaviors
|
||||
|
||||
private void UpdateHeaderTemplate()
|
||||
{
|
||||
if (_currentPage != null)
|
||||
if (this.currentPage != null)
|
||||
{
|
||||
var headerTemplate = GetHeaderTemplate(_currentPage);
|
||||
AssociatedObject.HeaderTemplate = headerTemplate ?? DefaultHeaderTemplate;
|
||||
var headerTemplate = GetHeaderTemplate(this.currentPage);
|
||||
this.AssociatedObject.HeaderTemplate = headerTemplate ?? this.DefaultHeaderTemplate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
{
|
||||
Always,
|
||||
Never,
|
||||
Minimal
|
||||
Minimal,
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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")]
|
@ -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 Windows.UI.Xaml;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
|
@ -16,9 +16,9 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
{
|
||||
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;
|
||||
|
||||
@ -18,22 +18,22 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
|
||||
public RelayCommand(Action execute, Func<bool> canExecute)
|
||||
{
|
||||
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||
_canExecute = canExecute;
|
||||
this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||
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
|
||||
{
|
||||
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;
|
||||
|
||||
@ -44,14 +44,14 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
|
||||
public RelayCommand(Action<T> execute, Func<T, bool> canExecute)
|
||||
{
|
||||
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||
_canExecute = canExecute;
|
||||
this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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 Windows.ApplicationModel.Resources;
|
||||
@ -7,11 +11,11 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
{
|
||||
internal static class ResourceExtensions
|
||||
{
|
||||
private static ResourceLoader _resLoader = new ResourceLoader();
|
||||
private static readonly ResourceLoader ResLoader = new ResourceLoader();
|
||||
|
||||
public static string GetLocalized(this string resourceKey)
|
||||
{
|
||||
return _resLoader.GetString(resourceKey);
|
||||
return ResLoader.GetString(resourceKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,9 +123,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Behaviors\NavigationViewHeaderBehavior.cs" />
|
||||
<Compile Include="Behaviors\NavigationViewHeaderMode.cs" />
|
||||
<Compile Include="Controls\DummyUserControl.xaml.cs">
|
||||
<DependentUpon>DummyUserControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
<Compile Include="Helpers\NavHelper.cs" />
|
||||
<Compile Include="Helpers\Observable.cs" />
|
||||
<Compile Include="Helpers\RelayCommand.cs" />
|
||||
@ -197,15 +195,16 @@
|
||||
<PackageReference Include="Newtonsoft.Json">
|
||||
<Version>12.0.3</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="StyleCop.Analyzers">
|
||||
<Version>1.1.118</Version>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PRIResource Include="Strings\en-us\Resources.resw" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Controls\DummyUserControl.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Styles\Page.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
@ -269,6 +268,11 @@
|
||||
<Name>Microsoft.PowerToys.Settings.UI.Lib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json">
|
||||
<Link>StyleCop.json</Link>
|
||||
</AdditionalFiles>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
@ -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.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -15,48 +19,48 @@ namespace Microsoft.PowerToys.Settings.UI.Services
|
||||
// https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md
|
||||
internal class ActivationService
|
||||
{
|
||||
private readonly App _app;
|
||||
private readonly Type _defaultNavItem;
|
||||
private Lazy<UIElement> _shell;
|
||||
private readonly App app;
|
||||
private readonly Type defaultNavItem;
|
||||
private Lazy<UIElement> shell;
|
||||
|
||||
private object _lastActivationArgs;
|
||||
private object lastActivationArgs;
|
||||
|
||||
public ActivationService(App app, Type defaultNavItem, Lazy<UIElement> shell = null)
|
||||
{
|
||||
_app = app;
|
||||
_shell = shell;
|
||||
_defaultNavItem = defaultNavItem;
|
||||
this.app = app;
|
||||
this.shell = shell;
|
||||
this.defaultNavItem = defaultNavItem;
|
||||
}
|
||||
|
||||
public async Task ActivateAsync(object activationArgs)
|
||||
{
|
||||
if (IsInteractive(activationArgs))
|
||||
if (this.IsInteractive(activationArgs))
|
||||
{
|
||||
// Initialize services that you need before app activation
|
||||
// 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,
|
||||
// just ensure that the window is active
|
||||
if (Window.Current.Content == null)
|
||||
{
|
||||
// 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
|
||||
// will navigate to the first page
|
||||
await HandleActivationAsync(activationArgs);
|
||||
_lastActivationArgs = activationArgs;
|
||||
await this.HandleActivationAsync(activationArgs);
|
||||
this.lastActivationArgs = activationArgs;
|
||||
|
||||
if (IsInteractive(activationArgs))
|
||||
if (this.IsInteractive(activationArgs))
|
||||
{
|
||||
// Ensure the current window is active
|
||||
Window.Current.Activate();
|
||||
|
||||
// Tasks after activation
|
||||
await StartupAsync();
|
||||
await this.StartupAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +71,7 @@ namespace Microsoft.PowerToys.Settings.UI.Services
|
||||
|
||||
private async Task HandleActivationAsync(object activationArgs)
|
||||
{
|
||||
var activationHandler = GetActivationHandlers()
|
||||
var activationHandler = this.GetActivationHandlers()
|
||||
.FirstOrDefault(h => h.CanHandle(activationArgs));
|
||||
|
||||
if (activationHandler != null)
|
||||
@ -75,9 +79,9 @@ namespace Microsoft.PowerToys.Settings.UI.Services
|
||||
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))
|
||||
{
|
||||
await defaultHandler.HandleAsync(activationArgs);
|
||||
|
@ -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.Controls;
|
||||
using Windows.UI.Xaml.Media.Animation;
|
||||
@ -13,26 +16,26 @@ namespace Microsoft.PowerToys.Settings.UI.Services
|
||||
|
||||
public static event NavigationFailedEventHandler NavigationFailed;
|
||||
|
||||
private static Frame _frame;
|
||||
private static object _lastParamUsed;
|
||||
private static Frame frame;
|
||||
private static object lastParamUsed;
|
||||
|
||||
public static Frame Frame
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_frame == null)
|
||||
if (frame == null)
|
||||
{
|
||||
_frame = Window.Current.Content as Frame;
|
||||
frame = Window.Current.Content as Frame;
|
||||
RegisterFrameEvents();
|
||||
}
|
||||
|
||||
return _frame;
|
||||
return frame;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
UnregisterFrameEvents();
|
||||
_frame = value;
|
||||
frame = value;
|
||||
RegisterFrameEvents();
|
||||
}
|
||||
}
|
||||
@ -57,12 +60,12 @@ namespace Microsoft.PowerToys.Settings.UI.Services
|
||||
public static bool Navigate(Type pageType, object parameter = null, NavigationTransitionInfo infoOverride = null)
|
||||
{
|
||||
// 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);
|
||||
if (navigationResult)
|
||||
{
|
||||
_lastParamUsed = parameter;
|
||||
lastParamUsed = parameter;
|
||||
}
|
||||
|
||||
return navigationResult;
|
||||
@ -79,19 +82,19 @@ namespace Microsoft.PowerToys.Settings.UI.Services
|
||||
|
||||
private static void RegisterFrameEvents()
|
||||
{
|
||||
if (_frame != null)
|
||||
if (frame != null)
|
||||
{
|
||||
_frame.Navigated += Frame_Navigated;
|
||||
_frame.NavigationFailed += Frame_NavigationFailed;
|
||||
frame.Navigated += Frame_Navigated;
|
||||
frame.NavigationFailed += Frame_NavigationFailed;
|
||||
}
|
||||
}
|
||||
|
||||
private static void UnregisterFrameEvents()
|
||||
{
|
||||
if (_frame != null)
|
||||
if (frame != null)
|
||||
{
|
||||
_frame.Navigated -= Frame_Navigated;
|
||||
_frame.NavigationFailed -= Frame_NavigationFailed;
|
||||
frame.Navigated -= Frame_Navigated;
|
||||
frame.NavigationFailed -= Frame_NavigationFailed;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -1,50 +1,50 @@
|
||||
// <copyright file="ShellViewModel.cs" company="Microsoft Corp">
|
||||
// Copyright (c) Microsoft Corp. All rights reserved.
|
||||
// </copyright>
|
||||
// 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.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
|
||||
{
|
||||
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
|
||||
{
|
||||
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 IList<KeyboardAccelerator> _keyboardAccelerators;
|
||||
private WinUI.NavigationView _navigationView;
|
||||
private WinUI.NavigationViewItem _selected;
|
||||
private ICommand _loadedCommand;
|
||||
private ICommand _itemInvokedCommand;
|
||||
private bool isBackEnabled;
|
||||
private IList<KeyboardAccelerator> keyboardAccelerators;
|
||||
private WinUI.NavigationView navigationView;
|
||||
private WinUI.NavigationViewItem selected;
|
||||
private ICommand loadedCommand;
|
||||
private ICommand itemInvokedCommand;
|
||||
|
||||
public bool IsBackEnabled
|
||||
{
|
||||
get { return _isBackEnabled; }
|
||||
set { Set(ref _isBackEnabled, value); }
|
||||
get { return this.isBackEnabled; }
|
||||
set { this.Set(ref this.isBackEnabled, value); }
|
||||
}
|
||||
|
||||
public WinUI.NavigationViewItem Selected
|
||||
{
|
||||
get { return _selected; }
|
||||
set { Set(ref _selected, value); }
|
||||
get { return this.selected; }
|
||||
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()
|
||||
{
|
||||
@ -52,54 +52,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
public void Initialize(Frame frame, WinUI.NavigationView navigationView, IList<KeyboardAccelerator> keyboardAccelerators)
|
||||
{
|
||||
_navigationView = navigationView;
|
||||
_keyboardAccelerators = keyboardAccelerators;
|
||||
this.navigationView = navigationView;
|
||||
this.keyboardAccelerators = keyboardAccelerators;
|
||||
NavigationService.Frame = frame;
|
||||
NavigationService.NavigationFailed += Frame_NavigationFailed;
|
||||
NavigationService.Navigated += Frame_Navigated;
|
||||
_navigationView.BackRequested += 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;
|
||||
NavigationService.NavigationFailed += this.Frame_NavigationFailed;
|
||||
NavigationService.Navigated += this.Frame_Navigated;
|
||||
this.navigationView.BackRequested += this.OnBackRequested;
|
||||
}
|
||||
|
||||
private static KeyboardAccelerator BuildKeyboardAccelerator(VirtualKey key, VirtualKeyModifiers? modifiers = null)
|
||||
@ -119,5 +77,47 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
var result = NavigationService.GoBack();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
@ -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.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
|
@ -1,19 +1,19 @@
|
||||
// <copyright file="GeneralPage.xaml.cs" company="Microsoft Corp">
|
||||
// Copyright (c) Microsoft Corp. All rights reserved.
|
||||
// </copyright>
|
||||
// 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.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
|
||||
{
|
||||
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>
|
||||
/// General Settings Page.
|
||||
/// </summary>
|
||||
@ -32,7 +32,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
@ -42,17 +42,19 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
// get settings file if they exist.
|
||||
settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
|
||||
|
||||
// load and apply theme settings
|
||||
this.ReLoadTheme(settings.theme);
|
||||
|
||||
// load run on start-up settings value and update the ui state.
|
||||
this.ToggleSwitch_RunAtStartUp.IsOn = settings.startup;
|
||||
}
|
||||
catch (Exception exp)
|
||||
catch
|
||||
{
|
||||
// create settings file if one is not found.
|
||||
settings = new GeneralSettings();
|
||||
SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty);
|
||||
|
||||
// load and apply theme settings
|
||||
this.ReLoadTheme(settings.theme);
|
||||
|
||||
@ -106,9 +108,9 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty);
|
||||
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;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
|
@ -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.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
|
@ -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.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 Microsoft.PowerToys.Settings.UI.Lib;
|
||||
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 Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
/// <summary>
|
||||
@ -40,15 +30,15 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
settings = SettingsUtils.GetSettings<PowerPreviewSettings>(POWERTOY_NAME);
|
||||
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_SVG.IsOn = settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.value;
|
||||
this.ToggleSwitch_Preview_MD.IsOn = settings.properties.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID.value;
|
||||
}
|
||||
catch(Exception exp)
|
||||
catch
|
||||
{
|
||||
settings = new PowerPreviewSettings(POWERTOY_NAME);
|
||||
SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOY_NAME);
|
||||
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_SVG.IsOn = settings.properties.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL.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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
SndModuleSettings<SndPowerPreviewSettings> ipcMessage = new SndModuleSettings<SndPowerPreviewSettings>(snd);
|
||||
ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString());
|
||||
ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.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.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
|
||||
@ -23,7 +15,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
public sealed partial class PowerRenamePage : Page
|
||||
{
|
||||
public PowerRenameViewModel ViewModel { get; } = new PowerRenameViewModel();
|
||||
private const string POWERTOY_NAME = "PowerRename";
|
||||
|
||||
private const string POWERTOYNAME = "PowerRename";
|
||||
|
||||
public PowerRenamePage()
|
||||
{
|
||||
@ -37,18 +30,17 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
PowerRenameSettings settings;
|
||||
try
|
||||
{
|
||||
settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME);
|
||||
UpdateView(settings);
|
||||
settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
|
||||
this.UpdateView(settings);
|
||||
}
|
||||
catch (Exception exp)
|
||||
catch
|
||||
{
|
||||
settings = new PowerRenameSettings(POWERTOY_NAME);
|
||||
SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOY_NAME);
|
||||
UpdateView(settings);
|
||||
settings = new PowerRenameSettings(POWERTOYNAME);
|
||||
SettingsUtils.SaveSettings(settings.ToJsonString(), POWERTOYNAME);
|
||||
this.UpdateView(settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UpdateView(PowerRenameSettings settings)
|
||||
{
|
||||
this.Toggle_PowerRename_Enable.IsOn = settings.properties.bool_mru_enabled.value;
|
||||
@ -64,32 +56,32 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
|
||||
if (swt != null)
|
||||
{
|
||||
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME);
|
||||
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
|
||||
settings.properties.bool_mru_enabled.value = swt.IsOn;
|
||||
|
||||
if (ShellPage.Default_SndMSG_Callback != null)
|
||||
if (ShellPage.DefaultSndMSGCallback != null)
|
||||
{
|
||||
SndPowerRenameSettings snd = new SndPowerRenameSettings(settings);
|
||||
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)
|
||||
{
|
||||
ToggleSwitch swt = sender as ToggleSwitch;
|
||||
|
||||
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;
|
||||
|
||||
if (ShellPage.Default_SndMSG_Callback != null)
|
||||
if (ShellPage.DefaultSndMSGCallback != null)
|
||||
{
|
||||
SndPowerRenameSettings snd = new SndPowerRenameSettings(settings);
|
||||
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)
|
||||
{
|
||||
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME);
|
||||
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
|
||||
settings.properties.bool_show_extended_menu.value = swt.IsOn;
|
||||
|
||||
if (ShellPage.Default_SndMSG_Callback != null)
|
||||
if (ShellPage.DefaultSndMSGCallback != null)
|
||||
{
|
||||
SndPowerRenameSettings snd = new SndPowerRenameSettings(settings);
|
||||
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)
|
||||
{
|
||||
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME);
|
||||
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
|
||||
settings.properties.bool_persist_input.value = swt.IsOn;
|
||||
|
||||
if (ShellPage.Default_SndMSG_Callback != null)
|
||||
if (ShellPage.DefaultSndMSGCallback != null)
|
||||
{
|
||||
SndPowerRenameSettings snd = new SndPowerRenameSettings(settings);
|
||||
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)
|
||||
{
|
||||
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOY_NAME);
|
||||
PowerRenameSettings settings = SettingsUtils.GetSettings<PowerRenameSettings>(POWERTOYNAME);
|
||||
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);
|
||||
SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd);
|
||||
ShellPage.Default_SndMSG_Callback(ipcMessage.ToJsonString());
|
||||
ShellPage.DefaultSndMSGCallback(ipcMessage.ToJsonString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@
|
||||
<!-- TO DO: Update icon -->
|
||||
<winui:NavigationViewItem x:Uid="Shell_FancyZones" helpers:NavHelper.NavigateTo="views:FancyZonesPage">
|
||||
<winui:NavigationViewItem.Icon>
|
||||
<FontIcon Glyph=""/>
|
||||
<PathIcon Data="M896 0v896H0V0h896zM768 768V128H128v640h640zM0 1920v-896h1920v896H0zm128-768v640h1664v-640H128zM1024 0h896v896h-896V0zm768 768V128h-640v640h640z"></PathIcon>
|
||||
</winui:NavigationViewItem.Icon>
|
||||
</winui:NavigationViewItem>
|
||||
|
||||
@ -89,7 +89,7 @@
|
||||
<!-- TO DO: Update icon -->
|
||||
<winui:NavigationViewItem x:Uid="Shell_ImageResizer" helpers:NavHelper.NavigateTo="views:ImageResizerPage">
|
||||
<winui:NavigationViewItem.Icon>
|
||||
<FontIcon Glyph=""/>
|
||||
<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>
|
||||
</winui:NavigationView.MenuItems>
|
||||
|
@ -1,19 +1,8 @@
|
||||
// <copyright file="ShellPage.xaml.cs" company="Microsoft Corp">
|
||||
// Copyright (c) Microsoft Corp. All rights reserved.
|
||||
// </copyright>
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
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>
|
||||
/// Root page.
|
||||
/// </summary>
|
||||
@ -25,21 +14,21 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
/// <param name="msg">message.</param>
|
||||
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>
|
||||
/// Gets view model.
|
||||
/// </summary>
|
||||
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>
|
||||
/// Initializes a new instance of the <see cref="ShellPage"/> class.
|
||||
/// Shell page constructor.
|
||||
@ -60,7 +49,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
/// <param name="implmentation">delegate function implementation.</param>
|
||||
public void SetDefaultSndMessageCallback(IPCMessageCallback implmentation)
|
||||
{
|
||||
Default_SndMSG_Callback = implmentation;
|
||||
DefaultSndMSGCallback = implmentation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,9 @@
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
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;
|
||||
// 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.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
|
||||
{
|
||||
|
@ -107,6 +107,11 @@
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack">
|
||||
@ -138,5 +143,11 @@
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
26
src/modules/previewpane/MarkDownPreviewHandler/Properties/Settings.Designer.cs
generated
Normal file
26
src/modules/previewpane/MarkDownPreviewHandler/Properties/Settings.Designer.cs
generated
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
Loading…
Reference in New Issue
Block a user