Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Making editor regions read-only
Making editor regions read-only [message #1841695] Tue, 25 May 2021 20:06 Go to next message
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
Hello folks,

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
https://www.adacore.com
Re: Making editor regions read-only [message #1841712 is a reply to message #1841695] Wed, 26 May 2021 12:01 Go to previous messageGo to next message
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
I ended up going a different path.

I implemented a state machine in my listener and I listened to changes in cursor position in addition to key presses.

Now when the first key is pressed, I determine if the edit is allowed or not and put the listener in the "allow" or "reject" state. The next key presses no longer trigger a lookup of the current object. All key presses are immediately allowed or rejected.

Then when the cursor moves to a new position, I reset the state of the listener. So the next key press re-triggers the expensive lookup and so on.

This is much more efficient than my initial plan.


Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
Re: Making editor regions read-only [message #1841863 is a reply to message #1841712] Tue, 01 June 2021 12:56 Go to previous message
Yannick DAVELUY is currently offline Yannick DAVELUYFriend
Messages: 39
Registered: July 2020
Member
Hello,

Maybe you could use code mining:
https://blogs.itemis.com/en/code-mining-support-in-xtext
https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#code-mining

Yannick
Previous Topic:Optional ordering with commas where first element can also be optional
Next Topic:How to change Xtext DSL file programmatically ? (Xtext 2.24)
Goto Forum:
  


Current Time: Thu Apr 25 00:17:09 GMT 2024

Powered by FUDForum. Page generated in 0.02999 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top