I want to prevent the user from deleting or copying some objects. I set their Deletable and Copyable property to false. That works fine.
But I want to show a message for the user telling him that he cant delete or copy that object.
The problem is that, when Deletable is set to false, the Remove() method is not called.
Also, when Copyable is set to false, the CopyObject is not called.
So, where can I call to show my message?
That depends on how the user tries to delete or copy things.
The Delete key invokes GoView.EditDelete() which calls GoView.DeleteSelection.
A Ctrl-C invokes GoView.EditCopy() which calls GoView.CopyToClipboard.
A Ctrl-X invokes GoView.EditCut() which calls CopyToClipboard and DeleteSelection.
A Ctrl-V invokes GoView.EditPaste() which calls GoView.PasteFromClipboard.
There is also ctrl-drag-and-drop, but that already gives feedback with a “no-drop” cursor.
So you can certainly override those GoView methods to show a message or otherwise to call the base method.
By the way, you probably do not want to override GoObject methods such as Remove or CopyObject for your purposes, since they can get called at other times than what you care about. In fact, Remove is just a convenience method, so it isn’t even called when an object is being removed from a group or a layer. Which is why that method isn’t even virtual.
If you really want to find out when an object has been removed or copied, you probably want to set up a GoDocument.Changed event handler. But, again, that’s not what you want.