From 8f1e8ccda6f7c4bd1c3a0b2d0494dc55edaf2ad7 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 5 Dec 2012 00:10:22 +0000 Subject: [PATCH] [NEW_FEATURE] Add Remove empty lines feature. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@991 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 19 +++++++++++++++---- PowerEditor/src/Notepad_plus.rc | 2 ++ PowerEditor/src/NppCommands.cpp | 12 ++++++++++++ PowerEditor/src/menuCmdID.h | 2 ++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 7c81d93a..0467aba7 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1236,17 +1236,28 @@ void Notepad_plus::removeEmptyLine(bool isBlankContained) FindOption env; if (isBlankContained) { - env._str2Search = TEXT("\r\n"); + env._str2Search = TEXT("^[\\t ]*$(\\r\\n|\\r|\\n)"); } else { - env._str2Search = TEXT("^$"); + env._str2Search = TEXT("^$(\\r\\n|\\r|\\n)"); } env._str4Replace = TEXT(""); - env._searchType = FindExtended;//FindRegex; - //env._doMarkLine = true; + env._searchType = FindRegex; _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); + + + // remove the last line if it's an empty line. + if (isBlankContained) + { + env._str2Search = TEXT("(\\r\\n|\\r|\\n)^[\\t ]*$"); + } + else + { + env._str2Search = TEXT("(\\r\\n|\\r|\\n)^$"); + } + _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); } void Notepad_plus::getMatchedFileNames(const TCHAR *dir, const vector & patterns, vector & fileNames, bool isRecursive, bool isInHiddenDir) diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 084ab3fd..e113ca69 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -251,6 +251,8 @@ BEGIN MENUITEM "Join Lines", IDM_EDIT_JOIN_LINES MENUITEM "Move Up Current Line", IDM_EDIT_LINE_UP MENUITEM "Move Down Current Line", IDM_EDIT_LINE_DOWN + MENUITEM "Remove Empty Lines", IDM_EDIT_REMOVEEMPTYLINES + MENUITEM "Remove Empty Lines (Containing Blank characters)", IDM_EDIT_REMOVEEMPTYLINESWITHBLANK END POPUP "Comment/Uncomment" BEGIN diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index b04f90c4..00c8a9ac 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -836,6 +836,18 @@ void Notepad_plus::command(int id) _pEditView->currentLinesDown(); break; + case IDM_EDIT_REMOVEEMPTYLINES: + _pEditView->execute(SCI_BEGINUNDOACTION); + removeEmptyLine(false); + _pEditView->execute(SCI_ENDUNDOACTION); + break; + + case IDM_EDIT_REMOVEEMPTYLINESWITHBLANK: + _pEditView->execute(SCI_BEGINUNDOACTION); + removeEmptyLine(true); + _pEditView->execute(SCI_ENDUNDOACTION); + break; + case IDM_EDIT_UPPERCASE: _pEditView->convertSelectedTextToUpperCase(); break; diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 1dff58b8..d5537bd3 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -73,6 +73,8 @@ #define IDM_EDIT_LINE_DOWN (IDM_EDIT + 15) #define IDM_EDIT_UPPERCASE (IDM_EDIT + 16) #define IDM_EDIT_LOWERCASE (IDM_EDIT + 17) + #define IDM_EDIT_REMOVEEMPTYLINES (IDM_EDIT + 55) + #define IDM_EDIT_REMOVEEMPTYLINESWITHBLANK (IDM_EDIT + 56) // Menu macro #define IDM_MACRO_STARTRECORDINGMACRO (IDM_EDIT + 18)