From b632d4a8a984957d86a9d25ff17058a0cc1f3beb Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Thu, 20 Aug 2015 17:17:21 +0800 Subject: [PATCH 1/4] improved `log viewer`: 1. add menu items for `clear logs`, `change fonts`, `wrap text` and `top most` functions. 2. hide toolbar default. but you can trigger it out by menu. --- shadowsocks-csharp/Data/cn.txt | 6 +- shadowsocks-csharp/View/LogForm.Designer.cs | 159 ++++++++++++++------ shadowsocks-csharp/View/LogForm.cs | 109 +++++++++++++- shadowsocks-csharp/View/LogForm.resx | 5 +- 4 files changed, 217 insertions(+), 62 deletions(-) diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index f2accf58..c8bde1ce 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -54,10 +54,12 @@ Move D&own=下移(&O) &File=文件(&F) &Open Location=在资源管理器中打开(&O) E&xit=退出(&X) -&Clean logs=清空(&C) -&Font=字体(&F) +&View=视图(&V) +&Clean logs=清空日志(&C) +Change &font=设置字体(&F) &Wrap text=自动换行(&W) &Top most=置顶(&T) +&Show toolbar=显示工具栏(&S) Log Viewer=日志查看器 # QRCode Form diff --git a/shadowsocks-csharp/View/LogForm.Designer.cs b/shadowsocks-csharp/View/LogForm.Designer.cs index d0913d16..187ab948 100644 --- a/shadowsocks-csharp/View/LogForm.Designer.cs +++ b/shadowsocks-csharp/View/LogForm.Designer.cs @@ -30,19 +30,25 @@ { this.components = new System.ComponentModel.Container(); this.LogMessageTextBox = new System.Windows.Forms.TextBox(); - this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components); + this.MainMenu = new System.Windows.Forms.MainMenu(this.components); this.FileMenuItem = new System.Windows.Forms.MenuItem(); this.OpenLocationMenuItem = new System.Windows.Forms.MenuItem(); this.ExitMenuItem = new System.Windows.Forms.MenuItem(); - this.panel1 = new System.Windows.Forms.Panel(); + this.ViewMenuItem = new System.Windows.Forms.MenuItem(); + this.CleanLogsMenuItem = new System.Windows.Forms.MenuItem(); + this.ChangeFontMenuItem = new System.Windows.Forms.MenuItem(); + this.WrapTextMenuItem = new System.Windows.Forms.MenuItem(); + this.TopMostMenuItem = new System.Windows.Forms.MenuItem(); + this.MenuItemSeparater = new System.Windows.Forms.MenuItem(); + this.ShowToolbarMenuItem = new System.Windows.Forms.MenuItem(); + this.TopMostCheckBox = new System.Windows.Forms.CheckBox(); this.ChangeFontButton = new System.Windows.Forms.Button(); this.CleanLogsButton = new System.Windows.Forms.Button(); this.WrapTextCheckBox = new System.Windows.Forms.CheckBox(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.TopMostCheckBox = new System.Windows.Forms.CheckBox(); - this.panel1.SuspendLayout(); + this.ToolbarFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); this.tableLayoutPanel1.SuspendLayout(); + this.ToolbarFlowLayoutPanel.SuspendLayout(); this.SuspendLayout(); // // LogMessageTextBox @@ -51,25 +57,20 @@ this.LogMessageTextBox.Dock = System.Windows.Forms.DockStyle.Fill; this.LogMessageTextBox.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.LogMessageTextBox.ForeColor = System.Drawing.Color.White; - this.LogMessageTextBox.Location = new System.Drawing.Point(3, 43); + this.LogMessageTextBox.Location = new System.Drawing.Point(3, 38); this.LogMessageTextBox.MaxLength = 2147483647; this.LogMessageTextBox.Multiline = true; this.LogMessageTextBox.Name = "LogMessageTextBox"; this.LogMessageTextBox.ReadOnly = true; this.LogMessageTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.LogMessageTextBox.Size = new System.Drawing.Size(541, 307); + this.LogMessageTextBox.Size = new System.Drawing.Size(584, 377); this.LogMessageTextBox.TabIndex = 0; - this.LogMessageTextBox.WordWrap = false; - // - // contextMenuStrip1 // - this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); + // MainMenu // - // mainMenu1 - // - this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { - this.FileMenuItem}); + this.MainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.FileMenuItem, + this.ViewMenuItem}); // // FileMenuItem // @@ -91,21 +92,70 @@ this.ExitMenuItem.Text = "E&xit"; this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click); // - // panel1 + // ViewMenuItem + // + this.ViewMenuItem.Index = 1; + this.ViewMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.CleanLogsMenuItem, + this.ChangeFontMenuItem, + this.WrapTextMenuItem, + this.TopMostMenuItem, + this.MenuItemSeparater, + this.ShowToolbarMenuItem}); + this.ViewMenuItem.Text = "&View"; + // + // CleanLogsMenuItem + // + this.CleanLogsMenuItem.Index = 0; + this.CleanLogsMenuItem.Text = "&Clean logs"; + this.CleanLogsMenuItem.Click += new System.EventHandler(this.CleanLogsMenuItem_Click); + // + // ChangeFontMenuItem + // + this.ChangeFontMenuItem.Index = 1; + this.ChangeFontMenuItem.Text = "Change &font"; + this.ChangeFontMenuItem.Click += new System.EventHandler(this.ChangeFontMenuItem_Click); // - this.panel1.Controls.Add(this.TopMostCheckBox); - this.panel1.Controls.Add(this.ChangeFontButton); - this.panel1.Controls.Add(this.CleanLogsButton); - this.panel1.Controls.Add(this.WrapTextCheckBox); - this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel1.Location = new System.Drawing.Point(3, 3); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(541, 34); - this.panel1.TabIndex = 1; + // WrapTextMenuItem + // + this.WrapTextMenuItem.Index = 2; + this.WrapTextMenuItem.Text = "&Wrap text"; + this.WrapTextMenuItem.Click += new System.EventHandler(this.WrapTextMenuItem_Click); + // + // TopMostMenuItem + // + this.TopMostMenuItem.Index = 3; + this.TopMostMenuItem.Text = "&Top most"; + this.TopMostMenuItem.Click += new System.EventHandler(this.TopMostMenuItem_Click); + // + // MenuItemSeparater + // + this.MenuItemSeparater.Index = 4; + this.MenuItemSeparater.Text = "-"; + // + // ShowToolbarMenuItem + // + this.ShowToolbarMenuItem.Index = 5; + this.ShowToolbarMenuItem.Text = "&Show toolbar"; + this.ShowToolbarMenuItem.Click += new System.EventHandler(this.ShowToolbarMenuItem_Click); + // + // TopMostCheckBox + // + this.TopMostCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.TopMostCheckBox.AutoSize = true; + this.TopMostCheckBox.Location = new System.Drawing.Point(249, 3); + this.TopMostCheckBox.Name = "TopMostCheckBox"; + this.TopMostCheckBox.Size = new System.Drawing.Size(72, 23); + this.TopMostCheckBox.TabIndex = 3; + this.TopMostCheckBox.Text = "&Top most"; + this.TopMostCheckBox.UseVisualStyleBackColor = true; + this.TopMostCheckBox.CheckedChanged += new System.EventHandler(this.TopMostCheckBox_CheckedChanged); // // ChangeFontButton // - this.ChangeFontButton.Location = new System.Drawing.Point(107, 4); + this.ChangeFontButton.AutoSize = true; + this.ChangeFontButton.Location = new System.Drawing.Point(84, 3); this.ChangeFontButton.Name = "ChangeFontButton"; this.ChangeFontButton.Size = new System.Drawing.Size(75, 23); this.ChangeFontButton.TabIndex = 2; @@ -115,7 +165,8 @@ // // CleanLogsButton // - this.CleanLogsButton.Location = new System.Drawing.Point(9, 4); + this.CleanLogsButton.AutoSize = true; + this.CleanLogsButton.Location = new System.Drawing.Point(3, 3); this.CleanLogsButton.Name = "CleanLogsButton"; this.CleanLogsButton.Size = new System.Drawing.Size(75, 23); this.CleanLogsButton.TabIndex = 1; @@ -125,10 +176,12 @@ // // WrapTextCheckBox // + this.WrapTextCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); this.WrapTextCheckBox.AutoSize = true; - this.WrapTextCheckBox.Location = new System.Drawing.Point(209, 9); + this.WrapTextCheckBox.Location = new System.Drawing.Point(165, 3); this.WrapTextCheckBox.Name = "WrapTextCheckBox"; - this.WrapTextCheckBox.Size = new System.Drawing.Size(78, 16); + this.WrapTextCheckBox.Size = new System.Drawing.Size(78, 23); this.WrapTextCheckBox.TabIndex = 0; this.WrapTextCheckBox.Text = "&Wrap text"; this.WrapTextCheckBox.UseVisualStyleBackColor = true; @@ -138,45 +191,47 @@ // this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 0); this.tableLayoutPanel1.Controls.Add(this.LogMessageTextBox, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.ToolbarFlowLayoutPanel, 0, 0); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 2; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.Size = new System.Drawing.Size(547, 353); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.Size = new System.Drawing.Size(590, 418); this.tableLayoutPanel1.TabIndex = 2; // - // TopMostCheckBox + // ToolbarFlowLayoutPanel // - this.TopMostCheckBox.AutoSize = true; - this.TopMostCheckBox.Location = new System.Drawing.Point(311, 9); - this.TopMostCheckBox.Name = "TopMostCheckBox"; - this.TopMostCheckBox.Size = new System.Drawing.Size(72, 16); - this.TopMostCheckBox.TabIndex = 3; - this.TopMostCheckBox.Text = "&Top most"; - this.TopMostCheckBox.UseVisualStyleBackColor = true; - this.TopMostCheckBox.CheckedChanged += new System.EventHandler(this.TopMostCheckBox_CheckedChanged); + this.ToolbarFlowLayoutPanel.AutoSize = true; + this.ToolbarFlowLayoutPanel.Controls.Add(this.CleanLogsButton); + this.ToolbarFlowLayoutPanel.Controls.Add(this.ChangeFontButton); + this.ToolbarFlowLayoutPanel.Controls.Add(this.WrapTextCheckBox); + this.ToolbarFlowLayoutPanel.Controls.Add(this.TopMostCheckBox); + this.ToolbarFlowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.ToolbarFlowLayoutPanel.Location = new System.Drawing.Point(3, 3); + this.ToolbarFlowLayoutPanel.Name = "ToolbarFlowLayoutPanel"; + this.ToolbarFlowLayoutPanel.Size = new System.Drawing.Size(584, 29); + this.ToolbarFlowLayoutPanel.TabIndex = 2; // // LogForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(547, 353); + this.ClientSize = new System.Drawing.Size(590, 418); this.Controls.Add(this.tableLayoutPanel1); - this.Menu = this.mainMenu1; + this.Menu = this.MainMenu; this.Name = "LogForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Log Viewer"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LogForm_FormClosing); this.Load += new System.EventHandler(this.LogForm_Load); this.Shown += new System.EventHandler(this.LogForm_Shown); - this.panel1.ResumeLayout(false); - this.panel1.PerformLayout(); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); + this.ToolbarFlowLayoutPanel.ResumeLayout(false); + this.ToolbarFlowLayoutPanel.PerformLayout(); this.ResumeLayout(false); } @@ -184,16 +239,22 @@ #endregion private System.Windows.Forms.TextBox LogMessageTextBox; - private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; - private System.Windows.Forms.MainMenu mainMenu1; + private System.Windows.Forms.MainMenu MainMenu; private System.Windows.Forms.MenuItem FileMenuItem; private System.Windows.Forms.MenuItem OpenLocationMenuItem; private System.Windows.Forms.MenuItem ExitMenuItem; - private System.Windows.Forms.Panel panel1; private System.Windows.Forms.CheckBox WrapTextCheckBox; private System.Windows.Forms.Button CleanLogsButton; private System.Windows.Forms.Button ChangeFontButton; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.CheckBox TopMostCheckBox; + private System.Windows.Forms.MenuItem ViewMenuItem; + private System.Windows.Forms.MenuItem CleanLogsMenuItem; + private System.Windows.Forms.MenuItem ChangeFontMenuItem; + private System.Windows.Forms.MenuItem WrapTextMenuItem; + private System.Windows.Forms.MenuItem TopMostMenuItem; + private System.Windows.Forms.FlowLayoutPanel ToolbarFlowLayoutPanel; + private System.Windows.Forms.MenuItem MenuItemSeparater; + private System.Windows.Forms.MenuItem ShowToolbarMenuItem; } } \ No newline at end of file diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index 3f4bc847..a9b85d52 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -34,9 +34,15 @@ namespace Shadowsocks.View OpenLocationMenuItem.Text = I18N.GetString("&Open Location"); ExitMenuItem.Text = I18N.GetString("E&xit"); CleanLogsButton.Text = I18N.GetString("&Clean logs"); - ChangeFontButton.Text = I18N.GetString("&Font"); + ChangeFontButton.Text = I18N.GetString("Change &font"); WrapTextCheckBox.Text = I18N.GetString("&Wrap text"); TopMostCheckBox.Text = I18N.GetString("&Top most"); + ViewMenuItem.Text = I18N.GetString("&View"); + CleanLogsMenuItem.Text = I18N.GetString("&Clean logs"); + ChangeFontMenuItem.Text = I18N.GetString("Change &font"); + WrapTextMenuItem.Text = I18N.GetString("&Wrap text"); + TopMostMenuItem.Text = I18N.GetString("&Top most"); + ShowToolbarMenuItem.Text = I18N.GetString("&Show toolbar"); this.Text = I18N.GetString("Log Viewer"); } @@ -97,6 +103,9 @@ namespace Shadowsocks.View timer.Interval = 300; timer.Tick += Timer_Tick; timer.Start(); + this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = TopMostTrigger; + LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked = WrapTextMenuItem.Checked = WrapTextTrigger; + ToolbarFlowLayoutPanel.Visible = ShowToolbarTrigger; } private void LogForm_FormClosing(object sender, FormClosingEventArgs e) @@ -121,18 +130,25 @@ namespace Shadowsocks.View LogMessageTextBox.ScrollToCaret(); } - private void WrapTextCheckBox_CheckedChanged(object sender, EventArgs e) + #region Clean up the content in LogMessageTextBox. + private void DoCleanLogs() { - LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked; - LogMessageTextBox.ScrollToCaret(); + LogMessageTextBox.Clear(); + } + + private void CleanLogsMenuItem_Click(object sender, EventArgs e) + { + DoCleanLogs(); } private void CleanLogsButton_Click(object sender, EventArgs e) { - LogMessageTextBox.Clear(); + DoCleanLogs(); } + #endregion - private void ChangeFontButton_Click(object sender, EventArgs e) + #region Change the font settings applied in LogMessageTextBox. + private void DoChangeFont() { try { @@ -150,9 +166,88 @@ namespace Shadowsocks.View } } + private void ChangeFontMenuItem_Click(object sender, EventArgs e) + { + DoChangeFont(); + } + + private void ChangeFontButton_Click(object sender, EventArgs e) + { + DoChangeFont(); + } + #endregion + + #region Trigger the log messages wrapable, or not. + bool WrapTextTrigger = false; + bool WrapTextTriggerLock = false; + + private void TriggerWrapText() + { + WrapTextTriggerLock = true; + + WrapTextTrigger = !WrapTextTrigger; + LogMessageTextBox.WordWrap = WrapTextTrigger; + LogMessageTextBox.ScrollToCaret(); + WrapTextMenuItem.Checked = WrapTextCheckBox.Checked = WrapTextTrigger; + + WrapTextTriggerLock = false; + } + + private void WrapTextMenuItem_Click(object sender, EventArgs e) + { + if (!WrapTextTriggerLock) + { + TriggerWrapText(); + } + } + + private void WrapTextCheckBox_CheckedChanged(object sender, EventArgs e) + { + if (!WrapTextTriggerLock) + { + TriggerWrapText(); + } + } + #endregion + + #region Trigger this window top most, or not. + bool TopMostTrigger = false; + bool TopMostTriggerLock = false; + + private void TriggerTopMost() + { + TopMostTriggerLock = true; + + TopMostTrigger = !TopMostTrigger; + this.TopMost = TopMostTrigger; + TopMostMenuItem.Checked = TopMostCheckBox.Checked = TopMostTrigger; + + TopMostTriggerLock = false; + } + private void TopMostCheckBox_CheckedChanged(object sender, EventArgs e) { - this.TopMost = TopMostCheckBox.Checked; + if (!TopMostTriggerLock) + { + TriggerTopMost(); + } + } + + private void TopMostMenuItem_Click(object sender, EventArgs e) + { + if (!TopMostTriggerLock) + { + TriggerTopMost(); + } + } + #endregion + + private bool ShowToolbarTrigger = false; + private void ShowToolbarMenuItem_Click(object sender, EventArgs e) + { + ShowToolbarTrigger = !ShowToolbarTrigger; + ToolbarFlowLayoutPanel.Visible = ShowToolbarTrigger; + ShowToolbarMenuItem.Checked = ShowToolbarTrigger; } } } diff --git a/shadowsocks-csharp/View/LogForm.resx b/shadowsocks-csharp/View/LogForm.resx index 34b690ce..e8bf04bf 100644 --- a/shadowsocks-csharp/View/LogForm.resx +++ b/shadowsocks-csharp/View/LogForm.resx @@ -117,10 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 - - 172, 17 - \ No newline at end of file From f1019b4aad868caaecbf46358b09c9d25e0ce585 Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Thu, 20 Aug 2015 21:01:40 +0800 Subject: [PATCH 2/4] fix variables' name: (first letter uppercase -> lowercase) 1. WrapTextTrigger -> wrapTextTrigger 2. WrapTextTriggerLock -> wrapTextTriggerLock 3. TopMostTrigger -> topMostTrigger 4. TopMostTriggerLock -> topMostTriggerLock 5. ShowToolbarTrigger -> toolbarTrigger --- shadowsocks-csharp/View/LogForm.cs | 50 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index a9b85d52..c906b7d5 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -103,9 +103,9 @@ namespace Shadowsocks.View timer.Interval = 300; timer.Tick += Timer_Tick; timer.Start(); - this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = TopMostTrigger; - LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked = WrapTextMenuItem.Checked = WrapTextTrigger; - ToolbarFlowLayoutPanel.Visible = ShowToolbarTrigger; + this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = topMostTrigger; + LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked = WrapTextMenuItem.Checked = wrapTextTrigger; + ToolbarFlowLayoutPanel.Visible = toolbarTrigger; } private void LogForm_FormClosing(object sender, FormClosingEventArgs e) @@ -178,24 +178,24 @@ namespace Shadowsocks.View #endregion #region Trigger the log messages wrapable, or not. - bool WrapTextTrigger = false; - bool WrapTextTriggerLock = false; + bool wrapTextTrigger = false; + bool wrapTextTriggerLock = false; private void TriggerWrapText() { - WrapTextTriggerLock = true; + wrapTextTriggerLock = true; - WrapTextTrigger = !WrapTextTrigger; - LogMessageTextBox.WordWrap = WrapTextTrigger; + wrapTextTrigger = !wrapTextTrigger; + LogMessageTextBox.WordWrap = wrapTextTrigger; LogMessageTextBox.ScrollToCaret(); - WrapTextMenuItem.Checked = WrapTextCheckBox.Checked = WrapTextTrigger; + WrapTextMenuItem.Checked = WrapTextCheckBox.Checked = wrapTextTrigger; - WrapTextTriggerLock = false; + wrapTextTriggerLock = false; } private void WrapTextMenuItem_Click(object sender, EventArgs e) { - if (!WrapTextTriggerLock) + if (!wrapTextTriggerLock) { TriggerWrapText(); } @@ -203,7 +203,7 @@ namespace Shadowsocks.View private void WrapTextCheckBox_CheckedChanged(object sender, EventArgs e) { - if (!WrapTextTriggerLock) + if (!wrapTextTriggerLock) { TriggerWrapText(); } @@ -211,23 +211,23 @@ namespace Shadowsocks.View #endregion #region Trigger this window top most, or not. - bool TopMostTrigger = false; - bool TopMostTriggerLock = false; + bool topMostTrigger = false; + bool topMostTriggerLock = false; private void TriggerTopMost() { - TopMostTriggerLock = true; + topMostTriggerLock = true; - TopMostTrigger = !TopMostTrigger; - this.TopMost = TopMostTrigger; - TopMostMenuItem.Checked = TopMostCheckBox.Checked = TopMostTrigger; + topMostTrigger = !topMostTrigger; + this.TopMost = topMostTrigger; + TopMostMenuItem.Checked = TopMostCheckBox.Checked = topMostTrigger; - TopMostTriggerLock = false; + topMostTriggerLock = false; } private void TopMostCheckBox_CheckedChanged(object sender, EventArgs e) { - if (!TopMostTriggerLock) + if (!topMostTriggerLock) { TriggerTopMost(); } @@ -235,19 +235,19 @@ namespace Shadowsocks.View private void TopMostMenuItem_Click(object sender, EventArgs e) { - if (!TopMostTriggerLock) + if (!topMostTriggerLock) { TriggerTopMost(); } } #endregion - private bool ShowToolbarTrigger = false; + private bool toolbarTrigger = false; private void ShowToolbarMenuItem_Click(object sender, EventArgs e) { - ShowToolbarTrigger = !ShowToolbarTrigger; - ToolbarFlowLayoutPanel.Visible = ShowToolbarTrigger; - ShowToolbarMenuItem.Checked = ShowToolbarTrigger; + toolbarTrigger = !toolbarTrigger; + ToolbarFlowLayoutPanel.Visible = toolbarTrigger; + ShowToolbarMenuItem.Checked = toolbarTrigger; } } } From 0eee5cd98f2e30edb3f4e29b970aba390980668e Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Thu, 20 Aug 2015 21:03:38 +0800 Subject: [PATCH 3/4] add feature: save LogForm's config into json file. --- shadowsocks-csharp/Model/Configuration.cs | 1 + shadowsocks-csharp/Model/LogViewerConfig.cs | 63 ++++++++++++++++++++ shadowsocks-csharp/View/LogForm.cs | 36 ++++++++++- shadowsocks-csharp/shadowsocks-csharp.csproj | 1 + 4 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 shadowsocks-csharp/Model/LogViewerConfig.cs diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index 35ee5235..cf506072 100755 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -24,6 +24,7 @@ namespace Shadowsocks.Model public bool useOnlinePac; public bool availabilityStatistics; public bool autoCheckUpdate; + public LogViewerConfig logViewer; private static string CONFIG_FILE = "gui-config.json"; diff --git a/shadowsocks-csharp/Model/LogViewerConfig.cs b/shadowsocks-csharp/Model/LogViewerConfig.cs new file mode 100644 index 00000000..28471084 --- /dev/null +++ b/shadowsocks-csharp/Model/LogViewerConfig.cs @@ -0,0 +1,63 @@ +using System; +using System.Drawing; + +namespace Shadowsocks.Model +{ + [Serializable] + public class LogViewerConfig + { + public string fontName; + public float fontSize; + public string bgColor; + public string textColor; + public bool topMost; + public bool wrapText; + public bool toolbarShown; + + public LogViewerConfig() + { + this.fontName = "Console"; + this.fontSize = 8; + this.bgColor = "black"; + this.textColor = "white"; + this.topMost = false; + this.wrapText = false; + this.toolbarShown = false; + } + + public Color GetBackgroundColor() + { + try + { + return ColorTranslator.FromHtml(bgColor); + } + catch (Exception) + { + return ColorTranslator.FromHtml("black"); + } + } + + public void SetBackgroundColor(Color color) + { + bgColor = ColorTranslator.ToHtml(color); + } + + public Color GetTextColor() + { + try + { + return ColorTranslator.FromHtml(textColor); + } + catch (Exception) + { + return ColorTranslator.FromHtml("white"); + throw; + } + } + + public void SetTextColor(Color color) + { + textColor = ColorTranslator.ToHtml(color); + } + } +} diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index c906b7d5..ab16faf0 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -18,6 +18,7 @@ namespace Shadowsocks.View string filename; Timer timer; const int BACK_OFFSET = 65536; + Model.Configuration config; public LogForm(string filename) { @@ -25,6 +26,21 @@ namespace Shadowsocks.View 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(); + } + UpdateTexts(); } @@ -103,14 +119,29 @@ namespace Shadowsocks.View timer.Interval = 300; timer.Tick += Timer_Tick; timer.Start(); + + topMostTriggerLock = true; this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = topMostTrigger; - LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked = WrapTextMenuItem.Checked = wrapTextTrigger; - ToolbarFlowLayoutPanel.Visible = toolbarTrigger; + topMostTriggerLock = false; + + wrapTextTriggerLock = true; + LogMessageTextBox.WordWrap = WrapTextMenuItem.Checked = WrapTextCheckBox.Checked = wrapTextTrigger; + wrapTextTriggerLock = false; + + ToolbarFlowLayoutPanel.Visible = ShowToolbarMenuItem.Checked = toolbarTrigger; } 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); } private void OpenLocationMenuItem_Click(object sender, EventArgs e) @@ -243,6 +274,7 @@ namespace Shadowsocks.View #endregion private bool toolbarTrigger = false; + private void ShowToolbarMenuItem_Click(object sender, EventArgs e) { toolbarTrigger = !toolbarTrigger; diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 8200aa07..dd957ffb 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -145,6 +145,7 @@ + From a070c3c98617889c5e92732902c26f4fd23021ed Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Tue, 22 Sep 2015 23:38:38 +0800 Subject: [PATCH 4/4] 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)