[NEW_FEATURE] Add trim functions (header/trailing/compact feature).

[NEW_FEATURE] Add white space and TAB conversion features.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@722 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2010-12-05 19:33:48 +00:00
parent 8b5a523e9c
commit 10b4a1c9e0
6 changed files with 129 additions and 28 deletions

View File

@ -943,26 +943,63 @@ bool Notepad_plus::matchInList(const TCHAR *fileName, const vector<generic_strin
return false;
}
void Notepad_plus::doTrimTrailing()
void Notepad_plus::wsTabConvert(bool tab2ws)
{
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)
{
blank2replace = ws;
}
else
{
blank2search= ws;
}
FindOption env;
env._str2Search = blank2search;
env._str4Replace = blank2replace;
env._searchType = FindRegex;
// do the replacement
_pEditView->execute(SCI_BEGINUNDOACTION);
int nbLines = _pEditView->execute(SCI_GETLINECOUNT);
for (int line = 0 ; line < nbLines ; line++)
_findReplaceDlg.processAll(ProcessReplaceAll, &env, true);
// if white space to TAB, we replace the remain white spaces by TAB
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);
for ( ; (i >= lineStart) && (c == ' ') || (c == '\t') ; c = (char)_pEditView->execute(SCI_GETCHARAT,i))
i--;
if (i < (lineEnd - 1))
_pEditView->replaceTarget(TEXT(""), i + 1, lineEnd);
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<generic_string> & patterns, vector<generic_string> & fileNames, bool isRecursive, bool isInHiddenDir)
{
generic_string dirFilter(dir);

View File

@ -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);
};

View File

@ -252,7 +252,17 @@ BEGIN
MENUITEM "UNIX Format", IDM_FORMAT_TOUNIX
MENUITEM "Mac Format", IDM_FORMAT_TOMAC
END
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

View File

@ -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 :

View File

@ -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},

View File

@ -72,6 +72,12 @@
#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)