com.intellij.openapi.fileEditor.ex.FileEditorProviderManager Java Examples
The following examples show how to use
com.intellij.openapi.fileEditor.ex.FileEditorProviderManager.
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: CsvTableEditorProviderTest.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
public void testWriteAndReadTableEditorState() { FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(getProject(), myFixture.getFile().getVirtualFile()); FileEditorProvider fileEditorProvider = fileEditorProviders[1]; CsvTableEditorState editorState = new CsvTableEditorState(); editorState.setColumnWidths(new int[]{ 120, 32, 9}); editorState.setRowLines(5); editorState.setShowInfoPanel(false); Element element = new Element("state"); fileEditorProvider.writeState(editorState, getProject(), element); FileEditorState readState = fileEditorProvider.readState(element, getProject(), myFixture.getFile().getVirtualFile()); assertInstanceOf(readState, CsvTableEditorState.class); CsvTableEditorState editorStateRead = (CsvTableEditorState)readState; assertTrue(Objects.deepEquals(editorState.getColumnWidths(), editorStateRead.getColumnWidths())); assertEquals(editorState.getRowLines(), editorStateRead.getRowLines()); assertEquals(editorState.showInfoPanel(), editorStateRead.showInfoPanel()); }
Example #2
Source File: CsvFileEditorTest.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
public void testCsvFileEditorProviderIsAvailableAndHasCorrectNameAndPolicy() { FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(myFixture.getProject(), myFixture.getFile().getVirtualFile()); assertEquals(2, fileEditorProviders.length); assertInstanceOf(fileEditorProviders[0], CsvFileEditorProvider.class); FileEditorProvider fileEditorProvider = fileEditorProviders[0]; assertEquals(CsvFileEditorProvider.EDITOR_TYPE_ID, fileEditorProvider.getEditorTypeId()); assertEquals(FileEditorPolicy.HIDE_DEFAULT_EDITOR, fileEditorProvider.getPolicy()); CsvEditorSettings csvEditorSettings = CsvEditorSettings.getInstance(); csvEditorSettings.setEditorPrio(CsvEditorSettings.EditorPrio.TEXT_ONLY); assertEquals(FileEditorPolicy.HIDE_DEFAULT_EDITOR, fileEditorProvider.getPolicy()); csvEditorSettings.setEditorPrio(CsvEditorSettings.EditorPrio.TABLE_FIRST); assertEquals(FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR, fileEditorProvider.getPolicy()); }
Example #3
Source File: ImplementationViewComponent.java From consulo with Apache License 2.0 | 6 votes |
private void updateEditorText() { disposeNonTextEditor(); final PsiElement elt = myElements[myIndex].getNavigationElement(); Project project = elt.getProject(); PsiFile psiFile = getContainingFile(elt); final VirtualFile vFile = psiFile.getVirtualFile(); if (vFile == null) return; final FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(project, vFile); for (FileEditorProvider provider : providers) { if (provider instanceof TextEditorProvider) { updateTextElement(elt); myBinarySwitch.show(myViewingPanel, TEXT_PAGE_KEY); break; } else if (provider.accept(project, vFile)) { myCurrentNonTextEditorProvider = provider; myNonTextEditor = myCurrentNonTextEditorProvider.createEditor(project, vFile); myBinaryPanel.removeAll(); myBinaryPanel.add(myNonTextEditor.getComponent()); myBinarySwitch.show(myViewingPanel, BINARY_PAGE_KEY); break; } } }
Example #4
Source File: CsvTableEditorProviderTest.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
public void testCsvTableEditorProviderIsAvailableAndHasCorrectNameAndPolicy() { FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(getProject(), myFixture.getFile().getVirtualFile()); assertEquals(2, fileEditorProviders.length); assertInstanceOf(fileEditorProviders[1], CsvTableEditorProvider.class); FileEditorProvider fileEditorProvider = fileEditorProviders[1]; assertEquals(CsvTableEditorProvider.EDITOR_TYPE_ID, fileEditorProvider.getEditorTypeId()); assertEquals(FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR, fileEditorProvider.getPolicy()); assertEquals(true, fileEditorProvider.accept(getProject(), myFixture.getFile().getVirtualFile())); CsvEditorSettings csvEditorSettings = CsvEditorSettings.getInstance(); csvEditorSettings.setEditorPrio(CsvEditorSettings.EditorPrio.TEXT_ONLY); assertEquals(FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR, fileEditorProvider.getPolicy()); assertEquals(false, fileEditorProvider.accept(getProject(), myFixture.getFile().getVirtualFile())); csvEditorSettings.setEditorPrio(CsvEditorSettings.EditorPrio.TABLE_FIRST); assertEquals(FileEditorPolicy.HIDE_DEFAULT_EDITOR, fileEditorProvider.getPolicy()); assertEquals(true, fileEditorProvider.accept(getProject(), myFixture.getFile().getVirtualFile())); }
Example #5
Source File: BinaryEditorHolder.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean canShowContent(@Nonnull DiffContent content, @Nonnull DiffContext context) { if (content instanceof DocumentContent) return true; if (content instanceof FileContent) { Project project = context.getProject(); if (project == null) project = ProjectManager.getInstance().getDefaultProject(); VirtualFile file = ((FileContent)content).getFile(); return FileEditorProviderManager.getInstance().getProviders(project, file).length != 0; } return false; }
Example #6
Source File: StructureViewWrapperImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private FileEditor createTempFileEditor(@Nonnull VirtualFile file) { if (file.getLength() > PersistentFSConstants.getMaxIntellisenseFileSize()) return null; FileEditorProviderManager editorProviderManager = FileEditorProviderManager.getInstance(); final FileEditorProvider[] providers = editorProviderManager.getProviders(myProject, file); return providers.length == 0 ? null : providers[0].createEditor(myProject, file); }
Example #7
Source File: OpenFileAction.java From consulo with Apache License 2.0 | 5 votes |
public static void openFile(final VirtualFile virtualFile, final Project project) { FileEditorProviderManager editorProviderManager = FileEditorProviderManager.getInstance(); if (editorProviderManager.getProviders(project, virtualFile).length == 0) { Messages.showMessageDialog(project, IdeBundle.message("error.files.of.this.type.cannot.be.opened", ApplicationNamesInfo.getInstance().getProductName()), IdeBundle.message("title.cannot.open.file"), Messages.getErrorIcon()); return; } NonProjectFileWritingAccessProvider.allowWriting(virtualFile); OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile); FileEditorManager.getInstance(project).openTextEditor(descriptor, true); }
Example #8
Source File: BinaryDiffTool.java From consulo with Apache License 2.0 | 5 votes |
public static boolean canShow(@Nonnull Project project, VirtualFile file) { if (file == null) return false; if (FileEditorProviderManager.getInstance().getProviders(project, file).length > 0) return true; final DirDiffManager diffManager = DirDiffManager.getInstance(project); return diffManager.createDiffElement(file) != null; }
Example #9
Source File: HistoryEntry.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static EntryData parseEntry(@Nonnull Project project, @Nonnull Element e) throws InvalidDataException { if (!e.getName().equals(TAG)) { throw new IllegalArgumentException("unexpected tag: " + e); } String url = e.getAttributeValue(FILE_ATTR); List<Pair<FileEditorProvider, FileEditorState>> providerStates = new ArrayList<>(); FileEditorProvider selectedProvider = null; VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); for (Element _e : e.getChildren(PROVIDER_ELEMENT)) { String typeId = _e.getAttributeValue(EDITOR_TYPE_ID_ATTR); FileEditorProvider provider = FileEditorProviderManager.getInstance().getProvider(typeId); if (provider == null) { continue; } if (Boolean.valueOf(_e.getAttributeValue(SELECTED_ATTR_VALUE))) { selectedProvider = provider; } Element stateElement = _e.getChild(STATE_ELEMENT); if (stateElement == null) { throw new InvalidDataException(); } if (file != null) { FileEditorState state = provider.readState(stateElement, project, file); providerStates.add(Pair.create(provider, state)); } } return new EntryData(url, providerStates, selectedProvider); }
Example #10
Source File: CreateUnresolvedElementFix.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nullable protected static Editor openEditor(@Nonnull PsiElement anchor, int offset) { PsiFile containingFile = anchor.getContainingFile(); if(containingFile == null) { return null; } VirtualFile virtualFile = containingFile.getVirtualFile(); if(virtualFile == null) { return null; } Project project = containingFile.getProject(); FileEditorProviderManager editorProviderManager = FileEditorProviderManager.getInstance(); if(editorProviderManager.getProviders(project, virtualFile).length == 0) { Messages.showMessageDialog(project, IdeBundle.message("error.files.of.this.type.cannot.be.opened", ApplicationNamesInfo.getInstance() .getProductName()), IdeBundle.message("title.cannot.open.file"), Messages.getErrorIcon()); return null; } OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile); Editor editor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true); if(editor != null) { editor.getCaretModel().moveToOffset(offset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); return editor; } return null; }
Example #11
Source File: CsvFileEditorTest.java From intellij-csv-validator with Apache License 2.0 | 5 votes |
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(), myFixture.getFile().getVirtualFile()); assertInstanceOf(state, TextEditorState.class); textEditor.setState(state); fileEditorProvider.writeState(state, this.getProject(), dummy); disposeTextEditor(textEditor); }
Example #12
Source File: CsvFileEditorTest.java From intellij-csv-validator with Apache License 2.0 | 5 votes |
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; CsvEditorSettings csvEditorSettings = CsvEditorSettings.getInstance(); EditorSettings editorSettings = textEditor.getEditor().getSettings(); assertEquals(csvEditorSettings.isCaretRowShown(), editorSettings.isCaretRowShown()); assertEquals(csvEditorSettings.isUseSoftWraps(), editorSettings.isUseSoftWraps()); disposeTextEditor(textEditor); }
Example #13
Source File: CsvTableEditorProviderTest.java From intellij-csv-validator with Apache License 2.0 | 5 votes |
public void testCsvTableEditorCreatesInstanceOfCsvTableEditor() { FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(getProject(), myFixture.getFile().getVirtualFile()); FileEditorProvider fileEditorProvider = fileEditorProviders[1]; FileEditor fileEditor = fileEditorProvider.createEditor(getProject(), myFixture.getFile().getVirtualFile()); assertInstanceOf(fileEditor, CsvTableEditor.class); fileEditorProvider.disposeEditor(fileEditor); }
Example #14
Source File: FileEditorManagerTestCase.java From consulo with Apache License 2.0 | 4 votes |
@Override protected void tearDown() throws Exception { myManager.closeAllFiles(); ((FileEditorProviderManagerImpl)FileEditorProviderManager.getInstance()).clearSelectedProviders(); super.tearDown(); }
Example #15
Source File: DesktopEditorComposite.java From consulo with Apache License 2.0 | 4 votes |
/** * @param file {@code file} for which composite is being constructed * @param editors {@code edittors} that should be placed into the composite * @throws IllegalArgumentException if {@code editors} * is {@code null} or {@code providers} is {@code null} or {@code myEditor} arrays is empty */ DesktopEditorComposite(@Nonnull final VirtualFile file, @Nonnull final FileEditor[] editors, @Nonnull final FileEditorManagerEx fileEditorManager) { myFile = file; myEditors = editors; if (NullUtils.hasNull(editors)) throw new IllegalArgumentException("Must not pass null editors in " + Arrays.asList(editors)); myFileEditorManager = fileEditorManager; myInitialFileTimeStamp = myFile.getTimeStamp(); Disposer.register(fileEditorManager.getProject(), this); if (editors.length > 1) { myTabbedPaneWrapper = createTabbedPaneWrapper(editors); JComponent component = myTabbedPaneWrapper.getComponent(); myComponent = new MyComponent(component, component); } else if (editors.length == 1) { myTabbedPaneWrapper = null; FileEditor editor = editors[0]; myComponent = new MyComponent(createEditorComponent(editor), editor.getPreferredFocusedComponent()); } else { throw new IllegalArgumentException("editors array cannot be empty"); } mySelectedEditor = editors[0]; myFocusWatcher = new FocusWatcher(); myFocusWatcher.install(myComponent); myFileEditorManager.addFileEditorManagerListener(new FileEditorManagerListener() { @Override public void selectionChanged(@Nonnull final FileEditorManagerEvent event) { final VirtualFile oldFile = event.getOldFile(); final VirtualFile newFile = event.getNewFile(); if (Comparing.equal(oldFile, newFile) && Comparing.equal(getFile(), newFile)) { Runnable runnable = () -> { final FileEditor oldEditor = event.getOldEditor(); if (oldEditor != null) oldEditor.deselectNotify(); final FileEditor newEditor = event.getNewEditor(); if (newEditor != null) newEditor.selectNotify(); ((FileEditorProviderManagerImpl)FileEditorProviderManager.getInstance()).providerSelected(DesktopEditorComposite.this); ((IdeDocumentHistoryImpl)IdeDocumentHistory.getInstance(myFileEditorManager.getProject())).onSelectionChanged(); }; if (ApplicationManager.getApplication().isDispatchThread()) { CommandProcessor.getInstance().executeCommand(myFileEditorManager.getProject(), runnable, "Switch Active Editor", null); } else { runnable.run(); // not invoked by user } } } }, this); }
Example #16
Source File: BinaryDiffTool.java From consulo with Apache License 2.0 | 4 votes |
private boolean canShowContent(final Project project, final VirtualFile file) { if (file == null) return true; return FileEditorProviderManager.getInstance().getProviders(project, file).length > 0; }
Example #17
Source File: CsvFileEditorTest.java From intellij-csv-validator with Apache License 2.0 | 4 votes |
private TextEditor getCurrentTextEditor() { FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(myFixture.getProject(), myFixture.getFile().getVirtualFile()); return (TextEditor)fileEditorProviders[0].createEditor(myFixture.getProject(), myFixture.getFile().getVirtualFile()); }
Example #18
Source File: CsvFileEditorTest.java From intellij-csv-validator with Apache License 2.0 | 4 votes |
private void disposeTextEditor(FileEditor fileEditor) { FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(myFixture.getProject(), myFixture.getFile().getVirtualFile()); fileEditorProviders[0].disposeEditor(fileEditor); }