2020-04-04 10:02:38 +08:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2020-04-08 01:19:14 +08:00
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
// See the LICENSE file in the project root for more information.
|
2020-04-04 10:02:38 +08:00
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using System.Text.Json;
|
2020-03-27 23:58:53 +08:00
|
|
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
2020-04-04 10:02:38 +08:00
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Views;
|
2020-03-27 23:58:53 +08:00
|
|
|
|
|
|
|
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;
|
2020-04-04 10:02:38 +08:00
|
|
|
|
2020-03-27 23:58:53 +08:00
|
|
|
public PowerLauncherViewModel()
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (SettingsUtils.SettingsExists(POWERTOYNAME))
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings = SettingsUtils.GetSettings<PowerLauncherSettings>(POWERTOYNAME);
|
|
|
|
}
|
|
|
|
else
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings = new PowerLauncherSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateSettings([CallerMemberName] string propertyName = null)
|
|
|
|
{
|
|
|
|
// Notify UI of property change
|
2020-04-08 15:19:00 +08:00
|
|
|
this.OnPropertyChanged(propertyName);
|
2020-04-04 10:02:38 +08:00
|
|
|
|
|
|
|
// Save settings to file
|
|
|
|
var options = new JsonSerializerOptions
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
WriteIndented = true,
|
2020-04-04 10:02:38 +08:00
|
|
|
};
|
2020-04-08 15:19:00 +08:00
|
|
|
SettingsUtils.SaveSettings(JsonSerializer.Serialize(this.settings, options), POWERTOYNAME);
|
2020-04-04 10:02:38 +08:00
|
|
|
|
|
|
|
// 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)));
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool EnablePowerLauncher
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
return this.settings.properties.enable_powerlauncher;
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (this.settings.properties.enable_powerlauncher != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.enable_powerlauncher = value;
|
|
|
|
this.UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string SearchResultPreference
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.settings.properties.search_result_preference;
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (this.settings.properties.search_result_preference != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.search_result_preference = value;
|
|
|
|
this.UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string SearchTypePreference
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.settings.properties.search_type_preference;
|
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (this.settings.properties.search_type_preference != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.search_type_preference = value;
|
|
|
|
this.UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int MaximumNumberOfResults
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.settings.properties.maximum_number_of_results;
|
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (this.settings.properties.maximum_number_of_results != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.maximum_number_of_results = value;
|
|
|
|
this.UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings OpenPowerLauncher
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.settings.properties.open_powerlauncher;
|
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (this.settings.properties.open_powerlauncher != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.open_powerlauncher = value;
|
|
|
|
this.UpdateSettings();
|
|
|
|
}
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings OpenFileLocation
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.settings.properties.open_file_location;
|
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (this.settings.properties.open_file_location != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.open_file_location = value;
|
|
|
|
this.UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings CopyPathLocation
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.settings.properties.copy_path_location;
|
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (this.settings.properties.copy_path_location != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.copy_path_location = value;
|
|
|
|
this.UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings OpenConsole
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.settings.properties.open_console;
|
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (this.settings.properties.open_console != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.open_console = value;
|
|
|
|
this.UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool OverrideWinRKey
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.settings.properties.override_win_r_key;
|
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (this.settings.properties.override_win_r_key != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.override_win_r_key = value;
|
|
|
|
this.UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool OverrideWinSKey
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.settings.properties.override_win_s_key;
|
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
if (this.settings.properties.override_win_s_key != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
this.settings.properties.override_win_s_key = value;
|
|
|
|
this.UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
2020-03-27 23:58:53 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|