Questions about project SDK update listener
Hi all, Currently, I want to update External Libraries immediately after I change the project SDK just like the screenshot upload below, but I can not find any code examples or documentations, so please excuse me for asking that which event I should listen to?
Thanks in advance for any help :)
Best regards,
Jihui

Please sign in to leave a comment.
The UI in the video from your post uses
@Eugene Zhuravlev Thanks for your reply. But if I remove this part https://github.com/ignatov/intellij-erlang/blob/master/src/org/intellij/erlang/inspection/SetupSDKNotificationProvider.java#L52-L60, I can still update the External Libraries tree with intellij-erlang plugin which is really confusing. As you mentioned, if I unsubscribe the PROJECT_ROOTS event, I can not receive project SDK changing notification anymore.
I'm not sure I understand the whole question right. Could you please describe in detail what you find confusing?
@Eugene Zhuravlev Thanks!
- Plugin version (or commit hash): 610ff0ef4e8a55690b9a480efe725c5776e341f8
- IDE name and version: IntelliJ IDEA 2016.2.2
- Java version: 1.8.0_111
- OS name and version: OSX 10.10.5
- What are you trying to do?
I'm currently using intellij-go plugin https://github.com/go-lang-plugin-org/go-lang-idea-plugin and I want to update the Go SDK after I change the project SDK in `Project Structure` panel.
- What would you expect to happen?
The External Libraries tree can be updated immediately after I change project SDK.
- What happens?
It always displays the same Go SDK no matter how I change the project SDK.
Additionally, I think `go-lang-idea-plugin` and `intellij-erlang` have a similar internal design, but I can easily update the External Libraries tree immediately after I change project SDK with `intellij-erlang` even I comment all the configurations here https://github.com/ignatov/intellij-erlang/blob/master/plugin/resources/META-INF/plugin.xml#L44-L57 which confuses me a lot.
You can easily run these two plugins using Gradle with `./gradlew runIdea`
@Eugene Zhuravlev And I also subscribe the ProjectTopics.PROJECT_ROOTS as you mentioned before, but when I setup breakpoint and debug the plugin, the listener will not be triggered everytime I change the project SDK, but If I debug intellij-erlang here https://github.com/ignatov/intellij-erlang/blob/master/src/org/intellij/erlang/inspection/SetupSDKNotificationProvider.java#L57 , this listener can be invoked everytime I change the project SDK, and if I remove the editorNotification https://github.com/ignatov/intellij-erlang/blob/master/resources/META-INF/ErlangPlugin.xml#L146 from intellij-erlang, it still can update External Libraries tree after I change project SDK, it is really magic here.
Hi @Eugene Zhuravlev, I think I have solved this issue by using `ModifiableRootModel#inheritSdk`. Thanks all the same :)
Glad to hear you have found a solution suitable for your case. This option makes makes module depend on whatever SDK configured as a Project SDK. This is a good default setting for a newly created module being added to the project.