ide: Comment/Uncomment block, Core: WString::Replace issue fixed

git-svn-id: svn://ultimatepp.org/upp/trunk@7085 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-03-24 14:34:50 +00:00
commit b109812220
6 changed files with 71 additions and 11 deletions

View file

@ -240,14 +240,14 @@ String FormatElapsedTime(double run)
void Ide::AlterText(WString (*op)(const WString& in))
{
if(designer)
if(designer || !editor.IsSelection())
return;
editor.NextUndo();
if(!editor.IsSelection())
editor.SelectAll();
WString w = editor.GetSelectionW();
editor.RemoveSelection();
int l = editor.GetCursor();
editor.Paste((*op)(w));
editor.SetSelection(l, editor.GetCursor());
}
void Ide::TextToUpper()
@ -294,6 +294,52 @@ void Ide::ToCString()
AlterText(sCString);
}
static WString sComment(const WString& s)
{
return "/*" + s + "*/";
}
void Ide::ToComment()
{
AlterText(sComment);
}
static WString sCommentLines(const WString& s)
{
String r;
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::CommentLines()
{
AlterText(sCommentLines);
}
static WString sUncomment(const WString& s)
{
WString h = s;
h.Replace("/*", "");
h.Replace("//", "");
h.Replace("*/", "");
return h;
}
void Ide::UnComment()
{
AlterText(sUncomment);
}
void Ide::Times()
{
WithStatisticsLayout<TopWindow> statdlg;