SelectionChangedListener never gets called [message #268238] |
Mon, 23 August 2004 11:23  |
Eclipse User |
|
|
|
Originally posted by: mvsteenbergen.eljakim.scratch-this.nl
In my TextEditor's constructor (Eclipse 3.0 plugin), I do the following:
getSelectionProvider().addSelectionChangedListener(
new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
System.out.println("selectionChanged");
}
}
);
Since getSelectionProvider().setSelection() changes the selection of the
text and the position of the caret, I expect my selectionChanged() to be
called whenever the text selection or caret position in my text editor
changes, but it doesn't. Not when I type, not when I use my mouse to
change the selection, and not even when I programmatically call
getSelectionProvider().setSelection() myself. What am I doing wrong? Are
my expectations wrong? Is there another way to listen for caret position
changes?
What I'd like to achieve eventually is that my outline view (which
displays a tree based on my text editor's text) follows the caret,
selecting the appropriate (most specific) tree node, just like in the
Java editor. The code for determining and selecting the appropriate node
I already have, and at the moment only gets called whenever I reparse my
text.
Thank you very much in advance,
Martijn van Steenbergen.
|
|
|
Re: SelectionChangedListener never gets called [message #268367 is a reply to message #268238] |
Tue, 24 August 2004 04:04   |
Eclipse User |
|
|
|
Originally posted by: daniel.megert.gmx.net
Martijn van Steenbergen wrote:
> In my TextEditor's constructor (Eclipse 3.0 plugin), I do the following:
>
> getSelectionProvider().addSelectionChangedListener(
> new ISelectionChangedListener() {
> public void selectionChanged(SelectionChangedEvent event) {
> System.out.println("selectionChanged");
> }
> }
> );
>
> Since getSelectionProvider().setSelection() changes the selection of
> the text and the position of the caret, I expect my selectionChanged()
> to be called whenever the text selection or caret position in my text
> editor changes, but it doesn't. Not when I type, not when I use my
> mouse to change the selection, and not even when I programmatically
> call getSelectionProvider().setSelection() myself. What am I doing
> wrong? Are my expectations wrong?
Yes. The selection changed event is only sent if the selection changes
but not if the selection remains empty (e.g. while you type or simply
set the caret).
> Is there another way to listen for caret position changes?
Yes, use a post-selection listener. Note: this will not be triggered
immediately i.e. while typing but after some timeout when the user
stopped typing.
HTH
Dani
>
> What I'd like to achieve eventually is that my outline view (which
> displays a tree based on my text editor's text) follows the caret,
> selecting the appropriate (most specific) tree node, just like in the
> Java editor. The code for determining and selecting the appropriate
> node I already have, and at the moment only gets called whenever I
> reparse my text.
>
> Thank you very much in advance,
>
> Martijn van Steenbergen.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 1.03847 seconds