Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Communication between editors
Communication between editors [message #266062] Mon, 09 August 2004 09:36 Go to next message
Eclipse UserFriend
Originally posted by: aheenan.ie.ibm.com

Hey everyone,

I have two editors embedded in a Sash (think multi page editor) this
allows both editors to be viewable at the same time.

What I want to happen is that when a user double clicks on a piece of
text in the first editor it will simultaneously highlight text at the
same position in the second editor.

I want to run all the above using what line number the person double
clicks on. I am currently able to find the current caret position using
the viewer and StyledText. However I want to relate that information
to the other editor. I get a bit lost at this point....

I've had a brief look at the design pattern the mediator which appeared
to be along the right lines however it appears to be used for more
complex situations.

I'd really appreciate some/any advice on where to start or what to look
further into. :-)

Thanks,
A.
Re: Communication between editors [message #266066 is a reply to message #266062] Mon, 09 August 2004 09:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Chris_Laffra.ca.ibm.com

You can start looking at how Outline views work. They really are
(very silly) editors that reacts to you navigating through another.

See FAQ 341 at http://eclipsefaq.org, and FAQ 179 which talks about
how a related view works, the Properties view.

Chris

"Angela Heenan" <aheenan@ie.ibm.com> wrote in message
news:cf7uf3$5qr$1@eclipse.org...
> Hey everyone,
>
> I have two editors embedded in a Sash (think multi page editor) this
> allows both editors to be viewable at the same time.
>
> What I want to happen is that when a user double clicks on a piece of
> text in the first editor it will simultaneously highlight text at the
> same position in the second editor.
>
> I want to run all the above using what line number the person double
> clicks on. I am currently able to find the current caret position using
> the viewer and StyledText. However I want to relate that information
> to the other editor. I get a bit lost at this point....
>
> I've had a brief look at the design pattern the mediator which appeared
> to be along the right lines however it appears to be used for more
> complex situations.
>
> I'd really appreciate some/any advice on where to start or what to look
> further into. :-)
>
> Thanks,
> A.
Re: Communication between editors [message #266093 is a reply to message #266062] Mon, 09 August 2004 11:05 Go to previous messageGo to next message
Eclipse UserFriend
Angela Heenan wrote:
> What I want to happen is that when a user double clicks on a piece of
> text in the first editor it will simultaneously highlight text at the
> same position in the second editor.

What does "same position" mean? The same line number and character
offset on that line number in the other document?

-tom
Re: Communication between editors [message #266108 is a reply to message #266093] Mon, 09 August 2004 12:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aheenan.ie.ibm.com

Tom Eicher wrote:
> What does "same position" mean? The same line number and character
> offset on that line number in the other document?
>
> -tom

Yes, exactly.

I'm currently having a look at how the outline is implemented as it
appears to be doing something very similar to what I am doing.

A.
Re: Communication between editors [message #266211 is a reply to message #266108] Tue, 10 August 2004 05:34 Go to previous messageGo to next message
Eclipse UserFriend
Angela Heenan wrote:
> I'm currently having a look at how the outline is implemented as it
> appears to be doing something very similar to what I am doing.

What isn't working with the way to get the current line and selection I
proposed before?

-t
Re: Communication between editors [message #266219 is a reply to message #266211] Tue, 10 August 2004 07:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aheenan.ie.ibm.com

Tom Eicher wrote:
> Angela Heenan wrote:
>
>> I'm currently having a look at how the outline is implemented as it
>> appears to be doing something very similar to what I am doing.
>
>
> What isn't working with the way to get the current line and selection I
> proposed before?
>
> -t

Hi Tom,

I implemented your suggestion as you suggested, more than likely
incorrectly as I'm new to all this so it's all a bit overwhelming.
I'll try to explain how I implemented it and could you please
point out where I'm going wrong.

I placed the following code in the createPages() method of the
MultiPageEditor. (I'm doubting this is the correct place for it)

editor1 = new CompilationUnitEditor();
addeditor(editor1, editorInput);
editor2 = new CompilationUnitEditor();
addeditor(editor2, editorInput);

ITextSelection
sel=(ITextSelection)editor1.getSelectionProvider().getSelect ion();

IDocument doc =
editor1.getDocumentProvider().getDocument(editor1.getEditorI nput());


try
{
int linenum = doc.getLineOfOffset(sel.getOffset());
System.out.println("line is : " + linenum);
}
catch(BadLocationException e){};


However the System.out.println is only called the once so all
it every prints out is line is : 0 Which is what I would
concider should happen when it's not placed in a listener.

Some help would be much appreciated.

Thanks,
A.
Re: Communication between editors [message #266233 is a reply to message #266219] Tue, 10 August 2004 09:20 Go to previous messageGo to next message
Eclipse UserFriend
Angela Heenan wrote:
> I placed the following code in the createPages() method of the
> MultiPageEditor. (I'm doubting this is the correct place for it)
>
> editor1 = new CompilationUnitEditor();
> addeditor(editor1, editorInput);
> editor2 = new CompilationUnitEditor();
> addeditor(editor2, editorInput);
>
> ITextSelection
> sel=(ITextSelection)editor1.getSelectionProvider().getSelect ion();
>
> IDocument doc =
> editor1.getDocumentProvider().getDocument(editor1.getEditorI nput());
>
>
> try
> {
> int linenum = doc.getLineOfOffset(sel.getOffset());
> System.out.println("line is : " + linenum);
> }
> catch(BadLocationException e){};
>
>
> However the System.out.println is only called the once so all
> it every prints out is line is : 0

Which makes sense, since you've just created the editors above, so they
probably don't have any content yet...

> Which is what I would
> concider should happen when it's not placed in a listener.

There is no listener involved with above code. All it does is find out
the current selection. To get informed about selection changes, you have
to register an ISelectionListener using the
SelectionProvider.addSelectionListener() method.

Note that you don't get all selection changes (e.g. when typing) with
this method. Instead you may want to look at the IPostSelectionProvider
interface that some selection providers implement. PostSelection events
are sent out after a small delay after the selection change.

-tom
Re: Communication between editors [message #266252 is a reply to message #266233] Tue, 10 August 2004 10:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aheenan.ie.ibm.com

Thanks Tom.

I have actually implemented what you say with the SelectionProvider.
addSelectionListener() but as you say it wasn't exactly what I needed.
Then I had a look at the IPostSelectionProvider and got a bit lost.

This is as far as I got with the PostSelectionProvider....

editor1.getSelectionProvider().addSelectionChangedListener(n ew
MySelectionChangedListener());

public class MySelectionChangedListener
implements IPostSelectionProvider
{
.....

public void selectionChanged(SelectionChangedEvent event)
{
ITextSelection sel= (ITextSelection)
editor1.getSelectionProvider().getSelection();
IDocument doc =
editor1.getDocumentProvider().getDocument(editor1.getEditorI nput());

try
{
int linenum = doc.getLineOfOffset(sel.getOffset());
System.out.println("line is : " + (linenum + 1));
}
catch(BadLocationException e){};
}

I know that the above is wrong and probably an awful, awful hack. Was
I close or so far away I can't even see it?

I'm currently reading FAQ 203 (How do I make a view respond to selection
changes in another view?)and adapting it to an editor. I hope to be able
to use the IPostSelectionProvider as in one of it's uses in the API it
lists the SourceViewer. Would this be another way to approach what I
want to do??

Many many thanks :-)
A.


>
> There is no listener involved with above code. All it does is find out
> the current selection. To get informed about selection changes, you have
> to register an ISelectionListener using the
> SelectionProvider.addSelectionListener() method.
>
> Note that you don't get all selection changes (e.g. when typing) with
> this method. Instead you may want to look at the IPostSelectionProvider
> interface that some selection providers implement. PostSelection events
> are sent out after a small delay after the selection change.
>
> -tom
Re: Communication between editors [message #266305 is a reply to message #266252] Tue, 10 August 2004 12:37 Go to previous message
Eclipse UserFriend
Angela,

the IPostSelectionProvider is not something you need to implement - it
is a provider similar to ISelectionProvider you can register a listener
with:

ISelectionProvider prov= editor1.getSelectionProvider();
if (prov instanceof IPostSelectionProvider) {
prov.addPostSelectionListener(new MySelectionChangedListener());
}

This will inform you about all selection changes after a certain delay
(so you don't get hundreds of events when the user presses and holds the
arrow keys, for example).

If you need instantanious information upon selection changes, you will
have to hack your way and listen for events (Key and Selection and
possibly others) on the underlying widget / viewer.

HTH, tom

Angela Heenan wrote:
> I have actually implemented what you say with the SelectionProvider.
> addSelectionListener() but as you say it wasn't exactly what I needed.
> Then I had a look at the IPostSelectionProvider and got a bit lost.
>
> This is as far as I got with the PostSelectionProvider....
>
> editor1.getSelectionProvider().addSelectionChangedListener(n ew
> MySelectionChangedListener());
>
> public class MySelectionChangedListener
> implements IPostSelectionProvider
> {
> .....
>
> public void selectionChanged(SelectionChangedEvent event)
> {
> ITextSelection sel= (ITextSelection)
> editor1.getSelectionProvider().getSelection();
> IDocument doc =
> editor1.getDocumentProvider().getDocument(editor1.getEditorI nput());
>
> try
> {
> int linenum = doc.getLineOfOffset(sel.getOffset());
> System.out.println("line is : " + (linenum + 1));
> }
> catch(BadLocationException e){};
> }
>
> I know that the above is wrong and probably an awful, awful hack. Was
> I close or so far away I can't even see it?
Previous Topic:Filtering of Problem Marker Type
Next Topic:Disable close button in viewpart
Goto Forum:
  


Current Time: Tue Jul 22 13:12:02 EDT 2025

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

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

Back to the top