From f1951d0d5fa12007c1d8bfced3141ca746473f47 Mon Sep 17 00:00:00 2001 From: Lavius Motileng <58791731+laviusmotileng-ms@users.noreply.github.com> Date: Mon, 30 Mar 2020 02:02:25 -0700 Subject: [PATCH] Setting v2: added power preview settings (#1702) * added power preview settings * Added link to module oververview * create settings file if one is not found * removed run oon start up speficic callback * Update src/core/Microsoft.PowerToys.Settings.UI.Lib/ModuleSettings.cs Co-Authored-By: Andrey Nekrasov * fixed merge conflicts Co-authored-by: Andrey Nekrasov --- PowerToys.sln | 2 +- .../Contributor.cs | 12 ++ .../PowerPreviewSettings.cs | 73 +++++++++ .../SndModuleSettings.cs | 28 ++++ .../MainWindow.xaml | 6 +- .../MainWindow.xaml.cs | 24 +-- .../Microsoft.PowerToys.Settings.UI.csproj | 9 +- .../Strings/en-us/Resources.resw | 6 +- .../Views/GeneralPage.xaml.cs | 42 +++-- .../Views/PowerPreviewPage.xaml | 27 ++++ .../Views/PowerPreviewPage.xaml.cs | 99 ++++++++++++ .../Views/ShellPage.xaml | 146 ++++++++++-------- .../Views/ShellPage.xaml.cs | 72 ++++++--- src/core/Test/Program.cs | 9 +- 14 files changed, 423 insertions(+), 132 deletions(-) create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/Contributor.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI/Views/PowerPreviewPage.xaml create mode 100644 src/core/Microsoft.PowerToys.Settings.UI/Views/PowerPreviewPage.xaml.cs diff --git a/PowerToys.sln b/PowerToys.sln index 80f1a60826..544c96ba52 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -191,7 +191,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/Contributor.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/Contributor.cs new file mode 100644 index 0000000000..4d4e53de9e --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/Contributor.cs @@ -0,0 +1,12 @@ +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; } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs new file mode 100644 index 0000000000..3552260b22 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + /// + /// This class models the settings for the PowerPreview class. + /// Eaxmple JSON: + /// { + /// "name": "File Explorer Preview", + /// "properties": { + /// "IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL": { "value": true }, + /// "PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID": { "value": true } + /// }, + /// "version": "1.0" + /// } + + /// + public class PowerPreviewSettings + { + public string name { get; set; } + public Properties properties { get; set; } + public string version { get; set; } + + public PowerPreviewSettings() + { + this.properties = new Properties(); + this.version = "1"; + this.name = "_unset_"; + } + + public PowerPreviewSettings(string ptName) + { + this.properties = new Properties(); + this.version = "1"; + this.name = ptName; + } + + public override string ToString() + { + return "{\"" + this.name + "\":" + JsonSerializer.Serialize(this) + "}"; + } + } + + public class Property + { + public bool value { get; set; } + + public override string ToString() + { + return JsonSerializer.Serialize(this); + } + } + + public class Properties + { + public Property IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL { get; set; } + public Property PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID { get; set; } + + public Properties() + { + this.IDS_PREVPANE_SVG_BOOL_TOGGLE_CONTROLL = new Property(); + this.PREVPANE_MD_BOOL_TOGGLE_CONTROLL_ID = new Property(); + } + + public override string ToString() + { + return JsonSerializer.Serialize(this); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs new file mode 100644 index 0000000000..a2e2c21037 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + /// + /// PowerToys runner expects a json text that contains one of the following attributes: refresh, general and powertoys. + /// The one for general settings is placed in the General settings model. This class represents the json text that starts with the "powertoys" attribute. + /// this will tell the runner that we are sending settings for a powertoy module and not for general settings. + /// + /// M stands for the Model of PT Module Settings to be sent. + public class SndModuleSettings + { + public M powertoys { get; set; } + + public SndModuleSettings(M ptModuleSettings) + { + this.powertoys = ptModuleSettings; + } + + public override string ToString() + { + return "{\"powertoys\":" + this.powertoys.ToString() + "}"; + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml index 010f229a3d..73fb39bcc5 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml @@ -7,10 +7,8 @@ xmlns:Controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls" xmlns:xaml="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost" mc:Ignorable="d" - Title="PowerToys Settings" Height="800" Width="800"> - - - + Title="PowerToys Settings" Height="800" Width="1000"> + diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs index 5c21af83ff..1500b388b5 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs @@ -25,30 +25,12 @@ namespace Microsoft.PowerToys.Settings.UI.Runner if (shellPage != null) { - shellPage.SetRestartElevatedCallback(delegate(string msg) + // send IPC Message + shellPage.SetDefaultSndMessageCallback(delegate (string msg) { - MessageBox.Show( - msg, - "Restart Elevated", - MessageBoxButton.OK); - - Program.ipcmanager.SendMessage(msg); - - int milliseconds = 2000; - Thread.Sleep(milliseconds); - - System.Windows.Application.Current.Shutdown(); - }); - - shellPage.SetRunOnStartUpCallback(delegate (string msg) - { - MessageBox.Show( - msg, - "Run On Start Up", - MessageBoxButton.OK); - Program.ipcmanager.SendMessage(msg); }); + } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj b/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj index 16da96b764..1463d65a70 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj +++ b/src/core/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj @@ -1,4 +1,4 @@ - + @@ -144,6 +144,9 @@ PowerLauncherPage.xaml + + PowerPreviewPage.xaml + PowerRenamePage.xaml @@ -223,6 +226,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw index da66b76da9..0ccb936aa8 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw +++ b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw @@ -1,4 +1,4 @@ - + - - - - - - - + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - - - - + + + + + + + + + + + + + + - - - - - + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + - + - - - - + + + + - + - - - - - - - + + + + + \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml.cs index 2fc23de931..bc4c14f497 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml.cs @@ -5,10 +5,13 @@ 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; /// @@ -30,19 +33,12 @@ namespace Microsoft.PowerToys.Settings.UI.Views /// /// A shell handler to be used to update contents of the shell dynamically from page within the frame. /// - public static Microsoft.UI.Xaml.Controls.NavigationView ShellHandler = null; - - - /// - /// IPC callback function for restart elevated. - /// - public static IPCMessageCallback Restart_Elevated_Callback = null; - + public static ShellPage ShellHandler = null; /// /// IPC callback function for run on start up. /// - public static IPCMessageCallback Run_OnStartUp_Callback = null; + public static IPCMessageCallback Default_SndMSG_Callback = null; /// /// Initializes a new instance of the class. @@ -53,27 +49,61 @@ namespace Microsoft.PowerToys.Settings.UI.Views this.InitializeComponent(); this.DataContext = this.ViewModel; - ShellHandler = this.navigationView; + ShellHandler = this; this.ViewModel.Initialize(this.shellFrame, this.navigationView, this.KeyboardAccelerators); this.shellFrame.Navigate(typeof(GeneralPage)); } - /// - /// Restart elevated callback function initialization. - /// - /// delegate function implementation. - public void SetRestartElevatedCallback(IPCMessageCallback implmentation) - { - Restart_Elevated_Callback = implmentation; - } - /// /// Run on start up callback function elevated initialization. /// /// delegate function implementation. - public void SetRunOnStartUpCallback(IPCMessageCallback implmentation) + public void SetDefaultSndMessageCallback(IPCMessageCallback implmentation) { - Run_OnStartUp_Callback = implmentation; + Default_SndMSG_Callback = implmentation; + } + + public void HideFeatureDetails() + { + this.Feature_Details_Title.Visibility = Visibility.Collapsed; + this.Feature_Details.Visibility = Visibility.Collapsed; + } + + public void ShowFeatureDetails() + { + this.Feature_Details_Title.Visibility = Visibility.Visible; + this.Feature_Details.Visibility = Visibility.Visible; + } + + public void SetFeatureDetails(string moduleOverviewLink,string reportBugLink) + { + this.Module_Overview_LinkButton.NavigateUri = new Uri(moduleOverviewLink); + this.Module_Feedback_LinkButton.NavigateUri = new Uri(reportBugLink); + } + + public void HideContributorsList() + { + this.Contributors_List_Title.Visibility = Visibility.Collapsed; + this.Contributors_List.Visibility = Visibility.Collapsed; + } + + public void ShowContributorsList() + { + this.Contributors_List_Title.Visibility = Visibility.Visible; + this.Contributors_List.Visibility = Visibility.Visible; + } + + public void PopulateContributorsList(List contributors) + { + this.Contributors_List.Items.Clear(); + + foreach (Contributor contributor in contributors) + { + HyperlinkButton link = new HyperlinkButton(); + link.Content = contributor.Name; + link.NavigateUri = new Uri(contributor.Link); + this.Contributors_List.Items.Add(link); + } } } } diff --git a/src/core/Test/Program.cs b/src/core/Test/Program.cs index f991ebb520..6b6e9fb5aa 100644 --- a/src/core/Test/Program.cs +++ b/src/core/Test/Program.cs @@ -10,9 +10,12 @@ namespace Test { static void Main(string[] args) { - GeneralSettings settings = SettingsUtils.GetSettings(string.Empty); - OutGoingGeneralSettings outSettings = new OutGoingGeneralSettings(settings); - Console.WriteLine(outSettings.ToString()); + PowerPreviewSettings pvst = new PowerPreviewSettings(); + pvst.name = "File Explorer"; + + SndModuleSettings snd = new SndModuleSettings(pvst); + + Console.WriteLine(snd.ToString()); } } }