fix vala code gen
[roobuilder] / src / Builder4 / Editor.bjs
1 {
2  "build_module" : "builder",
3  "items" : [
4   {
5    "# JsRender.JsRender? file" : "null",
6    "# JsRender.Node node" : "null",
7    "# JsRender.NodeProp? prop" : "null",
8    "# Xcls_MainWindow window" : "null",
9    "# bool dirty" : false,
10    "# bool pos" : false,
11    "# int pos_root_x" : "",
12    "# int pos_root_y" : "",
13    "# string activeEditor" : "\"\"",
14    "$ homogeneous" : false,
15    "$ xns" : "Gtk",
16    "* pack" : "add",
17    "@ void save" : "()",
18    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
19    "Gtk.SourceSearchContext searchcontext" : "null",
20    "bool hexpand" : true,
21    "bool vexpand" : true,
22    "int last_search_end" : 0,
23    "items" : [
24     {
25      "$ homogeneous" : false,
26      "$ xns" : "Gtk",
27      "* pack" : "pack_start,false,true",
28      "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
29      "items" : [
30       {
31        "$ xns" : "Gtk",
32        "* pack" : "pack_start,false,false",
33        "id" : "save_button",
34        "label" : "Save",
35        "listeners" : {
36         "clicked" : [
37          " () => { ",
38          "    _this.saveContents();",
39          "}",
40          "  "
41         ]
42        },
43        "xtype" : "Button"
44       },
45       {
46        "$ xns" : "Gtk",
47        "* pack" : "pack_start,true,true",
48        "bool editable" : false,
49        "id" : "key_edit",
50        "int width_request" : 100,
51        "xtype" : "Entry"
52       },
53       {
54        "$ xns" : "Gtk",
55        "* ctor" : "new Gtk.HScale.with_range (6, 30, 1)",
56        "* init" : [
57         "{",
58         "\tthis.el.set_range(6,30);",
59         "\tthis.el.set_value(8);",
60         "}",
61         ""
62        ],
63        "* pack" : "pack_end,true,true",
64        "bool draw_value" : true,
65        "bool has_origin" : true,
66        "bool sensitive" : true,
67        "int digits" : 0,
68        "listeners" : {
69         "change_value" : [
70          "(st, val ) => {",
71          "\t ",
72          "\t  var description =   Pango.FontDescription.from_string(\"monospace\");",
73          "\t  print(\"resize to %d\", (int)val*1000);",
74          "      description.set_size((int)val*1000);",
75          "      _this.view.el.override_font(description);",
76          "      return false;",
77          "}"
78         ]
79        },
80        "xtype" : "HScale"
81       }
82      ],
83      "xtype" : "Box"
84     },
85     {
86      "$ xns" : "Gtk",
87      "* init" : "this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
88      "* pack" : "pack_end,true,true",
89      "id" : "RightEditor",
90      "items" : [
91       {
92        "$ Gtk.SourceDrawSpacesFlags draw_spaces" : "Gtk.SourceDrawSpacesFlags.LEADING + Gtk.SourceDrawSpacesFlags.TRAILING + Gtk.SourceDrawSpacesFlags.TAB + Gtk.SourceDrawSpacesFlags.SPACE",
93        "$ gboolean auto_indent" : true,
94        "$ show_line_numbers" : true,
95        "$ xns" : "Gtk",
96        "* init" : [
97         " ",
98         "",
99         "\t\tvar description =   Pango.FontDescription.from_string(\"monospace\");",
100         "\t\tdescription.set_size(8000);",
101         "",
102         "\t\t this.el.override_font(description);",
103         "",
104         "\ttry {        ",
105         "\t\tthis.el.completion.add_provider(new Palete.CompletionProvider(_this));",
106         "    } catch (GLib.Error  e) {}",
107         "    ",
108         "\tthis.el.completion.unblock_interactive();",
109         "\tthis.el.completion.select_on_show\t\t\t= true; // select",
110         "\tthis.el.completion.show_headers\t\t\t= false;",
111         "\tthis.el.completion.remember_info_visibility\t\t= true;",
112         "    ",
113         "  ",
114         "    var attrs = new Gtk.SourceMarkAttributes();",
115         "    var  pink =   Gdk.RGBA();",
116         "    pink.parse ( \"pink\");",
117         "    attrs.set_background ( pink);",
118         "    attrs.set_icon_name ( \"process-stop\");    ",
119         "    attrs.query_tooltip_text.connect(( mark) => {",
120         "        //print(\"tooltip query? %s\\n\", mark.name);",
121         "        return mark.name;",
122         "    });",
123         "    ",
124         "    this.el.set_mark_attributes (\"ERR\", attrs, 1);",
125         "    ",
126         "     var wattrs = new Gtk.SourceMarkAttributes();",
127         "    var  blue =   Gdk.RGBA();",
128         "    blue.parse ( \"#ABF4EB\");",
129         "    wattrs.set_background ( blue);",
130         "    wattrs.set_icon_name ( \"process-stop\");    ",
131         "    wattrs.query_tooltip_text.connect(( mark) => {",
132         "        //print(\"tooltip query? %s\\n\", mark.name);",
133         "        return mark.name;",
134         "    });",
135         "    ",
136         "    this.el.set_mark_attributes (\"WARN\", wattrs, 1);",
137         "    ",
138         " ",
139         "    ",
140         "     var dattrs = new Gtk.SourceMarkAttributes();",
141         "    var  purple =   Gdk.RGBA();",
142         "    purple.parse ( \"#EEA9FF\");",
143         "    dattrs.set_background ( purple);",
144         "    dattrs.set_icon_name ( \"process-stop\");    ",
145         "    dattrs.query_tooltip_text.connect(( mark) => {",
146         "        //print(\"tooltip query? %s\\n\", mark.name);",
147         "        return mark.name;",
148         "    });",
149         "    ",
150         "    this.el.set_mark_attributes (\"DEPR\", dattrs, 1);",
151         "    ",
152         "    "
153        ],
154        "* pack" : "add",
155        "bool insert_spaces_instead_of_tabs" : true,
156        "gboolean highlight_current_line" : true,
157        "gboolean show_line_marks" : true,
158        "id" : "view",
159        "indent_width" : 4,
160        "items" : [
161         {
162          "$ xns" : "Gtk",
163          "* pack" : "set_buffer",
164          "bool check_queued" : false,
165          "bool check_running" : false,
166          "id" : "buffer",
167          "int error_line" : "-1",
168          "listeners" : {
169           "changed" : [
170            " () => {",
171            "    // check syntax??",
172            "    // ??needed..??",
173            "    _this.save_button.el.sensitive = true;",
174            "    print(\"EDITOR CHANGED\");",
175            "    this.checkSyntax();",
176            "   ",
177            "    _this.dirty = true;",
178            "",
179            "    // this.get('/LeftPanel.model').changed(  str , false);",
180            "    return ;",
181            "}",
182            "",
183            " ",
184            ""
185           ]
186          },
187          "xtype" : "SourceBuffer",
188          "|   bool checkSyntax" : [
189           " () {",
190           " ",
191           "    if (this.check_running) {",
192           "        print(\"Check is running\\n\");",
193           "        if (this.check_queued) { ",
194           "            print(\"Check is already queued\");",
195           "            return true;",
196           "        }",
197           "        this.check_queued = true;",
198           "        print(\"Adding queued Check \");",
199           "        GLib.Timeout.add_seconds(1, () => {",
200           "            this.check_queued = false;",
201           "            ",
202           "            this.checkSyntax();",
203           "            return false;",
204           "        });",
205           "    ",
206           "",
207           "        return true;",
208           "    }",
209           "    var str = this.toString();",
210           "    ",
211           "    // needed???",
212           "    if (this.error_line > 0) {",
213           "         Gtk.TextIter start;",
214           "         Gtk.TextIter end;     ",
215           "        this.el.get_bounds (out start, out end);",
216           "",
217           "        this.el.remove_source_marks (start, end, null);",
218           "    }",
219           "    if (str.length < 1) {",
220           "        print(\"checkSyntax - empty string?\\n\");",
221           "        return true;",
222           "    }",
223           "    ",
224           "    if (_this.file.xtype == \"PlainFile\") {",
225           "    ",
226           "        // assume it's gtk...",
227           "           this.check_running = true;",
228           " ",
229           "         if (!_this.window.windowstate.valasource.checkPlainFileSpawn(",
230           "\t   _this.file,",
231           "\t    str",
232           "\t )) {",
233           "            this.check_running = false;",
234           "        }",
235           "\t",
236           "        return true;",
237           "    ",
238           "    }",
239           "   if (_this.file == null) {",
240           "       return true;",
241           "   }",
242           "    var p = _this.file.project.palete;",
243           "    ",
244           "",
245           "     ",
246           "    this.check_running = true;",
247           "    ",
248           "    ",
249           "    if (_this.file.language == \"js\") {",
250           "        this.check_running = false;",
251           "        print(\"calling validate javascript\\n\"); ",
252           "        Gee.HashMap<int,string> errors;",
253           "        p.javascriptHasErrors(",
254           "    \t\t_this.window.windowstate,",
255           "            str, ",
256           "             _this.prop,",
257           "            _this.file,   // no reference not node?",
258           "            out errors",
259           "        );",
260           "        return this.highlightErrors(errors);    ",
261           "        ",
262           "    }",
263           "        ",
264           "        ",
265           "    print(\"calling validate vala\\n\");    ",
266           "    // clear the buttons.",
267           " ",
268           "    ",
269           "   if (! _this.window.windowstate.valasource.checkFileWithNodePropChange(",
270           "        _this.file,",
271           "        _this.node,",
272           "         _this.prop,        ",
273           "            str",
274           "        )) {",
275           "        this.check_running = false;",
276           "    } ",
277           "     ",
278           "    ",
279           "    ",
280           "    //print(\"done mark line\\n\");",
281           "     ",
282           "    return true; // at present allow saving - even if it's invalid..",
283           "}",
284           ""
285          ],
286          "|   string toString" : [
287           "  () {",
288           "    ",
289           "    Gtk.TextIter s;",
290           "    Gtk.TextIter e;",
291           "    this.el.get_start_iter(out s);",
292           "    this.el.get_end_iter(out e);",
293           "    var ret = this.el.get_text(s,e,true);",
294           "    //print(\"TO STRING? \" + ret);",
295           "    return ret;",
296           "}",
297           " "
298          ],
299          "| bool highlightErrors" : [
300           "( Gee.HashMap<int,string> validate_res) {",
301           "         ",
302           "        this.error_line = validate_res.size;",
303           "",
304           "        if (this.error_line < 1) {",
305           "              return true;",
306           "        }",
307           "        var tlines = this.el.get_line_count ();",
308           "        Gtk.TextIter iter;",
309           "        var valiter = validate_res.map_iterator();",
310           "        while (valiter.next()) {",
311           "        ",
312           "    //        print(\"get inter\\n\");",
313           "            var eline = valiter.get_key();",
314           "            if (eline > tlines) {",
315           "                continue;",
316           "            }",
317           "            this.el.get_iter_at_line( out iter, eline);",
318           "            //print(\"mark line\\n\");",
319           "            this.el.create_source_mark(valiter.get_value(), \"ERR\", iter);",
320           "        }   ",
321           "        return false;",
322           "    }"
323          ],
324          "| bool highlightErrorsJson" : [
325           "(string type, Json.Object obj) {",
326           "      Gtk.TextIter start;",
327           "     Gtk.TextIter end;     ",
328           "        this.el.get_bounds (out start, out end);",
329           "        ",
330           "        this.el.remove_source_marks (start, end, type);",
331           "                 ",
332           "     ",
333           "     // we should highlight other types of errors..",
334           "    ",
335           "    if (!obj.has_member(type)) {",
336           "        print(\"Return has no errors\\n\");",
337           "        return true;",
338           "    }",
339           "    ",
340           "    if (_this.window.windowstate.state != WindowState.State.CODEONLY ",
341           "      ",
342           "        ) {",
343           "        return true;",
344           "    } ",
345           "    ",
346           "    ",
347           "    var err = obj.get_object_member(type);",
348           "    ",
349           "    ",
350           "    if (_this.file == null) {",
351           "        return true;",
352           "    ",
353           "    }",
354           "    var valafn = _this.file.path;",
355           " ",
356           "    if (_this.file.xtype != \"PlainFile\") {",
357           "",
358           "",
359           "        ",
360           "        ",
361           "         valafn = \"\";",
362           "          try {             ",
363           "               var  regex = new Regex(\"\\\\.bjs$\");",
364           "               // should not happen",
365           "              ",
366           "             ",
367           "                valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");",
368           "             } catch (GLib.RegexError e) {",
369           "                return true;",
370           "            }   ",
371           "",
372           "",
373           "",
374           "      }",
375           "       if (!err.has_member(valafn)) {",
376           "            print(\"File path has no errors\\n\");",
377           "            return  true;",
378           "        }",
379           "",
380           "        var lines = err.get_object_member(valafn);",
381           "        ",
382           "        var offset = 1;",
383           "        if (obj.has_member(\"line_offset\")) {",
384           "            offset = (int)obj.get_int_member(\"line_offset\") + 1;",
385           "        }",
386           "    ",
387           "",
388           "     ",
389           "    ",
390           "    var tlines = this.el.get_line_count () +1;",
391           "    ",
392           "    lines.foreach_member((obj, line, node) => {",
393           "        ",
394           "             Gtk.TextIter iter;",
395           "    //        print(\"get inter\\n\");",
396           "            var eline = int.parse(line) - offset;",
397           "            print(\"GOT ERROR on line %s -- converted to %d\\n\", line,eline);",
398           "            ",
399           "            ",
400           "            if (eline > tlines || eline < 0) {",
401           "                return;",
402           "            }",
403           "            this.el.get_iter_at_line( out iter, eline);",
404           "            //print(\"mark line\\n\");",
405           "            var msg  = \"Line: %d\".printf(eline+1);",
406           "            var ar = lines.get_array_member(line);",
407           "            for (var i = 0 ; i < ar.get_length(); i++) {",
408           "\t\t    msg += (msg.length > 0) ? \"\\n\" : \"\";",
409           "\t\t    msg += ar.get_string_element(i);",
410           "\t    }",
411           "            ",
412           "            ",
413           "            this.el.create_source_mark(msg, type, iter);",
414           "        } );",
415           "        return false;",
416           "    ",
417           "",
418           "",
419           "",
420           "",
421           "}",
422           ""
423          ]
424         }
425        ],
426        "listeners" : {
427         "key_release_event" : [
428          " (event) => {",
429          "    ",
430          "    if (event.keyval == 115 && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
431          "        print(\"SAVE: ctrl-S  pressed\");",
432          "        _this.saveContents();",
433          "        return false;",
434          "    }",
435          "   // print(event.key.keyval)",
436          "    ",
437          "    return false;",
438          "",
439          "} ",
440          "",
441          " "
442         ]
443        },
444        "uint tab_width" : 4,
445        "xtype" : "SourceView",
446        "|   void load" : [
447         " (string str) {",
448         "",
449         "// show the help page for the active node..",
450         "   //this.get('/Help').show();",
451         "",
452         "",
453         "  // this.get('/BottomPane').el.set_current_page(0);",
454         "    var buf = (Gtk.SourceBuffer)this.el.get_buffer();",
455         "    buf.set_text(str, str.length);",
456         "    buf.set_undo_manager(null);",
457         "    ",
458         "    var lm = Gtk.SourceLanguageManager.get_default();",
459         "    var lang = \"vala\";",
460         "    if (_this.file != null) {",
461         "         lang = _this.file.language;",
462         "    }",
463         "    print(\"lang=%s, content_type = %s\\n\", lang, _this.file.content_type);",
464         "    var lg = _this.file.content_type.length > 0  ?",
465         "            lm.guess_language(_this.file.path, _this.file.content_type) :",
466         "            lm.get_language(lang);",
467         "     ",
468         "   ",
469         "    ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lg); ",
470         "",
471         "    this.el.insert_spaces_instead_of_tabs = true;",
472         "    if (lg != null) {",
473         "\t\tprint(\"sourcelanguage  = %s\\n\", lg.name);",
474         "\t\tif (lg.name == \"Vala\") {",
475         "\t\t    this.el.insert_spaces_instead_of_tabs = false;",
476         "\t\t}",
477         "     }",
478         "    _this.dirty = false;",
479         "    this.el.grab_focus();",
480         "    _this.save_button.el.sensitive = false;",
481         "}"
482        ]
483       }
484      ],
485      "xtype" : "ScrolledWindow"
486     }
487    ],
488    "string id" : "Editor",
489    "xtype" : "Box",
490    "|   void show" : [
491     "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
492     "{",
493     "    this.reset();",
494     "    this.file = file;    ",
495     "    ",
496     "    if (file.xtype != \"PlainFile\") {",
497     "    \tthis.prop = prop;",
498     "        this.node = node;",
499     "",
500     "        // find the text for the node..",
501     "        this.view.load( prop.val );",
502     "        this.key_edit.el.show();",
503     "        this.key_edit.el.text = prop.rtype +  \" \" + prop.name;  ",
504     "    ",
505     "    } else {",
506     "        this.view.load(        file.toSource() );",
507     "        this.key_edit.el.hide();",
508     "    }",
509     " ",
510     "}"
511    ],
512    "| bool saveContents" : [
513     "  ()  {",
514     "    ",
515     "    ",
516     "    if (_this.file == null) {",
517     "        return true;",
518     "    }",
519     "    ",
520     "     ",
521     "     ",
522     "     var str = _this.buffer.toString();",
523     "     ",
524     "     _this.buffer.checkSyntax();",
525     "     ",
526     "     ",
527     "     ",
528     "     // LeftPanel.model.changed(  str , false);",
529     "     _this.dirty = false;",
530     "     _this.save_button.el.sensitive = false;",
531     "     ",
532     "    // find the text for the node..",
533     "    if (_this.file.xtype != \"PlainFile\") {",
534     "       // in theory these properties have to exist!?!",
535     "    \tthis.prop.val = str;",
536     "        this.window.windowstate.left_props.reload();",
537     "    } else {",
538     "        _this.file.setSource(  str );",
539     "     }",
540     "    ",
541     "    // call the signal..",
542     "    this.save();",
543     "    ",
544     "    return true;",
545     "",
546     "} "
547    ],
548    "| int search" : [
549     "(string txt) {",
550     "",
551     "\tvar s = new Gtk.SourceSearchSettings();",
552     "\t",
553     "\tthis.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);",
554     "\tthis.searchcontext .set_highlight(true);",
555     "\ts.set_search_text(txt);",
556     "\tGtk.TextIter beg, st,en;",
557     "\t ",
558     "\tthis.buffer.el.get_start_iter(out beg);",
559     "\tthis.searchcontext.forward(beg, out st, out en);",
560     "\tthis.last_search_end = 0;",
561     "\t",
562     "\treturn this.searchcontext.get_occurrences_count();",
563     "",
564     " ",
565     "   ",
566     "",
567     "}",
568     ""
569    ],
570    "| void forwardSearch" : [
571     "(bool change_focus) {",
572     " ",
573     "\tif (this.searchcontext == null) {",
574     "\t\treturn;",
575     "\t}",
576     "\t",
577     "\tGtk.TextIter beg, st,en;",
578     "\t ",
579     "\tthis.buffer.el.get_iter_at_offset(out beg, this.last_search_end);",
580     "\tif (!this.searchcontext.forward(beg, out st, out en)) {",
581     "\t",
582     "\t\tthis.last_search_end = 0;",
583     "\t} else {",
584     "\t\tthis.last_search_end = en.get_offset();",
585     "\t\tif (change_focus) {",
586     "\t\t\tthis.view.el.grab_focus();",
587     "\t\t}",
588     "\t\tthis.buffer.el.place_cursor(st);",
589     "\t\tthis.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);",
590     "\t}",
591     " ",
592     "}",
593     ""
594    ],
595    "| void reset" : [
596     "() {",
597     "\t this.file = null;    ",
598     "     ",
599     "    this.node = null;",
600     "    this.prop = null;",
601     "\tthis.searchcontext = null;",
602     "  ",
603     "}",
604     ""
605    ],
606    "| void scroll_to_line" : [
607     "(int line) {",
608     "",
609     "\tGLib.Timeout.add(500, () => {",
610     "   ",
611     "\t\tvar buf = this.view.el.get_buffer();",
612     "",
613     "\t\tvar sbuf = (Gtk.SourceBuffer) buf;",
614     "",
615     "",
616     "\t\tGtk.TextIter iter;   ",
617     "\t\tsbuf.get_iter_at_line(out iter,  line);",
618     "\t\tthis.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
619     "\t\treturn false;",
620     "\t});   ",
621     "}",
622     ""
623    ]
624   }
625  ],
626  "modOrder" : "",
627  "name" : "Editor",
628  "parent" : "",
629  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/Editor.bjs",
630  "permname" : "",
631  "title" : ""
632 }