Fix #8032 - speed up add remove of errors from tree
[roobuilder] / src / Builder4 / WindowLeftTree.bjs
index 641f61d..bab93d9 100644 (file)
@@ -3,7 +3,9 @@
  "gen_extended" : false,
  "items" : [
   {
+   "# Gee.ArrayList<Gtk.Widget>? error_widgets" : "null",
    "# Xcls_MainWindow? main_window" : "null",
+   "# int last_error_counter" : "-1",
    "$ xns" : "Gtk",
    "@ bool before_node_change" : "()",
    "@ void changed" : "()",
@@ -12,7 +14,6 @@
    "bool hexpand" : true,
    "bool vexpand" : true,
    "id" : "WindowLeftTree",
-   "int last_error_counter" : "-1",
    "items" : [
     {
      "$ xns" : "Gtk",
@@ -41,7 +42,7 @@
        "$ xns" : "Gtk",
        "* init" : [
         "{",
-        " ",
+        " /*",
         "  this.css = new Gtk.CssProvider();",
         "//\ttry {",
         "\t\tthis.css.load_from_string(\"",
@@ -95,7 +96,7 @@
         "\t\tthis.css,",
         "\t\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
         "\t);",
-        "\t",
+        "\t*/",
         "\t  ",
         "}",
         ""
            "| int nodeToRow" : [
             "(JsRender.Node node) ",
             "{",
-            "\tvar row = -1;",
+            " ",
             "\tvar s = _this.view.el.model as Gtk.SingleSelection;",
             "\tfor (var i = 0; i < s.n_items; i++) {",
             "\t\t//GLib.debug(\"check node %s\", s.get_item(i).get_type().name());",
             "\t\tvar lr = s.get_item(i) as Gtk.TreeListRow;",
             "\t\t//GLib.debug(\"check node %s\", lr.get_item().get_type().name());",
-            "\t\tif ((lr.get_item() as JsRender.Node).oid == node.oid) {",
+            "\t\tvar nn = (lr.get_item() as JsRender.Node);",
+            "\t\tif (nn != null && nn.oid == node.oid) {",
             "\t\t\treturn i;",
             "\t\t\t",
             "\t\t}",
             ""
            ],
            "| void selectNode" : [
-            "(JsRender.Node node) ",
+            "(JsRender.Node node) ",
             "{",
-            "\tvar row = this.nodeToRow(node);",
             "\tvar s = _this.view.el.model as Gtk.SingleSelection;",
+            "\tif (node == null) {",
+            "\t\ts.selected=Gtk.INVALID_LIST_POSITION;",
+            "\t\treturn;",
+            "\t}",
+            "\tvar row = this.nodeToRow(node);",
+            "",
             "\t ",
             "\tif (row < 0) {",
             "\t\t// select none?",
             "\t\tGLib.debug(\"Could not find node\");",
+            "\t\ts.selected=Gtk.INVALID_LIST_POSITION;",
             "\t\treturn;",
             "\t}",
             "\tGLib.debug(\"Select %d\", row);",
              "    expand.set_hide_expander( !node.hasChildren() );",
              " \texpand.set_list_row(lr);",
              " \t",
-             " \tnode.bind_property(\"iconFilename\",",
-             "                    img, \"file\",",
+             " \tnode.bind_property(\"iconResourceName\",",
+             "                    img, \"resource\",",
              "                   GLib.BindingFlags.SYNC_CREATE);",
              " \t",
              " \tnode.bind_property(\"nodeTitleProp\",",
        "string name" : "left-tree-view",
        "xtype" : "ColumnView",
        "| Gtk.Widget? getWidgetAt" : [
-        "(double x,  double in_y) {",
-        "/*",
-        "    \t",
-        "from    \thttps://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465",
-        "    \tvar colview = gesture.widget;",
-        "    \tvar line_no = check_list_widget(colview, x,y);",
-        "         if (line_no > -1) {",
-        "    \t\tvar item = colview.model.get_item(line_no);",
-        "    \t\t ",
-        "    \t}",
-        "    \t*/",
-        "    \tvar y = in_y + _this.viewwin.el.vadjustment.value; ",
-        "        var  child = this.el.get_first_child(); ",
-        "    \t//Gtk.Allocation alloc = { 0, 0, 0, 0 };",
-        "    \tvar line_no = -1; ",
-        "    \tvar reading_header = true;",
-        "    \tvar curr_y = 0;",
-        "    \tvar header_height  = 0;",
-        "    \tvar h = 0;",
-        "    \twhile (child != null) {",
-        "\t\t\t//GLib.debug(\"Got %s\", child.get_type().name());",
-        "\t        if (reading_header) {",
-        "\t\t\t\t",
-        "",
-        "\t\t\t\tif (child.get_type().name() != \"GtkColumnListView\") {",
-        "\t\t\t        h += child.get_height();",
-        "\t\t\t\t\tchild = child.get_next_sibling();",
-        "\t\t\t\t\tcontinue;",
-        "\t\t\t\t}",
-        "\t\t\t\t// should be columnlistview",
-        "\t\t\t\tchild = child.get_first_child(); ",
-        "\t\t\t    GLib.debug(\"header height=%d\", h);",
-        "\t\t\t\theader_height =  h;",
-        "\t\t\t\t",
-        "\t\t\t\treading_header = false;",
-        "\t\t\t\tcontinue;",
-        "\t        }",
-        "\t\t    line_no++;",
+        "(double x,  double  y) {",
         "",
-        "\t\t\tif (y < header_height) {",
-        "\t\t    \treturn null;",
-        "\t    \t}",
-        "",
-        "\t\t\tvar hh = child.get_height();",
-        "\t\t\t//GLib.debug(\"got cell xy = %d,%d  w,h= %d,%d\", alloc.x, alloc.y, alloc.width, alloc.height);",
-        "\t\t\tif (child.has_css_class(\"node-err\") || ",
-        "\t\t\t\tchild.has_css_class(\"node-warn\") || ",
-        "\t\t\t\tchild.has_css_class(\"node-depr\")) {",
-        "\t\t\t\thh += 10;",
-        "\t\t\t",
-        "\t\t\t}\t",
-        "\t\t    if (y > curr_y && y <= header_height + hh + curr_y ) {",
-        "\t\t\t    return (Gtk.Widget)child;",
-        "\t\t    }",
-        "\t\t    curr_y +=  hh ;",
-        "",
-        "\t\t    if (curr_y > y) {",
-        "\t\t        return null;",
-        "\t        }",
-        "\t        child = child.get_next_sibling(); ",
-        "    \t}",
-        "        return null;",
+        "\tvar w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);",
+        "\t//GLib.debug(\"got widget %s\", w == null ? \"nothing\" : w.get_type().name());",
+        "\tif (w == null) {",
+        "\t\treturn null;",
+        "\t}",
+        "\t",
+        "\tvar row= w.get_ancestor(GLib.Type.from_name(\"GtkColumnViewRowWidget\"));",
+        "\tif (row == null) {",
+        "\t\treturn null;",
+        "\t}",
+        "\treturn row;",
+        " ",
         "",
         " }"
        ],
         " }"
        ],
        "| int getRowAt" : [
-        "(double x,  double in_y, out string pos) {",
-        "",
+        "(double x,  double  y, out string pos) {",
         "",
+        "\tpos = \"\";",
+        "\tvar w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);",
+        "\t//GLib.debug(\"got widget %s\", w == null ? \"nothing\" : w.get_type().name());",
+        "\tif (w == null) {",
+        "\t\treturn -1;",
+        "\t}",
+        "\t",
+        "\tvar row= w.get_ancestor(GLib.Type.from_name(\"GtkColumnViewRowWidget\"));",
+        "\tif (row == null) {",
+        "\t\treturn -1;",
+        "\t}",
+        "\t",
+        "\t//GLib.debug(\"got colview %s\", row == null ? \"nothing\" : row.get_type().name());",
         "\t ",
-        "",
-        "/*",
-        "    \t",
-        "from    \thttps://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465",
-        "    \tvar colview = gesture.widget;",
-        "    \tvar line_no = check_list_widget(colview, x,y);",
-        "         if (line_no > -1) {",
-        "    \t\tvar item = colview.model.get_item(line_no);",
-        "    \t\t ",
-        "    \t}",
-        "    \t*/",
-        " \t\t ",
-        " \t\t",
-        " \t\tGLib.debug(\"get Widget At Row x = %d  y = %d\", (int) x, (int) in_y);",
-        "    \tvar y = in_y + _this.viewwin.el.vadjustment.value; ",
-        "        var  child = this.el.get_first_child(); ",
-        "    \t//Gtk.Allocation alloc = { 0, 0, 0, 0 };",
-        "    \tvar line_no = -1; ",
-        "    \tvar reading_header = true;",
-        "    \tvar real_y = 0;",
-        "    \tvar header_height  = 0;",
-        "    \tpos = \"none\";",
-        "    \tvar h = 0;",
-        "    \twhile (child != null) {",
-        "\t\t\t//GLib.debug(\"Got %s\", child.get_type().name());",
-        "    \t    if (reading_header) {",
-        "\t\t\t\t",
-        "",
-        "\t\t\t\tif (child.get_type().name() != \"GtkColumnListView\") {",
-        "\t\t\t        h += child.get_height();",
-        "\t\t\t\t\tchild = child.get_next_sibling();",
-        "\t\t\t\t\tcontinue;",
-        "\t\t\t\t}",
-        "\t\t\t\t// should be columnlistview",
-        "\t\t\t\tchild = child.get_first_child(); ",
-        "\t\t\t    //GLib.debug(\"header height=%d\", h);",
-        "\t\t\t\theader_height =  h;",
-        "\t\t\t\t",
-        "\t\t\t\treading_header = false;",
-        "\t\t\t\tcontinue;",
-        "\t\t\t\t",
-        "\t        }",
-        "\t        ",
-        "\t\t    if (child.get_type().name() != \"GtkColumnViewRowWidget\") {",
-        "    \t\t    child = child.get_next_sibling();",
-        "    \t\t    continue;",
-        "\t\t    }",
-        "\t\t    ",
-        "\t\t \tif (y < header_height) {",
-        "\t\t    \treturn -1;",
-        "\t    \t}",
-        "\t\t    ",
-        "\t\t    line_no++;",
-        "\t\t\tvar hh = child.get_height();",
-        "\t\t\t",
-        "\t\t\tif (child.has_css_class(\"node-err\") || ",
-        "\t\t\t\tchild.has_css_class(\"node-warn\") || ",
-        "\t\t\t\tchild.has_css_class(\"node-depr\")) {",
-        "\t\t\t\thh += 10;",
-        "\t\t\t",
-        "\t\t\t}",
-        "\t\t\t//child.get_allocation(out alloc);",
-        "\t\t\t//GLib.debug(\"got cell xy = %d,%d  w,h= %d,%d\", alloc.x, alloc.y, alloc.width, alloc.height);",
-        "\t\t\t//GLib.debug(\"row %d y= %d %s\", line_no, (int) (header_height + alloc.y),",
-        "\t\t\t",
-        "\t\t\t//\tchild.visible ? \"VIS\" : \"hidden\");",
-        "",
-        "\t\t    if (y >  (header_height + real_y) && y <= (header_height +  real_y + hh) ) {",
-        "\t\t    \tif (y > ( header_height + real_y + (hh * 0.8))) {",
-        "\t\t    \t\tpos = \"below\";",
-        "\t    \t\t} else if (y > ( header_height + real_y + (hh * 0.2))) {",
-        "\t    \t\t\tpos = \"over\";",
-        "    \t\t\t} else {",
-        "    \t\t\t\tpos = \"above\";",
-        "\t\t\t\t}",
-        "\t\t    \t GLib.debug(\"getRowAt return : %d, %s\", line_no, pos);",
-        "\t\t\t    return line_no;",
-        "\t\t    }",
-        " ",
-        "",
-        "\t\t    if (real_y + hh > y) {",
-        "\t\t        return -1;",
-        "\t        }",
-        "\t        real_y += hh;",
-        "\t        child = child.get_next_sibling(); ",
-        "    \t}",
-        "        return -1;",
-        "",
+        "\tvar rn = 0;",
+        "\tvar cr = row;",
+        "\t ",
+        "\twhile (cr.get_prev_sibling() != null) {",
+        "\t\trn++;",
+        "\t\tcr = cr.get_prev_sibling();",
+        "\t}",
+        "\t",
+        "\t//GLib.debug(\"row number is %d\", rn);",
+        "\t//GLib.debug(\"click %d, %d\", (int)x, (int)y);",
+        "\t// above or belw",
+        "\tGraphene.Rect  bounds;",
+        "\trow.compute_bounds(this.el, out bounds);",
+        "\t//GLib.debug(\"click x=%d, y=%d, w=%d, h=%d\", ",
+        "\t//\t(int)bounds.get_x(), (int)bounds.get_y(),",
+        "\t//\t(int)bounds.get_width(), (int)bounds.get_height()",
+        "\t//\t);",
+        "\tvar ypos = y - bounds.get_y();",
+        "\t//GLib.debug(\"rel ypos = %d\", (int)ypos);\t",
+        "\tvar rpos = 100.0 * (ypos / bounds.get_height());",
+        "\t//GLib.debug(\"rel pos = %d %%\", (int)rpos);",
+        "\tpos = \"over\";",
+        "\t",
+        "\tif (rpos > 80) {",
+        "\t\tpos = \"below\";",
+        "\t} else if (rpos < 20) {",
+        "\t\tpos = \"above\";",
+        "\t} ",
+        "\treturn rn;",
         " }"
        ]
       },
          "items" : [
           {
            "$ xns" : "Gtk",
+           "bool has_frame" : false,
            "label" : "Delete Element",
            "listeners" : {
             "clicked" : [
           },
           {
            "$ xns" : "Gtk",
+           "bool has_frame" : false,
            "label" : "Save as Template",
            "listeners" : {
             "clicked" : [
           },
           {
            "$ xns" : "Gtk",
+           "bool has_frame" : false,
            "label" : "Save as Module",
            "listeners" : {
             "clicked" : [
    "| JsRender.JsRender getActiveFile" : [
     "() {",
     "    return this.main_window.windowstate.file;",
+    "    ",
     "}",
     ""
    ],
    ],
    "| void removeErrors" : [
     "() {",
+    "\tif (this.error_widgets == null || this.error_widgets.size < 1) {",
+    " \t\treturn;",
+    "\t}",
+    "\tforeach(var child in this.error_widgets) {",
+    "\t",
+    "\t\tif (child.has_css_class(\"node-err\")) {",
+    "\t\t\tchild.remove_css_class(\"node-err\");",
+    "\t\t}",
+    "\t\tif (child.has_css_class(\"node-warn\")) {",
+    "\t\t\tchild.remove_css_class(\"node-warn\");",
+    "\t\t}",
+    "\t\t",
+    "\t\tif (child.has_css_class(\"node-depr\")) {",
+    "\t\t\tchild.remove_css_class(\"node-depr\");",
+    "\t\t}",
+    "\t}",
+    "\tthis.error_widgets  = null;",
+    "\treturn;",
+    "\t",
+    "\t/*",
     "\tvar  child = this.view.el.get_first_child(); ",
     " ",
     "\tvar reading_header = true;",
     "        child = child.get_next_sibling(); ",
     "\t}",
     "\t//GLib.debug(\"Rturning null\");",
+    "\t*/",
     "     ",
     "}"
    ],
     "\t\treturn;",
     "\t}",
     "\tthis.removeErrors();",
-    "\t",
+    "\tthis.error_widgets = new Gee.ArrayList<Gtk.Widget>();",
     "\tforeach(var diag in ar) { ",
     "\t",
     "\t\t ",
     "    \tif (w == null) {",
     "    \t\treturn;",
     "\t\t}",
+    "\t\tthis.error_widgets.add(w);",
     "\t\t// always show errors.",
     "\t\tvar ed = diag.category.down();",
     "\t\tif (ed != \"err\" && w.has_css_class(\"node-err\")) {",