Index: CodeEditor/CodeEditor.cpp =================================================================== --- CodeEditor/CodeEditor.cpp (revision 45) +++ CodeEditor/CodeEditor.cpp (working copy) @@ -580,6 +580,55 @@ SetCursor(GetPos(atoi(line) - 1)); } +void CodeEditor::ToggleLineComments() +{ + int start_line, end_line; + if(!GetLineSelection(start_line, end_line)) + return; + + bool is_commented = true; + for (int line = start_line; is_commented && (line < end_line); ++line) + is_commented &= GetChar(GetPos(line))=='/' && + GetChar(GetPos(line)+1)=='/'; + + if (!is_commented) { + for (int line = start_line; line < end_line; ++line) + Insert(GetPos(line), "//"); + } else { + for (int line = start_line; line < end_line; ++line) + Remove(GetPos(line), 2); + + SetLineSelection(start_line, end_line); +} + +void CodeEditor::ToggleStarComments() +{ + int start_line, end_line; + if(!GetLineSelection(start_line, end_line)) + return; + + bool is_commented = + GetChar(GetPos(start_line)) == '/' && + GetChar(GetPos(start_line)+1) == '*' && + GetChar(GetPos(start_line)+2) == '\n' && + GetChar(GetPos(end_line-1)) == '*' && + GetChar(GetPos(end_line-1)+1) == '/' && + GetChar(GetPos(end_line-1)+2) == '\n'; + + if (!is_commented) { + // Backwards because inserting changes the end line # + Insert(GetPos(end_line),"*/\n"); + Insert(GetPos(start_line),"/*\n"); + SetLineSelection(start_line, end_line+2); + } else { + // Backwards because inserting changes the end line # + Remove(GetPos(end_line-1),3); + Remove(GetPos(start_line),3); + SetLineSelection(start_line, end_line-2); + } + +} + void CodeEditor::Enclose(const char *c1, const char *c2) { int l, h; @@ -657,9 +706,13 @@ return true; } if(code == '/') { - Enclose("/*", "*/"); + ToggleLineComments(); return true; } + if(code == '*') { + ToggleStarComments(); + return true; + } } if(code >= 32 && code < 128 && count == 1) { IndentInsert(code); Index: CodeEditor/CodeEditor.h =================================================================== --- CodeEditor/CodeEditor.h (revision 45) +++ CodeEditor/CodeEditor.h (working copy) @@ -275,6 +275,8 @@ void Bracket(int pos, HlSt& hls); void Enclose(const char *c1, const char *c2); + void ToggleLineComments(); + void ToggleStarComments(); enum { TIMEID_PERIODIC = Ctrl::TIMEID_COUNT, Index: ide/ide.lay =================================================================== --- ide/ide.lay (revision 45) +++ ide/ide.lay (working copy) @@ -403,7 +403,7 @@ ITEM(Option, filetabs, SetLabel(t_("File tabs")).LeftPosZ(12, 152).TopPosZ(216, 18)) ITEM(Switch, insert_include, SetLabel(t_("No #include in new souces\n#include first\n#include previous")).LeftPosZ(316, 156).TopPosZ(32, 56)) ITEM(Option, header_guards, SetLabel(t_("Insert guards to new headers")).LeftPosZ(316, 164).TopPosZ(12, 15)) - ITEM(Option, auto_enclose, SetLabel(t_("[ { ( \" / enclose selection")).LeftPosZ(12, 168).TopPosZ(236, 15)) + ITEM(Option, auto_enclose, SetLabel(t_("[ { ( \" enclose selection, / * toggle comments")).LeftPosZ(12, 256).TopPosZ(236, 15)) END_LAYOUT LAYOUT(SetupIdeLayout, 512, 248) @@ -467,3 +467,4 @@ ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(268, 64).TopPosZ(180, 24)) ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(336, 64).TopPosZ(180, 24)) END_LAYOUT +