@Nullable Editor selectEditor(Project project, @NotNull VirtualFile file) { FileEditorManager fMgr = FileEditorManager.getInstance(project); FileEditor[] feditors = fMgr.openFile(file, true); if (feditors.length > 0) { if (feditors[0] instanceof TextEditor) { return ((TextEditor)feditors[0]).getEditor(); } } return null; }
public void testCsvEditorStateReadsAndWritesStates() { TextEditor textEditor = getCurrentTextEditor(); FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(myFixture.getProject(), myFixture.getFile().getVirtualFile()); CsvFileEditorProvider fileEditorProvider = (CsvFileEditorProvider)fileEditorProviders[0]; Element dummy = new Element("dummy"); FileEditorState state = fileEditorProvider.readState(dummy, this.getProject(), this.getFile().getVirtualFile()); assertInstanceOf(state, TextEditorState.class); textEditor.setState(state); fileEditorProvider.writeState(state, this.getProject(), dummy); disposeTextEditor(textEditor); }
public void selectionChanged(@NotNull FileEditorManagerEvent event) { if (ExEntryPanel.getInstance().isActive()) { ExEntryPanel.getInstance().deactivate(false); } final FileEditor fileEditor = event.getOldEditor(); if (fileEditor instanceof TextEditor) { final Editor editor = ((TextEditor) fileEditor).getEditor(); ExOutputModel.getInstance(editor).clear(); if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) { VimPlugin.getMotion().exitVisual(editor); } } } }
/** * Scroll to the error specified by the given tree path, or do nothing * if no error is specified. * * @param treePath the tree path to scroll to. */ private void scrollToError(final TreePath treePath) { final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); if (treeNode == null || !(treeNode.getUserObject() instanceof ResultTreeNode)) { return; } final ResultTreeNode nodeInfo = (ResultTreeNode) treeNode.getUserObject(); if (nodeInfo.getFile() == null || nodeInfo.getProblem() == null) { return; // no problem here :-) } final VirtualFile virtualFile = nodeInfo.getFile().getVirtualFile(); if (virtualFile == null || !virtualFile.exists()) { return; } final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); final FileEditor[] editor = fileEditorManager.openFile( virtualFile, true); if (editor.length > 0 && editor[0] instanceof TextEditor) { final LogicalPosition problemPos = new LogicalPosition( Math.max(lineFor(nodeInfo) - 1, 0), Math.max(columnFor(nodeInfo), 0)); final Editor textEditor = ((TextEditor) editor[0]).getEditor(); textEditor.getCaretModel().moveToLogicalPosition(problemPos); textEditor.getScrollingModel().scrollToCaret(ScrollType.CENTER); } }
private static EditorEx getEditorEx(FileEditor fileEditor) { Editor editor = fileEditor instanceof TextEditor ? ((TextEditor) fileEditor).getEditor() : null; return editor instanceof EditorEx ? (EditorEx) editor : null; }
@NotNull public List<Editor> getGrammarEditors(@NotNull Project project) { VirtualFile file = getGrammarFile(); if (file == null) return Collections.emptyList(); FileEditor[] editors = FileEditorManager.getInstance(project).getAllEditors(file); if (editors.length == 0) return Collections.emptyList(); List<Editor> result = ContainerUtil.newArrayList(); for (FileEditor editor : editors) { if (editor instanceof TextEditor) result.add(((TextEditor)editor).getEditor()); } return result; }
@Nullable public static Editor getEditorIfSelected(Project project, PsiElement psiElement) { VirtualFile elementFile = getVirtualFile(project, psiElement); if (elementFile == null) { return null; } FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(elementFile); Editor editor = null; if (fileEditor != null && fileEditor instanceof TextEditor) { editor = ((TextEditor) fileEditor).getEditor(); } return editor; } }
@NotNull public List<Editor> getPreviewEditors(@NotNull Project project) { FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); VirtualFile[] files = fileEditorManager.getOpenFiles(); if (files.length == 0) return Collections.emptyList(); List<Editor> result = ContainerUtil.newArrayList(); PsiManager psiManager = PsiManager.getInstance(project); for (VirtualFile file : files) { PsiFile psiFile = psiManager.findFile(file); Language language = psiFile == null ? null : psiFile.getLanguage(); if (language == this) { for (FileEditor editor : fileEditorManager.getAllEditors(file)) { if (editor instanceof TextEditor) result.add(((TextEditor)editor).getEditor()); } } } return result; }
@Override protected StructureViewDescriptor createMainView( final FileEditor fileEditor, final PsiFile mainFile ) { final Editor editor = fileEditor instanceof TextEditor ? ((TextEditor) fileEditor).getEditor() : null; StructureViewModel model = new ImpexStructureViewModel(editor, psiFile); StructureView view = new ImpexStructureViewComponent(fileEditor, model, psiFile.getProject()); StructureViewDescriptor descriptor = new StructureViewDescriptor(psiFile.getName(), view, null); return descriptor; }
@Override public FileEditor build() { TextEditor textEditor = (TextEditor) TextEditorProvider.getInstance().createEditor(project, virtualFile); applySettings(textEditor.getEditor().getSettings(), CsvEditorSettingsExternalizable.getInstance()); return textEditor; } };
@Override public void applyFix(final @NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = descriptor.getPsiElement(); BnfRule rule = PsiTreeUtil.getParentOfType(element, BnfRule.class); if (rule == null) return; BnfRule addedRule = BnfIntroduceRuleHandler.addNextRule(project, rule, "private " + myName + " ::= "); FileEditor selectedEditor = FileEditorManager.getInstance(project).getSelectedEditor(rule.getContainingFile().getVirtualFile()); if (selectedEditor instanceof TextEditor) { final Editor editor = ((TextEditor)selectedEditor).getEditor(); editor.getCaretModel() .moveToOffset(addedRule.getTextRange().getEndOffset() - (BnfIntroduceRuleHandler.endsWithSemicolon(addedRule) ? 1 : 0)); editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); } } }
public void testCsvEditorSettingsAreApplied() { CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance(); csvEditorSettingsExternalizable.setCaretRowShown(false); csvEditorSettingsExternalizable.setUseSoftWraps(true); TextEditor textEditor = getCurrentTextEditor(); EditorSettings editorSettings = textEditor.getEditor().getSettings(); assertEquals(csvEditorSettingsExternalizable.isCaretRowShown(), editorSettings.isCaretRowShown()); assertEquals(csvEditorSettingsExternalizable.isUseSoftWraps(), editorSettings.isUseSoftWraps()); disposeTextEditor(textEditor); }
public void testCsvEditorIsTextEditorWithInitialCsvEditorSettings() { FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(myFixture.getProject(), myFixture.getFile().getVirtualFile()); FileEditor fileEditor = fileEditorProviders[0].createEditor(myFixture.getProject(), myFixture.getFile().getVirtualFile()); assertInstanceOf(fileEditor, TextEditor.class); TextEditor textEditor = (TextEditor)fileEditor; CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance(); EditorSettings editorSettings = textEditor.getEditor().getSettings(); assertEquals(csvEditorSettingsExternalizable.isCaretRowShown(), editorSettings.isCaretRowShown()); assertEquals(csvEditorSettingsExternalizable.isUseSoftWraps(), editorSettings.isUseSoftWraps()); disposeTextEditor(textEditor); }