Going from ITextEditor to ITextViewer and back

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Going from ITextEditor to ITextViewer and back

Nathan Ridge
Given an ITextEditor, is there a supported way to access its ITextViewer (if it has one)?

Given an ITextViewer, is there a supported way to find the ITextEditor it's associated with?

I find myself needing to go from one to the other fairly frequently.

Thanks,
Nate
_______________________________________________
platform-text-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-text-dev
Reply | Threaded
Open this post in threaded view
|

Re: Going from ITextEditor to ITextViewer and back

Nathan Ridge
> Given an ITextEditor, is there a supported way to access its ITextViewer (if it has one)?

One of the reasons I wanted to do this, is to access the StyledText control via the text viewer.

Today I discovered that you can access the StyledText from the editor directly via getAdapter():

    StyledText textWidget = (StyledText) editor.getAdapter(Control.class);

Are these adapter relationships documented somewhere?

Thanks,
Nate
_______________________________________________
platform-text-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-text-dev
Reply | Threaded
Open this post in threaded view
|

Re: Going from ITextEditor to ITextViewer andback

Daniel Megert
It is not a good practice to access the text widget unless you do it for your own editor. Please see org.eclipse.jface.text.ITextViewer.getTextWidget() for details.

Dani



From:        Nathan Ridge <[hidden email]>
To:        "[hidden email]" <[hidden email]>
Date:        06.08.2018 23:01
Subject:        Re: [platform-text-dev] Going from ITextEditor to ITextViewer and        back
Sent by:        [hidden email]




> Given an ITextEditor, is there a supported way to access its ITextViewer (if it has one)?

One of the reasons I wanted to do this, is to access the StyledText control via the text viewer.

Today I discovered that you can access the StyledText from the editor directly via getAdapter():

   StyledText textWidget = (StyledText) editor.getAdapter(Control.class);

Are these adapter relationships documented somewhere?

Thanks,
Nate
_______________________________________________
platform-text-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-text-dev





_______________________________________________
platform-text-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-text-dev
Reply | Threaded
Open this post in threaded view
|

Re: Going from ITextEditor to ITextViewer andback

Nathan Ridge
> It is not a good practice to access the text widget unless you do it for your own editor. Please see org.eclipse.jface.text.ITextViewer.getTextWidget() for details.

Let me give a concrete example.

In this StackOverflow question [1], a user is writing a plugin that provides a context menu action, and they want to write a filter for the action that enables the action based on what in the editor was right-clicked.

To do this, they need to map the coordinates of the right-click in the editor, to a character offset. StyledText provides a public API for doing this, getOffsetAtPoint(), so I suggested that they use getAdapter() to obtain the StyledText, and then getOffsetAtPoint() to obtain the character offset.

Is there something wrong with this? Is there a better way that I could have suggested?

Thanks,
Nate

[1] https://stackoverflow.com/questions/51710935/eclipse-cdt-plugin-get-ast-element-based-of-x-and-y-position-of-mouse-click-in/
_______________________________________________
platform-text-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-text-dev
Reply | Threaded
Open this post in threaded view
|

Re: Going from ITextEditor toITextViewerandback

Daniel Megert
If you only read values it's not an issue, but if you change things on StyledText it *might* interfere with features implemented in the viewer or the editor.

Dani



From:        Nathan Ridge <[hidden email]>
To:        Eclipse Platform Text component developers list <[hidden email]>
Date:        08.08.2018 19:20
Subject:        Re: [platform-text-dev] Going from ITextEditor to        ITextViewer        andback
Sent by:        [hidden email]




> It is not a good practice to access the text widget unless you do it for your own editor. Please see org.eclipse.jface.text.ITextViewer.getTextWidget() for details.

Let me give a concrete example.

In this StackOverflow question [1], a user is writing a plugin that provides a context menu action, and they want to write a filter for the action that enables the action based on what in the editor was right-clicked.

To do this, they need to map the coordinates of the right-click in the editor, to a character offset. StyledText provides a public API for doing this, getOffsetAtPoint(), so I suggested that they use getAdapter() to obtain the StyledText, and then getOffsetAtPoint() to obtain the character offset.

Is there something wrong with this? Is there a better way that I could have suggested?

Thanks,
Nate

[1]
https://stackoverflow.com/questions/51710935/eclipse-cdt-plugin-get-ast-element-based-of-x-and-y-position-of-mouse-click-in/
_______________________________________________
platform-text-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-text-dev





_______________________________________________
platform-text-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-text-dev