WinMerge Options system

WinMerge stores options into registry:

HKCU/Software/Thingamahoochie/WinMerge

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 (star, exit).

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 CRegOptions) instance in CMainFrame. But that can change in future.

Using COptionsMgr is pretty simple and straightforward:

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 CMainFrame::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.

CPreferencesDlg::ReadOptions() is place to read option values and update values to UI. CPreferencesDlg::SaveOptions() is place to save option values to COptionsMgr when dialog is closed with OK.

If options page (dialog consists of several sub-pages) has 'Defaults' button it needs pointer to COptionsMgr. Usually its easiest to give it in constructor. Then page can call COptionsMgr::GetDefault() for options it wants to reset to defaults when button is selected.