How to get project in VirtualFileListener
Answered
Hi,
Currently I've written a VirtualFileListener extending the VirtualFileAdapter class. But within the beforeFileDeletion() method there is no way for me to obtain the current project. Is there any way to obtain the Project within beforeFileDeletion() method.
Basically, all I want is to find the module where the deleted file belonged to. But all I got within beforeFileDeletion() method is the VirtualFileEvent.
Thanks.
Please sign in to leave a comment.
VFS is in application-wide abstraction; you need to pass a project reference to a VFS listener from outside - e.g. by registering the listener from some project-level component.
Or you can search for projects that contain this file under theirs source roots.
Hi Roman,
At the moment I register my VirtulaFileLiistener within the constructor of a FileEditorProvider class, this way I can guarantee that Listener is registered only once. But I don't have access to the project object within this constructor. I suppose I have to go with Aleksey's suggestions.
Hi Aleksey,
Thanks for the solution :)