When To Persist Project Settings on New Project

I've got a plug-in which creates a new project/module.  I've implemented a custom ModuleType, ModuleBuilder & ModuleWizardStep which asks the user for some project settings. It all works - I can successfully create a new project.

Now, I've created a PersistentStateComponent for persisting the settings in the project files - and configured it at a <projectService> in the plugin.xml.

But, I'm not sure at what point in the ModuleBuilder process to call ServiceManager.getService() to get my PersistentStateComponent and persist the project settings from the wizard.

Any help or sample code is appreciated!

Comment actions Permalink

You don't need to persist settings manually. Just fill the properties in your project service in ModuleBuilder#setupRootModel method and IDEA will
call 'getState' method and persist the settings automatically when project is saved.

Nikolay Chashnikov
"Develop with pleasure!"

Comment actions Permalink

Ah, I think I understand now.....

When the ModuleBuilder#setupRootModel method is called, IDEA has already setup the Project.  So by calling ServiceManager.getService(modifiableRootModel.getProject(), ServiceClass.class), I can obtain the Project's service/component.  Not sure why, but previously, I was getting a Null pointer when calling getService()....

Thanks for the info.


Please sign in to leave a comment.