Java Code Examples for com.intellij.openapi.fileTypes.PlainTextFileType#INSTANCE

The following examples show how to use com.intellij.openapi.fileTypes.PlainTextFileType#INSTANCE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParameterNameHintsConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static EditorTextField createEditorField(@Nonnull String text, @Nullable TextRange rangeToSelect) {
  Document document = EditorFactory.getInstance().createDocument(text);
  EditorTextField field = new EditorTextField(document, null, PlainTextFileType.INSTANCE, false, false);
  field.setPreferredSize(new Dimension(200, 350));
  field.addSettingsProvider(editor -> {
    editor.setVerticalScrollbarVisible(true);
    editor.setHorizontalScrollbarVisible(true);
    editor.getSettings().setAdditionalLinesCount(2);
    if (rangeToSelect != null) {
      editor.getCaretModel().moveToOffset(rangeToSelect.getStartOffset());
      editor.getScrollingModel().scrollVertically(document.getTextLength() - 1);
      editor.getSelectionModel().setSelection(rangeToSelect.getStartOffset(), rangeToSelect.getEndOffset());
    }
  });
  return field;
}
 
Example 2
Source File: DiffUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static EditorHighlighter createEditorHighlighter(@Nullable Project project, @Nonnull DocumentContent content) {
  FileType type = content.getContentType();
  VirtualFile file = content.getHighlightFile();
  Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);

  EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
  if (language != null) {
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file);
    return highlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme());
  }
  if (file != null) {
    if ((type == null || type == PlainTextFileType.INSTANCE) || file.getFileType() == type || file instanceof LightVirtualFile) {
      return highlighterFactory.createEditorHighlighter(project, file);
    }
  }
  if (type != null) {
    return highlighterFactory.createEditorHighlighter(project, type);
  }
  return null;
}
 
Example 3
Source File: DiffContentFactoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static DocumentContent createImpl(@javax.annotation.Nullable Project project,
                                          @Nonnull String text,
                                          @Nullable FileType fileType,
                                          @Nullable String fileName,
                                          @Nullable VirtualFile highlightFile,
                                          @javax.annotation.Nullable Charset charset,
                                          @javax.annotation.Nullable Boolean bom,
                                          boolean respectLineSeparators,
                                          boolean readOnly) {
  if (UnknownFileType.INSTANCE == fileType) fileType = PlainTextFileType.INSTANCE;

  // TODO: detect invalid (different across the file) separators ?
  LineSeparator separator = respectLineSeparators ? StringUtil.detectSeparators(text) : null;
  String correctedContent = StringUtil.convertLineSeparators(text);

  Document document = createDocument(project, correctedContent, fileType, fileName, readOnly);
  DocumentContent content = new DocumentContentImpl(project, document, fileType, highlightFile, separator, charset, bom);

  if (fileName != null) content.putUserData(DiffUserDataKeysEx.FILE_NAME, fileName);

  return content;
}
 
Example 4
Source File: AnnotateRevisionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
protected VirtualFile getFile(@Nonnull AnActionEvent e) {
  VcsFileRevision revision = getFileRevision(e);
  if (revision == null) return null;

  final FileType currentFileType = myAnnotation.getFile().getFileType();
  FilePath filePath = (revision instanceof VcsFileRevisionEx ? ((VcsFileRevisionEx)revision).getPath() : VcsUtil.getFilePath(myAnnotation.getFile()));
  return new VcsVirtualFile(filePath.getPath(), revision, VcsFileSystem.getInstance()) {
    @Nonnull
    @Override
    public FileType getFileType() {
      FileType type = super.getFileType();
      if (!type.isBinary()) return type;
      if (!currentFileType.isBinary()) return currentFileType;
      return PlainTextFileType.INSTANCE;
    }
  };
}
 
Example 5
Source File: PostfixDescriptionPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void showUsages(@Nonnull JPanel panel, @Nullable TextDescriptor exampleUsage) {
  String text = "";
  FileType fileType = PlainTextFileType.INSTANCE;
  if (exampleUsage != null) {
    try {
      text = exampleUsage.getText();
      String name = exampleUsage.getFileName();
      FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx();
      String extension = fileTypeManager.getExtension(name);
      fileType = fileTypeManager.getFileTypeByExtension(extension);
    }
    catch (IOException e) {
      LOG.error(e);
    }
  }

  ((ActionUsagePanel)panel.getComponent(0)).reset(text, fileType);
  panel.repaint();
}
 
Example 6
Source File: FileProviderFactory.java    From CodeGen with MIT License 6 votes vote down vote up
/**
 * 根据文件后缀获取文件类型
 */
public static FileType getFileType(String suffix) {
    if (StringUtils.isBlank(suffix)) {
        return PlainTextFileType.INSTANCE;
    }
    String extension = suffix.toLowerCase();
    FileType fileType = FILE_TYPES.get(extension);
    if (fileType == null) {
        for (FileType ft : FileTypeManager.getInstance().getRegisteredFileTypes()) {
            if (extension.equals(ft.getDefaultExtension())) {
                fileType = ft;
                FILE_TYPES.put(extension, ft);
                break;
            }
        }
    }
    return StringUtils.nullOr(fileType, PlainTextFileType.INSTANCE);
}
 
Example 7
Source File: TabbedLanguageCodeStylePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Nonnull
@Override
protected FileType getFileType() {
  Language language = getDefaultLanguage();
  return language != null ? language.getAssociatedFileType() : PlainTextFileType.INSTANCE;
}
 
Example 8
Source File: TabbedLanguageCodeStylePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Nonnull
@Override
protected FileType getFileType() {
  Language language = TabbedLanguageCodeStylePanel.this.getDefaultLanguage();
  return language != null ? language.getAssociatedFileType() : PlainTextFileType.INSTANCE;
}
 
