My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
#include "ide.h"

struct GatherLinksIterator : RichText::Iterator {
Index<String> link;

virtual bool operator()(int pos, const RichPara& para)
{
for(int i = 0; i < para.GetCount(); i++) {
String l = para[i].format.link;
if(!IsNull(l))
link.FindAdd(l);
}
return false;
}
};

void GatherLinks(Index<String>& link, const char *topic)
{
if(link.Find(topic) < 0) {
Topic p = GetTopic(topic);
if(IsNull(p.text))
return;
link.Add(topic);
RichText txt = ParseQTF(p.text);
SyncTopicFile(txt, topic, ":ide:", p.title);
GatherLinksIterator ti;
txt.Iterate(ti);
for(int i = 0; i < ti.link.GetCount(); i++)
GatherLinks(link, ti.link[i]);
}
}

Index<String> TopicCtrl::idelink;

void TopicCtrl::ScanDirForTpp(const char *dir, const String& rel,
Index<String>& donepackage, Index<String>& lang_list)
{
TopicLink tl;
for(FindFile pff(AppendFileName(dir, "*.*")); pff; pff.Next()) {
if(pff.IsFolder() && *pff.GetName() != '.') {
String pdir = AppendFileName(dir, pff.GetName());
tl.package = rel + pff.GetName();
if(donepackage.Find(tl.package) < 0) {
donepackage.Add(tl.package);
for(FindFile ff(AppendFileName(pdir, "*.tpp")); ff; ff.Next())
if(ff.IsFolder()) {
tl.group = GetFileTitle(ff.GetName());
String dir = AppendFileName(pdir, ff.GetName());
for(FindFile ft(AppendFileName(dir, "*.tpp")); ft; ft.Next())
if(ft.IsFile()) {
tl.topic = GetFileTitle(ft.GetName());
int q = tl.topic.ReverseFind('$');
String l;
if(q >= 0) {
l = ToUpper(tl.topic.Mid(q + 1));
lang_list.FindAdd(l);
}
map.GetAdd(tl.package).GetAdd(tl.group).FindAdd(tl.topic);
}
}
}
ScanDirForTpp(pdir, tl.package + '/', donepackage, lang_list);
}
}
}

int map_serial, topic_serial;

void TopicCtrl::LoadMap()
{
map.Clear();
lang_list.Clear();
Vector<String> upp = GetUppDirs();
Index<String> donepackage, lang_list;
for(int i = 0; i < upp.GetCount(); i++)
ScanDirForTpp(upp[i], String(), donepackage, lang_list);
Vector<String> l = lang_list.PickKeys();
Sort(l);
String lng = ~lang;
lang.Clear();
lang.Add("All");
for(int i = 0; i < l.GetCount(); i++)
lang.Add(l[i]);
if(lng.GetCount() && lang.Find(lng))
lang <<= lng;
else
if(lang.Find("EN-US"))
lang <<= "EN-US";
else
if(lang.GetCount())
lang.SetIndex(0);
}

static String sTopicHome = "\3topic://ide/app/index$en-us";
static String s_idehelp = "TheIDE help";
static String s_usedpackages = "Used packages";
static String s_otherpackages = "Other packages";
static String s_documents = "Documents";
static String s_reference = "Reference";
static String s_implementation = "Implementation";

inline int sFindN(const String& s)
{
if(s == s_idehelp) return 0;
if(s == s_usedpackages) return 1;
if(s == s_otherpackages) return 2;
if(s == s_documents) return 3;
if(s == s_reference) return 4;
if(s == s_implementation) return 5;
return 6;
}

int TopicSortOrder(const Value& k1, const Value& v1, const Value& k2, const Value& v2)
{
String s1 = v1;
String s2 = v2;
bool bk1 = IsNull(k1);
bool bk2 = IsNull(k2);
int q = (int)bk1 - (int)bk2;
if(q) return q;
if(bk1) {
int q = sFindN(s1) - sFindN(s2);
if(q) return q;
}
return StdValueCompare(v1, v2);
}

