[NEW_FEATURE] bookmarked lines operations.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@210 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2008-05-27 01:54:52 +00:00
parent b6020b9083
commit b62de8fd30
5 changed files with 121 additions and 37 deletions

View File

@ -2973,8 +2973,20 @@ void Notepad_plus::command(int id)
} }
break; break;
case IDM_EDIT_DELETEMARKEDLINES : case IDM_SEARCH_CUTMARKEDLINES :
markedLinesOperation(0); cutMarkedLines();
break;
case IDM_SEARCH_COPYMARKEDLINES :
copyMarkedLines();
break;
case IDM_SEARCH_PASTEMARKEDLINES :
pasteToMarkedLines();
break;
case IDM_SEARCH_DELETEMARKEDLINES :
deleteMarkedLines();
break; break;
case IDM_VIEW_FULLSCREENTOGGLE : case IDM_VIEW_FULLSCREENTOGGLE :
@ -3239,7 +3251,7 @@ void Notepad_plus::command(int id)
if (startLine == 0) if (startLine == 0)
startLine = 1; startLine = 1;
if (endLine == _pEditView->getNbLine()) if (endLine == _pEditView->lastZeroBasedLineNumber())
endLine -= 1; endLine -= 1;
_pEditView->execute(SCI_HIDELINES, startLine, endLine); _pEditView->execute(SCI_HIDELINES, startLine, endLine);
_pEditView->execute(SCI_MARKERADD, startLine-1, MARK_HIDELINESBEGIN); _pEditView->execute(SCI_MARKERADD, startLine-1, MARK_HIDELINESBEGIN);
@ -3480,7 +3492,6 @@ void Notepad_plus::command(int id)
::CloseClipboard(); ::CloseClipboard();
//Do not free anything, EmptyClipboard does that //Do not free anything, EmptyClipboard does that
//::GlobalFree(allocClipboardData);
_pEditView->execute(SCI_EMPTYUNDOBUFFER); _pEditView->execute(SCI_EMPTYUNDOBUFFER);
} }
break; break;
@ -4375,7 +4386,7 @@ void Notepad_plus::reloadOnSwitchBack()
const NppGUI & nppGUI = pNppParam->getNppGUI(); const NppGUI & nppGUI = pNppParam->getNppGUI();
if (nppGUI._fileAutoDetection == cdAutoUpdateGo2end || nppGUI._fileAutoDetection == cdGo2end) if (nppGUI._fileAutoDetection == cdAutoUpdateGo2end || nppGUI._fileAutoDetection == cdGo2end)
{ {
int line = _pEditView->getNbLine(); int line = _pEditView->lastZeroBasedLineNumber();
_pEditView->gotoLine(line); _pEditView->gotoLine(line);
} }
@ -4403,9 +4414,6 @@ void Notepad_plus::hideCurrentView()
::SendMessage(_hSelf, WM_SIZE, 0, 0); ::SendMessage(_hSelf, WM_SIZE, 0, 0);
switchEditViewTo((getCurrentView() == MAIN_VIEW)?SUB_VIEW:MAIN_VIEW); switchEditViewTo((getCurrentView() == MAIN_VIEW)?SUB_VIEW:MAIN_VIEW);
//setTitleWith(_pEditView->getCurrentTitle());
_mainWindowStatus &= ~TWO_VIEWS_MASK; _mainWindowStatus &= ~TWO_VIEWS_MASK;
} }
@ -4462,10 +4470,6 @@ bool Notepad_plus::fileClose()
PathRemoveFileSpec(fullPath); PathRemoveFileSpec(fullPath);
setWorkingDir(fullPath); setWorkingDir(fullPath);
//updateStatusBar();
//dynamicCheckMenuAndTB();
//setLangStatus(_pEditView->getCurrentDocType());
//checkDocState();
_linkTriggered = true; _linkTriggered = true;
::SendMessage(_hSelf, NPPM_INTERNAL_DOCSWITCHIN, 0, 0); ::SendMessage(_hSelf, NPPM_INTERNAL_DOCSWITCHIN, 0, 0);

View File

