## WinMerge Options system

WinMerge stores options into registry:

    HKCU/Software/Thingamahoochie/WinMerge

Several subkeys exists for different kind of options. `Settings` subkey is good place for most options. There are several subkeys for different sets of options, e.g. custom colors have their own subkey. If you need one single new option, put it top `Settings` subkey. If you need a new set of options for e.g. font setting, create a new subkey for them.

### Accessing options

Two ways to read and save options:

1. Direct access with WinAPI (`GetProfileInt()`, `GetProfileString`, `WriteProfileInt()` & `WriteProfileString()`).
2. Using `COptionsMgr` class (recommended)

### Direct access with WinAPI

This is handy for settings needed in few events or cases. Especially when `COptionsMgr` is not available, e.g. early in startup of WinMerge. However this method misses all advantages of COptionsMgr, like import/export and caching. So it should be used only when really necessary.

### COptionsMgr

Using `COptionsMgr` is recommended for all new options. Also all options visible in Options-dialog must use `COptionsMgr`. Currently there is one `COptionsMgr` (or actually `CRegOptionsMgr`) instance in `CMergeApp`.

Using `COptionsMgr` is pretty simple and straightforward:

- All options are accessed by constant names, listed in `OptionsDef.h`.
- Options are initialized in `CMergeApp::OptionsInit()`, located in `OptionsInit.cpp`. When initialised, type is determined and default value given. If option with that name does not yet exist, new one is created.
- Option value is read using `COptionsMgr::GetBool()`, `GetInt()` or `GetString()`.
- Option value is stored using `COptionsMgr::SaveOption()`. Note that value is saved to registry immediately.
- Option value can be reset to default value using `COptionsMgr::GetDefault()`
- Option value can be removed using `COptionsMgr::RemoveOption()`

### Adding a new option

1. Add option name and registry path into `OptionsDef.h`. Please try to keep options organised in registry, although all existing options aren't. And use meaningful names for options.
2. Add option initialiser to `CMergeApp::OptionsInit()`, with sensible default value. Remember default value is what most users see when first time using WinMerge or new feature using it. So it really must be good for normal use.
3. Use `GetX()` functions to read values and `SaveOption()` to store values.

### Caching

There are some very frequently used option values, like color values for editor syntax highlight. Reading and writing these kind of values through `COptionsMgr` every time would be pretty inefficient. So we only read them to local variables when needed and store when they are changed.

### Options dialog

OptionsDialog (`CPreferencesDlg`) receives pointer to `COptionsMgr` when initialised for access to options.

Note:All propertypages in OptionsDialog may not have GUI initialized, so remember to check window existence before trying to access it (get values/update it).

Options-propertypages implement `IOptionsPanel` interface. `ReadOptions()` and `WriteOptions()` must be implemented by all options-propertypages. Their functionality should be clear... `CPreferencesDlg` calls those functions when loading and saving options.

If propertypage has 'Defaults' button it needs pointer to `COptionsMgr`. Usually it is easiest to give it in constructor. Then page can call `COptionsMgr::GetDefault()` for options it wants to reset to defaults when button is selected.