void TopicCtrl::SyncDocTree()
{
if(map_serial != topic_serial) {
LoadMap();
map_serial = topic_serial;
}

Vector<String> ss = Split((String)~search, ' ');
Vector<String> sdx;
for(int i = 0; i < ss.GetCount(); i++)
sdx.Add(ToUtf8(ToLower(FromUtf8(ss[i]))));

ClearTree();

String hdx = sTopicHome.Mid(1);
if(idelink.GetCount() == 0)
GatherLinks(idelink, hdx);
int ide = 0;
bool idefirst = true;
if(MatchTopicLink(hdx, sdx)) {
ide = AddTree(0, IdeImg::Package(), "\3" + hdx, s_idehelp);
idefirst = false;
}
for(int i = 0; i < idelink.GetCount(); i++) {
if(idelink[i] != hdx && MatchTopicLink(idelink[i], sdx)) {
if(idefirst) {
ide = AddTree(0, IdeImg::Package(), "\3" + hdx, s_idehelp);
idefirst = false;
}
AddTree(ide, TopicImg::Topic(), "\3" + idelink[i], GetTopic(idelink[i]).title);
}
}

Index<String> used;
const Workspace& wspc = GetIdeWorkspace();
for(int i = 0; i < wspc.GetCount(); i++)
used.Add(wspc[i]);

int usid = 0;
bool usedfirst = true;
int otid = 0;
bool otherfirst = true;

String lng = ~lang;
for(int i = 0; i < map.GetCount(); i++) {
TopicLink tl;
tl.package = map.GetKey(i);
bool packagefirst = true;
int pid = 0;
VectorMap<String, Index<String> >& group = map[i];
for(int i = 0; i < group.GetCount(); i++) {
tl.group = group.GetKey(i);
if(all || tl.group == "src" || tl.group == "srcdoc" || tl.group == "srcimp") {
String n = tl.group;
if(n == "src")
n = s_reference;
if(n == "srcdoc")
n = s_documents;
if(n == "srcimp")
n = s_implementation;
int gid = 0;
bool groupfirst = true;
const Index<String>& topic = group[i];
for(int i = 0; i < topic.GetCount(); i++) {
tl.topic = topic[i];
int q = tl.topic.ReverseFind('$');
String l;
if(q >= 0)
l = ToUpper(tl.topic.Mid(q + 1));
String link = TopicLinkString(tl);
if(idelink.Find(link) < 0 && MatchTopicLink(link, sdx) && (lng == "All" || lng == l)) {
int pd;
if(used.Find(tl.package) >= 0) {
if(usedfirst) {
usid = AddTree(0, IdeImg::Package(), Null, s_usedpackages);
usedfirst = false;
}
pd = usid;
}
else {
if(otherfirst) {
otid = AddTree(0, IdeImg::Package(), Null, s_otherpackages);
otherfirst = false;
}
pd = otid;
}
if(packagefirst) {
pid = AddTree(pd, TopicImg::Package(), Null, tl.package);
packagefirst = false;
}
if(groupfirst) {
gid = AddTree(pid, Null, Null, n);
groupfirst = false;
}
String p = TopicLinkString(tl);
String t = GetTopicTitle(p);
AddTree(gid, TopicImg::Topic(), p, t);
}
}
}
}
}
SortTree(0, TopicSortOrder);
FinishTree();
if(sdx.GetCount()) {
OpenDeep();
CurrentOrHome();
}
}

Vector<String> GetTypeRefLinks(const String& t, String &label)
{
const char *tp[] = { "", "::struct", "::class", "::union", "::typedef", "::enum" };
Vector<String> f;
for(int i = 0; i < __countof(tp); i++) {
label = t + tp[i];
f = GetRefLinks(label);
if(f.GetCount())
break;
}
return f;
}

String recent_topic;

Topic TopicCtrl::AcquireTopic(const String& t)
{
recent_topic = t;
String topic = t;
internal = (byte)*topic < 32;
if(*topic == '\3')
return GetTopic(topic.Mid(1));
if(topic[0] == ':' && topic[1] == ':') {
String lbl;
Vector<String> link = GetTypeRefLinks(topic, lbl);
if(link.GetCount() == 0)
return Topic();
if(link.GetCount() == 1)
topic = link[0];
else {
WithSimpleListLayout<TopWindow> dlg;
CtrlLayoutOKCancel(dlg, "Choose one of more link targets");
dlg.list.AddKey();
dlg.list.AddColumn("Topic");
for(int i = 0; i < link.GetCount(); i++)
dlg.list.Add(link[i], GetTopicTitle(link[i]));
dlg.list.SetCursor(0);
if(dlg.Run() != IDOK || !dlg.list.IsCursor())
return Topic();
topic = dlg.list.GetKey();
}
if(lbl.GetCount())
topic << '#' << lbl;
}
TopicLink tl = ParseTopicLink(topic);
if(!IsNull(tl.package)) {
String path = AppendFileName(
AppendFileName(PackageDirectory(tl.package), tl.group + ".tpp"),
tl.topic + ".tpp");
Topic t = ReadTopic(LoadFile(path));
t.label = tl.label;
tl.label.Clear();
t.link = TopicLinkString(tl);
return t;
}
return Topic();
}



