From: Alan Knowles Date: Wed, 24 Sep 2014 06:31:07 +0000 (+0800) Subject: sync X-Git-Url: http://git.roojs.org/?p=app.Builder.js;a=commitdiff_plain;h=9d3d43bad904f9872aedd509065ea370d3272c4e sync --- diff --git a/Builder4/WindowLeftTree.bjs b/Builder4/WindowLeftTree.bjs index f1f0fb46b..7d86a561f 100644 --- a/Builder4/WindowLeftTree.bjs +++ b/Builder4/WindowLeftTree.bjs @@ -8,8 +8,8 @@ "items" : [ { "| JsRender.Node? getActiveElement" : " () { // return path to actie node.\n\n var path = this.getActivePath();\n if (path.length < 1) {\n return null;\n }\n return _this.model.pathToNode(path);\n \n}\n", - "@ bool before_node_change" : "(JsRender.Node? node)", "id" : "WindowLeftTree", + "@ bool before_node_change" : "(JsRender.Node? node)", "$ shadow_type" : "Gtk.ShadowType.IN", "* init" : " this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);\n \n", "| JsRender.JsRender getActiveFile" : "() {\n return this.model.file;\n}\n", @@ -24,17 +24,17 @@ { "listeners" : { "button_press_event" : " ( ev) => {\n //console.log(\"button press?\");\n if (! _this.before_node_change(null) ) {\n return true;\n }\n\n \n if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) {\n //print(\"click\" + ev.type);\n return false;\n }\n Gtk.TreePath res;\n if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {\n return true;\n }\n \n this.el.get_selection().select_path(res);\n \n //if (!this.get('/LeftTreeMenu').el) { \n // this.get('/LeftTreeMenu').init(); \n // }\n \n _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());\n _this.LeftTreeMenu.el.show_all();\n _this.LeftTreeMenu.el.popup(null, null, null, 3, ev.time);\n // print(\"click:\" + res.path.to_string());\n return true;\n}", + "drag_begin" : "( ctx) => {\n\t//print('SOURCE: drag-begin');\n \n \n //this.targetData = \"\";\n \n // find what is selected in our tree...\n \n var s = _this.view.el.get_selection();\n if (s.count_selected_rows() < 1) {\n return;\n }\n Gtk.TreeIter iter;\n Gtk.TreeModel mod;\n s.get_selected(out mod, out iter);\n\n \n\n // set some properties of the tree for use by the dropped element.\n GLib.Value value;\n _this.model.el.get_value(iter, 2, out value);\n var tp = mod.get_path(iter).to_string();\n var data = (JsRender.Node)(value.dup_object());\n var xname = data.fqn();\n print (\"XNAME IS \" + xname+ \"\\n\");\n this.dragData = tp;\n this.dropList = _this.model.file.palete().getDropList(xname);\n \n print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");\n \n\n // make the drag icon a picture of the node that was selected\n \n \n // by default returns the path..\n var path = _this.model.el.get_path(iter);\n\n \n var pix = this.el.create_row_drag_icon ( path);\n \n Gtk.drag_set_icon_surface (ctx, pix) ;\n \n return;\n}", "cursor_changed" : " ( ) => {\n\n\n if (this.blockChanges) { // probably not needed.. \n return ;\n }\n if (!_this.before_node_change(null) ) {\n\t this.blockChanges = true;\n\t this.el.get_selection().unselect_all();\n\t this.blockChanges = false;\n\t return;\n }\n if (_this.model.file == null) {\n return;\n } \n \n //var render = this.get('/LeftTree').getRenderer(); \n print(\"LEFT TREE -> view -> selection changed called\\n\");\n \n \n // -- it appears that the selection is not updated.\n \n GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {\n \n\n if (this.el.get_selection().count_selected_rows() < 1) {\n\n print(\"selected rows < 1\\n\");\n //??this.model.load( false);\n _this.node_selected(null);\n \n return false ;\n }\n \n //console.log('changed');\n var s = this.el.get_selection();\n Gtk.TreeIter iter;\n Gtk.TreeModel mod;\n s.get_selected(out mod, out iter);\n \n \n // var val = \"\";\n GLib.Value value;\n _this.model.el.get_value(iter, 2, out value);\n _this.model.activePath = mod.get_path(iter).to_string();\n \n var node = (JsRender.Node)value.dup_object();\n _this.node_selected(node);\n return false;\n }); \n //_this.after_node_change(node);\n\n// _this.model.file.changed(node, \"tree\");\n \n //Seed.print( value.get_string());\n return ;\n \n}", - "drag_begin" : "( ctx) => {\n\t//print('SOURCE: drag-begin');\n \n \n //this.targetData = \"\";\n \n // find what is selected in our tree...\n \n var s = _this.view.el.get_selection();\n if (s.count_selected_rows() < 1) {\n return;\n }\n Gtk.TreeIter iter;\n Gtk.TreeModel mod;\n s.get_selected(out mod, out iter);\n\n \n\n // set some properties of the tree for use by the dropped element.\n GLib.Value value;\n _this.model.el.get_value(iter, 2, out value);\n var tp = mod.get_path(iter).to_string();\n var data = (JsRender.Node)(value.dup_object());\n var xname = data.fqn();\n print (\"XNAME IS \" + xname+ \"\\n\");\n this.dragData = tp;\n //this.dropList = _this.model.file.palete().getDropList(xname);\n \n print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");\n \n\n // make the drag icon a picture of the node that was selected\n \n \n // by default returns the path..\n var path = _this.model.el.get_path(iter);\n\n \n var pix = this.el.create_row_drag_icon ( path);\n \n Gtk.drag_set_icon_surface (ctx, pix) ;\n \n return;\n}", "drag_end" : " (drag_context) => {\n\t//Seed.print('LEFT-TREE: drag-end');\n this.dragData = \"\";\n this.dropList = null;\n// this.targetData = \"\";\n this.highlightDropPath(\"\",0);\n// return true;\n}", - "drag_motion" : " ( ctx, x, y, time) => {\n \n // the point of this is to detect where an item could be dropped..\n print(\"got drag motion\");\n this.drag_in_motion = true;\n this.drag_x = x;\n this.drag_y = y;\n \n // request data that will be recieved by the recieve... \n Gtk.drag_get_data\n (\n this.el, // will receive 'drag-data-received' signal \n ctx, // represents the current state of the DnD \n Gdk.Atom.intern(\"STRING\",true), // the target type we want \n time // time stamp \n );\n return true;\n \n}", - "drag_data_get" : " ( drag_context, data, info, time) => {\n\n\n //print(\"drag-data-get\");\n var s = this.el.get_selection();\n if (s.count_selected_rows() < 1) {\n data.set_text(\"\",0); \n print(\"return empty string - no selection..\");\n return;\n }\n \n Gtk.TreeIter iter;\n Gtk.TreeModel mod;\n \n s.get_selected(out mod, out iter);\n \n \n \n GLib.Value value;\n _this.model.el.get_value(iter, 2, out value);\n var ndata = (JsRender.Node)(value.dup_object());\n var xname = ndata.fqn();\n \n \n var tp = mod.get_path(iter).to_string();\n // by default returns the path..\n \n if ( info != Gdk.Atom.intern(\"STRING\",true) ) {\n tp = ndata.toJsonString();\n } \n \n data.set_text(tp,tp.length); \n \n \n\n \n // print(\"return \" + tp);\n}", + "drag_motion" : " ( ctx, x, y, time) => {\n \n var src = Gtk.drag_get_source_widget(ctx);\n \n if (src != this.el) {\n \n \n \n // the point of this is to detect where an item could be dropped..\n print(\"got drag motion\");\n this.drag_in_motion = true;\n this.drag_x = x;\n this.drag_y = y;\n \n // request data that will be recieved by the recieve... \n Gtk.drag_get_data\n (\n this.el, // will receive 'drag-data-received' signal \n ctx, // represents the current state of the DnD \n Gdk.Atom.intern(\"STRING\",true), // the target type we want \n time // time stamp \n );\n return true;\n } \n\n\n\n //print(\"GETTING POS\");\n var targetData = \"\";\n\n Gtk.TreePath path;\n Gtk.TreeViewDropPosition pos;\n var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);\n\n // if there are not items in the tree.. the we have to set isOver to true for anything..\n var isEmpty = false;\n if (_this.model.el.iter_n_children(null) < 1) {\n print(\"got NO children?\\n\");\n isOver = true; //??? \n isEmpty = true;\n pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;\n }\n\n\n // ------------- a drag from self..\n\n\n //var action = Gdk.DragAction.COPY;\n // unless we are copying!!! ctl button..\n var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;\n\n\n if (_this.model.el.iter_n_children(null) < 1) {\n // no children.. -- asume it's ok..\n \n targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);\n \n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); \n Gdk.drag_status(ctx, action ,time);\n return true;\n \n // continue through to allow drop...\n\n } \n \n \n\n \n \n //print(\"ISOVER? \" + isOver);\n if (!isOver) {\n \n Gdk.drag_status(ctx, 0 ,time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); \n return false;\n\n }\n \n // drag node is parent of child..\n //console.log(\"SRC TREEPATH: \" + src.treepath);\n //console.log(\"TARGET TREEPATH: \" + data.path.to_string());\n \n // nned to check a few here..\n //Gtk.TreeViewDropPosition.INTO_OR_AFTER\n //Gtk.TreeViewDropPosition.INTO_OR_BEFORE\n //Gtk.TreeViewDropPosition.AFTER\n //Gtk.TreeViewDropPosition.BEFORE\n \n // locally dragged items to not really use the \n var selection_text = this.dragData;\n \n \n \n if (selection_text == null || selection_text.length < 1) {\n //print(\"Error - drag selection text returned NULL\");\n Gdk.drag_status(ctx, 0 ,time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);\n return false;\n }\n \n \n // see if we are dragging into ourself?\n print (\"got selection text of \" + selection_text);\n \n var target_path = path.to_string();\n //print(\"target_path=\"+target_path);\n\n // \n if (selection_text == target_path) {\n print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");\n \n Gdk.drag_status(ctx, 0 ,time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);\n return false;\n// -- fixme -- this is not really correct..\n\n }\n \n // check that \n //print(\"DUMPING DATA\");\n //console.dump(data);\n // path, pos\n \n //print(data.path.to_string() +' => '+ data.pos);\n \n // dropList is a list of xtypes that this node could be dropped on.\n // it is set up when we start to drag..\n \n \n targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);\n \n print(\"targetDAta: \" + targetData +\"\\n\");\n \n if (targetData.length < 1) {\n //print(\"Can not find drop node path\");\n \n Gdk.drag_status(ctx, 0, time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);\n return false;\n }\n \n var td_ar = targetData.split(\"|\");\n \n \n\n Gdk.drag_status(ctx, action ,time);\n this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));\n return true;\n \n \n}", + "drag_data_get" : "( drag_context, data, info, time) => {\n \n \n //print(\"drag-data-get\");\n var s = this.el.get_selection();\n if (s.count_selected_rows() < 1) {\n data.set_text(\"\",0); \n print(\"return empty string - no selection..\");\n return;\n }\n \n Gtk.TreeIter iter;\n Gtk.TreeModel mod;\n \n s.get_selected(out mod, out iter);\n \n \n \n GLib.Value value;\n _this.model.el.get_value(iter, 2, out value);\n var ndata = (JsRender.Node)(value.dup_object());\n var xname = ndata.fqn();\n \n \n var tp = mod.get_path(iter).to_string();\n // by default returns the path..\n \n if ( info != Gdk.Atom.intern(\"STRING\",true) ) {\n tp = ndata.toJsonString();\n } \n \n data.set_text(tp,tp.length); \n \n \n \n \n // print(\"return \" + tp);\n }", "drag_data_received" : " (ctx, x, y, sel, info, time) => {\n //print(\"Tree: drag-data-received\");\n\n\n var is_drag = info == Gdk.Atom.intern(\"STRING\",true);\n \n\n //print(\"GETTING POS\");\n var targetData = \"\";\n \n Gtk.TreePath path;\n Gtk.TreeViewDropPosition pos;\n var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);\n \n // if there are not items in the tree.. the we have to set isOver to true for anything..\n var isEmpty = false;\n if (_this.model.el.iter_n_children(null) < 1) {\n print(\"got NO children?\\n\");\n isOver = true; //??? \n isEmpty = true;\n pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;\n }\n \n \n //console.log(\"LEFT-TREE: drag-motion\");\n var src = Gtk.drag_get_source_widget(ctx);\n \n // a drag from elsewhere...- prevent drop..\n if (src != this.el) {\n //print(\"drag_data_recieved from another element\");\n \n \n var selection_text = sel.get_text();\n \n \n if (selection_text == null || selection_text.length < 1 || !isOver) {\n // nothing valid foudn to drop...\n if (is_drag) {\n Gdk.drag_status(ctx, 0, time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);\n return;\n }\n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n // no drop action...\n return; \n \n }\n var dropNode = new JsRender.Node(); \n \n var dropNodeType = selection_text;\n var show_templates = true;\n // for drop\n if (!is_drag && dropNodeType[0] == '{') {\n var pa = new Json.Parser();\n pa.load_from_data(dropNodeType);\n \n dropNode.loadFromJson( pa.get_root().get_object(), 2);\n dropNodeType = dropNode.fqn();\n show_templates = false;\n } else {\n\n dropNode.setFqn(selection_text);\n }\n\n \n // dropList --- need to gather this ... \n //print(\"get dropList for : %s\\n\",selection_text); \n var dropList = _this.model.file.palete().getDropList(dropNodeType);\n \n print(\"dropList: %s\\n\", string.joinv(\" , \", dropList));\n \n targetData = _this.model.findDropNodeByPath( isEmpty ? \"\" : path.to_string(), dropList, pos);\n \n print(\"targetDAta: \" + targetData +\"\\n\");\n \n if (targetData.length < 1) {\n \n // invalid drop path..\n if (this.drag_in_motion) {\n Gdk.drag_status(ctx, 0, time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);\n return;\n }\n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n // no drop action...\n return;\n }\n // valid drop path..\n \n var td_ar = targetData.split(\"|\");\n \n \n if (this.drag_in_motion) { \n Gdk.drag_status(ctx, Gdk.DragAction.COPY ,time);\n\n this.highlightDropPath( td_ar[0] , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));\n return;\n }\n // continue on to allow drop..\n \n\n // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..\n \n\n _this.model.dropNode(targetData, dropNode, show_templates);\n print(\"ADD new node!!!\\n\");\n \n ///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);\n \n Gtk.drag_finish (ctx, false, false,time);\n \n \n \n \n \n return;\n \n }\n \n // ------------- a drag from self..\n \n \n //var action = Gdk.DragAction.COPY;\n // unless we are copying!!! ctl button..\n var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;\n \n \n if (_this.model.el.iter_n_children(null) < 1) {\n // no children.. -- asume it's ok..\n \n targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);\n if (this.drag_in_motion) { \n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); \n Gdk.drag_status(ctx, action ,time);\n return;\n }\n // continue through to allow drop...\n\n } else {\n \n \n\n \n \n //print(\"ISOVER? \" + isOver);\n if (!isOver) {\n if (this.drag_in_motion) {\n Gdk.drag_status(ctx, 0 ,time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0); \n return;\n }\n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n return; // not over apoint!?! - no action on drop or motion..\n }\n \n // drag node is parent of child..\n //console.log(\"SRC TREEPATH: \" + src.treepath);\n //console.log(\"TARGET TREEPATH: \" + data.path.to_string());\n \n // nned to check a few here..\n //Gtk.TreeViewDropPosition.INTO_OR_AFTER\n //Gtk.TreeViewDropPosition.INTO_OR_BEFORE\n //Gtk.TreeViewDropPosition.AFTER\n //Gtk.TreeViewDropPosition.BEFORE\n \n // locally dragged items to not really use the \n var selection_text = this.dragData;\n \n \n \n if (selection_text == null || selection_text.length < 1) {\n //print(\"Error - drag selection text returned NULL\");\n if (this.drag_in_motion) {\n Gdk.drag_status(ctx, 0 ,time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);\n return;\n }\n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n return; /// -- fixme -- this is not really correct..\n } \n \n // see if we are dragging into ourself?\n print (\"got selection text of \" + selection_text);\n \n var target_path = path.to_string();\n //print(\"target_path=\"+target_path);\n\n // \n if (selection_text == target_path) {\n print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");\n if (this.drag_in_motion) {\n Gdk.drag_status(ctx, 0 ,time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);\n return;\n }\n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n\n return; /// -- fixme -- this is not really correct..\n\n }\n \n // check that \n //print(\"DUMPING DATA\");\n //console.dump(data);\n // path, pos\n \n //print(data.path.to_string() +' => '+ data.pos);\n \n // dropList is a list of xtypes that this node could be dropped on.\n // it is set up when we start to drag..\n \n \n targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);\n \n print(\"targetDAta: \" + targetData +\"\\n\");\n \n if (targetData.length < 1) {\n //print(\"Can not find drop node path\");\n if (this.drag_in_motion) {\n Gdk.drag_status(ctx, 0, time);\n this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);\n return;\n }\n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n return;\n }\n \n var td_ar = targetData.split(\"|\");\n \n \n if (this.drag_in_motion) { \n Gdk.drag_status(ctx, action ,time);\n this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));\n return;\n }\n // continue on to allow drop..\n }\n\n // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..\n\n\n var delete_selection_data = false;\n \n if (ctx.get_actions() == Gdk.DragAction.ASK) {\n /* Ask the user to move or copy, then set the ctx action. */\n }\n\n if (ctx.get_actions() == Gdk.DragAction.MOVE) {\n delete_selection_data = true;\n }\n \n \n // drag around.. - reorder..\n _this.model.moveNode(targetData, ctx.get_actions());\n \n \n \n \n \n // we can send stuff to souce here...\n\n\n // do we always say failure, so we handle the reall drop?\n Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);\n \n}", "drag_drop" : " ( ctx, x, y, time) => {\n //Seed.print(\"TARGET: drag-drop\");\n \n \n var src = Gtk.drag_get_source_widget(ctx);\n \n if (src != this.el) {\n \n \n \n this.drag_in_motion = false; \n // request data that will be recieved by the recieve... \n Gtk.drag_get_data\n (\n this.el, // will receive 'drag-data-received' signal \n ctx, // represents the current state of the DnD \n Gdk.Atom.intern(\"application/json\",true), // the target type we want \n time // time stamp \n );\n\n \n // No target offered by source => error\n \n\n return false;\n }\n \n // handle drop around self..\n \n \n \n //print(\"GETTING POS\");\n var targetData = \"\";\n \n Gtk.TreePath path;\n Gtk.TreeViewDropPosition pos;\n var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);\n \n // if there are not items in the tree.. the we have to set isOver to true for anything..\n var isEmpty = false;\n if (_this.model.el.iter_n_children(null) < 1) {\n print(\"got NO children?\\n\");\n isOver = true; //??? \n isEmpty = true;\n pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;\n }\n \n \n \n //var action = Gdk.DragAction.COPY;\n // unless we are copying!!! ctl button..\n var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;\n \n \n if (_this.model.el.iter_n_children(null) < 1) {\n // no children.. -- asume it's ok..\n \n targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);\n \n // continue through to allow drop...\n\n } else {\n \n \n \n \n \n //print(\"ISOVER? \" + isOver);\n if (!isOver) {\n \n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n return true; // not over apoint!?! - no action on drop or motion..\n }\n \n // drag node is parent of child..\n //console.log(\"SRC TREEPATH: \" + src.treepath);\n //console.log(\"TARGET TREEPATH: \" + data.path.to_string());\n \n // nned to check a few here..\n //Gtk.TreeViewDropPosition.INTO_OR_AFTER\n //Gtk.TreeViewDropPosition.INTO_OR_BEFORE\n //Gtk.TreeViewDropPosition.AFTER\n //Gtk.TreeViewDropPosition.BEFORE\n \n // locally dragged items to not really use the \n var selection_text = this.dragData;\n \n \n \n if (selection_text == null || selection_text.length < 1) {\n //print(\"Error - drag selection text returned NULL\");\n \n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n return true; /// -- fixme -- this is not really correct..\n } \n \n // see if we are dragging into ourself?\n print (\"got selection text of \" + selection_text);\n \n var target_path = path.to_string();\n //print(\"target_path=\"+target_path);\n\n // \n if (selection_text == target_path) {\n print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");\n \n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n\n return true; /// -- fixme -- this is not really correct..\n\n }\n \n // check that \n //print(\"DUMPING DATA\");\n //console.dump(data);\n // path, pos\n \n //print(data.path.to_string() +' => '+ data.pos);\n \n // dropList is a list of xtypes that this node could be dropped on.\n // it is set up when we start to drag..\n \n \n targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);\n \n print(\"targetDAta: \" + targetData +\"\\n\");\n \n if (targetData.length < 1) {\n //print(\"Can not find drop node path\");\n \n Gtk.drag_finish (ctx, false, false, time); // drop failed..\n return true;\n }\n \n var td_ar = targetData.split(\"|\");\n \n \n \n // continue on to allow drop..\n }\n // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..\n\n\n var delete_selection_data = false;\n \n if (ctx.get_actions() == Gdk.DragAction.ASK) {\n /* Ask the user to move or copy, then set the ctx action. */\n }\n\n if (ctx.get_actions() == Gdk.DragAction.MOVE) {\n delete_selection_data = true;\n }\n \n \n // drag around.. - reorder..\n _this.model.moveNode(targetData, ctx.get_actions());\n \n \n \n \n \n // we can send stuff to souce here...\n\n\n// do we always say failure, so we handle the reall drop?\n Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);\n\n return true;\n \n \n \n \n \n \n}" }, "# string dragData" : "", - "# string[] dropList" : "", "# int drag_x" : "", + "# string[] dropList" : "", "id" : "view", "gboolean headers_visible" : true, "# int drag_y" : "", @@ -52,8 +52,8 @@ "items" : [ { "| string findDropNode" : " (string treepath_str, string[] targets) {\n\n // this is used by the dragdrop code in the roo version AFAIR..\n\n //var path = treepath_str.replace(/^builder-/, '');\n // treemap is depreciated... - should really check if model has any entries..\n\n if (this.el.iter_n_children(null) < 1) {\n //print(\"NO KEYS\");\n return \"|%d\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);\n }\n //print(\"FIND treepath: \" + path);\n //console.dump(this.treemap);\n \n //if (!treepath_str.match(/^builder-/)) {\n // return []; // nothing!\n //}\n if (targets.length > 0 && targets[0] == \"*\") {\n return treepath_str;\n }\n return this.findDropNodeByPath(treepath_str,targets, -1);\n}\n", - "id" : "model", "currentTree" : false, + "id" : "model", "# DialogTemplateSelect template_select" : "null", "* init" : "print(\"model initialized\");\n\n", "| void loadFile" : "(JsRender.JsRender f) {\n //console.dump(f);\n this.el.clear();\n this.file = f;\n \n \n// if (!f) {\n// console.log('missing file');\n// return;\n// }\n \n // load the file if not loaded..\n if (f.tree == null) {\n f.loadItems( );\n }\n // if it's still null?\n if (f.tree == null) {\n return;\n }\n \n /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);\n \n //if (f.items.length && typeof(f.items[0]) == 'string') {\n \n //this.get('/RightEditor').el.show();\n //this.get('/RightEditor.view').load( f.items[0]);\n // return;\n //}\n //print(\"LOAD\");\n //print(JSON.stringify(f.items, null,4));\n //console.dump(f.items);\n var o = new Gee.ArrayList();\n o.add(f.tree);\n this.load(o,null);\n \n _this.view.el.expand_all();\n\n if (f.tree.items.size < 1) {\n // single item..\n \n //this.get('/Window.leftvpaned').el.set_position(80);\n // select first...\n _this.view.el.set_cursor( \n new Gtk.TreePath.from_string(\"0\"), null, false);\n \n \n } else {\n //this.get('/Window.leftvpaned').el.set_position(200);\n }\n \n return;\n /* \n \n //print(\"hide right editior\");\n //this.get('/RightEditor').el.hide();\n //this.get('/Editor').el.hide();\n //print(\"set current tree\");\n //this.currentTree = this.toJS(false, false)[0];\n //console.dump(this.currentTree);\n //this.currentTree = this.currentTree || { items: [] };\n //_this.renderView();\n //console.dump(this.map);\n //var RightPalete = imports.Builder.RightPalete.RightPalete;\n \n \n var pm = this.get('/RightPalete.model');\n // set up provider..\n \n this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();\n \n if (!this.get('/RightPalete').provider) {\n print (\"********* PALETE PROVIDER MISSING?!!\");\n }\n this.get('/LeftTree').renderView();\n \n pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));\n \n \n \n this.get('/Window.view-notebook').el.set_current_page(\n this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);\n */\n \n}\n", @@ -83,8 +83,8 @@ "items" : [ { "id" : "renderer", - "* pack" : "pack_start,true", "xtype" : "CellRendererText", + "* pack" : "pack_start,true", "$ xns" : "Gtk" } ] @@ -93,8 +93,8 @@ }, { "id" : "LeftTreeMenu", - "* pack" : false, "xtype" : "Menu", + "* pack" : false, "$ xns" : "Gtk", "items" : [ { @@ -102,8 +102,8 @@ "activate" : " ( ) => {\n \n print(\"ACTIVATE?\");\n \n \n _this.model.deleteSelected();\n}" }, "label" : "Delete Element", - "* pack" : "add", "xtype" : "MenuItem", + "* pack" : "add", "$ xns" : "Gtk" }, { @@ -111,8 +111,8 @@ "activate" : " () => {\n\n DialogSaveTemplate.singleton().show(\n (Gtk.Window) _this.el.get_toplevel (), \n _this.model.file.palete(), \n _this.getActiveElement()\n );\n \n \n}" }, "label" : "Save as Template", - "* pack" : "add", "xtype" : "MenuItem", + "* pack" : "add", "$ xns" : "Gtk" }, { @@ -120,8 +120,8 @@ "activate" : " () => {\n var node = _this.getActiveElement();\n var name = DialogSaveModule.singleton().show(\n (Gtk.Window) _this.el.get_toplevel (), \n _this.model.file.project, \n node\n );\n if (name.length < 1) {\n return;\n \n }\n node.props.set(\"* xinclude\", name);\n node.items.clear();\n\n\n var s = _this.view.el.get_selection();\n \n print(\"GET SELECTED?\");\n Gtk.TreeIter iter;\n Gtk.TreeModel mod;\n\n \n if (!s.get_selected(out mod, out iter)) {\n return; // nothing seleted..\n }\n Gtk.TreeIter citer;\n var n_cn = mod.iter_n_children(iter) -1;\n for (var i = n_cn; i > -1; i--) {\n mod.iter_nth_child(out citer, iter, i);\n \n\n print(\"removing node from Tree\\n\"); \n \n _this.model.el.remove(ref citer);\n }\n _this.changed();\n _this.node_selected(node);\n \n \n}" }, "label" : "Save as Module", - "* pack" : "add", "xtype" : "MenuItem", + "* pack" : "add", "$ xns" : "Gtk" } ] diff --git a/Builder4/WindowLeftTree.vala b/Builder4/WindowLeftTree.vala index 37780fa60..334196f64 100644 --- a/Builder4/WindowLeftTree.vala +++ b/Builder4/WindowLeftTree.vala @@ -76,8 +76,8 @@ public class Xcls_WindowLeftTree : Object // my vars (def) public string dragData; - public string[] dropList; public int drag_x; + public string[] dropList; public int drag_y; public bool drag_in_motion; public bool blockChanges; @@ -172,6 +172,50 @@ public class Xcls_WindowLeftTree : Object // print("click:" + res.path.to_string()); return true; }); + this.el.drag_begin.connect( ( ctx) => { + //print('SOURCE: drag-begin'); + + + //this.targetData = ""; + + // find what is selected in our tree... + + var s = _this.view.el.get_selection(); + if (s.count_selected_rows() < 1) { + return; + } + Gtk.TreeIter iter; + Gtk.TreeModel mod; + s.get_selected(out mod, out iter); + + + + // set some properties of the tree for use by the dropped element. + GLib.Value value; + _this.model.el.get_value(iter, 2, out value); + var tp = mod.get_path(iter).to_string(); + var data = (JsRender.Node)(value.dup_object()); + var xname = data.fqn(); + print ("XNAME IS " + xname+ "\n"); + this.dragData = tp; + this.dropList = _this.model.file.palete().getDropList(xname); + + print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n"); + + + // make the drag icon a picture of the node that was selected + + + // by default returns the path.. + var path = _this.model.el.get_path(iter); + + + var pix = this.el.create_row_drag_icon ( path); + + Gtk.drag_set_icon_surface (ctx, pix) ; + + return; + }); this.el.cursor_changed.connect( ( ) => { @@ -230,50 +274,6 @@ public class Xcls_WindowLeftTree : Object return ; }); - this.el.drag_begin.connect( ( ctx) => { - //print('SOURCE: drag-begin'); - - - //this.targetData = ""; - - // find what is selected in our tree... - - var s = _this.view.el.get_selection(); - if (s.count_selected_rows() < 1) { - return; - } - Gtk.TreeIter iter; - Gtk.TreeModel mod; - s.get_selected(out mod, out iter); - - - - // set some properties of the tree for use by the dropped element. - GLib.Value value; - _this.model.el.get_value(iter, 2, out value); - var tp = mod.get_path(iter).to_string(); - var data = (JsRender.Node)(value.dup_object()); - var xname = data.fqn(); - print ("XNAME IS " + xname+ "\n"); - this.dragData = tp; - //this.dropList = _this.model.file.palete().getDropList(xname); - - print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n"); - - - // make the drag icon a picture of the node that was selected - - - // by default returns the path.. - var path = _this.model.el.get_path(iter); - - - var pix = this.el.create_row_drag_icon ( path); - - Gtk.drag_set_icon_surface (ctx, pix) ; - - return; - }); this.el.drag_end.connect( (drag_context) => { //Seed.print('LEFT-TREE: drag-end'); this.dragData = ""; @@ -284,6 +284,12 @@ public class Xcls_WindowLeftTree : Object }); this.el.drag_motion.connect( ( ctx, x, y, time) => { + var src = Gtk.drag_get_source_widget(ctx); + + if (src != this.el) { + + + // the point of this is to detect where an item could be dropped.. print("got drag motion"); this.drag_in_motion = true; @@ -298,47 +304,173 @@ public class Xcls_WindowLeftTree : Object Gdk.Atom.intern("STRING",true), // the target type we want time // time stamp ); - return true; - - }); - this.el.drag_data_get.connect( ( drag_context, data, info, time) => { + return true; + } - //print("drag-data-get"); - var s = this.el.get_selection(); - if (s.count_selected_rows() < 1) { - data.set_text("",0); - print("return empty string - no selection.."); - return; - } - - Gtk.TreeIter iter; - Gtk.TreeModel mod; - - s.get_selected(out mod, out iter); - - + + //print("GETTING POS"); + var targetData = ""; + + Gtk.TreePath path; + Gtk.TreeViewDropPosition pos; + var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos); + + // if there are not items in the tree.. the we have to set isOver to true for anything.. + var isEmpty = false; + if (_this.model.el.iter_n_children(null) < 1) { + print("got NO children?\n"); + isOver = true; //??? + isEmpty = true; + pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER; + } + + + // ------------- a drag from self.. + + + //var action = Gdk.DragAction.COPY; + // unless we are copying!!! ctl button.. + var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ; + + + if (_this.model.el.iter_n_children(null) < 1) { + // no children.. -- asume it's ok.. + + targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER); + + this.highlightDropPath("", (Gtk.TreeViewDropPosition)0); + Gdk.drag_status(ctx, action ,time); + return true; + + // continue through to allow drop... + + } + + + - GLib.Value value; - _this.model.el.get_value(iter, 2, out value); - var ndata = (JsRender.Node)(value.dup_object()); - var xname = ndata.fqn(); + //print("ISOVER? " + isOver); + if (!isOver) { + + Gdk.drag_status(ctx, 0 ,time); + this.highlightDropPath("", (Gtk.TreeViewDropPosition)0); + return false; + + } + + // drag node is parent of child.. + //console.log("SRC TREEPATH: " + src.treepath); + //console.log("TARGET TREEPATH: " + data.path.to_string()); - var tp = mod.get_path(iter).to_string(); - // by default returns the path.. + // nned to check a few here.. + //Gtk.TreeViewDropPosition.INTO_OR_AFTER + //Gtk.TreeViewDropPosition.INTO_OR_BEFORE + //Gtk.TreeViewDropPosition.AFTER + //Gtk.TreeViewDropPosition.BEFORE - if ( info != Gdk.Atom.intern("STRING",true) ) { - tp = ndata.toJsonString(); - } - - data.set_text(tp,tp.length); + // locally dragged items to not really use the + var selection_text = this.dragData; + + + if (selection_text == null || selection_text.length < 1) { + //print("Error - drag selection text returned NULL"); + Gdk.drag_status(ctx, 0 ,time); + this.highlightDropPath("", (Gtk.TreeViewDropPosition)0); + return false; + } + + + // see if we are dragging into ourself? + print ("got selection text of " + selection_text); + var target_path = path.to_string(); + //print("target_path="+target_path); + // + if (selection_text == target_path) { + print("self drag ?? == we should perhaps allow copy onto self..\n"); + + Gdk.drag_status(ctx, 0 ,time); + this.highlightDropPath("", (Gtk.TreeViewDropPosition)0); + return false; + // -- fixme -- this is not really correct.. + + } + + // check that + //print("DUMPING DATA"); + //console.dump(data); + // path, pos + + //print(data.path.to_string() +' => '+ data.pos); + + // dropList is a list of xtypes that this node could be dropped on. + // it is set up when we start to drag.. + + + targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos); + + print("targetDAta: " + targetData +"\n"); + + if (targetData.length < 1) { + //print("Can not find drop node path"); + + Gdk.drag_status(ctx, 0, time); + this.highlightDropPath("", (Gtk.TreeViewDropPosition)0); + return false; + } + + var td_ar = targetData.split("|"); + - // print("return " + tp); + + Gdk.drag_status(ctx, action ,time); + this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1])); + return true; + + }); + this.el.drag_data_get.connect( ( drag_context, data, info, time) => { + + + //print("drag-data-get"); + var s = this.el.get_selection(); + if (s.count_selected_rows() < 1) { + data.set_text("",0); + print("return empty string - no selection.."); + return; + } + + Gtk.TreeIter iter; + Gtk.TreeModel mod; + + s.get_selected(out mod, out iter); + + + + GLib.Value value; + _this.model.el.get_value(iter, 2, out value); + var ndata = (JsRender.Node)(value.dup_object()); + var xname = ndata.fqn(); + + + var tp = mod.get_path(iter).to_string(); + // by default returns the path.. + + if ( info != Gdk.Atom.intern("STRING",true) ) { + tp = ndata.toJsonString(); + } + + data.set_text(tp,tp.length); + + + + + // print("return " + tp); + }); this.el.drag_data_received.connect( (ctx, x, y, sel, info, time) => { //print("Tree: drag-data-received");