fix merge
[roobuilder] / src / Builder4 / WindowLeftTree.bjs
index e1e1a17..5ac6726 100644 (file)
     },
     {
      "$ xns" : "Gtk",
-     "* init" : [
-      " this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
-      " "
-     ],
+     "Gtk.PolicyType hscrollbar_policy" : "Gtk.PolicyType.AUTOMATIC",
+     "Gtk.PolicyType vscrollbar_policy" : "Gtk.PolicyType.AUTOMATIC",
      "bool has_frame" : true,
      "bool hexpand" : true,
      "bool vexpand" : true,
@@ -37,6 +35,7 @@
      "items" : [
       {
        "# bool blockChanges" : false,
+       "$ JsRender.Node? dragNode" : "null",
        "$ string lastEventSource" : "\"\"",
        "$ xns" : "Gtk",
        "* init" : [
@@ -60,6 +59,9 @@
         "#left-tree-view indent {",
         "-gtk-icon-size : 2px;",
         "}",
+        "#left-tree-view indent:nth-last-child(2)  {",
+        "min-width: 24px;",
+        "}",
         "\");",
         "",
         "\tGtk.StyleContext.add_provider_for_display(",
            "\tGLib.debug(\"SOURCE: drag-begin\");",
            "\t ",
            "    // find what is selected in our tree...",
-           "   var data = _this.selmodel.getSelectedNode();",
+           "    var data = _this.selmodel.getSelectedNode();",
            "\tif (data == null) {",
            "\t\treturn  ;",
            "\t}",
-           "\t ",
+           "\t_this.view.dragNode = data;",
            "    var xname = data.fqn();",
            "    GLib.debug (\"XNAME  IS %s\", xname);",
            "",
            " ",
            "}"
           ],
+          "drag_cancel" : [
+           "(drag, reason) => {",
+           "",
+           "\t_this.view.dragNode = null;",
+           "\treturn true;",
+           "}",
+           ""
+          ],
+          "drag_end" : [
+           "(drag, delete_data) => {",
+           "",
+           "_this.view.dragNode = null;",
+           "}",
+           ""
+          ],
           "prepare" : [
            "(x, y) => {",
            "",
            "\t",
            "\tthis.addHighlight(null,\"\");",
            " ",
-           " ",
+           " \tvar is_shift = _this.keystate.is_shift > 0;",
            " ",
            " \tvar pos = \"\";",
            " \t// -- get position..",
            "\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\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\t\t\t\t\treturn false;\t",
+           "\t\t \t\t\t}",
+           "\t\t \t\t\t",
+           "\t\t \t\t}",
+           "\t\t\t\t",
+           "\t\t\t\t",
            "\t\t\t}",
            " \t\t}",
            " \t\t",
            "\t\t\treturn false;",
            "",
            "\t\t}",
+           "\t\tif (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) {",
+           " \t\t\tGLib.debug(\"shift drop not self not allowed\");",
+           "\t\t\treturn false;\t",
+           "\t\t}",
            "\t}",
            " \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\t",
            " \t\t\t_this.model.selectNode(dropNode); ",
+           " \t\t\t",
            " \t\t\t_this.changed();\t\t\t\t \t\t",
            "\t \t\treturn true;",
            "\t \t\t",
            " \t\tcase \"above\":",
            " \t\t\tGLib.debug(\"Above - insertBefore\");",
            " \t\t",
-           " \t\t\tnode.parent.insertBefore(dropNode, node);",
+           "\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\t\t_this.model.selectNode(dropNode); \t\t\t",
            " \t\t\t_this.changed();",
            " \t\t\treturn true;",
            " \t\t\t",
            " \t\tcase \"below\":",
            " \t\t\tGLib.debug(\"Below - insertAfter\"); \t\t",
+           "\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\t\t",
            " \t\t\tnode.parent.insertAfter(dropNode, node);",
            " \t\t\t_this.model.selectNode(dropNode);\t",
            " \t\t\t_this.changed();",
           "motion" : [
            "(  x, y) => {",
            " ",
+           "\tvar is_shift = _this.keystate.is_shift > 0;",
+           "\t",
+           "\tGLib.debug(\"shift is    %s\", _this.keystate.is_shift > 0 ? \"SHIFT\" : \"-\");",
            "\tstring pos; // over / before / after..",
            "",
-           "    GLib.debug(\"got drag motion\");",
+           "    //GLib.debug(\"got drag motion\");",
            "",
            "    GLib.Value v = GLib.Value(typeof(string));",
            "   \t//var str = drop.read_text( [ \"text/plain\" ] 0);",
            "\t\treturn Gdk.DragAction.COPY;\t ",
            "\t",
            "\t}",
-           "",
-           "\tGLib.debug(\"got %s\", v.get_string());",
+           " ",
+           "\t//GLib.debug(\"got %s\", v.get_string());",
            "\t  ",
            "\tif (this.lastDragString != v.get_string() || this.lastDragNode == null) {",
            "\t\t// still dragging same node",
            "\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\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\t \t\t\t\tthis.addHighlight(null, \"\");",
+           "\t\t \t\t\t\treturn Gdk.DragAction.COPY;\t",
+           "\t\t \t\t\t}",
+           "\t\t \t\t\t",
+           "\t\t \t\t}",
+           "\t\t\t\t",
            "\t\t\t}",
+           "\t\t\t",
+           "\t\t\t",
+           "\t\t\t",
            " \t\t}",
            " \t\t",
+           " \t\t",
            " \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\tthis.addHighlight(null, \"\"); ",
-           "\t\t\treturn Gdk.DragAction.COPY;\t\t",
+           "\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\tthis.addHighlight(null, \"\");",
+           " \t\t\t\treturn Gdk.DragAction.COPY;\t",
+           " \t\t\t}",
            "\t\t}",
+           " \t\t\t",
            "\t}",
            " \t",
            " \t",
            " \t    // _this.view.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
            "\tvar w = _this.view.getWidgetAt(x,y);",
            "\tthis.addHighlight(w, pos); ",
-           "    return Gdk.DragAction.COPY;\t\t\t",
+           "\treturn is_shift ?  Gdk.DragAction.MOVE :  Gdk.DragAction.COPY;\t\t",
            "}"
           ]
          },
             "\t\t",
             "\t\t}",
             "\t);",
+            "\tif (_this.selmodel.el == null) {",
+            "\t\treturn this.el;",
+            "\t}",
             "\t_this.selmodel.el.set_model(this.el);",
             "\treturn this.el;",
             "}"
             "        return;",
             "    }",
             "  \tm.append(f.tree);",
+            "  \t",
             "  \t// expand???",
             "",
             "/*",
             "    //_this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);",
             " ",
             "    _this.selmodel.el.set_selected(Gtk.INVALID_LIST_POSITION);",
-            "   ",
+            "   _this.updateErrors();",
             "    return;",
             " ",
             "            ",
             "\t}",
             "\tGLib.debug(\"Select %d\", row);",
             "\ts.set_selected(row);",
-            "\t_this.node_selected(node);\t\t\t",
+            "\t_this.view.el.scroll_to(row, null, Gtk.ListScrollFlags.SELECT, null);",
+            "\t//_this.node_selected(node);\t\t\t",
             "\t",
             "",
             "}"
          ],
          "string title" : "Add",
          "xtype" : "ColumnViewColumn"
+        },
+        {
+         "$ xns" : "Gtk",
+         "id" : "keystate",
+         "int is_shift" : 0,
+         "listeners" : {
+          "key_pressed" : [
+           "(keyval, keycode, state) => {",
+           "",
+           " \tif (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {",
+           " \t\tthis.is_shift = 1;",
+           "\t}",
+           "\treturn true;",
+           "}",
+           ""
+          ],
+          "key_released" : [
+           "(keyval, keycode, state) => {",
+           "\tGLib.debug(\"key release %d, %d, %d\" , (int) keyval, (int)  keycode, state);",
+           " \tif (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {",
+           " \t\tthis.is_shift = 0;",
+           "\t}",
+           "\t//GLib.debug(\"set state %d , shift = %d\", (int)this.el.get_current_event_state(), Gdk.ModifierType.SHIFT_MASK);",
+           "",
+           "",
+           " ",
+           "}"
+          ]
+         },
+         "xtype" : "EventControllerKey"
         }
        ],
        "string name" : "left-tree-view",
            "label" : "Delete Element",
            "listeners" : {
             "clicked" : [
-             "  ( ) => {",
-             "    ",
-             "    print(\"ACTIVATE?\");",
-             "    ",
-             "  \t_this.LeftTreeMenu.el.hide();",
-             "     _this.model.deleteSelected();",
+             " ( ) => {",
+             "_this.LeftTreeMenu.el.hide();",
+             " _this.model.deleteSelected();",
+             "_this.changed();",
              "}"
             ]
            },