3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
14 type : Gtk.WindowType.TOPLEVEL,
15 title : "Application Builder",
19 "STRING" : Gdk.atom_intern("STRING")
21 this.targetList = new Gtk.TargetList();
22 this.targetList.add( this.atoms["STRING"], 0, 0);
23 //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
25 "style \"gtkcombobox-style\" {\n" +
26 " GtkComboBox::appears-as-list = 1\n" +
28 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
29 XObject.prototype.init.call(this);
38 setTitle : function(str) {
39 this.el.set_title(this.title + ' - ' + str);
42 delete_event : function (self, event) {
45 destroy : function (self) {
48 show : function (self) {
49 print("WINDOW SHOWING - trying to hide");
50 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
51 this.get('/MidPropTree').hideWin();
52 this.get('/RightPalete').hide();
53 this.get('/BottomPane').el.hide();
64 pack : "pack_start,false,false",
78 label : "New _Project",
80 activate : function (self) {
82 this.get('/EditProject').show({
83 success : function(pr) {
84 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
95 activate : function (self) {
96 var fn = this.get('/LeftProjectTree.combo').getValue();
98 this.get('/LeftProjectTree').showNoProjectSelected();
101 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
102 this.get('/DialogNewComponent').show({
103 project : pm.getByFn(fn)
109 xtype: Gtk.SeparatorMenuItem,
114 use_underline : true,
116 label : "D_elete Project",
118 activate : function (self) {
120 var fn = this.get('/LeftProjectTree').get('combo').getValue();
122 this.get('/StandardErrorDialog').show("Select a project")
125 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
126 var pr = pm.getByFn(fn);
129 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
130 pm.deleteProject(fn);
138 xtype: Gtk.SeparatorMenuItem,
145 use_underline : true,
147 activate : function (self) {
159 use_underline : true,
164 pack : "set_submenu",
172 activate : function (self) {
173 var fn = this.get('/LeftTree').getActiveFile();
175 this.get('/StandardErrorDialog').show("No File active");
179 this.get('/DialogNewComponent').show(fn);
183 label : "File _Properties",
190 activate : function (self, event) {
191 this.get('/RooProjectProperties').show();
195 label : "Modify Project HTML ",
206 use_underline : true,
210 pack : "set_submenu",
218 activate : function (self, event) {
219 var js = this.get('/LeftTree.model').toJS();
221 this.get('/RightBrowser.view').renderJS(js[0]);
226 label : "_Redraw (Roo)",
233 activate : function (self, event)
235 /* Firefox testing for debugging..
236 - we can create a /tmp directory, and put.
237 builder.html, builder.html.js, link roojs1
238 add at the end of builder.html Roo.onload(function() {
240 if (!this.get('/Window.LeftTree').getActiveFile()) {
244 var js = this.get('/LeftTree.model').toJS();
248 var project = this.get('/Window.LeftTree').getActiveFile().project;
249 //print (project.fn);
251 project.runhtml = project.runhtml || '';
254 var File = imports.File.File;
256 var target = "/tmp/firetest"; // fixme..
257 if (!File.isDirectory(target)) {
260 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
261 if (!File.exists( target+ '/roojs1')) {
262 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
267 var html = imports.File.File.read(__script_path__ + '/../builder.html');
268 html = html.replace('</head>', project.runhtml + '</head>');
271 var jsstr = JSON.stringify(js[0]);
273 var runbuilder = '<script type="text/javascript">' + "\n" +
274 " Builder.render(" + jsstr + ");\n" +
277 html = html.replace('</body>', runbuilder + '</body>');
279 File.write( target+ '/builder.html', html);
281 this.get('/Terminal').feed("RUN DIR:" + target);
283 this.get('/Terminal').el.fork_command( null , [], [], target
284 , false,false,false);
285 var cmd = "firefox file://" + target + "/builder.html \n";
286 this.get('/Terminal').el.feed_child(cmd, cmd.length);
290 label : "_Test in Firefox (Roo)",
301 use_underline : true,
309 pack : "set_submenu",
318 use_underline : true,
320 activate : function (self) {
321 this.get('/About').el.run();
350 label : "Select Project",
352 pack : "pack_start,false,true",
354 XObject.prototype.init.call(this);
355 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
358 activate : function (self) {
359 var nb = this.get('/LeftTopPanel.notebook');
360 if (this.el.expanded) {
363 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
366 var model = this.get('/LeftProjectTree.combomodel');
367 // print ("loading Projects?")
368 //console.dump(pm.projects);
369 model.loadData(pm.projects);
372 nb.el.set_current_page(1);
373 //pm.on('changed', function() {
374 //console.log("CAUGHT project manager change");
375 // _combo.model.loadData(pm.projects);
379 nb.el.set_current_page(0);
381 enter_notify_event : function (self, event) {
382 this.el.expanded = !this.el.expanded;
383 //if (this.el.expanded ) {
384 this.listeners.activate.call(this);
396 pack : "pack_start,true,true",
398 XObject.prototype.init.call(this);
399 this.el.set_current_page(0);
404 xtype: Gtk.ScrolledWindow,
407 getActiveElement : function() { // return path to actie node.
409 var path = this.getActivePath();
413 var iter = new Gtk.TreeIter();
414 this.get('model').el.get_iter_from_string(iter, path);
416 var value = new GObject.Value('');
417 this.get('model').el.get_value(iter, 2, value);
419 return JSON.parse(value.value);
421 getActiveFile : function() {
422 return this.get('model').file;
424 getActivePath : function() {
425 var model = this.get('model');
426 var view = this.get('view');
427 if (view.selection.count_selected_rows() < 1) {
430 var iter = new Gtk.TreeIter();
432 view.selection.get_selected(model.el, iter);
433 return model.el.get_path(iter).to_string();
435 getPaleteProvider : function() {
436 var model = this.get('model');
437 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
438 return pm.getPalete(model.file.getType());
440 getRenderer : function() {
442 switch( this.getActiveFile().getType()) {
444 return this.get('/RightBrowser.view');
446 return this.get('/RightGtkView');
451 XObject.prototype.init.call(this);
452 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
454 renderView : function() {
455 var render = this.getRenderer();
456 var model = this.get('model');
458 render.renderJS(model.toJS(false,true)[0]);
460 print("NO RENDER JS METHOD?");
463 shadow_type : Gtk.ShadowType.IN,
469 headers_visible : false,
470 enable_tree_lines : true,
473 XObject.prototype.init.call(this);
474 var description = new Pango.FontDescription.c_new();
475 description.set_size(8000);
476 this.el.modify_font(description);
478 this.selection = this.el.get_selection();
479 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
482 // is this really needed??
483 this.selection.signal['changed'].connect(function() {
484 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
485 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
489 Gtk.drag_source_set (
490 this.el, /* widget will be drag-able */
491 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
492 null, /* lists of target to support */
493 0, /* size of list */
494 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
497 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
499 Gtk.drag_source_add_text_targets(this.el);
502 this.el, /* widget that will accept a drop */
503 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
504 null, /* lists of target to support */
505 0, /* size of list */
506 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
509 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
510 Gtk.drag_dest_add_text_targets(this.el);
512 highlight : function(treepath_ar) {
514 // highlighting for drag/drop
515 if (treepath_ar.length && treepath_ar[0].length ) {
516 this.el.set_drag_dest_row(
517 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
519 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
523 selectNode : function(treepath_str) {
524 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
525 var tp = new Gtk.TreePath.from_string(treepath_str);
526 this.el.set_cursor(tp, null, false);
527 this.el.scroll_to_cell(tp, null, false, 0,0);
530 button_press_event : function (self, ev) {
531 console.log("button press?");
532 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
533 print("click" + ev.type);
539 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
541 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
543 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
544 this.get('/LeftTreeMenu').el.show_all();
545 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
546 print("click:" + res.path.to_string());
549 drag_begin : function (self, drag_context) {
550 print('SOURCE: drag-begin');
551 this.targetData = false;
552 // find what is selected in our tree...
553 var iter = new Gtk.TreeIter();
554 var s = this.selection;
555 s.get_selected(this.get('/LeftTree.model').el, iter);
557 // set some properties of the tree for use by the dropped element.
558 var value = new GObject.Value('');
559 this.get('/LeftTree.model').el.get_value(iter, 2, value);
560 var data = JSON.parse(value.value);
561 var xname = this.get('/LeftTree.model').file.guessName(data);
563 this.el.dragData = xname;
564 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
567 // make the drag icon a picture of the node that was selected
568 var path = this.get('/LeftTree.model').el.get_path(iter);
569 this.el.treepath = path.to_string();
571 var pix = this.el.create_row_drag_icon ( path);
573 Gtk.drag_set_icon_pixmap (ctx,
582 drag_end : function (self, drag_context) {
583 Seed.print('LEFT-TREE: drag-end');
584 this.el.dragData = false;
585 this.el.dropList = false;
586 this.targetData = false;
587 this.get('/LeftTree.view').highlight(false);
590 drag_motion : function (self, ctx, x, y, time) {
591 console.log("LEFT-TREE: drag-motion");
592 var src = Gtk.drag_get_source_widget(ctx);
594 // a drag from elsewhere...- prevent drop..
596 print("no drag data!");
597 Gdk.drag_status(ctx, 0, time);
598 this.targetData = false;
601 var action = Gdk.DragAction.COPY;
602 if (src == this.el) {
603 // unless we are copying!!! ctl button..
604 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
608 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
609 // no children.. -- asume it's ok..
610 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
611 Gdk.drag_status(ctx, action ,time);
615 print("GETTING POS");
616 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
617 print("ISOVER? " + isOver);
619 Gdk.drag_status(ctx, 0 ,time);
620 return false; // not over apoint!?!
622 // drag node is parent of child..
623 console.log("SRC TREEPATH: " + src.treepath);
624 console.log("TARGET TREEPATH: " + data.path.to_string());
626 // nned to check a few here..
627 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
628 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
629 //Gtk.TreeViewDropPosition.AFTER
630 //Gtk.TreeViewDropPosition.BEFORE
632 if (typeof(src.treepath) != 'undefined' &&
633 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
634 print("subpath drag");
635 Gdk.drag_status(ctx, 0 ,time);
640 //print("DUMPING DATA");
641 //console.dump(data);
644 print(data.path.to_string() +' => '+ data.pos);
645 var tg = this.get('/LeftTree.model').findDropNodeByPath(
646 data.path.to_string(), src.dropList, data.pos);
648 this.get('/LeftTree.view').highlight(tg);
650 print("Can not find drop node path");
651 this.targetData = false;
652 Gdk.drag_status(ctx, 0, time);
656 this.targetData = tg;
659 Gdk.drag_status(ctx, action ,time);
663 drag_drop : function (w, ctx, x, y, time) {
664 Seed.print("TARGET: drag-drop");
668 w, /* will receive 'drag-data-received' signal */
669 ctx, /* represents the current state of the DnD */
670 this.get('/Window').atoms["STRING"], /* the target type we want */
671 time /* time stamp */
675 /* No target offered by source => error */
680 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
681 print("Tree: drag-data-received");
683 var delete_selection_data = false;
684 var dnd_success = false;
685 /* Deal with what we are given from source */
686 if( sel_data && sel_data.length ) {
688 if (ctx.action == Gdk.DragAction.ASK) {
689 /* Ask the user to move or copy, then set the ctx action. */
692 if (ctx.action == Gdk.DragAction.MOVE) {
693 //delete_selection_data = true;
696 var source = Gtk.drag_get_source_widget(ctx);
698 if (this.targetData) {
699 if (source != this.el) {
700 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
702 // drag around.. - reorder..
703 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
707 //Seed.print(this.targetData);
713 // we can send stuff to souce here...
719 if (dnd_success == false)
721 Seed.print ("DnD data transfer failed!\n");
724 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
727 cursor_changed : function (self) {
728 if (this.blockChanges) { // probably not needed..
731 var render = this.get('/LeftTree').getRenderer();
734 if (this.selection.count_selected_rows() < 1) {
735 this.get('/LeftPanel.model').load( false);
736 this.get('/MidPropTree').activeElement = false;
737 this.get('/MidPropTree').hideWin();
739 var pm = this.get('/RightPalete.model');
740 if (!this.get('/LeftTree').getPaleteProvider()) {
741 // it may not be loaded yet..
744 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
745 this.get('/LeftTree.model').listAllTypes()));
746 if (render && render.redraw) {
752 //console.log('changed');
753 var s = this.selection;
754 var iter = new Gtk.TreeIter();
755 s.get_selected(this.get('/LeftTree.model').el, iter);
759 var value = new GObject.Value('');
760 this.get('/LeftTree.model').el.get_value(iter, 2, value);
761 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
763 var data = JSON.parse(value.value);
764 this.get('/MidPropTree').activeElement = data;
765 this.get('/MidPropTree').hideWin();
766 this.get('/LeftPanel.model').load( data);
768 console.log(value.value);
769 // _g.button.set_label(''+value.get_string());
771 var pm =this.get('/RightPalete.model');
772 pm.load( this.get('/RightPalete').provider.gatherList(
773 this.get('/LeftTree.model').listAllTypes()));
776 if (render && render.redraw) {
780 //Seed.print( value.get_string());
787 xtype: Gtk.TreeStore,
792 changed : function(n, refresh) {
793 print("MODEL CHANGED CALLED" + this.activePath);
794 if (this.activePath) {
795 var iter = new Gtk.TreeIter();
796 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
797 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
798 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
800 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
802 //this.currentTree = this.toJS(false, true)[0];
803 this.file.items = this.toJS(false, false);
804 print("AFTER CHANGED");
805 //console.dump(this.file.items);
807 this.currentTree = this.file.items[0];
808 //console.log(this.file.toSource());
811 print("REDNER BROWSER?!");
812 this.get('/LeftTree').renderView();
814 var pm = this.get('/RightPalete.model');
815 if (!this.get('/RightPalete').provider) {
821 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
822 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
826 deleteSelected : function() {
827 this.get('/LeftTree.view').blockChanges = true;
828 var old_iter = new Gtk.TreeIter();
829 var s = this.get('/LeftTree.view').selection;
830 s.get_selected(this.el, old_iter);
831 var path = this.el.get_path(old_iter).to_string();
833 this.activePath= false;
836 this.activePath= false;
837 var iter = new Gtk.TreeIter();
838 this.el.get_iter_from_string(iter, path);
839 this.el.remove(iter);
841 // rebuild treemap. -- depreciated.!!
844 //this.toJS(null, true) // does not do anything?
845 this.activePath= false;
846 this.changed(false,true);
847 this.get('/LeftTree.view').blockChanges = false;
849 dropNode : function(target_data, node) {
852 console.dump(target_data);
853 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
855 print("add " + tp + "@" + target_data[1] );
858 if (tp && target_data[1] < 2) { // before or after..
859 var ar = target_data[0].split(':');
861 parent = new Gtk.TreePath.from_string( ar.join(':') );
864 var n_iter = new Gtk.TreeIter();
865 var iter_par = new Gtk.TreeIter();
866 var iter_after = after ? new Gtk.TreeIter() : false;
870 if (parent !== false) {
871 this.el.get_iter(iter_par, parent);
878 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
879 this.el.get_iter(iter_after, after);
880 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
881 n_iter, iter_par, iter_after);
884 this.el.append(n_iter, iter_par);
888 if (typeof(node) == 'string') {
889 var ar = node.split('.');
890 var xtype = ar.pop();
893 '|xns' : ar.join('.'),
896 if (target_data.length == 3 && target_data[2].length) {
897 node['*prop'] = target_data[2];
901 // work out what kind of packing to use..
902 if (typeof(node.pack) == 'undefined' && parent !== false) {
903 var pal = this.get('/LeftTree').getPaleteProvider();
905 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
906 print ("PNAME : " + pname);
907 var cname = pal.guessName(node);
908 print ("CNAME : " + cname);
909 node.pack = pal.getDefaultPack(pname, cname);
920 // load children - if it has any..
923 this.load(xitems, n_iter);
925 if (tp && (xitems || after)) {
926 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
928 // wee need to get the empty proptypes from somewhere..
930 //var olditer = this.activeIter;
931 this.activePath = this.el.get_path(n_iter).to_string();
933 // changed actually set's the node data..
934 this.changed(node, true);
938 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
940 //Builder.MidPropTree._model.load(node);
941 //Builder.MidPropTree._win.hideWin();
942 //Builder.LeftPanel._model.load( node);
946 findDropNode : function(treepath_str, targets) {
948 // this is used by the dragdrop code in the roo version AFAIR..
950 var path = treepath_str.replace(/^builder-/, '');
951 // treemap is depreciated... - should really check if model has any entries..
953 if (!this.el.iter_n_children(null)) {
955 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
957 print("FIND treepath: " + path);
958 //console.dump(this.treemap);
960 if (!treepath_str.match(/^builder-/)) {
961 return []; // nothing!
963 if (targets === true) {
966 return this.findDropNodeByPath(path,targets)
968 findDropNodeByPath : function(treepath_str, targets, pref) {
969 var path = treepath_str + ''; // dupe it..
970 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
972 //console.dump(this.treemap);
973 while (path.length) {
974 print("LOOKING FOR PATH: " + path);
975 var node_data = this.singleNodeToJS(path);
976 if (node_data === false) {
977 print("node not found");
981 var xname = this.get('/LeftTree.model').file.guessName(node_data);
984 targets.forEach(function(tg) {
988 if ((tg == xname) ) {
991 if (tg.indexOf(xname +':') === 0) {
993 prop = tg.split(':').pop();
998 if (last) { // pref is after/before..
999 // then it's after last
1001 return []; // do not allow..
1003 return [ last, pref , prop];
1006 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1008 var par = path.split(':');
1011 path = par.join(':');
1017 getIterValue : function (iter, col) {
1018 var gval = new GObject.Value('');
1019 this.el.get_value(iter, col ,gval);
1025 XObject.prototype.init.call(this);
1026 this.el.set_column_types ( 3, [
1027 GObject.TYPE_STRING, // title
1028 GObject.TYPE_STRING, // tip
1029 GObject.TYPE_STRING // source..
1032 listAllTypes : function() {
1033 var s = this.get('/LeftTree.view').selection;
1034 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1036 if (s.count_selected_rows() > 0) {
1037 var iter = new Gtk.TreeIter();
1038 s.get_selected(this.el, iter);
1040 // set some properties of the tree for use by the dropped element.
1041 var value = new GObject.Value('');
1042 this.el.get_value(iter, 2, value);
1043 var data = JSON.parse(value.value);
1046 var xname = this.get('/LeftTree.model').file.guessName(data);
1047 console.log('selected:' + xname);
1051 return []; // could not find it..
1059 li.forEach(function(el) {
1060 // this is specific to roo!!!?
1062 var fullpath = _this.file.guessName(el);
1063 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1068 if (el.items && el.items.length) {
1077 addall([this.currentTree]);
1079 // only if we have nothing, should we add '*top'
1083 //console.log('all types in tree');
1084 //console.dump(ret);
1089 load : function(tr,iter)
1091 var citer = new Gtk.TreeIter();
1092 //this.insert(citer,iter,0);
1093 for(var i =0 ; i < tr.length; i++) {
1095 this.el.insert(citer,iter,-1);
1097 this.el.append(citer);
1100 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1101 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1102 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1103 if (tr[i].items && tr[i].items.length) {
1104 this.load(tr[i].items, citer);
1108 loadFile : function(f) {
1114 console.log('missing file');
1118 // load the file if not loaded..
1119 if (f.items === false) {
1121 f.loadItems(function() {
1127 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1129 if (f.items.length && typeof(f.items[0]) == 'string') {
1131 this.get('/RightEditor').el.show();
1132 this.get('/RightEditor.view').load( f.items[0]);
1136 //console.dump(f.items);
1138 this.get('/LeftTree.view').el.expand_all();
1140 if (!f.items.length) {
1143 this.get('/Window.leftvpaned').el.set_position(80);
1145 this.get('/LeftTree.view').el.set_cursor(
1146 new Gtk.TreePath.from_string('0'), null, false);
1150 this.get('/Window.leftvpaned').el.set_position(200);
1154 //print("hide right editior");
1155 this.get('/RightEditor').el.hide();
1156 //print("set current tree");
1157 this.currentTree = this.toJS(false, false)[0];
1158 //console.dump(this.currentTree);
1159 this.currentTree = this.currentTree || { items: [] };
1160 this.get('/LeftTree').renderView();
1161 //console.dump(this.map);
1162 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1163 var pm = this.get('/RightPalete.model');
1164 // set up provider..
1166 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1168 if (!this.get('/RightPalete').provider) {
1169 print ("********* PALETE PROVIDER MISSING?!!");
1171 this.get('/LeftTree').renderView();
1173 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1177 this.get('/Window.view-notebook').el.set_current_page(
1178 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1181 moveNode : function(target_data, action) {
1182 //print("MOVE NODE");
1183 // console.dump(target_data);
1184 var old_iter = new Gtk.TreeIter();
1185 var s = this.get('/LeftTree.view').selection;
1186 s.get_selected(this.el, old_iter);
1187 var node = this.nodeToJS(old_iter,false);
1188 //console.dump(node);
1191 // needs to drop first, otherwise the target_data
1192 // treepath will be invalid.
1194 this.dropNode(target_data, node);
1195 if (action & Gdk.DragAction.MOVE) {
1196 // print("REMOVING OLD NODE");
1197 this.el.remove(old_iter);
1201 this.activePath= false;
1202 this.changed(false,true);
1204 nodeTip : function(c) {
1205 var ret = this.nodeTitle(c,true);
1211 if (!i.length || i[0] != '|') {
1217 if (typeof(c[i]) != 'string') {
1220 //print("prop : " + i + ':' + c[i]);
1221 if (!c[i].match(new RegExp('function'))) {
1224 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1228 ret+="\n\nMethods:" + funcs;
1233 nodeTitle : function(c, renderfull) {
1236 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1237 if (sr) txt.push('<s>');
1238 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1240 if (renderfull && c['|xns']) {
1241 txt.push(c['|xns']);
1244 if (c.xtype) { txt.push(c.xtype); }
1245 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1246 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1247 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1250 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1251 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1252 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1253 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1254 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1255 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1256 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1257 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1258 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1260 // for flat classes...
1261 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1262 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1265 if (sr) txt.push('</s>');
1266 return (txt.length == 0 ? "Element" : txt.join(" "));
1268 nodeToJS : function (treepath, with_id)
1271 var iter = treepath; // API used to be iter here..
1272 if (typeof(iter) == 'string') {
1273 iter = new Gtk.TreeIter();
1274 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1278 var par = new Gtk.TreeIter();
1279 var iv = this.getIterValue(iter, 2);
1280 // print("IV" + iv);
1281 var k = JSON.parse(iv);
1282 if (k.json && !this.el.iter_parent( par, iter )) {
1287 var treepath_str = this.el.get_path(iter).to_string();
1288 // not sure how we can handle mixed id stuff..
1289 if (typeof(k.id) == 'undefined') {
1290 k.id = 'builder-'+ treepath_str ;
1294 this.treemap[ treepath_str ] = k;
1295 k.xtreepath = treepath_str ;
1298 if (this.el.iter_has_child(iter)) {
1299 citer = new Gtk.TreeIter();
1300 this.el.iter_children(citer, iter);
1301 k.items = this.toJS(citer,with_id);
1305 nodeToJSON : function(c) {
1313 return JSON.stringify(o);
1315 singleNodeToJS : function (treepath)
1317 var iter = new Gtk.TreeIter();
1318 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1322 var iv = this.getIterValue(iter, 2);
1324 return JSON.parse(iv);
1327 toJS : function(treepath, with_id)
1329 //Seed.print("WITHID: "+ with_id);
1330 var iter = treepath; // API used to be iter here..
1331 if (typeof(iter) == 'string') {
1332 iter = new Gtk.TreeIter();
1333 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1342 iter = new Gtk.TreeIter();
1343 if (!this.el.get_iter_first(iter)) {
1353 var k = this.nodeToJS(iter, with_id);
1357 if (!this.el.iter_next(iter)) {
1363 // convert the list into a json string..
1369 xtype: Gtk.TreeViewColumn,
1370 pack : "append_column",
1372 XObject.prototype.init.call(this);
1373 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1377 xtype: Gtk.CellRendererText,
1387 id : "LeftTreeMenu",
1390 xtype: Gtk.MenuItem,
1392 label : "Delete Element",
1394 activate : function (self) {
1396 this.get('/LeftTree.model').deleteSelected();
1401 xtype: Gtk.MenuItem,
1403 activate : function (self) {
1405 var tree = this.get('/LeftTree');
1406 var model = this.get('/LeftTree.model');
1407 var el = tree.getActivePath();
1409 var js = model.toJS(el, false);
1410 print(JSON.stringify(js[0], null,4));
1414 label : "Save as Template",
1424 id : "LeftProjectTree",
1425 showNoProjectSelected : function() {
1426 this.get('/StandardErrorDialog').show("Select a Project first.");
1428 getActiveProject : function() {
1429 return this.project;
1432 leave_notify_event : function (self, event) {
1439 pack : "pack_start,false,false",
1442 xtype: Gtk.ComboBox,
1445 XObject.prototype.init.call(this);
1446 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1448 getValue : function() {
1449 var ix = this.el.get_active();
1453 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1454 if (typeof(data[ix]) == 'undefined') {
1459 setValue : function(fn)
1463 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1464 data.forEach(function(n, ix) {
1472 changed : function (self) {
1473 var fn = this.getValue();
1474 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1475 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1480 xtype: Gtk.CellRendererText,
1481 pack : "pack_start,true",
1485 xtype: Gtk.ListStore,
1488 XObject.prototype.init.call(this);
1489 this.el.set_column_types ( 2, [
1490 GObject.TYPE_STRING, // real key
1491 GObject.TYPE_STRING // real type
1495 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1497 pm.on('changed', function() {
1498 print("caught changed hook on project manager - reloading data");
1499 _this.loadData(pm.projects);
1503 loadData : function(data) {
1504 var ov = this.get('/LeftProjectTree.combo').getValue();
1506 var iter = new Gtk.TreeIter();
1508 data.forEach(function(p) {
1513 el.set_value(iter, 0, p.fn);
1514 el.set_value(iter, 1, p.name);
1518 this.get('/LeftProjectTree.combo').setValue(ov);
1527 xtype: Gtk.ScrolledWindow,
1529 shadow_type : Gtk.ShadowType.IN,
1531 XObject.prototype.init.call(this);
1532 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1536 xtype: Gtk.TreeView,
1537 headers_visible : false,
1538 enable_tree_lines : true,
1541 XObject.prototype.init.call(this);
1542 var description = new Pango.FontDescription.c_new();
1543 description.set_size(8000);
1544 this.el.modify_font(description);
1546 this.selection = this.el.get_selection();
1547 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1551 cursor_changed : function (self) {
1552 var iter = new Gtk.TreeIter();
1554 if (this.selection.count_selected_rows() < 1) {
1555 //XN.get('Builder.LeftTree.model').
1556 this.get('/LeftTree.model').load( false);
1560 var model = this.get('/LeftProjectTree.model');
1561 //console.log('changed');
1562 var s = this.selection;
1563 s.get_selected(model, iter);
1564 value = new GObject.Value('');
1565 model.el.get_value(iter, 2, value);
1567 console.log(value.value);// id..
1569 var file = this.get('/LeftProjectTree').project.getById(value.value);
1576 var nb = this.get('/LeftTopPanel.expander');
1577 nb.el.expanded = false;
1578 nb.listeners.activate.call(nb);
1579 //_expander.el.set_expanded(false);
1581 var ltm = this.get('/LeftTree.model');
1589 xtype: Gtk.TreeStore,
1593 XObject.prototype.init.call(this);
1594 this.el.set_column_types ( 3, [
1595 GObject.TYPE_STRING, // title
1596 GObject.TYPE_STRING, // tip
1597 GObject.TYPE_STRING // id..
1601 loadProject : function(pr) {
1602 print("LOAD PROJECT");
1608 this.get('/LeftProjectTree').project = pr;
1609 this.load(pr.toTree());
1610 this.get('/LeftProjectTree.view').el.expand_all();
1612 load : function(tr,iter) {
1613 // console.dump(tr);
1614 console.log('Project tree load: ' + tr.length);
1615 var citer = new Gtk.TreeIter();
1616 //this.insert(citer,iter,0);
1619 tr.forEach(function (r) {
1621 _this.el.append(citer);
1623 _this.el.insert(citer,iter,-1);
1625 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1626 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1627 _this.el.set_value(citer, 2, '' + r.id ); //id
1628 if (r.cn && r.cn.length) {
1629 _this.load(r.cn, citer);
1634 getValue : function(iter, col) {
1635 var gval = new GObject.Value('');
1636 this.el.get_value(iter, col ,gval);
1637 return '' + gval.value;
1641 xtype: Gtk.TreeViewColumn,
1642 pack : "append_column",
1644 XObject.prototype.init.call(this);
1645 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1649 xtype: Gtk.CellRendererText,
1672 pack : "pack_start,false,true,0",
1679 button_press_event : function (self, event) {
1680 this.get('/MidPropTree.model').showData('props');
1692 stock : Gtk.STOCK_ADD,
1693 icon_size : Gtk.IconSize.MENU
1708 button_press_event : function (self, event) {
1709 this.get('/MidPropTree.model').showData('events');
1721 stock : Gtk.STOCK_ADD,
1722 icon_size : Gtk.IconSize.MENU
1737 button_press_event : function (self, ev) {
1738 var p = this.get('/AddPropertyPopup');
1742 p.el.set_screen(Gdk.Screen.get_default());
1744 p.el.popup(null, null, null, null, 3, ev.button.time);
1756 stock : Gtk.STOCK_ADD,
1757 icon_size : Gtk.IconSize.MENU
1769 id : "AddPropertyPopup",
1772 xtype: Gtk.MenuItem,
1774 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1777 activate : function (self) {
1779 this.get('/LeftPanel.model').add( {
1790 xtype: Gtk.MenuItem,
1792 tooltip_markup : "Add what type of packing is to be used",
1795 activate : function (self) {
1797 this.get('/LeftPanel.model').add( {
1807 xtype: Gtk.MenuItem,
1809 tooltip_markup : "Override the init method",
1812 activate : function (self) {
1814 this.get('/LeftPanel.model').add( {
1817 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1824 xtype: Gtk.SeparatorMenuItem,
1828 xtype: Gtk.MenuItem,
1830 tooltip_markup : "Add a user defined string property",
1833 activate : function (self) {
1835 this.get('/LeftPanel.model').add( {
1845 xtype: Gtk.MenuItem,
1847 tooltip_markup : "Add a user defined number property",
1850 activate : function (self) {
1852 this.get('/LeftPanel.model').add( {
1862 xtype: Gtk.MenuItem,
1864 tooltip_markup : "Add a user defined boolean property",
1867 activate : function (self) {
1869 this.get('/LeftPanel.model').add( {
1879 xtype: Gtk.SeparatorMenuItem,
1883 xtype: Gtk.MenuItem,
1885 tooltip_markup : "Add a user function boolean property",
1888 activate : function (self) {
1890 this.get('/LeftPanel.model').add( {
1893 val : "function() {\n \n}\n",
1906 xtype: Gtk.ScrolledWindow,
1909 shadow_type : Gtk.ShadowType.IN,
1912 XObject.prototype.init.call(this);
1913 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1917 xtype: Gtk.TreeView,
1920 headers_visible : false,
1921 enable_tree_lines : true,
1923 XObject.prototype.init.call(this);
1925 this.selection = this.el.get_selection();
1926 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1929 var description = new Pango.FontDescription.c_new();
1930 description.set_size(8000);
1931 this.el.modify_font(description);
1934 button_press_event : function (self, ev) {
1938 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1939 return false; //not on a element.
1943 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1945 if (res.column.title != 'value') {
1946 return false; // ignore..
1948 if ( this.get('/LeftPanel').editing) {
1951 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1952 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1953 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1957 var provider = this.get('/LeftTree').getPaleteProvider();
1959 var opts = provider.findOptions(type);
1961 if (opts === false) {
1962 this.get('/LeftPanel').editableColumn.setOptions([]);
1963 renderer.has_entry = true;
1965 LeftPanel.editableColumn.setOptions(opts);
1966 renderer.has_entry = false;
1970 //Seed.print("click" + ev.type);
1971 //console.dump(res);
1977 if (res.column.title == 'value') {
1980 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1981 var p = this.get('/LeftPanelPopup');
1986 p.el.set_screen(Gdk.Screen.get_default());
1988 p.el.popup(null, null, null, null, 3, ev.button.time);
1989 //Seed.print("click:" + res.column.title);
1997 xtype: Gtk.TreeStore,
2001 getIterValue : function(iter, col) {
2002 var gval = new GObject.Value('');
2003 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2004 return '' + gval.value;
2006 add : function(info) {
2007 // info includes key, val, skel, etype..
2009 type = info.type.toLowerCase();
2010 var data = this.toJS();
2012 if (info.etype == 'events') {
2013 data.listeners = data.listeners || { };
2014 if (typeof(data.listeners[info.key]) != 'undefined') {
2015 return; //already set!
2018 if (typeof(data[info.key]) != 'undefined') {
2023 if (typeof(info.val) == 'undefined') {
2026 if (info.type == 'boolean') {
2029 if (type == 'number') {
2037 if (info.etype == 'events') {
2039 data.listeners[info.key] = info.val;
2042 data[info.key] = info.val;
2046 var map = this.load(data);
2048 // flag it as changed to the interface..
2050 this.get('/LeftTree.model').changed(data, true);
2053 this.startEditing(map[k]);
2056 LeftPanel.get('view').el.row_activated(
2057 new Gtk.TreePath.from_string(map[k]),
2058 LeftPanel.editableColumn.el
2062 changed : function(str, doRefresh) {
2063 if (!this.activePath) {
2066 var iter = new Gtk.TreeIter();
2067 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2069 this.el.set_value(iter, 1, '' +str);
2070 this.el.set_value(iter, 3, '' + this.toShort(str));
2071 var type = this.getIterValue(iter, 4);
2073 this.el.set_value(iter, 5, type + ' : ' + str);
2074 // update the tree...
2076 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2078 deleteSelected : function() {
2079 var data = this.toJS();
2080 var iter = new Gtk.TreeIter();
2081 var s = this.get('/LeftPanel.view').selection;
2082 s.get_selected(this.el, iter);
2085 var gval = new GObject.Value('');
2086 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2088 var val = gval.value;
2089 if (val[0] == '!') {
2091 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2094 delete data.listeners[ val.substring(1)];
2095 if (!XObject.keys(data.listeners).length) {
2096 delete data.listeners;
2100 if (typeof(data[val]) == 'undefined') {
2108 this.get('/LeftTree.model').changed(data, true);
2111 editSelected : function(e) {
2112 print("EDIT SELECTED?");
2113 var iter = new Gtk.TreeIter();
2114 var s = this.get('/LeftPanel.view').selection;
2115 s.get_selected(this.get('/LeftPanel.model').el, iter);
2116 var m = this.get('/LeftPanel.model')
2118 var gval = new GObject.Value('');
2119 this.el.get_value(iter, 0 ,gval);
2120 var val = '' + gval.value;
2122 gval = new GObject.Value('');
2123 this.el.get_value(iter, 1 ,gval);
2124 var rval = gval.value;
2125 var activePath = this.el.get_path(iter).to_string();
2126 this.activePath = activePath ;
2127 // was activeIter...
2130 var showEditor = false;
2132 if (val[0] == '!') {
2135 if (val[0] == '|') {
2136 if (rval.match(/function/g) || rval.match(/\n/g)) {
2143 this.activePath = false;
2144 GLib.timeout_add(0, 1, function() {
2145 // Gdk.threads_enter();
2146 _this.get('/BottomPane').el.show();
2147 _this.get('/RightEditor').el.show();
2148 _this.get('/RightEditor.view').load( rval );
2152 _this.activePath = activePath ;
2154 // Gdk.threads_leave();
2159 this.get('/BottomPane').el.hide();
2160 this.get('/RightEditor').el.hide();
2162 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2166 getType : function(treepath) {
2167 return this.getValue(treepath, 4);
2169 getValue : function(treepath_str, col) {
2170 var iter = new Gtk.TreeIter();
2171 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2173 var gval = new GObject.Value('');
2174 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2175 var val = '' + gval.value;
2179 var type = this.getType(this.el.get_path(iter).to_string());
2180 print("TYPE: " +type + " - val:" + val);
2181 switch(type.toLowerCase()) {
2185 return parseFloat(val); // Nan ?? invalid!!?
2188 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2190 return val == 'true' ? true : false;
2192 var nv = parseFloat(val);
2193 if (!isNaN(nv) && (val == ''+nv)) {
2201 XObject.prototype.init.call(this);
2202 this.el.set_column_types ( 6, [
2203 GObject.TYPE_STRING, // 0 real key
2204 GObject.TYPE_STRING, // 1 real value
2205 GObject.TYPE_STRING, // 2 visable key
2206 GObject.TYPE_STRING, // 3 visable value
2207 GObject.TYPE_STRING, // 4 need to store type of!!!
2208 GObject.TYPE_STRING // 5 tooltip
2212 load : function(ar) {
2215 this.get('/RightEditor').el.hide();
2222 var provider = this.get('/LeftTree').getPaleteProvider();
2223 var iter = new Gtk.TreeIter();
2226 var keys = XObject.keys(ar);
2228 ar.listeners = ar.listeners || {};
2230 for (var i in ar.listeners ) {
2231 this.el.append(iter);
2232 var p = this.el.get_path(iter).to_string();
2235 this.el.set_value(iter, 0, '!'+ i );
2236 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2237 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2239 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2240 this.el.set_value(iter, 4, 'function');
2241 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2247 keys.forEach(function(i) {
2248 if (typeof(ar[i]) == 'object') {
2252 var type = provider.findType(ar, i, ar[i]);
2254 _this.el.append(iter);
2255 var p = _this.el.get_path(iter).to_string();
2257 _this.el.set_value(iter, 0, ''+i);
2258 _this.el.set_value(iter, 1, '' + ar[i]);
2259 _this.el.set_value(iter, 2, ''+i);
2260 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2261 _this.el.set_value(iter, 4, ''+type);
2262 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2266 startEditing : function(path,col) {
2268 * start editing path (or selected if not set..)
2269 * @param {String|false} path (optional) treepath to edit - selected tree gets
2270 * edited by default.
2271 * @param {Number} 0 or 1 (optional)- column to edit.
2274 if (typeof(path) == 'string') {
2275 tp = new Gtk.TreePath.from_string(path);
2277 var iter = new Gtk.TreeIter();
2278 var s = this.get('/LeftPanel.view').selection;
2279 s.get_selected(this.el, iter);
2280 tp = this.el.get_path(iter);
2281 path = tp.to_string();
2285 // which colum is to be edited..
2287 if (typeof(col) == 'undefined') {
2288 var k = this.getValue(path, 0);
2289 colObj = (!k.length || k == '|') ?
2290 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2292 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2295 // make sure the pulldown is set correctly..
2296 // not really needed for second col...
2298 var provider = this.get('/LeftTree').getPaleteProvider();
2300 var type = this.get('/LeftPanel.model').getType(path);
2301 var opts = provider.findOptions(type);
2302 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2304 if (opts === false) {
2305 this.get('/LeftPanel').editableColumn.setOptions([]);
2306 renderer.has_entry = true; /// probably does not have any effect.
2308 this.get('/LeftPanel').editableColumn.setOptions(opts);
2309 renderer.has_entry = false;
2313 // iter now has row...
2314 GLib.timeout_add(0, 100, function() {
2316 colObj.items[0].el.editable = true; // esp. need for col 0..
2317 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2327 var iter = new Gtk.TreeIter();
2328 this.get('/LeftPanel.model').el.get_iter_first(iter);
2333 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2336 ar.listeners = ar.listeners || {};
2337 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2340 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2343 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2349 //print(JSON.stringify(ar));
2353 toShort : function(str) {
2354 var a = typeof(str) == 'string' ? str.split("\n") : [];
2355 return a.length > 1 ? a[0] + '....' : '' + str;
2359 xtype: Gtk.TreeViewColumn,
2360 pack : "append_column",
2362 XObject.prototype.init.call(this);
2364 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2365 this.get('/LeftPanel').propertyColumn = this;
2370 xtype: Gtk.CellRendererText,
2371 pack : "pack_start",
2373 editing_started : function (self, editable, path) {
2375 this.get('/LeftPanel.model').activePath = path;
2378 edited : function (self, object, p0) {
2379 var model = this.get('/LeftPanel.model');
2380 var path = model.activePath;
2381 var iter = new Gtk.TreeIter();
2382 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2383 model.el.set_value(iter, 0, p0);
2384 model.el.set_value(iter, 2, p0);
2386 model.activePath = false;
2388 this.get('/LeftTree.model').changed(model.toJS(), true);
2389 this.el.editable = false;
2396 xtype: Gtk.TreeViewColumn,
2397 pack : "append_column",
2399 XObject.prototype.init.call(this);
2400 this.el.add_attribute(this.items[0].el , 'text', 3 );
2401 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2402 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2403 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2405 this.get('/LeftPanel').editableColumn= this;
2407 setOptions : function(ar) {
2408 var m = this.items[0].el.model;
2410 var iter = new Gtk.TreeIter();
2411 ar.forEach(function(i) {
2414 m.set_value(iter, 0, i);
2420 xtype: Gtk.CellRendererCombo,
2421 pack : "pack_start",
2426 XObject.prototype.init.call(this);
2427 this.el.model = new Gtk.ListStore();
2428 this.el.model.set_column_types ( 1, [
2429 GObject.TYPE_STRING // 0 real key
2433 edited : function (self, object, p0) {
2434 this.get('/LeftPanel').editing = false;
2435 print("EDITED? p:" + p0 + " t:" + p0);
2436 this.get('/LeftPanel.model').changed(p0, true);
2437 this.get('/LeftPanel.model').activePath = false;
2439 editing_started : function (self, editable, path) {
2440 this.get('/LeftPanel').editing = true;
2441 // console.log('editing started');
2442 // r.has_entry = false;
2443 this.get('/LeftPanel.model').editSelected(editable);
2454 id : "LeftPanelPopup",
2457 xtype: Gtk.MenuItem,
2461 activate : function (self) {
2462 this.get('/LeftPanel.model').deleteSelected();
2467 xtype: Gtk.MenuItem,
2471 activate : function (self) {
2472 this.get('/LeftPanel.model').startEditing(false, 0);
2485 xtype: Gtk.ScrolledWindow,
2486 pack : "pack_end,false,true,0",
2488 shadow_type : Gtk.ShadowType.IN,
2490 XObject.prototype.init.call(this);
2491 XObject.prototype.init.call(this);
2492 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2493 this.el.set_size_request ( 150, -1 );
2496 activeElement : false,
2497 hideWin : function() {
2504 if (this.get('/Window.left').el.position < 160) {
2507 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2514 xtype: Gtk.TreeView,
2515 enable_tree_lines : true,
2516 headers_visible : false,
2519 XObject.prototype.init.call(this);
2521 var description = new Pango.FontDescription.c_new();
2522 description.set_size(8000);
2523 this.el.modify_font(description);
2525 //this.selection = this.el.get_selection();
2526 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2535 cursor_changed : function (self) {
2536 var iter = new Gtk.TreeIter();
2538 //console.log('changed');
2539 var m = this.get('model');
2540 if (!this.selection){
2541 this.selection = this.el.get_selection();
2544 var s = this.selection;
2545 if (!s.get_selected(m.el, iter)) {
2548 var tp = m.el.get_path(iter).to_string();
2553 var key = m.getValue(tp, 0);
2555 var type = m.getValue(tp, 1);
2556 var skel = m.getValue(tp, 3);
2557 var etype = m.getValue(tp, 5);
2560 this.get('/MidPropTree').hideWin();
2562 if (type == 'function') {
2564 if (etype != 'events') {
2568 this.get('/LeftPanel.model').add({
2577 if (type.indexOf('.') > -1 ||
2578 type == 'boolean') {
2582 this.get('/LeftPanel.model').add( {
2592 xtype: Gtk.ListStore,
2595 XObject.prototype.init.call(this);
2596 this.el.set_column_types ( 6, [
2597 GObject.TYPE_STRING, // real key
2598 GObject.TYPE_STRING, // real type
2599 GObject.TYPE_STRING, // docs ?
2600 GObject.TYPE_STRING, // visable desc
2601 GObject.TYPE_STRING, // function desc
2602 GObject.TYPE_STRING // element type (event|prop)
2606 getValue : function(treepath, col)
2608 var tp = new Gtk.TreePath.from_string (treepath);
2609 var iter = new Gtk.TreeIter();
2610 this.el.get_iter (iter, tp);
2611 var value = new GObject.Value('');
2612 this.el.get_value(iter, col, value);
2616 showData : function(type) {
2618 if (!this.get('/MidPropTree').activeElement || !type) {
2619 return; // no active element
2622 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2623 var palete = this.get('/LeftTree').getPaleteProvider();
2627 Seed.print('Showing right?');
2628 if (!this.get('/MidPropTree').shown) {
2630 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2631 this.get('/MidPropTree').el.show();
2632 this.get('/MidPropTree').shown = true;
2635 var elementList = palete.getPropertiesFor(fullpath, type);
2636 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2637 // console.dump(elementList);
2640 var iter = new Gtk.TreeIter();
2641 for(var i =0 ; i < elementList.length; i++) {
2642 var p=elementList[i];
2643 this.el.append(iter);
2644 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2645 //GObject.TYPE_STRING, // real key
2646 // GObject.TYPE_STRING, // real type
2647 // GObject.TYPE_STRING, // docs ?
2648 // GObject.TYPE_STRING // func def?
2651 this.el.set_value(iter, 0, p.name);
2652 this.el.set_value(iter, 1, p.type);
2653 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2654 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2655 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2656 this.el.set_value(iter, 5, type);
2664 xtype: Gtk.TreeViewColumn,
2666 this.el = new Gtk.TreeViewColumn();
2667 this.parent.el.append_column(this.el);
2669 XObject.prototype.init.call(this);
2670 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2675 xtype: Gtk.CellRendererText,
2676 pack : "pack_start,true"
2700 xtype: Gtk.Notebook,
2701 pack : "pack_start,true,true",
2702 id : "view-help-nb",
2704 XObject.prototype.init.call(this);
2705 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2706 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2710 xtype: Gtk.Notebook,
2712 id : "view-notebook",
2715 XObject.prototype.init.call(this);
2716 this.el.set_current_page(0);
2718 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2719 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2726 id : "RightBrowser",
2732 xtype: Gtk.ScrolledWindow,
2734 shadow_type : Gtk.ShadowType.IN,
2736 XObject.prototype.init.call(this);
2737 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2741 xtype: WebKit.WebView,
2745 XObject.prototype.init.call(this);
2746 // this may not work!?
2747 this.el.open('file:///' + __script_path__ + '/../builder.html');
2751 this.el, /* widget that will accept a drop */
2752 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2753 null, /* lists of target to support */
2754 0, /* size of list */
2755 Gdk.DragAction.COPY /* what to do with data after dropped */
2758 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2759 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2761 renderJS : function(data) {
2762 print("HTML RENDERING");
2763 /// prevent looping..
2764 //if (this.pendingRedraw) {
2765 // print("pending redraw active?!");
2770 if (!this.get('/Window.LeftTree').getActiveFile()) {
2774 var project = this.get('/Window.LeftTree').getActiveFile().project;
2775 //print (project.fn);
2777 project.runhtml = project.runhtml || '';
2780 this.runhtml = this.runhtml || '';
2782 if (project.runhtml != this.runhtml) {
2783 // then we need to reload the browser using
2784 // load_html_string..
2786 // then trigger a redraw once it's loaded..
2787 this.pendingRedraw = true;
2789 this.runhtml = project.runhtml;
2791 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2792 html = html.replace('</head>', this.runhtml + '</head>');
2793 print("LOAD HTML " + html);
2794 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2795 // should trigger load_finished!
2800 this.pendingRedraw = false;
2803 this.renderedData = data;
2804 var str = JSON.stringify(data) ;
2807 console.log('not loaded yet');
2809 //Seed.print("RENDER:" + str);
2810 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2812 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2815 load_finished : function (self, object) {
2816 // if (this.ready) { // dont do it twice!
2820 this.pendingRedraw = false;
2821 var js = this.get('/LeftTree.model').toJS();
2823 this.renderJS(js[0]);
2827 script_alert : function (self, object, p0) {
2830 return true; // do not display anything...
2832 console_message : function (self, object, p0, p1) {
2833 // console.log(object);
2834 if (!object.match(/^\{/)) {
2836 this.get('/Terminal').feed(object);
2837 return true; // do not handle!!! -> later maybe in console..
2839 // console.log(object);
2840 var val = JSON.parse(object);
2842 if (typeof(val['hover-node']) != 'undefined') {
2843 this.activeNode = val['hover-node'];
2844 console.log('active node: ' + this.activeNode);
2849 if (typeof(val['id']) != 'undefined') {
2850 // this.activeNode = val['id'];
2851 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2855 this.get('/LeftTree.view').selectNode(tg[0]);
2859 if (ret && typeof(val['set']) != 'undefined') {
2860 this.get('/LeftPanel.model').add({
2864 //console.log('active node: ' + this.activeNode);
2867 //Seed.print('a:'+a);
2868 //Seed.print('b:'+b);
2869 //Seed.print('c:'+c);
2872 drag_motion : function (w, ctx, x, y, time, ud) {
2873 // console.log('DRAG MOTION');
2875 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2876 this.targetData = [];
2877 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2879 // A) find out from drag all the places that node could be dropped.
2880 var src = Gtk.drag_get_source_widget(ctx);
2881 if (!src.dropList) {
2882 Gdk.drag_status(ctx, 0, time);
2885 // b) get what we are over.. (from activeNode)
2886 // tree is empty.. - list should be correct..
2887 if (!this.get('/LeftTree.model').currentTree) {
2888 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2892 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2894 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2897 Gdk.drag_status(ctx, 0,time);
2898 this.get('/LeftTree.view').highlight(false);
2902 // if we have a target..
2903 // -> highlight it! (in browser)
2904 // -> highlight it! (in tree)
2906 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2907 this.get('/LeftTree.view').highlight(tg);
2908 this.targetData = tg;
2909 // for tree we should handle this...
2912 drag_drop : function (w, ctx, x, y,time, ud) {
2913 print("TARGET: drag-drop");
2914 var is_valid_drop_site = true;
2919 w, /* will receive 'drag-data-received' signal */
2920 ctx, /* represents the current state of the DnD */
2921 this.get('/Window').atoms["STRING"], /* the target type we want */
2922 time /* time stamp */
2926 /* No target offered by source => error */
2929 return is_valid_drop_site;
2931 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2933 print("Browser: drag-data-received");
2934 var delete_selection_data = false;
2935 vardnd_success = false;
2936 /* Deal with what we are given from source */
2937 if( sel_data && sel_data.length ) {
2939 if (ctx.action == Gdk.DragAction.ASK) {
2940 /* Ask the user to move or copy, then set the ctx action. */
2943 if (ctx.action == Gdk.DragAction.MOVE) {
2944 delete_selection_data = true;
2946 var source = Gtk.drag_get_source_widget(ctx);
2948 print("Browser: source.DRAGDATA? " + source.dragData);
2949 if (this.targetData) {
2950 print(this.targetData);
2951 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2960 if (dnd_success == false)
2962 Seed.print ("DnD data transfer failed!\n");
2965 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2976 id : "RightGtkView",
2978 redraw : function() {
2979 this.highlightWidget = false;
2980 print("REDRAW CALLED");
2981 this.activePath = this.get('/LeftTree').getActivePath();
2982 if (this.renderedEl) {
2983 print("QUEUE DRAW CALLING");
2984 this.renderedEl.queue_draw();
2987 renderJS : function(data, withDebug)
2989 this.highlightWidget = false;
2991 this.withDebug = false;
2993 if (this.renderedEl) {
2994 this.get('view').el.remove(this.renderedEl);
2995 this.renderedEl.destroy();
2996 this.renderedEl = false;
3001 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3002 // in theory tree is actually window..
3004 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3009 this.get('view').el.set_size_request(
3010 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3013 this.renderedEl.set_size_request(
3014 tree.default_width || 600,
3015 tree.default_height || 400
3017 this.get('view').el.show_all();
3022 showInWindow : function() {
3023 print("GET PROEJCT");
3024 var pr = this.get('/LeftProjectTree').getActiveProject();
3026 console.log(pr.paths);
3029 var src= this.buildJS(
3030 this.get('/LeftTree.model').toJS()[0],
3035 //var x = new imports.sandbox.Context();
3039 Seed.check_syntax('var e = ' + src);
3042 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3043 this.get('/Terminal').feed(console._dump(e)+"\n");
3045 var lines = src.split("\n");
3046 var start = Math.max(0, e.line - 10);
3047 var end = Math.min(lines.length, e.line + 10);
3048 for (var i =start ; i < end; i++) {
3050 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3053 this.get('/Terminal').feed(lines[i] + "\n");
3060 this.get('/BottomPane').el.set_current_page(1);
3061 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3062 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3063 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3065 var _top = x.get_global_object()._top;
3067 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3069 if (_top.el.popup) {
3070 _top.el.popup(null, null, null, null, 3, null);
3074 viewAdd : function(item, par)
3076 // does something similar to xobject..
3077 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3079 if (item.pack===false || item.pack === 'false') { // no ;
3082 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3083 var type = item['|xns'] + '.' + item['xtype'];
3084 var ns = imports.gi[item['|xns']];
3085 var ctr = ns[item['xtype']];
3087 for(var k in item) {
3089 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3104 if (k[0] == '|' && typeof(kv) == 'string') {
3106 if (kv.match(new RegExp('function'))) {
3109 print("WASL " + k + '=' + kv);
3111 eval( 'kv = ' + kv);
3112 } catch(e) { continue; }
3115 // print(k + '=' + kv);
3117 if (k[0] == '|') { // should be boolean or number..
3119 //print(k + '=' + kv);
3122 if (k == 'show_tabs') { // force tab showing for notebooks.
3125 print(k + '=' + typeof(kv) + " : " + kv);
3131 var el = new ctr(ctr_args);
3133 print("PACK" + item.pack);
3134 //console.dump(item.pack);
3141 if (typeof(item.pack) == 'string') {
3143 item.pack.split(',').forEach(function(e, i) {
3145 if (e == 'false') { args.push( false); return; }
3146 if (e == 'true') { args.push( true); return; }
3147 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3150 //print(args.join(","));
3152 pack_m = args.shift();
3154 pack_m = item.pack.shift();
3159 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3161 name: "ArgumentError",
3162 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3163 "ADDING : " + item.id + " " + el
3172 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3173 //Seed.print('args: ' + args.length);
3175 par[pack_m].apply(par, args);
3179 item.items = item.items || [];
3180 item.items.forEach(function(ch,n) {
3182 print ("type:" + type);
3184 print ("ch.pack:" + ch.pack);
3185 if (type == 'Gtk.Table' && ch.pack == 'add') {
3186 var c = n % item.n_columns;
3187 var r = Math.floor(n/item.n_columns);
3188 ch.pack = [ 'attach', c, c+1, r, r+1,
3189 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3190 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3191 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3192 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3196 _this.viewAdd(ch, el);
3201 // add the signal handlers.
3202 // is it a widget!?!!?
3208 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3209 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3210 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3211 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3212 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3222 widgetDragDropEvent : function() {
3223 print("WIDGET DRAGDROP");
3226 widgetDragMotionEvent : function() {
3227 print("WIDGET DRAGMOTION");
3230 widgetExposeEvent : function(w, evt, ud, item) {
3232 if (this.inRender) {
3236 if ( this.highlightWidget) {
3237 this.inRender = true;
3238 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3239 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3241 this.inRender = false;
3246 if (this.activePath != item.xtreepath) {
3250 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3251 // work out the coords of the window..
3253 var dr = widget.window;
3254 this.gc = (new Gdk.GC.c_new(dr));
3255 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3256 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3260 var r = evt.expose.area;
3261 // console.dump([r.x, r.y, r.width, r.height ] );
3263 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3264 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3265 // happens with gtkscrollview embedded stuff..
3266 var np =this.activePath.split(':');
3268 this.activePath = np.join(':');
3269 this.renderedEl.queue_draw();
3285 this.inRender = true;
3288 this.highlightWidget = widget;
3293 // print("DRAW BOX");
3294 //console.dump(this.box);
3295 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3296 this.inRender = false;
3299 widgetPressEvent : function(w,e,u,d) {
3300 if (this.get('view').pressed) {
3303 this.get('view').pressed = true;
3304 print("WIDGET PRESS " + d.xtreepath );
3305 this.get('/LeftTree.view').selectNode( d.xtreepath );
3308 widgetReleaseEvent : function() {
3309 this.get('view').pressed = false;
3315 pack : "pack_start,false,true,0",
3319 pack : "pack_start,false,false,0",
3320 label : "Run The Application",
3322 button_press_event : function (self, event) {
3323 // call render on left tree - with special option!?!
3325 //print("GET PROEJCT");
3326 var pr = this.get('/LeftProjectTree').getActiveProject();
3329 for (var i in pr.paths) {
3333 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3334 this.get('/Terminal').feed("RUN DIR:" + dir);
3336 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3337 , false,false,false);
3338 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3339 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3349 xtype: Gtk.ScrolledWindow,
3352 shadow_type : Gtk.ShadowType.IN,
3354 XObject.prototype.init.call(this);
3355 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3359 xtype: Gtk.EventBox,
3360 pack : "add_with_viewport",
3362 XObject.prototype.init.call(this);
3363 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3364 red: 0x9F00, green: 0xB800 , blue : 0xA800
3372 XObject.prototype.init.call(this);
3373 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3374 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3379 xtype: Gtk.EventBox,
3382 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3383 XObject.prototype.init.call(this);
3387 this.el, /* widget that will accept a drop */
3388 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3389 null, /* lists of target to support */
3390 0, /* size of list */
3391 Gdk.DragAction.COPY /* what to do with data after dropped */
3394 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3395 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3398 getActiveNode : function(x,y)
3400 // workout what node is here..
3401 return '0'; // top..
3405 drag_motion : function (self, ctx, x, y, time) {
3407 // A) find out from drag all the places that node could be dropped.
3408 var src = Gtk.drag_get_source_widget(ctx);
3409 if (!src.dropList) {
3410 Gdk.drag_status(ctx, 0, time);
3413 // b) get what we are over.. (from activeNode)
3414 // tree is empty.. - list should be correct..
3415 if (!this.get('/LeftTree.model').currentTree) {
3416 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3420 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3421 var activeNode = this.getActiveNode(x, y);
3424 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3427 Gdk.drag_status(ctx, 0,time);
3428 this.get('/LeftTree.view').highlight(false);
3432 // if we have a target..
3433 // -> highlight it! (in browser)
3434 // -> highlight it! (in tree)
3436 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3437 this.get('/LeftTree.view').highlight(tg);
3438 this.targetData = tg;
3439 // for tree we should handle this...
3442 drag_drop : function (self,ctx, x, y, time) {
3443 Seed.print("TARGET: drag-drop");
3444 var is_valid_drop_site = true;
3449 self, /* will receive 'drag-data-received' signal */
3450 ctx, /* represents the current state of the this.gDnD */
3451 this.get('/Window').atoms["STRING"], /* the target type we want */
3452 time /* time stamp */
3456 /* No target offered by source => error */
3459 return is_valid_drop_site;
3462 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3464 Seed.print("GtkView: drag-data-received");
3465 var delete_selection_data = false;
3466 var dnd_success = false;
3467 /* Deal with what we are given from source */
3468 if( sel_data && sel_data.length ) {
3470 if (ctx.action == Gdk.DragAction.ASK) {
3471 /* Ask the user to move or copy, then set the ctx action. */
3474 if (ctx.action == Gdk.DragAction.MOVE) {
3475 delete_selection_data = true;
3477 var source = Gtk.drag_get_source_widget(ctx);
3479 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3480 if (this.targetData) {
3481 Seed.print(this.targetData);
3482 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3491 if (dnd_success == false)
3493 Seed.print ("DnD data transfer failed!\n");
3496 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3499 button_press_event : function (self, event) {
3500 this.pressed = false;
3516 xtype: Gtk.ScrolledWindow,
3521 var file = this.get('/LeftTree').getActiveFile();
3525 var activeEl = this.get('/LeftTree').getActiveElement();
3526 var xtype = file.guessName( activeEl )
3527 if (!xtype || !xtype.length) {
3530 this.get('/Window.view-help-nb').el.set_current_page(1);
3532 // get the active element being edited.
3533 var helpurl = file.getHelpUrl(xtype);
3535 // now load the help info in the page..
3536 this.get('help-view').el.open(helpurl);
3540 xtype: WebKit.WebView,
3544 XObject.prototype.init.call(this);
3545 this.get('/Window.help-view').el.open(
3546 "http://devel.akbkhome.com/seed/");
3558 xtype: Gtk.Notebook,
3561 XObject.prototype.init.call(this);
3562 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3563 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3568 xtype: Gtk.ScrolledWindow,
3573 xtype: GtkSource.View,
3577 XObject.prototype.init.call(this);
3578 var description = Pango.Font.description_from_string("monospace")
3579 description.set_size(8000);
3580 this.el.modify_font(description);
3583 load : function(str) {
3585 // show the help page for the active node..
3586 this.get('/Help').show();
3589 this.get('/BottomPane').el.set_current_page(0);
3590 this.el.get_buffer().set_text(str, str.length);
3591 var lm = GtkSource.LanguageManager.get_default();
3593 this.el.get_buffer().set_language(lm.get_language('js'));
3594 var buf = this.el.get_buffer();
3595 var cursor = buf.get_mark("insert");
3596 var iter= new Gtk.TextIter;
3597 buf.get_iter_at_mark(iter, cursor);
3599 iter.set_line_offset(4);
3600 buf.move_mark(cursor, iter);
3603 cursor = buf.get_mark("selection_bound");
3604 iter= new Gtk.TextIter;
3605 buf.get_iter_at_mark(iter, cursor);
3607 iter.set_line_offset(4);
3608 buf.move_mark(cursor, iter);
3610 this.el.grab_focus();
3612 insert_spaces_instead_of_tabs : true,
3615 show_line_numbers : true,
3618 xtype: GtkSource.Buffer,
3619 pack : "set_buffer",
3621 changed : function (self) {
3622 var s = new Gtk.TextIter();
3623 var e = new Gtk.TextIter();
3624 this.el.get_start_iter(s);
3625 this.el.get_end_iter(e);
3626 var str = this.el.get_text(s,e,true);
3628 Seed.check_syntax('var e = ' + str);
3630 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3631 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3633 print("SYNTAX ERROR IN EDITOR");
3638 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3639 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3642 this.get('/LeftPanel.model').changed( str , false);
3651 xtype: Gtk.ScrolledWindow,
3655 xtype: Vte.Terminal,
3658 feed : function(istr) {
3659 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3660 // we should make ourselves visable!!!
3661 this.get('/BottomPane').el.show();
3662 this.get('/BottomPane').el.set_current_page(1);
3664 this.el.feed(str ,str.length);
3666 scroll_on_output : true,
3668 XObject.prototype.init.call(this);
3669 this.el.set_size (80, 1000);
3671 scrollback_lines : 1000
3681 pack : "pack_start,false,false",
3685 this.get('buttonbar').el.show();
3686 this.get('viewbox').el.hide();
3687 print("TRIED TO HIDE");
3690 this.get('buttonbar').el.hide();
3691 this.get('viewbox').el.show();
3692 // this.get('model').expanded();
3704 pack : "pack_start,false,true",
3706 clicked : function (self) {
3707 this.get('/RightPalete').show();
3714 stock : Gtk.STOCK_GOTO_FIRST,
3715 icon_size : Gtk.IconSize.MENU
3725 XObject.prototype.init.call(this);
3726 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3729 enter_notify_event : function (self, event) {
3730 this.get('/RightPalete').show();
3744 pack : "pack_start,false,true",
3753 pack : "pack_start,false,true",
3755 clicked : function (self) {
3756 this.get('/RightPalete').hide();
3763 stock : Gtk.STOCK_GOTO_LAST,
3764 icon_size : Gtk.IconSize.MENU
3771 xtype: Gtk.ScrolledWindow,
3774 XObject.prototype.init.call(this);
3775 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3776 this.el.set_size_request(-1,200);
3778 shadow_type : Gtk.ShadowType.IN,
3781 xtype: Gtk.TreeView,
3784 XObject.prototype.init.call(this);
3785 this.el.set_size_request(150,-1);
3786 // set_reorderable: [1]
3788 var description = new Pango.FontDescription.c_new();
3789 description.set_size(8000);
3790 this.el.modify_font(description);
3792 this.selection = this.el.get_selection();
3793 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3794 // this.selection.signal['changed'].connect(function() {
3795 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3797 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3799 Gtk.drag_source_set (
3800 this.el, /* widget will be drag-able */
3801 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3802 null, /* lists of target to support */
3803 0, /* size of list */
3804 Gdk.DragAction.COPY /* what to do with data after dropped */
3806 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3808 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3809 Gtk.drag_source_add_text_targets(this.el);
3811 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3812 targets = new Gtk.TargetList();
3813 targets.add( LeftTree.atoms["STRING"], 0, 0);
3814 targets.add_text_targets( 1 );
3815 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3817 //if you want to allow text to be output elsewhere..
3818 //Gtk.drag_source_add_text_targets(this.el);
3822 headers_visible : false,
3823 enable_tree_lines : true,
3825 drag_begin : function (self, ctx) {
3826 // we could fill this in now...
3827 Seed.print('SOURCE: drag-begin');
3831 var iter = new Gtk.TreeIter();
3832 var s = this.selection;
3833 s.get_selected(this.get('/RightPalete.model').el, iter);
3834 var path = this.get('/RightPalete.model').el.get_path(iter);
3836 var pix = this.el.create_row_drag_icon ( path);
3839 Gtk.drag_set_icon_pixmap (ctx,
3846 var value = new GObject.Value('');
3847 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3848 if (!this.get('/RightPalete').provider) {
3851 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3852 this.el.dragData = value.value;
3859 drag_data_get : function (self, drag_context, selection_data, info, time) {
3860 //Seed.print('Palete: drag-data-get: ' + target_type);
3861 if (this.el.dragData && this.el.dragData.length ) {
3862 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3866 //this.el.dragData = "TEST from source widget";
3870 drag_end : function (self, drag_context) {
3871 Seed.print('SOURCE: drag-end');
3872 this.el.dragData = false;
3873 this.el.dropList = false;
3874 this.get('/LeftTree.view').highlight(false);
3880 xtype: Gtk.ListStore,
3883 XObject.prototype.init.call(this);
3884 this.el.set_column_types ( 2, [
3885 GObject.TYPE_STRING, // title
3886 GObject.TYPE_STRING // tip
3891 load : function(tr,iter)
3896 //console.log('Project tree load: ' + tr.length);
3897 var citer = new Gtk.TreeIter();
3898 //this.insert(citer,iter,0);
3899 for(var i =0 ; i < tr.length; i++) {
3902 this.el.append(citer);
3904 this.el.insert(citer,iter,-1);
3909 this.el.set_value(citer, 0, '' + r ); // title
3911 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3912 //if (r.cn && r.cn.length) {
3913 // this.load(r.cn, citer);
3919 getValue : function (iter, col) {
3920 var gval = new GObject.Value('');
3921 this.el.get_value(iter, col ,gval);
3928 xtype: Gtk.TreeViewColumn,
3929 pack : "append_column",
3931 XObject.prototype.init.call(this);
3932 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3936 xtype: Gtk.CellRendererText,
3958 XObject.cache['/Window'] = Window;