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;
18 delete_event : function (self, event) {
21 destroy : function (self) {
24 show : function (self) {
26 imports.ProjectManager.ProjectManager.loadConfig();
28 print("HIDEWIN - calling MidPropTree hidewin")
29 this.get('/MidPropTree').hideWin();
30 this.get('/RightPalete').hide();
31 this.get('/BottomPane').el.hide();
32 //this.get('/Editor').el.show_all();
40 title : "Application Builder",
42 setTitle : function(str) {
43 this.el.set_title(this.title + ' - ' + str);
45 type : Gtk.WindowType.TOPLEVEL,
53 pack : "pack_start,false,false",
67 label : "New _Project",
69 activate : function (self) {
71 this.get('/EditProject').show({
72 success : function(pr) {
73 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
84 activate : function (self) {
85 var fn = this.get('/LeftProjectTree.combo').getValue();
87 this.get('/LeftProjectTree').showNoProjectSelected();
90 var pm = imports.ProjectManager.ProjectManager;
91 this.get('/DialogNewComponent').show({
92 project : pm.getByFn(fn)
98 xtype: Gtk.SeparatorMenuItem,
103 use_underline : true,
105 label : "D_elete Project",
107 activate : function (self) {
109 var fn = this.get('/LeftProjectTree').get('combo').getValue();
111 this.get('/StandardErrorDialog').show("Select a project")
114 var pm = imports.ProjectManager.ProjectManager;
115 var pr = pm.getByFn(fn);
118 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
119 pm.deleteProject(fn);
127 xtype: Gtk.SeparatorMenuItem,
134 use_underline : true,
136 activate : function (self) {
148 use_underline : true,
153 pack : "set_submenu",
158 activate : function (self) {
159 var fn = this.get('/LeftTree').getActiveFile();
161 this.get('/StandardErrorDialog').show("No File active");
165 this.get('/DialogNewComponent').show(fn);
169 label : "File _Properties",
176 activate : function (self, event) {
177 this.get('/RooProjectProperties').show();
181 label : "Modify Project HTML ",
192 use_underline : true,
196 pack : "set_submenu",
201 activate : function (self, event) {
202 var js = this.get('/LeftTree.model').toJS();
204 this.get('/RightBrowser.view').renderJS(js[0], true);
209 label : "_Redraw (Roo)",
216 activate : function (self, event)
218 /* Firefox testing for debugging..
219 - we can create a /tmp directory, and put.
220 builder.html, builder.html.js, link roojs1
221 add at the end of builder.html Roo.onload(function() {
223 if (!this.get('/Window.LeftTree').getActiveFile()) {
227 var js = this.get('/LeftTree.model').toJS();
231 var project = this.get('/Window.LeftTree').getActiveFile().project;
232 //print (project.fn);
234 project.runhtml = project.runhtml || '';
237 var File = imports.File.File;
239 var target = "/tmp/firetest"; // fixme..
240 if (!File.isDirectory(target)) {
243 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
244 if (!File.exists( target+ '/roojs1')) {
245 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
250 var html = imports.File.File.read(__script_path__ + '/../builder.html');
251 html = html.replace('</head>', project.runhtml + '</head>');
254 var jsstr = JSON.stringify(js[0], null, 4);
256 var runbuilder = '<script type="text/javascript">' + "\n" +
257 " Builder.render(" + jsstr + ");\n" +
260 html = html.replace('</body>', runbuilder + '</body>');
262 File.write( target+ '/builder.html', html);
264 this.get('/Terminal').feed("RUN DIR:" + target);
266 this.get('/Terminal').el.fork_command_full(
267 Vte.PtyFlags.DEFAULT,
273 null, // child setupdata
276 var cmd = "firefox file://" + target + "/builder.html \n";
277 this.get('/Terminal').el.feed_child(cmd, cmd.length);
281 label : "_Test in Firefox (Roo)",
292 use_underline : true,
297 pack : "set_submenu",
303 use_underline : true,
305 activate : function (self) {
306 this.get('/About').el.run();
336 Gdk.EventMask.BUTTON_MOTION_MASK
340 activate : function (self) {
341 // this does not actually expand it..
342 // that is done by GTK..
345 if (!this.get('/Editor').save()) {
346 // popup!! - click handled..
350 if (!this.el.expanded) {
358 enter_notify_event : function (self, event) {
360 this.el.expanded = !this.el.expanded;
361 //if (this.el.expanded ) {
362 this.listeners.activate.call(this);
369 label : "Select Project or File",
370 pack : "pack_start,false,true",
372 onCollapse : function() {
374 var nb = this.get('/LeftTopPanel.notebook');
375 nb.el.set_current_page(0);
377 onExpand : function() {
378 var nb = this.get('/LeftTopPanel.notebook');
379 var pm = imports.ProjectManager.ProjectManager;
382 var model = this.get('/LeftProjectTree.combomodel');
383 // print ("loading Projects?")
384 //console.dump(pm.projects);
385 model.loadData(pm.projects);
388 nb.el.set_current_page(1);
389 //pm.on('changed', function() {
390 //console.log("CAUGHT project manager change");
391 // _combo.model.loadData(pm.projects);
399 pack : "pack_start,true,true",
406 xtype: Gtk.ScrolledWindow,
409 getActiveElement : function() { // return path to actie node.
411 var path = this.getActivePath();
416 this.get('model').el.get_iter_from_string(ret, path);
418 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
420 return JSON.parse(value);
422 getActiveFile : function() {
423 return this.get('model').file;
425 getActivePath : function() {
426 var model = this.get('model');
427 var view = this.get('view');
428 if (view.selection.count_selected_rows() < 1) {
432 view.selection.get_selected(ret);
433 return ret.model.get_path(ret.iter).to_string();
435 getPaleteProvider : function() {
436 var model = this.get('model');
437 var pm = imports.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');
452 renderView : function() {
453 var render = this.getRenderer();
454 var model = this.get('model');
456 render.renderJS(model.toJS(false,true)[0]);
458 print("NO RENDER JS METHOD?");
461 shadow_type : Gtk.ShadowType.IN,
466 button_press_event : function (self, ev) {
467 console.log("button press?");
469 if (!this.get('/Editor').save()) {
470 // popup!! - click handled..
474 if (ev.button.button != 3) {
475 print("click" + ev.button.button);
481 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
483 if (!this.get('/LeftTreeMenu').el) {
484 this.get('/LeftTreeMenu').init();
487 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
488 this.get('/LeftTreeMenu').el.show_all();
489 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
490 print("click:" + res.path.to_string());
493 drag_begin : function (self, ctx) {
494 print('SOURCE: drag-begin');
495 this.targetData = false;
496 // find what is selected in our tree...
498 this.selection.get_selected(ret);
500 // set some properties of the tree for use by the dropped element.
501 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
502 var data = JSON.parse(value);
503 var xname = this.get('/LeftTree.model').file.guessName(data);
505 this.el.dragData = xname;
506 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
509 // make the drag icon a picture of the node that was selected
510 var path = ret.model.get_path(ret.iter);
511 this.el.treepath = path.to_string();
513 // returns a cairo surface
514 var pix = this.el.create_row_drag_icon ( path);
516 if (Gtk.drag_set_icon_surface) {
517 Gtk.drag_set_icon_surface( ctx, pix );
519 Gtk.drag_set_icon_pixmap (ctx,
520 pix.get_colormap(), pix, null, -10, -10);
525 drag_end : function (self, drag_context) {
526 Seed.print('LEFT-TREE: drag-end');
527 this.el.dragData = false;
528 this.el.dropList = false;
529 this.targetData = false;
530 this.get('/LeftTree.view').highlight(false);
533 drag_data_get : function(self, ctx, sel_data, info, time)
543 drag_motion : function (self, ctx, x, y, time) {
544 console.log("LEFT-TREE: drag-motion");
545 var src = Gtk.drag_get_source_widget( ctx);
547 // a drag from elsewhere...- prevent drop..
549 print("no drag data!");
550 Gdk.drag_status(ctx, 0, time);
551 this.targetData = false;
554 var action = Gdk.DragAction.COPY;
555 if (src == this.el) {
556 // unless we are copying!!! ctl button..
557 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
561 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
562 // no children.. -- asume it's ok..
563 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
564 Gdk.drag_status(ctx, action ,time);
568 print("GETTING POS");
569 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
570 print("ISOVER? " + isOver);
572 Gdk.drag_status(ctx, 0 ,time);
573 return false; // not over apoint!?!
575 // drag node is parent of child..
576 console.log("SRC TREEPATH: " + src.treepath);
577 console.log("TARGET TREEPATH: " + data.path.to_string());
579 // nned to check a few here..
580 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
581 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
582 //Gtk.TreeViewDropPosition.AFTER
583 //Gtk.TreeViewDropPosition.BEFORE
585 if (typeof(src.treepath) != 'undefined' &&
586 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
587 print("subpath drag");
588 Gdk.drag_status( ctx, 0 ,time);
593 //print("DUMPING DATA");
594 //console.dump(data);
597 print(data.path.to_string() +' => '+ data.pos);
598 var tg = this.get('/LeftTree.model').findDropNodeByPath(
599 data.path.to_string(), src.dropList, data.pos);
601 this.get('/LeftTree.view').highlight(tg);
603 print("Can not find drop node path");
604 this.targetData = false;
605 Gdk.drag_status(ctx, 0, time);
608 print(JSON.stringify(tg,null,4));
610 this.targetData = tg;
613 Gdk.drag_status(ctx, action ,time);
617 drag_drop : function (w, ctx, x, y, time) {
618 Seed.print("TARGET: drag-drop");
619 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
621 ( /* will receive 'drag-data-received' signal */
622 ctx, /* represents the current state of the DnD */
623 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
624 time /* time stamp */
628 /* No target offered by source => error */
633 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
634 print("Tree: drag-data-received");
636 var delete_selection_data = false;
637 var dnd_success = false;
638 //print(JSON.stringify(sel_data, null,4));
639 /* Deal with what we are given from source */
641 // simce I can not be bothered to sort out
642 // drag drop = let's assume it worked...
644 if( true || (sel_data && sel_data.length )) {
646 if (ctx.action == Gdk.DragAction.ASK) {
647 /* Ask the user to move or copy, then set the ctx action. */
650 if (ctx.action == Gdk.DragAction.MOVE) {
651 //delete_selection_data = true;
654 var source = Gtk.drag_get_source_widget( ctx );
656 if (this.targetData) {
657 if (source != this.el) {
658 print("DRAG FROM ANOTHER WIDGET");
659 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
661 // drag around.. - reorder..
662 print("DRAG FROM SELF");
663 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
667 //Seed.print(this.targetData);
673 // we can send stuff to souce here...
679 if (dnd_success == false)
681 Seed.print ("DnD data transfer failed!\n");
684 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
687 cursor_changed : function (self) {
688 if (this.blockChanges) { // probably not needed..
691 var render = this.get('/LeftTree').getRenderer();
694 if (this.selection.count_selected_rows() < 1) {
695 this.get('/LeftPanel.model').load( false);
696 this.get('/MidPropTree').activeElement = false;
697 this.get('/MidPropTree').hideWin();
699 var pm = this.get('/RightPalete.model');
700 if (!this.get('/LeftTree').getPaleteProvider()) {
701 // it may not be loaded yet..
705 this.get('/LeftTree').getPaleteProvider().gatherList(
706 this.get('/LeftTree.model').listAllTypes()
709 if (render && render.redraw) {
715 //console.log('changed');
716 var s = this.selection;
721 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
722 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
724 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
727 var data = JSON.parse(value);
728 this.get('/MidPropTree').activeElement = data;
729 this.get('/MidPropTree').hideWin();
730 this.get('/LeftPanel.model').load( data);
733 // _g.button.set_label(''+value.get_string());
735 var pm =this.get('/RightPalete.model');
736 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
737 this.get('/LeftTree.model').listAllTypes()));
740 if (render && render.redraw) {
744 //Seed.print( value.get_string());
752 enable_tree_lines : true,
753 headers_visible : false,
754 highlight : function(treepath_ar) {
756 // highlighting for drag/drop
757 if (treepath_ar.length && treepath_ar[0].length ) {
758 this.el.set_drag_dest_row(
759 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
761 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
767 XObject.prototype.init.call(this);
768 var description = new Pango.FontDescription.c_new();
769 description.set_size(8000);
770 this.el.modify_font(description);
772 this.selection = this.el.get_selection();
773 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
776 // is this really needed??
777 this.selection.signal['changed'].connect(function() {
778 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
779 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
783 this.el.drag_source_set( /* widget will be drag-able */
784 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
785 null, /* lists of target to support */
786 0, /* size of list */
787 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
790 this.el.drag_source_set_target_list(imports.Builder3.Globals.targetList);
792 this.el.drag_source_add_text_targets();
793 this.el.drag_dest_set
795 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
796 null, /* lists of target to support */
797 0, /* size of list */
798 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
801 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
802 this.el.drag_dest_add_text_targets( );
804 selectNode : function(treepath_str) {
805 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
806 var tp = new Gtk.TreePath.from_string(treepath_str);
807 this.el.set_cursor(tp, null, false);
808 this.el.scroll_to_cell(tp, null, false, 0,0);
812 xtype: Gtk.TreeStore,
818 setFromNode : function(tp, n)
821 tp = this.get('/LeftTree').getActivePath();
824 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
825 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
826 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
827 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
831 changed : function( refresh) {
835 print("-------MODEL CHANGED CALLED" );
837 //this.currentTree = this.toJS(false, true)[0];
839 this.file.items = this.toJS(false, false);
840 print ("TO JS in " + ((new Date()) - d) + "ms");
841 // print("AFTER CHANGED");
842 //console.dump(this.file.items);
844 this.currentTree = this.file.items[0];
845 //console.log(this.file.toSource());
848 print("REDNER BROWSER?!");
849 this.get('/LeftTree').renderView();
851 var pm = this.get('/RightPalete.model');
852 if (!this.get('/RightPalete').provider) {
858 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
859 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
863 deleteSelected : function() {
864 this.get('/LeftTree.view').blockChanges = true;
866 var s = this.get('/LeftTree.view').selection;
867 s.get_selected(oret);
868 var path = this.el.get_path(oret.iter).to_string();
870 this.activePath= false;
873 this.activePath= false;
875 this.el.get_iter_from_string(ret, path);
876 this.el.remove(ret.iter);
878 // rebuild treemap. -- depreciated.!!
881 //this.toJS(null, true) // does not do anything?
882 this.activePath= false;
884 this.get('/LeftTree.view').blockChanges = false;
886 dropNode : function(target_data, node) {
888 // console.dump(node);
889 //print(JSON.Stringify(target_data, null, 4));
890 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
892 print("add " + tp + "@" + target_data[1] );
895 if (tp && target_data[1] < 2) { // before or after..
896 var ar = target_data[0].split(':');
898 parent = new Gtk.TreePath.from_string( ar.join(':') );
903 var aret = after ? {} : false;
907 if (parent !== false) {
908 this.el.get_iter(pret, parent);
915 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
916 this.el.get_iter(aret, after);
917 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
918 nret, pret.iter, aret.iter);
921 this.el.append(nret, pret.iter);
924 var new_path = this.el.get_path(nret.iter).to_string();
925 print("new path = " + new_path)
926 if (typeof(node) == 'string') {
927 var ar = node.split('.');
928 var xtype = ar.pop();
931 '|xns' : ar.join('.'),
934 if (target_data.length == 3 && target_data[2].length) {
935 node['*prop'] = target_data[2];
937 node = this.get('/DialogTemplateSelect').show(node);
940 // work out what kind of packing to use..
941 if (typeof(node.pack) == 'undefined' && parent !== false) {
942 var pal = this.get('/LeftTree').getPaleteProvider();
943 if (pal.name == 'Gtk') {
944 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
945 var cname = pal.guessName(node);
946 node.pack = pal.getDefaultPack(pname, cname);
957 // load children - if it has any..
960 this.load(xitems, nret.iter);
961 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
963 if (tp && (xitems || after)) {
964 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
966 // wee need to get the empty proptypes from somewhere..
968 //var olditer = this.activeIter;
969 //this.activePath = new_path;
970 print("calling changed with node data")
971 // changed actually set's the node data..
972 this.setFromNode(new_path,node);
977 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
979 //Builder.MidPropTree._model.load(node);
980 //Builder.MidPropTree._win.hideWin();
981 //Builder.LeftPanel._model.load( node);
985 findDropNode : function(treepath_str, targets) {
987 // this is used by the dragdrop code in the roo version AFAIR..
989 var path = treepath_str.replace(/^builder-/, '');
990 // treemap is depreciated... - should really check if model has any entries..
992 if (!this.el.iter_n_children(null)) {
994 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
996 print("FIND treepath: " + path);
997 //console.dump(this.treemap);
999 if (!treepath_str.match(/^builder-/)) {
1000 return []; // nothing!
1002 if (targets === true) {
1005 return this.findDropNodeByPath(path,targets)
1007 findDropNodeByPath : function(treepath_str, targets, pref) {
1008 var path = treepath_str + ''; // dupe it..
1009 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1011 //console.dump(this.treemap);
1012 while (path.length) {
1013 print("LOOKING FOR PATH: " + path);
1014 var node_data = this.singleNodeToJS(path);
1015 if (node_data === false) {
1016 print("node not found");
1020 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1023 targets.forEach(function(tg) {
1027 if ((tg == xname) ) {
1030 if (tg.indexOf(xname +':') === 0) {
1032 prop = tg.split(':').pop();
1037 if (last) { // pref is after/before..
1038 // then it's after last
1040 return []; // do not allow..
1042 return [ last, pref , prop];
1045 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1047 var par = path.split(':');
1050 path = par.join(':');
1056 getIterValue : function (iter, col) {
1058 var gval = ''+this.el.get_value(iter, col).value.get_string();
1067 XObject.prototype.init.call(this);
1068 this.el.set_column_types ( 3, [
1069 GObject.TYPE_STRING, // title
1070 GObject.TYPE_STRING, // tip
1071 GObject.TYPE_STRING // source..
1074 listAllTypes : function() {
1075 var s = this.get('/LeftTree.view').selection;
1076 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1078 if (s.count_selected_rows() > 0) {
1080 s.get_selected(ret);
1082 // set some properties of the tree for use by the dropped element.
1083 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1084 var data = JSON.parse(value);
1087 var xname = this.get('/LeftTree.model').file.guessName(data);
1088 console.log('selected:' + xname);
1092 return []; // could not find it..
1101 for (var i =0 ; i < li.length; i++ ) {
1104 // this is specific to roo!!!?
1105 if (!el) { // skip empty?
1108 var fullpath = _this.file.guessName(el);
1109 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1114 if (el.items && el.items.length) {
1123 addall([this.currentTree]);
1125 // only if we have nothing, should we add '*top'
1129 //console.log('all types in tree');
1130 //console.dump(ret);
1135 load : function(tr,iter)
1137 //this.insert(citer,iter,0);
1139 for(var i =0 ; i < tr.length; i++) {
1142 this.el.insert(ret ,iter,-1);
1144 this.el.append(ret);
1146 //print(JSON.stringify(ret,null,4));
1147 //print('call nodeToJSON: ' + tr[i]);
1148 var body = this.nodeToJSON(tr[i]);
1150 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1151 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1152 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1153 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1154 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1155 this.el.set_value(ret.iter, 2, '' + body );
1156 if (tr[i].items && tr[i].items.length) {
1157 this.load(tr[i].items, ret.iter);
1161 loadFile : function(f) {
1168 console.log('missing file');
1172 // load the file if not loaded..
1173 if (f.items === false) {
1175 f.loadItems(function() {
1181 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1183 if (f.items.length && typeof(f.items[0]) == 'string') {
1185 //this.get('/RightEditor').el.show();
1186 //this.get('/RightEditor.view').load( f.items[0]);
1190 //print(JSON.stringify(f.items, null,4));
1191 //console.dump(f.items);
1193 this.get('/LeftTree.view').el.expand_all();
1195 if (!f.items.length) {
1198 this.get('/Window.leftvpaned').el.set_position(80);
1200 this.get('/LeftTree.view').el.set_cursor(
1201 new Gtk.TreePath.from_string('0'), null, false);
1205 this.get('/Window.leftvpaned').el.set_position(200);
1208 //return; -- debuggin
1209 //print("hide right editior");
1210 //this.get('/RightEditor').el.hide();
1211 this.get('/Editor').el.hide();
1212 print("set current tree");
1214 this.currentTree = this.toJS(false, false)[0];
1217 //console.dump(this.currentTree);
1218 this.currentTree = this.currentTree || { items: [] };
1219 this.get('/LeftTree').renderView();
1220 // console.dump(this.map);
1221 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1222 var pm = this.get('/RightPalete.model');
1223 // set up provider..
1225 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1227 if (!this.get('/RightPalete').provider) {
1228 print ("********* PALETE PROVIDER MISSING?!!");
1230 this.get('/LeftTree').renderView();
1232 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1236 this.get('/Window.view-notebook').el.set_current_page(
1237 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1240 moveNode : function(target_data, action) {
1241 //print("MOVE NODE");
1242 // console.dump(target_data);
1244 var s = this.get('/LeftTree.view').selection;
1245 s.get_selected( oret);
1246 var node = this.nodeToJS(oret.iter,false);
1247 //console.dump(node);
1248 print(JSON.stringify(node, null,4));
1250 // needs to drop first, otherwise the target_data
1251 // treepath will be invalid.
1253 this.dropNode(target_data, node);
1254 if (action & Gdk.DragAction.MOVE) {
1255 // print("REMOVING OLD NODE");
1256 this.el.remove(oret.iter);
1260 this.activePath= false;
1263 nodeTip : function(c) {
1264 var ret = this.nodeTitle(c,true);
1270 if (!i.length || i[0] != '|') {
1276 if (typeof(c[i]) != 'string') {
1279 //print("prop : " + i + ':' + c[i]);
1280 if (!c[i].match(new RegExp('function'))) {
1283 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1287 ret+="\n\nMethods:" + funcs;
1292 nodeTitle : function(c, renderfull) {
1295 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1296 if (sr) txt.push('<s>');
1297 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1299 if (renderfull && c['|xns']) {
1300 txt.push(c['|xns']);
1303 if (c.xtype) { txt.push(c.xtype); }
1304 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1305 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1306 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1309 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1310 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1311 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1312 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1313 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1314 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1315 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1316 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1317 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1319 // for flat classes...
1320 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1321 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1324 if (sr) txt.push('</s>');
1325 return (txt.length == 0 ? "Element" : txt.join(" "));
1327 nodeToJS : function (treepath, with_id)
1329 //print("nodeToJS : WITHID: "+ with_id);
1330 var iter = treepath; // API used to be iter here..
1331 if (typeof(iter) == 'string') {
1333 if (!this.el.get_iter(ret,
1334 new Gtk.TreePath.from_string(treepath))) {
1340 var iv = this.getIterValue(iter, 2);
1341 // print("IV" + iv);
1342 var k = JSON.parse(iv);
1343 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1348 var treepath_str = this.el.get_path(iter).to_string();
1349 // not sure how we can handle mixed id stuff..
1350 if (typeof(k.id) == 'undefined') {
1351 k.id = 'builder-'+ treepath_str ;
1355 this.treemap[ treepath_str ] = k;
1356 k.xtreepath = treepath_str ;
1359 if (this.el.iter_has_child(iter)) {
1361 this.el.iter_children(cret, iter);
1362 k.items = this.toJS(cret.iter,with_id);
1366 nodeToJSON : function(c) {
1374 return JSON.stringify(o);
1376 singleNodeToJS : function (treepath)
1379 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1383 var iv = this.getIterValue(ret.iter, 2);
1385 return JSON.parse(iv);
1388 toJS : function(treepath, with_id)
1390 //print("toJS : WITHID: "+ with_id);
1392 var iter = treepath; // API used to be iter here..
1394 if (typeof(iter) == 'string') {
1396 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1408 if (!this.el.get_iter_first(ret)) {
1419 var k = this.nodeToJS(iter, with_id);
1423 if (!this.el.iter_next(iter)) {
1428 if (treepath === false) {
1430 return JSON.parse(JSON.stringify(ar));
1434 // convert the list into a json string..
1440 xtype: Gtk.TreeViewColumn,
1441 pack : "append_column",
1443 XObject.prototype.init.call(this);
1444 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1448 xtype: Gtk.CellRendererText,
1458 id : "LeftTreeMenu",
1461 xtype: Gtk.MenuItem,
1463 label : "Delete Element",
1465 activate : function (self) {
1467 this.get('/LeftTree.model').deleteSelected();
1472 xtype: Gtk.MenuItem,
1474 activate : function (self) {
1476 var tree = this.get('/LeftTree');
1477 var model = this.get('/LeftTree.model');
1478 var el = tree.getActivePath();
1480 var js = model.toJS(el, false);
1481 // print(JSON.stringify(js[0], null,4));
1482 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1487 label : "Save as Template",
1497 id : "LeftProjectTree",
1498 showNoProjectSelected : function() {
1499 this.get('/StandardErrorDialog').show("Select a Project first.");
1501 getActiveProject : function() {
1502 return this.project;
1505 leave_notify_event : function (self, event) {
1512 pack : "pack_start,false,false",
1515 xtype: Gtk.ComboBox,
1517 changed : function (self) {
1518 var fn = this.getValue();
1519 var pm = imports.ProjectManager.ProjectManager;
1520 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1524 getValue : function() {
1525 var ix = this.el.get_active();
1529 var data = imports.ProjectManager.ProjectManager.projects;
1530 if (typeof(data[ix]) == 'undefined') {
1536 XObject.prototype.init.call(this);
1537 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1539 setValue : function(fn)
1543 var data = imports.ProjectManager.ProjectManager.projects;
1544 data.forEach(function(n, ix) {
1553 xtype: Gtk.CellRendererText,
1554 pack : "pack_start,true",
1558 xtype: Gtk.ListStore,
1563 GObject.TYPE_STRING,
1569 XObject.prototype.init.call(this);
1570 this.el.set_column_types ( 2, [
1571 GObject.TYPE_STRING, // real key
1572 GObject.TYPE_STRING // real type
1576 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1577 var pm = imports.ProjectManager.ProjectManager;
1579 pm.on('changed', function() {
1580 print("caught changed hook on project manager - reloading data");
1581 _this.loadData(pm.projects);
1585 loadData : function(data) {
1586 var ov = this.get('/LeftProjectTree.combo').getValue();
1590 data.forEach(function(p) {
1593 //print(JSON.stringify(XObject.keys(na)));
1594 //print(typeof(na.iter));
1595 //print(JSON.stringify(iter))
1596 el.set_value(na.iter, 0, p.fn);
1597 el.set_value(na.iter, 1, p.name);
1601 this.get('/LeftProjectTree.combo').setValue(ov);
1609 xtype: Gtk.ScrolledWindow,
1611 shadow_type : Gtk.ShadowType.IN,
1613 XObject.prototype.init.call(this);
1614 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1618 xtype: Gtk.TreeView,
1621 cursor_changed : function (self) {
1623 var model = this.get('/LeftProjectTree.model');
1627 if (model.loading) {
1632 print("LOADING IS FALSE");
1634 if (this.selection.count_selected_rows() < 1) {
1635 //XN.get('Builder.LeftTree.model').
1636 this.get('/LeftTree.model').load( false);
1640 //console.log('changed');
1641 var s = this.selection;
1642 s.get_selected(ret);
1643 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1644 //console.log(JSON.stringify(value,null,4));// id..
1645 console.log("OUT?" + value);// id..
1646 var file = this.get('/LeftProjectTree').project.getById(value);
1653 var nb = this.get('/LeftTopPanel.expander');
1654 nb.el.expanded = false;
1656 //nb.listeners.activate.call(nb);
1657 //_expander.el.set_expanded(false);
1659 var ltm = this.get('/LeftTree.model');
1667 enable_tree_lines : true,
1668 headers_visible : false,
1670 XObject.prototype.init.call(this);
1671 var description = new Pango.FontDescription.c_new();
1672 description.set_size(8000);
1673 this.el.modify_font(description);
1675 this.selection = this.el.get_selection();
1676 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1680 xtype: Gtk.TreeStore,
1685 XObject.prototype.init.call(this);
1686 this.el.set_column_types ( 3, [
1687 GObject.TYPE_STRING, // title
1688 GObject.TYPE_STRING, // tip
1689 GObject.TYPE_STRING // id..
1693 loadProject : function(pr) {
1694 print("LOAD PROJECT");
1695 var model = this.get('/LeftProjectTree.model');
1696 model.loading = true;
1703 this.get('/LeftProjectTree').project = pr;
1705 this.load(pr.toTree());
1707 this.get('/LeftProjectTree.view').el.expand_all();
1708 model.loading = false;
1711 load : function(tr,iter) {
1712 // console.dump(tr);
1715 console.log('Project tree load: ' + tr.length);
1717 //this.insert(citer,iter,0);
1721 tr.forEach(function (r) {
1723 _this.el.append(cret);
1725 _this.el.insert(cret,iter,-1);
1727 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1728 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1729 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1730 if (r.cn && r.cn.length) {
1731 _this.load(r.cn, cret.iter);
1737 getValue : function(iter, col) {
1738 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1743 xtype: Gtk.TreeViewColumn,
1744 pack : "append_column",
1746 XObject.prototype.init.call(this);
1747 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1751 xtype: Gtk.CellRendererText,
1771 pack : "pack_start,false,true,0",
1778 button_press_event : function (self, event) {
1779 this.get('/MidPropTree.model').showData('props');
1791 stock : Gtk.STOCK_ADD,
1792 icon_size : Gtk.IconSize.MENU
1806 button_press_event : function (self, event) {
1808 if (!this.get('/Editor').save()) {
1809 // popup!! - click handled..
1812 this.get('/MidPropTree.model').showData('events');
1825 stock : Gtk.STOCK_ADD,
1826 icon_size : Gtk.IconSize.MENU
1840 button_press_event : function (self, ev) {
1842 if (!this.get('/Editor').save()) {
1843 // popup!! - click handled..
1847 var p = this.get('/AddPropertyPopup');
1851 p.el.set_screen(Gdk.Screen.get_default());
1853 p.el.popup(null, null, null, null, 3, ev.button.time);
1866 stock : Gtk.STOCK_ADD,
1867 icon_size : Gtk.IconSize.MENU
1879 id : "AddPropertyPopup",
1882 xtype: Gtk.MenuItem,
1884 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1887 activate : function (self) {
1889 this.get('/LeftPanel.model').add( {
1900 xtype: Gtk.MenuItem,
1902 tooltip_markup : "Add what type of packing is to be used",
1905 activate : function (self) {
1907 this.get('/LeftPanel.model').add( {
1917 xtype: Gtk.MenuItem,
1919 tooltip_markup : "Override the init method",
1922 activate : function (self) {
1924 this.get('/LeftPanel.model').add( {
1927 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1934 xtype: Gtk.SeparatorMenuItem,
1938 xtype: Gtk.MenuItem,
1940 tooltip_markup : "Add a user defined string property",
1943 activate : function (self) {
1945 this.get('/LeftPanel.model').add( {
1955 xtype: Gtk.MenuItem,
1957 tooltip_markup : "Add a user defined number property",
1960 activate : function (self) {
1962 this.get('/LeftPanel.model').add( {
1972 xtype: Gtk.MenuItem,
1974 tooltip_markup : "Add a user defined boolean property",
1977 activate : function (self) {
1979 this.get('/LeftPanel.model').add( {
1989 xtype: Gtk.SeparatorMenuItem,
1993 xtype: Gtk.MenuItem,
1995 tooltip_markup : "Add a user function boolean property",
1998 activate : function (self) {
2000 this.get('/LeftPanel.model').add( {
2003 val : "function() {\n \n}\n",
2016 xtype: Gtk.ScrolledWindow,
2021 XObject.prototype.init.call(this);
2022 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2024 shadow_type : Gtk.ShadowType.IN,
2027 xtype: Gtk.TreeView,
2029 button_press_event : function (self, ev) {
2032 if (!this.get('/Editor').save()) {
2033 // popup!! - click handled..
2038 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2039 return false; //not on a element.
2043 if (ev.button.button == 3) {
2045 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2048 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2049 var p = this.get('/LeftPanelPopup');
2054 p.el.set_screen(Gdk.Screen.get_default());
2056 p.el.popup(null, null, null, null, 3, ev.button.time);
2057 //Seed.print("click:" + res.column.title);
2064 if (res.column.title != 'value') {
2065 // XObject.error("column is not value?");
2066 return false; // ignore.. - key click.. ??? should we do this??
2069 // currently editing???
2070 // if ( this.activePath) {
2072 // this.activePath = false;
2074 if (this.get('/Editor').dirty) {
2075 //if (!this.get('/Editor.buffer').checkSyntax()) {
2076 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2080 if (!this.get('/Editor.view').save()) {
2084 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2085 this.get('/LeftPanel').editing = false;
2087 // XObject.error("Currently editing?");
2091 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2093 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2095 // get options for this type -- this is to support option lists etc..
2096 var provider = this.get('/LeftTree').getPaleteProvider();
2097 var opts = provider.findOptions(type);
2099 if (opts === false) {
2101 this.get('/LeftPanel').editableColumn.setOptions([]);
2102 renderer.has_entry = true;
2104 this.get('/LeftPanel').editableColumn.setOptions(opts);
2105 renderer.has_entry = false;
2107 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2109 //Seed.print("click" + ev.type);
2110 //console.dump(res);
2119 enable_tree_lines : true,
2120 headers_visible : false,
2122 XObject.prototype.init.call(this);
2124 this.selection = this.el.get_selection();
2125 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2128 var description = new Pango.FontDescription.c_new();
2129 description.set_size(8000);
2130 this.el.modify_font(description);
2134 xtype: Gtk.TreeStore,
2138 add : function(info) {
2139 // info includes key, val, skel, etype..
2141 type = info.type.toLowerCase();
2142 var data = this.toJS();
2144 if (info.etype == 'events') {
2145 data.listeners = data.listeners || { };
2146 if (typeof(data.listeners[info.key]) != 'undefined') {
2147 return; //already set!
2150 if (typeof(data[info.key]) != 'undefined') {
2155 if (typeof(info.val) == 'undefined') {
2158 if (info.type.toLowerCase() == 'boolean') {
2161 if (type == 'number') {
2169 if (info.etype == 'events') {
2171 data.listeners[info.key] = info.val;
2174 data[info.key] = info.val;
2178 var map = this.load(data);
2180 // flag it as changed to the interface..
2181 this.get('/LeftTree.model').setFromNode(false,node);
2182 this.get('/LeftTree.model').changed(true);
2185 this.startEditing(map[k]);
2188 LeftPanel.get('view').el.row_activated(
2189 new Gtk.TreePath.from_string(map[k]),
2190 LeftPanel.editableColumn.el
2194 changed : function(str, doRefresh) {
2195 if (!this.activePath) {
2196 print("NO active path when changed")
2200 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2202 this.el.set_value(ret.iter, 1, '' +str);
2203 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2204 var type = this.getIterValue(ret.iter, 4);
2206 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2207 // update the tree...
2208 print("new data: " + JSON.stringify(this.toJS() , null,4));
2209 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2210 this.get('/LeftTree.model').changed(doRefresh);
2213 deleteSelected : function() {
2214 var data = this.toJS();
2216 var s = this.get('/LeftPanel.view').selection;
2217 s.get_selected( ret);
2220 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2222 if (val[0] == '!') {
2224 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2227 delete data.listeners[ val.substring(1)];
2228 if (!XObject.keys(data.listeners).length) {
2229 delete data.listeners;
2233 if (typeof(data[val]) == 'undefined') {
2243 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2244 this.get('/LeftTree.model').changed(true);
2248 getIterValue : function(iter, col) {
2249 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2252 getType : function(treepath) {
2253 return this.getValue(treepath, 4);
2255 getValue : function(treepath_str, col)
2257 // get's the value in a row.. - keys - returns string, values - formats it..
2259 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2261 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2266 var type = this.getType(this.el.get_path(ret.iter).to_string());
2267 //print("TYPE: " +type + " - val:" + val);
2268 switch(type.toLowerCase()) {
2272 return parseFloat(val); // Nan ?? invalid!!?
2275 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2277 return val == 'true' ? true : false;
2279 var nv = parseFloat(val);
2280 if (!isNaN(nv) && (val == ''+nv)) {
2288 XObject.prototype.init.call(this);
2289 this.el.set_column_types ( 6, [
2290 GObject.TYPE_STRING, // 0 real key
2291 GObject.TYPE_STRING, // 1 real value
2292 GObject.TYPE_STRING, // 2 visable key
2293 GObject.TYPE_STRING, // 3 visable value
2294 GObject.TYPE_STRING, // 4 need to store type of!!!
2295 GObject.TYPE_STRING // 5 tooltip
2299 load : function(ar) {
2300 // might casue problesm..
2301 // this.get('/Editor.RightEditor').save();
2303 this.get('/Editor').el.hide();
2304 this.get('/Editor').activePath = false;
2309 //this.get('/RightEditor').el.hide();
2316 var provider = this.get('/LeftTree').getPaleteProvider();
2320 var keys = XObject.keys(ar);
2322 ar.listeners = ar.listeners || {};
2324 for (var i in ar.listeners ) {
2326 this.el.append(iret);
2327 var p = this.el.get_path(iret.iter).to_string();
2330 this.el.set_value(iret.iter, 0, '!'+ i );
2331 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2332 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2334 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2335 this.el.set_value(iret.iter, 4, 'function');
2336 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2342 keys.forEach(function(i) {
2343 if (typeof(ar[i]) == 'object') {
2347 var type = provider.findType(ar, i, ar[i]);
2349 _this.el.append(iret);
2350 var p = _this.el.get_path(iret.iter).to_string();
2352 _this.el.set_value(iret.iter, 0, ''+i);
2353 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2354 _this.el.set_value(iret.iter, 2, ''+i);
2355 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2356 _this.el.set_value(iret.iter, 4, ''+type);
2357 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2361 startEditing : function(path,col) {
2363 // alled by menu 'edit' currently..
2365 * start editing path (or selected if not set..)
2366 * @param {String|false} path (optional) treepath to edit - selected tree gets
2367 * edited by default.
2368 * @param {Number} 0 or 1 (optional)- column to edit.
2370 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2372 if (typeof(path) == 'string') {
2373 tp = new Gtk.TreePath.from_string(path);
2376 var s = this.get('/LeftPanel.view').selection;
2377 s.get_selected( itr);
2378 tp = this.el.get_path(itr.iter);
2379 path = tp.to_string();
2383 // which colum is to be edited..
2386 // not sure what this does..
2388 if (typeof(col) == 'undefined') {
2389 var k = this.getValue(path, 0);
2391 colObj = (!k.length || k == '|') ?
2392 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2394 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2397 // make sure the pulldown is set correctly..
2398 // not really needed for second col...
2399 var showEditor = false;
2400 this.get('/Editor').activePath = false;
2401 this.get('/Editor').el.hide();
2404 var provider = this.get('/LeftTree').getPaleteProvider();
2405 var type = this.get('/LeftPanel.model').getType(path);
2406 var opts = provider.findOptions(type);
2407 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2409 if (opts === false) {
2410 this.get('/LeftPanel').editableColumn.setOptions([]);
2411 renderer.has_entry = true;
2413 this.get('/LeftPanel').editableColumn.setOptions(opts);
2414 renderer.has_entry = false;/// - pulldowns do not have entries
2416 // determine if we should use the Text editor...
2417 var keyname = this.getValue(path, 0);
2418 var data_value = this.getValue(path, 1);
2420 if ((keyname[0] == '|') ||
2422 (typeof(data_value) == 'string' ) &&
2423 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2427 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2432 // this.get('/BottomPane').el.hide();
2433 //this.get('/RightEditor').el.hide();
2438 this.activePath = false;
2440 _this.get('/Editor').el.show_all();
2441 GLib.timeout_add(0, 1, function() {
2443 //_this.get('/BottomPane').el.show();
2444 //_this.get('/RightEditor').el.show();
2446 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2448 _this.get('/Editor').activePath = path;
2449 _this.activePath = path ;
2459 // iter now has row...
2460 GLib.timeout_add(0, 100, function() {
2461 _this.activePath = path;
2462 colObj.items[0].el.editable = true; // esp. need for col 0..
2463 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2474 this.get('/LeftPanel.model').el.get_iter_first(iret);
2480 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2483 ar.listeners = ar.listeners || {};
2484 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2487 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2490 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2496 //print(JSON.stringify(ar));
2500 toShort : function(str) {
2501 var a = typeof(str) == 'string' ? str.split("\n") : [];
2502 return a.length > 1 ? a[0] + '....' : '' + str;
2506 xtype: Gtk.TreeViewColumn,
2507 pack : "append_column",
2509 XObject.prototype.init.call(this);
2511 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2512 this.get('/LeftPanel').propertyColumn = this;
2517 xtype: Gtk.CellRendererText,
2518 pack : "pack_start",
2520 editing_started : function (self, editable, path) {
2522 this.get('/LeftPanel.model').activePath = path;
2525 edited : function (self, object, p0) {
2527 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2529 var model = this.get('/LeftPanel.model');
2530 var path = model.activePath;
2532 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2533 model.el.set_value(iret.iter, 0, p0);
2534 model.el.set_value(iret.iter, 2, p0);
2536 model.activePath = false;
2537 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2538 this.get('/LeftTree.model').changed(true);
2540 this.el.editable = false;
2547 xtype: Gtk.TreeViewColumn,
2548 pack : "append_column",
2551 XObject.prototype.init.call(this);
2552 this.el.add_attribute(this.items[0].el , 'text', 3 );
2553 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2554 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2555 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2557 this.get('/LeftPanel').editableColumn= this;
2559 setOptions : function(ar) {
2560 var m = this.items[0].el.model;
2563 ar.forEach(function(i) {
2567 m.set_value(iret.iter, 0, i);
2573 xtype: Gtk.CellRendererCombo,
2575 edited : function (self, object, p0) {
2577 this.get('/LeftPanel').editing = false;
2578 var ap = this.get('/LeftPanel.model').activePath
2579 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2580 this.get('/LeftPanel.model').changed(p0, true);
2581 this.get('/LeftPanel.model').activePath = false;
2582 this.el.editable = false;
2584 editing_started : function (self, editable, path) {
2585 this.get('/LeftPanel').editing = true;
2586 // console.log('editing started');
2587 // r.has_entry = false;
2589 this.el.editable = false; // make sure it's not editor...
2594 pack : "pack_start",
2598 XObject.prototype.init.call(this);
2599 this.el.model = new Gtk.ListStore();
2600 this.el.model.set_column_types ( 1, [
2601 GObject.TYPE_STRING // 0 real key
2612 id : "LeftPanelPopup",
2615 xtype: Gtk.MenuItem,
2619 activate : function (self) {
2620 this.get('/LeftPanel.model').deleteSelected();
2625 xtype: Gtk.MenuItem,
2629 activate : function (self) {
2630 this.get('/LeftPanel.model').startEditing(false, 0);
2643 xtype: Gtk.ScrolledWindow,
2644 pack : "pack_end,false,true,0",
2647 shadow_type : Gtk.ShadowType.IN,
2649 XObject.prototype.init.call(this);
2650 XObject.prototype.init.call(this);
2651 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2652 this.el.set_size_request ( 150, -1 );
2655 activeElement : false,
2656 hideWin : function() {
2659 print("HIDEWIN - currently not shown")
2664 if (this.get('/Window.left').el.position < 160) {
2665 print("HIDEWIN - small already.")
2669 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2670 print("HIDEWIN attempting to hide.")
2677 xtype: Gtk.TreeView,
2679 cursor_changed : function (self) {
2680 // this is getting fired when we are loading elements..
2681 if (this.get('/MidPropTree.model').loading) {
2687 //console.log('changed');
2688 var m = this.get('model');
2689 if (!this.selection){
2690 this.selection = this.el.get_selection();
2693 var s = this.selection;
2694 if (!s.get_selected(iret)) {
2697 var tp = m.el.get_path(iret.iter).to_string();
2702 var key = m.getValue(tp, 0);
2704 var type = m.getValue(tp, 1);
2705 var skel = m.getValue(tp, 3);
2706 var etype = m.getValue(tp, 5);
2709 this.get('/MidPropTree').hideWin();
2711 if (type.toLowerCase() == 'function') {
2713 if (etype != 'events') {
2716 print("cursor_changed: ADDding to left panel model");
2717 this.get('/LeftPanel.model').add({
2725 // has dot in name, and is boolean???? this does not make sense..
2726 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2729 print("cursor_changed: ADDding to left panel model");
2730 this.get('/LeftPanel.model').add( {
2740 enable_tree_lines : true,
2741 headers_visible : false,
2743 XObject.prototype.init.call(this);
2745 var description = new Pango.FontDescription.c_new();
2746 description.set_size(8000);
2747 this.el.modify_font(description);
2749 //this.selection = this.el.get_selection();
2750 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2759 xtype: Gtk.ListStore,
2763 getValue : function(treepath, col)
2765 var tp = new Gtk.TreePath.from_string (treepath);
2767 this.el.get_iter (iret, tp);
2768 var value = this.el.get_value(iret.iter, col);
2769 return ''+ value.value.get_string();
2773 XObject.prototype.init.call(this);
2774 this.el.set_column_types ( 6, [
2775 GObject.TYPE_STRING, // real key
2776 GObject.TYPE_STRING, // real type
2777 GObject.TYPE_STRING, // docs ?
2778 GObject.TYPE_STRING, // visable desc
2779 GObject.TYPE_STRING, // function desc
2780 GObject.TYPE_STRING // element type (event|prop)
2784 showData : function(type) {
2787 this.loading = true;
2789 if (!this.get('/MidPropTree').activeElement || !type) {
2790 this.loading = false;
2791 return; // no active element
2794 var fullpath = this.get('/LeftTree.model').file.guessName(
2795 this.get('/MidPropTree').activeElement);
2796 var palete = this.get('/LeftTree').getPaleteProvider();
2800 Seed.print('Showing right?');
2801 if (!this.get('/MidPropTree').shown) {
2803 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2804 this.get('/MidPropTree').el.show();
2805 this.get('/MidPropTree').shown = true;
2808 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2809 return a.name > b.name ? 1 : -1;
2811 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2812 // console.dump(elementList);
2814 // scope of this is off..??
2817 for(var i =0 ; i < elementList.length; i++) {
2819 var p=elementList[i];
2820 this.el.append(iret);
2821 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2822 //GObject.TYPE_STRING, // real key
2823 // GObject.TYPE_STRING, // real type
2824 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2825 // GObject.TYPE_STRING // func def?
2828 this.el.set_value(iret.iter, 0, p.name);
2829 this.el.set_value(iret.iter, 1, p.type);
2830 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2831 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2832 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2833 this.el.set_value(iret.iter, 5, type);
2836 this.loading = false;
2840 xtype: Gtk.TreeViewColumn,
2843 this.el = new Gtk.TreeViewColumn();
2844 this.parent.el.append_column(this.el);
2846 XObject.prototype.init.call(this);
2847 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2851 xtype: Gtk.CellRendererText,
2852 pack : "pack_start,true"
2879 xtype: Gtk.Notebook,
2880 pack : "pack_start,true,true",
2881 id : "view-help-nb",
2883 XObject.prototype.init.call(this);
2884 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2885 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2889 xtype: Gtk.Notebook,
2890 id : "view-notebook",
2894 XObject.prototype.init.call(this);
2895 this.el.set_current_page(0);
2896 //print("SET LABEL?")
2897 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2898 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2904 id : "RightBrowser",
2909 pack : "pack_start,false,true,0",
2914 clicked : function (self) {
2915 this.get('/RightBrowser.view').renderJS(null,true);
2919 pack : "pack_start,false,false,0"
2922 xtype: Gtk.CheckButton,
2924 toggled : function (self, state) {
2925 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2930 label : "Auto Redraw On",
2931 pack : "pack_start,false,false,0"
2936 clicked : function (self) {
2938 var view = this.get('/RightBrowser.view');
2939 //this.get('/RightBrowser.view').redraws = 99;
2940 view.refreshRequired = true;
2941 view.lastRedraw = false;
2942 view.renderedData = false;
2943 view.renderJS(null,true);
2947 label : "Full Redraw",
2948 pack : "pack_start,false,false,0"
2953 xtype: Gtk.ScrolledWindow,
2956 XObject.prototype.init.call(this);
2957 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2959 shadow_type : Gtk.ShadowType.IN,
2962 xtype: WebKit.WebView,
2964 load_finished : function (self, object) {
2965 print("load finished");
2966 // print("load_finished"); return;
2967 // if (this.ready) { // dont do it twice!
2970 if (!this.inspectorShown) {
2971 this.el.get_inspector().show();
2972 this.inspectorShown = true;
2977 //if (this.pendingRedraw) {
2978 // this.pendingRedraw = false;
2979 // this.refreshRequired = true;
2981 //var js = this.get('/LeftTree.model').toJS();
2982 //if (js && js[0]) {
2983 // this.renderJS(js[0]);
2987 script_alert : function (self, object, p0) {
2990 return true; // do not display anything...
2992 console_message : function (self, object, p0, p1) {
2994 // console.log(object);
2997 if (object.match(/variable/) && object.match(/Builder/)) {
2998 print("got builder missing message");
2999 this.refreshRequired = true;
3000 this.lastRedraw = 0;
3006 if (!object.match(/^\{/)) {
3008 //this.get('/Terminal').feed(object);
3009 return true; // do not handle!!! -> later maybe in console..
3015 // console.log(object);
3016 var val = JSON.parse(object);
3018 if (typeof(val['hover-node']) != 'undefined') {
3019 this.activeNode = val['hover-node'];
3020 console.log('active node: ' + this.activeNode);
3025 if (typeof(val['id']) != 'undefined') {
3026 // this.activeNode = val['id'];
3027 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
3028 if (!tg || typeof(tg[0]) == 'undefined') {
3031 print("SELECT node " + tg[0]);
3033 this.get('/LeftTree.view').selectNode(tg[0]);
3038 if (ret && typeof(val['set']) != 'undefined') {
3039 print("console messages: ADDding to left panel model");
3041 //this.get('/LeftPanel.model').add({
3042 // key : val['set'],
3043 // val : val['value']
3045 //console.log('active node: ' + this.activeNode);
3048 //Seed.print('a:'+a);
3049 //Seed.print('b:'+b);
3050 //Seed.print('c:'+c);
3053 drag_motion : function (w, ctx, x, y, time, ud) {
3054 // console.log('DRAG MOTION');
3056 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3057 this.targetData = [];
3058 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3060 // A) find out from drag all the places that node could be dropped.
3061 var src = Gtk.drag_get_source_widget(ctx);
3062 if (!src.dropList) {
3063 Gdk.drag_status(ctx,0, time);
3066 // b) get what we are over.. (from activeNode)
3067 // tree is empty.. - list should be correct..
3068 if (!this.get('/LeftTree.model').currentTree) {
3069 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3073 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3075 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3078 Gdk.drag_status(ctx, 0,time);
3079 this.get('/LeftTree.view').highlight(false);
3083 // if we have a target..
3084 // -> highlight it! (in browser)
3085 // -> highlight it! (in tree)
3087 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3088 this.get('/LeftTree.view').highlight(tg);
3089 this.targetData = tg;
3090 // for tree we should handle this...
3093 drag_drop : function (w, ctx, x, y,time, ud) {
3094 print("TARGET: drag-drop");
3095 var is_valid_drop_site = true;
3099 ( /* will receive 'drag-data-received' signal */
3100 ctx, /* represents the current state of the DnD */
3101 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3102 time /* time stamp */
3106 /* No target offered by source => error */
3109 return is_valid_drop_site;
3111 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3113 print("Browser: drag-data-received");
3114 var delete_selection_data = false;
3115 vardnd_success = false;
3116 /* Deal with what we are given from source */
3117 if( sel_data && sel_data.length ) {
3119 if (ctx.action == Gdk.DragAction.ASK) {
3120 /* Ask the user to move or copy, then set the ctx action. */
3123 if (ctx.action == Gdk.DragAction.MOVE) {
3124 delete_selection_data = true;
3126 var source = Gtk.drag_get_source_widget(ctx);
3128 print("Browser: source.DRAGDATA? " + source.dragData);
3129 if (this.targetData) {
3130 print(this.targetData);
3131 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3140 if (dnd_success == false)
3142 Seed.print ("DnD data transfer failed!\n");
3145 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3148 create_web_view : function (self, object) {
3149 print("CREATE WEB VIEW");
3150 return null; //new WebKit.WebView();
3157 XObject.prototype.init.call(this);
3158 // this may not work!?
3159 var settings = this.el.get_settings();
3160 settings.enable_developer_extras = true;
3162 // this was an attempt to change the url perms.. did not work..
3163 // settings.enable_file_access_from_file_uris = true;
3164 // settings.enable_offline_web_application_cache - true;
3165 // settings.enable_universal_access_from_file_uris = true;
3169 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3170 _this.get('/BottomPane.inspector').el.show();
3171 return _this.get('/BottomPane.inspector').el;
3175 // FIXME - base url of script..
3176 // we need it so some of the database features work.
3177 this.el.load_html_string( "Render not ready" ,
3178 //fixme - should be a config option!
3179 // or should we catch stuff and fix it up..
3180 'http://localhost/app.Builder/'
3184 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3186 this.el.drag_dest_set
3187 ( /* widget that will accept a drop */
3188 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3189 null, /* lists of target to support */
3190 0, /* size of list */
3191 Gdk.DragAction.COPY /* what to do with data after dropped */
3194 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3195 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3197 GLib.timeout_add_seconds(0, 1, function() {
3198 // print("run refresh?");
3205 renderJS : function(data, force) {
3207 // this is the public redraw call..
3208 // we refresh in a loop privately..
3209 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3210 if (!autodraw && !force) {
3211 print("Skipping redraw - no force, and autodraw off");
3214 this.refreshRequired = true;
3216 runRefresh : function()
3218 // this is run every 2 seconds from the init..
3222 if (!this.refreshRequired) {
3223 // print("no refresh required");
3227 if (this.lastRedraw) {
3228 // do not redraw if last redraw was less that 5 seconds ago.
3229 if (((new Date()) - this.lastRedraw) < 5000) {
3237 if (!this.get('/Window.LeftTree').getActiveFile()) {
3240 this.refreshRequired = false;
3241 // print("HTML RENDERING");
3243 this.get('/BottomPane').el.show();
3244 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3251 var js = this.get('/LeftTree.model').toJS();
3252 if (!js || !js.length) {
3261 var project = this.get('/Window.LeftTree').getActiveFile().project;
3262 //print (project.fn);
3263 // set it to non-empty.
3264 project.runhtml = project.runhtml || '';
3265 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3268 this.runhtml = this.runhtml || '';
3270 var file = this.get('/LeftTree.model').file;
3271 var items = file.items;
3272 file.items = this.get('/LeftTree.model').toJS(false, false);
3273 //file.items[0].background = false;
3274 //var p = file.parent;
3275 //file.parent = false;
3277 var js_src = file.toSourcePreview();
3278 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3279 // unless it' sforced..
3284 this.renderedData = js_src;
3287 //file.items = items;
3288 //print("send source as " + js_src);
3291 "Roo.onReady(function() {\n" +
3292 "if (" + file.name +".show) " + file.name +".show({});\n" +
3293 "Roo.XComponent.build();\n" +
3300 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3301 // then we need to reload the browser using
3302 // load_html_string..
3304 // then trigger a redraw once it's loaded..
3305 this.pendingRedraw = true;
3306 var runhtml = '<script type="text/javascript">' + "\n" ;
3307 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3308 runhtml += '</script>'+ "\n" ;
3310 this.runhtml = project.runhtml;
3311 // need to modify paths
3314 this.lastRedraw= new Date();
3315 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3316 html = html.replace('</head>',
3319 '<script type="text/javascript">' + "\n" +
3324 //print("LOAD HTML " + html);
3325 this.el.load_html_string( html ,
3326 //fixme - should be a config option!
3327 'http://localhost/app.Builder/'
3330 // should trigger load_finished! - which in truns shoudl set refresh Required;
3335 //this.renderedData = data;
3336 //var str = JSON.stringify(data) ;
3339 console.log('not loaded yet');
3341 this.lastRedraw = new Date();
3343 this.el.execute_script("Builder.render(" +
3344 JSON.stringify(js_src) +
3346 JSON.stringify(file.name) +
3349 print( "before render" + this.lastRedraw);
3350 print( "after render" + (new Date()));
3360 id : "RightGtkView",
3362 redraw : function() {
3363 this.highlightWidget = false;
3364 print("REDRAW CALLED");
3365 this.activePath = this.get('/LeftTree').getActivePath();
3366 if (this.renderedEl) {
3367 print("QUEUE DRAW CALLING");
3368 this.renderedEl.queue_draw();
3371 renderJS : function(data, withDebug)
3373 this.highlightWidget = false;
3375 this.withDebug = false;
3376 while (this.get('view').el.get_children().length) {
3377 var c = this.get('view').el.get_children()[0];
3378 this.get('view').el.remove(c);
3385 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3386 // in theory tree is actually window..
3389 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3395 this.get('view').el.set_size_request(
3396 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3398 if (this.renderedEl) {
3399 this.renderedEl.set_size_request(
3400 tree.default_width || 600,
3401 tree.default_height || 400
3404 this.get('view').el.show_all();
3409 showInWindow : function() {
3410 print("GET PROEJCT");
3411 var pr = this.get('/LeftProjectTree').getActiveProject();
3413 console.log(pr.paths);
3416 var src= this.buildJS(
3417 this.get('/LeftTree.model').toJS()[0],
3422 //var x = new imports.sandbox.Context();
3426 Seed.check_syntax('var e = ' + src);
3429 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3430 this.get('/Terminal').feed(console._dump(e)+"\n");
3432 var lines = src.split("\n");
3433 var start = Math.max(0, e.line - 10);
3434 var end = Math.min(lines.length, e.line + 10);
3435 for (var i =start ; i < end; i++) {
3437 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3440 this.get('/Terminal').feed(lines[i] + "\n");
3447 this.get('/BottomPane').el.set_current_page(1);
3448 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3449 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3450 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3452 var _top = x.get_global_object()._top;
3454 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3456 if (_top.el.popup) {
3457 _top.el.popup(null, null, null, null, 3, null);
3461 viewAdd : function(item, par)
3464 // does something similar to xobject..
3465 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3467 // pack is forced to 'false'
3468 if (item.pack===false || item.pack === 'false') { // no ;
3472 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3475 var type = item['|xns'] + '.' + item['xtype'];
3477 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3481 var ns = imports.gi[item['|xns']];
3482 var ctr = ns[item['xtype']]; // why are we using array here..?
3487 for(var k in item) {
3489 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3503 // value is a function..
3504 if (k[0] == '|' && typeof(kv) == 'string') {
3506 if (kv.match(new RegExp('function'))) {
3509 print("WASL " + k + '=' + kv);
3511 eval( 'kv = ' + kv);
3512 } catch(e) { continue; }
3515 // print(k + '=' + kv);
3517 if (k[0] == '|') { // should be boolean or number..
3519 //print(k + '=' + kv);
3522 if (k == 'show_tabs') { // force tab showing for notebooks.
3525 print(k + '=' + typeof(kv) + " : " + kv);
3529 var altctr = XObject.baseXObject({ xtype: ctr} );
3531 if (!item.pack && altctr) {
3533 print("SETTING PACK TO XObjectBase method");
3534 pack_m = altctr.prototype.pack;
3539 var el = new ctr(ctr_args);
3541 print("PACK" + item.pack);
3542 //console.dump(item.pack);
3549 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3550 if (typeof(item.pack) == 'string') {
3552 item.pack.split(',').forEach(function(e, i) {
3554 if (e == 'false') { args.push( false); return; }
3555 if (e == 'true') { args.push( true); return; }
3556 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3559 //print(args.join(","));
3561 pack_m = args.shift();
3563 pack_m = item.pack.shift();
3568 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3570 name: "ArgumentError",
3571 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3572 "ADDING : " + item.id + " " + el
3579 //console.dump(args);
3581 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3582 //Seed.print('args: ' + args.length);
3583 if (typeof(pack_m) == 'string') {
3584 par[pack_m].apply(par, args);
3585 } else if (pack_m) {
3586 pack_m.call(item, par, item);
3590 item.items = item.items || [];
3591 item.items.forEach(function(ch,n) {
3593 print ("type:" + type);
3595 print ("ch.pack:" + ch.pack);
3598 if (type == 'Gtk.Table' && ch.pack == 'add') {
3599 var c = n % item.n_columns;
3600 var r = Math.floor(n/item.n_columns);
3601 ch.pack = [ 'attach', c, c+1, r, r+1,
3602 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3603 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3604 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3605 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3609 _this.viewAdd(ch, el);
3614 // add the signal handlers.
3615 // is it a widget!?!!?
3621 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3622 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3623 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3624 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3625 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3635 widgetDragDropEvent : function() {
3636 print("WIDGET DRAGDROP");
3639 widgetDragMotionEvent : function() {
3640 print("WIDGET DRAGMOTION");
3643 widgetExposeEvent : function(w, evt, ud, item) {
3645 if (this.inRender) {
3649 if ( this.highlightWidget) {
3650 this.inRender = true;
3651 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3652 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3654 this.inRender = false;
3659 if (this.activePath != item.xtreepath) {
3663 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3664 // work out the coords of the window..
3666 var dr = widget.window;
3667 this.gc = (new Gdk.GC.c_new(dr));
3668 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3669 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3673 var r = evt.expose.area;
3674 // console.dump([r.x, r.y, r.width, r.height ] );
3676 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3677 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3678 // happens with gtkscrollview embedded stuff..
3679 var np =this.activePath.split(':');
3681 this.activePath = np.join(':');
3682 this.renderedEl.queue_draw();
3698 this.inRender = true;
3701 this.highlightWidget = widget;
3706 // print("DRAW BOX");
3707 //console.dump(this.box);
3708 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3709 this.inRender = false;
3712 widgetPressEvent : function(w,e,u,d) {
3713 if (this.get('view').pressed) {
3716 this.get('view').pressed = true;
3717 print("WIDGET PRESS " + d.xtreepath );
3718 this.get('/LeftTree.view').selectNode( d.xtreepath );
3721 widgetReleaseEvent : function() {
3722 this.get('view').pressed = false;
3728 pack : "pack_start,false,true,0",
3732 pack : "pack_start,false,false,0",
3733 label : "Run The Application",
3735 button_press_event : function (self, event) {
3736 // call render on left tree - with special option!?!
3738 //print("GET PROEJCT");
3739 var pr = this.get('/LeftProjectTree').getActiveProject();
3742 for (var i in pr.paths) {
3746 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3747 this.get('/Terminal').feed("RUN DIR:" + dir);
3750 this.get('/Terminal').el.fork_command_full(
3751 Vte.PtyFlags.DEFAULT,
3752 GLib.path_get_dirname (__script_path__) ,
3753 [ 'echo' , "hello"], //argv
3757 null, // child setupdata
3761 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3762 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3772 xtype: Gtk.ScrolledWindow,
3775 shadow_type : Gtk.ShadowType.IN,
3777 XObject.prototype.init.call(this);
3778 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3782 xtype: Gtk.EventBox,
3783 pack : "add_with_viewport",
3785 XObject.prototype.init.call(this);
3786 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3787 red: 0x9F00, green: 0xB800 , blue : 0xA800
3795 XObject.prototype.init.call(this);
3796 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3797 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3802 xtype: Gtk.EventBox,
3805 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3806 XObject.prototype.init.call(this);
3808 this.el.drag_dest_set
3809 ( /* widget that will accept a drop */
3810 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3811 null, /* lists of target to support */
3812 0, /* size of list */
3813 Gdk.DragAction.COPY /* what to do with data after dropped */
3816 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3817 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3820 getActiveNode : function(x,y)
3822 // workout what node is here..
3823 return '0'; // top..
3827 drag_motion : function (self, ctx, x, y, time) {
3829 // A) find out from drag all the places that node could be dropped.
3830 var src = Gtk.drag_get_source_widget(ctx);
3831 if (!src.dropList) {
3832 Gdk.drag_status(ctx, 0, time);
3835 // b) get what we are over.. (from activeNode)
3836 // tree is empty.. - list should be correct..
3837 if (!this.get('/LeftTree.model').currentTree) {
3838 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3842 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3843 var activeNode = this.getActiveNode(x, y);
3846 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3849 Gdk.drag_status(ctx, 0,time);
3850 this.get('/LeftTree.view').highlight(false);
3854 // if we have a target..
3855 // -> highlight it! (in browser)
3856 // -> highlight it! (in tree)
3858 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3859 this.get('/LeftTree.view').highlight(tg);
3860 this.targetData = tg;
3861 // for tree we should handle this...
3864 drag_drop : function (self,ctx, x, y, time) {
3865 Seed.print("TARGET: drag-drop");
3866 var is_valid_drop_site = true;
3870 ( /* will receive 'drag-data-received' signal */
3871 ctx, /* represents the current state of the this.gDnD */
3872 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3873 time /* time stamp */
3877 /* No target offered by source => error */
3880 return is_valid_drop_site;
3883 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3885 Seed.print("GtkView: drag-data-received");
3886 var delete_selection_data = false;
3887 var dnd_success = false;
3888 /* Deal with what we are given from source */
3889 if( sel_data && sel_data.length ) {
3891 if (ctx.action == Gdk.DragAction.ASK) {
3892 /* Ask the user to move or copy, then set the ctx action. */
3895 if (ctx.action == Gdk.DragAction.MOVE) {
3896 delete_selection_data = true;
3898 var source = Gtk.drag_get_source_widget( ctx );
3900 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3901 if (this.targetData) {
3902 Seed.print(this.targetData);
3903 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3912 if (dnd_success == false)
3914 Seed.print ("DnD data transfer failed!\n");
3917 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3920 button_press_event : function (self, event) {
3921 this.pressed = false;
3937 xtype: Gtk.ScrolledWindow,
3942 var file = this.get('/LeftTree').getActiveFile();
3946 var activeEl = this.get('/LeftTree').getActiveElement();
3947 var xtype = file.guessName( activeEl )
3948 if (!xtype || !xtype.length) {
3951 //this.get('/Window.view-help-nb').el.set_current_page(1);
3953 // get the active element being edited.
3954 var helpurl = file.getHelpUrl(xtype);
3956 // now load the help info in the page..
3957 this.get('help-view').el.open(helpurl);
3961 xtype: WebKit.WebView,
3965 XObject.prototype.init.call(this);
3966 this.get('/Window.help-view').el.open(
3967 "http://devel.akbkhome.com/seed/");
3979 xtype: Gtk.Notebook,
3983 XObject.prototype.init.call(this);
3984 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3985 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3986 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3990 xtype: Gtk.ScrolledWindow,
3994 xtype: Vte.Terminal,
3997 feed : function(istr) {
3998 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3999 // we should make ourselves visable!!!
4000 this.get('/BottomPane').el.show();
4001 this.get('/BottomPane').el.set_current_page(1);
4003 this.el.feed(str ,str.length);
4005 scroll_on_output : true,
4007 XObject.prototype.init.call(this);
4008 this.el.set_size (80, 1000);
4010 scrollback_lines : 1000
4015 xtype: Gtk.ScrolledWindow,
4019 xtype: WebKit.WebView,
4035 this.get('buttonbar').el.show();
4036 this.get('viewbox').el.hide();
4037 var ce = this.get('/Window.centereast').el;
4039 ce.set_position(ce.get_allocated_width() - 30);
4041 print("TRIED TO HIDE");
4044 this.get('buttonbar').el.hide();
4045 this.get('viewbox').el.show();
4046 var ce = this.get('/Window.centereast').el;
4047 print(JSON.stringify(XObject.keys(ce) ,null,4));
4048 ce.set_position(ce.get_allocated_width() - 150);
4050 // this.get('model').expanded();
4062 pack : "pack_start,false,true",
4064 clicked : function (self) {
4065 this.get('/RightPalete').show();
4072 stock : Gtk.STOCK_GOTO_FIRST,
4073 icon_size : Gtk.IconSize.MENU
4083 XObject.prototype.init.call(this);
4084 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4087 enter_notify_event : function (self, event) {
4088 this.get('/RightPalete').show();
4102 pack : "pack_start,false,true",
4111 pack : "pack_start,false,true",
4113 clicked : function (self) {
4114 this.get('/RightPalete').hide();
4121 stock : Gtk.STOCK_GOTO_LAST,
4122 icon_size : Gtk.IconSize.MENU
4129 xtype: Gtk.ScrolledWindow,
4132 XObject.prototype.init.call(this);
4133 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4134 this.el.set_size_request(-1,200);
4136 shadow_type : Gtk.ShadowType.IN,
4139 xtype: Gtk.TreeView,
4141 drag_begin : function (self, ctx) {
4142 // we could fill this in now...
4143 Seed.print('SOURCE: drag-begin');
4148 var s = this.selection;
4149 s.get_selected(iret);
4150 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4152 var pix = this.el.create_row_drag_icon ( path);
4155 if (Gtk.drag_set_icon_surface) {
4156 Gtk.drag_set_icon_surface( ctx, pix );
4158 Gtk.drag_set_icon_pixmap (ctx,
4159 pix.get_colormap(), pix, null, -10, -10);
4162 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4163 if (!this.get('/RightPalete').provider) {
4166 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4167 this.el.dragData = value;
4174 drag_data_get : function (self, drag_context, selection_data, info, time) {
4175 //Seed.print('Palete: drag-data-get: ' + target_type);
4176 if (this.el.dragData && this.el.dragData.length ) {
4177 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4181 //this.el.dragData = "TEST from source widget";
4185 drag_end : function (self, drag_context) {
4186 Seed.print('SOURCE: drag-end');
4187 this.el.dragData = false;
4188 this.el.dropList = false;
4189 this.get('/LeftTree.view').highlight(false);
4192 button_press_event : function (self, event) {
4194 if (!this.get('/Editor').save()) {
4195 // popup!! - click handled..
4202 enable_tree_lines : true,
4203 headers_visible : false,
4205 XObject.prototype.init.call(this);
4206 this.el.set_size_request(150,-1);
4207 // set_reorderable: [1]
4209 var description = new Pango.FontDescription.c_new();
4210 description.set_size(8000);
4211 this.el.modify_font(description);
4213 this.selection = this.el.get_selection();
4214 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4215 // this.selection.signal['changed'].connect(function() {
4216 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4218 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4220 this.el.drag_source_set ( /* widget will be drag-able */
4221 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4222 null, /* lists of target to support */
4223 0, /* size of list */
4224 Gdk.DragAction.COPY /* what to do with data after dropped */
4226 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4228 this.el.drag_source_set_target_list( imports.Builder3.Globals.targetList);
4229 this.el.drag_source_add_text_targets( );
4231 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4232 targets = new Gtk.TargetList();
4233 targets.add( LeftTree.atoms["STRING"], 0, 0);
4234 targets.add_text_targets( 1 );
4235 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4237 //if you want to allow text to be output elsewhere..
4238 //Gtk.drag_source_add_text_targets(this.el);
4244 xtype: Gtk.ListStore,
4247 XObject.prototype.init.call(this);
4248 this.el.set_column_types ( 2, [
4249 GObject.TYPE_STRING, // title
4250 GObject.TYPE_STRING // tip
4255 load : function(tr,iter)
4260 //console.log('Project tree load: ' + tr.length);
4262 //this.insert(citer,iter,0);
4263 for(var i =0 ; i < tr.length; i++) {
4266 this.el.append(cret);
4268 this.el.insert(cret,iter,-1);
4273 this.el.set_value(cret.iter, 0, '' + r ); // title
4275 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4276 //if (r.cn && r.cn.length) {
4277 // this.load(r.cn, citer);
4283 getValue : function (iter, col) {
4284 return this.el.get_value(iter, col).value.get_string();
4291 xtype: Gtk.TreeViewColumn,
4292 pack : "append_column",
4294 XObject.prototype.init.call(this);
4295 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4299 xtype: Gtk.CellRendererText,
4321 XObject.cache['/Window'] = Window;