com.intellij.openapi.fileTypes.FileTypeManager Java Examples
The following examples show how to use
com.intellij.openapi.fileTypes.FileTypeManager.
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: CodeInsightTestFixtureImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public PsiFile configureByText(final FileType fileType, @NonNls final String text) { assertInitialized(); final String extension = fileType.getDefaultExtension(); final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); if (fileTypeManager.getFileTypeByExtension(extension) != fileType) { new WriteCommandAction(getProject()) { @Override protected void run(Result result) throws Exception { fileTypeManager.associateExtension(fileType, extension); } }.execute(); } final String fileName = "aaa." + extension; return configureByText(fileName, text); }
Example #2
Source File: TextEditorComponent.java From consulo with Apache License 2.0 | 6 votes |
public TextEditorComponent(@Nonnull final Project project, @Nonnull final VirtualFile file, @Nonnull final DesktopTextEditorImpl textEditor) { super(new BorderLayout(), textEditor); myProject = project; myFile = file; myTextEditor = textEditor; myDocument = FileDocumentManager.getInstance().getDocument(myFile); LOG.assertTrue(myDocument != null); myDocument.addDocumentListener(new MyDocumentListener(), this); myEditor = createEditor(); add(myEditor.getComponent(), BorderLayout.CENTER); myModified = isModifiedImpl(); myValid = isEditorValidImpl(); LOG.assertTrue(myValid); MyVirtualFileListener myVirtualFileListener = new MyVirtualFileListener(); myFile.getFileSystem().addVirtualFileListener(myVirtualFileListener); Disposer.register(this, () -> myFile.getFileSystem().removeVirtualFileListener(myVirtualFileListener)); MessageBusConnection myConnection = project.getMessageBus().connect(this); myConnection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener()); myEditorHighlighterUpdater = new EditorHighlighterUpdater(myProject, this, (EditorEx)myEditor, myFile); }
Example #3
Source File: AssociateFileType.java From consulo with Apache License 2.0 | 6 votes |
@Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE); Project project = e.getData(CommonDataKeys.PROJECT); boolean haveSmthToDo; if (project == null || file == null || file.isDirectory()) { haveSmthToDo = false; } else { // the action should also be available for files which have been auto-detected as text or as a particular language (IDEA-79574) haveSmthToDo = FileTypeManager.getInstance().getFileTypeByFileName(file.getName()) == UnknownFileType.INSTANCE; } presentation.setVisible(haveSmthToDo || ActionPlaces.MAIN_MENU.equals(e.getPlace())); presentation.setEnabled(haveSmthToDo); }
Example #4
Source File: EditorHighlighterUpdater.java From consulo with Apache License 2.0 | 6 votes |
public EditorHighlighterUpdater(@Nonnull Project project, @Nonnull Disposable parentDisposable, @Nonnull EditorEx editor, @Nullable VirtualFile file) { myProject = project; myEditor = editor; myFile = file; MessageBusConnection connection = project.getMessageBus().connect(parentDisposable); connection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener()); connection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() { @Override public void enteredDumbMode() { updateHighlighters(); } @Override public void exitDumbMode() { updateHighlighters(); } }); }
Example #5
Source File: TestUtils.java From intellij with Apache License 2.0 | 6 votes |
static void createMockApplication(Disposable parentDisposable) { final MyMockApplication instance = new MyMockApplication(parentDisposable); // If there was no previous application, ApplicationManager leaves the MockApplication in place, // which can break future tests. Application oldApplication = ApplicationManager.getApplication(); if (oldApplication == null) { Disposer.register( parentDisposable, () -> new ApplicationManager() { { ourApplication = null; } }); } ApplicationManager.setApplication(instance, FileTypeManager::getInstance, parentDisposable); instance.registerService(EncodingManager.class, EncodingManagerImpl.class); }
Example #6
Source File: ErrorDiffTool.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Nonnull @Override public ToolbarComponents init() { if (myRequest instanceof UnknownFileTypeDiffRequest) { String fileName = ((UnknownFileTypeDiffRequest)myRequest).getFileName(); if (fileName != null && FileTypeManager.getInstance().getFileTypeByFileName(fileName) != UnknownFileType.INSTANCE) { // FileType was assigned elsewhere (ex: by other UnknownFileTypeDiffRequest). We should reload request. if (myContext instanceof DiffContextEx) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { ((DiffContextEx)myContext).reloadDiffRequest(); } }, ModalityState.current()); } } } return new ToolbarComponents(); }
Example #7
Source File: TestUtils.java From intellij with Apache License 2.0 | 6 votes |
public static void createMockApplication(Disposable parentDisposable) { final BlazeMockApplication instance = new BlazeMockApplication(parentDisposable); // If there was no previous application, // ApplicationManager leaves the MockApplication in place, which can break future tests. Application oldApplication = ApplicationManager.getApplication(); if (oldApplication == null) { Disposer.register( parentDisposable, () -> { new ApplicationManager() { { ourApplication = null; } }; }); } ApplicationManager.setApplication(instance, FileTypeManager::getInstance, parentDisposable); instance.registerService(EncodingManager.class, EncodingManagerImpl.class); }
Example #8
Source File: RemovedMappingTracker.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull static List<RemovedMapping> readRemovedMappings(@Nonnull Element e) { List<Element> children = e.getChildren(ELEMENT_REMOVED_MAPPING); if (children.isEmpty()) { return Collections.emptyList(); } List<RemovedMapping> result = new ArrayList<>(); for (Element mapping : children) { String ext = mapping.getAttributeValue(AbstractFileType.ATTRIBUTE_EXT); FileNameMatcher matcher = ext == null ? FileTypeManager.parseFromString(mapping.getAttributeValue(AbstractFileType.ATTRIBUTE_PATTERN)) : new ExtensionFileNameMatcher(ext); boolean approved = Boolean.parseBoolean(mapping.getAttributeValue(ATTRIBUTE_APPROVED)); String fileTypeName = mapping.getAttributeValue(ATTRIBUTE_TYPE); if (fileTypeName == null) continue; RemovedMapping removedMapping = new RemovedMapping(matcher, fileTypeName, approved); result.add(removedMapping); } return result; }
Example #9
Source File: IdeaGateway.java From consulo with Apache License 2.0 | 6 votes |
public boolean isVersioned(@Nonnull VirtualFile f, boolean shouldBeInContent) { if (!f.isInLocalFileSystem()) return false; if (!f.isDirectory() && StringUtil.endsWith(f.getNameSequence(), ".class")) return false; VersionedFilterData versionedFilterData = getVersionedFilterData(); boolean isInContent = false; int numberOfOpenProjects = versionedFilterData.myOpenedProjects.size(); for (int i = 0; i < numberOfOpenProjects; ++i) { if (f.equals(versionedFilterData.myWorkspaceFiles.get(i))) return false; ProjectFileIndex index = versionedFilterData.myProjectFileIndices.get(i); if (index.isExcluded(f)) return false; isInContent |= index.isInContent(f); } if (shouldBeInContent && !isInContent) return false; // optimisation: FileTypeManager.isFileIgnored(f) already checked inside ProjectFileIndex.isIgnored() return numberOfOpenProjects != 0 || !FileTypeManager.getInstance().isFileIgnored(f); }
Example #10
Source File: HaxeExpressionCodeFragmentImpl.java From intellij-haxe with Apache License 2.0 | 6 votes |
public HaxeExpressionCodeFragmentImpl(Project project, @NonNls String name, CharSequence text, boolean isPhysical) { super(new SingleRootFileViewProvider(PsiManager.getInstance(project), new LightVirtualFile(name, FileTypeManager.getInstance().getFileTypeByFileName(name), text), isPhysical) { @Override public boolean supportsIncrementalReparse(@NotNull Language rootLanguage) { return false; } }); myPhysical = isPhysical; ((SingleRootFileViewProvider)getViewProvider()).forceCachedPsi(this); final MyHaxeFileElementType type = new MyHaxeFileElementType(); init(type, type); }
Example #11
Source File: FileTemplateManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Inject public FileTemplateManagerImpl(@Nonnull FileTypeManager typeManager, FileTemplateSettings projectSettings, ExportableFileTemplateSettings defaultSettings, ProjectManager pm, final Project project) { myTypeManager = (FileTypeManagerEx)typeManager; myProjectSettings = projectSettings; myDefaultSettings = defaultSettings; myProject = project; myProjectScheme = project.isDefault() ? null : new FileTemplatesScheme("Project") { @Nonnull @Override public String getTemplatesDir() { return FileUtilRt.toSystemDependentName(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR); } @Nonnull @Override public Project getProject() { return project; } }; }
Example #12
Source File: UpdatingChangeListBuilder.java From consulo with Apache License 2.0 | 6 votes |
@Override public void processChangeInList(final Change change, @Nullable final ChangeList changeList, final VcsKey vcsKey) { checkIfDisposed(); LOG.debug("[processChangeInList-1] entering, cl name: " + ((changeList == null) ? null : changeList.getName()) + " change: " + ChangesUtil.getFilePath(change).getPath()); final String fileName = ChangesUtil.getFilePath(change).getName(); if (FileTypeManager.getInstance().isFileIgnored(fileName)) { LOG.debug("[processChangeInList-1] file type ignored"); return; } if (ChangeListManagerImpl.isUnder(change, myScope)) { if (changeList != null) { LOG.debug("[processChangeInList-1] to add change to cl"); myChangeListWorker.addChangeToList(changeList.getName(), change, vcsKey); } else { LOG.debug("[processChangeInList-1] to add to corresponding list"); myChangeListWorker.addChangeToCorrespondingList(change, vcsKey); } } else { LOG.debug("[processChangeInList-1] not under scope"); } }
Example #13
Source File: XLFFileTypeListener.java From idea-php-typo3-plugin with MIT License | 6 votes |
@Override public void projectOpened(@NotNull Project project) { if (!(FileTypeManager.getInstance().getFileTypeByExtension("xlf") instanceof XmlFileType)) { WriteCommandAction.runWriteCommandAction(ProjectManager.getInstance().getOpenProjects()[0], () -> { FileTypeManager.getInstance().associateExtension(XmlFileType.INSTANCE, "xlf"); ApplicationManager.getApplication().invokeLater(() -> { Notification notification = GROUP_DISPLAY_ID_INFO.createNotification( "TYPO3 CMS Plugin", "XLF File Type Association", "The XLF File Type was re-assigned to XML to prevent errors with the XLIFF Plugin and allow autocompletion. Please re-index your projects.", NotificationType.INFORMATION ); Project[] projects = ProjectManager.getInstance().getOpenProjects(); Notifications.Bus.notify(notification, projects[0]); }); }); } }
Example #14
Source File: CopyrightFormattingConfigurable.java From consulo with Apache License 2.0 | 6 votes |
@Override protected Configurable[] buildConfigurables() { getOrCreateMainPanel(); FileType[] registeredFileTypes = FileTypeManager.getInstance().getRegisteredFileTypes(); List<Configurable> list = new ArrayList<>(); for (FileType fileType : registeredFileTypes) { UpdateCopyrightsProvider updateCopyrightsProvider = CopyrightUpdaters.INSTANCE.forFileType(fileType); if (updateCopyrightsProvider == null) { continue; } list.add(updateCopyrightsProvider.createConfigurable(myProject, myPanel, fileType)); } Collections.sort(list, (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName())); return ContainerUtil.toArray(list, Configurable.ARRAY_FACTORY); }
Example #15
Source File: BreadcrumbsInitializingActivity.java From consulo with Apache License 2.0 | 6 votes |
@Override public void runActivity(@Nonnull Project project) { if (project.isDefault() || ApplicationManager.getApplication().isUnitTestMode() || project.isDisposed()) { return; } MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyFileEditorManagerListener()); connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() { @Override public void fileTypesChanged(@Nonnull FileTypeEvent event) { reinitBreadcrumbsInAllEditors(project); } }); VirtualFileManager.getInstance().addVirtualFileListener(new MyVirtualFileListener(project), project); connection.subscribe(UISettingsListener.TOPIC, uiSettings -> reinitBreadcrumbsInAllEditors(project)); UIUtil.invokeLaterIfNeeded(() -> reinitBreadcrumbsInAllEditors(project)); }
Example #16
Source File: OCamlSourcesOrderRootTypeUIFactory.java From reasonml-idea-plugin with MIT License | 6 votes |
@NotNull List<VirtualFile> suggestOCamlRoots(@NotNull VirtualFile dir, @NotNull final ProgressIndicator progressIndicator) { if (!dir.isDirectory()) { return ContainerUtil.emptyList(); } final FileTypeManager typeManager = FileTypeManager.getInstance(); final ArrayList<VirtualFile> foundDirectories = new ArrayList<>(); try { VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() { @NotNull @Override public Result visitFileEx(@NotNull VirtualFile file) { progressIndicator.checkCanceled(); if (!file.isDirectory()) { FileType type = typeManager.getFileTypeByFileName(file.getName()); if (type.getDefaultExtension().equals("ml")) { VirtualFile root = file.getParent(); if (root != null) { foundDirectories.add(root); return skipTo(root); } } } return CONTINUE; } }); } catch (ProcessCanceledException ignore) { } return foundDirectories; }
Example #17
Source File: LanguageServersRegistry.java From intellij-quarkus with Eclipse Public License 2.0 | 6 votes |
private void initialize() { Map<String, LanguageServerDefinition> servers = new HashMap<>(); List<ContentTypeMapping> contentTypes = new ArrayList<>(); for (ServerExtensionPointBean server : ServerExtensionPointBean.EP_NAME.getExtensions()) { if (server.id != null && !server.id.isEmpty()) { servers.put(server.id, new ExtensionLanguageServerDefinition(server)); } } for (ContentTypeMappingExtensionPointBean extension : ContentTypeMappingExtensionPointBean.EP_NAME.getExtensions()) { FileType contentType = FileTypeManager.getInstance().findFileTypeByName(extension.contenType); if (contentType != null) { contentTypes.add(new ContentTypeMapping(contentType, extension.id, extension.languageId)); } } for (ContentTypeMapping mapping : contentTypes) { LanguageServerDefinition lsDefinition = servers.get(mapping.languageId); if (lsDefinition != null) { registerAssociation(mapping.contentType, lsDefinition, mapping.languageId); } else { LOGGER.warn("server '" + mapping.id + "' not available"); //$NON-NLS-1$ //$NON-NLS-2$ } } }
Example #18
Source File: UpdatingChangeListBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Override public void processLocallyDeletedFile(LocallyDeletedChange locallyDeletedChange) { checkIfDisposed(); final FilePath file = locallyDeletedChange.getPath(); if (FileTypeManager.getInstance().isFileIgnored(file.getName())) return; if (myScope.belongsTo(file)) { myChangeListWorker.addLocallyDeleted(locallyDeletedChange); } }
Example #19
Source File: RenameToIgnoredDirectoryFileInputValidator.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @Override public String getErrorMessage(String newName, Project project) { if (FileTypeManager.getInstance().isFileIgnored(newName)) { return "Trying to create a directory with ignored name, result will not be visible"; } return null; }
Example #20
Source File: MarkAsOriginalTypeAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(AnActionEvent e) { DataContext dataContext = e.getDataContext(); final VirtualFile[] selectedFiles = dataContext.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY); final Presentation presentation = e.getPresentation(); final EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance(); presentation.setVisible(false); if (typeManager == null || selectedFiles == null || selectedFiles.length == 0) { return; } FileType originalType = null; for (VirtualFile file : selectedFiles) { if (typeManager.isMarkedAsPlainText(file)) { FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(file.getName()); if (originalType == null) { originalType = fileType; } else if (fileType != originalType) { return; } } else { return; } } if (originalType == null) return; presentation.setVisible(true); presentation.setText(ActionsBundle.actionText("MarkAsOriginalTypeAction") + " " + originalType.getName()); presentation.setIcon(originalType.getIcon()); }
Example #21
Source File: VirtualFileDiffElement.java From consulo with Apache License 2.0 | 5 votes |
@Override public VirtualFileDiffElement[] getChildren() { if (myFile.is(VFileProperty.SYMLINK)) { return new VirtualFileDiffElement[0]; } final VirtualFile[] files = myFile.getChildren(); final ArrayList<VirtualFileDiffElement> elements = new ArrayList<>(); for (VirtualFile file : files) { if (!FileTypeManager.getInstance().isFileIgnored(file) && file.isValid()) { elements.add(new VirtualFileDiffElement(file)); } } return elements.toArray(new VirtualFileDiffElement[elements.size()]); }
Example #22
Source File: AbstractVcsHelperImpl.java From consulo with Apache License 2.0 | 5 votes |
private static DiffContent getContentForVersion(final VcsFileRevision version, final File file) throws IOException, VcsException { VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file); if (vFile != null && (version instanceof CurrentRevision) && !vFile.getFileType().isBinary()) { return new DocumentContent(FileDocumentManager.getInstance().getDocument(vFile), vFile.getFileType()); } else { return new SimpleContent(VcsHistoryUtil.loadRevisionContentGuessEncoding(version, vFile, null), FileTypeManager.getInstance().getFileTypeByFileName(file.getName())); } }
Example #23
Source File: BaseApplication.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void bootstrapInjectingContainer(@Nonnull InjectingContainerBuilder builder) { super.bootstrapInjectingContainer(builder); builder.bind(Application.class).to(this); builder.bind(ApplicationEx.class).to(this); builder.bind(ApplicationEx2.class).to(this); builder.bind(ApplicationInfo.class).to(ApplicationInfo::getInstance); builder.bind(ContainerPathManager.class).to(ContainerPathManager::get); builder.bind(IApplicationStore.class).to(ApplicationStoreImpl.class).forceSingleton(); builder.bind(ApplicationPathMacroManager.class).to(ApplicationPathMacroManager.class).forceSingleton(); builder.bind(FileTypeRegistry.class).to(FileTypeManager::getInstance); }
Example #24
Source File: TranslatingCompilerFilesMonitorImpl.java From consulo with Apache License 2.0 | 5 votes |
public boolean isIgnoredOrUnderIgnoredDirectory(ProjectManager projectManager, VirtualFile file) { FileTypeManager fileTypeManager = FileTypeManager.getInstance(); if (fileTypeManager.isFileIgnored(file)) { return true; } //optimization: if file is in content of some project it's definitely not ignored boolean isInContent = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { for (Project project : projectManager.getOpenProjects()) { if (project.isInitialized() && ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) { return true; } } return false; } }); if (isInContent) { return false; } VirtualFile current = file.getParent(); while (current != null) { if (fileTypeManager.isFileIgnored(current)) { return true; } current = current.getParent(); } return false; }
Example #25
Source File: FileLabel.java From consulo with Apache License 2.0 | 5 votes |
public void setFile(File ioFile) { myFile = ioFile; if (myShowIcon) { setIcon(TargetAWT.to(FileTypeManager.getInstance().getFileTypeByFileName(myFile.getName()).getIcon())); } else { setIcon(null); } }
Example #26
Source File: FileChooserDescriptor.java From consulo with Apache License 2.0 | 5 votes |
/** * Defines whether file is visible in the tree */ public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { if (file.is(VFileProperty.SYMLINK) && file.getCanonicalPath() == null) { return false; } if (!file.isDirectory()) { if (FileElement.isArchive(file)) { if (!myChooseJars && !myChooseJarContents) { return false; } } else if (!myChooseFiles) { return false; } if (myFileFilter != null && !myFileFilter.value(file)) { return false; } } if (isHideIgnored() && FileTypeManager.getInstance().isFileIgnored(file)) { return false; } if (!showHiddenFiles && FileElement.isFileHidden(file)) { return false; } return true; }
Example #27
Source File: SimpleContent.java From consulo with Apache License 2.0 | 5 votes |
/** * @param file should exist and not to be a directory * @param charset name of file charset. If null IDE default charset will be used * @param fileType content type. If null file name will be used to select file type * @return Content representing text in file * @throws IOException */ public static DiffContent fromIoFile(File file, String charset, FileType fileType) throws IOException { if (file.isDirectory()) throw new IllegalArgumentException(file.toString()); if (fileType == null) fileType = FileTypeManager.getInstance().getFileTypeByFileName(file.getName()); BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file)); try { byte[] bytes = new byte[(int)file.length()]; int bytesRead = stream.read(bytes, 0, bytes.length); LOG.assertTrue(file.length() == bytesRead); return fromBytes(bytes, charset, fileType); } finally { stream.close(); } }
Example #28
Source File: SimpleContent.java From consulo with Apache License 2.0 | 5 votes |
/** * @param text text of content * @param fileName used to determine content type * @return */ public static SimpleContent forFileContent(String text, String fileName) { FileType fileType; if (fileName != null) { fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName); } else { fileType = null; } return new SimpleContent(text, fileType); }
Example #29
Source File: VfsUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void processFileRecursivelyWithoutIgnored(@Nonnull final VirtualFile root, @Nonnull final Processor<VirtualFile> processor) { final FileTypeManager ftm = FileTypeManager.getInstance(); processFilesRecursively(root, processor, new Convertor<VirtualFile, Boolean>() { public Boolean convert(final VirtualFile vf) { return !ftm.isFileIgnored(vf); } }); }
Example #30
Source File: VfsUtil.java From consulo with Apache License 2.0 | 5 votes |
public static String getUrlForLibraryRoot(@Nonnull File libraryRoot) { String path = FileUtil.toSystemIndependentName(libraryRoot.getAbsolutePath()); final FileType fileTypeByFileName = FileTypeManager.getInstance().getFileTypeByFileName(libraryRoot.getName()); if (fileTypeByFileName instanceof ArchiveFileType) { final String protocol = ((ArchiveFileType)fileTypeByFileName).getProtocol(); return VirtualFileManager.constructUrl(protocol, path + ArchiveFileSystem.ARCHIVE_SEPARATOR); } else { return VirtualFileManager.constructUrl(LocalFileSystem.getInstance().getProtocol(), path); } }