[ColorPicker]Add option to choose what clicking individual mouse buttons does (#39025)

## Summary of the Pull Request
Enables the users to choose what left, right, and middle click does when
color picker is open.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] **Closes:** #39006
- [x] **Communication:** I've discussed this with core contributors
already
- [x] **Tests:** All pass
- [x] **Localization:** All end user facing strings can be localized
- [x] **Dev docs:** No need
- [x] **New binaries:** None
- [x] **Documentation updated:** No need
## Detailed Description of the Pull Request / Additional comments
![Screenshot of the
settings](https://github.com/user-attachments/assets/a3e1349b-6bb9-4e2f-97f3-a5106a7d92ce)
Adds option to choose from 3 click behaviors for each standard mouse
button:
* **Pick color and open editor**: Copies color to clipboard, saves it to
the color history and opens the editor
* **Pick color and close**: Copies color to clipboard, saves it to the
color history and exits
* **Close**: Closes color picker without copying the color

Pressing <kbd>Enter</kbd> or <kbd>Space</kbd> does what clicking the
primary button would.
Left and middle click actions execute on mouse down, right click on
mouse up for reasons discussed previously (I can't find the conversation
now)
Default settings are chosen in such a way that very little or nothing
changes by updating.
## Validation Steps Performed
Tested:
* Migrating settings from v2.0 to v2.1 (v1 to v2.1 not tested)
* Settings page displays and saves settings correctly
* Default settings load correctly
* All three click actions do what they are supposed to
* Activation behavior works as expected, doesn't affect click actions
This commit is contained in:
PesBandi
2025-06-13 12:01:40 +02:00
committed by GitHub
parent 2d1676b7df
commit ce058f1dc7
17 changed files with 291 additions and 66 deletions

View File

@@ -50,12 +50,39 @@
<tkcontrols:SettingsCard x:Uid="ColorPicker_ActivationAction" HeaderIcon="{ui:FontIcon Glyph=&#xEC4E;}">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.ActivationBehavior, Mode=TwoWay}">
<ComboBoxItem x:Uid="EditorFirst" />
<ComboBoxItem x:Uid="ColorPickerFirst" />
<ComboBoxItem x:Uid="ColorPickerOnly" />
<ComboBoxItem x:Uid="ColorPicker_OpenEditor" />
<ComboBoxItem x:Uid="ColorPicker_PickColor" />
</ComboBox>
</tkcontrols:SettingsCard>
<tkcontrols:SettingsExpander
x:Uid="ColorPicker_MouseActions"
HeaderIcon="{ui:FontIcon Glyph=&#xE962;}"
IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard x:Uid="ColorPicker_PrimaryClick" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind ViewModel.PrimaryClickBehavior, Mode=TwoWay}">
<ComboBoxItem x:Uid="ColorPicker_PickColorThenEditor" />
<ComboBoxItem x:Uid="ColorPicker_PickColorAndClose" />
<ComboBoxItem x:Uid="ColorPicker_Close" />
</ComboBox>
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard x:Uid="ColorPicker_MiddleClick" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind ViewModel.MiddleClickBehavior, Mode=TwoWay}">
<ComboBoxItem x:Uid="ColorPicker_PickColorThenEditor" />
<ComboBoxItem x:Uid="ColorPicker_PickColorAndClose" />
<ComboBoxItem x:Uid="ColorPicker_Close" />
</ComboBox>
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard x:Uid="ColorPicker_SecondaryClick" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind ViewModel.SecondaryClickBehavior, Mode=TwoWay}">
<ComboBoxItem x:Uid="ColorPicker_PickColorThenEditor" />
<ComboBoxItem x:Uid="ColorPicker_PickColorAndClose" />
<ComboBoxItem x:Uid="ColorPicker_Close" />
</ComboBox>
</tkcontrols:SettingsCard>
</tkcontrols:SettingsExpander.Items>
</tkcontrols:SettingsExpander>
</controls:SettingsGroup>
<controls:SettingsGroup x:Uid="ColorFormats" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">

View File

@@ -1507,18 +1507,39 @@ Made with 💗 by Microsoft and the PowerToys community.</value>
<data name="ColorPicker_CopiedColorRepresentation.Header" xml:space="preserve">
<value>Default color format</value>
</data>
<data name="ColorPickerFirst.Content" xml:space="preserve">
<value>Pick a color and open editor</value>
</data>
<data name="EditorFirst.Content" xml:space="preserve">
<value>Open editor</value>
</data>
<data name="ColorPickerOnly.Content" xml:space="preserve">
<value>Only pick a color</value>
</data>
<data name="ColorPicker_ActivationAction.Header" xml:space="preserve">
<value>Activation behavior</value>
</data>
<data name="ColorPicker_OpenEditor.Content" xml:space="preserve">
<value>Open editor</value>
</data>
<data name="ColorPicker_PickColor.Content" xml:space="preserve">
<value>Pick a color first</value>
</data>
<data name="ColorPicker_MouseActions.Header" xml:space="preserve">
<value>Mouse actions</value>
</data>
<data name="ColorPicker_MouseActions.Description" xml:space="preserve">
<value>Choose what clicking individual buttons does</value>
</data>
<data name="ColorPicker_PrimaryClick.Header" xml:space="preserve">
<value>Primary click</value>
</data>
<data name="ColorPicker_MiddleClick.Header" xml:space="preserve">
<value>Middle click</value>
</data>
<data name="ColorPicker_SecondaryClick.Header" xml:space="preserve">
<value>Secondary click</value>
</data>
<data name="ColorPicker_PickColorThenEditor.Content" xml:space="preserve">
<value>Pick a color and open editor</value>
</data>
<data name="ColorPicker_PickColorAndClose.Content" xml:space="preserve">
<value>Pick a color and close</value>
</data>
<data name="ColorPicker_Close.Content" xml:space="preserve">
<value>Close</value>
</data>
<data name="ColorFormats.Header" xml:space="preserve">
<value>Picker behavior</value>
</data>

View File

@@ -182,6 +182,51 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public int PrimaryClickBehavior
{
get => (int)_colorPickerSettings.Properties.PrimaryClickAction;
set
{
if (value != (int)_colorPickerSettings.Properties.PrimaryClickAction)
{
_colorPickerSettings.Properties.PrimaryClickAction = (ColorPickerClickAction)value;
OnPropertyChanged(nameof(PrimaryClickBehavior));
NotifySettingsChanged();
}
}
}
public int MiddleClickBehavior
{
get => (int)_colorPickerSettings.Properties.MiddleClickAction;
set
{
if (value != (int)_colorPickerSettings.Properties.MiddleClickAction)
{
_colorPickerSettings.Properties.MiddleClickAction = (ColorPickerClickAction)value;
OnPropertyChanged(nameof(MiddleClickBehavior));
NotifySettingsChanged();
}
}
}
public int SecondaryClickBehavior
{
get => (int)_colorPickerSettings.Properties.SecondaryClickAction;
set
{
if (value != (int)_colorPickerSettings.Properties.SecondaryClickAction)
{
_colorPickerSettings.Properties.SecondaryClickAction = (ColorPickerClickAction)value;
OnPropertyChanged(nameof(SecondaryClickBehavior));
NotifySettingsChanged();
}
}
}
public bool ShowColorName
{
get => _colorPickerSettings.Properties.ShowColorName;