How to show Project Structure Dialog?

Answered

How to show Project Structure Module dialog to the user using plugin. I need that user add some Dependency into his project. so i wanted to show him Project Structure Module Dialog so that user can add required dependencies. How to do it? is it possible?

0
13 comments
Official comment

See com.intellij.openapi.roots.ui.configuration.ProjectSettingsService

Avatar
Permanently deleted user

Thanks a lot :)

0
Avatar
Permanently deleted user

I can't add some message to it like there is no API to add additional message to that dialog.

0

You can use com.intellij.openapi.ui.Messages#showInfoMessage() to show a dialog before opening the settings.

1
Avatar
Permanently deleted user

yeah tat is also fine.

0
Avatar
Permanently deleted user

Hey, after adding the dependencies on Project Structure dialog that i am showing using plugin, and when i am clicking OK , the added dependency is going. I have to commit the changes? Why is it happening? What can i do so the added dependency should be there.

0

The 'Project Structure' dialog have its own modifiable models (ModifiableRootModel, ModifiableModuleModel) which are changed when user modifies the modules and committed when he clicks 'OK'. So if you modify the project structure before showing the dialog, you indeed need to commit the changes.

0
Avatar
Permanently deleted user

I am showing the dialog using ProjectSettingsService.getInstance(Project).openModuleSettings(Module) via plugin and then user is adding the dependencies using '+' . At that time dependency is there but when user is clicking 'OK'. it is getting removed automatically from the Module dependencies. and according to functionality when user click on 'OK' module should be committed automatically. And i used ModuleRootManager.getInstance(Module).getModifiableModel().commit() but still after clicking 'OK'  newly added dependencies getting removed.

0

If the dependency is added by user manually, you don't need to commit the model yourself. Moreover 'ModuleRootManager.getInstance(Module).getModifiableModel().commit()' line is useless, because 'getModifiableModel' creates a new instance and if it's committed immediately, it doesn't change anything.

0
Avatar
Permanently deleted user

Actually i added this line. Because whenever user was clicking 'OK',all newly added dependencies was getting removed. if user is manually open the window and then add the dependencies it is working fine. But if using plugin this window is getting opened then it is not working. i am not even getting the error like where i am doing wrong. why is it is not working?

0

Do you invoke ModuleRootManager#getModifiableModel in your code? If you invoke it before opening the project structure dialog and commit after closing, the changes made by user in the dialog will be lost indeed (because the dialog will create its own ModifiableRootModel and the changes won't be added to your ModifiableRootModel). Anyway you can put a breakpoint in ModifiableModelCommitter#multiCommit and check when this method is invoked. When you press 'OK' in Project Structure, it should be called from ModulesConfigurator#apply method. You can spot other places which call this method to find the cause.

 

0
Avatar
Permanently deleted user

No i am not invoking ModuleRootManager#getModifiableModel before opening project structure dialog. Okay i am trying to find the cause.

0
Avatar
Permanently deleted user

Hey, I am telling you in detail what i am doing. I create a listener that is extending the ModuleRootListener so if user will add dependencies listener will get to know. And in rootsChanged i am checking for a particular dependency like it is present or not. so first i am registering the listener and then using ProjectSettingsService.getInstance(Project).openModuleSettings(Module), i am showing Project Structure Dialog to the user and saying to user to add some dependencies, so if user will add required dependencies then my listener will check for and notify like module is containing those dependencies or not. Now what is happening whenever user is clicking 'OK' after adding the dependencies, all the newly added dependencies is getting removed. so first my listener is sending present present and then Not present Not present. so finally i am getting not present. and in project also they are not. And if user will open on his own project structure and add those dependencies they are getting added perfectly. And listener is also giving the right result.

0

Please sign in to leave a comment.