com.intellij.ide.util.EditorHelper Java Examples
The following examples show how to use
com.intellij.ide.util.EditorHelper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractRefactoringPanel.java From IntelliJDeodorant with MIT License | 6 votes |
private static void highlightPsiElement(PsiElement psiElement, boolean openInEditor) { if (openInEditor) { EditorHelper.openInEditor(psiElement); } Editor editor = FileEditorManager.getInstance(psiElement.getProject()).getSelectedTextEditor(); if (editor == null) { return; } TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); editor.getMarkupModel().addRangeHighlighter( psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getEndOffset(), HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE ); }
Example #2
Source File: MoveMethodPanel.java From IntelliJDeodorant with MIT License | 6 votes |
private static void openDefinition(@Nullable PsiMember unit, AnalysisScope scope) { new Task.Backgroundable(scope.getProject(), "Search Definition") { private PsiElement result; @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); result = unit; } @Override public void onSuccess() { if (result != null) { EditorHelper.openInEditor(result); } } }.queue(); }
Example #3
Source File: MuleDomainMavenProjectBuilderHelper.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
public void configure(final Project project, final MavenId projectId, final String muleVersion, final VirtualFile root) { try { //Create mule folders. final VirtualFile appDirectory = VfsUtil.createDirectories(root.getPath() + "/src/main/domain"); final VirtualFile resources = VfsUtil.createDirectories(root.getPath() + "/src/main/resources"); final VirtualFile muleConfigFile = createMuleConfigFile(project, projectId, appDirectory); createMuleDeployPropertiesFile(project, projectId, appDirectory); createPomFile(project, projectId, muleVersion, root); // execute when current dialog is closed (e.g. Project Structure) MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> EditorHelper.openInEditor(getPsiFile(project, muleConfigFile))); } catch (IOException e) { e.printStackTrace(); } }
Example #4
Source File: CommanderPanel.java From consulo with Apache License 2.0 | 6 votes |
@Override public void selectElement(final PsiElement element) { final boolean isDirectory = element instanceof PsiDirectory; if (!isDirectory) { EditorHelper.openInEditor(element); } ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { myBuilder.selectElement(element, PsiUtilCore.getVirtualFile(element)); if (!isDirectory) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (myMoveFocus) { ToolWindowManager.getInstance(myProject).activateEditorComponent(); } } }); } } }, ModalityState.NON_MODAL); }
Example #5
Source File: FavoritesTreeViewPanel.java From consulo with Apache License 2.0 | 6 votes |
@Override public void selectElement(final PsiElement element) { if (element != null) { selectPsiElement(element, false); boolean requestFocus = true; final boolean isDirectory = element instanceof PsiDirectory; if (!isDirectory) { Editor editor = EditorHelper.openInEditor(element); if (editor != null) { ToolWindowManager.getInstance(myProject).activateEditorComponent(); requestFocus = false; } } if (requestFocus) { selectPsiElement(element, true); } } }
Example #6
Source File: CreateFromTemplateActionBase.java From consulo with Apache License 2.0 | 6 votes |
public static void startLiveTemplate(@Nonnull PsiFile file, @Nonnull Map<String, String> defaultValues) { Editor editor = EditorHelper.openInEditor(file); if (editor == null) return; TemplateImpl template = new TemplateImpl("", file.getText(), ""); template.setInline(true); int count = template.getSegmentsCount(); if (count == 0) return; Set<String> variables = new HashSet<>(); for (int i = 0; i < count; i++) { variables.add(template.getSegmentName(i)); } variables.removeAll(TemplateImpl.INTERNAL_VARS_SET); for (String variable : variables) { String defaultValue = defaultValues.getOrDefault(variable, variable); template.addVariable(variable, null, '"' + defaultValue + '"', true); } Project project = file.getProject(); WriteCommandAction.runWriteCommandAction(project, () -> editor.getDocument().setText(template.getTemplateText())); editor.getCaretModel().moveToOffset(0); // ensures caret at the start of the template TemplateManager.getInstance(project).startTemplate(editor, template); }
Example #7
Source File: ProjectViewImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void selectElement(PsiElement element) { selectPsiElement(element, false); boolean requestFocus = true; if (element != null) { final boolean isDirectory = element instanceof PsiDirectory; if (!isDirectory) { FileEditor editor = EditorHelper.openInEditor(element, false); if (editor != null) { ToolWindowManager.getInstance(myProject).activateEditorComponent(); requestFocus = false; } } } if (requestFocus) { selectPsiElement(element, true); } }
Example #8
Source File: ScopeTreeViewPanel.java From consulo with Apache License 2.0 | 6 votes |
@Override public void selectElement(final PsiElement element) { if (element != null) { final PackageSet packageSet = getCurrentScope().getValue(); final PsiFile psiFile = element.getContainingFile(); if (packageSet == null) return; final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() : (element instanceof PsiDirectory ? ((PsiDirectory)element).getVirtualFile() : null); if (virtualFile != null) { final ProjectView projectView = ProjectView.getInstance(myProject); final NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, CURRENT_SCOPE_NAME, myDependencyValidationManager); if (packageSet instanceof PackageSetBase && !((PackageSetBase)packageSet).contains(virtualFile, holder) || psiFile != null && !packageSet.contains(psiFile, holder)) { projectView.changeView(ProjectViewPane.ID); } projectView.select(element, virtualFile, false); } Editor editor = EditorHelper.openInEditor(element); if (editor != null) { ToolWindowManager.getInstance(myProject).activateEditorComponent(); } } }
Example #9
Source File: ExtractMethodPanel.java From IntelliJDeodorant with MIT License | 5 votes |
/** * Opens definition of method and highlights statements, which should be extracted. * * @param sourceMethod method from which code is proposed to be extracted into separate method. * @param scope scope of the current project. * @param slice computation slice. */ private static void openDefinition(@Nullable PsiMethod sourceMethod, AnalysisScope scope, ASTSlice slice) { new Task.Backgroundable(scope.getProject(), "Search Definition") { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); } @Override public void onSuccess() { if (sourceMethod != null) { Set<SmartPsiElementPointer<PsiElement>> statements = slice.getSliceStatements(); PsiStatement psiStatement = (PsiStatement) statements.iterator().next().getElement(); if (psiStatement != null && psiStatement.isValid()) { EditorHelper.openInEditor(psiStatement); Editor editor = FileEditorManager.getInstance(sourceMethod.getProject()).getSelectedTextEditor(); if (editor != null) { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); editor.getMarkupModel().removeAllHighlighters(); statements.stream() .filter(statement -> statement.getElement() != null) .forEach(statement -> editor.getMarkupModel().addRangeHighlighter(statement.getElement().getTextRange().getStartOffset(), statement.getElement().getTextRange().getEndOffset(), HighlighterLayer.SELECTION, attributes, HighlighterTargetArea.EXACT_RANGE)); } } } } }.queue(); }
Example #10
Source File: MuleMavenProjectBuilderHelper.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
public void configure(final Project project, final MavenId projectId, final String muleVersion, final VirtualFile root, @Nullable MavenId parentId) { try { //Create mule folders. final VirtualFile appDirectory = VfsUtil.createDirectories(root.getPath() + "/src/main/app"); final VirtualFile resources = VfsUtil.createDirectories(root.getPath() + "/src/main/resources"); createLog4J(project, projectId, resources); final VirtualFile muleConfigFile = createMuleConfigFile(project, projectId, appDirectory); createMuleDeployPropertiesFile(project, projectId, appDirectory); createMuleAppPropertiesFiles(project, appDirectory); VfsUtil.createDirectories(root.getPath() + "/src/main/api"); //MUnit support VfsUtil.createDirectories(root.getPath() + "/src/test/munit"); final VirtualFile testResources = VfsUtil.createDirectories(root.getPath() + "/src/test/resources"); createLog4JTest(project, projectId, testResources); if (parentId == null) createPomFile(project, projectId, muleVersion, root); else createModulePomFile(project, projectId, root, parentId); // execute when current dialog is closed (e.g. Project Structure) MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> EditorHelper.openInEditor(getPsiFile(project, muleConfigFile))); } catch (IOException e) { e.printStackTrace(); } }
Example #11
Source File: CopyFilesOrDirectoriesHandler.java From consulo with Apache License 2.0 | 4 votes |
/** * @param newName can be not null only if elements.length == 1 */ @RequiredReadAction private static void copyImpl(@Nonnull final VirtualFile[] files, @Nullable final String newName, @Nonnull final PsiDirectory targetDirectory, final boolean doClone, final boolean openInEditor) { if (doClone && files.length != 1) { throw new IllegalArgumentException("invalid number of elements to clone:" + files.length); } if (newName != null && files.length != 1) { throw new IllegalArgumentException("no new name should be set; number of elements is: " + files.length); } final Project project = targetDirectory.getProject(); if (!CommonRefactoringUtil.checkReadOnlyStatus(project, Collections.singleton(targetDirectory), false)) { return; } String title = RefactoringBundle.message(doClone ? "copy,handler.clone.files.directories" : "copy.handler.copy.files.directories"); try { PsiFile firstFile = null; final int[] choice = files.length > 1 || files[0].isDirectory() ? new int[]{-1} : null; PsiManager manager = PsiManager.getInstance(project); for (VirtualFile file : files) { PsiElement psiElement = file.isDirectory() ? manager.findDirectory(file) : manager.findFile(file); if (psiElement == null) { LOG.info("invalid file: " + file.getExtension()); continue; } PsiFile f = copyToDirectory((PsiFileSystemItem)psiElement, newName, targetDirectory, choice, title); if (firstFile == null) { firstFile = f; } } if (firstFile != null && openInEditor) { CopyHandler.updateSelectionInActiveProjectView(firstFile, project, doClone); if (!(firstFile instanceof PsiBinaryFile)) { EditorHelper.openInEditor(firstFile); ToolWindowManager.getInstance(project).activateEditorComponent(); } } } catch (final IncorrectOperationException | IOException ex) { Messages.showErrorDialog(project, ex.getMessage(), RefactoringBundle.message("error.title")); } }