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",
43 //imports.ProjectManager.ProjectManager.loadConfig();
45 XObject.prototype.init.call(this);
51 setTitle : function(str) {
52 this.el.set_title(this.title + ' - ' + str);
54 type : Gtk.WindowType.TOPLEVEL,
62 pack : "pack_start,false,false",
76 label : "New _Project",
78 activate : function (self) {
80 this.get('/EditProject').show({
81 success : function(pr) {
82 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
93 activate : function (self) {
94 var fn = this.get('/LeftProjectTree.combo').getValue();
96 this.get('/LeftProjectTree').showNoProjectSelected();
99 var pm = imports.ProjectManager.ProjectManager;
100 this.get('/DialogNewComponent').show({
101 project : pm.getByFn(fn)
107 xtype: Gtk.SeparatorMenuItem,
112 use_underline : true,
114 label : "D_elete Project",
116 activate : function (self) {
118 var fn = this.get('/LeftProjectTree').get('combo').getValue();
120 this.get('/StandardErrorDialog').show("Select a project")
123 var pm = imports.ProjectManager.ProjectManager;
124 var pr = pm.getByFn(fn);
127 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
128 pm.deleteProject(fn);
136 xtype: Gtk.SeparatorMenuItem,
143 use_underline : true,
145 activate : function (self) {
157 use_underline : true,
162 pack : "set_submenu",
167 activate : function (self) {
168 var fn = this.get('/LeftTree').getActiveFile();
170 this.get('/StandardErrorDialog').show("No File active");
174 this.get('/DialogNewComponent').show(fn);
178 label : "File _Properties",
185 activate : function (self, event) {
186 this.get('/RooProjectProperties').show();
190 label : "Modify Project HTML ",
201 use_underline : true,
205 pack : "set_submenu",
210 activate : function (self, event) {
211 var js = this.get('/LeftTree.model').toJS();
213 this.get('/RightBrowser.view').renderJS(js[0], true);
218 label : "_Redraw (Roo)",
225 activate : function (self, event)
227 /* Firefox testing for debugging..
228 - we can create a /tmp directory, and put.
229 builder.html, builder.html.js, link roojs1
230 add at the end of builder.html Roo.onload(function() {
232 if (!this.get('/Window.LeftTree').getActiveFile()) {
236 var js = this.get('/LeftTree.model').toJS();
240 var project = this.get('/Window.LeftTree').getActiveFile().project;
241 //print (project.fn);
243 project.runhtml = project.runhtml || '';
246 var File = imports.File.File;
248 var target = "/tmp/firetest"; // fixme..
249 if (!File.isDirectory(target)) {
252 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
253 if (!File.exists( target+ '/roojs1')) {
254 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
259 var html = imports.File.File.read(__script_path__ + '/../builder.html');
260 html = html.replace('</head>', project.runhtml + '</head>');
263 var jsstr = JSON.stringify(js[0], null, 4);
265 var runbuilder = '<script type="text/javascript">' + "\n" +
266 " Builder.render(" + jsstr + ");\n" +
269 html = html.replace('</body>', runbuilder + '</body>');
271 File.write( target+ '/builder.html', html);
273 this.get('/Terminal').feed("RUN DIR:" + target);
275 this.get('/Terminal').el.fork_command_full(
276 Vte.PtyFlags.DEFAULT,
282 null, // child setupdata
285 var cmd = "firefox file://" + target + "/builder.html \n";
286 this.get('/Terminal').el.feed_child(cmd, cmd.length);
290 label : "_Test in Firefox (Roo)",
301 use_underline : true,
306 pack : "set_submenu",
312 use_underline : true,
314 activate : function (self) {
315 this.get('/About').el.run();
345 activate : function (self) {
346 // this does not actually expand it..
347 // that is done by GTK..
350 if (!this.get('/Editor').save()) {
351 // popup!! - click handled..
355 if (!this.el.expanded) {
363 enter_notify_event : function (self, event) {
365 this.el.expanded = !this.el.expanded;
366 //if (this.el.expanded ) {
367 this.listeners.activate.call(this);
374 label : "Select Project or File",
375 pack : "pack_start,false,true",
377 XObject.prototype.init.call(this);
378 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
380 onCollapse : function() {
382 var nb = this.get('/LeftTopPanel.notebook');
383 nb.el.set_current_page(0);
385 onExpand : function() {
386 var nb = this.get('/LeftTopPanel.notebook');
387 var pm = imports.ProjectManager.ProjectManager;
390 var model = this.get('/LeftProjectTree.combomodel');
391 // print ("loading Projects?")
392 //console.dump(pm.projects);
393 model.loadData(pm.projects);
396 nb.el.set_current_page(1);
397 //pm.on('changed', function() {
398 //console.log("CAUGHT project manager change");
399 // _combo.model.loadData(pm.projects);
407 pack : "pack_start,true,true",
409 XObject.prototype.init.call(this);
410 this.el.set_current_page(0);
417 xtype: Gtk.ScrolledWindow,
420 getActiveElement : function() { // return path to actie node.
422 var path = this.getActivePath();
427 this.get('model').el.get_iter_from_string(ret, path);
429 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
431 return JSON.parse(value);
433 getActiveFile : function() {
434 return this.get('model').file;
436 getActivePath : function() {
437 var model = this.get('model');
438 var view = this.get('view');
439 if (view.selection.count_selected_rows() < 1) {
443 view.selection.get_selected(ret);
444 return ret.model.get_path(ret.iter).to_string();
446 getPaleteProvider : function() {
447 var model = this.get('model');
448 var pm = imports.ProjectManager.ProjectManager;
449 return pm.getPalete(model.file.getType());
451 getRenderer : function() {
453 switch( this.getActiveFile().getType()) {
455 return this.get('/RightBrowser.view');
457 return this.get('/RightGtkView');
462 XObject.prototype.init.call(this);
463 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
465 renderView : function() {
466 var render = this.getRenderer();
467 var model = this.get('model');
469 render.renderJS(model.toJS(false,true)[0]);
471 print("NO RENDER JS METHOD?");
474 shadow_type : Gtk.ShadowType.IN,
479 button_press_event : function (self, ev) {
480 console.log("button press?");
482 if (!this.get('/Editor').save()) {
483 // popup!! - click handled..
487 if (ev.button.button != 3) {
488 print("click" + ev.button.button);
494 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
496 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
498 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
499 this.get('/LeftTreeMenu').el.show_all();
500 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
501 print("click:" + res.path.to_string());
504 drag_begin : function (self, ctx) {
505 print('SOURCE: drag-begin');
506 this.targetData = false;
507 // find what is selected in our tree...
509 this.selection.get_selected(ret);
511 // set some properties of the tree for use by the dropped element.
512 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
513 var data = JSON.parse(value);
514 var xname = this.get('/LeftTree.model').file.guessName(data);
516 this.el.dragData = xname;
517 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
520 // make the drag icon a picture of the node that was selected
521 var path = ret.model.get_path(ret.iter);
522 this.el.treepath = path.to_string();
524 // returns a cairo surface
525 var pix = this.el.create_row_drag_icon ( path);
527 if (Gtk.drag_set_icon_surface) {
528 Gtk.drag_set_icon_surface( ctx, pix );
530 Gtk.drag_set_icon_pixmap (ctx,
531 pix.get_colormap(), pix, null, -10, -10);
536 drag_end : function (self, drag_context) {
537 Seed.print('LEFT-TREE: drag-end');
538 this.el.dragData = false;
539 this.el.dropList = false;
540 this.targetData = false;
541 this.get('/LeftTree.view').highlight(false);
544 drag_data_get : function(self, ctx, sel_data, info, time)
554 drag_motion : function (self, ctx, x, y, time) {
555 console.log("LEFT-TREE: drag-motion");
556 var src = Gtk.drag_get_source_widget( ctx);
558 // a drag from elsewhere...- prevent drop..
560 print("no drag data!");
561 Gdk.drag_status(ctx, 0, time);
562 this.targetData = false;
565 var action = Gdk.DragAction.COPY;
566 if (src == this.el) {
567 // unless we are copying!!! ctl button..
568 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
572 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
573 // no children.. -- asume it's ok..
574 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
575 Gdk.drag_status(ctx, action ,time);
579 print("GETTING POS");
580 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
581 print("ISOVER? " + isOver);
583 Gdk.drag_status(ctx, 0 ,time);
584 return false; // not over apoint!?!
586 // drag node is parent of child..
587 console.log("SRC TREEPATH: " + src.treepath);
588 console.log("TARGET TREEPATH: " + data.path.to_string());
590 // nned to check a few here..
591 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
592 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
593 //Gtk.TreeViewDropPosition.AFTER
594 //Gtk.TreeViewDropPosition.BEFORE
596 if (typeof(src.treepath) != 'undefined' &&
597 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
598 print("subpath drag");
599 Gdk.drag_status( ctx, 0 ,time);
604 //print("DUMPING DATA");
605 //console.dump(data);
608 print(data.path.to_string() +' => '+ data.pos);
609 var tg = this.get('/LeftTree.model').findDropNodeByPath(
610 data.path.to_string(), src.dropList, data.pos);
612 this.get('/LeftTree.view').highlight(tg);
614 print("Can not find drop node path");
615 this.targetData = false;
616 Gdk.drag_status(ctx, 0, time);
619 print(JSON.stringify(tg,null,4));
621 this.targetData = tg;
624 Gdk.drag_status(ctx, action ,time);
628 drag_drop : function (w, ctx, x, y, time) {
629 Seed.print("TARGET: drag-drop");
630 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
632 ( /* will receive 'drag-data-received' signal */
633 ctx, /* represents the current state of the DnD */
634 imports.Builder3.Main.atoms["STRING"], /* the target type we want */
635 time /* time stamp */
639 /* No target offered by source => error */
644 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
645 print("Tree: drag-data-received");
647 var delete_selection_data = false;
648 var dnd_success = false;
649 //print(JSON.stringify(sel_data, null,4));
650 /* Deal with what we are given from source */
652 // simce I can not be bothered to sort out
653 // drag drop = let's assume it worked...
655 if( true || (sel_data && sel_data.length )) {
657 if (ctx.action == Gdk.DragAction.ASK) {
658 /* Ask the user to move or copy, then set the ctx action. */
661 if (ctx.action == Gdk.DragAction.MOVE) {
662 //delete_selection_data = true;
665 var source = Gtk.drag_get_source_widget( ctx );
667 if (this.targetData) {
668 if (source != this.el) {
669 print("DRAG FROM ANOTHER WIDGET");
670 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
672 // drag around.. - reorder..
673 print("DRAG FROM SELF");
674 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
678 //Seed.print(this.targetData);
684 // we can send stuff to souce here...
690 if (dnd_success == false)
692 Seed.print ("DnD data transfer failed!\n");
695 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
698 cursor_changed : function (self) {
699 if (this.blockChanges) { // probably not needed..
702 var render = this.get('/LeftTree').getRenderer();
705 if (this.selection.count_selected_rows() < 1) {
706 this.get('/LeftPanel.model').load( false);
707 this.get('/MidPropTree').activeElement = false;
708 this.get('/MidPropTree').hideWin();
710 var pm = this.get('/RightPalete.model');
711 if (!this.get('/LeftTree').getPaleteProvider()) {
712 // it may not be loaded yet..
716 this.get('/LeftTree').getPaleteProvider().gatherList(
717 this.get('/LeftTree.model').listAllTypes()
720 if (render && render.redraw) {
726 //console.log('changed');
727 var s = this.selection;
732 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
733 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
735 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
738 var data = JSON.parse(value);
739 this.get('/MidPropTree').activeElement = data;
740 this.get('/MidPropTree').hideWin();
741 this.get('/LeftPanel.model').load( data);
744 // _g.button.set_label(''+value.get_string());
746 var pm =this.get('/RightPalete.model');
747 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
748 this.get('/LeftTree.model').listAllTypes()));
751 if (render && render.redraw) {
755 //Seed.print( value.get_string());
763 enable_tree_lines : true,
764 headers_visible : false,
765 highlight : function(treepath_ar) {
767 // highlighting for drag/drop
768 if (treepath_ar.length && treepath_ar[0].length ) {
769 this.el.set_drag_dest_row(
770 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
772 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
778 XObject.prototype.init.call(this);
779 var description = new Pango.FontDescription.c_new();
780 description.set_size(8000);
781 this.el.modify_font(description);
783 this.selection = this.el.get_selection();
784 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
787 // is this really needed??
788 this.selection.signal['changed'].connect(function() {
789 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
790 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
794 this.el.drag_source_set( /* widget will be drag-able */
795 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
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_source_set_target_list(imports.Builder3.Main.targetList);
803 this.el.drag_source_add_text_targets();
804 this.el.drag_dest_set
806 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
807 null, /* lists of target to support */
808 0, /* size of list */
809 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
812 this.el.drag_dest_set_target_list( imports.Builder3.Main.targetList);
813 this.el.drag_dest_add_text_targets( );
815 selectNode : function(treepath_str) {
816 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
817 var tp = new Gtk.TreePath.from_string(treepath_str);
818 this.el.set_cursor(tp, null, false);
819 this.el.scroll_to_cell(tp, null, false, 0,0);
823 xtype: Gtk.TreeStore,
829 setFromNode : function(tp, n)
832 tp = this.get('/LeftTree').getActivePath();
835 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
836 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
837 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
838 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
842 changed : function( refresh) {
846 print("-------MODEL CHANGED CALLED" );
848 //this.currentTree = this.toJS(false, true)[0];
850 this.file.items = this.toJS(false, false);
851 print ("TO JS in " + ((new Date()) - d) + "ms");
852 // print("AFTER CHANGED");
853 //console.dump(this.file.items);
855 this.currentTree = this.file.items[0];
856 //console.log(this.file.toSource());
859 print("REDNER BROWSER?!");
860 this.get('/LeftTree').renderView();
862 var pm = this.get('/RightPalete.model');
863 if (!this.get('/RightPalete').provider) {
869 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
870 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
874 deleteSelected : function() {
875 this.get('/LeftTree.view').blockChanges = true;
877 var s = this.get('/LeftTree.view').selection;
878 s.get_selected(oret);
879 var path = this.el.get_path(oret.iter).to_string();
881 this.activePath= false;
884 this.activePath= false;
886 this.el.get_iter_from_string(ret, path);
887 this.el.remove(ret.iter);
889 // rebuild treemap. -- depreciated.!!
892 //this.toJS(null, true) // does not do anything?
893 this.activePath= false;
895 this.get('/LeftTree.view').blockChanges = false;
897 dropNode : function(target_data, node) {
899 // console.dump(node);
900 //print(JSON.Stringify(target_data, null, 4));
901 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
903 print("add " + tp + "@" + target_data[1] );
906 if (tp && target_data[1] < 2) { // before or after..
907 var ar = target_data[0].split(':');
909 parent = new Gtk.TreePath.from_string( ar.join(':') );
914 var aret = after ? {} : false;
918 if (parent !== false) {
919 this.el.get_iter(pret, parent);
926 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
927 this.el.get_iter(aret, after);
928 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
929 nret, pret.iter, aret.iter);
932 this.el.append(nret, pret.iter);
935 var new_path = this.el.get_path(nret.iter).to_string();
936 print("new path = " + new_path)
937 if (typeof(node) == 'string') {
938 var ar = node.split('.');
939 var xtype = ar.pop();
942 '|xns' : ar.join('.'),
945 if (target_data.length == 3 && target_data[2].length) {
946 node['*prop'] = target_data[2];
948 node = this.get('/DialogTemplateSelect').show(node);
951 // work out what kind of packing to use..
952 if (typeof(node.pack) == 'undefined' && parent !== false) {
953 var pal = this.get('/LeftTree').getPaleteProvider();
954 if (pal.name == 'Gtk') {
955 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
956 var cname = pal.guessName(node);
957 node.pack = pal.getDefaultPack(pname, cname);
968 // load children - if it has any..
971 this.load(xitems, nret.iter);
972 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
974 if (tp && (xitems || after)) {
975 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
977 // wee need to get the empty proptypes from somewhere..
979 //var olditer = this.activeIter;
980 //this.activePath = new_path;
981 print("calling changed with node data")
982 // changed actually set's the node data..
983 this.setFromNode(new_path,node);
988 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
990 //Builder.MidPropTree._model.load(node);
991 //Builder.MidPropTree._win.hideWin();
992 //Builder.LeftPanel._model.load( node);
996 findDropNode : function(treepath_str, targets) {
998 // this is used by the dragdrop code in the roo version AFAIR..
1000 var path = treepath_str.replace(/^builder-/, '');
1001 // treemap is depreciated... - should really check if model has any entries..
1003 if (!this.el.iter_n_children(null)) {
1005 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
1007 print("FIND treepath: " + path);
1008 //console.dump(this.treemap);
1010 if (!treepath_str.match(/^builder-/)) {
1011 return []; // nothing!
1013 if (targets === true) {
1016 return this.findDropNodeByPath(path,targets)
1018 findDropNodeByPath : function(treepath_str, targets, pref) {
1019 var path = treepath_str + ''; // dupe it..
1020 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1022 //console.dump(this.treemap);
1023 while (path.length) {
1024 print("LOOKING FOR PATH: " + path);
1025 var node_data = this.singleNodeToJS(path);
1026 if (node_data === false) {
1027 print("node not found");
1031 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1034 targets.forEach(function(tg) {
1038 if ((tg == xname) ) {
1041 if (tg.indexOf(xname +':') === 0) {
1043 prop = tg.split(':').pop();
1048 if (last) { // pref is after/before..
1049 // then it's after last
1051 return []; // do not allow..
1053 return [ last, pref , prop];
1056 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1058 var par = path.split(':');
1061 path = par.join(':');
1067 getIterValue : function (iter, col) {
1069 var gval = ''+this.el.get_value(iter, col).value.get_string();
1075 XObject.prototype.init.call(this);
1076 this.el.set_column_types ( 3, [
1077 GObject.TYPE_STRING, // title
1078 GObject.TYPE_STRING, // tip
1079 GObject.TYPE_STRING // source..
1082 listAllTypes : function() {
1083 var s = this.get('/LeftTree.view').selection;
1084 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1086 if (s.count_selected_rows() > 0) {
1088 s.get_selected(ret);
1090 // set some properties of the tree for use by the dropped element.
1091 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1092 var data = JSON.parse(value);
1095 var xname = this.get('/LeftTree.model').file.guessName(data);
1096 console.log('selected:' + xname);
1100 return []; // could not find it..
1109 for (var i =0 ; i < li.length; i++ ) {
1112 // this is specific to roo!!!?
1113 if (!el) { // skip empty?
1116 var fullpath = _this.file.guessName(el);
1117 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1122 if (el.items && el.items.length) {
1131 addall([this.currentTree]);
1133 // only if we have nothing, should we add '*top'
1137 //console.log('all types in tree');
1138 //console.dump(ret);
1143 load : function(tr,iter)
1145 //this.insert(citer,iter,0);
1147 for(var i =0 ; i < tr.length; i++) {
1150 this.el.insert(ret ,iter,-1);
1152 this.el.append(ret);
1154 //print(JSON.stringify(ret,null,4));
1155 //print('call nodeToJSON: ' + tr[i]);
1156 var body = this.nodeToJSON(tr[i]);
1158 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1159 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1160 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1161 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1162 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1163 this.el.set_value(ret.iter, 2, '' + body );
1164 if (tr[i].items && tr[i].items.length) {
1165 this.load(tr[i].items, ret.iter);
1169 loadFile : function(f) {
1176 console.log('missing file');
1180 // load the file if not loaded..
1181 if (f.items === false) {
1183 f.loadItems(function() {
1189 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1191 if (f.items.length && typeof(f.items[0]) == 'string') {
1193 //this.get('/RightEditor').el.show();
1194 //this.get('/RightEditor.view').load( f.items[0]);
1198 //print(JSON.stringify(f.items, null,4));
1199 //console.dump(f.items);
1201 this.get('/LeftTree.view').el.expand_all();
1203 if (!f.items.length) {
1206 this.get('/Window.leftvpaned').el.set_position(80);
1208 this.get('/LeftTree.view').el.set_cursor(
1209 new Gtk.TreePath.from_string('0'), null, false);
1213 this.get('/Window.leftvpaned').el.set_position(200);
1216 //return; -- debuggin
1217 //print("hide right editior");
1218 //this.get('/RightEditor').el.hide();
1219 this.get('/Editor').el.hide();
1220 print("set current tree");
1222 this.currentTree = this.toJS(false, false)[0];
1225 //console.dump(this.currentTree);
1226 this.currentTree = this.currentTree || { items: [] };
1227 this.get('/LeftTree').renderView();
1228 // console.dump(this.map);
1229 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1230 var pm = this.get('/RightPalete.model');
1231 // set up provider..
1233 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1235 if (!this.get('/RightPalete').provider) {
1236 print ("********* PALETE PROVIDER MISSING?!!");
1238 this.get('/LeftTree').renderView();
1240 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1244 this.get('/Window.view-notebook').el.set_current_page(
1245 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1248 moveNode : function(target_data, action) {
1249 //print("MOVE NODE");
1250 // console.dump(target_data);
1252 var s = this.get('/LeftTree.view').selection;
1253 s.get_selected( oret);
1254 var node = this.nodeToJS(oret.iter,false);
1255 //console.dump(node);
1256 print(JSON.stringify(node, null,4));
1258 // needs to drop first, otherwise the target_data
1259 // treepath will be invalid.
1261 this.dropNode(target_data, node);
1262 if (action & Gdk.DragAction.MOVE) {
1263 // print("REMOVING OLD NODE");
1264 this.el.remove(oret.iter);
1268 this.activePath= false;
1271 nodeTip : function(c) {
1272 var ret = this.nodeTitle(c,true);
1278 if (!i.length || i[0] != '|') {
1284 if (typeof(c[i]) != 'string') {
1287 //print("prop : " + i + ':' + c[i]);
1288 if (!c[i].match(new RegExp('function'))) {
1291 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1295 ret+="\n\nMethods:" + funcs;
1300 nodeTitle : function(c, renderfull) {
1303 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1304 if (sr) txt.push('<s>');
1305 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1307 if (renderfull && c['|xns']) {
1308 txt.push(c['|xns']);
1311 if (c.xtype) { txt.push(c.xtype); }
1312 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1313 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1314 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1317 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1318 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1319 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1320 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1321 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1322 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1323 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1324 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1325 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1327 // for flat classes...
1328 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1329 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1332 if (sr) txt.push('</s>');
1333 return (txt.length == 0 ? "Element" : txt.join(" "));
1335 nodeToJS : function (treepath, with_id)
1337 //print("nodeToJS : WITHID: "+ with_id);
1338 var iter = treepath; // API used to be iter here..
1339 if (typeof(iter) == 'string') {
1341 if (!this.el.get_iter(ret,
1342 new Gtk.TreePath.from_string(treepath))) {
1348 var iv = this.getIterValue(iter, 2);
1349 // print("IV" + iv);
1350 var k = JSON.parse(iv);
1351 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1356 var treepath_str = this.el.get_path(iter).to_string();
1357 // not sure how we can handle mixed id stuff..
1358 if (typeof(k.id) == 'undefined') {
1359 k.id = 'builder-'+ treepath_str ;
1363 this.treemap[ treepath_str ] = k;
1364 k.xtreepath = treepath_str ;
1367 if (this.el.iter_has_child(iter)) {
1369 this.el.iter_children(cret, iter);
1370 k.items = this.toJS(cret.iter,with_id);
1374 nodeToJSON : function(c) {
1382 return JSON.stringify(o);
1384 singleNodeToJS : function (treepath)
1387 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1391 var iv = this.getIterValue(ret.iter, 2);
1393 return JSON.parse(iv);
1396 toJS : function(treepath, with_id)
1398 //print("toJS : WITHID: "+ with_id);
1400 var iter = treepath; // API used to be iter here..
1402 if (typeof(iter) == 'string') {
1404 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1416 if (!this.el.get_iter_first(ret)) {
1427 var k = this.nodeToJS(iter, with_id);
1431 if (!this.el.iter_next(iter)) {
1436 if (treepath === false) {
1438 return JSON.parse(JSON.stringify(ar));
1442 // convert the list into a json string..
1448 xtype: Gtk.TreeViewColumn,
1449 pack : "append_column",
1451 XObject.prototype.init.call(this);
1452 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1456 xtype: Gtk.CellRendererText,
1466 id : "LeftTreeMenu",
1469 xtype: Gtk.MenuItem,
1471 label : "Delete Element",
1473 activate : function (self) {
1475 this.get('/LeftTree.model').deleteSelected();
1480 xtype: Gtk.MenuItem,
1482 activate : function (self) {
1484 var tree = this.get('/LeftTree');
1485 var model = this.get('/LeftTree.model');
1486 var el = tree.getActivePath();
1488 var js = model.toJS(el, false);
1489 // print(JSON.stringify(js[0], null,4));
1490 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1495 label : "Save as Template",
1505 id : "LeftProjectTree",
1506 showNoProjectSelected : function() {
1507 this.get('/StandardErrorDialog').show("Select a Project first.");
1509 getActiveProject : function() {
1510 return this.project;
1513 leave_notify_event : function (self, event) {
1520 pack : "pack_start,false,false",
1523 xtype: Gtk.ComboBox,
1525 changed : function (self) {
1526 var fn = this.getValue();
1527 var pm = imports.ProjectManager.ProjectManager;
1528 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1532 getValue : function() {
1533 var ix = this.el.get_active();
1537 var data = imports.ProjectManager.ProjectManager.projects;
1538 if (typeof(data[ix]) == 'undefined') {
1544 XObject.prototype.init.call(this);
1545 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1547 setValue : function(fn)
1551 var data = imports.ProjectManager.ProjectManager.projects;
1552 data.forEach(function(n, ix) {
1561 xtype: Gtk.CellRendererText,
1562 pack : "pack_start,true",
1566 xtype: Gtk.ListStore,
1570 XObject.prototype.init.call(this);
1571 this.el.set_column_types ( 2, [
1572 GObject.TYPE_STRING, // real key
1573 GObject.TYPE_STRING // real type
1577 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1578 var pm = imports.ProjectManager.ProjectManager;
1580 pm.on('changed', function() {
1581 print("caught changed hook on project manager - reloading data");
1582 _this.loadData(pm.projects);
1586 loadData : function(data) {
1587 var ov = this.get('/LeftProjectTree.combo').getValue();
1591 data.forEach(function(p) {
1594 //print(JSON.stringify(XObject.keys(na)));
1595 //print(typeof(na.iter));
1596 //print(JSON.stringify(iter))
1597 el.set_value(na.iter, 0, p.fn);
1598 el.set_value(na.iter, 1, p.name);
1602 this.get('/LeftProjectTree.combo').setValue(ov);
1610 xtype: Gtk.ScrolledWindow,
1612 shadow_type : Gtk.ShadowType.IN,
1614 XObject.prototype.init.call(this);
1615 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1619 xtype: Gtk.TreeView,
1622 cursor_changed : function (self) {
1624 var model = this.get('/LeftProjectTree.model');
1628 if (model.loading) {
1633 print("LOADING IS FALSE");
1635 if (this.selection.count_selected_rows() < 1) {
1636 //XN.get('Builder.LeftTree.model').
1637 this.get('/LeftTree.model').load( false);
1641 //console.log('changed');
1642 var s = this.selection;
1643 s.get_selected(ret);
1644 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1645 //console.log(JSON.stringify(value,null,4));// id..
1646 console.log("OUT?" + value);// id..
1647 var file = this.get('/LeftProjectTree').project.getById(value);
1654 var nb = this.get('/LeftTopPanel.expander');
1655 nb.el.expanded = false;
1657 //nb.listeners.activate.call(nb);
1658 //_expander.el.set_expanded(false);
1660 var ltm = this.get('/LeftTree.model');
1668 enable_tree_lines : true,
1669 headers_visible : false,
1671 XObject.prototype.init.call(this);
1672 var description = new Pango.FontDescription.c_new();
1673 description.set_size(8000);
1674 this.el.modify_font(description);
1676 this.selection = this.el.get_selection();
1677 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1681 xtype: Gtk.TreeStore,
1686 XObject.prototype.init.call(this);
1687 this.el.set_column_types ( 3, [
1688 GObject.TYPE_STRING, // title
1689 GObject.TYPE_STRING, // tip
1690 GObject.TYPE_STRING // id..
1694 loadProject : function(pr) {
1695 print("LOAD PROJECT");
1696 var model = this.get('/LeftProjectTree.model');
1697 model.loading = true;
1704 this.get('/LeftProjectTree').project = pr;
1706 this.load(pr.toTree());
1708 this.get('/LeftProjectTree.view').el.expand_all();
1709 model.loading = false;
1712 load : function(tr,iter) {
1713 // console.dump(tr);
1716 console.log('Project tree load: ' + tr.length);
1718 //this.insert(citer,iter,0);
1722 tr.forEach(function (r) {
1724 _this.el.append(cret);
1726 _this.el.insert(cret,iter,-1);
1728 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1729 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1730 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1731 if (r.cn && r.cn.length) {
1732 _this.load(r.cn, cret.iter);
1738 getValue : function(iter, col) {
1739 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1744 xtype: Gtk.TreeViewColumn,
1745 pack : "append_column",
1747 XObject.prototype.init.call(this);
1748 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1752 xtype: Gtk.CellRendererText,
1772 pack : "pack_start,false,true,0",
1779 button_press_event : function (self, event) {
1780 this.get('/MidPropTree.model').showData('props');
1792 stock : Gtk.STOCK_ADD,
1793 icon_size : Gtk.IconSize.MENU
1807 button_press_event : function (self, event) {
1809 if (!this.get('/Editor').save()) {
1810 // popup!! - click handled..
1813 this.get('/MidPropTree.model').showData('events');
1826 stock : Gtk.STOCK_ADD,
1827 icon_size : Gtk.IconSize.MENU
1841 button_press_event : function (self, ev) {
1843 if (!this.get('/Editor').save()) {
1844 // popup!! - click handled..
1848 var p = this.get('/AddPropertyPopup');
1852 p.el.set_screen(Gdk.Screen.get_default());
1854 p.el.popup(null, null, null, null, 3, ev.button.time);
1867 stock : Gtk.STOCK_ADD,
1868 icon_size : Gtk.IconSize.MENU
1880 id : "AddPropertyPopup",
1883 xtype: Gtk.MenuItem,
1885 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1888 activate : function (self) {
1890 this.get('/LeftPanel.model').add( {
1901 xtype: Gtk.MenuItem,
1903 tooltip_markup : "Add what type of packing is to be used",
1906 activate : function (self) {
1908 this.get('/LeftPanel.model').add( {
1918 xtype: Gtk.MenuItem,
1920 tooltip_markup : "Override the init method",
1923 activate : function (self) {
1925 this.get('/LeftPanel.model').add( {
1928 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1935 xtype: Gtk.SeparatorMenuItem,
1939 xtype: Gtk.MenuItem,
1941 tooltip_markup : "Add a user defined string property",
1944 activate : function (self) {
1946 this.get('/LeftPanel.model').add( {
1956 xtype: Gtk.MenuItem,
1958 tooltip_markup : "Add a user defined number property",
1961 activate : function (self) {
1963 this.get('/LeftPanel.model').add( {
1973 xtype: Gtk.MenuItem,
1975 tooltip_markup : "Add a user defined boolean property",
1978 activate : function (self) {
1980 this.get('/LeftPanel.model').add( {
1990 xtype: Gtk.SeparatorMenuItem,
1994 xtype: Gtk.MenuItem,
1996 tooltip_markup : "Add a user function boolean property",
1999 activate : function (self) {
2001 this.get('/LeftPanel.model').add( {
2004 val : "function() {\n \n}\n",
2017 xtype: Gtk.ScrolledWindow,
2022 XObject.prototype.init.call(this);
2023 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2025 shadow_type : Gtk.ShadowType.IN,
2028 xtype: Gtk.TreeView,
2030 button_press_event : function (self, ev) {
2033 if (!this.get('/Editor').save()) {
2034 // popup!! - click handled..
2039 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2040 return false; //not on a element.
2044 if (ev.button.button == 3) {
2046 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2049 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2050 var p = this.get('/LeftPanelPopup');
2055 p.el.set_screen(Gdk.Screen.get_default());
2057 p.el.popup(null, null, null, null, 3, ev.button.time);
2058 //Seed.print("click:" + res.column.title);
2065 if (res.column.title != 'value') {
2066 // XObject.error("column is not value?");
2067 return false; // ignore.. - key click.. ??? should we do this??
2070 // currently editing???
2071 // if ( this.activePath) {
2073 // this.activePath = false;
2075 if (this.get('/Editor').dirty) {
2076 //if (!this.get('/Editor.buffer').checkSyntax()) {
2077 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2081 if (!this.get('/Editor.view').save()) {
2085 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2086 this.get('/LeftPanel').editing = false;
2088 // XObject.error("Currently editing?");
2092 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2094 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2096 // get options for this type -- this is to support option lists etc..
2097 var provider = this.get('/LeftTree').getPaleteProvider();
2098 var opts = provider.findOptions(type);
2100 if (opts === false) {
2102 this.get('/LeftPanel').editableColumn.setOptions([]);
2103 renderer.has_entry = true;
2105 this.get('/LeftPanel').editableColumn.setOptions(opts);
2106 renderer.has_entry = false;
2108 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2110 //Seed.print("click" + ev.type);
2111 //console.dump(res);
2120 enable_tree_lines : true,
2121 headers_visible : false,
2123 XObject.prototype.init.call(this);
2125 this.selection = this.el.get_selection();
2126 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2129 var description = new Pango.FontDescription.c_new();
2130 description.set_size(8000);
2131 this.el.modify_font(description);
2135 xtype: Gtk.TreeStore,
2139 add : function(info) {
2140 // info includes key, val, skel, etype..
2142 type = info.type.toLowerCase();
2143 var data = this.toJS();
2145 if (info.etype == 'events') {
2146 data.listeners = data.listeners || { };
2147 if (typeof(data.listeners[info.key]) != 'undefined') {
2148 return; //already set!
2151 if (typeof(data[info.key]) != 'undefined') {
2156 if (typeof(info.val) == 'undefined') {
2159 if (info.type.toLowerCase() == 'boolean') {
2162 if (type == 'number') {
2170 if (info.etype == 'events') {
2172 data.listeners[info.key] = info.val;
2175 data[info.key] = info.val;
2179 var map = this.load(data);
2181 // flag it as changed to the interface..
2182 this.get('/LeftTree.model').setFromNode(false,node);
2183 this.get('/LeftTree.model').changed(true);
2186 this.startEditing(map[k]);
2189 LeftPanel.get('view').el.row_activated(
2190 new Gtk.TreePath.from_string(map[k]),
2191 LeftPanel.editableColumn.el
2195 changed : function(str, doRefresh) {
2196 if (!this.activePath) {
2197 print("NO active path when changed")
2201 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2203 this.el.set_value(ret.iter, 1, '' +str);
2204 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2205 var type = this.getIterValue(ret.iter, 4);
2207 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2208 // update the tree...
2209 print("new data: " + JSON.stringify(this.toJS() , null,4));
2210 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2211 this.get('/LeftTree.model').changed(doRefresh);
2214 deleteSelected : function() {
2215 var data = this.toJS();
2217 var s = this.get('/LeftPanel.view').selection;
2218 s.get_selected( ret);
2221 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2223 if (val[0] == '!') {
2225 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2228 delete data.listeners[ val.substring(1)];
2229 if (!XObject.keys(data.listeners).length) {
2230 delete data.listeners;
2234 if (typeof(data[val]) == 'undefined') {
2244 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2245 this.get('/LeftTree.model').changed(true);
2249 getIterValue : function(iter, col) {
2250 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2253 getType : function(treepath) {
2254 return this.getValue(treepath, 4);
2256 getValue : function(treepath_str, col)
2258 // get's the value in a row.. - keys - returns string, values - formats it..
2260 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2262 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2267 var type = this.getType(this.el.get_path(ret.iter).to_string());
2268 //print("TYPE: " +type + " - val:" + val);
2269 switch(type.toLowerCase()) {
2273 return parseFloat(val); // Nan ?? invalid!!?
2276 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2278 return val == 'true' ? true : false;
2280 var nv = parseFloat(val);
2281 if (!isNaN(nv) && (val == ''+nv)) {
2289 XObject.prototype.init.call(this);
2290 this.el.set_column_types ( 6, [
2291 GObject.TYPE_STRING, // 0 real key
2292 GObject.TYPE_STRING, // 1 real value
2293 GObject.TYPE_STRING, // 2 visable key
2294 GObject.TYPE_STRING, // 3 visable value
2295 GObject.TYPE_STRING, // 4 need to store type of!!!
2296 GObject.TYPE_STRING // 5 tooltip
2300 load : function(ar) {
2301 // might casue problesm..
2302 // this.get('/Editor.RightEditor').save();
2304 this.get('/Editor').el.hide();
2305 this.get('/Editor').activePath = false;
2310 //this.get('/RightEditor').el.hide();
2317 var provider = this.get('/LeftTree').getPaleteProvider();
2321 var keys = XObject.keys(ar);
2323 ar.listeners = ar.listeners || {};
2325 for (var i in ar.listeners ) {
2327 this.el.append(iret);
2328 var p = this.el.get_path(iret.iter).to_string();
2331 this.el.set_value(iret.iter, 0, '!'+ i );
2332 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2333 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2335 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2336 this.el.set_value(iret.iter, 4, 'function');
2337 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2343 keys.forEach(function(i) {
2344 if (typeof(ar[i]) == 'object') {
2348 var type = provider.findType(ar, i, ar[i]);
2350 _this.el.append(iret);
2351 var p = _this.el.get_path(iret.iter).to_string();
2353 _this.el.set_value(iret.iter, 0, ''+i);
2354 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2355 _this.el.set_value(iret.iter, 2, ''+i);
2356 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2357 _this.el.set_value(iret.iter, 4, ''+type);
2358 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2362 startEditing : function(path,col) {
2364 // alled by menu 'edit' currently..
2366 * start editing path (or selected if not set..)
2367 * @param {String|false} path (optional) treepath to edit - selected tree gets
2368 * edited by default.
2369 * @param {Number} 0 or 1 (optional)- column to edit.
2371 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2373 if (typeof(path) == 'string') {
2374 tp = new Gtk.TreePath.from_string(path);
2377 var s = this.get('/LeftPanel.view').selection;
2378 s.get_selected( itr);
2379 tp = this.el.get_path(itr.iter);
2380 path = tp.to_string();
2384 // which colum is to be edited..
2387 // not sure what this does..
2389 if (typeof(col) == 'undefined') {
2390 var k = this.getValue(path, 0);
2392 colObj = (!k.length || k == '|') ?
2393 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2395 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2398 // make sure the pulldown is set correctly..
2399 // not really needed for second col...
2400 var showEditor = false;
2401 this.get('/Editor').activePath = false;
2402 this.get('/Editor').el.hide();
2405 var provider = this.get('/LeftTree').getPaleteProvider();
2406 var type = this.get('/LeftPanel.model').getType(path);
2407 var opts = provider.findOptions(type);
2408 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2410 if (opts === false) {
2411 this.get('/LeftPanel').editableColumn.setOptions([]);
2412 renderer.has_entry = true;
2414 this.get('/LeftPanel').editableColumn.setOptions(opts);
2415 renderer.has_entry = false;/// - pulldowns do not have entries
2417 // determine if we should use the Text editor...
2418 var keyname = this.getValue(path, 0);
2419 var data_value = this.getValue(path, 1);
2421 if ((keyname[0] == '|') ||
2423 (typeof(data_value) == 'string' ) &&
2424 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2428 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2433 // this.get('/BottomPane').el.hide();
2434 //this.get('/RightEditor').el.hide();
2439 this.activePath = false;
2441 _this.get('/Editor').el.show_all();
2442 GLib.timeout_add(0, 1, function() {
2444 //_this.get('/BottomPane').el.show();
2445 //_this.get('/RightEditor').el.show();
2447 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2449 _this.get('/Editor').activePath = path;
2450 _this.activePath = path ;
2460 // iter now has row...
2461 GLib.timeout_add(0, 100, function() {
2462 _this.activePath = path;
2463 colObj.items[0].el.editable = true; // esp. need for col 0..
2464 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2475 this.get('/LeftPanel.model').el.get_iter_first(iret);
2481 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2484 ar.listeners = ar.listeners || {};
2485 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2488 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2491 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2497 //print(JSON.stringify(ar));
2501 toShort : function(str) {
2502 var a = typeof(str) == 'string' ? str.split("\n") : [];
2503 return a.length > 1 ? a[0] + '....' : '' + str;
2507 xtype: Gtk.TreeViewColumn,
2508 pack : "append_column",
2510 XObject.prototype.init.call(this);
2512 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2513 this.get('/LeftPanel').propertyColumn = this;
2518 xtype: Gtk.CellRendererText,
2519 pack : "pack_start",
2521 editing_started : function (self, editable, path) {
2523 this.get('/LeftPanel.model').activePath = path;
2526 edited : function (self, object, p0) {
2528 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2530 var model = this.get('/LeftPanel.model');
2531 var path = model.activePath;
2533 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2534 model.el.set_value(iret.iter, 0, p0);
2535 model.el.set_value(iret.iter, 2, p0);
2537 model.activePath = false;
2538 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2539 this.get('/LeftTree.model').changed(true);
2541 this.el.editable = false;
2548 xtype: Gtk.TreeViewColumn,
2549 pack : "append_column",
2552 XObject.prototype.init.call(this);
2553 this.el.add_attribute(this.items[0].el , 'text', 3 );
2554 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2555 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2556 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2558 this.get('/LeftPanel').editableColumn= this;
2560 setOptions : function(ar) {
2561 var m = this.items[0].el.model;
2564 ar.forEach(function(i) {
2568 m.set_value(iret.iter, 0, i);
2574 xtype: Gtk.CellRendererCombo,
2576 edited : function (self, object, p0) {
2578 this.get('/LeftPanel').editing = false;
2579 var ap = this.get('/LeftPanel.model').activePath
2580 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2581 this.get('/LeftPanel.model').changed(p0, true);
2582 this.get('/LeftPanel.model').activePath = false;
2583 this.el.editable = false;
2585 editing_started : function (self, editable, path) {
2586 this.get('/LeftPanel').editing = true;
2587 // console.log('editing started');
2588 // r.has_entry = false;
2590 this.el.editable = false; // make sure it's not editor...
2595 pack : "pack_start",
2599 XObject.prototype.init.call(this);
2600 this.el.model = new Gtk.ListStore();
2601 this.el.model.set_column_types ( 1, [
2602 GObject.TYPE_STRING // 0 real key
2613 id : "LeftPanelPopup",
2616 xtype: Gtk.MenuItem,
2620 activate : function (self) {
2621 this.get('/LeftPanel.model').deleteSelected();
2626 xtype: Gtk.MenuItem,
2630 activate : function (self) {
2631 this.get('/LeftPanel.model').startEditing(false, 0);
2644 xtype: Gtk.ScrolledWindow,
2645 pack : "pack_end,false,true,0",
2648 shadow_type : Gtk.ShadowType.IN,
2650 XObject.prototype.init.call(this);
2651 XObject.prototype.init.call(this);
2652 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2653 this.el.set_size_request ( 150, -1 );
2656 activeElement : false,
2657 hideWin : function() {
2660 print("HIDEWIN - currently not shown")
2665 if (this.get('/Window.left').el.position < 160) {
2666 print("HIDEWIN - small already.")
2670 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2671 print("HIDEWIN attempting to hide.")
2678 xtype: Gtk.TreeView,
2680 cursor_changed : function (self) {
2681 // this is getting fired when we are loading elements..
2682 if (this.get('/MidPropTree.model').loading) {
2688 //console.log('changed');
2689 var m = this.get('model');
2690 if (!this.selection){
2691 this.selection = this.el.get_selection();
2694 var s = this.selection;
2695 if (!s.get_selected(iret)) {
2698 var tp = m.el.get_path(iret.iter).to_string();
2703 var key = m.getValue(tp, 0);
2705 var type = m.getValue(tp, 1);
2706 var skel = m.getValue(tp, 3);
2707 var etype = m.getValue(tp, 5);
2710 this.get('/MidPropTree').hideWin();
2712 if (type.toLowerCase() == 'function') {
2714 if (etype != 'events') {
2717 print("cursor_changed: ADDding to left panel model");
2718 this.get('/LeftPanel.model').add({
2726 // has dot in name, and is boolean???? this does not make sense..
2727 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2730 print("cursor_changed: ADDding to left panel model");
2731 this.get('/LeftPanel.model').add( {
2741 enable_tree_lines : true,
2742 headers_visible : false,
2744 XObject.prototype.init.call(this);
2746 var description = new Pango.FontDescription.c_new();
2747 description.set_size(8000);
2748 this.el.modify_font(description);
2750 //this.selection = this.el.get_selection();
2751 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2760 xtype: Gtk.ListStore,
2764 getValue : function(treepath, col)
2766 var tp = new Gtk.TreePath.from_string (treepath);
2768 this.el.get_iter (iret, tp);
2769 var value = this.el.get_value(iret.iter, col);
2770 return ''+ value.value.get_string();
2774 XObject.prototype.init.call(this);
2775 this.el.set_column_types ( 6, [
2776 GObject.TYPE_STRING, // real key
2777 GObject.TYPE_STRING, // real type
2778 GObject.TYPE_STRING, // docs ?
2779 GObject.TYPE_STRING, // visable desc
2780 GObject.TYPE_STRING, // function desc
2781 GObject.TYPE_STRING // element type (event|prop)
2785 showData : function(type) {
2788 this.loading = true;
2790 if (!this.get('/MidPropTree').activeElement || !type) {
2791 this.loading = false;
2792 return; // no active element
2795 var fullpath = this.get('/LeftTree.model').file.guessName(
2796 this.get('/MidPropTree').activeElement);
2797 var palete = this.get('/LeftTree').getPaleteProvider();
2801 Seed.print('Showing right?');
2802 if (!this.get('/MidPropTree').shown) {
2804 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2805 this.get('/MidPropTree').el.show();
2806 this.get('/MidPropTree').shown = true;
2809 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2810 return a.name > b.name ? 1 : -1;
2812 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2813 // console.dump(elementList);
2815 // scope of this is off..??
2818 for(var i =0 ; i < elementList.length; i++) {
2820 var p=elementList[i];
2821 this.el.append(iret);
2822 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2823 //GObject.TYPE_STRING, // real key
2824 // GObject.TYPE_STRING, // real type
2825 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2826 // GObject.TYPE_STRING // func def?
2829 this.el.set_value(iret.iter, 0, p.name);
2830 this.el.set_value(iret.iter, 1, p.type);
2831 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2832 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2833 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2834 this.el.set_value(iret.iter, 5, type);
2837 this.loading = false;
2841 xtype: Gtk.TreeViewColumn,
2844 this.el = new Gtk.TreeViewColumn();
2845 this.parent.el.append_column(this.el);
2847 XObject.prototype.init.call(this);
2848 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2852 xtype: Gtk.CellRendererText,
2853 pack : "pack_start,true"
2880 xtype: Gtk.Notebook,
2881 pack : "pack_start,true,true",
2882 id : "view-help-nb",
2884 XObject.prototype.init.call(this);
2885 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2886 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2890 xtype: Gtk.Notebook,
2891 id : "view-notebook",
2895 XObject.prototype.init.call(this);
2896 this.el.set_current_page(0);
2897 //print("SET LABEL?")
2898 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2899 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2905 id : "RightBrowser",
2910 pack : "pack_start,false,true,0",
2915 clicked : function (self) {
2916 this.get('/RightBrowser.view').renderJS(null,true);
2920 pack : "pack_start,false,false,0"
2923 xtype: Gtk.CheckButton,
2925 toggled : function (self, state) {
2926 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2931 label : "Auto Redraw On",
2932 pack : "pack_start,false,false,0"
2937 clicked : function (self) {
2939 var view = this.get('/RightBrowser.view');
2940 //this.get('/RightBrowser.view').redraws = 99;
2941 view.refreshRequired = true;
2942 view.lastRedraw = false;
2943 view.renderedData = false;
2944 view.renderJS(null,true);
2948 label : "Full Redraw",
2949 pack : "pack_start,false,false,0"
2954 xtype: Gtk.ScrolledWindow,
2957 XObject.prototype.init.call(this);
2958 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2960 shadow_type : Gtk.ShadowType.IN,
2963 xtype: WebKit.WebView,
2965 load_finished : function (self, object) {
2966 print("load finished");
2967 // print("load_finished"); return;
2968 // if (this.ready) { // dont do it twice!
2971 if (!this.inspectorShown) {
2972 this.el.get_inspector().show();
2973 this.inspectorShown = true;
2978 //if (this.pendingRedraw) {
2979 // this.pendingRedraw = false;
2980 // this.refreshRequired = true;
2982 //var js = this.get('/LeftTree.model').toJS();
2983 //if (js && js[0]) {
2984 // this.renderJS(js[0]);
2988 script_alert : function (self, object, p0) {
2991 return true; // do not display anything...
2993 console_message : function (self, object, p0, p1) {
2995 // console.log(object);
2998 if (object.match(/variable/) && object.match(/Builder/)) {
2999 print("got builder missing message");
3000 this.refreshRequired = true;
3001 this.lastRedraw = 0;
3007 if (!object.match(/^\{/)) {
3009 //this.get('/Terminal').feed(object);
3010 return true; // do not handle!!! -> later maybe in console..
3016 // console.log(object);
3017 var val = JSON.parse(object);
3019 if (typeof(val['hover-node']) != 'undefined') {
3020 this.activeNode = val['hover-node'];
3021 console.log('active node: ' + this.activeNode);
3026 if (typeof(val['id']) != 'undefined') {
3027 // this.activeNode = val['id'];
3028 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
3029 if (!tg || typeof(tg[0]) == 'undefined') {
3032 print("SELECT node " + tg[0]);
3034 this.get('/LeftTree.view').selectNode(tg[0]);
3039 if (ret && typeof(val['set']) != 'undefined') {
3040 print("console messages: ADDding to left panel model");
3042 //this.get('/LeftPanel.model').add({
3043 // key : val['set'],
3044 // val : val['value']
3046 //console.log('active node: ' + this.activeNode);
3049 //Seed.print('a:'+a);
3050 //Seed.print('b:'+b);
3051 //Seed.print('c:'+c);
3054 drag_motion : function (w, ctx, x, y, time, ud) {
3055 // console.log('DRAG MOTION');
3057 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3058 this.targetData = [];
3059 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3061 // A) find out from drag all the places that node could be dropped.
3062 var src = Gtk.drag_get_source_widget(ctx);
3063 if (!src.dropList) {
3064 Gdk.drag_status(ctx,0, time);
3067 // b) get what we are over.. (from activeNode)
3068 // tree is empty.. - list should be correct..
3069 if (!this.get('/LeftTree.model').currentTree) {
3070 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3074 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3076 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3079 Gdk.drag_status(ctx, 0,time);
3080 this.get('/LeftTree.view').highlight(false);
3084 // if we have a target..
3085 // -> highlight it! (in browser)
3086 // -> highlight it! (in tree)
3088 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3089 this.get('/LeftTree.view').highlight(tg);
3090 this.targetData = tg;
3091 // for tree we should handle this...
3094 drag_drop : function (w, ctx, x, y,time, ud) {
3095 print("TARGET: drag-drop");
3096 var is_valid_drop_site = true;
3100 ( /* will receive 'drag-data-received' signal */
3101 ctx, /* represents the current state of the DnD */
3102 imports.Builder3.Main.atoms["STRING"], /* the target type we want */
3103 time /* time stamp */
3107 /* No target offered by source => error */
3110 return is_valid_drop_site;
3112 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3114 print("Browser: drag-data-received");
3115 var delete_selection_data = false;
3116 vardnd_success = false;
3117 /* Deal with what we are given from source */
3118 if( sel_data && sel_data.length ) {
3120 if (ctx.action == Gdk.DragAction.ASK) {
3121 /* Ask the user to move or copy, then set the ctx action. */
3124 if (ctx.action == Gdk.DragAction.MOVE) {
3125 delete_selection_data = true;
3127 var source = Gtk.drag_get_source_widget(ctx);
3129 print("Browser: source.DRAGDATA? " + source.dragData);
3130 if (this.targetData) {
3131 print(this.targetData);
3132 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3141 if (dnd_success == false)
3143 Seed.print ("DnD data transfer failed!\n");
3146 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3149 create_web_view : function (self, object) {
3150 print("CREATE WEB VIEW");
3151 return null; //new WebKit.WebView();
3158 XObject.prototype.init.call(this);
3159 // this may not work!?
3160 var settings = this.el.get_settings();
3161 settings.enable_developer_extras = true;
3163 // this was an attempt to change the url perms.. did not work..
3164 // settings.enable_file_access_from_file_uris = true;
3165 // settings.enable_offline_web_application_cache - true;
3166 // settings.enable_universal_access_from_file_uris = true;
3170 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3171 _this.get('/BottomPane.inspector').el.show();
3172 return _this.get('/BottomPane.inspector').el;
3176 // FIXME - base url of script..
3177 // we need it so some of the database features work.
3178 this.el.load_html_string( "Render not ready" ,
3179 //fixme - should be a config option!
3180 // or should we catch stuff and fix it up..
3181 'http://localhost/app.Builder/'
3185 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3187 this.el.drag_dest_set
3188 ( /* widget that will accept a drop */
3189 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3190 null, /* lists of target to support */
3191 0, /* size of list */
3192 Gdk.DragAction.COPY /* what to do with data after dropped */
3195 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3196 this.el.drag_dest_set_target_list( imports.Builder3.Main.targetList);
3198 GLib.timeout_add_seconds(0, 1, function() {
3199 // print("run refresh?");
3206 renderJS : function(data, force) {
3208 // this is the public redraw call..
3209 // we refresh in a loop privately..
3210 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3211 if (!autodraw && !force) {
3212 print("Skipping redraw - no force, and autodraw off");
3215 this.refreshRequired = true;
3217 runRefresh : function()
3219 // this is run every 2 seconds from the init..
3223 if (!this.refreshRequired) {
3224 // print("no refresh required");
3228 if (this.lastRedraw) {
3229 // do not redraw if last redraw was less that 5 seconds ago.
3230 if (((new Date()) - this.lastRedraw) < 5000) {
3238 if (!this.get('/Window.LeftTree').getActiveFile()) {
3241 this.refreshRequired = false;
3242 // print("HTML RENDERING");
3244 this.get('/BottomPane').el.show();
3245 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3252 var js = this.get('/LeftTree.model').toJS();
3253 if (!js || !js.length) {
3262 var project = this.get('/Window.LeftTree').getActiveFile().project;
3263 //print (project.fn);
3264 // set it to non-empty.
3265 project.runhtml = project.runhtml || '';
3266 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3269 this.runhtml = this.runhtml || '';
3271 var file = this.get('/LeftTree.model').file;
3272 var items = file.items;
3273 file.items = this.get('/LeftTree.model').toJS(false, false);
3274 //file.items[0].background = false;
3275 //var p = file.parent;
3276 //file.parent = false;
3278 var js_src = file.toSourcePreview();
3279 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3280 // unless it' sforced..
3285 this.renderedData = js_src;
3288 //file.items = items;
3289 //print("send source as " + js_src);
3292 "Roo.onReady(function() {\n" +
3293 "if (" + file.name +".show) " + file.name +".show({});\n" +
3294 "Roo.XComponent.build();\n" +
3301 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3302 // then we need to reload the browser using
3303 // load_html_string..
3305 // then trigger a redraw once it's loaded..
3306 this.pendingRedraw = true;
3307 var runhtml = '<script type="text/javascript">' + "\n" ;
3308 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3309 runhtml += '</script>'+ "\n" ;
3311 this.runhtml = project.runhtml;
3312 // need to modify paths
3315 this.lastRedraw= new Date();
3316 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3317 html = html.replace('</head>',
3320 '<script type="text/javascript">' + "\n" +
3325 //print("LOAD HTML " + html);
3326 this.el.load_html_string( html ,
3327 //fixme - should be a config option!
3328 'http://localhost/app.Builder/'
3331 // should trigger load_finished! - which in truns shoudl set refresh Required;
3336 //this.renderedData = data;
3337 //var str = JSON.stringify(data) ;
3340 console.log('not loaded yet');
3342 this.lastRedraw = new Date();
3344 this.el.execute_script("Builder.render(" +
3345 JSON.stringify(js_src) +
3347 JSON.stringify(file.name) +
3350 print( "before render" + this.lastRedraw);
3351 print( "after render" + (new Date()));
3361 id : "RightGtkView",
3363 redraw : function() {
3364 this.highlightWidget = false;
3365 print("REDRAW CALLED");
3366 this.activePath = this.get('/LeftTree').getActivePath();
3367 if (this.renderedEl) {
3368 print("QUEUE DRAW CALLING");
3369 this.renderedEl.queue_draw();
3372 renderJS : function(data, withDebug)
3374 this.highlightWidget = false;
3376 this.withDebug = false;
3377 while (this.get('view').el.get_children().length) {
3378 var c = this.get('view').el.get_children()[0];
3379 this.get('view').el.remove(c);
3386 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3387 // in theory tree is actually window..
3390 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3396 this.get('view').el.set_size_request(
3397 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3399 if (this.renderedEl) {
3400 this.renderedEl.set_size_request(
3401 tree.default_width || 600,
3402 tree.default_height || 400
3405 this.get('view').el.show_all();
3410 showInWindow : function() {
3411 print("GET PROEJCT");
3412 var pr = this.get('/LeftProjectTree').getActiveProject();
3414 console.log(pr.paths);
3417 var src= this.buildJS(
3418 this.get('/LeftTree.model').toJS()[0],
3423 //var x = new imports.sandbox.Context();
3427 Seed.check_syntax('var e = ' + src);
3430 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3431 this.get('/Terminal').feed(console._dump(e)+"\n");
3433 var lines = src.split("\n");
3434 var start = Math.max(0, e.line - 10);
3435 var end = Math.min(lines.length, e.line + 10);
3436 for (var i =start ; i < end; i++) {
3438 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3441 this.get('/Terminal').feed(lines[i] + "\n");
3448 this.get('/BottomPane').el.set_current_page(1);
3449 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3450 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3451 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3453 var _top = x.get_global_object()._top;
3455 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3457 if (_top.el.popup) {
3458 _top.el.popup(null, null, null, null, 3, null);
3462 viewAdd : function(item, par)
3465 // does something similar to xobject..
3466 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3468 // pack is forced to 'false'
3469 if (item.pack===false || item.pack === 'false') { // no ;
3473 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3476 var type = item['|xns'] + '.' + item['xtype'];
3478 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3482 var ns = imports.gi[item['|xns']];
3483 var ctr = ns[item['xtype']]; // why are we using array here..?
3488 for(var k in item) {
3490 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3504 // value is a function..
3505 if (k[0] == '|' && typeof(kv) == 'string') {
3507 if (kv.match(new RegExp('function'))) {
3510 print("WASL " + k + '=' + kv);
3512 eval( 'kv = ' + kv);
3513 } catch(e) { continue; }
3516 // print(k + '=' + kv);
3518 if (k[0] == '|') { // should be boolean or number..
3520 //print(k + '=' + kv);
3523 if (k == 'show_tabs') { // force tab showing for notebooks.
3526 print(k + '=' + typeof(kv) + " : " + kv);
3530 var altctr = XObject.baseXObject({ xtype: ctr} );
3532 if (!item.pack && altctr) {
3534 print("SETTING PACK TO XObjectBase method");
3535 pack_m = altctr.prototype.pack;
3540 var el = new ctr(ctr_args);
3542 print("PACK" + item.pack);
3543 //console.dump(item.pack);
3550 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3551 if (typeof(item.pack) == 'string') {
3553 item.pack.split(',').forEach(function(e, i) {
3555 if (e == 'false') { args.push( false); return; }
3556 if (e == 'true') { args.push( true); return; }
3557 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3560 //print(args.join(","));
3562 pack_m = args.shift();
3564 pack_m = item.pack.shift();
3569 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3571 name: "ArgumentError",
3572 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3573 "ADDING : " + item.id + " " + el
3580 //console.dump(args);
3582 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3583 //Seed.print('args: ' + args.length);
3584 if (typeof(pack_m) == 'string') {
3585 par[pack_m].apply(par, args);
3586 } else if (pack_m) {
3587 pack_m.call(item, par, item);
3591 item.items = item.items || [];
3592 item.items.forEach(function(ch,n) {
3594 print ("type:" + type);
3596 print ("ch.pack:" + ch.pack);
3599 if (type == 'Gtk.Table' && ch.pack == 'add') {
3600 var c = n % item.n_columns;
3601 var r = Math.floor(n/item.n_columns);
3602 ch.pack = [ 'attach', c, c+1, r, r+1,
3603 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3604 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3605 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3606 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3610 _this.viewAdd(ch, el);
3615 // add the signal handlers.
3616 // is it a widget!?!!?
3622 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3623 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3624 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3625 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3626 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3636 widgetDragDropEvent : function() {
3637 print("WIDGET DRAGDROP");
3640 widgetDragMotionEvent : function() {
3641 print("WIDGET DRAGMOTION");
3644 widgetExposeEvent : function(w, evt, ud, item) {
3646 if (this.inRender) {
3650 if ( this.highlightWidget) {
3651 this.inRender = true;
3652 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3653 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3655 this.inRender = false;
3660 if (this.activePath != item.xtreepath) {
3664 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3665 // work out the coords of the window..
3667 var dr = widget.window;
3668 this.gc = (new Gdk.GC.c_new(dr));
3669 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3670 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3674 var r = evt.expose.area;
3675 // console.dump([r.x, r.y, r.width, r.height ] );
3677 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3678 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3679 // happens with gtkscrollview embedded stuff..
3680 var np =this.activePath.split(':');
3682 this.activePath = np.join(':');
3683 this.renderedEl.queue_draw();
3699 this.inRender = true;
3702 this.highlightWidget = widget;
3707 // print("DRAW BOX");
3708 //console.dump(this.box);
3709 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3710 this.inRender = false;
3713 widgetPressEvent : function(w,e,u,d) {
3714 if (this.get('view').pressed) {
3717 this.get('view').pressed = true;
3718 print("WIDGET PRESS " + d.xtreepath );
3719 this.get('/LeftTree.view').selectNode( d.xtreepath );
3722 widgetReleaseEvent : function() {
3723 this.get('view').pressed = false;
3729 pack : "pack_start,false,true,0",
3733 pack : "pack_start,false,false,0",
3734 label : "Run The Application",
3736 button_press_event : function (self, event) {
3737 // call render on left tree - with special option!?!
3739 //print("GET PROEJCT");
3740 var pr = this.get('/LeftProjectTree').getActiveProject();
3743 for (var i in pr.paths) {
3747 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3748 this.get('/Terminal').feed("RUN DIR:" + dir);
3751 this.get('/Terminal').el.fork_command_full(
3752 Vte.PtyFlags.DEFAULT,
3753 GLib.path_get_dirname (__script_path__) ,
3754 [ 'echo' , "hello"], //argv
3758 null, // child setupdata
3762 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3763 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3773 xtype: Gtk.ScrolledWindow,
3776 shadow_type : Gtk.ShadowType.IN,
3778 XObject.prototype.init.call(this);
3779 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3783 xtype: Gtk.EventBox,
3784 pack : "add_with_viewport",
3786 XObject.prototype.init.call(this);
3787 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3788 red: 0x9F00, green: 0xB800 , blue : 0xA800
3796 XObject.prototype.init.call(this);
3797 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3798 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3803 xtype: Gtk.EventBox,
3806 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3807 XObject.prototype.init.call(this);
3809 this.el.drag_dest_set
3810 ( /* widget that will accept a drop */
3811 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3812 null, /* lists of target to support */
3813 0, /* size of list */
3814 Gdk.DragAction.COPY /* what to do with data after dropped */
3817 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3818 this.el.drag_dest_set_target_list( imports.Builder3.Main.targetList);
3821 getActiveNode : function(x,y)
3823 // workout what node is here..
3824 return '0'; // top..
3828 drag_motion : function (self, ctx, x, y, time) {
3830 // A) find out from drag all the places that node could be dropped.
3831 var src = Gtk.drag_get_source_widget(ctx);
3832 if (!src.dropList) {
3833 Gdk.drag_status(ctx, 0, time);
3836 // b) get what we are over.. (from activeNode)
3837 // tree is empty.. - list should be correct..
3838 if (!this.get('/LeftTree.model').currentTree) {
3839 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3843 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3844 var activeNode = this.getActiveNode(x, y);
3847 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3850 Gdk.drag_status(ctx, 0,time);
3851 this.get('/LeftTree.view').highlight(false);
3855 // if we have a target..
3856 // -> highlight it! (in browser)
3857 // -> highlight it! (in tree)
3859 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3860 this.get('/LeftTree.view').highlight(tg);
3861 this.targetData = tg;
3862 // for tree we should handle this...
3865 drag_drop : function (self,ctx, x, y, time) {
3866 Seed.print("TARGET: drag-drop");
3867 var is_valid_drop_site = true;
3871 ( /* will receive 'drag-data-received' signal */
3872 ctx, /* represents the current state of the this.gDnD */
3873 imports.Builder3.Main.atoms["STRING"], /* the target type we want */
3874 time /* time stamp */
3878 /* No target offered by source => error */
3881 return is_valid_drop_site;
3884 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3886 Seed.print("GtkView: drag-data-received");
3887 var delete_selection_data = false;
3888 var dnd_success = false;
3889 /* Deal with what we are given from source */
3890 if( sel_data && sel_data.length ) {
3892 if (ctx.action == Gdk.DragAction.ASK) {
3893 /* Ask the user to move or copy, then set the ctx action. */
3896 if (ctx.action == Gdk.DragAction.MOVE) {
3897 delete_selection_data = true;
3899 var source = Gtk.drag_get_source_widget( ctx );
3901 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3902 if (this.targetData) {
3903 Seed.print(this.targetData);
3904 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3913 if (dnd_success == false)
3915 Seed.print ("DnD data transfer failed!\n");
3918 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3921 button_press_event : function (self, event) {
3922 this.pressed = false;
3938 xtype: Gtk.ScrolledWindow,
3943 var file = this.get('/LeftTree').getActiveFile();
3947 var activeEl = this.get('/LeftTree').getActiveElement();
3948 var xtype = file.guessName( activeEl )
3949 if (!xtype || !xtype.length) {
3952 //this.get('/Window.view-help-nb').el.set_current_page(1);
3954 // get the active element being edited.
3955 var helpurl = file.getHelpUrl(xtype);
3957 // now load the help info in the page..
3958 this.get('help-view').el.open(helpurl);
3962 xtype: WebKit.WebView,
3966 XObject.prototype.init.call(this);
3967 this.get('/Window.help-view').el.open(
3968 "http://devel.akbkhome.com/seed/");
3980 xtype: Gtk.Notebook,
3984 XObject.prototype.init.call(this);
3985 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3986 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3987 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3991 xtype: Gtk.ScrolledWindow,
3995 xtype: Vte.Terminal,
3998 feed : function(istr) {
3999 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
4000 // we should make ourselves visable!!!
4001 this.get('/BottomPane').el.show();
4002 this.get('/BottomPane').el.set_current_page(1);
4004 this.el.feed(str ,str.length);
4006 scroll_on_output : true,
4008 XObject.prototype.init.call(this);
4009 this.el.set_size (80, 1000);
4011 scrollback_lines : 1000
4016 xtype: Gtk.ScrolledWindow,
4020 xtype: WebKit.WebView,
4036 this.get('buttonbar').el.show();
4037 this.get('viewbox').el.hide();
4038 var ce = this.get('/Window.centereast').el;
4040 ce.set_position(ce.get_allocated_width() - 30);
4042 print("TRIED TO HIDE");
4045 this.get('buttonbar').el.hide();
4046 this.get('viewbox').el.show();
4047 var ce = this.get('/Window.centereast').el;
4048 print(JSON.stringify(XObject.keys(ce) ,null,4));
4049 ce.set_position(ce.get_allocated_width() - 150);
4051 // this.get('model').expanded();
4063 pack : "pack_start,false,true",
4065 clicked : function (self) {
4066 this.get('/RightPalete').show();
4073 stock : Gtk.STOCK_GOTO_FIRST,
4074 icon_size : Gtk.IconSize.MENU
4084 XObject.prototype.init.call(this);
4085 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4088 enter_notify_event : function (self, event) {
4089 this.get('/RightPalete').show();
4103 pack : "pack_start,false,true",
4112 pack : "pack_start,false,true",
4114 clicked : function (self) {
4115 this.get('/RightPalete').hide();
4122 stock : Gtk.STOCK_GOTO_LAST,
4123 icon_size : Gtk.IconSize.MENU
4130 xtype: Gtk.ScrolledWindow,
4133 XObject.prototype.init.call(this);
4134 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4135 this.el.set_size_request(-1,200);
4137 shadow_type : Gtk.ShadowType.IN,
4140 xtype: Gtk.TreeView,
4142 drag_begin : function (self, ctx) {
4143 // we could fill this in now...
4144 Seed.print('SOURCE: drag-begin');
4149 var s = this.selection;
4150 s.get_selected(iret);
4151 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4153 var pix = this.el.create_row_drag_icon ( path);
4156 if (Gtk.drag_set_icon_surface) {
4157 Gtk.drag_set_icon_surface( ctx, pix );
4159 Gtk.drag_set_icon_pixmap (ctx,
4160 pix.get_colormap(), pix, null, -10, -10);
4163 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4164 if (!this.get('/RightPalete').provider) {
4167 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4168 this.el.dragData = value;
4175 drag_data_get : function (self, drag_context, selection_data, info, time) {
4176 //Seed.print('Palete: drag-data-get: ' + target_type);
4177 if (this.el.dragData && this.el.dragData.length ) {
4178 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4182 //this.el.dragData = "TEST from source widget";
4186 drag_end : function (self, drag_context) {
4187 Seed.print('SOURCE: drag-end');
4188 this.el.dragData = false;
4189 this.el.dropList = false;
4190 this.get('/LeftTree.view').highlight(false);
4193 button_press_event : function (self, event) {
4195 if (!this.get('/Editor').save()) {
4196 // popup!! - click handled..
4203 enable_tree_lines : true,
4204 headers_visible : false,
4206 XObject.prototype.init.call(this);
4207 this.el.set_size_request(150,-1);
4208 // set_reorderable: [1]
4210 var description = new Pango.FontDescription.c_new();
4211 description.set_size(8000);
4212 this.el.modify_font(description);
4214 this.selection = this.el.get_selection();
4215 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4216 // this.selection.signal['changed'].connect(function() {
4217 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4219 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4221 this.el.drag_source_set ( /* widget will be drag-able */
4222 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4223 null, /* lists of target to support */
4224 0, /* size of list */
4225 Gdk.DragAction.COPY /* what to do with data after dropped */
4227 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4229 this.el.drag_source_set_target_list( imports.Builder3.Main.targetList);
4230 this.el.drag_source_add_text_targets( );
4232 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4233 targets = new Gtk.TargetList();
4234 targets.add( LeftTree.atoms["STRING"], 0, 0);
4235 targets.add_text_targets( 1 );
4236 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4238 //if you want to allow text to be output elsewhere..
4239 //Gtk.drag_source_add_text_targets(this.el);
4245 xtype: Gtk.ListStore,
4248 XObject.prototype.init.call(this);
4249 this.el.set_column_types ( 2, [
4250 GObject.TYPE_STRING, // title
4251 GObject.TYPE_STRING // tip
4256 load : function(tr,iter)
4261 //console.log('Project tree load: ' + tr.length);
4263 //this.insert(citer,iter,0);
4264 for(var i =0 ; i < tr.length; i++) {
4267 this.el.append(cret);
4269 this.el.insert(cret,iter,-1);
4274 this.el.set_value(cret.iter, 0, '' + r ); // title
4276 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4277 //if (r.cn && r.cn.length) {
4278 // this.load(r.cn, citer);
4284 getValue : function (iter, col) {
4285 return this.el.get_value(iter, col).value.get_string();
4292 xtype: Gtk.TreeViewColumn,
4293 pack : "append_column",
4295 XObject.prototype.init.call(this);
4296 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4300 xtype: Gtk.CellRendererText,
4322 XObject.cache['/Window'] = Window;