I want to build a simple idea plugin, which will detect the changes of a kind of file, then convert them to another format.
Current, I use such code to 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. How to do that?
I guess you'll have found the answer by now, but for others it seems to work like this
public class A implements ApplicationComponent, BulkFileListener {
private final MessageBusConnection connection;
public A() {
connection = ApplicationManager.getApplication().getMessageBus().connect();
}
public void initComponent() {
connection.subscribe(VirtualFileManager.VFS_CHANGES, this);
}
public void disposeComponent() {
connection.disconnect();
}
public void before(List<? extends VFileEvent> events) {
// ...
}
public void after(List<? extends VFileEvent> events) {
// ...
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With