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

The following examples show how to use com.intellij.openapi.fileTypes.PlainTextFileType. These examples are extracted from open source projects. 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 Project: CodeGen   Source File: FileProviderFactory.java    License: 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 2
Source Project: PackageTemplates   Source File: CreateFileAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void doRun() {
        PsiDirectory psiParent = VFSHelper.findPsiDirByPath(project, file.getParentFile().getPath());
        if(psiParent==null){
            ReportHelper.setState(ExecutionState.FAILED);
            return;
        }

        try {
            PsiFile psiResultFile = PsiFileFactory.getInstance(project).createFileFromText(file.getName(), PlainTextFileType.INSTANCE, content);
//            PsiFile psiFile = psiDirectory.createFile(psiDirectory.createFile(file.getName()).getName());
//            psiFile.getVirtualFile().
            psiParent.add(psiResultFile);
        } catch (IncorrectOperationException ex){
            Logger.log("CreateFileAction " + ex.getMessage());
            Logger.printStack(ex);
            ReportHelper.setState(ExecutionState.FAILED);
            return;
        }
    }
 
Example 3
@NotNull
@Override
public Collection<AbstractTreeNode<?>> modify(@NotNull AbstractTreeNode<?> parent,
                                           @NotNull Collection<AbstractTreeNode<?>> children,
                                           ViewSettings settings) {
  ArrayList<AbstractTreeNode<?>> nodes = new ArrayList<>();
  for (AbstractTreeNode<?> child : children) {
    if (child instanceof PsiFileNode) {
      VirtualFile file = ((PsiFileNode) child).getVirtualFile();
      if (file != null && !file.isDirectory() && !(file.getFileType() instanceof PlainTextFileType)) {
        continue;
      }
    }
    nodes.add(child);
  }
  return nodes;
}
 
Example 4
Source Project: consulo   Source File: DiffUtil.java    License: 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 5
Source Project: consulo   Source File: DiffContentFactoryImpl.java    License: 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 6
Source Project: consulo   Source File: SelectionQuotingTypedHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
private void doTest(@Nonnull final String cs, @Nonnull String before, @Nonnull String expected) {
  final boolean smarterSelection = Registry.is("editor.smarterSelectionQuoting");
  Registry.get("editor.smarterSelectionQuoting").setValue(true);
  try {
    myFixture.configureByText(PlainTextFileType.INSTANCE, before);
    final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();

    performAction(myFixture.getProject(), new Runnable() {
      @Override
      public void run() {
        for (int i = 0, max = cs.length(); i < max; i++) {
          final char c = cs.charAt(i);
          typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext());
        }
      }
    });
    myFixture.checkResult(expected);
  } finally {
    Registry.get("editor.smarterSelectionQuoting").setValue(smarterSelection);
  }
}
 
Example 7
Source Project: consulo   Source File: SelectionQuotingTypedHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testRuby7852ErrantEditor() {
  myFixture.configureByText(PlainTextFileType.INSTANCE, "\"aaa\"\nbbb\n\n");
  myFixture.getEditor().getCaretModel().moveToOffset(0);
  myFixture.getEditor().getSelectionModel().setSelection(0, 5);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), '\'', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult("'aaa'\nbbb\n\n");

  myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3));
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), 'A', ((EditorEx)myFixture.getEditor()).getDataContext());
      typedAction.actionPerformed(myFixture.getEditor(), 'B', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.checkResult("'aaa'\nbbb\n\nAB");
}
 
Example 8
public SyntaxHighlighterOverEditorHighlighter(SyntaxHighlighter _highlighter, VirtualFile file, Project project) {
  if (file.getFileType() == PlainTextFileType.INSTANCE) { // optimization for large files, PlainTextSyntaxHighlighterFactory is slow
    highlighter = new PlainSyntaxHighlighter();
    lexer = highlighter.getHighlightingLexer();
  } else {
    highlighter = _highlighter;
    LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE);
    EditorHighlighter editorHighlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file);

    try {
      if (editorHighlighter instanceof LayeredLexerEditorHighlighter) {
        lexer = new LexerEditorHighlighterLexer(editorHighlighter, false);
      }
      else {
        lexer = highlighter.getHighlightingLexer();
      }
    }
    finally {
      LayeredLexer.ourDisableLayersFlag.set(null);
    }
  }
}
 
