From 7c9e5a199f7fa301617eb33c07cbafea287cc259 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Mon, 1 Jan 2024 01:25:58 +0300 Subject: [PATCH 1/4] Fix #1590. --- .../Windows/TextInput.Designer.cs | 200 +++++++++--------- UndertaleModTool/Windows/TextInput.cs | 16 +- 2 files changed, 110 insertions(+), 106 deletions(-) diff --git a/UndertaleModTool/Windows/TextInput.Designer.cs b/UndertaleModTool/Windows/TextInput.Designer.cs index 1bbbfd41e..1008b6c1d 100644 --- a/UndertaleModTool/Windows/TextInput.Designer.cs +++ b/UndertaleModTool/Windows/TextInput.Designer.cs @@ -29,145 +29,139 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.richTextBox1 = new System.Windows.Forms.RichTextBox(); - this.textCommandsMenu = new System.Windows.Forms.ContextMenuStrip(this.components); - this.copyMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.copyAllMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.cutMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.pasteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.button1 = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.textCopyMenu = new System.Windows.Forms.ContextMenuStrip(this.components); - this.copyMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.copyAllMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.textCommandsMenu.SuspendLayout(); - this.textCopyMenu.SuspendLayout(); - this.SuspendLayout(); + components = new System.ComponentModel.Container(); + richTextBox1 = new System.Windows.Forms.RichTextBox(); + textCommandsMenu = new System.Windows.Forms.ContextMenuStrip(components); + copyMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + copyAllMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + cutMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + pasteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + button1 = new System.Windows.Forms.Button(); + label1 = new System.Windows.Forms.Label(); + textCopyMenu = new System.Windows.Forms.ContextMenuStrip(components); + copyMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + copyAllMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + textCommandsMenu.SuspendLayout(); + textCopyMenu.SuspendLayout(); + SuspendLayout(); // // richTextBox1 // - this.richTextBox1.ContextMenuStrip = this.textCommandsMenu; - this.richTextBox1.HideSelection = false; - this.richTextBox1.Location = new System.Drawing.Point(12, 57); - this.richTextBox1.Name = "richTextBox1"; - this.richTextBox1.Size = new System.Drawing.Size(569, 283); - this.richTextBox1.TabIndex = 0; - this.richTextBox1.Text = "Input Text Here"; - this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged); - this.richTextBox1.BackColor = System.Drawing.SystemColors.ControlLight; + richTextBox1.BackColor = System.Drawing.SystemColors.ControlLight; + richTextBox1.ContextMenuStrip = textCommandsMenu; + richTextBox1.HideSelection = false; + richTextBox1.Location = new System.Drawing.Point(12, 57); + richTextBox1.Name = "richTextBox1"; + richTextBox1.Size = new System.Drawing.Size(569, 283); + richTextBox1.TabIndex = 0; + richTextBox1.Text = "Input Text Here"; + richTextBox1.TextChanged += richTextBox1_TextChanged; + richTextBox1.KeyDown += richTextBox1_KeyDown; // // textCommandsMenu // - this.textCommandsMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.copyMenuItem, - this.copyAllMenuItem, - this.cutMenuItem, - this.pasteMenuItem}); - this.textCommandsMenu.Name = "textCommandsMenu"; - this.textCommandsMenu.ShowImageMargin = false; - this.textCommandsMenu.Size = new System.Drawing.Size(93, 92); - this.textCommandsMenu.Opening += new System.ComponentModel.CancelEventHandler(this.textCommandsMenu_Opening); + textCommandsMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { copyMenuItem, copyAllMenuItem, cutMenuItem, pasteMenuItem }); + textCommandsMenu.Name = "textCommandsMenu"; + textCommandsMenu.ShowImageMargin = false; + textCommandsMenu.Size = new System.Drawing.Size(93, 92); + textCommandsMenu.Opening += textCommandsMenu_Opening; // // copyMenuItem // - this.copyMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.copyMenuItem.Name = "copyMenuItem"; - this.copyMenuItem.Size = new System.Drawing.Size(92, 22); - this.copyMenuItem.Text = "Copy"; - this.copyMenuItem.Click += new System.EventHandler(this.copyMenuItem_Click); + copyMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + copyMenuItem.Name = "copyMenuItem"; + copyMenuItem.Size = new System.Drawing.Size(92, 22); + copyMenuItem.Text = "Copy"; + copyMenuItem.Click += copyMenuItem_Click; // // copyAllMenuItem // - this.copyAllMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.copyAllMenuItem.Name = "copyAllMenuItem"; - this.copyAllMenuItem.Size = new System.Drawing.Size(92, 22); - this.copyAllMenuItem.Text = "Copy all"; - this.copyAllMenuItem.Click += new System.EventHandler(this.copyAllMenuItem_Click); + copyAllMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + copyAllMenuItem.Name = "copyAllMenuItem"; + copyAllMenuItem.Size = new System.Drawing.Size(92, 22); + copyAllMenuItem.Text = "Copy all"; + copyAllMenuItem.Click += copyAllMenuItem_Click; // // cutMenuItem // - this.cutMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.cutMenuItem.Name = "cutMenuItem"; - this.cutMenuItem.Size = new System.Drawing.Size(92, 22); - this.cutMenuItem.Text = "Cut"; - this.cutMenuItem.Click += new System.EventHandler(this.cutMenuItem_Click); + cutMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + cutMenuItem.Name = "cutMenuItem"; + cutMenuItem.Size = new System.Drawing.Size(92, 22); + cutMenuItem.Text = "Cut"; + cutMenuItem.Click += cutMenuItem_Click; // // pasteMenuItem // - this.pasteMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.pasteMenuItem.Name = "pasteMenuItem"; - this.pasteMenuItem.Size = new System.Drawing.Size(92, 22); - this.pasteMenuItem.Text = "Paste"; - this.pasteMenuItem.Click += new System.EventHandler(this.pasteMenuItem_Click); + pasteMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + pasteMenuItem.Name = "pasteMenuItem"; + pasteMenuItem.Size = new System.Drawing.Size(92, 22); + pasteMenuItem.Text = "Paste"; + pasteMenuItem.Click += pasteMenuItem_Click; // // button1 // - this.button1.Location = new System.Drawing.Point(211, 346); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(189, 41); - this.button1.TabIndex = 1; - this.button1.Text = "Done"; - this.button1.UseCompatibleTextRendering = true; - this.button1.UseVisualStyleBackColor = true; - this.button1.BackColor = System.Drawing.SystemColors.Control; - this.button1.Click += new System.EventHandler(this.button1_Click); + button1.BackColor = System.Drawing.SystemColors.Control; + button1.Location = new System.Drawing.Point(211, 346); + button1.Name = "button1"; + button1.Size = new System.Drawing.Size(189, 41); + button1.TabIndex = 1; + button1.Text = "Done"; + button1.UseCompatibleTextRendering = true; + button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; // // label1 // - this.label1.AutoSize = true; - this.label1.Dock = System.Windows.Forms.DockStyle.Top; - this.label1.Location = new System.Drawing.Point(0, 0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(133, 17); - this.label1.TabIndex = 2; - this.label1.Text = "Default Prompt Text"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.label1.Click += new System.EventHandler(this.label1_Click); + label1.AutoSize = true; + label1.Dock = System.Windows.Forms.DockStyle.Top; + label1.Location = new System.Drawing.Point(0, 0); + label1.Name = "label1"; + label1.Size = new System.Drawing.Size(133, 17); + label1.TabIndex = 2; + label1.Text = "Default Prompt Text"; + label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + label1.Click += label1_Click; // // textCopyMenu // - this.textCopyMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.copyMenuItem1, - this.copyAllMenuItem1}); - this.textCopyMenu.ShowImageMargin = false; - this.textCopyMenu.Name = "textCopyMenu"; - this.textCopyMenu.Size = new System.Drawing.Size(118, 48); - this.textCopyMenu.Opening += new System.ComponentModel.CancelEventHandler(this.textCopyMenu_Opening); + textCopyMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { copyMenuItem1, copyAllMenuItem1 }); + textCopyMenu.Name = "textCopyMenu"; + textCopyMenu.ShowImageMargin = false; + textCopyMenu.Size = new System.Drawing.Size(118, 48); + textCopyMenu.Opening += textCopyMenu_Opening; // // copyMenuItem1 // - this.copyMenuItem1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.copyMenuItem1.Name = "copyMenuItem1"; - this.copyMenuItem1.Size = new System.Drawing.Size(117, 22); - this.copyMenuItem1.Text = "Copy"; - this.copyMenuItem1.Click += new System.EventHandler(this.copyMenuItem_Click); + copyMenuItem1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + copyMenuItem1.Name = "copyMenuItem1"; + copyMenuItem1.Size = new System.Drawing.Size(117, 22); + copyMenuItem1.Text = "Copy"; + copyMenuItem1.Click += copyMenuItem_Click; // // copyAllMenuItem1 // - this.copyAllMenuItem1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.copyAllMenuItem1.Name = "copyAllMenuItem1"; - this.copyAllMenuItem1.Size = new System.Drawing.Size(117, 22); - this.copyAllMenuItem1.Text = "Copy all"; - this.copyAllMenuItem1.Click += new System.EventHandler(this.copyAllMenuItem_Click); + copyAllMenuItem1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + copyAllMenuItem1.Name = "copyAllMenuItem1"; + copyAllMenuItem1.Size = new System.Drawing.Size(117, 22); + copyAllMenuItem1.Text = "Copy all"; + copyAllMenuItem1.Click += copyAllMenuItem_Click; // // TextInput // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(594, 397); - this.BackColor = System.Drawing.SystemColors.Window; - this.Controls.Add(this.label1); - this.Controls.Add(this.button1); - this.Controls.Add(this.richTextBox1); - this.Name = "TextInput"; - this.Text = "Default Title Message"; - this.Load += new System.EventHandler(this.TextInput_Load); - this.textCommandsMenu.ResumeLayout(false); - this.textCopyMenu.ResumeLayout(false); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + BackColor = System.Drawing.SystemColors.Window; + ClientSize = new System.Drawing.Size(594, 397); + Controls.Add(label1); + Controls.Add(button1); + Controls.Add(richTextBox1); + Name = "TextInput"; + Text = "Default Title Message"; + Load += TextInput_Load; + textCommandsMenu.ResumeLayout(false); + textCopyMenu.ResumeLayout(false); + ResumeLayout(false); + PerformLayout(); } #endregion diff --git a/UndertaleModTool/Windows/TextInput.cs b/UndertaleModTool/Windows/TextInput.cs index d89a7d817..434865c1a 100644 --- a/UndertaleModTool/Windows/TextInput.cs +++ b/UndertaleModTool/Windows/TextInput.cs @@ -80,7 +80,7 @@ public TextInput(string message, string title, string defaultValue, bool allowMu label1.Text = message; richTextBox1.Multiline = AllowMultiline; richTextBox1.DetectUrls = false; - richTextBox1.LanguageOption = RichTextBoxLanguageOptions.UIFonts; //prevents the bug with Japanese characters + richTextBox1.LanguageOption = RichTextBoxLanguageOptions.UIFonts; // Prevents the bug with Japanese characters richTextBox1.ReadOnly = readOnly; label1.AutoSize = false; @@ -100,7 +100,7 @@ public TextInput(string message, string title, string defaultValue, bool allowMu private void TextInput_Load(object sender, EventArgs e) { - richTextBox1.Clear(); //remove "Input text here" + richTextBox1.Clear(); // Remove "Input text here" if (DefaultValue.Length > 0) { @@ -111,7 +111,7 @@ private void TextInput_Load(object sender, EventArgs e) if (richTextBox1.ReadOnly) { - richTextBox1.BackColor = TextBoxBGColor; //restore color to default one. + richTextBox1.BackColor = TextBoxBGColor; // Restore color to default one. richTextBox1.ContextMenuStrip = textCopyMenu; } } @@ -119,6 +119,16 @@ private void TextInput_Load(object sender, EventArgs e) private void richTextBox1_TextChanged(object sender, EventArgs e) { } + private void richTextBox1_KeyDown(object sender, KeyEventArgs e) + { + // Prevent image pasting + if (e.Control && e.KeyCode == Keys.V) + { + if (Clipboard.ContainsText()) + richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Text)); + e.Handled = true; + } + } private void button1_Click(object sender, EventArgs e) { From 1db6151616c44d0cb2cd03acbe3f62458e79e2d8 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Mon, 1 Jan 2024 01:54:15 +0300 Subject: [PATCH 2/4] Improve text input paste detection. --- UndertaleModTool/Windows/TextInput.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UndertaleModTool/Windows/TextInput.cs b/UndertaleModTool/Windows/TextInput.cs index 434865c1a..fe466925e 100644 --- a/UndertaleModTool/Windows/TextInput.cs +++ b/UndertaleModTool/Windows/TextInput.cs @@ -122,10 +122,13 @@ private void richTextBox1_TextChanged(object sender, EventArgs e) private void richTextBox1_KeyDown(object sender, KeyEventArgs e) { // Prevent image pasting - if (e.Control && e.KeyCode == Keys.V) + // Based on this - https://stackoverflow.com/questions/13703083/prevent-images-in-rich-text-box + if (e.Control && e.KeyCode == Keys.V + || e.Shift & e.KeyCode == Keys.Insert) { if (Clipboard.ContainsText()) richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Text)); + e.Handled = true; } } From f79c2d43567f004afe617c21c108e57b9e93b503 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Mon, 1 Jan 2024 03:04:47 +0300 Subject: [PATCH 3/4] Add a comment about Wine. --- UndertaleModTool/Windows/TextInput.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/UndertaleModTool/Windows/TextInput.cs b/UndertaleModTool/Windows/TextInput.cs index fe466925e..b358d4866 100644 --- a/UndertaleModTool/Windows/TextInput.cs +++ b/UndertaleModTool/Windows/TextInput.cs @@ -123,6 +123,7 @@ private void richTextBox1_KeyDown(object sender, KeyEventArgs e) { // Prevent image pasting // Based on this - https://stackoverflow.com/questions/13703083/prevent-images-in-rich-text-box + // TODO: What if you use a different key combination when you run the app from Wine on Linux? if (e.Control && e.KeyCode == Keys.V || e.Shift & e.KeyCode == Keys.Insert) { From bd1ab05f53fee6ce81792ab530fa216a7b79bbec Mon Sep 17 00:00:00 2001 From: VladiStep Date: Mon, 1 Jan 2024 16:05:06 +0300 Subject: [PATCH 4/4] Fix a typo. --- UndertaleModTool/Windows/TextInput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UndertaleModTool/Windows/TextInput.cs b/UndertaleModTool/Windows/TextInput.cs index b358d4866..027af7a09 100644 --- a/UndertaleModTool/Windows/TextInput.cs +++ b/UndertaleModTool/Windows/TextInput.cs @@ -125,7 +125,7 @@ private void richTextBox1_KeyDown(object sender, KeyEventArgs e) // Based on this - https://stackoverflow.com/questions/13703083/prevent-images-in-rich-text-box // TODO: What if you use a different key combination when you run the app from Wine on Linux? if (e.Control && e.KeyCode == Keys.V - || e.Shift & e.KeyCode == Keys.Insert) + || e.Shift && e.KeyCode == Keys.Insert) { if (Clipboard.ContainsText()) richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Text));