src/Builder4/WindowRooView.bjs
authorAlan Knowles <alan@roojs.com>
Fri, 19 Jun 2015 07:38:00 +0000 (15:38 +0800)
committerAlan Knowles <alan@roojs.com>
Fri, 19 Jun 2015 07:38:00 +0000 (15:38 +0800)
src/Builder4/WindowRooView.vala

src/Builder4/WindowRooView.bjs
src/Builder4/WindowRooView.vala

index 94860f5..ffe98aa 100644 (file)
    "items" : [
     {
      "id" : "notebook",
-     "xtype" : "Notebook",
      "* pack" : "pack_start,true,true,0",
+     "xtype" : "Notebook",
      "$ xns" : "Gtk",
      "items" : [
       {
        "id" : "label_preview",
-       "xtype" : "Label",
        "* pack" : false,
+       "xtype" : "Label",
        "$ xns" : "Gtk",
        "utf8 label" : "Preview"
       },
       {
        "id" : "label_code",
-       "* pack" : false,
        "xtype" : "Label",
+       "* pack" : false,
        "$ xns" : "Gtk",
        "utf8 label" : "Preview Generated Code"
       },
       {
        "id" : "paned",
-       "xtype" : "Paned",
        "* pack" : "add",
+       "xtype" : "Paned",
        "$ xns" : "Gtk",
        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
        "items" : [
         {
          "id" : "viewbox",
-         "xtype" : "Box",
          "* pack" : "pack1,true,true",
+         "xtype" : "Box",
          "$ xns" : "Gtk",
          "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
          "$ homogeneous" : false,
          "items" : [
           {
            "$ vexpand" : false,
-           "* pack" : "pack_start,false,true,0",
            "$ height_request" : 20,
+           "* pack" : "pack_start,false,true,0",
            "xtype" : "Box",
            "$ xns" : "Gtk",
            "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
@@ -76,8 +76,8 @@
               "clicked" : "( ) => {\n    _this.view.renderJS(  true);\n}"
              },
              "label" : "Redraw",
-             "* pack" : "pack_start,false,false,0",
              "xtype" : "Button",
+             "* pack" : "pack_start,false,false,0",
              "$ xns" : "Gtk"
             },
             {
               "clicked" : " () => {\n  _this.view.redraws = 99;\n    _this.view.el.web_context.clear_cache();  \n  //_this.view.renderJS(true);\n  FakeServerCache.clear();\n  _this.view.reInit();\n\n}"
              },
              "label" : "Full Redraw",
-             "* pack" : "pack_start,false,false,0",
              "xtype" : "Button",
+             "* pack" : "pack_start,false,false,0",
              "$ xns" : "Gtk"
             }
            ]
           },
           {
            "id" : "viewcontainer",
-           "$ shadow_type" : "Gtk.ShadowType.IN",
            "* init" : "  this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);\n \n",
+           "$ shadow_type" : "Gtk.ShadowType.IN",
            "* pack" : "pack_end,true,true,0",
            "xtype" : "ScrolledWindow",
            "$ xns" : "Gtk",
         },
         {
          "id" : "inspectorcontainer",
-         "$ shadow_type" : "Gtk.ShadowType.IN",
          "* init" : "  this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);\n \n",
+         "$ shadow_type" : "Gtk.ShadowType.IN",
          "xtype" : "ScrolledWindow",
          "* pack" : "pack2,true,true",
          "$ xns" : "Gtk"
          "gboolean show_line_marks" : true,
          "id" : "sourceview",
          "* init" : "{\n   \n    var description =   Pango.FontDescription.from_string(\"monospace\");\n    description.set_size(8000);\n    this.el.override_font(description);\n\n    this.loading = true;\n    var buf = this.el.get_buffer();\n    buf.notify.connect((ps) => {\n        if (this.loading) {\n            return;\n        }\n        if (ps.name != \"cursor-position\") {\n            return;\n        }\n        print(\"cursor changed : %d\\n\", buf.cursor_position);\n        Gtk.TextIter cpos;\n        buf.get_iter_at_offset(out cpos, buf.cursor_position);\n        \n        var ln = cpos.get_line();\n \n        var node = _this.file.lineToNode(ln);\n \n        if (node == null) {\n            print(\"can not find node\\n\");\n            return;\n        }\n        var ltree = _this.main_window.windowstate.left_tree;\n        var tp = ltree.model.treePathFromNode(node);\n        print(\"got tree path %s\\n\", tp);\n        if (tp != \"\") {\n\t       this.allow_node_scroll = false;        \n\t       print(\"changing cursor on tree..\\n\");\n            ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);\n            // scrolling is disabled... as node selection calls scroll 10ms after it changes.\n            GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {\n\t            this.allow_node_scroll = true;\n\t            return false;\n            });\n        }\n        \n        // highlight the node..\n        \n    });\n  \n  \n  \n    var attrs = new Gtk.SourceMarkAttributes();\n    var  pink =   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 (\"ERR\", attrs, 1);\n    \n     var wattrs = new Gtk.SourceMarkAttributes();\n    var  blue =   Gdk.RGBA();\n    blue.parse ( \"#ABF4EB\");\n    wattrs.set_background ( blue);\n    wattrs.set_icon_name ( \"process-stop\");    \n    wattrs.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 (\"WARN\", wattrs, 1);\n    \n \n    \n     var dattrs = new Gtk.SourceMarkAttributes();\n    var  purple =   Gdk.RGBA();\n    purple.parse ( \"#EEA9FF\");\n    dattrs.set_background ( purple);\n    dattrs.set_icon_name ( \"process-stop\");    \n    dattrs.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 (\"DEPR\", dattrs, 1);\n    \n    \n    var gattrs = new Gtk.SourceMarkAttributes();\n    var  grey =   Gdk.RGBA();\n    grey.parse ( \"#ccc\");\n    gattrs.set_background ( grey);\n \n    \n    this.el.set_mark_attributes (\"grey\", gattrs, 1);\n    \n    \n    \n    \n    \n    \n}\n ",
-         "| void nodeSelected" : "(JsRender.Node? sel) {\n  \n    \n  \n    // this is connected in widnowstate\n    print(\"node selected\\n\");\n    var buf = this.el.get_buffer();\n \n    var sbuf = (Gtk.SourceBuffer) buf;\n\n   \n    while(Gtk.events_pending()) {\n        Gtk.main_iteration();\n    }\n    \n   \n    // clear all the marks..\n     Gtk.TextIter start;\n    Gtk.TextIter end;     \n        \n    sbuf.get_bounds (out start, out end);\n    sbuf.remove_source_marks (start, end, \"grey\");\n    \n    \n     if (sel == null) {\n\t     print(\"no selected node\\n\");\n        // no highlighting..\n        return;\n    }\n    \n    print(\"highlight region %d to %d\\n\", sel.line_start,sel.line_end);\n    Gtk.TextIter iter;   \n    sbuf.get_iter_at_line(out iter,  sel.line_start);\n    \n    \n    Gtk.TextIter cur_iter;\n    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);\n    \n    //var cur_line = cur_iter.get_line();\n    //if (cur_line > sel.line_start && cur_line < sel.line_end) {\n    \n    //} else {\n    if (this.allow_node_scroll) {\n\t\t \n    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);\n\t}\n    \n     \n    \n    for (var i = 0; i < buf.get_line_count();i++) {\n        if (i < sel.line_start || i > sel.line_end) {\n           \n            sbuf.get_iter_at_line(out iter, i);\n            sbuf.create_source_mark(null, \"grey\", iter);\n            \n        }\n    \n    }\n    \n\n}\n",
+         "| void nodeSelected" : "(JsRender.Node? sel) {\n  \n    \n  \n    // this is connected in widnowstate\n    print(\"node selected\\n\");\n    var buf = this.el.get_buffer();\n \n    var sbuf = (Gtk.SourceBuffer) buf;\n\n   \n    while(Gtk.events_pending()) {\n        Gtk.main_iteration();\n    }\n    \n   \n    // clear all the marks..\n     Gtk.TextIter start;\n    Gtk.TextIter end;     \n        \n    sbuf.get_bounds (out start, out end);\n    sbuf.remove_source_marks (start, end, \"grey\");\n    \n    \n     if (sel == null) {\n\t     print(\"no selected node\\n\");\n        // no highlighting..\n        return;\n    }\n    \n    print(\"highlight region %d to %d\\n\", sel.line_start,sel.line_end);\n    Gtk.TextIter iter;   \n    sbuf.get_iter_at_line(out iter,  sel.line_start);\n    \n    \n    Gtk.TextIter cur_iter;\n    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);\n    \n    //var cur_line = cur_iter.get_line();\n    //if (cur_line > sel.line_start && cur_line < sel.line_end) {\n    \n    //} else {\n    if (this.allow_node_scroll) {\n\t\t \n    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);\n\t}\n    \n    var sl = sel.line_start -1;\n    var el = sel.line_end - 1;\n    for (var i = 0; i < buf.get_line_count();i++) {\n        if (i < sl || i > el) {\n           \n            sbuf.get_iter_at_line(out iter, i);\n            sbuf.create_source_mark(null, \"grey\", iter);\n            \n        }\n    \n    }\n    \n\n}\n",
          "bool loading" : true,
          "| string toString" : "() {\n   Gtk.TextIter s;\n    Gtk.TextIter e;\n    this.el.get_buffer().get_start_iter(out s);\n    this.el.get_buffer().get_end_iter(out e);\n    var ret = this.el.get_buffer().get_text(s,e,true);\n    //print(\"TO STRING? \" + ret);\n    return ret;\n}\n",
          "| void loadFile" : "( ) {\n    this.loading = true;\n    var buf = this.el.get_buffer();\n    buf.set_text(\"\",0);\n    var sbuf = (Gtk.SourceBuffer) buf;\n\n    \n\n    if (_this.file == null || _this.file.xtype != \"Roo\") {\n        print(\"xtype != Gtk\");\n        this.loading = false;\n        return;\n    }\n    \n    var valafn = \"\";\n      try {             \n           var  regex = new Regex(\"\\\\.bjs$\");\n        \n         \n            valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".js\");\n         } catch (GLib.RegexError e) {\n             this.loading = false;\n            return;\n        }   \n    \n\n   if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {\n        print(\"File path has no errors\\n\");\n        this.loading = false;\n        return  ;\n    }\n    \n    string str;\n    try {\n    \n        GLib.FileUtils.get_contents (valafn, out str);\n    } catch (Error e) {\n        this.loading = false;\n        return  ;\n    }\n\n//    print(\"setting str %d\\n\", str.length);\n    buf.set_text(str, str.length);\n    var lm = Gtk.SourceLanguageManager.get_default();\n     \n    //?? is javascript going to work as js?\n    \n    ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));\n  \n    \n    Gtk.TextIter start;\n    Gtk.TextIter end;     \n        \n    sbuf.get_bounds (out start, out end);\n    sbuf.remove_source_marks (start, end, null); // remove all marks..\n    \n    \n    \n    \n    this.loading = false; \n}\n",
index e5e8b84..79f7dbf 100644 (file)
@@ -1100,10 +1100,10 @@ public class Xcls_WindowRooView : Object
                this.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
                }
             
-             
-            
+            var sl = sel.line_start -1;
+            var el = sel.line_end - 1;
             for (var i = 0; i < buf.get_line_count();i++) {
-                if (i < sel.line_start || i > sel.line_end) {
+                if (i < sl || i > el) {
                    
                     sbuf.get_iter_at_line(out iter, i);
                     sbuf.create_source_mark(null, "grey", iter);