How to get module from a VirtualFile in VirtualFileListener.fileDeleted
Hi all,
Does anyone know how to get module from a VirtualFile in VirtualFileListener.fileDeleted event? I'v tried ModuleUtil.findModuleForFile( virtualFile, project), but it returns null value.
Any ideas?
Out of curious, why openAPI doesn't have project/module based VirtualFileListener? I think it would be very convenient as we can add listeners for interested projects/modules without having to do additional works for determining which project/module they (virtualFiles) are belong to.
Thank You!
Regards
Boon Ping
Please sign in to leave a comment.
Hello Lan,
What is the project value that you pass to this method?
And of course, a null value is a valid return value for this method - a VirtualFileListener
can get notifications about changes in files which are not in any module.
Well, there are no such classes in OpenAPI because we don't have them in
IntelliJ IDEA. We do not create utility classes to be only used by third-party
plugins. If we had such classes internally, there would be no problem to
expose them in the API.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hi Dimitry,
Thanks for the reply. In my case, the deleted file was in a module, the reason ModuleUtil.findModuleForFile() returns null value because the deleted file is no longer exist in that module, it is make sense to return null value I think.
One solution to solve this problem would be tracking the VirtualFiles manually. On fileDeleted event, we can then determine the deleted file's module & project with local tracking virtualFiles. What do you think? Or is there a better way way to solve this?
Thanks.
Regards
Boon Ping.
Hello Lan,
A better way is to use the beforeFileDeletion event to perform your processing
(or at least to remember the information you need about the file). All the
necessary information is still available when this event is processed.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hi Dmitry,
Agreed, this is a much better solution. Thanks a lot!
Regards
Boon Ping.