Skip to content

Commit

Permalink
Add support for text persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
suconbu committed Oct 19, 2022
1 parent 4efaaab commit 83e2e92
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions Dentacs/Dentacs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Window\Persistance.cs" />
<Compile Include="Window\TextBoxHelper.cs" />
<Page Include="Resource\Color.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down
4 changes: 2 additions & 2 deletions Dentacs/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("dentacs")]
[assembly: AssemblyCopyright("Copyright © D.Miwa 2020")]
[assembly: AssemblyCopyright("Copyright © D.Miwa 2020-2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down Expand Up @@ -51,5 +51,5 @@
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
61 changes: 61 additions & 0 deletions Dentacs/Window/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using System.Diagnostics;

namespace Suconbu.Dentacs
{
Expand Down Expand Up @@ -51,6 +53,7 @@ public enum ErrorState { None, ErrorWithoutMessage, ErrorWithMessage }

static readonly double[] kZoomTable = new[] { 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 4.0 };
static readonly int kCopyFlashInterval = 100;
readonly string kPersistanceFileName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + "_persistance.xml";
readonly Random random = new Random();

public MainWindow()
Expand Down Expand Up @@ -98,6 +101,64 @@ public MainWindow()
this.FullScreenKeypadPanel.ItemMouseEnter += (s, item) => { this.RxUsageText.Value = item.Usage; };
this.FullScreenKeypadPanel.ItemMouseLeave += (s, item) => { this.RxUsageText.Value = null; };
this.FullScreenKeypadPanel.ItemClick += (s, item) => this.KeypadPanel_ItemClick(item);

this.Loaded += MainWindow_Loaded;
this.Closed += MainWindow_Closed;
}

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.LoadSetting();
}

private void MainWindow_Closed(object sender, EventArgs e)
{
this.SaveSetting();
}

void LoadSetting()
{
if (File.Exists(this.kPersistanceFileName))
{
try
{
using (var reader = new StreamReader(this.kPersistanceFileName))
{
var xs = new XmlSerializer(typeof(Persistance));
var persistent = xs.Deserialize(reader) as Persistance;

this.InputTextBox.Text = persistent.Text;
//this.RxZoomIndex.Value = persistent.ZoomIndex;
//this.fullScreenZoomIndexBackup = persistent.ZoomIndexFullScreen;
}
}
catch(Exception ex)
{
Debug.WriteLine(ex);
}
}
}

void SaveSetting()
{
var persistent = new Persistance()
{
Text = this.InputTextBox.Text,
//ZoomIndex = this.RxZoomIndex.Value,
//ZoomIndexFullScreen = this.fullScreenZoomIndexBackup
};
var xs = new XmlSerializer(persistent.GetType());
try
{
using (var writer = new StreamWriter(this.kPersistanceFileName, false, System.Text.Encoding.UTF8))
{
xs.Serialize(writer, persistent);
}
}
catch(IOException ex)
{
Debug.Write(ex);
}
}

string MakeTitleText()
Expand Down
15 changes: 15 additions & 0 deletions Dentacs/Window/Persistance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Suconbu.Dentacs
{
public class Persistance
{
public string Text { get; set; }
//public int ZoomIndex { get; set; }
//public int ZoomIndexFullScreen { get; set; }
}
}

0 comments on commit 83e2e92

Please sign in to comment.