Find/Replace logic and fix to Copy/Paste of linked text
This commit is contained in:
parent
b0fc93d078
commit
ad901cb553
@ -1349,6 +1349,42 @@ namespace Volian.Controls.Library
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetSelectedDisplayableText()
|
||||
{
|
||||
StepRTB srtb = new StepRTB();
|
||||
srtb.Rtf = this.SelectedRtf.Replace(@"\u8209?", "-");
|
||||
string rtnstr = "";
|
||||
string ctxt = srtb.Text;//this.SelectedText;
|
||||
if (ctxt.EndsWith("<START]"))
|
||||
ctxt = ctxt.Substring(0, ctxt.Length - 7);
|
||||
int idx = 0;
|
||||
int strtidx = ctxt.IndexOf("<START]");
|
||||
int lnkidx = ctxt.IndexOf("#Link");
|
||||
int endidx = ctxt.IndexOf("[END>");
|
||||
if ((strtidx == -1 || strtidx > lnkidx) && lnkidx > -1 && endidx > -1)
|
||||
{
|
||||
rtnstr += ctxt.Substring(idx, lnkidx);
|
||||
idx = endidx + 5;
|
||||
strtidx = ctxt.IndexOf("<START]", idx);
|
||||
lnkidx = ctxt.IndexOf("#Link:", idx);
|
||||
endidx = ctxt.IndexOf("[END>", idx);
|
||||
}
|
||||
while (strtidx > -1)
|
||||
{
|
||||
rtnstr += ctxt.Substring(idx, strtidx - idx);
|
||||
idx = strtidx + 7;
|
||||
rtnstr += ctxt.Substring(idx, lnkidx - idx);
|
||||
idx = endidx + 5;
|
||||
strtidx = ctxt.IndexOf("<START]", idx);
|
||||
lnkidx = ctxt.IndexOf("#Link:", idx);
|
||||
endidx = ctxt.IndexOf("[END>", idx);
|
||||
}
|
||||
if (idx < ctxt.Length)
|
||||
rtnstr += ctxt.Substring(idx);
|
||||
return rtnstr;
|
||||
}
|
||||
|
||||
private bool IsControlChar = false;
|
||||
private bool _SendBackSpace = false;
|
||||
void StepRTB_KeyDown(object sender, KeyEventArgs e)
|
||||
@ -1358,6 +1394,16 @@ namespace Volian.Controls.Library
|
||||
IsControlChar = true;
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.X: //ctrl-X
|
||||
case Keys.C: //ctrl-C
|
||||
// handle the clipboard copy and cut when a Transition or RO is selected
|
||||
// For now, we are coping/cutting just the displayed text to the clipboard (like 16-bit VE-PROMS)
|
||||
Clipboard.SetText(GetSelectedDisplayableText());
|
||||
e.Handled = true;
|
||||
e.SuppressKeyPress = true;
|
||||
if (e.KeyCode == Keys.X) // cut to clipboard - delete the selected text
|
||||
HandleDeleteKeyWithSelectedText(e, null);
|
||||
break;
|
||||
case Keys.V:
|
||||
IDataObject iData = Clipboard.GetDataObject();
|
||||
if (!iData.GetDataPresent(DataFormats.Text) && !iData.GetDataPresent(DataFormats.Rtf))
|
||||
@ -1813,8 +1859,28 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public DialogResult ReplaceText(string rpltxt, string fndstr, bool caseSensitive, bool matchWholeWord, bool reverse, bool prompt, IWin32Window fndrpldlg)
|
||||
{
|
||||
DialogResult dlgrslt = DialogResult.Yes;
|
||||
if (SelectionLength > 0)
|
||||
{
|
||||
if (IsSelectionLinked(SelectionStart, SelectionLength))
|
||||
{
|
||||
MessageBox.Show(fndrpldlg,"Cannot replace linked text!", "Find/Replace");
|
||||
dlgrslt = DialogResult.No;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (prompt)
|
||||
dlgrslt = MessageBox.Show(fndrpldlg,"Replace This Occurence?", "Replace Text", MessageBoxButtons.YesNoCancel);
|
||||
if (dlgrslt == DialogResult.Yes)
|
||||
SelectedText = rpltxt;
|
||||
}
|
||||
}
|
||||
return dlgrslt;
|
||||
}
|
||||
private RichTextBoxFinds _FindOptions = RichTextBoxFinds.None;
|
||||
public void FindText(string str, bool caseSensitive, bool matchWholeWord, bool reverse)
|
||||
public bool FindText(string str, bool caseSensitive, bool matchWholeWord, bool reverse)
|
||||
{
|
||||
StepRTB savRTF = new StepRTB();
|
||||
int startpos = SelectionStart + SelectionLength;
|
||||
@ -1831,12 +1897,12 @@ namespace Volian.Controls.Library
|
||||
savRTF.Text = this.Text.Substring(0, SelectionStart);
|
||||
startpos = savRTF.Text.Length;
|
||||
if (startpos == 0)
|
||||
return; // at beginning of rtfbox during a reverse find
|
||||
return false; // at beginning of rtfbox during a reverse find
|
||||
}
|
||||
else
|
||||
{
|
||||
if (startpos >= savRTF.Text.Length)
|
||||
return; // at end of rtfbox during a forward find
|
||||
return false; // at end of rtfbox during a forward find
|
||||
}
|
||||
// look for the find string in the temporary rtfbox
|
||||
// then set the cursor selection in the real rtfbox
|
||||
@ -1847,7 +1913,7 @@ namespace Volian.Controls.Library
|
||||
keepgoing = false;
|
||||
if (pos >= 0)
|
||||
{
|
||||
if (this.SkipLinkInfo(pos,str.Length))
|
||||
if (this.SkipLinkInfo(pos, str.Length))
|
||||
{
|
||||
if (reverse)
|
||||
{
|
||||
@ -1856,8 +1922,8 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
else
|
||||
startpos++;
|
||||
if (startpos > 0 && startpos < savRTF.Text.Length)
|
||||
keepgoing = true;
|
||||
if (startpos > 0 && startpos < savRTF.Text.Length)
|
||||
keepgoing = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1865,7 +1931,10 @@ namespace Volian.Controls.Library
|
||||
SelectionLength = str.Length;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private int FindStart()
|
||||
{
|
||||
@ -2493,6 +2562,63 @@ namespace Volian.Controls.Library
|
||||
if (NextLink != null)
|
||||
Console.WriteLine("LinkLocation: {0}.NextLink {1}", str, NextLink);
|
||||
}
|
||||
// #region ClipboardHandler
|
||||
// private const int WM_CUT = 0x0300;
|
||||
// private const int WM_COPY = 0x0301;
|
||||
// private const int WM_PASTE = 0x0302;
|
||||
|
||||
// public delegate void ClipboardEventHandler(object sender, ClipboardEventArgs e);
|
||||
|
||||
// [Category("Clipboard")]
|
||||
// public event ClipboardEventHandler CutText;
|
||||
// [Category("Clipboard")]
|
||||
// public event ClipboardEventHandler CopiedText;
|
||||
// [Category("Clipboard")]
|
||||
// public event ClipboardEventHandler PastedText;
|
||||
|
||||
// protected override void WndProc(ref Message m)
|
||||
// {
|
||||
// if (m.Msg == WM_CUT)
|
||||
// {
|
||||
// if (CutText != null)
|
||||
// CutText(this, new ClipboardEventArgs(this.SelectedText));
|
||||
// }
|
||||
// else if (m.Msg == WM_COPY)
|
||||
// {
|
||||
// if (CopiedText != null)
|
||||
// CopiedText(this, new ClipboardEventArgs(this.SelectedText));
|
||||
// }
|
||||
// else if (m.Msg == WM_PASTE)
|
||||
// {
|
||||
// if (PastedText != null)
|
||||
// PastedText(this, new ClipboardEventArgs(Clipboard.GetText()));
|
||||
// }
|
||||
|
||||
// base.WndProc(ref m);
|
||||
// }
|
||||
//}
|
||||
|
||||
//public class ClipboardEventArgs : EventArgs
|
||||
//{
|
||||
// private string clipboardText;
|
||||
// public string ClipboardText
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return clipboardText;
|
||||
// }
|
||||
|
||||
// set
|
||||
// {
|
||||
// clipboardText = value;
|
||||
// }
|
||||
// }
|
||||
|
||||
// public ClipboardEventArgs(string clipboardText)
|
||||
// {
|
||||
// this.clipboardText = clipboardText;
|
||||
// }
|
||||
// #endregion
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
Loading…
x
Reference in New Issue
Block a user