diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 4529eca12..2361490d2 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -943,26 +943,63 @@ bool Notepad_plus::matchInList(const TCHAR *fileName, const vectorexecute(SCI_BEGINUNDOACTION); - int nbLines = _pEditView->execute(SCI_GETLINECOUNT); - for (int line = 0 ; line < nbLines ; line++) + generic_string tab = TEXT(" "); + generic_string blank2search = tab; + generic_string blank2replace = tab; + + // Get tab size (ws length) + int tabWidth = _pEditView->execute(SCI_GETTABWIDTH); + generic_string ws(tabWidth, ' '); + + // tab2ws or ws2tab ? + if (tab2ws) { - int lineStart = _pEditView->execute(SCI_POSITIONFROMLINE,line); - int lineEnd = _pEditView->execute(SCI_GETLINEENDPOSITION,line); - int i = lineEnd - 1; - char c = (char)_pEditView->execute(SCI_GETCHARAT,i); + blank2replace = ws; + } + else + { + blank2search= ws; + } - for ( ; (i >= lineStart) && (c == ' ') || (c == '\t') ; c = (char)_pEditView->execute(SCI_GETCHARAT,i)) - i--; + FindOption env; + env._str2Search = blank2search; + env._str4Replace = blank2replace; + env._searchType = FindRegex; - if (i < (lineEnd - 1)) - _pEditView->replaceTarget(TEXT(""), i + 1, lineEnd); + // do the replacement + _pEditView->execute(SCI_BEGINUNDOACTION); + _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); + + // if white space to TAB, we replace the remain white spaces by TAB + if (!tab2ws) + { + env._str2Search = TEXT(" +"); + _findReplaceDlg.processAll(ProcessReplaceAll, &env, true); } _pEditView->execute(SCI_ENDUNDOACTION); } +void Notepad_plus::doTrim(trimOp whichPart) +{ + // whichPart : line head or line tail + FindOption env; + if (whichPart == lineHeader) + { + env._str2Search = TEXT("^[ ]+"); + } + else if (whichPart == lineTail) + { + env._str2Search = TEXT("[ ]+$"); + } + else + return; + env._str4Replace = TEXT(""); + 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 0abd1179b..306bd5dea 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -130,19 +130,14 @@ enum WindowStatus { //bitwise mask WindowMask = 0x07 }; - -/* -//Plugins rely on #define's -enum Views { - MAIN_VIEW = 0x00, - SUB_VIEW = 0x01 +enum trimOp { + lineHeader = 0, + lineTail = 1, + lineEol = 2 }; -*/ - struct TaskListInfo; - struct VisibleGUIConf { bool isPostIt; bool isFullScreen; @@ -253,10 +248,6 @@ public: bool doBlockComment(comment_mode currCommentMode); bool doStreamComment(); - void doTrimTrailing(); - - - bool addCurrentMacro(); void macroPlayback(Macro); @@ -576,6 +567,9 @@ private: bool goToPreviousIndicator(int indicID2Search, bool isWrap = true) const; bool goToNextIndicator(int indicID2Search, bool isWrap = true) const; int wordCount(); + + void wsTabConvert(bool whichWay); + void doTrim(trimOp whichPart); }; diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 2b2210bc3..645802849 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -252,7 +252,17 @@ BEGIN MENUITEM "UNIX Format", IDM_FORMAT_TOUNIX MENUITEM "Mac Format", IDM_FORMAT_TOMAC END - MENUITEM "Trim Trailing Space", IDM_EDIT_TRIMTRAILING + POPUP "Blank Operations" + BEGIN + MENUITEM "Trim Trailing Space", IDM_EDIT_TRIMTRAILING + MENUITEM "Trim Header Space", IDM_EDIT_TRIMLINEHEAD + MENUITEM "Trim Header and Trailing Space", IDM_EDIT_TRIM_BOTH + MENUITEM "EOL to Space", IDM_EDIT_EOL2WS + MENUITEM "Remove Unnecessary Blank and EOL", IDM_EDIT_TRIMALL + MENUITEM SEPARATOR + MENUITEM "TAB to Space", IDM_EDIT_TAB2SW + MENUITEM "Space to TAB", IDM_EDIT_SW2TAB + END MENUITEM SEPARATOR MENUITEM "Column Editor...", IDM_EDIT_COLUMNMODE MENUITEM SEPARATOR diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 0e4ae1235..57780b628 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -624,7 +624,48 @@ void Notepad_plus::command(int id) break; case IDM_EDIT_TRIMTRAILING: - doTrimTrailing(); + _pEditView->execute(SCI_BEGINUNDOACTION); + doTrim(lineTail); + _pEditView->execute(SCI_ENDUNDOACTION); + break; + + case IDM_EDIT_TRIMLINEHEAD: + _pEditView->execute(SCI_BEGINUNDOACTION); + doTrim(lineHeader); + _pEditView->execute(SCI_ENDUNDOACTION); + break; + + case IDM_EDIT_TRIM_BOTH: + _pEditView->execute(SCI_BEGINUNDOACTION); + doTrim(lineTail); + doTrim(lineHeader); + _pEditView->execute(SCI_ENDUNDOACTION); + break; + + case IDM_EDIT_EOL2WS: + _pEditView->execute(SCI_BEGINUNDOACTION); + _pEditView->execute(SCI_SETTARGETSTART, 0); + _pEditView->execute(SCI_SETTARGETEND, _pEditView->getCurrentDocLen()); + _pEditView->execute(SCI_LINESJOIN); + _pEditView->execute(SCI_ENDUNDOACTION); + break; + + case IDM_EDIT_TRIMALL: + _pEditView->execute(SCI_BEGINUNDOACTION); + doTrim(lineTail); + doTrim(lineHeader); + _pEditView->execute(SCI_SETTARGETSTART, 0); + _pEditView->execute(SCI_SETTARGETEND, _pEditView->getCurrentDocLen()); + _pEditView->execute(SCI_LINESJOIN); + _pEditView->execute(SCI_ENDUNDOACTION); + break; + + case IDM_EDIT_TAB2SW: + wsTabConvert(true); + break; + + case IDM_EDIT_SW2TAB: + wsTabConvert(false); break; case IDM_EDIT_SETREADONLY: @@ -2071,6 +2112,12 @@ void Notepad_plus::command(int id) case IDM_EDIT_BLOCK_UNCOMMENT: case IDM_EDIT_STREAM_COMMENT: case IDM_EDIT_TRIMTRAILING: + case IDM_EDIT_TRIMLINEHEAD: + case IDM_EDIT_TRIM_BOTH: + case IDM_EDIT_EOL2WS: + case IDM_EDIT_TRIMALL: + case IDM_EDIT_TAB2SW: + case IDM_EDIT_SW2TAB: case IDM_EDIT_SETREADONLY : case IDM_EDIT_FULLPATHTOCLIP : case IDM_EDIT_FILENAMETOCLIP : diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 2c21160de..4aee691b6 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -86,6 +86,13 @@ WinMenuKeyDefinition winKeyDefs[] = { {VK_UP, IDM_EDIT_LINE_UP, true, false, true, NULL}, {VK_DOWN, IDM_EDIT_LINE_DOWN, true, false, true, NULL}, {VK_NULL, IDM_EDIT_TRIMTRAILING, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_TRIMLINEHEAD, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_TRIM_BOTH, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_EOL2WS, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_TRIMALL, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_TAB2SW, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_SW2TAB, false, false, false, NULL}, + {VK_C, IDM_EDIT_COLUMNMODE, false, true, false, NULL}, {VK_U, IDM_EDIT_UPPERCASE, true, false, true, NULL}, {VK_U, IDM_EDIT_LOWERCASE, true, false, false, NULL}, diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 6bbe5f54c..fb0052fe8 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -72,7 +72,13 @@ #define IDM_EDIT_BLOCK_COMMENT (IDM_EDIT + 22) #define IDM_EDIT_STREAM_COMMENT (IDM_EDIT + 23) #define IDM_EDIT_TRIMTRAILING (IDM_EDIT + 24) - + #define IDM_EDIT_TRIMLINEHEAD (IDM_EDIT + 42) + #define IDM_EDIT_TRIM_BOTH (IDM_EDIT + 43) + #define IDM_EDIT_EOL2WS (IDM_EDIT + 44) + #define IDM_EDIT_TRIMALL (IDM_EDIT + 45) + #define IDM_EDIT_TAB2SW (IDM_EDIT + 46) + #define IDM_EDIT_SW2TAB (IDM_EDIT + 47) + // Menu macro #define IDM_MACRO_SAVECURRENTMACRO (IDM_EDIT + 25) //-----------