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