This Question is Possibly Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
2 Replies Last post: Apr 14, 2010 11:30 AM by Frank Wienberg  
StanAccy Novice 495 posts since
Mar 18, 2003
Currently Being Moderated

Feb 5, 2010 9:29 PM

Project view - file type icon customization

How do I set a different icon for a particular file type that has specific content?

 

Specifically, I'm trying to set a custom icon for an in-house XML file (similar to how the IDEA plugin icon is different than a regular XML file icon).

The file typically is located at a known place in the directory structure and has a known name, but ideally Id like to be able to check for the existence of an in-house XML element (so any *.xml file with the right contents will have the custom icon)

 

After a Google search, it looks like IconProvider has something to do with it, but I didnt find anything about how to register this new IconProvider with IDEA and I didnt see anything about checking the contents of the file.

 

What are the specifics for the icon (size, format and number of colors)?

 

Regards

 

Nick

Dmitry Jemerov JetBrains 11,708 posts since
Aug 19, 2002
Currently Being Moderated
Feb 8, 2010 1:34 PM in response to: StanAccy
Re: Project view - file type icon customization

Hello Nick,

 

Yes, IconProvider is the right API in this case. The implementation is registered

as an extension in the iconProvider extension point. You need to check whether

the PSI element passed to your IconProvider is an XmlFile, and if it is,

use the XML PSI to check if you need to change the icon.

 

The icons are 16x16, the format and number of colors doesn't matter.

 

How do I set a different icon for a particular file type that has

specific content?

 

Specifically, I'm trying to set a custom icon for an in-house XML file

(similar to how the IDEA plugin icon is different than a regular XML

file icon). The file typically is located at a known place in the

directory structure and has a known name, but ideally Id like to be

able to check for the existence of an in-house XML element (so any

*.xml file with the right contents will have the custom icon)

 

After a Google search, it looks like IconProvider has something to do

with it, but I didnt find anything about how to register this new

IconProvider with IDEA and I didnt see anything about checking the

contents of the file.

 

What are the specifics for the icon (size, format and number of

colors)?

 

Regards

 

Nick

 

---

Original message URL:

http://www.jetbrains.net/devnet/message/5256092#5256092

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

 

 

 

Frank Wienberg Newbie 22 posts since
Oct 2, 2002
Currently Being Moderated
Apr 14, 2010 11:30 AM in response to: Dmitry Jemerov
Re: Project view - file type icon customization

For everybody who likes example code, here is some that works for my plugin:

 

package net.jangaroo.ide.idea.exml;
 
import com.intellij.ide.IconProvider;
import com.intellij.openapi.util.IconLoader;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
 
import javax.swing.Icon;
 
/**
 * Provides a custom icon for *.exml files.
 */
public class ExmlIconProvider extends IconProvider {
 
  private static final String EXML_ICON_URL = "/net/jangaroo/EXML-logo-16x16.png";
 
  public Icon getIcon(@NotNull PsiElement psiElement, int flags) {
    PsiFile containingFile = psiElement.getContainingFile();
    if (containingFile != null && containingFile.getName().endsWith(".exml")) {
      return IconLoader.getIcon(EXML_ICON_URL);
    }
    return null;
  }
 
}

 

The icon has to be packaged as a resource into the plugin jar.

 

plugin.xml fragment:

 

  <extensions defaultExtensionNs="com.intellij">
    <iconProvider implementation="net.jangaroo.ide.idea.exml.ExmlIconProvider"/>
  </extensions>

More Like This

  • Retrieving data ...