Fix #8062 - fix new file node selection issue
[roobuilder] / src / Builder4 / WindowLeftTree.bjs
index fd97955..9bf6162 100644 (file)
@@ -3,6 +3,7 @@
  "gen_extended" : false,
  "items" : [
   {
+   "# Gee.ArrayList<Gtk.Widget>? error_widgets" : "null",
    "# Xcls_MainWindow? main_window" : "null",
    "# int last_error_counter" : "-1",
    "$ xns" : "Gtk",
           "drop" : [
            "(v, x, y) => {",
            "\t",
+           "\t// must get the pos before we clear the hightlihg.",
+           " \tvar pos = \"\";",
+           " \tvar row = _this.view.getRowAt(x,y, out pos);",
            "\tthis.addHighlight(null,\"\");",
            " ",
            " \tvar is_shift = _this.keystate.is_shift > 0;",
            " ",
-           " \tvar pos = \"\";",
+           "",
            " \t// -- get position..",
            " \tif (this.lastDragString != v.get_string() || this.lastDragNode == null) {",
            "\t\t// still dragging same node",
            " \t     ",
            "       ",
            "    var dropNode = new JsRender.Node(); ",
-           "\tdropNode.loadFromJsonString(v.get_string(), 1);",
+           "\tdropNode.loadFromJsonString(v.get_string(), 2);",
+           "\tGLib.debug(\"dropped node %s\", dropNode.toJsonString());",
+           "\t",
+           "\t",
            "\tvar drop_on_to = _this.main_window.windowstate.file.palete().getDropList(dropNode.fqn());",
            "   ",
            "    // if there are not items in the tree.. the we have to set isOver to true for anything..",
            "\t\t\treturn false;\t",
            "\t\t}",
            "\t\t// add new node to top..",
-           "\t\t",
+           "\t\tGLib.debug(\"adding to top\");",
            "\t\t",
            "\t\t var m = (GLib.ListStore) _this.model.el.model;",
            "     \t_this.main_window.windowstate.file.tree = dropNode;  ",
            "\t\tm.append(dropNode);",
            "\t\t_this.model.selectNode(dropNode); \t",
            "\t\t_this.changed();",
+           "\t\t_this.node_selected(dropNode);",
            "\t\treturn true; // no need to highlight?",
            "     ",
            "    }",
            "",
            "",
            "",
-           "\tvar row = _this.view.getRowAt(x,y, out pos);",
+           "",
            "\tif (row < 0) {",
+           "\t\tGLib.debug(\"could not get row %d,%d, %s\", (int)x,(int)y,pos);",
            "\t\treturn   false; //Gdk.DragAction.COPY;",
            "\t}",
            "\tvar tr = (Gtk.TreeListRow)_this.view.el.model.get_object(row);",
            " \t",
            " \tswitch(pos) {",
            " \t\tcase \"over\":",
-           "\t \t\tnode.appendChild(dropNode);",
+           "",
            "\t \t\tif (is_shift && _this.view.dragNode != null) {",
            "\t\t \t\t_this.model.selectNode(null); ",
            "\t\t \t\t_this.view.dragNode.remove();",
            "\t \t\t}",
-           "\t \t\t\t",
+           " \t \t\tnode.appendChild(dropNode);\t\t\t",
            "\t \t\tdropNode.updated_count++;",
            " \t\t\t_this.model.selectNode(dropNode); ",
            " \t\t\t",
            " \t\tcase \"above\":",
            " \t\t\tGLib.debug(\"Above - insertBefore\");",
            " \t\t",
-           "\t\t\tnode.parent.insertBefore(dropNode, node);",
+           "",
            "\t \t\tif (is_shift && _this.view.dragNode != null) {",
            "\t\t \t\t_this.model.selectNode(null); \t \t\t",
            "\t\t \t\t_this.view.dragNode.remove();",
            "\t \t\t}",
+           "\t\t\tnode.parent.insertBefore(dropNode, node);\t \t\t",
            "\t\t\tdropNode.updated_count++;",
            " \t\t\t_this.model.selectNode(dropNode); \t\t\t",
            " \t\t\t_this.changed();",
            " ",
            "\tvar is_shift = _this.keystate.is_shift > 0;",
            "\t",
-           "\tGLib.debug(\"shift is    %s\", _this.keystate.is_shift > 0 ? \"SHIFT\" : \"-\");",
+           "\t//GLib.debug(\"shift is    %s\", _this.keystate.is_shift > 0 ? \"SHIFT\" : \"-\");",
            "\tstring pos; // over / before / after..",
            "",
            "    //GLib.debug(\"got drag motion\");",
            "   \ttry {",
            "  \t\tcont.get_value(ref v);",
            "\t} catch (GLib.Error e) {",
-           "\t    GLib.debug(\"failed to get drag value\");",
+           "\t   // GLib.debug(\"failed to get drag value\");",
            "\t\treturn Gdk.DragAction.COPY;\t ",
            "\t",
            "\t}",
            "     foreach(var dp in drop_on_to) {",
            "     \tstr += dp;",
            " \t}",
-           " \tGLib.debug(\"droplist: %s\", string.joinv(\", \", str));",
+           " \t//GLib.debug(\"droplist: %s\", string.joinv(\", \", str));",
            "     ",
            "     ",
            "    // if there are not items in the tree.. the we have to set isOver to true for anything..",
            "    }",
            "    ",
            "    ",
-           " \tGLib.debug(\"check is over\");",
+           "",
            " \t ",
            "    // if path of source and dest are inside each other..",
            "    // need to add source info to drag?",
            "    // the fail();",
            " \tvar row = _this.view.getRowAt(x,y, out pos);",
-           " \t",
+           " \t//GLib.debug(\"check is over %d, %d, %s\", (int)x,(int)y, pos);",
+           "",
            " \tif (row < 0) {",
            "\t\tthis.addHighlight(null, \"\");\t",
            "\t \treturn Gdk.DragAction.COPY;",
            "\t",
            "\tvar node =  (JsRender.Node)tr.get_item();",
            "\t",
-           "\tGLib.debug(\"Drop over node: %s\", node.fqn());",
+           "\t//GLib.debug(\"Drop over node: %s\", node.fqn());",
            "\t",
            "",
            " \tif (pos == \"above\" || pos == \"below\") {",
            "\t\tif (node.parent == null) {",
-           "\t\t\tGLib.debug(\"no parent try center\");",
+           "\t\t\t//GLib.debug(\"no parent try center\");",
            "\t\t\tpos = \"over\";",
            "\t\t} else {",
            "\t \t\t ",
            "\t \t\tif (!drop_on_to.contains(node.parent.fqn())) {",
-           "\t\t\t\tGLib.debug(\"drop on does not contain %s - try center\" , node.parent.fqn());",
+           "\t\t\t\t//GLib.debug(\"drop on does not contain %s - try center\" , node.parent.fqn());",
            "\t \t\t\tpos = \"over\";",
            " \t\t\t} else {",
-           "\t\t\t\tGLib.debug(\"drop  contains %s - using %s\" , node.parent.fqn(), pos);",
+           "\t\t\t\t//GLib.debug(\"drop  contains %s - using %s\" , node.parent.fqn(), pos);",
            "\t\t\t\tif (_this.view.dragNode  != null && is_shift) {",
            "\t\t \t\t\tif (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) {",
            "\t\t\t \t\t\tGLib.debug(\"shift drop not self not allowed\");",
            " \t}",
            " \tif (pos == \"over\") {",
            "\t \tif (!drop_on_to.contains(node.fqn())) {",
-           "\t\t\tGLib.debug(\"drop on does not contain %s - try center\" , node.fqn());",
+           "\t\t\t//GLib.debug(\"drop on does not contain %s - try center\" , node.fqn());",
            "\t\t\tthis.addHighlight(null, \"\"); ",
            "\t\t\treturn is_shift ?  Gdk.DragAction.MOVE :  Gdk.DragAction.COPY;\t\t",
            "\t\t}",
            "\t\tif (_this.view.dragNode  != null && is_shift) {",
            " \t\t\tif (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) {",
-           "\t \t\t\tGLib.debug(\"shift drop not self not allowed\");",
+           "\t \t\t\t//GLib.debug(\"shift drop not self not allowed\");",
            " \t\t\t\tthis.addHighlight(null, \"\");",
            " \t\t\t\treturn Gdk.DragAction.COPY;\t",
            " \t\t\t}",
           "(Gtk.Widget? w, string hl) {",
           "\tif (this.highlightWidget != null) {",
           "\t\tvar ww  = this.highlightWidget;",
-          "\t\tGLib.debug(\"clear drag from previous highlight\");",
+          "\t\t//GLib.debug(\"clear drag from previous highlight\");",
           "\t\tif (ww.has_css_class(\"drag-below\")) {",
           "\t\t\t ww.remove_css_class(\"drag-below\");",
           "\t\t}",
           "\t\t}",
           "\t}",
           "\tif (w != null) {",
-          "\t\tGLib.debug(\"add drag=%s to widget\", hl);\t",
+          "\t\t//GLib.debug(\"add drag=%s to widget\", hl);\t",
           "\t\tif (!w.has_css_class(\"drag-\" + hl)) {",
           "\t\t\tw.add_css_class(\"drag-\" + hl);",
           "\t\t}",
         {
          "$ xns" : "Gtk",
          "* prop" : "model",
+         "bool can_unselect" : true,
          "id" : "selmodel",
          "items" : [
           {
             "\t     return;",
             "     }",
             "    _this.selmodel.el.unselect_all();",
-            "    ",
-            "    node.remove();",
-            " \tGLib.debug(\"delete Selected - done\");",
-            "    _this.changed();",
+            "    if (node.parent != null) {",
+            "\t\tnode.remove();",
+            "\t \tGLib.debug(\"delete Selected - done\");",
+            "\t\t_this.changed();",
+            "\t\treturn;",
+            "\t}",
+            "\tthis.updateModel(null);",
+            "\t_this.main_window.windowstate.file.tree = null;",
+            "\t_this.changed();",
+            "\t_this.node_selected(null);",
             "/*    ",
             "    print(\"DELETE SELECTED?\");",
             "    //_this.view.blockChanges = true;",
            "\t    // why dup_?",
            "\t    ",
            "",
-           "\t    GLib.debug (\"calling left_tree.node_selected\");",
+           "\t    GLib.debug (\"calling left_tree.node_selected %s\", snode.toJsonString());",
            "\t    _this.node_selected(snode);",
            "\t   ",
            "\t     ",
           "() {",
           "  if (this.el.selected_item == null) {",
           "\t\treturn null;",
-          "  }\t\t\t        ",
+          "  }\t",
+          "   ",
+          "  ",
           "   var tr = (Gtk.TreeListRow)this.el.selected_item;",
+          "  ",
           "   return (JsRender.Node)tr.get_item();",
           "\t ",
           "}"
            "listeners" : {
             "bind" : [
              "(listitem) => {",
-             "\t GLib.debug(\"listitme is is %s\", ((Gtk.ListItem)listitem).get_type().name());",
+             "\t// GLib.debug(\"listitme is is %s\", ((Gtk.ListItem)listitem).get_type().name());",
              "\t",
              "\t//var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();",
              "\tvar expand = (Gtk.TreeExpander)  ((Gtk.ListItem)listitem).get_child();",
              "\t",
              "\tvar lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();",
              "\tvar node = (JsRender.Node) lr.get_item();",
-             "\t",
-             "   GLib.debug(\"node is %s\", node.get_type().name());",
+             "\tif (node == null || node.fqn() == \"\") {",
+             "\t\treturn;",
+             "\t}",
+             "   //GLib.debug(\"node is %s\", node.get_type().name());",
              "// was item (1) in old layout",
              "",
              "\t",
    ],
    "| 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\")) {",