Skip to content

Commit

Permalink
Add option to hide settings panel
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN committed Feb 16, 2019
1 parent 38db081 commit a1ace0f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
7 changes: 5 additions & 2 deletions FlagCarrierWin/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
<value>https://oromit.de/hosts.php</value>
</setting>
<setting name="privateKey" serializeAs="String">
<value/>
<value />
</setting>
<setting name="publicKey" serializeAs="String">
<value/>
<value />
</setting>
<setting name="hideSettings" serializeAs="String">
<value>False</value>
</setting>
</FlagCarrierWin.Properties.Settings>
</userSettings>
Expand Down
20 changes: 20 additions & 0 deletions FlagCarrierWin/Controls/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Windows;
using System.Windows.Input;

using FlagCarrierBase;
using NdefLibrary.Ndef;
Expand All @@ -20,6 +21,10 @@ public MainWindow()
{
InitializeComponent();

RoutedCommand jumpToSettings = new RoutedCommand();
jumpToSettings.InputGestures.Add(new KeyGesture(Key.O, ModifierKeys.Control | ModifierKeys.Shift));
CommandBindings.Add(new CommandBinding(jumpToSettings, JumpToSettings));

nfcHandler = new NfcHandler();
nfcHandler.CardAdded += NfcHandler_CardAdded;
nfcHandler.StatusMessage += StatusMessage;
Expand All @@ -33,6 +38,21 @@ public MainWindow()

settingsControl.WriteToTagRequest += SettingsControl_WriteToTagRequest;
settingsControl.UpdatedSettings += loginControl.SettingsChanged;
settingsControl.UpdatedSettings += UpdatedSettings;

UpdatedSettings();
}

private void JumpToSettings(object sender, ExecutedRoutedEventArgs e)
{
mainTabControl.SelectedItem = settingsTab;
}

private void UpdatedSettings()
{
settingsTab.Visibility = Properties.Settings.Default.hideSettings
? Visibility.Hidden
: Visibility.Visible;
}

private void Window_Loaded(object sender, RoutedEventArgs e)
Expand Down
1 change: 1 addition & 0 deletions FlagCarrierWin/Controls/SettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<TextBlock Margin="0,2,0,5">Private Key</TextBlock>
<TextBox Name="privKeyBox" TextChanged="TextChanged" />
<Button Margin="0,5,0,5" Click="GeneratePair_Click">Generate Keypair</Button>
<CheckBox Name="hideSettingsCheckBox" Margin="0,5,0,5" Click="HideSettings_Click">Hide Settings</CheckBox>
</StackPanel>
<Button Name="applyButton" IsEnabled="False" Margin="2" Grid.Row="2" Grid.Column="0" Click="ApplyButton_Click">Apply</Button>
<Button Margin="2" Grid.Row="2" Grid.Column="1" Click="WriteToTagButton_Click">Write to tag</Button>
Expand Down
10 changes: 9 additions & 1 deletion FlagCarrierWin/Controls/SettingsControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ private void TextChanged(object sender, TextChangedEventArgs e)
applyButton.IsEnabled = true;
}

private void HideSettings_Click(object sender, RoutedEventArgs e)
{
applyButton.IsEnabled = true;
}

private void ApplyButton_Click(object sender, RoutedEventArgs args)
{
Properties.Settings.Default.deviceID = deviceIdBox.Text;
Expand All @@ -44,6 +49,7 @@ private void ApplyButton_Click(object sender, RoutedEventArgs args)
Properties.Settings.Default.targetUrl = targetUrlBox.Text;
Properties.Settings.Default.publicKey = pubKeyBox.Text;
Properties.Settings.Default.privateKey = privKeyBox.Text;
Properties.Settings.Default.hideSettings = (bool)hideSettingsCheckBox.IsChecked;
Properties.Settings.Default.Save();
applyButton.IsEnabled = false;
ApplyKeyPair();
Expand Down Expand Up @@ -78,6 +84,7 @@ private void ResetSettings()
targetUrlBox.Text = Properties.Settings.Default.targetUrl;
pubKeyBox.Text = Properties.Settings.Default.publicKey;
privKeyBox.Text = Properties.Settings.Default.privateKey;
hideSettingsCheckBox.IsChecked = Properties.Settings.Default.hideSettings;
applyButton.IsEnabled = false;
}

Expand All @@ -102,7 +109,8 @@ private void ApplyKeyPair()
privKey = null;

FlagCarrierBase.NdefHandler.SetKeys(pubKey, privKey);
} catch(FormatException)
}
catch (FormatException)
{
MessageBox.Show("Invalid base64 in keypair!", "Error");
return;
Expand Down
14 changes: 13 additions & 1 deletion FlagCarrierWin/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions FlagCarrierWin/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
<Setting Name="publicKey" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="hideSettings" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit a1ace0f

Please sign in to comment.