Example 9
Source Project: consulo   Source File: ExternalSystemTasksPanel.java    License: Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
private Location buildLocation() {
  if (mySelectedTaskProvider == null) {
    return null;
  }
  ExternalTaskExecutionInfo task = mySelectedTaskProvider.produce();
  if (task == null) {
    return null;
  }

  String projectPath = task.getSettings().getExternalProjectPath();
  String name = myExternalSystemId.getReadableName() + projectPath + StringUtil.join(task.getSettings().getTaskNames(), " ");
  // We create a dummy text file instead of re-using external system file in order to avoid clashing with other configuration producers.
  // For example gradle files are enhanced groovy scripts but we don't want to run them via regular IJ groovy script runners.
  // Gradle tooling api should be used for running gradle tasks instead. IJ execution sub-system operates on Location objects
  // which encapsulate PsiElement and groovy runners are automatically applied if that PsiElement IS-A GroovyFile.
  PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(name, PlainTextFileType.INSTANCE, "nichts");

  return new ExternalSystemTaskLocation(myProject, file, task);
}
 
Example 10
Source Project: consulo   Source File: ExportToFileUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true);
  ((DocumentImpl)document).setAcceptSlashR(true);

  myTextArea = EditorFactory.getInstance().createEditor(document, myProject, PlainTextFileType.INSTANCE, true);
  final EditorSettings settings = myTextArea.getSettings();
  settings.setLineNumbersShown(false);
  settings.setLineMarkerAreaShown(false);
  settings.setFoldingOutlineShown(false);
  settings.setRightMarginShown(false);
  settings.setAdditionalLinesCount(0);
  settings.setAdditionalColumnsCount(0);
  settings.setAdditionalPageAtBottom(false);
  ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor());
  return myTextArea.getComponent();
}
 
Example 11
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor) {
  if (file.getFileType() != PlainTextFileType.INSTANCE && !(file.getFileType() instanceof AbstractFileType)) return null;

  final String extension = file.getExtension();
  if (extension == null) {
    return null;
  }

  if (myEnabledExtensions.contains(extension) || isIgnoredFile(file)) return null;

  UnknownExtension fileFeatureForChecking = new UnknownExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP.getName(), file.getName());

  List<PluginDescriptor> allPlugins = PluginsAdvertiserHolder.getLoadedPluginDescriptors();

  Set<PluginDescriptor> byFeature = PluginsAdvertiser.findByFeature(allPlugins, fileFeatureForChecking);
  if (!byFeature.isEmpty()) {
    return createPanel(file, byFeature);

  }
  return null;
}
 
Example 12
Source Project: consulo   Source File: AnnotateRevisionAction.java    License: 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 13
Source Project: consulo   Source File: ParameterNameHintsConfigurable.java    License: 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 14
Source Project: consulo   Source File: PostfixDescriptionPanel.java    License: 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 15
Source Project: consulo   Source File: FileIncludeManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private PsiFileSystemItem doResolve(@Nonnull final FileIncludeInfo info, @Nonnull final PsiFile context) {
  if (info instanceof FileIncludeInfoImpl) {
    String id = ((FileIncludeInfoImpl)info).providerId;
    FileIncludeProvider provider = id == null ? null : myProviderMap.get(id);
    final PsiFileSystemItem resolvedByProvider = provider == null ? null : provider.resolveIncludedFile(info, context);
    if (resolvedByProvider != null) {
      return resolvedByProvider;
    }
  }

  PsiFileImpl psiFile = (PsiFileImpl)myPsiFileFactory.createFileFromText("dummy.txt", PlainTextFileType.INSTANCE, info.path);
  psiFile.setOriginalFile(context);
  return new FileReferenceSet(psiFile) {
    @Override
    protected boolean useIncludingFileAsContext() {
      return false;
    }
  }.resolve();
}
 
Example 16
Source Project: consulo   Source File: RenameDialog.java    License: Apache License 2.0 6 votes vote down vote up
protected void createNewNameComponent() {
  String[] suggestedNames = getSuggestedNames();
  myOldName = UsageViewUtil.getShortName(myPsiElement);
  myNameSuggestionsField = new NameSuggestionsField(suggestedNames, myProject, PlainTextFileType.INSTANCE, myEditor) {
    @Override
    protected boolean shouldSelectAll() {
      return myEditor == null || myEditor.getSettings().isPreselectRename();
    }
  };
  if (myPsiElement instanceof PsiFile && myEditor == null) {
    myNameSuggestionsField.selectNameWithoutExtension();
  }
  myNameChangedListener = new NameSuggestionsField.DataChanged() {
    @Override
    public void dataChanged() {
      processNewNameChanged();
    }
  };
  myNameSuggestionsField.addDataChangedListener(myNameChangedListener);

}
 
Example 17
Source Project: consulo   Source File: SelectionQuotingTypedHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
private void doTest(final char c, @Nonnull String before, @Nonnull String expected) {
  myFixture.configureByText(PlainTextFileType.INSTANCE, before);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult(expected);
}
 
