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 PowerLauncherSettings settings;
|
2020-04-04 10:02:38 +08:00
|
|
|
|
2020-04-27 04:15:40 +08:00
|
|
|
public delegate void SendCallback(PowerLauncherSettings settings);
|
|
|
|
|
|
|
|
private readonly SendCallback callback;
|
|
|
|
|
2020-03-27 23:58:53 +08:00
|
|
|
public PowerLauncherViewModel()
|
|
|
|
{
|
2020-04-27 04:15:40 +08:00
|
|
|
if (SettingsUtils.SettingsExists(PowerLauncherSettings.POWERTOYNAME))
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-27 04:15:40 +08:00
|
|
|
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.POWERTOYNAME);
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
else
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings = new PowerLauncherSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
2020-04-27 04:15:40 +08:00
|
|
|
|
|
|
|
callback = (PowerLauncherSettings settings) =>
|
|
|
|
{
|
|
|
|
// Propagate changes to Power Launcher through IPC
|
|
|
|
var propertiesJson = JsonSerializer.Serialize(settings.properties);
|
|
|
|
ShellPage.DefaultSndMSGCallback(
|
|
|
|
string.Format("{{ \"{0}\": {1} }}", PowerLauncherSettings.POWERTOYNAME, JsonSerializer.Serialize(settings.properties)));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
|
|
|
|
{
|
|
|
|
this.settings = settings;
|
|
|
|
this.callback = callback;
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateSettings([CallerMemberName] string propertyName = null)
|
|
|
|
{
|
|
|
|
// Notify UI of property change
|
2020-04-11 06:22:07 +08:00
|
|
|
OnPropertyChanged(propertyName);
|
2020-04-04 10:02:38 +08:00
|
|
|
|
2020-04-27 04:15:40 +08:00
|
|
|
settings.Save();
|
|
|
|
callback(settings);
|
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-11 06:22:07 +08:00
|
|
|
return settings.properties.enable_powerlauncher;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.enable_powerlauncher != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.enable_powerlauncher = value;
|
|
|
|
UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string SearchResultPreference
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
return settings.properties.search_result_preference;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.search_result_preference != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.search_result_preference = value;
|
|
|
|
UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string SearchTypePreference
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
return settings.properties.search_type_preference;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.search_type_preference != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.search_type_preference = value;
|
|
|
|
UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int MaximumNumberOfResults
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
return settings.properties.maximum_number_of_results;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.maximum_number_of_results != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.maximum_number_of_results = value;
|
|
|
|
UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings OpenPowerLauncher
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
return settings.properties.open_powerlauncher;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.open_powerlauncher != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.open_powerlauncher = value;
|
|
|
|
UpdateSettings();
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings OpenFileLocation
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
return settings.properties.open_file_location;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.open_file_location != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.open_file_location = value;
|
|
|
|
UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings CopyPathLocation
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
return settings.properties.copy_path_location;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.copy_path_location != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.copy_path_location = value;
|
|
|
|
UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings OpenConsole
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
return settings.properties.open_console;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.open_console != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.open_console = value;
|
|
|
|
UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool OverrideWinRKey
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
return settings.properties.override_win_r_key;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.override_win_r_key != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.override_win_r_key = value;
|
|
|
|
UpdateSettings();
|
2020-04-04 10:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool OverrideWinSKey
|
|
|
|
{
|
2020-04-08 15:19:00 +08:00
|
|
|
get
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
return settings.properties.override_win_s_key;
|
2020-04-08 15:19:00 +08:00
|
|
|
}
|
|
|
|
|
2020-04-04 10:02:38 +08:00
|
|
|
set
|
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
if (settings.properties.override_win_s_key != value)
|
2020-04-04 10:02:38 +08:00
|
|
|
{
|
2020-04-11 06:22:07 +08:00
|
|
|
settings.properties.override_win_s_key = value;
|
|
|
|
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
|
|
|
}
|