mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
Merge pull request #3512 from RaiKoHoff/Dev_DM_STD
File-ext writing to style .ini files only on change or export
This commit is contained in:
commit
802f590ba5
@ -2062,8 +2062,8 @@ static bool _SaveSettings(bool bForceSaveSettings)
|
||||
|
||||
if (Globals.uCurrentThemeIndex == 0) {
|
||||
IniSectionDelete(IniSecStyles, L"ThemeFileName", false);
|
||||
Style_FileExtToIniSection(Globals.bIniFileFromScratch);
|
||||
Style_ToIniSection(Globals.bIniFileFromScratch); // Scintilla Styles
|
||||
Style_ToIniSection(false); // Scintilla Styles
|
||||
Style_FileExtToIniSection(false);
|
||||
} else {
|
||||
IniSectionSetString(IniSecStyles, L"ThemeFileName", Settings.CurrentThemeName);
|
||||
}
|
||||
|
||||
54
src/Styles.c
54
src/Styles.c
@ -482,7 +482,7 @@ bool Style_DynamicThemesMenuCmd(int cmd)
|
||||
if (!Flags.bSettingsFileSoftLocked) {
|
||||
Globals.bCanSaveIniFile = CreateIniFile(Paths.IniFile, NULL);
|
||||
if (Globals.bCanSaveIniFile) {
|
||||
Style_ExportToFile(Paths.IniFile, Globals.bIniFileFromScratch);
|
||||
Style_ExportToFile(Paths.IniFile, false);
|
||||
}
|
||||
}
|
||||
} else if (PathIsExistingFile(Theme_Files[Globals.uCurrentThemeIndex].szFilePath)) {
|
||||
@ -617,25 +617,6 @@ int Style_RgbAlpha(int rgbFore, int rgbBack, int alpha)
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Style_Load()
|
||||
//
|
||||
void Style_Load()
|
||||
{
|
||||
_SetBaseFontSize(GLOBAL_INITIAL_FONTSIZE);
|
||||
_SetCurrentFontSize(GLOBAL_INITIAL_FONTSIZE);
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
g_colorCustom[i] = s_colorDefault[i];
|
||||
}
|
||||
|
||||
_FillThemesMenuTable();
|
||||
Style_LoadLexerFileExtensions();
|
||||
Style_ImportTheme(Globals.uCurrentThemeIndex);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Style_Import()
|
||||
@ -668,9 +649,9 @@ bool Style_Import(HWND hwnd)
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Style_LoadLexerFileExtensions()
|
||||
// _LoadLexerFileExtensions()
|
||||
//
|
||||
void Style_LoadLexerFileExtensions()
|
||||
static void _LoadLexerFileExtensions()
|
||||
{
|
||||
bool bOpendByMe;
|
||||
OpenSettingsFile(&bOpendByMe);
|
||||
@ -710,6 +691,23 @@ void Style_LoadLexerFileExtensions()
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Style_Load()
|
||||
//
|
||||
void Style_Load() {
|
||||
_SetBaseFontSize(GLOBAL_INITIAL_FONTSIZE);
|
||||
_SetCurrentFontSize(GLOBAL_INITIAL_FONTSIZE);
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
g_colorCustom[i] = s_colorDefault[i];
|
||||
}
|
||||
|
||||
_FillThemesMenuTable();
|
||||
_LoadLexerFileExtensions();
|
||||
Style_ImportTheme(Globals.uCurrentThemeIndex);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
@ -833,7 +831,7 @@ bool Style_ImportTheme(const int iThemeIdx) {
|
||||
void Style_SaveSettings(bool bForceSaveSettings)
|
||||
{
|
||||
if (Settings.SaveSettings || bForceSaveSettings) {
|
||||
Style_ExportToFile(Theme_Files[Globals.uCurrentThemeIndex].szFilePath, Globals.bIniFileFromScratch);
|
||||
Style_ExportToFile(Theme_Files[Globals.uCurrentThemeIndex].szFilePath, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -878,6 +876,7 @@ bool Style_Export(HWND hwnd)
|
||||
void Style_FileExtToIniSection(bool bForceAll)
|
||||
{
|
||||
for (int iLexer = 0; iLexer < COUNTOF(g_pLexArray); ++iLexer) {
|
||||
|
||||
LPCWSTR const Lexer_Section = g_pLexArray[iLexer]->pszName;
|
||||
|
||||
if (bForceAll || (StringCchCompareXI(g_pLexArray[iLexer]->szExtensions, g_pLexArray[iLexer]->pszDefExt) != 0)) {
|
||||
@ -903,15 +902,13 @@ void Style_FileExtToIniSection(bool bForceAll)
|
||||
|
||||
void Style_ToIniSection(bool bForceAll)
|
||||
{
|
||||
bool const bForceAllNotFromScratch = (bForceAll && !Globals.bIniFileFromScratch);
|
||||
|
||||
// Custom colors
|
||||
const WCHAR* const CustomColors_Section = L"Custom Colors";
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
WCHAR tch[32] = { L'\0' };
|
||||
StringCchPrintf(tch, COUNTOF(tch), L"%02i", i + 1);
|
||||
if ((g_colorCustom[i] != s_colorDefault[i]) || bForceAllNotFromScratch) {
|
||||
if ((g_colorCustom[i] != s_colorDefault[i]) || bForceAll) {
|
||||
WCHAR wch[32] = { L'\0' };
|
||||
StringCchPrintf(wch, COUNTOF(wch), L"#%02X%02X%02X",
|
||||
(int)GetRValue(g_colorCustom[i]), (int)GetGValue(g_colorCustom[i]), (int)GetBValue(g_colorCustom[i]));
|
||||
@ -968,7 +965,7 @@ void Style_ToIniSection(bool bForceAll)
|
||||
wchDefaultStyle[0] = L'\0'; // empty
|
||||
Style_CopyStyles_IfNotDefined(pszDefault, wchDefaultStyle, COUNTOF(wchDefaultStyle));
|
||||
|
||||
if (bForceAllNotFromScratch || (StringCchCompareX(wchCurrentStyle, wchDefaultStyle) != 0)) {
|
||||
if (bForceAll || (StringCchCompareX(wchCurrentStyle, wchDefaultStyle) != 0)) {
|
||||
IniSectionSetString(Lexer_Section, pszName, wchCurrentStyle);
|
||||
} else {
|
||||
IniSectionDelete(Lexer_Section, pszName, false);
|
||||
@ -1006,8 +1003,8 @@ bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll)
|
||||
if (StringCchCompareXI(szFilePathNorm, Paths.IniFile) == 0) {
|
||||
bool bOpendByMe;
|
||||
if (OpenSettingsFile(&bOpendByMe)) {
|
||||
Style_FileExtToIniSection(bForceAll);
|
||||
Style_ToIniSection(bForceAll);
|
||||
Style_FileExtToIniSection(bForceAll);
|
||||
ok = CloseSettingsFile(true, bOpendByMe);
|
||||
}
|
||||
} else {
|
||||
@ -1022,6 +1019,7 @@ bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll)
|
||||
}
|
||||
if (LoadIniFileCache(szFilePathNorm)) {
|
||||
Style_ToIniSection(bForceAll);
|
||||
Style_FileExtToIniSection(bForceAll);
|
||||
ok = SaveIniFileCache(szFilePathNorm);
|
||||
ResetIniFileCache();
|
||||
}
|
||||
|
||||
@ -32,7 +32,6 @@ int Style_NumOfLexers(); // Number of Lexers in pLexArray
|
||||
void Style_Load();
|
||||
bool Style_Import(HWND hwnd);
|
||||
bool Style_ImportTheme(const int iThemeIdx); // -1 => Factory Reset
|
||||
void Style_LoadLexerFileExtensions();
|
||||
bool Style_ImportFromFile(const WCHAR* szFile);
|
||||
void Style_SaveSettings(bool bForceSaveSettings);
|
||||
bool Style_Export(HWND hwnd);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user