PowerToys/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerLauncherViewModel.cs

219 lines
6.1 KiB
C#
Raw Normal View History

// 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.Runtime.CompilerServices;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Views;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class PowerLauncherViewModel : Observable
{
2020-04-08 15:19:00 +08:00
private const string POWERTOYNAME = "PowerLauncher";
private PowerLauncherSettings settings;
public PowerLauncherViewModel()
{
2020-04-08 15:19:00 +08:00
if (SettingsUtils.SettingsExists(POWERTOYNAME))
{
2020-04-08 15:19:00 +08:00
this.settings = SettingsUtils.GetSettings<PowerLauncherSettings>(POWERTOYNAME);
}
else
{
2020-04-08 15:19:00 +08:00
this.settings = new PowerLauncherSettings();
}
}
private void UpdateSettings([CallerMemberName] string propertyName = null)
{
// Notify UI of property change
2020-04-08 15:19:00 +08:00
this.OnPropertyChanged(propertyName);
// Save settings to file
var options = new JsonSerializerOptions
{
2020-04-08 15:19:00 +08:00
WriteIndented = true,
};
2020-04-08 15:19:00 +08:00
SettingsUtils.SaveSettings(JsonSerializer.Serialize(this.settings, options), POWERTOYNAME);
// Propagate changes to Power Launcher through IPC
2020-04-08 15:19:00 +08:00
var propertiesJson = JsonSerializer.Serialize(this.settings.properties);
ShellPage.DefaultSndMSGCallback(
string.Format("{{ \"{0}\": {1} }}", POWERTOYNAME, JsonSerializer.Serialize(this.settings.properties)));
}
public bool EnablePowerLauncher
{
2020-04-08 15:19:00 +08:00
get
{
2020-04-08 15:19:00 +08:00
return this.settings.properties.enable_powerlauncher;
}
set
{
if (this.settings.properties.enable_powerlauncher != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.enable_powerlauncher = value;
this.UpdateSettings();
}
}
}
public string SearchResultPreference
{
2020-04-08 15:19:00 +08:00
get
{
return this.settings.properties.search_result_preference;
}
set
{
2020-04-08 15:19:00 +08:00
if (this.settings.properties.search_result_preference != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.search_result_preference = value;
this.UpdateSettings();
}
}
}
public string SearchTypePreference
{
2020-04-08 15:19:00 +08:00
get
{
return this.settings.properties.search_type_preference;
}
set
{
2020-04-08 15:19:00 +08:00
if (this.settings.properties.search_type_preference != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.search_type_preference = value;
this.UpdateSettings();
}
}
}
public int MaximumNumberOfResults
{
2020-04-08 15:19:00 +08:00
get
{
return this.settings.properties.maximum_number_of_results;
}
set
{
2020-04-08 15:19:00 +08:00
if (this.settings.properties.maximum_number_of_results != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.maximum_number_of_results = value;
this.UpdateSettings();
}
}
}
public HotkeySettings OpenPowerLauncher
{
2020-04-08 15:19:00 +08:00
get
{
return this.settings.properties.open_powerlauncher;
}
set
{
2020-04-08 15:19:00 +08:00
if (this.settings.properties.open_powerlauncher != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.open_powerlauncher = value;
this.UpdateSettings();
}
}
}
public HotkeySettings OpenFileLocation
{
2020-04-08 15:19:00 +08:00
get
{
return this.settings.properties.open_file_location;
}
set
{
2020-04-08 15:19:00 +08:00
if (this.settings.properties.open_file_location != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.open_file_location = value;
this.UpdateSettings();
}
}
}
public HotkeySettings CopyPathLocation
{
2020-04-08 15:19:00 +08:00
get
{
return this.settings.properties.copy_path_location;
}
set
{
2020-04-08 15:19:00 +08:00
if (this.settings.properties.copy_path_location != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.copy_path_location = value;
this.UpdateSettings();
}
}
}
public HotkeySettings OpenConsole
{
2020-04-08 15:19:00 +08:00
get
{
return this.settings.properties.open_console;
}
set
{
2020-04-08 15:19:00 +08:00
if (this.settings.properties.open_console != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.open_console = value;
this.UpdateSettings();
}
}
}
public bool OverrideWinRKey
{
2020-04-08 15:19:00 +08:00
get
{
return this.settings.properties.override_win_r_key;
}
set
{
2020-04-08 15:19:00 +08:00
if (this.settings.properties.override_win_r_key != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.override_win_r_key = value;
this.UpdateSettings();
}
}
}
public bool OverrideWinSKey
{
2020-04-08 15:19:00 +08:00
get
{
return this.settings.properties.override_win_s_key;
}
set
{
2020-04-08 15:19:00 +08:00
if (this.settings.properties.override_win_s_key != value)
{
2020-04-08 15:19:00 +08:00
this.settings.properties.override_win_s_key = value;
this.UpdateSettings();
}
}
}
}
2020-04-08 15:19:00 +08:00
}