Java 类com.intellij.openapi.fileTypes.ex.FileTypeChooser 实例源码

项目:intellij-ce-playground    文件:UnknownFileTypeDiffRequest.java   
@NotNull
@Override
public JComponent getComponent(@NotNull final DiffContext context) {
  final SimpleColoredComponent label = new SimpleColoredComponent();
  label.append("Can't show diff for unknown file type. ",
               new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getInactiveTextColor()));
  if (myFileName != null) {
    label.append("Associate", SimpleTextAttributes.LINK_ATTRIBUTES, new Runnable() {
      @Override
      public void run() {
        DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
          @Override
          public void run() {
            FileType type = FileTypeChooser.associateFileType(myFileName);
            if (type != null) onSuccess(context);
          }
        });
      }
    });
    LinkMouseListenerBase.installSingleTagOn(label);
  }
  return DiffUtil.createMessagePanel(label);
}
项目:intellij-ce-playground    文件:ChangeDiffRequestPresentable.java   
public static boolean checkAssociate(final Project project, String fileName, DiffChainContext context) {
  final String pattern = FileUtilRt.getExtension(fileName).toLowerCase();
  if (context.contains(pattern)) return false;
  int rc = Messages.showOkCancelDialog(project,
                               VcsBundle.message("diff.unknown.file.type.prompt", fileName),
                               VcsBundle.message("diff.unknown.file.type.title"),
                                 VcsBundle.message("diff.unknown.file.type.associate"),
                                 CommonBundle.getCancelButtonText(),
                               Messages.getQuestionIcon());
  if (rc == Messages.OK) {
    FileType fileType = FileTypeChooser.associateFileType(fileName);
    return fileType != null && !fileType.isBinary();
  } else {
    context.add(pattern);
  }
  return false;
}
项目:intellij-ce-playground    文件:PatchApplier.java   
private boolean fileTypesAreOk(final List<Pair<VirtualFile, ApplyTextFilePatch>> textPatches) {
  for (Pair<VirtualFile, ApplyTextFilePatch> textPatch : textPatches) {
    final VirtualFile file = textPatch.getFirst();
    if (! file.isDirectory()) {
      FileType fileType = file.getFileType();
      if (fileType == FileTypes.UNKNOWN) {
        fileType = FileTypeChooser.associateFileType(file.getName());
        if (fileType == null) {
          showError(myProject, "Cannot apply patch. File " + file.getPresentableName() + " type not defined.", true);
          return false;
        }
      }
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:CreateFileAction.java   
@Override
public boolean canClose(final String inputString) {
  if (inputString.length() == 0) {
    return super.canClose(inputString);
  }

  final PsiDirectory psiDirectory = getDirectory();

  final Project project = psiDirectory.getProject();
  final boolean[] result = {false};
  DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
    @Override
    public void run() {
      final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(new FakeVirtualFile(psiDirectory.getVirtualFile(), getFileName(inputString)),
                                                                        project);
      result[0] = type != null && MyValidator.super.canClose(getFileName(inputString));
    }
  });
  return result[0];
}
项目:intellij-ce-playground    文件:FileTemplateConfigurable.java   
@Override
public void apply() throws ConfigurationException {
  if (myTemplate != null) {
    myTemplate.setText(myTemplateEditor.getDocument().getText());
    String name = myNameField.getText();
    String extension = myExtensionField.getText();
    String filename = name + "." + extension;
    if (name.length() == 0 || !isValidFilename(filename)) {
      throw new ConfigurationException(IdeBundle.message("error.invalid.template.file.name.or.extension"));
    }
    FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(filename);
    if (fileType == UnknownFileType.INSTANCE) {
      FileTypeChooser.associateFileType(filename);
    }
    myTemplate.setName(name);
    myTemplate.setExtension(extension);
    myTemplate.setReformatCode(myAdjustBox.isSelected());
    myTemplate.setLiveTemplateEnabled(myLiveTemplateBox.isSelected());
  }
  myModified = false;
}
项目:tools-idea    文件:ChangeDiffRequestPresentable.java   
public static boolean checkAssociate(final Project project, final FilePath file, DiffChainContext context) {
  final String pattern = FileUtilRt.getExtension(file.getName()).toLowerCase();
  if (context.contains(pattern)) return false;
  int rc = Messages.showOkCancelDialog(project,
                               VcsBundle.message("diff.unknown.file.type.prompt", file.getName()),
                               VcsBundle.message("diff.unknown.file.type.title"),
                                 VcsBundle.message("diff.unknown.file.type.associate"),
                                 CommonBundle.getCancelButtonText(),
                               Messages.getQuestionIcon());
  if (rc == 0) {
    FileType fileType = FileTypeChooser.associateFileType(file.getName());
    return fileType != null && !fileType.isBinary();
  } else {
    context.add(pattern);
  }
  return false;
}
项目:tools-idea    文件:PatchApplier.java   
private boolean fileTypesAreOk(final List<Pair<VirtualFile, ApplyTextFilePatch>> textPatches) {
  for (Pair<VirtualFile, ApplyTextFilePatch> textPatch : textPatches) {
    final VirtualFile file = textPatch.getFirst();
    if (! file.isDirectory()) {
      FileType fileType = file.getFileType();
      if (fileType == FileTypes.UNKNOWN) {
        fileType = FileTypeChooser.associateFileType(file.getPresentableName());
        if (fileType == null) {
          showError(myProject, "Cannot apply patch. File " + file.getPresentableName() + " type not defined.", true);
          return false;
        }
      }
    }
  }
  return true;
}
项目:consulo    文件:UnknownFileTypeDiffRequest.java   
@Nonnull
@Override
public JComponent getComponent(@Nonnull final DiffContext context) {
  final SimpleColoredComponent label = new SimpleColoredComponent();
  label.setTextAlign(SwingConstants.CENTER);
  label.append("Can't show diff for unknown file type. ",
               new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getInactiveTextColor()));
  if (myFileName != null) {
    label.append("Associate", SimpleTextAttributes.LINK_ATTRIBUTES, new Runnable() {
      @Override
      public void run() {
        FileType type = FileTypeChooser.associateFileType(myFileName);
        if (type != null) onSuccess(context);
      }
    });
    LinkMouseListenerBase.installSingleTagOn(label);
  }
  return JBUI.Panels.simplePanel(label).withBorder(JBUI.Borders.empty(5));
}
项目:consulo    文件:ChangeDiffRequestPresentable.java   
public static boolean checkAssociate(final Project project, String fileName, DiffChainContext context) {
  final String pattern = FileUtilRt.getExtension(fileName).toLowerCase();
  if (context.contains(pattern)) return false;
  int rc = Messages.showOkCancelDialog(project,
                                       VcsBundle.message("diff.unknown.file.type.prompt", fileName),
                                       VcsBundle.message("diff.unknown.file.type.title"),
                                       VcsBundle.message("diff.unknown.file.type.associate"),
                                       CommonBundle.getCancelButtonText(),
                                       Messages.getQuestionIcon());
  if (rc == Messages.OK) {
    FileType fileType = FileTypeChooser.associateFileType(fileName);
    return fileType != null && !fileType.isBinary();
  } else {
    context.add(pattern);
  }
  return false;
}
项目:consulo    文件:PathsVerifier.java   
private boolean isFileTypeOk(@Nonnull VirtualFile file) {
  FileType fileType = file.getFileType();
  if (fileType == UnknownFileType.INSTANCE) {
    fileType = FileTypeChooser.associateFileType(file.getName());
    if (fileType == null) {
      PatchApplier
              .showError(myProject, "Cannot apply content for " + file.getPresentableName() + " file from patch because its type not defined.",
                         true);
      return false;
    }
  }
  if (fileType.isBinary()) {
    PatchApplier.showError(myProject, "Cannot apply file " + file.getPresentableName() + " from patch because it is binary.", true);
    return false;
  }
  return true;
}
项目:consulo    文件:FileTemplateConfigurable.java   
@RequiredDispatchThread
@Override
public void apply() throws ConfigurationException {
  if (myTemplate != null) {
    myTemplate.setText(myTemplateEditor.getDocument().getText());
    String name = myNameField.getText();
    String extension = myExtensionField.getText();
    String filename = name + "." + extension;
    if (name.length() == 0 || !isValidFilename(filename)) {
      throw new ConfigurationException(IdeBundle.message("error.invalid.template.file.name.or.extension"));
    }
    FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(filename);
    if (fileType == UnknownFileType.INSTANCE) {
      FileTypeChooser.associateFileType(filename);
    }
    myTemplate.setName(name);
    myTemplate.setExtension(extension);
    myTemplate.setReformatCode(myAdjustBox.isSelected());
    myTemplate.setLiveTemplateEnabled(myLiveTemplateBox.isSelected());
  }
  myModified = false;
}
项目:intellij-ce-playground    文件:ExtractIncludeDialog.java   
@Override
protected void doOKAction() {
  final Project project = myCurrentDirectory.getProject();

  final String directoryName = myTargetDirectoryField.getText().replace(File.separatorChar, '/');
  final String targetFileName = getTargetFileName();

  if (isFileExist(directoryName, targetFileName)) {
    Messages.showErrorDialog(project, RefactoringBundle.message("file.already.exist", targetFileName), RefactoringBundle.message("file.already.exist.title"));
    return;
  }

  final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(targetFileName);
  if (type == null) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          try {
            PsiDirectory targetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(project), directoryName);
            targetDirectory.checkCreateFile(targetFileName);
            final String webPath = PsiFileSystemItemUtil.getRelativePath(myCurrentDirectory, targetDirectory);
            myTargetDirectory = webPath == null ? null : targetDirectory;
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, e.getMessage(), null, project);
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  }, RefactoringBundle.message("create.directory"), null);
  if (myTargetDirectory == null) return;
  super.doOKAction();
}
项目:tools-idea    文件:OpenFileAction.java   
private static void doOpenFile(@Nullable final Project project,
                               @NotNull final List<VirtualFile> result) {
  for (final VirtualFile file : result) {
    if (file.isDirectory()) {
      Project openedProject;
      if (ProjectAttachProcessor.canAttachToProject()) {
        openedProject = PlatformProjectOpenProcessor.doOpenProject(file, project, false, -1, null, false);
      }
      else {
        openedProject = ProjectUtil.openOrImport(file.getPath(), project, false);
      }
      FileChooserUtil.setLastOpenedFile(openedProject, file);
      return;
    }

    if (OpenProjectFileChooserDescriptor.isProjectFile(file)) {
      int answer = Messages.showYesNoDialog(project,
                                            IdeBundle.message("message.open.file.is.project", file.getName()),
                                            IdeBundle.message("title.open.project"),
                                            Messages.getQuestionIcon());
      if (answer == 0) {
        FileChooserUtil.setLastOpenedFile(ProjectUtil.openOrImport(file.getPath(), project, false), 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);
      }
    }
  }
}
项目:tools-idea    文件:CreateFileAction.java   
@Override
public boolean canClose(String inputString) {
  if (inputString.length() == 0) {
    return super.canClose(inputString);
  }

  final PsiDirectory psiDirectory = getDirectory();

  final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(new FakeVirtualFile(psiDirectory.getVirtualFile(), getFileName(inputString)),
                                                                    psiDirectory.getProject());
  return type != null && super.canClose(getFileName(inputString));
}
项目:tools-idea    文件:ExtractIncludeDialog.java   
@Override
protected void doOKAction() {
  final Project project = myCurrentDirectory.getProject();

  final String directoryName = myTargetDirectoryField.getText().replace(File.separatorChar, '/');
  final String targetFileName = getTargetFileName();

  if (isFileExist(directoryName, targetFileName)) {
    Messages.showErrorDialog(project, RefactoringBundle.message("file.already.exist", targetFileName), RefactoringBundle.message("file.already.exist.title"));
    return;
  }

  final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(targetFileName);
  if (type == null) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          try {
            PsiDirectory targetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(project), directoryName);
            targetDirectory.checkCreateFile(targetFileName);
            final String webPath = PsiFileSystemItemUtil.getRelativePath(myCurrentDirectory, targetDirectory);
            myTargetDirectory = webPath == null ? null : targetDirectory;
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, e.getMessage(), null, project);
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  }, RefactoringBundle.message("create.directory"), null);
  if (myTargetDirectory == null) return;
  super.doOKAction();
}
项目:consulo    文件:OpenFileAction.java   
private static void doOpenFile(@Nullable final Project project,
                               @Nonnull final List<VirtualFile> result) {
  for (final VirtualFile file : result) {
    if (file.isDirectory()) {
      Project openedProject = ProjectUtil.open(file.getPath(), project, false);
      FileChooserUtil.setLastOpenedFile(openedProject, file);
      return;
    }

    if (OpenProjectFileChooserDescriptor.canOpen(file)) {
      int answer = Messages.showYesNoDialog(project,
                                            IdeBundle.message("message.open.file.is.project", file.getName()),
                                            IdeBundle.message("title.open.project"),
                                            Messages.getQuestionIcon());
      if (answer == 0) {
        FileChooserUtil.setLastOpenedFile(ProjectUtil.open(file.getPath(), project, false), file);
        return;
      }
    }

    FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(file, project);
    if (type == null) return;

    if (project != null) {
      openFile(file, project);
    }
    else {
      PlatformProjectOpenProcessor processor = PlatformProjectOpenProcessor.getInstance();
      processor.doOpenProject(file, null, false);
    }
  }
}
项目:consulo    文件:CreateFileAction.java   
@RequiredDispatchThread
@Override
public boolean canClose(final String inputString) {
  if (inputString.length() == 0) {
    return super.canClose(inputString);
  }

  final PsiDirectory psiDirectory = getDirectory();

  final Project project = psiDirectory.getProject();
  final boolean[] result = {false};
  FileTypeChooser.getKnownFileTypeOrAssociate(psiDirectory.getVirtualFile(), getFileName(inputString), project);
  result[0] = super.canClose(getFileName(inputString));
  return result[0];
}
项目:consulo    文件:ExtractIncludeDialog.java   
@Override
protected void doOKAction() {
  final Project project = myCurrentDirectory.getProject();

  final String directoryName = myTargetDirectoryField.getText().replace(File.separatorChar, '/');
  final String targetFileName = getTargetFileName();

  if (isFileExist(directoryName, targetFileName)) {
    Messages.showErrorDialog(project, RefactoringBundle.message("file.already.exist", targetFileName), RefactoringBundle.message("file.already.exist.title"));
    return;
  }

  final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(targetFileName);
  if (type == null) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          try {
            PsiDirectory targetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(project), directoryName);
            targetDirectory.checkCreateFile(targetFileName);
            final String webPath = PsiFileSystemItemUtil.getRelativePath(myCurrentDirectory, targetDirectory);
            myTargetDirectory = webPath == null ? null : targetDirectory;
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, e.getMessage(), null, project);
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  }, RefactoringBundle.message("create.directory"), null);
  if (myTargetDirectory == null) return;
  super.doOKAction();
}
项目:intellij-ce-playground    文件:AssociateFileTypeAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
  VirtualFile file = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE);
  FileTypeChooser.associateFileType(file.getName());
}
项目:tools-idea    文件:AssociateFileType.java   
public void actionPerformed(AnActionEvent e) {
  VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
  FileTypeChooser.associateFileType(file.getName());
}
项目:consulo    文件:AssociateFileType.java   
@Override
public void actionPerformed(AnActionEvent e) {
  VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
  FileTypeChooser.associateFileType(file.getName());
}