Calling a function on plugin load
I am trying to use virtualfilelistener to do custom actions after any file add, edit, etc. I have implemented below function which creates a virtualfilelistener and add it to virtualfilemanager. Currently I am calling this function on a button action. But I am looking if it can be called automatically on plugin load or IDE load with plugin installed. Any suggestions on how that can be done?
public void flitener() {
public VirtualFileListener mylistener;
mylistener = new VirtualFileAdapter() {
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
}
@Override
public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
}
@Override
public void contentsChanged(@NotNull VirtualFileEvent event) {
}
@Override
public void fileDeleted(@NotNull VirtualFileEvent event) {
}
@Override
public void fileMoved(@NotNull VirtualFileMoveEvent event) {
}
@Override
public void fileCopied(@NotNull VirtualFileCopyEvent event) {
}
@Override
public void beforePropertyChange(@NotNull VirtualFilePropertyEvent event) {
}
@Override
public void beforeContentsChange(@NotNull VirtualFileEvent event) {
}
@Override
public void beforeFileDeletion(@NotNull VirtualFileEvent event) {
}
@Override
public void beforeFileMovement(@NotNull VirtualFileMoveEvent event) {
}
}
VirtualFileManager.getInstance().addVirtualFileListener(mylistener);
}
Please sign in to leave a comment.
You should register your listener from an ApplicationComponent or ProjectComponent.
With above code, I don't see any of the logs getting printed. Is this correct? Do I need to make change to any other plugin.xml file too?
Yes, you do. Why don't you read the documentation explaining this in detail? http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure.html