mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
PowerLauncher Settings
* Cherry Picked commit branch due to merge conflicts * add HotkeySettingsControl * add localization strings * add PowerLauncherPage ViewModel * fix build dependency - settings.ui.runner depends on TwoWayIPCLib * uncomment IPC settings propagation
This commit is contained in:
committed by
Tomas Agustin Raies
parent
cea6b7067a
commit
443b3c8b82
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
{
|
||||
public class HotkeySettings
|
||||
{
|
||||
public bool win { get; set; }
|
||||
public bool ctrl { get; set; }
|
||||
public bool alt { get; set; }
|
||||
public bool shift { get; set; }
|
||||
public string key { get; set; }
|
||||
public int code { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
if (win)
|
||||
{
|
||||
output.Append("Win + ");
|
||||
}
|
||||
if (ctrl)
|
||||
{
|
||||
output.Append("Ctrl + ");
|
||||
}
|
||||
if (alt)
|
||||
{
|
||||
output.Append("Alt + ");
|
||||
}
|
||||
if (shift)
|
||||
{
|
||||
output.Append("Shift + ");
|
||||
}
|
||||
output.Append(key);
|
||||
return output.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
{
|
||||
public class PowerLauncherSettings : BasePTModuleSettings
|
||||
{
|
||||
public PowerLauncherProperties properties { get; set; }
|
||||
|
||||
public PowerLauncherSettings()
|
||||
{
|
||||
this.properties = new PowerLauncherProperties();
|
||||
this.version = "1";
|
||||
this.name = "_unset_";
|
||||
}
|
||||
}
|
||||
|
||||
public class PowerLauncherProperties
|
||||
{
|
||||
public bool enable_powerlauncher { get; set; }
|
||||
public string search_result_preference { get; set; }
|
||||
public string search_type_preference { get; set; }
|
||||
public int maximum_number_of_results { get; set; }
|
||||
public HotkeySettings open_powerlauncher { get; set; }
|
||||
public HotkeySettings open_file_location { get; set; }
|
||||
public HotkeySettings copy_path_location { get; set; }
|
||||
public HotkeySettings open_console { get; set; }
|
||||
public bool override_win_r_key { get; set; }
|
||||
public bool override_win_s_key { get; set; }
|
||||
|
||||
public PowerLauncherProperties()
|
||||
{
|
||||
open_powerlauncher = new HotkeySettings();
|
||||
open_file_location = new HotkeySettings();
|
||||
copy_path_location = new HotkeySettings();
|
||||
open_console = new HotkeySettings();
|
||||
search_result_preference = "most_recently_used";
|
||||
search_type_preference = "application_name";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,22 +8,48 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
{
|
||||
public static class SettingsUtils
|
||||
{
|
||||
// Get path to the json settings file.
|
||||
private static string LocalApplicationDataFolder()
|
||||
{
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
}
|
||||
|
||||
public static bool SettingsFolderExists(string powertoy)
|
||||
{
|
||||
return Directory.Exists(Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
public static void CreateSettingsFolder(string powertoy)
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get path to the json settings file.
|
||||
/// </summary>
|
||||
/// <returns>string path.</returns>
|
||||
public static string GetSettingsPath(string powertoy)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(powertoy))
|
||||
{
|
||||
return Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\settings.json");
|
||||
}
|
||||
|
||||
return Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\{powertoy}\\settings.json");
|
||||
}
|
||||
|
||||
// Get a Deserialized object of the json settings string.
|
||||
public static bool SettingsExists(string powertoy)
|
||||
{
|
||||
return File.Exists(SettingsUtils.GetSettingsPath(powertoy));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a Deserialized object of the json settings string.
|
||||
/// </summary>
|
||||
/// <returns>Deserialized json settings object.</returns>
|
||||
public static T GetSettings<T>(string powertoy)
|
||||
{
|
||||
var jsonSettingsString = System.IO.File.ReadAllText(SettingsUtils.GetSettingsPath(powertoy));
|
||||
@@ -31,11 +57,18 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
}
|
||||
|
||||
// Save settings to a json file.
|
||||
public static void SaveSettings(string moduleJsonSettings, string powertoyModuleName)
|
||||
public static void SaveSettings(string jsonSettings, string powertoy)
|
||||
{
|
||||
System.IO.File.WriteAllText(
|
||||
SettingsUtils.GetSettingsPath(powertoyModuleName),
|
||||
moduleJsonSettings);
|
||||
if(jsonSettings != null)
|
||||
{
|
||||
if (!SettingsFolderExists(powertoy))
|
||||
{
|
||||
CreateSettingsFolder(powertoy);
|
||||
}
|
||||
System.IO.File.WriteAllText(
|
||||
SettingsUtils.GetSettingsPath(powertoy),
|
||||
jsonSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user