+ opt: 1-pass (file open/close) save settings

This commit is contained in:
Rainer Kottenhoff 2019-09-15 17:26:05 +02:00
parent c89343cd4f
commit 470bfcea63
9 changed files with 960 additions and 881 deletions

File diff suppressed because it is too large Load Diff

View File

@ -27,11 +27,15 @@ extern "C" {
bool FindIniFile();
int TestIniFile();
bool CreateIniFile();
bool CreateIniFile();
bool CreateIniFileEx(LPCWSTR lpszIniFile);
void LoadSettings();
void LoadFlags();
bool OpenSettingsFile();
bool SaveSettings(bool);
bool CloseSettingsFile();
// ----------------------------------------------------------------------------
@ -108,10 +112,23 @@ bool IniFileDelete(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR lpKeyName,
typedef void (CALLBACK* IterSectionFunc_t)(LPCWSTR key, LPCWSTR value);
bool IniFileIterateSection(LPCWSTR lpFilePath, LPCWSTR lpSectionName, IterSectionFunc_t callBack);
//==== MRU Functions ==========================================================
LPMRULIST MRU_Create(LPCWSTR pszRegKey, int iFlags, int iSize);
bool MRU_Destroy(LPMRULIST pmru);
bool MRU_Add(LPMRULIST pmru, LPCWSTR pszNew, cpi_enc_t iEnc, DocPos iPos, LPCWSTR pszBookMarks);
bool MRU_FindFile(LPMRULIST pmru, LPCWSTR pszFile, int* iIndex);
bool MRU_AddFile(LPMRULIST pmru, LPCWSTR pszFile, bool, bool, cpi_enc_t iEnc, DocPos iPos, LPCWSTR pszBookMarks);
bool MRU_Delete(LPMRULIST pmru, int iIndex);
bool MRU_Empty(LPMRULIST pmru);
int MRU_Enum(LPMRULIST pmru, int iIndex, LPWSTR pszItem, int cchItem);
bool MRU_Load(LPMRULIST pmru);
bool MRU_Save(LPMRULIST pmru);
bool MRU_MergeSave(LPMRULIST pmru, bool, bool, bool);
#define MRU_Count(pmru) MRU_Enum((pmru), 0, NULL, 0)
// ----------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif

View File

@ -1966,7 +1966,6 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM
if ((IDOK == answer) || (IDYES == answer)) {
MRU_Delete(Globals.pFileMRU,lvi.iItem);
MRU_DeleteFileFromStore(Globals.pFileMRU,tchFileName);
//SendDlgItemMessage(hwnd,IDC_FILEMRU,LB_DELETESTRING,(WPARAM)iItem,0);
//ListView_DeleteItem(GetDlgItem(hwnd,IDC_FILEMRU),lvi.iItem);

View File

@ -1452,311 +1452,6 @@ UINT CharSetFromCodePage(UINT uCodePage) {
}
//=============================================================================
//
// MRU functions
//
LPMRULIST MRU_Create(LPCWSTR pszRegKey,int iFlags,int iSize)
{
LPMRULIST pmru = AllocMem(sizeof(MRULIST), HEAP_ZERO_MEMORY);
if (pmru) {
ZeroMemory(pmru, sizeof(MRULIST));
pmru->szRegKey = pszRegKey;
pmru->iFlags = iFlags;
pmru->iSize = min_i(iSize, MRU_MAXITEMS);
}
return(pmru);
}
bool MRU_Destroy(LPMRULIST pmru)
{
int i;
for (i = 0; i < pmru->iSize; i++) {
if (pmru->pszItems[i])
LocalFree(pmru->pszItems[i]); // StrDup()
if (pmru->pszBookMarks[i])
LocalFree(pmru->pszBookMarks[i]); // StrDup()
}
ZeroMemory(pmru,sizeof(MRULIST));
FreeMem(pmru);
return true;
}
int MRU_Compare(LPMRULIST pmru,LPCWSTR psz1,LPCWSTR psz2)
{
if (pmru->iFlags & MRU_NOCASE) {
return(StringCchCompareXI(psz1, psz2));
}
return(StringCchCompareX(psz1,psz2));
}
bool MRU_Add(LPMRULIST pmru, LPCWSTR pszNew, cpi_enc_t iEnc, DocPos iPos, LPCWSTR pszBookMarks)
{
int i;
for (i = 0; i < pmru->iSize; i++) {
if (MRU_Compare(pmru,pmru->pszItems[i],pszNew) == 0) {
LocalFree(pmru->pszItems[i]); // StrDup()
break;
}
}
i = min_i(i,pmru->iSize-1);
for (; i > 0; i--) {
pmru->pszItems[i] = pmru->pszItems[i - 1];
pmru->iEncoding[i] = pmru->iEncoding[i - 1];
pmru->iCaretPos[i] = pmru->iCaretPos[i - 1];
}
pmru->pszItems[0] = StrDup(pszNew); // LocalAlloc()
pmru->iEncoding[0] = iEnc;
pmru->iCaretPos[0] = (Settings.PreserveCaretPos ? iPos : 0);
pmru->pszBookMarks[0] = (pszBookMarks ? StrDup(pszBookMarks) : NULL); // LocalAlloc()
return true;
}
bool MRU_FindFile(LPMRULIST pmru,LPCWSTR pszFile,int* iIndex) {
WCHAR wchItem[MAX_PATH] = { L'\0' };
int i;
for (i = 0; i < pmru->iSize; i++) {
if (pmru->pszItems[i] == NULL) {
*iIndex = i;
return false;
}
if (StringCchCompareXI(pmru->pszItems[i],pszFile) == 0) {
*iIndex = i;
return true;
}
PathAbsoluteFromApp(pmru->pszItems[i],wchItem,COUNTOF(wchItem),true);
if (StringCchCompareXI(wchItem,pszFile) == 0) {
*iIndex = i;
return true;
}
}
*iIndex = i;
return false;
}
bool MRU_AddFile(LPMRULIST pmru,LPCWSTR pszFile,bool bRelativePath,bool bUnexpandMyDocs,
cpi_enc_t iEnc, DocPos iPos, LPCWSTR pszBookMarks) {
int i = 0;
if (MRU_FindFile(pmru,pszFile,&i)) {
LocalFree(pmru->pszItems[i]); // StrDup()
}
else {
i = (i < pmru->iSize) ? i : (pmru->iSize - 1);
}
for (; i > 0; i--) {
pmru->pszItems[i] = pmru->pszItems[i-1];
pmru->iEncoding[i] = pmru->iEncoding[i-1];
pmru->iCaretPos[i] = pmru->iCaretPos[i-1];
pmru->pszBookMarks[i] = pmru->pszBookMarks[i-1];
}
if (bRelativePath) {
WCHAR wchFile[MAX_PATH] = { L'\0' };
PathRelativeToApp((LPWSTR)pszFile,wchFile,COUNTOF(wchFile),true,true,bUnexpandMyDocs);
pmru->pszItems[0] = StrDup(wchFile); // LocalAlloc()
}
else {
pmru->pszItems[0] = StrDup(pszFile); // LocalAlloc()
}
pmru->iEncoding[0] = iEnc;
pmru->iCaretPos[0] = (Settings.PreserveCaretPos ? iPos : 0);
pmru->pszBookMarks[0] = (pszBookMarks ? StrDup(pszBookMarks) : NULL); // LocalAlloc()
return true;
}
bool MRU_Delete(LPMRULIST pmru,int iIndex) {
int i;
if (iIndex < 0 || iIndex > pmru->iSize - 1) {
return false;
}
if (pmru->pszItems[iIndex]) {
LocalFree(pmru->pszItems[iIndex]); // StrDup()
}
if (pmru->pszBookMarks[iIndex]) {
LocalFree(pmru->pszBookMarks[iIndex]); // StrDup()
}
for (i = iIndex; i < pmru->iSize-1; i++) {
pmru->pszItems[i] = pmru->pszItems[i+1];
pmru->iEncoding[i] = pmru->iEncoding[i+1];
pmru->iCaretPos[i] = pmru->iCaretPos[i+1];
pmru->pszBookMarks[i] = pmru->pszBookMarks[i+1];
pmru->pszItems[i+1] = NULL;
pmru->iEncoding[i+1] = 0;
pmru->iCaretPos[i+1] = 0;
pmru->pszBookMarks[i+1] = NULL;
}
return true;
}
bool MRU_DeleteFileFromStore(LPMRULIST pmru,LPCWSTR pszFile) {
int i = 0;
LPMRULIST pmruStore;
WCHAR wchItem[MAX_PATH] = { L'\0' };
pmruStore = MRU_Create(pmru->szRegKey,pmru->iFlags,pmru->iSize);
MRU_Load(pmruStore);
while (MRU_Enum(pmruStore,i,wchItem,COUNTOF(wchItem)) != -1)
{
PathAbsoluteFromApp(wchItem,wchItem,COUNTOF(wchItem),true);
if (StringCchCompareXI(wchItem,pszFile) == 0)
MRU_Delete(pmruStore,i);
else
i++;
}
MRU_Save(pmruStore);
MRU_Destroy(pmruStore);
return true;
}
bool MRU_Empty(LPMRULIST pmru)
{
for (int i = 0; i < pmru->iSize; i++) {
if (pmru->pszItems[i]) {
LocalFree(pmru->pszItems[i]); // StrDup()
pmru->pszItems[i] = NULL;
pmru->iEncoding[i] = 0;
pmru->iCaretPos[i] = 0;
if (pmru->pszBookMarks[i]) {
LocalFree(pmru->pszBookMarks[i]); // StrDup()
}
pmru->pszBookMarks[i] = NULL;
}
}
return true;
}
int MRU_Enum(LPMRULIST pmru, int iIndex, LPWSTR pszItem, int cchItem)
{
if (pszItem == NULL || cchItem == 0) {
int i = 0;
while (i < pmru->iSize && pmru->pszItems[i]) { ++i; }
return(i);
}
if (iIndex < 0 || iIndex > pmru->iSize - 1 || !pmru->pszItems[iIndex]) {
return(-1);
}
StringCchCopyN(pszItem, cchItem, pmru->pszItems[iIndex], cchItem);
return((int)StringCchLen(pszItem, cchItem));
}
bool MRU_Load(LPMRULIST pmru)
{
MRU_Empty(pmru);
LoadIniFile(Globals.IniFile);
const WCHAR* const RegKey_Section = pmru->szRegKey;
int n = 0;
for (int i = 0; i < pmru->iSize; i++) {
WCHAR tchName[32] = { L'\0' };
StringCchPrintf(tchName, COUNTOF(tchName), L"%.2i", i + 1);
WCHAR tchItem[2048] = { L'\0' };
if (IniSectionGetString(RegKey_Section, tchName, L"", tchItem, COUNTOF(tchItem))) {
size_t const len = StringCchLen(tchItem, 0);
if ((len > 0) && (tchItem[0] == L'"') && (tchItem[len-1] == L'"')) {
MoveMemory(tchItem, (tchItem+1), len * sizeof(WCHAR));
tchItem[len - 2] = L'\0'; // clear dangling '"'
}
pmru->pszItems[n] = StrDup(tchItem);
StringCchPrintf(tchName, COUNTOF(tchName), L"ENC%.2i", i + 1);
int const iCP = (cpi_enc_t)IniSectionGetInt(RegKey_Section, tchName, 0);
pmru->iEncoding[n] = (cpi_enc_t)Encoding_MapIniSetting(true, iCP);
StringCchPrintf(tchName, COUNTOF(tchName), L"POS%.2i", i + 1);
pmru->iCaretPos[n] = (Settings.PreserveCaretPos) ? IniSectionGetInt(RegKey_Section, tchName, 0) : 0;
StringCchPrintf(tchName, COUNTOF(tchName), L"BMRK%.2i", i + 1);
WCHAR wchBookMarks[MRU_BMRK_SIZE] = { L'\0' };
IniSectionGetString(RegKey_Section, tchName, L"", wchBookMarks, COUNTOF(wchBookMarks));
pmru->pszBookMarks[n] = StrDup(wchBookMarks);
++n;
}
}
ReleaseIniFile();
return true;
}
bool MRU_Save(LPMRULIST pmru)
{
if (LoadIniFile(Globals.IniFile)) {
WCHAR tchName[32] = { L'\0' };
WCHAR tchItem[2048] = { L'\0' };
const WCHAR* const RegKey_Section = pmru->szRegKey;
IniSectionClear(pmru->szRegKey, false);
for (int i = 0; i < pmru->iSize; i++) {
if (pmru->pszItems[i]) {
StringCchPrintf(tchName, COUNTOF(tchName), L"%.2i", i + 1);
StringCchPrintf(tchItem, COUNTOF(tchItem), L"\"%s\"", pmru->pszItems[i]);
IniSectionSetString(RegKey_Section, tchName, tchItem);
if (pmru->iEncoding[i] > 0) {
StringCchPrintf(tchName, COUNTOF(tchName), L"ENC%.2i", i + 1);
int const iCP = (int)Encoding_MapIniSetting(false, (int)pmru->iEncoding[i]);
IniSectionSetInt(RegKey_Section, tchName, iCP);
}
if (pmru->iCaretPos[i] > 0) {
StringCchPrintf(tchName, COUNTOF(tchName), L"POS%.2i", i + 1);
IniSectionSetPos(RegKey_Section, tchName, pmru->iCaretPos[i]);
}
if (pmru->pszBookMarks[i] && (StringCchLenW(pmru->pszBookMarks[i], MRU_BMRK_SIZE) > 0)) {
StringCchPrintf(tchName, COUNTOF(tchName), L"BMRK%.2i", i + 1);
IniSectionSetString(RegKey_Section, tchName, pmru->pszBookMarks[i]);
}
}
}
SaveIniFile(Globals.IniFile);
return true;
}
return false;
}
bool MRU_MergeSave(LPMRULIST pmru,bool bAddFiles,bool bRelativePath,bool bUnexpandMyDocs) {
int i;
LPMRULIST pmruBase;
pmruBase = MRU_Create(pmru->szRegKey,pmru->iFlags,pmru->iSize);
MRU_Load(pmruBase);
if (bAddFiles) {
for (i = pmru->iSize-1; i >= 0; i--) {
if (pmru->pszItems[i]) {
WCHAR wchItem[MAX_PATH] = { L'\0' };
PathAbsoluteFromApp(pmru->pszItems[i],wchItem,COUNTOF(wchItem),true);
MRU_AddFile(pmruBase,wchItem,bRelativePath,bUnexpandMyDocs,
pmru->iEncoding[i],pmru->iCaretPos[i],pmru->pszBookMarks[i]);
}
}
}
else {
for (i = pmru->iSize-1; i >= 0; i--) {
if (pmru->pszItems[i])
MRU_Add(pmruBase,pmru->pszItems[i],
pmru->iEncoding[i],pmru->iCaretPos[i],pmru->pszBookMarks[i]);
}
}
MRU_Save(pmruBase);
MRU_Destroy(pmruBase);
return true;
}
/** ******************************************************************************
*
* UnSlash functions

View File

@ -20,6 +20,7 @@
#include <math.h>
#include <shlwapi.h>
#include <heapapi.h>
#include <versionhelpers.h>
// ============================================================================
@ -332,22 +333,6 @@ UINT CodePageFromCharSet(UINT uCharSet);
UINT CharSetFromCodePage(UINT uCodePage);
//==== MRU Functions ==========================================================
LPMRULIST MRU_Create(LPCWSTR pszRegKey,int iFlags,int iSize);
bool MRU_Destroy(LPMRULIST pmru);
bool MRU_Add(LPMRULIST pmru, LPCWSTR pszNew, cpi_enc_t iEnc, DocPos iPos, LPCWSTR pszBookMarks);
bool MRU_FindFile(LPMRULIST pmru,LPCWSTR pszFile,int* iIndex);
bool MRU_AddFile(LPMRULIST pmru, LPCWSTR pszFile, bool, bool, cpi_enc_t iEnc, DocPos iPos, LPCWSTR pszBookMarks);
bool MRU_Delete(LPMRULIST pmru,int iIndex);
bool MRU_DeleteFileFromStore(LPMRULIST pmru,LPCWSTR pszFile);
bool MRU_Empty(LPMRULIST pmru);
int MRU_Enum(LPMRULIST pmru,int iIndex,LPWSTR pszItem,int cchItem);
bool MRU_Load(LPMRULIST pmru);
bool MRU_Save(LPMRULIST pmru);
bool MRU_MergeSave(LPMRULIST pmru,bool,bool,bool);
#define MRU_Count(pmru) MRU_Enum((pmru), 0, NULL, 0)
//==== UnSlash Functions ======================================================
unsigned int UnSlash(char* s, UINT cpEdit);
void TransformBackslashes(char* pszInput,bool,UINT cpEdit,int* iReplaceMsg);

View File

@ -52,6 +52,7 @@ CONSTANTS_T const Constants = {
2 // StdDefaultLexerID
, L"minipath.exe" // FileBrowserMiniPath
, L"Suppressed Messages" // SectionSuppressedMessages
, L"ThemeFileName" // StylingThemeName
};
FLAGS_T Flags;
@ -117,10 +118,6 @@ static LPWSTR s_lpFileList[FILE_LIST_SIZE] = { NULL };
static int s_cFileList = 0;
static int s_cchiFileList = 0;
static WCHAR* const _s_RecentFiles = L"Recent Files";
static WCHAR* const _s_RecentFind = L"Recent Find";
static WCHAR* const _s_RecentReplace = L"Recent Replace";
static WCHAR s_tchLastSaveCopyDir[MAX_PATH] = { L'\0' };
static bool s_bRunningWatch = false;
@ -627,6 +624,9 @@ static void _InitGlobals()
ZeroMemory(&(Globals.fvBackup), sizeof(FILEVARS));
Globals.hMainMenu = NULL;
Globals.pFileMRU = NULL;
Globals.pMRUfind = NULL;
Globals.pMRUreplace = NULL;
Globals.CallTipType = CT_NONE;
Globals.iAvailLngCount = 1;
Globals.iWrapCol = 0;
@ -643,6 +643,7 @@ static void _InitGlobals()
Globals.bReplaceInitialized = false;
Globals.FindReplaceMatchFoundState = FND_NOP;
Globals.bDocHasInconsistentEOLs = false;
Globals.idxSelectedTheme = 1; // Default(0), Standard(1)
Flags.bDevDebugMode = DefaultFlags.bDevDebugMode = false;
Flags.bStickyWindowPosition = DefaultFlags.bStickyWindowPosition = false;
@ -1608,8 +1609,51 @@ bool SaveAllSettings(bool bSaveSettingsNow)
WCHAR tchMsg[80];
GetLngString(IDS_MUI_SAVINGSETTINGS, tchMsg, COUNTOF(tchMsg));
BeginWaitCursor(tchMsg);
bool ok = OpenSettingsFile();
bool const ok = SaveSettings(bSaveSettingsNow);
if (ok) {
ok = SaveSettings(bSaveSettingsNow);
if (StrIsNotEmpty(Globals.IniFile))
{
// Cleanup unwanted MRU'selEmpty
if (!Settings.SaveRecentFiles) {
MRU_Empty(Globals.pFileMRU);
MRU_Save(Globals.pFileMRU);
}
else {
MRU_MergeSave(Globals.pFileMRU, true, Flags.RelativeFileMRU, Flags.PortableMyDocs);
}
MRU_Destroy(Globals.pFileMRU);
Globals.pFileMRU = NULL;
if (!Settings.SaveFindReplace) {
MRU_Empty(Globals.pMRUfind);
MRU_Empty(Globals.pMRUreplace);
MRU_Save(Globals.pMRUfind);
MRU_Save(Globals.pMRUreplace);
}
else {
MRU_MergeSave(Globals.pMRUfind, false, false, false);
MRU_MergeSave(Globals.pMRUreplace, false, false, false);
}
MRU_Destroy(Globals.pMRUfind);
Globals.pMRUfind = NULL;
MRU_Destroy(Globals.pMRUreplace);
Globals.pMRUreplace = NULL;
}
}
if (ok) {
ok = CloseSettingsFile();
}
// separate INI files for Style-Themes
if (Globals.idxSelectedTheme >= 2) {
Style_SaveSettings();
}
EndWaitCursor();
return ok;
@ -2007,17 +2051,6 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam,LPARAM lParam)
pDropTarget = RegisterDragAndDrop(hwnd, &cfDrpF, 1, WM_NULL, DropFilesProc, (void*)Globals.hwndEdit);
#endif
// File MRU
Globals.pFileMRU = MRU_Create(_s_RecentFiles, MRU_NOCASE, MRU_ITEMSFILE);
MRU_Load(Globals.pFileMRU);
Globals.pMRUfind = MRU_Create(_s_RecentFind, (/*IsWindowsNT()*/true) ? MRU_UTF8 : 0, MRU_ITEMSFNDRPL);
MRU_Load(Globals.pMRUfind);
SetFindPattern(Globals.pMRUfind->pszItems[0]);
Globals.pMRUreplace = MRU_Create(_s_RecentReplace, (/*IsWindowsNT()*/true) ? MRU_UTF8 : 0, MRU_ITEMSFNDRPL);
MRU_Load(Globals.pMRUreplace);
if (Globals.hwndEdit == NULL || s_hwndEditFrame == NULL ||
Globals.hwndStatus == NULL || Globals.hwndToolbar == NULL || s_hwndReBar == NULL) {
return -1LL;
@ -2455,35 +2488,9 @@ LRESULT MsgEndSession(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
DestroyWindow(Globals.hwndDlgCustomizeSchemes);
}
// call SaveSettings() when Globals.hwndToolbar is still valid
// call SaveAllSettings() when Globals.hwndToolbar is still valid
SaveAllSettings(false);
if (StrIsNotEmpty(Globals.IniFile))
{
// Cleanup unwanted MRU'selEmpty
if (!Settings.SaveRecentFiles) {
MRU_Empty(Globals.pFileMRU);
MRU_Save(Globals.pFileMRU);
}
else {
MRU_MergeSave(Globals.pFileMRU, true, Flags.RelativeFileMRU, Flags.PortableMyDocs);
}
MRU_Destroy(Globals.pFileMRU);
if (!Settings.SaveFindReplace) {
MRU_Empty(Globals.pMRUfind);
MRU_Empty(Globals.pMRUreplace);
MRU_Save(Globals.pMRUfind);
MRU_Save(Globals.pMRUreplace);
}
else {
MRU_MergeSave(Globals.pMRUfind, false, false, false);
MRU_MergeSave(Globals.pMRUreplace, false, false, false);
}
MRU_Destroy(Globals.pMRUfind);
MRU_Destroy(Globals.pMRUreplace);
}
// Remove tray icon if necessary
ShowNotifyIcon(hwnd, false);
@ -9453,7 +9460,7 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload,
_END_UNDO_ACTION_
}
else {
fSuccess = FileIO(true, szFileName, bSkipUnicodeDetect, bSkipANSICPDetection, bForceEncDetection, true, &fioStatus, false, false);
fSuccess = FileIO(true, szFileName, bSkipUnicodeDetect, bSkipANSICPDetection, bForceEncDetection, !s_IsThisAnElevatedRelaunch, &fioStatus, false, false);
}
}
@ -9658,7 +9665,8 @@ bool FileRevert(LPCWSTR szFileName, bool bIgnoreCmdLnEnc)
//
bool DoElevatedRelaunch(EditFileIOStatus* pFioStatus)
{
SaveSettings(false);
SaveAllSettings(false);
s_flagDoRelaunchElevated = true;
LPWSTR lpCmdLine = GetCommandLine();

View File

@ -138,15 +138,7 @@ static int s_cyStyleSelectDlg = STYLESELECTDLG_Y;
//=============================================================================
typedef struct _themeFiles
{
UINT rid;
WCHAR szName[80];
WCHAR szFilePath[MAX_PATH];
} THEMEFILES, * PTHEMEFILES;
static THEMEFILES Theme_Files[] =
THEMEFILES Theme_Files[] =
{
{ 0, L"Default", L"" },
{ 0, L"Standard", L"" },
@ -176,9 +168,6 @@ static THEMEFILES Theme_Files[] =
{ 0, L"", L"" }
};
unsigned ThemeItems_CountOf() { return COUNTOF(Theme_Files); }
static unsigned s_idxSelectedTheme = 1; // Default(0), Standard(1)
const WCHAR* const STYLING_THEME_NAME = L"ThemeFileName";
static void _FillThemesMenuTable()
{
@ -282,17 +271,17 @@ bool Style_InsertThemesMenu(HMENU hMenuBar)
}
// --- insert ---
WCHAR wchMenuItemStrg[80] = { L'\0' };
WCHAR wchMenuItemStrg[128] = { L'\0' };
GetLngString(IDS_MUI_MENU_THEMES, wchMenuItemStrg, COUNTOF(wchMenuItemStrg));
//bool const res = InsertMenu(hMenuBar, pos, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)s_hmenuThemes, wchMenuItemStrg);
bool const res = InsertMenu(hMenuBar, IDM_VIEW_SCHEMECONFIG, MF_BYCOMMAND | MF_POPUP | MF_STRING, (UINT_PTR)s_hmenuThemes, wchMenuItemStrg);
CheckCmd(hMenuBar, Theme_Files[s_idxSelectedTheme].rid, true);
CheckCmd(hMenuBar, Theme_Files[Globals.idxSelectedTheme].rid, true);
if (StrIsEmpty(Theme_Files[s_idxSelectedTheme].szFilePath))
if (StrIsEmpty(Theme_Files[Globals.idxSelectedTheme].szFilePath))
{
EnableCmd(hMenuBar, Theme_Files[s_idxSelectedTheme].rid, false);
EnableCmd(hMenuBar, Theme_Files[Globals.idxSelectedTheme].rid, false);
}
return res;
@ -317,15 +306,15 @@ void Style_DynamicThemesMenuCmd(int cmd, bool bEnableSaveSettings)
if ((iThemeIdx < 0) || (iThemeIdx >= ThemeItems_CountOf())) {
return;
}
if (iThemeIdx == s_idxSelectedTheme) { return; }
if (iThemeIdx == Globals.idxSelectedTheme) { return; }
CheckCmd(Globals.hMainMenu, Theme_Files[s_idxSelectedTheme].rid, false);
CheckCmd(Globals.hMainMenu, Theme_Files[Globals.idxSelectedTheme].rid, false);
if (Settings.SaveSettings) {
if (s_idxSelectedTheme == 0) {
if (Globals.idxSelectedTheme == 0) {
// internal defaults
}
else if (s_idxSelectedTheme == 1) {
else if (Globals.idxSelectedTheme == 1) {
if (bEnableSaveSettings) {
CreateIniFile();
if (StrIsNotEmpty(Globals.IniFile)) {
@ -333,21 +322,22 @@ void Style_DynamicThemesMenuCmd(int cmd, bool bEnableSaveSettings)
}
}
}
else if (PathFileExists(Theme_Files[s_idxSelectedTheme].szFilePath))
else if (PathFileExists(Theme_Files[Globals.idxSelectedTheme].szFilePath))
{
bool const bIndependentFromStandardSettings = true;
Style_ExportToFile(Theme_Files[s_idxSelectedTheme].szFilePath, bIndependentFromStandardSettings);
Style_ExportToFile(Theme_Files[Globals.idxSelectedTheme].szFilePath, bIndependentFromStandardSettings);
}
}
s_idxSelectedTheme = iThemeIdx;
Globals.idxSelectedTheme = iThemeIdx;
StringCchCopy(Globals.SelectedThemeName, COUNTOF(Globals.SelectedThemeName), Theme_Files[Globals.idxSelectedTheme].szName);
bool result = true;
if ((s_idxSelectedTheme > 1) && PathFileExists(Theme_Files[s_idxSelectedTheme].szFilePath))
if ((Globals.idxSelectedTheme > 1) && PathFileExists(Theme_Files[Globals.idxSelectedTheme].szFilePath))
{
result = Style_ImportFromFile(Theme_Files[s_idxSelectedTheme].szFilePath);
result = Style_ImportFromFile(Theme_Files[Globals.idxSelectedTheme].szFilePath);
}
else if (s_idxSelectedTheme == 1) {
else if (Globals.idxSelectedTheme == 1) {
result = Style_ImportFromFile(Globals.IniFile);
}
else {
@ -358,11 +348,11 @@ void Style_DynamicThemesMenuCmd(int cmd, bool bEnableSaveSettings)
Style_ResetCurrentLexer(Globals.hwndEdit);
SendWMSize(Globals.hwndMain, NULL);
UpdateUI();
_EnableSchemeConfig(s_idxSelectedTheme != 0);
_EnableSchemeConfig(Globals.idxSelectedTheme != 0);
UpdateAllBars(true);
}
CheckCmd(Globals.hMainMenu, Theme_Files[s_idxSelectedTheme].rid, true);
CheckCmd(Globals.hMainMenu, Theme_Files[Globals.idxSelectedTheme].rid, true);
}
@ -489,19 +479,18 @@ void Style_Load()
_FillThemesMenuTable();
// get theme name from settings
WCHAR wchThemeName[80];
IniFileGetString(Globals.IniFile, L"Styles", STYLING_THEME_NAME, L"", wchThemeName, COUNTOF(wchThemeName));
unsigned iTheme = 1;
if (StrIsNotEmpty(wchThemeName)) {
if (StrIsNotEmpty(Globals.SelectedThemeName)) {
for (; iTheme < ThemeItems_CountOf(); ++iTheme)
{
if (StringCchCompareXI(wchThemeName, Theme_Files[iTheme].szName) == 0) { break; }
if (StringCchCompareXI(Globals.SelectedThemeName, Theme_Files[iTheme].szName) == 0) { break; }
}
}
s_idxSelectedTheme = (iTheme < ThemeItems_CountOf()) ? iTheme : 1;
Globals.idxSelectedTheme = (iTheme < ThemeItems_CountOf()) ? iTheme : 1;
StringCchCopy(Globals.SelectedThemeName, COUNTOF(Globals.SelectedThemeName), Theme_Files[Globals.idxSelectedTheme].szName);
Style_ImportFromFile(Theme_Files[s_idxSelectedTheme].szFilePath);
Style_ImportFromFile(Theme_Files[Globals.idxSelectedTheme].szFilePath);
}
@ -653,18 +642,11 @@ bool Style_ImportFromFile(const WCHAR* szFile)
//=============================================================================
//
// Style_Save()
// Style_SaveSettings()
//
void Style_Save()
void Style_SaveSettings()
{
Style_ExportToFile(Theme_Files[s_idxSelectedTheme].szFilePath, Globals.bIniFileFromScratch);
if (s_idxSelectedTheme > 1) {
IniFileSetString(Globals.IniFile, L"Styles", STYLING_THEME_NAME, Theme_Files[s_idxSelectedTheme].szName);
}
else {
IniFileDelete(Globals.IniFile, L"Styles", STYLING_THEME_NAME, false);
}
Style_ExportToFile(Theme_Files[Globals.idxSelectedTheme].szFilePath, Globals.bIniFileFromScratch);
}
@ -705,7 +687,7 @@ bool Style_Export(HWND hwnd)
//=============================================================================
//
// Style_Export()
// Style_ToIniSection()
//
#define SAVE_STYLE_IF_NOT_EQ_DEFAULT(TYPE, VARNAME, VALUE, DEFAULT) \
@ -714,7 +696,6 @@ bool Style_Export(HWND hwnd)
} else { \
IniSectionDelete(Styles_Section, _W(_STRG(VARNAME)), false); \
}
// ----------------------------------------------------------------------------
void Style_ToIniSection(bool bForceAll)
@ -818,7 +799,7 @@ void Style_ToIniSection(bool bForceAll)
bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll)
{
if (StrIsEmpty(szFile)) {
if (s_idxSelectedTheme != 0) {
if (Globals.idxSelectedTheme != 0) {
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_SETTINGSNOTSAVED);
}
return false;
@ -4332,7 +4313,7 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam
{
_ApplyDialogItemText(hwnd, pCurrentLexer, pCurrentStyle, iCurStyleIdx, bIsStyleSelected);
if ((!bWarnedNoIniFile && StrIsEmpty(Theme_Files[s_idxSelectedTheme].szFilePath)) && (s_idxSelectedTheme > 0))
if ((!bWarnedNoIniFile && StrIsEmpty(Theme_Files[Globals.idxSelectedTheme].szFilePath)) && (Globals.idxSelectedTheme > 0))
{
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_SETTINGSNOTSAVED);
bWarnedNoIniFile = true;

View File

@ -32,7 +32,7 @@
void Style_Load();
bool Style_Import(HWND hwnd);
bool Style_ImportFromFile(const WCHAR* szFile);
void Style_Save();
void Style_SaveSettings();
bool Style_Export(HWND hwnd);
void Style_ToIniSection(bool bForceAll);
bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll);

View File

@ -275,6 +275,7 @@ typedef struct _constants_t
int const StdDefaultLexerID; // Pure Text Files
const WCHAR* const FileBrowserMiniPath;
const WCHAR* const SectionSuppressedMessages;
const WCHAR* const StylingThemeName;
} CONSTANTS_T, *PCONSTANTS_T;
@ -326,6 +327,8 @@ typedef struct _globals_t
bool bFindReplCopySelOrClip;
bool bReplaceInitialized;
bool bDocHasInconsistentEOLs;
unsigned idxSelectedTheme;
WCHAR SelectedThemeName[128];
FR_STATES FindReplaceMatchFoundState;
@ -433,7 +436,7 @@ typedef struct _settings_t
int CustomSchemesDlgPosY;
bool MuteMessageBeep;
bool SplitUndoTypingSeqOnLnBreak;
RECT PrintMargin;
EDITFINDREPLACE EFR_Data;
WCHAR OpenWithDir[MAX_PATH];
@ -596,6 +599,18 @@ typedef struct _docviewpos_t
#define INIT_DOCVIEWPOS { 0, 0, /*0, 0,*/ 0, 0, 0, 0, 0, false }
//=============================================================================
typedef struct _themeFiles
{
UINT rid;
WCHAR szName[80];
WCHAR szFilePath[MAX_PATH];
} THEMEFILES, * PTHEMEFILES;
//=============================================================================
// --------- common defines --------