mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
+ fix: handling of some settings default values
This commit is contained in:
parent
7d06abb8e7
commit
9ca9e305f3
@ -84,8 +84,7 @@ static WCHAR s_wchTmpFilePath[MAX_PATH + 1] = { L'\0' };
|
||||
|
||||
static WCHAR* const s_tchAvailableLanguages = L"af-ZA be-BY de-DE es-ES en-GB fr-FR ja-JP nl-NL ru-RU zh-CN"; // en-US internal
|
||||
|
||||
static int s_iSettingsVersion = CFG_VER_NONE;
|
||||
static bool s_bSaveSettings = true;
|
||||
static int s_iSettingsVersion = CFG_VER_CURRENT;
|
||||
static bool s_bEnableSaveSettings = true;
|
||||
|
||||
static prefix_t s_mxSBPrefix[STATUS_SECTOR_COUNT];
|
||||
@ -2950,7 +2949,7 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
CheckMenuRadioItem(hmenu,IDM_VIEW_NOESCFUNC,IDM_VIEW_ESCEXIT,i,MF_BYCOMMAND);
|
||||
|
||||
i = (int)StringCchLenW(Globals.IniFile,COUNTOF(Globals.IniFile));
|
||||
CheckCmd(hmenu,IDM_VIEW_SAVESETTINGS,s_bSaveSettings && i);
|
||||
CheckCmd(hmenu,IDM_VIEW_SAVESETTINGS,Settings.SaveSettings && i);
|
||||
|
||||
EnableCmd(hmenu,IDM_VIEW_REUSEWINDOW,i);
|
||||
EnableCmd(hmenu,IDM_VIEW_STICKYWINPOS,i);
|
||||
@ -5011,11 +5010,11 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
case IDM_VIEW_SAVESETTINGS:
|
||||
if (IsCmdEnabled(hwnd, IDM_VIEW_SAVESETTINGS)) {
|
||||
s_bSaveSettings = !s_bSaveSettings;
|
||||
if (s_bSaveSettings)
|
||||
Settings.SaveSettings = !Settings.SaveSettings;
|
||||
if (Settings.SaveSettings == Defaults.SaveSettings)
|
||||
IniSetString(L"Settings", L"SaveSettings", NULL);
|
||||
else
|
||||
IniSetBool(L"Settings", L"SaveSettings", s_bSaveSettings);
|
||||
IniSetBool(L"Settings", L"SaveSettings", Settings.SaveSettings);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -6614,9 +6613,11 @@ void LoadSettings()
|
||||
if (pIniSection)
|
||||
{
|
||||
// prerequisites
|
||||
s_bSaveSettings = IniGetBool(L"Settings", L"SaveSettings", true);
|
||||
s_iSettingsVersion = IniGetInt(L"Settings", L"SettingsVersion", CFG_VER_NONE);
|
||||
|
||||
Defaults.SaveSettings = true;
|
||||
Settings.SaveSettings = IniGetBool(L"Settings", L"SaveSettings", Defaults.SaveSettings);
|
||||
|
||||
// first load "hard coded" .ini-Settings
|
||||
// --------------------------------------------------------------------------
|
||||
LoadIniSection(L"Settings2", pIniSection, cchIniSection);
|
||||
@ -6648,7 +6649,7 @@ void LoadSettings()
|
||||
|
||||
// deprecated
|
||||
Defaults.RenderingTechnology = IniSectionGetInt(pIniSection, L"SciDirectWriteTech", -111);
|
||||
if ((Defaults.RenderingTechnology != -111) && s_bSaveSettings) {
|
||||
if ((Defaults.RenderingTechnology != -111) && Settings.SaveSettings) {
|
||||
// cleanup
|
||||
IniSetString(L"Settings2", L"SciDirectWriteTech", NULL);
|
||||
}
|
||||
@ -6656,7 +6657,7 @@ void LoadSettings()
|
||||
|
||||
// Settings2 deprecated
|
||||
Defaults.Bidirectional = IniSectionGetInt(pIniSection, L"EnableBidirectionalSupport", -111);
|
||||
if ((Defaults.Bidirectional != -111) && s_bSaveSettings) {
|
||||
if ((Defaults.Bidirectional != -111) && Settings.SaveSettings) {
|
||||
// cleanup
|
||||
IniSetString(L"Settings2", L"EnableBidirectionalSupport", NULL);
|
||||
}
|
||||
@ -6747,12 +6748,12 @@ void LoadSettings()
|
||||
LoadIniSection(L"Settings", pIniSection, cchIniSection);
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#define GET_BOOL_VALUE_FROM_INISECTION(VARNAME,DEFAULT) \
|
||||
Defaults.##VARNAME = DEFAULT; \
|
||||
#define GET_BOOL_VALUE_FROM_INISECTION(VARNAME,DEFAULT) \
|
||||
Defaults.##VARNAME = DEFAULT; \
|
||||
Settings.##VARNAME = IniSectionGetBool(pIniSection, STRGW(VARNAME), Defaults.##VARNAME)
|
||||
|
||||
#define GET_INT_VALUE_FROM_INISECTION(VARNAME,DEFAULT,MIN,MAX) \
|
||||
Defaults.##VARNAME = DEFAULT; \
|
||||
#define GET_INT_VALUE_FROM_INISECTION(VARNAME,DEFAULT,MIN,MAX) \
|
||||
Defaults.##VARNAME = DEFAULT; \
|
||||
Settings.##VARNAME = clampi(IniSectionGetInt(pIniSection, STRGW(VARNAME), Defaults.##VARNAME),MIN,MAX)
|
||||
|
||||
GET_BOOL_VALUE_FROM_INISECTION(SaveRecentFiles, true);
|
||||
@ -6840,8 +6841,8 @@ void LoadSettings()
|
||||
GET_BOOL_VALUE_FROM_INISECTION(ViewWhiteSpace, false);
|
||||
GET_BOOL_VALUE_FROM_INISECTION(ViewEOLs, false);
|
||||
|
||||
GET_INT_VALUE_FROM_INISECTION(DefaultEncoding, CPI_NONE, CED_NO_MAPPING, Encoding_CountOf()-1);
|
||||
// if DefaultEncoding is not defined set to UTF-8 //~system's current code-page
|
||||
int const iPrefEncIniSetting = Encoding_MapIniSetting(false, PREFERRED_DEFAULT_ENCODING);
|
||||
GET_INT_VALUE_FROM_INISECTION(DefaultEncoding, iPrefEncIniSetting, CED_NO_MAPPING, Encoding_CountOf()-1);
|
||||
Settings.DefaultEncoding = ((Settings.DefaultEncoding == CPI_NONE) ?
|
||||
PREFERRED_DEFAULT_ENCODING : Encoding_MapIniSetting(true, Settings.DefaultEncoding));
|
||||
|
||||
@ -7080,7 +7081,7 @@ void LoadSettings()
|
||||
|
||||
#define SAVE_VALUE_IF_NOT_EQ_DEFAULT(TYPE,VARNAME) \
|
||||
if (Settings.##VARNAME != Defaults.##VARNAME) { \
|
||||
IniSectionSet##TYPE(pIniSection, STRGW(VARNAME), Settings.##VARNAME); \
|
||||
IniSectionSet##TYPE(pIniSection, STRGW(VARNAME), Settings.##VARNAME); \
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -7096,8 +7097,11 @@ void SaveSettings(bool bSaveSettingsNow)
|
||||
|
||||
CreateIniFile();
|
||||
|
||||
if (!(s_bSaveSettings || bSaveSettingsNow)) {
|
||||
IniSetBool(L"Settings", L"SaveSettings", s_bSaveSettings);
|
||||
if (!(Settings.SaveSettings || bSaveSettingsNow)) {
|
||||
IniSetInt(L"Settings", L"SettingsVersion", CFG_VER_CURRENT);
|
||||
if (Settings.SaveSettings != Defaults.SaveSettings) {
|
||||
IniSetBool(L"Settings", L"SaveSettings", Settings.SaveSettings);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// update window placement
|
||||
@ -7110,10 +7114,11 @@ void SaveSettings(bool bSaveSettingsNow)
|
||||
int const cchIniSection = INISECTIONBUFCNT * HUGE_BUFFER;
|
||||
WCHAR *pIniSection = AllocMem(sizeof(WCHAR) * cchIniSection, HEAP_ZERO_MEMORY);
|
||||
|
||||
if (pIniSection) {
|
||||
if (pIniSection)
|
||||
{
|
||||
IniSectionSetInt(pIniSection, L"SettingsVersion", CFG_VER_CURRENT);
|
||||
IniSectionSetBool(pIniSection, L"SaveSettings", s_bSaveSettings);
|
||||
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveSettings);
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveRecentFiles);
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, PreserveCaretPos);
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveFindReplace);
|
||||
@ -7200,9 +7205,10 @@ void SaveSettings(bool bSaveSettingsNow)
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ViewWhiteSpace);
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ViewEOLs);
|
||||
|
||||
if (Settings.DefaultEncoding != Defaults.DefaultEncoding) {
|
||||
IniSectionSetInt(pIniSection, L"DefaultEncoding", Encoding_MapIniSetting(false, Settings.DefaultEncoding));
|
||||
}
|
||||
Settings.DefaultEncoding = Encoding_MapIniSetting(false, Settings.DefaultEncoding);
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, DefaultEncoding);
|
||||
Settings.DefaultEncoding = Encoding_MapIniSetting(true, Settings.DefaultEncoding);
|
||||
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, UseDefaultForFileEncoding);
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SkipUnicodeDetection);
|
||||
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SkipANSICodePageDetection);
|
||||
@ -7903,8 +7909,8 @@ int FindIniFile() {
|
||||
bFound = _CheckIniFile(tchPath,tchModule);
|
||||
}
|
||||
|
||||
if (bFound) {
|
||||
|
||||
if (bFound)
|
||||
{
|
||||
// allow two redirections: administrator -> user -> custom
|
||||
if (_CheckIniFileRedirect(MKWCS(APPNAME), MKWCS(APPNAME) L".ini", tchPath, tchModule)) {
|
||||
_CheckIniFileRedirect(MKWCS(APPNAME), MKWCS(APPNAME) L".ini", tchPath, tchModule);
|
||||
@ -8843,7 +8849,7 @@ void UpdateSettingsCmds()
|
||||
{
|
||||
HMENU hmenu = GetSystemMenu(Globals.hwndMain, false);
|
||||
bool hasIniFile = (StringCchLenW(Globals.IniFile,COUNTOF(Globals.IniFile)) > 0 || StringCchLenW(s_wchIniFile2,COUNTOF(s_wchIniFile2)) > 0);
|
||||
CheckCmd(hmenu, IDM_VIEW_SAVESETTINGS, s_bSaveSettings && s_bEnableSaveSettings);
|
||||
CheckCmd(hmenu, IDM_VIEW_SAVESETTINGS, Settings.SaveSettings && s_bEnableSaveSettings);
|
||||
EnableCmd(hmenu, IDM_VIEW_SAVESETTINGS, hasIniFile && s_bEnableSaveSettings);
|
||||
EnableCmd(hmenu, IDM_VIEW_SAVESETTINGSNOW, hasIniFile && s_bEnableSaveSettings);
|
||||
if (SciCall_GetZoom() != 100) { EditShowZoomCallTip(Globals.hwndEdit); }
|
||||
|
||||
@ -258,6 +258,7 @@ extern GLOBALS_T Globals;
|
||||
|
||||
typedef struct _settings_t
|
||||
{
|
||||
bool SaveSettings;
|
||||
bool SaveRecentFiles;
|
||||
bool PreserveCaretPos;
|
||||
bool SaveFindReplace;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user