Example 9
Source File: TextViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public TextViewer(@Nonnull Document document, @Nonnull Project project, boolean embeddedIntoDialogWrapper, boolean useSoftWraps) {
  super(document, project, PlainTextFileType.INSTANCE, true, false);

  myEmbeddedIntoDialogWrapper = embeddedIntoDialogWrapper;
  myUseSoftWraps = useSoftWraps;
  setFontInheritedFromLAF(false);
}
 
Example 10
Source File: DummyHolder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public FileType getFileType() {
  PsiElement context = getContext();
  if (context != null) {
    PsiFile containingFile = context.getContainingFile();
    if (containingFile != null) return containingFile.getFileType();
  }
  final LanguageFileType fileType = myLanguage.getAssociatedFileType();
  return fileType != null ? fileType : PlainTextFileType.INSTANCE;
}
 
Example 11
Source File: DocumentationManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String generateFileDoc(@Nonnull PsiFile psiFile, boolean withUrl) {
  VirtualFile file = PsiUtilCore.getVirtualFile(psiFile);
  File ioFile = file == null || !file.isInLocalFileSystem() ? null : VfsUtilCore.virtualToIoFile(file);
  BasicFileAttributes attr = null;
  try {
    attr = ioFile == null ? null : Files.readAttributes(Paths.get(ioFile.toURI()), BasicFileAttributes.class);
  }
  catch (Exception ignored) {
  }
  if (attr == null) return null;
  FileType type = file.getFileType();
  String typeName = type == UnknownFileType.INSTANCE ? "Unknown" : type == PlainTextFileType.INSTANCE ? "Text" : type instanceof ArchiveFileType ? "Archive" : type.getId();
  String languageName = type.isBinary() ? "" : psiFile.getLanguage().getDisplayName();
  return (withUrl ? DocumentationMarkup.DEFINITION_START + file.getPresentableUrl() + DocumentationMarkup.DEFINITION_END + DocumentationMarkup.CONTENT_START : "") +
         getVcsStatus(psiFile.getProject(), file) +
         getScope(psiFile.getProject(), file) +
         "<p><span class='grayed'>Size:</span> " +
         StringUtil.formatFileSize(attr.size()) +
         "<p><span class='grayed'>Type:</span> " +
         typeName +
         (type.isBinary() || typeName.equals(languageName) ? "" : " (" + languageName + ")") +
         "<p><span class='grayed'>Modified:</span> " +
         DateFormatUtil.formatDateTime(attr.lastModifiedTime().toMillis()) +
         "<p><span class='grayed'>Created:</span> " +
         DateFormatUtil.formatDateTime(attr.creationTime().toMillis()) +
         (withUrl ? DocumentationMarkup.CONTENT_END : "");
}
 
Example 12
Source File: IdeConsoleRootType.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Image substituteIcon(@Nonnull Project project, @Nonnull VirtualFile file) {
  if (file.isDirectory()) return null;
  FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(file.getNameSequence());
  Image icon = fileType == UnknownFileType.INSTANCE || fileType == PlainTextFileType.INSTANCE ? AllIcons.Debugger.Console : ObjectUtils.notNull(fileType.getIcon(), AllIcons.Debugger.Console);
  return ImageEffects.layered(icon, AllIcons.Nodes.RunnableMark);
}
 
Example 13
Source File: MergeVersion.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public FileType getContentType() {
  VirtualFile file = getFile();
  if (file == null) return PlainTextFileType.INSTANCE;
  return file.getFileType();
}
 
Example 14
Source File: EditorComboBox.java    From consulo with Apache License 2.0 4 votes vote down vote up
public EditorComboBox(String text) {
  this(EditorFactory.getInstance().createDocument(text), null, PlainTextFileType.INSTANCE);
}
 
Example 15
Source File: PrintManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static TextPainter doInitTextPainter(@Nonnull final DocumentEx doc, Project project) {
  EditorHighlighter highlighter = HighlighterFactory.createHighlighter(project, "unknown");
  highlighter.setText(doc.getCharsSequence());
  return new TextPainter(doc, highlighter, "unknown", project, PlainTextFileType.INSTANCE, null);
}
 
Example 16
Source File: PsiPlainTextFileImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public PsiPlainTextFileImpl(FileViewProvider viewProvider) {
  super(PlainTextTokenTypes.PLAIN_TEXT_FILE, PlainTextTokenTypes.PLAIN_TEXT_FILE, viewProvider);
  myFileType = viewProvider.getBaseLanguage() != PlainTextLanguage.INSTANCE ? PlainTextFileType.INSTANCE : viewProvider.getFileType();
}
 
Example 17
Source File: MergePanel2.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static FileType getContentType(DiffRequest diffData) {
  FileType contentType = diffData.getContents()[1].getContentType();
  if (contentType == null) contentType = PlainTextFileType.INSTANCE;
  return contentType;
}
 
Example 18
Source File: MergePanel2.java    From consulo with Apache License 2.0 4 votes vote down vote up
public FileType getContentType() {
  return myData == null ? PlainTextFileType.INSTANCE : getContentType(myData);
}
 
Example 19
Source File: MockVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public FileType getFileType() {
  return PlainTextFileType.INSTANCE;
}
 
Example 20
Source File: ScriptDialog.java    From PackageTemplates with Apache License 2.0 4 votes vote down vote up
private void createEditorField() {
    PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText("Script", PlainTextLanguage.INSTANCE, code);

    etfCode = new EditorTextField(PsiDocumentManager.getInstance(project).getDocument(psiFile), project, PlainTextFileType.INSTANCE);
    etfCode.setOneLineMode(false);
}