Skip to content

Commit

Permalink
Saving and loading layouts is now possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Nolin committed Aug 29, 2015
1 parent 67043e1 commit c2c110f
Show file tree
Hide file tree
Showing 13 changed files with 408 additions and 153 deletions.
315 changes: 197 additions & 118 deletions FaceSplit/Model/LayoutSettings.cs

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions FaceSplit/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 FaceSplit/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,8 @@
<Setting Name="SegmentTimerPausedColor" Type="System.Drawing.Color" Scope="User">
<Value Profile="(Default)">Yellow</Value>
</Setting>
<Setting Name="LayoutSettingsFile" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
44 changes: 37 additions & 7 deletions FaceSplit/View/FaceSplit.Designer.cs

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

121 changes: 98 additions & 23 deletions FaceSplit/View/FaceSplit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using System.Windows.Forms;
using System.Diagnostics;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.InteropServices;
using FaceSplit.Model;
using System.Xml.Serialization;
using System.IO;
using Shortcut;
using FaceSplit.Properties;
Expand Down Expand Up @@ -40,8 +40,15 @@ public partial class FaceSplit : Form
DisplayMode displayMode;
List<Information> informations;

SaveFileDialog saveFileDialog;
OpenFileDialog openFileDialog;
Model.LayoutSettings layoutSettings;

SaveFileDialog saveRunDialog;
SaveFileDialog saveLayoutDialog;

OpenFileDialog openRunDialog;
OpenFileDialog openLayoutDialog;

XmlSerializer serializer;

/// <summary>
/// The watch on the screen.
Expand Down Expand Up @@ -96,6 +103,11 @@ public FaceSplit()
{
InitializeComponent();
this.ConfigureFilesDialogs();
this.layoutSettings = new Model.LayoutSettings();
if (!Settings.Default.LayoutSettingsFile.Equals(""))
{
this.layoutSettings.File = Settings.Default.LayoutSettingsFile;
}
this.hotkeyBinder = new HotkeyBinder();
this.BindHotkeys();
this.globalHotkeysActive = true;
Expand Down Expand Up @@ -194,32 +206,32 @@ private void mnuSaveRun_Click(object sender, EventArgs e)
{
if (this.split.File == null)
{
this.SaveFileAs();
this.SaveRunToFileAs();
}
else
{
this.SaveFile();
this.SaveRunToFile();
}

}
}

private void mnuSaveRunAs_Click(object sender, EventArgs e)
{
this.SaveFileAs();
this.SaveRunToFileAs();
}

private void mnuLoadRun_Click(object sender, EventArgs e)
{
if (this.openFileDialog.ShowDialog() == DialogResult.OK)
if (this.openRunDialog.ShowDialog() == DialogResult.OK)
{
this.LoadFile(openFileDialog.FileName);
this.LoadFile(openRunDialog.FileName);
}
}

private void mnuEditLayout_Click(object sender, EventArgs e)
{
LayoutSettings layoutSettings = new LayoutSettings();
LayoutSettingsEditor layoutSettings = new LayoutSettingsEditor();
if (layoutSettings.ShowDialog() == DialogResult.OK)
{
Settings.Default.Save();
Expand All @@ -230,6 +242,32 @@ private void mnuEditLayout_Click(object sender, EventArgs e)
}
}

private void mnuSaveLayout_Click(object sender, EventArgs e)
{
if (this.layoutSettings.File == null)
{
this.SaveLayoutToFileAs();
}
else
{
this.SaveLayoutToFile();
}
}

private void mnuSaveLayoutAs_Click(object sender, EventArgs e)
{
this.SaveLayoutToFileAs();
}


private void loadLayoutToolStripMenuItem_Click(object sender, EventArgs e)
{
if(openLayoutDialog.ShowDialog() == DialogResult.OK)
{
LoadLayoutFromFile(openLayoutDialog.FileName);
}
}

