When creating a new project with my plugin, I need to copy a bunch of files from an external directory. To achieve that I added a runnable via runWhenProjectIsInitialized in my ModuleBuilder's setupRootModel method and run a code similar to this:
VirtualFile sourceDir = scriptsDir.createChildDirectory(this, "source");
VirtualFile originScripts = myOriginDirectory.getScriptsDir();
VfsUtil.copyDirectory(this, originScripts, sourceDir, null);
It works, but not without a problem. It seems, that copyDirectory method initially reads through origin files and copies them to memory, which causes IDE window to lock. After that, it releases code execution, and everything written after it is executed. This means that after that initial hiccup the project is considered created and editor becomes operational. However, actual physical files are still being copied at the moment. IDE shows an indexing process while this is happening.
What I need is a way to monitor copying process to know when it finishes, is there any way to do that?
Also, before calling copyDirectory I attempt to show a popup, but it only appears after copyDirectory has run it's course and IDE did the freezing. What can be the cause of this?
Finally, can I postpone the moment the project is considered created until after physical files were created?