Skip to content

Commit

Permalink
Added the possibility to set the favorite color "type" (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Apr 16, 2022
1 parent d00c6a9 commit 8057a95
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ColorPicker/Classes/Settings.cs
Expand Up @@ -21,6 +21,7 @@ MIT License
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using ColorPicker.Enums;
using LeoCorpLibrary;
using System;
using System.Diagnostics;
Expand Down Expand Up @@ -86,6 +87,11 @@ public class Settings
/// True if this is the first time ColorPicker is launched.
/// </summary>
public bool? IsFirstRun { get; set; }

/// <summary>
/// The favorite color type of the user.
/// </summary>
public ColorTypes? FavoriteColorType { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -124,6 +130,7 @@ public static void Load()
RestoreColorHistory = true,
RestorePaletteColorHistory = true,
IsFirstRun = true,
FavoriteColorType = ColorTypes.RGB,
}; // Create a new settings file

Save(); // Save the changes
Expand Down
6 changes: 5 additions & 1 deletion ColorPicker/Pages/SettingsPage.xaml
Expand Up @@ -148,7 +148,11 @@

<CheckBox Margin="0 5 0 2" x:Name="HEXUseUpperCaseChk" Style="{DynamicResource CheckBoxStyle1}" Content="{x:Static lang:Resources.UseUpperCaseHEX}" BorderThickness="3" Foreground="{Binding Source={StaticResource Foreground1}}" FontSize="14" VerticalContentAlignment="Center" Unchecked="HEXUseUpperCaseChk_Checked" Checked="HEXUseUpperCaseChk_Checked"/>

</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Static lang:Resources.DefaultColor}" Foreground="{Binding Source={StaticResource Foreground1}}" VerticalAlignment="Center"/>
<ComboBox SelectionChanged="FavoriteColorComboBox_SelectionChanged" BorderThickness="2" Padding="5" Style="{DynamicResource ComboBoxStyle1}" x:Name="FavoriteColorComboBox" Background="Transparent" BorderBrush="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource Foreground1}}" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</Expander>

<Expander Style="{DynamicResource ExpanderStyle1}" Margin="10,10,10,0" Background="{Binding Source={StaticResource Background2}}" Foreground="{Binding Source={StaticResource Foreground1}}">
Expand Down
20 changes: 20 additions & 0 deletions ColorPicker/Pages/SettingsPage.xaml.cs
Expand Up @@ -107,6 +107,11 @@ private async void InitUI()
Global.Settings.IsFirstRun = true; // Set default value
}

if (!Global.Settings.FavoriteColorType.HasValue)
{
Global.Settings.FavoriteColorType = Enums.ColorTypes.RGB; // Set default value
}

// Load checkboxes
CheckUpdatesOnStartChk.IsChecked = Global.Settings.CheckUpdatesOnStart; // Set
NotifyUpdatesChk.IsChecked = Global.Settings.NotifyUpdates; // Set
Expand All @@ -131,6 +136,14 @@ private async void InitUI()
{
Global.Settings.RGBSeparator = ";"; // Set
}

// Load FavoriteColorComboBox
for (int i = 0; i < Enum.GetValues(typeof(Enums.ColorTypes)).Length; i++)
{
FavoriteColorComboBox.Items.Add(Global.ColorTypesToString((Enums.ColorTypes)i));
}

FavoriteColorComboBox.SelectedIndex = (int)Global.Settings.FavoriteColorType; // Set selected index

RGBSeparatorTxt.Text = Global.Settings.RGBSeparator; // Set text

Expand Down Expand Up @@ -420,6 +433,7 @@ private void ResetSettingsLink_Click(object sender, RoutedEventArgs e)
RestoreColorHistory = true,
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,
}; // Create default settings

SettingsManager.Save(); // Save the changes
Expand Down Expand Up @@ -452,5 +466,11 @@ private void RestoreColorPaletteHistoryOnStartChk_Checked(object sender, RoutedE
Global.Settings.RestorePaletteColorHistory = RestoreColorPaletteHistoryOnStartChk.IsChecked; // Set
SettingsManager.Save(); // Save changes
}

private void FavoriteColorComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Global.Settings.FavoriteColorType = (Enums.ColorTypes)FavoriteColorComboBox.SelectedIndex; // Set
SettingsManager.Save(); // Save changes
}
}
}

0 comments on commit 8057a95

Please sign in to comment.