From d8b52b69a0e4ed8afacc438bc6d952b277cf330e Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Mon, 26 Oct 2009 10:26:04 +0000 Subject: [PATCH] RAD-48: Add multiline paste capability in chat input. git-svn-id: https://radegast.googlecode.com/svn/trunk@371 f7a694da-4d33-11de-9ad6-1127a62b9fcd --- Radegast/Core/Types/ChatInputBox.cs | 71 ++++++++++++++++++++++ Radegast/GUI/Consoles/ChatConsole.Designer.cs | 5 +- Radegast/GUI/Consoles/ChatConsole.cs | 5 +- .../GUI/Consoles/ConferenceIMTabWindow.Designer.cs | 32 +++++----- Radegast/GUI/Consoles/ConferenceIMTabWindow.cs | 4 +- Radegast/GUI/Consoles/GroupIMTabWindow.Designer.cs | 10 +-- Radegast/GUI/Consoles/GroupIMTabWindow.cs | 4 +- Radegast/GUI/Consoles/IMTabWindow.Designer.cs | 31 +++++----- Radegast/GUI/Consoles/IMTabWindow.cs | 20 +++++- Radegast/Radegast.csproj | 3 + 10 files changed, 136 insertions(+), 49 deletions(-) create mode 100644 Radegast/Core/Types/ChatInputBox.cs diff --git a/Radegast/Core/Types/ChatInputBox.cs b/Radegast/Core/Types/ChatInputBox.cs new file mode 100644 index 0000000..0158bfa --- /dev/null +++ b/Radegast/Core/Types/ChatInputBox.cs @@ -0,0 +1,71 @@ +// +// Radegast Metaverse Client +// Copyright (c) 2009, Radegast Development Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of the application "Radegast", nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// $Id: IMTabWindow.Designer.cs 323 2009-10-07 01:08:34Z latifer@gmail.com $ +// +using System; +using System.Windows.Forms; + +namespace Radegast +{ + public class ChatInputBox : TextBox + { + public static readonly string NewlineMarker = new string('\u00b6', 1); + + public ChatInputBox() + : base() + { + } + + protected override void WndProc(ref Message m) + { + switch (m.Msg) + { + case 0x302: //WM_PASTE + Paste(); + break; + + default: + base.WndProc(ref m); + break; + } + } + + public new void Paste() + { + Paste(Clipboard.GetText()); + } + + public new void Paste(string text) + { + base.Paste(text.Replace(Environment.NewLine, NewlineMarker)); + } + + + } +} diff --git a/Radegast/GUI/Consoles/ChatConsole.Designer.cs b/Radegast/GUI/Consoles/ChatConsole.Designer.cs index eb1aefa..287a22e 100644 --- a/Radegast/GUI/Consoles/ChatConsole.Designer.cs +++ b/Radegast/GUI/Consoles/ChatConsole.Designer.cs @@ -63,7 +63,7 @@ namespace Radegast this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChatConsole)); this.rtbChat = new System.Windows.Forms.RichTextBox(); - this.cbxInput = new System.Windows.Forms.ComboBox(); + this.cbxInput = new ChatInputBox(); this.btnSay = new System.Windows.Forms.Button(); this.btnShout = new System.Windows.Forms.Button(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); @@ -130,7 +130,6 @@ namespace Radegast this.cbxInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.cbxInput.Enabled = false; - this.cbxInput.FormattingEnabled = true; this.cbxInput.Location = new System.Drawing.Point(0, 0); this.cbxInput.Name = "cbxInput"; this.cbxInput.Size = new System.Drawing.Size(352, 21); @@ -525,7 +524,7 @@ namespace Radegast public ListViewNoFlicker lvwObjects; public RichTextBox rtbChat; - public ComboBox cbxInput; + public ChatInputBox cbxInput; public Button btnSay; public Button btnShout; public SplitContainer splitContainer1; diff --git a/Radegast/GUI/Consoles/ChatConsole.cs b/Radegast/GUI/Consoles/ChatConsole.cs index fce9b11..3e92729 100644 --- a/Radegast/GUI/Consoles/ChatConsole.cs +++ b/Radegast/GUI/Consoles/ChatConsole.cs @@ -53,7 +53,7 @@ namespace Radegast private Dictionary avatars = new Dictionary(); private Dictionary bots = new Dictionary(); private readonly Dictionary agentSimHandle = new Dictionary(); - public ComboBox ChatInputText { get { return cbxInput; } } + public ChatInputBox ChatInputText { get { return cbxInput; } } public ChatConsole(RadegastInstance instance) { @@ -284,6 +284,8 @@ namespace Radegast msg = input; } + msg = msg.Replace(ChatInputBox.NewlineMarker, "\n"); + int ch = 0; Match m = chatRegex.Match(msg); @@ -301,7 +303,6 @@ namespace Radegast private void ClearChatInput() { - cbxInput.Items.Add(cbxInput.Text); cbxInput.Text = string.Empty; } diff --git a/Radegast/GUI/Consoles/ConferenceIMTabWindow.Designer.cs b/Radegast/GUI/Consoles/ConferenceIMTabWindow.Designer.cs index d6213d8..aaa2474 100644 --- a/Radegast/GUI/Consoles/ConferenceIMTabWindow.Designer.cs +++ b/Radegast/GUI/Consoles/ConferenceIMTabWindow.Designer.cs @@ -59,8 +59,8 @@ namespace Radegast private void InitializeComponent() { this.rtbIMText = new System.Windows.Forms.RichTextBox(); - this.cbxInput = new System.Windows.Forms.ComboBox(); this.btnSend = new System.Windows.Forms.Button(); + this.cbxInput = new Radegast.ChatInputBox(); this.SuspendLayout(); // // rtbIMText @@ -78,24 +78,11 @@ namespace Radegast this.rtbIMText.Text = ""; this.rtbIMText.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.rtbIMText_LinkClicked); // - // cbxInput - // - this.cbxInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.cbxInput.FormattingEnabled = true; - this.cbxInput.Location = new System.Drawing.Point(3, 306); - this.cbxInput.Name = "cbxInput"; - this.cbxInput.Size = new System.Drawing.Size(413, 21); - this.cbxInput.TabIndex = 0; - this.cbxInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyUp); - this.cbxInput.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyDown); - this.cbxInput.TextChanged += new System.EventHandler(this.cbxInput_TextChanged); - // // btnSend // this.btnSend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnSend.Enabled = false; - this.btnSend.Location = new System.Drawing.Point(422, 304); + this.btnSend.Location = new System.Drawing.Point(422, 305); this.btnSend.Name = "btnSend"; this.btnSend.Size = new System.Drawing.Size(75, 23); this.btnSend.TabIndex = 1; @@ -103,6 +90,18 @@ namespace Radegast this.btnSend.UseVisualStyleBackColor = true; this.btnSend.Click += new System.EventHandler(this.btnSend_Click); // + // cbxInput + // + this.cbxInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.cbxInput.Location = new System.Drawing.Point(3, 306); + this.cbxInput.Name = "cbxInput"; + this.cbxInput.Size = new System.Drawing.Size(413, 21); + this.cbxInput.TabIndex = 0; + this.cbxInput.TextChanged += new System.EventHandler(this.cbxInput_TextChanged); + this.cbxInput.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyDown); + this.cbxInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyUp); + // // ConferenceIMTabWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -114,13 +113,14 @@ namespace Radegast this.Name = "ConferenceIMTabWindow"; this.Size = new System.Drawing.Size(500, 330); this.ResumeLayout(false); + this.PerformLayout(); } #endregion public System.Windows.Forms.RichTextBox rtbIMText; - public System.Windows.Forms.ComboBox cbxInput; + public ChatInputBox cbxInput; public System.Windows.Forms.Button btnSend; } diff --git a/Radegast/GUI/Consoles/ConferenceIMTabWindow.cs b/Radegast/GUI/Consoles/ConferenceIMTabWindow.cs index ad6ea00..3723fd5 100644 --- a/Radegast/GUI/Consoles/ConferenceIMTabWindow.cs +++ b/Radegast/GUI/Consoles/ConferenceIMTabWindow.cs @@ -139,7 +139,8 @@ namespace Radegast private void SendMessage(string msg) { - string message = msg; + string message = msg.Replace(ChatInputBox.NewlineMarker, "\n"); + if (message.Length > 1023) { message = message.Remove(1023); @@ -152,7 +153,6 @@ namespace Radegast private void ClearIMInput() { - cbxInput.Items.Add(cbxInput.Text); cbxInput.Text = string.Empty; } diff --git a/Radegast/GUI/Consoles/GroupIMTabWindow.Designer.cs b/Radegast/GUI/Consoles/GroupIMTabWindow.Designer.cs index 56727da..a52d452 100644 --- a/Radegast/GUI/Consoles/GroupIMTabWindow.Designer.cs +++ b/Radegast/GUI/Consoles/GroupIMTabWindow.Designer.cs @@ -59,7 +59,7 @@ namespace Radegast private void InitializeComponent() { this.rtbIMText = new System.Windows.Forms.RichTextBox(); - this.cbxInput = new System.Windows.Forms.ComboBox(); + this.cbxInput = new Radegast.ChatInputBox(); this.btnSend = new System.Windows.Forms.Button(); this.chatSplit = new System.Windows.Forms.SplitContainer(); this.Participants = new Radegast.ListViewNoFlicker(); @@ -86,14 +86,13 @@ namespace Radegast // this.cbxInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.cbxInput.FormattingEnabled = true; this.cbxInput.Location = new System.Drawing.Point(3, 306); this.cbxInput.Name = "cbxInput"; this.cbxInput.Size = new System.Drawing.Size(373, 21); this.cbxInput.TabIndex = 0; - this.cbxInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyUp); - this.cbxInput.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyDown); this.cbxInput.TextChanged += new System.EventHandler(this.cbxInput_TextChanged); + this.cbxInput.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyDown); + this.cbxInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyUp); // // btnSend // @@ -168,13 +167,14 @@ namespace Radegast this.chatSplit.Panel2.ResumeLayout(false); this.chatSplit.ResumeLayout(false); this.ResumeLayout(false); + this.PerformLayout(); } #endregion public System.Windows.Forms.RichTextBox rtbIMText; - public System.Windows.Forms.ComboBox cbxInput; + public ChatInputBox cbxInput; public System.Windows.Forms.Button btnSend; public System.Windows.Forms.SplitContainer chatSplit; public ListViewNoFlicker Participants; diff --git a/Radegast/GUI/Consoles/GroupIMTabWindow.cs b/Radegast/GUI/Consoles/GroupIMTabWindow.cs index 64e4d63..4f54884 100644 --- a/Radegast/GUI/Consoles/GroupIMTabWindow.cs +++ b/Radegast/GUI/Consoles/GroupIMTabWindow.cs @@ -300,7 +300,8 @@ namespace Radegast { if (cbxInput.Text.Length == 0) return; - string message = cbxInput.Text; + string message = cbxInput.Text.Replace(ChatInputBox.NewlineMarker, "\n"); + if (message.Length > 1023) message = message.Remove(1023); if (!client.Self.GroupChatSessions.ContainsKey(session)) @@ -326,7 +327,6 @@ namespace Radegast private void ClearIMInput() { - cbxInput.Items.Add(cbxInput.Text); cbxInput.Text = string.Empty; } diff --git a/Radegast/GUI/Consoles/IMTabWindow.Designer.cs b/Radegast/GUI/Consoles/IMTabWindow.Designer.cs index 3c534fe..9224a9e 100644 --- a/Radegast/GUI/Consoles/IMTabWindow.Designer.cs +++ b/Radegast/GUI/Consoles/IMTabWindow.Designer.cs @@ -59,10 +59,10 @@ namespace Radegast private void InitializeComponent() { this.rtbIMText = new System.Windows.Forms.RichTextBox(); - this.cbxInput = new System.Windows.Forms.ComboBox(); this.btnSend = new System.Windows.Forms.Button(); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.tbtnProfile = new System.Windows.Forms.ToolStripButton(); + this.cbxInput = new Radegast.ChatInputBox(); this.toolStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -81,24 +81,11 @@ namespace Radegast this.rtbIMText.Text = ""; this.rtbIMText.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.rtbIMText_LinkClicked); // - // cbxInput - // - this.cbxInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.cbxInput.FormattingEnabled = true; - this.cbxInput.Location = new System.Drawing.Point(3, 306); - this.cbxInput.Name = "cbxInput"; - this.cbxInput.Size = new System.Drawing.Size(413, 21); - this.cbxInput.TabIndex = 0; - this.cbxInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyUp); - this.cbxInput.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyDown); - this.cbxInput.TextChanged += new System.EventHandler(this.cbxInput_TextChanged); - // // btnSend // this.btnSend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnSend.Enabled = false; - this.btnSend.Location = new System.Drawing.Point(422, 304); + this.btnSend.Location = new System.Drawing.Point(422, 302); this.btnSend.Name = "btnSend"; this.btnSend.Size = new System.Drawing.Size(75, 23); this.btnSend.TabIndex = 1; @@ -126,6 +113,18 @@ namespace Radegast this.tbtnProfile.Text = "Profile"; this.tbtnProfile.Click += new System.EventHandler(this.tbtnProfile_Click); // + // cbxInput + // + this.cbxInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.cbxInput.Location = new System.Drawing.Point(3, 304); + this.cbxInput.Name = "cbxInput"; + this.cbxInput.Size = new System.Drawing.Size(413, 21); + this.cbxInput.TabIndex = 0; + this.cbxInput.TextChanged += new System.EventHandler(this.cbxInput_TextChanged); + this.cbxInput.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyDown); + this.cbxInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cbxInput_KeyUp); + // // IMTabWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -147,7 +146,7 @@ namespace Radegast #endregion public System.Windows.Forms.RichTextBox rtbIMText; - public System.Windows.Forms.ComboBox cbxInput; + public ChatInputBox cbxInput; public System.Windows.Forms.Button btnSend; public System.Windows.Forms.ToolStrip toolStrip1; public System.Windows.Forms.ToolStripButton tbtnProfile; diff --git a/Radegast/GUI/Consoles/IMTabWindow.cs b/Radegast/GUI/Consoles/IMTabWindow.cs index bdd6f1b..4d2b6c7 100644 --- a/Radegast/GUI/Consoles/IMTabWindow.cs +++ b/Radegast/GUI/Consoles/IMTabWindow.cs @@ -100,7 +100,7 @@ namespace Radegast private void btnSend_Click(object sender, EventArgs e) { - netcom.SendInstantMessage(cbxInput.Text, target, session); + netcom.SendInstantMessage(cbxInput.Text.Replace(ChatInputBox.NewlineMarker, "\n"), target, session); this.ClearIMInput(); } @@ -142,13 +142,12 @@ namespace Radegast e.SuppressKeyPress = true; if (cbxInput.Text.Length == 0) return; - netcom.SendInstantMessage(cbxInput.Text, target, session); + netcom.SendInstantMessage(cbxInput.Text.Replace(ChatInputBox.NewlineMarker, "\n"), target, session); this.ClearIMInput(); } private void ClearIMInput() { - cbxInput.Items.Add(cbxInput.Text); cbxInput.Text = string.Empty; } @@ -195,5 +194,20 @@ namespace Radegast get { return textManager; } set { textManager = value; } } + + private void chatInput_TextChanged(object sender, EventArgs e) + { + + } + + private void chatInput_KeyDown(object sender, KeyEventArgs e) + { + + } + + private void chatInput_KeyUp(object sender, KeyEventArgs e) + { + + } } } diff --git a/Radegast/Radegast.csproj b/Radegast/Radegast.csproj index 3c8df92..beddd5e 100644 --- a/Radegast/Radegast.csproj +++ b/Radegast/Radegast.csproj @@ -131,6 +131,9 @@ Component + + Component + UserControl -- 2.11.0