Skip to content

Commit

Permalink
Added the possibility to export settings (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Jun 15, 2021
1 parent fb7a141 commit d3d6927
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 1 deletion.
24 changes: 24 additions & 0 deletions ColorPicker/Classes/Settings.cs
Expand Up @@ -28,6 +28,7 @@ MIT License
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Xml.Serialization;

namespace ColorPicker.Classes
Expand Down Expand Up @@ -122,5 +123,28 @@ public static void Save()

streamWriter.Dispose();
}

/// <summary>
/// Exports current settings.
/// </summary>
/// <param name="path">The path where the settings file should be exported.</param>
public static void Export(string path)
{
try
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Settings)); // Create XML Serializer

StreamWriter streamWriter = new StreamWriter(path); // The place where the file is going to be written
xmlSerializer.Serialize(streamWriter, Global.Settings);

streamWriter.Dispose();

MessageBox.Show(Properties.Resources.SettingsExportedSucessMsg, Properties.Resources.ColorPicker, MessageBoxButton.OK, MessageBoxImage.Information); // Show message
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Properties.Resources.ColorPicker, MessageBoxButton.OK, MessageBoxImage.Error); // Show error message
}
}
}
}
16 changes: 15 additions & 1 deletion ColorPicker/Pages/SettingsPage.xaml
Expand Up @@ -11,7 +11,7 @@
Title="SettingsPage">

<ScrollViewer HorizontalScrollBarVisibility="Hidden" Template="{DynamicResource ScrollViewerControlTemplate}" CanContentScroll="True" Height="344">
<Grid Height="640">
<Grid Height="700">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
Expand Down Expand Up @@ -85,6 +85,20 @@
<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"/>

<TextBlock Text="{x:Static lang:Resources.Data}" Foreground="{Binding Source={StaticResource Foreground1}}" FontWeight="Bold" FontSize="20" Margin="0,10,0,0"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Button x:Name="ImportBtn" Click="ImportBtn_Click" Background="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" FontWeight="Bold" Cursor="Hand" VerticalAlignment="Center" Margin="0,0,10,0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xF151;" FontWeight="Regular" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Margin="0,0,5,0" VerticalAlignment="Center" FontSize="16"/>
<TextBlock Text="{x:Static lang:Resources.Import}" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<Button x:Name="ExportBtn" Click="ExportBtn_Click" Background="{Binding Source={StaticResource Background2}}" Foreground="{Binding Source={StaticResource Foreground1}}" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" FontWeight="Bold" Cursor="Hand" VerticalAlignment="Center" MouseEnter="BtnEnter" MouseLeave="BtnLeave">
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xF1A5;" FontWeight="Regular" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Margin="0,0,5,0" VerticalAlignment="Center" FontSize="16"/>
<TextBlock Text="{x:Static lang:Resources.Export}" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>
<TextBlock x:Name="ResetSettingsLink" Text="{x:Static lang:Resources.ResetSettings}" Foreground="{Binding Source={StaticResource AccentColor}}" FontSize="14" FontWeight="Bold" Cursor="Hand" MouseLeftButtonDown="ResetSettingsLink_MouseLeftButtonDown">
<TextBlock.TextDecorations>
<TextDecoration/>
Expand Down
33 changes: 33 additions & 0 deletions ColorPicker/Pages/SettingsPage.xaml.cs
Expand Up @@ -23,6 +23,7 @@ MIT License
*/
using ColorPicker.Classes;
using LeoCorpLibrary;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -304,5 +305,37 @@ private void HEXUseUpperCaseChk_Checked(object sender, RoutedEventArgs e)
Global.Settings.HEXUseUpperCase = HEXUseUpperCaseChk.IsChecked; // Set
SettingsManager.Save(); // Save changes
}

private void ImportBtn_Click(object sender, RoutedEventArgs e)
{

}

private void ExportBtn_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog saveFileDialog = new()
{
FileName = "ColorPickerSettings.xml",
Filter = "XML|*.xml",
Title = Properties.Resources.Export
}; // Create file dialog

if (saveFileDialog.ShowDialog() ?? true)
{
SettingsManager.Export(saveFileDialog.FileName); // Export games
}
}

private void BtnEnter(object sender, MouseEventArgs e)
{
Button button = (Button)sender; // Create button
button.Foreground = new SolidColorBrush { Color = (Color)ColorConverter.ConvertFromString(App.Current.Resources["WindowButtonsHoverForeground1"].ToString()) }; // Set the foreground
}

private void BtnLeave(object sender, MouseEventArgs e)
{
Button button = (Button)sender; // Create button
button.Foreground = new SolidColorBrush { Color = (Color)ColorConverter.ConvertFromString(App.Current.Resources["Foreground1"].ToString()) }; // Set the foreground
}
}
}
36 changes: 36 additions & 0 deletions ColorPicker/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ColorPicker/Properties/Resources.en-US.resx
Expand Up @@ -339,4 +339,16 @@
<data name="UseUpperCaseHEX" xml:space="preserve">
<value>Use upper case for HEX colors</value>
</data>
<data name="Import" xml:space="preserve">
<value>Import settings</value>
</data>
<data name="Export" xml:space="preserve">
<value>Export settings</value>
</data>
<data name="SettingsExportedSucessMsg" xml:space="preserve">
<value>Settings exported sucessfully.</value>
</data>
<data name="SettingsImportedMsg" xml:space="preserve">
<value>Settings have been imported sucessfully. To finish the process, ColorPicker will now restart.</value>
</data>
</root>
12 changes: 12 additions & 0 deletions ColorPicker/Properties/Resources.fr-FR.resx
Expand Up @@ -339,4 +339,16 @@
<data name="UseUpperCaseHEX" xml:space="preserve">
<value>Utiliser des majuscules pour les couleurs HEX</value>
</data>
<data name="Import" xml:space="preserve">
<value>Importer les paramètres</value>
</data>
<data name="Export" xml:space="preserve">
<value>Exporter les paramètres</value>
</data>
<data name="SettingsExportedSucessMsg" xml:space="preserve">
<value>Les paramètres ont été exportés avec succès.</value>
</data>
<data name="SettingsImportedMsg" xml:space="preserve">
<value>Les paramètres ont été importés avec succès. Pour finir le processus, ColorPicker va redémarrer.</value>
</data>
</root>
12 changes: 12 additions & 0 deletions ColorPicker/Properties/Resources.resx
Expand Up @@ -319,4 +319,16 @@
<data name="UseUpperCaseHEX" xml:space="preserve">
<value>Use upper case for HEX colors</value>
</data>
<data name="Import" xml:space="preserve">
<value>Import settings</value>
</data>
<data name="Export" xml:space="preserve">
<value>Export settings</value>
</data>
<data name="SettingsExportedSucessMsg" xml:space="preserve">
<value>Settings exported sucessfully.</value>
</data>
<data name="SettingsImportedMsg" xml:space="preserve">
<value>Settings have been imported sucessfully. To finish the process, ColorPicker will now restart.</value>
</data>
</root>

0 comments on commit d3d6927

Please sign in to comment.