|Making editor regions read-only [message #1841695]
||Tue, 25 May 2021 20:06
| Elie Richa
Registered: February 2016
I would like to implement a functionality where there's an external set of qualified names of objects that I would like to be non-editable. I have a design in mind and I would appreciate feedback on whether this is the right way to go.
I tried a first approach of configuring a custom IXtextEditorCallback, and I registered a custom SWT VerifyListener to intercept editor keystrokes and decide whether to allow them or not.
This worked well. I was able to bring up a dialog message when a protected object is edited and discard the keystroke. But for non-protected objects, typing became unacceptably slow, so I need to improve the design.
I suspect that the slow part is retrieving the current EObject given the current offset of the cursor. I do that using an EObjectAtOffsetHelper.
So now I'm thinking I should avoid that step, and instead be able to decide whether to allow the keystroke or not only based on the offset, without needing to get to the EObject.
To do that I can pre-compute the set of read-only TextRegions when the editor is first loaded. When a key is pressed, I only need to compare the offset with the known read-only regions. That should be much faster than the current computation. And when the keypress occurs in a writable region, I adjust the offsets of read-only regions occurring after the edit point. That's still a bit expensive but hopefully not too much.
Does that seem like a good approach or is there a better way?
Thanks in advance!
Elie Richa, Ph.D
Software Engineer, AdaCore
Powered by FUDForum
. Page generated in 0.01951 seconds