From a070c3c98617889c5e92732902c26f4fd23021ed Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Tue, 22 Sep 2015 23:38:38 +0800 Subject: [PATCH] small fix --- .../Controller/ShadowsocksController.cs | 6 +++ shadowsocks-csharp/Model/LogViewerConfig.cs | 19 ++++++- shadowsocks-csharp/View/LogForm.cs | 54 +++++++++---------- shadowsocks-csharp/View/MenuViewController.cs | 2 +- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 1debda15..40496cfe 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -286,6 +286,12 @@ namespace Shadowsocks.Controller Configuration.Save(_config); } + public void SaveLogViewerConfig(LogViewerConfig newConfig) + { + _config.logViewer = newConfig; + Configuration.Save(_config); + } + protected void Reload() { // some logic in configuration updated the config when saving, we need to read it again diff --git a/shadowsocks-csharp/Model/LogViewerConfig.cs b/shadowsocks-csharp/Model/LogViewerConfig.cs index 28471084..245e5ddb 100644 --- a/shadowsocks-csharp/Model/LogViewerConfig.cs +++ b/shadowsocks-csharp/Model/LogViewerConfig.cs @@ -25,6 +25,24 @@ namespace Shadowsocks.Model this.toolbarShown = false; } + public Font GetFont() + { + try + { + return new Font(fontName, fontSize); + } + catch (Exception) + { + return new Font("Console", 8F); + } + } + + public void SetFont(Font font) + { + fontName = font.Name; + fontSize = font.Size; + } + public Color GetBackgroundColor() { try @@ -51,7 +69,6 @@ namespace Shadowsocks.Model catch (Exception) { return ColorTranslator.FromHtml("white"); - throw; } } diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index ab16faf0..ff1c9bb8 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -1,6 +1,4 @@ -using Shadowsocks.Controller; -using Shadowsocks.Properties; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -10,6 +8,10 @@ using System.Linq; using System.Text; using System.Windows.Forms; +using Shadowsocks.Controller; +using Shadowsocks.Properties; +using Shadowsocks.Model; + namespace Shadowsocks.View { public partial class LogForm : Form @@ -18,28 +20,24 @@ namespace Shadowsocks.View string filename; Timer timer; const int BACK_OFFSET = 65536; - Model.Configuration config; + ShadowsocksController controller; - public LogForm(string filename) + public LogForm(ShadowsocksController controller, string filename) { + this.controller = controller; this.filename = filename; InitializeComponent(); this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); - config = Model.Configuration.Load(); - if (config.logViewer == null) - { - config.logViewer = new Model.LogViewerConfig(); - } - else - { - topMostTrigger = config.logViewer.topMost; - wrapTextTrigger = config.logViewer.wrapText; - toolbarTrigger = config.logViewer.toolbarShown; - LogMessageTextBox.Font = new Font(config.logViewer.fontName, config.logViewer.fontSize); - LogMessageTextBox.BackColor = config.logViewer.GetBackgroundColor(); - LogMessageTextBox.ForeColor = config.logViewer.GetTextColor(); - } + LogViewerConfig config = controller.GetConfigurationCopy().logViewer; + if (config == null) + config = new LogViewerConfig(); + topMostTrigger = config.topMost; + wrapTextTrigger = config.wrapText; + toolbarTrigger = config.toolbarShown; + LogMessageTextBox.BackColor = config.GetBackgroundColor(); + LogMessageTextBox.ForeColor = config.GetTextColor(); + LogMessageTextBox.Font = config.GetFont(); UpdateTexts(); } @@ -134,14 +132,16 @@ namespace Shadowsocks.View private void LogForm_FormClosing(object sender, FormClosingEventArgs e) { timer.Stop(); - config.logViewer.topMost = topMostTrigger; - config.logViewer.wrapText = wrapTextTrigger; - config.logViewer.toolbarShown = toolbarTrigger; - config.logViewer.fontName = LogMessageTextBox.Font.Name; - config.logViewer.fontSize = LogMessageTextBox.Font.Size; - config.logViewer.SetBackgroundColor(LogMessageTextBox.BackColor); - config.logViewer.SetTextColor(LogMessageTextBox.ForeColor); - Model.Configuration.Save(config); + LogViewerConfig config = controller.GetConfigurationCopy().logViewer; + if (config == null) + config = new LogViewerConfig(); + config.topMost = topMostTrigger; + config.wrapText = wrapTextTrigger; + config.toolbarShown = toolbarTrigger; + config.SetFont(LogMessageTextBox.Font); + config.SetBackgroundColor(LogMessageTextBox.BackColor); + config.SetTextColor(LogMessageTextBox.ForeColor); + controller.SaveLogViewerConfig(config); } private void OpenLocationMenuItem_Click(object sender, EventArgs e) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index e729d943..a3c383df 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -439,7 +439,7 @@ namespace Shadowsocks.View { string argument = Logging.LogFile; - new LogForm(argument).Show(); + new LogForm(controller, argument).Show(); } private void QRCodeItem_Click(object sender, EventArgs e)