Disable ctrl-x on a GoSimpleNode


#1

Is there a away to disable cutting a node from a GoDocument? I want to allow the user to use the delete key to remove nodes, but not cntrl-x.



Thanks for any help!



nic


#2

Did you want to disallow both Edit | Cut and Control-X? Do you want to permit copying of the node? If YES and NO, respectively, you can just disable copying by setting AllowCopy to false on the view or on the document.
If you just want to disable Control-X, you can install an instance of a subclass of GoToolManager as the GoView.DefaultTool. Just override GoToolManager.DoKeyDown() to check for .LastInput.Control and also .LastInput.Key being equal to Keys.X. If it’s not Control-X, call the base method.
[Serializable]
public class MyToolManager : GoToolManager {
public MyToolManager(GoView v) : base(v) {}
public override void DoKeyDown() {
if (!this.LastInput.Control || this.LastInput.Key != Keys.X)
base.DoKeyDown();
}
}
and when initializing your view:
goView1.DefaultTool = new MyToolManager(goView1);
goView1.Tool = goView1.DefaultTool;
Remember that this just intercepts Control-X; the Edit | Cut menu will still work, and calls to GoView.EditCut() will still work in the normal circumstances.


#3

Thanks Walter, that worked perfectly.