Java Code Examples for com.intellij.openapi.fileTypes.ex.FileTypeManagerEx

The following examples show how to use com.intellij.openapi.fileTypes.ex.FileTypeManagerEx. 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: 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 2
Source Project: consulo   Source File: FileTemplateManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Inject
public FileTemplateManagerImpl(@Nonnull FileTypeManager typeManager,
                               FileTemplateSettings projectSettings,
                               ExportableFileTemplateSettings defaultSettings,
                               ProjectManager pm,
                               final Project project) {
  myTypeManager = (FileTypeManagerEx)typeManager;
  myProjectSettings = projectSettings;
  myDefaultSettings = defaultSettings;
  myProject = project;

  myProjectScheme = project.isDefault() ? null : new FileTemplatesScheme("Project") {
    @Nonnull
    @Override
    public String getTemplatesDir() {
      return FileUtilRt.toSystemDependentName(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR);
    }

    @Nonnull
    @Override
    public Project getProject() {
      return project;
    }
  };
}
 
Example 3
Source Project: idea-php-typo3-plugin   Source File: FluidConfigurationPage.java    License: MIT License 5 votes vote down vote up
@Override
public void apply() {
    FluidConfig.setAutoGenerateCloseTagEnabled(myAutoGenerateClosingTagCheckBox.isSelected());
    FluidConfig.setAutocompleteMustachesEnabled(myAutocompleteMustaches.isSelected());
    FluidConfig.setFormattingEnabled(myFormattingCheckBox.isSelected());
    FluidConfig.setCommenterLanguage((Language) myCommenterLanguage.getSelectedItem());

    if (FluidConfig.setShouldOpenHtmlAsHandlebars(htmlAsHb.isSelected(), myProject)) {
        ApplicationManager.getApplication().runWriteAction(() -> FileTypeManagerEx.getInstanceEx().fireFileTypesChanged());
    }
}
 
Example 4
Source Project: consulo   Source File: FileTypeIndexTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testAddFileType() throws Exception {
  FileType foo = new FakeFileType() {
    @Override
    public boolean isMyFileType(VirtualFile file) {
      return true;
    }

    @Nonnull
    @Override
    public String getId() {
      return "foo";
    }

    @Nonnull
    @Override
    public String getDescription() {
      return "";
    }
  };
  FileTypeIndexImpl index = new FileTypeIndexImpl();
  int version = index.getVersion();

  try {
    FileTypeManagerEx.getInstanceEx().registerFileType(foo);
    assertNotSame(version, index.getVersion());
  }
  finally {
    FileTypeManagerEx.getInstanceEx().unregisterFileType(foo);
  }
}
 
Example 5
Source Project: consulo   Source File: ChooseByNameBase.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isFileName(@Nonnull String name) {
  final int index = name.lastIndexOf('.');
  if (index > 0) {
    String ext = name.substring(index + 1);
    if (ext.contains(":")) {
      ext = ext.substring(0, ext.indexOf(':'));
    }
    if (FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(ext) != UnknownFileType.INSTANCE) {
      return true;
    }
  }
  return false;
}
 
Example 6
@Override
public boolean handlesTemplate(FileTemplate template) {
    FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension());
    return fileType.equals(XQueryFileType.INSTANCE);
}
 
Example 7
Source Project: consulo   Source File: IntentionDescriptionPanel.java    License: Apache License 2.0 4 votes vote down vote up
private static void showUsages(final JPanel panel,
                               final TitledSeparator separator,
                               final List<IntentionUsagePanel> usagePanels,
                               @Nullable final TextDescriptor[] exampleUsages) throws IOException {
  GridBagConstraints gb = null;
  boolean reuse = exampleUsages != null && panel.getComponents().length == exampleUsages.length;
  if (!reuse) {
    disposeUsagePanels(usagePanels);
    panel.setLayout(new GridBagLayout());
    panel.removeAll();
    gb = new GridBagConstraints();
    gb.anchor = GridBagConstraints.NORTHWEST;
    gb.fill = GridBagConstraints.BOTH;
    gb.gridheight = GridBagConstraints.REMAINDER;
    gb.gridwidth = 1;
    gb.gridx = 0;
    gb.gridy = 0;
    gb.insets = new Insets(0,0,0,0);
    gb.ipadx = 5;
    gb.ipady = 5;
    gb.weightx = 1;
    gb.weighty = 1;
  }

  if (exampleUsages != null) {
    for (int i = 0; i < exampleUsages.length; i++) {
      final TextDescriptor exampleUsage = exampleUsages[i];
      final String name = exampleUsage.getFileName();
      final FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx();
      final String extension = fileTypeManager.getExtension(name);
      final FileType fileType = fileTypeManager.getFileTypeByExtension(extension);

      IntentionUsagePanel usagePanel;
      if (reuse) {
        usagePanel = (IntentionUsagePanel)panel.getComponent(i);
      }
      else {
        usagePanel = new IntentionUsagePanel();
        usagePanels.add(usagePanel);
      }
      usagePanel.reset(exampleUsage.getText(), fileType);

      if (!reuse) {
        if (i == exampleUsages.length) {
          gb.gridwidth = GridBagConstraints.REMAINDER;
        }
        panel.add(usagePanel, gb);
        gb.gridx++;
      }
    }
  }
  panel.revalidate();
  panel.repaint();
}
 
Example 8
Source Project: consulo   Source File: FileTemplateUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean canCreateFromTemplate(PsiDirectory[] dirs, FileTemplate template) {
  FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension());
  if (fileType.equals(UnknownFileType.INSTANCE)) return false;
  CreateFromTemplateHandler handler = findHandler(template);
  return handler.canCreate(dirs);
}
 
Example 9
Source Project: consulo   Source File: FileTemplateBase.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean isTemplateOfType(@Nonnull final FileType fType) {
  return fType.equals(FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(getExtension()));
}