diff --git a/uppsrc/ide/Insert.cpp b/uppsrc/ide/Insert.cpp index 1318144ac..808cb6467 100644 --- a/uppsrc/ide/Insert.cpp +++ b/uppsrc/ide/Insert.cpp @@ -81,6 +81,13 @@ void Ide::InsertText(const String& text) editor.Paste(text.ToWString()); } +void Ide::InsertCString() +{ + String txt = ReadClipboardText(); + if(txt.GetCount()) + editor.Paste(AsCString(txt).ToWString()); +} + void Ide::InsertMenu(Bar& bar) { if(bar.IsScanKeys()) @@ -123,6 +130,7 @@ void Ide::InsertMenu(Bar& bar) bar.Add(s, THISBACK1(InsertText, s)); } } + bar.Add("Insert clipboard as C string", THISBACK(InsertCString)); } void Ide::EditorMenu(Bar& bar) diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index 79691ffcf..cece0dcbf 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -847,6 +847,7 @@ public: void InsertLay(const String& fn); void InsertIml(const String& fn, String classname); void InsertText(const String& text); + void InsertCString(); void InsertMenu(Bar& bar); void EditorMenu(Bar& bar); @@ -870,6 +871,7 @@ public: void TextToAscii(); void TextInitCaps(); void SwapCase(); + void ToCString(); void MacroMenu(Bar& menu); bool HasMacros(); diff --git a/uppsrc/ide/ide.key b/uppsrc/ide/ide.key index 3b5f76e29..ac31177c4 100644 --- a/uppsrc/ide/ide.key +++ b/uppsrc/ide/ide.key @@ -103,6 +103,7 @@ KEY(TOLOWER, "To lowercase", 0) 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(DIFF, "Compare with file..", 0) KEY(SVNDIFF, "Show svn history of file..", 0) diff --git a/uppsrc/ide/idebar.cpp b/uppsrc/ide/idebar.cpp index 60f3ddeb2..1fb08cd6a 100644 --- a/uppsrc/ide/idebar.cpp +++ b/uppsrc/ide/idebar.cpp @@ -117,6 +117,8 @@ void Ide::EditSpecial(Bar& menu) .Help("Capitalize the first character of words in selection"); menu.Add(AK_SWAPCASE, THISBACK(SwapCase)) .Help("Swap the case of letters in selection"); + menu.Add(AK_TOCSTRING, THISBACK(ToCString)) + .Help("Convert selection to CString"); } void Ide::SearchMenu(Bar& menu) diff --git a/uppsrc/ide/idetool.cpp b/uppsrc/ide/idetool.cpp index 8c836ca84..320ee1ad6 100644 --- a/uppsrc/ide/idetool.cpp +++ b/uppsrc/ide/idetool.cpp @@ -283,6 +283,16 @@ void Ide::SwapCase() AlterText(sSwapCase); } +static WString sCString(const WString& s) +{ + return AsCString(s.ToString()).ToWString(); +} + +void Ide::ToCString() +{ + AlterText(sCString); +} + void Ide::Times() { WithStatisticsLayout statdlg;