0

I need to add a listener to one of my plugin views. I need the view to update when a mouse or key event occurs in the CEditor in Eclipse. I have done it by:

((StyledText)((AbstractTextEditor)activeEditor).getAdapter(Control.class)).addKeyListener(l);

But when I change to a different file in the editor the listeners do not work. Any ideas?

0

1 Answer 1

0

Solved: I scrapped the idea of key/mouse listeners and just added a SelectionListener to my Eclipse page. Then created a custom selectionListener that only responded when the selection was in the CEditor.

Made my view class implement ISelectionListener

getViewSite().getPage().addSelectionListener(this);

@Override 

public void selectionChanged(IWorkbenchPart part, ISelection selection) {

    if(part.getClass() == CEditor.class){

        //Do what I needed 
    } 
}

This made it so it only responded to selection changes in my CEditor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.