2020-07-23 04:27:17 +08:00
|
|
|
// 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
|
|
|
|
{
|
|
|
|
private PowerLauncherSettings settings;
|
|
|
|
private GeneralSettings generalSettings;
|
|
|
|
|
|
|
|
public delegate void SendCallback(PowerLauncherSettings settings);
|
|
|
|
|
|
|
|
private readonly SendCallback callback;
|
|
|
|
|
|
|
|
public PowerLauncherViewModel()
|
|
|
|
{
|
|
|
|
callback = (PowerLauncherSettings settings) =>
|
|
|
|
{
|
|
|
|
// Propagate changes to Power Launcher through IPC
|
|
|
|
ShellPage.DefaultSndMSGCallback(
|
|
|
|
string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.ModuleName, JsonSerializer.Serialize(settings)));
|
|
|
|
};
|
|
|
|
if (SettingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
|
|
|
|
{
|
|
|
|
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
settings = new PowerLauncherSettings();
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.OpenPowerLauncher.Alt = true;
|
|
|
|
settings.Properties.OpenPowerLauncher.Code = (int)Windows.System.VirtualKey.Space;
|
|
|
|
settings.Properties.MaximumNumberOfResults = 4;
|
2020-07-23 04:27:17 +08:00
|
|
|
callback(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SettingsUtils.SettingsExists())
|
|
|
|
{
|
|
|
|
generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
generalSettings = new GeneralSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
|
|
|
|
{
|
|
|
|
this.settings = settings;
|
|
|
|
this.callback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateSettings([CallerMemberName] string propertyName = null)
|
|
|
|
{
|
|
|
|
// Notify UI of property change
|
|
|
|
OnPropertyChanged(propertyName);
|
|
|
|
|
|
|
|
callback(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool EnablePowerLauncher
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return generalSettings.Enabled.PowerLauncher;
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (generalSettings.Enabled.PowerLauncher != value)
|
|
|
|
{
|
|
|
|
generalSettings.Enabled.PowerLauncher = value;
|
|
|
|
OnPropertyChanged(nameof(EnablePowerLauncher));
|
|
|
|
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettings);
|
|
|
|
ShellPage.DefaultSndMSGCallback(outgoing.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string SearchResultPreference
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.SearchResultPreference;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.SearchResultPreference != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.SearchResultPreference = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string SearchTypePreference
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.SearchTypePreference;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.SearchTypePreference != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.SearchTypePreference = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int MaximumNumberOfResults
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.MaximumNumberOfResults;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.MaximumNumberOfResults != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.MaximumNumberOfResults = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings OpenPowerLauncher
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.OpenPowerLauncher;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.OpenPowerLauncher != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.OpenPowerLauncher = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public HotkeySettings OpenFileLocation
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.OpenFileLocation;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.OpenFileLocation != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.OpenFileLocation = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 06:58:01 +08:00
|
|
|
public HotkeySettings OpenConsole
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return settings.Properties.OpenConsole;
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (settings.Properties.OpenConsole != value)
|
|
|
|
{
|
|
|
|
settings.Properties.OpenConsole = value;
|
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 04:27:17 +08:00
|
|
|
public HotkeySettings CopyPathLocation
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.CopyPathLocation;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.CopyPathLocation != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.CopyPathLocation = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool OverrideWinRKey
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.OverrideWinkeyR;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.OverrideWinkeyR != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.OverrideWinkeyR = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool OverrideWinSKey
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.OverrideWinkeyS;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.OverrideWinkeyS != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.OverrideWinkeyS = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IgnoreHotkeysInFullScreen
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.IgnoreHotkeysInFullscreen;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.IgnoreHotkeysInFullscreen != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.IgnoreHotkeysInFullscreen = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ClearInputOnLaunch
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.ClearInputOnLaunch;
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.ClearInputOnLaunch != value)
|
2020-07-23 04:27:17 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.ClearInputOnLaunch = value;
|
2020-07-23 04:27:17 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 08:50:42 +08:00
|
|
|
public bool DisableDriveDetectionWarning
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
return settings.Properties.DisableDriveDetectionWarning;
|
2020-07-21 08:50:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
if (settings.Properties.DisableDriveDetectionWarning != value)
|
2020-07-21 08:50:42 +08:00
|
|
|
{
|
2020-07-24 02:01:49 +08:00
|
|
|
settings.Properties.DisableDriveDetectionWarning = value;
|
2020-07-21 08:50:42 +08:00
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
}
|
2020-07-23 04:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|