开发者

(Eclipse RCP) How can I get the reference of Editor in command handler

开发者 https://www.devze.com 2022-12-17 21:59 出处:网络
I\'d like the get the text of 开发者_开发问答editor in a command handler, so how can I get the reference of Editor, thanksto get the referece of the editor in a command handler you could do this:

I'd like the get the text of 开发者_开发问答editor in a command handler, so how can I get the reference of Editor, thanks


to get the referece of the editor in a command handler you could 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


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

Then you type cast so combining with above answer now execute and enabling both shall work.

0

精彩评论

暂无评论...
验证码 换一张
取 消