com.intellij.openapi.fileEditor.TextEditor Java Examples
The following examples show how to use
com.intellij.openapi.fileEditor.TextEditor.
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: FlutterWidgetPerf.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void showFor(Set<TextEditor> editors) { AsyncUtils.invokeAndWait(() -> { currentEditors.clear(); currentEditors.addAll(editors); // Harvest old editors. harvestInvalidEditors(editors); for (TextEditor fileEditor : currentEditors) { // Create a new EditorPerfModel if necessary. if (!editorDecorations.containsKey(fileEditor)) { editorDecorations.put(fileEditor, perfModelFactory.create(fileEditor)); } } requestRepaint(When.now); }); }
Example #2
Source File: FileUtilsTest.java From lsp4intellij with Apache License 2.0 | 6 votes |
@PrepareForTest(FileEditorManager.class) @Test public void testEditorFromVirtualFile() { VirtualFile file = PowerMockito.mock(VirtualFile.class); Project project = PowerMockito.mock(Project.class); Editor editor = PowerMockito.mock(Editor.class); TextEditor textEditor = PowerMockito.mock(TextEditor.class); PowerMockito.when(textEditor.getEditor()).thenReturn(editor); FileEditorManagerEx fileEditorManagerEx = PowerMockito.mock(FileEditorManagerEx.class); PowerMockito.mockStatic(FileEditorManager.class); PowerMockito.when(fileEditorManagerEx.getAllEditors(file)) .thenReturn(new FileEditor[]{textEditor}) .thenReturn(new FileEditor[0]); PowerMockito.when(FileEditorManager.getInstance(project)).thenReturn(fileEditorManagerEx); Assert.assertEquals(editor, FileUtils.editorFromVirtualFile(file, project)); Assert.assertNull(FileUtils.editorFromVirtualFile(file, project)); }
Example #3
Source File: InferredTypesService.java From reasonml-idea-plugin with MIT License | 6 votes |
public static void annotatePsiFile(@NotNull Project project, @NotNull Language lang, @Nullable VirtualFile sourceFile, @Nullable InferredTypes types) { if (types == null || sourceFile == null) { return; } if (FileHelper.isInterface(sourceFile.getFileType())) { return; } LOG.debug("Updating signatures in user data cache for file", sourceFile); TextEditor selectedEditor = (TextEditor) FileEditorManager.getInstance(project).getSelectedEditor(sourceFile); if (selectedEditor != null) { CodeLensView.CodeLensInfo userData = getCodeLensData(project); userData.putAll(sourceFile, types.signaturesByLines(lang)); } PsiFile psiFile = PsiManager.getInstance(project).findFile(sourceFile); if (psiFile != null && !FileHelper.isInterface(psiFile.getFileType())) { String[] lines = psiFile.getText().split("\n"); psiFile.putUserData(SignatureProvider.SIGNATURE_CONTEXT, new SignatureProvider.InferredTypesWithLines(types, lines)); } }
Example #4
Source File: ORFileEditorListener.java From reasonml-idea-plugin with MIT License | 6 votes |
@Override public void documentChanged(@NotNull DocumentEvent event) { Document document = event.getDocument(); // When document lines count change, we move the type annotations int newLineCount = document.getLineCount(); if (newLineCount != m_oldLinesCount) { CodeLensView.CodeLensInfo userData = m_project.getUserData(CodeLensView.CODE_LENS); if (userData != null) { VirtualFile file = FileDocumentManager.getInstance().getFile(document); if (file != null) { FileEditor selectedEditor = FileEditorManager.getInstance(m_project).getSelectedEditor(file); if (selectedEditor instanceof TextEditor) { TextEditor editor = (TextEditor) selectedEditor; LogicalPosition cursorPosition = editor.getEditor().offsetToLogicalPosition(event.getOffset()); int direction = newLineCount - m_oldLinesCount; userData.move(file, cursorPosition, direction); } } } } m_queue.queue(m_project, document); }
Example #5
Source File: WidgetPerfTable.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
void sortByMetric(ArrayList<SlidingWindowStatsSummary> entries) { openPaths.clear(); for (TextEditor editor : perfManager.getSelectedEditors()) { final VirtualFile file = editor.getFile(); if (file != null) { openPaths.add(file.getPath()); } } if (entries != null) { entries.sort((a, b) -> { final int comparison = Integer.compare(b.getValue(metric), a.getValue(metric)); if (comparison != 0) { return comparison; } return Boolean.compare(isOpenLocation(b.getLocation()), isOpenLocation(a.getLocation())); }); } }
Example #6
Source File: BasicFormatFilter.java From CppTools with Apache License 2.0 | 6 votes |
private static HyperlinkInfo createHyperLink(final VirtualFile child1, final int lineNumber, final int columnNumber) { return new HyperlinkInfo() { public void navigate(Project project) { new OpenFileDescriptor(project, child1).navigate(lineNumber == 0); if (lineNumber != 0) { final FileEditor[] fileEditors = FileEditorManager.getInstance(project).getEditors(child1); Editor editor = null; for(FileEditor fe:fileEditors) { if (fe instanceof TextEditor) { editor = ((TextEditor)fe).getEditor(); break; } } if (editor != null) { int offset = editor.getDocument().getLineStartOffset(lineNumber - 1) + (columnNumber != 0?columnNumber - 1:0); new OpenFileDescriptor(project, child1,offset).navigate(true); } } } }; }
Example #7
Source File: EmacsIdeasAction.java From emacsIDEAs with Apache License 2.0 | 6 votes |
private ArrayList<Editor> collect_active_editors(AnActionEvent e) { ArrayList<Editor> editors = new ArrayList<Editor>(); final Project project = e.getData(CommonDataKeys.PROJECT); final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project); FileEditor[] selectedEditors = fileEditorManager.getSelectedEditors(); for (FileEditor selectedEditor : selectedEditors) { if (selectedEditor instanceof TextEditor) { Editor editor = ((TextEditor) selectedEditor).getEditor(); editors.add(editor); } } return editors; }
Example #8
Source File: BreadcrumbsInitializingActivity.java From consulo with Apache License 2.0 | 6 votes |
private static void reinitBreadcrumbsComponent(@Nonnull final FileEditorManager fileEditorManager, @Nonnull VirtualFile file) { boolean above = EditorSettingsExternalizable.getInstance().isBreadcrumbsAbove(); for (FileEditor fileEditor : fileEditorManager.getAllEditors(file)) { if (fileEditor instanceof TextEditor) { TextEditor textEditor = (TextEditor)fileEditor; Editor editor = textEditor.getEditor(); BreadcrumbsWrapper wrapper = BreadcrumbsWrapper.getBreadcrumbsComponent(editor); if (isSuitable(textEditor, file)) { if (wrapper != null) { if (wrapper.breadcrumbs.above != above) { remove(fileEditorManager, fileEditor, wrapper); wrapper.breadcrumbs.above = above; add(fileEditorManager, fileEditor, wrapper); } wrapper.queueUpdate(); } else { registerWrapper(fileEditorManager, fileEditor, new BreadcrumbsWrapper(editor)); } } else if (wrapper != null) { disposeWrapper(fileEditorManager, fileEditor, wrapper); } } } }
Example #9
Source File: WrapEditorAction.java From idea-latex with MIT License | 6 votes |
/** * Unwraps selection. * * @param editor Current editor. * @param matched Matched PSI element. */ private void unwrap(@NotNull final TextEditor editor, @NotNull final PsiElement matched) { final Document document = editor.getEditor().getDocument(); final SelectionModel selectionModel = editor.getEditor().getSelectionModel(); final CaretModel caretModel = editor.getEditor().getCaretModel(); final int start = matched.getTextRange().getStartOffset(); final int end = matched.getTextRange().getEndOffset(); final String text = StringUtil.notNullize(matched.getText()); String newText = StringUtil.trimEnd(StringUtil.trimStart(text, getLeftText()), getRightText()); int newStart = selectionModel.getSelectionStart() - getLeftText().length(); int newEnd = selectionModel.getSelectionEnd() - getLeftText().length(); document.replaceString(start, end, newText); selectionModel.setSelection(newStart, newEnd); caretModel.moveToOffset(newEnd); }
Example #10
Source File: FlutterWidgetPerf.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void showFor(Set<TextEditor> editors) { AsyncUtils.invokeAndWait(() -> { currentEditors.clear(); currentEditors.addAll(editors); // Harvest old editors. harvestInvalidEditors(editors); for (TextEditor fileEditor : currentEditors) { // Create a new EditorPerfModel if necessary. if (!editorDecorations.containsKey(fileEditor)) { editorDecorations.put(fileEditor, perfModelFactory.create(fileEditor)); } } requestRepaint(When.now); }); }
Example #11
Source File: CreateFileFix.java From consulo with Apache License 2.0 | 6 votes |
protected void openFile(@Nonnull Project project, PsiDirectory directory, PsiFile newFile, String text) { final FileEditorManager editorManager = FileEditorManager.getInstance(directory.getProject()); final FileEditor[] fileEditors = editorManager.openFile(newFile.getVirtualFile(), true); if (text != null) { for (FileEditor fileEditor : fileEditors) { if (fileEditor instanceof TextEditor) { // JSP is not safe to edit via Psi final Document document = ((TextEditor)fileEditor).getEditor().getDocument(); document.setText(text); if (ApplicationManager.getApplication().isUnitTestMode()) { FileDocumentManager.getInstance().saveDocument(document); } PsiDocumentManager.getInstance(project).commitDocument(document); break; } } } }
Example #12
Source File: XDebuggerInlayUtil.java From consulo with Apache License 2.0 | 6 votes |
public static void clearInlays(@Nonnull Project project) { UIUtil.invokeLaterIfNeeded(() -> { FileEditor[] editors = FileEditorManager.getInstance(project).getAllEditors(); for (FileEditor editor : editors) { if (editor instanceof TextEditor) { Editor e = ((TextEditor)editor).getEditor(); List<Inlay> existing = e.getInlayModel().getInlineElementsInRange(0, e.getDocument().getTextLength()); for (Inlay inlay : existing) { if (inlay.getRenderer() instanceof MyRenderer) { Disposer.dispose(inlay); } } } } }); }
Example #13
Source File: ShowImplementationsAction.java From consulo with Apache License 2.0 | 6 votes |
protected static Editor getEditor(@Nonnull DataContext dataContext) { Editor editor = dataContext.getData(CommonDataKeys.EDITOR); if (editor == null) { final PsiFile file = dataContext.getData(CommonDataKeys.PSI_FILE); if (file != null) { final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile != null) { final FileEditor fileEditor = FileEditorManager.getInstance(file.getProject()).getSelectedEditor(virtualFile); if (fileEditor instanceof TextEditor) { editor = ((TextEditor)fileEditor).getEditor(); } } } } return editor; }
Example #14
Source File: FindManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
private boolean findNextUsageInFile(@Nonnull FileEditor fileEditor, @Nonnull SearchResults.Direction direction) { if (fileEditor instanceof TextEditor) { TextEditor textEditor = (TextEditor)fileEditor; Editor editor = textEditor.getEditor(); editor.getCaretModel().removeSecondaryCarets(); if (tryToFindNextUsageViaEditorSearchComponent(editor, direction)) { return true; } RangeHighlighter[] highlighters = ((HighlightManagerImpl)HighlightManager.getInstance(myProject)).getHighlighters(editor); if (highlighters.length > 0) { return highlightNextHighlighter(highlighters, editor, editor.getCaretModel().getOffset(), direction == SearchResults.Direction.DOWN, false); } } if (direction == SearchResults.Direction.DOWN) { return myFindUsagesManager.findNextUsageInFile(fileEditor); } return myFindUsagesManager.findPreviousUsageInFile(fileEditor); }
Example #15
Source File: WidgetPerfTable.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
void sortByMetric(ArrayList<SlidingWindowStatsSummary> entries) { openPaths.clear(); for (TextEditor editor : perfManager.getSelectedEditors()) { final VirtualFile file = editor.getFile(); if (file != null) { openPaths.add(file.getPath()); } } if (entries != null) { entries.sort((a, b) -> { final int comparison = Integer.compare(b.getValue(metric), a.getValue(metric)); if (comparison != 0) { return comparison; } return Boolean.compare(isOpenLocation(b.getLocation()), isOpenLocation(a.getLocation())); }); } }
Example #16
Source File: EditorNotificationActions.java From consulo with Apache License 2.0 | 6 votes |
@Override public void collectActions(@Nonnull Editor hostEditor, @Nonnull PsiFile hostFile, @Nonnull ShowIntentionsPass.IntentionsInfo intentions, int passIdToShowIntentionsFor, int offset) { Project project = hostEditor.getProject(); if (project == null) return; FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); if (!(fileEditorManager instanceof FileEditorManagerImpl)) return; TextEditor fileEditor = TextEditorProvider.getInstance().getTextEditor(hostEditor); List<JComponent> components = ((FileEditorManagerImpl)fileEditorManager).getTopComponents(fileEditor); for (JComponent component : components) { if (component instanceof IntentionActionProvider) { IntentionActionWithOptions action = ((IntentionActionProvider)component).getIntentionAction(); if (action != null) { intentions.notificationActionsToShow.add(new HighlightInfo.IntentionActionDescriptor(action, action.getOptions(), null)); } } } }
Example #17
Source File: ViewStructureAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(@Nonnull AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) return; FileEditor fileEditor = e.getData(PlatformDataKeys.FILE_EDITOR); if (fileEditor == null) return; VirtualFile virtualFile = fileEditor.getFile(); Editor editor = fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : e.getData(CommonDataKeys.EDITOR); if (editor != null) { PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file.structure"); FileStructurePopup popup = createPopup(project, fileEditor); if (popup == null) return; String title = virtualFile == null ? fileEditor.getName() : virtualFile.getName(); popup.setTitle(title); popup.show(); }
Example #18
Source File: FileUtils.java From lsp4intellij with Apache License 2.0 | 6 votes |
public static List<Editor> getAllOpenedEditors(Project project) { return computableReadAction(() -> { List<Editor> editors = new ArrayList<>(); FileEditor[] allEditors = FileEditorManager.getInstance(project).getAllEditors(); for (FileEditor fEditor : allEditors) { if (fEditor instanceof TextEditor) { Editor editor = ((TextEditor) fEditor).getEditor(); if (editor.isDisposed() || !isEditorSupported(editor)) { continue; } editors.add(editor); } } return editors; }); }
Example #19
Source File: FindManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void findUsagesInEditor(@Nonnull PsiElement element, @Nonnull FileEditor fileEditor) { if (fileEditor instanceof TextEditor) { TextEditor textEditor = (TextEditor)fileEditor; Editor editor = textEditor.getEditor(); Document document = editor.getDocument(); PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document); myFindUsagesManager.findUsages(element, psiFile, fileEditor, false, null); } }
Example #20
Source File: SearchBackAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(AnActionEvent event){ Presentation presentation = event.getPresentation(); Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { presentation.setEnabled(false); return; } final FileEditor editor = event.getData(PlatformDataKeys.FILE_EDITOR); presentation.setEnabled(editor instanceof TextEditor); }
Example #21
Source File: EditorAction.java From idea-latex with MIT License | 5 votes |
/** * Action handler. * * @param event Carries information on the invocation place */ @Override final public void actionPerformed(AnActionEvent event) { final VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE); final Project project = event.getData(CommonDataKeys.PROJECT); final TextEditor editor = getEditor(event); if (virtualFile == null || project == null || editor == null) { return; } actionPerformed(event, project, virtualFile, editor); }
Example #22
Source File: CodeGeneratorController.java From android-codegenerator-plugin-intellij with Apache License 2.0 | 5 votes |
private Editor getEditor(Project project, Editor editor, VirtualFile file) { if (editor == null) { TextEditor textEditor = getTextEditor(project, file); if (textEditor != null) { return textEditor.getEditor(); } } return editor; }
Example #23
Source File: NavigationUtil.java From consulo with Apache License 2.0 | 5 votes |
private static boolean activatePsiElementIfOpen(@Nonnull PsiElement elt, boolean searchForOpen, boolean requestFocus) { if (!elt.isValid()) return false; elt = elt.getNavigationElement(); final PsiFile file = elt.getContainingFile(); if (file == null || !file.isValid()) return false; VirtualFile vFile = file.getVirtualFile(); if (vFile == null) return false; if (!EditorHistoryManager.getInstance(elt.getProject()).hasBeenOpen(vFile)) return false; final FileEditorManager fem = FileEditorManager.getInstance(elt.getProject()); if (!fem.isFileOpen(vFile)) { fem.openFile(vFile, requestFocus, searchForOpen); } final TextRange range = elt.getTextRange(); if (range == null) return false; final FileEditor[] editors = fem.getEditors(vFile); for (FileEditor editor : editors) { if (editor instanceof TextEditor) { final Editor text = ((TextEditor)editor).getEditor(); final int offset = text.getCaretModel().getOffset(); if (range.containsOffset(offset)) { // select the file fem.openFile(vFile, requestFocus, searchForOpen); return true; } } } return false; }
Example #24
Source File: GraphQLSchemaEndpointsListNode.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Override public void handleDoubleClickOrEnter(SimpleTree tree, InputEvent inputEvent) { final String introspect = "Get GraphQL Schema from Endpoint (introspection)"; final String createScratch = "New GraphQL Scratch File (for query, mutation testing)"; ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<String>("Choose Endpoint Action", introspect, createScratch) { @Override public PopupStep onChosen(String selectedValue, boolean finalChoice) { return doFinalStep(() -> { if (introspect.equals(selectedValue)) { GraphQLIntrospectionHelper.getService(myProject).performIntrospectionQueryAndUpdateSchemaPathFile(myProject, endpoint); } else if (createScratch.equals(selectedValue)) { final String configBaseDir = endpoint.configPackageSet.getConfigBaseDir().getPresentableUrl(); final String text = "# " + GRAPHQLCONFIG_COMMENT + configBaseDir + "!" + Optional.ofNullable(projectKey).orElse("") + "\n\nquery ScratchQuery {\n\n}"; final VirtualFile scratchFile = ScratchRootType.getInstance().createScratchFile(myProject, "scratch.graphql", GraphQLLanguage.INSTANCE, text); if (scratchFile != null) { FileEditor[] fileEditors = FileEditorManager.getInstance(myProject).openFile(scratchFile, true); for (FileEditor editor : fileEditors) { if (editor instanceof TextEditor) { final JSGraphQLEndpointsModel endpointsModel = ((TextEditor) editor).getEditor().getUserData(JS_GRAPH_QL_ENDPOINTS_MODEL); if (endpointsModel != null) { endpointsModel.setSelectedItem(endpoint); } } } } } }); } }); if (inputEvent instanceof KeyEvent) { listPopup.showInFocusCenter(); } else if (inputEvent instanceof MouseEvent) { listPopup.show(new RelativePoint((MouseEvent) inputEvent)); } }
Example #25
Source File: FlutterSampleNotificationProvider.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable @Override public EditorNotificationPanel createNotificationPanel( @NotNull VirtualFile file, @NotNull FileEditor fileEditor, @NotNull Project project) { if (!(fileEditor instanceof TextEditor)) { return null; } final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project); if (sdk == null) { return null; } final String flutterPackagePath = sdk.getHomePath() + "/packages/flutter/lib/src/"; final String filePath = file.getPath(); // Only show for files in the flutter sdk. if (!filePath.startsWith(flutterPackagePath)) { return null; } final TextEditor textEditor = (TextEditor)fileEditor; final Editor editor = textEditor.getEditor(); final Document document = editor.getDocument(); final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); if (psiFile == null || !psiFile.isValid()) { return null; } // Run the code to query the document in a read action. final List<FlutterSample> samples = ApplicationManager.getApplication(). runReadAction((Computable<List<FlutterSample>>)() -> { //noinspection CodeBlock2Expr return getSamplesFromDoc(flutterPackagePath, document, filePath); }); return samples.isEmpty() ? null : new FlutterSampleActionsPanel(samples); }
Example #26
Source File: FindUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void searchBack(Project project, FileEditor fileEditor, @Nullable DataContext dataContext) { if (!(fileEditor instanceof TextEditor)) return; TextEditor textEditor = (TextEditor)fileEditor; Editor editor = textEditor.getEditor(); searchBack(project, editor, dataContext); }
Example #27
Source File: UndoRedoAction.java From consulo with Apache License 2.0 | 5 votes |
private static Project getProject(FileEditor editor, DataContext dataContext) { Project project; if (editor instanceof TextEditor) { project = ((TextEditor)editor).getEditor().getProject(); } else { project = dataContext.getData(CommonDataKeys.PROJECT); } return project; }
Example #28
Source File: FlutterWidgetPerf.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void harvestInvalidEditors(Set<TextEditor> newEditors) { final Iterator<TextEditor> editors = editorDecorations.keySet().iterator(); while (editors.hasNext()) { final TextEditor editor = editors.next(); if (!editor.isValid() || (newEditors != null && !newEditors.contains(editor))) { final EditorPerfModel editorPerfDecorations = editorDecorations.get(editor); editors.remove(); Disposer.dispose(editorPerfDecorations); } } }
Example #29
Source File: ProjectAPI.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Returns whether there is an open text editor for the given file. * * @param project the project in which to check * @param file the file to check * @return whether there is an open text editor for the given file */ public static boolean isOpenInTextEditor(@NotNull Project project, @NotNull VirtualFile file) { FileEditorManager fileEditorManager = getFileEditorManager(project); FileEditor[] fileEditors = EDTExecutor.invokeAndWait(() -> fileEditorManager.getEditors(file)); for (FileEditor fileEditor : fileEditors) { if (fileEditor instanceof TextEditor) { return true; } } return false; }
Example #30
Source File: XVariablesViewBase.java From consulo with Apache License 2.0 | 5 votes |
private void registerInlineEvaluator(final XStackFrame stackFrame, final XSourcePosition position, final Project project) { final VirtualFile file = position.getFile(); final FileEditor fileEditor = FileEditorManagerEx.getInstanceEx(project).getSelectedEditor(file); if (fileEditor instanceof TextEditor) { final Editor editor = ((TextEditor)fileEditor).getEditor(); removeSelectionListener(); mySelectionListener = new MySelectionListener(editor, stackFrame, project); editor.getSelectionModel().addSelectionListener(mySelectionListener); } }