locked
Detect when a Visual Studio Custom Options Value changes.... RRS feed

  • Question

  • I have written a custom options page that appears within the Tools|Options dialog using the instructions I found here: http://msdn.microsoft.com/en-us/library/cc138529.aspx.

    I need to check the value of these options several thousand times as my functions execute, so I would like to cache the values of the user options in my own local data structures.  Is there a way to detect when these options are changed, or even detect when the Tools|Options dialog is closed so that I can reload my custom options values accordingly?

    Thanks in advance for any help.

    ~ Cameron

    Friday, May 27, 2011 4:48 PM

Answers

  • Ahhh, MPF is the one doing the saving/restoring not VS (sorry, for you there is probably not a difference but MPF is a layer built on top of the VS extensibility stuff, so for me there is a difference :)).

    We (VS) simply ask the page (the MPF impl you derive from) to save and load its settings when we need it to do so. VS proper has no clue about what that does, thus there is no 'general' VS mechanism for announcing that something has changed.  DialogPage offers overrideable methods called LoadSettingsFromStorage and SaveSettingsToStorage that do the regsitry reading/writing for the options values and are invoked when the properties change (it uses reflection property listeners to observe when that happens).

    I am not sure if you have to 'give up' on the property grid per se, you could hook your properties using reflection property change listeners the same way VS does, you could also possibly implement the setter of your property that is being exposed off the page to do the propagation/eventing since I believe it should be invoked to change the value of the property.

    Ryan

    Friday, May 27, 2011 8:37 PM

All replies

  • I'm confused, your custom options page is constructed and used to change said values no?  Can it not write them into your local 'cache' for use by your function?  I don't believe there is a generalized 'option has changed' mechanism for tools options pages since their content and value types are a black box to VS.

    Ryan

    Friday, May 27, 2011 5:24 PM
  • Since VS maintains the values it would know when they are changed, black box or not.  My fall back position is to write something that can monitor the changes, but then I have to give up on the property grid, and write a user control to edit the values, which I was hoping to avoid.
    Friday, May 27, 2011 7:37 PM
  • Ahhh, MPF is the one doing the saving/restoring not VS (sorry, for you there is probably not a difference but MPF is a layer built on top of the VS extensibility stuff, so for me there is a difference :)).

    We (VS) simply ask the page (the MPF impl you derive from) to save and load its settings when we need it to do so. VS proper has no clue about what that does, thus there is no 'general' VS mechanism for announcing that something has changed.  DialogPage offers overrideable methods called LoadSettingsFromStorage and SaveSettingsToStorage that do the regsitry reading/writing for the options values and are invoked when the properties change (it uses reflection property listeners to observe when that happens).

    I am not sure if you have to 'give up' on the property grid per se, you could hook your properties using reflection property change listeners the same way VS does, you could also possibly implement the setter of your property that is being exposed off the page to do the propagation/eventing since I believe it should be invoked to change the value of the property.

    Ryan

    Friday, May 27, 2011 8:37 PM
  • Thanks.  I will give that a try.

    ~ Cameron


    Cameron Peters
    Saturday, May 28, 2011 1:07 PM