-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXWndClass.xcsm
654 lines (575 loc) · 24.9 KB
/
XWndClass.xcsm
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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
class XWndClass : QDockWidget
{
QTreeWidget _treeview;
public XWorkspace workspace;
JsonArray sources;
QLineEdit editSearch;
ContextMenu _contextMenu = new ContextMenu();
public static class ItemLoader
{
public long loaditem;
public JsonArray object;
public bool isStatic;
public ItemLoader(long i, JsonArray o, bool bs)
{
loaditem = i;
object = o;
isStatic = bs;
}
};
public static class Position : ClassViewInfo
{
public Position(int s,int l,int r, bool b, JsonObject _node)
{
source = s;
line = l;
row = r;
lib = b;
node = _node;
}
public int source = -1, line, row;
public bool lib = false;
public JsonObject node;
public int getLine(){
return line;
}
int getColumn(){
return row;
}
JsonObject getObject(){
return node;
}
bool isExternal(){
return lib;
}
};
Map<long, ItemLoader> expand_data = new Map<long, ItemLoader>();
Map<long, Position> position_info = new Map<long, Position>();
public static XWndClass wndClass;
String searchkey = nilptr;
public void onAttach()
{
editSearch = (QLineEdit)attachByName(new QLineEdit(), "classSearch");
_treeview = (QTreeWidget)attachByName(new QTreeWidget(), "tree_class");
wndClass = this;
/*
改成layout之后就不需要resize了
setOnLayoutEventListener(new onLayoutEventListener(){
void onResize(QObject obj, int w, int h, int oldw, int oldh)override {
if (_treeview != nilptr){
_treeview.resize(w, h - 25);
}
}
});*/
_treeview.setOnTreeViewItemEvent(new onTreeViewItemEvent() {
void onItemExpanded(QTreeWidget,long item)override {
XWndClass.this.expandLoad(item);
}
void onItemDoubleClicked(QTreeWidget,long item, int column) {
String text = _treeview.getItemText(item,0);
if (text.equals("外部库")) {
workspace.showProperites("项目设置");
}
}
void onItemClicked(QTreeWidget,long item, int column)override {
XWndClass.this.clickItem(item);
}
void onItemPressed(QTreeWidget, long item, int column)override {
Position pos = nilptr;
String source = nilptr;
try {
pos = position_info.get(item);
source = sources.getString(pos.source);
} catch(Exception e) {
}
PluginsController.updateClassViewActionState(workspace.getCurrentProject(), source, pos);
}
});
editSearch.setOnKeyEventListener(new onKeyEventListener() {
bool onKeyPress(QObject obj,int key,bool repeat,int count,String text,int scanCode,int virtualKey,int modifier)override {
if (key == Constant.Key_Escape) {
editSearch.setText("");
} else if (key == Constant.Key_Return) {
synchronized(searchLock) {
searchLock.notify();
}
}
return true;
}
});
editSearch.setOnEditEventListener(new onEditEventListener() {
void onTextChanged(QObject, String text)override {
if (ignoreSearch || workspace.getCurrentProject() == nilptr) {
return;
}
searchkey = text;
if (searchkey.length() == 0) {
searchkey = nilptr;
refresh();
} else {
onSearch();
}
}
});
}
public void createContextMenu()
{
ActionIdent [] ais = PluginsController.getClassViewContextActions();
__nilptr_safe(_treeview);
String [] acts = { "复制到剪贴板" };
_contextMenu.create(_treeview, acts, new onEventListener (){
public void onTrigger(QObject obj) {
long item = _treeview.getSelItem();
if (item != 0){
String str = _treeview.getItemText(item,0);
if (str != nilptr){
setClipboardText(str);
}
}
}
}, ais);
_contextMenu.setEnable(0, true);
}
Thread searchThread = nilptr;
bool ignoreSearch = false;
Object searchLock = new Object();
public void onSearch()
{
synchronized(searchLock) {
if (searchThread == nilptr) {
searchThread = new Thread() {
void run()override {
String currentKey = nilptr;
synchronized(searchLock) {
bool bw = false;
String _thekey = searchkey;
while (currentKey == nilptr || (_thekey != nilptr && currentKey.equals(_thekey) == false)) {
currentKey = _thekey;
if (bw == false) {
bw = searchLock.wait(800);
}
_thekey = searchkey;
}
}
ignoreSearch = true;
runOnUi(new Runnable() {
void run()override {
editSearch.setText("搜索中...");
editSearch.setEnabled(false);
}
});
if (currentKey != nilptr) {
search(workspace.getCurrentProject(), currentKey.upper());
}
synchronized(searchLock) {
if (currentKey != nilptr) {
refresh();
}
searchThread = nilptr;
}
runOnUi(new Runnable() {
void run()override {
if (currentKey != nilptr) {
editSearch.setText(currentKey);
} else {
editSearch.setText("");
}
editSearch.setEnabled(true);
editSearch.setFocus();
ignoreSearch = false;
}
});
}
};
searchThread.start();
}
}
}
public static void prepare(@NotNilptr Project project)
{
wndClass._treeview.addItem("res/toolbar/project.png", project.getName() + "(正在生成类视图...)");
}
public static void refresh()
{
XWndClass.postNotify(XWorkspace.AUTODOMPEVENTID);
}
public void clickItem(long item)
{
Position pos = nilptr;
try {
pos = position_info.get(item);
} catch(Exception e) {
}
if (pos != nilptr) {
//_system_.consoleWrite("" + pos.source + ": " + pos.line + "." + pos.row + "\n");
if (pos.source == -1) {
//QMessageBox.Information("注意", "对象不在源代码中定义.", QMessageBox.Ok, QMessageBox.Ok);
return ;
}
String source = sources.getString(pos.source);
if (source == nilptr || source.length() == 0) {
//QMessageBox.Information("注意", "对象不在源代码中定义.", QMessageBox.Ok, QMessageBox.Ok);
return ;
}
Project pjct = workspace.getCurrentProject();
if (pjct != nilptr) {
source = pjct.getFullPath(source);
}
if (XPlatform.existsSystemFile(source) == false) {
if (pos.lib == false) {
QMessageBox.Critical("文件不存在", "找不到文件:" + sources.getString(pos.source) + "该位置的文件已不存在.", QMessageBox.Ok, QMessageBox.Ok);
}
} else {
workspace.openTextFileInfo(source, pos.line + 1, pos.row + 1);
}
}
}
public void expandLoad(long item)
{
ItemLoader loader = nilptr;
try {
loader = expand_data.get(item);
} catch(Exception e) {
}
if (loader != nilptr) {
int count = loader.object.length();
if (count > 0) {
_treeview.setItemText(loader.loaditem, 0, String.format("%d个", count));
} else {
_treeview.setItemText(loader.loaditem, 0, "无");
}
expand_data.remove(item);
loadObject(item, nilptr, loader.object, 0, loader.isStatic);
}
}
public static void postNotify(int id)
{
wndClass.Notify(id);
}
public void clear()
{
_treeview.clear();
expand_data.clear();
position_info.clear();
sources = nilptr;
}
public void onNotification(long eventid)
{
if (workspace.getCurrentProject() != nilptr) {
Project pj = workspace.getCurrentProject();
if (pj != nilptr){
loadProject(pj);
}
}
}
/*static void load(Project project){
wndClass.loadProject(project);
}*/
public long [][] loadLibs(@NotNilptr Project project, Configure configure)
{
long [] hlibs;
long [] hlinks;
if (configure != nilptr) {
long libroot = 0;
JsonArray libs = project.getExternLibs(configure);
if (libs != nilptr) {
hlibs = new long[libs.length()];
if (libs.length() > 0) {
libroot = _treeview.addItem("res/toolbar/extern.png", "外部库");
}
for (int i = 0, c = libs.length(); i < c; i++) {
String var = libs.getString(i);
if (var != nilptr) {
hlibs[i] = _treeview.insertItem(libroot, "res/toolbar/library.png", var.findFilenameAndExtension());
}
}
}
JsonArray links = (JsonArray)configure.root.get("links");
if (links != nilptr) {
hlinks = new long[links.length()];
if (links.length() > 0 && libroot == 0) {
libroot = _treeview.addItem("res/toolbar/extern.png", "外部库");
}
for (int i = 0, c = links.length(); i < c; i++) {
String var = links.getString(i);
if (var != nilptr) {
hlinks[i] = _treeview.insertItem(libroot, "res/toolbar/library.png", var.findFilenameAndExtension());
}
}
}
}
long [][] hret = {hlibs, hlinks};
return hret;
}
public void search(Project project, String key)
{
if (project != nilptr) {
JsonObject json = project.xintelliSenseMap;
bool showBuildin = Setting.isShowBuildin();
if (json != nilptr) {
JsonArray template_class = (JsonArray)json.get("template_class");
JsonArray template_instance = (JsonArray)json.get("template_instance");
JsonArray heap = (JsonArray)json.get("heap");
if (template_class != nilptr)
searchObject(template_class, key, showBuildin);
if (template_instance != nilptr)
searchObject(template_instance, key, showBuildin);
if (heap != nilptr)
searchObject(heap, key, showBuildin);
}
}
}
public int searchObject(JsonArray objs, String key, bool showBuildin)
{
int hasVisible = 0;
if (objs == nilptr ) {
return 0;
}
for (int i =0, c = objs.length(); i < c; i++) {
JsonObject obj = (JsonObject)objs.get(i);
if (obj == nilptr){
continue;
}
int type = obj.getInt("type");
String objname = obj.getString("name");
if (objname != nilptr){
objname = objname.upper();
}
if (obj.has("buildin")) {
if (showBuildin == false) {
continue;
}
}
int bVisible = 0;
obj.remove("mathced");
try{
if (Pattern.test(objname, key, 0, false)) {
bVisible ++;
}
if (type == 31) {
bVisible += searchObject((JsonArray)obj.get("properites"), key, showBuildin);
bVisible += searchObject((JsonArray)obj.get("static_properites"), key, showBuildin);
bVisible += searchObject((JsonArray)obj.get("method"), key, showBuildin);
bVisible += searchObject((JsonArray)obj.get("static_method"), key, showBuildin);
} else if (type == 23) {
JsonArray param = (JsonArray)obj.get("params");
if (param != nilptr){
for (int x = 0, y = param.length(); x < y; x++) {
JsonObject jo = (JsonObject)param.get(x);
if (jo != nilptr){
String fname = jo.getString("name");
if (fname != nilptr){
fname = fname.upper();
}
jo.remove("mathced");
if (Pattern.test(fname, key, 0, false)) {
jo.put("mathced",1);
bVisible ++;
}
}
}
}
}
}catch(Exception e){
}
if (bVisible > 0) {
hasVisible++;
obj.put("mathced", 1);
}
}
return hasVisible;
}
public void loadProject(@NotNilptr Project project)
{
clear();
long root = _treeview.addItem("res/toolbar/project.png", project.getName());
long hbuildin = 0;
if (Setting.isShowBuildin()) {
hbuildin = _treeview.addItem("res/toolbar/sources.png", "内置对象");
}
long [][]libs = loadLibs(project, project.getCurrentConfig());
if (project.xintelliSenseMap != nilptr) {
sources = (JsonArray)project.xintelliSenseMap.get("sources");
JsonArray template_class = (JsonArray)project.xintelliSenseMap.get("template_class");
JsonArray template_instance = (JsonArray)project.xintelliSenseMap.get("template_instance");
JsonArray heap = (JsonArray)project.xintelliSenseMap.get("heap");
loadObject(root, libs, template_class, hbuildin, false);
loadObject(root, libs, template_instance, hbuildin, false);
loadObject(root, libs, heap, hbuildin, false);
_treeview.setExpand(root, true);
}
}
public long insertLoad(long item)
{
return _treeview.insertItem(item, nilptr, "加载中...");
}
public void loadObject(long hroot, long [][]libs, JsonArray objs, long hbuildin, bool isStatic)
{
if (objs == nilptr) {
return ;
}
bool searched = searchkey!= nilptr;
bool showBuildin = Setting.isShowBuildin();
for (int i =0, c = objs.length(); i < c; i++) {
long root = hroot;
JsonObject obj = (JsonObject)objs.get(i);
if (obj == nilptr){
continue;
}
if (searched && !obj.has("mathced")) {
continue;
}
if (obj.has("buildin")) {
if (showBuildin == false) {
continue;
} else {
if (hbuildin != 0) {
root = hbuildin;
}
}
}
int type = obj.getInt("type");
int visibility = obj.getInt("visibility");
bool blib = obj.has("lib");
if (blib && libs != nilptr && libs[0] != nilptr) {
int libid = obj.getInt("lib");
if (libid < libs[0].length) {
root = libs[0][libid];
} else {
continue;
}
}
bool blink = obj.has("link");
if (blink && libs != nilptr && libs[1] != nilptr) {
int linkid = obj.getInt("link");
if (linkid < libs[1].length) {
root = libs[1][linkid];
} else {
continue;
}
}
String prototype = obj.getString("prototype");
long item = 0;
if (type == 34) {
item = _treeview.insertItem(root, "res/toolbar/template.png", obj.getString("name"));
if (prototype != nilptr){
_treeview.insertItem(item, "res/toolbar/prototype.png", prototype);
}
} else if (type == 31) {
bool bpackage = false;
bool binterface = false;
if (obj.has("template")) {
item = _treeview.insertItem(root, "res/toolbar/tempinst.png", obj.getString("name"));
long temp = _treeview.insertItem(item, "res/toolbar/template.png", "模板");
_treeview.insertItem(temp, "res/toolbar/template.png", obj.getString("template"));
} else if (obj.has("interface")) {
item = _treeview.insertItem(root, "res/toolbar/interface.png", obj.getString("name"));
binterface = true;
} else if (obj.has("package")) {
item = _treeview.insertItem(root, "res/toolbar/package_icon.png", obj.getString("name"));
bpackage = true;
} else {
item = _treeview.insertItem(root, "res/toolbar/class.png", obj.getString("name"));
}
if (prototype != nilptr){
_treeview.insertItem(item, "res/toolbar/prototype.png", prototype);
}
if (obj.has("base")) {
long temp = _treeview.insertItem(item, "res/toolbar/class.png", "基类");
_treeview.insertItem(temp, "res/toolbar/class.png", obj.getString("base"));
}
if (bpackage){
long static_prop = _treeview.insertItem(item, "res/toolbar/static.png", "成员");
expand_data.put(static_prop,new ItemLoader(insertLoad(static_prop), (JsonArray)obj.get("static_properites"), false));
}else
if (binterface){
long method = _treeview.insertItem(item, "res/toolbar/function.png", "抽象方法");
long static_method = _treeview.insertItem(item, "res/toolbar/staticfunction.png", "静态接口方法");
expand_data.put(method, new ItemLoader(insertLoad(method), (JsonArray)obj.get("method"), false));
expand_data.put(static_method,new ItemLoader( insertLoad(static_method), (JsonArray)obj.get("static_method"), true));
}else{
JsonArray properites = (JsonArray)obj.get("properites");
if (properites != nilptr && properites.length() > 0){
long prop = _treeview.insertItem(item, "res/toolbar/member.png", "成员");
expand_data.put(prop,new ItemLoader(insertLoad(prop), properites, false));
}
JsonArray static_properites = (JsonArray)obj.get("static_properites");
if (static_properites != nilptr && static_properites.length() > 0){
long static_prop = _treeview.insertItem(item, "res/toolbar/static.png", "静态成员");
expand_data.put(static_prop,new ItemLoader(insertLoad(static_prop), static_properites, true));
}
JsonArray methods = (JsonArray)obj.get("method");
if (methods != nilptr && methods.length() > 0){
long method = _treeview.insertItem(item, "res/toolbar/function.png", "方法");
expand_data.put(method, new ItemLoader(insertLoad(method), methods, false));
}
JsonArray static_methods = (JsonArray)obj.get("static_method");
if (static_methods != nilptr && static_methods.length() > 0){
long static_method = _treeview.insertItem(item, "res/toolbar/staticfunction.png", "静态方法");
expand_data.put(static_method,new ItemLoader( insertLoad(static_method), static_methods, true));
}
}
/*loadObject(prop, (JsonArray)obj.get("properites"));
loadObject(static_prop, (JsonArray)obj.get("static_properites"));
loadObject(method, (JsonArray)obj.get("method"));
loadObject(static_method, (JsonArray)obj.get("static_method"));*/
} else if (type == 23) {
if (obj.has("interface")) {
item = _treeview.insertItem(root, "res/toolbar/interfacefun.png", obj.getString("name"));
} else {
if (isStatic){
if (visibility >= 0x40){
item = _treeview.insertItem(root, "res/toolbar/methodstatic.png", obj.getString("name"));
}else{
item = _treeview.insertItem(root, "res/toolbar/methodstaticprivate.png", obj.getString("name"));
}
}else
if (visibility >= 0x40){
item = _treeview.insertItem(root, "res/toolbar/method.png", obj.getString("name"));
}else{
item = _treeview.insertItem(root, "res/toolbar/methodprivate.png", obj.getString("name"));
}
if (prototype != nilptr){
_treeview.insertItem(item, "res/toolbar/prototype.png", prototype);
}
}
if (obj.has("typeobj")) {
long temp = _treeview.insertItem(item, "res/toolbar/class.png", "类型");
_treeview.insertItem(temp, nilptr, obj.getString("typeobj"));
}
long params = 0;
JsonArray param = (JsonArray)obj.get("params");
if (param != nilptr){
if (param.length() > 0){
params = _treeview.insertItem(item, "res/toolbar/params.png", "参数列表");
}
for (int x = 0, y = param.length(); x < y; x++) {
JsonObject jo = (JsonObject)param.get(x);
if (jo == nilptr){
continue;
}
if (searched && !jo.has("mathced")) {
continue;
}
long pitem = _treeview.insertItem(params, "res/toolbar/param.png", jo.getString("name"));
long temp = _treeview.insertItem(pitem, "res/toolbar/class.png", "类型");
_treeview.insertItem(temp, nilptr, jo.getString("type"));
}
}
} else if (type == 18) {
item = _treeview.insertItem(root, "res/toolbar/object.png", obj.getString("name"));
if (obj.has("typeobj")) {
long temp = _treeview.insertItem(item, "res/toolbar/class.png", "类型");
_treeview.insertItem(temp, nilptr, obj.getString("typeobj"));
}
}
if (item != 0) {
int sourceid = -1;
if (obj.has("source")) {
sourceid = obj.getInt("source");
}
position_info.put(item, new Position(sourceid, obj.getInt("line"), obj.getInt("column"), blib, obj));
}
}
}
};