Package javarepl.plugin

Source Code of javarepl.plugin.JavaREPLExecuteActionBase

package javarepl.plugin;

import com.intellij.codeInsight.completion.CompletionProcess;
import com.intellij.codeInsight.completion.CompletionService;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.EmptyAction;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.util.IconLoader;

public abstract class JavaREPLExecuteActionBase extends DumbAwareAction {
    public static final String ACTIONS_EXECUTE_ICON = "/actions/execute.png";

    protected final JavaREPLLanguageConsole languageConsole;
    protected final ProcessHandler myProcessHandler;

    public JavaREPLExecuteActionBase(JavaREPLLanguageConsole languageConsole,
                                     ProcessHandler processHandler,
                                     String actionId) {
        super(null, null, IconLoader.getIcon(ACTIONS_EXECUTE_ICON));
        this.languageConsole = languageConsole;
        this.myProcessHandler = processHandler;
        EmptyAction.setupAction(this, actionId, null);
    }

    public void update(final AnActionEvent e) {
        e.getPresentation().setEnabled(isActionEnabled());
    }

    private boolean isActionEnabled() {
        if (myProcessHandler.isProcessTerminated()) {
            return false;
        }

        final Lookup lookup = LookupManager.getActiveLookup(languageConsole.getConsoleEditor());
        if (lookup == null || !lookup.isCompletion()) {
            return true;
        }

        CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
        if (completion != null && completion.isAutopopupCompletion() && !lookup.isSelectionTouched()) {
            return true;
        }
        return false;
    }

}
TOP

Related Classes of javarepl.plugin.JavaREPLExecuteActionBase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.