From 51f10bdba56a415d42eb829b27a08955cb7db0dd Mon Sep 17 00:00:00 2001 From: Don HO Date: Fri, 1 Feb 2019 01:00:36 +0100 Subject: [PATCH] Add "Remove Duplicate Lines" feature Remove duplicate consecutive lines from whole document. --- PowerEditor/src/Notepad_plus.cpp | 17 +++++++++++++++++ PowerEditor/src/Notepad_plus.h | 1 + PowerEditor/src/Notepad_plus.rc | 1 + PowerEditor/src/NppCommands.cpp | 6 ++++++ PowerEditor/src/menuCmdID.h | 1 + 5 files changed, 26 insertions(+) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 0f859b7c..3d134198 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1406,6 +1406,23 @@ void Notepad_plus::removeEmptyLine(bool isBlankContained) _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); } +void Notepad_plus::removeDuplicateLines() +{ + // whichPart : line head or line tail + FindOption env; + + env._str2Search = TEXT("^(.*\\r?\\n)(\\1)+"); + env._str4Replace = TEXT("\\1"); + env._searchType = FindRegex; + _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); + + // remove the last line if it's a duplicate line. + env._str2Search = TEXT("^(.+)\\r?\\n(\\1)"); + env._str4Replace = TEXT("\\1"); + env._searchType = FindRegex; + _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); +} + void Notepad_plus::getMatchedFileNames(const TCHAR *dir, const vector & patterns, vector & fileNames, bool isRecursive, bool isInHiddenDir) { generic_string dirFilter(dir); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index d5039827..b4318355 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -589,6 +589,7 @@ private: void wsTabConvert(spaceTab whichWay); void doTrim(trimOp whichPart); void removeEmptyLine(bool isBlankContained); + void removeDuplicateLines(); void launchAnsiCharPanel(); void launchClipboardHistoryPanel(); void launchFileSwitcherPanel(); diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 171f1bf0..9f3ab1bc 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -298,6 +298,7 @@ BEGIN POPUP "Line Operations" BEGIN MENUITEM "Duplicate Current Line", IDM_EDIT_DUP_LINE + MENUITEM "Remove Duplicate Lines", IDM_EDIT_REMOVE_DUP_LINES MENUITEM "Split Lines", IDM_EDIT_SPLIT_LINES MENUITEM "Join Lines", IDM_EDIT_JOIN_LINES MENUITEM "Move Up Current Line", IDM_EDIT_LINE_UP diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 872c54c1..0ebe2942 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1384,6 +1384,12 @@ void Notepad_plus::command(int id) _pEditView->execute(SCI_LINEDUPLICATE); break; + case IDM_EDIT_REMOVE_DUP_LINES: + _pEditView->execute(SCI_BEGINUNDOACTION); + removeDuplicateLines(); + _pEditView->execute(SCI_ENDUNDOACTION); + break; + case IDM_EDIT_SPLIT_LINES: _pEditView->execute(SCI_TARGETFROMSELECTION); if (_pEditView->execute(SCI_GETEDGEMODE) == EDGE_NONE) diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 48357695..77864b12 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -104,6 +104,7 @@ #define IDM_EDIT_INS_TAB (IDM_EDIT + 8) #define IDM_EDIT_RMV_TAB (IDM_EDIT + 9) #define IDM_EDIT_DUP_LINE (IDM_EDIT + 10) + #define IDM_EDIT_REMOVE_DUP_LINES (IDM_EDIT + 77) #define IDM_EDIT_TRANSPOSE_LINE (IDM_EDIT + 11) #define IDM_EDIT_SPLIT_LINES (IDM_EDIT + 12) #define IDM_EDIT_JOIN_LINES (IDM_EDIT + 13)