From: Alan Date: Thu, 25 Jan 2024 10:08:11 +0000 (+0800) Subject: Fix #7987 - drag move supported with shift key now X-Git-Tag: release-5.0.2~30^2 X-Git-Url: http://git.roojs.org/?p=roobuilder;a=commitdiff_plain;h=f284cfb87a5e06ed4068f75cea5a9f108a69e1b2 Fix #7987 - drag move supported with shift key now --- 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", diff --git a/src/Builder4/WindowLeftTree.vala b/src/Builder4/WindowLeftTree.vala index a56c2154b..443b713f7 100644 --- a/src/Builder4/WindowLeftTree.vala +++ b/src/Builder4/WindowLeftTree.vala @@ -18,6 +18,7 @@ public class Xcls_WindowLeftTree : Object public Xcls_selmodel selmodel; public Xcls_model model; public Xcls_maincol maincol; + public Xcls_keystate keystate; public Xcls_LeftTreeMenu LeftTreeMenu; // my vars (def) @@ -126,16 +127,14 @@ public class Xcls_WindowLeftTree : Object // my vars (dec) // set gobject values + this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC; this.el.has_frame = true; this.el.hexpand = true; this.el.vexpand = true; + this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC; new Xcls_view( _this ); this.el.child = _this.view.el; new Xcls_LeftTreeMenu( _this ); - - // init method - - this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); } // user defined functions @@ -152,6 +151,7 @@ public class Xcls_WindowLeftTree : Object public string lastEventSource; public bool button_is_pressed; public Gtk.CssProvider css; + public JsRender.Node? dragNode; // ctor public Xcls_view(Xcls_WindowLeftTree _owner ) @@ -166,6 +166,7 @@ public class Xcls_WindowLeftTree : Object this.headers_visible = false; this.lastEventSource = ""; this.button_is_pressed = false; + this.dragNode = null; // set gobject values this.el.name = "left-tree-view"; @@ -190,6 +191,8 @@ public class Xcls_WindowLeftTree : Object var child_8 = new Xcls_ColumnViewColumn15( _this ); child_8.ref(); this.el.append_column ( child_8.el ); + new Xcls_keystate( _this ); + this.el.add_controller( _this.keystate.el ); // init method @@ -631,6 +634,11 @@ public class Xcls_WindowLeftTree : Object this.el.actions = Gdk.DragAction.COPY | Gdk.DragAction.MOVE ; //listeners + this.el.drag_cancel.connect( (drag, reason) => { + + _this.view.dragNode = null; + return true; + }); this.el.prepare.connect( (x, y) => { @@ -671,11 +679,11 @@ public class Xcls_WindowLeftTree : Object GLib.debug("SOURCE: drag-begin"); // find what is selected in our tree... - var data = _this.selmodel.getSelectedNode(); + var data = _this.selmodel.getSelectedNode(); if (data == null) { return ; } - + _this.view.dragNode = data; var xname = data.fqn(); GLib.debug ("XNAME IS %s", xname); @@ -686,6 +694,10 @@ public class Xcls_WindowLeftTree : Object this.el.set_icon(paintable, 0,0); + }); + this.el.drag_end.connect( (drag, delete_data) => { + + _this.view.dragNode = null; }); } @@ -942,9 +954,12 @@ public class Xcls_WindowLeftTree : Object }); this.el.motion.connect( ( x, y) => { + var is_shift = _this.keystate.is_shift > 0; + + GLib.debug("shift is %s", _this.keystate.is_shift > 0 ? "SHIFT" : "-"); string pos; // over / before / after.. - GLib.debug("got drag motion"); + //GLib.debug("got drag motion"); GLib.Value v = GLib.Value(typeof(string)); //var str = drop.read_text( [ "text/plain" ] 0); @@ -956,8 +971,8 @@ public class Xcls_WindowLeftTree : Object return Gdk.DragAction.COPY; } - - GLib.debug("got %s", v.get_string()); + + //GLib.debug("got %s", v.get_string()); if (this.lastDragString != v.get_string() || this.lastDragNode == null) { // still dragging same node @@ -1021,23 +1036,44 @@ public class Xcls_WindowLeftTree : Object pos = "over"; } else { GLib.debug("drop contains %s - using %s" , node.parent.fqn(), pos); + if (_this.view.dragNode != null && is_shift) { + if (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) { + GLib.debug("shift drop not self not allowed"); + this.addHighlight(null, ""); + return Gdk.DragAction.COPY; + } + + } + } + + + } + } if (pos == "over") { if (!drop_on_to.contains(node.fqn())) { GLib.debug("drop on does not contain %s - try center" , node.fqn()); this.addHighlight(null, ""); - return Gdk.DragAction.COPY; + return is_shift ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY; + } + if (_this.view.dragNode != null && is_shift) { + if (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) { + GLib.debug("shift drop not self not allowed"); + this.addHighlight(null, ""); + return Gdk.DragAction.COPY; + } } + } // _this.view.highlightDropPath("", (Gtk.TreeViewDropPosition)0); var w = _this.view.getWidgetAt(x,y); this.addHighlight(w, pos); - return Gdk.DragAction.COPY; + return is_shift ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY; }); this.el.leave.connect( ( ) => { this.addHighlight(null,""); @@ -1047,7 +1083,7 @@ public class Xcls_WindowLeftTree : Object this.addHighlight(null,""); - + var is_shift = _this.keystate.is_shift > 0; var pos = ""; // -- get position.. @@ -1104,6 +1140,15 @@ public class Xcls_WindowLeftTree : Object pos = "over"; } else { GLib.debug("drop contains %s - using %s" , node.parent.fqn(), pos); + if (_this.view.dragNode != null && is_shift) { + if (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) { + GLib.debug("shift drop not self not allowed"); + return false; + } + + } + + } } @@ -1114,25 +1159,47 @@ public class Xcls_WindowLeftTree : Object return false; } + if (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) { + GLib.debug("shift drop not self not allowed"); + return false; + } } switch(pos) { case "over": node.appendChild(dropNode); + if (is_shift && _this.view.dragNode != null) { + _this.model.selectNode(null); + _this.view.dragNode.remove(); + } + + _this.model.selectNode(dropNode); + _this.changed(); return true; case "above": GLib.debug("Above - insertBefore"); - node.parent.insertBefore(dropNode, node); + node.parent.insertBefore(dropNode, node); + if (is_shift && _this.view.dragNode != null) { + _this.model.selectNode(null); + _this.view.dragNode.remove(); + } + _this.model.selectNode(dropNode); _this.changed(); return true; case "below": GLib.debug("Below - insertAfter"); + if (is_shift && _this.view.dragNode != null) { + _this.model.selectNode(null); + _this.view.dragNode.remove(); + } + + node.parent.insertAfter(dropNode, node); _this.model.selectNode(dropNode); _this.changed(); @@ -1682,6 +1749,50 @@ public class Xcls_WindowLeftTree : Object } + public class Xcls_keystate : Object + { + public Gtk.EventControllerKey el; + private Xcls_WindowLeftTree _this; + + + // my vars (def) + public int is_shift; + + // ctor + public Xcls_keystate(Xcls_WindowLeftTree _owner ) + { + _this = _owner; + _this.keystate = this; + this.el = new Gtk.EventControllerKey(); + + // my vars (dec) + this.is_shift = 0; + + // set gobject values + + //listeners + this.el.key_released.connect( (keyval, keycode, state) => { + GLib.debug("key release %d, %d, %d" , (int) keyval, (int) keycode, state); + if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) { + this.is_shift = 0; + } + //GLib.debug("set state %d , shift = %d", (int)this.el.get_current_event_state(), Gdk.ModifierType.SHIFT_MASK); + + + + }); + this.el.key_pressed.connect( (keyval, keycode, state) => { + + if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) { + this.is_shift = 1; + } + return true; + }); + } + + // user defined functions + } + public class Xcls_LeftTreeMenu : Object { @@ -1701,13 +1812,13 @@ public class Xcls_WindowLeftTree : Object // my vars (dec) // set gobject values - var child_1 = new Xcls_Box18( _this ); + var child_1 = new Xcls_Box19( _this ); this.el.child = child_1.el; } // user defined functions } - public class Xcls_Box18 : Object + public class Xcls_Box19 : Object { public Gtk.Box el; private Xcls_WindowLeftTree _this; @@ -1716,7 +1827,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) // ctor - public Xcls_Box18(Xcls_WindowLeftTree _owner ) + public Xcls_Box19(Xcls_WindowLeftTree _owner ) { _this = _owner; this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 ); @@ -1724,20 +1835,20 @@ public class Xcls_WindowLeftTree : Object // my vars (dec) // set gobject values - var child_1 = new Xcls_Button19( _this ); + var child_1 = new Xcls_Button20( _this ); child_1.ref(); this.el.append( child_1.el ); - var child_2 = new Xcls_Button20( _this ); + var child_2 = new Xcls_Button21( _this ); child_2.ref(); this.el.append( child_2.el ); - var child_3 = new Xcls_Button21( _this ); + var child_3 = new Xcls_Button22( _this ); child_3.ref(); this.el.append( child_3.el ); } // user defined functions } - public class Xcls_Button19 : Object + public class Xcls_Button20 : Object { public Gtk.Button el; private Xcls_WindowLeftTree _this; @@ -1746,7 +1857,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) // ctor - public Xcls_Button19(Xcls_WindowLeftTree _owner ) + public Xcls_Button20(Xcls_WindowLeftTree _owner ) { _this = _owner; this.el = new Gtk.Button(); @@ -1767,7 +1878,7 @@ public class Xcls_WindowLeftTree : Object // user defined functions } - public class Xcls_Button20 : Object + public class Xcls_Button21 : Object { public Gtk.Button el; private Xcls_WindowLeftTree _this; @@ -1776,7 +1887,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) // ctor - public Xcls_Button20(Xcls_WindowLeftTree _owner ) + public Xcls_Button21(Xcls_WindowLeftTree _owner ) { _this = _owner; this.el = new Gtk.Button(); @@ -1802,7 +1913,7 @@ public class Xcls_WindowLeftTree : Object // user defined functions } - public class Xcls_Button21 : Object + public class Xcls_Button22 : Object { public Gtk.Button el; private Xcls_WindowLeftTree _this; @@ -1811,7 +1922,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) // ctor - public Xcls_Button21(Xcls_WindowLeftTree _owner ) + public Xcls_Button22(Xcls_WindowLeftTree _owner ) { _this = _owner; this.el = new Gtk.Button(); diff --git a/src/JsRender/Node.vala b/src/JsRender/Node.vala index 7c448bb06..a06076a62 100644 --- a/src/JsRender/Node.vala +++ b/src/JsRender/Node.vala @@ -151,6 +151,20 @@ public class JsRender.Node : GLib.Object { } + public bool has_parent(Node n) + { + if (this.parent == null) { + return false; + } + if (this.parent.oid == n.oid) { + return true; + } + + + return this.parent.has_parent(n); + } + + public Gee.ArrayList readItems() { return this.items; // note should not modify add/remove from this directly.. @@ -212,6 +226,7 @@ public class JsRender.Node : GLib.Object { + //GLib.debug("setLine %d, %s", line, type + ":" + prop); } public void sortLines() { diff --git a/src/Palete/ValaCompileRequest.vala b/src/Palete/ValaCompileRequest.vala index 62319fbe2..90982ccd7 100644 --- a/src/Palete/ValaCompileRequest.vala +++ b/src/Palete/ValaCompileRequest.vala @@ -64,7 +64,7 @@ namespace Palete { if (GLib.FileUtils.test(this.project.path + "/build/meson-info", GLib.FileTest.EXISTS)) { return 0; //assume it's been set up. } - string[] args = { "/usr/bin/meson" ,"setup", "build", "--prefix=/" }; + string[] args = { "/usr/bin/meson" ,"setup", "build", "--prefix=/usr" }; GLib.debug("running meson"); this.spawn = new Spawn(this.project.path , args); this.spawn.output_line.connect(( str) => {