[Plugin Dev] Trigger code when application's settings were changed

Hi All,

Is exists API to trigger some code when any settings were changed?

In my case I need to detect if File Template Settings was changed, but I agree to perform my code on any changes in the Settings...

I'm only noticed

ApplicationMagager.getApplication().addApplicationListener(new ApplicationListener() {  boolean canExitApplication();   void applicationExiting() {}   void beforeWriteActionStart(Object action) {}   void writeActionStarted(Object action) {}   void writeActionFinished(Object action) {
     // my code
  }
}


Is it correct or this similiar to  "dirty hack" =) ?

Thanks,
Vladimir

0
7 comments
Avatar
Permanently deleted user

Hello,

no, we don't have an universal listener for changes in settings. There are some listeners for specific settings but we don't have such listeners for
File Template Settings.

--
Nikolay Chashnikov
JetBrains
http://www.jetbrains.com
"Develop with pleasure!"

0

Hi Nikolay,

Any chance that we can have such listeners in the future versions?
Or I should open a enchancement for such functionality on YouTrack?

Thanks,
Vladimir

0

Could you explain your use-case?


0

Hi Yann,

In my case such listener will be userfull for optimization behavior.

I have plugin which using DefaultTemplatePropertiesProvider API.
My plugin calculate all possible variables which are defined in the File and Code Templates. This operation take some time (On my Core I5 it take 1-2 sec). In most of cases it's not bad, but from optimization perspective.... It's not good, I think. Bacause each showing of dialog will recalculate the same data which are not changed.
Thus I want to optimize this using cache of all variables. Updating of this cache should be performed only in case when File and Code Template settings were changed (or any IDEA setting was changed in bad API)

This is a my case...

But such behavior I think should be exists, since any plugin can use any IDEA's setting with a big amount of data.

Thanks,
Vladimir

0

I think it will be great if will be something like:

interface SettingsChangeListener {
   public void onChange(Class<? extends Configurable>[] configrations);
   // if needed to detect specific changes search class in the configurations array
}

0

I wrote some code which is not tested yet, but it can show how I can see this implementation.

https://github.com/vkravets/intellij-community/commit/8fa995141ff51d89986ddd6456640155d8641010

After this we can create any listener which will call after any settings change:

SettingsListenerManager.getInstance().add(new SettingsChangeListener() {

     }
});
0

Please sign in to leave a comment.