diff --git a/uppsrc/CtrlLib/Ch.cpp b/uppsrc/CtrlLib/Ch.cpp index f66963876..4d84089f0 100644 --- a/uppsrc/CtrlLib/Ch.cpp +++ b/uppsrc/CtrlLib/Ch.cpp @@ -63,7 +63,7 @@ void MakeDialogIcons() return w; }; - static const char *s_information = "M28.75 28.31 Q32.63 28.31 35.28 31.00 Q37.94 33.69 37.94 37.50 Q37.94 41.31 35.25 44.00 Q32.56 46.69 28.75 46.69 Q25.00 46.69 22.31 44.00 Q19.63 41.31 19.63 37.50 Q19.63 33.69 22.28 31.00 Q24.94 28.31 28.75 28.31 ZM32.63 57.06 L19.81 101.50 Q18.75 105.31 18.75 106.50 Q18.75 107.19 19.31 107.78 Q19.88 108.38 20.50 108.38 Q21.56 108.38 22.63 107.44 Q25.44 105.13 29.38 99.06 L31.50 100.31 Q22.06 116.75 11.44 116.75 Q7.38 116.75 4.97 114.47 Q2.56 112.19 2.56 108.69 Q2.56 106.38 3.63 102.81 L12.31 72.94 Q13.56 68.63 13.56 66.44 Q13.56 65.06 12.38 64.00 Q11.19 62.94 9.13 62.94 Q8.19 62.94 6.88 63.00 L7.69 60.50 L28.88 57.06 Z"; + static const char *s_information = "|M28.75 28.31 Q32.63 28.31 35.28 31.00 Q37.94 33.69 37.94 37.50 Q37.94 41.31 35.25 44.00 Q32.56 46.69 28.75 46.69 Q25.00 46.69 22.31 44.00 Q19.63 41.31 19.63 37.50 Q19.63 33.69 22.28 31.00 Q24.94 28.31 28.75 28.31 ZM32.63 57.06 L19.81 101.50 Q18.75 105.31 18.75 106.50 Q18.75 107.19 19.31 107.78 Q19.88 108.38 20.50 108.38 Q21.56 108.38 22.63 107.44 Q25.44 105.13 29.38 99.06 L31.50 100.31 Q22.06 116.75 11.44 116.75 Q7.38 116.75 4.97 114.47 Q2.56 112.19 2.56 108.69 Q2.56 106.38 3.63 102.81 L12.31 72.94 Q13.56 68.63 13.56 66.44 Q13.56 65.06 12.38 64.00 Q11.19 62.94 9.13 62.94 Q8.19 62.94 6.88 63.00 L7.69 60.50 L28.88 57.06 Z"; CtrlImg::Set(CtrlImg::I_information, MakeCircularIcon(Color(85, 127, 200), s_information, 0.6, Color(243, 255, 211))); static const char *s_question = "M15.81 79.13 Q17.56 81.00 18.63 83.16 Q19.69 85.31 19.69 87.50 Q19.69 89.00 19.13 90.28 Q18.56 91.56 17.59 92.50 Q16.63 93.44 15.31 93.97 Q14.00 94.50 12.44 94.50 Q11.00 94.50 9.69 94.03 Q8.38 93.56 7.31 92.63 Q6.25 91.69 5.63 90.31 Q5.00 88.94 5.00 87.06 Q5.00 84.25 6.59 81.09 Q8.19 77.94 11.28 75.31 Q14.38 72.69 19.00 70.94 Q23.63 69.19 29.63 69.19 Q35.56 69.19 40.16 70.94 Q44.75 72.69 47.91 75.59 Q51.06 78.50 52.69 82.25 Q54.31 86.00 54.31 90.06 Q54.31 98.06 47.88 105.06 Q45.25 107.94 41.94 110.56 Q38.63 113.19 35.72 116.06 Q32.81 118.94 30.84 122.34 Q28.88 125.75 28.88 130.13 Q28.88 131.00 28.97 132.16 Q29.06 133.31 29.25 134.56 Q28.25 134.94 27.09 135.09 Q25.94 135.25 24.88 135.25 Q23.88 131.31 23.88 127.94 Q23.88 124.69 24.69 122.06 Q25.50 119.44 26.78 117.28 Q28.06 115.13 29.66 113.28 Q31.25 111.44 32.88 109.75 Q34.81 107.63 36.50 105.63 Q38.19 103.63 39.41 101.31 Q40.63 99.00 41.34 96.22 Q42.06 93.44 42.06 89.81 Q42.06 85.56 41.06 82.59 Q40.06 79.63 38.25 77.75 Q36.44 75.88 33.91 75.03 Q31.38 74.19 28.25 74.19 Q24.50 74.19 21.19 75.38 Q17.88 76.56 15.81 79.13 ZM27.19 161.75 Q25.38 161.75 23.84 161.13 Q22.31 160.50 21.13 159.38 Q19.94 158.25 19.28 156.69 Q18.63 155.13 18.63 153.25 Q18.63 151.38 19.31 149.78 Q20.00 148.19 21.16 147.06 Q22.31 145.94 23.88 145.28 Q25.44 144.63 27.25 144.63 Q29.00 144.63 30.56 145.25 Q32.13 145.88 33.31 147.00 Q34.50 148.13 35.16 149.69 Q35.81 151.25 35.81 153.13 Q35.81 155.00 35.16 156.59 Q34.50 158.19 33.31 159.34 Q32.13 160.50 30.56 161.13 Q29.00 161.75 27.19 161.75 Z"; CtrlImg::Set(CtrlImg::I_question, MakeCircularIcon(Color(85, 127, 200), s_question)); diff --git a/uppsrc/ide/Insert.cpp b/uppsrc/ide/Insert.cpp index 6b67b24f4..4e6a07346 100644 --- a/uppsrc/ide/Insert.cpp +++ b/uppsrc/ide/Insert.cpp @@ -148,15 +148,6 @@ void Ide::InsertText(const String& text) editor.Paste(text.ToWString()); } -void Ide::InsertCString() -{ - if(editor.IsReadOnly()) - return; - String txt = ReadClipboardText(); - if(txt.GetCount()) - editor.Paste(AsCString(txt).ToWString()); -} - void Ide::InsertFilePath(bool c) { if(editor.IsReadOnly()) @@ -170,6 +161,53 @@ void Ide::InsertFilePath(bool c) } } + +void Ide::InsertAs(const String& data) +{ + WithInsertAsLayout dlg; + CtrlLayoutOKCancel(dlg, "Insert data"); + if(data.GetCount() > 20*1024) + Exclamation("Data size is too big!&(Limit is 20KB.)"); + String f[6]; + f[0] = data; + f[1] = Encode64(data); + f[2] = data; + f[3] = LZ4Compress(data); + f[4] = ZCompress(data); + f[5] = LZMACompress(data); + for(int i = 0; i < 6; i++) + dlg.format.SetLabel(i, dlg.format.GetLabel(i) + " (" + AsString(f[i].GetCount()) + ")"); + + if(dlg.Execute() != IDOK) + return; + int i = ~dlg.format; + if(i < 0 || i >= 6) + return; + String d = f[i]; + WriteClipboardText(AsString(d.GetCount())); + if(i == 0 || i == 1) + editor.Paste(AsCString(d).ToWString()); + else { + for(int i = 0; i < d.GetCount(); i += 256) { + int e = min(i + 256, d.GetCount()); + String h; + for(int j = i; j < e; j++) + h << AsString((int)(byte)d[j]) << ','; + h << '\n'; + editor.Paste(h.ToWString()); + } + } +} + +void Ide::InsertAs() +{ + if(editor.IsReadOnly()) + return; + String txt = ReadClipboardText(); + if(txt.GetCount()) + InsertAs(txt); +} + void Ide::InsertFileBase64() { if(editor.IsReadOnly()) @@ -177,11 +215,13 @@ void Ide::InsertFileBase64() String path = SelectFileOpen("All files\t*.*"); path.Replace("\\", "/"); if(path.GetCount()) { - if(GetFileLength(path) >= 100*1024) { - Exclamation("File is too big!&(Limit is 100KB.)"); + if(GetFileLength(path) >= 20*1024) { + Exclamation("File is too big!&(Limit is 20KB.)"); return; } - String s = Encode64(LoadFile(path)); + InsertAs(LoadFile(path)); + } +/* String s = Encode64(LoadFile(path)); int i = 0; while(i < s.GetLength()) { int n = min(s.GetCount() - i, 2000); @@ -190,7 +230,7 @@ void Ide::InsertFileBase64() editor.Paste(AsCString(s.Mid(i, n)).ToWString()); i += n; } - } + }*/ } void Ide::InsertMenu(Bar& bar) @@ -235,10 +275,10 @@ void Ide::InsertMenu(Bar& bar) bar.Add(s, THISBACK1(InsertText, s)); } } - bar.Add("Insert clipboard as C string", THISBACK(InsertCString)); bar.Add("Insert file path..", THISBACK1(InsertFilePath, false)); bar.Add("Insert file path as C string..", THISBACK1(InsertFilePath, true)); - bar.Add("Insert file as C string Base64 encoded..", THISBACK(InsertFileBase64)); + bar.Add("Insert clipboard as..", [=] { InsertAs(); }); + bar.Add("Insert file as..", THISBACK(InsertFileBase64)); } void Ide::InsertInclude(Bar& bar) diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index ac41bbb11..450cc1368 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -811,7 +811,8 @@ public: void InsertLay(const String& fn); void InsertIml(const Package& pkg, const String& fn, String classname); void InsertText(const String& text); - void InsertCString(); + void InsertAs(const String& data); + void InsertAs(); void InsertFilePath(bool c); void InsertFileBase64(); void InsertMenu(Bar& bar); diff --git a/uppsrc/ide/ide.lay b/uppsrc/ide/ide.lay index ba618ef7b..6a03af08d 100644 --- a/uppsrc/ide/ide.lay +++ b/uppsrc/ide/ide.lay @@ -869,3 +869,10 @@ LAYOUT(SlideShowSettingsLayout, 184, 188) ITEM(Button, report, SetLabel(t_("Export")).LeftPosZ(8, 104).TopPosZ(164, 20)) END_LAYOUT +LAYOUT(InsertAsLayout, 276, 168) + ITEM(Switch, format, SetLabel(t_("C string\nBase64 encoded text\nByte values\nLZ4 compressed byte values\nZ compressed byte values\n7z compressed byte values")).LeftPosZ(8, 260).TopPosZ(8, 96)) + ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(76, 64).BottomPosZ(8, 24)) + ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24)) + ITEM(Label, dv___3, SetLabel(t_("Data length will be put into the clipboard")).LeftPosZ(8, 260).TopPosZ(108, 19)) +END_LAYOUT +