Fix #7265 - object adding changes - no pack on property add, and Gtk.Image, look...
[roobuilder] / src / Builder4 / WindowLeftTree.bjs
1 {
2  "build_module" : "builder",
3  "items" : [
4   {
5    "# Xcls_MainWindow main_window" : "null",
6    "$ xns" : "Gtk",
7    "* pack" : "add",
8    "@ bool before_node_change" : "()",
9    "@ void changed" : "()",
10    "@ void node_selected" : "(JsRender.Node? node, string source)",
11    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
12    "id" : "WindowLeftTree",
13    "items" : [
14     {
15      "$ xns" : "Gtk",
16      "* pack" : "add",
17      "bool always_show_image" : true,
18      "bool hexpand" : true,
19      "items" : [
20       {
21        "$ xns" : "Gtk",
22        "* pack" : "set_image",
23        "utf8 icon_name" : "list-add",
24        "xtype" : "Image"
25       }
26      ],
27      "listeners" : {
28       "clicked" : [
29        "  ( ) => {",
30        "    ",
31        "",
32        "  \t_this.main_window.windowstate.showAddObject(this.el);",
33        " ",
34        "}"
35       ]
36      },
37      "string label" : "Add Child Element",
38      "xtype" : "Button"
39     },
40     {
41      "$ xns" : "Gtk",
42      "* init" : [
43       " this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
44       " ",
45       ""
46      ],
47      "* pack" : "add",
48      "Gtk.ShadowType shadow_type" : "Gtk.ShadowType.IN",
49      "items" : [
50       {
51        "# bool blockChanges" : false,
52        "# bool drag_in_motion" : "",
53        "# int drag_x" : "",
54        "# int drag_y" : "",
55        "# string dragData" : "",
56        "# string[] dropList" : "",
57        "$ enable_tree_lines" : true,
58        "$ string lastEventSource" : "\"\"",
59        "$ xns" : "Gtk",
60        "* init" : [
61         "{",
62         "    var description = new Pango.FontDescription();",
63         "    description.set_size(8000);",
64         "    this.el.override_font(description);",
65         "",
66         "    var selection = this.el.get_selection();",
67         "    selection.set_mode( Gtk.SelectionMode.SINGLE);",
68         "",
69         "",
70         "    // is this really needed??",
71         "    /*",
72         "    this.selection.signal['changed'].connect(function() {",
73         "\t    _this.get('/LeftTree.view').listeners.cursor_changed.apply(",
74         "\t        _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']",
75         "\t    );",
76         "    });",
77         "    */",
78         "    Gtk.drag_source_set (",
79         "\t    this.el,            /* widget will be drag-able */",
80         "\t    Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */",
81         "\t    BuilderApplication.targetList,            /* lists of target to support */",
82         "\t    Gdk.DragAction.COPY   | Gdk.DragAction.MOVE    |  Gdk.DragAction.LINK           /* what to do with data after dropped */",
83         "    );",
84         "",
85         "    // ?? needed??",
86         "    //Gtk.drag_source_add_text_targets(this.el); ",
87         "",
88         "    Gtk.drag_dest_set",
89         "    (",
90         "        this.el,              /* widget that will accept a drop */",
91         "        Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,",
92         "        BuilderApplication.targetList,            /* lists of target to support */",
93         "        Gdk.DragAction.COPY   | Gdk.DragAction.MOVE   | Gdk.DragAction.LINK     /* what to do with data after dropped */",
94         "    );",
95         "",
96         "    //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList);",
97         "    //Gtk.drag_dest_add_text_targets(this.el);",
98         "}",
99         ""
100        ],
101        "* pack" : "add",
102        "bool button_is_pressed" : false,
103        "bool expand" : true,
104        "bool key_is_pressed" : false,
105        "gboolean headers_visible" : true,
106        "id" : "view",
107        "items" : [
108         {
109          "# DialogTemplateSelect template_select" : "null",
110          "# string activePath" : "\"\"",
111          "$ columns" : "typeof(string),typeof(string),typeof(Object),typeof(Gdk.Pixbuf)",
112          "$ listAllTypes" : [
113           "function() {",
114           "    var s = this.get('/LeftTree.view').selection;",
115           "    print (\"LIST ALL TYPES: \" + s.count_selected_rows() );",
116           "    ",
117           "    if (s.count_selected_rows() > 0) {",
118           "        var iter = new Gtk.TreeIter();    ",
119           "        s.get_selected(this.el, iter);",
120           "",
121           "        // set some properties of the tree for use by the dropped element.",
122           "        var value = new GObject.Value('');",
123           "        this.el.get_value(iter, 2, value);",
124           "        var data = JSON.parse(value.value);",
125           "        ",
126           "        ",
127           "        var xname = this.get('/LeftTree.model').file.guessName(data);",
128           "        console.log('selected:' + xname);",
129           "        if (xname.length) {",
130           "            return [ xname ];",
131           "        }",
132           "        return []; // could not find it..",
133           "    }",
134           "    ",
135           "    var ret = [ ];",
136           "    ",
137           "   var _this = this;",
138           "    function addall(li)",
139           "    {",
140           "        li.forEach(function(el) {",
141           "            // this is specific to roo!!!?",
142           "            if (!el) { // skip empty?",
143           "                return;",
144           "            }",
145           "            var fullpath =  _this.file.guessName(el);",
146           "            if (fullpath.length && ret.indexOf(fullpath) < 0) {",
147           "                ret.push(fullpath);",
148           "            }",
149           "            ",
150           "            ",
151           "            if (el.items && el.items.length) {",
152           "                addall(el.items);",
153           "            }",
154           "            ",
155           "        });",
156           "        ",
157           "        ",
158           "    }",
159           "    ",
160           "    addall([this.currentTree]);",
161           "    ",
162           "    // only if we have nothing, should we add '*top'",
163           "    if (!ret.length) {",
164           "        ret = [ '*top' ];",
165           "    }",
166           "    //console.log('all types in tree');",
167           "    //console.dump(ret);",
168           "    ",
169           "    return ret;",
170           "                            ",
171           "}",
172           ""
173          ],
174          "$ xns" : "Gtk",
175          "* init" : [
176           "print(\"model initialized\");",
177           "",
178           ""
179          ],
180          "* pack" : "set_model",
181          "currentTree" : false,
182          "id" : "model",
183          "n_columns" : 4,
184          "xtype" : "TreeStore",
185          "| JsRender.Node pathToNode" : [
186           "(string path) {",
187           " ",
188           "     ",
189           "     Gtk.TreeIter   iter;",
190           "     _this.model.el.get_iter_from_string(out iter, path);",
191           "     ",
192           "     GLib.Value value;",
193           "     _this.model.el.get_value(iter, 2, out value);",
194           "     ",
195           "     return (JsRender.Node)value.dup_object();",
196           "",
197           "}"
198          ],
199          "| string findDropNode" : [
200           " (string treepath_str, string[] targets) {",
201           "",
202           "    // this is used by the dragdrop code in the roo version AFAIR..",
203           "",
204           "    //var path = treepath_str.replace(/^builder-/, '');",
205           "    // treemap is depreciated... - should really check if model has any entries..",
206           "",
207           "    if (this.el.iter_n_children(null) < 1) {",
208           "        //print(\"NO KEYS\");",
209           "        return \"|%d\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
210           "    }",
211           "    //print(\"FIND treepath: \" + path);",
212           "    //console.dump(this.treemap);",
213           "    ",
214           "    //if (!treepath_str.match(/^builder-/)) {",
215           "    //    return []; // nothing!",
216           "    //}",
217           "    if (targets.length > 0 && targets[0] == \"*\") {",
218           "        return  treepath_str;",
219           "    }",
220           "    return this.findDropNodeByPath(treepath_str,targets, -1);",
221           "}",
222           ""
223          ],
224          "| string findDropNodeByPath" : [
225           " (string treepath_str, string[] targets, int in_pref = -1) {",
226           "",
227           "    var path = treepath_str; // dupe it..",
228           "    ",
229           "    ",
230           "    // pref : 3 = ontop - 0 = after, 1 = before",
231           "    int pref = in_pref < 0  ?  Gtk.TreeViewDropPosition.INTO_OR_AFTER : in_pref;",
232           "    ",
233           "    var last = \"\";",
234           "    ",
235           "    //console.dump(this.treemap);",
236           "    ",
237           "    print(\"findDropNodeByPath : got path length %d / %s\\n\", path.length, path);",
238           "    ",
239           "    if (path.length == 0) {",
240           "        // top drop. // just return empty..",
241           "        return \"|%d\".printf((int)pref) ;",
242           "        ",
243           "    }",
244           "    ",
245           "    ",
246           "    while (path.length > 0) {",
247           "    ",
248           "        if (path.length == treepath_str.length && pref != Gtk.TreeViewDropPosition.INTO_OR_AFTER) {",
249           "            if (path.last_index_of(\":\") < 0 ) {",
250           "                return \"\";",
251           "            }",
252           "            path = path.substring(0, path.last_index_of(\":\"));",
253           "            last = treepath_str;",
254           "            print(\"DROP  before or after : using %s\\n\",path);",
255           "            continue;",
256           "        }",
257           "    ",
258           "        //print(\"LOOKING FOR PATH: \" + path);",
259           "        var node_data = this.pathToNode(path);",
260           "        ",
261           "        if (node_data == null) {",
262           "            print(\"node not found\");",
263           "            return \"\";",
264           "        }",
265           "        ",
266           "        var xname = node_data.fqn();",
267           "        var match = \"\";",
268           "        var prop = \"\";",
269           "        ",
270           "        for (var i =0; i < targets.length; i++)  {",
271           "            var tg = targets[i];",
272           "            if ((tg == xname)  ) {",
273           "                match = tg;",
274           "                break;",
275           "            }",
276           "            // if target is \"xxxx:name\"",
277           "            if (tg.contains(xname +\":\")) {",
278           "                match = tg;",
279           "                var ar = tg.split(\":\");",
280           "                prop = ar[1];",
281           "                break;",
282           "            }",
283           "        }",
284           "        ",
285           "        if (match.length > 0) {",
286           "            if (last.length > 0) { // pref is after/before..",
287           "                // then it's after last",
288           "                //if (pref > 1) {",
289           "                //    return \"\";",
290           "                //}",
291           "                return last + \"|%d\".printf((int)pref) + \"|\" + prop;",
292           "",
293           "                ",
294           "            }",
295           "            // we need to add prop - as :store -> needs to bee added when dropping onto.",
296           "            return path + \"|%d\".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER)  + \"|\" + prop;",
297           "        }",
298           "        /*",
299           "        last = \"\" + path;",
300           "        var par = path.split(\":\");",
301           "        string [] ppar = {};",
302           "        for (var i = 0; i < par.length-1; i++) {",
303           "            ppar += par[i];",
304           "        }",
305           "        ",
306           "        path = string.joinv(\":\", ppar);",
307           "        */",
308           "        break;",
309           "",
310           "    }",
311           "    ",
312           "    return \"\";",
313           "            ",
314           "}",
315           ""
316          ],
317          "| string treePathFromNode" : [
318           "(JsRender.Node node) {",
319           "    // iterate through the tree and find the node",
320           "    var ret = \"\";",
321           "    ",
322           "    this.el.foreach((mod, pth, iter) => {",
323           "        // get the node..",
324           "      ",
325           "     ",
326           "         GLib.Value value;",
327           "         _this.model.el.get_value(iter, 2, out value);",
328           "         ",
329           "",
330           "         ",
331           "         var n = (JsRender.Node)value;",
332           "",
333           "         print(\"compare %s to %s\\n\", n.fqn(), node.fqn());",
334           "        if (node == n) {",
335           "            ret = pth.to_string();",
336           "            return true;",
337           "        }",
338           "        return false;",
339           "    });",
340           "    return ret;",
341           "",
342           "}",
343           ""
344          ],
345          "| void deleteSelected" : [
346           "() {",
347           "    ",
348           "    print(\"DELETE SELECTED?\");",
349           "    //_this.view.blockChanges = true;",
350           "    print(\"GET SELECTION?\");",
351           "",
352           "    var s = _this.view.el.get_selection();",
353           "    ",
354           "    print(\"GET  SELECTED?\");",
355           "   Gtk.TreeIter iter;",
356           "    Gtk.TreeModel mod;",
357           "",
358           "    ",
359           "    if (!s.get_selected(out mod, out iter)) {",
360           "        return; // nothing seleted..",
361           "    }",
362           "      ",
363           "",
364           "",
365           "    this.activePath= \"\";      ",
366           "    print(\"GET  vnode value?\");",
367           "",
368           "    GLib.Value value;",
369           "    this.el.get_value(iter, 2, out value);",
370           "    var data = (JsRender.Node)(value.get_object());",
371           "    print(\"removing node from Render\\n\");",
372           "    if (data.parent == null) {",
373           "       _this.main_window.windowstate.file.tree = null;",
374           "    } else {",
375           "        data.remove();",
376           "    }",
377           "    print(\"removing node from Tree\\n\");    ",
378           "    s.unselect_all();",
379           "    this.el.remove(ref iter);",
380           "",
381           "    ",
382           "    ",
383           "    ",
384           "    // ",
385           "    ",
386           "    ",
387           "",
388           "",
389           "    this.activePath= \"\"; // again!?!?      ",
390           "    //this.changed(null,true);",
391           "    ",
392           "    _this.changed();",
393           "    ",
394           "    _this.view.blockChanges = false;",
395           "}",
396           ""
397          ],
398          "| void dropNode" : [
399           "(string target_data_str, JsRender.Node node, bool show_templates) {",
400           "//         print(\"drop Node\");",
401           "     // console.dump(node);",
402           "  //    console.dump(target_data);",
403           "  ",
404           "  \t\t//target_data_str",
405           "  \t\t//   {parent}|{pos}|{prop}",
406           "  ",
407           "  ",
408           "        // 0 = before , 1=after 2/3 onto",
409           "  ",
410           "  \t\tGLib.debug(\"dropNode %s\", target_data_str);",
411           "        ",
412           "        var target_data= target_data_str.split(\"|\");",
413           "  ",
414           "        var parent_str = target_data[0].length > 0 ? target_data[0] : \"\";",
415           "        var pos = target_data.length > 1 ? int.parse(target_data[1]) : 2; // ontop..",
416           "  ",
417           "  ",
418           "        Gtk.TreePath tree_path  =   parent_str.length > 0 ? new  Gtk.TreePath.from_string( parent_str ) : null;",
419           "        ",
420           "        ",
421           "        ",
422           "        //print(\"add \" + tp + \"@\" + target_data[1]  );",
423           "        ",
424           "        JsRender.Node parentNode = null;",
425           "        ",
426           "        Gtk.TreeIter iter_after;",
427           "        Gtk.TreeIter iter_par ;",
428           "        ",
429           "       \t// this appears to be done in drag_ddata_recieved as well.",
430           "         if (target_data.length == 3 && target_data[2].length > 0) {",
431           "\t         node.set_prop(new JsRender.NodeProp.special(\"prop\", target_data[2]));",
432           "",
433           "        }",
434           "",
435           "        Gtk.TreePath expand_parent = null;",
436           "        ",
437           "        // we only need to show the template if it's come from else where?",
438           "         if (show_templates) {",
439           "         ",
440           "             var ts = _this.main_window.windowstate.template_select;",
441           "         ",
442           "             var new_node = ts.show(",
443           "                  _this.main_window, // (Gtk.Window) _this.el.get_toplevel (),",
444           "                 _this.main_window.windowstate.file.palete(),",
445           "                    node,",
446           "                    _this.main_window.windowstate.project);",
447           "                   ",
448           "             if (new_node == null) {",
449           "                 return; // do not add?",
450           "             }",
451           "             node = new_node;",
452           "        }        ",
453           "        ",
454           "         //print(\"pos is %d  \\n\".printf(pos));",
455           "        ",
456           "         Gtk.TreeIter n_iter; ",
457           "         ",
458           "         if ( parent_str.length < 1) {",
459           "              this.el.append(out n_iter, null); // drop at top level..",
460           "              node.parent = null;",
461           "              _this.main_window.windowstate.file.tree = node;",
462           "              ",
463           "              ",
464           "        } else   if (pos  < 2) {",
465           "            //print(target_data[1]  > 0 ? 'insert_after' : 'insert_before');",
466           "            ",
467           "            this.el.get_iter(out iter_after, tree_path );            ",
468           "            this.el.iter_parent(out iter_par, iter_after);",
469           "            expand_parent = this.el.get_path(iter_par);",
470           "            ",
471           "            ",
472           "            // not sure why all the 'dup_object()' stuff? did it crash before?",
473           "            GLib.Value value;",
474           "            this.el.get_value( iter_par, 2, out value);",
475           "            parentNode =  (JsRender.Node)value.dup_object();",
476           "            ",
477           "            ",
478           "            this.el.get_value( iter_after, 2, out value);",
479           "            var relNode =  (JsRender.Node)value.dup_object();",
480           "            ",
481           "            if ( pos  > 0 ) {",
482           "             ",
483           "                this.el.insert_after(out n_iter,    iter_par  , iter_after);",
484           "                var ix = parentNode.items.index_of(relNode);",
485           "                parentNode.items.insert(ix+1, node);",
486           "                ",
487           "            } else {",
488           "                this.el.insert_before(out n_iter,  iter_par  , iter_after);",
489           "                var ix = parentNode.items.index_of(relNode);",
490           "                parentNode.items.insert(ix, node);",
491           " ",
492           "            }",
493           "            node.parent = parentNode;",
494           "            ",
495           "            ",
496           "            ",
497           "        } else {",
498           "           //  print(\"appending to  \" + parent_str);",
499           "            this.el.get_iter(out iter_par, tree_path);",
500           "            this.el.append(out n_iter,   iter_par );",
501           "            expand_parent = this.el.get_path(iter_par);",
502           "            ",
503           "            GLib.Value value;",
504           "            this.el.get_value( iter_par, 2, out value);",
505           "            parentNode =  (JsRender.Node)value.dup_object();",
506           "            node.parent = parentNode;",
507           "            parentNode.items.add(node);",
508           "        }",
509           "        ",
510           "        ",
511           "        ",
512           "        ",
513           "        // work out what kind of packing to use.. -- should be in ",
514           "       ",
515           "            ",
516           "            //_this.main_window.windowstate.file.palete().fillPack(node,parentNode);",
517           "        _this.main_window.windowstate.file.palete().on_child_added(parentNode,node);",
518           "            ",
519           "          ",
520           "        ",
521           "        // add the node...",
522           "        ",
523           "        this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1  );",
524           "        var o =   GLib.Value(typeof(Object));",
525           "        o.set_object((Object)node);",
526           "        ",
527           "        this.el.set_value(n_iter, 2, o);",
528           "        ",
529           "        ",
530           "        ",
531           "        ",
532           "// load children - if it has any..",
533           "      ",
534           "        if (node.items.size > 0) {",
535           "            this.load(node.items, n_iter);",
536           "            _this.view.el.expand_row(this.el.get_path(n_iter), true);",
537           "        } else if (expand_parent != null && !_this.view.el.is_row_expanded(expand_parent)) {",
538           "           _this.view.el.expand_row(expand_parent,true);",
539           "        }",
540           "",
541           "        //if (tp != null && (node.items.length() > 0 || pos > 1)) {",
542           "        //    _this.view.el.expand_row(this.el.get_path(iter_par), true);",
543           "       // }",
544           "        // wee need to get the empty proptypes from somewhere..",
545           "        ",
546           "        //var olditer = this.activeIter;",
547           "        this.activePath = this.el.get_path(n_iter).to_string();",
548           "",
549           "",
550           "        // pretend button was pressed, so that we can trigger select node...",
551           "        _this.view.button_is_pressed = true;",
552           "        _this.view.lastEventSource = \"\";",
553           "        _this.view.el.set_cursor(this.el.get_path(n_iter), null, false);",
554           "        _this.view.button_is_pressed = false;",
555           "        _this.changed();",
556           "     ",
557           "        ",
558           "            ",
559           "}",
560           ""
561          ],
562          "| void load" : [
563           "(Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) ",
564           "{",
565           "    Gtk.TreeIter citer;",
566           "    //this.insert(citer,iter,0);",
567           "    var ic = Gtk.IconTheme.get_default();",
568           "    var pixdef = ic.load_icon(\"emblem-new\", 16,0);",
569           "    ",
570           "    for(var i =0 ; i < tr.size; i++) {",
571           "        if (iter != null) {",
572           "            this.el.insert(out citer,iter,-1); // why not append?",
573           "        } else {",
574           "            this.el.append(out citer,null);",
575           "        }",
576           "        ",
577           "        this.el.set(citer, 0, tr.get(i).nodeTitle(),",
578           "                1, tr.get(i).nodeTip(), -1",
579           "        );",
580           "        var o =   GLib.Value(typeof(Object));",
581           "        o.set_object((Object)tr.get(i));",
582           "        ",
583           "        this.el.set_value(citer, 2, o);",
584           "        ",
585           "        var clsname = tr.get(i).fqn();",
586           "        ",
587           "        var clsb = clsname.split(\".\");",
588           "        var sub = clsb.length > 1 ? clsb[1].down()  : \"\";",
589           "        ",
590           "        var pix = pixdef;",
591           "        var fn = \"/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-\" + sub + \".png\";",
592           "        if (FileUtils.test (fn, FileTest.IS_REGULAR)) {",
593           "\t        pix = new Gdk.Pixbuf.from_file (fn);",
594           "        }",
595           "        ",
596           "        ",
597           "        this.el.set_value(citer, 3,   pix );",
598           "        ",
599           "        ",
600           "        ",
601           "        ",
602           "        ",
603           "        if (tr.get(i).items.size > 0) {",
604           "            this.load(tr.get(i).items, citer);",
605           "        }",
606           "     ",
607           "    }",
608           "",
609           "    ",
610           "}"
611          ],
612          "| void loadFile" : [
613           "(JsRender.JsRender f) {",
614           "    //console.dump(f);",
615           "    this.el.clear();",
616           "    _this.main_window.windowstate.leftTreeNodeSelected(null, \"\");",
617           "    // needed???",
618           "    _this.main_window.windowstate.file = f;",
619           "    ",
620           "   ",
621           "    if (f.tree == null) {",
622           "\t    try {",
623           "\t        f.loadItems( );",
624           "        } catch (Error e) {",
625           "    \t\treturn;",
626           "        }",
627           "    }",
628           "    // if it's still null?",
629           "    if (f.tree == null) {",
630           "        return;",
631           "    }",
632           "  ",
633           "    var o = new Gee.ArrayList<JsRender.Node>();",
634           "    o.add(f.tree);",
635           "    this.load(o,null);",
636           "    ",
637           "    _this.view.el.expand_all();",
638           "",
639           "    if (f.tree.items.size < 1) {",
640           "        // single item..",
641           "        ",
642           "        //this.get('/Window.leftvpaned').el.set_position(80);",
643           "        // select first...",
644           "        _this.view.el.set_cursor( ",
645           "            new  Gtk.TreePath.from_string(\"0\"), null, false);",
646           "        ",
647           "        ",
648           "    } else {",
649           "          //this.get('/Window.leftvpaned').el.set_position(200);",
650           "    }",
651           "    ",
652           "    return;",
653           " ",
654           "            ",
655           "}",
656           ""
657          ],
658          "| void moveNode" : [
659           "(string target_data, Gdk.DragAction action) ",
660           "{",
661           "   ",
662           "   /// target_data = \"path|pos\");",
663           "   ",
664           "   ",
665           "    //print(\"MOVE NODE\");",
666           "    // console.dump(target_data);",
667           "    Gtk.TreeIter old_iter;",
668           "    Gtk.TreeModel mod;",
669           "    ",
670           "    var s = _this.view.el.get_selection();",
671           "    s.get_selected(out mod , out old_iter);",
672           "    mod.get_path(old_iter);",
673           "    ",
674           "    var node = this.pathToNode(mod.get_path(old_iter).to_string());",
675           "    //console.dump(node);",
676           "    if (node == null) {",
677           "        print(\"moveNode: ERROR - node is null?\");",
678           "    }",
679           "    ",
680           "    ",
681           "",
682           "    // needs to drop first, otherwise the target_data ",
683           "    // treepath will be invalid.",
684           "",
685           "    ",
686           "    if ((action & Gdk.DragAction.MOVE) > 0) {",
687           "            print(\"REMOVING OLD NODE : \" + target_data + \"\\n\");",
688           "            node.remove();",
689           "            this.dropNode(target_data, node, false);",
690           "            this.el.remove(ref old_iter);",
691           "            ",
692           "            ",
693           "                         ",
694           "    } else {",
695           "        print(\"DROPPING NODE // copy: \" + target_data + \"\\n\");",
696           "        node = node.deepClone();",
697           "        this.dropNode(target_data, node, false);",
698           "    }",
699           "    _this.changed();",
700           "    this.activePath= \"\";",
701           "    //this.updateNode(false,true);",
702           "}",
703           ""
704          ],
705          "| void updateSelected" : [
706           "() {",
707           "  ",
708           "   ",
709           "    var s = _this.view.el.get_selection();",
710           "    ",
711           "     Gtk.TreeIter iter;",
712           "    Gtk.TreeModel mod;",
713           "    ",
714           "    ",
715           "    ",
716           "    if (!s.get_selected(out mod, out iter)) {",
717           "        return; // nothing seleted..",
718           "    }",
719           "  ",
720           "  GLib.Value value;",
721           "    this.el.get_value(iter, 2, out value);",
722           "    var node = (JsRender.Node)(value.get_object());",
723           "    ",
724           "      this.el.set(iter, 0, node.nodeTitle(),",
725           "                1, node.nodeTip(), -1",
726           "        );",
727           "}",
728           ""
729          ]
730         },
731         {
732          "$ xns" : "Gtk",
733          "* init" : [
734           "  this.el.add_attribute(_this.renderer.el , \"markup\", 0 );",
735           "  this.el.add_attribute(_this.iconrender.el , \"pixbuf\",  3 );",
736           " "
737          ],
738          "* pack" : "append_column",
739          "items" : [
740           {
741            "$ xns" : "Gtk",
742            "* pack" : "pack_start,true",
743            "id" : "iconrender",
744            "xtype" : "CellRendererPixbuf"
745           },
746           {
747            "$ xns" : "Gtk",
748            "* pack" : "pack_start,true",
749            "id" : "renderer",
750            "xtype" : "CellRendererText"
751           }
752          ],
753          "utf8 title" : "test",
754          "xtype" : "TreeViewColumn"
755         }
756        ],
757        "listeners" : {
758         "button_press_event" : [
759          "  ( ev) => {",
760          "    //console.log(\"button press?\");",
761          "    this.button_is_pressed = true;",
762          "    print(\"BUTTON DOWN\\n\");",
763          "    ",
764          "    this.lastEventSource = \"tree\";",
765          "    if (! _this.before_node_change() ) {",
766          "    ",
767          "       return true;",
768          "    }",
769          "    ",
770          "\t",
771          "    ",
772          "    if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button != 3) {",
773          "        //print(\"click\" + ev.type);",
774          "        return false;",
775          "    }",
776          "    Gtk.TreePath res;",
777          "    if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, null, null, null) ) {",
778          "        return true;",
779          "    }",
780          "    ",
781          "",
782          "    _this.main_window.windowstate.leftTreeBeforeChange();",
783          "",
784          "    ",
785          "     ",
786          "    this.el.get_selection().select_path(res);",
787          "     ",
788          "      //if (!this.get('/LeftTreeMenu').el)  { ",
789          "      //      this.get('/LeftTreeMenu').init(); ",
790          "      //  }",
791          "        ",
792          "     _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());",
793          "     _this.LeftTreeMenu.el.show_all();",
794          "      _this.LeftTreeMenu.el.popup(null, null, null,  3, ev.time);",
795          "     //   print(\"click:\" + res.path.to_string());",
796          "      return true;",
797          "}"
798         ],
799         "button_release_event" : [
800          "(ev) => { ",
801          "    this.button_is_pressed = false;",
802          "  return false;",
803          "}"
804         ],
805         "cursor_changed" : [
806          " ( ) => {",
807          "    print(\"LEFT TREE Cursor Changed\\n\");",
808          "\tif (!this.button_is_pressed && !this.key_is_pressed) {",
809          "\t\t// then event was started by some other action",
810          "\t\t// which should manually trigger all the events..",
811          "\t\tprint(\"SKIPPING select - no button or key pressed\\n\");",
812          "\t\treturn;",
813          "\t}",
814          "",
815          "",
816          "     if (this.blockChanges) { // probably not needed.. ",
817          "\t\tprint(\"SKIPPING select - blockchanges set..\\n\");     ",
818          "       return  ;",
819          "     }",
820          "      if (!_this.before_node_change( ) ) {",
821          "\t     this.blockChanges = true;",
822          "\t     this.el.get_selection().unselect_all();",
823          "\t     this.blockChanges = false;",
824          "\t     ",
825          "\t     return;",
826          "     }",
827          "     if (_this.main_window.windowstate.file == null) {",
828          "   \t\tprint(\"SKIPPING select windowstate file is not set...\\n\");     ",
829          "         return;",
830          "     } ",
831          "     ",
832          "     //var render = this.get('/LeftTree').getRenderer();                ",
833          "    print(\"LEFT TREE -> view -> selection changed called\\n\");",
834          "    ",
835          "    ",
836          "    // -- it appears that the selection is not updated.",
837          "      ",
838          "    GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {",
839          "         print(\"LEFT TREE -> view -> selection changed TIMEOUT CALLED\\n\");",
840          "",
841          "            if (this.el.get_selection().count_selected_rows() < 1) {",
842          "",
843          "                print(\"selected rows < 1\\n\");",
844          "                //??this.model.load( false);",
845          "                _this.node_selected(null, this.lastEventSource);",
846          "                ",
847          "                return false ;",
848          "            }",
849          "                ",
850          "                //console.log('changed');",
851          "            var s = this.el.get_selection();",
852          "             Gtk.TreeIter iter;",
853          "             Gtk.TreeModel mod;",
854          "            s.get_selected(out mod, out iter);",
855          "            ",
856          "            ",
857          "            // var val = \"\";",
858          "            GLib.Value value;",
859          "            _this.model.el.get_value(iter, 2, out value);",
860          "            _this.model.activePath = mod.get_path(iter).to_string();",
861          "            ",
862          "            var node = (JsRender.Node)value.dup_object();",
863          "            print (\"calling left_tree.node_selected\\n\");",
864          "            _this.node_selected(node, this.lastEventSource);",
865          "            while (Gtk.events_pending()) {",
866          "                Gtk.main_iteration();",
867          "           }",
868          "            var cp = mod.get_path(iter);",
869          "            Gtk.TreePath sp, ep;",
870          "            this.el.get_visible_range(out sp, out ep);",
871          "            // if sp is before cp then retuns 1.",
872          "            // if cp is before ep then retuns 1.",
873          "            if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {",
874          "                return false;",
875          "            }",
876          "            ",
877          "             ",
878          "            ",
879          "            this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);",
880          "            ",
881          "            return false;",
882          "      });  ",
883          "    //_this.after_node_change(node);",
884          "",
885          "//        _this.model.file.changed(node, \"tree\");",
886          "   ",
887          "    //Seed.print( value.get_string());",
888          "    return  ;",
889          "                ",
890          "}"
891         ],
892         "drag_begin" : [
893          "( ctx)  => {",
894          "\t//print('SOURCE: drag-begin');",
895          "        ",
896          "        ",
897          "        //this.targetData = \"\";",
898          "        ",
899          "        // find what is selected in our tree...",
900          "        ",
901          "        var s = _this.view.el.get_selection();",
902          "        if (s.count_selected_rows() < 1) {",
903          "            return;",
904          "        }",
905          "        Gtk.TreeIter iter;",
906          "        Gtk.TreeModel mod;",
907          "        s.get_selected(out mod, out iter);",
908          "",
909          "        ",
910          "",
911          "        // set some properties of the tree for use by the dropped element.",
912          "        GLib.Value value;",
913          "        _this.model.el.get_value(iter, 2, out value);",
914          "        var tp = mod.get_path(iter).to_string();",
915          "        var data = (JsRender.Node)(value.dup_object());",
916          "        var xname = data.fqn();",
917          "        print (\"XNAME  IS \" + xname+ \"\\n\");",
918          "        this.dragData = tp;",
919          "        this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);",
920          "        ",
921          "        print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");",
922          "        ",
923          "",
924          "        // make the drag icon a picture of the node that was selected",
925          "    ",
926          "        ",
927          "    // by default returns the path..",
928          "       var path = _this.model.el.get_path(iter);",
929          "",
930          "         ",
931          "        var pix = this.el.create_row_drag_icon ( path);",
932          "        ",
933          "        Gtk.drag_set_icon_surface (ctx, pix) ;",
934          "        ",
935          "        return;",
936          "}"
937         ],
938         "drag_data_get" : [
939          "( drag_context, data, info, time) => {",
940          "            ",
941          "",
942          "\t//print(\"drag-data-get\");",
943          "\tvar s = this.el.get_selection();",
944          "\tif (s.count_selected_rows() < 1) {",
945          "\t\tdata.set_text(\"\",0);     ",
946          "\t\t print(\"return empty string - no selection..\");",
947          "\t\treturn;",
948          "\t}",
949          "",
950          "\tGtk.TreeIter iter;",
951          "\tGtk.TreeModel mod;",
952          "",
953          "\ts.get_selected(out mod, out iter);",
954          "",
955          "",
956          "",
957          "\tGLib.Value value;",
958          "\t_this.model.el.get_value(iter, 2, out value);",
959          "\tvar ndata = (JsRender.Node)(value.dup_object());",
960          "",
961          "",
962          "",
963          "\tvar tp = mod.get_path(iter).to_string();",
964          "\t// by default returns the path..",
965          "",
966          "\tif ( info != Gdk.Atom.intern(\"STRING\",true) ) {",
967          "\t\ttp = ndata.toJsonString();",
968          "\t}   ",
969          "",
970          "\t//data.set_text(tp,tp.length);   ",
971          "",
972          "\tdata.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());",
973          "",
974          "",
975          "\t//  print(\"return \" + tp);",
976          "\t}"
977         ],
978         "drag_data_received" : [
979          "\t(ctx, x, y, sel, info, time)  => {",
980          "",
981          "\t// THIS CODE ONLY RELATES TO drag  or drop of \"NEW\" elements or \"FROM another tree..\"",
982          "",
983          "",
984          "\t//  print(\"Tree: drag-data-received\\n\");",
985          "\tvar selection_text = (string)sel.get_data();",
986          "\t//print(\"selection_text= %s\\n\",selection_text);",
987          "",
988          "\tvar is_drag = this.drag_in_motion;",
989          "",
990          "",
991          "",
992          "\tGLib.debug(\"Is Drag %s\\n\", is_drag ? \"Y\": \"N\");",
993          "\tvar  targetData = \"\";",
994          "",
995          "\tGtk.TreePath path;",
996          "\tGtk.TreeViewDropPosition pos;",
997          "\tvar isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
998          "",
999          "\t// if there are not items in the tree.. the we have to set isOver to true for anything..",
1000          "\tvar isEmpty = false;",
1001          "\tif (_this.model.el.iter_n_children(null) < 1) {",
1002          "\t\tGLib.debug(\"got NO children?\\n\");",
1003          "\t\tisOver = true; //??? ",
1004          "\t\tisEmpty = true;",
1005          "\t\tpos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1006          "\t}",
1007          "",
1008          "",
1009          "\t//console.log(\"LEFT-TREE: drag-motion\");",
1010          "\tvar src = Gtk.drag_get_source_widget(ctx);",
1011          "",
1012          "\t// a drag from self - this should be handled by drop and motion.",
1013          "\tif (src == this.el) {",
1014          "\t\tGLib.debug(\"Source == this element should not happen.. ? \\n\");",
1015          "\t\treturn;",
1016          "\t}",
1017          "\t//print(\"drag_data_recieved from another element\");",
1018          "",
1019          "\t ",
1020          "",
1021          "",
1022          "\tif (selection_text == null || selection_text.length < 1 || !isOver) {",
1023          "\t\t// nothing valid foudn to drop...",
1024          "\t\t   GLib.debug(\"empty sel text or not over\");",
1025          "\t\tif (is_drag) {",
1026          "\t\t    Gdk.drag_status(ctx, 0, time);",
1027          "\t\t    this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1028          "\t\t    return;",
1029          "\t\t}",
1030          "\t\tGtk.drag_finish (ctx, false, false, time);        // drop failed..",
1031          "\t\t// no drop action...",
1032          "\t\treturn;            ",
1033          "",
1034          "\t}",
1035          "\tvar dropNode = new JsRender.Node(); ",
1036          "",
1037          "\tvar dropNodeType  = selection_text;",
1038          "\tvar show_templates = true;",
1039          "\t// for drop",
1040          "\tif (dropNodeType[0] == '{') {",
1041          "\t\tvar pa = new Json.Parser();",
1042          "\t\ttry {",
1043          "\t\t    pa.load_from_data(dropNodeType);",
1044          "\t\t} catch (Error e) {",
1045          "\t\t    Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1046          "\t\t    // no drop action...",
1047          "\t\t    return;   ",
1048          "\t\t}",
1049          "\t\t ",
1050          "\t\tdropNode.loadFromJson( pa.get_root().get_object(), 2);",
1051          "\t\tdropNodeType = dropNode.fqn();",
1052          "\t\tshow_templates = false;",
1053          "\t\t",
1054          "\t\t",
1055          "\t} else {",
1056          "\t\t// drop with property.",
1057          "\t\tif (selection_text.contains(\":\")) {",
1058          "\t\t\tvar bits = selection_text.split(\":\");",
1059          "\t\t    dropNode.setFqn(bits[0]);",
1060          "\t\t    dropNode.set_prop(new JsRender.NodeProp.special(\"prop\", bits[1]));",
1061          "\t\t    ",
1062          "\t\t    ",
1063          "\t\t    ",
1064          "\t\t} else {",
1065          "\t\t    dropNode.setFqn(selection_text);",
1066          "\t\t}",
1067          "\t}",
1068          "",
1069          "\t ",
1070          "\t// dropList --- need to gather this ... ",
1071          "\tGLib.debug(\"get dropList for : %s\\n\",dropNodeType);            ",
1072          "\tvar dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);",
1073          "",
1074          "\tGLib.debug(\"dropList: %s\\n\", string.joinv(\" , \", dropList));",
1075          "",
1076          "\t// if drag action is link ... then we can drop it anywahere...",
1077          "\t if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {",
1078          "\t\t // if path is null?? dragging into an empty tree?",
1079          "\t\t targetData = (path == null ? \"\" :  path.to_string()) + \"|%d\".printf((int)pos);",
1080          "\t } else {",
1081          "",
1082          "",
1083          "\t\ttargetData = _this.model.findDropNodeByPath( isEmpty ? \"\" : path.to_string(), dropList, pos);",
1084          "\t }",
1085          "",
1086          "",
1087          "\t\t",
1088          "\tGLib.debug(\"targetDAta: %s\", targetData );",
1089          "",
1090          "\tif (targetData.length < 1) {",
1091          "\t ",
1092          "\t\t// invalid drop path..",
1093          "\t\tif (this.drag_in_motion) {",
1094          "\t\t    Gdk.drag_status(ctx, 0, time);",
1095          "\t\t    this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1096          "\t\t    return;",
1097          "\t\t}",
1098          "\t\tGtk.drag_finish (ctx, false, false, time);        // drop failed..",
1099          "\t\t// no drop action...",
1100          "\t\treturn;",
1101          "\t}",
1102          "",
1103          "",
1104          "",
1105          "\t var td_ar = targetData.split(\"|\");",
1106          "\t  ",
1107          "",
1108          "\tif (this.drag_in_motion) { ",
1109          "\t\tGdk.drag_status(ctx, Gdk.DragAction.COPY ,time);",
1110          "",
1111          "\t\tthis.highlightDropPath(  td_ar[0]  , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1112          "\t\treturn;",
1113          "\t}",
1114          "\t// continue on to allow drop..",
1115          "",
1116          "",
1117          "\t// at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1118          "\t//targetData",
1119          "\t//   {parent}|{pos}|{prop}",
1120          "",
1121          "",
1122          "   _this.model.dropNode(targetData, dropNode, show_templates);",
1123          "    ",
1124          "\tGLib.debug(\"ADD new node!!!\\n\");",
1125          "\t\t",
1126          "\t///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);",
1127          "",
1128          "\tGtk.drag_finish (ctx, false, false,time);",
1129          "",
1130          "",
1131          "\t\t",
1132          "\t\t",
1133          "",
1134          "}"
1135         ],
1136         "drag_drop" : [
1137          " (  ctx, x, y, time)  => {",
1138          "      //Seed.print(\"TARGET: drag-drop\");",
1139          "   ",
1140          "   ",
1141          "    var src = Gtk.drag_get_source_widget(ctx);",
1142          "     ",
1143          "   if (src != this.el) {",
1144          "   ",
1145          "    ",
1146          "       ",
1147          "       this.drag_in_motion = false;   ",
1148          "            // request data that will be recieved by the recieve...              ",
1149          "        Gtk.drag_get_data",
1150          "        (",
1151          "                this.el,         // will receive 'drag-data-received' signal ",
1152          "                ctx,        // represents the current state of the DnD ",
1153          "                Gdk.Atom.intern(\"application/json\",true),    // the target type we want ",
1154          "                time            // time stamp ",
1155          "        );",
1156          "",
1157          "         ",
1158          "        // No target offered by source => error",
1159          "   ",
1160          "",
1161          "         return  false;",
1162          "     }",
1163          "     ",
1164          "     // handle drop around self..",
1165          "     ",
1166          "                  ",
1167          "            ",
1168          "    //print(\"GETTING POS\");",
1169          "    var  targetData = \"\";",
1170          "    ",
1171          "    Gtk.TreePath path;",
1172          "    Gtk.TreeViewDropPosition pos;",
1173          "    var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1174          "    ",
1175          "    // if there are not items in the tree.. the we have to set isOver to true for anything..",
1176          "    var isEmpty = false;",
1177          "    if (_this.model.el.iter_n_children(null) < 1) {",
1178          "        print(\"got NO children?\\n\");",
1179          "        isOver = true; //??? ",
1180          "        isEmpty = true;",
1181          "        pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1182          "    }",
1183          "    ",
1184          "     ",
1185          "     ",
1186          "    //var action = Gdk.DragAction.COPY;",
1187          "        // unless we are copying!!! ctl button..",
1188          "    ",
1189          "    var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1190          "                 Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;",
1191          "                // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1192          "",
1193          "      ",
1194          "    if (_this.model.el.iter_n_children(null) < 1) {",
1195          "        // no children.. -- asume it's ok..",
1196          "        ",
1197          "        targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1198          "         ",
1199          "        // continue through to allow drop...",
1200          "",
1201          "    } else {",
1202          "                ",
1203          "                ",
1204          "    ",
1205          "                ",
1206          "                ",
1207          "                //print(\"ISOVER? \" + isOver);",
1208          "        if (!isOver) {",
1209          "            ",
1210          "            Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1211          "            return true; // not over apoint!?! - no action on drop or motion..",
1212          "        }",
1213          "                ",
1214          "        // drag node is parent of child..",
1215          "        //console.log(\"SRC TREEPATH: \" + src.treepath);",
1216          "        //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1217          "        ",
1218          "        // nned to check a  few here..",
1219          "        //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1220          "        //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1221          "        //Gtk.TreeViewDropPosition.AFTER",
1222          "        //Gtk.TreeViewDropPosition.BEFORE",
1223          "        ",
1224          "        // locally dragged items to not really use the ",
1225          "        var selection_text = this.dragData;",
1226          "        ",
1227          "        ",
1228          "        ",
1229          "        if (selection_text == null || selection_text.length < 1) {",
1230          "            //print(\"Error  - drag selection text returned NULL\");",
1231          "          ",
1232          "             Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1233          "             return true; /// -- fixme -- this is not really correct..",
1234          "        }                ",
1235          "                ",
1236          "                // see if we are dragging into ourself?",
1237          "                print (\"got selection text of  \" + selection_text);",
1238          "        ",
1239          "        var target_path = path.to_string();",
1240          "        //print(\"target_path=\"+target_path);",
1241          "",
1242          "        // ",
1243          "        if (selection_text  == target_path) {",
1244          "            print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1245          "            ",
1246          "             Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1247          "",
1248          "             return true; /// -- fixme -- this is not really correct..",
1249          "",
1250          "        }",
1251          "                ",
1252          "        // check that ",
1253          "        //print(\"DUMPING DATA\");",
1254          "        //console.dump(data);",
1255          "        // path, pos",
1256          "        ",
1257          "        //print(data.path.to_string() +' => '+  data.pos);",
1258          "        ",
1259          "        // dropList is a list of xtypes that this node could be dropped on.",
1260          "        // it is set up when we start to drag..",
1261          "        ",
1262          "        ",
1263          "        targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1264          "            ",
1265          "        print(\"targetDAta: \" + targetData +\"\\n\");",
1266          "        ",
1267          "        if (targetData.length < 1) {",
1268          "            //print(\"Can not find drop node path\");",
1269          "             ",
1270          "            Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1271          "            return true;",
1272          "        }",
1273          "                    ",
1274          "                ",
1275          "                ",
1276          "                // continue on to allow drop..",
1277          "  }",
1278          "        // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1279          "",
1280          "",
1281          "     var delete_selection_data = false;",
1282          "        ",
1283          "    if (action == Gdk.DragAction.ASK)  {",
1284          "        /* Ask the user to move or copy, then set the ctx action. */",
1285          "    }",
1286          "",
1287          "    if (action == Gdk.DragAction.MOVE) {",
1288          "        delete_selection_data = true;",
1289          "    }",
1290          "      ",
1291          "                // drag around.. - reorder..",
1292          "    _this.model.moveNode(targetData, action);",
1293          "        ",
1294          "       ",
1295          "        ",
1296          "        ",
1297          "        ",
1298          "        // we can send stuff to souce here...",
1299          "",
1300          "",
1301          "// do we always say failure, so we handle the reall drop?",
1302          "    Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);",
1303          "",
1304          "    return true;",
1305          " ",
1306          " ",
1307          " ",
1308          " ",
1309          " ",
1310          " ",
1311          "}"
1312         ],
1313         "drag_end" : [
1314          "  (drag_context) => {",
1315          "\t//Seed.print('LEFT-TREE: drag-end');",
1316          "        this.dragData = \"\";",
1317          "        this.dropList = null;",
1318          "//        this.targetData = \"\";",
1319          "        this.highlightDropPath(\"\",0);",
1320          "//        return true;",
1321          "}"
1322         ],
1323         "drag_motion" : [
1324          " ( ctx, x, y, time)  => {",
1325          "   print(\"got drag motion\\n\");",
1326          "    var src = Gtk.drag_get_source_widget(ctx);",
1327          "   this.drag_x = x;",
1328          "   this.drag_y = y;     ",
1329          "",
1330          "   if (src != this.el) {",
1331          "   ",
1332          " ",
1333          " ",
1334          "    // the point of this is to detect where an item could be dropped..",
1335          "        print(\"requesting drag data\\n\");",
1336          "       this.drag_in_motion = true;",
1337          "       ",
1338          "            // request data that will be recieved by the recieve...              ",
1339          "        Gtk.drag_get_data",
1340          "        (",
1341          "                this.el,         // will receive 'drag-data-received' signal ",
1342          "                ctx,        // represents the current state of the DnD ",
1343          "                Gdk.Atom.intern(\"STRING\",true),    // the target type we want ",
1344          "                time            // time stamp ",
1345          "        );",
1346          "        return true;",
1347          "  }    ",
1348          "",
1349          "",
1350          "  print(\"action: %d\\n\", ctx.get_actions());",
1351          " //print(\"GETTING POS\");",
1352          "    var  targetData = \"\";",
1353          "",
1354          "    Gtk.TreePath path;",
1355          "    Gtk.TreeViewDropPosition pos;",
1356          "    var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1357          "",
1358          "    // if there are not items in the tree.. the we have to set isOver to true for anything..",
1359          "    var isEmpty = false;",
1360          "    if (_this.model.el.iter_n_children(null) < 1) {",
1361          "        print(\"got NO children?\\n\");",
1362          "        isOver = true; //??? ",
1363          "        isEmpty = true;",
1364          "        pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1365          "    }",
1366          "",
1367          "",
1368          "    // ------------- a drag from self..",
1369          "",
1370          "",
1371          "    //var action = Gdk.DragAction.COPY;",
1372          "        // unless we are copying!!! ctl button..",
1373          "    ",
1374          "    var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1375          "                 Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;",
1376          "                // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1377          "",
1378          "",
1379          "    if (_this.model.el.iter_n_children(null) < 1) {",
1380          "        // no children.. -- asume it's ok..",
1381          "        ",
1382          "        targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1383          "           ",
1384          "        this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);        ",
1385          "        Gdk.drag_status(ctx, action ,time);",
1386          "        return true;",
1387          "        ",
1388          "        // continue through to allow drop...",
1389          "",
1390          "    } ",
1391          "        ",
1392          "        ",
1393          "",
1394          "    ",
1395          "    ",
1396          "    //print(\"ISOVER? \" + isOver);",
1397          "    if (!isOver) {",
1398          "  ",
1399          "        Gdk.drag_status(ctx, 0 ,time);",
1400          "         this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);                    ",
1401          "         return false;",
1402          "",
1403          "    }",
1404          "            ",
1405          "    // drag node is parent of child..",
1406          "    //console.log(\"SRC TREEPATH: \" + src.treepath);",
1407          "    //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1408          "    ",
1409          "    // nned to check a  few here..",
1410          "    //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1411          "    //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1412          "    //Gtk.TreeViewDropPosition.AFTER",
1413          "    //Gtk.TreeViewDropPosition.BEFORE",
1414          "    ",
1415          "    // locally dragged items to not really use the ",
1416          "    var selection_text = this.dragData;",
1417          "    ",
1418          "            ",
1419          "            ",
1420          "    if (selection_text == null || selection_text.length < 1) {",
1421          "                //print(\"Error  - drag selection text returned NULL\");",
1422          "             Gdk.drag_status(ctx, 0 ,time);",
1423          "            this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1424          "             return false;",
1425          "     }",
1426          "                       ",
1427          "            ",
1428          "            // see if we are dragging into ourself?",
1429          "    var target_path = path.to_string();            ",
1430          "    print (\"Drag  %s onto %s--%d\\n \", selection_text, target_path, pos);",
1431          "    ",
1432          "    // pos : 3 = ontop - 0 = after, 1 = before",
1433          "    //print(\"target_path=\"+target_path);",
1434          "",
1435          "    // ",
1436          "    if (selection_text  == target_path) {",
1437          "        print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1438          "                ",
1439          "         Gdk.drag_status(ctx, 0 ,time);",
1440          "          this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1441          "          return false;",
1442          "//                 -- fixme -- this is not really correct..",
1443          "",
1444          "    }",
1445          "            ",
1446          "    // check that ",
1447          "    //print(\"DUMPING DATA\");",
1448          "    //console.dump(data);",
1449          "    // path, pos",
1450          "    ",
1451          "    //print(data.path.to_string() +' => '+  data.pos);",
1452          "    ",
1453          "    // dropList is a list of xtypes that this node could be dropped on.",
1454          "    // it is set up when we start to drag..",
1455          "    ",
1456          "    ",
1457          "    targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1458          "        ",
1459          "    print(\"targetDAta: \" + targetData +\"\\n\");",
1460          "    ",
1461          "    if (targetData.length < 1) {",
1462          "        //print(\"Can not find drop node path\");",
1463          "       ",
1464          "        Gdk.drag_status(ctx, 0, time);",
1465          "        this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1466          "        return false;",
1467          "    }",
1468          "    ",
1469          "    var td_ar = targetData.split(\"|\");",
1470          "      ",
1471          "    ",
1472          "",
1473          "    Gdk.drag_status(ctx, action ,time);",
1474          "    this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1475          "    return true;",
1476          "       ",
1477          "       ",
1478          "}"
1479         ],
1480         "key_press_event" : [
1481          "(ev) => {",
1482          "   this.key_is_pressed = true;",
1483          "    return false;",
1484          "}"
1485         ],
1486         "key_release_event" : [
1487          "(ev) => {",
1488          "       this.key_is_pressed = false;",
1489          "      return false;",
1490          "}",
1491          ""
1492         ]
1493        },
1494        "tooltip_column" : 1,
1495        "xtype" : "TreeView",
1496        "| void highlightDropPath" : [
1497         " ( string treepath, Gtk.TreeViewDropPosition pos) {",
1498         "",
1499         "        // highlighting for drag/drop",
1500         "        if (treepath.length > 0) {",
1501         "            this.el.set_drag_dest_row(  new  Gtk.TreePath.from_string( treepath ), pos);",
1502         "          } else {",
1503         "            this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1504         "         }",
1505         "             ",
1506         "}"
1507        ],
1508        "| void selectNode" : [
1509         "(string treepath_str, string source) {",
1510         "\tthis.lastEventSource = source;",
1511         "    //this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));",
1512         "     var tp = new Gtk.TreePath.from_string(treepath_str);",
1513         "     ",
1514         "     this.el.set_cursor(tp, null, false);  ",
1515         "     this.el.scroll_to_cell(tp, null, false, 0,0);",
1516         "}",
1517         ""
1518        ],
1519        "| void setCursor" : [
1520         "(string treepath, string sourceEvent)   {",
1521         "\tthis.lastEventSource = sourceEvent;",
1522         "\t//this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..",
1523         "    this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); ",
1524         "    // fire node_selected..",
1525         "    //this.blockChanges = false;",
1526         "\tthis.lastEventSource = \"\";",
1527         "}",
1528         ""
1529        ]
1530       },
1531       {
1532        "$ xns" : "Gtk",
1533        "* pack" : false,
1534        "id" : "LeftTreeMenu",
1535        "items" : [
1536         {
1537          "$ xns" : "Gtk",
1538          "* pack" : "add",
1539          "label" : "Delete Element",
1540          "listeners" : {
1541           "activate" : [
1542            "  ( ) => {",
1543            "    ",
1544            "    print(\"ACTIVATE?\");",
1545            "    ",
1546            "  ",
1547            "     _this.model.deleteSelected();",
1548            "}"
1549           ]
1550          },
1551          "xtype" : "MenuItem"
1552         },
1553         {
1554          "$ xns" : "Gtk",
1555          "* pack" : "add",
1556          "label" : "Save as Template",
1557          "listeners" : {
1558           "activate" : [
1559            "  () => {",
1560            "",
1561            "     DialogSaveTemplate.singleton().show(",
1562            "            (Gtk.Window) _this.el.get_toplevel (), ",
1563            "            _this.main_window.windowstate.file.palete(), ",
1564            "            _this.getActiveElement()",
1565            "    );",
1566            "     ",
1567            "    ",
1568            "}"
1569           ]
1570          },
1571          "xtype" : "MenuItem"
1572         },
1573         {
1574          "$ xns" : "Gtk",
1575          "* pack" : "add",
1576          "label" : "Save as Module",
1577          "listeners" : {
1578           "activate" : [
1579            "  () => {",
1580            "    var node = _this.getActiveElement();",
1581            "     var name = DialogSaveModule.singleton().show(",
1582            "            (Gtk.Window) _this.el.get_toplevel (), ",
1583            "            _this.main_window.windowstate.project, ",
1584            "            node",
1585            "     );",
1586            "     if (name.length < 1) {",
1587            "            return;",
1588            "  ",
1589            "     }",
1590            "     node.set_prop( new JsRender.NodeProp.special(\"xinclude\", name));",
1591            "     node.items.clear();",
1592            "",
1593            "",
1594            "    var s = _this.view.el.get_selection();",
1595            "    ",
1596            "    print(\"GET  SELECTED?\");",
1597            "    Gtk.TreeIter iter;",
1598            "    Gtk.TreeModel mod;",
1599            "",
1600            "    ",
1601            "    if (!s.get_selected(out mod, out iter)) {",
1602            "        return; // nothing seleted..",
1603            "    }",
1604            "    Gtk.TreeIter citer;",
1605            "    var n_cn = mod.iter_n_children(iter) -1;",
1606            "    for (var i = n_cn; i > -1; i--) {",
1607            "        mod.iter_nth_child(out citer, iter, i);",
1608            "        ",
1609            "",
1610            "        print(\"removing node from Tree\\n\");    ",
1611            "    ",
1612            "        _this.model.el.remove(ref citer);",
1613            "    }",
1614            "    _this.changed();",
1615            "    _this.node_selected(node, \"tree\");",
1616            "     ",
1617            "    ",
1618            "}"
1619           ]
1620          },
1621          "xtype" : "MenuItem"
1622         }
1623        ],
1624        "xtype" : "Menu"
1625       }
1626      ],
1627      "xtype" : "ScrolledWindow"
1628     }
1629    ],
1630    "xtype" : "Box",
1631    "| JsRender.JsRender getActiveFile" : [
1632     "() {",
1633     "    return this.main_window.windowstate.file;",
1634     "}",
1635     ""
1636    ],
1637    "| JsRender.Node? getActiveElement" : [
1638     " () { // return path to actie node.",
1639     "",
1640     "     var path = this.getActivePath();",
1641     "     if (path.length < 1) {",
1642     "        return null;",
1643     "     }",
1644     "     return _this.model.pathToNode(path);",
1645     "     ",
1646     "}",
1647     ""
1648    ],
1649    "| string getActivePath" : [
1650     " () {",
1651     "    ",
1652     "    var view = this.view.el;",
1653     "    if (view.get_selection().count_selected_rows() < 1) {",
1654     "        return \"\";",
1655     "    }",
1656     "    Gtk.TreeIter iter;",
1657     "    Gtk.TreeModel mod;",
1658     "    view.get_selection().get_selected(out mod, out iter);",
1659     "    return mod.get_path(iter).to_string();",
1660     "}",
1661     " "
1662    ]
1663   }
1664  ],
1665  "modOrder" : "",
1666  "name" : "WindowLeftTree",
1667  "parent" : "",
1668  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/WindowLeftTree.bjs",
1669  "permname" : "",
1670  "title" : ""
1671 }