1 #ifndef _Browser_Browser_h
2 #define _Browser_Browser_h
3
4 #include <CtrlLib/CtrlLib.h>
5 #include <CppBase/CppBase.h>
6 #include <ide/Common/Common.h>
7 #include <RichEdit/RichEdit.h>
8 #include <PdfDraw/PdfDraw.h>
9
10 #define LAYOUTFILE <ide/Browser/Browser.lay>
11 #include <CtrlCore/lay.h>
12
13 #define IMAGECLASS BrowserImg
14 #define IMAGEFILE <ide/Browser/Browser.iml>
15 #include <Draw/iml_header.h>
16
17 INITIALIZE(CodeBase)
18
19 class Browser;
20
21 void ReduceCacheFolder(const char *path, int max_total);
22
23 void LockCodeBase();
24 void UnlockCodeBase();
25 void UnlockCodeBaseAll();
26
27 struct CodeBaseLock { // Use when accessing CodeBase
CodeBaseLockCodeBaseLock28 CodeBaseLock() { LockCodeBase(); }
~CodeBaseLockCodeBaseLock29 ~CodeBaseLock() { UnlockCodeBase(); }
30 };
31
32 CppBase& CodeBase();
33
34 struct SourceFileInfo {
35 Time time;
36 String dependencies_md5sum; // dependencies from other files - usings, initial namespace, macros
37 String md5sum; // preprocessing 'fingerprint' to detect changes
38 Vector<int> depends; // indicies of file this files depends on, for time-check
39 Time depends_time;
40
41 void Serialize(Stream& s);
42
SourceFileInfoSourceFileInfo43 SourceFileInfo() { time = Null; depends_time = Null; }
44 };
45
46 void NewCodeBase();
47 void ParseSrc(Stream& in, int file, Event<int, const String&> error);
48 void CodeBaseScanFile(Stream& in, const String& fn);
49 void CodeBaseScanFile(const String& fn, bool auto_check);
50 void ClearCodeBase();
51 // void CheckCodeBase();
52 void RescanCodeBase();
53 void SyncCodeBase();
54 void SaveCodeBase();
55 bool ExistsBrowserItem(const String& item);
56 void FinishCodeBase();
57
58 String PreprocessLayFile(const char *fn);
59 Vector<String> PreprocessSchFile(const char *fn);
60 String PreprocessImlFile(const char *fn);
61
62 int GetSourceFileIndex(const String& path);
63 String GetSourceFilePath(int file);
64
65 String MakeCodeRef(const String& scope, const String& item);
66 void SplitCodeRef(const String& ref, String& scope, String& item);
67
68 const CppItem *GetCodeRefItem(const String& ref, const String& rfile);
69 const CppItem *GetCodeRefItem(const String& ref);
70
71 int GetMatchLen(const char *s, const char *t);
72
73
74 enum WithBodyEnum { WITHBODY = 33 };
75
BrowserFont()76 inline Font BrowserFont() { return StdFont(); }
77
78 struct CppItemInfo : CppItem {
79 String scope;
80 bool over;
81 bool overed;
82 int inherited;
83 int typei;
84
CppItemInfoCppItemInfo85 CppItemInfo() { over = overed = virt = false; inherited = line = 0; }
86 };
87
88 enum {
89 ITEM_TEXT,
90 ITEM_NAME,
91 ITEM_CPP_TYPE,
92 ITEM_CPP,
93 ITEM_PNAME,
94 ITEM_TNAME,
95 ITEM_NUMBER,
96 ITEM_SIGN,
97 ITEM_UPP,
98 ITEM_TYPE,
99
100 ITEM_PTYPE = ITEM_TYPE + 10000,
101 };
102
103 struct ItemTextPart : Moveable<ItemTextPart> {
104 int pos;
105 int len;
106 int type;
107 int ii;
108 int pari;
109 };
110
111 Vector<ItemTextPart> ParseItemNatural(const String& name, const String& natural, const String& ptype,
112 const String& pname, const String& type, const String& tname,
113 const String& ctname, const char *s);
114 Vector<ItemTextPart> ParseItemNatural(const String& name, const CppItem& m, const char *natural);
115 Vector<ItemTextPart> ParseItemNatural(const CppItemInfo& m);
116 Vector<ItemTextPart> ParseItemNatural(const CppItemInfo& m);
117
118 int GetItemHeight(const CppItem& m, int cx);
119
120 enum AdditionalKinds {
121 KIND_INCLUDEFILE = 100,
122 KIND_INCLUDEFILE_ANY,
123 KIND_INCLUDEFOLDER,
124 };
125
126 void PaintText(Draw& w, int& x, int y, const char *text,
127 const Vector<ItemTextPart>& n, int starti, int count, bool focuscursor,
128 Color _ink, bool italic);
129 void PaintCppItemImage(Draw& w, int& x, int ry, int access, int kind, bool focuscursor);
130
131 struct CppItemInfoDisplay : public Display
132 {
133 bool namestart;
134 bool showtopic;
135
136 int DoPaint(Draw& w, const Rect& r, const Value& q,
137 Color _ink, Color paper, dword style) const;
138 virtual void Paint(Draw& w, const Rect& r, const Value& q,
139 Color _ink, Color paper, dword style) const;
140 virtual Size GetStdSize(const Value& q) const;
141
CppItemInfoDisplayCppItemInfoDisplay142 CppItemInfoDisplay() { namestart = false; showtopic = false; }
143 };
144
145 int SearchItemFilter(int c);
146
147 struct CodeBrowser {
148 typedef CodeBrowser CLASSNAME;
149
150 CppItemInfoDisplay display;
151 ArrayCtrl scope;
152 ArrayCtrl item;
153 EditString search_scope;
154 EditString search;
155 // FrameRight<Button> clear;
156 int range;
157 ButtonOption rangebutton[3];
158 ButtonOption sort;
159 Event<> WhenKeyItem;
160 Event<> WhenClear;
161
162 String GetPm();
163 void Load();
164 void LoadScope();
165 void Goto(const String& coderef, const String& rfile);
166 void Search();
NameStartCodeBrowser167 void NameStart() { display.namestart = true; }
168 String GetCodeRef(int i) const;
169 String GetCodeRef() const;
170 CppItemInfo GetItemInfo(int i) const;
171 CppItemInfo GetItemInfo() const;
172 bool Key(dword key, int count);
173 bool IsSearch() const;
174 void ClearSearch();
175 void SetRange(int r);
176 void Sort();
177
178 CodeBrowser();
179 };
180
181 struct TopicInfo : Moveable<TopicInfo> {
182 Time time;
183 String path;
184 String title;
185 Vector<int> words;
186
TopicInfoTopicInfo187 TopicInfo() {}
188
189 rval_default(TopicInfo);
190 };
191
192 String GetTopicPath(const TopicLink& link);
193 String GetTopicPath(const String& link);
194
195 extern bool SyncRefsFinished;
196 extern bool SyncRefsShowProgress;
197
198 void SyncRefs();
199 void SyncTopicFile(const RichText& text, const String& link, const String& path,
200 const String& title);
201 void SyncTopicFile(const String& link);
202 String GetTopicTitle(const String& link);
203 void InvalidateTopicInfoPath(const String& path);
204
205 bool LegacyRef(String& ref);
206
207 Vector<String> GetRefLinks(const String& ref);
208
209 int TopicWordIndex(const String& w);
210 int MatchWord(const Vector<int>& w, const String& pattern);
211 bool MatchTopicLink(const String& link, const Vector<String>& query);
212
213 #define LAYOUTFILE <ide/Browser/Topic.lay>
214 #include <CtrlCore/lay.h>
215
216 struct ReferenceDlg : WithReferenceDlgLayout<TopWindow>, CodeBrowser {
217 void EnterItem();
218 void EnterItemOk();
219 void Set(const String& s);
GetReferenceDlg220 String Get() const { return ~reference; }
221
SerializeReferenceDlg222 void Serialize(Stream& s) { SerializePlacement(s); }
223
224 typedef ReferenceDlg CLASSNAME;
225
226 ReferenceDlg();
227 };
228
229 #define IMAGEFILE <ide/Browser/Topic.iml>
230 #define IMAGECLASS TopicImg
231 #include <Draw/iml_header.h>
232
233 String DecoratedItem(const String& name, const CppItem& m, const char *natural, int pari = INT_MIN);
234
235 int CharFilterID(int c);
236
237 bool ParseTopicFileName(const String& fn, String& topic, int& lang);
238
239 Topic ReadTopic(const char *text);
240 Vector<String> GatherLabels(const RichText& text);
241 String WriteTopic(const char *title, const RichText& text);
242 String WriteTopicI(const char *title, const RichText& text);
243
244 bool LoadTopics(Vector<String>& topics, const String& dir);
245 void FillTopicsList(FileList& list, const Vector<String>& topics);
246
247 TopicLink ParseTopicFilePath(const String& path);
248 String TopicFilePath(const TopicLink& tl);
249
250 void SaveGroupInc(const String& grouppath);
251
252 void SetTopicGroupIncludeable(const char *path, bool set);
253
254 Uuid CodeItemUuid();
255 Uuid StructItemUuid();
256 Uuid BeginUuid();
257 Uuid EndUuid();
258
259 struct StyleDlg;
260
261 template <class T>
262 struct TopicDlg : T {
GetNameTopicDlg263 String GetName() const {
264 return (String)~T::topic + "_" + ToLower(LNGAsText(~T::lang)) + ".tpp";
265 }
266
TopicDlgTopicDlg267 TopicDlg(const char *title) {
268 CtrlLayoutOKCancel(*this, title);
269 T::topic.NotNull();
270 T::topic.MaxLen(30);
271 T::topic.SetFilter(CharFilterID);
272 }
273 };
274
275 class TopicEditor : public IdeDesigner, public Ctrl {
276 public:
277 virtual String GetFileName() const;
278 virtual void Save();
279 virtual void EditMenu(Bar& menu);
DesignerCtrl()280 virtual Ctrl& DesignerCtrl() { return *this; }
281 virtual void SetFocus();
RestoreEditPos()282 virtual void RestoreEditPos() { editor.SetFocus(); }
283
284
285 virtual bool Key(dword key, int);
286
287 protected:
288 ToolBar tool;
289
290 Vector<String> topics;
291 ParentCtrl topics_parent;
292 FileList topics_list;
293 EditString topics_search;
294
295 EditString title;
296 RichEdit editor;
297
298 StaticRect right;
299 Splitter left_right;
300
301 String grouppath;
302 String topicpath;
303 String singlefilepath;
304
305 static String lasttemplate;
306 static int lastlang;
307 static bool allfonts;
308 static int serial;
309
310 struct FileInfo {
311 Time time;
312 RichEdit::UndoInfo undo;
313 RichEdit::PosInfo pos;
314
FileInfoFileInfo315 FileInfo() { time = Time(1, 1, 1); }
316 };
317
318 static VectorMap<String, String> grouptopic;
319 static ArrayMap<String, FileInfo> editstate;
320
321 protected:
322 void FormatMenu(Bar& bar);
323 void TableMenu(Bar& bar);
324 void TopicMenu(Bar& bar);
325 void MainTool(Bar& bar);
326 void FileBar(Bar& bar);
327 void SetBar();
328
329 String GetCurrentTopicPath();
330
331 void InsertNew(const String& coderef);
332 void NewTopic();
333 void MoveTopic();
334 void RemoveTopic();
335
336 bool autosave;
337 ReferenceDlg ref;
338
339 void ShowTopic(bool b = true);
HideTopic()340 void HideTopic() { ShowTopic(false); }
341
342 void TopicCursor();
343
344 void ListTemplates(Vector<String>& path, Vector<String>& name);
345 String ChooseTemplate(const char *title);
346
347 void SaveAsTemplate();
348 void ApplyStylesheet();
349 void ApplyStylesheetGroup();
350
351 void Hyperlink(String&, WString&);
352
353 void Load(const String& path);
354 void SaveTopic();
355 void SaveInc();
356 void Flush();
357
358 void SyncFonts();
359 void AllFonts();
360
361 void Tools(Bar& bar);
362 void Label(String&);
363 void InsertItem();
364
365 void FindBrokenRef();
366 void JumpToDefinition();
367 String GetLang() const;
368
369 void FixTopic();
370
371 void OnSearch();
372 void DoSearch();
373
374 public:
375 Event<Bar&> WhenTemplatesMenu;
376
377 enum {
378 TIMEID_AUTOSAVE = Ctrl::TIMEID_COUNT,
379 TIMEID_COUNT
380 };
381
TopicPage()382 static Size TopicPage() { return Size(3968, INT_MAX); }
383
384 void ExportPdf();
385 void ExportGroupPdf();
386 void ExportHTML();
387 void ExportGroupHTML();
388 void Print();
389
390 typedef TopicEditor CLASSNAME;
391
ShowEditor(bool b)392 void ShowEditor(bool b) { editor.Show(b); }
393 bool NewTopicEx(const String& name, const String& create);
394 void Open(const String& grouppath);
395 void OpenFile(const String& path);
396 void GoTo(const String& topic, const String& link, const String& create, bool before);
PersistentFindReplace(bool b)397 void PersistentFindReplace(bool b) { editor.PersistentFindReplace(b); }
398
399 static int GetSerial();
400
401 static void SerializeEditPos(Stream& s);
402
403 void Serialize(Stream& s);
404
405 TopicEditor();
406 virtual ~TopicEditor();
407 };
408
409 #endif
410