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