X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=src%2FBuilder4%2FWindowLeftTree.bjs;h=6fbd90d5bcc29e35811c4e99d67680566c52568f;hb=f284cfb87a5e06ed4068f75cea5a9f108a69e1b2;hp=148220b3daad1ab7a792db9825814288aed63f12;hpb=45be8f358c440d4422ed87a39a16f57c7ecf6d61;p=roobuilder diff --git a/src/Builder4/WindowLeftTree.bjs b/src/Builder4/WindowLeftTree.bjs index 148220b3d..6fbd90d5b 100644 --- a/src/Builder4/WindowLeftTree.bjs +++ b/src/Builder4/WindowLeftTree.bjs @@ -26,10 +26,8 @@ }, { "$ 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" : [ @@ -220,11 +219,11 @@ "\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);", "", @@ -237,6 +236,21 @@ " ", "}" ], + "drag_cancel" : [ + "(drag, reason) => {", + "", + "\t_this.view.dragNode = null;", + "\treturn true;", + "}", + "" + ], + "drag_end" : [ + "(drag, delete_data) => {", + "", + "_this.view.dragNode = null;", + "}", + "" + ], "prepare" : [ "(x, y) => {", "", @@ -503,7 +517,7 @@ "\t", "\tthis.addHighlight(null,\"\");", " ", - " ", + " \tvar is_shift = _this.keystate.is_shift > 0;", " ", " \tvar pos = \"\";", " \t// -- get position..", @@ -560,6 +574,15 @@ "\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", @@ -570,25 +593,47 @@ "\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();", @@ -618,9 +663,12 @@ "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);", @@ -632,8 +680,8 @@ "\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", @@ -697,23 +745,44 @@ "\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", "}" ] }, @@ -1178,6 +1247,36 @@ ], "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",