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());
}
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);
}
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);
}
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) {
}
}
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;
}
});
}
Aggregations