diff --git a/src/Dialogs.c b/src/Dialogs.c index 1bb144d09..3a74b5685 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -4864,9 +4864,9 @@ void DialogNewWindow(HWND hwnd, bool bSaveBeforeOpen, const HPATHL hFilePath, WI HPATHL hmod_pth = Path_Allocate(NULL); Path_GetModuleFilePath(hmod_pth); - StringCchPrintf(wch, COUNTOF(wch), L"\"-appid=%s\"", Settings2.AppUserModelID); + StringCchPrintf(wch, COUNTOF(wch), L"-appid=\"%s\"", Settings2.AppUserModelID); HSTRINGW hparam_str = StrgCreate(wch); - StringCchPrintf(wch, COUNTOF(wch), L"\" -sysmru=%i\"", (Flags.ShellUseSystemMRU ? 1 : 0)); + StringCchPrintf(wch, COUNTOF(wch), L" -sysmru=\"%i\"", (Flags.ShellUseSystemMRU ? 1 : 0)); StrgCat(hparam_str, wch); if (Path_IsNotEmpty(Paths.IniFile)) { HPATHL hini_path = Path_Copy(Paths.IniFile); @@ -5263,12 +5263,19 @@ static HPATHL s_pthCachedFilePath = NULL; void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T properties, LPCWSTR lpszExcerpt, bool forceRedraw) { static TITLEPROPS_T s_properties = { 0 }; + static WCHAR s_compTitleExcerpt[MIDSZ_BUFFER] = { L'\0' }; static size_t s_hashFileName = 0; - static size_t s_hashExcerpt = 0; + + bool bExcerptChanged = false; + bool bFilePathChanged = false; if (s_bFreezeAppTitle) { return; } + if (!s_pthCachedFilePath) { + s_pthCachedFilePath = Path_Allocate(L""); + } + if (!forceRedraw) { if (s_properties.iFormat != properties.iFormat) { @@ -5296,16 +5303,17 @@ void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T prop forceRedraw = true; } else { - size_t const hashExcerpt = SimpleHash(lpszExcerpt); - if (s_hashExcerpt != hashExcerpt) { - forceRedraw = true; - } - else { - size_t const hashFileName = SimpleHash(Path_Get(pthFilePath)); - if (s_hashFileName != hashFileName) { + for (int i = 0; i < COUNTOF(s_compTitleExcerpt); ++i) { + if (s_compTitleExcerpt[i] != lpszExcerpt[i]) { forceRedraw = true; + bExcerptChanged = true; + break; } } + if (Path_StrgComparePath(s_pthCachedFilePath, pthFilePath, Paths.WorkingDirectory) != 0) { + forceRedraw = true; + bFilePathChanged = true; + } } } @@ -5315,12 +5323,19 @@ void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T prop // save current state s_properties = properties; - s_hashExcerpt = SimpleHash(lpszExcerpt); - s_hashFileName = SimpleHash(Path_Get(pthFilePath)); - if (!s_pthCachedFilePath) { - s_pthCachedFilePath = Path_Allocate(L""); + if (bExcerptChanged) { + StringCchCopy(s_compTitleExcerpt, COUNTOF(s_compTitleExcerpt), lpszExcerpt); } + if (bFilePathChanged) { + if (Path_IsNotEmpty(pthFilePath)) { + Path_Reset(s_pthCachedFilePath, Path_Get(pthFilePath)); + } + else { + Path_Empty(s_pthCachedFilePath, false); + } + } + WCHAR szAppName[SMALL_BUFFER] = { L'\0' }; if (properties.bPasteBoard) { @@ -5363,11 +5378,11 @@ void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T prop else if (Path_IsNotEmpty(pthFilePath)) { if (properties.iFormat < 2) { - if (Path_StrgComparePath(s_pthCachedFilePath, pthFilePath, Paths.WorkingDirectory) != 0) { - Path_Reset(s_pthCachedFilePath, Path_Get(pthFilePath)); + if (bFilePathChanged) { + //StringCchCopy(s_wchCachedDisplayName, COUNTOF(s_wchCachedDisplayName), Path_FindFileName(s_pthCachedFilePath)); Path_GetDisplayName(s_wchCachedDisplayName, COUNTOF(s_wchCachedDisplayName), s_pthCachedFilePath, s_szUntitled, true); } - StringCchCat(szTitle, COUNTOF(szTitle), Path_FindFileName(s_pthCachedFilePath)); + StringCchCat(szTitle, COUNTOF(szTitle), s_wchCachedDisplayName); if (properties.iFormat == 1) { HPATHL hdir = Path_Copy(s_pthCachedFilePath); if (Path_IsNotEmpty(hdir)) { @@ -5384,7 +5399,6 @@ void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T prop } } else { - Path_Empty(s_pthCachedFilePath, false); s_wchCachedDisplayName[0] = L'\0'; StringCchCat(szTitle, COUNTOF(szTitle), s_szUntitled); } diff --git a/src/Edit.c b/src/Edit.c index 8f16842be..7197a6ba5 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -3079,20 +3079,18 @@ void EditCutLines(HWND hwnd, const bool bMSBehavSelEmpty) // // EditCopyMultiSelection() // -void EditCopyMultiSelection(HWND hwnd) { - +void EditCopyMultiSelection(HWND hwnd) +{ + UNREFERENCED_PARAMETER(hwnd); if (SciCall_IsSelectionEmpty()) { return; } if (Sci_IsMultiSelection()) { - EditClearClipboard(hwnd); - DocPosU const selCount = SciCall_GetSelections(); - for (DocPosU s = 0; s < selCount; ++s) { - EditCopyRangeAppend(hwnd, SciCall_GetSelectionNStart(s), SciCall_GetSelectionNEnd(s), true); - } - } else { - SciCall_Copy(); + char pchSep[3] = { '\0' }; + Sci_GetCurrentEOL_A(pchSep); + SciCall_SetCopySeparator(pchSep); } + SciCall_Copy(); } diff --git a/src/Edit.h b/src/Edit.h index b245800ad..227bc7252 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -24,7 +24,6 @@ void DuplicateEFR(LPEDITFINDREPLACE dst, CLPCEDITFINDREPLACE src); void ReleaseEFR(LPEDITFINDREPLACE efr); -void EditInitializeSciCtrl(HWND); void EditReplaceSelection(const char* text, bool bForceSel); void EditInitWordDelimiter(HWND hwnd); void EditSetNewText(HWND hwnd, const char* lpstrText, DocPosU lenText, bool bClearUndoHistory, bool bReload); diff --git a/src/Helpers.c b/src/Helpers.c index 8ba238aa2..ba0fbe7f9 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -1832,17 +1832,6 @@ int Hex2Char(char* ch, int cnt) } -//============================================================================= - -size_t SimpleHash(LPCWSTR string) -{ - size_t hash = 0; - for (size_t i = 0, l = wcslen(string); i < l; ++i) { - hash += hash * 65599 + string[i]; - } - return hash ^ (hash >> 16); -} - //============================================================================= #ifdef WC2MB_EX diff --git a/src/Notepad3.c b/src/Notepad3.c index e1337b926..a2cd56a86 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -183,6 +183,8 @@ static int const INISECTIONBUFCNT = 32; // .ini file load buffer in KB // ---------------------------------------------------------------------------- +const char* const _assert_msg = "Broken UndoRedo-Transaction!"; + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // (!) ENSURE IDT_FILE_NEW -> IDT_VIEW_NEW_WINDOW corresponds to order of Toolbar.bmp #define NUMTOOLBITMAPS (31) @@ -433,17 +435,11 @@ static LONG _UndoRedoActionMap(const LONG token, const UndoRedoSelection_t** se // => UndoTransActionBegin(); // => EndUndoTransAction(); - -static volatile int UndoRedoActionStackCount = 0; - -__forceinline bool _InUndoRedoTransaction() -{ - return (UndoRedoActionStackCount > 0); -} +// ---------------------------------------------------------------------------- static inline void _SplitUndoTransaction() { - if (_InUndoRedoTransaction()) { + if (SciCall_GetUndoSequence() > 0) { SciCall_EndUndoAction(); SciCall_BeginUndoAction(); } @@ -674,6 +670,7 @@ static inline void ResetFileObservationData(const bool bResetEvt) { ZeroMemory(&(s_FileChgObsvrData.fdCurFile), sizeof(WIN32_FIND_DATA)); } } + } // ---------------------------------------------------------------------------- @@ -1365,6 +1362,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, return 1; } + // !!! now, SciCall_ functions are available (initialized library) + DrawMenuBar(hwnd); HACCEL const hAccMain = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_MAINWND)); @@ -3599,10 +3598,8 @@ LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam) s_WinCurrentWidth = cx; - UpdateToolbar(); - UpdateStatusbar(true); + UpdateToolbar_Now(hwnd); UpdateMargins(true); - UpdateTitlebar(hwnd); //~UpdateUI(); //~ recursion return FALSE; @@ -3770,7 +3767,7 @@ LRESULT MsgDropFiles(HWND hwnd, WPARAM wParam, LPARAM lParam) DragFinish(hDrop); Path_Release(hdrop_pth); - UpdateToolbar(hwnd); + UpdateToolbar_Now(hwnd); } return 0; } @@ -3953,8 +3950,7 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam) FreeMem(params); } - UpdateToolbar(); - UpdateStatusbar(true); + UpdateToolbar_Now(hwnd); UpdateMargins(true); } @@ -4687,8 +4683,8 @@ static void _ApplyChangeHistoryMode() else { SciCall_SetChangeHistory(Settings.ChangeHistoryMode); } - UpdateMargins(true); UpdateToolbar(); + UpdateMargins(true); } @@ -4707,7 +4703,6 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) Style_InsertThemesMenu(Globals.hMainMenu); DrawMenuBar(Globals.hwndMain); UpdateToolbar(); - UpdateStatusbar(true); return FALSE; } #endif @@ -4789,9 +4784,9 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) break; - case IDM_FILE_SAVE: - FileSave(FSF_None); - break; + case IDM_FILE_SAVE: { + FileSave((FileWatching.FileWatchingMode <= FWM_DONT_CARE) ? FileSave(FSF_SaveAlways) : FSF_None); + } break; case IDM_FILE_SAVEAS: @@ -5371,18 +5366,22 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_EDIT_INDENT: EditIndentBlock(Globals.hwndEdit, SCI_TAB, true, false); + //EditIndentBlock(Globals.hwndEdit, SCI_LINEINDENT, true, false); break; case IDM_EDIT_UNINDENT: EditIndentBlock(Globals.hwndEdit, SCI_BACKTAB, true, false); + //EditIndentBlock(Globals.hwndEdit, SCI_LINEDEDENT, true, false); break; case CMD_TAB: EditIndentBlock(Globals.hwndEdit, SCI_TAB, false, false); + //EditIndentBlock(Globals.hwndEdit, SCI_LINEINDENT, false, false); break; case CMD_BACKTAB: EditIndentBlock(Globals.hwndEdit, SCI_BACKTAB, false, false); + //EditIndentBlock(Globals.hwndEdit, SCI_LINEDEDENT, false, false); break; case CMD_CTRLTAB: @@ -8776,7 +8775,7 @@ inline static LRESULT _MsgNotifyLean(const SCNotification* const scn, bool* bMod if (iModType & (SC_MOD_BEFOREINSERT | SC_MOD_BEFOREDELETE)) { *bModified = false; // not yet if (!bInUndoRedoStep) { - if (!_InUndoRedoTransaction() && (_urtoken < URTok_TokenStart)) { + if ((SciCall_GetUndoSequence() <= 1) && (_urtoken < URTok_TokenStart)) { _SaveSelectionToBuffer(); bool const bSelEmpty = SciCall_IsSelectionEmpty(); bool const bIsMultiRectSel = Sci_IsMultiOrRectangleSelection(); @@ -8796,7 +8795,7 @@ inline static LRESULT _MsgNotifyLean(const SCNotification* const scn, bool* bMod } else if (iModType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT)) { if (!bInUndoRedoStep) { - if (!_InUndoRedoTransaction() && (_urtoken >= URTok_TokenStart)) { + if ((SciCall_GetUndoSequence() <= 1) && (_urtoken >= URTok_TokenStart)) { _SaveRedoSelection(_urtoken, SciCall_GetModify()); _urtoken = URTok_NoTransaction; } @@ -9433,6 +9432,8 @@ void ParseCommandLine() LPWSTR const lp2 = AllocMem(sizeof(WCHAR)*len,HEAP_ZERO_MEMORY); LPWSTR const lp3 = AllocMem(sizeof(WCHAR)*len,HEAP_ZERO_MEMORY); + //assert(!"ParseCommandLine() - ATTACH DEBUGGER NOW"); + if (lp1 && lp2 && lp3) { // Start with 2nd argument @@ -9468,6 +9469,7 @@ void ParseCommandLine() bIsFileArg = true; } // pathname + if (bIsFileArg) { LPWSTR const lpFileBuf = AllocMem(sizeof(WCHAR) * len, HEAP_ZERO_MEMORY); @@ -10036,6 +10038,13 @@ void UpdateToolbar() _DelayUpdateTitlebar(_MQ_STD, Globals.hwndMain); } +void UpdateToolbar_Now(const HWND hwnd) +{ + _UpdateToolbarDelayed(); + _UpdateStatusbarDelayed(true); + _UpdateTitlebarDelayed(hwnd); +} + //============================================================================= @@ -10876,6 +10885,8 @@ static void _UndoRedoRecordingStart() static void _UndoRedoRecordingStop() { _UndoRedoActionMap(URTok_NoTransaction, NULL); // clear + while (SciCall_GetUndoSequence() > 0) + SciCall_EndUndoAction(); SciCall_EmptyUndoBuffer(); SciCall_SetSavePoint(); SciCall_SetChangeHistory(SC_CHANGE_HISTORY_DISABLED); @@ -11073,8 +11084,7 @@ LONG BeginUndoActionSelection() { if (SciCall_GetUndoCollection()) { SciCall_BeginUndoAction(); - ++UndoRedoActionStackCount; - if (1 == UndoRedoActionStackCount) { + if (SciCall_GetUndoSequence() == 1) { DisableDocChangeNotification(); } return SciCall_IsSelectionEmpty() ? URTok_NoTransaction : _SaveUndoSelection(); @@ -11087,20 +11097,16 @@ LONG BeginUndoActionSelection() // // EndUndoActionSelection() // -const char* const _assert_msg = "Broken UndoRedo-Transaction!"; -// void EndUndoActionSelection(const LONG token) { if (SciCall_GetUndoCollection()) { if (token >= URTok_TokenStart) { _SaveRedoSelection(token, SciCall_GetModify()); } - --UndoRedoActionStackCount; SciCall_EndUndoAction(); - if (0 == UndoRedoActionStackCount) { + if (SciCall_GetUndoSequence() == 0) { EnableDocChangeNotification(EVM_Default); } - assert(_assert_msg && (UndoRedoActionStackCount >= 0)); } } @@ -11110,7 +11116,7 @@ void EndUndoActionSelection(const LONG token) // static void _RestoreActionSelection(const LONG token, DoAction doAct) { - if (_InUndoRedoTransaction()) { + if (SciCall_GetUndoSequence() > 0) { assert("Wrong Transaction!" && 0); return; } @@ -11217,7 +11223,7 @@ static void _RestoreActionSelection(const LONG token, DoAction doAct) // static void _RestoreActionSelection(const LONG token, DoAction doAct) { - if (_InUndoRedoTransaction()) { + if (SciCall_GetUndoSequence() > 0) { assert("Wrong Transaction!" && 0); return; } @@ -11332,12 +11338,10 @@ static LONG _UndoRedoActionMap(const LONG token, const UndoRedoSelection_t** sel if (token <= URTok_NoTransaction) { // reset / clear if (SciCall_GetUndoCollection()) { - while (UndoRedoActionStackCount > 0) { + while (SciCall_GetUndoSequence() > 0) { SciCall_EndUndoAction(); - --UndoRedoActionStackCount; } } - UndoRedoActionStackCount = 0; utarray_clear(UndoRedoSelectionUTArray); //~utarray_free(UndoRedoSelectionUTArray); @@ -11551,7 +11555,6 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags, const DocP UpdateToolbar(); UpdateMargins(true); - UpdateStatusbar(true); if (SciCall_GetZoom() != 100) { ShowZoomCallTip(); } @@ -11788,12 +11791,6 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags, const DocP Flags.bHugeFileLoadState = false; // reset } - UpdateToolbar(); - UpdateMargins(true); - UpdateStatusbar(true); - if (SciCall_GetZoom() != 100) { - ShowZoomCallTip(); - } Path_Release(hopen_file); @@ -11806,6 +11803,13 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags, const DocP if (visLn > 0) { SciCall_SetFirstVisibleLine(visLn); } + + UpdateMargins(true); + if (SciCall_GetZoom() != 100) { + ShowZoomCallTip(); + } + UpdateToolbar_Now(Globals.hwndMain); + return fSuccess; } @@ -11860,7 +11864,6 @@ bool FileRevert(const HPATHL hfile_pth, bool bIgnoreCmdLnEnc) SetSaveDone(); UpdateToolbar(); UpdateMargins(true); - UpdateStatusbar(true); return result; } @@ -13034,7 +13037,7 @@ void InstallFileWatching(const bool bInstall) { bool const bPrevReadOnlyAttrib = IsFileReadOnly(); if (bPrevReadOnlyAttrib) { - SendWMCommand(Globals.hwndMain, IDM_FILE_READONLY); // try to gain access + PostWMCommand(Globals.hwndMain, IDM_FILE_READONLY); // try to gain access } if (!IsFileReadOnly()) { @@ -13065,7 +13068,7 @@ void InstallFileWatching(const bool bInstall) { } if (bPrevReadOnlyAttrib && !IsFileReadOnly()) { - SendWMCommand(Globals.hwndMain, IDM_FILE_READONLY); // try to reset + PostWMCommand(Globals.hwndMain, IDM_FILE_READONLY); // try to reset } } } diff --git a/src/Notepad3.h b/src/Notepad3.h index 60501bf07..ff33c98a6 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -129,6 +129,7 @@ void ShowWrapAroundCallTip(bool forwardSearch); void MarkAllOccurrences(const LONG64 delay, const bool bForceClear); void UpdateToolbar(); +void UpdateToolbar_Now(const HWND hwnd); void UpdateStatusbar(const bool bForceRedraw); void UpdateMargins(const bool bForce); void UpdateSaveSettingsCmds(); diff --git a/src/SciCall.h b/src/SciCall.h index 4c0d25262..45b95c7fc 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -376,6 +376,7 @@ DeclareSciCallR01(GetTextRangeFull, GETTEXTRANGEFULL, DocPos, struct Sci_TextRan DeclareSciCallV0(UpperCase, UPPERCASE); DeclareSciCallV0(LowerCase, LOWERCASE); DeclareSciCallV2(ReplaceRectangular, REPLACERECTANGULAR, DocPos, length, const char *, text); +DeclareSciCallV01(SetCopySeparator, SETCOPYSEPARATOR, const char*, sep); //DeclareSciCallR01(TargetAsUTF8, TARGETASUTF8, DocPos, const char*, text); // WideCharToMultiByteEx(Encoding_SciCP); @@ -749,6 +750,7 @@ DeclareSciCallV2(AddUndoAction, ADDUNDOACTION, int, token, int, flags); DeclareSciCallV0(EndUndoAction, ENDUNDOACTION); DeclareSciCallR0(GetUndoCollection, GETUNDOCOLLECTION, bool); DeclareSciCallV1(SetUndoCollection, SETUNDOCOLLECTION, bool, bCollectUndo); +DeclareSciCallR0(GetUndoSequence, GETUNDOSEQUENCE, int); //=============================================================================