struct HighlightWords : RichText::Iterator {
Vector<String> words;
struct Pos : Moveable<Pos> { int pos, len; };
Vector<Pos> pos;

int FindPattern(const String& x) {
for(int i = 0; i < words.GetCount(); i++)
if(x.StartsWith(words[i]))
return words[i].GetCount();
return -1;
}

virtual bool operator()(int tpos, const RichPara& para) {
WString text = para.GetText();
const wchar *s = text;
for(;;) {
while(!IsAlpha(*s) && !IsDigit(*s) && *s)
s++;
if(*s == '\0')
break;
String wb;
const wchar *b = s;
while(IsAlpha(*s) || IsDigit(*s))
wb.Cat(ToUpper(*s++));
int q = FindPattern(wb);
if(q >= 0) {
Pos& p = pos.Add();
p.pos = int(b - ~text) + tpos;
p.len = q;
}
}
return false;
}
};

void TopicCtrl::FinishText(RichText& text)
{
spos.Clear();
if(!showwords)
return;
Vector<String> ss = Split((String)~search, ' ');

if(ss.GetCount() == 0)
return;
HighlightWords hw;
hw.words = ss;
text.Iterate(hw);
RichText::FormatInfo fi;
fi.charvalid = RichText::PAPER|RichText::INK;
fi.paravalid = 0;
fi.paper = SColorHighlight();
fi.ink = SColorHighlightText();
for(int i = 0; i < hw.pos.GetCount(); i++) {
text.ApplyFormatInfo(hw.pos[i].pos, fi, hw.pos[i].len);
spos.Add(hw.pos[i].pos);
}
}

void TopicCtrl::OpenTopic()
{
WhenTopic();
}

struct SlideShow : TopWindow {
virtual bool Key(dword key, int count);

RichTextView text;
Vector<String> path;
int page;
int rp;

void SetPage();

SlideShow();
};

bool SlideShow::Key(dword key, int count)
{
switch(key) {
case K_ESCAPE:
Break();
break;
case K_LEFT:
case K_UP:
case K_PAGEUP:
page--;
SetPage();
break;
case K_RIGHT:
case K_DOWN:
case K_PAGEDOWN:
page++;
SetPage();
break;
}
return true;
}

void SlideShow::SetPage()
{
page = minmax(page, 0, path.GetCount() - 1);
if(page != rp) {
rp = page;
text <<= ReadTopic(LoadFile(path[page])).text;
}
}

SlideShow::SlideShow()
{
FullScreen();
Add(text.SizePos());
text.NoHyperlinkDecoration();
text.NoSb();
text.VCenter();
text.SetZoom(Zoom(1, 5));
text.Margins(8);
rp = -1;
}

void TopicCtrl::SShow()
{
SlideShow ss;
TopicLink tl = ParseTopicLink(GetCurrent());
if(IsNull(tl.package))
return;
String folder = AppendFileName(PackageDirectory(tl.package), tl.group + ".tpp");
FindFile ff(AppendFileName(folder, "*.tpp"));
Array<String> l;
while(ff) {
if(ff.IsFile())
l.Add(GetFileTitle(ff.GetName()));
ff.Next();
}
if(l.GetCount() == 0)
return;
Sort(l);
for(int i = 0; i < l.GetCount(); i++) {
if(tl.topic == l[i])
ss.page = i;
ss.path.Add(AppendFileName(folder, l[i] + ".tpp"));
}
ss.SetPage();
ss.Run();
tl.topic = l[ss.page];
GoTo(TopicLinkString(tl));
}

void TopicCtrl::Search()
{
int l, h;
ClearCurrentLink();
search.GetSelection(l, h);
SyncDocTree();
SetBar();
search.SetFocus();
search.SetSelection(l, h);
}

void TopicCtrl::SearchWord(const String& s)
{
search <<= ToUpper(s);
Search();
}

void TopicCtrl::ShowWords()
{
showwords = !showwords;
SetBar();
GoTo(GetCurrent());
}

void TopicCtrl::All()
{
all = !all;
SyncDocTree();
SetBar();
}

void TopicCtrl::Lang()
{
SyncDocTree();
SetBar();
}

bool TopicCtrl::Key(dword key, int count)
{
if(key == K_ENTER && search.HasFocus()) {
Search();
return true;
}
return HelpWindow::Key(key, count);
}

void TopicCtrl::FocusSearch()
{
search.SetFocus();
}

void TopicCtrl::Prev()
{
if(!Up(spos))
HelpWindow::Prev();
}

