[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: How can I get notified when CTRL+click (open declaration) is executed?

Hi Dani,

I added a part listener so that I can find out when the editor was opened/activated. However, I don't know how to look in the stack to see the event that triggers it. Can you please tell me the class name of the stack/listener?

Here is my part listener code:

IWorkbenchPage page=window.getActivePage();
page.addPartListener(new IPartListener()
{
//...other methods partOpened, partDeactivated, partClosed, partBroughtToTop
public void partActivated(IWorkbenchPart part)
{
if (part instanceof EditorPart)
{
//a new file was activated in the editor

//How can I look at the stack to see what triggered?
}
}
});


Thank you,
Bogdan

Daniel Megert wrote:

Bogdan Dit wrote:
Hi Dani,

I am conducting a study that analyzes how people open files in Eclipse. I just want to be notified when the user is opening a declaration (using CTRL+click) so that I can capture this interaction in a log file. I already know how to capture the interaction when the user opens a declaration using F3 or the menu "Navigate->Open Declaration".
There's no hook to detect that the hyperlink got clicked. You could add a part listener and then look in the stack what triggered it.

Dani
Thank you
Bogdan

Daniel Megert wrote:

Bogdan wrote:
Hello,

I am writing a plug-in (using Eclipse 3.4) and I want to be notified if a user opens a file using CTRL+click (open declaration) in a Java source code file.
What exactly do you want to achieve?

Dani

So far, I added a IExecutionListener to a ICommandService for the current workbench window:


IWorkbenchWindow window = PlatformUI.getWorkbench().getWorkbenchWindows()[0];

ICommandService service = (ICommandService) window.getService(ICommandService.class);
service.addExecutionListener(new IExecutionListener() {


//ᅵ other methods (notHandled, postExecuteFailure, postExecuteSuccess)

public void preExecute(String commandId, ExecutionEvent event) {
//check for "open declaration" events
}
});

This code works fine (I triggers an ᅵopen declarationᅵ event which I catch it inside the preExecute function) but ONLY in the following TWO cases: 1) if I press F3 (Open declaration) or 2) Go to menu ᅵNavigate->Open Declaration F3ᅵ. However, when I use CTRL+click (which the documentation says should do the same thing (open declaration)), that event does not trigger my preExecute function.

I also added an IPartListener to the active Workbench page to notify me when a new file is being opened. This notifies me when a new file was opened, but it does not tell me the source of the event (whether it was CTRL+click, a file opened from the Package Explorer, a file opened from Tabs, etc.)

IWorkbenchPage page=window.getActivePage();
page.addPartListener(new IPartListener()
{
//...other methods partOpened, partDeactivated, partClosed, partBroughtToTop
public void partActivated(IWorkbenchPart arg0)
{
// notifies if a file was opened
//does not provide the source of the event (CTRL+click, package explorer, opened files in tabs)


}
});

I was wondering if there is any other mechanism (listener) that could notify me when the user presses CTRL+click, such as a listener for actions, a source for where the action was generated or triggered, or anything else. I searched for hyperlinks, editor listener, mouse hover, etc., but nothing worked.

I would really appreciate any information that could help me solve this.

Thank you