when the user pastes XML text in the editor, I want to check whether the pasted text (or the new content of the editor) contains the “xmlns” attribute. If it is missing, I want to add it.
There is no callback/event to be notified after a paste operation.
So, I thought about hiding the default “Paste” menu item and replacing it with my own “Paste” item. But it is also hard to identify the menu items - I could search them in “SytaxEdit.DefaultMenu” by comparing the ToolStripMenuItem texts.
So I suggest either
a virtual method “OnPasted” and/or an event “Pasted” - same for the other menu items
OR
properties to access the default menu items
Would it be possible to add any of those two suggestions?
We will add Selection.PasteText event, so you will be able to modify the text being pasted. It’s going to be included in the next major update which we aim to release before New Year.
Let me know if you need it earlier and we will provide a hot fix for version 7.2.
We will also look at adding shortcuts for the default popup menu.
Great! Just to clarify: I only need a notification after pasting and then I will check whether the current editor text contains the “xmlns” attribute. I don’t need any information about the pasted text.
We will add two events, like BeforePaste/AfterPaste. In BeforePaste you will be able to modify text which is about to be pasted. What you need is an AfterPaste event to analyse text after it has been already pasted, which you could have a workaround right now, something along this line:
class MySelection : Selection
{
public MySelection(ISyntaxEdit owner)
: base(owner)
{
}
public override void Paste()
{
base.Paste();
if (!Owner.Lines.Text.Contains("xmlns"))
DoSomething();
}
}
class MySyntaxEdit : SyntaxEdit
{
protected override ISelection CreateSelection()
{
return new MySelection(this);
}