Merge branch 'master' of http://git.roojs.com/roobuilder
[roobuilder] / src / Builder4 / PopoverFiles.bjs
1 {
2  "build_module" : "",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "# Gdk.Pixbuf missing_thumb_pixbuf" : "",
7    "# Gee.HashMap<string,Gdk.Pixbuf> image_cache" : "null",
8    "# Project.Project selectedProject" : "",
9    "# Xcls_MainWindow win" : "",
10    "# bool is_loaded" : false,
11    "# bool is_loading" : false,
12    "# bool new_window" : false,
13    "$ xns" : "Gtk",
14    "Gtk.PositionType position" : "Gtk.PositionType.TOP",
15    "bool active" : false,
16    "bool hexpand" : false,
17    "bool in_onprojectselected" : false,
18    "bool modal" : true,
19    "id" : "PopoverFiles",
20    "int height_request" : 800,
21    "int width_request" : 900,
22    "items" : [
23     {
24      "$ xns" : "Gtk",
25      "* pack" : "set_child",
26      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
27      "bool hexpand" : true,
28      "bool vexpand" : true,
29      "items" : [
30       {
31        "$ xns" : "Gtk",
32        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
33        "bool hexpand" : true,
34        "items" : [
35         {
36          "$ Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
37          "$ xns" : "Gtk",
38          "items" : [
39           {
40            "$ xns" : "Gtk",
41            "items" : [
42             {
43              "$ Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
44              "$ xns" : "Gtk",
45              "* prop" : "child",
46              "items" : [
47               {
48                "$ Gtk.IconSize icon_size" : "Gtk.IconSize.NORMAL",
49                "$ xns" : "Gtk",
50                "int margin_end" : 4,
51                "string icon_name" : "folder-new",
52                "xtype" : "Image"
53               },
54               {
55                "$ xns" : "Gtk",
56                "string label" : "New Project",
57                "xtype" : "Label"
58               }
59              ],
60              "xtype" : "Box"
61             }
62            ],
63            "listeners" : {
64             "clicked" : [
65              "  ( ) => {",
66              "  ",
67              "    // create a new file in project..",
68              "    //Xcls_DialogNewComponent.singleton().show(",
69              "   var  pe =      EditProject.singleton();",
70              "   pe.el.application = _this.win.el.application;",
71              "    pe.el.set_transient_for( _this.win.el );",
72              " ",
73              "   _this.el.hide();",
74              "   ",
75              "    pe.selected.connect((pr) => {",
76              "     \t",
77              "\t     _this.is_loaded = false;",
78              "\t     _this.show(null, pr, _this.new_window);",
79              "",
80              "    });",
81              "    ",
82              "    pe.canceled.connect((pr) => {",
83              "     \t",
84              " ",
85              "\t     _this.show(null, null, _this.new_window);",
86              "",
87              "    });",
88              "    ",
89              "    pe.showIt();",
90              "   ",
91              "",
92              "}"
93             ]
94            },
95            "string label" : "New Project",
96            "xtype" : "Button"
97           },
98           {
99            "$ xns" : "Gtk",
100            "listeners" : {
101             "clicked" : [
102              "  ( ) => {",
103              "  // should disable the button really.",
104              "   if (_this.selectedProject == null) {",
105              "\t   return;",
106              "   }",
107              "\t_this.win.windowstate.projectPopoverShow(this.el, _this.selectedProject);",
108              " }"
109             ]
110            },
111            "string icon_name" : "emblem-system",
112            "string label" : "Project Properties",
113            "xtype" : "Button"
114           },
115           {
116            "$ xns" : "Gtk",
117            "listeners" : {
118             "clicked" : [
119              "  ( ) => {",
120              "  /*",
121              "   var cd = DialogConfirm.singleton();",
122              "     cd.el.set_transient_for(_this.el);",
123              "    cd.el.set_modal(true);",
124              "",
125              "     var project =   _this.windowstate.left_projects.getSelectedProject();",
126              "    if (project == null) {",
127              "        print(\"SKIP - no project\\n\");",
128              "        return;",
129              "    }",
130              "    ",
131              "        ",
132              "     if (Gtk.ResponseType.YES != cd.show(\"Confirm\", ",
133              "        \"Are you sure you want to delete project %s\".printf(project.name))) {",
134              "        return;",
135              "    }",
136              "     ",
137              "",
138              "    // confirm?",
139              "    Project.Project.remove(project);",
140              "    _this.project = null;",
141              "    ",
142              "    _this.windowstate.left_projects.is_loaded =  false;",
143              "    _this.windowstate.left_projects.load();",
144              "    _this.windowstate.clutterfiles.clearFiles();",
145              "*/",
146              "",
147              "}"
148             ]
149            },
150            "string icon_name" : "user-trash",
151            "string label" : "Delete Project",
152            "xtype" : "Button"
153           },
154           {
155            "$ xns" : "Gtk",
156            "listeners" : {
157             "clicked" : [
158              " () => {",
159              "    // create a new file in project..",
160              "    print(\"add file selected\\n\");",
161              "    ",
162              "    if (_this.selectedProject == null) {",
163              "    \treturn;",
164              "    }",
165              "    try {",
166              "    \tvar f = JsRender.JsRender.factory(_this.selectedProject.xtype,  _this.selectedProject, \"\");",
167              "     \t_this.win.windowstate.file_details.show( f, this.el, _this.new_window );",
168              "     } catch (JsRender.Error e) {}",
169              "",
170              "}"
171             ]
172            },
173            "string icon_name" : "document-new",
174            "string label" : "New File",
175            "xtype" : "Button"
176           }
177          ],
178          "xtype" : "Box"
179         }
180        ],
181        "xtype" : "Box"
182       },
183       {
184        "$ xns" : "Gtk",
185        "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
186        "bool hexpand" : true,
187        "bool homogeneous" : false,
188        "bool vexpand" : true,
189        "items" : [
190         {
191          "$ xns" : "Gtk",
192          "* init" : [
193           "  this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
194           " "
195          ],
196          "bool expand" : true,
197          "bool has_frame" : true,
198          "bool hexpand" : true,
199          "bool vexpand" : true,
200          "int width_request" : 150,
201          "items" : [
202           {
203            "$ enable_tree_lines" : true,
204            "$ headers_visible" : true,
205            "$ xns" : "Gtk",
206            "* init" : [
207             "   ",
208             "        ",
209             "this.css = new Gtk.CssProvider();",
210             "try {",
211             "\tthis.css.load_from_data(\"#popover-files-view { font-size: 10px;}\".data);",
212             "} catch (Error e) {}",
213             "this.el.get_style_context().add_provider(this.css,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);",
214             "        ",
215             "        ",
216             "        ",
217             "        ",
218             "var selection = this.el.get_selection();",
219             "selection.set_mode( Gtk.SelectionMode.SINGLE);",
220             "",
221             "",
222             "    ",
223             "   ",
224             " "
225            ],
226            "* pack" : "set_child",
227            "Gtk.CssProvider css" : "",
228            "bool hexpand" : true,
229            "bool vexpand" : true,
230            "id" : "view",
231            "items" : [
232             {
233              "$ columns" : "typeof(string), typeof(Object)",
234              "$ xns" : "Gtk",
235              "* init" : [
236               "{",
237               "   this.el.set_sort_func(0, (mod,a,b) => {",
238               "       GLib.Value ga, gb;",
239               "       mod.get_value(a,0, out ga);",
240               "       mod.get_value(b,0, out gb);",
241               "        ",
242               "        if ((string)ga == (string)gb) {",
243               "            return 0;",
244               "        }",
245               "        return (string)ga > (string)gb ? 1 : -1;",
246               "   }); ",
247               "",
248               "",
249               "}",
250               ""
251              ],
252              "* pack" : "set_model",
253              "id" : "model",
254              "n_columns" : 2,
255              "xtype" : "ListStore"
256             },
257             {
258              "$ xns" : "Gtk",
259              "* init" : [
260               "",
261               "    this.el.add_attribute(_this.namecol.el , \"markup\", 0  );",
262               " "
263              ],
264              "* pack" : "append_column",
265              "items" : [
266               {
267                "$ xns" : "Gtk",
268                "* pack" : "pack_start,true",
269                "id" : "namecol",
270                "xtype" : "CellRendererText"
271               }
272              ],
273              "utf8 title" : "Projects",
274              "xtype" : "TreeViewColumn"
275             }
276            ],
277            "listeners" : {
278             "cursor_changed" : [
279              " () => {",
280              "    if (_this.is_loading) {",
281              "        return;",
282              "    }",
283              "    ",
284              "    Gtk.TreeIter iter;",
285              "    Gtk.TreeModel mod;",
286              "            ",
287              "    var s = this.el.get_selection();",
288              "    if (!s.get_selected(out mod, out iter)) {",
289              "        return;",
290              "    }",
291              "    ",
292              "    GLib.Value gval;",
293              "",
294              "    mod.get_value(iter, 1 , out gval);",
295              "    var project = (Project.Project)gval.get_object();",
296              "    ",
297              "    _this.onProjectSelected(project);",
298              "    ",
299              "}  "
300             ]
301            },
302            "string name" : "popover-files-view",
303            "xtype" : "TreeView"
304           }
305          ],
306          "xtype" : "ScrolledWindow"
307         },
308         {
309          "$ xns" : "Gtk",
310          "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
311          "bool hexpand" : true,
312          "bool vexpand" : true,
313          "int spacing" : 0,
314          "int width_request" : 600,
315          "items" : [
316           {
317            "$ xns" : "Gtk",
318            "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
319            "bool hexpand" : true,
320            "int spacing" : 0,
321            "items" : [
322             {
323              "$ xns" : "Gtk",
324              "* init" : [
325               " ",
326               "",
327               "this.css = new Gtk.CssProvider();",
328               "try {",
329               "\tthis.css.load_from_data(\"#popover-files-iconsearch { font:  10px monospace;}\".data);",
330               "} catch (Error e) {}",
331               "this.el.get_style_context().add_provider(this.css,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);",
332               "        ",
333               "        ",
334               ""
335              ],
336              "Gtk.CssProvider css" : "",
337              "bool hexpand" : true,
338              "id" : "iconsearch",
339              "listeners" : {
340               "changed" : [
341                "( ) => {",
342                "\tGLib.debug(\"Got '%s'\", this.el.text);",
343                "\t",
344                "\tif (this.el.text.down() != _this.lastfilter) {",
345                "\t\t_this.loadIconView();",
346                "\t\t_this.loadTreeView();",
347                "\t}",
348                "}",
349                ""
350               ]
351              },
352              "string name" : "popover-files-iconsearch",
353              "string placeholder_text" : "type to filter results",
354              "xtype" : "SearchEntry"
355             }
356            ],
357            "xtype" : "Box"
358           },
359           {
360            "$ xns" : "Gtk",
361            "* init" : [
362             "  this.el.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);",
363             "  "
364            ],
365            "bool has_frame" : true,
366            "bool hexpand" : true,
367            "bool vexpand" : true,
368            "id" : "iconscroll",
369            "int width_request" : 600,
370            "items" : [
371             {
372              "$ xns" : "Gtk",
373              "* init" : [
374               "{",
375               " ",
376               "}",
377               ""
378              ],
379              "* pack" : "set_child",
380              "bool has_tooltip" : true,
381              "bool hexpand" : true,
382              "bool vexpand" : true,
383              "id" : "iconview",
384              "int item_width" : 100,
385              "int markup_column" : 1,
386              "int pixbuf_column" : 3,
387              "items" : [
388               {
389                "$ columns" : "typeof(Object), typeof(string), typeof(string), typeof(Gdk.Pixbuf), typeof(Gdk.Pixbuf) ",
390                "$ xns" : "Gtk",
391                "* prop" : "model",
392                "id" : "iconmodel",
393                "int n_columns" : 4,
394                "xtype" : "ListStore"
395               }
396              ],
397              "listeners" : {
398               "item_activated" : [
399                "(path) => {",
400                "    ",
401                "    _this.win.windowstate.project = _this.selectedProject;",
402                "    _this.el.hide();",
403                "    ",
404                "    ",
405                " \tGtk.TreeIter iter;",
406                "   ",
407                "            ",
408                "\tthis.el.model.get_iter(out iter, path);",
409                "    ",
410                "    GLib.Value gval;",
411                "",
412                "    this.el.model.get_value(iter, 0 , out gval);",
413                "    var file = (JsRender.JsRender)gval;",
414                "    ",
415                "    ",
416                "    _this.win.windowstate.fileViewOpen(file, _this.new_window);",
417                "",
418                "    ",
419                "    ",
420                "}"
421               ],
422               "query_tooltip" : [
423                "(x, y, keyboard_tooltip, tooltip) => {",
424                "",
425                "\tGtk.TreePath path;",
426                "\tGtk.CellRenderer cell;",
427                "\t_this.iconview.el.get_item_at_pos(x,y + (int) _this.iconscroll.el.vadjustment.value, out path, out cell);",
428                "\t",
429                "\t",
430                "   // GLib.debug(\"Tooltip? %d,%d scroll: %d\",x,y, (int)_this.iconscroll.el.vadjustment.value);",
431                "\t ",
432                "\t",
433                "\tif (path == null) {",
434                "\t\t// GLib.debug(\"Tooltip? - no path\");",
435                "\t\treturn false;",
436                "\t}",
437                "\t",
438                "\tGtk.TreeIter iter;",
439                "\t_this.iconmodel.el.get_iter(out iter, path);",
440                "\tGLib.Value val;",
441                "\t_this.iconmodel.el.get_value(iter, 4, out val);",
442                "\t",
443                "\ttooltip.set_icon(  Gdk.Texture.for_pixbuf(",
444                "\t\t(Gdk.Pixbuf) val.get_object()",
445                "\t));",
446                "\t _this.iconview.el.set_tooltip_item(tooltip, path);",
447                "\treturn true;",
448                "}",
449                ""
450               ]
451              },
452              "xtype" : "IconView"
453             }
454            ],
455            "xtype" : "ScrolledWindow"
456           }
457          ],
458          "xtype" : "Box"
459         },
460         {
461          "$ xns" : "Gtk",
462          "* init" : "  this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
463          "bool has_frame" : true,
464          "bool hexpand" : true,
465          "bool vexpand" : true,
466          "bool visible" : false,
467          "id" : "file_container",
468          "int width_request" : 200,
469          "items" : [
470           {
471            "$ enable_tree_lines" : true,
472            "$ headers_visible" : true,
473            "$ xns" : "Gtk",
474            "* init" : [
475             "",
476             "this.css = new Gtk.CssProvider();",
477             "try {",
478             "\tthis.css.load_from_data(\"#popover-files-fileview { font-size: 12px;}\".data);",
479             "} catch (Error e) {}",
480             "this.el.get_style_context().add_provider(this.css,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);",
481             "        ",
482             "        ",
483             "        ",
484             " ",
485             "                ",
486             "var selection = this.el.get_selection();",
487             "selection.set_mode( Gtk.SelectionMode.SINGLE);",
488             "",
489             "",
490             "",
491             "",
492             ""
493            ],
494            "* pack" : "set_child",
495            "Gtk.CssProvider css" : "",
496            "bool activate_on_single_click" : false,
497            "bool hexpand" : true,
498            "bool vexpand" : true,
499            "id" : "fileview",
500            "items" : [
501             {
502              "$ columns" : "typeof(string), typeof(string)",
503              "$ xns" : "Gtk",
504              "* init" : [
505               "{",
506               "   this.el.set_sort_func(0, (mod,a,b) => {",
507               "       GLib.Value ga, gb;",
508               "       mod.get_value(a,0, out ga);",
509               "       mod.get_value(b,0, out gb);",
510               "        ",
511               "        if ((string)ga == (string)gb) {",
512               "            return 0;",
513               "        }",
514               "        return (string)ga > (string)gb ? 1 : -1;",
515               "   }); ",
516               " ",
517               "",
518               "}",
519               ""
520              ],
521              "* pack" : "set_model",
522              "id" : "filemodel",
523              "n_columns" : 2,
524              "xtype" : "TreeStore"
525             },
526             {
527              "$ xns" : "Gtk",
528              "* init" : [
529               "",
530               "    this.el.add_attribute(_this.filenamecol.el , \"markup\", 0  );",
531               " "
532              ],
533              "* pack" : "append_column",
534              "items" : [
535               {
536                "$ xns" : "Gtk",
537                "* pack" : "pack_start,true",
538                "id" : "filenamecol",
539                "xtype" : "CellRendererText"
540               }
541              ],
542              "utf8 title" : "File",
543              "xtype" : "TreeViewColumn"
544             }
545            ],
546            "listeners" : {
547             "cursor_changed" : [
548              " () => {",
549              " /*",
550              "    if (_this.is_loading) {",
551              "        return;",
552              "    }",
553              "    ",
554              "    Gtk.TreeIter iter;",
555              "    Gtk.TreeModel mod;",
556              "            ",
557              "    var s = this.el.get_selection();",
558              "    if (!s.get_selected(out mod, out iter)) {",
559              "        return;",
560              "    }",
561              "    ",
562              "    GLib.Value gval;",
563              "",
564              "    mod.get_value(iter, 1 , out gval);",
565              "    var project = (Project.Project)gval.get_object();",
566              "    ",
567              "    _this.project_selected(project);",
568              "    */",
569              "}  "
570             ],
571             "row_activated" : [
572              "(path, col) => {",
573              "",
574              "\tGtk.TreeIter iter;",
575              "   ",
576              "            ",
577              "\tthis.el.model.get_iter(out iter, path);",
578              "    ",
579              "    GLib.Value gval;",
580              "",
581              "    this.el.model.get_value(iter, 1 , out gval);",
582              "   var fn = (string)gval;",
583              "    if (fn.length < 1) {",
584              "    \treturn;",
585              "\t}",
586              "    _this.win.windowstate.project = _this.selectedProject;",
587              "     _this.el.hide();",
588              "    try {",
589              "\t\tvar f = JsRender.JsRender.factory(\"PlainFile\", _this.selectedProject, fn);",
590              "\t\t_this.win.windowstate.fileViewOpen(f, _this.new_window);",
591              "\t} catch (JsRender.Error e) {}   ",
592              "    ",
593              "}"
594             ]
595            },
596            "string name" : "popover-files-fileview",
597            "xtype" : "TreeView"
598           }
599          ],
600          "xtype" : "ScrolledWindow"
601         }
602        ],
603        "xtype" : "Box"
604       }
605      ],
606      "xtype" : "Box"
607     }
608    ],
609    "listeners" : {
610     "hide" : [
611      "( ) => {",
612      "\t// save...",
613      "\t//this.load();",
614      "\t//if (project != null) {",
615      "//\t\tthis.selectProject(project);",
616      "//\t}",
617      " \t//if (_this.win.windowstate.project == null) {",
618      " \t//\tthis.el.show();",
619      "\t//}",
620      "}"
621     ]
622    },
623    "string lastfilter" : "\"\"",
624    "string title" : "Select Project /File",
625    "xtype" : "Window",
626    "| void load" : [
627     "() {",
628     "     // clear list...",
629     "    ",
630     "     if (_this.is_loaded) {",
631     "         return;",
632     "     }",
633     "     _this.is_loading = true;",
634     "        ",
635     "     _this.is_loaded = true;",
636     "     ",
637     "     Project.Project.loadAll();",
638     "     var projects = Project.Project.allProjectsByName();",
639     "     ",
640     "     Gtk.TreeIter iter;",
641     "     var m = this.model.el;",
642     "     m.clear();",
643     "          ",
644     "     for (var i = 0; i < projects.size; i++) {",
645     "        m.append(out iter);",
646     "        m.set(iter,   0,projects.get(i).name );",
647     "        ",
648     "        var o =  GLib.Value(typeof(Object));",
649     "        o.set_object((Object)projects.get(i));",
650     "                   ",
651     "        m.set_value(iter, 1, o);",
652     "     ",
653     "     }",
654     "     m.set_sort_column_id(0, Gtk.SortType.ASCENDING);",
655     "     _this.is_loading = false;      ",
656     "}",
657     ""
658    ],
659    "| void loadIconView" : [
660     "() {",
661     "\t",
662     "\tif (_this.image_cache == null) {",
663     "\t\t_this.image_cache = new Gee.HashMap<string,Gdk.Pixbuf>();",
664     "\t}",
665     "\t",
666     "\t var project =  this.selectedProject;",
667     " ",
668     " \t Gdk.Pixbuf pixbuf = null;",
669     "  \t Gdk.Pixbuf bigpixbuf = null;",
670     "\t Gtk.TreeIter iter;",
671     "     var m = this.iconmodel.el;",
672     "     m.clear();",
673     " ",
674     " ",
675     " \tvar filter = _this.iconsearch.el.text.down();",
676     " \tthis.lastfilter = filter;",
677     " ",
678     "    var fiter = project.sortedFiles().list_iterator();",
679     "    ",
680     "    ",
681     "      try {",
682     "        if (_this.missing_thumb_pixbuf == null) {",
683     "        ",
684     "        \tvar icon_theme = Gtk.IconTheme.get_for_display(this.el.get_display());",
685     "        \t var icon = icon_theme.lookup_icon (\"package-x-generic\", null,  92,1, ",
686     "\t\t\t\t\t Gtk.TextDirection.NONE, 0);",
687     "\t\t \t_this.missing_thumb_pixbuf = (new Gdk.Pixbuf.from_file (icon.file.get_path())).scale_simple(",
688     "\t\t \t\t92, 92 \t, Gdk.InterpType.NEAREST) ;",
689     "            _this.missing_thumb_pixbuf.ref();",
690     "        }",
691     "\t        ",
692     "",
693     "\t    } catch (Error e) {",
694     "\t        // noop?",
695     "\t    }",
696     "    ",
697     "",
698     "    ",
699     "    while (fiter.next()) {",
700     "    ",
701     "        var file = fiter.get();",
702     "        if (filter != \"\") {",
703     "        \tif (!file.name.down().contains(filter)) {",
704     "        \t\tcontinue;",
705     "    \t\t}",
706     "        ",
707     "        }    ",
708     "    \t",
709     "    ",
710     "    ",
711     "        m.append(out iter);",
712     "",
713     "        m.set(iter,   0,file ); // zero contains the file reference",
714     "        m.set(iter,   1,file.nickType() + \"\\n\" + file.nickName()); // marked up title?",
715     "        m.set(iter,   2,file.nickType() ); // file type?",
716     "        ",
717     "       ",
718     " ",
719     "\t    ",
720     "\t    pixbuf = file.getIcon(92);",
721     "\t\tbigpixbuf = file.getIcon(368);",
722     "",
723     "\t\t ",
724     "         ",
725     "        if (pixbuf == null) {",
726     "        \tGLib.debug(\"PIXBUF is null? %s\", file.name);",
727     "\t\t    pixbuf = _this.missing_thumb_pixbuf;",
728     "        \tbigpixbuf = _this.missing_thumb_pixbuf;",
729     "\t\t}",
730     "\t\t",
731     "\t\t",
732     "\t\t",
733     "        m.set(iter,   3,pixbuf);",
734     "        m.set(iter,   4,bigpixbuf);",
735     "      ",
736     "        // this needs to add to the iconview?",
737     "        ",
738     "        //var a = new Xcls_fileitem(this,fiter.get());",
739     "        //this.fileitems.add(a);",
740     "",
741     "        //this.filelayout.el.add_child(a.el);",
742     "    }",
743     "}"
744    ],
745    "| void loadTreeView" : [
746     "() {",
747     "  var project =  this.selectedProject;",
748     "  ",
749     "  this.filemodel.el.clear();",
750     "    ",
751     "    // folders...",
752     "    ",
753     "    if (!(project is Project.Gtk)) {",
754     "        //print (\"not gtk... skipping files\");",
755     "        this.file_container.el.hide();",
756     "        return;",
757     "    }",
758     "    ",
759     "    ",
760     "    ",
761     "    var filter = _this.iconsearch.el.text.down();",
762     "    ",
763     "    this.file_container.el.show();",
764     "    var gpr = (Project.Gtk)project;",
765     "     var def = gpr.compilegroups.get(\"_default_\");",
766     "     // not sure why the above is returng null!??",
767     "     if (def == null) {",
768     " \t\tdef = new Project.GtkValaSettings(\"_default_\"); ",
769     " \t\tgpr.compilegroups.set(\"_default_\", def);",
770     "     }",
771     "\t var items  = def.sources;",
772     "\t\t ",
773     "\t Gtk.TreeIter citer;  // folder iter",
774     "\t  Gtk.TreeIter fxiter;  // file iter",
775     "\tfor(var i =0 ; i < items.size; i++) {",
776     "\t    // print (\"cheking folder %s\\n\", items.get(i));",
777     "\t     var files = gpr.filesForOpen(items.get(i));",
778     "\t     ",
779     "\t     ",
780     "\t     ",
781     "\t     ",
782     "\t     ",
783     "\t     if (files.size < 1) {",
784     "\t        continue;",
785     "\t     }",
786     "\t     var nf = 0;",
787     "\t     for(var j =0 ; j < files.size; j++) {",
788     "\t    ",
789     "\t    \tif (filter != \"\") {",
790     "\t    \t\tvar ff = GLib.Path.get_basename(files.get(j)).down();",
791     "\t    \t\tvar dp = ff.last_index_of(\".\");",
792     "\t\t    \tif (!ff.substring(0,dp  < 0 ? ff.length :dp ).contains(filter)) {",
793     "\t\t    \t\tcontinue;",
794     "\t\t\t\t}",
795     "\t\t    ",
796     "\t\t    }  ",
797     "\t\t    nf++;",
798     "\t    }",
799     "\t    if (nf < 1) {",
800     "\t    \tcontinue;",
801     "    \t} ",
802     "\t     ",
803     "\t\t this.filemodel.el.append(out citer,null);",
804     "\t\t this.filemodel.el.set(citer, 0, GLib.Path.get_basename(items.get(i)));",
805     "\t\t this.filemodel.el.set(citer, 1, null); // parent (empty as it's a folder)",
806     "\t\t",
807     "\t\t",
808     "\t    // add the directory... items.get(i);",
809     "\t    //var x = new Xcls_folderitem(this,items.get(i));",
810     "\t    //this.fileitems.add(x);",
811     "\t    //this.filelayout.el.add_child(x.el);",
812     "\t    ",
813     "\t    ",
814     "\t    for(var j =0 ; j < files.size; j++) {",
815     "\t    ",
816     "\t    \tif (filter != \"\") {",
817     "\t    \t\tvar ff = GLib.Path.get_basename(files.get(j)).down();",
818     "\t    \t\tvar dp = ff.last_index_of(\".\");",
819     "\t\t    \tif (!ff.substring(0,dp  < 0 ? ff.length :dp ).contains(filter)) {",
820     "\t\t    \t\tcontinue;",
821     "\t\t\t\t}",
822     "\t\t    ",
823     "\t\t    }  ",
824     "\t    ",
825     "\t\t    this.filemodel.el.insert(out fxiter,citer, -1);",
826     "\t     \tthis.filemodel.el.set(fxiter, 0,  GLib.Path.get_basename(files.get(j))); // filename",
827     "\t\t \tthis.filemodel.el.set(fxiter, 1, files.get(j)); // Folder?",
828     "\t         ",
829     "\t        ",
830     "\t    }",
831     "\t    ",
832     "\t    ",
833     "\t    //this.el.set_value(citer, 1,   items.get(i) );",
834     "\t}",
835     "    _this.fileview.el.expand_all();",
836     "}"
837    ],
838    "| void onProjectSelected" : [
839     "(Project.Project project) ",
840     "{",
841     "\tif (this.in_onprojectselected) { ",
842     "\t\treturn;",
843     "\t}",
844     "\tthis.in_onprojectselected = true;",
845     "\t",
846     "\t",
847     "\tthis.selectedProject = project;",
848     "\tproject.scanDirs();",
849     "\t//this.clutterfiles.loadProject(proj);",
850     "\t",
851     "\t",
852     "\t",
853     "\t_this.iconsearch.el.text = \"\";",
854     "\t",
855     "\t ",
856     "\t",
857     "    ",
858     "    ",
859     "    //this.project_title_name.el.text = pr.name;",
860     "    //this.project_title_path.el.text = pr.firstPath();",
861     "    ",
862     "    // file items contains a reference until we reload ...",
863     "  \t this.loadIconView();",
864     "  \t ",
865     "  \t ",
866     "  \t GLib.Timeout.add(500, () => {",
867     "\t     _this.iconsearch.el.grab_focus();",
868     "\t     return false;",
869     "     });",
870     "    ",
871     "    ",
872     "",
873     "\tthis.loadTreeView();",
874     "\tthis.in_onprojectselected = false;\t",
875     "}",
876     ""
877    ],
878    "| void selectProject" : [
879     "(Project.Project project) {",
880     "    ",
881     "    var sel = _this.view.el.get_selection();",
882     "    ",
883     "    sel.unselect_all();",
884     "    ",
885     "    var found = false;",
886     "    _this.model.el.foreach((mod, path, iter) => {",
887     "        GLib.Value val;",
888     "    ",
889     "        mod.get_value(iter, 1, out val);",
890     "        if ( ( (Project.Project)val.get_object()).fn != project.fn) {",
891     "            print(\"SKIP %s != %s\\n\", ((Project.Project)val.get_object()).name , project.name);",
892     "            return false;//continue",
893     "        }",
894     "        sel.select_iter(iter);",
895     "\t\tthis.selectedProject = project;",
896     "        this.onProjectSelected(project);",
897     "        found = true;",
898     "        return true;",
899     "        ",
900     "    ",
901     "    });",
902     "     if (!found) {",
903     "\t    print(\"tried to select %s, could not find it\", project.name);",
904     "    }",
905     "}",
906     ""
907    ],
908    "| void setMainWindow" : [
909     "(Xcls_MainWindow win) {",
910     "\tthis.win = win;",
911     "\tthis.el.set_transient_for(win.el);",
912     "\tthis.el.application = BuilderApplication.singleton({});",
913     "}",
914     ""
915    ],
916    "| void show" : [
917     "(Gtk.Widget? on_el, Project.Project? project, bool new_window) {",
918     "\t//this.editor.show( file, node, ptype, key);",
919     "\t",
920     "\tthis.new_window = new_window;",
921     "\t\t// save...",
922     "\tthis.load();",
923     "\tif (on_el != null) {",
924     "\t\tthis.el.set_parent(on_el);",
925     "\t}",
926     "\t // show first - so we can hide stuff later.\t",
927     "\tif (project != null) {",
928     "\t",
929     "\t\tthis.selectProject(project);",
930     "\t}",
931     "\t",
932     "\t",
933     "  //   var win = this.win.el;",
934     "  //  var  w = win.get_width();",
935     "  //  var h = win.get_height();",
936     "",
937     "    // left tree = 250, editor area = 500?",
938     "    ",
939     "    // min 450?",
940     "\t// max hieght ...",
941     "\t",
942     "\t//var  ww =  on_el.get_allocated_width();",
943     "\t",
944     "\t// width = should be max = w-ww , or 600 at best..?",
945     "\t ",
946     "    //this.el.set_size_request( w - 100, h - 100); // same as parent...",
947     "",
948     "",
949     "\t//this.el.set_autohide(true); // can hide",
950     "\t//Gtk.Allocation rect;",
951     "\t//on_el.get_allocation(out rect);",
952     "   // this.el.set_pointing_to(rect);",
953     "    //this.el.set_offset(200,0);",
954     "    //this.el.set_position(Gtk.PositionType.BOTTOM);",
955     "\tthis.el.show();",
956     "\t  ",
957     "}",
958     ""
959    ]
960   }
961  ],
962  "name" : "PopoverFiles",
963  "namespace" : ""
964 }