Skip to content

Commit

Permalink
Added the possibility to set default keyboard shortcuts (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Apr 17, 2022
1 parent 76c79fb commit 6a4eff1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
12 changes: 12 additions & 0 deletions ColorPicker/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public class Settings
/// The favorite color type of the user.
/// </summary>
public ColorTypes? FavoriteColorType { get; set; }

/// <summary>
/// The keyboard shortcut used to copy a color when selecting one.
/// </summary>
public string CopyKeyboardShortcut { get; set; }

/// <summary>
/// The keyboard shortcut used to start the selection of a color.
/// </summary>
public string SelectKeyboardShortcut { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -131,6 +141,8 @@ public static void Load()
RestorePaletteColorHistory = true,
IsFirstRun = true,
FavoriteColorType = ColorTypes.RGB,
CopyKeyboardShortcut = "Shift+C",
SelectKeyboardShortcut = "Shift+S",
}; // Create a new settings file

Save(); // Save the changes
Expand Down
4 changes: 2 additions & 2 deletions ColorPicker/Pages/PickerPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ private void InitUI()

Hook.GlobalEvents().OnCombination(new Dictionary<Combination, Action>
{
{ Combination.FromString("Shift+C"), HandleCopyKeyboard },
{ Combination.FromString("Shift+S"), HandleSelectKeyboard }
{ Combination.FromString(Global.Settings.CopyKeyboardShortcut), HandleCopyKeyboard },
{ Combination.FromString(Global.Settings.SelectKeyboardShortcut), HandleSelectKeyboard }
});

if (Global.Settings.RestoreColorHistory.Value && Global.ColorContentHistory.PickerColorsRGB.Count > 0)
Expand Down
18 changes: 18 additions & 0 deletions ColorPicker/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ private async void InitUI()
Global.Settings.FavoriteColorType = Enums.ColorTypes.RGB; // Set default value
}

if (string.IsNullOrEmpty(Global.Settings.CopyKeyboardShortcut))
{
Global.Settings.CopyKeyboardShortcut = "Shift+C"; // Set default value
}

if (string.IsNullOrEmpty(Global.Settings.SelectKeyboardShortcut))
{
Global.Settings.SelectKeyboardShortcut = "Shift+S"; // Set default value
}

// Load checkboxes
CheckUpdatesOnStartChk.IsChecked = Global.Settings.CheckUpdatesOnStart; // Set
NotifyUpdatesChk.IsChecked = Global.Settings.NotifyUpdates; // Set
Expand Down Expand Up @@ -458,6 +468,8 @@ private void ResetSettingsLink_Click(object sender, RoutedEventArgs e)
RestorePaletteColorHistory = true,
IsFirstRun = false, // False instead of true because the user just want to reset settings, not go through the "welcome" process again.
FavoriteColorType = Enums.ColorTypes.RGB,
CopyKeyboardShortcut = "Shift+C",
SelectKeyboardShortcut = "Shift+S",
}; // Create default settings

SettingsManager.Save(); // Save the changes
Expand Down Expand Up @@ -517,6 +529,9 @@ private void EditCopyShortcutBtn_Click(object sender, RoutedEventArgs e)
GlobalHook.KeyDown -= GlobalHook_KeyDown; // Unsubscribe
Global.KeyBoardShortcutsAvailable = true; // Set
if (CopyShortcutTxt.Text.Length == 0) CopyShortcutTxt.Text = "Shift+C"; // Set default

Global.Settings.CopyKeyboardShortcut = CopyShortcutTxt.Text; // Set
SettingsManager.Save(); // Save changes
}
}

Expand All @@ -539,6 +554,9 @@ private void EditSelectShortcutBtn_Click(object sender, RoutedEventArgs e)
GlobalHook.KeyDown -= GlobalHook_KeyDown; // Unsubscribe
Global.KeyBoardShortcutsAvailable = true; // Set
if (SelectShortcutTxt.Text.Length == 0) SelectShortcutTxt.Text = "Shift+S"; // Set default

Global.Settings.SelectKeyboardShortcut = SelectShortcutTxt.Text; // Set
SettingsManager.Save(); // Save changes
}
}
}
Expand Down

0 comments on commit 6a4eff1

Please sign in to comment.