Search in sources :

Example 11 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class FilePathImpl method getFileType.

@Override
@NotNull
public FileType getFileType() {
    VirtualFile file = getVirtualFile();
    FileTypeManager manager = FileTypeManager.getInstance();
    return file != null ? manager.getFileTypeByFile(file) : manager.getFileTypeByFileName(getName());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class CodeInsightTestFixtureImpl method configureByText.

@Override
public PsiFile configureByText(@NotNull final FileType fileType, @NotNull 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(@NotNull Result result) throws Exception {
                fileTypeManager.associateExtension(fileType, extension);
            }
        }.execute();
    }
    final String fileName = "aaa." + extension;
    return configureByText(fileName, text);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Result(com.intellij.openapi.application.Result)

Example 13 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class MarkAsOriginalTypeAction method update.

@Override
public void update(AnActionEvent e) {
    EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
    JBIterable<VirtualFile> selectedFiles = JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)).filter(file -> !file.isDirectory() && typeManager.isMarkedAsPlainText(file));
    FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    boolean enabled = e.getProject() != null && !selectedFiles.isEmpty();
    Set<FileType> fileTypes = selectedFiles.map(file -> fileTypeManager.getFileTypeByFileName(file.getName())).toSet();
    if (fileTypes.size() == 1) {
        FileType original = fileTypes.iterator().next();
        String originalName = original.getName();
        String text = ActionsBundle.actionText("MarkAsOriginalTypeAction").replace("Original File Type", originalName);
        e.getPresentation().setText(text);
        e.getPresentation().setIcon(original.getIcon());
    }
    e.getPresentation().setEnabledAndVisible(enabled);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) JBIterable(com.intellij.util.containers.JBIterable) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Project(com.intellij.openapi.project.Project) Set(java.util.Set) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) FileType(com.intellij.openapi.fileTypes.FileType) ActionsBundle(com.intellij.idea.ActionsBundle) FileType(com.intellij.openapi.fileTypes.FileType) EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager) EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager)

Example 14 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class PruneEmptyDirectoriesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(e.getDataContext());
    assert files != null;
    FileTypeManager ftManager = FileTypeManager.getInstance();
    try {
        for (VirtualFile file : files) {
            pruneEmptiesIn(file, ftManager);
        }
    } catch (IOException ignored) {
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) IOException(java.io.IOException)

Example 15 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class VcsUtil method collectFiles.

/**
   * Collects all files which are located in the passed directory.
   *
   * @throws IllegalArgumentException if {@code dir} isn't a directory.
   */
public static void collectFiles(final VirtualFile dir, final List<VirtualFile> files, final boolean recursive, final boolean addDirectories) {
    if (!dir.isDirectory()) {
        throw new IllegalArgumentException(VcsBundle.message("exception.text.file.should.be.directory", dir.getPresentableUrl()));
    }
    final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {

        @Override
        public boolean visitFile(@NotNull VirtualFile file) {
            if (file.isDirectory()) {
                if (addDirectories) {
                    files.add(file);
                }
                if (!recursive && !Comparing.equal(file, dir)) {
                    return false;
                }
            } else if (fileTypeManager == null || file.getFileType() != FileTypes.UNKNOWN) {
                files.add(file);
            }
            return true;
        }
    });
}
Also used : FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager)

Aggregations

FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)5 NotNull (org.jetbrains.annotations.NotNull)5 FileType (com.intellij.openapi.fileTypes.FileType)4 Result (com.intellij.openapi.application.Result)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 IOException (java.io.IOException)3 Nullable (org.jetbrains.annotations.Nullable)3 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 Project (com.intellij.openapi.project.Project)2 VfsUtilCore (com.intellij.openapi.vfs.VfsUtilCore)2 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 MockDisposable (com.facebook.buck.intellij.ideabuck.test.util.MockDisposable)1 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 FindBundle (com.intellij.find.FindBundle)1 FindModel (com.intellij.find.FindModel)1 FindInProjectManager (com.intellij.find.findInProject.FindInProjectManager)1