mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
New color picker module - integrated from github.com/martinchrzan/Col… (#4778)
* New color picker module - integrated from github.com/martinchrzan/ColorPicker * Trying to fix build in github * Replaced icon in the settings to use font icon instead of path icon * Closing ColorPicker.exe when PowerToys process closed, added color picker project into runner dependencies, restoring cursors on exit, added ManagedCommon as a dependency into installer * User/ryanbod/fix colorpicker release (#5046) * Changing configuration to x64 instead of AnyCPU. The previous configuration was preventing the ManagedCommon binary from being loaded in Release. * Updating MSI Installer with new icons (#4998) * Adding missed dll into installer * Fixed potential exception * Creating settings.json on the first start when there are none, fixed default keyboard shortcut * Added ColorPicker.exe.config into installer * Start filewatcher after default settings file is created * Fixing build Co-authored-by: ryanbodrug-microsoft <56318517+ryanbodrug-microsoft@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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 ColorPickerViewModel : Observable
|
||||
{
|
||||
private ColorPickerSettings _colorPickerSettings;
|
||||
private bool _isEnabled;
|
||||
|
||||
public ColorPickerViewModel()
|
||||
{
|
||||
if (SettingsUtils.SettingsExists(ColorPickerSettings.ModuleName))
|
||||
{
|
||||
_colorPickerSettings = SettingsUtils.GetSettings<ColorPickerSettings>(ColorPickerSettings.ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_colorPickerSettings = new ColorPickerSettings();
|
||||
}
|
||||
|
||||
if (SettingsUtils.SettingsExists())
|
||||
{
|
||||
var generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
|
||||
_isEnabled = generalSettings.Enabled.ColorPicker;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_isEnabled != value)
|
||||
{
|
||||
_isEnabled = value;
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
|
||||
// grab the latest version of settings
|
||||
var generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
|
||||
generalSettings.Enabled.ColorPicker = value;
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettings);
|
||||
ShellPage.DefaultSndMSGCallback(outgoing.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ChangeCursor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorPickerSettings.properties.ChangeCursor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.properties.ChangeCursor != value)
|
||||
{
|
||||
_colorPickerSettings.properties.ChangeCursor = value;
|
||||
OnPropertyChanged(nameof(ChangeCursor));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings ActivationShortcut
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorPickerSettings.properties.ActivationShortcut;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.properties.ActivationShortcut != value)
|
||||
{
|
||||
_colorPickerSettings.properties.ActivationShortcut = value;
|
||||
OnPropertyChanged(nameof(ActivationShortcut));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int CopiedColorRepresentationIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)_colorPickerSettings.properties.CopiedColorRepresentation;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.properties.CopiedColorRepresentation != (ColorRepresentationType)value)
|
||||
{
|
||||
_colorPickerSettings.properties.CopiedColorRepresentation = (ColorRepresentationType)value;
|
||||
OnPropertyChanged(nameof(CopiedColorRepresentationIndex));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifySettingsChanged()
|
||||
{
|
||||
ShellPage.DefaultSndMSGCallback(
|
||||
string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", ColorPickerSettings.ModuleName, JsonSerializer.Serialize(_colorPickerSettings)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user