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();
334 //xtype: Gtk.Expander,
337 // Gdk.EventMask.BUTTON_MOTION_MASK
341 activate : function (self) {
342 // this does not actually expand it..
343 // that is done by GTK..
346 if (!this.get('/Editor').save()) {
347 // popup!! - click handled..
351 if (!this.el.expanded) {
359 clicked : function(self) {
363 pressed : function(self) {
367 enter_notify_event : function (self, event) {
369 this.el.expanded = !this.el.expanded;
370 //if (this.el.expanded ) {
371 this.listeners.activate.call(this);
378 label : "Select Project or File",
379 pack : "pack_start,false,true",
381 onCollapse : function() {
383 var nb = this.get('/LeftTopPanel.notebook');
384 nb.el.set_current_page(0);
386 onExpand : function() {
387 var nb = this.get('/LeftTopPanel.notebook');
388 var pm = imports.ProjectManager.ProjectManager;
391 var model = this.get('/LeftProjectTree.combomodel');
392 // print ("loading Projects?")
393 //print(JSON.stringify(pm.projects, null,4));Seed.quit();
394 //console.dump(pm.projects);
395 model.loadData(pm.projects);
398 nb.el.set_current_page(1);
399 //pm.on('changed', function() {
400 //console.log("CAUGHT project manager change");
401 // _combo.model.loadData(pm.projects);
409 pack : "pack_start,true,true",
416 xtype: Gtk.ScrolledWindow,
419 getActiveElement : function() { // return path to actie node.
421 var path = this.getActivePath();
426 this.get('model').el.get_iter_from_string(ret, path);
428 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
430 return JSON.parse(value);
432 getActiveFile : function() {
433 return this.get('model').file;
435 getActivePath : function() {
436 var model = this.get('model');
437 var view = this.get('view');
438 if (view.selection.count_selected_rows() < 1) {
442 view.selection.get_selected(ret);
443 return ret.model.get_path(ret.iter).to_string();
445 getPaleteProvider : function() {
446 var model = this.get('model');
447 var pm = imports.ProjectManager.ProjectManager;
448 return pm.getPalete(model.file.getType());
450 getRenderer : function() {
452 switch( this.getActiveFile().getType()) {
454 return this.get('/RightBrowser.view');
456 return this.get('/RightGtkView');
462 renderView : function() {
463 var render = this.getRenderer();
464 var model = this.get('model');
466 render.renderJS(model.toJS(false,true)[0]);
468 print("NO RENDER JS METHOD?");
471 shadow_type : Gtk.ShadowType.IN,
476 button_press_event : function (self, ev) {
477 console.log("button press?");
479 if (!this.get('/Editor').save()) {
480 // popup!! - click handled..
484 if (ev.button.button != 3) {
485 print("click" + ev.button.button);
491 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
493 if (!this.get('/LeftTreeMenu').el) {
494 this.get('/LeftTreeMenu').init();
497 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
498 this.get('/LeftTreeMenu').el.show_all();
499 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
500 print("click:" + res.path.to_string());
503 drag_begin : function (self, ctx) {
504 print('SOURCE: drag-begin');
505 this.targetData = false;
506 // find what is selected in our tree...
508 this.selection.get_selected(ret);
510 // set some properties of the tree for use by the dropped element.
511 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
512 var data = JSON.parse(value);
513 var xname = this.get('/LeftTree.model').file.guessName(data);
515 this.el.dragData = xname;
516 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
519 // make the drag icon a picture of the node that was selected
520 var path = ret.model.get_path(ret.iter);
521 this.el.treepath = path.to_string();
523 // returns a cairo surface
524 var pix = this.el.create_row_drag_icon ( path);
526 if (Gtk.drag_set_icon_surface) {
527 Gtk.drag_set_icon_surface( ctx, pix );
529 Gtk.drag_set_icon_pixmap (ctx,
530 pix.get_colormap(), pix, null, -10, -10);
535 drag_end : function (self, drag_context) {
536 Seed.print('LEFT-TREE: drag-end');
537 this.el.dragData = false;
538 this.el.dropList = false;
539 this.targetData = false;
540 this.get('/LeftTree.view').highlight(false);
543 drag_data_get : function(self, ctx, sel_data, info, time)
553 drag_motion : function (self, ctx, x, y, time) {
554 console.log("LEFT-TREE: drag-motion");
555 var src = Gtk.drag_get_source_widget( ctx);
557 // a drag from elsewhere...- prevent drop..
559 print("no drag data!");
560 Gdk.drag_status(ctx, 0, time);
561 this.targetData = false;
564 var action = Gdk.DragAction.COPY;
565 if (src == this.el) {
566 // unless we are copying!!! ctl button..
567 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
571 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
572 // no children.. -- asume it's ok..
573 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
574 Gdk.drag_status(ctx, action ,time);
578 print("GETTING POS");
579 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
580 print("ISOVER? " + isOver);
582 Gdk.drag_status(ctx, 0 ,time);
583 return false; // not over apoint!?!
585 // drag node is parent of child..
586 console.log("SRC TREEPATH: " + src.treepath);
587 console.log("TARGET TREEPATH: " + data.path.to_string());
589 // nned to check a few here..
590 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
591 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
592 //Gtk.TreeViewDropPosition.AFTER
593 //Gtk.TreeViewDropPosition.BEFORE
595 if (typeof(src.treepath) != 'undefined' &&
596 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
597 print("subpath drag");
598 Gdk.drag_status( ctx, 0 ,time);
603 //print("DUMPING DATA");
604 //console.dump(data);
607 print(data.path.to_string() +' => '+ data.pos);
608 var tg = this.get('/LeftTree.model').findDropNodeByPath(
609 data.path.to_string(), src.dropList, data.pos);
611 this.get('/LeftTree.view').highlight(tg);
613 print("Can not find drop node path");
614 this.targetData = false;
615 Gdk.drag_status(ctx, 0, time);
618 print(JSON.stringify(tg,null,4));
620 this.targetData = tg;
623 Gdk.drag_status(ctx, action ,time);
627 drag_drop : function (w, ctx, x, y, time) {
628 Seed.print("TARGET: drag-drop");
629 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
631 ( /* will receive 'drag-data-received' signal */
632 ctx, /* represents the current state of the DnD */
633 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
634 time /* time stamp */
638 /* No target offered by source => error */
643 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
644 print("Tree: drag-data-received");
646 var delete_selection_data = false;
647 var dnd_success = false;
648 //print(JSON.stringify(sel_data, null,4));
649 /* Deal with what we are given from source */
651 // simce I can not be bothered to sort out
652 // drag drop = let's assume it worked...
654 if( true || (sel_data && sel_data.length )) {
656 if (ctx.action == Gdk.DragAction.ASK) {
657 /* Ask the user to move or copy, then set the ctx action. */
660 if (ctx.action == Gdk.DragAction.MOVE) {
661 //delete_selection_data = true;
664 var source = Gtk.drag_get_source_widget( ctx );
666 if (this.targetData) {
667 if (source != this.el) {
668 print("DRAG FROM ANOTHER WIDGET");
669 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
671 // drag around.. - reorder..
672 print("DRAG FROM SELF");
673 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
677 //Seed.print(this.targetData);
683 // we can send stuff to souce here...
689 if (dnd_success == false)
691 Seed.print ("DnD data transfer failed!\n");
694 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
697 cursor_changed : function (self) {
698 if (this.blockChanges) { // probably not needed..
701 var render = this.get('/LeftTree').getRenderer();
704 if (this.selection.count_selected_rows() < 1) {
705 this.get('/LeftPanel.model').load( false);
706 this.get('/MidPropTree').activeElement = false;
707 this.get('/MidPropTree').hideWin();
709 var pm = this.get('/RightPalete.model');
710 if (!this.get('/LeftTree').getPaleteProvider()) {
711 // it may not be loaded yet..
715 this.get('/LeftTree').getPaleteProvider().gatherList(
716 this.get('/LeftTree.model').listAllTypes()
719 if (render && render.redraw) {
725 //console.log('changed');
726 var s = this.selection;
731 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
732 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
734 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
737 var data = JSON.parse(value);
738 this.get('/MidPropTree').activeElement = data;
739 this.get('/MidPropTree').hideWin();
740 this.get('/LeftPanel.model').load( data);
743 // _g.button.set_label(''+value.get_string());
745 var pm =this.get('/RightPalete.model');
746 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
747 this.get('/LeftTree.model').listAllTypes()));
750 if (render && render.redraw) {
754 //Seed.print( value.get_string());
762 enable_tree_lines : true,
763 headers_visible : false,
764 highlight : function(treepath_ar) {
766 // highlighting for drag/drop
767 if (treepath_ar.length && treepath_ar[0].length ) {
768 this.el.set_drag_dest_row(
769 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
771 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
777 XObject.prototype.init.call(this);
778 var description = new Pango.FontDescription.c_new();
779 description.set_size(8000);
780 this.el.modify_font(description);
782 this.selection = this.el.get_selection();
783 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
786 // is this really needed??
787 this.selection.signal['changed'].connect(function() {
788 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
789 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
793 this.el.drag_source_set( /* widget will be drag-able */
794 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
795 null, /* lists of target to support */
796 0, /* size of list */
797 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
800 this.el.drag_source_set_target_list(imports.Builder3.Globals.targetList);
802 this.el.drag_source_add_text_targets();
803 this.el.drag_dest_set
805 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
806 null, /* lists of target to support */
807 0, /* size of list */
808 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
811 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
812 this.el.drag_dest_add_text_targets( );
814 selectNode : function(treepath_str) {
815 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
816 var tp = new Gtk.TreePath.from_string(treepath_str);
817 this.el.set_cursor(tp, null, false);
818 this.el.scroll_to_cell(tp, null, false, 0,0);
822 xtype: Gtk.TreeStore,
828 setFromNode : function(tp, n)
831 tp = this.get('/LeftTree').getActivePath();
834 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
835 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
836 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
837 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
841 changed : function( refresh) {
845 print("-------MODEL CHANGED CALLED" );
847 //this.currentTree = this.toJS(false, true)[0];
849 this.file.items = this.toJS(false, false);
850 print ("TO JS in " + ((new Date()) - d) + "ms");
851 // print("AFTER CHANGED");
852 //console.dump(this.file.items);
854 this.currentTree = this.file.items[0];
855 //console.log(this.file.toSource());
858 print("REDNER BROWSER?!");
859 this.get('/LeftTree').renderView();
861 var pm = this.get('/RightPalete.model');
862 if (!this.get('/RightPalete').provider) {
868 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
869 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
873 deleteSelected : function() {
874 this.get('/LeftTree.view').blockChanges = true;
876 var s = this.get('/LeftTree.view').selection;
877 s.get_selected(oret);
878 var path = this.el.get_path(oret.iter).to_string();
880 this.activePath= false;
883 this.activePath= false;
885 this.el.get_iter_from_string(ret, path);
886 this.el.remove(ret.iter);
888 // rebuild treemap. -- depreciated.!!
891 //this.toJS(null, true) // does not do anything?
892 this.activePath= false;
894 this.get('/LeftTree.view').blockChanges = false;
896 dropNode : function(target_data, node) {
898 // console.dump(node);
899 //print(JSON.Stringify(target_data, null, 4));
900 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
902 print("add " + tp + "@" + target_data[1] );
905 if (tp && target_data[1] < 2) { // before or after..
906 var ar = target_data[0].split(':');
908 parent = new Gtk.TreePath.from_string( ar.join(':') );
913 var aret = after ? {} : false;
917 if (parent !== false) {
918 this.el.get_iter(pret, parent);
925 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
926 this.el.get_iter(aret, after);
927 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
928 nret, pret.iter, aret.iter);
931 this.el.append(nret, pret.iter);
934 var new_path = this.el.get_path(nret.iter).to_string();
935 print("new path = " + new_path)
936 if (typeof(node) == 'string') {
937 var ar = node.split('.');
938 var xtype = ar.pop();
941 '|xns' : ar.join('.'),
944 if (target_data.length == 3 && target_data[2].length) {
945 node['*prop'] = target_data[2];
947 node = this.get('/DialogTemplateSelect').show(node);
950 // work out what kind of packing to use..
951 if (typeof(node.pack) == 'undefined' && parent !== false) {
952 var pal = this.get('/LeftTree').getPaleteProvider();
953 if (pal.name == 'Gtk') {
954 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
955 var cname = pal.guessName(node);
956 node.pack = pal.getDefaultPack(pname, cname);
967 // load children - if it has any..
970 this.load(xitems, nret.iter);
971 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
973 if (tp && (xitems || after)) {
974 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
976 // wee need to get the empty proptypes from somewhere..
978 //var olditer = this.activeIter;
979 //this.activePath = new_path;
980 print("calling changed with node data")
981 // changed actually set's the node data..
982 this.setFromNode(new_path,node);
987 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
989 //Builder.MidPropTree._model.load(node);
990 //Builder.MidPropTree._win.hideWin();
991 //Builder.LeftPanel._model.load( node);
995 findDropNode : function(treepath_str, targets) {
997 // this is used by the dragdrop code in the roo version AFAIR..
999 var path = treepath_str.replace(/^builder-/, '');
1000 // treemap is depreciated... - should really check if model has any entries..
1002 if (!this.el.iter_n_children(null)) {
1004 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
1006 print("FIND treepath: " + path);
1007 //console.dump(this.treemap);
1009 if (!treepath_str.match(/^builder-/)) {
1010 return []; // nothing!
1012 if (targets === true) {
1015 return this.findDropNodeByPath(path,targets)
1017 findDropNodeByPath : function(treepath_str, targets, pref) {
1018 var path = treepath_str + ''; // dupe it..
1019 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1021 //console.dump(this.treemap);
1022 while (path.length) {
1023 print("LOOKING FOR PATH: " + path);
1024 var node_data = this.singleNodeToJS(path);
1025 if (node_data === false) {
1026 print("node not found");
1030 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1033 targets.forEach(function(tg) {
1037 if ((tg == xname) ) {
1040 if (tg.indexOf(xname +':') === 0) {
1042 prop = tg.split(':').pop();
1047 if (last) { // pref is after/before..
1048 // then it's after last
1050 return []; // do not allow..
1052 return [ last, pref , prop];
1055 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1057 var par = path.split(':');
1060 path = par.join(':');
1066 getIterValue : function (iter, col) {
1068 var gval = ''+this.el.get_value(iter, col).value.get_string();
1074 GObject.TYPE_STRING, // title
1075 GObject.TYPE_STRING, // tip
1076 GObject.TYPE_STRING // source..
1081 listAllTypes : function() {
1082 var s = this.get('/LeftTree.view').selection;
1083 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1085 if (s.count_selected_rows() > 0) {
1087 s.get_selected(ret);
1089 // set some properties of the tree for use by the dropped element.
1090 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1091 var data = JSON.parse(value);
1094 var xname = this.get('/LeftTree.model').file.guessName(data);
1095 console.log('selected:' + xname);
1099 return []; // could not find it..
1108 for (var i =0 ; i < li.length; i++ ) {
1111 // this is specific to roo!!!?
1112 if (!el) { // skip empty?
1115 var fullpath = _this.file.guessName(el);
1116 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1121 if (el.items && el.items.length) {
1130 addall([this.currentTree]);
1132 // only if we have nothing, should we add '*top'
1136 //console.log('all types in tree');
1137 //console.dump(ret);
1142 load : function(tr,iter)
1144 //this.insert(citer,iter,0);
1146 for(var i =0 ; i < tr.length; i++) {
1149 this.el.insert(ret ,iter,-1);
1151 this.el.append(ret);
1153 //print(JSON.stringify(ret,null,4));
1154 //print('call nodeToJSON: ' + tr[i]);
1155 var body = this.nodeToJSON(tr[i]);
1157 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1158 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1159 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1160 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1161 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1162 this.el.set_value(ret.iter, 2, '' + body );
1163 if (tr[i].items && tr[i].items.length) {
1164 this.load(tr[i].items, ret.iter);
1168 loadFile : function(f) {
1175 console.log('missing file');
1179 // load the file if not loaded..
1180 if (f.items === false) {
1182 f.loadItems(function() {
1188 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1190 if (f.items.length && typeof(f.items[0]) == 'string') {
1192 //this.get('/RightEditor').el.show();
1193 //this.get('/RightEditor.view').load( f.items[0]);
1197 //print(JSON.stringify(f.items, null,4));
1198 //console.dump(f.items);
1200 this.get('/LeftTree.view').el.expand_all();
1202 if (!f.items.length) {
1205 this.get('/Window.leftvpaned').el.set_position(80);
1207 this.get('/LeftTree.view').el.set_cursor(
1208 new Gtk.TreePath.from_string('0'), null, false);
1212 this.get('/Window.leftvpaned').el.set_position(200);
1215 //return; -- debuggin
1216 //print("hide right editior");
1217 //this.get('/RightEditor').el.hide();
1218 this.get('/Editor').el.hide();
1219 print("set current tree");
1221 this.currentTree = this.toJS(false, false)[0];
1224 //console.dump(this.currentTree);
1225 this.currentTree = this.currentTree || { items: [] };
1226 this.get('/LeftTree').renderView();
1227 // console.dump(this.map);
1228 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1229 var pm = this.get('/RightPalete.model');
1230 // set up provider..
1232 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1234 if (!this.get('/RightPalete').provider) {
1235 print ("********* PALETE PROVIDER MISSING?!!");
1237 this.get('/LeftTree').renderView();
1239 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1243 this.get('/Window.view-notebook').el.set_current_page(
1244 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1247 moveNode : function(target_data, action) {
1248 //print("MOVE NODE");
1249 // console.dump(target_data);
1251 var s = this.get('/LeftTree.view').selection;
1252 s.get_selected( oret);
1253 var node = this.nodeToJS(oret.iter,false);
1254 //console.dump(node);
1255 print(JSON.stringify(node, null,4));
1257 // needs to drop first, otherwise the target_data
1258 // treepath will be invalid.
1260 this.dropNode(target_data, node);
1261 if (action & Gdk.DragAction.MOVE) {
1262 // print("REMOVING OLD NODE");
1263 this.el.remove(oret.iter);
1267 this.activePath= false;
1270 nodeTip : function(c) {
1271 var ret = this.nodeTitle(c,true);
1277 if (!i.length || i[0] != '|') {
1283 if (typeof(c[i]) != 'string') {
1286 //print("prop : " + i + ':' + c[i]);
1287 if (!c[i].match(new RegExp('function'))) {
1290 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1294 ret+="\n\nMethods:" + funcs;
1299 nodeTitle : function(c, renderfull) {
1302 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1303 if (sr) txt.push('<s>');
1304 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1306 if (renderfull && c['|xns']) {
1307 txt.push(c['|xns']);
1310 if (c.xtype) { txt.push(c.xtype); }
1311 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1312 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1313 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1316 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1317 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1318 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1319 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1320 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1321 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1322 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1323 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1324 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1326 // for flat classes...
1327 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1328 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1331 if (sr) txt.push('</s>');
1332 return (txt.length == 0 ? "Element" : txt.join(" "));
1334 nodeToJS : function (treepath, with_id)
1336 //print("nodeToJS : WITHID: "+ with_id);
1337 var iter = treepath; // API used to be iter here..
1338 if (typeof(iter) == 'string') {
1340 if (!this.el.get_iter(ret,
1341 new Gtk.TreePath.from_string(treepath))) {
1347 var iv = this.getIterValue(iter, 2);
1348 // print("IV" + iv);
1349 var k = JSON.parse(iv);
1350 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1355 var treepath_str = this.el.get_path(iter).to_string();
1356 // not sure how we can handle mixed id stuff..
1357 if (typeof(k.id) == 'undefined') {
1358 k.id = 'builder-'+ treepath_str ;
1362 this.treemap[ treepath_str ] = k;
1363 k.xtreepath = treepath_str ;
1366 if (this.el.iter_has_child(iter)) {
1368 this.el.iter_children(cret, iter);
1369 k.items = this.toJS(cret.iter,with_id);
1373 nodeToJSON : function(c) {
1381 return JSON.stringify(o);
1383 singleNodeToJS : function (treepath)
1386 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1390 var iv = this.getIterValue(ret.iter, 2);
1392 return JSON.parse(iv);
1395 toJS : function(treepath, with_id)
1397 //print("toJS : WITHID: "+ with_id);
1399 var iter = treepath; // API used to be iter here..
1401 if (typeof(iter) == 'string') {
1403 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1415 if (!this.el.get_iter_first(ret)) {
1426 var k = this.nodeToJS(iter, with_id);
1430 if (!this.el.iter_next(iter)) {
1435 if (treepath === false) {
1437 return JSON.parse(JSON.stringify(ar));
1441 // convert the list into a json string..
1447 xtype: Gtk.TreeViewColumn,
1448 pack : "append_column",
1450 XObject.prototype.init.call(this);
1451 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1455 xtype: Gtk.CellRendererText,
1465 id : "LeftTreeMenu",
1468 xtype: Gtk.MenuItem,
1470 label : "Delete Element",
1472 activate : function (self) {
1474 this.get('/LeftTree.model').deleteSelected();
1479 xtype: Gtk.MenuItem,
1481 activate : function (self) {
1483 var tree = this.get('/LeftTree');
1484 var model = this.get('/LeftTree.model');
1485 var el = tree.getActivePath();
1487 var js = model.toJS(el, false);
1488 // print(JSON.stringify(js[0], null,4));
1489 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1494 label : "Save as Template",
1504 id : "LeftProjectTree",
1505 showNoProjectSelected : function() {
1506 this.get('/StandardErrorDialog').show("Select a Project first.");
1508 getActiveProject : function() {
1509 return this.project;
1512 leave_notify_event : function (self, event) {
1519 pack : "pack_start,false,false",
1522 xtype: Gtk.ComboBox,
1524 changed : function (self) {
1525 var fn = this.getValue();
1526 var pm = imports.ProjectManager.ProjectManager;
1527 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1531 getValue : function() {
1532 var ix = this.el.get_active();
1536 var data = imports.ProjectManager.ProjectManager.projects;
1537 if (typeof(data[ix]) == 'undefined') {
1543 XObject.prototype.init.call(this);
1544 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1546 setValue : function(fn)
1550 var data = imports.ProjectManager.ProjectManager.projects;
1551 data.forEach(function(n, ix) {
1560 xtype: Gtk.CellRendererText,
1561 pack : "pack_start,true",
1565 xtype: Gtk.ListStore,
1570 GObject.TYPE_STRING,
1576 loadData : function(data) {
1577 //print("load data called");Seed.quit();
1578 //print(data);Seed.quit();
1580 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,
1611 xtype: Gtk.TreeView,
1614 cursor_changed : function (self) {
1616 var model = this.get('/LeftProjectTree.model');
1620 if (model.loading) {
1625 print("LOADING IS FALSE");
1627 if (this.selection.count_selected_rows() < 1) {
1628 //XN.get('Builder.LeftTree.model').
1629 this.get('/LeftTree.model').load( false);
1633 //console.log('changed');
1634 var s = this.selection;
1635 s.get_selected(ret);
1636 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1637 //console.log(JSON.stringify(value,null,4));// id..
1638 console.log("OUT?" + value);// id..
1639 var file = this.get('/LeftProjectTree').project.getById(value);
1646 var nb = this.get('/LeftTopPanel.expander');
1647 nb.el.expanded = false;
1649 //nb.listeners.activate.call(nb);
1650 //_expander.el.set_expanded(false);
1652 var ltm = this.get('/LeftTree.model');
1660 enable_tree_lines : true,
1661 headers_visible : false,
1663 XObject.prototype.init.call(this);
1664 var description = new Pango.FontDescription.c_new();
1665 description.set_size(8000);
1666 this.el.modify_font(description);
1668 this.selection = this.el.get_selection();
1669 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1673 xtype: Gtk.TreeStore,
1678 GObject.TYPE_STRING, // title
1679 GObject.TYPE_STRING, // tip
1680 GObject.TYPE_STRING // id..
1684 loadProject : function(pr) {
1685 print("LOAD PROJECT");
1686 var model = this.get('/LeftProjectTree.model');
1687 model.loading = true;
1694 this.get('/LeftProjectTree').project = pr;
1696 this.load(pr.toTree());
1698 this.get('/LeftProjectTree.view').el.expand_all();
1699 model.loading = false;
1702 load : function(tr,iter) {
1703 // console.dump(tr);
1706 console.log('Project tree load: ' + tr.length);
1708 //this.insert(citer,iter,0);
1712 tr.forEach(function (r) {
1714 _this.el.append(cret);
1716 _this.el.insert(cret,iter,-1);
1718 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1719 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1720 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1721 if (r.cn && r.cn.length) {
1722 _this.load(r.cn, cret.iter);
1728 getValue : function(iter, col) {
1729 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1734 xtype: Gtk.TreeViewColumn,
1735 pack : "append_column",
1737 XObject.prototype.init.call(this);
1738 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1742 xtype: Gtk.CellRendererText,
1762 pack : "pack_start,false,true,0",
1769 button_press_event : function (self, event) {
1770 this.get('/MidPropTree.model').showData('props');
1782 stock : Gtk.STOCK_ADD,
1783 icon_size : Gtk.IconSize.MENU
1797 button_press_event : function (self, event) {
1799 if (!this.get('/Editor').save()) {
1800 // popup!! - click handled..
1803 this.get('/MidPropTree.model').showData('events');
1816 stock : Gtk.STOCK_ADD,
1817 icon_size : Gtk.IconSize.MENU
1831 button_press_event : function (self, ev) {
1833 if (!this.get('/Editor').save()) {
1834 // popup!! - click handled..
1838 var p = this.get('/AddPropertyPopup');
1842 p.el.set_screen(Gdk.Screen.get_default());
1844 p.el.popup(null, null, null, null, 3, ev.button.time);
1857 stock : Gtk.STOCK_ADD,
1858 icon_size : Gtk.IconSize.MENU
1870 id : "AddPropertyPopup",
1873 xtype: Gtk.MenuItem,
1875 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1878 activate : function (self) {
1880 this.get('/LeftPanel.model').add( {
1891 xtype: Gtk.MenuItem,
1893 tooltip_markup : "Add what type of packing is to be used",
1896 activate : function (self) {
1898 this.get('/LeftPanel.model').add( {
1908 xtype: Gtk.MenuItem,
1910 tooltip_markup : "Override the init method",
1913 activate : function (self) {
1915 this.get('/LeftPanel.model').add( {
1918 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1925 xtype: Gtk.SeparatorMenuItem,
1929 xtype: Gtk.MenuItem,
1931 tooltip_markup : "Add a user defined string property",
1934 activate : function (self) {
1936 this.get('/LeftPanel.model').add( {
1946 xtype: Gtk.MenuItem,
1948 tooltip_markup : "Add a user defined number property",
1951 activate : function (self) {
1953 this.get('/LeftPanel.model').add( {
1963 xtype: Gtk.MenuItem,
1965 tooltip_markup : "Add a user defined boolean property",
1968 activate : function (self) {
1970 this.get('/LeftPanel.model').add( {
1980 xtype: Gtk.SeparatorMenuItem,
1984 xtype: Gtk.MenuItem,
1986 tooltip_markup : "Add a user function boolean property",
1989 activate : function (self) {
1991 this.get('/LeftPanel.model').add( {
1994 val : "function() {\n \n}\n",
2007 xtype: Gtk.ScrolledWindow,
2012 shadow_type : Gtk.ShadowType.IN,
2015 xtype: Gtk.TreeView,
2017 button_press_event : function (self, ev) {
2020 if (!this.get('/Editor').save()) {
2021 // popup!! - click handled..
2026 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2027 return false; //not on a element.
2031 if (ev.button.button == 3) {
2033 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2036 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2037 var p = this.get('/LeftPanelPopup');
2042 p.el.set_screen(Gdk.Screen.get_default());
2044 p.el.popup(null, null, null, null, 3, ev.button.time);
2045 //Seed.print("click:" + res.column.title);
2052 if (res.column.title != 'value') {
2053 // XObject.error("column is not value?");
2054 return false; // ignore.. - key click.. ??? should we do this??
2057 // currently editing???
2058 // if ( this.activePath) {
2060 // this.activePath = false;
2062 if (this.get('/Editor').dirty) {
2063 //if (!this.get('/Editor.buffer').checkSyntax()) {
2064 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2068 if (!this.get('/Editor.view').save()) {
2072 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2073 this.get('/LeftPanel').editing = false;
2075 // XObject.error("Currently editing?");
2079 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2081 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2083 // get options for this type -- this is to support option lists etc..
2084 var provider = this.get('/LeftTree').getPaleteProvider();
2085 var opts = provider.findOptions(type);
2087 if (opts === false) {
2089 this.get('/LeftPanel').editableColumn.setOptions([]);
2090 renderer.has_entry = true;
2092 this.get('/LeftPanel').editableColumn.setOptions(opts);
2093 renderer.has_entry = false;
2095 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2097 //Seed.print("click" + ev.type);
2098 //console.dump(res);
2107 enable_tree_lines : true,
2108 headers_visible : false,
2110 XObject.prototype.init.call(this);
2112 this.selection = this.el.get_selection();
2113 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2116 var description = new Pango.FontDescription.c_new();
2117 description.set_size(8000);
2118 this.el.modify_font(description);
2122 xtype: Gtk.TreeStore,
2126 add : function(info) {
2127 // info includes key, val, skel, etype..
2129 type = info.type.toLowerCase();
2130 var data = this.toJS();
2132 if (info.etype == 'events') {
2133 data.listeners = data.listeners || { };
2134 if (typeof(data.listeners[info.key]) != 'undefined') {
2135 return; //already set!
2138 if (typeof(data[info.key]) != 'undefined') {
2143 if (typeof(info.val) == 'undefined') {
2146 if (info.type.toLowerCase() == 'boolean') {
2149 if (type == 'number') {
2157 if (info.etype == 'events') {
2159 data.listeners[info.key] = info.val;
2162 data[info.key] = info.val;
2166 var map = this.load(data);
2168 // flag it as changed to the interface..
2169 this.get('/LeftTree.model').setFromNode(false,node);
2170 this.get('/LeftTree.model').changed(true);
2173 this.startEditing(map[k]);
2176 LeftPanel.get('view').el.row_activated(
2177 new Gtk.TreePath.from_string(map[k]),
2178 LeftPanel.editableColumn.el
2182 changed : function(str, doRefresh) {
2183 if (!this.activePath) {
2184 print("NO active path when changed")
2188 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2190 this.el.set_value(ret.iter, 1, '' +str);
2191 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2192 var type = this.getIterValue(ret.iter, 4);
2194 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2195 // update the tree...
2196 print("new data: " + JSON.stringify(this.toJS() , null,4));
2197 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2198 this.get('/LeftTree.model').changed(doRefresh);
2201 deleteSelected : function() {
2202 var data = this.toJS();
2204 var s = this.get('/LeftPanel.view').selection;
2205 s.get_selected( ret);
2208 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2210 if (val[0] == '!') {
2212 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2215 delete data.listeners[ val.substring(1)];
2216 if (!XObject.keys(data.listeners).length) {
2217 delete data.listeners;
2221 if (typeof(data[val]) == 'undefined') {
2231 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2232 this.get('/LeftTree.model').changed(true);
2236 getIterValue : function(iter, col) {
2237 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2240 getType : function(treepath) {
2241 return this.getValue(treepath, 4);
2243 getValue : function(treepath_str, col)
2245 // get's the value in a row.. - keys - returns string, values - formats it..
2247 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2249 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2254 var type = this.getType(this.el.get_path(ret.iter).to_string());
2255 //print("TYPE: " +type + " - val:" + val);
2256 switch(type.toLowerCase()) {
2260 return parseFloat(val); // Nan ?? invalid!!?
2263 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2265 return val == 'true' ? true : false;
2267 var nv = parseFloat(val);
2268 if (!isNaN(nv) && (val == ''+nv)) {
2276 GObject.TYPE_STRING, // 0 real key
2277 GObject.TYPE_STRING, // 1 real value
2278 GObject.TYPE_STRING, // 2 visable key
2279 GObject.TYPE_STRING, // 3 visable value
2280 GObject.TYPE_STRING, // 4 need to store type of!!!
2281 GObject.TYPE_STRING // 5 tooltip
2285 load : function(ar) {
2286 // might casue problesm..
2287 // this.get('/Editor.RightEditor').save();
2289 this.get('/Editor').el.hide();
2290 this.get('/Editor').activePath = false;
2295 //this.get('/RightEditor').el.hide();
2302 var provider = this.get('/LeftTree').getPaleteProvider();
2306 var keys = XObject.keys(ar);
2308 ar.listeners = ar.listeners || {};
2310 for (var i in ar.listeners ) {
2312 this.el.append(iret);
2313 var p = this.el.get_path(iret.iter).to_string();
2316 this.el.set_value(iret.iter, 0, '!'+ i );
2317 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2318 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2320 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2321 this.el.set_value(iret.iter, 4, 'function');
2322 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2328 keys.forEach(function(i) {
2329 if (typeof(ar[i]) == 'object') {
2333 var type = provider.findType(ar, i, ar[i]);
2335 _this.el.append(iret);
2336 var p = _this.el.get_path(iret.iter).to_string();
2338 _this.el.set_value(iret.iter, 0, ''+i);
2339 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2340 _this.el.set_value(iret.iter, 2, ''+i);
2341 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2342 _this.el.set_value(iret.iter, 4, ''+type);
2343 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2347 startEditing : function(path,col) {
2349 // alled by menu 'edit' currently..
2351 * start editing path (or selected if not set..)
2352 * @param {String|false} path (optional) treepath to edit - selected tree gets
2353 * edited by default.
2354 * @param {Number} 0 or 1 (optional)- column to edit.
2356 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2358 if (typeof(path) == 'string') {
2359 tp = new Gtk.TreePath.from_string(path);
2362 var s = this.get('/LeftPanel.view').selection;
2363 s.get_selected( itr);
2364 tp = this.el.get_path(itr.iter);
2365 path = tp.to_string();
2369 // which colum is to be edited..
2372 // not sure what this does..
2374 if (typeof(col) == 'undefined') {
2375 var k = this.getValue(path, 0);
2377 colObj = (!k.length || k == '|') ?
2378 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2380 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2383 // make sure the pulldown is set correctly..
2384 // not really needed for second col...
2385 var showEditor = false;
2386 this.get('/Editor').activePath = false;
2387 this.get('/Editor').el.hide();
2390 var provider = this.get('/LeftTree').getPaleteProvider();
2391 var type = this.get('/LeftPanel.model').getType(path);
2392 var opts = provider.findOptions(type);
2393 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2395 if (opts === false) {
2396 this.get('/LeftPanel').editableColumn.setOptions([]);
2397 renderer.has_entry = true;
2399 this.get('/LeftPanel').editableColumn.setOptions(opts);
2400 renderer.has_entry = false;/// - pulldowns do not have entries
2402 // determine if we should use the Text editor...
2403 var keyname = this.getValue(path, 0);
2404 var data_value = this.getValue(path, 1);
2406 if ((keyname[0] == '|') ||
2408 (typeof(data_value) == 'string' ) &&
2409 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2413 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2418 // this.get('/BottomPane').el.hide();
2419 //this.get('/RightEditor').el.hide();
2424 this.activePath = false;
2426 _this.get('/Editor').el.show_all();
2427 GLib.timeout_add(0, 1, function() {
2429 //_this.get('/BottomPane').el.show();
2430 //_this.get('/RightEditor').el.show();
2432 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2434 _this.get('/Editor').activePath = path;
2435 _this.activePath = path ;
2445 // iter now has row...
2446 GLib.timeout_add(0, 100, function() {
2447 _this.activePath = path;
2448 colObj.items[0].el.editable = true; // esp. need for col 0..
2449 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2460 this.get('/LeftPanel.model').el.get_iter_first(iret);
2466 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2469 ar.listeners = ar.listeners || {};
2470 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2473 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2476 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2482 //print(JSON.stringify(ar));
2486 toShort : function(str) {
2487 var a = typeof(str) == 'string' ? str.split("\n") : [];
2488 return a.length > 1 ? a[0] + '....' : '' + str;
2492 xtype: Gtk.TreeViewColumn,
2493 pack : "append_column",
2495 XObject.prototype.init.call(this);
2497 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2498 this.get('/LeftPanel').propertyColumn = this;
2503 xtype: Gtk.CellRendererText,
2504 pack : "pack_start",
2506 editing_started : function (self, editable, path) {
2508 this.get('/LeftPanel.model').activePath = path;
2511 edited : function (self, object, p0) {
2513 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2515 var model = this.get('/LeftPanel.model');
2516 var path = model.activePath;
2518 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2519 model.el.set_value(iret.iter, 0, p0);
2520 model.el.set_value(iret.iter, 2, p0);
2522 model.activePath = false;
2523 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2524 this.get('/LeftTree.model').changed(true);
2526 this.el.editable = false;
2533 xtype: Gtk.TreeViewColumn,
2534 pack : "append_column",
2537 XObject.prototype.init.call(this);
2538 this.el.add_attribute(this.items[0].el , 'text', 3 );
2539 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2540 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2541 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2543 this.get('/LeftPanel').editableColumn= this;
2545 setOptions : function(ar) {
2546 var m = this.items[0].el.model;
2549 ar.forEach(function(i) {
2553 m.set_value(iret.iter, 0, i);
2559 xtype: Gtk.CellRendererCombo,
2561 edited : function (self, object, p0) {
2563 this.get('/LeftPanel').editing = false;
2564 var ap = this.get('/LeftPanel.model').activePath
2565 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2566 this.get('/LeftPanel.model').changed(p0, true);
2567 this.get('/LeftPanel.model').activePath = false;
2568 this.el.editable = false;
2570 editing_started : function (self, editable, path) {
2571 this.get('/LeftPanel').editing = true;
2572 // console.log('editing started');
2573 // r.has_entry = false;
2575 this.el.editable = false; // make sure it's not editor...
2580 pack : "pack_start",
2584 XObject.prototype.init.call(this);
2585 this.el.model = new Gtk.ListStore();
2586 this.el.model.set_column_types ( 1, [
2587 GObject.TYPE_STRING // 0 real key
2598 id : "LeftPanelPopup",
2601 xtype: Gtk.MenuItem,
2605 activate : function (self) {
2606 this.get('/LeftPanel.model').deleteSelected();
2611 xtype: Gtk.MenuItem,
2615 activate : function (self) {
2616 this.get('/LeftPanel.model').startEditing(false, 0);
2629 xtype: Gtk.ScrolledWindow,
2630 pack : "pack_end,false,true,0",
2633 shadow_type : Gtk.ShadowType.IN,
2635 XObject.prototype.init.call(this);
2636 XObject.prototype.init.call(this);
2637 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2638 this.el.set_size_request ( 150, -1 );
2641 activeElement : false,
2642 hideWin : function() {
2645 print("HIDEWIN - currently not shown")
2650 if (this.get('/Window.left').el.position < 160) {
2651 print("HIDEWIN - small already.")
2655 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2656 print("HIDEWIN attempting to hide.")
2663 xtype: Gtk.TreeView,
2665 cursor_changed : function (self) {
2666 // this is getting fired when we are loading elements..
2667 if (this.get('/MidPropTree.model').loading) {
2673 //console.log('changed');
2674 var m = this.get('model');
2675 if (!this.selection){
2676 this.selection = this.el.get_selection();
2679 var s = this.selection;
2680 if (!s.get_selected(iret)) {
2683 var tp = m.el.get_path(iret.iter).to_string();
2688 var key = m.getValue(tp, 0);
2690 var type = m.getValue(tp, 1);
2691 var skel = m.getValue(tp, 3);
2692 var etype = m.getValue(tp, 5);
2695 this.get('/MidPropTree').hideWin();
2697 if (type.toLowerCase() == 'function') {
2699 if (etype != 'events') {
2702 print("cursor_changed: ADDding to left panel model");
2703 this.get('/LeftPanel.model').add({
2711 // has dot in name, and is boolean???? this does not make sense..
2712 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2715 print("cursor_changed: ADDding to left panel model");
2716 this.get('/LeftPanel.model').add( {
2726 enable_tree_lines : true,
2727 headers_visible : false,
2729 XObject.prototype.init.call(this);
2731 var description = new Pango.FontDescription.c_new();
2732 description.set_size(8000);
2733 this.el.modify_font(description);
2735 //this.selection = this.el.get_selection();
2736 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2745 xtype: Gtk.ListStore,
2749 getValue : function(treepath, col)
2751 var tp = new Gtk.TreePath.from_string (treepath);
2753 this.el.get_iter (iret, tp);
2754 var value = this.el.get_value(iret.iter, col);
2755 return ''+ value.value.get_string();
2759 XObject.prototype.init.call(this);
2760 this.el.set_column_types ( 6, [
2761 GObject.TYPE_STRING, // real key
2762 GObject.TYPE_STRING, // real type
2763 GObject.TYPE_STRING, // docs ?
2764 GObject.TYPE_STRING, // visable desc
2765 GObject.TYPE_STRING, // function desc
2766 GObject.TYPE_STRING // element type (event|prop)
2770 showData : function(type) {
2773 this.loading = true;
2775 if (!this.get('/MidPropTree').activeElement || !type) {
2776 this.loading = false;
2777 return; // no active element
2780 var fullpath = this.get('/LeftTree.model').file.guessName(
2781 this.get('/MidPropTree').activeElement);
2782 var palete = this.get('/LeftTree').getPaleteProvider();
2786 Seed.print('Showing right?');
2787 if (!this.get('/MidPropTree').shown) {
2789 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2790 this.get('/MidPropTree').el.show();
2791 this.get('/MidPropTree').shown = true;
2794 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2795 return a.name > b.name ? 1 : -1;
2797 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2798 // console.dump(elementList);
2800 // scope of this is off..??
2803 for(var i =0 ; i < elementList.length; i++) {
2805 var p=elementList[i];
2806 this.el.append(iret);
2807 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2808 //GObject.TYPE_STRING, // real key
2809 // GObject.TYPE_STRING, // real type
2810 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2811 // GObject.TYPE_STRING // func def?
2814 this.el.set_value(iret.iter, 0, p.name);
2815 this.el.set_value(iret.iter, 1, p.type);
2816 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2817 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2818 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2819 this.el.set_value(iret.iter, 5, type);
2822 this.loading = false;
2826 xtype: Gtk.TreeViewColumn,
2829 this.el = new Gtk.TreeViewColumn();
2830 this.parent.el.append_column(this.el);
2832 XObject.prototype.init.call(this);
2833 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2837 xtype: Gtk.CellRendererText,
2838 pack : "pack_start,true"
2865 xtype: Gtk.Notebook,
2866 pack : "pack_start,true,true",
2867 id : "view-help-nb",
2869 XObject.prototype.init.call(this);
2870 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2871 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2875 xtype: Gtk.Notebook,
2876 id : "view-notebook",
2880 XObject.prototype.init.call(this);
2881 this.el.set_current_page(0);
2882 //print("SET LABEL?")
2883 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2884 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2890 id : "RightBrowser",
2895 pack : "pack_start,false,true,0",
2900 clicked : function (self) {
2901 this.get('/RightBrowser.view').renderJS(null,true);
2905 pack : "pack_start,false,false,0"
2908 xtype: Gtk.CheckButton,
2910 toggled : function (self, state) {
2911 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2916 label : "Auto Redraw On",
2917 pack : "pack_start,false,false,0"
2922 clicked : function (self) {
2924 var view = this.get('/RightBrowser.view');
2925 //this.get('/RightBrowser.view').redraws = 99;
2926 view.refreshRequired = true;
2927 view.lastRedraw = false;
2928 view.renderedData = false;
2929 view.renderJS(null,true);
2933 label : "Full Redraw",
2934 pack : "pack_start,false,false,0"
2939 xtype: Gtk.ScrolledWindow,
2942 XObject.prototype.init.call(this);
2943 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2945 shadow_type : Gtk.ShadowType.IN,
2948 xtype: WebKit.WebView,
2950 load_finished : function (self, object) {
2951 print("load finished");
2952 // print("load_finished"); return;
2953 // if (this.ready) { // dont do it twice!
2956 if (!this.inspectorShown) {
2957 this.el.get_inspector().show();
2958 this.inspectorShown = true;
2963 //if (this.pendingRedraw) {
2964 // this.pendingRedraw = false;
2965 // this.refreshRequired = true;
2967 //var js = this.get('/LeftTree.model').toJS();
2968 //if (js && js[0]) {
2969 // this.renderJS(js[0]);
2973 script_alert : function (self, object, p0) {
2976 return true; // do not display anything...
2978 console_message : function (self, object, p0, p1) {
2980 // console.log(object);
2983 if (object.match(/variable/) && object.match(/Builder/)) {
2984 print("got builder missing message");
2985 this.refreshRequired = true;
2986 this.lastRedraw = 0;
2992 if (!object.match(/^\{/)) {
2994 //this.get('/Terminal').feed(object);
2995 return true; // do not handle!!! -> later maybe in console..
3001 // console.log(object);
3002 var val = JSON.parse(object);
3004 if (typeof(val['hover-node']) != 'undefined') {
3005 this.activeNode = val['hover-node'];
3006 console.log('active node: ' + this.activeNode);
3011 if (typeof(val['id']) != 'undefined') {
3012 // this.activeNode = val['id'];
3013 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
3014 if (!tg || typeof(tg[0]) == 'undefined') {
3017 print("SELECT node " + tg[0]);
3019 this.get('/LeftTree.view').selectNode(tg[0]);
3024 if (ret && typeof(val['set']) != 'undefined') {
3025 print("console messages: ADDding to left panel model");
3027 //this.get('/LeftPanel.model').add({
3028 // key : val['set'],
3029 // val : val['value']
3031 //console.log('active node: ' + this.activeNode);
3034 //Seed.print('a:'+a);
3035 //Seed.print('b:'+b);
3036 //Seed.print('c:'+c);
3039 drag_motion : function (w, ctx, x, y, time, ud) {
3040 // console.log('DRAG MOTION');
3042 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3043 this.targetData = [];
3044 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3046 // A) find out from drag all the places that node could be dropped.
3047 var src = Gtk.drag_get_source_widget(ctx);
3048 if (!src.dropList) {
3049 Gdk.drag_status(ctx,0, time);
3052 // b) get what we are over.. (from activeNode)
3053 // tree is empty.. - list should be correct..
3054 if (!this.get('/LeftTree.model').currentTree) {
3055 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3059 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3061 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3064 Gdk.drag_status(ctx, 0,time);
3065 this.get('/LeftTree.view').highlight(false);
3069 // if we have a target..
3070 // -> highlight it! (in browser)
3071 // -> highlight it! (in tree)
3073 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3074 this.get('/LeftTree.view').highlight(tg);
3075 this.targetData = tg;
3076 // for tree we should handle this...
3079 drag_drop : function (w, ctx, x, y,time, ud) {
3080 print("TARGET: drag-drop");
3081 var is_valid_drop_site = true;
3085 ( /* will receive 'drag-data-received' signal */
3086 ctx, /* represents the current state of the DnD */
3087 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3088 time /* time stamp */
3092 /* No target offered by source => error */
3095 return is_valid_drop_site;
3097 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3099 print("Browser: drag-data-received");
3100 var delete_selection_data = false;
3101 vardnd_success = false;
3102 /* Deal with what we are given from source */
3103 if( sel_data && sel_data.length ) {
3105 if (ctx.action == Gdk.DragAction.ASK) {
3106 /* Ask the user to move or copy, then set the ctx action. */
3109 if (ctx.action == Gdk.DragAction.MOVE) {
3110 delete_selection_data = true;
3112 var source = Gtk.drag_get_source_widget(ctx);
3114 print("Browser: source.DRAGDATA? " + source.dragData);
3115 if (this.targetData) {
3116 print(this.targetData);
3117 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3126 if (dnd_success == false)
3128 Seed.print ("DnD data transfer failed!\n");
3131 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3134 create_web_view : function (self, object) {
3135 print("CREATE WEB VIEW");
3136 return null; //new WebKit.WebView();
3143 XObject.prototype.init.call(this);
3144 // this may not work!?
3145 var settings = this.el.get_settings();
3146 settings.enable_developer_extras = true;
3148 // this was an attempt to change the url perms.. did not work..
3149 // settings.enable_file_access_from_file_uris = true;
3150 // settings.enable_offline_web_application_cache - true;
3151 // settings.enable_universal_access_from_file_uris = true;
3155 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3156 _this.get('/BottomPane.inspector').el.show();
3157 return _this.get('/BottomPane.inspector').el;
3161 // FIXME - base url of script..
3162 // we need it so some of the database features work.
3163 this.el.load_html_string( "Render not ready" ,
3164 //fixme - should be a config option!
3165 // or should we catch stuff and fix it up..
3166 'http://localhost/app.Builder/'
3170 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3172 this.el.drag_dest_set
3173 ( /* widget that will accept a drop */
3174 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3175 null, /* lists of target to support */
3176 0, /* size of list */
3177 Gdk.DragAction.COPY /* what to do with data after dropped */
3180 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3181 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3183 GLib.timeout_add_seconds(0, 1, function() {
3184 // print("run refresh?");
3191 renderJS : function(data, force) {
3193 // this is the public redraw call..
3194 // we refresh in a loop privately..
3195 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3196 if (!autodraw && !force) {
3197 print("Skipping redraw - no force, and autodraw off");
3200 this.refreshRequired = true;
3202 runRefresh : function()
3204 // this is run every 2 seconds from the init..
3208 if (!this.refreshRequired) {
3209 // print("no refresh required");
3213 if (this.lastRedraw) {
3214 // do not redraw if last redraw was less that 5 seconds ago.
3215 if (((new Date()) - this.lastRedraw) < 5000) {
3223 if (!this.get('/Window.LeftTree').getActiveFile()) {
3226 this.refreshRequired = false;
3227 // print("HTML RENDERING");
3229 this.get('/BottomPane').el.show();
3230 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3237 var js = this.get('/LeftTree.model').toJS();
3238 if (!js || !js.length) {
3247 var project = this.get('/Window.LeftTree').getActiveFile().project;
3248 //print (project.fn);
3249 // set it to non-empty.
3250 project.runhtml = project.runhtml || '';
3251 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3254 this.runhtml = this.runhtml || '';
3256 var file = this.get('/LeftTree.model').file;
3257 var items = file.items;
3258 file.items = this.get('/LeftTree.model').toJS(false, false);
3259 //file.items[0].background = false;
3260 //var p = file.parent;
3261 //file.parent = false;
3263 var js_src = file.toSourcePreview();
3264 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3265 // unless it' sforced..
3270 this.renderedData = js_src;
3273 //file.items = items;
3274 //print("send source as " + js_src);
3277 "Roo.onReady(function() {\n" +
3278 "if (" + file.name +".show) " + file.name +".show({});\n" +
3279 "Roo.XComponent.build();\n" +
3286 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3287 // then we need to reload the browser using
3288 // load_html_string..
3290 // then trigger a redraw once it's loaded..
3291 this.pendingRedraw = true;
3292 var runhtml = '<script type="text/javascript">' + "\n" ;
3293 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3294 runhtml += '</script>'+ "\n" ;
3296 this.runhtml = project.runhtml;
3297 // need to modify paths
3300 this.lastRedraw= new Date();
3301 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3302 html = html.replace('</head>',
3305 '<script type="text/javascript">' + "\n" +
3310 //print("LOAD HTML " + html);
3311 this.el.load_html_string( html ,
3312 //fixme - should be a config option!
3313 'http://localhost/app.Builder/'
3316 // should trigger load_finished! - which in truns shoudl set refresh Required;
3321 //this.renderedData = data;
3322 //var str = JSON.stringify(data) ;
3325 console.log('not loaded yet');
3327 this.lastRedraw = new Date();
3329 this.el.execute_script("Builder.render(" +
3330 JSON.stringify(js_src) +
3332 JSON.stringify(file.name) +
3335 print( "before render" + this.lastRedraw);
3336 print( "after render" + (new Date()));
3346 id : "RightGtkView",
3348 redraw : function() {
3349 this.highlightWidget = false;
3350 print("REDRAW CALLED");
3351 this.activePath = this.get('/LeftTree').getActivePath();
3352 if (this.renderedEl) {
3353 print("QUEUE DRAW CALLING");
3354 this.renderedEl.queue_draw();
3357 renderJS : function(data, withDebug)
3359 this.highlightWidget = false;
3361 this.withDebug = false;
3362 while (this.get('view').el.get_children().length) {
3363 var c = this.get('view').el.get_children()[0];
3364 this.get('view').el.remove(c);
3371 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3372 // in theory tree is actually window..
3375 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3381 this.get('view').el.set_size_request(
3382 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3384 if (this.renderedEl) {
3385 this.renderedEl.set_size_request(
3386 tree.default_width || 600,
3387 tree.default_height || 400
3390 this.get('view').el.show_all();
3395 showInWindow : function() {
3396 print("GET PROEJCT");
3397 var pr = this.get('/LeftProjectTree').getActiveProject();
3399 console.log(pr.paths);
3402 var src= this.buildJS(
3403 this.get('/LeftTree.model').toJS()[0],
3408 //var x = new imports.sandbox.Context();
3412 Seed.check_syntax('var e = ' + src);
3415 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3416 this.get('/Terminal').feed(console._dump(e)+"\n");
3418 var lines = src.split("\n");
3419 var start = Math.max(0, e.line - 10);
3420 var end = Math.min(lines.length, e.line + 10);
3421 for (var i =start ; i < end; i++) {
3423 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3426 this.get('/Terminal').feed(lines[i] + "\n");
3433 this.get('/BottomPane').el.set_current_page(1);
3434 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3435 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3436 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3438 var _top = x.get_global_object()._top;
3440 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3442 if (_top.el.popup) {
3443 _top.el.popup(null, null, null, null, 3, null);
3447 viewAdd : function(item, par)
3450 // does something similar to xobject..
3451 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3453 // pack is forced to 'false'
3454 if (item.pack===false || item.pack === 'false') { // no ;
3458 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3461 var type = item['|xns'] + '.' + item['xtype'];
3463 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3467 var ns = imports.gi[item['|xns']];
3468 var ctr = ns[item['xtype']]; // why are we using array here..?
3473 for(var k in item) {
3475 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3489 // value is a function..
3490 if (k[0] == '|' && typeof(kv) == 'string') {
3492 if (kv.match(new RegExp('function'))) {
3495 print("WASL " + k + '=' + kv);
3497 eval( 'kv = ' + kv);
3498 } catch(e) { continue; }
3501 // print(k + '=' + kv);
3503 if (k[0] == '|') { // should be boolean or number..
3505 //print(k + '=' + kv);
3508 if (k == 'show_tabs') { // force tab showing for notebooks.
3511 print(k + '=' + typeof(kv) + " : " + kv);
3515 var altctr = XObject.baseXObject({ xtype: ctr} );
3517 if (!item.pack && altctr) {
3519 print("SETTING PACK TO XObjectBase method");
3520 pack_m = altctr.prototype.pack;
3525 var el = new ctr(ctr_args);
3527 print("PACK" + item.pack);
3528 //console.dump(item.pack);
3535 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3536 if (typeof(item.pack) == 'string') {
3538 item.pack.split(',').forEach(function(e, i) {
3540 if (e == 'false') { args.push( false); return; }
3541 if (e == 'true') { args.push( true); return; }
3542 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3545 //print(args.join(","));
3547 pack_m = args.shift();
3549 pack_m = item.pack.shift();
3554 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3556 name: "ArgumentError",
3557 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3558 "ADDING : " + item.id + " " + el
3565 //console.dump(args);
3567 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3568 //Seed.print('args: ' + args.length);
3569 if (typeof(pack_m) == 'string') {
3570 par[pack_m].apply(par, args);
3571 } else if (pack_m) {
3572 pack_m.call(item, par, item);
3576 item.items = item.items || [];
3577 item.items.forEach(function(ch,n) {
3579 print ("type:" + type);
3581 print ("ch.pack:" + ch.pack);
3584 if (type == 'Gtk.Table' && ch.pack == 'add') {
3585 var c = n % item.n_columns;
3586 var r = Math.floor(n/item.n_columns);
3587 ch.pack = [ 'attach', c, c+1, r, r+1,
3588 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3589 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3590 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3591 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3595 _this.viewAdd(ch, el);
3600 // add the signal handlers.
3601 // is it a widget!?!!?
3607 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3608 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3609 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3610 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3611 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3621 widgetDragDropEvent : function() {
3622 print("WIDGET DRAGDROP");
3625 widgetDragMotionEvent : function() {
3626 print("WIDGET DRAGMOTION");
3629 widgetExposeEvent : function(w, evt, ud, item) {
3631 if (this.inRender) {
3635 if ( this.highlightWidget) {
3636 this.inRender = true;
3637 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3638 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3640 this.inRender = false;
3645 if (this.activePath != item.xtreepath) {
3649 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3650 // work out the coords of the window..
3652 var dr = widget.window;
3653 this.gc = (new Gdk.GC.c_new(dr));
3654 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3655 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3659 var r = evt.expose.area;
3660 // console.dump([r.x, r.y, r.width, r.height ] );
3662 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3663 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3664 // happens with gtkscrollview embedded stuff..
3665 var np =this.activePath.split(':');
3667 this.activePath = np.join(':');
3668 this.renderedEl.queue_draw();
3684 this.inRender = true;
3687 this.highlightWidget = widget;
3692 // print("DRAW BOX");
3693 //console.dump(this.box);
3694 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3695 this.inRender = false;
3698 widgetPressEvent : function(w,e,u,d) {
3699 if (this.get('view').pressed) {
3702 this.get('view').pressed = true;
3703 print("WIDGET PRESS " + d.xtreepath );
3704 this.get('/LeftTree.view').selectNode( d.xtreepath );
3707 widgetReleaseEvent : function() {
3708 this.get('view').pressed = false;
3714 pack : "pack_start,false,true,0",
3718 pack : "pack_start,false,false,0",
3719 label : "Run The Application",
3721 button_press_event : function (self, event) {
3722 // call render on left tree - with special option!?!
3724 //print("GET PROEJCT");
3725 var pr = this.get('/LeftProjectTree').getActiveProject();
3728 for (var i in pr.paths) {
3732 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3733 this.get('/Terminal').feed("RUN DIR:" + dir);
3736 this.get('/Terminal').el.fork_command_full(
3737 Vte.PtyFlags.DEFAULT,
3738 GLib.path_get_dirname (__script_path__) ,
3739 [ 'echo' , "hello"], //argv
3743 null, // child setupdata
3747 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3748 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3758 xtype: Gtk.ScrolledWindow,
3761 shadow_type : Gtk.ShadowType.IN,
3763 XObject.prototype.init.call(this);
3764 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3768 xtype: Gtk.EventBox,
3769 pack : "add_with_viewport",
3771 XObject.prototype.init.call(this);
3772 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3773 red: 0x9F00, green: 0xB800 , blue : 0xA800
3781 XObject.prototype.init.call(this);
3782 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3783 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3788 xtype: Gtk.EventBox,
3791 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3792 XObject.prototype.init.call(this);
3794 this.el.drag_dest_set
3795 ( /* widget that will accept a drop */
3796 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3797 null, /* lists of target to support */
3798 0, /* size of list */
3799 Gdk.DragAction.COPY /* what to do with data after dropped */
3802 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3803 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3806 getActiveNode : function(x,y)
3808 // workout what node is here..
3809 return '0'; // top..
3813 drag_motion : function (self, ctx, x, y, time) {
3815 // A) find out from drag all the places that node could be dropped.
3816 var src = Gtk.drag_get_source_widget(ctx);
3817 if (!src.dropList) {
3818 Gdk.drag_status(ctx, 0, time);
3821 // b) get what we are over.. (from activeNode)
3822 // tree is empty.. - list should be correct..
3823 if (!this.get('/LeftTree.model').currentTree) {
3824 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3828 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3829 var activeNode = this.getActiveNode(x, y);
3832 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3835 Gdk.drag_status(ctx, 0,time);
3836 this.get('/LeftTree.view').highlight(false);
3840 // if we have a target..
3841 // -> highlight it! (in browser)
3842 // -> highlight it! (in tree)
3844 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3845 this.get('/LeftTree.view').highlight(tg);
3846 this.targetData = tg;
3847 // for tree we should handle this...
3850 drag_drop : function (self,ctx, x, y, time) {
3851 Seed.print("TARGET: drag-drop");
3852 var is_valid_drop_site = true;
3856 ( /* will receive 'drag-data-received' signal */
3857 ctx, /* represents the current state of the this.gDnD */
3858 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3859 time /* time stamp */
3863 /* No target offered by source => error */
3866 return is_valid_drop_site;
3869 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3871 Seed.print("GtkView: drag-data-received");
3872 var delete_selection_data = false;
3873 var dnd_success = false;
3874 /* Deal with what we are given from source */
3875 if( sel_data && sel_data.length ) {
3877 if (ctx.action == Gdk.DragAction.ASK) {
3878 /* Ask the user to move or copy, then set the ctx action. */
3881 if (ctx.action == Gdk.DragAction.MOVE) {
3882 delete_selection_data = true;
3884 var source = Gtk.drag_get_source_widget( ctx );
3886 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3887 if (this.targetData) {
3888 Seed.print(this.targetData);
3889 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3898 if (dnd_success == false)
3900 Seed.print ("DnD data transfer failed!\n");
3903 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3906 button_press_event : function (self, event) {
3907 this.pressed = false;
3923 xtype: Gtk.ScrolledWindow,
3928 var file = this.get('/LeftTree').getActiveFile();
3932 var activeEl = this.get('/LeftTree').getActiveElement();
3933 var xtype = file.guessName( activeEl )
3934 if (!xtype || !xtype.length) {
3937 //this.get('/Window.view-help-nb').el.set_current_page(1);
3939 // get the active element being edited.
3940 var helpurl = file.getHelpUrl(xtype);
3942 // now load the help info in the page..
3943 this.get('help-view').el.open(helpurl);
3947 xtype: WebKit.WebView,
3951 XObject.prototype.init.call(this);
3952 this.get('/Window.help-view').el.open(
3953 "http://devel.akbkhome.com/seed/");
3965 xtype: Gtk.Notebook,
3969 XObject.prototype.init.call(this);
3970 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3971 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3972 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3976 xtype: Gtk.ScrolledWindow,
3980 xtype: Vte.Terminal,
3983 feed : function(istr) {
3984 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3985 // we should make ourselves visable!!!
3986 this.get('/BottomPane').el.show();
3987 this.get('/BottomPane').el.set_current_page(1);
3989 this.el.feed(str ,str.length);
3991 scroll_on_output : true,
3993 XObject.prototype.init.call(this);
3994 this.el.set_size (80, 1000);
3996 scrollback_lines : 1000
4001 xtype: Gtk.ScrolledWindow,
4005 xtype: WebKit.WebView,
4021 this.get('buttonbar').el.show();
4022 this.get('viewbox').el.hide();
4023 var ce = this.get('/Window.centereast').el;
4025 ce.set_position(ce.get_allocated_width() - 30);
4027 print("TRIED TO HIDE");
4030 this.get('buttonbar').el.hide();
4031 this.get('viewbox').el.show();
4032 var ce = this.get('/Window.centereast').el;
4033 print(JSON.stringify(XObject.keys(ce) ,null,4));
4034 ce.set_position(ce.get_allocated_width() - 150);
4036 // this.get('model').expanded();
4048 pack : "pack_start,false,true",
4050 clicked : function (self) {
4051 this.get('/RightPalete').show();
4058 stock : Gtk.STOCK_GOTO_FIRST,
4059 icon_size : Gtk.IconSize.MENU
4069 XObject.prototype.init.call(this);
4070 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4073 enter_notify_event : function (self, event) {
4074 this.get('/RightPalete').show();
4088 pack : "pack_start,false,true",
4097 pack : "pack_start,false,true",
4099 clicked : function (self) {
4100 this.get('/RightPalete').hide();
4107 stock : Gtk.STOCK_GOTO_LAST,
4108 icon_size : Gtk.IconSize.MENU
4115 xtype: Gtk.ScrolledWindow,
4118 XObject.prototype.init.call(this);
4119 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4120 this.el.set_size_request(-1,200);
4122 shadow_type : Gtk.ShadowType.IN,
4125 xtype: Gtk.TreeView,
4127 drag_begin : function (self, ctx) {
4128 // we could fill this in now...
4129 Seed.print('SOURCE: drag-begin');
4134 var s = this.selection;
4135 s.get_selected(iret);
4136 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4138 var pix = this.el.create_row_drag_icon ( path);
4141 if (Gtk.drag_set_icon_surface) {
4142 Gtk.drag_set_icon_surface( ctx, pix );
4144 Gtk.drag_set_icon_pixmap (ctx,
4145 pix.get_colormap(), pix, null, -10, -10);
4148 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4149 if (!this.get('/RightPalete').provider) {
4152 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4153 this.el.dragData = value;
4160 drag_data_get : function (self, drag_context, selection_data, info, time) {
4161 //Seed.print('Palete: drag-data-get: ' + target_type);
4162 if (this.el.dragData && this.el.dragData.length ) {
4163 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4167 //this.el.dragData = "TEST from source widget";
4171 drag_end : function (self, drag_context) {
4172 Seed.print('SOURCE: drag-end');
4173 this.el.dragData = false;
4174 this.el.dropList = false;
4175 this.get('/LeftTree.view').highlight(false);
4178 button_press_event : function (self, event) {
4180 if (!this.get('/Editor').save()) {
4181 // popup!! - click handled..
4188 enable_tree_lines : true,
4189 headers_visible : false,
4191 XObject.prototype.init.call(this);
4192 this.el.set_size_request(150,-1);
4193 // set_reorderable: [1]
4195 var description = new Pango.FontDescription.c_new();
4196 description.set_size(8000);
4197 this.el.modify_font(description);
4199 this.selection = this.el.get_selection();
4200 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4201 // this.selection.signal['changed'].connect(function() {
4202 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4204 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4206 this.el.drag_source_set ( /* widget will be drag-able */
4207 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4208 null, /* lists of target to support */
4209 0, /* size of list */
4210 Gdk.DragAction.COPY /* what to do with data after dropped */
4212 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4214 this.el.drag_source_set_target_list( imports.Builder3.Globals.targetList);
4215 this.el.drag_source_add_text_targets( );
4217 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4218 targets = new Gtk.TargetList();
4219 targets.add( LeftTree.atoms["STRING"], 0, 0);
4220 targets.add_text_targets( 1 );
4221 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4223 //if you want to allow text to be output elsewhere..
4224 //Gtk.drag_source_add_text_targets(this.el);
4230 xtype: Gtk.ListStore,
4233 XObject.prototype.init.call(this);
4234 this.el.set_column_types ( 2, [
4235 GObject.TYPE_STRING, // title
4236 GObject.TYPE_STRING // tip
4241 load : function(tr,iter)
4246 //console.log('Project tree load: ' + tr.length);
4248 //this.insert(citer,iter,0);
4249 for(var i =0 ; i < tr.length; i++) {
4252 this.el.append(cret);
4254 this.el.insert(cret,iter,-1);
4259 this.el.set_value(cret.iter, 0, '' + r ); // title
4261 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4262 //if (r.cn && r.cn.length) {
4263 // this.load(r.cn, citer);
4269 getValue : function (iter, col) {
4270 return this.el.get_value(iter, col).value.get_string();
4277 xtype: Gtk.TreeViewColumn,
4278 pack : "append_column",
4280 XObject.prototype.init.call(this);
4281 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4285 xtype: Gtk.CellRendererText,
4307 XObject.cache['/Window'] = Window;