@ -536,29 +536,110 @@ private:
_pEditView->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK); _pEditView->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK);
}; };
void markedLinesOperation(int whichOp) {
int nbLine = _pEditView->getNbLine();
for (int i = 0 ; i < nbLine ; i++) void copyMarkedLines() {
int lastLine = _pEditView->lastZeroBasedLineNumber();
string globalStr = "";
for (int i = lastLine ; i >= 0 ; i--)
{ {
if (bookmarkPresent(i)) if (bookmarkPresent(i))
lineOperation(i, whichOp); {
string currentStr = getMarkedLine(i) + globalStr;
globalStr = currentStr;
} }
}
str2Cliboard(globalStr.c_str());
}; };
void lineOperation(int ln, int op) { void cutMarkedLines() {
int lastLine = _pEditView->lastZeroBasedLineNumber();
string globalStr = "";
_pEditView->execute(SCI_BEGINUNDOACTION);
for (int i = lastLine ; i >= 0 ; i--)
{
if (bookmarkPresent(i))
{
string currentStr = getMarkedLine(i) + globalStr;
globalStr = currentStr;
deleteMarkedline(i);
}
}
_pEditView->execute(SCI_ENDUNDOACTION);
str2Cliboard(globalStr.c_str());
};
void deleteMarkedLines() {
int lastLine = _pEditView->lastZeroBasedLineNumber();
_pEditView->execute(SCI_BEGINUNDOACTION);
for (int i = lastLine ; i >= 0 ; i--)
{
if (bookmarkPresent(i))
deleteMarkedline(i);
}
_pEditView->execute(SCI_ENDUNDOACTION);
};
void pasteToMarkedLines() {
int lastLine = _pEditView->lastZeroBasedLineNumber();
::OpenClipboard(_hSelf);
HANDLE clipboardData = ::GetClipboardData(CF_TEXT);
int len = ::GlobalSize(clipboardData);
LPVOID clipboardDataPtr = ::GlobalLock(clipboardData);
string clipboardStr = (const char *)clipboardDataPtr;
::GlobalUnlock(clipboardData);
::CloseClipboard();
_pEditView->execute(SCI_BEGINUNDOACTION);
for (int i = lastLine ; i >= 0 ; i--)
{
if (bookmarkPresent(i))
{
replaceMarkedline(i, clipboardStr.c_str());
}
}
_pEditView->execute(SCI_ENDUNDOACTION);
};
void deleteMarkedline(int ln) {
int lineLen = _pEditView->execute(SCI_LINELENGTH, ln); int lineLen = _pEditView->execute(SCI_LINELENGTH, ln);
int lineBegin = _pEditView->execute(SCI_POSITIONFROMLINE, ln); int lineBegin = _pEditView->execute(SCI_POSITIONFROMLINE, ln);
bookmarkDelete(ln); bookmarkDelete(ln);
_pEditView->execute(SCI_SETTARGETSTART, lineBegin); _pEditView->execute(SCI_SETTARGETSTART, lineBegin);
_pEditView->execute(SCI_SETTARGETEND, lineBegin + lineLen); _pEditView->execute(SCI_SETTARGETEND, lineBegin + lineLen);
char emptyString[2] = ""; char emptyString[2] = "";
_pEditView->execute(SCI_REPLACETARGET, strlen(emptyString), (LPARAM)emptyString); _pEditView->execute(SCI_REPLACETARGET, strlen(emptyString), (LPARAM)emptyString);
}; };
void replaceMarkedline(int ln, const char *str) {
int lineBegin = _pEditView->execute(SCI_POSITIONFROMLINE, ln);
int lineEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, ln);
_pEditView->execute(SCI_SETTARGETSTART, lineBegin);
_pEditView->execute(SCI_SETTARGETEND, lineEnd);
_pEditView->execute(SCI_REPLACETARGET, strlen(str), (LPARAM)str);
};
string getMarkedLine(int ln) {
int lineLen = _pEditView->execute(SCI_LINELENGTH, ln);
int lineBegin = _pEditView->execute(SCI_POSITIONFROMLINE, ln);
char * buf = new char[lineLen+1];
_pEditView->getText(buf, lineBegin, lineBegin + lineLen);
string line = buf;
delete [] buf;
return line;
};
int hideLinesMarkPresent(int lineno) const { int hideLinesMarkPresent(int lineno) const {
LRESULT state = _pEditView->execute(SCI_MARKERGET, lineno); LRESULT state = _pEditView->execute(SCI_MARKERGET, lineno);
if ((state & (1 << MARK_HIDELINESBEGIN)) != 0) if ((state & (1 << MARK_HIDELINESBEGIN)) != 0)
@ -597,7 +678,7 @@ private:
} }
else if (hideLinesMark == MARK_HIDELINESBEGIN) else if (hideLinesMark == MARK_HIDELINESBEGIN)
{ {
long nbLine = _pEditView->getNbLine(); long nbLine = _pEditView->lastZeroBasedLineNumber();
start = lineno; start = lineno;
int i = lineno + 1; int i = lineno + 1;
for ( ; i < nbLine ; i++) for ( ; i < nbLine ; i++)

View File

@ -304,11 +304,7 @@ BEGIN
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "Set Read Only", IDM_EDIT_SETREADONLY MENUITEM "Set Read Only", IDM_EDIT_SETREADONLY
MENUITEM "Clear Read Only Flag", IDM_EDIT_CLEARREADONLY MENUITEM "Clear Read Only Flag", IDM_EDIT_CLEARREADONLY
MENUITEM SEPARATOR //MENUITEM SEPARATOR
MENUITEM "Cut marked lines", IDM_EDIT_CUTMARKEDLINES
MENUITEM "Copy marked lines", IDM_EDIT_COPYMARKEDLINES
MENUITEM "Paste to (Replace) marked lines", IDM_EDIT_PASTEMARKEDLINES
MENUITEM "Delete marked lines", IDM_EDIT_DELETEMARKEDLINES
END END
POPUP "&Search" POPUP "&Search"
@ -331,6 +327,10 @@ BEGIN
MENUITEM "Next Bookmark", IDM_SEARCH_NEXT_BOOKMARK MENUITEM "Next Bookmark", IDM_SEARCH_NEXT_BOOKMARK
MENUITEM "Previous Bookmark", IDM_SEARCH_PREV_BOOKMARK MENUITEM "Previous Bookmark", IDM_SEARCH_PREV_BOOKMARK
MENUITEM "Clear all Bookmarks", IDM_SEARCH_CLEAR_BOOKMARKS MENUITEM "Clear all Bookmarks", IDM_SEARCH_CLEAR_BOOKMARKS
MENUITEM "Cut bookmarked lines", IDM_SEARCH_CUTMARKEDLINES
MENUITEM "Copy bookmarked lines", IDM_SEARCH_COPYMARKEDLINES
MENUITEM "Paste to (Replace) bookmarked lines", IDM_SEARCH_PASTEMARKEDLINES
MENUITEM "Delete bookmarked lines", IDM_SEARCH_DELETEMARKEDLINES
END END
POPUP "&View" POPUP "&View"

View File

@ -427,7 +427,7 @@ public:
return long(execute(SCI_LINEFROMPOSITION, execute(SCI_GETCURRENTPOS))); return long(execute(SCI_LINEFROMPOSITION, execute(SCI_GETCURRENTPOS)));
}; };
long getNbLine() const { long lastZeroBasedLineNumber() const {
int endPos = execute(SCI_GETLENGTH); int endPos = execute(SCI_GETLENGTH);
return execute(SCI_LINEFROMPOSITION, endPos); return execute(SCI_LINEFROMPOSITION, endPos);
}; };