private void mnuResetLayout_Click(object sender, EventArgs e)
{
Settings.Default.Reset();
Expand Down Expand Up @@ -277,32 +315,42 @@ private void UpdateInformationsStyle()

private void ConfigureFilesDialogs()
{
this.saveFileDialog = new SaveFileDialog();
this.saveFileDialog.DefaultExt = ".fss";
this.saveFileDialog.Filter = "FaceSplit split file (*.fss)|*.fss";
this.saveFileDialog.AddExtension = true;
this.saveRunDialog = new SaveFileDialog();
this.saveRunDialog.DefaultExt = ".fss";
this.saveRunDialog.Filter = "FaceSplit split file (*.fss)|*.fss";
this.saveRunDialog.AddExtension = true;

this.openFileDialog = new OpenFileDialog();
this.openFileDialog.DefaultExt = ".fss";
this.openFileDialog.Filter = "FaceSplit split file (*.fss)|*.fss";
this.openFileDialog.AddExtension = true;
this.saveLayoutDialog = new SaveFileDialog();
this.saveLayoutDialog.DefaultExt = ".fsl";
this.saveLayoutDialog.Filter = "FaceSplit layout file (*.fsl)|*.fsl";
this.saveLayoutDialog.AddExtension = true;

this.openRunDialog = new OpenFileDialog();
this.openRunDialog.DefaultExt = ".fss";
this.openRunDialog.Filter = "FaceSplit split file (*.fss)|*.fss";
this.openRunDialog.AddExtension = true;

this.openLayoutDialog = new OpenFileDialog();
this.openLayoutDialog.DefaultExt = ".fsl";
this.openLayoutDialog.Filter = "FaceSplit layout file (*.fsl)|*.fsl";
this.openLayoutDialog.AddExtension = true;
}

private void SaveFileAs()
private void SaveRunToFileAs()
{
if (this.split != null)
{
if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
if (this.saveRunDialog.ShowDialog() == DialogResult.OK)
{
this.split.File = saveFileDialog.FileName;
this.SaveFile();
this.split.File = saveRunDialog.FileName;
this.SaveRunToFile();
}
}
}

private void SaveFile()
private void SaveRunToFile()
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(this.split.File, false))
using (StreamWriter file = new StreamWriter(this.split.File, false))
{
file.WriteLine(this.split.RunTitle);
file.WriteLine(this.split.RunGoal);
Expand Down Expand Up @@ -360,6 +408,33 @@ private void LoadFile(String fileName)
}
}

private void SaveLayoutToFileAs()
{
if (this.saveLayoutDialog.ShowDialog() == DialogResult.OK)
{
this.layoutSettings.File = saveLayoutDialog.FileName;
this.SaveLayoutToFile();
}
}

private void SaveLayoutToFile()
{
layoutSettings.SaveLayoutSettings();
Settings.Default.LayoutSettingsFile = layoutSettings.File;
serializer = new XmlSerializer(layoutSettings.GetType());
serializer.Serialize(new StreamWriter(this.layoutSettings.File, false), layoutSettings);
Settings.Default.Save();
}

private void LoadLayoutFromFile(String file)
{
serializer = new XmlSerializer(layoutSettings.GetType());
layoutSettings = (Model.LayoutSettings)serializer.Deserialize(new StreamReader(file));
layoutSettings.LoadLayoutSettings();
layoutSettings.File = file;
Settings.Default.Save();
}

/// <summary>
/// Create a rectangle for each segment and adjust the position of the clock
/// and the heigt of FaceSplit.
Expand Down
4 changes: 2 additions & 2 deletions FaceSplit/View/LayoutSettingsEditor.Designer.cs

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

4 changes: 2 additions & 2 deletions FaceSplit/View/LayoutSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

namespace FaceSplit
{
public partial class LayoutSettings : Form
public partial class LayoutSettingsEditor : Form
{
private FontDialog fontDialog;
private ColorDialog colorDialog;

public LayoutSettings()
public LayoutSettingsEditor()
{
InitializeComponent();
this.fontDialog = new FontDialog();
Expand Down
3 changes: 3 additions & 0 deletions FaceSplit/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@
<setting name="SegmentTimerPausedColor" serializeAs="String">
<value>Yellow</value>
</setting>
<setting name="LayoutSettingsFile" serializeAs="String">
<value />
</setting>
</FaceSplit.Properties.Settings>
</userSettings>
</configuration>
3 changes: 3 additions & 0 deletions FaceSplit/bin/Debug/FaceSplit.exe.config
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@
<setting name="SegmentTimerPausedColor" serializeAs="String">
<value>Yellow</value>
</setting>
<setting name="LayoutSettingsFile" serializeAs="String">
<value />
</setting>
</FaceSplit.Properties.Settings>
</userSettings>
</configuration>
3 changes: 3 additions & 0 deletions FaceSplit/bin/Debug/FaceSplit.vshost.exe.config
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@
<setting name="SegmentTimerPausedColor" serializeAs="String">
<value>Yellow</value>
</setting>
<setting name="LayoutSettingsFile" serializeAs="String">
<value />
</setting>
</FaceSplit.Properties.Settings>
</userSettings>
</configuration>
Loading

0 comments on commit c2c110f

Please sign in to comment.