Use the currently active control for Ctrl-C, Ctrl-X and Ctrl-V
This commit is contained in:
parent
624a3669bb
commit
fa9ad85a36
@ -14,6 +14,7 @@ namespace Volian.Controls.Library
|
|||||||
{
|
{
|
||||||
public partial class StepTabRibbon : UserControl
|
public partial class StepTabRibbon : UserControl
|
||||||
{
|
{
|
||||||
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
#region Properties
|
#region Properties
|
||||||
private VlnFlexGrid MyFlexGrid
|
private VlnFlexGrid MyFlexGrid
|
||||||
{
|
{
|
||||||
@ -888,32 +889,102 @@ namespace Volian.Controls.Library
|
|||||||
private void btnPaste_Click(object sender, EventArgs e)
|
private void btnPaste_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
IDataObject myDO = Clipboard.GetDataObject();
|
IDataObject myDO = Clipboard.GetDataObject();
|
||||||
|
RichTextBox myRtb = _MyStepRTB;
|
||||||
|
Control ctrl = FindActiveControl();
|
||||||
|
Console.WriteLine("Paste myRTB == ctrl {0}", myRtb.Equals(ctrl));
|
||||||
|
if (!_MyStepRTB.Focused)
|
||||||
|
{
|
||||||
|
if (ctrl is RichTextBox)
|
||||||
|
{
|
||||||
|
myRtb = ctrl as RichTextBox;
|
||||||
|
}
|
||||||
|
else if (ctrl is ComboBox)
|
||||||
|
{
|
||||||
|
ComboBox cmb = ctrl as ComboBox;
|
||||||
|
if (myDO.GetDataPresent(DataFormats.Text))
|
||||||
|
cmb.SelectedText = myDO.GetData(DataFormats.Text).ToString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SaveErrorInLogProblemWithType(ctrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (myDO.GetDataPresent(DataFormats.Rtf))
|
if (myDO.GetDataPresent(DataFormats.Rtf))
|
||||||
{
|
{
|
||||||
string tmpForLink = myDO.GetData(DataFormats.Rtf).ToString();
|
string tmpForLink = myDO.GetData(DataFormats.Rtf).ToString();
|
||||||
tmpForLink = Regex.Replace(tmpForLink, @"#Link:ReferencedObject:[0-9]+ ", @"#Link:ReferencedObject:<NewID> ");
|
tmpForLink = Regex.Replace(tmpForLink, @"#Link:ReferencedObject:[0-9]+ ", @"#Link:ReferencedObject:<NewID> ");
|
||||||
tmpForLink = Regex.Replace(tmpForLink, @"#Link:Transition:([0-9]+) [0-9]+ ", @"#Link:Transition:$1 <NewID> ");
|
tmpForLink = Regex.Replace(tmpForLink, @"#Link:Transition:([0-9]+) [0-9]+ ", @"#Link:Transition:$1 <NewID> ");
|
||||||
tmpForLink = Regex.Replace(tmpForLink, @"#Link:TransitionRange:([0-9]+) [0-9]+ ", @"#Link:TransitionRange:$1 <NewID> ");
|
tmpForLink = Regex.Replace(tmpForLink, @"#Link:TransitionRange:([0-9]+) [0-9]+ ", @"#Link:TransitionRange:$1 <NewID> ");
|
||||||
_MyStepRTB.SelectedRtf = tmpForLink;
|
myRtb.SelectedRtf = tmpForLink;
|
||||||
}
|
}
|
||||||
else if (myDO.GetDataPresent(DataFormats.Text))
|
else if (myDO.GetDataPresent(DataFormats.Text))
|
||||||
_MyStepRTB.SelectedText = myDO.GetData(DataFormats.Text).ToString();
|
myRtb.SelectedText = myDO.GetData(DataFormats.Text).ToString();
|
||||||
if (_MyStepRTB.SelectionLength == 0) _MyStepRTB.SelectionFont = _MyStepRTB.MyStyleFont.WindowsFont;
|
if (myRtb.SelectionLength == 0 && myRtb is StepRTB) myRtb.SelectionFont = (myRtb as StepRTB).MyStyleFont.WindowsFont;
|
||||||
|
}
|
||||||
|
private void SaveErrorInLogProblemWithType(Control ctrl)
|
||||||
|
{
|
||||||
|
StringBuilder errormsg = new StringBuilder(string.Format("Failed clipboard action with control {0} a {1} ", ctrl.Name, ctrl.GetType().Name));
|
||||||
|
Type typ = ctrl.GetType();
|
||||||
|
while (typ.Name != "Control")
|
||||||
|
{
|
||||||
|
errormsg.Append(string.Format(", dervied from {0}", typ.BaseType.Name));
|
||||||
|
typ = typ.BaseType;
|
||||||
|
}
|
||||||
|
_MyLog.Error(errormsg);
|
||||||
|
}
|
||||||
|
private Control FindActiveControl()
|
||||||
|
{
|
||||||
|
Control tmp = this;
|
||||||
|
while (!(tmp.Parent is Form))
|
||||||
|
tmp = tmp.Parent;
|
||||||
|
Form frm = tmp.Parent as Form;
|
||||||
|
tmp = frm.ActiveControl;
|
||||||
|
while (tmp.Controls.Count > 0)
|
||||||
|
foreach (Control ctrl in tmp.Controls)
|
||||||
|
if (ctrl.ContainsFocus)
|
||||||
|
{
|
||||||
|
tmp = ctrl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
}
|
}
|
||||||
private void btnCut_Click(object sender, EventArgs e)
|
private void btnCut_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
MoveSelectedToClipboard(true);
|
||||||
|
}
|
||||||
|
private void MoveSelectedToClipboard(bool isCut)
|
||||||
|
{
|
||||||
|
Control ctrl = FindActiveControl();
|
||||||
Clipboard.Clear();
|
Clipboard.Clear();
|
||||||
DataObject myDO = new DataObject("Rich Text Format", _MyStepRTB.SelectedRtf);
|
DataObject myDO;
|
||||||
myDO.SetText(_MyStepRTB.SelectedText);
|
if (ctrl is RichTextBox)
|
||||||
|
{
|
||||||
|
myDO = new DataObject("Rich Text Format", (ctrl as RichTextBox).SelectedRtf);
|
||||||
|
myDO.SetText(_MyStepRTB.SelectedText);
|
||||||
|
(ctrl as RichTextBox).SelectedText = "";
|
||||||
|
}
|
||||||
|
else if (ctrl is ComboBox)
|
||||||
|
{
|
||||||
|
myDO = new DataObject("Text Format", (ctrl as ComboBox).SelectedText);
|
||||||
|
(ctrl as ComboBox).SelectedText = "";
|
||||||
|
}
|
||||||
|
else if (ctrl is TextBox)
|
||||||
|
{
|
||||||
|
myDO = new DataObject("Text Format", (ctrl as TextBox).SelectedText);
|
||||||
|
(ctrl as TextBox).SelectedText = "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SaveErrorInLogProblemWithType(ctrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Clipboard.SetDataObject(myDO);
|
Clipboard.SetDataObject(myDO);
|
||||||
_MyStepRTB.SelectedText = "";
|
|
||||||
}
|
}
|
||||||
private void btnCopy_Click(object sender, EventArgs e)
|
private void btnCopy_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Clipboard.Clear();
|
MoveSelectedToClipboard(false);
|
||||||
DataObject myDO = new DataObject("Rich Text Format", _MyStepRTB.SelectedRtf);
|
|
||||||
myDO.SetText(_MyStepRTB.SelectedText);
|
|
||||||
Clipboard.SetDataObject(myDO);
|
|
||||||
}
|
}
|
||||||
private void btnBold_Click(object sender, EventArgs e)
|
private void btnBold_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user