Java Code Examples for com.intellij.ide.util.EditorHelper#openInEditor()
The following examples show how to use
com.intellij.ide.util.EditorHelper#openInEditor() .
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: 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 3
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 4
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 5
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 6
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 7
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")); } }