WinMerge stores options into registry:
HKCU/Software/Thingamahoochie/WinMerge
Two ways to read and save options:
GetProfileInt()
, GetProfileString
,
WriteProfileInt()
& WriteProfileString()
).
COptionsMgr
class (recommended)This is handy for settings needed in few events or cases (star, exit).
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:
OptionsDef.h
.CMainFrame::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.
COptionsMgr::GetBool()
, GetInt()
or GetString()
.COptionsMgr::SaveOption()
. Note that value is saved to registry immediately.COptionsMgr::GetDefault()
OptionsDef.h
. Please try to keep
options organised in registry, although all existing options aren't.
And use meaningful names for options.
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.
GetX()
functions to read values and SaveOption()
to store values.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.
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.