View File

@ -77,11 +77,6 @@
#define IDM_EDIT_BLOCK_COMMENT_SET (IDM_EDIT+35) #define IDM_EDIT_BLOCK_COMMENT_SET (IDM_EDIT+35)
#define IDM_EDIT_BLOCK_UNCOMMENT (IDM_EDIT+36) #define IDM_EDIT_BLOCK_UNCOMMENT (IDM_EDIT+36)
#define IDM_EDIT_CUTMARKEDLINES (IDM_EDIT+42)
#define IDM_EDIT_COPYMARKEDLINES (IDM_EDIT+43)
#define IDM_EDIT_PASTEMARKEDLINES (IDM_EDIT+44)
#define IDM_EDIT_DELETEMARKEDLINES (IDM_EDIT+45)
#define IDM_EDIT_AUTOCOMPLETE (50000+0) #define IDM_EDIT_AUTOCOMPLETE (50000+0)
#define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000+1) #define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000+1)
#define IDM_EDIT_FUNCCALLTIP (50000+2) #define IDM_EDIT_FUNCCALLTIP (50000+2)
@ -108,6 +103,10 @@
#define IDM_SEARCH_VOLATILE_FINDPREV (IDM_SEARCH + 15) #define IDM_SEARCH_VOLATILE_FINDPREV (IDM_SEARCH + 15)
#define IDM_SEARCH_MARKALL (IDM_SEARCH + 16) #define IDM_SEARCH_MARKALL (IDM_SEARCH + 16)
#define IDM_SEARCH_UNMARKALL (IDM_SEARCH + 17) #define IDM_SEARCH_UNMARKALL (IDM_SEARCH + 17)
#define IDM_SEARCH_CUTMARKEDLINES (IDM_SEARCH + 18)
#define IDM_SEARCH_COPYMARKEDLINES (IDM_SEARCH + 19)
#define IDM_SEARCH_PASTEMARKEDLINES (IDM_SEARCH + 20)
#define IDM_SEARCH_DELETEMARKEDLINES (IDM_SEARCH + 21)
#define IDM_VIEW (IDM + 4000) #define IDM_VIEW (IDM + 4000)
#define IDM_VIEW_TOOLBAR_HIDE (IDM_VIEW + 1) #define IDM_VIEW_TOOLBAR_HIDE (IDM_VIEW + 1)