IDE_MT.patch

Razvan Oprea, 02/14/2011 08:09 AM

Download (34.3 KB)

View differences:

Assist.cpp (working copy)
24 24
	assist.NoGrid();
25 25
	assist.AddColumn().Margin(0).SetDisplay(Single<CppItemInfoDisplay>());
26 26
	assist.WhenLeftClick = THISBACK(AssistInsert);
27
	
28
	
29
	files.AutoHideSb(true).NoHeader().NoGrid().AddColumn().Margin(0).SetDisplay(Single<IncludeFileItem::MyDisplay>());
30
	files.SetFrame(BlackFrame()).BackPaint();
31
	files.WhenLeftClick = THISBACK(AssistFileInsert);
32
	mAssistSearchStringConfig = "h;hpp";
33
	mUseIncludeAssist = true;
34
	mWorkerBusy = false;
35
	mIncludePathDepth = 0;
36
	mAssistFrontCharacter = 0;
37
	
38
	
39
	
27 40
	type.NoHeader();
28 41
	type.NoGrid();
29 42
	type.AddColumn();
......
110 123
	return id;
111 124
}
112 125

  
126
inline bool IsSpc(int c)
127
{
128
	return c > 0 && c <= 32;
129
}
130
/**/
131

  
113 132
void AssistEditor::DirtyFrom(int line)
114 133
{
115 134
	if(line >= cachedln) {
......
123 142
int AssistEditor::Ch(int i)
124 143
{
125 144
	if(i >= 0 && i < GetLength()) {
126
		if(i < cachedpos || i - cachedpos > cachedline.GetCount()) {
145
		if(i < cachedpos || i - cachedpos > cachedline.GetCount()) 
146
		{
127 147
			cachedln = GetLine(i);
128 148
			cachedline = GetWLine(cachedln);
129 149
			cachedpos = GetPos(cachedln);
......
149 169
	return max(0, q);
150 170
}
151 171

  
152
bool IsSpc(int c)
153
{
154
	return c > 0 && c <= 32;
155
}
156

  
157 172
void AssistEditor::SkipSpcBack(int& q)
158 173
{
159 174
	while(q > 0 && IsSpc(Ch(q - 1)))
......
285 300

  
286 301
int memcmp_i(const char *s, const char *t, int n)
287 302
{
288
	while(n--) {
303
	while(n--) 
304
	{
289 305
		int q = ToUpper(*s++) - ToUpper(*t++);
290 306
		if(q)
291 307
			return q;
......
299 315
	name = ReadIdBack(GetCursor());
300 316
	assist.Clear();
301 317
	int typei = type.GetCursor() - 1;
302
	for(int p = 0; p < 2; p++) {
318
	
319
	if(typei < 0)
320
	{
303 321
		VectorMap<String, int> over;
304
		for(int i = 0; i < assist_item.GetCount(); i++) {
322
		for(int i = 0; i < assist_item.GetCount(); i++) 
323
		{
305 324
			const CppItemInfo& m = assist_item[i];
325
			if(memcmp_i(name, m.name, name.GetCount()) == 0)
326
			{
327
				int q = over.Find(m.name);
328
				if(m.scope.GetCount() && q < 0)
329
				{
330
					assist.Add(RawToValue(m));
331
					over.Add(m.name);
332
				}
333
			}
334
		}
335
	}
336
	else
337
	{
338
		for(int i = 0; i < assist_item.GetCount(); i++) 
339
		{
340
			const CppItemInfo& m = assist_item[i];
341
			if(	m.typei == typei && (memcmp_i(name, m.name, name.GetCount()) == 0) )
342
			{
343
				if(m.scope.GetCount())
344
					assist.Add(RawToValue(m));
345
			}
346
		}
347
	}
348
	
349
	/*/
350
	for(int p = 0; p < 2; p++) 
351
	{
352
		
353
		VectorMap<String, int> over;
354
		
355
		for(int i = 0; i < assist_item.GetCount(); i++) 
356
		{
357
			const CppItemInfo& m = assist_item[i];
358
			
306 359
			if((typei < 0 || m.typei == typei) &&
307 360
			   (p ? memcmp_i(name, m.name, name.GetCount()) == 0
308 361
			        && memcmp(name, m.name, name.GetCount())
309
			      : memcmp(name, m.name, name.GetCount()) == 0)) {
362
			      : memcmp(name, m.name, name.GetCount()) == 0)) 
363
			      {
310 364
				int q = over.Find(m.name);
311
				if(q < 0 || over[q] == m.typei && m.scope.GetCount()) {
365
				if(q < 0 || over[q] == m.typei && m.scope.GetCount()) 
366
				{
312 367
					assist.Add(RawToValue(m));
313 368
					if(q < 0)
314 369
						over.Add(m.name, m.typei);
......
316 371
			}
317 372
		}
318 373
	}
374
	/**/
319 375
	assist.Sort(0, CppItemInfoOrder);
320 376
}
321 377

  
......
330 386
	assist_cursor = q;
331 387
	assist_type.Clear();
332 388
	assist_item.Clear();
389

  
333 390
	Index<String> in_types;
334 391
	while(iscid(Ch(q - 1)))
335 392
		q--;
336 393
	SkipSpcBack(q);
337 394
	thisback = false;
338
	if(Ch(q - 1) == '(') {
395
	
396
	int Character = Ch(q-1);
397
	
398
	if(Character == '(')
399
	{
339 400
		--q;
340 401
		String id = IdBack(q);
341
		if(id == "THISBACK") {
402
		if(id == "THISBACK") 
403
		{
342 404
			thisback = true;
343 405
			thisbackn = false;
344 406
			GatherItems(parser.current_scope, false, in_types, false);
345 407
			PopUpAssist();
346 408
			return;
347 409
		}
348
		if(id == "THISBACK1" || id == "THISBACK2" || id == "THISBACK3" || id == "THISBACK4") {
410
		if(id == "THISBACK1" || id == "THISBACK2" || id == "THISBACK3" || id == "THISBACK4") 
411
		{
349 412
			thisback = true;
350 413
			thisbackn = true;
351 414
			GatherItems(parser.current_scope, false, in_types, false);
......
353 416
			return;
354 417
		}
355 418
	}
356
	if(Ch(q - 1) == ':') {
419
	else if(Character == ':') 
420
	{
357 421
		while(Ch(q - 1) == ':')
358 422
			q--;
359 423
		Vector<String> tparam;
360 424
		String scope = ParseTemplatedType(Qualify(parser.current_scope, CompleteIdBack(q)), tparam);
361 425
		GatherItems(scope, false, in_types, true);
362 426
	}
363
	else {
427
	else 
428
	{
364 429
		String tp;
365 430
		Vector<String> xp = ReadBack(q);
366 431
		if(xp.GetCount()) {
......
570 635
		}
571 636
	}
572 637
	
573
	if(popup.IsOpen()) {
638
	if(popup.IsOpen()) 
639
	{
574 640
		int k = key & ~K_CTRL;
575 641
		ArrayCtrl& kt = key & K_CTRL ? type : assist;
576 642
		if(k == K_UP || k == K_PAGEUP || k == K_CTRL_PAGEUP || k == K_CTRL_END)
......
587 653
				kt.SetCursor(0);
588 654
				return true;
589 655
			}
590
		if(key == K_ENTER && assist.IsCursor()) {
656
		if(key == K_ENTER && assist.IsCursor()) 
657
		{
591 658
			AssistInsert();
592 659
			return true;
593 660
		}
594
		if(key == K_TAB && !assist.IsCursor() && assist.GetCount()) {
661
		if(key == K_TAB && !assist.IsCursor() && assist.GetCount()) 
662
		{
595 663
			assist.GoBegin();
596 664
			AssistInsert();
597 665
			return true;
598 666
		}
599 667
	}
668
	else if(files.IsOpen())
669
	{
670
		int k = key & ~K_CTRL;
671
		if(k == K_UP || k == K_PAGEUP || k == K_CTRL_PAGEUP || k == K_CTRL_END)
672
			if(files.IsCursor())
673
				return files.Key(k, count);
674
			else {
675
				files.SetCursor(files.GetCount() - 1);
676
				return true;
677
			}
678
		if(k == K_DOWN || k == K_PAGEDOWN || k == K_CTRL_PAGEDOWN || k == K_CTRL_HOME)
679
			if(files.IsCursor())
680
				return files.Key(k, count);
681
			else {
682
				files.SetCursor(0);
683
				return true;
684
			}
685
		if(files.IsCursor())
686
		{
687
			if(key == K_ENTER)
688
			{
689
				AssistFileInsert();
690
				return true;
691
			}
692
		}
693
		else if(key == K_TAB && files.GetCount())
694
		{
695
			files.GoBegin();
696
			AssistFileInsert();
697
			return true;
698
		}
699
		else if(key == '/')
700
		{
701
			if(AssistFileManualInsert())
702
				return true;
703
		}
704
	}
705
	
600 706
	int c = GetCursor();
601 707
	int cc = GetChar(c);
602 708
	int bcc = c > 0 ? GetChar(c - 1) : 0;
603 709
	bool b = CodeEditor::Key(key, count);
604
	if(assist.IsOpen()) {
710
	
711
	if(assist.IsOpen()) 
712
	{
605 713
		if(!iscid(key) &&
606 714
		   !(iscid(cc) && (key == K_DELETE || key == K_RIGHT)) &&
607
		   !(iscid(bcc) && (key == K_LEFT || key == K_BACKSPACE))) {
608
			if(b) {
715
		   !(iscid(bcc) && (key == K_LEFT || key == K_BACKSPACE))) 
716
		   {
717
			if(b) 
718
			{
609 719
				CloseAssist();
610 720
				if(key == '.')
611 721
					Assist();
......
614 724
		else
615 725
			SyncAssist();
616 726
	}
617
	else
618
	if(auto_assist && InCode()) {
619
		if(key == '.' || key == '>' && Ch(GetCursor() - 2) == '-' ||
620
		   key == ':' && Ch(GetCursor() - 2) == ':')
727
	else if(files.IsOpen())
728
	{
729
		if(!(iscid(key) || key == '.' || key == '/' || (key == K_DELETE || key == K_RIGHT) || (bcc != '<' && bcc != '"' && (key == K_LEFT || key == K_BACKSPACE)) ))
730
		{
731
			if(b) 
732
				CloseFiles();
733
		}
734
		else if(mWorkerBusy == false && key != '/')
735
		{
736
			HandleIncludePopup();
737
		}
738
	}
739
	else if((key == '"' || key == '<') && IsIncludeAssistAvailable())
740
	{
741
		if(IncludeAssist())
742
			return true;
743
	}
744
	if(auto_assist && InCode()) 
745
	{
746
		int CH = Ch(GetCursor() - 2);
747
		if(key == '.' || (key == '>' && CH == '-') ||
748
		   (key == ':' && CH == ':')
749
		   )
621 750
			Assist();
622
		else
623
		if(key == '(') {
751
		else if(key == '(') 
752
		{
624 753
			int q = GetCursor() - 1;
625 754
			String id = IdBack(q);
626 755
			if(id == "THISBACK" || id == "THISBACK1" || id == "THISBACK2" || id == "THISBACK3" || id == "THISBACK4")
......
630 759
	return b;
631 760
}
632 761

  
762

  
633 763
void AssistEditor::MouseWheel(Point p, int zdelta, dword keyflags)
634 764
{
635 765
	if(keyflags & K_CTRL)
......
650 780
void AssistEditor::LostFocus()
651 781
{
652 782
	CloseAssist();
783
	if(files.IsOpen())
784
		CloseFiles();
653 785
}
654 786

  
655 787
String AssistEditor::RemoveDefPar(const char *s)
656 788
{
789
	
657 790
	String r;
658 791
	int lvl = 0;
659 792
	bool dp = true;
......
850 983
	return GetIdScope(os, scope, id, done);
851 984
}
852 985

  
853
bool IsPif(const String& l)
986
inline bool IsPif(const String& l)
854 987
{
855 988
	return l.Find("#if") >= 0;
856 989
}
857 990

  
858
bool IsPelse(const String& l)
991
inline bool IsPelse(const String& l)
859 992
{
860 993
	return l.Find("#el") >= 0;
861 994
}
862 995

  
863
bool IsPendif(const String& l)
996
inline bool IsPendif(const String& l)
864 997
{
865 998
	return l.Find("#endif") >= 0;
866 999
}
......
1084 1217
bool AssistEditor::Esc()
1085 1218
{
1086 1219
	bool r = false;
1087
	if(assist.IsOpen()) {
1220
	if(assist.IsOpen()) 
1221
	{
1088 1222
		CloseAssist();
1089 1223
		r = true;
1090 1224
	}
1225
	else if(files.IsOpen())
1226
	{
1227
		CloseFiles();
1228
		r = true;
1229
	}
1091 1230
	if(param_info.IsOpen()) {
1092 1231
		for(int i = 0; i < PARAMN; i++)
1093 1232
			param[i].line = -1;
Browser/Browser.h (working copy)
112 112
	CppItemInfoDisplay() { namestart = false; showtopic = false; }
113 113
};
114 114

  
115
class IncludeFileDisplayClass;
116
struct IncludeFileItem : Moveable<IncludeFileItem> 
117
{
118
	int 			Type;
119
	String 			name;
120
	String			fullPath;
121
				
122
	inline IncludeFileItem(const String & nm,const String& Path,int tp):Type(tp),name(nm),fullPath(Path)
123
	{
124
	}
125
	IncludeFileItem();
126
	IncludeFileItem(const char *);
127
	
128
	inline bool IsFile()const { return (Type > 0); }
129
	inline bool IsFolder()const { return (Type == 0); }
130
	inline bool IsRefreshSymbol()const { return (Type == -1); }
131
	inline bool IsValid()const { return (Type>=0); }
132
	typedef IncludeFileDisplayClass MyDisplay;
133
	
134
	static IncludeFileItem& GetLoadingItem();
135
	static IncludeFileItem& GetEmptyItem();
136
	static IncludeFileItem&	GetInvalidItem();
137
	
138
	static int CompareForArrayCtrl(const Value& va,const Value& vb);
139
};
140

  
141
class IncludeFileDisplayClass : public Display
142
{
143
public:
144
	virtual void Paint0(Draw& draw, const Rect& rc, const Value& v, Color ink, Color paper, dword style) const;
145
	virtual void Paint(Draw& draw, const Rect& rc, const Value& v, Color ink, Color paper, dword style) const;
146
	virtual Size GetStdSize(const Value& q) const;
147
};
148

  
115 149
int SearchItemFilter(int c);
116 150

  
117 151
struct CodeBrowser {
Browser/ItemDisplay.cpp (working copy)
189 189
	            max(16, BrowserFont().Info().GetHeight()));
190 190
}
191 191

  
192

  
193
void IncludeFileDisplayClass::Paint0(Draw& w, const Rect& r, const Value& q,
194
                             Color ink, Color paper, dword s) const
195
{
196
	WString txt;
197
	Font font = StdFont();
198
	int x = r.left+3;
199
	int y = r.top;
200
	int width = r.GetWidth();
201
	
202
	const IncludeFileItem& t = ValueTo<IncludeFileItem>(q);
203
	txt = t.name.ToWString();
204
	if(t.IsFile()) 
205
	{
206
		//const Image & img = BrowserImg::IncludeFile();
207
		const Image & img = CtrlImg::File();
208
		Size isz = img.GetSize();
209
		w.DrawImage(x, y + max((r.Height() - isz.cy) / 2, 0), img);
210
		x += isz.cx + 4;
211
	}
212
	else if(t.IsFolder())
213
	{
214
		//const Image & img = BrowserImg::IncludeFolder();
215
		const Image & img = CtrlImg::Dir();		
216
		Size isz = img.GetSize();
217
		w.DrawImage(x, y + max((r.Height() - isz.cy) / 2, 0), img);
218
		x += isz.cx + 4;
219
	}
220
	else if(t.IsRefreshSymbol())
221
	{
222
		//refresh symbol
223
		//const Image & img = BrowserImg::IncludeRefresh();
224
		const Image & img = CtrlImg::Toggle();
225
		Size isz = img.GetSize();
226
		w.DrawImage(x, y + max((r.Height() - isz.cy) / 2, 0), img);
227
		x += isz.cx + 4;
228
	}
229
	else
230
	{
231
		const Image & img = CtrlImg::Remove();
232
		Size isz = img.GetSize();
233
		w.DrawImage(x, y + max((r.Height() - isz.cy) / 2, 0), img);
234
		x += isz.cx + 4;
235
	}
236
	
237
	int tcy = GetTLTextHeight(txt, font);
238
	int tt = y + max((r.Height() - tcy) / 2, 0);
239
	DrawTLText(w, x, tt, width, txt, font, ink);/**/
240
}
241
void IncludeFileDisplayClass::Paint(Draw& w, const Rect& r, const Value& q,
242
                    Color ink, Color paper, dword s) const
243
{
244
	PaintBackground(w, r, q, ink, paper, s);
245
	Paint0(w, r, q, ink, paper, s);
246
}
247
Size IncludeFileDisplayClass::GetStdSize(const Value& q) const
248
{
249
	Font font = StdFont();
250
	WString txt;
251
	Size isz(0, 0);
252
	
253
	const IncludeFileItem& t = ValueTo<IncludeFileItem>(q);
254
	
255
	txt = t.name.ToWString();
256
	isz = CtrlImg::Dir().GetSize();
257
	
258
	isz.cx += 4;//t.imgspc
259
	
260
	Size sz = GetTLTextSize(txt, font);
261
	
262
	return Size(sz.cx + isz.cx, max(sz.cy, isz.cy));
263
}
264

  
Browser/Util.cpp (working copy)
1
#include "Browser.h"
2

  
3
void SplitCodeRef(const String& s, String& scope, String& item)
4
{
5
	int q = s.FindFirstOf("( ");
6
	q = q >= 0 ? s.ReverseFind(':', q) : s.ReverseFind(':');
7
	if(q < 0) {
8
		scope.Clear();
9
		item = s;
10
	}
11
	else {
12
		scope = s.Mid(0, max(q - 1, 0));
13
		item = s.Mid(q + 1);
14
	}
15
}
16

  
17
String MakeCodeRef(const String& nest, const String& item)
18
{
19
	if(nest.GetCount())
20
		return nest + "::" + item;
21
	return item;
22
}
23

  
24
int GetMatchLen(const char *s, const char *t)
25
{
26
	int i = 0;
27
	while(s[i] == t[i] && s[i])
28
		i++;
29
	return i;
30
}
31

  
32
const CppItem *GetCodeRefItem(const String& ref, const String& rfile)
33
{
34
	String scope;
35
	String item;
36
	SplitCodeRef(ref, scope, item);
37
	int q = CodeBase().Find(scope);
38
	if(q < 0)
39
		return NULL;
40
	const Array<CppItem>& n = CodeBase()[q];
41
	q = FindItem(n, item);
42
	if(q < 0)
43
		return NULL;
44
	if(!IsNull(rfile)) {
45
		int i = q;
46
		int qml = 0;
47
		while(i < n.GetCount() && n[i].qitem == item) {
48
			int ml = GetMatchLen(GetCppFile(n[i].file), rfile);
49
			if(ml > qml) {
50
				q = i;
51
				qml = ml;
52
			}
53
			i++;
54
		}
55
	}
56
	return &n[q];
57
}
58

  
59
const CppItem *GetCodeRefItem(const String& ref)
60
{
61
	return GetCodeRefItem(ref, Null);
62
}
1
#include "Browser.h"
2

  
3

  
4
void SplitCodeRef(const String& s, String& scope, String& item)
5
{
6
	int q = s.FindFirstOf("( ");
7
	q = q >= 0 ? s.ReverseFind(':', q) : s.ReverseFind(':');
8
	if(q < 0) {
9
		scope.Clear();
10
		item = s;
11
	}
12
	else {
13
		scope = s.Mid(0, max(q - 1, 0));
14
		item = s.Mid(q + 1);
15
	}
16
}
17

  
18
String MakeCodeRef(const String& nest, const String& item)
19
{
20
	if(nest.GetCount())
21
		return nest + "::" + item;
22
	return item;
23
}
24

  
25
int GetMatchLen(const char *s, const char *t)
26
{
27
	int i = 0;
28
	while(s[i] == t[i] && s[i])
29
		i++;
30
	return i;
31
}
32

  
33
const CppItem *GetCodeRefItem(const String& ref, const String& rfile)
34
{
35
	String scope;
36
	String item;
37
	SplitCodeRef(ref, scope, item);
38
	int q = CodeBase().Find(scope);
39
	if(q < 0)
40
		return NULL;
41
	const Array<CppItem>& n = CodeBase()[q];
42
	q = FindItem(n, item);
43
	if(q < 0)
44
		return NULL;
45
	if(!IsNull(rfile)) {
46
		int i = q;
47
		int qml = 0;
48
		while(i < n.GetCount() && n[i].qitem == item) {
49
			int ml = GetMatchLen(GetCppFile(n[i].file), rfile);
50
			if(ml > qml) {
51
				q = i;
52
				qml = ml;
53
			}
54
			i++;
55
		}
56
	}
57
	return &n[q];
58
}
59

  
60
const CppItem *GetCodeRefItem(const String& ref)
61
{
62
	return GetCodeRefItem(ref, Null);
63
}
64

  
65
IncludeFileItem::IncludeFileItem():Type(-1),name("Loading...")
66
{
67
}
68
IncludeFileItem::IncludeFileItem(const char * text):Type(-2),name(text)
69
{
70
}
71
IncludeFileItem& IncludeFileItem::GetLoadingItem()
72
{
73
	static IncludeFileItem item;
74
	return item;
75
}
76
IncludeFileItem& IncludeFileItem::GetEmptyItem()
77
{
78
	static IncludeFileItem item("No files.");
79
	return item;
80
}
81
IncludeFileItem& IncludeFileItem::GetInvalidItem()
82
{
83
	static IncludeFileItem item("Invalid path!");
84
	return item;
85
}
86

  
87
int IncludeFileItem::CompareForArrayCtrl(const Value& va,const Value& vb)
88
{
89
	const IncludeFileItem& a = ValueTo<IncludeFileItem>(va);
90
	const IncludeFileItem& b = ValueTo<IncludeFileItem>(vb);
91
	return a.name.Compare(b.name);
92
}
93
                                                
ide.h (working copy)
329 329
	int            cachedpos;
330 330
	int            cachedln;
331 331
	
332
	
333
	//----------------------------------------------
334
	ArrayCtrl					files;//control to display the include assist
335
	Array<IncludeFileItem>		mMainIncludeFiles;//will hold all the files from VC Include directories + all files/folders from the current assembly
336
	Array<IncludeFileItem>		mTempIncludeFiles;//temporarely hold some scanned filed depending on context
337
	Vector<String> 				mIncludeSearchExtTypes;	
338
	Vector<String>				mIncludePathStack;
339

  
340
	int							mIncludePathDepth;	
341
	
342
	String						mFolderNameStringCache;
343
	String						mCurentBuildMethod;//keeps the build method saved in order to check for changes
344
	bool						mWorkerBusy;//scanning some files in the background?
345
	int							mAssistFrontCharacter;//stores the character with which include assist was started
346
	
347
	bool						mUseIncludeAssist;
348
	String						mAssistSearchStringConfig;
349
	//----------------------------------------------
350
	
351
	
332 352
	RichTextCtrl   param_info;
333 353
	String         param_qtf;
334 354
	struct ParamInfo {
......
344 364
	ParamInfo param[PARAMN];
345 365
	int       parami;
346 366
	
367
	
368
	//----------------------------------------------
369
	void			PopUpFiles();
370
	void			ShapeFilesPopup();
371
	void 			CloseFiles();
372
	void 			SyncFiles();
373
	void			InsertFiles(bool get_local);
374
	bool 			IncludeAssist();//returnes true if file assist was opened
375
	
376
	void			ScanFrontFiles();
377
	void			ScanLocalFiles();
378
	void			NotifyScanFinish();
379
	bool			AssistFileManualInsert();
380
	void 			AssistFileInsert();
381
	int 			ReadPathBack(int q);//returnes true if has the character < or " in front
382
	bool			ComposeSearchPath();
383
	bool			UpdateFileSync(int count);
384
	void			HandleIncludePopup();
385
	void			InclLocateFolderPath(int &left,int &right);
386
	void 			InsertInvalidPath();
387
	bool			IsBuildMethodChanged()const;
388
	bool			IsIncludeAssistAvailable()const;
389
	void			NotifyIncludeConfigChange();
390
	//----------------------------------------------
391
	
347 392
	void           PopUpAssist(bool auto_insert = false);
348 393
	void           CloseAssist();
349 394
	void           Assist();
......
610 655
	String    recent_stdout_file;
611 656

  
612 657
// ------------------------------------
613

  
658
	CoWork		mWork;
659
// ------------------------------------
614 660
	One<Debugger> debugger;
615 661

  
616 662
	Time      start_time;
ide.lay (working copy)
442 442
	ITEM(Option, tabs_serialize, SetLabel(t_("Persistent tabs")).LeftPosZ(272, 108).TopPosZ(108, 16))
443 443
END_LAYOUT
444 444

  
445
LAYOUT(SetupAssistLayout, 520, 124)
446
	ITEM(Option, assist, SetLabel(t_("Automatic assist")).HSizePosZ(4, 280).TopPosZ(4, 16))
445
LAYOUT(SetupAssistLayout, 440, 124)
446
	ITEM(Option, assist, SetLabel(t_("Automatic assist")).HSizePosZ(4, 200).TopPosZ(4, 16))
447 447
	ITEM(Option, commentdp, SetLabel(t_("Comment out default parameters")).Tip(t_("Comment out default parameters when converting declaration to definition instead of removing them")).LeftPosZ(4, 236).TopPosZ(24, 16))
448 448
	ITEM(Option, auto_enclose, SetLabel(t_("[ { ( \" / * enclose selection")).LeftPosZ(4, 236).TopPosZ(44, 16))
449 449
	ITEM(Option, mark_lines, SetLabel(t_("Mark lines with errors, warning and changes")).LeftPosZ(4, 236).TopPosZ(64, 16))
450 450
	ITEM(Option, barline, SetLabel(t_("Highlight line in the left bar")).LeftPosZ(4, 236).TopPosZ(84, 16))
451 451
	ITEM(Option, qtfsel, SetLabel(t_("QTF designer edits selection")).LeftPosZ(4, 236).TopPosZ(104, 16))
452 452
	ITEM(Option, header_guards, SetLabel(t_("Insert guards to new headers")).LeftPosZ(272, 164).TopPosZ(4, 16))
453
	ITEM(Switch, insert_include, SetLabel(t_("No #include in new sources\n#include first\n#include previous")).LeftPosZ(272, 156).TopPosZ(24, 52))
453
	ITEM(Option, use_assist, SetLabel(t_("Start Assist for #include")).Tip(t_("In c/c++ code the assist will popup when needed showing you the files you can include.")).LeftPosZ(272, 164).TopPosZ(80, 16))
454
	ITEM(Switch, insert_include, SetLabel(t_("No #include in new sources\n#include first\n#include previous")).LeftPosZ(272, 164).TopPosZ(24, 52))
455
	ITEM(EditString, include_assist_headers, Tip(t_("The extensions of the files to search for will be specified here separated by ';'")).LeftPosZ(272, 164).TopPosZ(100, 19))
454 456
END_LAYOUT
455 457

  
456 458
LAYOUT(SetupIdeLayout, 512, 264)
ide.upp (working copy)
40 40
	Bottom.cpp,
41 41
	t.cpp,
42 42
	Cpp.cpp,
43
	IncludeAssist.cpp,
43 44
	Assist.cpp,
44 45
	ParamInfo.cpp,
45 46
	Navigator.cpp,
......
83 84
	Copying;
84 85

  
85 86
mainconfig
86
	"" = "GUI",
87
	"" = "GUI MT",
87 88
	"" = "GUI .USEMALLOC",
88 89
	"" = ".NOGTK GUI",
89 90
	"" = "GUI HEAPDBG CHECKINIT",
idewin.cpp (working copy)
79 79
	}
80 80
}
81 81

  
82
void Ide::Serialize(Stream& s) {
83
	int version = 18;
82
void Ide::Serialize(Stream& s) 
83
{
84
	int version = 19;
84 85
	s.Magic(0x1234);
85 86
	s / version;
86 87
	s % main;
......
101 102
	s % font2;
102 103
	s % show_status_bar;
103 104
	s % toolbar_in_row;
105
	
106
	if(version >= 19)
107
	{
108
		s % editor.mUseIncludeAssist;
109
		s % editor.mAssistSearchStringConfig;
110
		/*if(s.IsLoading())
111
			editor.NotifyIncludeConfigChange();/**/
112
	}
104 113
	if(version >= 18) {
105 114
		s % filetabs;
106 115
	}
......
1015 1024
		ide.editor_bottom.Zoom(0);
1016 1025
		ide.right_split.Zoom(0);
1017 1026
		ide.UpdateFormat();
1027
		ide.editor.NotifyIncludeConfigChange();
1028
		
1018 1029
		RestoreKeys(LoadFile(ConfigFile("ide.key")));
1019 1030
		ide.editor.LoadHlStyles(LoadFile(ConfigFile("ide.colors")));
1020 1031
		if(FileExists(ConfigFile("developide"))) {
IncludeAssist.cpp (revision 0)
1
#include "ide.h"
2

  
3

  
4
int memcmp_i(const char *s, const char *t, int n);
5
bool IsFolderChar(int c)
6
{
7
	//need all of them???
8
	return (iscid(c) || (c == '!')|| (c == '@')|| (c == '#')|| (c == '$')|| (c == '%')|| (c == '^')|| (c == '&')|| (c == '(')|| (c == ')')|| (c == '_')
9
	|| (c == '-')|| (c == '+')|| (c == '=')|| (c == ',')|| (c == '.')|| (c == '`')|| (c == '~'));
10
	//posix folders have even more characters
11
}
12
inline bool IsSpc0(int c)
13
{
14
	return c > 0 && c <= 32;
15
}
16
bool AssistEditor::IsIncludeAssistAvailable()const
17
{
18
	return mUseIncludeAssist;
19
}
20
int AssistEditor::ReadPathBack(int q)
21
{
22
	int ch;
23
	int ids = q;
24
	int len;
25
	int depth = 0;
26
#ifdef PLATFORM_WIN32
27
	int depth2 = 0;
28
#endif
29
	if(ids > 0)
30
	{
31
		ch = GetChar(ids - 1);
32
		if(IsSpc0(ch))
33
			return -1;
34
		while(ids > 0 && IsFolderChar(ch))
35
		{
36
			ids--;
37
			ch = GetChar(ids - 1);
38
		}
39
		len = q - ids;
40
#ifdef PLATFORM_WIN32
41
		while(ids > 0 && (IsFolderChar(ch) || ch == '/' || ch == '.' || ch == '\\'))
42
#else
43
		while(ids > 0 && (IsFolderChar(ch) || ch == '/' || ch == '.'))
44
#endif
45
		{
46
			depth += (int)(ch == '/');
47
#ifdef PLATFORM_WIN32
48
			depth2 += (int)(ch == '\\');
49
#endif	
50

  
51
			ids--;
52
			ch = GetChar(ids - 1);
53
		}
54
		if(!((ch == '<') || (ch == '"')))
55
			return -1;
56
	}
57
	else 
58
		return -1;
59
	mFolderNameStringCache.Clear();
60
	while(len!=0 && len < GetLength())
61
	{
62
		ch = GetChar(q-len);
63
		//path << (char)ch;
64
		mFolderNameStringCache << (char)ch;
65
		len--;
66
	}
67
#ifdef PLATFORM_WIN32
68
	return depth + depth2/2;//will this work??
69
#else
70
	return depth;
71
#endif
72
}
73

  
74
bool AssistEditor::IncludeAssist()
75
{
76
	CloseFiles();
77
	
78
	int q = GetCursor();
79
	int Character = Ch(q-1);
80
	
81
	if(Character == '"' || Character == '<')//this check should not happen
82
	{
83
		--q;
84
		SkipSpcBack(q);
85
		String id = IdBack(q);
86
		
87
		//if(id == "include")
88
		if(memcmp_i(id,"include",id.GetCount()) == 0)
89
		{
90
			mAssistFrontCharacter = Character;
91
			if(mWorkerBusy == false)
92
			{
93
				
94
				InsertFiles(Character == '"');
95
				PopUpFiles();
96
				return true;
97
			}
98
		}
99
	}
100
	return false;
101
}
102

  
103
void			AssistEditor::NotifyIncludeConfigChange()
104
{
105
	Vector<String> local = Split(mAssistSearchStringConfig,";");
106

  
107
	mIncludeSearchExtTypes.Clear();
108
	mIncludeSearchExtTypes.Reserve(local.GetCount()+1);
109
	mIncludeSearchExtTypes.Add("*");//add the folder
110
	String tmp = "*.";
111
	for(int i = 0; i < local.GetCount(); i++)
112
	{
113
		if(local[i].GetCount() != 0)
114
			mIncludeSearchExtTypes.Add(tmp+local[i]);
115
	}
116
	mCurentBuildMethod.Clear();
117
}
118

  
119
void			AssistEditor::ShapeFilesPopup()
120
{
121
	int lcy = max(16, BrowserFont().Info().GetHeight());
122
	int cy;
123
	
124
	if(files.GetCount() > 0)
125
		cy = lcy * min(16,(files.GetCount()-1)) + HeaderCtrl::GetStdHeight() + 4;
126
	else
127
		cy = 4 + HeaderCtrl::GetStdHeight() ;
128

  
129
	files.SetLineCy(lcy);
130
	
131
	Point p = GetCaretPoint() + GetScreenView().TopLeft();
132
	Rect wa = GetWorkArea();
133
	int cx = min(wa.Width() - 100, HorzLayoutZoom(250));
134
	
135
	if(p.x + cx > wa.right)
136
		p.x = wa.right - cx;
137
	if(p.y + cy + GetFontSize().cy < wa.bottom)
138
		files.SetRect(p.x, p.y + GetFontSize().cy, cx, cy);
139
	else
140
		files.SetRect(p.x, p.y - cy, cx, cy);
141
}
142
void			AssistEditor::PopUpFiles()
143
{
144
	ShapeFilesPopup();
145
	files.Ctrl::PopUp(this, false, false, true);
146
}
147
bool AssistEditor::UpdateFileSync(int count)
148
{
149
	if(count == 0)
150
	{
151
		mIncludePathDepth = 0;
152
		mIncludePathStack.Clear();
153
		if(mAssistFrontCharacter == '"')
154
		{
155
			mWorkerBusy = true;
156
			files.Clear();
157
			files.Add(RawToValue(IncludeFileItem::GetLoadingItem()));
158
			mIncludePathStack.Add(GetFileDirectory(theide->editfile));
159
			theide->mWork.Do(THISBACK(ScanLocalFiles));
160
		}
161
		else if(IsBuildMethodChanged())
162
		{
163
			mWorkerBusy = true;
164
			files.Clear();
165
			files.Add(RawToValue(IncludeFileItem::GetLoadingItem()));
166
			mCurentBuildMethod = theide->method;
167
			mIncludePathStack.Clear();
168
			theide->mWork.Do(THISBACK(ScanFrontFiles));
169
		}
170
		else
171
			return true;
172
	}
173
	else
174
	{
175
		if(count < mIncludePathDepth)
176
		{
177
			while(mIncludePathDepth != count)
178
			{
179
				mIncludePathStack.Pop();
180
				mIncludePathDepth--;
181
			}
182
		}
183
		else
184
		{
185
			//...u lalalaaa
186
		}
187
		mWorkerBusy = true;
188
		theide->mWork.Do(THISBACK(ScanLocalFiles));
189
	}
190
	return false;
191
}
192
void AssistEditor::InclLocateFolderPath(int &left,int &right)
193
{
194
	while(left > 0 && IsFolderChar(Ch(left-1)))
195
		left--;
196
	if(right<GetLength())
197
	{
198
		int temp = Ch(right);
199
#ifdef PLATFORM_WIN32
200
		while(right < GetLength() && (IsFolderChar(temp) || temp == '/' || temp == '\\'))
201
#else
202
		while(right < GetLength() && (IsFolderChar(temp) || temp == '/'))
203
#endif
204
			temp = Ch(++right);
205
	}
206
}
207
bool AssistEditor::IsBuildMethodChanged()const
208
{
209
	return (mCurentBuildMethod != theide->method);
210
}
211
bool AssistEditor::AssistFileManualInsert()
212
{
213
	if(mFolderNameStringCache == "..")
214
	{
215
		if(mIncludePathStack.GetCount() == 0)
216
		{
217
			mTempIncludeFiles.Clear();
218
			InsertInvalidPath();
219
		}
220
		else
221
		{
222
			String new_path = mIncludePathStack.Top();
223
#ifdef PLATFORM_WIN32
224
			if(new_path.GetLength() <= 3)
225
#else
226
			if(new_path == "/" || new_path.GetCount()<=1)
227
#endif
228
			{
229
				//invalid Path
230
				mTempIncludeFiles.Clear();
231
				InsertInvalidPath();
232
			}
233
			else
234
			{
235
				mIncludePathDepth++;
236
				new_path.Trim(new_path.GetLength()-1);
237
				new_path = GetFileDirectory(new_path);
238
				mIncludePathStack.Add(new_path);
239
				mWorkerBusy = true;
240
				theide->mWork.Do(THISBACK(ScanLocalFiles));
241
			}
242
		}
243
		return false;
244
	}
245
	
246
	int cursor_pos = GetCursor();
247
	int cursor_aux_pos = cursor_pos;
248
	String txt;
249
	Array<IncludeFileItem> & touse = (mIncludePathDepth==0 && mAssistFrontCharacter == '<') ? mMainIncludeFiles : mTempIncludeFiles;
250
	int found_index = -1;
251
	
252
	//find best fit for the name
253
	for(int i = 0; i < touse.GetCount(); i++) 
254
	{
255
		const IncludeFileItem & item = touse[i];
256
		if(!item.IsFolder())
257
			continue;
258
		if(mFolderNameStringCache == item.name)//exact fit
259
		{
260
			mIncludePathDepth++;
261
			mIncludePathStack.Add(AppendFileName(item.fullPath,item.name+"/"));
262
			mWorkerBusy = true;
263
			theide->mWork.Do(THISBACK(ScanLocalFiles));
264
			return false;
265
		}
266
		else if(memcmp_i(item.name,mFolderNameStringCache,item.name.GetCount()) == 0)
267
			found_index = i;
268
	}
269
	if(found_index != -1)
270
	{
271
		const IncludeFileItem & item = touse[found_index];
272
		txt = item.name;
273
		InclLocateFolderPath(cursor_pos,cursor_aux_pos);
274
		
275
		Remove(cursor_pos, cursor_aux_pos - cursor_pos);
276
		SetCursor(cursor_pos);
277
		
278
		mIncludePathDepth++;
279
		txt+="/";
280
		Paste(ToUnicode(txt, CHARSET_WIN1250));
281

  
282
		mIncludePathStack.Add(AppendFileName(item.fullPath,txt));
283
		mWorkerBusy = true;
284
		theide->mWork.Do(THISBACK(ScanLocalFiles));
285
		
286
		return true;
287
	}
288
	else
289
	{
290
		InsertInvalidPath();
291
		return false;
292
	}
293
}
294
void AssistEditor::AssistFileInsert()
295
{
296
	if(mWorkerBusy)
297
		return;
298
	
299
	String txt;
300
	
301
	int cursor_pos = GetCursor();
302
	int cursor_aux_pos = cursor_pos;
303
	int depth = 0;
304
	
305
	const IncludeFileItem& item = ValueTo<IncludeFileItem>(files.Get(0));
306
	if(!item.IsValid())
307
		return;
308
	
309
	txt = item.name;
310
	InclLocateFolderPath(cursor_pos,cursor_aux_pos);
311
	
312
	Remove(cursor_pos, cursor_aux_pos - cursor_pos);
313
	SetCursor(cursor_pos);
314
		
315
	if(item.IsFile())
316
	{
317
		if(mAssistFrontCharacter == '"')
318
			txt+="\"";
319
		else if(mAssistFrontCharacter == '<')
320
			txt+=">";
321
			
322
		Paste(ToUnicode(txt, CHARSET_WIN1250));
323
		CloseFiles();
324
		IgnoreMouseUp();
325
	}
326
	else
327
	{
328
		mIncludePathDepth++;
329
		txt+="/";
330
		Paste(ToUnicode(txt, CHARSET_WIN1250));
331

  
332
		mIncludePathStack.Add(AppendFileName(item.fullPath,txt));
333
		mWorkerBusy = true;
334
		theide->mWork.Do(THISBACK(ScanLocalFiles));
335
	}
336
}
337
void AssistEditor::InsertInvalidPath()
338
{
339
	mIncludePathDepth++;
340
	mIncludePathStack.Add();
341
	files.Clear();
342
	files.Add(RawToValue(IncludeFileItem::GetInvalidItem()));
343
	ShapeFilesPopup();
344
}
345
void AssistEditor::NotifyScanFinish()
346
{
347
	if(files.IsOpen())//still opened then use 
348
	{
349
		int Count = (mIncludePathDepth==0 && mAssistFrontCharacter == '<') ? mMainIncludeFiles.GetCount() : mTempIncludeFiles.GetCount();
350

  
351
		files.Clear();
352
		if(Count == 0)
353
		{
354
			files.Add(RawToValue(IncludeFileItem::GetEmptyItem()));
355
			ShapeFilesPopup();
356
		}
357
		else
358
		{
359
			int rezult = ReadPathBack(GetCursor());
360
			if(rezult != -1)
361
			{
362
				if(rezult != mIncludePathDepth)
363
				{
364
					if(UpdateFileSync(rezult))
365
					{
366
						SyncFiles();
367
						ShapeFilesPopup();
368
					}
369
				}
370
				else
371
				{
372
					SyncFiles();
373
					ShapeFilesPopup();
374
				}
375
			}
376
			else
377
				CloseFiles();
378
		}
379
	}
380
	mWorkerBusy = false;
381
}
382
void AssistEditor::HandleIncludePopup()
383
{
384
	int rezult = ReadPathBack(GetCursor());
385
	if(rezult != -1)
386
	{
387
		if(rezult != mIncludePathDepth)
388
		{
389
			if(UpdateFileSync(rezult))
390
			{
391
				SyncFiles();
392
				ShapeFilesPopup();
393
			}
394
		}
395
		else 
396
		{
397
			SyncFiles();
398
			ShapeFilesPopup();
399
		}
400
	}
401
	else
402
		CloseFiles();
403
}
404
#ifdef PLATFORM_LINUX
405
void GCC_HARDWIRE_INCLUDE_HACK(Vector<String> & l)
406
{
407
	String a = "/usr/include";
408
	String b = "/usr/local/include";
409
	
410
	bool oka = true;
411
	bool okb = true;
412
	for(int i = 0; i < l.GetCount(); i++)
413
	{
414
		String s = NativePath(l[i]);
415
		if(s == a)
416
			oka = false;
417
		else if(s == b)
418
			okb = false;
419
	}
420
	if(oka)
421
		l.Add(a);
422
	if(okb)
423
		l.Add(b);
424
}
425
#endif
426

  
427
void AssistEditor::ScanFrontFiles()
428
{
429
	VectorMap<String, String> BuildMethodMap = GetMethodVars(theide->method);
430
	Vector<String> SearchPaths = SplitDirs(GetVar("UPP") + ';' + BuildMethodMap.Get("INCLUDE", ""));
431
	
432
#ifdef PLATFORM_WIN32
433
	const char * intermediate = "\\";
434
#else
435

  
436
#ifdef PLATFORM_LINUX
437
	GCC_HARDWIRE_INCLUDE_HACK(SearchPaths);
438
#endif
439
	const char * intermediate = "/";
440

  
441
#endif
442

  
443
	mMainIncludeFiles.Clear();
444
	for(int i = 0; i < SearchPaths.GetCount(); i++)
445
		for(int j = 0; j < mIncludeSearchExtTypes.GetCount(); j++)
446
			for(FindFile ff(SearchPaths[i] + intermediate + mIncludeSearchExtTypes[j]);ff;ff.Next())
447
				if(ff.IsFolder() || (ff.IsFile() && j != 0))
448
					mMainIncludeFiles.Add(IncludeFileItem(ff.GetName(),SearchPaths[i],j));
449
	Call(THISBACK(NotifyScanFinish));
450
}
451

  
452
void AssistEditor::ScanLocalFiles()
453
{
454
	const String &top = mIncludePathStack.Top();
455
	mTempIncludeFiles.Clear();
456
	if(top.GetCount()!=0)
457
	{
458
		String search_path = NativePath(top);
459
		for(int i = 0; i < mIncludeSearchExtTypes.GetCount(); i++)
460
			for(FindFile ff(search_path + mIncludeSearchExtTypes[i]);ff;ff.Next())
461
				if(ff.IsFolder() || (ff.IsFile() && i != 0))
462
					mTempIncludeFiles.Add(IncludeFileItem(ff.GetName(),search_path,i));
463
	}
464
	Call(THISBACK(NotifyScanFinish));
465
}
466
void AssistEditor::InsertFiles(bool get_local)
467
{
468
	if(get_local)
469
	{
470
		mWorkerBusy = true;
471
		if(files.GetCount() == 0)
472
			files.Add(RawToValue(IncludeFileItem::GetLoadingItem()));
473
		mIncludePathStack.Add(GetFileDirectory(theide->editfile));
474
		theide->mWork.Do(THISBACK(ScanLocalFiles));
475
	}
476
	else if(IsBuildMethodChanged())
477
	{
478
		
479
		mWorkerBusy = true;
480
		files.Add(RawToValue(IncludeFileItem::GetLoadingItem()));
481
		mCurentBuildMethod = theide->method;
482
		theide->mWork.Do(THISBACK(ScanFrontFiles));
483
	}
484
	else
485
	{
486
		Array<IncludeFileItem> & touse = (mIncludePathDepth==0 && mAssistFrontCharacter == '<') ? mMainIncludeFiles : mTempIncludeFiles;
487
		for(int i = 0; i < touse.GetCount(); i++)
488
			files.Add(RawToValue(touse[i]));
489
		files.Sort(0,IncludeFileItem::CompareForArrayCtrl);
490
	}
491
}
492
void AssistEditor::SyncFiles()
493
{
494
	Array<IncludeFileItem> & touse = (mIncludePathDepth==0 && mAssistFrontCharacter == '<') ? mMainIncludeFiles : mTempIncludeFiles;
495
	//int active_count = files.GetCount();
496
	files.Clear();
497
	if(mFolderNameStringCache.GetCount() == 0)
498
	{
499
		for(int i = 0; i < touse.GetCount(); i++)
500
			files.Add(RawToValue(touse[i]));
501
		//active_count -= touse.GetCount();
502
	}
503
	else
504
	{
505
		for(int i = 0; i < touse.GetCount(); i++) 
506
		{
507
			const IncludeFileItem & item = touse[i];
508
			if(memcmp_i(mFolderNameStringCache,item.name,mFolderNameStringCache.GetCount())==0)
509
			{
510
				files.Add(RawToValue(item));
511
				//active_count--;
512
			}
513
		}
514
	}
515
	if(files.GetCount() == 0)
516
		files.Add(RawToValue(IncludeFileItem::GetEmptyItem()));
517
	else
518
		files.Sort(0,IncludeFileItem::CompareForArrayCtrl);
519
	//return active_count;
520
};
521
void AssistEditor::CloseFiles()
522
{
523
	mFolderNameStringCache.Clear();
524
	mIncludePathStack.Clear();
525
	files.Close();
526
	files.Clear();
527
	mIncludePathDepth = 0;
528
}
Methods.cpp (working copy)
402 402
		int c = m.Run();
403 403
		if(c == IDCANCEL)
404 404
			break;
405
		if(c == IDOK && m.Save()) {
405
		if(c == IDOK && m.Save()) 
406
		{
406 407
			use_target = m.use_target;
408
			editor.NotifyIncludeConfigChange();
407 409
			break;
408 410
		}
409 411
	}
Setup.cpp (working copy)
390 390
		(assist.mark_lines, mark_lines)
391 391
		(assist.qtfsel, qtfsel)
392 392
		(assist.assist, editor.auto_assist)
393
		(assist.use_assist, editor.mUseIncludeAssist)
394
		(assist.include_assist_headers, editor.mAssistSearchStringConfig)
393 395

  
394 396
		(ide.showtime, showtime)
395 397
		(ide.show_status_bar, show_status_bar)
......
481 483
		FlushFile();
482 484
		FileCursor();
483 485
	}
486
	editor.NotifyIncludeConfigChange();
484 487
	FileSetTime(ConfigFile("version"), ToTime(~ide.showtimeafter));
485 488
	SaveLoadPackage();
486 489
	SyncCh();