I have some problems when I create my first idea plugin

I'm new to idea from eclipse. I want to create an idea plugin to convert some haml-like files into html files. I built one on eclipse, but I don't know how to do it in idea.

What the plugin will do?

1. When a haml file be created, the plugin will convert it to a html file in background
2. When a haml file be modified, it will be converted to a html file in background
3. When a haml file be deleted, the corresponding html file will be deleted too

My questions:

This kind of plugin on eclipse can be called a builder. I just create a class which implement an builder interface, it will get all the changed files. Then conversion work will be performed in background automatically.

But now it's idea:

1. Is there a similar "builder" as eclipse?

2. How to get the changed files?  I can do this:

VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {
    @Override
    public void contentsChanged(VirtualFileEvent event) {
         // do something
    }
});
 

It works, but not efficient.
I found this article says:

The most efficient way to listen to VFS events is to implement the BulkFileListener interface and to subscribe with it to the VirtualFileManager.VFS_CHANGES topic.

But I can't find any example to implement it.

3. How to perform this conversion in background? Is it automatically? Or do I need to create a daemon thread?

4. Is there any similar plugin I can study from? I searched, but not found.

2 comments
Comment actions Permalink

Hello freewind,

I'm new to idea from eclipse. I want to create an idea plugin to
convert some haml-like files into html files. I built one on eclipse,
but I don't know how to do it in idea.

What the plugin will do?

1. When a haml file be created, the plugin will convert it to a html
file in background
2. When a haml file be modified, it will be converted to a html file
in background
3. When a haml file be deleted, the corresponding html file will be
deleted too
My questions:

This kind of plugin on eclipse can be called a builder. I just create
a class which implement an builder interface, it will get all the
changed files. Then conversion work will be performed in background
automatically.

But now it's idea:

1. Is there a similar "builder" as eclipse?


No, there is no direct equivalent in the IntelliJ IDEA API.


2. How to get the changed files?  I can do this:

 r(new VirtualFileAdapter() {
> @Override
> public void contentsChanged(VirtualFileEvent event) {
> // do something
> }
> });]]>

It works, but not efficient.
I found
http://confluence.jetbrains.net/display/IDEADEV/IntelliJIDEAVirtual+
File+System says:

>> The most efficient way to listen to VFS events is to implement the
>> BulkFileListener interface and to subscribe with it to the
>> VirtualFileManager.VFS_CHANGES topic.
>>

But I can't find any example to implement it.


You can find several simple examples in the Community Edition sources. Here's
one:
http://git.jetbrains.org/?p=idea/community.git;a=blob;f=platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredFilesComponent.java;hb=HEAD

3. How to perform this conversion in background? Is it automatically?
Or do I need to create a daemon thread?


Use ApplicationManager.getApplication().runOnPooledThread() to run a task
in a background thread.

4. Is there any similar plugin I can study from? I searched, but not
found.


I don't know of any existing plugin that does something similar.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Thank you very much, it's very helpful!

0

Please sign in to leave a comment.