-
Notifications
You must be signed in to change notification settings - Fork 2
/
Setting.xcsm
1513 lines (1249 loc) · 59.3 KB
/
Setting.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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//xlang Source, Name:Setting.xcsm
//Date: Wed Sep 16:29:18 2018
class Setting : QDialog {
static JsonObject _template_root;
static QRect rect = nilptr;
public bool onClose(){
rect = new QRect(x(), y(), width(), height());
return true;
}
public static class Preference{
JsonObject root;
public Preference(){
loadPreference();
}
public @NotNilptr String getSetting(String [] options,@NotNilptr String key){
String val = root.getString(key);
if (val == nilptr){
val = "";
}
if (options != nilptr){
for (int i = 0; i < options.length; i++){
if (options[i].equals(val)){
val = "" + i;
break;
}
}
}
return val;
}
public bool setSetting(@NotNilptr String key,String val){
if (val == nilptr){
val = "";
}
while (root.has(key)){
root.remove(key);
}
root.put(key, val);
return true;
}
public String getPreferencePath(){
String file = XPlatform.getAppDirectory();
return file.appendPath("config").appendPath("preference.prop");
}
public void loadPreference(){
String file = getPreferencePath();
if (file != nilptr){
FileInputStream fis = nilptr;
try{
fis = new FileInputStream(file);
}catch(Exception e){
_system_.consoleWrite("canot read file " + file);
}
if (fis != nilptr){
byte []data = fis.read();
String content = new String(data);
try{
root = new JsonObject(content);
}catch(Exception e){
}
}
if (root == nilptr){
root = new JsonObject();
}
}
}
public void apply(@NotNilptr JsonObject template){
if (root != nilptr){
JsonObject keys = (JsonObject)template.get("加速键");
if (keys == nilptr){
return;
}
JsonObject skey = (JsonObject)keys.child();
if (skey != nilptr){
Map<String, String> keyMap = new Map<String, String>();
bool bConflict = false;
while ((skey = (JsonObject)skey.next()) != nilptr){
String name = skey.getName();
if (name != nilptr){
String []names = name.split(":");
if (names.length == 2){
String keyname = names[1];
String shortkey = root.getString(names[1]);
if (shortkey == nilptr){
shortkey = "";
}
if (XMenuManager._menuMgr != nilptr && XMenuManager._menuMgr.mainwindow != nilptr){
QAction action = (QAction)XMenuManager._menuMgr.mainwindow.findByName(keyname);
if (action != nilptr){
action.setShortcut(shortkey);
}
}
if (shortkey.length() > 0){
Map.Iterator<String,String> iter = keyMap.find(shortkey);
if (iter != nilptr){
String oldKey = iter.getValue();
XWndOutput.outputWnd.Output("加速键 [" + names[0] + "] 与 [" + oldKey + "] 存在冲突:" + shortkey + "\n", 0);
bConflict = true;
}else{
keyMap.put(shortkey, names[0]);
}
}
}
}
}
XStackInfor.setThreadOuputStatus(outputThreadStat());
XLogcatWnd.setMaxItems(getLogcatMaxitems());
if (bConflict){
QMessageBox.Critical("注意","加速键存在冲突, 可能不会生效.",QMessageBox.Ok,QMessageBox.Ok);
}
}
}
}
public void save(){
String file = getPreferencePath();
if (file != nilptr){
FileOutputStream fos = nilptr;
try{
fos = new FileOutputStream(file);
}catch(Exception e){
_system_.consoleWrite("canot read file " + file);
}
if (fos != nilptr){
String content = root.toString(true);
byte []data = content.getBytes();
try{
fos.write(data);
}catch(Exception e){
}
fos.close();
}
}
}
};
static bool bTemplateLoaded = loadTemplate();
static Preference preference = new Preference();
QPushButton btnClose;
QTreeWidget _listview;
QPropertyBrowser _propTable = new QPropertyBrowser();
QScintilla _sci = new QScintilla();
class ItemRecord{
public JsonObject obj;
public IXPlugin plugin;
public ItemRecord(JsonObject str, IXPlugin xp){
obj = (JsonObject)str.clone();
plugin = xp;
}
};
class ItemValue{
public ItemRecord ir;
public String defaultText;
public ItemValue(ItemRecord _ir, String ds){
ir = _ir;
defaultText = ds;
}
public ItemValue(ItemRecord _ir){
ir = _ir;
}
};
Vector<ItemRecord> _propItems = new Vector<ItemRecord>();
Map<String, QPropertyBrowser.QtVariantProperty> currentProps = new Map<String, QPropertyBrowser.QtVariantProperty>();
int current_sel_setting = 0;
bool showSci = false;
onTreeViewItemEvent listlistener = new onTreeViewItemEvent(){
public void onItemClicked(@NotNilptr QTreeWidget list,long item, int column)override{
current_sel_setting = list.getItemTag(item, 0);
String seltext = _listview.getItemText(item,0);
showSci = seltext.equals("文本编辑器配色");
saveSetting();
reloadProperty();
}
};
public void reloadProperty(){
_propTable.clear();
currentProps.clear();
if (current_sel_setting >=0 && current_sel_setting < _propItems.size()){
ItemRecord jo = _propItems.get(current_sel_setting);
if (jo != nilptr){
loadFeature((JsonObject)jo.obj.child(), jo);
int w = width(), h = height();
if (showSci){
_sci.show();
// top = 40
_propTable.resize(w - 200, h - 290);
syntaxForXlang();
_sci.move(170,h - 230);
_sci.resize(w - 200,190);
}else{
_sci.hide();
_propTable.resize(w - 200, h - 90);
}
}
//在这里注意
}
}
public static String readSlnPropFile(@NotNilptr String file){
FileInputStream fis = nilptr;
try{
fis = new FileInputStream(file);
}catch(Exception e){
_system_.consoleWrite("canot read file " + file);
}
if (fis != nilptr){
byte []data = fis.read();
return new String(data);
}
return nilptr;
}
public static bool loadTemplate(){
String file = XPlatform.getAppDirectory();
file = file.appendPath("config").appendPath("setting.prop");
String content = readSlnPropFile(file);
if (content != nilptr){
try{
_template_root = new JsonObject(content);
}catch(Exception e){
}
return true;
}
return false;
}
public bool loadSetting(){
if (_template_root == nilptr){
loadTemplate();
}
bool noload = false;
if (_template_root != nilptr){
loadProperites((JsonObject)_template_root.child(), nilptr, noload);
noload = true;
}
loadPlugins(noload);
return true;
}
bool oldbuildinsetting = false;
public void onAttach(){
//setWindowFlags(CustomizeWindowHint | WindowMinMaxButtonsHint | WindowCloseButtonHint | Tool);
_listview = (QTreeWidget)attachByName(new QTreeWidget(), "listProp");
_propTable.create(this);
_propTable.move(170, 40);
_propTable.resize(500, 410);
_propTable.setLables("项","值");
_propTable.enableAdjust(true);
_propTable.setHeaderWidths(200, 300);
String [] columns = {"选项"};
_listview.setColumns(columns);
_listview.setOnTreeViewItemEvent(listlistener);
_sci.create(this);
_sci.move(170, 40);
_sci.resize(500, 410);
_sci.hide();
_sci.setText("//xlang " +
"\npackage System{" +
"\n public class out{" +
"\n public static int println(String text){" +
"\n return _system_.consoleWrite(text + \"\\n\");" +
"\n }" +
"\n public static int print(String text){" +
"\n return _system_.consoleWrite(text);" +
"\n }" +
"\n };" +
"\n " +
"\n public class Console{" +
"\n public Console(){" +
"\n _system_.createConsole();" +
"\n }" +
"\n };" +
"\n};" +
"\n\n" +
"\nusing { System; };" +
"\n\n" +
"\nint main(String [] args){" +
"\n\n new Console();" +
"\n\n System.out.println(\"hello world\");" +
"\n\n _system_.sleep(3000);" +
"\n\n return 0;" +
"\n}\n");
_sci.sendEditor(QScintilla.SCI_MARKERADD, 1, 8);
_sci.sendEditor(QScintilla.SCI_MARKERADD, 2, 9);
_sci.sendEditor(QScintilla.SCI_MARKERADD, 3, 12);
_sci.sendEditor(QScintilla.SCI_MARKERADD, 4, 13);
if (loadSetting() == false){
close();
return ;
}
btnClose = (QPushButton)attachByName(new QPushButton(), "btnClose");
btnClose.setOnClickListener(
new onClickListener(){
public void onClick(QObject obj, bool checked)override{
saveSetting();
applySetting();
//QApp.statusBar.showStatusMessage("部分设置需要在XStudio重新开启后生效.");
if (oldbuildinsetting != isShowBuildin()){
XWndClass.refresh();
}
close();
}
});
setOnLayoutEventListener(new onLayoutEventListener(){
public void onResize(QObject obj, int w, int h, int oldw, int oldh)override {
_listview.resize(141, h - 50);
btnClose.move(w - 100, h - 40);
//_propTable.move(170, 40);
if (showSci == false){
_propTable.resize(w - 200, h - 90);
}else{
_propTable.resize(w - 200, h - 290);
_sci.move(170,h - 230);
_sci.resize(w - 200,190);
}
}
});
setWindowTitle("设置");
setWindowIcon("./res/toolbar/prop.png");
if (rect != nilptr){
move(rect.left,rect.top);
resize(rect.right,rect.bottom);
}
setModal(true);
show();
oldbuildinsetting = isShowBuildin();//XWorkspace.workspace.XIntelliSense();
}
public void loadFeature(@NotNilptr JsonObject confi, ItemRecord xp){
QPropertyBrowser.QtVariantPropertyManager variantManager = new QPropertyBrowser.QtVariantPropertyManager(_propTable);
while(confi != nilptr){
String cfgName = confi.getName();
String type = confi.getString("type");
if (cfgName != nilptr && type != nilptr){
if (cfgName.split(':').length == 2){
if (type.equals("string")){
loadString(variantManager, cfgName, confi, xp);
}else
if (type.equals("stringlist")){
loadStringList(variantManager, cfgName, confi, xp);
}else
if (type.equals("keysequence")){
loadKeySequence(variantManager, cfgName, confi, xp);
}else
if (type.equals("color")){
loadColor(variantManager, cfgName, confi, xp);
}else
if (type.equals("options")){
loadOptions(variantManager, cfgName, confi, xp);
}else
if (type.equals("bool")){
loadBoolean(variantManager, cfgName, confi, xp);
}else
if (type.equals("text")){
loadTextItem(variantManager, cfgName, confi, xp);
}else
if (type.equals("params")){
loadTextparams(variantManager, cfgName, confi, xp);
}else
if (type.equals("fileout")){
loadSavePath(variantManager, cfgName, confi, xp);
}else
if (type.equals("filein")){
loadOpenPath(variantManager, cfgName, confi, xp);
}else
if (type.equals("folder")){
loadPath(variantManager, cfgName, confi, xp);
}
}
}
confi = (JsonObject)confi.next();
}
_propTable.setFactoryForManager(variantManager, new QPropertyBrowser.QtVariantEditorFactory(_propTable));
_propTable.setPropertiesWithoutValueMarked(true);
_propTable.setRootIsDecorated(false);
}
public bool loadPlugins(bool noload)
{
Map.Iterator<String, XPluginShell> iter = PluginsController.plugins_list.iterator();
while (iter.hasNext()) {
XPluginShell splug = iter.getValue();
if (splug != nilptr && (splug._plugin != nilptr) && (splug.inited)) {
IXPlugin xp = splug._plugin;
String strSetting = xp.getSetting();
if (strSetting != nilptr){
try{
loadProperites((JsonObject)(new JsonObject(strSetting).child()), xp, noload);
noload = true;
}catch(Exception e){
}
}
}
iter.next();
}
return true;
}
public void loadProperites( @NotNilptr JsonObject root, IXPlugin xp, bool noload){
bool loaded = noload;
//new QPropertyBrowser.QtVariantPropertyManager()
while(root != nilptr){
String featName = root.getName();
JsonObject confi = (JsonObject)root.child();
if (confi != nilptr){
long litem = _listview.addItem(nilptr, featName);
_listview.setItemTag(litem, 0, _propItems.size());
ItemRecord jo = new ItemRecord(root, xp);
_propItems.add(jo);
if (loaded == false){
loadFeature(confi, jo);
loaded = true;
}
}
root = (JsonObject)root.next();
}
}
public void loadOpenPath(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager, @NotNilptr String name, @NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addEnumProperty(new QPropertyBrowser.QtVariantProperty(), kv[0]);
String defaultValue = getSetting(nilptr, kv[1]);
item.setTagObject(new ItemValue(xp));
String [] options = new String[2];
options[0] = defaultValue;
options[1] = "<浏览...>";
item.setAttributeEnumNames(options);
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(){
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
if (stringValue.parseInt() != 0){
item.setValue(defaultValue);
String newValue = QFileDialog.getOpenFileName("浏览 - " + kv[0], options[0],"*",Setting.this);
if (newValue != nilptr){
//_prop.setValue(_project,_curconfig, kv[1], newValue);
options[0] = newValue;
item.setAttributeEnumNames(options);
}
item.setValue("0");
}
}
}
});
_propTable.addProperty(item);
currentProps.put(kv[1], item);
}
public void loadPath(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr String name, @NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addEnumProperty(new QPropertyBrowser.QtVariantProperty(), kv[0]);
String defaultText = getSetting(nilptr, kv[1]);
String [] options = new String[2];
options[0] = defaultText;
options[1] = "<浏览...>";
item.setAttributeEnumNames(options);
item.setTagObject(new ItemValue(xp));
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(){
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
if (stringValue.parseInt() != 0){
item.setValue("0");
String newValue = QFileDialog.getFolderPath("选择目录",options[0],nilptr,Setting.this);
if (newValue != nilptr){
options[0] = newValue;
item.setAttributeEnumNames(options);
}
item.setValue("0");
}
}
}
});
_propTable.addProperty(item);
currentProps.put(kv[1], item);
}
public void loadSavePath(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr String name,@NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addEnumProperty(new QPropertyBrowser.QtVariantProperty(), kv[0]);
String defaultValue = getSetting(nilptr, kv[1]);
String [] options = new String[2];
options[0] = defaultValue;
options[1] = "<浏览...>";
item.setAttributeEnumNames(options);
item.setTagObject(new ItemValue(xp));
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(){
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
if (stringValue.parseInt() != 0){
item.setValue(defaultValue);
String newValue = QFileDialog.getOpenFileName("浏览 - " + kv[0], options[0],"*",Setting.this);
if (newValue != nilptr){
//_prop.setValue(_project,_curconfig, kv[1], newValue);
options[0] = newValue;
item.setAttributeEnumNames(options);
}
item.setValue("0");
}
}
}
});
_propTable.addProperty(item);
currentProps.put(kv[1], item);
}
public void loadTextparams(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr String name, @NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addEnumProperty(new QPropertyBrowser.QtVariantProperty(), kv[0]);
item.setFlags(2);
String defaultValue = getSetting(nilptr, kv[1]);
ItemValue iv = new ItemValue(xp, defaultValue);
item.setTagObject(iv);
String simpleValue = "", detailValue = "";
try{
JsonArray jarv = new JsonArray(defaultValue);
for (int i = 0, c = jarv.length(); i < c; i++){
String value = jarv.getString(i);
if (detailValue.length() > 0){
detailValue = detailValue + "\n" + value;
simpleValue = simpleValue + ";" + value;
}else{
detailValue = value;
simpleValue = value;
}
}
}catch(Exception e){
}
String [] options = new String[2];
options[0] = simpleValue;
options[1] = "<编辑...>";
item.setAttributeEnumNames(options);
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(defaultValue){
public onPropertyEventListener(String def){
defText = def;
}
String defText = "";
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
if (stringValue.parseInt() != 0){
TextDetail td = nilptr;
td = new TextDetail(new TextDetail.closeListener() {
void onClose(@NotNilptr String text, bool updated) {
if (updated){
detailValue = text.trim(true);
String [] newValue = detailValue.split('\n');
JsonArray jset = new JsonArray();
for (int i = 0; i < newValue.length; i++){
jset.put(newValue[i]);
}
defText = jset.toString(true);
iv.defaultText = defText;
//_prop.setValue(_project,_curconfig, kv[1], defaultValue);
simpleValue = text.trim(true).replace("\n", ";");
options[0] = simpleValue;
item.setAttributeEnumNames(options);
}
item.setValue("0");
}
void onCreate() {
td.centerScreen();
}
});
td.create("编辑 - " + kv[0], detailValue, Setting.this, true);
}
}
}
});
_propTable.addProperty(item);
currentProps.put(kv[1], item);
}
public void loadTextItem(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr String name,@NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addEnumProperty(new QPropertyBrowser.QtVariantProperty(), kv[0]);
String defaultValue = getSetting(nilptr, kv[1]);
item.setTagObject(new ItemValue(xp));
String [] options = new String[2];
options[0] = defaultValue;
options[1] = "<编辑...>";
item.setAttributeEnumNames(options);
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(){
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
if (stringValue.parseInt() != 0){
TextDetail td = nilptr;
td = new TextDetail(new TextDetail.closeListener() {
void onClose(@NotNilptr String text, bool updated) {
if (updated){
String newValue = text.trim(true);
//_prop.setValue(_project,_curconfig, kv[1], newValue);
options[0] = newValue;
item.setAttributeEnumNames(options);
}
item.setValue("0");
}
void onCreate() {
td.centerScreen();
}
});
td.create("编辑 - " + kv[0], options[0], Setting.this, true);
}
}
}
});
_propTable.addProperty(item);
currentProps.put(kv[1], item);
}
public void loadString(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr String name,@NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addProperty(new QPropertyBrowser.QtVariantProperty(),QVariant.String, kv[0]);
item.setTagObject(new ItemValue(xp));
_propTable.addProperty(item);
item.setValue(getSetting(nilptr, kv[1]));
currentProps.put(kv[1], item);
}
public void loadBoolean(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr String name,@NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addEnumProperty(new QPropertyBrowser.QtVariantProperty(), kv[0]);
item.setTagObject(new ItemValue(xp));
item.setFlags(1);
String selvalue = getSetting(nilptr , kv[1]);
if (selvalue != nilptr){
if (selvalue.equals("True")){
selvalue = "1";
}else{
selvalue = "0";
}
}
String [] options = {"否(False)", "是(True)"};
item.setAttributeEnumNames(options);
item.setValue(selvalue);
_propTable.addProperty(item);
currentProps.put(kv[1], item);
}
public void loadOptions(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr String name,@NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addEnumProperty(new QPropertyBrowser.QtVariantProperty(), kv[0]);
JsonArray list = root.getArray("list");
if (list == nilptr){
return ;
}
item.setTagObject(new ItemValue(xp));
item.setFlags(1);
String selvalue = getSetting(nilptr , kv[1]);
if (selvalue != nilptr){
int count = list.length();
String addition = nilptr;
if (selvalue.length() == 0 || selvalue.equals("Not Set") || selvalue.equals("未设置")){
selvalue = "0";
}else{
bool bfound = false;
String ends = "(" + selvalue + ")";
for (int i = 0; i < list.length(); i++){
String szItem = list.getString(i);
if (szItem != nilptr){
if (szItem.endsWith(ends) || szItem.equals(selvalue)){
selvalue = "" + i;
bfound = true;
break;
}
}
}
if (!bfound){
count++;
addition = ends;
selvalue = "" + list.length();
}
}
String [] options = new String[count];
for (int i = 0;i < list.length(); i++){
options[i] = list.getString(i);
}
if (addition != nilptr){
options[count - 1] = "未知" + addition;
}
item.setAttributeEnumNames(options);
item.setValue(selvalue);
}
_propTable.addProperty(item);
currentProps.put(kv[1], item);
}
public void loadKeySequence(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr String name,@NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addProperty(new QPropertyBrowser.QtVariantProperty(),QVariant.KeySequence, kv[0]);
item.setTagObject(new ItemValue(xp));
_propTable.addProperty(item);
item.setValue(getSetting(nilptr, kv[1]));
currentProps.put(kv[1], item);
}
public static String splitColor(@NotNilptr String text){
if (text.startsWith("#")){
if (text.length() == 7){
return "ff" + text.substring(5,7) + text.substring(3,5) + text.substring(1,3);
}
if (text.length() == 9){
return text.substring(1,3) + text.substring(7,9) + text.substring(5,7) + text.substring(3,5);
}
}else
if (text.startsWith("0x")){
return text.substring(2,text.length());
}
return "ff000000";
}
public static String getColor(@NotNilptr String text,@NotNilptr String prefix){
if (text.startsWith(prefix)){
return text;
}
if (text.startsWith("#")){
if (prefix.equals("0x")){
return prefix + splitColor(text);
}
return "0xff000000";
}
if (text.startsWith("0x")){
if (prefix.equals("#")){
return prefix + splitColor(text.replace("0x", prefix));
}
return "#ff000000";
}
text = text.replace("[", "").replace("]", "").replace("(", ",").replace(")", "");
String [] colors = text.split(',');
if (colors.length == 4){
for (int i = 0; i < 4; i++){
colors[i] = String.format("%02X", colors[i].trim(true).parseInt());
}
String outcolor = "";
if (prefix.equals("0x")){
outcolor = prefix + colors[3] + colors[2] + colors[1] + colors[0];
}else{
outcolor = prefix + colors[3] + colors[0] + colors[1] + colors[2];
}
return outcolor;
}
return prefix + "00000000";
}
public void loadColor(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr String name, JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addProperty(new QPropertyBrowser.QtVariantProperty(),QVariant.Color, kv[0]);
item.setTagObject(new ItemValue(xp));
QPropertyBrowser.QtBrowserItem pitem = _propTable.addProperty(item);
_propTable.setItemExpand(pitem,false);
String strvalue = getSetting(nilptr, kv[1]);
item.setValue(getColor(strvalue, "#"));
currentProps.put(kv[1], item);
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(){
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
preference.setSetting(kv[1], stringValue);
syntaxForXlang();
}
}
});
}
public void loadStringList(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager, @NotNilptr String name, @NotNilptr JsonObject root, ItemRecord xp){
String [] kv = name.split(':');
QPropertyBrowser.QtVariantProperty item = (QPropertyBrowser.QtVariantProperty)manager.addEnumProperty(new QPropertyBrowser.QtVariantProperty(), kv[0]);
JsonArray list = root.getArray("list");
item.setTagObject(new ItemValue(xp));
if (list != nilptr){
String [] options = new String[list.length()];
for (int i = 0;i < options.length; i++){
options[i] = list.getString(i);
if (options[i].startsWith("$(")){
String svalue = options[i].substring(2,options[i].length() - 1);
options[i] = getSetting(nilptr, svalue);
}
}
item.setAttributeEnumNames(options);
String defaultValue = getSetting(options, kv[1]);
item.setValue(defaultValue);
_propTable.addProperty(item);
currentProps.put(kv[1], item);
onLoadList(manager,item, kv[1], defaultValue);
}
}
public void onLoadList(@NotNilptr QPropertyBrowser.QtVariantPropertyManager manager,@NotNilptr QPropertyBrowser.QtVariantProperty item,@NotNilptr String kv, String defaultValue){
if (kv.equals("style_color")){
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(){
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
if (stringValue.parseInt() > 1){
if (QMessageBox.Question("注意","加载选择的配色方案后,现有自定义配色设置将丢失?",QMessageBox.Yes,QMessageBox.No) == QMessageBox.Yes){
if (loadColorSet(stringValue.parseInt()) == false){
QMessageBox.Critical("注意","配色方案文件丢失,不能加载配色设置",QMessageBox.Ok,QMessageBox.Ok);
}
reloadProperty();
preference.setSetting("style_color", "自定义");
}else{
item.setValue("1");
}
}
}
}
});
}else
if (kv.equals("shortkeystyle")){
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(){
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
if (stringValue.parseInt() != 0){
if (QMessageBox.Question("注意","加载选择的键盘布局后,现有加速键设置将丢失?",QMessageBox.Yes,QMessageBox.No) == QMessageBox.Yes){
if (loadKeyMap(stringValue.parseInt()) == false){
QMessageBox.Critical("注意","加速键配置文件丢失,不能加载键盘布局",QMessageBox.Ok,QMessageBox.Ok);
}
reloadProperty();
preference.setSetting("shortkeystyle", "0");
}else{
item.setValue("0");
}
}
}
}
});
}else
if (kv.equals("editorfont")){
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(){
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
if (stringValue.parseInt() != 0){
item.setValue(defaultValue);
flushSetting();
String newFont = QFontDialog.getFontDialog("选择字体",getSetting(nilptr,"editorfont"),Setting.this);
if (newFont != nilptr){
preference.setSetting("editorfont", newFont);
reloadProperty();
}else{
item.setValue("0");
}
}
}
}
});
}else
if (kv.equals("workspace")){
manager.setPropertyEventListener(item,
new QPropertyBrowser.PropertyManager.onPropertyEventListener(){
void onVariantPropertyValueChanged(long prop, int dataType, String stringValue)override{
if (stringValue != nilptr){
if (stringValue.parseInt() != 0){
item.setValue(defaultValue);
flushSetting();
String newFont = QFileDialog.getFolderPath("选择默认工作空间",getSetting(nilptr,"workspace"),nilptr,Setting.this);
if (newFont != nilptr){
preference.setSetting("workspace", newFont);
reloadProperty();