From 77d90b136d4a7e5232d2a5c4d3a29c9b83a0cee1 Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 9 Sep 2015 19:21:31 +0300 Subject: [PATCH] Added IRC error output event and it will show red in output tab --- ShareX.IRCLib/IRC.cs | 21 +- .../IRCClient/IRCClientForm.Designer.cs | 21 +- ShareX.IRCLib/IRCClient/IRCClientForm.cs | 24 +- ShareX.IRCLib/IRCClient/IRCClientForm.resx | 325 +++++++----------- ShareX.IRCLib/IRCClient/TabInfo.cs | 5 - ShareX.IRCLib/IRCClient/TabManager.cs | 2 +- 6 files changed, 167 insertions(+), 231 deletions(-) diff --git a/ShareX.IRCLib/IRC.cs b/ShareX.IRCLib/IRC.cs index ff820e64a..893223670 100644 --- a/ShareX.IRCLib/IRC.cs +++ b/ShareX.IRCLib/IRC.cs @@ -40,6 +40,7 @@ public class IRC : IDisposable public const int DefaultPortSSL = 6697; public event Action Output; + public event Action ErrorOutput; public event Action Connected, Disconnected; public delegate void MessageEventHandler(UserInfo user, string channel, string message); public event MessageEventHandler Message; @@ -150,6 +151,7 @@ public void Connect() { IsWorking = false; DebugHelper.WriteLine(e.ToString()); + OnErrorOutput(e); } } @@ -171,6 +173,7 @@ public void Disconnect() catch (Exception e) { DebugHelper.WriteLine(e.ToString()); + OnErrorOutput(e); } } @@ -195,15 +198,17 @@ private void ConnectionThread() catch (Exception e) { DebugHelper.WriteLine(e.ToString()); + OnErrorOutput(e); } } } - catch (IOException) - { - } catch (Exception e) { - DebugHelper.WriteLine(e.ToString()); + if (!disconnecting) + { + DebugHelper.WriteLine(e.ToString()); + OnErrorOutput(e); + } } OnDisconnected(); @@ -334,6 +339,14 @@ private void OnOutput(MessageInfo messageInfo) //Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {messageInfo.Content}"); } + private void OnErrorOutput(Exception e) + { + if (ErrorOutput != null) + { + ErrorOutput(e); + } + } + protected void OnConnected() { IsConnected = true; diff --git a/ShareX.IRCLib/IRCClient/IRCClientForm.Designer.cs b/ShareX.IRCLib/IRCClient/IRCClientForm.Designer.cs index 15df33837..cf9bd54d3 100644 --- a/ShareX.IRCLib/IRCClient/IRCClientForm.Designer.cs +++ b/ShareX.IRCLib/IRCClient/IRCClientForm.Designer.cs @@ -41,7 +41,6 @@ private void InitializeComponent() this.tsmiColorGrey = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiColorLightGrey = new System.Windows.Forms.ToolStripMenuItem(); this.btnMessageSend = new System.Windows.Forms.Button(); - this.txtOutput = new System.Windows.Forms.TextBox(); this.tcMain = new System.Windows.Forms.TabControl(); this.tpMain = new System.Windows.Forms.TabPage(); this.btnConnect = new System.Windows.Forms.Button(); @@ -50,6 +49,7 @@ private void InitializeComponent() this.txtCommand = new System.Windows.Forms.TextBox(); this.lblCommand = new System.Windows.Forms.Label(); this.btnCommandSend = new System.Windows.Forms.Button(); + this.rtbOutput = new System.Windows.Forms.RichTextBox(); this.tpMessages = new System.Windows.Forms.TabPage(); this.tcMessages = new System.Windows.Forms.TabControl(); this.btnMessagesMenu = new System.Windows.Forms.Button(); @@ -262,13 +262,6 @@ private void InitializeComponent() this.btnMessageSend.UseVisualStyleBackColor = true; this.btnMessageSend.Click += new System.EventHandler(this.btnMessageSend_Click); // - // txtOutput - // - resources.ApplyResources(this.txtOutput, "txtOutput"); - this.txtOutput.BackColor = System.Drawing.Color.White; - this.txtOutput.Name = "txtOutput"; - this.txtOutput.ReadOnly = true; - // // tcMain // this.tcMain.Controls.Add(this.tpMain); @@ -307,7 +300,7 @@ private void InitializeComponent() this.tpOutput.Controls.Add(this.txtCommand); this.tpOutput.Controls.Add(this.lblCommand); this.tpOutput.Controls.Add(this.btnCommandSend); - this.tpOutput.Controls.Add(this.txtOutput); + this.tpOutput.Controls.Add(this.rtbOutput); resources.ApplyResources(this.tpOutput, "tpOutput"); this.tpOutput.Name = "tpOutput"; this.tpOutput.UseVisualStyleBackColor = true; @@ -330,6 +323,14 @@ private void InitializeComponent() this.btnCommandSend.UseVisualStyleBackColor = true; this.btnCommandSend.Click += new System.EventHandler(this.btnCommandSend_Click); // + // rtbOutput + // + resources.ApplyResources(this.rtbOutput, "rtbOutput"); + this.rtbOutput.BackColor = System.Drawing.Color.White; + this.rtbOutput.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.rtbOutput.Name = "rtbOutput"; + this.rtbOutput.ReadOnly = true; + // // tpMessages // this.tpMessages.Controls.Add(this.tcMessages); @@ -393,7 +394,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txtMessage; private System.Windows.Forms.Button btnMessageSend; - private System.Windows.Forms.TextBox txtOutput; private System.Windows.Forms.TabControl tcMain; private System.Windows.Forms.TabPage tpOutput; private System.Windows.Forms.TabPage tpMessages; @@ -430,6 +430,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem tsmiColorGrey; private System.Windows.Forms.ToolStripMenuItem tsmiColorLightGrey; private System.Windows.Forms.TabControl tcMessages; + private System.Windows.Forms.RichTextBox rtbOutput; } } diff --git a/ShareX.IRCLib/IRCClient/IRCClientForm.cs b/ShareX.IRCLib/IRCClient/IRCClientForm.cs index 5c9a61699..40b23633d 100644 --- a/ShareX.IRCLib/IRCClient/IRCClientForm.cs +++ b/ShareX.IRCLib/IRCClient/IRCClientForm.cs @@ -46,6 +46,7 @@ public IRCClientForm() : this(new IRCInfo()) public IRCClientForm(IRCInfo info) { InitializeComponent(); + rtbOutput.AddContextMenu(); ((ToolStripDropDownMenu)tsmiColors.DropDown).ShowImageMargin = false; tabManager = new TabManager(tcMessages); @@ -56,6 +57,7 @@ public IRCClientForm(IRCInfo info) IRC = new IRC(Info); IRC.Disconnected += IRC_Disconnected; IRC.Output += IRC_Output; + IRC.ErrorOutput += IRC_ErrorOutput; IRC.Message += IRC_Message; IRC.UserJoined += IRC_UserJoined; } @@ -78,6 +80,16 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } + private void AppendOutput(string output, Color color) + { + this.InvokeSafe(() => + { + rtbOutput.Select(rtbOutput.TextLength, 0); + rtbOutput.SelectionColor = color; + rtbOutput.AppendText($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {output}\r\n"); + }); + } + private void AppendMessage(string message) { txtMessage.AppendTextToSelection(message); @@ -394,10 +406,12 @@ private void IRC_Disconnected() private void IRC_Output(MessageInfo messageInfo) { - this.InvokeSafe(() => - { - txtOutput.AppendText($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {messageInfo.Content}\r\n"); - }); + AppendOutput(messageInfo.Content, Color.Black); + } + + private void IRC_ErrorOutput(Exception e) + { + AppendOutput(e.ToString(), Color.Red); } private void IRC_Message(UserInfo user, string channel, string message) @@ -409,7 +423,7 @@ private void IRC_Message(UserInfo user, string channel, string message) channel = user.Nickname; } - tabManager.AddMessage(channel, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {user.Nickname}: {message}"); + tabManager.AddMessage(channel, $"{user.Nickname}: {message}"); }); } diff --git a/ShareX.IRCLib/IRCClient/IRCClientForm.resx b/ShareX.IRCLib/IRCClient/IRCClientForm.resx index 2cdcb037e..a63fc3c72 100644 --- a/ShareX.IRCLib/IRCClient/IRCClientForm.resx +++ b/ShareX.IRCLib/IRCClient/IRCClientForm.resx @@ -147,15 +147,6 @@ 17, 17 - - 101, 114 - - - cmsMessage - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Segoe UI, 9pt, style=Bold @@ -189,12 +180,6 @@ Normal - - 100, 22 - - - Colors - 135, 22 @@ -291,6 +276,21 @@ Light Grey + + 100, 22 + + + Colors + + + 101, 114 + + + cmsMessage + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Bottom, Right @@ -321,38 +321,20 @@ 6 - - Top, Bottom, Left, Right + + Bottom, Left - - 8, 8 + + 8, 500 - - True + + 112, 24 - - Both + + 0 - - 760, 484 - - - 3 - - - False - - - txtOutput - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpOutput - - - 3 + + Connect btnConnect @@ -366,6 +348,18 @@ 0 + + Top, Bottom, Left, Right + + + 8, 8 + + + 760, 484 + + + 1 + pgSettings @@ -489,6 +483,36 @@ 2 + + Top, Bottom, Left, Right + + + 8, 8 + + + 760, 484 + + + 4 + + + + + + False + + + rtbOutput + + + System.Windows.Forms.RichTextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpOutput + + + 3 + 4, 22 @@ -516,168 +540,6 @@ 1 - - tcMessages - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMessages - - - 0 - - - btnMessagesMenu - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMessages - - - 1 - - - lblMessage - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMessages - - - 2 - - - lblChannel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMessages - - - 3 - - - txtChannel - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMessages - - - 4 - - - 4, 22 - - - 3, 3, 3, 3 - - - 776, 535 - - - 1 - - - Messages - - - tpMessages - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tcMain - - - 2 - - - Fill - - - 0, 0 - - - 784, 561 - - - 0 - - - tcMain - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 1 - - - Bottom, Left - - - 8, 500 - - - 112, 24 - - - 0 - - - Connect - - - btnConnect - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMain - - - 0 - - - Top, Bottom, Left, Right - - - 8, 8 - - - 760, 484 - - - 1 - - - pgSettings - - - System.Windows.Forms.PropertyGrid, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMain - - - 1 - Top, Bottom, Left, Right @@ -716,7 +578,7 @@ ... - @Invariant + btnMessagesMenu @@ -813,6 +675,57 @@ 4 + + 4, 22 + + + 3, 3, 3, 3 + + + 776, 535 + + + 1 + + + Messages + + + tpMessages + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tcMain + + + 2 + + + Fill + + + 0, 0 + + + 784, 561 + + + 0 + + + tcMain + + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + True diff --git a/ShareX.IRCLib/IRCClient/TabInfo.cs b/ShareX.IRCLib/IRCClient/TabInfo.cs index d7421ed91..583bfc6d4 100644 --- a/ShareX.IRCLib/IRCClient/TabInfo.cs +++ b/ShareX.IRCLib/IRCClient/TabInfo.cs @@ -53,10 +53,5 @@ public TabInfo(string name) }; Tab.Controls.Add(TextBox); } - - public void AppendText(string text) - { - TextBox.AppendText(text + "\r\n"); - } } } \ No newline at end of file diff --git a/ShareX.IRCLib/IRCClient/TabManager.cs b/ShareX.IRCLib/IRCClient/TabManager.cs index 7e2685403..e91c8aaca 100644 --- a/ShareX.IRCLib/IRCClient/TabManager.cs +++ b/ShareX.IRCLib/IRCClient/TabManager.cs @@ -93,7 +93,7 @@ private void tc_MouseClick(object sender, MouseEventArgs e) public void AddMessage(string channel, string message) { TabInfo tabInfo = AddChannel(channel); - tabInfo.AppendText(message); + tabInfo.TextBox.AppendText($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {message}\r\n"); } public TabInfo AddChannel(string channel)