Index: ide.h =================================================================== --- ide.h (revision 7000) +++ ide.h (working copy) @@ -870,6 +870,8 @@ void TextInitCaps(); void SwapCase(); void ToCString(); + void ToComment(); + void UnComment(); void MacroMenu(Bar& menu); bool HasMacros(); Index: ide.key =================================================================== --- ide.key (revision 7000) +++ ide.key (working copy) @@ -108,6 +108,8 @@ KEY(SWAPCASE, "Swap case", 0) KEY(TOASCII, "To ASCII", 0) KEY(TOCSTRING, "Convert to C string", 0) +KEY(TOCOMMENT, "Comment code", K_ALT_K) +KEY(UNCOMMENT, "Uncomment code", K_SHIFT|K_ALT_K) KEY(DIFF, "Compare with file..", 0) KEY(SVNDIFF, "Show svn history of file..", 0) Index: idebar.cpp =================================================================== --- idebar.cpp (revision 7000) +++ idebar.cpp (working copy) @@ -121,6 +121,10 @@ .Help("Swap the case of letters in selection"); menu.Add(AK_TOCSTRING, THISBACK(ToCString)) .Help("Convert selection to CString"); + menu.Add(AK_TOCOMMENT, THISBACK(ToComment)) + .Help("Comments code"); + menu.Add(AK_UNCOMMENT, THISBACK(UnComment)) + .Help("Uncomments code"); } void Ide::SearchMenu(Bar& menu) Index: idetool.cpp =================================================================== --- idetool.cpp (revision 7000) +++ idetool.cpp (working copy) @@ -294,6 +294,61 @@ AlterText(sCString); } +static WString sComment(const WString& s) +{ + String r; + if(s.IsEmpty()) + return s; + if(*s.Last() != '\n') + return "/*" + s + "*/"; + StringStream ss(s.ToString()); + for(;;) { + String line = ss.GetLine(); + if(ss.IsError()) + return s; + else + if(!line.IsVoid()) + r << "//" << line << "\n"; + if(ss.IsEof()) + break; + } + return r.ToWString(); +} + +void Ide::ToComment() +{ + AlterText(sComment); +} + +static WString sUncomment(const WString& s) +{ + String r; + if(s.StartsWith("/*") && s.EndsWith("*/")) + return s.Mid(2, s.GetCount() - 4); + StringStream ss(s.ToString()); + for(;;) { + String line = ss.GetLine(); + if(ss.IsError()) + return s; + int pos = line.Find("//"); + if(pos >= 0) + line.Remove(pos, 2); + r << line; + if(ss.IsEof()) { + if(*s.Last() == '\n') + r << "\n"; + break; + } + r << "\n"; + } + return r.ToWString(); +} + +void Ide::UnComment() +{ + AlterText(sUncomment); +} + void Ide::Times() { WithStatisticsLayout statdlg;