From 223c651e1665c8bf4d6ca4e257a848cd0e04fc1c Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 31 Aug 2015 13:57:51 +0300 Subject: [PATCH] Added fundamental tab support to IRC client --- .../{ => IRCClient}/IRCClientForm.Designer.cs | 19 +- .../{ => IRCClient}/IRCClientForm.cs | 13 +- .../{ => IRCClient}/IRCClientForm.resx | 579 ++++++++++-------- ShareX.IRCLib/IRCClient/TabInfo.cs | 63 ++ ShareX.IRCLib/IRCClient/TabManager.cs | 60 ++ ShareX.IRCLib/ShareX.IRCLib.csproj | 8 +- 6 files changed, 460 insertions(+), 282 deletions(-) rename ShareX.IRCLib/{ => IRCClient}/IRCClientForm.Designer.cs (98%) rename ShareX.IRCLib/{ => IRCClient}/IRCClientForm.cs (97%) rename ShareX.IRCLib/{ => IRCClient}/IRCClientForm.resx (92%) create mode 100644 ShareX.IRCLib/IRCClient/TabInfo.cs create mode 100644 ShareX.IRCLib/IRCClient/TabManager.cs diff --git a/ShareX.IRCLib/IRCClientForm.Designer.cs b/ShareX.IRCLib/IRCClient/IRCClientForm.Designer.cs similarity index 98% rename from ShareX.IRCLib/IRCClientForm.Designer.cs rename to ShareX.IRCLib/IRCClient/IRCClientForm.Designer.cs index 9417eeca0..0165283b1 100644 --- a/ShareX.IRCLib/IRCClientForm.Designer.cs +++ b/ShareX.IRCLib/IRCClient/IRCClientForm.Designer.cs @@ -67,8 +67,8 @@ private void InitializeComponent() this.btnMessagesMenu = new System.Windows.Forms.Button(); this.lblMessage = new System.Windows.Forms.Label(); this.lblChannel = new System.Windows.Forms.Label(); - this.txtMessages = new System.Windows.Forms.TextBox(); this.txtChannel = new System.Windows.Forms.TextBox(); + this.tcMessages = new System.Windows.Forms.TabControl(); this.cmsMessage.SuspendLayout(); this.tcMain.SuspendLayout(); this.tpMain.SuspendLayout(); @@ -344,10 +344,10 @@ private void InitializeComponent() // // tpMessages // + this.tpMessages.Controls.Add(this.tcMessages); this.tpMessages.Controls.Add(this.btnMessagesMenu); this.tpMessages.Controls.Add(this.lblMessage); this.tpMessages.Controls.Add(this.lblChannel); - this.tpMessages.Controls.Add(this.txtMessages); this.tpMessages.Controls.Add(this.txtChannel); this.tpMessages.Controls.Add(this.txtMessage); this.tpMessages.Controls.Add(this.btnMessageSend); @@ -372,18 +372,17 @@ private void InitializeComponent() resources.ApplyResources(this.lblChannel, "lblChannel"); this.lblChannel.Name = "lblChannel"; // - // txtMessages - // - resources.ApplyResources(this.txtMessages, "txtMessages"); - this.txtMessages.BackColor = System.Drawing.Color.White; - this.txtMessages.Name = "txtMessages"; - this.txtMessages.ReadOnly = true; - // // txtChannel // resources.ApplyResources(this.txtChannel, "txtChannel"); this.txtChannel.Name = "txtChannel"; // + // tcMessages + // + resources.ApplyResources(this.tcMessages, "tcMessages"); + this.tcMessages.Name = "tcMessages"; + this.tcMessages.SelectedIndex = 0; + // // IRCClientForm // resources.ApplyResources(this, "$this"); @@ -410,7 +409,6 @@ private void InitializeComponent() private System.Windows.Forms.TabControl tcMain; private System.Windows.Forms.TabPage tpOutput; private System.Windows.Forms.TabPage tpMessages; - private System.Windows.Forms.TextBox txtMessages; private System.Windows.Forms.TextBox txtChannel; private System.Windows.Forms.Label lblChannel; private System.Windows.Forms.Label lblMessage; @@ -443,6 +441,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem tsmiColorPink; private System.Windows.Forms.ToolStripMenuItem tsmiColorGrey; private System.Windows.Forms.ToolStripMenuItem tsmiColorLightGrey; + private System.Windows.Forms.TabControl tcMessages; } } diff --git a/ShareX.IRCLib/IRCClientForm.cs b/ShareX.IRCLib/IRCClient/IRCClientForm.cs similarity index 97% rename from ShareX.IRCLib/IRCClientForm.cs rename to ShareX.IRCLib/IRCClient/IRCClientForm.cs index fee3a1c50..7e46a51fe 100644 --- a/ShareX.IRCLib/IRCClientForm.cs +++ b/ShareX.IRCLib/IRCClient/IRCClientForm.cs @@ -35,6 +35,7 @@ public partial class IRCClientForm : Form public IRCInfo Info { get; private set; } public IRC IRC { get; private set; } + private TabManager tabManager; private string lastCommand, lastMessage; public IRCClientForm() : this(new IRCInfo()) @@ -47,6 +48,8 @@ public IRCClientForm(IRCInfo info) Icon = ShareXResources.Icon; ((ToolStripDropDownMenu)tsmiColors.DropDown).ShowImageMargin = false; + tabManager = new TabManager(tcMessages); + Info = info; pgSettings.SelectedObject = Info; @@ -190,10 +193,7 @@ private bool CheckInfo() private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { - if (IRC.IsConnected) - { - IRC.Disconnect(); - } + IRC.Disconnect(); } private void btnConnect_Click(object sender, EventArgs e) @@ -376,7 +376,10 @@ private void IRC_Output(MessageInfo messageInfo) private void IRC_Message(UserInfo user, string channel, string message) { - WriteText($"{DateTime.Now:HH:mm:ss} - {user.Nickname} > {channel}: {message}", txtMessages); + this.InvokeSafe(() => + { + tabManager.AddMessage(channel, $"{DateTime.Now:HH:mm:ss} - {user.Nickname}: {message}"); + }); } private void IRC_UserJoined(UserInfo user, string channel) diff --git a/ShareX.IRCLib/IRCClientForm.resx b/ShareX.IRCLib/IRCClient/IRCClientForm.resx similarity index 92% rename from ShareX.IRCLib/IRCClientForm.resx rename to ShareX.IRCLib/IRCClient/IRCClientForm.resx index b0d4f273f..f49005cb1 100644 --- a/ShareX.IRCLib/IRCClientForm.resx +++ b/ShareX.IRCLib/IRCClient/IRCClientForm.resx @@ -147,6 +147,15 @@ 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 @@ -180,6 +189,12 @@ Normal + + 100, 22 + + + Colors + 135, 22 @@ -276,21 +291,6 @@ 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 @@ -354,6 +354,306 @@ 3 + + btnConnect + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpMain + + + 0 + + + pgSettings + + + System.Windows.Forms.PropertyGrid, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpMain + + + 1 + + + 4, 22 + + + 3, 3, 3, 3 + + + 976, 635 + + + 2 + + + Main + + + tpMain + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tcMain + + + 0 + + + txtCommand + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpOutput + + + 0 + + + lblCommand + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpOutput + + + 1 + + + btnCommandSend + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpOutput + + + 2 + + + 4, 22 + + + 3, 3, 3, 3 + + + 976, 635 + + + 0 + + + IRC output + + + tpOutput + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tcMain + + + 1 + + + Top, Bottom, Left, Right + + + 0, 0 + + + 976, 592 + + + 5 + + + tcMessages + + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpMessages + + + 0 + + + Bottom, Right + + + 856, 602 + + + 24, 24 + + + 4 + + + ... + + + btnMessagesMenu + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpMessages + + + 1 + + + Bottom, Left + + + True + + + 192, 608 + + + 53, 13 + + + 0 + + + Message: + + + lblMessage + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpMessages + + + 2 + + + Bottom, Left + + + True + + + 8, 608 + + + 76, 13 + + + 2 + + + Channel/Nick: + + + lblChannel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpMessages + + + 3 + + + Bottom, Left + + + 88, 604 + + + 96, 20 + + + 1 + + + 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 + + + 976, 635 + + + 1 + + + Messages + + + tpMessages + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tcMain + + + 2 + + + Fill + + + 0, 0 + + + 984, 661 + + + 0 + + + tcMain + + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + Bottom, Left @@ -405,33 +705,6 @@ 1 - - 4, 22 - - - 3, 3, 3, 3 - - - 976, 635 - - - 2 - - - Main - - - tpMain - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tcMain - - - 0 - Bottom, Left, Right @@ -516,228 +789,6 @@ 2 - - 4, 22 - - - 3, 3, 3, 3 - - - 976, 635 - - - 0 - - - IRC output - - - tpOutput - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tcMain - - - 1 - - - Bottom, Right - - - 856, 602 - - - 24, 24 - - - 4 - - - ... - @Invariant - - btnMessagesMenu - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMessages - - - 0 - - - Bottom, Left - - - True - - - 192, 608 - - - 53, 13 - - - 0 - - - Message: - - - lblMessage - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMessages - - - 1 - - - Bottom, Left - - - True - - - 8, 608 - - - 76, 13 - - - 2 - - - Channel/Nick: - - - lblChannel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMessages - - - 2 - - - Top, Bottom, Left, Right - - - 8, 8 - - - True - - - Both - - - 960, 584 - - - 3 - - - False - - - txtMessages - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpMessages - - - 3 - - - Bottom, Left - - - 88, 604 - - - 96, 20 - - - 1 - - - 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 - - - 976, 635 - - - 1 - - - Messages - - - tpMessages - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tcMain - - - 2 - - - Fill - - - 0, 0 - - - 984, 661 - - - 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 new file mode 100644 index 000000000..930971a8a --- /dev/null +++ b/ShareX.IRCLib/IRCClient/TabInfo.cs @@ -0,0 +1,63 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2015 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace ShareX.IRCLib +{ + internal class TabInfo + { + public string Name { get; private set; } + public TabPage Tab { get; private set; } + public TextBox TextBox { get; private set; } + + public TabInfo(string name) + { + Name = name; + Tab = new TabPage(Name); + Tab.Tag = this; + TextBox = new TextBox() + { + BackColor = Color.White, + Dock = DockStyle.Fill, + Multiline = true, + ReadOnly = true, + ScrollBars = ScrollBars.Both, + WordWrap = false + }; + 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 new file mode 100644 index 000000000..354e7df06 --- /dev/null +++ b/ShareX.IRCLib/IRCClient/TabManager.cs @@ -0,0 +1,60 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2015 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace ShareX.IRCLib +{ + internal class TabManager + { + public List Tabs { get; private set; } + + private TabControl tc; + + public TabManager(TabControl tabControl) + { + tc = tabControl; + Tabs = new List(); + } + + public void AddMessage(string channel, string text) + { + TabInfo tabInfo = Tabs.FirstOrDefault(x => x.Name.Equals(channel, StringComparison.InvariantCultureIgnoreCase)); + + if (tabInfo == null) + { + tabInfo = new TabInfo(channel); + tc.Controls.Add(tabInfo.Tab); + Tabs.Add(tabInfo); + } + + tabInfo.AppendText(text); + } + } +} \ No newline at end of file diff --git a/ShareX.IRCLib/ShareX.IRCLib.csproj b/ShareX.IRCLib/ShareX.IRCLib.csproj index 3543d5afe..005b32dc7 100644 --- a/ShareX.IRCLib/ShareX.IRCLib.csproj +++ b/ShareX.IRCLib/ShareX.IRCLib.csproj @@ -46,20 +46,22 @@ - + Form - + IRCClientForm.cs + + - + IRCClientForm.cs