From d9b98681f4905e1b8a361a1a477183c2b1aeb47b Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 5 Jul 2023 02:15:08 +0200 Subject: [PATCH] Add change history navgation commands Add Go to next/prev change & clear change history commands. Fix #12248, close #13861 --- PowerEditor/installer/nativeLang/english.xml | 6 +- .../nativeLang/english_customizable.xml | 6 +- PowerEditor/installer/nativeLang/french.xml | 6 +- .../nativeLang/taiwaneseMandarin.xml | 6 +- PowerEditor/src/Notepad_plus.cpp | 80 +++++++++++++++++++ PowerEditor/src/Notepad_plus.h | 1 + PowerEditor/src/Notepad_plus.rc | 18 +++-- PowerEditor/src/NppBigSwitch.cpp | 9 ++- PowerEditor/src/NppCommands.cpp | 9 +++ PowerEditor/src/NppIO.cpp | 2 +- PowerEditor/src/Parameters.cpp | 3 + PowerEditor/src/localization.cpp | 15 ++-- PowerEditor/src/menuCmdID.h | 4 + 13 files changed, 145 insertions(+), 20 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index 82b21f4d7..6e37855f1 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -5,7 +5,7 @@ Translation note: 2. All the comments are for explanation, they are not for translation. --> - +
@@ -39,6 +39,7 @@ Translation note: + @@ -251,6 +252,9 @@ Translation note: + + + diff --git a/PowerEditor/installer/nativeLang/english_customizable.xml b/PowerEditor/installer/nativeLang/english_customizable.xml index 658ebfdaf..46831e617 100644 --- a/PowerEditor/installer/nativeLang/english_customizable.xml +++ b/PowerEditor/installer/nativeLang/english_customizable.xml @@ -5,7 +5,7 @@ Translation note: 2. All the comments are for explanation, they are not for translation. --> - +
@@ -39,6 +39,7 @@ Translation note: + @@ -251,6 +252,9 @@ Translation note: + + + diff --git a/PowerEditor/installer/nativeLang/french.xml b/PowerEditor/installer/nativeLang/french.xml index b8ce88380..ff2e8a6b2 100644 --- a/PowerEditor/installer/nativeLang/french.xml +++ b/PowerEditor/installer/nativeLang/french.xml @@ -3,7 +3,7 @@ The comments are here for explanation, it's not necessary to translate them. --> - +
@@ -37,6 +37,7 @@ The comments are here for explanation, it's not necessary to translate them. + @@ -248,6 +249,9 @@ The comments are here for explanation, it's not necessary to translate them. + + + diff --git a/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml b/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml index b0491fc20..f4c32d39b 100644 --- a/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml +++ b/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml @@ -1,6 +1,6 @@ - +
@@ -34,6 +34,7 @@ + @@ -244,6 +245,9 @@ + + + diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 0c338bdf8..d72c40002 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -8667,4 +8667,84 @@ void Notepad_plus::clearChangesHistory() SendMessage(_pEditView->getHSelf(), SCI_SETCHANGEHISTORY, chFlags, 0); SendMessage(_pEditView->getHSelf(), SCI_GOTOPOS, pos, 0); + + checkUndoState(); } + +// Based on https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12248#issuecomment-1258561261. +void Notepad_plus::changedHistoryGoTo(int idGoTo) +{ + int mask = (1 << SC_MARKNUM_HISTORY_REVERTED_TO_ORIGIN) | + (1 << SC_MARKNUM_HISTORY_SAVED) | + (1 << SC_MARKNUM_HISTORY_MODIFIED) | + (1 << SC_MARKNUM_HISTORY_REVERTED_TO_MODIFIED); + + intptr_t line = -1; + intptr_t blockIndicator = _pEditView->getCurrentLineNumber(); + intptr_t lastLine = _pEditView->execute(SCI_GETLINECOUNT); + + if (idGoTo == IDM_SEARCH_CHANGED_NEXT) // Next. + { + intptr_t currentLine = blockIndicator; + + // Start from currentLine (not currentLine + 1) in case currentLine is not-changed and the next line IS changed. lastLine is at least *1*. + for (intptr_t i = currentLine; i < lastLine; i++) + { + if (_pEditView->execute(SCI_MARKERGET, i) & mask) + { + if (i != blockIndicator) // Changed-line found in a different block. + { + line = i; + break; + } + else + { + blockIndicator++; + } + } + } + + if (line == -1) // Wrap around. + { + intptr_t endRange = currentLine + 1; // "+ 1": currentLine might be *0*. + for (intptr_t i = 0; i < endRange; i++) + { + if (_pEditView->execute(SCI_MARKERGET, i) & mask) + { + line = i; + break; + } + } + } + } + else // Prev. + { + while (true) + { + line = _pEditView->execute(SCI_MARKERPREVIOUS, blockIndicator, mask); + // "line == -1": no changed-line found. "line != blockIndicator": changed-line found in a different block. + if (line == -1 || line != blockIndicator) + break; + else + blockIndicator--; + } + + if (line == -1) // Wrap around. + { + line = _pEditView->execute(SCI_MARKERPREVIOUS, lastLine - 1, mask); + } + } + + if (line != -1) + { + _pEditView->execute(SCI_ENSUREVISIBLEENFORCEPOLICY, line); + _pEditView->execute(SCI_GOTOLINE, line); + } + else + { + bool isSilent = NppParameters::getInstance().getNppGUI()._muteSounds; + + if (!isSilent) + ::MessageBeep(MB_ICONEXCLAMATION); + } +} \ No newline at end of file diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 1a35a24af..a4863d2fd 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -646,4 +646,5 @@ private: HBITMAP generateSolidColourMenuItemIcon(COLORREF colour); void clearChangesHistory(); + void changedHistoryGoTo(int idGoTo); }; diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index c45baded0..cfb0b1aaf 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -545,17 +545,17 @@ BEGIN MENUITEM "Open File", IDM_EDIT_OPENASFILE MENUITEM "Open Containing Folder in Explorer", IDM_EDIT_OPENINFOLDER MENUITEM SEPARATOR - MENUITEM "Search on Internet", IDM_EDIT_SEARCHONINTERNET + MENUITEM "Search on Internet", IDM_EDIT_SEARCHONINTERNET MENUITEM "Change Search Engine...", IDM_EDIT_CHANGESEARCHENGINE END MENUITEM SEPARATOR - MENUITEM "Column Mode...", IDM_EDIT_COLUMNMODETIP + MENUITEM "Column Mode...", IDM_EDIT_COLUMNMODETIP MENUITEM "Colum&n Editor...", IDM_EDIT_COLUMNMODE - MENUITEM "Character &Panel", IDM_EDIT_CHAR_PANEL - MENUITEM "Clipboard &History", IDM_EDIT_CLIPBOARDHISTORY_PANEL + MENUITEM "Character &Panel", IDM_EDIT_CHAR_PANEL + MENUITEM "Clipboard &History", IDM_EDIT_CLIPBOARDHISTORY_PANEL MENUITEM SEPARATOR MENUITEM "&Set Read-Only", IDM_EDIT_SETREADONLY - MENUITEM "Clear Read-Only Flag", IDM_EDIT_CLEARREADONLY + MENUITEM "Clear Read-Only Flag", IDM_EDIT_CLEARREADONLY END POPUP "&Search" @@ -578,7 +578,13 @@ BEGIN MENUITEM "Select All Between &Matching Braces", IDM_SEARCH_SELECTMATCHINGBRACES MENUITEM "Mar&k...", IDM_SEARCH_MARK MENUITEM SEPARATOR - + POPUP "Change History" + BEGIN + MENUITEM "Go to Next Change", IDM_SEARCH_CHANGED_NEXT + MENUITEM "Go to Previous Change", IDM_SEARCH_CHANGED_PREV + MENUITEM "Clear Change History", IDM_SEARCH_CLEAR_CHANGE_HISTORY + END + MENUITEM SEPARATOR POPUP "Style &All Occurrences of Token" BEGIN MENUITEM "Using 1st Style", IDM_SEARCH_MARKALLEXT1 diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 28522ab2a..091177866 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1893,8 +1893,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa if (notification->nmhdr.code == SCN_UPDATEUI) { - checkClipboard(); //6 - checkUndoState(); //4 + checkClipboard(); + checkUndoState(); } if (wParam == LINKTRIGGERED) @@ -2984,6 +2984,11 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa _mainEditView.showChangeHistoryMargin(svp._isChangeHistoryEnabled); _subEditView.showChangeHistoryMargin(svp._isChangeHistoryEnabled); + + enableCommand(IDM_SEARCH_CHANGED_PREV, svp._isChangeHistoryEnabled, MENU); + enableCommand(IDM_SEARCH_CHANGED_NEXT, svp._isChangeHistoryEnabled, MENU); + enableCommand(IDM_SEARCH_CLEAR_CHANGE_HISTORY, svp._isChangeHistoryEnabled, MENU); + return TRUE; } diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 39e934244..d32221a69 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1680,6 +1680,15 @@ void Notepad_plus::command(int id) bookmarkClearAll(); break; + case IDM_SEARCH_CHANGED_PREV: + case IDM_SEARCH_CHANGED_NEXT: + changedHistoryGoTo(id); + break; + + case IDM_SEARCH_CLEAR_CHANGE_HISTORY: + clearChangesHistory(); + break; + case IDM_LANG_USER_DLG : { bool isUDDlgVisible = false; diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 32098a08d..6012f4244 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -589,7 +589,7 @@ bool Notepad_plus::doReload(BufferID id, bool alert) // many settings such as update status bar, clickable link etc. activateBuffer(id, currentView(), true); - if (NppParameters::getInstance().getSVP()._isChangeHistoryEnabled4NextSession) + if (NppParameters::getInstance().getSVP()._isChangeHistoryEnabled) clearChangesHistory(); return res; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 8ada9b1d2..dbd6db06c 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -199,6 +199,9 @@ static const WinMenuKeyDefinition winKeyDefs[] = { VK_G, IDM_SEARCH_GOTOLINE, true, false, false, nullptr }, { VK_B, IDM_SEARCH_GOTOMATCHINGBRACE, true, false, false, nullptr }, { VK_B, IDM_SEARCH_SELECTMATCHINGBRACES, true, true, false, nullptr }, + { VK_NULL, IDM_SEARCH_CHANGED_PREV, false, false, false, nullptr }, + { VK_NULL, IDM_SEARCH_CHANGED_NEXT, false, false, false, nullptr }, + { VK_NULL, IDM_SEARCH_CLEAR_CHANGE_HISTORY, false, false, false, nullptr }, { VK_M, IDM_SEARCH_MARK, true, false, false, nullptr }, { VK_NULL, IDM_SEARCH_MARKALLEXT1, false, false, false, TEXT("Style all using 1st style") }, { VK_NULL, IDM_SEARCH_MARKALLEXT2, false, false, false, TEXT("Style all using 2nd style") }, diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index f8868d46e..5c5a08ec6 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -58,13 +58,14 @@ MenuPosition menuPos[] = { { 1, 20, -1, "edit-pasteSpecial" }, { 1, 21, -1, "edit-onSelection" }, - { 2, 18, -1, "search-markAll" }, - { 2, 19, -1, "search-markOne" }, - { 2, 20, -1, "search-unmarkAll" }, - { 2, 21, -1, "search-jumpUp" }, - { 2, 22, -1, "search-jumpDown" }, - { 2, 23, -1, "search-copyStyledText" }, - { 2, 25, -1, "search-bookmark" }, + { 2, 18, -1, "search-changeHistory" }, + { 2, 20, -1, "search-markAll" }, + { 2, 21, -1, "search-markOne" }, + { 2, 22, -1, "search-unmarkAll" }, + { 2, 23, -1, "search-jumpUp" }, + { 2, 24, -1, "search-jumpDown" }, + { 2, 25, -1, "search-copyStyledText" }, + { 2, 27, -1, "search-bookmark" }, { 3, 5, -1, "view-currentFileIn" }, { 3, 7, -1, "view-showSymbol" }, diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index fb10ff681..d21db0e6d 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -251,6 +251,10 @@ #define IDM_SEARCH_MARKONEEXT4 (IDM_SEARCH + 65) #define IDM_SEARCH_MARKONEEXT5 (IDM_SEARCH + 66) + #define IDM_SEARCH_CHANGED_NEXT (IDM_SEARCH + 67) + #define IDM_SEARCH_CHANGED_PREV (IDM_SEARCH + 68) + #define IDM_SEARCH_CLEAR_CHANGE_HISTORY (IDM_SEARCH + 69) + #define IDM_MISC (IDM + 3500) #define IDM_DOCLIST_FILESCLOSE (IDM_MISC + 1) #define IDM_DOCLIST_FILESCLOSEOTHERS (IDM_MISC + 2)