mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
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:
parent
2a8a97e7cb
commit
b109812220
6 changed files with 71 additions and 11 deletions
|
|
@ -106,7 +106,8 @@ void AString<B>::Replace(const tchar *find, int findlen, const tchar *replace, i
|
|||
i = j + findlen;
|
||||
}
|
||||
r.Cat(p + i, B::GetCount() - i);
|
||||
*this = r;
|
||||
Free();
|
||||
Set(r);
|
||||
}
|
||||
|
||||
template <class B>
|
||||
|
|
|
|||
|
|
@ -670,6 +670,8 @@ public:
|
|||
|
||||
WString0() { Zero(); }
|
||||
~WString0() { Free(); }
|
||||
|
||||
WString0& operator=(const WString0& s) { Free(); Set(s); return *this; }
|
||||
};
|
||||
|
||||
class WString : public Moveable<WString, AString<WString0> >
|
||||
|
|
|
|||
|
|
@ -874,6 +874,9 @@ public:
|
|||
void TextInitCaps();
|
||||
void SwapCase();
|
||||
void ToCString();
|
||||
void ToComment();
|
||||
void CommentLines();
|
||||
void UnComment();
|
||||
|
||||
void MacroMenu(Bar& menu);
|
||||
bool HasMacros();
|
||||
|
|
|
|||
|
|
@ -108,6 +108,9 @@ KEY(INITCAPS, "Capitalize the first character of words", 0)
|
|||
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(COMMENTLINES, "Comment code lines", K_SHIFT|K_ALT_K)
|
||||
KEY(UNCOMMENT, "Uncomment code", K_CTRL_K|K_ALT_K)
|
||||
|
||||
KEY(DIFF, "Compare with file..", 0)
|
||||
KEY(SVNDIFF, "Show svn history of file..", 0)
|
||||
|
|
|
|||
|
|
@ -109,19 +109,24 @@ void Ide::EditSpecial(Bar& menu)
|
|||
.Help("Copy the current identifier to the clipboard");
|
||||
menu.Add(AK_FORMATCODE, THISBACK(FormatCode))
|
||||
.Help("Reformat code in editor");
|
||||
menu.Add(AK_TOUPPER, THISBACK(TextToUpper))
|
||||
menu.Add(editor.IsSelection(), AK_TOUPPER, THISBACK(TextToUpper))
|
||||
.Help("Convert letters in selection to uppercase");
|
||||
menu.Add(AK_TOLOWER, THISBACK(TextToLower))
|
||||
menu.Add(editor.IsSelection(), AK_TOLOWER, THISBACK(TextToLower))
|
||||
.Help("Convert letters in selection to lowercase");
|
||||
menu.Add(AK_TOASCII, THISBACK(TextToAscii))
|
||||
menu.Add(editor.IsSelection(), AK_TOASCII, THISBACK(TextToAscii))
|
||||
.Help("Covert text to 7-bit ASCII removing all accents and special symbols");
|
||||
menu.Add(AK_INITCAPS, THISBACK(TextInitCaps))
|
||||
menu.Add(editor.IsSelection(), AK_INITCAPS, THISBACK(TextInitCaps))
|
||||
.Help("Capitalize the first character of words in selection");
|
||||
menu.Add(AK_SWAPCASE, THISBACK(SwapCase))
|
||||
menu.Add(editor.IsSelection(), AK_SWAPCASE, THISBACK(SwapCase))
|
||||
.Help("Swap the case of letters in selection");
|
||||
menu.Add(AK_TOCSTRING, THISBACK(ToCString))
|
||||
menu.Add(editor.IsSelection(), AK_TOCSTRING, THISBACK(ToCString))
|
||||
.Help("Convert selection to CString");
|
||||
}
|
||||
menu.Add(editor.IsSelection(), AK_TOCOMMENT, THISBACK(ToComment))
|
||||
.Help("Comment code");
|
||||
menu.Add(editor.IsSelection(), AK_COMMENTLINES, THISBACK(CommentLines))
|
||||
.Help("Comment code lines");
|
||||
menu.Add(editor.IsSelection(), AK_UNCOMMENT, THISBACK(UnComment))
|
||||
.Help("Uncomment code");}
|
||||
|
||||
void Ide::SearchMenu(Bar& menu)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue