Mark directory as sources root from plugin
Hello,
Is it possible to automatically mark a directory as 'Sources root' from the plugin?
The use case is like this: after the user selects the application type that is handled by the plugin, if it's a new project in a new directory, the directories are created to match a specific layout but I can't mark the 'src' directory as a 'Source root' from (or better said, I don't know how to do it).
Thanks,
Florin
Please sign in to leave a comment.
Hi there,
I haven't tested this; However -
ModifiableRootModel model = ModuleRootManager.getInstance(yourModule).getModifiableModel();
model.addContentEntry(yourVirtualFile).addSourceFolder(yourVirtualFile, false);
model.commit(); // Note - *Must* be called, or model.dispose()
Let me know if this works for you :)
Alan
Hi Alan,
Thanks for the quick reply.
It works like a charm, thank you!
There was a small trick, to call "getParent()" on the directory which I wanted marked as a source.
The code used to do this looks like this (in case someone else needs it (and I dont' do anything wrong with it):
Kind regards,
Florin
Added workaround information. Message was edited by: Florin Patan