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
339 XObject.prototype.init.call(this);
340 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
343 activate : function (self) {
344 // this does not actually expand it..
345 // that is done by GTK..
348 if (!this.get('/Editor').save()) {
349 // popup!! - click handled..
353 if (!this.el.expanded) {
361 enter_notify_event : function (self, event) {
363 this.el.expanded = !this.el.expanded;
364 //if (this.el.expanded ) {
365 this.listeners.activate.call(this);
372 label : "Select Project or File",
373 pack : "pack_start,false,true",
375 onCollapse : function() {
377 var nb = this.get('/LeftTopPanel.notebook');
378 nb.el.set_current_page(0);
380 onExpand : function() {
381 var nb = this.get('/LeftTopPanel.notebook');
382 var pm = imports.ProjectManager.ProjectManager;
385 var model = this.get('/LeftProjectTree.combomodel');
386 // print ("loading Projects?")
387 //console.dump(pm.projects);
388 model.loadData(pm.projects);
391 nb.el.set_current_page(1);
392 //pm.on('changed', function() {
393 //console.log("CAUGHT project manager change");
394 // _combo.model.loadData(pm.projects);
402 pack : "pack_start,true,true",
404 XObject.prototype.init.call(this);
405 this.el.set_current_page(0);
412 xtype: Gtk.ScrolledWindow,
415 getActiveElement : function() { // return path to actie node.
417 var path = this.getActivePath();
422 this.get('model').el.get_iter_from_string(ret, path);
424 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
426 return JSON.parse(value);
428 getActiveFile : function() {
429 return this.get('model').file;
431 getActivePath : function() {
432 var model = this.get('model');
433 var view = this.get('view');
434 if (view.selection.count_selected_rows() < 1) {
438 view.selection.get_selected(ret);
439 return ret.model.get_path(ret.iter).to_string();
441 getPaleteProvider : function() {
442 var model = this.get('model');
443 var pm = imports.ProjectManager.ProjectManager;
444 return pm.getPalete(model.file.getType());
446 getRenderer : function() {
448 switch( this.getActiveFile().getType()) {
450 return this.get('/RightBrowser.view');
452 return this.get('/RightGtkView');
457 XObject.prototype.init.call(this);
458 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
460 renderView : function() {
461 var render = this.getRenderer();
462 var model = this.get('model');
464 render.renderJS(model.toJS(false,true)[0]);
466 print("NO RENDER JS METHOD?");
469 shadow_type : Gtk.ShadowType.IN,
474 button_press_event : function (self, ev) {
475 console.log("button press?");
477 if (!this.get('/Editor').save()) {
478 // popup!! - click handled..
482 if (ev.button.button != 3) {
483 print("click" + ev.button.button);
489 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
491 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
493 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
494 this.get('/LeftTreeMenu').el.show_all();
495 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
496 print("click:" + res.path.to_string());
499 drag_begin : function (self, ctx) {
500 print('SOURCE: drag-begin');
501 this.targetData = false;
502 // find what is selected in our tree...
504 this.selection.get_selected(ret);
506 // set some properties of the tree for use by the dropped element.
507 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
508 var data = JSON.parse(value);
509 var xname = this.get('/LeftTree.model').file.guessName(data);
511 this.el.dragData = xname;
512 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
515 // make the drag icon a picture of the node that was selected
516 var path = ret.model.get_path(ret.iter);
517 this.el.treepath = path.to_string();
519 // returns a cairo surface
520 var pix = this.el.create_row_drag_icon ( path);
522 if (Gtk.drag_set_icon_surface) {
523 Gtk.drag_set_icon_surface( ctx, pix );
525 Gtk.drag_set_icon_pixmap (ctx,
526 pix.get_colormap(), pix, null, -10, -10);
531 drag_end : function (self, drag_context) {
532 Seed.print('LEFT-TREE: drag-end');
533 this.el.dragData = false;
534 this.el.dropList = false;
535 this.targetData = false;
536 this.get('/LeftTree.view').highlight(false);
539 drag_data_get : function(self, ctx, sel_data, info, time)
549 drag_motion : function (self, ctx, x, y, time) {
550 console.log("LEFT-TREE: drag-motion");
551 var src = Gtk.drag_get_source_widget( ctx);
553 // a drag from elsewhere...- prevent drop..
555 print("no drag data!");
556 Gdk.drag_status(ctx, 0, time);
557 this.targetData = false;
560 var action = Gdk.DragAction.COPY;
561 if (src == this.el) {
562 // unless we are copying!!! ctl button..
563 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
567 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
568 // no children.. -- asume it's ok..
569 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
570 Gdk.drag_status(ctx, action ,time);
574 print("GETTING POS");
575 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
576 print("ISOVER? " + isOver);
578 Gdk.drag_status(ctx, 0 ,time);
579 return false; // not over apoint!?!
581 // drag node is parent of child..
582 console.log("SRC TREEPATH: " + src.treepath);
583 console.log("TARGET TREEPATH: " + data.path.to_string());
585 // nned to check a few here..
586 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
587 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
588 //Gtk.TreeViewDropPosition.AFTER
589 //Gtk.TreeViewDropPosition.BEFORE
591 if (typeof(src.treepath) != 'undefined' &&
592 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
593 print("subpath drag");
594 Gdk.drag_status( ctx, 0 ,time);
599 //print("DUMPING DATA");
600 //console.dump(data);
603 print(data.path.to_string() +' => '+ data.pos);
604 var tg = this.get('/LeftTree.model').findDropNodeByPath(
605 data.path.to_string(), src.dropList, data.pos);
607 this.get('/LeftTree.view').highlight(tg);
609 print("Can not find drop node path");
610 this.targetData = false;
611 Gdk.drag_status(ctx, 0, time);
614 print(JSON.stringify(tg,null,4));
616 this.targetData = tg;
619 Gdk.drag_status(ctx, action ,time);
623 drag_drop : function (w, ctx, x, y, time) {
624 Seed.print("TARGET: drag-drop");
625 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
627 ( /* will receive 'drag-data-received' signal */
628 ctx, /* represents the current state of the DnD */
629 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
630 time /* time stamp */
634 /* No target offered by source => error */
639 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
640 print("Tree: drag-data-received");
642 var delete_selection_data = false;
643 var dnd_success = false;
644 //print(JSON.stringify(sel_data, null,4));
645 /* Deal with what we are given from source */
647 // simce I can not be bothered to sort out
648 // drag drop = let's assume it worked...
650 if( true || (sel_data && sel_data.length )) {
652 if (ctx.action == Gdk.DragAction.ASK) {
653 /* Ask the user to move or copy, then set the ctx action. */
656 if (ctx.action == Gdk.DragAction.MOVE) {
657 //delete_selection_data = true;
660 var source = Gtk.drag_get_source_widget( ctx );
662 if (this.targetData) {
663 if (source != this.el) {
664 print("DRAG FROM ANOTHER WIDGET");
665 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
667 // drag around.. - reorder..
668 print("DRAG FROM SELF");
669 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
673 //Seed.print(this.targetData);
679 // we can send stuff to souce here...
685 if (dnd_success == false)
687 Seed.print ("DnD data transfer failed!\n");
690 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
693 cursor_changed : function (self) {
694 if (this.blockChanges) { // probably not needed..
697 var render = this.get('/LeftTree').getRenderer();
700 if (this.selection.count_selected_rows() < 1) {
701 this.get('/LeftPanel.model').load( false);
702 this.get('/MidPropTree').activeElement = false;
703 this.get('/MidPropTree').hideWin();
705 var pm = this.get('/RightPalete.model');
706 if (!this.get('/LeftTree').getPaleteProvider()) {
707 // it may not be loaded yet..
711 this.get('/LeftTree').getPaleteProvider().gatherList(
712 this.get('/LeftTree.model').listAllTypes()
715 if (render && render.redraw) {
721 //console.log('changed');
722 var s = this.selection;
727 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
728 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
730 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
733 var data = JSON.parse(value);
734 this.get('/MidPropTree').activeElement = data;
735 this.get('/MidPropTree').hideWin();
736 this.get('/LeftPanel.model').load( data);
739 // _g.button.set_label(''+value.get_string());
741 var pm =this.get('/RightPalete.model');
742 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
743 this.get('/LeftTree.model').listAllTypes()));
746 if (render && render.redraw) {
750 //Seed.print( value.get_string());
758 enable_tree_lines : true,
759 headers_visible : false,
760 highlight : function(treepath_ar) {
762 // highlighting for drag/drop
763 if (treepath_ar.length && treepath_ar[0].length ) {
764 this.el.set_drag_dest_row(
765 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
767 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
773 XObject.prototype.init.call(this);
774 var description = new Pango.FontDescription.c_new();
775 description.set_size(8000);
776 this.el.modify_font(description);
778 this.selection = this.el.get_selection();
779 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
782 // is this really needed??
783 this.selection.signal['changed'].connect(function() {
784 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
785 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
789 this.el.drag_source_set( /* widget will be drag-able */
790 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
791 null, /* lists of target to support */
792 0, /* size of list */
793 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
796 this.el.drag_source_set_target_list(imports.Builder3.Globals.targetList);
798 this.el.drag_source_add_text_targets();
799 this.el.drag_dest_set
801 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
802 null, /* lists of target to support */
803 0, /* size of list */
804 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
807 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
808 this.el.drag_dest_add_text_targets( );
810 selectNode : function(treepath_str) {
811 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
812 var tp = new Gtk.TreePath.from_string(treepath_str);
813 this.el.set_cursor(tp, null, false);
814 this.el.scroll_to_cell(tp, null, false, 0,0);
818 xtype: Gtk.TreeStore,
824 setFromNode : function(tp, n)
827 tp = this.get('/LeftTree').getActivePath();
830 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
831 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
832 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
833 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
837 changed : function( refresh) {
841 print("-------MODEL CHANGED CALLED" );
843 //this.currentTree = this.toJS(false, true)[0];
845 this.file.items = this.toJS(false, false);
846 print ("TO JS in " + ((new Date()) - d) + "ms");
847 // print("AFTER CHANGED");
848 //console.dump(this.file.items);
850 this.currentTree = this.file.items[0];
851 //console.log(this.file.toSource());
854 print("REDNER BROWSER?!");
855 this.get('/LeftTree').renderView();
857 var pm = this.get('/RightPalete.model');
858 if (!this.get('/RightPalete').provider) {
864 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
865 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
869 deleteSelected : function() {
870 this.get('/LeftTree.view').blockChanges = true;
872 var s = this.get('/LeftTree.view').selection;
873 s.get_selected(oret);
874 var path = this.el.get_path(oret.iter).to_string();
876 this.activePath= false;
879 this.activePath= false;
881 this.el.get_iter_from_string(ret, path);
882 this.el.remove(ret.iter);
884 // rebuild treemap. -- depreciated.!!
887 //this.toJS(null, true) // does not do anything?
888 this.activePath= false;
890 this.get('/LeftTree.view').blockChanges = false;
892 dropNode : function(target_data, node) {
894 // console.dump(node);
895 //print(JSON.Stringify(target_data, null, 4));
896 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
898 print("add " + tp + "@" + target_data[1] );
901 if (tp && target_data[1] < 2) { // before or after..
902 var ar = target_data[0].split(':');
904 parent = new Gtk.TreePath.from_string( ar.join(':') );
909 var aret = after ? {} : false;
913 if (parent !== false) {
914 this.el.get_iter(pret, parent);
921 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
922 this.el.get_iter(aret, after);
923 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
924 nret, pret.iter, aret.iter);
927 this.el.append(nret, pret.iter);
930 var new_path = this.el.get_path(nret.iter).to_string();
931 print("new path = " + new_path)
932 if (typeof(node) == 'string') {
933 var ar = node.split('.');
934 var xtype = ar.pop();
937 '|xns' : ar.join('.'),
940 if (target_data.length == 3 && target_data[2].length) {
941 node['*prop'] = target_data[2];
943 node = this.get('/DialogTemplateSelect').show(node);
946 // work out what kind of packing to use..
947 if (typeof(node.pack) == 'undefined' && parent !== false) {
948 var pal = this.get('/LeftTree').getPaleteProvider();
949 if (pal.name == 'Gtk') {
950 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
951 var cname = pal.guessName(node);
952 node.pack = pal.getDefaultPack(pname, cname);
963 // load children - if it has any..
966 this.load(xitems, nret.iter);
967 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
969 if (tp && (xitems || after)) {
970 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
972 // wee need to get the empty proptypes from somewhere..
974 //var olditer = this.activeIter;
975 //this.activePath = new_path;
976 print("calling changed with node data")
977 // changed actually set's the node data..
978 this.setFromNode(new_path,node);
983 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
985 //Builder.MidPropTree._model.load(node);
986 //Builder.MidPropTree._win.hideWin();
987 //Builder.LeftPanel._model.load( node);
991 findDropNode : function(treepath_str, targets) {
993 // this is used by the dragdrop code in the roo version AFAIR..
995 var path = treepath_str.replace(/^builder-/, '');
996 // treemap is depreciated... - should really check if model has any entries..
998 if (!this.el.iter_n_children(null)) {
1000 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
1002 print("FIND treepath: " + path);
1003 //console.dump(this.treemap);
1005 if (!treepath_str.match(/^builder-/)) {
1006 return []; // nothing!
1008 if (targets === true) {
1011 return this.findDropNodeByPath(path,targets)
1013 findDropNodeByPath : function(treepath_str, targets, pref) {
1014 var path = treepath_str + ''; // dupe it..
1015 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1017 //console.dump(this.treemap);
1018 while (path.length) {
1019 print("LOOKING FOR PATH: " + path);
1020 var node_data = this.singleNodeToJS(path);
1021 if (node_data === false) {
1022 print("node not found");
1026 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1029 targets.forEach(function(tg) {
1033 if ((tg == xname) ) {
1036 if (tg.indexOf(xname +':') === 0) {
1038 prop = tg.split(':').pop();
1043 if (last) { // pref is after/before..
1044 // then it's after last
1046 return []; // do not allow..
1048 return [ last, pref , prop];
1051 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1053 var par = path.split(':');
1056 path = par.join(':');
1062 getIterValue : function (iter, col) {
1064 var gval = ''+this.el.get_value(iter, col).value.get_string();
1070 XObject.prototype.init.call(this);
1071 this.el.set_column_types ( 3, [
1072 GObject.TYPE_STRING, // title
1073 GObject.TYPE_STRING, // tip
1074 GObject.TYPE_STRING // source..
1077 listAllTypes : function() {
1078 var s = this.get('/LeftTree.view').selection;
1079 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1081 if (s.count_selected_rows() > 0) {
1083 s.get_selected(ret);
1085 // set some properties of the tree for use by the dropped element.
1086 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1087 var data = JSON.parse(value);
1090 var xname = this.get('/LeftTree.model').file.guessName(data);
1091 console.log('selected:' + xname);
1095 return []; // could not find it..
1104 for (var i =0 ; i < li.length; i++ ) {
1107 // this is specific to roo!!!?
1108 if (!el) { // skip empty?
1111 var fullpath = _this.file.guessName(el);
1112 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1117 if (el.items && el.items.length) {
1126 addall([this.currentTree]);
1128 // only if we have nothing, should we add '*top'
1132 //console.log('all types in tree');
1133 //console.dump(ret);
1138 load : function(tr,iter)
1140 //this.insert(citer,iter,0);
1142 for(var i =0 ; i < tr.length; i++) {
1145 this.el.insert(ret ,iter,-1);
1147 this.el.append(ret);
1149 //print(JSON.stringify(ret,null,4));
1150 //print('call nodeToJSON: ' + tr[i]);
1151 var body = this.nodeToJSON(tr[i]);
1153 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1154 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1155 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1156 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1157 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1158 this.el.set_value(ret.iter, 2, '' + body );
1159 if (tr[i].items && tr[i].items.length) {
1160 this.load(tr[i].items, ret.iter);
1164 loadFile : function(f) {
1171 console.log('missing file');
1175 // load the file if not loaded..
1176 if (f.items === false) {
1178 f.loadItems(function() {
1184 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1186 if (f.items.length && typeof(f.items[0]) == 'string') {
1188 //this.get('/RightEditor').el.show();
1189 //this.get('/RightEditor.view').load( f.items[0]);
1193 //print(JSON.stringify(f.items, null,4));
1194 //console.dump(f.items);
1196 this.get('/LeftTree.view').el.expand_all();
1198 if (!f.items.length) {
1201 this.get('/Window.leftvpaned').el.set_position(80);
1203 this.get('/LeftTree.view').el.set_cursor(
1204 new Gtk.TreePath.from_string('0'), null, false);
1208 this.get('/Window.leftvpaned').el.set_position(200);
1211 //return; -- debuggin
1212 //print("hide right editior");
1213 //this.get('/RightEditor').el.hide();
1214 this.get('/Editor').el.hide();
1215 print("set current tree");
1217 this.currentTree = this.toJS(false, false)[0];
1220 //console.dump(this.currentTree);
1221 this.currentTree = this.currentTree || { items: [] };
1222 this.get('/LeftTree').renderView();
1223 // console.dump(this.map);
1224 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1225 var pm = this.get('/RightPalete.model');
1226 // set up provider..
1228 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1230 if (!this.get('/RightPalete').provider) {
1231 print ("********* PALETE PROVIDER MISSING?!!");
1233 this.get('/LeftTree').renderView();
1235 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1239 this.get('/Window.view-notebook').el.set_current_page(
1240 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1243 moveNode : function(target_data, action) {
1244 //print("MOVE NODE");
1245 // console.dump(target_data);
1247 var s = this.get('/LeftTree.view').selection;
1248 s.get_selected( oret);
1249 var node = this.nodeToJS(oret.iter,false);
1250 //console.dump(node);
1251 print(JSON.stringify(node, null,4));
1253 // needs to drop first, otherwise the target_data
1254 // treepath will be invalid.
1256 this.dropNode(target_data, node);
1257 if (action & Gdk.DragAction.MOVE) {
1258 // print("REMOVING OLD NODE");
1259 this.el.remove(oret.iter);
1263 this.activePath= false;
1266 nodeTip : function(c) {
1267 var ret = this.nodeTitle(c,true);
1273 if (!i.length || i[0] != '|') {
1279 if (typeof(c[i]) != 'string') {
1282 //print("prop : " + i + ':' + c[i]);
1283 if (!c[i].match(new RegExp('function'))) {
1286 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1290 ret+="\n\nMethods:" + funcs;
1295 nodeTitle : function(c, renderfull) {
1298 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1299 if (sr) txt.push('<s>');
1300 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1302 if (renderfull && c['|xns']) {
1303 txt.push(c['|xns']);
1306 if (c.xtype) { txt.push(c.xtype); }
1307 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1308 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1309 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1312 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1313 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1314 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1315 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1316 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1317 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1318 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1319 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1320 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1322 // for flat classes...
1323 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1324 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1327 if (sr) txt.push('</s>');
1328 return (txt.length == 0 ? "Element" : txt.join(" "));
1330 nodeToJS : function (treepath, with_id)
1332 //print("nodeToJS : WITHID: "+ with_id);
1333 var iter = treepath; // API used to be iter here..
1334 if (typeof(iter) == 'string') {
1336 if (!this.el.get_iter(ret,
1337 new Gtk.TreePath.from_string(treepath))) {
1343 var iv = this.getIterValue(iter, 2);
1344 // print("IV" + iv);
1345 var k = JSON.parse(iv);
1346 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1351 var treepath_str = this.el.get_path(iter).to_string();
1352 // not sure how we can handle mixed id stuff..
1353 if (typeof(k.id) == 'undefined') {
1354 k.id = 'builder-'+ treepath_str ;
1358 this.treemap[ treepath_str ] = k;
1359 k.xtreepath = treepath_str ;
1362 if (this.el.iter_has_child(iter)) {
1364 this.el.iter_children(cret, iter);
1365 k.items = this.toJS(cret.iter,with_id);
1369 nodeToJSON : function(c) {
1377 return JSON.stringify(o);
1379 singleNodeToJS : function (treepath)
1382 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1386 var iv = this.getIterValue(ret.iter, 2);
1388 return JSON.parse(iv);
1391 toJS : function(treepath, with_id)
1393 //print("toJS : WITHID: "+ with_id);
1395 var iter = treepath; // API used to be iter here..
1397 if (typeof(iter) == 'string') {
1399 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1411 if (!this.el.get_iter_first(ret)) {
1422 var k = this.nodeToJS(iter, with_id);
1426 if (!this.el.iter_next(iter)) {
1431 if (treepath === false) {
1433 return JSON.parse(JSON.stringify(ar));
1437 // convert the list into a json string..
1443 xtype: Gtk.TreeViewColumn,
1444 pack : "append_column",
1446 XObject.prototype.init.call(this);
1447 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1451 xtype: Gtk.CellRendererText,
1461 id : "LeftTreeMenu",
1464 xtype: Gtk.MenuItem,
1466 label : "Delete Element",
1468 activate : function (self) {
1470 this.get('/LeftTree.model').deleteSelected();
1475 xtype: Gtk.MenuItem,
1477 activate : function (self) {
1479 var tree = this.get('/LeftTree');
1480 var model = this.get('/LeftTree.model');
1481 var el = tree.getActivePath();
1483 var js = model.toJS(el, false);
1484 // print(JSON.stringify(js[0], null,4));
1485 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1490 label : "Save as Template",
1500 id : "LeftProjectTree",
1501 showNoProjectSelected : function() {
1502 this.get('/StandardErrorDialog').show("Select a Project first.");
1504 getActiveProject : function() {
1505 return this.project;
1508 leave_notify_event : function (self, event) {
1515 pack : "pack_start,false,false",
1518 xtype: Gtk.ComboBox,
1520 changed : function (self) {
1521 var fn = this.getValue();
1522 var pm = imports.ProjectManager.ProjectManager;
1523 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1527 getValue : function() {
1528 var ix = this.el.get_active();
1532 var data = imports.ProjectManager.ProjectManager.projects;
1533 if (typeof(data[ix]) == 'undefined') {
1539 XObject.prototype.init.call(this);
1540 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1542 setValue : function(fn)
1546 var data = imports.ProjectManager.ProjectManager.projects;
1547 data.forEach(function(n, ix) {
1556 xtype: Gtk.CellRendererText,
1557 pack : "pack_start,true",
1561 xtype: Gtk.ListStore,
1565 XObject.prototype.init.call(this);
1566 this.el.set_column_types ( 2, [
1567 GObject.TYPE_STRING, // real key
1568 GObject.TYPE_STRING // real type
1572 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1573 var pm = imports.ProjectManager.ProjectManager;
1575 pm.on('changed', function() {
1576 print("caught changed hook on project manager - reloading data");
1577 _this.loadData(pm.projects);
1581 loadData : function(data) {
1582 var ov = this.get('/LeftProjectTree.combo').getValue();
1586 data.forEach(function(p) {
1589 //print(JSON.stringify(XObject.keys(na)));
1590 //print(typeof(na.iter));
1591 //print(JSON.stringify(iter))
1592 el.set_value(na.iter, 0, p.fn);
1593 el.set_value(na.iter, 1, p.name);
1597 this.get('/LeftProjectTree.combo').setValue(ov);
1605 xtype: Gtk.ScrolledWindow,
1607 shadow_type : Gtk.ShadowType.IN,
1609 XObject.prototype.init.call(this);
1610 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1614 xtype: Gtk.TreeView,
1617 cursor_changed : function (self) {
1619 var model = this.get('/LeftProjectTree.model');
1623 if (model.loading) {
1628 print("LOADING IS FALSE");
1630 if (this.selection.count_selected_rows() < 1) {
1631 //XN.get('Builder.LeftTree.model').
1632 this.get('/LeftTree.model').load( false);
1636 //console.log('changed');
1637 var s = this.selection;
1638 s.get_selected(ret);
1639 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1640 //console.log(JSON.stringify(value,null,4));// id..
1641 console.log("OUT?" + value);// id..
1642 var file = this.get('/LeftProjectTree').project.getById(value);
1649 var nb = this.get('/LeftTopPanel.expander');
1650 nb.el.expanded = false;
1652 //nb.listeners.activate.call(nb);
1653 //_expander.el.set_expanded(false);
1655 var ltm = this.get('/LeftTree.model');
1663 enable_tree_lines : true,
1664 headers_visible : false,
1666 XObject.prototype.init.call(this);
1667 var description = new Pango.FontDescription.c_new();
1668 description.set_size(8000);
1669 this.el.modify_font(description);
1671 this.selection = this.el.get_selection();
1672 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1676 xtype: Gtk.TreeStore,
1681 XObject.prototype.init.call(this);
1682 this.el.set_column_types ( 3, [
1683 GObject.TYPE_STRING, // title
1684 GObject.TYPE_STRING, // tip
1685 GObject.TYPE_STRING // id..
1689 loadProject : function(pr) {
1690 print("LOAD PROJECT");
1691 var model = this.get('/LeftProjectTree.model');
1692 model.loading = true;
1699 this.get('/LeftProjectTree').project = pr;
1701 this.load(pr.toTree());
1703 this.get('/LeftProjectTree.view').el.expand_all();
1704 model.loading = false;
1707 load : function(tr,iter) {
1708 // console.dump(tr);
1711 console.log('Project tree load: ' + tr.length);
1713 //this.insert(citer,iter,0);
1717 tr.forEach(function (r) {
1719 _this.el.append(cret);
1721 _this.el.insert(cret,iter,-1);
1723 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1724 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1725 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1726 if (r.cn && r.cn.length) {
1727 _this.load(r.cn, cret.iter);
1733 getValue : function(iter, col) {
1734 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1739 xtype: Gtk.TreeViewColumn,
1740 pack : "append_column",
1742 XObject.prototype.init.call(this);
1743 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1747 xtype: Gtk.CellRendererText,
1767 pack : "pack_start,false,true,0",
1774 button_press_event : function (self, event) {
1775 this.get('/MidPropTree.model').showData('props');
1787 stock : Gtk.STOCK_ADD,
1788 icon_size : Gtk.IconSize.MENU
1802 button_press_event : function (self, event) {
1804 if (!this.get('/Editor').save()) {
1805 // popup!! - click handled..
1808 this.get('/MidPropTree.model').showData('events');
1821 stock : Gtk.STOCK_ADD,
1822 icon_size : Gtk.IconSize.MENU
1836 button_press_event : function (self, ev) {
1838 if (!this.get('/Editor').save()) {
1839 // popup!! - click handled..
1843 var p = this.get('/AddPropertyPopup');
1847 p.el.set_screen(Gdk.Screen.get_default());
1849 p.el.popup(null, null, null, null, 3, ev.button.time);
1862 stock : Gtk.STOCK_ADD,
1863 icon_size : Gtk.IconSize.MENU
1875 id : "AddPropertyPopup",
1878 xtype: Gtk.MenuItem,
1880 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1883 activate : function (self) {
1885 this.get('/LeftPanel.model').add( {
1896 xtype: Gtk.MenuItem,
1898 tooltip_markup : "Add what type of packing is to be used",
1901 activate : function (self) {
1903 this.get('/LeftPanel.model').add( {
1913 xtype: Gtk.MenuItem,
1915 tooltip_markup : "Override the init method",
1918 activate : function (self) {
1920 this.get('/LeftPanel.model').add( {
1923 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1930 xtype: Gtk.SeparatorMenuItem,
1934 xtype: Gtk.MenuItem,
1936 tooltip_markup : "Add a user defined string property",
1939 activate : function (self) {
1941 this.get('/LeftPanel.model').add( {
1951 xtype: Gtk.MenuItem,
1953 tooltip_markup : "Add a user defined number property",
1956 activate : function (self) {
1958 this.get('/LeftPanel.model').add( {
1968 xtype: Gtk.MenuItem,
1970 tooltip_markup : "Add a user defined boolean property",
1973 activate : function (self) {
1975 this.get('/LeftPanel.model').add( {
1985 xtype: Gtk.SeparatorMenuItem,
1989 xtype: Gtk.MenuItem,
1991 tooltip_markup : "Add a user function boolean property",
1994 activate : function (self) {
1996 this.get('/LeftPanel.model').add( {
1999 val : "function() {\n \n}\n",
2012 xtype: Gtk.ScrolledWindow,
2017 XObject.prototype.init.call(this);
2018 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2020 shadow_type : Gtk.ShadowType.IN,
2023 xtype: Gtk.TreeView,
2025 button_press_event : function (self, ev) {
2028 if (!this.get('/Editor').save()) {
2029 // popup!! - click handled..
2034 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2035 return false; //not on a element.
2039 if (ev.button.button == 3) {
2041 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2044 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2045 var p = this.get('/LeftPanelPopup');
2050 p.el.set_screen(Gdk.Screen.get_default());
2052 p.el.popup(null, null, null, null, 3, ev.button.time);
2053 //Seed.print("click:" + res.column.title);
2060 if (res.column.title != 'value') {
2061 // XObject.error("column is not value?");
2062 return false; // ignore.. - key click.. ??? should we do this??
2065 // currently editing???
2066 // if ( this.activePath) {
2068 // this.activePath = false;
2070 if (this.get('/Editor').dirty) {
2071 //if (!this.get('/Editor.buffer').checkSyntax()) {
2072 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2076 if (!this.get('/Editor.view').save()) {
2080 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2081 this.get('/LeftPanel').editing = false;
2083 // XObject.error("Currently editing?");
2087 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2089 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2091 // get options for this type -- this is to support option lists etc..
2092 var provider = this.get('/LeftTree').getPaleteProvider();
2093 var opts = provider.findOptions(type);
2095 if (opts === false) {
2097 this.get('/LeftPanel').editableColumn.setOptions([]);
2098 renderer.has_entry = true;
2100 this.get('/LeftPanel').editableColumn.setOptions(opts);
2101 renderer.has_entry = false;
2103 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2105 //Seed.print("click" + ev.type);
2106 //console.dump(res);
2115 enable_tree_lines : true,
2116 headers_visible : false,
2118 XObject.prototype.init.call(this);
2120 this.selection = this.el.get_selection();
2121 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2124 var description = new Pango.FontDescription.c_new();
2125 description.set_size(8000);
2126 this.el.modify_font(description);
2130 xtype: Gtk.TreeStore,
2134 add : function(info) {
2135 // info includes key, val, skel, etype..
2137 type = info.type.toLowerCase();
2138 var data = this.toJS();
2140 if (info.etype == 'events') {
2141 data.listeners = data.listeners || { };
2142 if (typeof(data.listeners[info.key]) != 'undefined') {
2143 return; //already set!
2146 if (typeof(data[info.key]) != 'undefined') {
2151 if (typeof(info.val) == 'undefined') {
2154 if (info.type.toLowerCase() == 'boolean') {
2157 if (type == 'number') {
2165 if (info.etype == 'events') {
2167 data.listeners[info.key] = info.val;
2170 data[info.key] = info.val;
2174 var map = this.load(data);
2176 // flag it as changed to the interface..
2177 this.get('/LeftTree.model').setFromNode(false,node);
2178 this.get('/LeftTree.model').changed(true);
2181 this.startEditing(map[k]);
2184 LeftPanel.get('view').el.row_activated(
2185 new Gtk.TreePath.from_string(map[k]),
2186 LeftPanel.editableColumn.el
2190 changed : function(str, doRefresh) {
2191 if (!this.activePath) {
2192 print("NO active path when changed")
2196 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2198 this.el.set_value(ret.iter, 1, '' +str);
2199 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2200 var type = this.getIterValue(ret.iter, 4);
2202 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2203 // update the tree...
2204 print("new data: " + JSON.stringify(this.toJS() , null,4));
2205 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2206 this.get('/LeftTree.model').changed(doRefresh);
2209 deleteSelected : function() {
2210 var data = this.toJS();
2212 var s = this.get('/LeftPanel.view').selection;
2213 s.get_selected( ret);
2216 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2218 if (val[0] == '!') {
2220 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2223 delete data.listeners[ val.substring(1)];
2224 if (!XObject.keys(data.listeners).length) {
2225 delete data.listeners;
2229 if (typeof(data[val]) == 'undefined') {
2239 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2240 this.get('/LeftTree.model').changed(true);
2244 getIterValue : function(iter, col) {
2245 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2248 getType : function(treepath) {
2249 return this.getValue(treepath, 4);
2251 getValue : function(treepath_str, col)
2253 // get's the value in a row.. - keys - returns string, values - formats it..
2255 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2257 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2262 var type = this.getType(this.el.get_path(ret.iter).to_string());
2263 //print("TYPE: " +type + " - val:" + val);
2264 switch(type.toLowerCase()) {
2268 return parseFloat(val); // Nan ?? invalid!!?
2271 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2273 return val == 'true' ? true : false;
2275 var nv = parseFloat(val);
2276 if (!isNaN(nv) && (val == ''+nv)) {
2284 XObject.prototype.init.call(this);
2285 this.el.set_column_types ( 6, [
2286 GObject.TYPE_STRING, // 0 real key
2287 GObject.TYPE_STRING, // 1 real value
2288 GObject.TYPE_STRING, // 2 visable key
2289 GObject.TYPE_STRING, // 3 visable value
2290 GObject.TYPE_STRING, // 4 need to store type of!!!
2291 GObject.TYPE_STRING // 5 tooltip
2295 load : function(ar) {
2296 // might casue problesm..
2297 // this.get('/Editor.RightEditor').save();
2299 this.get('/Editor').el.hide();
2300 this.get('/Editor').activePath = false;
2305 //this.get('/RightEditor').el.hide();
2312 var provider = this.get('/LeftTree').getPaleteProvider();
2316 var keys = XObject.keys(ar);
2318 ar.listeners = ar.listeners || {};
2320 for (var i in ar.listeners ) {
2322 this.el.append(iret);
2323 var p = this.el.get_path(iret.iter).to_string();
2326 this.el.set_value(iret.iter, 0, '!'+ i );
2327 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2328 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2330 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2331 this.el.set_value(iret.iter, 4, 'function');
2332 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2338 keys.forEach(function(i) {
2339 if (typeof(ar[i]) == 'object') {
2343 var type = provider.findType(ar, i, ar[i]);
2345 _this.el.append(iret);
2346 var p = _this.el.get_path(iret.iter).to_string();
2348 _this.el.set_value(iret.iter, 0, ''+i);
2349 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2350 _this.el.set_value(iret.iter, 2, ''+i);
2351 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2352 _this.el.set_value(iret.iter, 4, ''+type);
2353 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2357 startEditing : function(path,col) {
2359 // alled by menu 'edit' currently..
2361 * start editing path (or selected if not set..)
2362 * @param {String|false} path (optional) treepath to edit - selected tree gets
2363 * edited by default.
2364 * @param {Number} 0 or 1 (optional)- column to edit.
2366 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2368 if (typeof(path) == 'string') {
2369 tp = new Gtk.TreePath.from_string(path);
2372 var s = this.get('/LeftPanel.view').selection;
2373 s.get_selected( itr);
2374 tp = this.el.get_path(itr.iter);
2375 path = tp.to_string();
2379 // which colum is to be edited..
2382 // not sure what this does..
2384 if (typeof(col) == 'undefined') {
2385 var k = this.getValue(path, 0);
2387 colObj = (!k.length || k == '|') ?
2388 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2390 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2393 // make sure the pulldown is set correctly..
2394 // not really needed for second col...
2395 var showEditor = false;
2396 this.get('/Editor').activePath = false;
2397 this.get('/Editor').el.hide();
2400 var provider = this.get('/LeftTree').getPaleteProvider();
2401 var type = this.get('/LeftPanel.model').getType(path);
2402 var opts = provider.findOptions(type);
2403 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2405 if (opts === false) {
2406 this.get('/LeftPanel').editableColumn.setOptions([]);
2407 renderer.has_entry = true;
2409 this.get('/LeftPanel').editableColumn.setOptions(opts);
2410 renderer.has_entry = false;/// - pulldowns do not have entries
2412 // determine if we should use the Text editor...
2413 var keyname = this.getValue(path, 0);
2414 var data_value = this.getValue(path, 1);
2416 if ((keyname[0] == '|') ||
2418 (typeof(data_value) == 'string' ) &&
2419 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2423 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2428 // this.get('/BottomPane').el.hide();
2429 //this.get('/RightEditor').el.hide();
2434 this.activePath = false;
2436 _this.get('/Editor').el.show_all();
2437 GLib.timeout_add(0, 1, function() {
2439 //_this.get('/BottomPane').el.show();
2440 //_this.get('/RightEditor').el.show();
2442 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2444 _this.get('/Editor').activePath = path;
2445 _this.activePath = path ;
2455 // iter now has row...
2456 GLib.timeout_add(0, 100, function() {
2457 _this.activePath = path;
2458 colObj.items[0].el.editable = true; // esp. need for col 0..
2459 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2470 this.get('/LeftPanel.model').el.get_iter_first(iret);
2476 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2479 ar.listeners = ar.listeners || {};
2480 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2483 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2486 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2492 //print(JSON.stringify(ar));
2496 toShort : function(str) {
2497 var a = typeof(str) == 'string' ? str.split("\n") : [];
2498 return a.length > 1 ? a[0] + '....' : '' + str;
2502 xtype: Gtk.TreeViewColumn,
2503 pack : "append_column",
2505 XObject.prototype.init.call(this);
2507 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2508 this.get('/LeftPanel').propertyColumn = this;
2513 xtype: Gtk.CellRendererText,
2514 pack : "pack_start",
2516 editing_started : function (self, editable, path) {
2518 this.get('/LeftPanel.model').activePath = path;
2521 edited : function (self, object, p0) {
2523 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2525 var model = this.get('/LeftPanel.model');
2526 var path = model.activePath;
2528 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2529 model.el.set_value(iret.iter, 0, p0);
2530 model.el.set_value(iret.iter, 2, p0);
2532 model.activePath = false;
2533 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2534 this.get('/LeftTree.model').changed(true);
2536 this.el.editable = false;
2543 xtype: Gtk.TreeViewColumn,
2544 pack : "append_column",
2547 XObject.prototype.init.call(this);
2548 this.el.add_attribute(this.items[0].el , 'text', 3 );
2549 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2550 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2551 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2553 this.get('/LeftPanel').editableColumn= this;
2555 setOptions : function(ar) {
2556 var m = this.items[0].el.model;
2559 ar.forEach(function(i) {
2563 m.set_value(iret.iter, 0, i);
2569 xtype: Gtk.CellRendererCombo,
2571 edited : function (self, object, p0) {
2573 this.get('/LeftPanel').editing = false;
2574 var ap = this.get('/LeftPanel.model').activePath
2575 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2576 this.get('/LeftPanel.model').changed(p0, true);
2577 this.get('/LeftPanel.model').activePath = false;
2578 this.el.editable = false;
2580 editing_started : function (self, editable, path) {
2581 this.get('/LeftPanel').editing = true;
2582 // console.log('editing started');
2583 // r.has_entry = false;
2585 this.el.editable = false; // make sure it's not editor...
2590 pack : "pack_start",
2594 XObject.prototype.init.call(this);
2595 this.el.model = new Gtk.ListStore();
2596 this.el.model.set_column_types ( 1, [
2597 GObject.TYPE_STRING // 0 real key
2608 id : "LeftPanelPopup",
2611 xtype: Gtk.MenuItem,
2615 activate : function (self) {
2616 this.get('/LeftPanel.model').deleteSelected();
2621 xtype: Gtk.MenuItem,
2625 activate : function (self) {
2626 this.get('/LeftPanel.model').startEditing(false, 0);
2639 xtype: Gtk.ScrolledWindow,
2640 pack : "pack_end,false,true,0",
2643 shadow_type : Gtk.ShadowType.IN,
2645 XObject.prototype.init.call(this);
2646 XObject.prototype.init.call(this);
2647 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2648 this.el.set_size_request ( 150, -1 );
2651 activeElement : false,
2652 hideWin : function() {
2655 print("HIDEWIN - currently not shown")
2660 if (this.get('/Window.left').el.position < 160) {
2661 print("HIDEWIN - small already.")
2665 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2666 print("HIDEWIN attempting to hide.")
2673 xtype: Gtk.TreeView,
2675 cursor_changed : function (self) {
2676 // this is getting fired when we are loading elements..
2677 if (this.get('/MidPropTree.model').loading) {
2683 //console.log('changed');
2684 var m = this.get('model');
2685 if (!this.selection){
2686 this.selection = this.el.get_selection();
2689 var s = this.selection;
2690 if (!s.get_selected(iret)) {
2693 var tp = m.el.get_path(iret.iter).to_string();
2698 var key = m.getValue(tp, 0);
2700 var type = m.getValue(tp, 1);
2701 var skel = m.getValue(tp, 3);
2702 var etype = m.getValue(tp, 5);
2705 this.get('/MidPropTree').hideWin();
2707 if (type.toLowerCase() == 'function') {
2709 if (etype != 'events') {
2712 print("cursor_changed: ADDding to left panel model");
2713 this.get('/LeftPanel.model').add({
2721 // has dot in name, and is boolean???? this does not make sense..
2722 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2725 print("cursor_changed: ADDding to left panel model");
2726 this.get('/LeftPanel.model').add( {
2736 enable_tree_lines : true,
2737 headers_visible : false,
2739 XObject.prototype.init.call(this);
2741 var description = new Pango.FontDescription.c_new();
2742 description.set_size(8000);
2743 this.el.modify_font(description);
2745 //this.selection = this.el.get_selection();
2746 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2755 xtype: Gtk.ListStore,
2759 getValue : function(treepath, col)
2761 var tp = new Gtk.TreePath.from_string (treepath);
2763 this.el.get_iter (iret, tp);
2764 var value = this.el.get_value(iret.iter, col);
2765 return ''+ value.value.get_string();
2769 XObject.prototype.init.call(this);
2770 this.el.set_column_types ( 6, [
2771 GObject.TYPE_STRING, // real key
2772 GObject.TYPE_STRING, // real type
2773 GObject.TYPE_STRING, // docs ?
2774 GObject.TYPE_STRING, // visable desc
2775 GObject.TYPE_STRING, // function desc
2776 GObject.TYPE_STRING // element type (event|prop)
2780 showData : function(type) {
2783 this.loading = true;
2785 if (!this.get('/MidPropTree').activeElement || !type) {
2786 this.loading = false;
2787 return; // no active element
2790 var fullpath = this.get('/LeftTree.model').file.guessName(
2791 this.get('/MidPropTree').activeElement);
2792 var palete = this.get('/LeftTree').getPaleteProvider();
2796 Seed.print('Showing right?');
2797 if (!this.get('/MidPropTree').shown) {
2799 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2800 this.get('/MidPropTree').el.show();
2801 this.get('/MidPropTree').shown = true;
2804 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2805 return a.name > b.name ? 1 : -1;
2807 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2808 // console.dump(elementList);
2810 // scope of this is off..??
2813 for(var i =0 ; i < elementList.length; i++) {
2815 var p=elementList[i];
2816 this.el.append(iret);
2817 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2818 //GObject.TYPE_STRING, // real key
2819 // GObject.TYPE_STRING, // real type
2820 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2821 // GObject.TYPE_STRING // func def?
2824 this.el.set_value(iret.iter, 0, p.name);
2825 this.el.set_value(iret.iter, 1, p.type);
2826 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2827 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2828 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2829 this.el.set_value(iret.iter, 5, type);
2832 this.loading = false;
2836 xtype: Gtk.TreeViewColumn,
2839 this.el = new Gtk.TreeViewColumn();
2840 this.parent.el.append_column(this.el);
2842 XObject.prototype.init.call(this);
2843 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2847 xtype: Gtk.CellRendererText,
2848 pack : "pack_start,true"
2875 xtype: Gtk.Notebook,
2876 pack : "pack_start,true,true",
2877 id : "view-help-nb",
2879 XObject.prototype.init.call(this);
2880 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2881 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2885 xtype: Gtk.Notebook,
2886 id : "view-notebook",
2890 XObject.prototype.init.call(this);
2891 this.el.set_current_page(0);
2892 //print("SET LABEL?")
2893 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2894 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2900 id : "RightBrowser",
2905 pack : "pack_start,false,true,0",
2910 clicked : function (self) {
2911 this.get('/RightBrowser.view').renderJS(null,true);
2915 pack : "pack_start,false,false,0"
2918 xtype: Gtk.CheckButton,
2920 toggled : function (self, state) {
2921 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2926 label : "Auto Redraw On",
2927 pack : "pack_start,false,false,0"
2932 clicked : function (self) {
2934 var view = this.get('/RightBrowser.view');
2935 //this.get('/RightBrowser.view').redraws = 99;
2936 view.refreshRequired = true;
2937 view.lastRedraw = false;
2938 view.renderedData = false;
2939 view.renderJS(null,true);
2943 label : "Full Redraw",
2944 pack : "pack_start,false,false,0"
2949 xtype: Gtk.ScrolledWindow,
2952 XObject.prototype.init.call(this);
2953 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2955 shadow_type : Gtk.ShadowType.IN,
2958 xtype: WebKit.WebView,
2960 load_finished : function (self, object) {
2961 print("load finished");
2962 // print("load_finished"); return;
2963 // if (this.ready) { // dont do it twice!
2966 if (!this.inspectorShown) {
2967 this.el.get_inspector().show();
2968 this.inspectorShown = true;
2973 //if (this.pendingRedraw) {
2974 // this.pendingRedraw = false;
2975 // this.refreshRequired = true;
2977 //var js = this.get('/LeftTree.model').toJS();
2978 //if (js && js[0]) {
2979 // this.renderJS(js[0]);
2983 script_alert : function (self, object, p0) {
2986 return true; // do not display anything...
2988 console_message : function (self, object, p0, p1) {
2990 // console.log(object);
2993 if (object.match(/variable/) && object.match(/Builder/)) {
2994 print("got builder missing message");
2995 this.refreshRequired = true;
2996 this.lastRedraw = 0;
3002 if (!object.match(/^\{/)) {
3004 //this.get('/Terminal').feed(object);
3005 return true; // do not handle!!! -> later maybe in console..
3011 // console.log(object);
3012 var val = JSON.parse(object);
3014 if (typeof(val['hover-node']) != 'undefined') {
3015 this.activeNode = val['hover-node'];
3016 console.log('active node: ' + this.activeNode);
3021 if (typeof(val['id']) != 'undefined') {
3022 // this.activeNode = val['id'];
3023 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
3024 if (!tg || typeof(tg[0]) == 'undefined') {
3027 print("SELECT node " + tg[0]);
3029 this.get('/LeftTree.view').selectNode(tg[0]);
3034 if (ret && typeof(val['set']) != 'undefined') {
3035 print("console messages: ADDding to left panel model");
3037 //this.get('/LeftPanel.model').add({
3038 // key : val['set'],
3039 // val : val['value']
3041 //console.log('active node: ' + this.activeNode);
3044 //Seed.print('a:'+a);
3045 //Seed.print('b:'+b);
3046 //Seed.print('c:'+c);
3049 drag_motion : function (w, ctx, x, y, time, ud) {
3050 // console.log('DRAG MOTION');
3052 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3053 this.targetData = [];
3054 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3056 // A) find out from drag all the places that node could be dropped.
3057 var src = Gtk.drag_get_source_widget(ctx);
3058 if (!src.dropList) {
3059 Gdk.drag_status(ctx,0, time);
3062 // b) get what we are over.. (from activeNode)
3063 // tree is empty.. - list should be correct..
3064 if (!this.get('/LeftTree.model').currentTree) {
3065 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3069 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3071 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3074 Gdk.drag_status(ctx, 0,time);
3075 this.get('/LeftTree.view').highlight(false);
3079 // if we have a target..
3080 // -> highlight it! (in browser)
3081 // -> highlight it! (in tree)
3083 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3084 this.get('/LeftTree.view').highlight(tg);
3085 this.targetData = tg;
3086 // for tree we should handle this...
3089 drag_drop : function (w, ctx, x, y,time, ud) {
3090 print("TARGET: drag-drop");
3091 var is_valid_drop_site = true;
3095 ( /* will receive 'drag-data-received' signal */
3096 ctx, /* represents the current state of the DnD */
3097 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3098 time /* time stamp */
3102 /* No target offered by source => error */
3105 return is_valid_drop_site;
3107 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3109 print("Browser: drag-data-received");
3110 var delete_selection_data = false;
3111 vardnd_success = false;
3112 /* Deal with what we are given from source */
3113 if( sel_data && sel_data.length ) {
3115 if (ctx.action == Gdk.DragAction.ASK) {
3116 /* Ask the user to move or copy, then set the ctx action. */
3119 if (ctx.action == Gdk.DragAction.MOVE) {
3120 delete_selection_data = true;
3122 var source = Gtk.drag_get_source_widget(ctx);
3124 print("Browser: source.DRAGDATA? " + source.dragData);
3125 if (this.targetData) {
3126 print(this.targetData);
3127 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3136 if (dnd_success == false)
3138 Seed.print ("DnD data transfer failed!\n");
3141 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3144 create_web_view : function (self, object) {
3145 print("CREATE WEB VIEW");
3146 return null; //new WebKit.WebView();
3153 XObject.prototype.init.call(this);
3154 // this may not work!?
3155 var settings = this.el.get_settings();
3156 settings.enable_developer_extras = true;
3158 // this was an attempt to change the url perms.. did not work..
3159 // settings.enable_file_access_from_file_uris = true;
3160 // settings.enable_offline_web_application_cache - true;
3161 // settings.enable_universal_access_from_file_uris = true;
3165 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3166 _this.get('/BottomPane.inspector').el.show();
3167 return _this.get('/BottomPane.inspector').el;
3171 // FIXME - base url of script..
3172 // we need it so some of the database features work.
3173 this.el.load_html_string( "Render not ready" ,
3174 //fixme - should be a config option!
3175 // or should we catch stuff and fix it up..
3176 'http://localhost/app.Builder/'
3180 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3182 this.el.drag_dest_set
3183 ( /* widget that will accept a drop */
3184 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3185 null, /* lists of target to support */
3186 0, /* size of list */
3187 Gdk.DragAction.COPY /* what to do with data after dropped */
3190 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3191 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3193 GLib.timeout_add_seconds(0, 1, function() {
3194 // print("run refresh?");
3201 renderJS : function(data, force) {
3203 // this is the public redraw call..
3204 // we refresh in a loop privately..
3205 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3206 if (!autodraw && !force) {
3207 print("Skipping redraw - no force, and autodraw off");
3210 this.refreshRequired = true;
3212 runRefresh : function()
3214 // this is run every 2 seconds from the init..
3218 if (!this.refreshRequired) {
3219 // print("no refresh required");
3223 if (this.lastRedraw) {
3224 // do not redraw if last redraw was less that 5 seconds ago.
3225 if (((new Date()) - this.lastRedraw) < 5000) {
3233 if (!this.get('/Window.LeftTree').getActiveFile()) {
3236 this.refreshRequired = false;
3237 // print("HTML RENDERING");
3239 this.get('/BottomPane').el.show();
3240 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3247 var js = this.get('/LeftTree.model').toJS();
3248 if (!js || !js.length) {
3257 var project = this.get('/Window.LeftTree').getActiveFile().project;
3258 //print (project.fn);
3259 // set it to non-empty.
3260 project.runhtml = project.runhtml || '';
3261 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3264 this.runhtml = this.runhtml || '';
3266 var file = this.get('/LeftTree.model').file;
3267 var items = file.items;
3268 file.items = this.get('/LeftTree.model').toJS(false, false);
3269 //file.items[0].background = false;
3270 //var p = file.parent;
3271 //file.parent = false;
3273 var js_src = file.toSourcePreview();
3274 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3275 // unless it' sforced..
3280 this.renderedData = js_src;
3283 //file.items = items;
3284 //print("send source as " + js_src);
3287 "Roo.onReady(function() {\n" +
3288 "if (" + file.name +".show) " + file.name +".show({});\n" +
3289 "Roo.XComponent.build();\n" +
3296 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3297 // then we need to reload the browser using
3298 // load_html_string..
3300 // then trigger a redraw once it's loaded..
3301 this.pendingRedraw = true;
3302 var runhtml = '<script type="text/javascript">' + "\n" ;
3303 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3304 runhtml += '</script>'+ "\n" ;
3306 this.runhtml = project.runhtml;
3307 // need to modify paths
3310 this.lastRedraw= new Date();
3311 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3312 html = html.replace('</head>',
3315 '<script type="text/javascript">' + "\n" +
3320 //print("LOAD HTML " + html);
3321 this.el.load_html_string( html ,
3322 //fixme - should be a config option!
3323 'http://localhost/app.Builder/'
3326 // should trigger load_finished! - which in truns shoudl set refresh Required;
3331 //this.renderedData = data;
3332 //var str = JSON.stringify(data) ;
3335 console.log('not loaded yet');
3337 this.lastRedraw = new Date();
3339 this.el.execute_script("Builder.render(" +
3340 JSON.stringify(js_src) +
3342 JSON.stringify(file.name) +
3345 print( "before render" + this.lastRedraw);
3346 print( "after render" + (new Date()));
3356 id : "RightGtkView",
3358 redraw : function() {
3359 this.highlightWidget = false;
3360 print("REDRAW CALLED");
3361 this.activePath = this.get('/LeftTree').getActivePath();
3362 if (this.renderedEl) {
3363 print("QUEUE DRAW CALLING");
3364 this.renderedEl.queue_draw();
3367 renderJS : function(data, withDebug)
3369 this.highlightWidget = false;
3371 this.withDebug = false;
3372 while (this.get('view').el.get_children().length) {
3373 var c = this.get('view').el.get_children()[0];
3374 this.get('view').el.remove(c);
3381 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3382 // in theory tree is actually window..
3385 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3391 this.get('view').el.set_size_request(
3392 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3394 if (this.renderedEl) {
3395 this.renderedEl.set_size_request(
3396 tree.default_width || 600,
3397 tree.default_height || 400
3400 this.get('view').el.show_all();
3405 showInWindow : function() {
3406 print("GET PROEJCT");
3407 var pr = this.get('/LeftProjectTree').getActiveProject();
3409 console.log(pr.paths);
3412 var src= this.buildJS(
3413 this.get('/LeftTree.model').toJS()[0],
3418 //var x = new imports.sandbox.Context();
3422 Seed.check_syntax('var e = ' + src);
3425 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3426 this.get('/Terminal').feed(console._dump(e)+"\n");
3428 var lines = src.split("\n");
3429 var start = Math.max(0, e.line - 10);
3430 var end = Math.min(lines.length, e.line + 10);
3431 for (var i =start ; i < end; i++) {
3433 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3436 this.get('/Terminal').feed(lines[i] + "\n");
3443 this.get('/BottomPane').el.set_current_page(1);
3444 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3445 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3446 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3448 var _top = x.get_global_object()._top;
3450 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3452 if (_top.el.popup) {
3453 _top.el.popup(null, null, null, null, 3, null);
3457 viewAdd : function(item, par)
3460 // does something similar to xobject..
3461 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3463 // pack is forced to 'false'
3464 if (item.pack===false || item.pack === 'false') { // no ;
3468 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3471 var type = item['|xns'] + '.' + item['xtype'];
3473 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3477 var ns = imports.gi[item['|xns']];
3478 var ctr = ns[item['xtype']]; // why are we using array here..?
3483 for(var k in item) {
3485 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3499 // value is a function..
3500 if (k[0] == '|' && typeof(kv) == 'string') {
3502 if (kv.match(new RegExp('function'))) {
3505 print("WASL " + k + '=' + kv);
3507 eval( 'kv = ' + kv);
3508 } catch(e) { continue; }
3511 // print(k + '=' + kv);
3513 if (k[0] == '|') { // should be boolean or number..
3515 //print(k + '=' + kv);
3518 if (k == 'show_tabs') { // force tab showing for notebooks.
3521 print(k + '=' + typeof(kv) + " : " + kv);
3525 var altctr = XObject.baseXObject({ xtype: ctr} );
3527 if (!item.pack && altctr) {
3529 print("SETTING PACK TO XObjectBase method");
3530 pack_m = altctr.prototype.pack;
3535 var el = new ctr(ctr_args);
3537 print("PACK" + item.pack);
3538 //console.dump(item.pack);
3545 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3546 if (typeof(item.pack) == 'string') {
3548 item.pack.split(',').forEach(function(e, i) {
3550 if (e == 'false') { args.push( false); return; }
3551 if (e == 'true') { args.push( true); return; }
3552 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3555 //print(args.join(","));
3557 pack_m = args.shift();
3559 pack_m = item.pack.shift();
3564 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3566 name: "ArgumentError",
3567 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3568 "ADDING : " + item.id + " " + el
3575 //console.dump(args);
3577 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3578 //Seed.print('args: ' + args.length);
3579 if (typeof(pack_m) == 'string') {
3580 par[pack_m].apply(par, args);
3581 } else if (pack_m) {
3582 pack_m.call(item, par, item);
3586 item.items = item.items || [];
3587 item.items.forEach(function(ch,n) {
3589 print ("type:" + type);
3591 print ("ch.pack:" + ch.pack);
3594 if (type == 'Gtk.Table' && ch.pack == 'add') {
3595 var c = n % item.n_columns;
3596 var r = Math.floor(n/item.n_columns);
3597 ch.pack = [ 'attach', c, c+1, r, r+1,
3598 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3599 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3600 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3601 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3605 _this.viewAdd(ch, el);
3610 // add the signal handlers.
3611 // is it a widget!?!!?
3617 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3618 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3619 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3620 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3621 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3631 widgetDragDropEvent : function() {
3632 print("WIDGET DRAGDROP");
3635 widgetDragMotionEvent : function() {
3636 print("WIDGET DRAGMOTION");
3639 widgetExposeEvent : function(w, evt, ud, item) {
3641 if (this.inRender) {
3645 if ( this.highlightWidget) {
3646 this.inRender = true;
3647 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3648 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3650 this.inRender = false;
3655 if (this.activePath != item.xtreepath) {
3659 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3660 // work out the coords of the window..
3662 var dr = widget.window;
3663 this.gc = (new Gdk.GC.c_new(dr));
3664 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3665 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3669 var r = evt.expose.area;
3670 // console.dump([r.x, r.y, r.width, r.height ] );
3672 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3673 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3674 // happens with gtkscrollview embedded stuff..
3675 var np =this.activePath.split(':');
3677 this.activePath = np.join(':');
3678 this.renderedEl.queue_draw();
3694 this.inRender = true;
3697 this.highlightWidget = widget;
3702 // print("DRAW BOX");
3703 //console.dump(this.box);
3704 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3705 this.inRender = false;
3708 widgetPressEvent : function(w,e,u,d) {
3709 if (this.get('view').pressed) {
3712 this.get('view').pressed = true;
3713 print("WIDGET PRESS " + d.xtreepath );
3714 this.get('/LeftTree.view').selectNode( d.xtreepath );
3717 widgetReleaseEvent : function() {
3718 this.get('view').pressed = false;
3724 pack : "pack_start,false,true,0",
3728 pack : "pack_start,false,false,0",
3729 label : "Run The Application",
3731 button_press_event : function (self, event) {
3732 // call render on left tree - with special option!?!
3734 //print("GET PROEJCT");
3735 var pr = this.get('/LeftProjectTree').getActiveProject();
3738 for (var i in pr.paths) {
3742 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3743 this.get('/Terminal').feed("RUN DIR:" + dir);
3746 this.get('/Terminal').el.fork_command_full(
3747 Vte.PtyFlags.DEFAULT,
3748 GLib.path_get_dirname (__script_path__) ,
3749 [ 'echo' , "hello"], //argv
3753 null, // child setupdata
3757 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3758 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3768 xtype: Gtk.ScrolledWindow,
3771 shadow_type : Gtk.ShadowType.IN,
3773 XObject.prototype.init.call(this);
3774 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3778 xtype: Gtk.EventBox,
3779 pack : "add_with_viewport",
3781 XObject.prototype.init.call(this);
3782 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3783 red: 0x9F00, green: 0xB800 , blue : 0xA800
3791 XObject.prototype.init.call(this);
3792 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3793 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3798 xtype: Gtk.EventBox,
3801 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3802 XObject.prototype.init.call(this);
3804 this.el.drag_dest_set
3805 ( /* widget that will accept a drop */
3806 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3807 null, /* lists of target to support */
3808 0, /* size of list */
3809 Gdk.DragAction.COPY /* what to do with data after dropped */
3812 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3813 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3816 getActiveNode : function(x,y)
3818 // workout what node is here..
3819 return '0'; // top..
3823 drag_motion : function (self, ctx, x, y, time) {
3825 // A) find out from drag all the places that node could be dropped.
3826 var src = Gtk.drag_get_source_widget(ctx);
3827 if (!src.dropList) {
3828 Gdk.drag_status(ctx, 0, time);
3831 // b) get what we are over.. (from activeNode)
3832 // tree is empty.. - list should be correct..
3833 if (!this.get('/LeftTree.model').currentTree) {
3834 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3838 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3839 var activeNode = this.getActiveNode(x, y);
3842 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3845 Gdk.drag_status(ctx, 0,time);
3846 this.get('/LeftTree.view').highlight(false);
3850 // if we have a target..
3851 // -> highlight it! (in browser)
3852 // -> highlight it! (in tree)
3854 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3855 this.get('/LeftTree.view').highlight(tg);
3856 this.targetData = tg;
3857 // for tree we should handle this...
3860 drag_drop : function (self,ctx, x, y, time) {
3861 Seed.print("TARGET: drag-drop");
3862 var is_valid_drop_site = true;
3866 ( /* will receive 'drag-data-received' signal */
3867 ctx, /* represents the current state of the this.gDnD */
3868 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3869 time /* time stamp */
3873 /* No target offered by source => error */
3876 return is_valid_drop_site;
3879 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3881 Seed.print("GtkView: drag-data-received");
3882 var delete_selection_data = false;
3883 var dnd_success = false;
3884 /* Deal with what we are given from source */
3885 if( sel_data && sel_data.length ) {
3887 if (ctx.action == Gdk.DragAction.ASK) {
3888 /* Ask the user to move or copy, then set the ctx action. */
3891 if (ctx.action == Gdk.DragAction.MOVE) {
3892 delete_selection_data = true;
3894 var source = Gtk.drag_get_source_widget( ctx );
3896 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3897 if (this.targetData) {
3898 Seed.print(this.targetData);
3899 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3908 if (dnd_success == false)
3910 Seed.print ("DnD data transfer failed!\n");
3913 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3916 button_press_event : function (self, event) {
3917 this.pressed = false;
3933 xtype: Gtk.ScrolledWindow,
3938 var file = this.get('/LeftTree').getActiveFile();
3942 var activeEl = this.get('/LeftTree').getActiveElement();
3943 var xtype = file.guessName( activeEl )
3944 if (!xtype || !xtype.length) {
3947 //this.get('/Window.view-help-nb').el.set_current_page(1);
3949 // get the active element being edited.
3950 var helpurl = file.getHelpUrl(xtype);
3952 // now load the help info in the page..
3953 this.get('help-view').el.open(helpurl);
3957 xtype: WebKit.WebView,
3961 XObject.prototype.init.call(this);
3962 this.get('/Window.help-view').el.open(
3963 "http://devel.akbkhome.com/seed/");
3975 xtype: Gtk.Notebook,
3979 XObject.prototype.init.call(this);
3980 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3981 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3982 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3986 xtype: Gtk.ScrolledWindow,
3990 xtype: Vte.Terminal,
3993 feed : function(istr) {
3994 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3995 // we should make ourselves visable!!!
3996 this.get('/BottomPane').el.show();
3997 this.get('/BottomPane').el.set_current_page(1);
3999 this.el.feed(str ,str.length);
4001 scroll_on_output : true,
4003 XObject.prototype.init.call(this);
4004 this.el.set_size (80, 1000);
4006 scrollback_lines : 1000
4011 xtype: Gtk.ScrolledWindow,
4015 xtype: WebKit.WebView,
4031 this.get('buttonbar').el.show();
4032 this.get('viewbox').el.hide();
4033 var ce = this.get('/Window.centereast').el;
4035 ce.set_position(ce.get_allocated_width() - 30);
4037 print("TRIED TO HIDE");
4040 this.get('buttonbar').el.hide();
4041 this.get('viewbox').el.show();
4042 var ce = this.get('/Window.centereast').el;
4043 print(JSON.stringify(XObject.keys(ce) ,null,4));
4044 ce.set_position(ce.get_allocated_width() - 150);
4046 // this.get('model').expanded();
4058 pack : "pack_start,false,true",
4060 clicked : function (self) {
4061 this.get('/RightPalete').show();
4068 stock : Gtk.STOCK_GOTO_FIRST,
4069 icon_size : Gtk.IconSize.MENU
4079 XObject.prototype.init.call(this);
4080 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4083 enter_notify_event : function (self, event) {
4084 this.get('/RightPalete').show();
4098 pack : "pack_start,false,true",
4107 pack : "pack_start,false,true",
4109 clicked : function (self) {
4110 this.get('/RightPalete').hide();
4117 stock : Gtk.STOCK_GOTO_LAST,
4118 icon_size : Gtk.IconSize.MENU
4125 xtype: Gtk.ScrolledWindow,
4128 XObject.prototype.init.call(this);
4129 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4130 this.el.set_size_request(-1,200);
4132 shadow_type : Gtk.ShadowType.IN,
4135 xtype: Gtk.TreeView,
4137 drag_begin : function (self, ctx) {
4138 // we could fill this in now...
4139 Seed.print('SOURCE: drag-begin');
4144 var s = this.selection;
4145 s.get_selected(iret);
4146 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4148 var pix = this.el.create_row_drag_icon ( path);
4151 if (Gtk.drag_set_icon_surface) {
4152 Gtk.drag_set_icon_surface( ctx, pix );
4154 Gtk.drag_set_icon_pixmap (ctx,
4155 pix.get_colormap(), pix, null, -10, -10);
4158 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4159 if (!this.get('/RightPalete').provider) {
4162 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4163 this.el.dragData = value;
4170 drag_data_get : function (self, drag_context, selection_data, info, time) {
4171 //Seed.print('Palete: drag-data-get: ' + target_type);
4172 if (this.el.dragData && this.el.dragData.length ) {
4173 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4177 //this.el.dragData = "TEST from source widget";
4181 drag_end : function (self, drag_context) {
4182 Seed.print('SOURCE: drag-end');
4183 this.el.dragData = false;
4184 this.el.dropList = false;
4185 this.get('/LeftTree.view').highlight(false);
4188 button_press_event : function (self, event) {
4190 if (!this.get('/Editor').save()) {
4191 // popup!! - click handled..
4198 enable_tree_lines : true,
4199 headers_visible : false,
4201 XObject.prototype.init.call(this);
4202 this.el.set_size_request(150,-1);
4203 // set_reorderable: [1]
4205 var description = new Pango.FontDescription.c_new();
4206 description.set_size(8000);
4207 this.el.modify_font(description);
4209 this.selection = this.el.get_selection();
4210 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4211 // this.selection.signal['changed'].connect(function() {
4212 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4214 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4216 this.el.drag_source_set ( /* widget will be drag-able */
4217 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4218 null, /* lists of target to support */
4219 0, /* size of list */
4220 Gdk.DragAction.COPY /* what to do with data after dropped */
4222 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4224 this.el.drag_source_set_target_list( imports.Builder3.Globals.targetList);
4225 this.el.drag_source_add_text_targets( );
4227 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4228 targets = new Gtk.TargetList();
4229 targets.add( LeftTree.atoms["STRING"], 0, 0);
4230 targets.add_text_targets( 1 );
4231 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4233 //if you want to allow text to be output elsewhere..
4234 //Gtk.drag_source_add_text_targets(this.el);
4240 xtype: Gtk.ListStore,
4243 XObject.prototype.init.call(this);
4244 this.el.set_column_types ( 2, [
4245 GObject.TYPE_STRING, // title
4246 GObject.TYPE_STRING // tip
4251 load : function(tr,iter)
4256 //console.log('Project tree load: ' + tr.length);
4258 //this.insert(citer,iter,0);
4259 for(var i =0 ; i < tr.length; i++) {
4262 this.el.append(cret);
4264 this.el.insert(cret,iter,-1);
4269 this.el.set_value(cret.iter, 0, '' + r ); // title
4271 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4272 //if (r.cn && r.cn.length) {
4273 // this.load(r.cn, citer);
4279 getValue : function (iter, col) {
4280 return this.el.get_value(iter, col).value.get_string();
4287 xtype: Gtk.TreeViewColumn,
4288 pack : "append_column",
4290 XObject.prototype.init.call(this);
4291 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4295 xtype: Gtk.CellRendererText,
4317 XObject.cache['/Window'] = Window;