How to Save Customized Settings
Hi,
I'm trying to develop a plugin for IDEA. I created it as a tool window so it can be accessible in view -> tool windows menu. And I want to add a customized settings for this plugin. I implement ProjectComponent, Configurable, ToolWindowFactory interfaces in my class. So I can create a simple gui for my settings(just one label and textfield) and I can access it in file->settings->project settings. I want to save String in the textfield for my plugin settings but I can't save it. How can I save a string for my plugin settings?
请先登录再写评论。
Please see http://confluence.jetbrains.com/display/IDEADEV/Persisting+State+of+Components
Thank you for your reply. But I can't handle this. Do I need to register in plugin.xml? Or is there any working example?
There's many many examples of this in IntelliJ Community Edition source code. For Example, com.intellij.ide.ui.AppearanceConfigurable
Here's my main code
Here's my form code in File->Settings.
I still can't save phrase, I can't figure what I miss.
Please don't put all of your code in a single class, this won't work as you expect. IntelliJ IDEA will create multiple instances of your class, one as a Configurable and another as a PersistentStateComponent, so the instance in which you put the data when the settings are saved will not be the same instance from which it will take the data to be saved. Instead, you need to use a separate class for the implementation of each interface and use the getComponent() or ServiceManager.getService() methods to connect them with each other. You can see multiple examples of this everywhere in the IntelliJ IDEA codebase.
Thank you for reply. I'm looking at an example now. I'm trying to develop plugin based on this document: https://www.jetbrains.com/idea/docs/TheBasicsofPluginDevelopment.pdf
And in this document single class works.
I have a question: In my class, I have implemented 4 interface, so I need to make 4 class or more?
Another question: I need to store just one string, so instead of PersistentStateComponent, can I use PropertiesComponent.GetInstance(project).setValue and getValue?
This PDF is completely out of date, please follow documentation here http://confluence.jetbrains.com/display/IDEADEV/PluginDevelopment or just look for examples in Community Edition.
Using PropertiesComponent is also possible, of course, but then quite limited.