+fix: trim line endings on Save except AutoSave

+fix: support User-Doc on Recent Files Jump List
This commit is contained in:
METANEOCORTEX\Kotti 2021-12-20 13:05:20 +01:00
parent 9b4ccdefd8
commit 958d78edc1
7 changed files with 64 additions and 86 deletions

View File

@ -2332,7 +2332,7 @@ bool MRU_Destroy(LPMRULIST pmru)
}
int MRU_Compare(LPMRULIST pmru, LPCWSTR psz1, LPCWSTR psz2)
static int _MRU_Compare(LPMRULIST pmru, LPCWSTR psz1, LPCWSTR psz2)
{
if (pmru) {
if (pmru->iFlags & MRU_NOCASE) {
@ -2349,7 +2349,7 @@ bool MRU_Add(LPMRULIST pmru, LPCWSTR pszNew, cpi_enc_t iEnc, DocPos iPos, DocPos
if (pmru) {
int i = 0;
for (; i < pmru->iSize; ++i) {
if (MRU_Compare(pmru, pmru->pszItems[i], pszNew) == 0) {
if (_MRU_Compare(pmru, pmru->pszItems[i], pszNew) == 0) {
LocalFree(pmru->pszItems[i]); // StrDup()
pmru->pszItems[i] = NULL;
break;
@ -2374,50 +2374,21 @@ bool MRU_Add(LPMRULIST pmru, LPCWSTR pszNew, cpi_enc_t iEnc, DocPos iPos, DocPos
}
bool MRU_FindFile(LPMRULIST pmru, LPCWSTR pszFile, int* iIndex)
{
*iIndex = 0;
bool res = false;
if (pmru) {
HPATHL hpth = Path_Allocate(NULL);
int i = 0;
for (i = 0; i < pmru->iSize; ++i) {
if (pmru->pszItems[i] == NULL) {
break;
}
if (StringCchCompareXI(pmru->pszItems[i], pszFile) == 0) {
res = true;
break;
}
Path_Reset(hpth, pmru->pszItems[i]);
Path_AbsoluteFromApp(hpth, true);
if (StringCchCompareXI(Path_Get(hpth), pszFile) == 0) {
res = true;
break;
}
}
*iIndex = i;
Path_Release(hpth);
}
return res;
}
bool MRU_FindPath(LPMRULIST pmru, const HPATHL hpth, int* iIndex)
{
*iIndex = 0;
bool res = false;
if (pmru) {
HPATHL hcpy = Path_Copy(hpth);
Path_AbsoluteFromApp(hcpy, true);
HPATHL hcmp = Path_Allocate(NULL);
int i = 0;
for (i = 0; i < pmru->iSize; ++i) {
if (pmru->pszItems[i] == NULL) {
break;
}
if (StringCchCompareXI(pmru->pszItems[i], Path_Get(hpth)) == 0) {
res = true;
break;
}
Path_Reset(hcmp, pmru->pszItems[i]);
Path_AbsoluteFromApp(hcmp, true);
if (StringCchCompareXI(Path_Get(hcmp), Path_Get(hpth)) == 0) {
@ -2426,17 +2397,20 @@ bool MRU_FindPath(LPMRULIST pmru, const HPATHL hpth, int* iIndex)
}
}
*iIndex = i;
Path_Release(hcmp);
Path_Release(hcpy);
}
return res;
}
bool MRU_AddFile(LPMRULIST pmru, LPCWSTR pszFile, bool bRelativePath, bool bUnexpandMyDocs,
bool MRU_AddPath(LPMRULIST pmru, const HPATHL hpth, bool bRelativePath, bool bUnexpandMyDocs,
cpi_enc_t iEnc, DocPos iPos, DocPos iSelAnc, LPCWSTR pszBookMarks)
{
if (pmru) {
int i = 0;
bool const bAlreadyInList = MRU_FindFile(pmru, pszFile, &i);
bool const bAlreadyInList = MRU_FindPath(pmru, hpth, &i);
if (bAlreadyInList) {
LocalFree(pmru->pszItems[i]); // StrDup()
pmru->pszItems[i] = NULL;
@ -2451,21 +2425,18 @@ bool MRU_AddFile(LPMRULIST pmru, LPCWSTR pszFile, bool bRelativePath, bool bUnex
pmru->pszBookMarks[i] = pmru->pszBookMarks[i - 1];
}
HPATHL const hpth = Path_Allocate(pszFile);
HPATHL hpth_cpy = Path_Copy(hpth);
if (bRelativePath) {
Path_RelativeToApp(hpth, true, true, bUnexpandMyDocs);
Path_RelativeToApp(hpth_cpy, true, true, bUnexpandMyDocs);
}
pmru->pszItems[0] = StrDupW(Path_Get(hpth)); // LocalAlloc()
pmru->pszItems[0] = StrDupW(Path_Get(hpth_cpy)); // LocalAlloc()
pmru->iEncoding[0] = iEnc;
pmru->iCaretPos[0] = (Settings.PreserveCaretPos ? iPos : -1);
pmru->iSelAnchPos[0] = (Settings.PreserveCaretPos ? iSelAnc : -1);
pmru->pszBookMarks[0] = (pszBookMarks ? StrDupW(pszBookMarks) : NULL); // LocalAlloc()
if (!bAlreadyInList) {
AddFilePathToRecentDocs(hpth);
}
Path_Release(hpth);
Path_Release(hpth_cpy);
return bAlreadyInList;
}
@ -2712,7 +2683,7 @@ bool MRU_MergeSave(LPMRULIST pmru, bool bAddFiles, bool bRelativePath, bool bUne
if (pmru->pszItems[i]) {
Path_Reset(hpth, pmru->pszItems[i]);
Path_AbsoluteFromApp(hpth, true);
MRU_AddFile(pmruBase, Path_Get(hpth), bRelativePath, bUnexpandMyDocs,
MRU_AddPath(pmruBase, hpth, bRelativePath, bUnexpandMyDocs,
pmru->iEncoding[i], pmru->iCaretPos[i], pmru->iSelAnchPos[i], pmru->pszBookMarks[i]);
}
}

View File

@ -139,9 +139,8 @@ void AddFilePathToRecentDocs(const HPATHL hpthFile);
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, DocPos iSelAnc, LPCWSTR pszBookMarks);
bool MRU_FindFile(LPMRULIST pmru, LPCWSTR pszFile, int* iIndex);
bool MRU_FindPath(LPMRULIST pmru, const HPATHL hpth, int* iIndex);
bool MRU_AddFile(LPMRULIST pmru, LPCWSTR pszFile, bool bRelativePath, bool bUnexpandMyDocs, cpi_enc_t iEnc, DocPos iPos, DocPos iSelAnc, LPCWSTR pszBookMarks);
bool MRU_AddPath(LPMRULIST pmru, const HPATHL hpth, bool bRelativePath, bool bUnexpandMyDocs, cpi_enc_t iEnc, DocPos iPos, DocPos iSelAnc, LPCWSTR pszBookMarks);
bool MRU_Delete(LPMRULIST pmru, int iIndex);
bool MRU_Empty(LPMRULIST pmru, bool bExceptLeast, bool bDelete);
int MRU_Enum(LPMRULIST pmru, int iIndex, LPWSTR pszItem, int cchItem);

View File

@ -1486,8 +1486,8 @@ bool EditSaveFile(
return false;
}
// maybe not enough time to do that (WM_POWERBROADCAST, WM_QUERYENDSESSION)
if (!(fSaveFlags & FSF_EndSession)) {
// maybe not enough time to do that (WM_POWERBROADCAST)
if ((fSaveFlags & FSF_EndSession) || !(fSaveFlags & FSF_AutoSave)) {
// ensure consistent line endings
if (Settings.FixLineEndings) {
@ -1655,7 +1655,7 @@ bool EditSaveFile(
CloseHandle(hFile);
if (bWriteSuccess && !(fSaveFlags & FSF_SaveCopy)) {
if (bWriteSuccess && (!(fSaveFlags & (FSF_SaveCopy | FSF_AutoSave)) || (fSaveFlags & FSF_EndSession))) {
SetSavePoint();
}
return bWriteSuccess;

View File

@ -1830,9 +1830,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case WM_QUERYENDSESSION:
if (Settings.AutoSaveOptions & ASB_Shutdown) {
AutoSaveDoWork(true);
AutoSaveDoWork(FSF_EndSession);
}
if (FileSave(FSF_Ask | FSF_EndSession)) {
else if (FileSave(FSF_Ask | FSF_EndSession)) {
return TRUE;
}
break;
@ -1841,7 +1841,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
if (wParam == PBT_APMSUSPEND) {
// we only have 2 seconds to save current file
if (Settings.AutoSaveOptions & ASB_Suspend) {
AutoSaveDoWork(true);
AutoSaveDoWork(FSF_None);
}
}
break;
@ -2998,7 +2998,7 @@ LRESULT MsgEndSession(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
}
// Terminate AutoSave
AutoSaveStop(true);
AutoSaveStop();
// Terminate file watching
InstallFileWatching(false);
@ -6210,7 +6210,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
AutoSaveStart(periodSav != Settings.AutoSaveInterval);
}
else {
AutoSaveStop(false);
AutoSaveStop();
}
}
}
@ -6320,7 +6320,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case CMD_SHIFTESC:
FileSave(FSF_None);
FileSave(FSF_EndSession);
case IDT_FILE_EXIT:
CloseApplication();
break;
@ -10397,7 +10397,7 @@ bool FileIO(bool fLoad, const HPATHL hfile_pth, EditFileIOStatus* status,
fSuccess = EditLoadFile(Globals.hwndEdit, hfile_pth, status, fLoadFlags, bSetSavePoint);
} else {
int idx;
if (MRU_FindFile(Globals.pFileMRU, Path_Get(hfile_pth), &idx)) {
if (MRU_FindPath(Globals.pFileMRU, hfile_pth, &idx)) {
Globals.pFileMRU->iEncoding[idx] = status->iEncoding;
Globals.pFileMRU->iCaretPos[idx] = (Settings.PreserveCaretPos ? SciCall_GetCurrentPos() : -1);
Globals.pFileMRU->iSelAnchPos[idx] = (Settings.PreserveCaretPos ? SciCall_GetAnchor() : -1);
@ -10528,7 +10528,7 @@ bool FileLoad(const HPATHL hfile_pth, FileLoadFlags fLoadFlags)
UpdateTitleBar(Globals.hwndMain);
// Terminate file watching
AutoSaveStop(true);
AutoSaveStop();
InstallFileWatching(false); // terminate
if (Settings.ResetFileWatching) {
_ResetFileWatchingMode();
@ -10611,7 +10611,7 @@ bool FileLoad(const HPATHL hfile_pth, FileLoadFlags fLoadFlags)
}
else {
int idx;
if (!(fLoadFlags & FLF_Reload) && MRU_FindFile(Globals.pFileMRU, Path_Get(hopen_file), &idx)) {
if (!(fLoadFlags & FLF_Reload) && MRU_FindPath(Globals.pFileMRU, hopen_file, &idx)) {
fioStatus.iEncoding = Globals.pFileMRU->iEncoding[idx];
if (Encoding_IsValid(fioStatus.iEncoding)) {
Encoding_SrcWeak(fioStatus.iEncoding);
@ -10660,13 +10660,14 @@ bool FileLoad(const HPATHL hfile_pth, FileLoadFlags fLoadFlags)
DocPos iCaretPos = -1;
DocPos iAnchorPos = -1;
LPCWSTR pszBookMarks = L"";
if (!(fLoadFlags & FLF_Reload) && MRU_FindFile(Globals.pFileMRU, Path_Get(Paths.CurrentFile), &idx)) {
if (!(fLoadFlags & FLF_Reload) && MRU_FindPath(Globals.pFileMRU, Paths.CurrentFile, &idx)) {
iCaretPos = Globals.pFileMRU->iCaretPos[idx];
iAnchorPos = Globals.pFileMRU->iSelAnchPos[idx];
pszBookMarks = Globals.pFileMRU->pszBookMarks[idx];
}
if (!(Flags.bDoRelaunchElevated || s_IsThisAnElevatedRelaunch)) {
MRU_AddFile(Globals.pFileMRU, Path_Get(Paths.CurrentFile), Flags.RelativeFileMRU, Flags.PortableMyDocs, fioStatus.iEncoding, iCaretPos, iAnchorPos, pszBookMarks);
MRU_AddPath(Globals.pFileMRU, Paths.CurrentFile, Flags.RelativeFileMRU, Flags.PortableMyDocs, fioStatus.iEncoding, iCaretPos, iAnchorPos, pszBookMarks);
AddFilePathToRecentDocs(Paths.CurrentFile);
}
EditSetBookmarkList(Globals.hwndEdit, pszBookMarks);
@ -10675,7 +10676,7 @@ bool FileLoad(const HPATHL hfile_pth, FileLoadFlags fLoadFlags)
}
// Install watching of the current file
AutoSaveStop(!(fLoadFlags & FLF_Reload));
AutoSaveStop();
if (!(fLoadFlags & FLF_Reload)) {
InstallFileWatching(false); // terminate previous
if (Settings.ResetFileWatching) {
@ -10998,7 +10999,7 @@ bool FileSave(FileSaveFlags fSaveFlags)
}
Globals.pFileMRU->pszBookMarks[idx] = StrDup(wchBookMarks);
}
AutoSaveStop(fSaveFlags & FSF_EndSession);
AutoSaveStop();
ResetFileObservationData(true);
return true;
}
@ -11018,7 +11019,7 @@ bool FileSave(FileSaveFlags fSaveFlags)
case IDCANCEL:
return false;
case IDNO:
AutoSaveStop(false);
AutoSaveStop();
return true;
default:
// proceed
@ -11106,7 +11107,8 @@ bool FileSave(FileSaveFlags fSaveFlags)
const DocPos iAnchorPos = Sci_IsMultiOrRectangleSelection() ? -1 : SciCall_GetAnchor();
WCHAR wchBookMarks[MRU_BMRK_SIZE] = { L'\0' };
EditGetBookmarkList(Globals.hwndEdit, wchBookMarks, COUNTOF(wchBookMarks));
MRU_AddFile(Globals.pFileMRU, Path_Get(Paths.CurrentFile), Flags.RelativeFileMRU, Flags.PortableMyDocs, iCurrEnc, iCaretPos, iAnchorPos, wchBookMarks);
MRU_AddPath(Globals.pFileMRU, Paths.CurrentFile, Flags.RelativeFileMRU, Flags.PortableMyDocs, iCurrEnc, iCaretPos, iAnchorPos, wchBookMarks);
AddFilePathToRecentDocs(Paths.CurrentFile);
SetSavePoint();
@ -11163,7 +11165,7 @@ bool FileSave(FileSaveFlags fSaveFlags)
}
}
if (fSuccess) {
AutoSaveStop(fSaveFlags & FSF_EndSession);
AutoSaveStop();
ResetFileObservationData(true);
}
@ -12120,10 +12122,8 @@ void AutoSaveStart(bool bReset)
//
// AutoSaveStop()
//
void AutoSaveStop(bool bKeepBackup)
void AutoSaveStop()
{
UNREFERENCED_PARAMETER(bKeepBackup);
if (s_bAutoSaveTimerSet) {
s_bAutoSaveTimerSet = false;
KillTimer(Globals.hwndMain, ID_AUTOSAVETIMER);
@ -12135,14 +12135,12 @@ void AutoSaveStop(bool bKeepBackup)
//
// AutoSaveDoWork()
//
void AutoSaveDoWork(bool bKeepBackup)
void AutoSaveDoWork(FileSaveFlags fSaveFlags)
{
UNREFERENCED_PARAMETER(bKeepBackup);
if (!IsDocumentModified()) {
return;
}
FileSave(FSF_None);
FileSave(fSaveFlags | FSF_AutoSave);
}
//=============================================================================
@ -12156,7 +12154,7 @@ void CALLBACK AutoSaveTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dw
UNREFERENCED_PARAMETER(idEvent);
UNREFERENCED_PARAMETER(dwTime);
AutoSaveDoWork(false);
AutoSaveDoWork(FSF_None);
}

View File

@ -166,8 +166,8 @@ void CALLBACK PasteBoardTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD
void InstallFileWatching(const bool bInstall);
void AutoSaveStart(bool bReset);
void AutoSaveStop(bool bKeepBackup);
void AutoSaveDoWork(bool bKeepBackup);
void AutoSaveStop();
void AutoSaveDoWork(FileSaveFlags fSaveFlags);
void CALLBACK AutoSaveTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
//LPCWSTR BackupGetDefaultFolder(HPATHL hfile_pth_io);

View File

@ -1751,6 +1751,13 @@ bool PTHAPI Path_CanonicalizeEx(HPATHL hpth_in_out, const HPATHL hdir_rel_base)
if (!hstr_io)
return false;
if (StrgFind(hstr_io, PATH_CSIDL_MYDOCUMENTS, 0) == 0) {
HPATHL hfld_pth = Path_Allocate(NULL);
Path_GetKnownFolder(&FOLDERID_Documents, hfld_pth);
StrgReplace(hstr_io, PATH_CSIDL_MYDOCUMENTS, PathGet(hfld_pth));
Path_Release(hfld_pth);
}
ExpandEnvironmentStrgs(hstr_io, true);
bool res = false;
@ -1991,19 +1998,19 @@ void PTHAPI Path_RelativeToApp(HPATHL hpth_in_out, bool bSrcIsFile, bool bUnexpa
return;
}
HPATHL happdir_pth = Path_Allocate(NULL);
HPATHL const happdir_pth = Path_Allocate(NULL);
Path_GetAppDirectory(happdir_pth);
HPATHL husrdoc_pth = Path_Allocate(NULL);
HPATHL const husrdoc_pth = Path_Allocate(NULL);
Path_GetKnownFolder(&FOLDERID_Documents, husrdoc_pth);
HPATHL hprgs_pth = Path_Allocate(NULL);
HPATHL const hprgs_pth = Path_Allocate(NULL);
#ifdef _WIN64
Path_GetKnownFolder(&FOLDERID_ProgramFiles, hprgs_pth);
#else
Path_GetKnownFolder(&FOLDERID_ProgramFilesX86, hprgs_pth);
#endif
//~HPATHL hwindows_pth = Path_Allocate(NULL);
//~HPATHL const hwindows_pth = Path_Allocate(NULL);
//~Path_GetKnownFolder(&FOLDERID_Windows, hwindows_pth); // deprecated
bool const bPathIsRelative = _Path_IsRelative(hpth_in_out);
@ -2023,14 +2030,15 @@ void PTHAPI Path_RelativeToApp(HPATHL hpth_in_out, bool bSrcIsFile, bool bUnexpa
}
}
if (bUnexpandEnv) {
Path_UnExpandEnvStrings(hpth_in_out);
}
Path_Release(htmp_pth);
Path_Release(hprgs_pth);
Path_Release(husrdoc_pth);
Path_Release(happdir_pth);
if (bUnexpandEnv) {
Path_UnExpandEnvStrings(hpth_in_out);
}
}
// ----------------------------------------------------------------------------
@ -2156,6 +2164,7 @@ void PTHAPI Path_AbsoluteFromApp(HPATHL hpth_in_out, bool bExpandEnv)
HSTRINGW htmp_str = ToHStrgW(htmp_pth); // inplace hpth_in_out
if (StrgFind(hstr_in_out, PATH_CSIDL_MYDOCUMENTS, 0) == 0) {
HPATHL hfld_pth = Path_Allocate(NULL);
Path_GetKnownFolder(&FOLDERID_Documents, hfld_pth);
StrgReplace(htmp_str, PATH_CSIDL_MYDOCUMENTS, PathGet(hfld_pth));

View File

@ -791,7 +791,8 @@ typedef enum FileSaveFlags {
FSF_Ask = 1 << 1,
FSF_SaveAs = 1 << 2,
FSF_SaveCopy = 1 << 3,
FSF_EndSession = 1 << 4
FSF_AutoSave = 1 << 4,
FSF_EndSession = 1 << 5
} FileSaveFlags;