Minor fix for msg box copy text

Only use selected text if any
This commit is contained in:
Nikolaj Olsson 2023-12-13 07:17:17 +01:00
parent 6fe1f4f593
commit 563633fc0f
3 changed files with 53 additions and 26 deletions

View File

@ -61,7 +61,7 @@
this.buttonCancel.Text = "C&ancel"; this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Visible = false; this.buttonCancel.Visible = false;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
// //
// buttonOK // buttonOK
// //
@ -74,7 +74,7 @@
this.buttonOK.Text = "&OK"; this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true; this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Visible = false; this.buttonOK.Visible = false;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); this.buttonOK.Click += new System.EventHandler(this.ButtonOK_Click);
// //
// buttonYes // buttonYes
// //
@ -87,7 +87,7 @@
this.buttonYes.Text = "Yes"; this.buttonYes.Text = "Yes";
this.buttonYes.UseVisualStyleBackColor = true; this.buttonYes.UseVisualStyleBackColor = true;
this.buttonYes.Visible = false; this.buttonYes.Visible = false;
this.buttonYes.Click += new System.EventHandler(this.buttonYes_Click); this.buttonYes.Click += new System.EventHandler(this.ButtonYes_Click);
// //
// buttonNo // buttonNo
// //
@ -100,7 +100,7 @@
this.buttonNo.Text = "No"; this.buttonNo.Text = "No";
this.buttonNo.UseVisualStyleBackColor = true; this.buttonNo.UseVisualStyleBackColor = true;
this.buttonNo.Visible = false; this.buttonNo.Visible = false;
this.buttonNo.Click += new System.EventHandler(this.buttonNo_Click); this.buttonNo.Click += new System.EventHandler(this.ButtonNo_Click);
// //
// buttonAbort // buttonAbort
// //
@ -113,7 +113,7 @@
this.buttonAbort.Text = "Abort"; this.buttonAbort.Text = "Abort";
this.buttonAbort.UseVisualStyleBackColor = true; this.buttonAbort.UseVisualStyleBackColor = true;
this.buttonAbort.Visible = false; this.buttonAbort.Visible = false;
this.buttonAbort.Click += new System.EventHandler(this.buttonAbort_Click); this.buttonAbort.Click += new System.EventHandler(this.ButtonAbort_Click);
// //
// buttonRetry // buttonRetry
// //
@ -126,7 +126,7 @@
this.buttonRetry.Text = "Retry"; this.buttonRetry.Text = "Retry";
this.buttonRetry.UseVisualStyleBackColor = true; this.buttonRetry.UseVisualStyleBackColor = true;
this.buttonRetry.Visible = false; this.buttonRetry.Visible = false;
this.buttonRetry.Click += new System.EventHandler(this.buttonRetry_Click); this.buttonRetry.Click += new System.EventHandler(this.ButtonRetry_Click);
// //
// buttonIgnore // buttonIgnore
// //
@ -139,7 +139,7 @@
this.buttonIgnore.Text = "Ignore"; this.buttonIgnore.Text = "Ignore";
this.buttonIgnore.UseVisualStyleBackColor = true; this.buttonIgnore.UseVisualStyleBackColor = true;
this.buttonIgnore.Visible = false; this.buttonIgnore.Visible = false;
this.buttonIgnore.Click += new System.EventHandler(this.buttonIgnore_Click); this.buttonIgnore.Click += new System.EventHandler(this.ButtonIgnore_Click);
// //
// labelText // labelText
// //
@ -183,11 +183,11 @@
this.copyTextToolStripMenuItem.Name = "copyTextToolStripMenuItem"; this.copyTextToolStripMenuItem.Name = "copyTextToolStripMenuItem";
this.copyTextToolStripMenuItem.Size = new System.Drawing.Size(125, 22); this.copyTextToolStripMenuItem.Size = new System.Drawing.Size(125, 22);
this.copyTextToolStripMenuItem.Text = "Copy text"; this.copyTextToolStripMenuItem.Text = "Copy text";
this.copyTextToolStripMenuItem.Click += new System.EventHandler(this.copyTextToolStripMenuItem_Click); this.copyTextToolStripMenuItem.Click += new System.EventHandler(this.CopyTextToolStripMenuItem_Click);
// //
// seTextBox2 // seTextBox2
// //
this.seTextBox2.BackColor = System.Drawing.SystemColors.WindowFrame; this.seTextBox2.BackColor = System.Drawing.SystemColors.Window;
this.seTextBox2.CurrentLanguage = ""; this.seTextBox2.CurrentLanguage = "";
this.seTextBox2.CurrentLineIndex = 0; this.seTextBox2.CurrentLineIndex = 0;
this.seTextBox2.HideSelection = true; this.seTextBox2.HideSelection = true;
@ -202,7 +202,7 @@
this.seTextBox2.Name = "seTextBox2"; this.seTextBox2.Name = "seTextBox2";
this.seTextBox2.Padding = new System.Windows.Forms.Padding(1); this.seTextBox2.Padding = new System.Windows.Forms.Padding(1);
this.seTextBox2.ReadOnly = false; this.seTextBox2.ReadOnly = false;
this.seTextBox2.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None; this.seTextBox2.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Both;
this.seTextBox2.SelectedText = ""; this.seTextBox2.SelectedText = "";
this.seTextBox2.SelectionLength = 0; this.seTextBox2.SelectionLength = 0;
this.seTextBox2.SelectionStart = 0; this.seTextBox2.SelectionStart = 0;
@ -216,12 +216,12 @@
this.contextMenuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.contextMenuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemCopyText}); this.toolStripMenuItemCopyText});
this.contextMenuStrip2.Name = "contextMenuStrip1"; this.contextMenuStrip2.Name = "contextMenuStrip1";
this.contextMenuStrip2.Size = new System.Drawing.Size(181, 48); this.contextMenuStrip2.Size = new System.Drawing.Size(126, 26);
// //
// toolStripMenuItemCopyTxt // toolStripMenuItemCopyText
// //
this.toolStripMenuItemCopyText.Name = "toolStripMenuItemCopyText"; this.toolStripMenuItemCopyText.Name = "toolStripMenuItemCopyText";
this.toolStripMenuItemCopyText.Size = new System.Drawing.Size(180, 22); this.toolStripMenuItemCopyText.Size = new System.Drawing.Size(125, 22);
this.toolStripMenuItemCopyText.Text = "Copy text"; this.toolStripMenuItemCopyText.Text = "Copy text";
// //
// MessageBoxForm // MessageBoxForm

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms.SeMsgBox namespace Nikse.SubtitleEdit.Forms.SeMsgBox
@ -159,7 +160,7 @@ namespace Nikse.SubtitleEdit.Forms.SeMsgBox
var arr = text.SplitToLines(); var arr = text.SplitToLines();
if (arr.Any(p => p.Length > 140)) if (arr.Any(p => p.Length > 140))
{ {
return true; return true;
} }
@ -241,37 +242,37 @@ namespace Nikse.SubtitleEdit.Forms.SeMsgBox
} }
} }
private void buttonYes_Click(object sender, EventArgs e) private void ButtonYes_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Yes; DialogResult = DialogResult.Yes;
} }
private void buttonNo_Click(object sender, EventArgs e) private void ButtonNo_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.No; DialogResult = DialogResult.No;
} }
private void buttonOK_Click(object sender, EventArgs e) private void ButtonOK_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }
private void buttonCancel_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
} }
private void buttonAbort_Click(object sender, EventArgs e) private void ButtonAbort_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Abort; DialogResult = DialogResult.Abort;
} }
private void buttonRetry_Click(object sender, EventArgs e) private void ButtonRetry_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Retry; DialogResult = DialogResult.Retry;
} }
private void buttonIgnore_Click(object sender, EventArgs e) private void ButtonIgnore_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Ignore; DialogResult = DialogResult.Ignore;
} }
@ -286,16 +287,42 @@ namespace Nikse.SubtitleEdit.Forms.SeMsgBox
else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.C) else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.C)
{ {
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
if (!string.IsNullOrEmpty(_text)) SetClipboardText();
}
}
private void SetClipboardText()
{
if (seTextBox2.Visible && seTextBox2.SelectionLength > 0)
{
ClipboardSetText(seTextBox2.SelectedText);
}
else if (!string.IsNullOrEmpty(_text))
{
ClipboardSetText(_text);
}
}
private void ClipboardSetText(string text)
{
for (int i = 0; i < 5; i++)
{
try
{ {
Clipboard.SetText(_text); Clipboard.Clear();
Clipboard.SetText(text);
return;
}
catch
{
Thread.Sleep(100);
} }
} }
} }
private void copyTextToolStripMenuItem_Click(object sender, EventArgs e) private void CopyTextToolStripMenuItem_Click(object sender, EventArgs e)
{ {
Clipboard.SetText(_text); SetClipboardText();
} }
private void MessageBoxForm_Shown(object sender, EventArgs e) private void MessageBoxForm_Shown(object sender, EventArgs e)

View File

@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAm ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAm
CgAAAk1TRnQBSQFMAgEBBAEAAUgBAAFIAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo CgAAAk1TRnQBSQFMAgEBBAEAAVABAAFQAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAASADAAEBAQABCAYAAQgYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AwABQAMAASADAAEBAQABCAYAAQgYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA