Callback "OnPasted" in Xml Editor

Hi,

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

  1. a virtual method “OnPasted” and/or an event “Pasted” - same for the other menu items
    OR
  2. properties to access the default menu items

Would it be possible to add any of those two suggestions?

Best regards

Wolfgang

Just noticed that the context menu items don’t have shortcuts and you handle “Ctrl+V” in “WndProc”.

So, replacing the context menu item would not have the desired effect if the user uses the keyboard => I want the events ;-).

Hi Wolfgang,

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.

Regards,
Dmitry

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.

Yes, that’s fine.

Best regards

Wolfgang

Hi Wolfgang,

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);
            }

Regards,
Dmitry

Thanks, this workaround works like a charm and fulfills my requirement. But having an event would be nicer of course - less subclasses ;-).

Best regards

Wolfgang