Example 18
Source Project: consulo   Source File: ShowTextPopupHyperlinkInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(Project project) {
  Application.get().invokeLater(() -> {
    Document document = EditorFactory.getInstance().createDocument(StringUtil.convertLineSeparators(myText));
    EditorTextField textField = new EditorTextField(document, project, PlainTextFileType.INSTANCE, true, false) {
      @Override
      protected EditorEx createEditor() {
        EditorEx editor = super.createEditor();
        editor.getScrollPane().setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        editor.getScrollPane().setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        editor.getSettings().setUseSoftWraps(true);
        return editor;
      }
    };

    Window frame = TargetAWT.to(WindowManager.getInstance().getWindow(project));
    if(frame != null) {
      Dimension size = frame.getSize();
      if(size != null) {
        textField.setPreferredSize(new Dimension(size.width / 2, size.height / 2));
      }
    }

    JBPopupFactory.getInstance()
            .createComponentPopupBuilder(textField, textField)
            .setTitle(myTitle)
            .setResizable(true)
            .setMovable(true)
            .setRequestFocus(true)
            .createPopup()
            .showCenteredInCurrentWindow(project);
  });
}
 
Example 19
Source Project: consulo   Source File: DummyHolder.java    License: 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 20
Source Project: consulo   Source File: TextViewer.java    License: 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 21
Source Project: consulo   Source File: ApplyPatchDifferentiatedDialog.java    License: Apache License 2.0 5 votes vote down vote up
public static FileChooserDescriptor createSelectPatchDescriptor() {
  return new FileChooserDescriptor(true, false, false, false, false, false) {
    @Override
    public boolean isFileSelectable(VirtualFile file) {
      return file.getFileType() == PatchFileType.INSTANCE || file.getFileType() == PlainTextFileType.INSTANCE;
    }
  };
}
 
Example 22
Source Project: consulo   Source File: ChangeListChooserPanel.java    License: Apache License 2.0 5 votes vote down vote up
public MyEditorComboBox(Project project) {
  super(PREF_WIDTH);
  setEditor(new StringComboboxEditor(project, PlainTextFileType.INSTANCE, this) {
    @Override
    protected void onEditorCreate(EditorEx editor) {
      super.onEditorCreate(editor);
      getDocument().putUserData(CONTINUE_RUN_COMPLETION, true);
    }
  });
}
 
Example 23
Source Project: consulo   Source File: TemplateCommentPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void initEditor() {
  if (myEditor == null) {
    myPreviewEditorPanel.removeAll();
    EditorFactory editorFactory = EditorFactory.getInstance();
    myDocument = editorFactory.createDocument("");

    myEditor = editorFactory.createEditor(myDocument, myProject, ObjectUtil.notNull(myFileType, PlainTextFileType.INSTANCE), true);
    CopyrightConfigurable.setupEditor(myEditor);

    myPreviewEditorPanel.add(myEditor.getComponent(), BorderLayout.CENTER);
  }
}
 
Example 24
Source Project: consulo   Source File: DocumentationManager.java    License: 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 25
Source Project: consulo   Source File: TabbedLanguageCodeStylePanel.java    License: 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 26
Source Project: consulo   Source File: TabbedLanguageCodeStylePanel.java    License: 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 27
@Nonnull
@Override
protected FileType getFileType() {
  if (getDefaultLanguage() != null) {
    FileType assocType = getDefaultLanguage().getAssociatedFileType();
    if (assocType != null) {
      return assocType;
    }
  }
  return PlainTextFileType.INSTANCE;
}
 
Example 28
Source Project: consulo   Source File: DiffPreviewPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public DiffContent[] getContents() {
  return new DiffContent[]{
          new SimpleContent(LEFT_TEXT, PlainTextFileType.INSTANCE),
          new SimpleContent(CENTER_TEXT, PlainTextFileType.INSTANCE),
          new SimpleContent(RIGHT_TEXT, PlainTextFileType.INSTANCE)
  };
}
 
Example 29
Source Project: consulo   Source File: IdeConsoleRootType.java    License: 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 30
Source Project: consulo   Source File: EditorComboWithBrowseButton.java    License: Apache License 2.0 5 votes vote down vote up
public EditorComboWithBrowseButton(final ActionListener browseActionListener,
                                   final String text,
                                   @Nonnull final Project project,
                                   final String recentsKey) {
  super(new EditorComboBox(text, project, PlainTextFileType.INSTANCE), browseActionListener);
  final List<String> recentEntries = RecentsManager.getInstance(project).getRecentEntries(recentsKey);
  if (recentEntries != null) {
    setHistory(ArrayUtil.toStringArray(recentEntries));
  }
  if (text != null && text.length() > 0) {
    prependItem(text);
  }
}