void TopicCtrl::Next()
{
if(!Down(spos))
HelpWindow::Next();
}

void TopicCtrl::BarEx(Bar& bar)
{
bar.Gap();
bar.Add(lang, HorzLayoutZoom(60));
bar.Add("All topics", IdeImg::HelpAll(), THISBACK(All))
.Check(all);
bar.Gap(HorzLayoutZoom(30));
bar.Add(search, HorzLayoutZoom(300));
bar.Add(search.GetLength(), "Prev", IdeImg::GoPrev(), THISBACK(Prev));
bar.Add(search.GetLength(), "Next", IdeImg::GoNext(), THISBACK(Next));

bar.AddKey(K_CTRL_F, THISBACK(FocusSearch));
/* bar.Add("Highlight search keywords in topic", IdeImg::ShowWords(), THISBACK(ShowWords))
.Check(showwords);*/
bar.Add(!internal && GetCurrent().StartsWith("topic:"),
IdeImg::show(), THISBACK(SShow));
bar.GapRight();
bar.Separator();
bar.Add(!internal && GetCurrent().StartsWith("topic:"),
TopicImg::Topic(), THISBACK(OpenTopic));
}

void TopicCtrl::Serialize(Stream& s)
{
int version = 3;
s / version;
if(version < 3) {
WithDropChoice<EditString> dummy;
dummy.SerializeList(s);
}
if(version >= 1)
s % showwords;
if(version >= 2)
s % all;
}

struct HelpDes : public IdeDesigner {
TopicCtrl *topic;

virtual String GetFileName() const { return HELPNAME; }
virtual void Save() {}
virtual void EditMenu(Bar& menu) {}
virtual Ctrl& DesignerCtrl() { return *topic; }
virtual void SetFocus() { topic->SetFocus(); }

~HelpDes() { topic->Remove(); }
};

bool IsHelpName(const char *path)
{
return strcmp(path, HELPNAME) == 0;
}

struct HelpModule : public IdeModule {
virtual Image FileIcon(const char *path) {
return IsHelpName(path) ? IdeImg::help() : Null;
}
virtual IdeDesigner *CreateDesigner(Ide *ide, const char *path, byte cs) {
if(IsHelpName(path)) {
topic_serial++;
GetRefLinks("");
ide->doc.SyncDocTree();
ide->doc.GoTo(Nvl(recent_topic, sTopicHome));
HelpDes *d = new HelpDes;
d->topic = &ide->doc;
return d;
}
return false;
}
virtual void Serialize(Stream& s) {
s % recent_topic;
}
};

INITBLOCK {
RegisterIdeModule(Single<HelpModule>());
}

int CharFilterTopicSearch(int c)
{
if(c == ' ') return c;
c = CharFilterDefaultToUpperAscii(c);
return IsAlNum(c) ? c : 0;
}

TopicCtrl::TopicCtrl()
{
showwords = true;
all = false;
lang <<= THISBACK(Lang);
lang.Tip("Language"),
search.NullText("Search", StdFont().Italic(), SColorDisabled());
search.Tip("Full text search");
search <<= THISBACK(Search);
search.SetFilter(CharFilterTopicSearch);
internal = true;
}

void Ide::ShowTopics()
{
if(designer && designer->GetFileName() == HELPNAME) {
CycleFiles();
tabi = 0;
return;
}
if(doc_serial != TopicEditor::GetSerial()) {
GetRefLinks("");
doc.SyncDocTree();
doc.GoTo(sTopicHome);
doc_serial = TopicEditor::GetSerial();
}
EditFile(HELPNAME);
}

void Ide::SearchTopics()
{
String s = editor.GetWord();
GetRefLinks("");
doc.SyncDocTree();
doc.GoTo(sTopicHome);
EditFile(HELPNAME);
if(s.GetLength())
doc.SearchWord(s);
}

void Ide::RefreshBrowser()
{
editor.SyncNavigator();
doc.SyncDocTree();
}

Change log

r4457 by cxl on Jan 21, 2012   Diff
*uppsrc: Fixed many GCC warnings
Go to: 
Project members, sign in to write a code review

Older revisions

r1916 by cxl on Jan 21, 2010   Diff
TheIDE: Help system now higlights
search words and allows navigating
them up/down
r1913 by cxl on Jan 20, 2010   Diff
theide: Fixed highlighting of searched
words in help
r1159 by cxl on May 11, 2009   Diff
CtrlLib/theide: Fixed issue with wrong
opening web browser in help
All revisions of this file

File info

Size: 14261 bytes, 637 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting