From 50ad9154347498f8738788f3cfce05f711c6596e Mon Sep 17 00:00:00 2001 From: donho Date: Mon, 10 Dec 2007 01:36:32 +0000 Subject: [PATCH] [NEW_FEATURE] Comment (Ctrl+K) and Uncomment (Ctrl+Shift+K) is separated now. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@81 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 78 ++++++++++++++++++++------------ PowerEditor/src/Notepad_plus.h | 3 +- PowerEditor/src/Notepad_plus.rc | 6 ++- PowerEditor/src/menuCmdID.h | 3 ++ 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index fc67d692..793574f3 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1237,6 +1237,8 @@ void Notepad_plus::checkClipboard() enableCommand(IDM_EDIT_UPPERCASE, hasSelection, MENU); enableCommand(IDM_EDIT_LOWERCASE, hasSelection, MENU); enableCommand(IDM_EDIT_BLOCK_COMMENT, hasSelection, MENU); + enableCommand(IDM_EDIT_BLOCK_COMMENT_SET, hasSelection, MENU); + enableCommand(IDM_EDIT_BLOCK_UNCOMMENT, hasSelection, MENU); enableCommand(IDM_EDIT_STREAM_COMMENT, hasSelection, MENU); } @@ -2773,7 +2775,15 @@ void Notepad_plus::command(int id) break; case IDM_EDIT_BLOCK_COMMENT: - doBlockComment(); + doBlockComment(cm_toggle); + break; + + case IDM_EDIT_BLOCK_COMMENT_SET: + doBlockComment(cm_comment); + break; + + case IDM_EDIT_BLOCK_UNCOMMENT: + doBlockComment(cm_uncomment); break; case IDM_EDIT_STREAM_COMMENT: @@ -3793,6 +3803,8 @@ void Notepad_plus::command(int id) case IDM_EDIT_UPPERCASE: case IDM_EDIT_LOWERCASE: case IDM_EDIT_BLOCK_COMMENT: + case IDM_EDIT_BLOCK_COMMENT_SET: + case IDM_EDIT_BLOCK_UNCOMMENT: case IDM_EDIT_STREAM_COMMENT: case IDM_EDIT_TRIMTRAILING: case IDM_EDIT_SETREADONLY : @@ -5109,7 +5121,7 @@ static string extractSymbol(char prefix, const char *str2extract) return string(extracted); }; -bool Notepad_plus::doBlockComment() +bool Notepad_plus::doBlockComment(comment_mode currCommentMode) { const char *commentLineSybol; string symbol; @@ -5165,34 +5177,40 @@ bool Notepad_plus::doBlockComment() // empty lines are not commented if (strlen(linebuf) < 1) continue; - if (memcmp(linebuf, comment.c_str(), comment_length - 1) == 0) - { - if (memcmp(linebuf, long_comment.c_str(), comment_length) == 0) - { - // removing comment with space after it - _pEditView->execute(SCI_SETSEL, lineIndent, lineIndent + comment_length); - _pEditView->execute(SCI_REPLACESEL, 0, (WPARAM)""); - if (i == selStartLine) // is this the first selected line? - selectionStart -= comment_length; - selectionEnd -= comment_length; // every iteration - continue; - } - else - { - // removing comment _without_ space - _pEditView->execute(SCI_SETSEL, lineIndent, lineIndent + comment_length - 1); - _pEditView->execute(SCI_REPLACESEL, 0, (WPARAM)""); - if (i == selStartLine) // is this the first selected line? - selectionStart -= (comment_length - 1); - selectionEnd -= (comment_length - 1); // every iteration - continue; - } - } - if (i == selStartLine) // is this the first selected line? - selectionStart += comment_length; - selectionEnd += comment_length; // every iteration - _pEditView->execute(SCI_INSERTTEXT, lineIndent, (WPARAM)long_comment.c_str()); - } + if (currCommentMode != cm_comment) + { + if (memcmp(linebuf, comment.c_str(), comment_length - 1) == 0) + { + if (memcmp(linebuf, long_comment.c_str(), comment_length) == 0) + { + // removing comment with space after it + _pEditView->execute(SCI_SETSEL, lineIndent, lineIndent + comment_length); + _pEditView->execute(SCI_REPLACESEL, 0, (WPARAM)""); + if (i == selStartLine) // is this the first selected line? + selectionStart -= comment_length; + selectionEnd -= comment_length; // every iteration + continue; + } + else + { + // removing comment _without_ space + _pEditView->execute(SCI_SETSEL, lineIndent, lineIndent + comment_length - 1); + _pEditView->execute(SCI_REPLACESEL, 0, (WPARAM)""); + if (i == selStartLine) // is this the first selected line? + selectionStart -= (comment_length - 1); + selectionEnd -= (comment_length - 1); // every iteration + continue; + } + } + } + if ((currCommentMode == cm_toggle) || (currCommentMode == cm_comment)) + { + if (i == selStartLine) // is this the first selected line? + selectionStart += comment_length; + selectionEnd += comment_length; // every iteration + _pEditView->execute(SCI_INSERTTEXT, lineIndent, (WPARAM)long_comment.c_str()); + } + } // after uncommenting selection may promote itself to the lines // before the first initially selected line; // another problem - if only comment symbol was selected; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index ae02f23c..60c1a1e3 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -78,6 +78,7 @@ struct iconLocator { class FileDialog; class Notepad_plus : public Window { + enum comment_mode {cm_comment, cm_uncomment, cm_toggle}; public: Notepad_plus(); @@ -310,7 +311,7 @@ public: const char * getNativeTip(int btnID); void changeToolBarIcons(); - bool doBlockComment(); + bool doBlockComment(comment_mode currCommentMode); bool doStreamComment(); void doTrimTrailing() { _pEditView->execute(SCI_BEGINUNDOACTION); diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index a425e100..21a7bea4 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -291,7 +291,9 @@ BEGIN MENUITEM "to &Upper case\tCtrl+Shift+U", IDM_EDIT_UPPERCASE MENUITEM "to &Lower case\tCtrl+U", IDM_EDIT_LOWERCASE MENUITEM SEPARATOR - MENUITEM "Block comment/uncomment\tCtrl+Q", IDM_EDIT_BLOCK_COMMENT + MENUITEM "Block toggle comment \tCtrl+Q", IDM_EDIT_BLOCK_COMMENT + MENUITEM "Block comment\tCtrl+K", IDM_EDIT_BLOCK_COMMENT_SET + MENUITEM "Block uncomment\tCtrl+Shift+K", IDM_EDIT_BLOCK_UNCOMMENT MENUITEM "Stream comment\tCtrl+Shift+Q", IDM_EDIT_STREAM_COMMENT MENUITEM SEPARATOR MENUITEM "Function completion\tCtrl+SPACE", IDM_EDIT_AUTOCOMPLETE @@ -575,6 +577,8 @@ BEGIN "R", IDC_EDIT_TOGGLEMACRORECORDING, VIRTKEY, CONTROL, SHIFT "P", IDM_MACRO_PLAYBACKRECORDEDMACRO, VIRTKEY, CONTROL, SHIFT "Q", IDM_EDIT_BLOCK_COMMENT, VIRTKEY, CONTROL + "K", IDM_EDIT_BLOCK_COMMENT_SET, VIRTKEY, CONTROL + "K", IDM_EDIT_BLOCK_UNCOMMENT, VIRTKEY, CONTROL, SHIFT "Q", IDM_EDIT_STREAM_COMMENT, VIRTKEY, CONTROL, SHIFT "V", IDM_EDIT_PASTE, VIRTKEY, CONTROL diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 35eb3325..2a2a1360 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -73,6 +73,9 @@ #define IDM_EDIT_CLEARREADONLY (IDM_EDIT+33) #define IDM_EDIT_COLUMNMODE (IDM_EDIT+34) + #define IDM_EDIT_BLOCK_COMMENT_SET (IDM_EDIT+35) + #define IDM_EDIT_BLOCK_UNCOMMENT (IDM_EDIT+36) + #define IDM_EDIT_AUTOCOMPLETE (50000+0) #define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000+1)