use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class GroovyStatementMover method checkAvailable.
@Override
public boolean checkAvailable(@NotNull Editor editor, @NotNull PsiFile file, @NotNull MoveInfo info, boolean down) {
final Project project = file.getProject();
if (!HandlerUtils.canBeInvoked(editor, project) || !(file instanceof GroovyFileBase))
return false;
LineRange range = getLineRangeFromSelection(editor);
final Document document = editor.getDocument();
final int offset = document.getLineStartOffset(range.startLine);
final GrLiteral literal = PsiTreeUtil.findElementOfClassAtOffset(file, offset, GrLiteral.class, false);
//multiline string
if (literal != null && literal.textContains('\n'))
return false;
final GroovyPsiElement pivot = getElementToMove((GroovyFileBase) file, offset);
if (pivot == null)
return false;
final LineRange pivotRange = getLineRange(pivot);
range = new LineRange(Math.min(range.startLine, pivotRange.startLine), Math.max(range.endLine, pivotRange.endLine));
final GroovyPsiElement scope = PsiTreeUtil.getParentOfType(pivot, GrMethod.class, GrTypeDefinitionBody.class, GroovyFileBase.class);
final boolean stmtLevel = isStatement(pivot);
boolean topLevel = pivot instanceof GrTypeDefinition && pivot.getParent() instanceof GroovyFileBase;
final List<LineRange> allRanges = allRanges(scope, stmtLevel, topLevel);
LineRange prev = null;
LineRange next = null;
for (LineRange each : allRanges) {
if (each.endLine <= range.startLine) {
prev = each;
}
if (each.containsLine(range.startLine)) {
range = new LineRange(each.startLine, range.endLine);
}
if (each.startLine < range.endLine && each.endLine > range.endLine) {
range = new LineRange(range.startLine, each.endLine);
}
if (each.startLine >= range.endLine && next == null) {
next = each;
}
}
info.toMove = range;
info.toMove2 = down ? next : prev;
return true;
}
use of com.intellij.openapi.project.Project 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 com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class GrNewConsoleAction method getModule.
@Nullable
protected Module getModule(AnActionEvent e) {
final Project project = e.getProject();
if (project == null)
return null;
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
if (file != null) {
final Module moduleForFile = ModuleUtilCore.findModuleForFile(file, project);
if (moduleForFile != null)
return moduleForFile;
}
final List<Module> modules = ModuleChooserUtil.filterGroovyCompatibleModules(Arrays.asList(ModuleManager.getInstance(project).getModules()), APPLICABLE_MODULE);
return modules.isEmpty() ? null : modules.get(0);
}
use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.
the class GrNewConsoleAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
final Module module = getModule(e);
if (project == null || module == null)
return;
final VirtualFile contentFile = ConsoleHistoryController.getContentFile(GroovyConsoleRootType.getInstance(), GroovyConsoleRootType.CONTENT_ID, ScratchFileService.Option.create_new_always);
assert contentFile != null;
GroovyConsole.createConsole(project, contentFile, module);
FileEditorManager.getInstance(project).openFile(contentFile, true);
}
use of com.intellij.openapi.project.Project 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