Skip to content

Commit

Permalink
[Color Picker] Open settings (#13747)
Browse files Browse the repository at this point in the history
* Add settings

* Added try catch and icon update

Co-authored-by: Laute <Niels.Laute@philips.com>
  • Loading branch information
niels9001 and Laute committed Oct 11, 2021
1 parent 85eddfc commit 0ca9b1b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using System;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Windows;
using ColorPicker.Settings;
using ColorPicker.ViewModelContracts;
Expand Down Expand Up @@ -134,6 +136,7 @@ private void ShowColorPickerEditor()
_colorEditorWindow = new ColorEditorWindow(this);
_colorEditorWindow.Content = _colorEditorViewModel;
_colorEditorViewModel.OpenColorPickerRequested += ColorEditorViewModel_OpenColorPickerRequested;
_colorEditorViewModel.OpenSettingsRequested += ColorEditorViewModel_OpenSettingsRequested;
_colorEditorViewModel.OpenColorPickerRequested += (object sender, EventArgs e) =>
{
SessionEventHelper.Event.EditorColorPickerOpened = true;
Expand Down Expand Up @@ -183,5 +186,20 @@ private void ColorEditorViewModel_OpenColorPickerRequested(object sender, EventA

_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
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ public interface IColorEditorViewModel
{
event EventHandler OpenColorPickerRequested;

event EventHandler OpenSettingsRequested;

ICommand OpenColorPickerCommand { get; }

ICommand OpenSettingsCommand { get; }

ICommand RemoveColorCommand { get; }

ObservableCollection<ColorFormatModel> ColorRepresentations { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ColorEditorViewModel : ViewModelBase, IColorEditorViewModel
public ColorEditorViewModel(IUserSettings userSettings)
{
OpenColorPickerCommand = new RelayCommand(() => OpenColorPickerRequested?.Invoke(this, EventArgs.Empty));
OpenSettingsCommand = new RelayCommand(() => OpenSettingsRequested?.Invoke(this, EventArgs.Empty));
RemoveColorCommand = new RelayCommand(DeleteSelectedColor);

SelectedColorChangedCommand = new RelayCommand((newColor) =>
Expand All @@ -47,8 +48,12 @@ public ColorEditorViewModel(IUserSettings userSettings)

public event EventHandler OpenColorPickerRequested;

public event EventHandler OpenSettingsRequested;

public ICommand OpenColorPickerCommand { get; }

public ICommand OpenSettingsCommand { get; }

public ICommand RemoveColorCommand { get; }

public ICommand SelectedColorChangedCommand { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@
VerticalAlignment="Center"
Margin="0,1,0,0" />

<!-- Enable once we have settings linking available -->
<!--<Button Width="46"
<Button Width="46"
Command="{Binding OpenSettingsCommand}"
Height="32"
Content="&#xE115;"
Content="&#xE713;"
TabIndex="2"
Background="Transparent"
FontFamily="Segoe MDL2 Assets"
HorizontalAlignment="Right"
Margin="0,0,46,0"
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"
Height="32"
Expand Down

0 comments on commit 0ca9b1b

Please sign in to comment.