sync
[app.Builder.js] / src / Builder4 / Editor.bjs
1 {
2  "name" : "Editor",
3  "parent" : "",
4  "title" : "",
5  "path" : "/home/alan/gitlive/app.Builder.js/src/Builder4/Editor.bjs",
6  "permname" : "",
7  "modOrder" : "",
8  "build_module" : "",
9  "items" : [
10   {
11    "# string activeEditor" : "\"\"",
12    "|   bool saveContents" : "  ()  {\n    \n    \n    \n    \n    \n    \n    \n   \n     \n     var str = _this.buffer.toString();\n     \n      \n     \n     \n     if (!_this.buffer.checkSyntax()) {\n         print(\"check syntax failed\");\n         //this.get('/StandardErrorDialog').show(\"Fix errors in code and save..\"); \n         //return false;\n     }\n     \n     // LeftPanel.model.changed(  str , false);\n     _this.dirty = false;\n     _this.save_button.el.sensitive = false;\n     \n     \n        \n     \n    // find the text for the node..\n    if (ptype == \"listener\") {\n        this.node.listeners.set(key,str);\n    \n    } else {\n         this.node.props.set(key,str);\n    }\n\n     \n    \n    // call the signal..\n    this.save();\n    \n    return true;\n\n} ",
13    "# int pos_root_x" : "",
14    "# int pos_root_y" : "",
15    "# string ptype" : "\"\"",
16    "# string key" : "\"\"",
17    "* pack" : "add",
18    "xtype" : "VBox",
19    "|   void show" : "(JsRender.JsRender file, JsRender.Node node, string ptype, string key)\n{\n    this.ptype = ptype;\n    this.key  = key;\n    this.node = node;\n    this.file = file;\n    \n   string val = \"\";\n    // find the text for the node..\n    if (ptype == \"listener\") {\n        val = node.listeners.get(key);\n    \n    } else {\n        val = node.props.get(key);\n    }\n    this.view.load(val);\n    this.key_edit.el.text = key;    \n\n}",
20    "# JsRender.JsRender file" : "null",
21    "# bool pos" : false,
22    "string id" : "Editor",
23    "# bool dirty" : false,
24    "$ xns" : "Gtk",
25    "@ void save" : "()",
26    "$ homogeneous" : false,
27    "# JsRender.Node node" : "null",
28    "items" : [
29     {
30      "* pack" : "pack_start,false,true",
31      "xtype" : "HBox",
32      "$ xns" : "Gtk",
33      "$ homogeneous" : false,
34      "items" : [
35       {
36        "listeners" : {
37         "clicked" : " () => { \n    _this.saveContents();\n}\n \n"
38        },
39        "label" : "Save",
40        "id" : "save_button",
41        "* pack" : "pack_start,false,false",
42        "xtype" : "Button",
43        "$ xns" : "Gtk"
44       },
45       {
46        "id" : "key_edit",
47        "xtype" : "Entry",
48        "* pack" : "pack_end,true,true",
49        "$ xns" : "Gtk"
50       }
51      ]
52     },
53     {
54      "id" : "RightEditor",
55      "* init" : "this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
56      "xtype" : "ScrolledWindow",
57      "* pack" : "add",
58      "$ xns" : "Gtk",
59      "items" : [
60       {
61        "listeners" : {
62         "key_release_event" : " (event) => {\n    \n    if (event.keyval == 115 && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {\n        print(\"SAVE: ctrl-S  pressed\");\n        _this.saveContents();\n        return false;\n    }\n   // print(event.key.keyval)\n    \n    return false;\n\n} \n\n"
63        },
64        "gboolean show_line_marks" : true,
65        "id" : "view",
66        "* init" : " \n    var description =   Pango.FontDescription.from_string(\"monospace\");\n    description.set_size(8000);\n    this.el.override_font(description);\n\n    var attrs = new Gtk.SourceMarkAttributes();\n    var  pink = new Gdk.RGBA();\n    pink.parse ( \"pink\");\n    attrs.set_background ( pink);\n    attrs.set_icon_name ( \"process-stop\");    \n    attrs.query_tooltip_text.connect(( mark) => {\n        print(\"tooltip query? %s\\n\", mark.name);\n        return mark.name;\n    });\n    \n    this.el.set_mark_attributes (\"error\", attrs, 1);\n    \n    ",
67        "$ insert_spaces_instead_of_tabs" : true,
68        "* pack" : "add",
69        "xtype" : "View",
70        "gboolean highlight_current_line" : true,
71        "$ gboolean auto_indent" : true,
72        "$ xns" : "GtkSource",
73        "|   void load" : " (string str) {\n\n// show the help page for the active node..\n   //this.get('/Help').show();\n\n\n  // this.get('/BottomPane').el.set_current_page(0);\n    this.el.get_buffer().set_text(str, str.length);\n    var lm = Gtk.SourceLanguageManager.get_default();\n    \n    var lang = _this.file.language;\n    //?? is javascript going to work as js?\n    \n    ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lm.get_language(lang));\n    var buf = this.el.get_buffer();\n    \n    /* -- what does all this do? */\n    /*\n    var cursor = buf.get_mark(\"insert\");\n    Gtk.TextIter iter;\n    buf.get_iter_at_mark(out iter, cursor);\n    iter.set_line(1);\n    iter.set_line_offset(4);\n    buf.move_mark(cursor, iter);\n    \n    \n    cursor = buf.get_mark(\"selection_bound\");\n    //iter= new Gtk.TextIter;\n    buf.get_iter_at_mark(out iter, cursor);\n    iter.set_line(1);\n    iter.set_line_offset(4);\n    buf.move_mark(cursor, iter);\n    \n    */\n    \n    _this.dirty = false;\n    this.el.grab_focus();\n    _this.save_button.el.sensitive = false;\n}",
74        "indent_width" : 4,
75        "$ show_line_numbers" : true,
76        "items" : [
77         {
78          "listeners" : {
79           "changed" : " () => {\n    // check syntax??\n    // ??needed..??\n    _this.save_button.el.sensitive = true;\n    print(\"EDITOR CHANGED\");\n    this.checkSyntax();\n   \n    _this.dirty = true;\n\n    // this.get('/LeftPanel.model').changed(  str , false);\n    return ;\n}\n\n \n"
80          },
81          "bool check_queued" : false,
82          "id" : "buffer",
83          "int error_line" : "-1",
84          "| bool highlightErrors" : "( Gee.HashMap<int,string> validate_res) {\n        this.error_line = validate_res.size;\n\n        if (this.error_line < 1) {\n              return true;\n        }\n        var tlines = this.el.get_line_count ();\n        Gtk.TextIter iter;\n        var valiter = validate_res.map_iterator();\n        while (valiter.next()) {\n        \n    //        print(\"get inter\\n\");\n            var eline = valiter.get_key();\n            if (eline > tlines) {\n                continue;\n            }\n            this.el.get_iter_at_line( out iter, eline);\n            //print(\"mark line\\n\");\n            this.el.create_source_mark(valiter.get_value(), \"error\", iter);\n        }   \n        return false;\n    }",
85          "|   string toString" : "  () {\n    \n    Gtk.TextIter s;\n    Gtk.TextIter e;\n    this.el.get_start_iter(out s);\n    this.el.get_end_iter(out e);\n    var ret = this.el.get_text(s,e,true);\n    //print(\"TO STRING? \" + ret);\n    return ret;\n}\n ",
86          "|   bool checkSyntax" : " () {\n \n    if (this.check_running) {\n        print(\"Check is running\\n\");\n        if (this.check_queued) { \n            print(\"Check is already queued\");\n            return true;\n        }\n        this.check_queued = true;\n        print(\"Adding queued Check \");\n        GLib.Timeout.add_seconds(1, () => {\n            this.check_queued = false;\n            \n            this.checkSyntax();\n            return false;\n        });\n    \n\n        return true;\n    }\n   \n   \n    var p = Palete.factory(_this.file.xtype);   \n    \n    var str = this.toString();\n    \n    string res = \"\";\n    \n    if (this.error_line > 0) {\n         Gtk.TextIter start;\n         Gtk.TextIter end;     \n        this.el.get_bounds (out start, out end);\n\n        this.el.remove_source_marks (start, end, null);\n    }\n    \n    if (str.length < 1) {\n        print(\"checkSyntax - empty string?\\n\");\n        return true;\n    }\n    this.check_running = true;\n    \n    \n    if (_this.file.language == \"js\") {\n        this.check_running = false;\n        print(\"calling validate javascript\\n\"); \n        return this.highlightErrors(p.validateJavascript(\n            str, \n             _this.key, \n            _this.ptype,\n            _this.file,\n            _this.node\n        ));    \n        \n    }\n        \n    print(\"calling validate vala\\n\");    \n    p.validateVala.begin(\n        str, \n         _this.key, \n        _this.ptype,\n        _this.file,\n        _this.node,\n        (obj, res) => {\n            this.check_running = false;\n            var validate_res = p.validateVala.end(res);\n            this.highlightErrors(validate_res);\n\n        }\n        \n    );\n     \n    \n    \n    //print(\"done mark line\\n\");\n     \n    return true; // at present allow saving - even if it's invalid..\n}\n",
87          "* pack" : "set_buffer",
88          "xtype" : "Buffer",
89          "bool check_running" : false,
90          "$ xns" : "GtkSource"
91         }
92        ]
93       }
94      ]
95     }
96    ]
97   }
98  ]
99 }