(Eclipse RCP) How to get editor link in command handler

I would like to get the editor text in the command handler, since I can get the editor link, thanks

+3
source share
2 answers

to get the editor referee in the command handler, you can do this:

public class myCommandHandler extends AbstractHandler implements IHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
        IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
        IEditorInput editorInput = page.getActiveEditor().getEditorInput();
...

Good luck.

+9
source
@Override
public void setEnabled(Object evaluationContext) {
    Object editor = ((EvaluationContext)evaluationContext).getParent().getVariable("activeEditor");

Then you type casting to combine with the above answer and perform both.

0
source

Source: https://habr.com/ru/post/1729423/


All Articles