3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
18 delete_event : function (self, event) {
21 destroy : function (self) {
24 show : function (self) {
26 imports.ProjectManager.ProjectManager.loadConfig();
28 print("HIDEWIN - calling MidPropTree hidewin")
29 this.get('/MidPropTree').hideWin();
30 this.get('/RightPalete').hide();
31 this.get('/BottomPane').el.hide();
32 //this.get('/Editor').el.show_all();
40 title : "Application Builder",
42 setTitle : function(str) {
43 this.el.set_title(this.title + ' - ' + str);
45 type : Gtk.WindowType.TOPLEVEL,
53 pack : "pack_start,false,false",
67 label : "New _Project",
69 activate : function (self) {
71 this.get('/EditProject').show({
72 success : function(pr) {
73 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
84 activate : function (self) {
85 var fn = this.get('/LeftProjectTree.combo').getValue();
87 this.get('/LeftProjectTree').showNoProjectSelected();
90 var pm = imports.ProjectManager.ProjectManager;
91 this.get('/DialogNewComponent').show({
92 project : pm.getByFn(fn)
98 xtype: Gtk.SeparatorMenuItem,
103 use_underline : true,
105 label : "D_elete Project",
107 activate : function (self) {
109 var fn = this.get('/LeftProjectTree').get('combo').getValue();
111 this.get('/StandardErrorDialog').show("Select a project")
114 var pm = imports.ProjectManager.ProjectManager;
115 var pr = pm.getByFn(fn);
118 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
119 pm.deleteProject(fn);
127 xtype: Gtk.SeparatorMenuItem,
134 use_underline : true,
136 activate : function (self) {
148 use_underline : true,
153 pack : "set_submenu",
158 activate : function (self) {
159 var fn = this.get('/LeftTree').getActiveFile();
161 this.get('/StandardErrorDialog').show("No File active");
165 this.get('/DialogNewComponent').show(fn);
169 label : "File _Properties",
176 activate : function (self, event) {
177 this.get('/RooProjectProperties').show();
181 label : "Modify Project HTML ",
192 use_underline : true,
196 pack : "set_submenu",
201 activate : function (self, event) {
202 var js = this.get('/LeftTree.model').toJS();
204 this.get('/RightBrowser.view').renderJS(js[0], true);
209 label : "_Redraw (Roo)",
216 activate : function (self, event)
218 /* Firefox testing for debugging..
219 - we can create a /tmp directory, and put.
220 builder.html, builder.html.js, link roojs1
221 add at the end of builder.html Roo.onload(function() {
223 if (!this.get('/Window.LeftTree').getActiveFile()) {
227 var js = this.get('/LeftTree.model').toJS();
231 var project = this.get('/Window.LeftTree').getActiveFile().project;
232 //print (project.fn);
234 project.runhtml = project.runhtml || '';
237 var File = imports.File.File;
239 var target = "/tmp/firetest"; // fixme..
240 if (!File.isDirectory(target)) {
243 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
244 if (!File.exists( target+ '/roojs1')) {
245 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
250 var html = imports.File.File.read(__script_path__ + '/../builder.html');
251 html = html.replace('</head>', project.runhtml + '</head>');
254 var jsstr = JSON.stringify(js[0], null, 4);
256 var runbuilder = '<script type="text/javascript">' + "\n" +
257 " Builder.render(" + jsstr + ");\n" +
260 html = html.replace('</body>', runbuilder + '</body>');
262 File.write( target+ '/builder.html', html);
264 this.get('/Terminal').feed("RUN DIR:" + target);
266 this.get('/Terminal').el.fork_command_full(
267 Vte.PtyFlags.DEFAULT,
273 null, // child setupdata
276 var cmd = "firefox file://" + target + "/builder.html \n";
277 this.get('/Terminal').el.feed_child(cmd, cmd.length);
281 label : "_Test in Firefox (Roo)",
292 use_underline : true,
297 pack : "set_submenu",
303 use_underline : true,
305 activate : function (self) {
306 this.get('/About').el.run();
336 Gdk.EventMask.BUTTON_MOTION_MASK
340 activate : function (self) {
341 // this does not actually expand it..
342 // that is done by GTK..
345 if (!this.get('/Editor').save()) {
346 // popup!! - click handled..
350 if (!this.el.expanded) {
358 enter_notify_event : function (self, event) {
360 this.el.expanded = !this.el.expanded;
361 //if (this.el.expanded ) {
362 this.listeners.activate.call(this);
369 label : "Select Project or File",
370 pack : "pack_start,false,true",
372 onCollapse : function() {
374 var nb = this.get('/LeftTopPanel.notebook');
375 nb.el.set_current_page(0);
377 onExpand : function() {
378 var nb = this.get('/LeftTopPanel.notebook');
379 var pm = imports.ProjectManager.ProjectManager;
382 var model = this.get('/LeftProjectTree.combomodel');
383 // print ("loading Projects?")
384 //console.dump(pm.projects);
385 model.loadData(pm.projects);
388 nb.el.set_current_page(1);
389 //pm.on('changed', function() {
390 //console.log("CAUGHT project manager change");
391 // _combo.model.loadData(pm.projects);
399 pack : "pack_start,true,true",
406 xtype: Gtk.ScrolledWindow,
409 getActiveElement : function() { // return path to actie node.
411 var path = this.getActivePath();
416 this.get('model').el.get_iter_from_string(ret, path);
418 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
420 return JSON.parse(value);
422 getActiveFile : function() {
423 return this.get('model').file;
425 getActivePath : function() {
426 var model = this.get('model');
427 var view = this.get('view');
428 if (view.selection.count_selected_rows() < 1) {
432 view.selection.get_selected(ret);
433 return ret.model.get_path(ret.iter).to_string();
435 getPaleteProvider : function() {
436 var model = this.get('model');
437 var pm = imports.ProjectManager.ProjectManager;
438 return pm.getPalete(model.file.getType());
440 getRenderer : function() {
442 switch( this.getActiveFile().getType()) {
444 return this.get('/RightBrowser.view');
446 return this.get('/RightGtkView');
452 XObject.prototype.init.call(this);
453 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
455 renderView : function() {
456 var render = this.getRenderer();
457 var model = this.get('model');
459 render.renderJS(model.toJS(false,true)[0]);
461 print("NO RENDER JS METHOD?");
464 shadow_type : Gtk.ShadowType.IN,
469 button_press_event : function (self, ev) {
470 console.log("button press?");
472 if (!this.get('/Editor').save()) {
473 // popup!! - click handled..
477 if (ev.button.button != 3) {
478 print("click" + ev.button.button);
484 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
486 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
488 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
489 this.get('/LeftTreeMenu').el.show_all();
490 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
491 print("click:" + res.path.to_string());
494 drag_begin : function (self, ctx) {
495 print('SOURCE: drag-begin');
496 this.targetData = false;
497 // find what is selected in our tree...
499 this.selection.get_selected(ret);
501 // set some properties of the tree for use by the dropped element.
502 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
503 var data = JSON.parse(value);
504 var xname = this.get('/LeftTree.model').file.guessName(data);
506 this.el.dragData = xname;
507 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
510 // make the drag icon a picture of the node that was selected
511 var path = ret.model.get_path(ret.iter);
512 this.el.treepath = path.to_string();
514 // returns a cairo surface
515 var pix = this.el.create_row_drag_icon ( path);
517 if (Gtk.drag_set_icon_surface) {
518 Gtk.drag_set_icon_surface( ctx, pix );
520 Gtk.drag_set_icon_pixmap (ctx,
521 pix.get_colormap(), pix, null, -10, -10);
526 drag_end : function (self, drag_context) {
527 Seed.print('LEFT-TREE: drag-end');
528 this.el.dragData = false;
529 this.el.dropList = false;
530 this.targetData = false;
531 this.get('/LeftTree.view').highlight(false);
534 drag_data_get : function(self, ctx, sel_data, info, time)
544 drag_motion : function (self, ctx, x, y, time) {
545 console.log("LEFT-TREE: drag-motion");
546 var src = Gtk.drag_get_source_widget( ctx);
548 // a drag from elsewhere...- prevent drop..
550 print("no drag data!");
551 Gdk.drag_status(ctx, 0, time);
552 this.targetData = false;
555 var action = Gdk.DragAction.COPY;
556 if (src == this.el) {
557 // unless we are copying!!! ctl button..
558 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
562 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
563 // no children.. -- asume it's ok..
564 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
565 Gdk.drag_status(ctx, action ,time);
569 print("GETTING POS");
570 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
571 print("ISOVER? " + isOver);
573 Gdk.drag_status(ctx, 0 ,time);
574 return false; // not over apoint!?!
576 // drag node is parent of child..
577 console.log("SRC TREEPATH: " + src.treepath);
578 console.log("TARGET TREEPATH: " + data.path.to_string());
580 // nned to check a few here..
581 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
582 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
583 //Gtk.TreeViewDropPosition.AFTER
584 //Gtk.TreeViewDropPosition.BEFORE
586 if (typeof(src.treepath) != 'undefined' &&
587 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
588 print("subpath drag");
589 Gdk.drag_status( ctx, 0 ,time);
594 //print("DUMPING DATA");
595 //console.dump(data);
598 print(data.path.to_string() +' => '+ data.pos);
599 var tg = this.get('/LeftTree.model').findDropNodeByPath(
600 data.path.to_string(), src.dropList, data.pos);
602 this.get('/LeftTree.view').highlight(tg);
604 print("Can not find drop node path");
605 this.targetData = false;
606 Gdk.drag_status(ctx, 0, time);
609 print(JSON.stringify(tg,null,4));
611 this.targetData = tg;
614 Gdk.drag_status(ctx, action ,time);
618 drag_drop : function (w, ctx, x, y, time) {
619 Seed.print("TARGET: drag-drop");
620 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
622 ( /* will receive 'drag-data-received' signal */
623 ctx, /* represents the current state of the DnD */
624 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
625 time /* time stamp */
629 /* No target offered by source => error */
634 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
635 print("Tree: drag-data-received");
637 var delete_selection_data = false;
638 var dnd_success = false;
639 //print(JSON.stringify(sel_data, null,4));
640 /* Deal with what we are given from source */
642 // simce I can not be bothered to sort out
643 // drag drop = let's assume it worked...
645 if( true || (sel_data && sel_data.length )) {
647 if (ctx.action == Gdk.DragAction.ASK) {
648 /* Ask the user to move or copy, then set the ctx action. */
651 if (ctx.action == Gdk.DragAction.MOVE) {
652 //delete_selection_data = true;
655 var source = Gtk.drag_get_source_widget( ctx );
657 if (this.targetData) {
658 if (source != this.el) {
659 print("DRAG FROM ANOTHER WIDGET");
660 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
662 // drag around.. - reorder..
663 print("DRAG FROM SELF");
664 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
668 //Seed.print(this.targetData);
674 // we can send stuff to souce here...
680 if (dnd_success == false)
682 Seed.print ("DnD data transfer failed!\n");
685 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
688 cursor_changed : function (self) {
689 if (this.blockChanges) { // probably not needed..
692 var render = this.get('/LeftTree').getRenderer();
695 if (this.selection.count_selected_rows() < 1) {
696 this.get('/LeftPanel.model').load( false);
697 this.get('/MidPropTree').activeElement = false;
698 this.get('/MidPropTree').hideWin();
700 var pm = this.get('/RightPalete.model');
701 if (!this.get('/LeftTree').getPaleteProvider()) {
702 // it may not be loaded yet..
706 this.get('/LeftTree').getPaleteProvider().gatherList(
707 this.get('/LeftTree.model').listAllTypes()
710 if (render && render.redraw) {
716 //console.log('changed');
717 var s = this.selection;
722 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
723 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
725 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
728 var data = JSON.parse(value);
729 this.get('/MidPropTree').activeElement = data;
730 this.get('/MidPropTree').hideWin();
731 this.get('/LeftPanel.model').load( data);
734 // _g.button.set_label(''+value.get_string());
736 var pm =this.get('/RightPalete.model');
737 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
738 this.get('/LeftTree.model').listAllTypes()));
741 if (render && render.redraw) {
745 //Seed.print( value.get_string());
753 enable_tree_lines : true,
754 headers_visible : false,
755 highlight : function(treepath_ar) {
757 // highlighting for drag/drop
758 if (treepath_ar.length && treepath_ar[0].length ) {
759 this.el.set_drag_dest_row(
760 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
762 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
768 XObject.prototype.init.call(this);
769 var description = new Pango.FontDescription.c_new();
770 description.set_size(8000);
771 this.el.modify_font(description);
773 this.selection = this.el.get_selection();
774 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
777 // is this really needed??
778 this.selection.signal['changed'].connect(function() {
779 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
780 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
784 this.el.drag_source_set( /* widget will be drag-able */
785 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
786 null, /* lists of target to support */
787 0, /* size of list */
788 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
791 this.el.drag_source_set_target_list(imports.Builder3.Globals.targetList);
793 this.el.drag_source_add_text_targets();
794 this.el.drag_dest_set
796 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
797 null, /* lists of target to support */
798 0, /* size of list */
799 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
802 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
803 this.el.drag_dest_add_text_targets( );
805 selectNode : function(treepath_str) {
806 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
807 var tp = new Gtk.TreePath.from_string(treepath_str);
808 this.el.set_cursor(tp, null, false);
809 this.el.scroll_to_cell(tp, null, false, 0,0);
813 xtype: Gtk.TreeStore,
819 setFromNode : function(tp, n)
822 tp = this.get('/LeftTree').getActivePath();
825 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
826 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
827 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
828 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
832 changed : function( refresh) {
836 print("-------MODEL CHANGED CALLED" );
838 //this.currentTree = this.toJS(false, true)[0];
840 this.file.items = this.toJS(false, false);
841 print ("TO JS in " + ((new Date()) - d) + "ms");
842 // print("AFTER CHANGED");
843 //console.dump(this.file.items);
845 this.currentTree = this.file.items[0];
846 //console.log(this.file.toSource());
849 print("REDNER BROWSER?!");
850 this.get('/LeftTree').renderView();
852 var pm = this.get('/RightPalete.model');
853 if (!this.get('/RightPalete').provider) {
859 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
860 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
864 deleteSelected : function() {
865 this.get('/LeftTree.view').blockChanges = true;
867 var s = this.get('/LeftTree.view').selection;
868 s.get_selected(oret);
869 var path = this.el.get_path(oret.iter).to_string();
871 this.activePath= false;
874 this.activePath= false;
876 this.el.get_iter_from_string(ret, path);
877 this.el.remove(ret.iter);
879 // rebuild treemap. -- depreciated.!!
882 //this.toJS(null, true) // does not do anything?
883 this.activePath= false;
885 this.get('/LeftTree.view').blockChanges = false;
887 dropNode : function(target_data, node) {
889 // console.dump(node);
890 //print(JSON.Stringify(target_data, null, 4));
891 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
893 print("add " + tp + "@" + target_data[1] );
896 if (tp && target_data[1] < 2) { // before or after..
897 var ar = target_data[0].split(':');
899 parent = new Gtk.TreePath.from_string( ar.join(':') );
904 var aret = after ? {} : false;
908 if (parent !== false) {
909 this.el.get_iter(pret, parent);
916 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
917 this.el.get_iter(aret, after);
918 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
919 nret, pret.iter, aret.iter);
922 this.el.append(nret, pret.iter);
925 var new_path = this.el.get_path(nret.iter).to_string();
926 print("new path = " + new_path)
927 if (typeof(node) == 'string') {
928 var ar = node.split('.');
929 var xtype = ar.pop();
932 '|xns' : ar.join('.'),
935 if (target_data.length == 3 && target_data[2].length) {
936 node['*prop'] = target_data[2];
938 node = this.get('/DialogTemplateSelect').show(node);
941 // work out what kind of packing to use..
942 if (typeof(node.pack) == 'undefined' && parent !== false) {
943 var pal = this.get('/LeftTree').getPaleteProvider();
944 if (pal.name == 'Gtk') {
945 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
946 var cname = pal.guessName(node);
947 node.pack = pal.getDefaultPack(pname, cname);
958 // load children - if it has any..
961 this.load(xitems, nret.iter);
962 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
964 if (tp && (xitems || after)) {
965 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
967 // wee need to get the empty proptypes from somewhere..
969 //var olditer = this.activeIter;
970 //this.activePath = new_path;
971 print("calling changed with node data")
972 // changed actually set's the node data..
973 this.setFromNode(new_path,node);
978 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
980 //Builder.MidPropTree._model.load(node);
981 //Builder.MidPropTree._win.hideWin();
982 //Builder.LeftPanel._model.load( node);
986 findDropNode : function(treepath_str, targets) {
988 // this is used by the dragdrop code in the roo version AFAIR..
990 var path = treepath_str.replace(/^builder-/, '');
991 // treemap is depreciated... - should really check if model has any entries..
993 if (!this.el.iter_n_children(null)) {
995 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
997 print("FIND treepath: " + path);
998 //console.dump(this.treemap);
1000 if (!treepath_str.match(/^builder-/)) {
1001 return []; // nothing!
1003 if (targets === true) {
1006 return this.findDropNodeByPath(path,targets)
1008 findDropNodeByPath : function(treepath_str, targets, pref) {
1009 var path = treepath_str + ''; // dupe it..
1010 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1012 //console.dump(this.treemap);
1013 while (path.length) {
1014 print("LOOKING FOR PATH: " + path);
1015 var node_data = this.singleNodeToJS(path);
1016 if (node_data === false) {
1017 print("node not found");
1021 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1024 targets.forEach(function(tg) {
1028 if ((tg == xname) ) {
1031 if (tg.indexOf(xname +':') === 0) {
1033 prop = tg.split(':').pop();
1038 if (last) { // pref is after/before..
1039 // then it's after last
1041 return []; // do not allow..
1043 return [ last, pref , prop];
1046 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1048 var par = path.split(':');
1051 path = par.join(':');
1057 getIterValue : function (iter, col) {
1059 var gval = ''+this.el.get_value(iter, col).value.get_string();
1065 XObject.prototype.init.call(this);
1066 this.el.set_column_types ( 3, [
1067 GObject.TYPE_STRING, // title
1068 GObject.TYPE_STRING, // tip
1069 GObject.TYPE_STRING // source..
1072 listAllTypes : function() {
1073 var s = this.get('/LeftTree.view').selection;
1074 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1076 if (s.count_selected_rows() > 0) {
1078 s.get_selected(ret);
1080 // set some properties of the tree for use by the dropped element.
1081 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1082 var data = JSON.parse(value);
1085 var xname = this.get('/LeftTree.model').file.guessName(data);
1086 console.log('selected:' + xname);
1090 return []; // could not find it..
1099 for (var i =0 ; i < li.length; i++ ) {
1102 // this is specific to roo!!!?
1103 if (!el) { // skip empty?
1106 var fullpath = _this.file.guessName(el);
1107 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1112 if (el.items && el.items.length) {
1121 addall([this.currentTree]);
1123 // only if we have nothing, should we add '*top'
1127 //console.log('all types in tree');
1128 //console.dump(ret);
1133 load : function(tr,iter)
1135 //this.insert(citer,iter,0);
1137 for(var i =0 ; i < tr.length; i++) {
1140 this.el.insert(ret ,iter,-1);
1142 this.el.append(ret);
1144 //print(JSON.stringify(ret,null,4));
1145 //print('call nodeToJSON: ' + tr[i]);
1146 var body = this.nodeToJSON(tr[i]);
1148 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1149 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1150 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1151 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1152 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1153 this.el.set_value(ret.iter, 2, '' + body );
1154 if (tr[i].items && tr[i].items.length) {
1155 this.load(tr[i].items, ret.iter);
1159 loadFile : function(f) {
1166 console.log('missing file');
1170 // load the file if not loaded..
1171 if (f.items === false) {
1173 f.loadItems(function() {
1179 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1181 if (f.items.length && typeof(f.items[0]) == 'string') {
1183 //this.get('/RightEditor').el.show();
1184 //this.get('/RightEditor.view').load( f.items[0]);
1188 //print(JSON.stringify(f.items, null,4));
1189 //console.dump(f.items);
1191 this.get('/LeftTree.view').el.expand_all();
1193 if (!f.items.length) {
1196 this.get('/Window.leftvpaned').el.set_position(80);
1198 this.get('/LeftTree.view').el.set_cursor(
1199 new Gtk.TreePath.from_string('0'), null, false);
1203 this.get('/Window.leftvpaned').el.set_position(200);
1206 //return; -- debuggin
1207 //print("hide right editior");
1208 //this.get('/RightEditor').el.hide();
1209 this.get('/Editor').el.hide();
1210 print("set current tree");
1212 this.currentTree = this.toJS(false, false)[0];
1215 //console.dump(this.currentTree);
1216 this.currentTree = this.currentTree || { items: [] };
1217 this.get('/LeftTree').renderView();
1218 // console.dump(this.map);
1219 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1220 var pm = this.get('/RightPalete.model');
1221 // set up provider..
1223 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1225 if (!this.get('/RightPalete').provider) {
1226 print ("********* PALETE PROVIDER MISSING?!!");
1228 this.get('/LeftTree').renderView();
1230 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1234 this.get('/Window.view-notebook').el.set_current_page(
1235 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1238 moveNode : function(target_data, action) {
1239 //print("MOVE NODE");
1240 // console.dump(target_data);
1242 var s = this.get('/LeftTree.view').selection;
1243 s.get_selected( oret);
1244 var node = this.nodeToJS(oret.iter,false);
1245 //console.dump(node);
1246 print(JSON.stringify(node, null,4));
1248 // needs to drop first, otherwise the target_data
1249 // treepath will be invalid.
1251 this.dropNode(target_data, node);
1252 if (action & Gdk.DragAction.MOVE) {
1253 // print("REMOVING OLD NODE");
1254 this.el.remove(oret.iter);
1258 this.activePath= false;
1261 nodeTip : function(c) {
1262 var ret = this.nodeTitle(c,true);
1268 if (!i.length || i[0] != '|') {
1274 if (typeof(c[i]) != 'string') {
1277 //print("prop : " + i + ':' + c[i]);
1278 if (!c[i].match(new RegExp('function'))) {
1281 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1285 ret+="\n\nMethods:" + funcs;
1290 nodeTitle : function(c, renderfull) {
1293 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1294 if (sr) txt.push('<s>');
1295 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1297 if (renderfull && c['|xns']) {
1298 txt.push(c['|xns']);
1301 if (c.xtype) { txt.push(c.xtype); }
1302 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1303 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1304 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1307 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1308 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1309 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1310 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1311 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1312 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1313 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1314 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1315 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1317 // for flat classes...
1318 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1319 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1322 if (sr) txt.push('</s>');
1323 return (txt.length == 0 ? "Element" : txt.join(" "));
1325 nodeToJS : function (treepath, with_id)
1327 //print("nodeToJS : WITHID: "+ with_id);
1328 var iter = treepath; // API used to be iter here..
1329 if (typeof(iter) == 'string') {
1331 if (!this.el.get_iter(ret,
1332 new Gtk.TreePath.from_string(treepath))) {
1338 var iv = this.getIterValue(iter, 2);
1339 // print("IV" + iv);
1340 var k = JSON.parse(iv);
1341 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1346 var treepath_str = this.el.get_path(iter).to_string();
1347 // not sure how we can handle mixed id stuff..
1348 if (typeof(k.id) == 'undefined') {
1349 k.id = 'builder-'+ treepath_str ;
1353 this.treemap[ treepath_str ] = k;
1354 k.xtreepath = treepath_str ;
1357 if (this.el.iter_has_child(iter)) {
1359 this.el.iter_children(cret, iter);
1360 k.items = this.toJS(cret.iter,with_id);
1364 nodeToJSON : function(c) {
1372 return JSON.stringify(o);
1374 singleNodeToJS : function (treepath)
1377 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1381 var iv = this.getIterValue(ret.iter, 2);
1383 return JSON.parse(iv);
1386 toJS : function(treepath, with_id)
1388 //print("toJS : WITHID: "+ with_id);
1390 var iter = treepath; // API used to be iter here..
1392 if (typeof(iter) == 'string') {
1394 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1406 if (!this.el.get_iter_first(ret)) {
1417 var k = this.nodeToJS(iter, with_id);
1421 if (!this.el.iter_next(iter)) {
1426 if (treepath === false) {
1428 return JSON.parse(JSON.stringify(ar));
1432 // convert the list into a json string..
1438 xtype: Gtk.TreeViewColumn,
1439 pack : "append_column",
1441 XObject.prototype.init.call(this);
1442 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1446 xtype: Gtk.CellRendererText,
1456 id : "LeftTreeMenu",
1459 xtype: Gtk.MenuItem,
1461 label : "Delete Element",
1463 activate : function (self) {
1465 this.get('/LeftTree.model').deleteSelected();
1470 xtype: Gtk.MenuItem,
1472 activate : function (self) {
1474 var tree = this.get('/LeftTree');
1475 var model = this.get('/LeftTree.model');
1476 var el = tree.getActivePath();
1478 var js = model.toJS(el, false);
1479 // print(JSON.stringify(js[0], null,4));
1480 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1485 label : "Save as Template",
1495 id : "LeftProjectTree",
1496 showNoProjectSelected : function() {
1497 this.get('/StandardErrorDialog').show("Select a Project first.");
1499 getActiveProject : function() {
1500 return this.project;
1503 leave_notify_event : function (self, event) {
1510 pack : "pack_start,false,false",
1513 xtype: Gtk.ComboBox,
1515 changed : function (self) {
1516 var fn = this.getValue();
1517 var pm = imports.ProjectManager.ProjectManager;
1518 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1522 getValue : function() {
1523 var ix = this.el.get_active();
1527 var data = imports.ProjectManager.ProjectManager.projects;
1528 if (typeof(data[ix]) == 'undefined') {
1534 XObject.prototype.init.call(this);
1535 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1537 setValue : function(fn)
1541 var data = imports.ProjectManager.ProjectManager.projects;
1542 data.forEach(function(n, ix) {
1551 xtype: Gtk.CellRendererText,
1552 pack : "pack_start,true",
1556 xtype: Gtk.ListStore,
1560 XObject.prototype.init.call(this);
1561 this.el.set_column_types ( 2, [
1562 GObject.TYPE_STRING, // real key
1563 GObject.TYPE_STRING // real type
1567 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1568 var pm = imports.ProjectManager.ProjectManager;
1570 pm.on('changed', function() {
1571 print("caught changed hook on project manager - reloading data");
1572 _this.loadData(pm.projects);
1576 loadData : function(data) {
1577 var ov = this.get('/LeftProjectTree.combo').getValue();
1581 data.forEach(function(p) {
1584 //print(JSON.stringify(XObject.keys(na)));
1585 //print(typeof(na.iter));
1586 //print(JSON.stringify(iter))
1587 el.set_value(na.iter, 0, p.fn);
1588 el.set_value(na.iter, 1, p.name);
1592 this.get('/LeftProjectTree.combo').setValue(ov);
1600 xtype: Gtk.ScrolledWindow,
1602 shadow_type : Gtk.ShadowType.IN,
1604 XObject.prototype.init.call(this);
1605 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1609 xtype: Gtk.TreeView,
1612 cursor_changed : function (self) {
1614 var model = this.get('/LeftProjectTree.model');
1618 if (model.loading) {
1623 print("LOADING IS FALSE");
1625 if (this.selection.count_selected_rows() < 1) {
1626 //XN.get('Builder.LeftTree.model').
1627 this.get('/LeftTree.model').load( false);
1631 //console.log('changed');
1632 var s = this.selection;
1633 s.get_selected(ret);
1634 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1635 //console.log(JSON.stringify(value,null,4));// id..
1636 console.log("OUT?" + value);// id..
1637 var file = this.get('/LeftProjectTree').project.getById(value);
1644 var nb = this.get('/LeftTopPanel.expander');
1645 nb.el.expanded = false;
1647 //nb.listeners.activate.call(nb);
1648 //_expander.el.set_expanded(false);
1650 var ltm = this.get('/LeftTree.model');
1658 enable_tree_lines : true,
1659 headers_visible : false,
1661 XObject.prototype.init.call(this);
1662 var description = new Pango.FontDescription.c_new();
1663 description.set_size(8000);
1664 this.el.modify_font(description);
1666 this.selection = this.el.get_selection();
1667 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1671 xtype: Gtk.TreeStore,
1676 XObject.prototype.init.call(this);
1677 this.el.set_column_types ( 3, [
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 XObject.prototype.init.call(this);
2013 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2015 shadow_type : Gtk.ShadowType.IN,
2018 xtype: Gtk.TreeView,
2020 button_press_event : function (self, ev) {
2023 if (!this.get('/Editor').save()) {
2024 // popup!! - click handled..
2029 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2030 return false; //not on a element.
2034 if (ev.button.button == 3) {
2036 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2039 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2040 var p = this.get('/LeftPanelPopup');
2045 p.el.set_screen(Gdk.Screen.get_default());
2047 p.el.popup(null, null, null, null, 3, ev.button.time);
2048 //Seed.print("click:" + res.column.title);
2055 if (res.column.title != 'value') {
2056 // XObject.error("column is not value?");
2057 return false; // ignore.. - key click.. ??? should we do this??
2060 // currently editing???
2061 // if ( this.activePath) {
2063 // this.activePath = false;
2065 if (this.get('/Editor').dirty) {
2066 //if (!this.get('/Editor.buffer').checkSyntax()) {
2067 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2071 if (!this.get('/Editor.view').save()) {
2075 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2076 this.get('/LeftPanel').editing = false;
2078 // XObject.error("Currently editing?");
2082 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2084 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2086 // get options for this type -- this is to support option lists etc..
2087 var provider = this.get('/LeftTree').getPaleteProvider();
2088 var opts = provider.findOptions(type);
2090 if (opts === false) {
2092 this.get('/LeftPanel').editableColumn.setOptions([]);
2093 renderer.has_entry = true;
2095 this.get('/LeftPanel').editableColumn.setOptions(opts);
2096 renderer.has_entry = false;
2098 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2100 //Seed.print("click" + ev.type);
2101 //console.dump(res);
2110 enable_tree_lines : true,
2111 headers_visible : false,
2113 XObject.prototype.init.call(this);
2115 this.selection = this.el.get_selection();
2116 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2119 var description = new Pango.FontDescription.c_new();
2120 description.set_size(8000);
2121 this.el.modify_font(description);
2125 xtype: Gtk.TreeStore,
2129 add : function(info) {
2130 // info includes key, val, skel, etype..
2132 type = info.type.toLowerCase();
2133 var data = this.toJS();
2135 if (info.etype == 'events') {
2136 data.listeners = data.listeners || { };
2137 if (typeof(data.listeners[info.key]) != 'undefined') {
2138 return; //already set!
2141 if (typeof(data[info.key]) != 'undefined') {
2146 if (typeof(info.val) == 'undefined') {
2149 if (info.type.toLowerCase() == 'boolean') {
2152 if (type == 'number') {
2160 if (info.etype == 'events') {
2162 data.listeners[info.key] = info.val;
2165 data[info.key] = info.val;
2169 var map = this.load(data);
2171 // flag it as changed to the interface..
2172 this.get('/LeftTree.model').setFromNode(false,node);
2173 this.get('/LeftTree.model').changed(true);
2176 this.startEditing(map[k]);
2179 LeftPanel.get('view').el.row_activated(
2180 new Gtk.TreePath.from_string(map[k]),
2181 LeftPanel.editableColumn.el
2185 changed : function(str, doRefresh) {
2186 if (!this.activePath) {
2187 print("NO active path when changed")
2191 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2193 this.el.set_value(ret.iter, 1, '' +str);
2194 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2195 var type = this.getIterValue(ret.iter, 4);
2197 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2198 // update the tree...
2199 print("new data: " + JSON.stringify(this.toJS() , null,4));
2200 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2201 this.get('/LeftTree.model').changed(doRefresh);
2204 deleteSelected : function() {
2205 var data = this.toJS();
2207 var s = this.get('/LeftPanel.view').selection;
2208 s.get_selected( ret);
2211 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2213 if (val[0] == '!') {
2215 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2218 delete data.listeners[ val.substring(1)];
2219 if (!XObject.keys(data.listeners).length) {
2220 delete data.listeners;
2224 if (typeof(data[val]) == 'undefined') {
2234 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2235 this.get('/LeftTree.model').changed(true);
2239 getIterValue : function(iter, col) {
2240 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2243 getType : function(treepath) {
2244 return this.getValue(treepath, 4);
2246 getValue : function(treepath_str, col)
2248 // get's the value in a row.. - keys - returns string, values - formats it..
2250 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2252 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2257 var type = this.getType(this.el.get_path(ret.iter).to_string());
2258 //print("TYPE: " +type + " - val:" + val);
2259 switch(type.toLowerCase()) {
2263 return parseFloat(val); // Nan ?? invalid!!?
2266 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2268 return val == 'true' ? true : false;
2270 var nv = parseFloat(val);
2271 if (!isNaN(nv) && (val == ''+nv)) {
2279 XObject.prototype.init.call(this);
2280 this.el.set_column_types ( 6, [
2281 GObject.TYPE_STRING, // 0 real key
2282 GObject.TYPE_STRING, // 1 real value
2283 GObject.TYPE_STRING, // 2 visable key
2284 GObject.TYPE_STRING, // 3 visable value
2285 GObject.TYPE_STRING, // 4 need to store type of!!!
2286 GObject.TYPE_STRING // 5 tooltip
2290 load : function(ar) {
2291 // might casue problesm..
2292 // this.get('/Editor.RightEditor').save();
2294 this.get('/Editor').el.hide();
2295 this.get('/Editor').activePath = false;
2300 //this.get('/RightEditor').el.hide();
2307 var provider = this.get('/LeftTree').getPaleteProvider();
2311 var keys = XObject.keys(ar);
2313 ar.listeners = ar.listeners || {};
2315 for (var i in ar.listeners ) {
2317 this.el.append(iret);
2318 var p = this.el.get_path(iret.iter).to_string();
2321 this.el.set_value(iret.iter, 0, '!'+ i );
2322 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2323 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2325 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2326 this.el.set_value(iret.iter, 4, 'function');
2327 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2333 keys.forEach(function(i) {
2334 if (typeof(ar[i]) == 'object') {
2338 var type = provider.findType(ar, i, ar[i]);
2340 _this.el.append(iret);
2341 var p = _this.el.get_path(iret.iter).to_string();
2343 _this.el.set_value(iret.iter, 0, ''+i);
2344 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2345 _this.el.set_value(iret.iter, 2, ''+i);
2346 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2347 _this.el.set_value(iret.iter, 4, ''+type);
2348 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2352 startEditing : function(path,col) {
2354 // alled by menu 'edit' currently..
2356 * start editing path (or selected if not set..)
2357 * @param {String|false} path (optional) treepath to edit - selected tree gets
2358 * edited by default.
2359 * @param {Number} 0 or 1 (optional)- column to edit.
2361 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2363 if (typeof(path) == 'string') {
2364 tp = new Gtk.TreePath.from_string(path);
2367 var s = this.get('/LeftPanel.view').selection;
2368 s.get_selected( itr);
2369 tp = this.el.get_path(itr.iter);
2370 path = tp.to_string();
2374 // which colum is to be edited..
2377 // not sure what this does..
2379 if (typeof(col) == 'undefined') {
2380 var k = this.getValue(path, 0);
2382 colObj = (!k.length || k == '|') ?
2383 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2385 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2388 // make sure the pulldown is set correctly..
2389 // not really needed for second col...
2390 var showEditor = false;
2391 this.get('/Editor').activePath = false;
2392 this.get('/Editor').el.hide();
2395 var provider = this.get('/LeftTree').getPaleteProvider();
2396 var type = this.get('/LeftPanel.model').getType(path);
2397 var opts = provider.findOptions(type);
2398 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2400 if (opts === false) {
2401 this.get('/LeftPanel').editableColumn.setOptions([]);
2402 renderer.has_entry = true;
2404 this.get('/LeftPanel').editableColumn.setOptions(opts);
2405 renderer.has_entry = false;/// - pulldowns do not have entries
2407 // determine if we should use the Text editor...
2408 var keyname = this.getValue(path, 0);
2409 var data_value = this.getValue(path, 1);
2411 if ((keyname[0] == '|') ||
2413 (typeof(data_value) == 'string' ) &&
2414 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2418 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2423 // this.get('/BottomPane').el.hide();
2424 //this.get('/RightEditor').el.hide();
2429 this.activePath = false;
2431 _this.get('/Editor').el.show_all();
2432 GLib.timeout_add(0, 1, function() {
2434 //_this.get('/BottomPane').el.show();
2435 //_this.get('/RightEditor').el.show();
2437 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2439 _this.get('/Editor').activePath = path;
2440 _this.activePath = path ;
2450 // iter now has row...
2451 GLib.timeout_add(0, 100, function() {
2452 _this.activePath = path;
2453 colObj.items[0].el.editable = true; // esp. need for col 0..
2454 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2465 this.get('/LeftPanel.model').el.get_iter_first(iret);
2471 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2474 ar.listeners = ar.listeners || {};
2475 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2478 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2481 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2487 //print(JSON.stringify(ar));
2491 toShort : function(str) {
2492 var a = typeof(str) == 'string' ? str.split("\n") : [];
2493 return a.length > 1 ? a[0] + '....' : '' + str;
2497 xtype: Gtk.TreeViewColumn,
2498 pack : "append_column",
2500 XObject.prototype.init.call(this);
2502 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2503 this.get('/LeftPanel').propertyColumn = this;
2508 xtype: Gtk.CellRendererText,
2509 pack : "pack_start",
2511 editing_started : function (self, editable, path) {
2513 this.get('/LeftPanel.model').activePath = path;
2516 edited : function (self, object, p0) {
2518 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2520 var model = this.get('/LeftPanel.model');
2521 var path = model.activePath;
2523 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2524 model.el.set_value(iret.iter, 0, p0);
2525 model.el.set_value(iret.iter, 2, p0);
2527 model.activePath = false;
2528 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2529 this.get('/LeftTree.model').changed(true);
2531 this.el.editable = false;
2538 xtype: Gtk.TreeViewColumn,
2539 pack : "append_column",
2542 XObject.prototype.init.call(this);
2543 this.el.add_attribute(this.items[0].el , 'text', 3 );
2544 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2545 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2546 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2548 this.get('/LeftPanel').editableColumn= this;
2550 setOptions : function(ar) {
2551 var m = this.items[0].el.model;
2554 ar.forEach(function(i) {
2558 m.set_value(iret.iter, 0, i);
2564 xtype: Gtk.CellRendererCombo,
2566 edited : function (self, object, p0) {
2568 this.get('/LeftPanel').editing = false;
2569 var ap = this.get('/LeftPanel.model').activePath
2570 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2571 this.get('/LeftPanel.model').changed(p0, true);
2572 this.get('/LeftPanel.model').activePath = false;
2573 this.el.editable = false;
2575 editing_started : function (self, editable, path) {
2576 this.get('/LeftPanel').editing = true;
2577 // console.log('editing started');
2578 // r.has_entry = false;
2580 this.el.editable = false; // make sure it's not editor...
2585 pack : "pack_start",
2589 XObject.prototype.init.call(this);
2590 this.el.model = new Gtk.ListStore();
2591 this.el.model.set_column_types ( 1, [
2592 GObject.TYPE_STRING // 0 real key
2603 id : "LeftPanelPopup",
2606 xtype: Gtk.MenuItem,
2610 activate : function (self) {
2611 this.get('/LeftPanel.model').deleteSelected();
2616 xtype: Gtk.MenuItem,
2620 activate : function (self) {
2621 this.get('/LeftPanel.model').startEditing(false, 0);
2634 xtype: Gtk.ScrolledWindow,
2635 pack : "pack_end,false,true,0",
2638 shadow_type : Gtk.ShadowType.IN,
2640 XObject.prototype.init.call(this);
2641 XObject.prototype.init.call(this);
2642 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2643 this.el.set_size_request ( 150, -1 );
2646 activeElement : false,
2647 hideWin : function() {
2650 print("HIDEWIN - currently not shown")
2655 if (this.get('/Window.left').el.position < 160) {
2656 print("HIDEWIN - small already.")
2660 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2661 print("HIDEWIN attempting to hide.")
2668 xtype: Gtk.TreeView,
2670 cursor_changed : function (self) {
2671 // this is getting fired when we are loading elements..
2672 if (this.get('/MidPropTree.model').loading) {
2678 //console.log('changed');
2679 var m = this.get('model');
2680 if (!this.selection){
2681 this.selection = this.el.get_selection();
2684 var s = this.selection;
2685 if (!s.get_selected(iret)) {
2688 var tp = m.el.get_path(iret.iter).to_string();
2693 var key = m.getValue(tp, 0);
2695 var type = m.getValue(tp, 1);
2696 var skel = m.getValue(tp, 3);
2697 var etype = m.getValue(tp, 5);
2700 this.get('/MidPropTree').hideWin();
2702 if (type.toLowerCase() == 'function') {
2704 if (etype != 'events') {
2707 print("cursor_changed: ADDding to left panel model");
2708 this.get('/LeftPanel.model').add({
2716 // has dot in name, and is boolean???? this does not make sense..
2717 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2720 print("cursor_changed: ADDding to left panel model");
2721 this.get('/LeftPanel.model').add( {
2731 enable_tree_lines : true,
2732 headers_visible : false,
2734 XObject.prototype.init.call(this);
2736 var description = new Pango.FontDescription.c_new();
2737 description.set_size(8000);
2738 this.el.modify_font(description);
2740 //this.selection = this.el.get_selection();
2741 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2750 xtype: Gtk.ListStore,
2754 getValue : function(treepath, col)
2756 var tp = new Gtk.TreePath.from_string (treepath);
2758 this.el.get_iter (iret, tp);
2759 var value = this.el.get_value(iret.iter, col);
2760 return ''+ value.value.get_string();
2764 XObject.prototype.init.call(this);
2765 this.el.set_column_types ( 6, [
2766 GObject.TYPE_STRING, // real key
2767 GObject.TYPE_STRING, // real type
2768 GObject.TYPE_STRING, // docs ?
2769 GObject.TYPE_STRING, // visable desc
2770 GObject.TYPE_STRING, // function desc
2771 GObject.TYPE_STRING // element type (event|prop)
2775 showData : function(type) {
2778 this.loading = true;
2780 if (!this.get('/MidPropTree').activeElement || !type) {
2781 this.loading = false;
2782 return; // no active element
2785 var fullpath = this.get('/LeftTree.model').file.guessName(
2786 this.get('/MidPropTree').activeElement);
2787 var palete = this.get('/LeftTree').getPaleteProvider();
2791 Seed.print('Showing right?');
2792 if (!this.get('/MidPropTree').shown) {
2794 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2795 this.get('/MidPropTree').el.show();
2796 this.get('/MidPropTree').shown = true;
2799 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2800 return a.name > b.name ? 1 : -1;
2802 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2803 // console.dump(elementList);
2805 // scope of this is off..??
2808 for(var i =0 ; i < elementList.length; i++) {
2810 var p=elementList[i];
2811 this.el.append(iret);
2812 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2813 //GObject.TYPE_STRING, // real key
2814 // GObject.TYPE_STRING, // real type
2815 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2816 // GObject.TYPE_STRING // func def?
2819 this.el.set_value(iret.iter, 0, p.name);
2820 this.el.set_value(iret.iter, 1, p.type);
2821 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2822 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2823 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2824 this.el.set_value(iret.iter, 5, type);
2827 this.loading = false;
2831 xtype: Gtk.TreeViewColumn,
2834 this.el = new Gtk.TreeViewColumn();
2835 this.parent.el.append_column(this.el);
2837 XObject.prototype.init.call(this);
2838 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2842 xtype: Gtk.CellRendererText,
2843 pack : "pack_start,true"
2870 xtype: Gtk.Notebook,
2871 pack : "pack_start,true,true",
2872 id : "view-help-nb",
2874 XObject.prototype.init.call(this);
2875 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2876 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2880 xtype: Gtk.Notebook,
2881 id : "view-notebook",
2885 XObject.prototype.init.call(this);
2886 this.el.set_current_page(0);
2887 //print("SET LABEL?")
2888 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2889 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2895 id : "RightBrowser",
2900 pack : "pack_start,false,true,0",
2905 clicked : function (self) {
2906 this.get('/RightBrowser.view').renderJS(null,true);
2910 pack : "pack_start,false,false,0"
2913 xtype: Gtk.CheckButton,
2915 toggled : function (self, state) {
2916 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2921 label : "Auto Redraw On",
2922 pack : "pack_start,false,false,0"
2927 clicked : function (self) {
2929 var view = this.get('/RightBrowser.view');
2930 //this.get('/RightBrowser.view').redraws = 99;
2931 view.refreshRequired = true;
2932 view.lastRedraw = false;
2933 view.renderedData = false;
2934 view.renderJS(null,true);
2938 label : "Full Redraw",
2939 pack : "pack_start,false,false,0"
2944 xtype: Gtk.ScrolledWindow,
2947 XObject.prototype.init.call(this);
2948 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2950 shadow_type : Gtk.ShadowType.IN,
2953 xtype: WebKit.WebView,
2955 load_finished : function (self, object) {
2956 print("load finished");
2957 // print("load_finished"); return;
2958 // if (this.ready) { // dont do it twice!
2961 if (!this.inspectorShown) {
2962 this.el.get_inspector().show();
2963 this.inspectorShown = true;
2968 //if (this.pendingRedraw) {
2969 // this.pendingRedraw = false;
2970 // this.refreshRequired = true;
2972 //var js = this.get('/LeftTree.model').toJS();
2973 //if (js && js[0]) {
2974 // this.renderJS(js[0]);
2978 script_alert : function (self, object, p0) {
2981 return true; // do not display anything...
2983 console_message : function (self, object, p0, p1) {
2985 // console.log(object);
2988 if (object.match(/variable/) && object.match(/Builder/)) {
2989 print("got builder missing message");
2990 this.refreshRequired = true;
2991 this.lastRedraw = 0;
2997 if (!object.match(/^\{/)) {
2999 //this.get('/Terminal').feed(object);
3000 return true; // do not handle!!! -> later maybe in console..
3006 // console.log(object);
3007 var val = JSON.parse(object);
3009 if (typeof(val['hover-node']) != 'undefined') {
3010 this.activeNode = val['hover-node'];
3011 console.log('active node: ' + this.activeNode);
3016 if (typeof(val['id']) != 'undefined') {
3017 // this.activeNode = val['id'];
3018 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
3019 if (!tg || typeof(tg[0]) == 'undefined') {
3022 print("SELECT node " + tg[0]);
3024 this.get('/LeftTree.view').selectNode(tg[0]);
3029 if (ret && typeof(val['set']) != 'undefined') {
3030 print("console messages: ADDding to left panel model");
3032 //this.get('/LeftPanel.model').add({
3033 // key : val['set'],
3034 // val : val['value']
3036 //console.log('active node: ' + this.activeNode);
3039 //Seed.print('a:'+a);
3040 //Seed.print('b:'+b);
3041 //Seed.print('c:'+c);
3044 drag_motion : function (w, ctx, x, y, time, ud) {
3045 // console.log('DRAG MOTION');
3047 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3048 this.targetData = [];
3049 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3051 // A) find out from drag all the places that node could be dropped.
3052 var src = Gtk.drag_get_source_widget(ctx);
3053 if (!src.dropList) {
3054 Gdk.drag_status(ctx,0, time);
3057 // b) get what we are over.. (from activeNode)
3058 // tree is empty.. - list should be correct..
3059 if (!this.get('/LeftTree.model').currentTree) {
3060 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3064 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3066 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3069 Gdk.drag_status(ctx, 0,time);
3070 this.get('/LeftTree.view').highlight(false);
3074 // if we have a target..
3075 // -> highlight it! (in browser)
3076 // -> highlight it! (in tree)
3078 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3079 this.get('/LeftTree.view').highlight(tg);
3080 this.targetData = tg;
3081 // for tree we should handle this...
3084 drag_drop : function (w, ctx, x, y,time, ud) {
3085 print("TARGET: drag-drop");
3086 var is_valid_drop_site = true;
3090 ( /* will receive 'drag-data-received' signal */
3091 ctx, /* represents the current state of the DnD */
3092 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3093 time /* time stamp */
3097 /* No target offered by source => error */
3100 return is_valid_drop_site;
3102 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3104 print("Browser: drag-data-received");
3105 var delete_selection_data = false;
3106 vardnd_success = false;
3107 /* Deal with what we are given from source */
3108 if( sel_data && sel_data.length ) {
3110 if (ctx.action == Gdk.DragAction.ASK) {
3111 /* Ask the user to move or copy, then set the ctx action. */
3114 if (ctx.action == Gdk.DragAction.MOVE) {
3115 delete_selection_data = true;
3117 var source = Gtk.drag_get_source_widget(ctx);
3119 print("Browser: source.DRAGDATA? " + source.dragData);
3120 if (this.targetData) {
3121 print(this.targetData);
3122 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3131 if (dnd_success == false)
3133 Seed.print ("DnD data transfer failed!\n");
3136 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3139 create_web_view : function (self, object) {
3140 print("CREATE WEB VIEW");
3141 return null; //new WebKit.WebView();
3148 XObject.prototype.init.call(this);
3149 // this may not work!?
3150 var settings = this.el.get_settings();
3151 settings.enable_developer_extras = true;
3153 // this was an attempt to change the url perms.. did not work..
3154 // settings.enable_file_access_from_file_uris = true;
3155 // settings.enable_offline_web_application_cache - true;
3156 // settings.enable_universal_access_from_file_uris = true;
3160 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3161 _this.get('/BottomPane.inspector').el.show();
3162 return _this.get('/BottomPane.inspector').el;
3166 // FIXME - base url of script..
3167 // we need it so some of the database features work.
3168 this.el.load_html_string( "Render not ready" ,
3169 //fixme - should be a config option!
3170 // or should we catch stuff and fix it up..
3171 'http://localhost/app.Builder/'
3175 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3177 this.el.drag_dest_set
3178 ( /* widget that will accept a drop */
3179 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3180 null, /* lists of target to support */
3181 0, /* size of list */
3182 Gdk.DragAction.COPY /* what to do with data after dropped */
3185 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3186 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3188 GLib.timeout_add_seconds(0, 1, function() {
3189 // print("run refresh?");
3196 renderJS : function(data, force) {
3198 // this is the public redraw call..
3199 // we refresh in a loop privately..
3200 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3201 if (!autodraw && !force) {
3202 print("Skipping redraw - no force, and autodraw off");
3205 this.refreshRequired = true;
3207 runRefresh : function()
3209 // this is run every 2 seconds from the init..
3213 if (!this.refreshRequired) {
3214 // print("no refresh required");
3218 if (this.lastRedraw) {
3219 // do not redraw if last redraw was less that 5 seconds ago.
3220 if (((new Date()) - this.lastRedraw) < 5000) {
3228 if (!this.get('/Window.LeftTree').getActiveFile()) {
3231 this.refreshRequired = false;
3232 // print("HTML RENDERING");
3234 this.get('/BottomPane').el.show();
3235 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3242 var js = this.get('/LeftTree.model').toJS();
3243 if (!js || !js.length) {
3252 var project = this.get('/Window.LeftTree').getActiveFile().project;
3253 //print (project.fn);
3254 // set it to non-empty.
3255 project.runhtml = project.runhtml || '';
3256 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3259 this.runhtml = this.runhtml || '';
3261 var file = this.get('/LeftTree.model').file;
3262 var items = file.items;
3263 file.items = this.get('/LeftTree.model').toJS(false, false);
3264 //file.items[0].background = false;
3265 //var p = file.parent;
3266 //file.parent = false;
3268 var js_src = file.toSourcePreview();
3269 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3270 // unless it' sforced..
3275 this.renderedData = js_src;
3278 //file.items = items;
3279 //print("send source as " + js_src);
3282 "Roo.onReady(function() {\n" +
3283 "if (" + file.name +".show) " + file.name +".show({});\n" +
3284 "Roo.XComponent.build();\n" +
3291 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3292 // then we need to reload the browser using
3293 // load_html_string..
3295 // then trigger a redraw once it's loaded..
3296 this.pendingRedraw = true;
3297 var runhtml = '<script type="text/javascript">' + "\n" ;
3298 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3299 runhtml += '</script>'+ "\n" ;
3301 this.runhtml = project.runhtml;
3302 // need to modify paths
3305 this.lastRedraw= new Date();
3306 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3307 html = html.replace('</head>',
3310 '<script type="text/javascript">' + "\n" +
3315 //print("LOAD HTML " + html);
3316 this.el.load_html_string( html ,
3317 //fixme - should be a config option!
3318 'http://localhost/app.Builder/'
3321 // should trigger load_finished! - which in truns shoudl set refresh Required;
3326 //this.renderedData = data;
3327 //var str = JSON.stringify(data) ;
3330 console.log('not loaded yet');
3332 this.lastRedraw = new Date();
3334 this.el.execute_script("Builder.render(" +
3335 JSON.stringify(js_src) +
3337 JSON.stringify(file.name) +
3340 print( "before render" + this.lastRedraw);
3341 print( "after render" + (new Date()));
3351 id : "RightGtkView",
3353 redraw : function() {
3354 this.highlightWidget = false;
3355 print("REDRAW CALLED");
3356 this.activePath = this.get('/LeftTree').getActivePath();
3357 if (this.renderedEl) {
3358 print("QUEUE DRAW CALLING");
3359 this.renderedEl.queue_draw();
3362 renderJS : function(data, withDebug)
3364 this.highlightWidget = false;
3366 this.withDebug = false;
3367 while (this.get('view').el.get_children().length) {
3368 var c = this.get('view').el.get_children()[0];
3369 this.get('view').el.remove(c);
3376 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3377 // in theory tree is actually window..
3380 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3386 this.get('view').el.set_size_request(
3387 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3389 if (this.renderedEl) {
3390 this.renderedEl.set_size_request(
3391 tree.default_width || 600,
3392 tree.default_height || 400
3395 this.get('view').el.show_all();
3400 showInWindow : function() {
3401 print("GET PROEJCT");
3402 var pr = this.get('/LeftProjectTree').getActiveProject();
3404 console.log(pr.paths);
3407 var src= this.buildJS(
3408 this.get('/LeftTree.model').toJS()[0],
3413 //var x = new imports.sandbox.Context();
3417 Seed.check_syntax('var e = ' + src);
3420 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3421 this.get('/Terminal').feed(console._dump(e)+"\n");
3423 var lines = src.split("\n");
3424 var start = Math.max(0, e.line - 10);
3425 var end = Math.min(lines.length, e.line + 10);
3426 for (var i =start ; i < end; i++) {
3428 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3431 this.get('/Terminal').feed(lines[i] + "\n");
3438 this.get('/BottomPane').el.set_current_page(1);
3439 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3440 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3441 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3443 var _top = x.get_global_object()._top;
3445 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3447 if (_top.el.popup) {
3448 _top.el.popup(null, null, null, null, 3, null);
3452 viewAdd : function(item, par)
3455 // does something similar to xobject..
3456 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3458 // pack is forced to 'false'
3459 if (item.pack===false || item.pack === 'false') { // no ;
3463 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3466 var type = item['|xns'] + '.' + item['xtype'];
3468 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3472 var ns = imports.gi[item['|xns']];
3473 var ctr = ns[item['xtype']]; // why are we using array here..?
3478 for(var k in item) {
3480 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3494 // value is a function..
3495 if (k[0] == '|' && typeof(kv) == 'string') {
3497 if (kv.match(new RegExp('function'))) {
3500 print("WASL " + k + '=' + kv);
3502 eval( 'kv = ' + kv);
3503 } catch(e) { continue; }
3506 // print(k + '=' + kv);
3508 if (k[0] == '|') { // should be boolean or number..
3510 //print(k + '=' + kv);
3513 if (k == 'show_tabs') { // force tab showing for notebooks.
3516 print(k + '=' + typeof(kv) + " : " + kv);
3520 var altctr = XObject.baseXObject({ xtype: ctr} );
3522 if (!item.pack && altctr) {
3524 print("SETTING PACK TO XObjectBase method");
3525 pack_m = altctr.prototype.pack;
3530 var el = new ctr(ctr_args);
3532 print("PACK" + item.pack);
3533 //console.dump(item.pack);
3540 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3541 if (typeof(item.pack) == 'string') {
3543 item.pack.split(',').forEach(function(e, i) {
3545 if (e == 'false') { args.push( false); return; }
3546 if (e == 'true') { args.push( true); return; }
3547 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3550 //print(args.join(","));
3552 pack_m = args.shift();
3554 pack_m = item.pack.shift();
3559 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3561 name: "ArgumentError",
3562 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3563 "ADDING : " + item.id + " " + el
3570 //console.dump(args);
3572 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3573 //Seed.print('args: ' + args.length);
3574 if (typeof(pack_m) == 'string') {
3575 par[pack_m].apply(par, args);
3576 } else if (pack_m) {
3577 pack_m.call(item, par, item);
3581 item.items = item.items || [];
3582 item.items.forEach(function(ch,n) {
3584 print ("type:" + type);
3586 print ("ch.pack:" + ch.pack);
3589 if (type == 'Gtk.Table' && ch.pack == 'add') {
3590 var c = n % item.n_columns;
3591 var r = Math.floor(n/item.n_columns);
3592 ch.pack = [ 'attach', c, c+1, r, r+1,
3593 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3594 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3595 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3596 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3600 _this.viewAdd(ch, el);
3605 // add the signal handlers.
3606 // is it a widget!?!!?
3612 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3613 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3614 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3615 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3616 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3626 widgetDragDropEvent : function() {
3627 print("WIDGET DRAGDROP");
3630 widgetDragMotionEvent : function() {
3631 print("WIDGET DRAGMOTION");
3634 widgetExposeEvent : function(w, evt, ud, item) {
3636 if (this.inRender) {
3640 if ( this.highlightWidget) {
3641 this.inRender = true;
3642 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3643 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3645 this.inRender = false;
3650 if (this.activePath != item.xtreepath) {
3654 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3655 // work out the coords of the window..
3657 var dr = widget.window;
3658 this.gc = (new Gdk.GC.c_new(dr));
3659 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3660 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3664 var r = evt.expose.area;
3665 // console.dump([r.x, r.y, r.width, r.height ] );
3667 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3668 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3669 // happens with gtkscrollview embedded stuff..
3670 var np =this.activePath.split(':');
3672 this.activePath = np.join(':');
3673 this.renderedEl.queue_draw();
3689 this.inRender = true;
3692 this.highlightWidget = widget;
3697 // print("DRAW BOX");
3698 //console.dump(this.box);
3699 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3700 this.inRender = false;
3703 widgetPressEvent : function(w,e,u,d) {
3704 if (this.get('view').pressed) {
3707 this.get('view').pressed = true;
3708 print("WIDGET PRESS " + d.xtreepath );
3709 this.get('/LeftTree.view').selectNode( d.xtreepath );
3712 widgetReleaseEvent : function() {
3713 this.get('view').pressed = false;
3719 pack : "pack_start,false,true,0",
3723 pack : "pack_start,false,false,0",
3724 label : "Run The Application",
3726 button_press_event : function (self, event) {
3727 // call render on left tree - with special option!?!
3729 //print("GET PROEJCT");
3730 var pr = this.get('/LeftProjectTree').getActiveProject();
3733 for (var i in pr.paths) {
3737 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3738 this.get('/Terminal').feed("RUN DIR:" + dir);
3741 this.get('/Terminal').el.fork_command_full(
3742 Vte.PtyFlags.DEFAULT,
3743 GLib.path_get_dirname (__script_path__) ,
3744 [ 'echo' , "hello"], //argv
3748 null, // child setupdata
3752 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3753 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3763 xtype: Gtk.ScrolledWindow,
3766 shadow_type : Gtk.ShadowType.IN,
3768 XObject.prototype.init.call(this);
3769 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3773 xtype: Gtk.EventBox,
3774 pack : "add_with_viewport",
3776 XObject.prototype.init.call(this);
3777 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3778 red: 0x9F00, green: 0xB800 , blue : 0xA800
3786 XObject.prototype.init.call(this);
3787 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3788 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3793 xtype: Gtk.EventBox,
3796 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3797 XObject.prototype.init.call(this);
3799 this.el.drag_dest_set
3800 ( /* widget that will accept a drop */
3801 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3802 null, /* lists of target to support */
3803 0, /* size of list */
3804 Gdk.DragAction.COPY /* what to do with data after dropped */
3807 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3808 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3811 getActiveNode : function(x,y)
3813 // workout what node is here..
3814 return '0'; // top..
3818 drag_motion : function (self, ctx, x, y, time) {
3820 // A) find out from drag all the places that node could be dropped.
3821 var src = Gtk.drag_get_source_widget(ctx);
3822 if (!src.dropList) {
3823 Gdk.drag_status(ctx, 0, time);
3826 // b) get what we are over.. (from activeNode)
3827 // tree is empty.. - list should be correct..
3828 if (!this.get('/LeftTree.model').currentTree) {
3829 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3833 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3834 var activeNode = this.getActiveNode(x, y);
3837 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3840 Gdk.drag_status(ctx, 0,time);
3841 this.get('/LeftTree.view').highlight(false);
3845 // if we have a target..
3846 // -> highlight it! (in browser)
3847 // -> highlight it! (in tree)
3849 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3850 this.get('/LeftTree.view').highlight(tg);
3851 this.targetData = tg;
3852 // for tree we should handle this...
3855 drag_drop : function (self,ctx, x, y, time) {
3856 Seed.print("TARGET: drag-drop");
3857 var is_valid_drop_site = true;
3861 ( /* will receive 'drag-data-received' signal */
3862 ctx, /* represents the current state of the this.gDnD */
3863 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3864 time /* time stamp */
3868 /* No target offered by source => error */
3871 return is_valid_drop_site;
3874 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3876 Seed.print("GtkView: drag-data-received");
3877 var delete_selection_data = false;
3878 var dnd_success = false;
3879 /* Deal with what we are given from source */
3880 if( sel_data && sel_data.length ) {
3882 if (ctx.action == Gdk.DragAction.ASK) {
3883 /* Ask the user to move or copy, then set the ctx action. */
3886 if (ctx.action == Gdk.DragAction.MOVE) {
3887 delete_selection_data = true;
3889 var source = Gtk.drag_get_source_widget( ctx );
3891 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3892 if (this.targetData) {
3893 Seed.print(this.targetData);
3894 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3903 if (dnd_success == false)
3905 Seed.print ("DnD data transfer failed!\n");
3908 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3911 button_press_event : function (self, event) {
3912 this.pressed = false;
3928 xtype: Gtk.ScrolledWindow,
3933 var file = this.get('/LeftTree').getActiveFile();
3937 var activeEl = this.get('/LeftTree').getActiveElement();
3938 var xtype = file.guessName( activeEl )
3939 if (!xtype || !xtype.length) {
3942 //this.get('/Window.view-help-nb').el.set_current_page(1);
3944 // get the active element being edited.
3945 var helpurl = file.getHelpUrl(xtype);
3947 // now load the help info in the page..
3948 this.get('help-view').el.open(helpurl);
3952 xtype: WebKit.WebView,
3956 XObject.prototype.init.call(this);
3957 this.get('/Window.help-view').el.open(
3958 "http://devel.akbkhome.com/seed/");
3970 xtype: Gtk.Notebook,
3974 XObject.prototype.init.call(this);
3975 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3976 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3977 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3981 xtype: Gtk.ScrolledWindow,
3985 xtype: Vte.Terminal,
3988 feed : function(istr) {
3989 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3990 // we should make ourselves visable!!!
3991 this.get('/BottomPane').el.show();
3992 this.get('/BottomPane').el.set_current_page(1);
3994 this.el.feed(str ,str.length);
3996 scroll_on_output : true,
3998 XObject.prototype.init.call(this);
3999 this.el.set_size (80, 1000);
4001 scrollback_lines : 1000
4006 xtype: Gtk.ScrolledWindow,
4010 xtype: WebKit.WebView,
4026 this.get('buttonbar').el.show();
4027 this.get('viewbox').el.hide();
4028 var ce = this.get('/Window.centereast').el;
4030 ce.set_position(ce.get_allocated_width() - 30);
4032 print("TRIED TO HIDE");
4035 this.get('buttonbar').el.hide();
4036 this.get('viewbox').el.show();
4037 var ce = this.get('/Window.centereast').el;
4038 print(JSON.stringify(XObject.keys(ce) ,null,4));
4039 ce.set_position(ce.get_allocated_width() - 150);
4041 // this.get('model').expanded();
4053 pack : "pack_start,false,true",
4055 clicked : function (self) {
4056 this.get('/RightPalete').show();
4063 stock : Gtk.STOCK_GOTO_FIRST,
4064 icon_size : Gtk.IconSize.MENU
4074 XObject.prototype.init.call(this);
4075 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4078 enter_notify_event : function (self, event) {
4079 this.get('/RightPalete').show();
4093 pack : "pack_start,false,true",
4102 pack : "pack_start,false,true",
4104 clicked : function (self) {
4105 this.get('/RightPalete').hide();
4112 stock : Gtk.STOCK_GOTO_LAST,
4113 icon_size : Gtk.IconSize.MENU
4120 xtype: Gtk.ScrolledWindow,
4123 XObject.prototype.init.call(this);
4124 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4125 this.el.set_size_request(-1,200);
4127 shadow_type : Gtk.ShadowType.IN,
4130 xtype: Gtk.TreeView,
4132 drag_begin : function (self, ctx) {
4133 // we could fill this in now...
4134 Seed.print('SOURCE: drag-begin');
4139 var s = this.selection;
4140 s.get_selected(iret);
4141 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4143 var pix = this.el.create_row_drag_icon ( path);
4146 if (Gtk.drag_set_icon_surface) {
4147 Gtk.drag_set_icon_surface( ctx, pix );
4149 Gtk.drag_set_icon_pixmap (ctx,
4150 pix.get_colormap(), pix, null, -10, -10);
4153 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4154 if (!this.get('/RightPalete').provider) {
4157 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4158 this.el.dragData = value;
4165 drag_data_get : function (self, drag_context, selection_data, info, time) {
4166 //Seed.print('Palete: drag-data-get: ' + target_type);
4167 if (this.el.dragData && this.el.dragData.length ) {
4168 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4172 //this.el.dragData = "TEST from source widget";
4176 drag_end : function (self, drag_context) {
4177 Seed.print('SOURCE: drag-end');
4178 this.el.dragData = false;
4179 this.el.dropList = false;
4180 this.get('/LeftTree.view').highlight(false);
4183 button_press_event : function (self, event) {
4185 if (!this.get('/Editor').save()) {
4186 // popup!! - click handled..
4193 enable_tree_lines : true,
4194 headers_visible : false,
4196 XObject.prototype.init.call(this);
4197 this.el.set_size_request(150,-1);
4198 // set_reorderable: [1]
4200 var description = new Pango.FontDescription.c_new();
4201 description.set_size(8000);
4202 this.el.modify_font(description);
4204 this.selection = this.el.get_selection();
4205 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4206 // this.selection.signal['changed'].connect(function() {
4207 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4209 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4211 this.el.drag_source_set ( /* widget will be drag-able */
4212 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4213 null, /* lists of target to support */
4214 0, /* size of list */
4215 Gdk.DragAction.COPY /* what to do with data after dropped */
4217 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4219 this.el.drag_source_set_target_list( imports.Builder3.Globals.targetList);
4220 this.el.drag_source_add_text_targets( );
4222 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4223 targets = new Gtk.TargetList();
4224 targets.add( LeftTree.atoms["STRING"], 0, 0);
4225 targets.add_text_targets( 1 );
4226 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4228 //if you want to allow text to be output elsewhere..
4229 //Gtk.drag_source_add_text_targets(this.el);
4235 xtype: Gtk.ListStore,
4238 XObject.prototype.init.call(this);
4239 this.el.set_column_types ( 2, [
4240 GObject.TYPE_STRING, // title
4241 GObject.TYPE_STRING // tip
4246 load : function(tr,iter)
4251 //console.log('Project tree load: ' + tr.length);
4253 //this.insert(citer,iter,0);
4254 for(var i =0 ; i < tr.length; i++) {
4257 this.el.append(cret);
4259 this.el.insert(cret,iter,-1);
4264 this.el.set_value(cret.iter, 0, '' + r ); // title
4266 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4267 //if (r.cn && r.cn.length) {
4268 // this.load(r.cn, citer);
4274 getValue : function (iter, col) {
4275 return this.el.get_value(iter, col).value.get_string();
4282 xtype: Gtk.TreeViewColumn,
4283 pack : "append_column",
4285 XObject.prototype.init.call(this);
4286 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4290 xtype: Gtk.CellRendererText,
4312 XObject.cache['/Window'] = Window;