Fix #7394 - more warning fixes
[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 = null,addi = null;",
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           "    ",
553           "    var fn = \"/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-\" + sub + \".png\";",
554           "    try { ",
555           "\t\taddi =  ic.load_icon(\"list-add\", 16,0);",
556           "\t\tif (FileUtils.test (fn, FileTest.IS_REGULAR)) {",
557           "\t\t\t",
558           "\t\t    \tpix = new Gdk.Pixbuf.from_file (fn);",
559           "\t\t\t",
560           "\t\t}  else {",
561           "\t\t \tpix = ic.load_icon(\"emblem-new\", 16,0);",
562           "\t \t}",
563           " \t} catch (GLib.Error e) {}",
564           "    ",
565           "    var fqn = node.fqn();",
566           "    var cn = _this.main_window.windowstate.project.palete.getChildList(fqn);",
567           "    ",
568           "    this.el.set(",
569           "    \t\titer, ",
570           "    \t\t0, node.nodeTitle(),",
571           "            1, node.nodeTip(), ",
572           "            -1",
573           "    );",
574           "    this.el.set_value(iter, 2,o);",
575           "    this.el.set_value(iter, 3,pix);    ",
576           "  \tthis.el.set_value(iter, 4, cn.length > 0 ? addi : null);   ",
577           "    ",
578           "",
579           "}"
580          ],
581          "| void load" : [
582           "(Gee.ArrayList<JsRender.Node> tr, Gtk.TreeIter? iter) ",
583           "{",
584           "    ",
585           "  \t",
586           "    Gtk.TreeIter citer;",
587           "    //this.insert(citer,iter,0);",
588           "   ",
589           "    ",
590           "    for(var i =0 ; i < tr.size; i++) {",
591           "        if (iter != null) {",
592           "            this.el.insert(out citer,iter,-1); // why not append?",
593           "        } else {",
594           "            this.el.append(out citer,null);",
595           "        }",
596           "        this.iterSetValues(citer, tr.get(i));",
597           "        ",
598           " ",
599           "         ",
600           "        if (tr.get(i).items.size > 0) {",
601           "            this.load(tr.get(i).items, citer);",
602           "        }",
603           "     ",
604           "    }",
605           "",
606           "    ",
607           "}"
608          ],
609          "| void loadFile" : [
610           "(JsRender.JsRender f) {",
611           "    //console.dump(f);",
612           "    this.el.clear();",
613           "    _this.main_window.windowstate.leftTreeNodeSelected(null, \"\");",
614           "    // needed???",
615           "    _this.main_window.windowstate.file = f;",
616           "    ",
617           "   ",
618           "    if (f.tree == null) {",
619           "\t    try {",
620           "\t        f.loadItems( );",
621           "        } catch (Error e) {",
622           "    \t\treturn;",
623           "        }",
624           "    }",
625           "    // if it's still null?",
626           "    if (f.tree == null) {",
627           "\t\t_this.main_window.windowstate.showAddObject(_this.view.el);",
628           "    ",
629           "        return;",
630           "    }",
631           "  ",
632           "    var o = new Gee.ArrayList<JsRender.Node>();",
633           "    o.add(f.tree);",
634           "    this.load(o,null);",
635           "    ",
636           "    _this.view.el.expand_all();",
637           "",
638           "    if (f.tree.items.size < 1) {",
639           "        // single item..",
640           "        ",
641           "        //this.get('/Window.leftvpaned').el.set_position(80);",
642           "        // select first...",
643           "        _this.view.el.set_cursor( ",
644           "            new  Gtk.TreePath.from_string(\"0\"), null, false);",
645           "        ",
646           "        ",
647           "    } else {",
648           "          //this.get('/Window.leftvpaned').el.set_position(200);",
649           "    }",
650           "    ",
651           "    ",
652           "    while (Gtk.events_pending()) {",
653           "        Gtk.main_iteration();",
654           "   }",
655           "",
656           "    _this.maincol.el.set_max_width(_this.viewwin.el.get_allocated_width() - 32);",
657           " ",
658           "    ",
659           "   ",
660           "    return;",
661           " ",
662           "            ",
663           "}",
664           ""
665          ],
666          "| void moveNode" : [
667           "(string target_data, Gdk.DragAction action) ",
668           "{",
669           "   ",
670           "   /// target_data = \"path|pos\");",
671           "   ",
672           "   ",
673           "    //print(\"MOVE NODE\");",
674           "    // console.dump(target_data);",
675           "    Gtk.TreeIter old_iter;",
676           "    Gtk.TreeModel mod;",
677           "    ",
678           "    var s = _this.view.el.get_selection();",
679           "    s.get_selected(out mod , out old_iter);",
680           "    mod.get_path(old_iter);",
681           "    ",
682           "    var node = this.pathToNode(mod.get_path(old_iter).to_string());",
683           "    //console.dump(node);",
684           "    if (node == null) {",
685           "        GLib.debug(\"moveNode: ERROR - node is null?\");",
686           "    }",
687           "    ",
688           "    ",
689           "",
690           "    // needs to drop first, otherwise the target_data ",
691           "    // treepath will be invalid.",
692           "",
693           "    ",
694           "    if ((action & Gdk.DragAction.MOVE) > 0) {",
695           "            GLib.debug(\"REMOVING OLD NODE : \" + target_data + \"\\n\");",
696           "            node.remove();",
697           "            this.dropNode(target_data, node, false);",
698           "            this.el.remove(ref old_iter);",
699           "            ",
700           "            ",
701           "                         ",
702           "    } else {",
703           "        GLib.debug(\"DROPPING NODE // copy: \" + target_data + \"\\n\");",
704           "        node = node.deepClone();",
705           "        this.dropNode(target_data, node, false);",
706           "    }",
707           "    _this.changed();",
708           "    this.activePath= \"\";",
709           "    //this.updateNode(false,true);",
710           "}",
711           ""
712          ],
713          "| void updateSelected" : [
714           "() {",
715           "  ",
716           "   ",
717           "    var s = _this.view.el.get_selection();",
718           "    ",
719           "     Gtk.TreeIter iter;",
720           "    Gtk.TreeModel mod;",
721           "    ",
722           "    ",
723           "    ",
724           "    if (!s.get_selected(out mod, out iter)) {",
725           "        return; // nothing seleted..",
726           "    }",
727           "  ",
728           "  GLib.Value value;",
729           "    this.el.get_value(iter, 2, out value);",
730           "    var node = (JsRender.Node)(value.get_object());",
731           "    ",
732           "      this.el.set(iter, 0, node.nodeTitle(),",
733           "                1, node.nodeTip(), -1",
734           "        );",
735           "}",
736           ""
737          ]
738         },
739         {
740          "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
741          "$ xns" : "Gtk",
742          "* init" : [
743           "  this.el.add_attribute(_this.renderer.el , \"markup\", 0 );",
744           "  this.el.add_attribute(_this.iconrender.el , \"pixbuf\",  3 );",
745           " "
746          ],
747          "* pack" : "append_column",
748          "bool expand" : true,
749          "bool resizable" : true,
750          "id" : "maincol",
751          "items" : [
752           {
753            "$ xns" : "Gtk",
754            "* pack" : "pack_start,false",
755            "id" : "iconrender",
756            "int width" : 16,
757            "xtype" : "CellRendererPixbuf"
758           },
759           {
760            "$ xns" : "Gtk",
761            "* pack" : "pack_start,true",
762            "id" : "renderer",
763            "xtype" : "CellRendererText"
764           }
765          ],
766          "utf8 title" : "Node",
767          "xtype" : "TreeViewColumn"
768         },
769         {
770          "$ Gtk.TreeViewColumnSizing sizing" : "Gtk.TreeViewColumnSizing.FIXED",
771          "$ xns" : "Gtk",
772          "* init" : [
773           " this.el.add_attribute(_this.addiconrender.el , \"pixbuf\",  4 );",
774           " "
775          ],
776          "* pack" : "append_column",
777          "bool expand" : false,
778          "int max_width" : 24,
779          "items" : [
780           {
781            "$ xns" : "Gtk",
782            "* pack" : "pack_start,true",
783            "id" : "addiconrender",
784            "int width" : 16,
785            "xtype" : "CellRendererPixbuf"
786           }
787          ],
788          "utf8 title" : "Add",
789          "xtype" : "TreeViewColumn"
790         }
791        ],
792        "listeners" : {
793         "button_press_event" : [
794          "  ( ev) => {",
795          "    //console.log(\"button press?\");",
796          "    this.button_is_pressed = true;",
797          "    print(\"BUTTON DOWN\\n\");",
798          "    ",
799          "    this.lastEventSource = \"tree\";",
800          "    if (! _this.before_node_change() ) {",
801          "    ",
802          "       return true;",
803          "    }",
804          "    ",
805          "\tif (ev.type != Gdk.EventType.BUTTON_PRESS) {",
806          "\t\treturn false;",
807          "\t}",
808          "    if (_this.model.el.iter_n_children(null) < 1) {",
809          "\t    _this.main_window.windowstate.showAddObject(_this.view.el);",
810          "\t    return true;",
811          "    }",
812          "    ",
813          "   ",
814          "    Gtk.TreePath res;",
815          "    Gtk.TreeViewColumn col;",
816          "    if (!_this.view.el.get_path_at_pos((int)ev.x,(int)ev.y, out res, out col, null, null) ) {",
817          "        return true;",
818          "    }",
819          "    ",
820          "    if (col.title == \"Add\") {",
821          " \t\tGLib.Value value;",
822          " \t\tGtk.TreeIter iter;",
823          "",
824          "\t\t_this.model.el.get_iter (out  iter, res);",
825          "        _this.model.el.get_value(iter, 2, out value);\t\t",
826          "            // why dup_ - gets and and inc's ref count (which in theory should be freed at the end.?",
827          "            ",
828          "        var node = (JsRender.Node)value.dup_object();",
829          "        var fqn = node.fqn();",
830          "    \tvar cn = _this.main_window.windowstate.project.palete.getChildList(fqn);",
831          "  \t\tif (cn.length < 1) {",
832          "  \t\t\treturn true;",
833          "\t\t}",
834          "    ",
835          "         _this.main_window.windowstate.leftTreeBeforeChange();",
836          "         this.el.get_selection().select_path(res);",
837          "     \t_this.main_window.windowstate.showAddObject(this.el);",
838          "     \treturn true;",
839          "     }",
840          "    ",
841          "\tif (  ev.button != 3) {",
842          "        //print(\"click\" + ev.type);",
843          "        return false;",
844          "     }",
845          "    _this.main_window.windowstate.leftTreeBeforeChange();",
846          "",
847          "    ",
848          "     ",
849          "    this.el.get_selection().select_path(res);",
850          "     ",
851          "      ",
852          "     ",
853          "      //if (!this.get('/LeftTreeMenu').el)  { ",
854          "      //      this.get('/LeftTreeMenu').init(); ",
855          "      //  }",
856          "        ",
857          "     _this.LeftTreeMenu.el.set_screen(Gdk.Screen.get_default());",
858          "     _this.LeftTreeMenu.el.show_all();",
859          "      _this.LeftTreeMenu.el.popup(null, null, null,  3, ev.time);",
860          "     //   print(\"click:\" + res.path.to_string());",
861          "      return true;",
862          "}"
863         ],
864         "button_release_event" : [
865          "(ev) => { ",
866          "    this.button_is_pressed = false;",
867          "  return false;",
868          "}"
869         ],
870         "cursor_changed" : [
871          " ( ) => {",
872          "    print(\"LEFT TREE Cursor Changed\\n\");",
873          "\t//if (!this.button_is_pressed && !this.key_is_pressed) {",
874          "\t\t// then event was started by some other action",
875          "\t\t// which should manually trigger all the events..",
876          "\t//\tprint(\"SKIPPING select - no button or key pressed\\n\");",
877          "\t//\treturn;",
878          "\t//}",
879          "",
880          "",
881          "     if (this.blockChanges) { // probably not needed.. ",
882          "\t\tprint(\"SKIPPING select - blockchanges set..\\n\");     ",
883          "       return  ;",
884          "     }",
885          "      if (!_this.before_node_change( ) ) {",
886          "\t     this.blockChanges = true;",
887          "\t     this.el.get_selection().unselect_all();",
888          "\t     this.blockChanges = false;",
889          "\t     ",
890          "\t     return;",
891          "     }",
892          "     if (_this.main_window.windowstate.file == null) {",
893          "   \t\tprint(\"SKIPPING select windowstate file is not set...\\n\");     ",
894          "         return;",
895          "     } ",
896          "     ",
897          "     //var render = this.get('/LeftTree').getRenderer();                ",
898          "    print(\"LEFT TREE -> view -> selection changed called\\n\");",
899          "    ",
900          "    ",
901          "    // -- it appears that the selection is not updated.",
902          "      ",
903          "    GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => {",
904          "         print(\"LEFT TREE -> view -> selection changed TIMEOUT CALLED\\n\");",
905          "",
906          "            if (this.el.get_selection().count_selected_rows() < 1) {",
907          "",
908          "                print(\"selected rows < 1\\n\");",
909          "                //??this.model.load( false);",
910          "                _this.node_selected(null, this.lastEventSource);",
911          "                ",
912          "                return false ;",
913          "            }",
914          "                ",
915          "                //console.log('changed');",
916          "            var s = this.el.get_selection();",
917          "             Gtk.TreeIter iter;",
918          "             Gtk.TreeModel mod;",
919          "            s.get_selected(out mod, out iter);",
920          "            ",
921          "            ",
922          "            // var val = \"\";",
923          "            GLib.Value value;",
924          "            _this.model.el.get_value(iter, 2, out value);",
925          "            _this.model.activePath = mod.get_path(iter).to_string();",
926          "            ",
927          "            // why dup_?",
928          "            ",
929          "            var node = (JsRender.Node)value.dup_object();",
930          "            print (\"calling left_tree.node_selected\\n\");",
931          "            _this.node_selected(node, this.lastEventSource);",
932          "            while (Gtk.events_pending()) {",
933          "                Gtk.main_iteration();",
934          "           }",
935          "            var cp = mod.get_path(iter);",
936          "            Gtk.TreePath sp, ep;",
937          "            this.el.get_visible_range(out sp, out ep);",
938          "            // if sp is before cp then retuns 1.",
939          "            // if cp is before ep then retuns 1.",
940          "            if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) {",
941          "                return false;",
942          "            }",
943          "            ",
944          "             ",
945          "            ",
946          "            this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);",
947          "            ",
948          "            return false;",
949          "      });  ",
950          "    //_this.after_node_change(node);",
951          "",
952          "//        _this.model.file.changed(node, \"tree\");",
953          "   ",
954          "    //Seed.print( value.get_string());",
955          "    return  ;",
956          "                ",
957          "}"
958         ],
959         "drag_begin" : [
960          "( ctx)  => {",
961          "\t//print('SOURCE: drag-begin');",
962          "        ",
963          "        ",
964          "        //this.targetData = \"\";",
965          "        ",
966          "        // find what is selected in our tree...",
967          "        ",
968          "        var s = _this.view.el.get_selection();",
969          "        if (s.count_selected_rows() < 1) {",
970          "            return;",
971          "        }",
972          "        Gtk.TreeIter iter;",
973          "        Gtk.TreeModel mod;",
974          "        s.get_selected(out mod, out iter);",
975          "",
976          "        ",
977          "",
978          "        // set some properties of the tree for use by the dropped element.",
979          "        GLib.Value value;",
980          "        _this.model.el.get_value(iter, 2, out value);",
981          "        var tp = mod.get_path(iter).to_string();",
982          "        var data = (JsRender.Node)(value.dup_object());",
983          "        var xname = data.fqn();",
984          "        print (\"XNAME  IS \" + xname+ \"\\n\");",
985          "        this.dragData = tp;",
986          "        this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname);",
987          "        ",
988          "        print (\"DROP LIST IS \" + string.joinv(\", \", this.dropList) + \"\\n\");",
989          "        ",
990          "",
991          "        // make the drag icon a picture of the node that was selected",
992          "    ",
993          "        ",
994          "    // by default returns the path..",
995          "       var path = _this.model.el.get_path(iter);",
996          "",
997          "         ",
998          "        var pix = this.el.create_row_drag_icon ( path);",
999          "        ",
1000          "        Gtk.drag_set_icon_surface (ctx, pix) ;",
1001          "        ",
1002          "        return;",
1003          "}"
1004         ],
1005         "drag_data_get" : [
1006          "( drag_context, data, info, time) => {",
1007          "            ",
1008          "",
1009          "\t//print(\"drag-data-get\");",
1010          "\tvar s = this.el.get_selection();",
1011          "\tif (s.count_selected_rows() < 1) {",
1012          "\t\tdata.set_text(\"\",0);     ",
1013          "\t\t print(\"return empty string - no selection..\");",
1014          "\t\treturn;",
1015          "\t}",
1016          "",
1017          "\tGtk.TreeIter iter;",
1018          "\tGtk.TreeModel mod;",
1019          "",
1020          "\ts.get_selected(out mod, out iter);",
1021          "",
1022          "",
1023          "",
1024          "\tGLib.Value value;",
1025          "\t_this.model.el.get_value(iter, 2, out value);",
1026          "\tvar ndata = (JsRender.Node)(value.dup_object());",
1027          "",
1028          "",
1029          "",
1030          "\tvar tp = mod.get_path(iter).to_string();",
1031          "\t// by default returns the path..",
1032          "",
1033          "\tif ( info != Gdk.Atom.intern(\"STRING\",true) ) {",
1034          "\t\ttp = ndata.toJsonString();",
1035          "\t}   ",
1036          "",
1037          "\t//data.set_text(tp,tp.length);   ",
1038          "",
1039          "\tdata.set (data.get_target (), 8, (uchar[]) tp.to_utf8 ());",
1040          "",
1041          "",
1042          "\t//  print(\"return \" + tp);",
1043          "\t}"
1044         ],
1045         "drag_data_received" : [
1046          "\t(ctx, x, y, sel, info, time)  => {",
1047          "",
1048          "\t// THIS CODE ONLY RELATES TO drag  or drop of \"NEW\" elements or \"FROM another tree..\"",
1049          "",
1050          "",
1051          "\t//  print(\"Tree: drag-data-received\\n\");",
1052          "\tvar selection_text = (string)sel.get_data();",
1053          "\t//print(\"selection_text= %s\\n\",selection_text);",
1054          "",
1055          "\tvar is_drag = this.drag_in_motion;",
1056          "",
1057          "",
1058          "",
1059          "\tGLib.debug(\"Is Drag %s\\n\", is_drag ? \"Y\": \"N\");",
1060          "\tvar  targetData = \"\";",
1061          "",
1062          "\tGtk.TreePath path;",
1063          "\tGtk.TreeViewDropPosition pos;",
1064          "\tvar isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1065          "",
1066          "\t// if there are not items in the tree.. the we have to set isOver to true for anything..",
1067          "\tvar isEmpty = false;",
1068          "\tif (_this.model.el.iter_n_children(null) < 1) {",
1069          "\t\tGLib.debug(\"got NO children?\\n\");",
1070          "\t\tisOver = true; //??? ",
1071          "\t\tisEmpty = true;",
1072          "\t\tpos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1073          "\t}",
1074          "",
1075          "",
1076          "\t//console.log(\"LEFT-TREE: drag-motion\");",
1077          "\tvar src = Gtk.drag_get_source_widget(ctx);",
1078          "",
1079          "\t// a drag from self - this should be handled by drop and motion.",
1080          "\tif (src == this.el) {",
1081          "\t\tGLib.debug(\"Source == this element should not happen.. ? \\n\");",
1082          "\t\treturn;",
1083          "\t}",
1084          "\t//print(\"drag_data_recieved from another element\");",
1085          "",
1086          "\t ",
1087          "",
1088          "",
1089          "\tif (selection_text == null || selection_text.length < 1 || !isOver) {",
1090          "\t\t// nothing valid foudn to drop...",
1091          "\t\t   GLib.debug(\"empty sel text or not over\");",
1092          "\t\tif (is_drag) {",
1093          "\t\t    Gdk.drag_status(ctx, 0, time);",
1094          "\t\t    this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1095          "\t\t    return;",
1096          "\t\t}",
1097          "\t\tGtk.drag_finish (ctx, false, false, time);        // drop failed..",
1098          "\t\t// no drop action...",
1099          "\t\treturn;            ",
1100          "",
1101          "\t}",
1102          "\tvar dropNode = new JsRender.Node(); ",
1103          "",
1104          "\tvar dropNodeType  = selection_text;",
1105          "\tvar show_templates = true;",
1106          "\t// for drop",
1107          "\tif (dropNodeType[0] == '{') {",
1108          "\t\tvar pa = new Json.Parser();",
1109          "\t\ttry {",
1110          "\t\t    pa.load_from_data(dropNodeType);",
1111          "\t\t} catch (Error e) {",
1112          "\t\t    Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1113          "\t\t    // no drop action...",
1114          "\t\t    return;   ",
1115          "\t\t}",
1116          "\t\t ",
1117          "\t\tdropNode.loadFromJson( pa.get_root().get_object(), 2);",
1118          "\t\tdropNodeType = dropNode.fqn();",
1119          "\t\tshow_templates = false;",
1120          "\t\t",
1121          "\t\t",
1122          "\t} else {",
1123          "\t\t// drop with property.",
1124          "\t\tif (selection_text.contains(\":\")) {",
1125          "\t\t\tvar bits = selection_text.split(\":\");",
1126          "\t\t    dropNode.setFqn(bits[0]);",
1127          "\t\t    dropNode.set_prop(new JsRender.NodeProp.special(\"prop\", bits[1]));",
1128          "\t\t    ",
1129          "\t\t    ",
1130          "\t\t    ",
1131          "\t\t} else {",
1132          "\t\t    dropNode.setFqn(selection_text);",
1133          "\t\t}",
1134          "\t}",
1135          "",
1136          "\t ",
1137          "\t// dropList --- need to gather this ... ",
1138          "\tGLib.debug(\"get dropList for : %s\\n\",dropNodeType);            ",
1139          "\tvar dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType);",
1140          "",
1141          "\tGLib.debug(\"dropList: %s\\n\", string.joinv(\" , \", dropList));",
1142          "",
1143          "\t// if drag action is link ... then we can drop it anywahere...",
1144          "\t if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) {",
1145          "\t\t // if path is null?? dragging into an empty tree?",
1146          "\t\t targetData = (path == null ? \"\" :  path.to_string()) + \"|%d\".printf((int)pos);",
1147          "\t } else {",
1148          "",
1149          "",
1150          "\t\ttargetData = _this.model.findDropNodeByPath( isEmpty ? \"\" : path.to_string(), dropList, pos);",
1151          "\t }",
1152          "",
1153          "",
1154          "\t\t",
1155          "\tGLib.debug(\"targetDAta: %s\", targetData );",
1156          "",
1157          "\tif (targetData.length < 1) {",
1158          "\t ",
1159          "\t\t// invalid drop path..",
1160          "\t\tif (this.drag_in_motion) {",
1161          "\t\t    Gdk.drag_status(ctx, 0, time);",
1162          "\t\t    this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1163          "\t\t    return;",
1164          "\t\t}",
1165          "\t\tGtk.drag_finish (ctx, false, false, time);        // drop failed..",
1166          "\t\t// no drop action...",
1167          "\t\treturn;",
1168          "\t}",
1169          "",
1170          "",
1171          "",
1172          "\t var td_ar = targetData.split(\"|\");",
1173          "\t  ",
1174          "",
1175          "\tif (this.drag_in_motion) { ",
1176          "\t\tGdk.drag_status(ctx, Gdk.DragAction.COPY ,time);",
1177          "",
1178          "\t\tthis.highlightDropPath(  td_ar[0]  , (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1179          "\t\treturn;",
1180          "\t}",
1181          "\t// continue on to allow drop..",
1182          "",
1183          "",
1184          "\t// at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1185          "\t//targetData",
1186          "\t//   {parent}|{pos}|{prop}",
1187          "",
1188          "",
1189          "   _this.model.dropNode(targetData, dropNode, show_templates);",
1190          "    ",
1191          "\tGLib.debug(\"ADD new node!!!\\n\");",
1192          "\t\t",
1193          "\t///Xcls_DialogTemplateSelect.singleton().show( _this.model.file.palete(), node);",
1194          "",
1195          "\tGtk.drag_finish (ctx, false, false,time);",
1196          "",
1197          "",
1198          "\t\t",
1199          "\t\t",
1200          "",
1201          "}"
1202         ],
1203         "drag_drop" : [
1204          " (  ctx, x, y, time)  => {",
1205          "      //Seed.print(\"TARGET: drag-drop\");",
1206          "   ",
1207          "   ",
1208          "    var src = Gtk.drag_get_source_widget(ctx);",
1209          "     ",
1210          "   if (src != this.el) {",
1211          "   ",
1212          "    ",
1213          "       ",
1214          "       this.drag_in_motion = false;   ",
1215          "            // request data that will be recieved by the recieve...              ",
1216          "        Gtk.drag_get_data",
1217          "        (",
1218          "                this.el,         // will receive 'drag-data-received' signal ",
1219          "                ctx,        // represents the current state of the DnD ",
1220          "                Gdk.Atom.intern(\"application/json\",true),    // the target type we want ",
1221          "                time            // time stamp ",
1222          "        );",
1223          "",
1224          "         ",
1225          "        // No target offered by source => error",
1226          "   ",
1227          "",
1228          "         return  false;",
1229          "     }",
1230          "     ",
1231          "     // handle drop around self..",
1232          "     ",
1233          "                  ",
1234          "            ",
1235          "    //print(\"GETTING POS\");",
1236          "    var  targetData = \"\";",
1237          "    ",
1238          "    Gtk.TreePath path;",
1239          "    Gtk.TreeViewDropPosition pos;",
1240          "    var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1241          "    ",
1242          "    // if there are not items in the tree.. the we have to set isOver to true for anything..",
1243          "    var isEmpty = false;",
1244          "    if (_this.model.el.iter_n_children(null) < 1) {",
1245          "        print(\"got NO children?\\n\");",
1246          "        isOver = true; //??? ",
1247          "        isEmpty = true;",
1248          "        pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1249          "    }",
1250          "    ",
1251          "     ",
1252          "     ",
1253          "    //var action = Gdk.DragAction.COPY;",
1254          "        // unless we are copying!!! ctl button..",
1255          "    ",
1256          "    var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1257          "                 Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;",
1258          "                // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1259          "",
1260          "      ",
1261          "    if (_this.model.el.iter_n_children(null) < 1) {",
1262          "        // no children.. -- asume it's ok..",
1263          "        ",
1264          "        targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1265          "         ",
1266          "        // continue through to allow drop...",
1267          "",
1268          "    } else {",
1269          "                ",
1270          "                ",
1271          "    ",
1272          "                ",
1273          "                ",
1274          "                //print(\"ISOVER? \" + isOver);",
1275          "        if (!isOver) {",
1276          "            ",
1277          "            Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1278          "            return true; // not over apoint!?! - no action on drop or motion..",
1279          "        }",
1280          "                ",
1281          "        // drag node is parent of child..",
1282          "        //console.log(\"SRC TREEPATH: \" + src.treepath);",
1283          "        //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1284          "        ",
1285          "        // nned to check a  few here..",
1286          "        //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1287          "        //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1288          "        //Gtk.TreeViewDropPosition.AFTER",
1289          "        //Gtk.TreeViewDropPosition.BEFORE",
1290          "        ",
1291          "        // locally dragged items to not really use the ",
1292          "        var selection_text = this.dragData;",
1293          "        ",
1294          "        ",
1295          "        ",
1296          "        if (selection_text == null || selection_text.length < 1) {",
1297          "            //print(\"Error  - drag selection text returned NULL\");",
1298          "          ",
1299          "             Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1300          "             return true; /// -- fixme -- this is not really correct..",
1301          "        }                ",
1302          "                ",
1303          "                // see if we are dragging into ourself?",
1304          "                print (\"got selection text of  \" + selection_text);",
1305          "        ",
1306          "        var target_path = path.to_string();",
1307          "        //print(\"target_path=\"+target_path);",
1308          "",
1309          "        // ",
1310          "        if (selection_text  == target_path) {",
1311          "            print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1312          "            ",
1313          "             Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1314          "",
1315          "             return true; /// -- fixme -- this is not really correct..",
1316          "",
1317          "        }",
1318          "                ",
1319          "        // check that ",
1320          "        //print(\"DUMPING DATA\");",
1321          "        //console.dump(data);",
1322          "        // path, pos",
1323          "        ",
1324          "        //print(data.path.to_string() +' => '+  data.pos);",
1325          "        ",
1326          "        // dropList is a list of xtypes that this node could be dropped on.",
1327          "        // it is set up when we start to drag..",
1328          "        ",
1329          "        ",
1330          "        targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1331          "            ",
1332          "        print(\"targetDAta: \" + targetData +\"\\n\");",
1333          "        ",
1334          "        if (targetData.length < 1) {",
1335          "            //print(\"Can not find drop node path\");",
1336          "             ",
1337          "            Gtk.drag_finish (ctx, false, false, time);        // drop failed..",
1338          "            return true;",
1339          "        }",
1340          "                    ",
1341          "                ",
1342          "                ",
1343          "                // continue on to allow drop..",
1344          "  }",
1345          "        // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..",
1346          "",
1347          "",
1348          "     var delete_selection_data = false;",
1349          "        ",
1350          "    if (action == Gdk.DragAction.ASK)  {",
1351          "        /* Ask the user to move or copy, then set the ctx action. */",
1352          "    }",
1353          "",
1354          "    if (action == Gdk.DragAction.MOVE) {",
1355          "        delete_selection_data = true;",
1356          "    }",
1357          "      ",
1358          "                // drag around.. - reorder..",
1359          "    _this.model.moveNode(targetData, action);",
1360          "        ",
1361          "       ",
1362          "        ",
1363          "        ",
1364          "        ",
1365          "        // we can send stuff to souce here...",
1366          "",
1367          "",
1368          "// do we always say failure, so we handle the reall drop?",
1369          "    Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);",
1370          "",
1371          "    return true;",
1372          " ",
1373          " ",
1374          " ",
1375          " ",
1376          " ",
1377          " ",
1378          "}"
1379         ],
1380         "drag_end" : [
1381          "  (drag_context) => {",
1382          "\t//Seed.print('LEFT-TREE: drag-end');",
1383          "        this.dragData = \"\";",
1384          "        this.dropList = null;",
1385          "//        this.targetData = \"\";",
1386          "        this.highlightDropPath(\"\",0);",
1387          "//        return true;",
1388          "}"
1389         ],
1390         "drag_motion" : [
1391          " ( ctx, x, y, time)  => {",
1392          "   print(\"got drag motion\\n\");",
1393          "    var src = Gtk.drag_get_source_widget(ctx);",
1394          "   this.drag_x = x;",
1395          "   this.drag_y = y;     ",
1396          "",
1397          "   if (src != this.el) {",
1398          "   ",
1399          " ",
1400          " ",
1401          "    // the point of this is to detect where an item could be dropped..",
1402          "        print(\"requesting drag data\\n\");",
1403          "       this.drag_in_motion = true;",
1404          "       ",
1405          "            // request data that will be recieved by the recieve...              ",
1406          "        Gtk.drag_get_data",
1407          "        (",
1408          "                this.el,         // will receive 'drag-data-received' signal ",
1409          "                ctx,        // represents the current state of the DnD ",
1410          "                Gdk.Atom.intern(\"STRING\",true),    // the target type we want ",
1411          "                time            // time stamp ",
1412          "        );",
1413          "        return true;",
1414          "  }    ",
1415          "",
1416          "",
1417          "  print(\"action: %d\\n\", ctx.get_actions());",
1418          " //print(\"GETTING POS\");",
1419          "    var  targetData = \"\";",
1420          "",
1421          "    Gtk.TreePath path;",
1422          "    Gtk.TreeViewDropPosition pos;",
1423          "    var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);",
1424          "",
1425          "    // if there are not items in the tree.. the we have to set isOver to true for anything..",
1426          "    var isEmpty = false;",
1427          "    if (_this.model.el.iter_n_children(null) < 1) {",
1428          "        print(\"got NO children?\\n\");",
1429          "        isOver = true; //??? ",
1430          "        isEmpty = true;",
1431          "        pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;",
1432          "    }",
1433          "",
1434          "",
1435          "    // ------------- a drag from self..",
1436          "",
1437          "",
1438          "    //var action = Gdk.DragAction.COPY;",
1439          "        // unless we are copying!!! ctl button..",
1440          "    ",
1441          "    var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?",
1442          "                 Gdk.DragAction.COPY  : Gdk.DragAction.MOVE ;",
1443          "                // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;",
1444          "",
1445          "",
1446          "    if (_this.model.el.iter_n_children(null) < 1) {",
1447          "        // no children.. -- asume it's ok..",
1448          "        ",
1449          "        targetData = \"|%d|\".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1450          "           ",
1451          "        this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);        ",
1452          "        Gdk.drag_status(ctx, action ,time);",
1453          "        return true;",
1454          "        ",
1455          "        // continue through to allow drop...",
1456          "",
1457          "    } ",
1458          "        ",
1459          "        ",
1460          "",
1461          "    ",
1462          "    ",
1463          "    //print(\"ISOVER? \" + isOver);",
1464          "    if (!isOver) {",
1465          "  ",
1466          "        Gdk.drag_status(ctx, 0 ,time);",
1467          "         this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);                    ",
1468          "         return false;",
1469          "",
1470          "    }",
1471          "            ",
1472          "    // drag node is parent of child..",
1473          "    //console.log(\"SRC TREEPATH: \" + src.treepath);",
1474          "    //console.log(\"TARGET TREEPATH: \" + data.path.to_string());",
1475          "    ",
1476          "    // nned to check a  few here..",
1477          "    //Gtk.TreeViewDropPosition.INTO_OR_AFTER",
1478          "    //Gtk.TreeViewDropPosition.INTO_OR_BEFORE",
1479          "    //Gtk.TreeViewDropPosition.AFTER",
1480          "    //Gtk.TreeViewDropPosition.BEFORE",
1481          "    ",
1482          "    // locally dragged items to not really use the ",
1483          "    var selection_text = this.dragData;",
1484          "    ",
1485          "            ",
1486          "            ",
1487          "    if (selection_text == null || selection_text.length < 1) {",
1488          "                //print(\"Error  - drag selection text returned NULL\");",
1489          "             Gdk.drag_status(ctx, 0 ,time);",
1490          "            this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1491          "             return false;",
1492          "     }",
1493          "                       ",
1494          "            ",
1495          "            // see if we are dragging into ourself?",
1496          "    var target_path = path.to_string();            ",
1497          "    print (\"Drag  %s onto %s--%d\\n \", selection_text, target_path, pos);",
1498          "    ",
1499          "    // pos : 3 = ontop - 0 = after, 1 = before",
1500          "    //print(\"target_path=\"+target_path);",
1501          "",
1502          "    // ",
1503          "    if (selection_text  == target_path) {",
1504          "        print(\"self drag ?? == we should perhaps allow copy onto self..\\n\");",
1505          "                ",
1506          "         Gdk.drag_status(ctx, 0 ,time);",
1507          "          this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1508          "          return false;",
1509          "//                 -- fixme -- this is not really correct..",
1510          "",
1511          "    }",
1512          "            ",
1513          "    // check that ",
1514          "    //print(\"DUMPING DATA\");",
1515          "    //console.dump(data);",
1516          "    // path, pos",
1517          "    ",
1518          "    //print(data.path.to_string() +' => '+  data.pos);",
1519          "    ",
1520          "    // dropList is a list of xtypes that this node could be dropped on.",
1521          "    // it is set up when we start to drag..",
1522          "    ",
1523          "    ",
1524          "    targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);",
1525          "        ",
1526          "    print(\"targetDAta: \" + targetData +\"\\n\");",
1527          "    ",
1528          "    if (targetData.length < 1) {",
1529          "        //print(\"Can not find drop node path\");",
1530          "       ",
1531          "        Gdk.drag_status(ctx, 0, time);",
1532          "        this.highlightDropPath(\"\", (Gtk.TreeViewDropPosition)0);",
1533          "        return false;",
1534          "    }",
1535          "    ",
1536          "    var td_ar = targetData.split(\"|\");",
1537          "      ",
1538          "    ",
1539          "",
1540          "    Gdk.drag_status(ctx, action ,time);",
1541          "    this.highlightDropPath(td_ar[0], (Gtk.TreeViewDropPosition)int.parse(td_ar[1]));",
1542          "    return true;",
1543          "       ",
1544          "       ",
1545          "}"
1546         ],
1547         "key_press_event" : [
1548          "(ev) => {",
1549          "   this.key_is_pressed = true;",
1550          "    return false;",
1551          "}"
1552         ],
1553         "key_release_event" : [
1554          "(ev) => {",
1555          "       this.key_is_pressed = false;",
1556          "      return false;",
1557          "}",
1558          ""
1559         ]
1560        },
1561        "tooltip_column" : 1,
1562        "xtype" : "TreeView",
1563        "| void highlightDropPath" : [
1564         " ( string treepath, Gtk.TreeViewDropPosition pos) {",
1565         "",
1566         "        // highlighting for drag/drop",
1567         "        if (treepath.length > 0) {",
1568         "            this.el.set_drag_dest_row(  new  Gtk.TreePath.from_string( treepath ), pos);",
1569         "          } else {",
1570         "            this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);",
1571         "         }",
1572         "             ",
1573         "}"
1574        ],
1575        "| void selectNode" : [
1576         "(string treepath_str, string source) {",
1577         "\tthis.lastEventSource = source;",
1578         "    //this.selection.select_path(new  Gtk.TreePath.from_string( treepath_str));",
1579         "     var tp = new Gtk.TreePath.from_string(treepath_str);",
1580         "     ",
1581         "     this.el.set_cursor(tp, null, false);  ",
1582         "     this.el.scroll_to_cell(tp, null, false, 0,0);",
1583         "}",
1584         ""
1585        ],
1586        "| void setCursor" : [
1587         "(string treepath, string sourceEvent)   {",
1588         "\tthis.lastEventSource = sourceEvent;",
1589         "\t//this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected..",
1590         "    this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); ",
1591         "    // fire node_selected..",
1592         "    //this.blockChanges = false;",
1593         "\tthis.lastEventSource = \"\";",
1594         "}",
1595         ""
1596        ]
1597       },
1598       {
1599        "$ xns" : "Gtk",
1600        "* pack" : false,
1601        "id" : "LeftTreeMenu",
1602        "items" : [
1603         {
1604          "$ xns" : "Gtk",
1605          "* pack" : "add",
1606          "label" : "Delete Element",
1607          "listeners" : {
1608           "activate" : [
1609            "  ( ) => {",
1610            "    ",
1611            "    print(\"ACTIVATE?\");",
1612            "    ",
1613            "  ",
1614            "     _this.model.deleteSelected();",
1615            "}"
1616           ]
1617          },
1618          "xtype" : "MenuItem"
1619         },
1620         {
1621          "$ xns" : "Gtk",
1622          "* pack" : "add",
1623          "label" : "Save as Template",
1624          "listeners" : {
1625           "activate" : [
1626            "  () => {",
1627            "",
1628            "     DialogSaveTemplate.singleton().show(",
1629            "            (Gtk.Window) _this.el.get_toplevel (), ",
1630            "            _this.main_window.windowstate.file.palete(), ",
1631            "            _this.getActiveElement()",
1632            "    );",
1633            "     ",
1634            "    ",
1635            "}"
1636           ]
1637          },
1638          "xtype" : "MenuItem"
1639         },
1640         {
1641          "$ xns" : "Gtk",
1642          "* pack" : "add",
1643          "label" : "Save as Module",
1644          "listeners" : {
1645           "activate" : [
1646            "  () => {",
1647            "    var node = _this.getActiveElement();",
1648            "     var name = DialogSaveModule.singleton().show(",
1649            "            (Gtk.Window) _this.el.get_toplevel (), ",
1650            "            _this.main_window.windowstate.project, ",
1651            "            node",
1652            "     );",
1653            "     if (name.length < 1) {",
1654            "            return;",
1655            "  ",
1656            "     }",
1657            "     node.set_prop( new JsRender.NodeProp.special(\"xinclude\", name));",
1658            "     node.items.clear();",
1659            "",
1660            "",
1661            "    var s = _this.view.el.get_selection();",
1662            "    ",
1663            "    print(\"GET  SELECTED?\");",
1664            "    Gtk.TreeIter iter;",
1665            "    Gtk.TreeModel mod;",
1666            "",
1667            "    ",
1668            "    if (!s.get_selected(out mod, out iter)) {",
1669            "        return; // nothing seleted..",
1670            "    }",
1671            "    Gtk.TreeIter citer;",
1672            "    var n_cn = mod.iter_n_children(iter) -1;",
1673            "    for (var i = n_cn; i > -1; i--) {",
1674            "        mod.iter_nth_child(out citer, iter, i);",
1675            "        ",
1676            "",
1677            "        print(\"removing node from Tree\\n\");    ",
1678            "    ",
1679            "        _this.model.el.remove(ref citer);",
1680            "    }",
1681            "    _this.changed();",
1682            "    _this.node_selected(node, \"tree\");",
1683            "     ",
1684            "    ",
1685            "}"
1686           ]
1687          },
1688          "xtype" : "MenuItem"
1689         }
1690        ],
1691        "xtype" : "Menu"
1692       }
1693      ],
1694      "listeners" : {
1695       "size_allocate" : [
1696        "(allocation) => {",
1697        "",
1698        "\t ",
1699        "\t//GLib.debug(\"Got allocation width of scrolled view %d\", allocation.width );",
1700        "\t_this.maincol.el.set_max_width(allocation.width - 32);",
1701        "}",
1702        ""
1703       ]
1704      },
1705      "xtype" : "ScrolledWindow"
1706     }
1707    ],
1708    "xtype" : "Box",
1709    "| JsRender.JsRender getActiveFile" : [
1710     "() {",
1711     "    return this.main_window.windowstate.file;",
1712     "}",
1713     ""
1714    ],
1715    "| JsRender.Node? getActiveElement" : [
1716     " () { // return path to actie node.",
1717     "",
1718     "     var path = this.getActivePath();",
1719     "     if (path.length < 1) {",
1720     "        return null;",
1721     "     }",
1722     "     return _this.model.pathToNode(path);",
1723     "     ",
1724     "}",
1725     ""
1726    ],
1727    "| string getActivePath" : [
1728     " () {",
1729     "    ",
1730     "    var view = this.view.el;",
1731     "    if (view.get_selection().count_selected_rows() < 1) {",
1732     "        return \"\";",
1733     "    }",
1734     "    Gtk.TreeIter iter;",
1735     "    Gtk.TreeModel mod;",
1736     "    view.get_selection().get_selected(out mod, out iter);",
1737     "    return mod.get_path(iter).to_string();",
1738     "}",
1739     " "
1740    ]
1741   }
1742  ],
1743  "modOrder" : "",
1744  "name" : "WindowLeftTree",
1745  "parent" : "",
1746  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/WindowLeftTree.bjs",
1747  "permname" : "",
1748  "title" : ""
1749 }