Search in sources :

Example 1 with EnforcedPlainTextFileTypeManager

use of com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager in project intellij-community by JetBrains.

the class EnforcedPlaintTextFileTypeManagerTest method testMarkAsPlainText.

public void testMarkAsPlainText() {
    EnforcedPlainTextFileTypeManager manager = EnforcedPlainTextFileTypeManager.getInstance();
    VirtualFile file = myFixture.getTempDirFixture().createFile("test.java");
    FileType originalType = file.getFileType();
    assertEquals("JAVA", originalType.getName());
    manager.markAsPlainText(getProject(), file);
    // reparseFiles in invokeLater
    UIUtil.dispatchAllInvocationEvents();
    FileType changedType = file.getFileType();
    assertEquals(EnforcedPlainTextFileTypeFactory.ENFORCED_PLAIN_TEXT, changedType.getName());
    manager.resetOriginalFileType(getProject(), file);
    FileType revertedType = file.getFileType();
    assertEquals(originalType, revertedType);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager)

Example 2 with EnforcedPlainTextFileTypeManager

use of com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager in project intellij-community by JetBrains.

the class MarkAsOriginalTypeAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
    if (project == null || typeManager == null)
        return;
    JBIterable<VirtualFile> selectedFiles = JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)).filter(file -> !file.isDirectory() && typeManager.isMarkedAsPlainText(file));
    typeManager.resetOriginalFileType(project, VfsUtilCore.toVirtualFileArray(selectedFiles.toList()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager)

Example 3 with EnforcedPlainTextFileTypeManager

use of com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager in project intellij-community by JetBrains.

the class MarkAsPlainTextAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
    if (project == null || typeManager == null)
        return;
    JBIterable<VirtualFile> selectedFiles = JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)).filter(file -> EnforcedPlainTextFileTypeManager.isApplicableFor(file) && !typeManager.isMarkedAsPlainText(file));
    typeManager.markAsPlainText(project, VfsUtilCore.toVirtualFileArray(selectedFiles.toList()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager)

Example 4 with EnforcedPlainTextFileTypeManager

use of com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager in project intellij-community by JetBrains.

the class MarkAsPlainTextAction method update.

@Override
public void update(AnActionEvent e) {
    EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
    JBIterable<VirtualFile> selectedFiles = typeManager == null ? JBIterable.empty() : JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)).filter(file -> EnforcedPlainTextFileTypeManager.isApplicableFor(file) && !typeManager.isMarkedAsPlainText(file));
    boolean enabled = e.getProject() != null && !selectedFiles.isEmpty();
    e.getPresentation().setEnabledAndVisible(enabled);
    e.getPresentation().setIcon(EnforcedPlainTextFileTypeFactory.ENFORCED_PLAIN_TEXT_ICON);
}
Also used : EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBIterable(com.intellij.util.containers.JBIterable) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) EnforcedPlainTextFileTypeFactory(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeFactory) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) VirtualFile(com.intellij.openapi.vfs.VirtualFile) EnforcedPlainTextFileTypeManager(com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager)

Example 5 with EnforcedPlainTextFileTypeManager

use of com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager 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)

Aggregations

EnforcedPlainTextFileTypeManager (com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Project (com.intellij.openapi.project.Project)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 VfsUtilCore (com.intellij.openapi.vfs.VfsUtilCore)2 JBIterable (com.intellij.util.containers.JBIterable)2 ActionsBundle (com.intellij.idea.ActionsBundle)1 EnforcedPlainTextFileTypeFactory (com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeFactory)1 FileType (com.intellij.openapi.fileTypes.FileType)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 Set (java.util.Set)1