[Color Picker] Open settings (#13747)

* Add settings

* Added try catch and icon update

Co-authored-by: Laute <Niels.Laute@philips.com>
This commit is contained in:
Niels Laute
2021-10-11 18:03:40 +02:00
committed by GitHub
parent 85eddfc536
commit 0ca9b1be48
4 changed files with 31 additions and 4 deletions

View File

@@ -4,6 +4,8 @@
using System; using System;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Windows; using System.Windows;
using ColorPicker.Settings; using ColorPicker.Settings;
using ColorPicker.ViewModelContracts; using ColorPicker.ViewModelContracts;
@@ -134,6 +136,7 @@ namespace ColorPicker.Helpers
_colorEditorWindow = new ColorEditorWindow(this); _colorEditorWindow = new ColorEditorWindow(this);
_colorEditorWindow.Content = _colorEditorViewModel; _colorEditorWindow.Content = _colorEditorViewModel;
_colorEditorViewModel.OpenColorPickerRequested += ColorEditorViewModel_OpenColorPickerRequested; _colorEditorViewModel.OpenColorPickerRequested += ColorEditorViewModel_OpenColorPickerRequested;
_colorEditorViewModel.OpenSettingsRequested += ColorEditorViewModel_OpenSettingsRequested;
_colorEditorViewModel.OpenColorPickerRequested += (object sender, EventArgs e) => _colorEditorViewModel.OpenColorPickerRequested += (object sender, EventArgs e) =>
{ {
SessionEventHelper.Event.EditorColorPickerOpened = true; SessionEventHelper.Event.EditorColorPickerOpened = true;
@@ -183,5 +186,20 @@ namespace ColorPicker.Helpers
_colorEditorWindow.Hide(); _colorEditorWindow.Hide();
} }
private void ColorEditorViewModel_OpenSettingsRequested(object sender, EventArgs e)
{
try
{
var assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
var fullPath = Directory.GetParent(assemblyPath).FullName;
Process.Start(new ProcessStartInfo(fullPath + "\\..\\PowerToys.exe") { Arguments = "--open-settings=ColorPicker" });
}
#pragma warning disable CA1031 // Do not catch general exception types
catch
#pragma warning restore CA1031 // Do not catch general exception types
{
}
}
} }
} }

View File

@@ -14,8 +14,12 @@ namespace ColorPicker.ViewModelContracts
{ {
event EventHandler OpenColorPickerRequested; event EventHandler OpenColorPickerRequested;
event EventHandler OpenSettingsRequested;
ICommand OpenColorPickerCommand { get; } ICommand OpenColorPickerCommand { get; }
ICommand OpenSettingsCommand { get; }
ICommand RemoveColorCommand { get; } ICommand RemoveColorCommand { get; }
ObservableCollection<ColorFormatModel> ColorRepresentations { get; } ObservableCollection<ColorFormatModel> ColorRepresentations { get; }

View File

@@ -32,6 +32,7 @@ namespace ColorPicker.ViewModels
public ColorEditorViewModel(IUserSettings userSettings) public ColorEditorViewModel(IUserSettings userSettings)
{ {
OpenColorPickerCommand = new RelayCommand(() => OpenColorPickerRequested?.Invoke(this, EventArgs.Empty)); OpenColorPickerCommand = new RelayCommand(() => OpenColorPickerRequested?.Invoke(this, EventArgs.Empty));
OpenSettingsCommand = new RelayCommand(() => OpenSettingsRequested?.Invoke(this, EventArgs.Empty));
RemoveColorCommand = new RelayCommand(DeleteSelectedColor); RemoveColorCommand = new RelayCommand(DeleteSelectedColor);
SelectedColorChangedCommand = new RelayCommand((newColor) => SelectedColorChangedCommand = new RelayCommand((newColor) =>
@@ -47,8 +48,12 @@ namespace ColorPicker.ViewModels
public event EventHandler OpenColorPickerRequested; public event EventHandler OpenColorPickerRequested;
public event EventHandler OpenSettingsRequested;
public ICommand OpenColorPickerCommand { get; } public ICommand OpenColorPickerCommand { get; }
public ICommand OpenSettingsCommand { get; }
public ICommand RemoveColorCommand { get; } public ICommand RemoveColorCommand { get; }
public ICommand SelectedColorChangedCommand { get; } public ICommand SelectedColorChangedCommand { get; }

View File

@@ -82,17 +82,17 @@
VerticalAlignment="Center" VerticalAlignment="Center"
Margin="0,1,0,0" /> Margin="0,1,0,0" />
<!-- Enable once we have settings linking available --> <Button Width="46"
<!--<Button Width="46" Command="{Binding OpenSettingsCommand}"
Height="32" Height="32"
Content="&#xE115;" Content="&#xE713;"
TabIndex="2" TabIndex="2"
Background="Transparent" Background="Transparent"
FontFamily="Segoe MDL2 Assets" FontFamily="Segoe MDL2 Assets"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,46,0" Margin="0,0,46,0"
ToolTipService.ToolTip="{x:Static p:Resources.Open_settings}" ToolTipService.ToolTip="{x:Static p:Resources.Open_settings}"
AutomationProperties.Name="{x:Static p:Resources.Open_settings}" />--> AutomationProperties.Name="{x:Static p:Resources.Open_settings}" />
<Button Width="64" <Button Width="64"
Height="32" Height="32"