1
|
#include "ide.h"
|
2
|
|
3
|
INITBLOCK {
|
4
|
RegisterGlobalConfig("QTF-designer");
|
5
|
RegisterGlobalConfig("QTF-designer-editor");
|
6
|
}
|
7
|
|
8
|
class QtfDlg : public TopWindow {
|
9
|
typedef QtfDlg CLASSNAME;
|
10
|
|
11
|
void Text();
|
12
|
void Clear();
|
13
|
void Copy();
|
14
|
void Editor();
|
15
|
|
16
|
public:
|
17
|
Splitter leftSplit, mainSplit;
|
18
|
WithQtfLayout<ParentCtrl> qtfText;
|
19
|
RichTextCtrl qtf;
|
20
|
RichTextView help;
|
21
|
|
22
|
void Serialize(Stream& s);
|
23
|
|
24
|
QtfDlg();
|
25
|
};
|
26
|
|
27
|
void QtfDlg::Text()
|
28
|
{
|
29
|
qtf <<= ~qtfText.text;
|
30
|
}
|
31
|
|
32
|
void QtfDlg::Clear()
|
33
|
{
|
34
|
qtfText.text.Clear();
|
35
|
Text();
|
36
|
}
|
37
|
|
38
|
void QtfDlg::Copy()
|
39
|
{
|
40
|
WriteClipboardText(~qtfText.text);
|
41
|
Break();
|
42
|
}
|
43
|
|
44
|
struct QtfDlgEditor : TopWindow {
|
45
|
RichEditWithToolBar editor;
|
46
|
|
47
|
void Serialize(Stream& s);
|
48
|
|
49
|
QtfDlgEditor();
|
50
|
};
|
51
|
|
52
|
void QtfDlgEditor::Serialize(Stream& s)
|
53
|
{
|
54
|
SerializePlacement(s);
|
55
|
}
|
56
|
|
57
|
QtfDlgEditor::QtfDlgEditor()
|
58
|
{
|
59
|
Add(editor.SizePos());
|
60
|
Rect r = GetWorkArea();
|
61
|
Sizeable().Zoomable();
|
62
|
SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 100);
|
63
|
SetMinSize(Size(min(640, r.GetWidth() - 100), min(480, r.GetHeight() - 100)));
|
64
|
}
|
65
|
|
66
|
void QtfDlg::Editor()
|
67
|
{
|
68
|
QtfDlgEditor dlg;
|
69
|
LoadFromGlobal(dlg, "QTF-designer-editor");
|
70
|
dlg.editor.SetQTF((String)~qtfText.text);
|
71
|
dlg.Run();
|
72
|
if(PromptYesNo("Use the text?")) {
|
73
|
qtfText.text <<= AsQTF(dlg.editor.Get(),
|
74
|
CHARSET_UTF8, QTF_BODY|QTF_NOSTYLES|QTF_NOCHARSET|QTF_NOLANG);
|
75
|
Text();
|
76
|
}
|
77
|
StoreToGlobal(dlg, "QTF-designer-editor");
|
78
|
}
|
79
|
|
80
|
QtfDlg::QtfDlg()
|
81
|
{
|
82
|
Title("QTF designer");
|
83
|
CtrlLayout(qtfText);
|
84
|
qtfText.text <<= THISBACK(Text);
|
85
|
qtf.SetFrame(ViewFrame());
|
86
|
qtf.Background(SColorPaper);
|
87
|
Sizeable().Zoomable();
|
88
|
Rect r = GetWorkArea();
|
89
|
SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 200);
|
90
|
SetMinSize(Size(min(640, r.GetWidth() - 100), min(480, r.GetHeight() - 200)));
|
91
|
|
92
|
String path = AppendFileName(AppendFileName(PackageDirectory("RichText"), "srcdoc.tpp"), "QTF$en-us.tpp");
|
93
|
if(FileExists(path))
|
94
|
help.SetQTF(ReadTopic(LoadFile(path)).text);
|
95
|
else
|
96
|
help <<= "[= &&&QTF documentation not found";
|
97
|
|
98
|
qtfText.clear <<= THISBACK(Clear);
|
99
|
qtfText.copy <<= THISBACK(Copy);
|
100
|
qtfText.editor <<= THISBACK(Editor);
|
101
|
|
102
|
leftSplit.Vert(qtfText, qtf).SetPos(4000);
|
103
|
mainSplit.Horz(leftSplit, help).SetPos(3500);
|
104
|
Add(mainSplit.HSizePosZ(4, 4).VSizePosZ(4, 4));
|
105
|
}
|
106
|
|
107
|
void QtfDlg::Serialize(Stream& s)
|
108
|
{
|
109
|
int version = 1;
|
110
|
s / version;
|
111
|
s % qtfText.text;
|
112
|
SerializePlacement(s);
|
113
|
if(version >= 1) {
|
114
|
leftSplit.Serialize(s);
|
115
|
mainSplit.Serialize(s);
|
116
|
}
|
117
|
Text();
|
118
|
}
|
119
|
|
120
|
void Ide::Qtf()
|
121
|
{
|
122
|
QtfDlg dlg;
|
123
|
LoadFromGlobal(dlg, "QTF-designer");
|
124
|
int l,h;
|
125
|
bool sel=editor.GetSelection(l,h);
|
126
|
if(qtfsel && sel){
|
127
|
dlg.qtfText.text<<=(~editor).ToString().Mid(l,h-l);
|
128
|
dlg.qtfText.copy.SetLabel("Apply and close");
|
129
|
dlg.Run();
|
130
|
editor.Remove(l,h-l);
|
131
|
editor.Insert(l,(~dlg.qtfText.text).ToString());
|
132
|
}
|
133
|
else{
|
134
|
dlg.qtfText.copy.SetLabel("Copy and close");
|
135
|
dlg.Run();
|
136
|
}
|
137
|
StoreToGlobal(dlg, "QTF-designer");
|
138
|
}
|