ultimatepp/uppsrc/ide/Insert.cpp
cxl f1ca0f32d0 Removed stray DDUMP
git-svn-id: svn://ultimatepp.org/upp/trunk@1103 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2009-04-27 07:40:59 +00:00

120 lines
2.7 KiB
C++

#include "ide.h"
class InsertColorDlg : public WithInsertColorLayout<TopWindow> {
typedef InsertColorDlg CLASSNAME;
String r[4];
void Sync();
void Select(int i);
public:
String result;
InsertColorDlg();
};
void InsertColorDlg::Select(int i)
{
result = r[i];
Break(IDOK);
}
void InsertColorDlg::Sync()
{
RGBA c = rgbactrl.Get();
r[0] = Format("RGBA(%d, %d, %d, %d)", c.a, c.r, c.g, c.b);
rgba.SetLabel(r[0]);
r[1] = Format("Color(%d, %d, %d)", c.r, c.g, c.b);
color.SetLabel(r[1]);
r[2] = Format("%02x%02x%02x%02x", c.a, c.r, c.g, c.b);
ahex.SetLabel(r[2]);
r[3] = Format("%02x%02x%02x", c.r, c.g, c.b);
hex.SetLabel(r[3]);
}
InsertColorDlg::InsertColorDlg()
{
CtrlLayoutCancel(*this, "Insert color");
rgbactrl <<= THISBACK(Sync);
rgba <<= THISBACK1(Select, 0);
color <<= THISBACK1(Select, 1);
ahex <<= THISBACK1(Select, 2);
hex <<= THISBACK1(Select, 3);
Sync();
}
void Ide::InsertColor()
{
InsertColorDlg dlg;
dlg.Execute();
editor.Paste(dlg.result.ToWString());
}
void Ide::InsertLay(const String& fn)
{
String s;
s << "#define LAYOUTFILE <" << fn << ">\n"
<< "#include <CtrlCore/lay.h>\n";
editor.Paste(s.ToWString());
}
void Ide::InsertIml(const String& fn, String classname)
{
if(!EditText(classname, "Insert .iml include", "Img class"))
return;
String h;
h << "#define IMAGECLASS " << classname << "\n"
<< "#define IMAGEFILE <" << fn << ">\n"
<< "#include <Draw/iml";
editor.Paste((h + "_header.h>\n").ToWString());
ClearClipboard();
AppendClipboardText((h + "_source.h>\n"));
PromptOK("The .cpp part was saved to clipboard");
}
void Ide::InsertTpp(const String& fn)
{
String s;
s << "#define TOPICFILE <" << fn << "/all.i>\n"
<< "#include <Core/topic_group.h>\n";
editor.Paste(s.ToWString());
}
void Ide::InsertMenu(Bar& bar)
{
bar.Add("Insert color..", THISBACK(InsertColor));
int pi = GetPackageIndex();
const Workspace& wspc = IdeWorkspace();
if(pi >= 0 && pi < wspc.GetCount()) {
String pn = wspc[pi];
const Package& p = wspc.GetPackage(pi);
int n = 0;
for(int i = 0; i < p.GetCount() && n < 12; i++) {
String fn = p[i];
String ext = ToLower(GetFileExt(fn));
String pp = pn + '/' + fn;
if(ext == ".lay") {
bar.Add(fn + " include", THISBACK1(InsertLay, pp));
n++;
}
if(ext == ".iml") {
String c = GetFileTitle(fn);
c.Set(0, ToUpper(c[0]));
bar.Add(fn + " include", THISBACK2(InsertIml, pp, c.EndsWith("Img") ? c : c + "Img"));
n++;
}
if(ext == ".tpp") {
bar.Add(fn + " include", THISBACK1(InsertTpp, pp));
n++;
}
}
}
}
void Ide::EditorMenu(Bar& bar)
{
bar.Add("Insert", THISBACK(InsertMenu));
bar.MenuSeparator();
editor.StdBar(bar);
}