Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/tool/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="BBSFW.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<BBSFW.Properties.Settings>
<setting name="UseFreedomUnits" serializeAs="String">
<value>False</value>
</setting>
<setting name="LastLoadedFile" serializeAs="String">
<value />
</setting>
</BBSFW.Properties.Settings>
</userSettings>
</configuration>
18 changes: 17 additions & 1 deletion src/tool/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,17 @@ public byte[] WriteToBuffer()
}
}

/// <summary>
/// Creates a new Configuration, copies the contents to it, and returns the new config object
/// </summary>
/// <returns>A completely new config object with the same values as this configuration</returns>
public Configuration Clone()
{
Configuration newConfig = new Configuration();
newConfig.CopyFrom(this);
return newConfig;
}

public void CopyFrom(Configuration cfg)
{
Target = cfg.Target;
Expand Down Expand Up @@ -796,9 +807,14 @@ public void WriteToFile(string filepath)
{
var serializer = new XmlSerializer(typeof(Configuration));
var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true };
using (var xmlWriter = XmlWriter.Create(new StreamWriter(filepath), settings))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment. This definitely looks like it should work, but with the hotkeys you can cause an exception by just saving the config repeatedly very quickly. I suspect some part of the close() is asynchronous but I'm not too familiar with C# streaming.

// This line used to create a new xmlWriter directly, which seems like it should work,
// but it doesn't. (saving the same file repeatedly very fast causes exceptions)
// So we create a streamWriter and pass it to the xmlWriter so we can close it explicitly
using (var streamWriter = new StreamWriter(filepath))
{
var xmlWriter = XmlWriter.Create(streamWriter, settings);
serializer.Serialize(xmlWriter, this);
xmlWriter.Close();
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/tool/Properties/Settings.Designer.cs

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

5 changes: 4 additions & 1 deletion src/tool/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?xml version='1.0' encoding='utf-8'?>
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="BBSFW.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="UseFreedomUnits" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="LastLoadedFile" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
54 changes: 35 additions & 19 deletions src/tool/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
xmlns:vm="clr-namespace:BBSFW.ViewModel"
xmlns:vw="clr-namespace:BBSFW.View"
mc:Ignorable="d"
Title="BBS-FW Tool" Height="640" Width="860"
Background="#FFE8E8E8">
Title="{Binding ApplicationTitle}" Height="640" Width="860"
Background="#FFE8E8E8"
Closing="Window_Closing">

<Window.DataContext>
<vm:MainViewModel />
Expand All @@ -20,30 +21,32 @@
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>

<Menu Grid.Row="0">
<MenuItem Header="File" Height="22" VerticalContentAlignment="Center">
<MenuItem Header="Open..." Command="{Binding OpenConfigCommand}" />
<MenuItem Header="Save As..." Command="{Binding SaveConfigCommand}" />
<MenuItem Header="_File" Height="22" VerticalContentAlignment="Center">
<MenuItem Header="_Open..." Command="{Binding OpenConfigCommand}" InputGestureText="Ctrl+O" />
<MenuItem Header="_Close..." Command="{Binding CloseConfigCommand}" IsEnabled="{Binding ConfigFilenameExists}" InputGestureText="Ctrl+W" />
<MenuItem Header="_Save..." Command="{Binding SaveConfigCommand}" IsEnabled="{Binding ConfigFilenameExists}" InputGestureText="Ctrl+S" />
<MenuItem Header="Save As..." Command="{Binding SaveAsConfigCommand}" InputGestureText="Ctrl+Shift+S" />
<Separator />
<MenuItem Header="Save Log..." Command="{Binding SaveLogCommand}" />
<MenuItem Header="Save _Log..." Command="{Binding SaveLogCommand}" />
<Separator />
<MenuItem Header="Exit" Command="{Binding ExitCommand}" />
<MenuItem Header="E_xit" Command="{Binding ExitCommand}" InputGestureText="Alt+F4" />
</MenuItem>
<MenuItem Header="Flash" Height="22" VerticalContentAlignment="Center">
<MenuItem Header="Read" IsEnabled="{Binding ConnectionVm.IsConnected}" Command="{Binding ReadFlashCommand}" />
<MenuItem Header="Write" IsEnabled="{Binding ConnectionVm.IsConnected}" Command="{Binding WriteFlashCommand}" />
<MenuItem Header="F_lash" Height="22" VerticalContentAlignment="Center">
<MenuItem Header="_Read" IsEnabled="{Binding ConnectionVm.IsConnected}" Command="{Binding ReadFlashCommand}" InputGestureText="Ctrl+Shift+R" />
<MenuItem Header="_Write" IsEnabled="{Binding ConnectionVm.IsConnected}" Command="{Binding WriteFlashCommand}" InputGestureText="Ctrl+Shift+W" />
<Separator />
<MenuItem Header="Reset" IsEnabled="{Binding ConnectionVm.IsConnected}" Command="{Binding ResetFlashCommand}" />
<MenuItem Header="Rese_t" IsEnabled="{Binding ConnectionVm.IsConnected}" Command="{Binding ResetFlashCommand}" InputGestureText="Ctrl+Shift+D" />
</MenuItem>
<MenuItem Header="Options" Height="22" VerticalContentAlignment="Center">
<MenuItem Header="Units">
<MenuItem Header="Metric" IsCheckable="True" IsChecked="{Binding ConfigVm.UseMetricUnits}" />
<MenuItem Header="Imperial" IsCheckable="True" IsChecked="{Binding ConfigVm.UseImperialUnits}" />
<MenuItem Header="_Options" Height="22" VerticalContentAlignment="Center">
<MenuItem Header="_Units">
<MenuItem Header="_Metric" IsCheckable="True" IsChecked="{Binding ConfigVm.UseMetricUnits}" InputGestureText="Ctrl+Shift+M" />
<MenuItem Header="_Imperial" IsCheckable="True" IsChecked="{Binding ConfigVm.UseImperialUnits}" InputGestureText="Ctrl+Shift+I" />
</MenuItem>
</MenuItem>
<MenuItem Header="Help" Height="22" VerticalContentAlignment="Center">
<MenuItem Header="About" Command="{Binding ShowAboutCommand}" />
<MenuItem Header="_Help" Height="22" VerticalContentAlignment="Center">
<MenuItem Header="_About" Command="{Binding ShowAboutCommand}" />
</MenuItem>
</Menu>

Expand All @@ -64,6 +67,19 @@
<vw:EventLogView Margin="10" />
</TabItem>
</TabControl>

</Grid>

<Window.InputBindings>
<KeyBinding Key="o" Modifiers="Ctrl" Command="{Binding OpenConfigCommand}" />
<KeyBinding Key="s" Modifiers="Ctrl" Command="{Binding SaveConfigCommand}" />
<KeyBinding Key="s" Modifiers="Ctrl+Shift" Command="{Binding SaveAsConfigCommand}" />
<KeyBinding Key="w" Modifiers="Ctrl" Command="{Binding CloseConfigCommand}" />
<KeyBinding Key="F4" Modifiers="Alt" Command="{Binding ExitCommand}" />
<KeyBinding Key="r" Modifiers="Ctrl+Shift" Command="{Binding ReadFlashCommand}" />
<KeyBinding Key="w" Modifiers="Ctrl+Shift" Command="{Binding WriteFlashCommand}" />
<KeyBinding Key="d" Modifiers="Ctrl+Shift" Command="{Binding ResetFlashCommand}" />
<KeyBinding Key="m" Modifiers="Ctrl+Shift" Command="{Binding UseMetricUnitsCommand}" />
<KeyBinding Key="i" Modifiers="Ctrl+Shift" Command="{Binding UseImperialUnitsCommand}" />
</Window.InputBindings>

</Window>
15 changes: 15 additions & 0 deletions src/tool/View/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -24,5 +25,19 @@ public MainWindow()
{
InitializeComponent();
}

/// <summary>
/// Application closing callback.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Closing(object sender, CancelEventArgs e)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to intercept closing if we want to save the name of the currently open file. I could have just saved this upon load (and this is a bit more complicated a solution than doing that) so if that would be preferred I could change it, but I think this is a pretty reasonable solution. Note also that we can't cancel Application.shutDown() as it's just not supported. But window.close() is.

{
// Get the view model
if (DataContext is ViewModel.MainViewModel viewModel)
{
e.Cancel = viewModel.OnExitCancellable();
}
}
}
}
Loading