com.intellij.openapi.fileEditor.FileEditorProvider Java Examples
The following examples show how to use
com.intellij.openapi.fileEditor.FileEditorProvider.
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 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 #2
Source File: HistoryEntry.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static HistoryEntry createHeavy(@Nonnull Project project, @Nonnull VirtualFile file, @Nonnull FileEditorProvider[] providers, @Nonnull FileEditorState[] states, @Nonnull FileEditorProvider selectedProvider) { if (project.isDisposed()) return createLight(file, providers, states, selectedProvider); Disposable disposable = Disposable.newDisposable(); VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(file, disposable, null); HistoryEntry entry = new HistoryEntry(pointer, selectedProvider, disposable); for (int i = 0; i < providers.length; i++) { FileEditorProvider provider = providers[i]; FileEditorState state = states[i]; if (provider != null && state != null) { entry.putState(provider, state); } } return entry; }
Example #3
Source File: HistoryEntry.java From consulo with Apache License 2.0 | 6 votes |
/** * @return element that was added to the <code>element</code>. * Returned element has tag {@link #TAG}. Never null. */ public Element writeExternal(Element element, Project project) { Element e = new Element(TAG); element.addContent(e); e.setAttribute(FILE_ATTR, myFilePointer.getUrl()); for (final Map.Entry<FileEditorProvider, FileEditorState> entry : myProvider2State.entrySet()) { FileEditorProvider provider = entry.getKey(); Element providerElement = new Element(PROVIDER_ELEMENT); if (provider.equals(mySelectedProvider)) { providerElement.setAttribute(SELECTED_ATTR_VALUE, Boolean.TRUE.toString()); } providerElement.setAttribute(EDITOR_TYPE_ID_ATTR, provider.getEditorTypeId()); Element stateElement = new Element(STATE_ELEMENT); providerElement.addContent(stateElement); provider.writeState(entry.getValue(), project, stateElement); e.addContent(providerElement); } return e; }
Example #4
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 #5
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 #6
Source File: FileEditorProviderManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nullable FileEditorProvider getSelectedFileEditorProvider(EditorHistoryManager editorHistoryManager, VirtualFile file, FileEditorProvider[] providers) { FileEditorProvider provider = editorHistoryManager.getSelectedProvider(file); if (provider != null || providers.length < 2) { return provider; } String id = mySelectedProviders.get(computeKey(providers)); return id == null ? null : getProvider(id); }
Example #7
Source File: DesktopPsiAwareFileEditorManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override protected EditorWithProviderComposite createEditorWithProviderComposite(@Nonnull VirtualFile file, @Nonnull FileEditor[] editors, @Nonnull FileEditorProvider[] providers, @Nonnull FileEditorManagerEx fileEditorManager) { return new DesktopEditorWithProviderComposite(file, editors, providers, fileEditorManager); }
Example #8
Source File: HistoryEntry.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static HistoryEntry createHeavy(@Nonnull Project project, @Nonnull Element e) throws InvalidDataException { if (project.isDisposed()) return createLight(project, e); EntryData entryData = parseEntry(project, e); Disposable disposable = Disposable.newDisposable(); VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(entryData.url, disposable, null); HistoryEntry entry = new HistoryEntry(pointer, entryData.selectedProvider, disposable); for (Pair<FileEditorProvider, FileEditorState> state : entryData.providerStates) { entry.putState(state.first, state.second); } return entry; }
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: HistoryEntry.java From consulo with Apache License 2.0 | 5 votes |
public EntryData(@Nonnull String url, @Nonnull List<Pair<FileEditorProvider, FileEditorState>> providerStates, @Nullable FileEditorProvider selectedProvider) { this.url = url; this.providerStates = providerStates; this.selectedProvider = selectedProvider; }
Example #11
Source File: FileEditorProviderManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public FileEditorProvider[] getProviders(@Nonnull final Project project, @Nonnull final VirtualFile file) { // Collect all possible editors List<FileEditorProvider> sharedProviders = new ArrayList<>(); boolean doNotShowTextEditor = false; for (final FileEditorProvider provider : myProviders) { ThrowableComputable<Boolean, RuntimeException> action = () -> { if (DumbService.isDumb(project) && !DumbService.isDumbAware(provider)) { return false; } return provider.accept(project, file); }; if (AccessRule.read(action)) { sharedProviders.add(provider); doNotShowTextEditor |= provider.getPolicy() == FileEditorPolicy.HIDE_DEFAULT_EDITOR; } } // Throw out default editors provider if necessary if (doNotShowTextEditor) { ContainerUtil.retainAll(sharedProviders, provider -> !(provider instanceof TextEditorProvider)); } // Sort editors according policies Collections.sort(sharedProviders, MyComparator.ourInstance); return sharedProviders.toArray(new FileEditorProvider[sharedProviders.size()]); }
Example #12
Source File: FileEditorProviderManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nullable public FileEditorProvider getProvider(@Nonnull String editorTypeId) { for (FileEditorProvider provider : myProviders) { if (provider.getEditorTypeId().equals(editorTypeId)) { return provider; } } return null; }
Example #13
Source File: FileEditorProviderManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private void registerProvider(@Nonnull FileEditorProvider provider) { String editorTypeId = provider.getEditorTypeId(); if (getProvider(editorTypeId) != null) { throw new IllegalArgumentException("attempt to register provider with non unique editorTypeId: " + editorTypeId); } myProviders.add(provider); }
Example #14
Source File: WebEditorWithProviderComposite.java From consulo with Apache License 2.0 | 5 votes |
public WebEditorWithProviderComposite(VirtualFile file, FileEditor[] editors, FileEditorProvider[] providers, FileEditorManagerEx fileEditorManager) { myFile = file; myEditors = editors; myProviders = providers; myFileEditorManager = fileEditorManager; myComponents = new Component[editors.length]; for (int i = 0; i < editors.length; i++) { FileEditor editor = editors[i]; myComponents[i] = editor.getUIComponent(); } }
Example #15
Source File: FileEditorProviderManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public int compare(FileEditorProvider provider1, FileEditorProvider provider2) { final int i1 = provider1.getPolicy().ordinal(); final int i2 = provider2.getPolicy().ordinal(); if (i1 != i2) return i1 - i2; final double value = getWeight(provider1) - getWeight(provider2); return value > 0 ? 1 : value < 0 ? -1 : 0; }
Example #16
Source File: DockManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public Pair<FileEditor[], FileEditorProvider[]> createNewDockContainerFor(@Nonnull VirtualFile file, @Nonnull FileEditorManagerImpl fileEditorManager) { DockContainer container = getFactory(DockableEditorContainerFactory.TYPE).createContainer(null); register(container); final DockWindow window = createWindowFor(null, container); window.show(true); final EditorWindow editorWindow = ((DockableEditorTabbedContainer)container).getSplitters().getOrCreateCurrentWindow(file); final Pair<FileEditor[], FileEditorProvider[]> result = fileEditorManager.openFileImpl2(UIAccess.get(), editorWindow, file, true); container.add(EditorTabbedContainer.createDockableEditor(myProject, null, file, new Presentation(file.getName()), editorWindow), null); SwingUtilities.invokeLater(() -> window.myUiContainer.setPreferredSize(null)); return result; }
Example #17
Source File: WebPsiAwareFileEditorManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override protected EditorWithProviderComposite createEditorWithProviderComposite(@Nonnull VirtualFile file, @Nonnull FileEditor[] editors, @Nonnull FileEditorProvider[] providers, @Nonnull FileEditorManagerEx fileEditorManager) { return new WebEditorWithProviderComposite(file, editors, providers, fileEditorManager); }
Example #18
Source File: TestEditorTabGroup.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public Pair<FileEditor, FileEditorProvider> getOpenedEditor(){ VirtualFile openedFile = getOpenedFile(); if (openedFile == null) { return null; } return myOpenedTabs.get(openedFile); }
Example #19
Source File: TestEditorSplitter.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public FileEditor getFocusedFileEditor() { Pair<FileEditor, FileEditorProvider> openedEditor = getActiveTabGroup().getOpenedEditor(); if(openedEditor == null) return null; return openedEditor.first; }
Example #20
Source File: TestEditorSplitter.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public FileEditorProvider getProviderFromFocused() { Pair<FileEditor, FileEditorProvider> openedEditor = getActiveTabGroup().getOpenedEditor(); if(openedEditor == null) return null; return openedEditor.second; }
Example #21
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 #22
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 #23
Source File: HistoryEntry.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static HistoryEntry createLight(@Nonnull VirtualFile file, @Nonnull FileEditorProvider[] providers, @Nonnull FileEditorState[] states, @Nonnull FileEditorProvider selectedProvider) { VirtualFilePointer pointer = new LightFilePointer(file); HistoryEntry entry = new HistoryEntry(pointer, selectedProvider, null); for (int i = 0; i < providers.length; i++) { entry.putState(providers[i], states[i]); } return entry; }
Example #24
Source File: HistoryEntry.java From consulo with Apache License 2.0 | 5 votes |
private HistoryEntry(@Nonnull VirtualFilePointer filePointer, @Nullable FileEditorProvider selectedProvider, @Nullable Disposable disposable) { myFilePointer = filePointer; mySelectedProvider = selectedProvider; myDisposable = disposable; myProvider2State = new HashMap<>(); }
Example #25
Source File: DesktopEditorWithProviderComposite.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public HistoryEntry currentStateAsHistoryEntry() { final FileEditor[] editors = getEditors(); final FileEditorState[] states = new FileEditorState[editors.length]; for (int j = 0; j < states.length; j++) { states[j] = editors[j].getState(FileEditorStateLevel.FULL); LOG.assertTrue(states[j] != null); } final int selectedProviderIndex = ArrayUtil.find(editors, getSelectedEditor()); LOG.assertTrue(selectedProviderIndex != -1); final FileEditorProvider[] providers = getProviders(); return HistoryEntry.createLight(getFile(), providers, states, providers[selectedProviderIndex]); }
Example #26
Source File: HistoryEntry.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static HistoryEntry createLight(@Nonnull Project project, @Nonnull Element e) throws InvalidDataException { EntryData entryData = parseEntry(project, e); VirtualFilePointer pointer = new LightFilePointer(entryData.url); HistoryEntry entry = new HistoryEntry(pointer, entryData.selectedProvider, null); for (Pair<FileEditorProvider, FileEditorState> state : entryData.providerStates) { entry.putState(state.first, state.second); } return entry; }
Example #27
Source File: FileEditorWithProvider.java From consulo with Apache License 2.0 | 4 votes |
public FileEditorWithProvider(FileEditor fileEditor, FileEditorProvider provider) { myFileEditor = fileEditor; myProvider = provider; }
Example #28
Source File: BinaryEditorHolder.java From consulo with Apache License 2.0 | 4 votes |
public BinaryEditorHolder(@Nonnull FileEditor editor, @Nonnull FileEditorProvider editorProvider) { myEditor = editor; myEditorProvider = editorProvider; }
Example #29
Source File: WebEditorWithProviderComposite.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public FileEditorProvider[] getProviders() { return myProviders; }
Example #30
Source File: EditorWithProviderComposite.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull FileEditorProvider[] getProviders();