Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Custom TextEditor, key events and custom encoding
Custom TextEditor, key events and custom encoding [message #509960] Mon, 25 January 2010 21:57 Go to next message
Axel Gneiting is currently offline Axel GneitingFriend
Messages: 10
Registered: January 2010
Junior Member
I'm currently writing a text editor plugin for a custom language (there is already a working Netbeans version). Syntax highlighting, partitioning etc. is all working well now.

The editor is for a theorem proof assistant (Isabelle) and thus the user should have the ability to enter math symbols very easily. This leads to two problems I'm facing right now:


  • I need an IAutoEditStrategy (do I?) that replaces e.g. -> with → (Unicode right arrow). The user should be able to prohibit this transformation by pressing ESC before entering it. But I can't find a way to get that information. There doesn't seem to be a way to listen to key events inside an editor, or I just can't find it.
  • Isabelle only understands ASCII. That means every unicode character must be replaced by an ASCII representation (e.g. → to "\<rightarrow>"). I also can't find an interface suitable of doing that. I tried to register a new Charset to Java via CharsetProvider, but without luck.

I would be very happy if someone could point me in the right directions. Thank you.
Re: Custom TextEditor, key events and custom encoding [message #510202 is a reply to message #509960] Tue, 26 January 2010 11:50 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Axel Gneiting wrote:
> I'm currently writing a text editor plugin for a custom language
> (there is already a working Netbeans version). Syntax highlighting,
> partitioning etc. is all working well now.
>
> The editor is for a theorem proof assistant (Isabelle) and thus the
> user should have the ability to enter math symbols very easily. This
> leads to two problems I'm facing right now:
>
>
> I need an IAutoEditStrategy (do I?) that replaces e.g. -> with →
> (Unicode right arrow). The user should be able to prohibit this
> transformation by pressing ESC before entering it. But I can't find a
> way to get that information. There doesn't seem to be a way to listen
> to key events inside an editor, or I just can't find it.
> Isabelle only understands ASCII.That means every unicode character
> must be replaced by an ASCII representation (e.g. → to "\<rightarrow>").
Can you explain in more detail what user types and what you expect to
happen? I'm a bit confused because first you say you want to replace
"->" with the Unicode arrow and then you say it should only allow ASCII.

Dani

> I also can't find an interface suitable of doing that. I tried to
> register a new Charset to Java via CharsetProvider, but without luck.
>
> I would be very happy if someone could point me in the right
> directions. Thank you.
Re: Custom TextEditor, key events and custom encoding [message #510217 is a reply to message #510202] Tue, 26 January 2010 18:22 Go to previous messageGo to next message
Axel Gneiting is currently offline Axel GneitingFriend
Messages: 10
Registered: January 2010
Junior Member
Please reread the question. These are two completely separate problems.

Problem 1: The editor itself needs to display unicode and provide an easy way to enter these symbols fast, because it's a math language.

Problem 2: Loading and saving the unicode characters from/to a custom ASCII encoding, because the theorem proof assistant doesn't understand them.

[Updated on: Tue, 26 January 2010 18:23]

Report message to a moderator

Re: Custom TextEditor, key events and custom encoding [message #510369 is a reply to message #510217] Wed, 27 January 2010 11:26 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Axel Gneiting wrote:
> Please reread the question. These are two completely separate problems.
>
> Problem 1: The editor itself needs to display unicode and have the
> ability to enter these symbols fast, because it's a math language.
The auto-edit strategy + a verify key listener is the right way to go. I
suggest you take a look at
org.eclipse.jdt.internal.ui.text.java.SmartSemicolonAutoEdit Strategy and
org.eclipse.jdt.internal.ui.text.SmartBackspaceManager: they implement
the Java Editor's smart semicolon feature and allow to und the smartness
by pressing the 'Backspace' key.
>
> Problem 2: Loading and saving the unicode characters from/to a custom
> ASCII encoding, because the theorem proof assistant doesn't understand
> them.
That's best done by writing your own document provider where you can do
the conversion in setDocumentContent and doSaveDocument.

Dani
Re: Custom TextEditor, key events and custom encoding [message #510614 is a reply to message #509960] Thu, 28 January 2010 01:11 Go to previous messageGo to next message
Axel Gneiting is currently offline Axel GneitingFriend
Messages: 10
Registered: January 2010
Junior Member
Thank you very much for pointing me in the right directions Smile
Re: Custom TextEditor, key events and custom encoding [message #510882 is a reply to message #509960] Thu, 28 January 2010 23:31 Go to previous messageGo to next message
Axel Gneiting is currently offline Axel GneitingFriend
Messages: 10
Registered: January 2010
Junior Member
One (hopefully) last question? Where do I define a "verify key listener"?

I'm extending "TextEditor" if that is of any help.
Re: Custom TextEditor, key events and custom encoding [message #511641 is a reply to message #510882] Tue, 02 February 2010 11:08 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Axel Gneiting wrote:
> One (hopefully) last question? Where do I define a "verify key listener"?
Either you also write some sort of manager like the
SmartBackspaceManager and do it there or you directly do it in your editor.

Dani
>
> I'm extending "TextEditor" if that is of any help.
Re: Custom TextEditor, key events and custom encoding [message #511754 is a reply to message #509960] Tue, 02 February 2010 17:58 Go to previous messageGo to next message
Axel Gneiting is currently offline Axel GneitingFriend
Messages: 10
Registered: January 2010
Junior Member
The AutoEditStrategy is working now Smile

But I have a problem with the DocumentProvider:
I use TextFileDocumentProvider, because it allows to open files outside of the project. But apparently there is no way to do the encoding stuff by extending it, or am I missing something?
Re: Custom TextEditor, key events and custom encoding [message #511881 is a reply to message #511754] Wed, 03 February 2010 05:30 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Axel Gneiting wrote:
> The AutoEditStrategy is working now :)
>
> But I have a problem with the DocumentProvider:
> I use TextFileDocumentProvider, because it allows to open files
> outside of the project. But apparently there is no way to do the
> encoding stuff by extending it, or am I missing something?
You are right. As I outlined before you have to write your own document
provider (which can inherit from the TFDP).

Dani
Re: Custom TextEditor, key events and custom encoding [message #512021 is a reply to message #509960] Wed, 03 February 2010 16:45 Go to previous messageGo to next message
Axel Gneiting is currently offline Axel GneitingFriend
Messages: 10
Registered: January 2010
Junior Member
I wanted to extend TextFileDocumentProvider, but the Problem is, that it does not have the functions setDocumentContent and doSaveDocument.

[Updated on: Wed, 03 February 2010 16:45]

Report message to a moderator

Re: Custom TextEditor, key events and custom encoding [message #512145 is a reply to message #512021] Thu, 04 February 2010 02:50 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Axel Gneiting wrote:
> Yeah, I want to extend TextFileDocumentProvider, but the Problem is,
> that it does not have the functions setDocumentContent and
> doSaveDocument.
Right, those methods are in a different IDocumentProvider
implementation. However, similar methods exist in TFDP, just read the
Javadoc. If you extend the TFDP you need to introduce a second document
because the one in the file buffer will not be the same as the one shown
in the editor.

Dani
Re: Custom TextEditor, key events and custom encoding [message #512239 is a reply to message #509960] Thu, 04 February 2010 13:34 Go to previous message
Axel Gneiting is currently offline Axel GneitingFriend
Messages: 10
Registered: January 2010
Junior Member
I looked at the JavaDoc.

There are at least three different methods for saving:
commitFileBuffer
createFileFromDocument
createFileStoreFromDocument

For read operations I think the ITextFileBuffer is created from FileBuffers.getTextFileBufferManager() when connect is called.
And if that is not working the parent document provider (StorageDocumentProvider per default) is used.

So for saving I could change all three methods, but for reading I still can't find a way to extend this class without reimplementing large parts of it. Is there a alternative to TextFileDocumentProvider with an easier interface?

I'm sorry, but the main problem is that Eclipse has such a huge codebase, and I just don't know where to look at exactly.
Previous Topic:Workspace changes
Next Topic:Problem with Eclipse missing /usr/lib/eclipse/startup.jar on Unbuntu
Goto Forum:
  


Current Time: Tue Apr 23 10:31:10 GMT 2024

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

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

Back to the top