Adding Configuration features at runtime to a plugin
Answered
Hi guys,
I just developed a plugin that added Java Method suggestion for the specific XML attribute value. I defined the target XML attribute values at config.properties file into my plugin open source project. Now, I am wondering if there is any way for users of this plugin that end user could define his own XML attribute and uses this plugin features for his desire XML attribute. Actually, I am looking for a way that target user after downloading my plugin be able to change the config.properties values. I just defined my key values at config.properties file like this:
#Seperate your xml attributes by ',' like this: operationId,returnObject
target-xml-attributes= operationId
I appreciate your time.
Please sign in to leave a comment.
The "proper" way is to persist settings via www.jetbrains.org/intellij/sdk/docs/basics/persisting_state_of_components.html and expose a corresponding UI in Settings. This will also allow per-project configuration.
Another idea might be to have a fixed/configurable location for user's config.properties (e.g. in user's home directory) that will be read in addition/replacing default config file by plugin.
You must expose Project-level configurable to be added to "Settings (Preferences)" dialog, see com.intellij.openapi.options.Configurable it has extensive Javadoc and you can find many existing usages in IntelliJ Community sources as reference.
Dear Yann,
Thank you so much for your response. The first way that you suggested is a better way. I read about PersistentStateComponent and it is perfect. But, I couldn't your point in the second part of your comment: "expose a corresponding UI in Settings". Do you mean I must provide action at my plugin and then end user could register her/his own XML attribute tag by providing a UI at IntelliJ for the end-user?
Regards,
Yann Cebron sorry to resume this old thread, but I have one question, how can I access the Configurable at runtime?
should I just
and then access the public properties?
Or is there a better way?
Thanks
Gioioso Matteo That's correct approach