Search in sources :

Example 16 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 17 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 18 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 19 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 20 with FileTypeManager

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

the class VfsUtil method processFileRecursivelyWithoutIgnored.

public static void processFileRecursivelyWithoutIgnored(@NotNull VirtualFile root, @NotNull Processor<VirtualFile> processor) {
    FileTypeManager ftm = FileTypeManager.getInstance();
    visitChildrenRecursively(root, new VirtualFileVisitor() {

        @NotNull
        @Override
        public Result visitFileEx(@NotNull VirtualFile file) {
            if (!processor.process(file))
                return skipTo(root);
            return file.isDirectory() && ftm.isFileIgnored(file) ? SKIP_CHILDREN : CONTINUE;
        }
    });
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

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