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);
}
}
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());
}
Aggregations