-
Notifications
You must be signed in to change notification settings - Fork 0
/
gifded.vala
2349 lines (2159 loc) · 81.2 KB
/
gifded.vala
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
// script Q
// by cpbrown 2022
// todo next: finish assigning standard gtk icons
using Gtk;
// globals.................... andwhy
bool doup; // used to block ui signals everywhere
GtkSource.View htmloutput; // the output html, needed to show parser results, used everywhere
GtkSource.Buffer htmlbuff; // the buffer for the above, needed to switch syntax, used everywhere
GtkSource.View datoutput; // data output viewer, needed to show parser internals, used everywhere
ParserBox[] allt; // the nodes, gets created & destroyed by the user, prodded & poked by everything
ParserBox[] tempallt; // temp list for removing stuff from the above
Gtk.Box parserslist; // the node container, used to contain allt, frequently hosed, rebuilt & re-ordered
int selectednode; // currently selected node, used for add, remove, duplicate, move... super important
Gtk.Paned vdiv; // the splitter, needed to reflow node params
Gtk.Stack outputstack; // the output panels, needed to see what should be displayed by the node
//Gtk.WebView webrenderer; // testing this... oh its 1 gen behind, try again with gtk5
// do python
string dopy (string[] a) {
try {
string o;
Pid p;
GLib.Process.spawn_sync (null,a,null,SpawnFlags.SEARCH_PATH,null,out o,null,out p);
print("process %d started...\n", p);
return o;
} catch (SpawnError e) { print ("Error: %s\n", e.message); }
return "";
}
// separate fn for the reeb, just in case...
string doreeb (string[] a) {
try {
string o;
Pid p;
// go reeeeeeb, you can do it mate...
GLib.Process.spawn_sync (null,a,null,SpawnFlags.SEARCH_PATH,null,out o,null,out p);
print("process %d started...\n", p);
return o;
} catch (SpawnError e) { print ("Error: %s\n", e.message); }
return "";
}
// shell script
string dosh (string[] a) {
try {
foreach (string v in a) {
print("dosh: \targ = %s\n",v);
}
//string[] env = Environ.get(); // has no effect
//string here = GLib.Environment.get_current_dir(); // has no effect
//here = here.concat("/");
//print("here = %s\n", here);
string o;
Pid p;
GLib.Process.spawn_sync (null,a,null,SpawnFlags.SEARCH_PATH,null,out o,null,out p);
print("process %d started...\n", p);
return o;
} catch (SpawnError e) { print ("Error: %s\n", e.message); return "Error: %s\n".printf(e.message); }
return "";
}
// some commonly used functions
string getfilenamefile (string f) {
if (f != null) {
if (f.strip() != "") {
string[] fp = f.strip().split("/");
if (fp.length > 1) {
string[] pp = fp[(fp.length - 1)].split(".");
return pp[0];
}
}
}
return "";
}
string getfileext (string f) {
if (f != null) {
if (f.strip() != "") {
string[] fp = f.strip().split("/");
if (fp.length > 1) {
string[] pp = fp[(fp.length - 1)].split(".");
return pp[(pp.length - 1)];
}
}
}
return "";
}
File getfiledir (string f) {
string o = "";
File x = File.new_for_path(o);
if (f != null) {
if (f.strip() != "") {
string[] fp = f.strip().split("/");
if (fp.length > 1) {
for (int l = 0; l < (fp.length - 1); l++) {
o = o.concat(fp[l],"/");
}
}
x = File.new_for_path(o);
return x;
}
}
return x;
}
// load ui from an org file... its stupid but funny
void spawnuifromorg (string o) {
// assumes allt and parsersbox have been hosed by the calling event
string[] lines = o.split("\n");
bool amnode = false;
bool amprop = false;
bool amsrc = false;
bool amres = false;
bool spoolsrc = false;
bool spoolres = false;
string nom = "";
int idx = 0;
int typ = 0;
bool frz = false;
bool hoi = true;
bool pui = false;
string pre = "";
string lod = "";
string rex = "";
string cex = "";
string lex = "";
string src = "";
string res = "";
int nodecount = 0;
int srcspooldepth = 0;
int resspooldepth = 0;
// use a counter to add nodes
// exampled * and # should be prefixed with , for the highlighter and org itself
// +---------------------------+---------------------------------------------------------+
// | [A][C] LINE | NOTE |
// +---------------------------+---------------------------------------------------------+
// | [0][1] * node | ** node [C+=1] |
// | [0][1] ** code | |
// +--------------------+------+ |
// | [0][1] ** result | | |
// | [1][2] * node |// | END_OF_NODE AND C>A [A += NODE] ** node [C+=1] |
// | [1][2] ** code |// | |
// | [1][2] ** result |// | |
// | [2][3] * node |//// | END_OF_NODE AND C>A [A += NODE] ** node [C+=1] |
// | [2][3] ** code |//// | |
// | [2][3] ** result |//// | |
// | [3][3] |//////| END_OF_NODE AND C>A [A += NODE] |
// +--------------------+------+---------------------------------------------------------+
foreach (string l in lines) {
//if (amprop == false) { print("LINE=%s\n",l); }
if (l.get_char(0) == '*' && l.get_char(1) == ' ') {
print("\nheadline found : %s\n",l);
print("\tamnode = %s\n",amnode.to_string());
print("\tamprop = %s\n",amprop.to_string());
print("\tamsrc = %s\n",amsrc.to_string());
print("\tspoolsrc = %s\n",spoolsrc.to_string());
print("\tsrcspooldepth = %d\n",srcspooldepth);
print("\tamres = %s\n",amres.to_string());
print("\tspoolres = %s\n",spoolres.to_string());
print("\tresspooldepth = %d\n",resspooldepth);
print("\tnodecount = %d\n",nodecount);
print("\tallt.length = %d\n",allt.length);
print("\n");
}
if (amnode == false && amres == false && amprop == false && amsrc == false && srcspooldepth == 0 && resspooldepth == 0 && spoolsrc == false && spoolres == false) {
if (nodecount > allt.length) {
print("ADD NODE %s\n",nom);
ParserBox nn = new ParserBox(idx, nom, typ, frz, hoi, pui, pre, lod, cex, rex, lex, src, res);
allt += nn;
amnode = false;
amprop = false;
amsrc = false;
amres = false;
spoolsrc = false;
spoolres = false;
srcspooldepth = 0;
resspooldepth = 0;
nom = "";
idx = 0;
typ = 0;
frz = false;
hoi = true;
pui = false;
pre = "";
lod = "";
rex = "";
lex = "";
cex = "";
src = "";
res = "";
}
if (l.get_char(0) == '*' && l.get_char(1) == ' ') {
print("\n");
nom = l.replace("*","").strip();
print("\tnom = %s\n", nom);
amnode = true;
nodecount += 1;
//print("\tnodecount = %d\n",nodecount);
//print("\n");
continue;
}
}
if (amnode) {
if (l.strip() == ":PROPERTIES:") { amprop = true; }
if (amprop) {
if (l.length >= 5) {
string chk = l.substring(0,5);
// save order:
//:PROPERTIES: :TYP: :FRZ: :HOI: :PUI: :LOD: :PRE: :LEX: :CEX: :REX: :END:
if (chk == ":END:") { amprop = false; print("\n"); continue; }
if (chk == ":TYP:") { string huh = l.substring(5,((l.length)) - 5).strip(); typ = int.parse(huh); print("\ttyp = %d\n",typ); }
if (chk == ":FRZ:") { string huh = l.substring(5,((l.length)) - 5).strip(); frz = int.parse(huh) == 1; if (frz) { print("\tfrz = true\n"); } else { print("\tfrz = false\n"); } }
if (chk == ":HOI:") { string huh = l.substring(5,((l.length)) - 5).strip(); hoi = int.parse(huh) == 1; if (hoi) { print("\thoi = true\n"); } else { print("\thoi = false\n"); } }
if (chk == ":PUI:") { string huh = l.substring(5,((l.length)) - 5).strip(); pui = int.parse(huh) == 1; if (pui) { print("\tpui = true\n"); } else { print("\tpui = false\n"); } }
if (chk == ":LOD:") { string huh = l.substring(5,((l.length)) - 5).strip(); lod = huh; print("\tlod = %s\n",lod); }
if (chk == ":PRE:") { string huh = l.substring(5,((l.length)) - 5).strip(); pre = huh; print("\tpre = %s\n",pre); }
if (chk == ":LEX:") { string huh = l.substring(5,((l.length)) - 5).strip(); lex = huh; print("\tlex = %s\n",lex); }
if (chk == ":CEX:") { string huh = l.substring(5,((l.length)) - 5).strip(); cex = huh; print("\tcex = %s\n",cex); }
if (chk == ":REX:") { string huh = l.substring(5,((l.length)) - 5).strip(); rex = huh; print("\trex = %s\n",rex); }
} else { amprop = false; continue; }
}
if (spoolsrc == false && spoolres == false) {
if (l.length >= 7) {
if (l.substring(0,7) == "** code") { amprop = false; amsrc = true; spoolsrc = false; amres = false; spoolres = false; continue;}
}
if (l.length >= 9) {
if (l.substring(0,9) == "** result") { amprop = false; spoolsrc = false; amsrc = false; amres = true; spoolres = false; continue; }
}
}
if (amsrc) {
// using a counter to handle orgception
// exampled * and # should be prefixed with , for the highlighter and org itself
// +-----------------------+---------------------------------------------------------+
// | [S][R] LINE | NOTE |
// +-----------------------+---------------------------------------------------------+
// | [0][0] ** code | ** code AND S==0 [ |
// | [1][0] #+BEGIN | #+BEGIN [S+=1] s==1 AND #+BEGIN [START_READ NEXT] |
// +--------------------+--+ |
// | [1][1] ** code |>>| |
// | [2][1] #+BEGIN |>>| #+BEGIN [S+=1] |
// | [2][1] some code |>>| |
// | [1][1] #+END |>>| #+END [S-=1] |
// +--------------------+--+ |
// | [0][0] #+END | #+END [S-=1] #+END AND S==0 [STOP_READ] |
// | | ] |
// +-----------------------+---------------------------------------------------------+
if (l.length >= 5) {
if (l.substring(0,5) == "#+BEG") {
srcspooldepth += 1;
if (srcspooldepth == 1) {
spoolsrc = true;
continue;
}
}
if (l.substring(0,5) == "#+END") {
srcspooldepth -= 1;
if (srcspooldepth == 0) {
spoolsrc = false;
amsrc = false;
continue;
}
}
}
if (spoolsrc) {
src = src.concat(l,"\n");
}
}
if (amres) {
if (l.length >= 5) {
if (l.substring(0,5) == "#+BEG") {
resspooldepth += 1;
if (resspooldepth == 1) {
spoolres = true;
continue;
}
}
if (l.substring(0,5) == "#+END") {
resspooldepth -= 1;
if (resspooldepth == 0) {
spoolres = false;
amres = false;
// res is the last thing we need, so break out of the node, incrament to add a parser using collected data
amnode = false;
nodecount += 1;
continue;
}
}
}
if (spoolres) {
res = res.concat(l,"\n");
}
}
}
}
}
// the parser 'node'
public class ParserBox : Gtk.Box {
private Gtk.Box headbox;
private Gtk.Entry nameentry;
private Gtk.ScrolledWindow srcscroll;
private Gtk.DropDown oplist;
private Gtk.ToggleButton enableswitch;
private Gtk.ToggleButton isotoggle;
public GtkSource.View srctext;
private Gtk.TextTagTable srctextbufftags;
private GtkSource.Buffer srctextbuff;
private Pango.TabArray srctab;
private Gtk.Box scrollbox;
private Gtk.Button evalbutton;
private Gtk.Box headflow;
private Gtk.Box firstbox;
private Gtk.Box secondbox;
private Gtk.Box thirdbox;
private Gtk.Box firstrow;
private Gtk.Box secondrow;
private Gtk.Box thirdrow;
private Gtk.Box filebox;
private Gtk.Entry fileentry;
private Gtk.MenuButton filebutton;
private Gtk.Popover filepop;
private Gtk.Box filepopbox;
private Gtk.GestureClick fileclick;
private Gtk.Box presetbox;
private Gtk.Entry presetentry;
private Gtk.MenuButton presetbutton;
private Gtk.Popover presetpop;
private Gtk.Box presetpopbox;
private Gtk.Button presetsave;
private Gtk.GestureClick presetclick;
private Gtk.GestureClick thisclick;
private GLib.Dir dcr;
private Gtk.ToggleButton foldbutton;
private Gtk.CssProvider fesp;
private Gtk.CssProvider hosp;
private string fess;
private string hoss;
private bool thf;
private bool twf;
private bool tnf;
private string extname (string e) {
string o = "html";
switch (e) {
case "txt" : o = "text"; break;
case "htm" : o = "html"; break;
case "py" : o = "python"; break;
case "r3" : o = "rebol"; break;
case "r" : o = "rebol"; break;
case "reb" : o = "rebol"; break;
case "sh" : o = "sh"; break;
case "xml" : o = "xml"; break;
case "org" : o = "orgmode"; break;
default : o = "html"; break;
}
return o;
}
private string exttype (string e) {
string o = "html";
switch (e) {
case "text" : o = "txt"; break;
case "html" : o = "html"; break;
case "python" : o = "py"; break;
case "rebol" : o = "r3"; break;
case "sh" : o = "sh"; break;
case "xml" : o = "xml"; break;
case "orgmode" : o = "org"; break;
default : o = "html"; break;
}
return o;
}
private void evalnode (string l, int i, bool v) {
print("\tevalnode: started: i = %d\n", i);
print("\tevalnode:\tincoming source.length = %d\n", l.length);
string rets = "";
bool allgood = true;
// loaders are native hardcoded vala
if (allt[i].typ == 0) {
if (allt[i].lod != null) {
if (allt[i].lod.strip() != "") {
File lodfile = File.new_for_path(allt[i].lod);
if (lodfile.query_exists() == true) {
try {
uint8[] c; string e;
lodfile.load_contents (null, out c, out e);
rets = (string) c;
//allt[i].res = (string) c;
print ("\tevalnode:\tload node successfully loaded file %s...\n",allt[i].lod);
allgood = true;
} catch (Error e) {
print ("\tevalnode:\tfailed to read %s: %s\n", lodfile.get_path(), e.message);
}
} else { print("\tevalnode:\t%s doesn't exist, aborting...\n",allt[i].lod); }
} else { print("\tevalnode:\tlod %s is empty, aborting...\n",allt[i].lod); }
} else { print("\tevalnode:\tlod is null, aborting...\n"); }
}
// savers are native hardcoded vala
if (allt[i].typ == 1) {
allgood = false;
if (allt[i].lod != null) {
if (allt[i].lod.strip() != "") {
rets = l;
File lodfile = File.new_for_path(allt[i].lod);
File loddir = getfiledir(allt[i].lod);
if (lodfile.query_exists() == true) {
lodfile.delete();
} else {
try {
loddir.make_directory_with_parents();
} catch (Error e) { print("\tevalnode:\tmake_dir error: %s\n", e.message); }
}
if (loddir.query_exists() == true) {
FileOutputStream lodstream = lodfile.replace(null, false, FileCreateFlags.PRIVATE);
try {
lodstream.write(l.data);
allt[i].res = l;
fess = ".xx { background: #00FF0020; }";
fesp.load_from_data(fess.data);
} catch (Error e) {
rets = e.message; print("\tevalnode:\tfilestream error: %s\n",rets);
}
} else { print("\tevalnode:\tlod file couldn't be created, aborting...\n"); }
} else { print("\tevalnode:\tlod is empty, aborting...\n"); }
} else { print("\tevalnode:\tlod is null, aborting...\n"); }
}
if (allt[i].typ > 1) {
if (allt[i].cex == "html" || allt[i].cex == "text" || allt[i].cex == "xml") {
print("\tevalnode:\tinsert into html...\n");
rets = allt[i].src.replace("<!--[lastres]-->",l);
allgood = true;
} else {
if (allt[i].src != null) {
if (allt[i].src.strip() != "") {
if (l.length > 0) {
bool doit = true;
print("\tevalnode:\tsrc.length = %d\n", allt[i].src.length);
var ddd = GLib.Environment.get_current_dir();
string eee = exttype(allt[i].cex);
string ttt = "temp.%s".printf(eee);
print("\tevalnode:\ttempfilename is : %s\n", ttt);
var ppp = Path.build_filename (ddd, ttt);
File tempfile = File.new_for_path(ppp);
if (tempfile.query_exists() == true) {
try {
tempfile.delete();
} catch (Error e) {
print("\tevalnode:\ttfailed to delete old tempfile: %s\n", ((string) tempfile.get_path()));
doit = false;
}
}
FileOutputStream tempstream = null;
try {
tempstream = tempfile.replace (null, false, FileCreateFlags.PRIVATE);
tempstream.write(allt[i].src.data);
} catch (Error e) {
print("\tevalnode:\ttfailed to write filestream: %s\n", ttt);
doit = false;
}
File temppath = File.new_for_path (ddd.concat("/temp/"));
if (temppath.query_exists() == false) {
try {
temppath.make_directory_with_parents();
} catch (Error e) {
print("\tevalnode:\ttfailed to makedirs: %s\n", ((string) temppath.get_path()));
doit = false;
}
}
string tmpn = allt[i].nom.replace(" ","_");
string rrt = "%s.tmp".printf(tmpn);
print("\tevalnode:\tlastres temp filename is : %s\n", rrt);
var rrr = Path.build_filename (ddd.concat("/temp/"), rrt);
File tempresfile = File.new_for_path(rrr);
if (tempresfile.query_exists() == true) {
try {
tempresfile.delete();
} catch (Error e) {
print("\tevalnode:\ttfailed to delete old tempfile: %s\n", ((string) tempresfile.get_path()));
doit = false;
}
}
FileOutputStream tempresstream = null;
try {
tempresstream = tempresfile.replace (null, false, FileCreateFlags.PRIVATE);
tempresstream.write(l.data);
} catch (Error e) {
print("\tevalnode:\ttfailed to write filestream: %s\n", rrr);
doit = false;
}
if (doit) {
if (allt[i].cex == "python") {
print("\tevalnode:\tcalling python...\n");
string cmd = "".concat("python3 ", ppp, " ", rrr);
string[] cmda = {"python3", ppp, rrr};
rets = dopy(cmda);
allgood = true;
}
if (allt[i].cex == "rebol") {
print("\tevalnode:\tcalling the reeb...\n");
string cmd = "".concat("./r3 ", ppp, " ", rrr);
string[] cmda = {"./r3", ppp, rrr};
rets = doreeb(cmda);
allgood = true;
}
if (allt[i].cex == "sh") {
print("\tevalnode:\tcalling the shell...\n");
string cmd = "".concat("sh ", ppp, " ", rrr);
string[] cmda = {"sh", ppp, rrr};
rets = dosh(cmda);
allgood = true;
}
} else { print("\tevalnode:\tfailed to write outputstreams...\n"); }
} else { print("\tevalnode:\tno source in %s node %s...\n",allt[i].cex,allt[i].nom); }
} else { print("\tevalnode:\tinput for %s node %s is empty...\n",allt[i].cex,allt[i].nom); }
} else { print("\tevalnode:\tsource in %s node %s is null...\n",allt[i].cex,allt[i].nom); }
}
}
if (allgood) {
allt[i].res = "";
if (rets != null) {
if (rets.strip() != "") {
allt[i].res = rets;
string[] rtl = rets.split("\n");
// autodetect type of output, save they type to rex, which is used for org export of the scenario, and sytnax highlighting
if (rtl.length >= 1) {
print("\tevalnode:\twrote %d lines to %s.res\n",rtl.length,allt[i].nom);
// set fallback to text, then ransack returned strings for identifiers...
print("\tevalnode:\tdetermining filetype of returned output...\n");
allt[i].rex = "text";
for(int j = 0; j < rtl.length; j++) {
if (rtl[j].length > 7) {
if (rtl[j].contains("<!DOCTYPE HTML")) { allt[i].rex = "html"; break; }
if (rtl[j].contains("<?xml")) { allt[i].rex = "xml"; break; }
if (rtl[j].substring(0,7) == "import ") { allt[i].rex = "python"; break; }
if (rtl[j].substring(0,4) == "def ") { allt[i].rex = "python"; break; }
if (rtl[j].substring(0,5) == "REBOL") { allt[i].rex = "rebol"; break; }
if (rtl[j].contains("-*-")) {
if (rtl[j].contains("mode: org")) { allt[i].rex = "orgmode"; break; }
if (rtl[j].contains("mode:org")) { allt[i].rex = "orgmode"; break; }
}
}
// break if nothing is found in the 1st 100 lines, suckshit if there's heaps of commentary
if (j > 100) { break; }
}
print("\tevalnode:\toutput is probably %s\n", ((string) allt[i].rex));
if (v) {
if (allt[i].rex != null) {
print("\tevalnode:\tsetting output syntax highlighter...\n");
if (allt[i].rex == "orgmode") {
htmlbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-orgmode"));
htmlbuff.set_language(GtkSource.LanguageManager.get_default().get_language("orgmode"));
}
if (allt[i].rex == "rebol") {
htmlbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-gifded"));
htmlbuff.set_language(GtkSource.LanguageManager.get_default().get_language("rebol"));
}
if (allt[i].rex == "python") {
htmlbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
htmlbuff.set_language(GtkSource.LanguageManager.get_default().get_language("python"));
}
if (allt[i].rex == "sh") {
htmlbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
htmlbuff.set_language(GtkSource.LanguageManager.get_default().get_language("sh"));
}
if (allt[i].rex == "html") {
htmlbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
htmlbuff.set_language(GtkSource.LanguageManager.get_default().get_language("html"));
}
if (allt[i].rex == "xml") {
htmlbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
htmlbuff.set_language(GtkSource.LanguageManager.get_default().get_language("xml"));
}
if (allt[i].rex == "text") {
htmlbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
htmlbuff.set_language(GtkSource.LanguageManager.get_default().get_language("text"));
}
if (allt[i].rex.strip() == "") {
htmlbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
htmlbuff.set_language(GtkSource.LanguageManager.get_default().get_language("html"));
}
print("\tevalnode:\twriting to output buffer...\n");
htmloutput.buffer.text = rets;
//if (allt[i].red == "html") { webrenderer.load_html(rets); }
print("\tevalnode:\tdone.\n\n");
}
} else { print("\tevalnode:\t dont write unselected node output to output buffer...\n"); if (v) { htmloutput.buffer.text = ""; } }
} else { print("\tevalnode:\teval returned empty string...\n"); if (v) { htmloutput.buffer.text = ""; } }
} else { print("\tevalnode:\teval returned empty string...\n"); if (v) { htmloutput.buffer.text = ""; } }
} else { print("\tevalnode:\teval returned null...\n"); if (v) { htmloutput.buffer.text = ""; } }
} else { print("\tevalnode:\tnothing was evaluated...\n"); if (v) { htmloutput.buffer.text = ""; } }
//print("\tevalnode: allt[%d].res = \n%s\n",i,((string) allt[i].res));
}
public void orgmydat () {
if (idx == selectednode) {
if (outputstack.visible_child_name == "data") {
string odat = "* %s\n".printf((string) nom);
odat = odat.concat(":PROPERTIES:\n");
odat = odat.concat(":IDX: %s\n".printf(idx.to_string()));
odat = odat.concat(":TYP: %s\n".printf(typ.to_string()));
odat = odat.concat(":FRZ: %s\n".printf(frz.to_string()));
odat = odat.concat(":HOI: %s\n".printf(hoi.to_string()));
odat = odat.concat(":PUI: %s\n".printf(pui.to_string()));
odat = odat.concat(":PRE: %s\n".printf((string) pre));
odat = odat.concat(":LOD: %s\n".printf((string) lod));
odat = odat.concat(":LEX: %s\n".printf((string) lex));
odat = odat.concat(":CEX: %s\n".printf((string) cex));
odat = odat.concat(":REX: %s\n".printf((string) rex));
odat = odat.concat(":END:\n");
// something in here is causing a segfault
odat = odat.concat("** code\n");
odat = odat.concat("#+BEGIN_SRC %s\n".printf((string) cex));
if (src != null) {
if (src.strip() != "") {
string[] srclines = src.split("\n");
if (srclines.length > 1) {
foreach (string sl in srclines) { odat = odat.concat("%s\n".printf(sl)); }
} else { odat = odat.concat("%s\n".printf(src)); }
}
}
odat = odat.concat("#+END_SRC\n");
odat = odat.concat("** result\n");
if (rex == "orgmode") {
odat = odat.concat("#+BEGIN_EXAMPLE\n");
} else {
odat = odat.concat("#+BEGIN_SRC %s\n".printf(rex));
}
if (res != null) {
if (res.strip() != "") {
string[] reslines = res.split("\n");
if (reslines.length > 1) {
foreach (string rl in reslines) { odat = odat.concat("%s\n".printf(rl)); }
} else { odat = odat.concat("%s\n".printf(res)); }
}
}
if (rex == "orgmode") {
odat = odat.concat("#+END_EXAMPLE\n");
} else {
odat = odat.concat("#+END_SRC\n");
}
datoutput.buffer.set_text(odat);
}
}
}
public void selectme(int ix) {
foreach (ParserBox n in allt) {
if (n.idx != ix) {
n.myc = ".xx { background: #E0E0E010; box-shadow: 2px 2px 2px #00000066; }";
n.myp.load_from_data(n.myc.data);
} else {
n.myc = ".xx { background: #88DDFF20; box-shadow: 2px 2px 2px #00000066; }";
n.myp.load_from_data(n.myc.data);
}
}
// super fucking important to set this correctly
selectednode = ix;
//print("\nSELECTED NODE IS %d\n",selectednode);
}
public void reflowparams (int sx) {
// cause flowbox is just a shitty nxn grid
if (thf) {
if (sx > (thirdbox.width_request + secondbox.width_request)) {
var th = thirdrow.get_last_child();
thirdrow.remove(th);
secondrow.append(th);
thf = false;
}
}
if (twf) {
if (sx > (firstbox.width_request + secondbox.width_request)) {
var tw = secondrow.get_first_child();
secondrow.remove(tw);
firstrow.append(tw);
twf = false;
}
}
if (tnf) {
if (sx > (firstbox.width_request + secondbox.width_request + thirdbox.width_request)) {
var tn = secondrow.get_first_child();
secondrow.remove(tn);
firstrow.append(tn);
tnf = false;
}
}
if ((sx - 40) < (firstbox.width_request + secondbox.width_request + thirdbox.width_request)) {
if (tnf == false) {
var tn = firstrow.get_last_child();
firstrow.remove(tn);
secondrow.append(tn);
tnf = true;
}
}
if ((sx - 40) < (firstbox.width_request + secondbox.width_request)) {
if (twf == false) {
var tn = firstrow.get_last_child();
firstrow.remove(tn);
tn.insert_before(secondrow,secondrow.get_first_child());
twf = true;
}
}
if ((sx - 40) < (secondbox.width_request + thirdbox.width_request)) {
if (thf == false) {
var tn = secondrow.get_last_child();
secondrow.remove(tn);
thirdrow.append(tn);
thf = true;
}
}
}
public string nom; // the node name - used for the org headline on save, otherwise not important
public int idx; // the node index - important for anything that needs a node selection
public string src; // the parser code - gets evaluated
public string res; // result of node eval - used by the next node
public string cex; // file type of code - used for syntax highlighting, org-block type
public string rex; // file type of eval output - used for saving/export/viewing
public int typ; // sourceview file type menu index - used to initialize ui
public bool frz; // freze node - used to initialize ui, block changes, prevent eval
public bool hoi; // on/off - used to initialize ui, skipped in eval stack
public bool pui; // fold/expand - used to initialize ui, cosmetic
public string pre; // path to preset - used to initialize ui, for quick save
public string lod; // file to load, if any - used to initialize ui, used for load and save
public string lex; // file type of loaded file - used for saving/export/viewing
public string myc; // my css string - used for parser selection tint
public Gtk.CssProvider myp; // my css provider - gtk oop shitfuckery for the above
// ParserBox (idx, nom, typ, frz, hoi, pui, pre, lod, cex, rex, lex, src, res );
public ParserBox (int ii, string nn, int tt, bool ff, bool hh, bool pp, string ee, string oo, string cc, string xx, string ll, string ss, string rr) {
nom = nn;
idx = ii;
typ = tt;
frz = ff;
hoi = hh;
pui = pp;
pre = ee;
lod = oo;
cex = cc;
rex = xx;
lex = ll;
src = ss;
res = rr;
thf = true;
twf = true;
tnf = true;
this.set_orientation(VERTICAL);
this.spacing = 10;
this.vexpand = false;
// selection tint
myp = new Gtk.CssProvider();
myc = ".xx { background: #E0E0E010; box-shadow: 2px 2px 2px #00000066; }";
myp.load_from_data(myc.data);
this.get_style_context().add_provider(myp, Gtk.STYLE_PROVIDER_PRIORITY_USER);
this.get_style_context().add_class("xx");
thisclick = new Gtk.GestureClick();
this.add_controller(thisclick);
thisclick.pressed.connect(() => {
if (idx >= 0) {
selectme(idx);
orgmydat();
}
});
// parser name
nameentry = new Gtk.Entry();
nameentry.changed.connect(() => {
if (doup && frz != true) {
doup = false;
if (nameentry.text != null) {
if (nameentry.text.strip() != "") {
nom = nameentry.text;
}
}
doup = true;
}
});
// parser type
oplist = new Gtk.DropDown(null,null);
// Load and Save must come 1st...
oplist.set_model(new Gtk.StringList({"Load", "Save", "html", "xml", "python", "rebol", "sh", "text"}));
oplist.set_selected(tt);
oplist.notify["selected"].connect(() => {
if (doup && frz != true) {
doup = false;
var n = oplist.get_selected();
cex = ((StringObject?) oplist.selected_item).string;
typ = ((int) n);
if (typ < 2) {
scrollbox.visible = false;
filebox.visible = true;
presetbox.visible = false;
res = null; rex = null;
src = null;
cex = "sh";
lod = null;
lex = null;
pre = null;
presetentry.text = "";
fess = ".xx { background: #FF000020; }";
fesp.load_from_data(fess.data);
fileentry.text = "";
orgmydat();
} else {
filebox.visible = false;
scrollbox.visible = true;
presetbox.visible = true;
if (cex == "python") {
srctextbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
srctextbuff.set_language(GtkSource.LanguageManager.get_default().get_language("python"));
}
if (cex == "rebol") {
srctextbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-gifded"));
srctextbuff.set_language(GtkSource.LanguageManager.get_default().get_language("rebol"));
}
if (cex == "sh") {
srctextbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
srctextbuff.set_language(GtkSource.LanguageManager.get_default().get_language("sh"));
}
if (cex == "html") {
srctextbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
srctextbuff.set_language(GtkSource.LanguageManager.get_default().get_language("html"));
}
if (cex == "text") {
srctextbuff.set_style_scheme(GtkSource.StyleSchemeManager.get_default().get_scheme("Adwaita-dark"));
srctextbuff.set_language(GtkSource.LanguageManager.get_default().get_language("text"));
}
pre = null;
presetentry.text = "";
lod = null;
lex = null;
fileentry.text = "";
res = null; rex = null;
orgmydat();
}
doup = true;
}
});
// parser lock/unlock
isotoggle = new Gtk.ToggleButton();
isotoggle.icon_name = "system-lock-screen";
isotoggle.set_active(ff);
isotoggle.toggled.connect(() => {
print("%s.isotoggle.state is %s\n", nom, isotoggle.active.to_string());
frz = isotoggle.active;
print("%s.frz is %s\n", nom, frz.to_string());
bool a = (frz != true);
nameentry.set_sensitive(a);
oplist.set_sensitive(a);
enableswitch.set_sensitive(a);
srctext.set_sensitive(a);
evalbutton.set_sensitive(a);
fileentry.set_sensitive(a);
filebutton.set_sensitive(a);
presetentry.set_sensitive(a);
presetbutton.set_sensitive(a);
presetsave.set_sensitive(a);
orgmydat();
});
// parser on/off
enableswitch = new Gtk.ToggleButton();
//enableswitch.icon_name = "media-playback-play";
enableswitch.set_active(hh);
hosp = new Gtk.CssProvider();
hoss = ".xx { background: #00FF0020; }";
enableswitch.get_style_context().add_provider(hosp, Gtk.STYLE_PROVIDER_PRIORITY_USER);
enableswitch.get_style_context().add_class("xx");
if (hh) {
hoss = ".xx { background: #00FF0020; }";
hosp.load_from_data(hoss.data);
enableswitch.icon_name = "media-playback-start";
} else {
hoss = ".xx { background: #AA000040; }";
hosp.load_from_data(hoss.data);
enableswitch.icon_name = "media-playback-pause";
}
enableswitch.toggled.connect(() => {
if (doup && frz != true) {
doup = false;
if (enableswitch.active) {
//enableswitch.set_label("HOI");
hoss = ".xx { background: #00FF0020; }";
hosp.load_from_data(hoss.data);
enableswitch.icon_name = "media-playback-start";
} else {
//enableswitch.set_label("OFF");
hoss = ".xx { background: #AA000040; }";
hosp.load_from_data(hoss.data);
enableswitch.icon_name = "media-playback-pause";
}
print("%s.enableswitch.state is %s\n", nom, enableswitch.active.to_string());
hoi = enableswitch.active;
print("%s.hoi is %s\n", nom, hoi.to_string());
orgmydat();
doup = true;
}
});
// parser fold/unfold
foldbutton = new Gtk.ToggleButton.with_label("-");
foldbutton.set_active(pp);
evalbutton = new Gtk.Button.with_label("evaluate");
nameentry.text = nn;
nameentry.hexpand = true;
// containers: params
headbox = new Gtk.Box(HORIZONTAL,10);
headbox.margin_top = 0;
headbox.margin_end = 0;
headbox.margin_start = 0;
headbox.margin_bottom = 0;
firstbox = new Gtk.Box(HORIZONTAL,0);
secondbox = new Gtk.Box(HORIZONTAL,0);
thirdbox = new Gtk.Box(HORIZONTAL,0);
firstbox.append(nameentry);
firstbox.append(evalbutton);
thirdbox.append(isotoggle);
thirdbox.append(enableswitch);
thirdbox.append(foldbutton);
secondbox.append(oplist);
firstbox.width_request = 150;
secondbox.width_request = 80;
thirdbox.width_request = 150;
firstrow = new Gtk.Box(HORIZONTAL,0);
secondrow = new Gtk.Box(HORIZONTAL,0);
thirdrow = new Gtk.Box(HORIZONTAL,0);
firstrow.append(firstbox);
secondrow.append(secondbox);
thirdrow.append(thirdbox);
secondrow.margin_top = 0;
secondrow.margin_end = 0;
secondrow.margin_start = 0;
secondrow.margin_bottom = 0;
thirdrow.margin_top = 0;
thirdrow.margin_end = 0;
thirdrow.margin_start = 0;
thirdrow.margin_bottom = 0;
headflow = new Gtk.Box(VERTICAL,0);
headflow.append(firstrow);
headflow.append(secondrow);
headflow.append(thirdrow);
headbox.append(headflow);
headflow.margin_top = 10;
headflow.margin_end = 10;
headflow.margin_start = 10;