use of com.intellij.ide.highlighter.ProjectFileType in project intellij-community by JetBrains.
the class OpenFileAction method doOpenFile.
private static void doOpenFile(@Nullable Project project, @NotNull List<VirtualFile> result) {
for (VirtualFile file : result) {
if (file.isDirectory()) {
Project openedProject;
if (ProjectAttachProcessor.canAttachToProject()) {
EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
openedProject = PlatformProjectOpenProcessor.doOpenProject(file, project, -1, null, options);
} else {
openedProject = ProjectUtil.openOrImport(file.getPath(), project, false);
}
FileChooserUtil.setLastOpenedFile(openedProject, file);
return;
}
// try to open as a project - unless the file is an .ipr of the current one
if ((project == null || !file.equals(project.getProjectFile())) && OpenProjectFileChooserDescriptor.isProjectFile(file)) {
int answer = file.getFileType() instanceof ProjectFileType ? Messages.YES : Messages.showYesNoCancelDialog(project, IdeBundle.message("message.open.file.is.project", file.getName()), IdeBundle.message("title.open.project"), IdeBundle.message("message.open.file.is.project.open.as.project"), IdeBundle.message("message.open.file.is.project.open.as.file"), IdeBundle.message("button.cancel"), Messages.getQuestionIcon());
if (answer == Messages.CANCEL)
return;
if (answer == Messages.YES) {
Project openedProject = ProjectUtil.openOrImport(file.getPath(), project, false);
if (openedProject != null) {
FileChooserUtil.setLastOpenedFile(openedProject, file);
}
return;
}
}
FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(file, project);
if (type == null)
return;
if (project != null) {
openFile(file, project);
} else {
PlatformProjectOpenProcessor processor = PlatformProjectOpenProcessor.getInstanceIfItExists();
if (processor != null) {
processor.doOpenProject(file, null, false);
}
}
}
}
use of com.intellij.ide.highlighter.ProjectFileType in project intellij-community by JetBrains.
the class FileTypesTest method testReDetectOnContentsChange.
public void testReDetectOnContentsChange() throws IOException {
final FileTypeRegistry fileTypeManager = FileTypeRegistry.getInstance();
assertTrue(fileTypeManager.getClass().getName(), fileTypeManager instanceof FileTypeManagerImpl);
FileType fileType = fileTypeManager.getFileTypeByFileName("x" + ModuleFileType.DOT_DEFAULT_EXTENSION);
assertTrue(fileType.toString(), fileType instanceof ModuleFileType);
fileType = fileTypeManager.getFileTypeByFileName("x" + ProjectFileType.DOT_DEFAULT_EXTENSION);
assertTrue(fileType.toString(), fileType instanceof ProjectFileType);
FileType module = fileTypeManager.findFileTypeByName("IDEA_MODULE");
assertNotNull(module);
assertFalse(module.equals(PlainTextFileType.INSTANCE));
FileType project = fileTypeManager.findFileTypeByName("IDEA_PROJECT");
assertNotNull(project);
assertFalse(project.equals(PlainTextFileType.INSTANCE));
final Set<VirtualFile> detectorCalled = ContainerUtil.newConcurrentSet();
FileTypeRegistry.FileTypeDetector detector = new FileTypeRegistry.FileTypeDetector() {
@Nullable
@Override
public FileType detect(@NotNull VirtualFile file, @NotNull ByteSequence firstBytes, @Nullable CharSequence firstCharsIfText) {
detectorCalled.add(file);
String text = firstCharsIfText.toString();
FileType result = text.startsWith("TYPE:") ? fileTypeManager.findFileTypeByName(StringUtil.trimStart(text, "TYPE:")) : null;
log("T: my detector run for " + file.getName() + "; result: " + (result == null ? null : result.getName()));
return result;
}
@Override
public int getVersion() {
return 0;
}
};
Extensions.getRootArea().getExtensionPoint(FileTypeRegistry.FileTypeDetector.EP_NAME).registerExtension(detector);
myFileTypeManager.toLog = true;
try {
log("T: ------ akjdhfksdjgf");
File f = createTempFile("xx.asfdasdfas", "akjdhfksdjgf");
VirtualFile vFile = getVirtualFile(f);
ensureRedetected(vFile, detectorCalled);
assertTrue(vFile.getFileType().toString(), vFile.getFileType() instanceof PlainTextFileType);
log("T: ------ TYPE:IDEA_MODULE");
setFileText(vFile, "TYPE:IDEA_MODULE");
ensureRedetected(vFile, detectorCalled);
assertTrue(vFile.getFileType().toString(), vFile.getFileType() instanceof ModuleFileType);
log("T: ------ TYPE:IDEA_PROJECT");
setFileText(vFile, "TYPE:IDEA_PROJECT");
ensureRedetected(vFile, detectorCalled);
assertTrue(vFile.getFileType().toString(), vFile.getFileType() instanceof ProjectFileType);
log("T: ------");
} finally {
Extensions.getRootArea().getExtensionPoint(FileTypeRegistry.FileTypeDetector.EP_NAME).unregisterExtension(detector);
myFileTypeManager.toLog = false;
}
}
Aggregations