PowerToys/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/PowerLauncherViewModel.cs

497 lines
14 KiB
C#
Raw Normal View History

2020-08-17 19:00:56 +02: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;
2021-02-26 12:21:58 +01:00
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
2021-02-26 12:21:58 +01:00
using System.Linq;
2020-08-17 19:00:56 +02:00
using System.Runtime.CompilerServices;
using System.Text.Json;
2021-08-12 14:53:12 +02:00
using System.Windows.Input;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
2021-08-12 14:53:12 +02:00
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
2020-08-17 19:00:56 +02:00
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
2020-08-17 19:00:56 +02:00
{
public class PowerLauncherViewModel : Observable
{
private bool _isDarkThemeRadioButtonChecked;
private bool _isLightThemeRadioButtonChecked;
private bool _isSystemThemeRadioButtonChecked;
[PT Run] Run dialog now has monitor positioning options (#9492) * Run dialog now has monitor positioning options * add monitor index validation in window position calculation * correct path in page * change how radio buttons are declared to resolve them not being set based on setting * Change "follow mouse" wording Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> * PowerLauncher -> PowerToysRun for new variables/resources * correct header label id and update wording to PowerToys Run * only enable custom index if BOTH custom position radio checked and Run is enabled * retrieve list count of detected monitors to limit selection of MonitorToDisplayOn * add a link to Windows Display settings * fix display settings link * change how we get the number of connected monitors so we're not relying on presentation core, windowsbase etc which seem to fail the build * combine position and appearance headers * change references for custom position to "focus" * restore accidentally removed files * remove unused directives * hook up "active window" position with the launcher window * remove left overs * remove uneeded itemgroup * make resource prefixes consistent; using "Run_" * add etcoreapp to spell check * undo change to file not modified in the end * remove unused checkbox post rebase * remove change to reduce diff size * changes according to review * revert whitespace changes post rebase * revert resources * add changes back * Update src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw Add comment Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * remove unneeded resource string Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
2021-03-09 18:20:49 +01:00
private bool _isCursorPositionRadioButtonChecked;
private bool _isPrimaryMonitorPositionRadioButtonChecked;
private bool _isFocusPositionRadioButtonChecked;
2021-08-12 14:53:12 +02:00
private string _searchText;
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
private GeneralSettings GeneralSettingsConfig { get; set; }
2020-08-17 19:00:56 +02:00
private PowerLauncherSettings settings;
public delegate void SendCallback(PowerLauncherSettings settings);
private readonly SendCallback callback;
2021-02-26 12:21:58 +01:00
private readonly Func<bool> isDark;
private Func<string, int> SendConfigMSG { get; }
public PowerLauncherViewModel(PowerLauncherSettings settings, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<bool> isDark)
2020-08-17 19:00:56 +02:00
{
if (settings == null)
{
throw new ArgumentException("settings argument can not be null");
}
this.settings = settings;
2021-02-26 12:21:58 +01:00
this.isDark = isDark;
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
// To obtain the general Settings configurations of PowerToys
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
GeneralSettingsConfig = settingsRepository.SettingsConfig;
2020-09-10 18:44:10 +02:00
// set the callback functions value to hangle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
callback = (PowerLauncherSettings s) =>
2020-08-17 19:00:56 +02:00
{
2020-09-10 18:44:10 +02:00
// Propagate changes to Power Launcher through IPC
// Using InvariantCulture as this is an IPC message
2020-09-10 18:44:10 +02:00
SendConfigMSG(
string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
PowerLauncherSettings.ModuleName,
JsonSerializer.Serialize(s)));
2020-09-10 18:44:10 +02:00
};
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
switch (settings.Properties.Theme)
{
case Theme.Light:
_isLightThemeRadioButtonChecked = true;
break;
case Theme.Dark:
_isDarkThemeRadioButtonChecked = true;
break;
case Theme.System:
_isSystemThemeRadioButtonChecked = true;
break;
}
2021-02-26 12:21:58 +01:00
[PT Run] Run dialog now has monitor positioning options (#9492) * Run dialog now has monitor positioning options * add monitor index validation in window position calculation * correct path in page * change how radio buttons are declared to resolve them not being set based on setting * Change "follow mouse" wording Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> * PowerLauncher -> PowerToysRun for new variables/resources * correct header label id and update wording to PowerToys Run * only enable custom index if BOTH custom position radio checked and Run is enabled * retrieve list count of detected monitors to limit selection of MonitorToDisplayOn * add a link to Windows Display settings * fix display settings link * change how we get the number of connected monitors so we're not relying on presentation core, windowsbase etc which seem to fail the build * combine position and appearance headers * change references for custom position to "focus" * restore accidentally removed files * remove unused directives * hook up "active window" position with the launcher window * remove left overs * remove uneeded itemgroup * make resource prefixes consistent; using "Run_" * add etcoreapp to spell check * undo change to file not modified in the end * remove unused checkbox post rebase * remove change to reduce diff size * changes according to review * revert whitespace changes post rebase * revert resources * add changes back * Update src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw Add comment Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * remove unneeded resource string Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
2021-03-09 18:20:49 +01:00
switch (settings.Properties.Position)
{
case StartupPosition.Cursor:
_isCursorPositionRadioButtonChecked = true;
break;
case StartupPosition.PrimaryMonitor:
_isPrimaryMonitorPositionRadioButtonChecked = true;
break;
case StartupPosition.Focus:
_isFocusPositionRadioButtonChecked = true;
break;
}
2021-02-26 12:21:58 +01:00
foreach (var plugin in Plugins)
{
plugin.PropertyChanged += OnPluginInfoChange;
}
2021-08-12 14:53:12 +02:00
SearchPluginsCommand = new RelayCommand(SearchPlugins);
2021-02-26 12:21:58 +01:00
}
private void OnPluginInfoChange(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged(nameof(ShowAllPluginsDisabledWarning));
UpdateSettings();
2020-08-17 19:00:56 +02:00
}
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
{
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
return GeneralSettingsConfig.Enabled.PowerLauncher;
2020-08-17 19:00:56 +02:00
}
set
{
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
if (GeneralSettingsConfig.Enabled.PowerLauncher != value)
2020-08-17 19:00:56 +02:00
{
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
GeneralSettingsConfig.Enabled.PowerLauncher = value;
2020-08-17 19:00:56 +02:00
OnPropertyChanged(nameof(EnablePowerLauncher));
2021-02-26 12:21:58 +01:00
OnPropertyChanged(nameof(ShowAllPluginsDisabledWarning));
OnPropertyChanged(nameof(ShowPluginsLoadingMessage));
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoing.ToString());
2020-08-17 19:00:56 +02:00
}
}
}
public string SearchResultPreference
{
get
{
return settings.Properties.SearchResultPreference;
}
set
{
if (settings.Properties.SearchResultPreference != value)
{
settings.Properties.SearchResultPreference = value;
UpdateSettings();
}
}
}
public string SearchTypePreference
{
get
{
return settings.Properties.SearchTypePreference;
}
set
{
if (settings.Properties.SearchTypePreference != value)
{
settings.Properties.SearchTypePreference = value;
UpdateSettings();
}
}
}
public int MaximumNumberOfResults
{
get
{
return settings.Properties.MaximumNumberOfResults;
}
set
{
if (settings.Properties.MaximumNumberOfResults != value)
{
settings.Properties.MaximumNumberOfResults = value;
UpdateSettings();
}
}
}
public bool IsDarkThemeRadioButtonChecked
{
get
{
return _isDarkThemeRadioButtonChecked;
}
set
{
if (value == true)
{
settings.Properties.Theme = Theme.Dark;
_isDarkThemeRadioButtonChecked = value;
UpdateSettings();
}
}
}
public bool IsLightThemeRadioButtonChecked
{
get
{
return _isLightThemeRadioButtonChecked;
}
set
{
if (value == true)
{
settings.Properties.Theme = Theme.Light;
_isDarkThemeRadioButtonChecked = value;
UpdateSettings();
}
}
}
public bool IsSystemThemeRadioButtonChecked
{
get
{
return _isSystemThemeRadioButtonChecked;
}
set
{
if (value == true)
{
settings.Properties.Theme = Theme.System;
_isDarkThemeRadioButtonChecked = value;
UpdateSettings();
}
}
}
[PT Run] Run dialog now has monitor positioning options (#9492) * Run dialog now has monitor positioning options * add monitor index validation in window position calculation * correct path in page * change how radio buttons are declared to resolve them not being set based on setting * Change "follow mouse" wording Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> * PowerLauncher -> PowerToysRun for new variables/resources * correct header label id and update wording to PowerToys Run * only enable custom index if BOTH custom position radio checked and Run is enabled * retrieve list count of detected monitors to limit selection of MonitorToDisplayOn * add a link to Windows Display settings * fix display settings link * change how we get the number of connected monitors so we're not relying on presentation core, windowsbase etc which seem to fail the build * combine position and appearance headers * change references for custom position to "focus" * restore accidentally removed files * remove unused directives * hook up "active window" position with the launcher window * remove left overs * remove uneeded itemgroup * make resource prefixes consistent; using "Run_" * add etcoreapp to spell check * undo change to file not modified in the end * remove unused checkbox post rebase * remove change to reduce diff size * changes according to review * revert whitespace changes post rebase * revert resources * add changes back * Update src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw Add comment Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * remove unneeded resource string Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
2021-03-09 18:20:49 +01:00
public bool IsCursorPositionRadioButtonChecked
{
get
{
return _isCursorPositionRadioButtonChecked;
}
set
{
if (value == true)
{
settings.Properties.Position = StartupPosition.Cursor;
2021-03-31 20:54:10 +02:00
_isCursorPositionRadioButtonChecked = value;
UpdateSettings();
[PT Run] Run dialog now has monitor positioning options (#9492) * Run dialog now has monitor positioning options * add monitor index validation in window position calculation * correct path in page * change how radio buttons are declared to resolve them not being set based on setting * Change "follow mouse" wording Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> * PowerLauncher -> PowerToysRun for new variables/resources * correct header label id and update wording to PowerToys Run * only enable custom index if BOTH custom position radio checked and Run is enabled * retrieve list count of detected monitors to limit selection of MonitorToDisplayOn * add a link to Windows Display settings * fix display settings link * change how we get the number of connected monitors so we're not relying on presentation core, windowsbase etc which seem to fail the build * combine position and appearance headers * change references for custom position to "focus" * restore accidentally removed files * remove unused directives * hook up "active window" position with the launcher window * remove left overs * remove uneeded itemgroup * make resource prefixes consistent; using "Run_" * add etcoreapp to spell check * undo change to file not modified in the end * remove unused checkbox post rebase * remove change to reduce diff size * changes according to review * revert whitespace changes post rebase * revert resources * add changes back * Update src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw Add comment Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * remove unneeded resource string Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
2021-03-09 18:20:49 +01:00
}
}
}
public bool IsPrimaryMonitorPositionRadioButtonChecked
{
get
{
return _isPrimaryMonitorPositionRadioButtonChecked;
}
set
{
if (value == true)
{
settings.Properties.Position = StartupPosition.PrimaryMonitor;
2021-03-31 20:54:10 +02:00
_isPrimaryMonitorPositionRadioButtonChecked = value;
UpdateSettings();
[PT Run] Run dialog now has monitor positioning options (#9492) * Run dialog now has monitor positioning options * add monitor index validation in window position calculation * correct path in page * change how radio buttons are declared to resolve them not being set based on setting * Change "follow mouse" wording Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> * PowerLauncher -> PowerToysRun for new variables/resources * correct header label id and update wording to PowerToys Run * only enable custom index if BOTH custom position radio checked and Run is enabled * retrieve list count of detected monitors to limit selection of MonitorToDisplayOn * add a link to Windows Display settings * fix display settings link * change how we get the number of connected monitors so we're not relying on presentation core, windowsbase etc which seem to fail the build * combine position and appearance headers * change references for custom position to "focus" * restore accidentally removed files * remove unused directives * hook up "active window" position with the launcher window * remove left overs * remove uneeded itemgroup * make resource prefixes consistent; using "Run_" * add etcoreapp to spell check * undo change to file not modified in the end * remove unused checkbox post rebase * remove change to reduce diff size * changes according to review * revert whitespace changes post rebase * revert resources * add changes back * Update src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw Add comment Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * remove unneeded resource string Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
2021-03-09 18:20:49 +01:00
}
}
}
public bool IsFocusPositionRadioButtonChecked
{
get
{
return _isFocusPositionRadioButtonChecked;
}
set
{
if (value == true)
{
settings.Properties.Position = StartupPosition.Focus;
2021-03-31 20:54:10 +02:00
_isFocusPositionRadioButtonChecked = value;
UpdateSettings();
[PT Run] Run dialog now has monitor positioning options (#9492) * Run dialog now has monitor positioning options * add monitor index validation in window position calculation * correct path in page * change how radio buttons are declared to resolve them not being set based on setting * Change "follow mouse" wording Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> * PowerLauncher -> PowerToysRun for new variables/resources * correct header label id and update wording to PowerToys Run * only enable custom index if BOTH custom position radio checked and Run is enabled * retrieve list count of detected monitors to limit selection of MonitorToDisplayOn * add a link to Windows Display settings * fix display settings link * change how we get the number of connected monitors so we're not relying on presentation core, windowsbase etc which seem to fail the build * combine position and appearance headers * change references for custom position to "focus" * restore accidentally removed files * remove unused directives * hook up "active window" position with the launcher window * remove left overs * remove uneeded itemgroup * make resource prefixes consistent; using "Run_" * add etcoreapp to spell check * undo change to file not modified in the end * remove unused checkbox post rebase * remove change to reduce diff size * changes according to review * revert whitespace changes post rebase * revert resources * add changes back * Update src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw Add comment Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * remove unneeded resource string Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
2021-03-09 18:20:49 +01:00
}
}
}
2021-08-12 14:53:12 +02:00
public string SearchText
{
get
{
return _searchText;
}
set
{
if (_searchText != value)
{
_searchText = value;
OnPropertyChanged(nameof(SearchText));
}
}
}
public ICommand SearchPluginsCommand { get; }
2020-08-17 19:00:56 +02:00
public HotkeySettings OpenPowerLauncher
{
get
{
return settings.Properties.OpenPowerLauncher;
}
set
{
if (settings.Properties.OpenPowerLauncher != value)
{
settings.Properties.OpenPowerLauncher = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenFileLocation
{
get
{
return settings.Properties.OpenFileLocation;
}
set
{
if (settings.Properties.OpenFileLocation != value)
{
settings.Properties.OpenFileLocation = value;
UpdateSettings();
}
}
}
public HotkeySettings CopyPathLocation
{
get
{
return settings.Properties.CopyPathLocation;
}
set
{
if (settings.Properties.CopyPathLocation != value)
{
settings.Properties.CopyPathLocation = value;
UpdateSettings();
}
}
}
public bool OverrideWinRKey
{
get
{
return settings.Properties.OverrideWinkeyR;
}
set
{
if (settings.Properties.OverrideWinkeyR != value)
{
settings.Properties.OverrideWinkeyR = value;
UpdateSettings();
}
}
}
public bool OverrideWinSKey
{
get
{
return settings.Properties.OverrideWinkeyS;
}
set
{
if (settings.Properties.OverrideWinkeyS != value)
{
settings.Properties.OverrideWinkeyS = value;
UpdateSettings();
}
}
}
public bool IgnoreHotkeysInFullScreen
{
get
{
return settings.Properties.IgnoreHotkeysInFullscreen;
}
set
{
if (settings.Properties.IgnoreHotkeysInFullscreen != value)
{
settings.Properties.IgnoreHotkeysInFullscreen = value;
UpdateSettings();
}
}
}
public bool ClearInputOnLaunch
{
get
{
return settings.Properties.ClearInputOnLaunch;
}
set
{
if (settings.Properties.ClearInputOnLaunch != value)
{
settings.Properties.ClearInputOnLaunch = value;
UpdateSettings();
}
}
}
2021-02-26 12:21:58 +01:00
private ObservableCollection<PowerLauncherPluginViewModel> _plugins;
public ObservableCollection<PowerLauncherPluginViewModel> Plugins
2020-08-17 19:00:56 +02:00
{
get
{
2021-02-26 12:21:58 +01:00
if (_plugins == null)
2020-08-17 19:00:56 +02:00
{
2021-02-26 12:21:58 +01:00
_plugins = new ObservableCollection<PowerLauncherPluginViewModel>(settings.Plugins.Select(x => new PowerLauncherPluginViewModel(x, isDark)));
2020-08-17 19:00:56 +02:00
}
2021-02-26 12:21:58 +01:00
return _plugins;
2020-08-17 19:00:56 +02:00
}
}
2021-02-26 12:21:58 +01:00
public bool ShowAllPluginsDisabledWarning
{
get => EnablePowerLauncher && Plugins.Any() && Plugins.All(x => x.Disabled);
}
public bool ShowPluginsLoadingMessage
{
get => EnablePowerLauncher && !Plugins.Any();
2021-02-26 12:21:58 +01:00
}
public bool IsUpToDate(PowerLauncherSettings settings)
{
return this.settings.Equals(settings);
}
2021-08-12 14:53:12 +02:00
public void SearchPlugins()
{
if (!string.IsNullOrWhiteSpace(SearchText))
{
var plugins = settings.Plugins.Where(p => p.Name.StartsWith(SearchText, StringComparison.OrdinalIgnoreCase) || p.Name.IndexOf($" {SearchText}", StringComparison.OrdinalIgnoreCase) > 0);
_plugins = new ObservableCollection<PowerLauncherPluginViewModel>(plugins.Select(x => new PowerLauncherPluginViewModel(x, isDark)));
}
else
{
_plugins = null;
}
OnPropertyChanged(nameof(Plugins));
}
2020-08-17 19:00:56 +02:00
}
}