Search in sources :

Example 1 with GroovyConsole

use of org.jetbrains.plugins.groovy.console.GroovyConsole in project intellij-community by JetBrains.

the class GrExecuteCommandAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
    final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    if (project == null || editor == null || virtualFile == null)
        return;
    FileDocumentManager.getInstance().saveAllDocuments();
    final Document document = editor.getDocument();
    final TextRange selectedRange = EditorUtil.getSelectionInAnyMode(editor);
    final String command = (selectedRange.isEmpty() ? document.getText() : document.getText(selectedRange));
    final GroovyConsole existingConsole = virtualFile.getUserData(GroovyConsole.GROOVY_CONSOLE);
    if (existingConsole == null) {
        GroovyConsole.getOrCreateConsole(project, virtualFile, console -> console.execute(command));
    } else {
        existingConsole.execute(command);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GroovyConsole(org.jetbrains.plugins.groovy.console.GroovyConsole) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document)

Example 2 with GroovyConsole

use of org.jetbrains.plugins.groovy.console.GroovyConsole in project intellij-community by JetBrains.

the class GrSelectModuleAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null)
        return;
    GroovyConsoleUtil.selectModuleAndRun(project, module -> {
        final Module existingModule = myProjectConsole.getSelectedModule(myFile);
        if (module.equals(existingModule))
            return;
        final GroovyConsole existingConsole = myFile.getUserData(GroovyConsole.GROOVY_CONSOLE);
        if (existingConsole != null)
            existingConsole.stop();
        myProjectConsole.setFileModule(myFile, module);
        myFile.putUserData(GroovyConsole.GROOVY_CONSOLE, null);
        ProjectView.getInstance(project).refresh();
    }, e.getDataContext());
}
Also used : Project(com.intellij.openapi.project.Project) GroovyConsole(org.jetbrains.plugins.groovy.console.GroovyConsole) Module(com.intellij.openapi.module.Module)

Aggregations

Project (com.intellij.openapi.project.Project)2 GroovyConsole (org.jetbrains.plugins.groovy.console.GroovyConsole)2 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 Module (com.intellij.openapi.module.Module)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1