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 XObject.prototype.init.call(this);
337 this.el.add_events (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",
401 XObject.prototype.init.call(this);
402 this.el.set_current_page(0);
409 xtype: Gtk.ScrolledWindow,
412 getActiveElement : function() { // return path to actie node.
414 var path = this.getActivePath();
419 this.get('model').el.get_iter_from_string(ret, path);
421 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
423 return JSON.parse(value);
425 getActiveFile : function() {
426 return this.get('model').file;
428 getActivePath : function() {
429 var model = this.get('model');
430 var view = this.get('view');
431 if (view.selection.count_selected_rows() < 1) {
435 view.selection.get_selected(ret);
436 return ret.model.get_path(ret.iter).to_string();
438 getPaleteProvider : function() {
439 var model = this.get('model');
440 var pm = imports.ProjectManager.ProjectManager;
441 return pm.getPalete(model.file.getType());
443 getRenderer : function() {
445 switch( this.getActiveFile().getType()) {
447 return this.get('/RightBrowser.view');
449 return this.get('/RightGtkView');
454 XObject.prototype.init.call(this);
455 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
457 renderView : function() {
458 var render = this.getRenderer();
459 var model = this.get('model');
461 render.renderJS(model.toJS(false,true)[0]);
463 print("NO RENDER JS METHOD?");
466 shadow_type : Gtk.ShadowType.IN,
471 button_press_event : function (self, ev) {
472 console.log("button press?");
474 if (!this.get('/Editor').save()) {
475 // popup!! - click handled..
479 if (ev.button.button != 3) {
480 print("click" + ev.button.button);
486 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
488 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
490 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
491 this.get('/LeftTreeMenu').el.show_all();
492 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
493 print("click:" + res.path.to_string());
496 drag_begin : function (self, ctx) {
497 print('SOURCE: drag-begin');
498 this.targetData = false;
499 // find what is selected in our tree...
501 this.selection.get_selected(ret);
503 // set some properties of the tree for use by the dropped element.
504 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
505 var data = JSON.parse(value);
506 var xname = this.get('/LeftTree.model').file.guessName(data);
508 this.el.dragData = xname;
509 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
512 // make the drag icon a picture of the node that was selected
513 var path = ret.model.get_path(ret.iter);
514 this.el.treepath = path.to_string();
516 // returns a cairo surface
517 var pix = this.el.create_row_drag_icon ( path);
519 if (Gtk.drag_set_icon_surface) {
520 Gtk.drag_set_icon_surface( ctx, pix );
522 Gtk.drag_set_icon_pixmap (ctx,
523 pix.get_colormap(), pix, null, -10, -10);
528 drag_end : function (self, drag_context) {
529 Seed.print('LEFT-TREE: drag-end');
530 this.el.dragData = false;
531 this.el.dropList = false;
532 this.targetData = false;
533 this.get('/LeftTree.view').highlight(false);
536 drag_data_get : function(self, ctx, sel_data, info, time)
546 drag_motion : function (self, ctx, x, y, time) {
547 console.log("LEFT-TREE: drag-motion");
548 var src = Gtk.drag_get_source_widget( ctx);
550 // a drag from elsewhere...- prevent drop..
552 print("no drag data!");
553 Gdk.drag_status(ctx, 0, time);
554 this.targetData = false;
557 var action = Gdk.DragAction.COPY;
558 if (src == this.el) {
559 // unless we are copying!!! ctl button..
560 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
564 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
565 // no children.. -- asume it's ok..
566 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
567 Gdk.drag_status(ctx, action ,time);
571 print("GETTING POS");
572 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
573 print("ISOVER? " + isOver);
575 Gdk.drag_status(ctx, 0 ,time);
576 return false; // not over apoint!?!
578 // drag node is parent of child..
579 console.log("SRC TREEPATH: " + src.treepath);
580 console.log("TARGET TREEPATH: " + data.path.to_string());
582 // nned to check a few here..
583 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
584 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
585 //Gtk.TreeViewDropPosition.AFTER
586 //Gtk.TreeViewDropPosition.BEFORE
588 if (typeof(src.treepath) != 'undefined' &&
589 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
590 print("subpath drag");
591 Gdk.drag_status( ctx, 0 ,time);
596 //print("DUMPING DATA");
597 //console.dump(data);
600 print(data.path.to_string() +' => '+ data.pos);
601 var tg = this.get('/LeftTree.model').findDropNodeByPath(
602 data.path.to_string(), src.dropList, data.pos);
604 this.get('/LeftTree.view').highlight(tg);
606 print("Can not find drop node path");
607 this.targetData = false;
608 Gdk.drag_status(ctx, 0, time);
611 print(JSON.stringify(tg,null,4));
613 this.targetData = tg;
616 Gdk.drag_status(ctx, action ,time);
620 drag_drop : function (w, ctx, x, y, time) {
621 Seed.print("TARGET: drag-drop");
622 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
624 ( /* will receive 'drag-data-received' signal */
625 ctx, /* represents the current state of the DnD */
626 imports.Builder3.Main.atoms["STRING"], /* the target type we want */
627 time /* time stamp */
631 /* No target offered by source => error */
636 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
637 print("Tree: drag-data-received");
639 var delete_selection_data = false;
640 var dnd_success = false;
641 //print(JSON.stringify(sel_data, null,4));
642 /* Deal with what we are given from source */
644 // simce I can not be bothered to sort out
645 // drag drop = let's assume it worked...
647 if( true || (sel_data && sel_data.length )) {
649 if (ctx.action == Gdk.DragAction.ASK) {
650 /* Ask the user to move or copy, then set the ctx action. */
653 if (ctx.action == Gdk.DragAction.MOVE) {
654 //delete_selection_data = true;
657 var source = Gtk.drag_get_source_widget( ctx );
659 if (this.targetData) {
660 if (source != this.el) {
661 print("DRAG FROM ANOTHER WIDGET");
662 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
664 // drag around.. - reorder..
665 print("DRAG FROM SELF");
666 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
670 //Seed.print(this.targetData);
676 // we can send stuff to souce here...
682 if (dnd_success == false)
684 Seed.print ("DnD data transfer failed!\n");
687 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
690 cursor_changed : function (self) {
691 if (this.blockChanges) { // probably not needed..
694 var render = this.get('/LeftTree').getRenderer();
697 if (this.selection.count_selected_rows() < 1) {
698 this.get('/LeftPanel.model').load( false);
699 this.get('/MidPropTree').activeElement = false;
700 this.get('/MidPropTree').hideWin();
702 var pm = this.get('/RightPalete.model');
703 if (!this.get('/LeftTree').getPaleteProvider()) {
704 // it may not be loaded yet..
708 this.get('/LeftTree').getPaleteProvider().gatherList(
709 this.get('/LeftTree.model').listAllTypes()
712 if (render && render.redraw) {
718 //console.log('changed');
719 var s = this.selection;
724 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
725 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
727 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
730 var data = JSON.parse(value);
731 this.get('/MidPropTree').activeElement = data;
732 this.get('/MidPropTree').hideWin();
733 this.get('/LeftPanel.model').load( data);
736 // _g.button.set_label(''+value.get_string());
738 var pm =this.get('/RightPalete.model');
739 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
740 this.get('/LeftTree.model').listAllTypes()));
743 if (render && render.redraw) {
747 //Seed.print( value.get_string());
755 enable_tree_lines : true,
756 headers_visible : false,
757 highlight : function(treepath_ar) {
759 // highlighting for drag/drop
760 if (treepath_ar.length && treepath_ar[0].length ) {
761 this.el.set_drag_dest_row(
762 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
764 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
770 XObject.prototype.init.call(this);
771 var description = new Pango.FontDescription.c_new();
772 description.set_size(8000);
773 this.el.modify_font(description);
775 this.selection = this.el.get_selection();
776 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
779 // is this really needed??
780 this.selection.signal['changed'].connect(function() {
781 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
782 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
786 this.el.drag_source_set( /* widget will be drag-able */
787 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
788 null, /* lists of target to support */
789 0, /* size of list */
790 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
793 this.el.drag_source_set_target_list(imports.Builder3.Main.targetList);
795 this.el.drag_source_add_text_targets();
796 this.el.drag_dest_set
798 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
799 null, /* lists of target to support */
800 0, /* size of list */
801 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
804 this.el.drag_dest_set_target_list( imports.Builder3.Main.targetList);
805 this.el.drag_dest_add_text_targets( );
807 selectNode : function(treepath_str) {
808 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
809 var tp = new Gtk.TreePath.from_string(treepath_str);
810 this.el.set_cursor(tp, null, false);
811 this.el.scroll_to_cell(tp, null, false, 0,0);
815 xtype: Gtk.TreeStore,
821 setFromNode : function(tp, n)
824 tp = this.get('/LeftTree').getActivePath();
827 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
828 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
829 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
830 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
834 changed : function( refresh) {
838 print("-------MODEL CHANGED CALLED" );
840 //this.currentTree = this.toJS(false, true)[0];
842 this.file.items = this.toJS(false, false);
843 print ("TO JS in " + ((new Date()) - d) + "ms");
844 // print("AFTER CHANGED");
845 //console.dump(this.file.items);
847 this.currentTree = this.file.items[0];
848 //console.log(this.file.toSource());
851 print("REDNER BROWSER?!");
852 this.get('/LeftTree').renderView();
854 var pm = this.get('/RightPalete.model');
855 if (!this.get('/RightPalete').provider) {
861 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
862 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
866 deleteSelected : function() {
867 this.get('/LeftTree.view').blockChanges = true;
869 var s = this.get('/LeftTree.view').selection;
870 s.get_selected(oret);
871 var path = this.el.get_path(oret.iter).to_string();
873 this.activePath= false;
876 this.activePath= false;
878 this.el.get_iter_from_string(ret, path);
879 this.el.remove(ret.iter);
881 // rebuild treemap. -- depreciated.!!
884 //this.toJS(null, true) // does not do anything?
885 this.activePath= false;
887 this.get('/LeftTree.view').blockChanges = false;
889 dropNode : function(target_data, node) {
891 // console.dump(node);
892 //print(JSON.Stringify(target_data, null, 4));
893 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
895 print("add " + tp + "@" + target_data[1] );
898 if (tp && target_data[1] < 2) { // before or after..
899 var ar = target_data[0].split(':');
901 parent = new Gtk.TreePath.from_string( ar.join(':') );
906 var aret = after ? {} : false;
910 if (parent !== false) {
911 this.el.get_iter(pret, parent);
918 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
919 this.el.get_iter(aret, after);
920 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
921 nret, pret.iter, aret.iter);
924 this.el.append(nret, pret.iter);
927 var new_path = this.el.get_path(nret.iter).to_string();
928 print("new path = " + new_path)
929 if (typeof(node) == 'string') {
930 var ar = node.split('.');
931 var xtype = ar.pop();
934 '|xns' : ar.join('.'),
937 if (target_data.length == 3 && target_data[2].length) {
938 node['*prop'] = target_data[2];
940 node = this.get('/DialogTemplateSelect').show(node);
943 // work out what kind of packing to use..
944 if (typeof(node.pack) == 'undefined' && parent !== false) {
945 var pal = this.get('/LeftTree').getPaleteProvider();
946 if (pal.name == 'Gtk') {
947 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
948 var cname = pal.guessName(node);
949 node.pack = pal.getDefaultPack(pname, cname);
960 // load children - if it has any..
963 this.load(xitems, nret.iter);
964 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
966 if (tp && (xitems || after)) {
967 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
969 // wee need to get the empty proptypes from somewhere..
971 //var olditer = this.activeIter;
972 //this.activePath = new_path;
973 print("calling changed with node data")
974 // changed actually set's the node data..
975 this.setFromNode(new_path,node);
980 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
982 //Builder.MidPropTree._model.load(node);
983 //Builder.MidPropTree._win.hideWin();
984 //Builder.LeftPanel._model.load( node);
988 findDropNode : function(treepath_str, targets) {
990 // this is used by the dragdrop code in the roo version AFAIR..
992 var path = treepath_str.replace(/^builder-/, '');
993 // treemap is depreciated... - should really check if model has any entries..
995 if (!this.el.iter_n_children(null)) {
997 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
999 print("FIND treepath: " + path);
1000 //console.dump(this.treemap);
1002 if (!treepath_str.match(/^builder-/)) {
1003 return []; // nothing!
1005 if (targets === true) {
1008 return this.findDropNodeByPath(path,targets)
1010 findDropNodeByPath : function(treepath_str, targets, pref) {
1011 var path = treepath_str + ''; // dupe it..
1012 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1014 //console.dump(this.treemap);
1015 while (path.length) {
1016 print("LOOKING FOR PATH: " + path);
1017 var node_data = this.singleNodeToJS(path);
1018 if (node_data === false) {
1019 print("node not found");
1023 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1026 targets.forEach(function(tg) {
1030 if ((tg == xname) ) {
1033 if (tg.indexOf(xname +':') === 0) {
1035 prop = tg.split(':').pop();
1040 if (last) { // pref is after/before..
1041 // then it's after last
1043 return []; // do not allow..
1045 return [ last, pref , prop];
1048 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1050 var par = path.split(':');
1053 path = par.join(':');
1059 getIterValue : function (iter, col) {
1061 var gval = ''+this.el.get_value(iter, col).value.get_string();
1067 XObject.prototype.init.call(this);
1068 this.el.set_column_types ( 3, [
1069 GObject.TYPE_STRING, // title
1070 GObject.TYPE_STRING, // tip
1071 GObject.TYPE_STRING // source..
1074 listAllTypes : function() {
1075 var s = this.get('/LeftTree.view').selection;
1076 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1078 if (s.count_selected_rows() > 0) {
1080 s.get_selected(ret);
1082 // set some properties of the tree for use by the dropped element.
1083 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1084 var data = JSON.parse(value);
1087 var xname = this.get('/LeftTree.model').file.guessName(data);
1088 console.log('selected:' + xname);
1092 return []; // could not find it..
1101 for (var i =0 ; i < li.length; i++ ) {
1104 // this is specific to roo!!!?
1105 if (!el) { // skip empty?
1108 var fullpath = _this.file.guessName(el);
1109 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1114 if (el.items && el.items.length) {
1123 addall([this.currentTree]);
1125 // only if we have nothing, should we add '*top'
1129 //console.log('all types in tree');
1130 //console.dump(ret);
1135 load : function(tr,iter)
1137 //this.insert(citer,iter,0);
1139 for(var i =0 ; i < tr.length; i++) {
1142 this.el.insert(ret ,iter,-1);
1144 this.el.append(ret);
1146 //print(JSON.stringify(ret,null,4));
1147 //print('call nodeToJSON: ' + tr[i]);
1148 var body = this.nodeToJSON(tr[i]);
1150 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1151 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1152 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1153 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1154 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1155 this.el.set_value(ret.iter, 2, '' + body );
1156 if (tr[i].items && tr[i].items.length) {
1157 this.load(tr[i].items, ret.iter);
1161 loadFile : function(f) {
1168 console.log('missing file');
1172 // load the file if not loaded..
1173 if (f.items === false) {
1175 f.loadItems(function() {
1181 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1183 if (f.items.length && typeof(f.items[0]) == 'string') {
1185 //this.get('/RightEditor').el.show();
1186 //this.get('/RightEditor.view').load( f.items[0]);
1190 //print(JSON.stringify(f.items, null,4));
1191 //console.dump(f.items);
1193 this.get('/LeftTree.view').el.expand_all();
1195 if (!f.items.length) {
1198 this.get('/Window.leftvpaned').el.set_position(80);
1200 this.get('/LeftTree.view').el.set_cursor(
1201 new Gtk.TreePath.from_string('0'), null, false);
1205 this.get('/Window.leftvpaned').el.set_position(200);
1208 //return; -- debuggin
1209 //print("hide right editior");
1210 //this.get('/RightEditor').el.hide();
1211 this.get('/Editor').el.hide();
1212 print("set current tree");
1214 this.currentTree = this.toJS(false, false)[0];
1217 //console.dump(this.currentTree);
1218 this.currentTree = this.currentTree || { items: [] };
1219 this.get('/LeftTree').renderView();
1220 // console.dump(this.map);
1221 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1222 var pm = this.get('/RightPalete.model');
1223 // set up provider..
1225 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1227 if (!this.get('/RightPalete').provider) {
1228 print ("********* PALETE PROVIDER MISSING?!!");
1230 this.get('/LeftTree').renderView();
1232 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1236 this.get('/Window.view-notebook').el.set_current_page(
1237 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1240 moveNode : function(target_data, action) {
1241 //print("MOVE NODE");
1242 // console.dump(target_data);
1244 var s = this.get('/LeftTree.view').selection;
1245 s.get_selected( oret);
1246 var node = this.nodeToJS(oret.iter,false);
1247 //console.dump(node);
1248 print(JSON.stringify(node, null,4));
1250 // needs to drop first, otherwise the target_data
1251 // treepath will be invalid.
1253 this.dropNode(target_data, node);
1254 if (action & Gdk.DragAction.MOVE) {
1255 // print("REMOVING OLD NODE");
1256 this.el.remove(oret.iter);
1260 this.activePath= false;
1263 nodeTip : function(c) {
1264 var ret = this.nodeTitle(c,true);
1270 if (!i.length || i[0] != '|') {
1276 if (typeof(c[i]) != 'string') {
1279 //print("prop : " + i + ':' + c[i]);
1280 if (!c[i].match(new RegExp('function'))) {
1283 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1287 ret+="\n\nMethods:" + funcs;
1292 nodeTitle : function(c, renderfull) {
1295 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1296 if (sr) txt.push('<s>');
1297 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1299 if (renderfull && c['|xns']) {
1300 txt.push(c['|xns']);
1303 if (c.xtype) { txt.push(c.xtype); }
1304 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1305 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1306 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1309 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1310 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1311 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1312 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1313 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1314 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1315 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1316 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1317 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1319 // for flat classes...
1320 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1321 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1324 if (sr) txt.push('</s>');
1325 return (txt.length == 0 ? "Element" : txt.join(" "));
1327 nodeToJS : function (treepath, with_id)
1329 //print("nodeToJS : WITHID: "+ with_id);
1330 var iter = treepath; // API used to be iter here..
1331 if (typeof(iter) == 'string') {
1333 if (!this.el.get_iter(ret,
1334 new Gtk.TreePath.from_string(treepath))) {
1340 var iv = this.getIterValue(iter, 2);
1341 // print("IV" + iv);
1342 var k = JSON.parse(iv);
1343 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1348 var treepath_str = this.el.get_path(iter).to_string();
1349 // not sure how we can handle mixed id stuff..
1350 if (typeof(k.id) == 'undefined') {
1351 k.id = 'builder-'+ treepath_str ;
1355 this.treemap[ treepath_str ] = k;
1356 k.xtreepath = treepath_str ;
1359 if (this.el.iter_has_child(iter)) {
1361 this.el.iter_children(cret, iter);
1362 k.items = this.toJS(cret.iter,with_id);
1366 nodeToJSON : function(c) {
1374 return JSON.stringify(o);
1376 singleNodeToJS : function (treepath)
1379 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1383 var iv = this.getIterValue(ret.iter, 2);
1385 return JSON.parse(iv);
1388 toJS : function(treepath, with_id)
1390 //print("toJS : WITHID: "+ with_id);
1392 var iter = treepath; // API used to be iter here..
1394 if (typeof(iter) == 'string') {
1396 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1408 if (!this.el.get_iter_first(ret)) {
1419 var k = this.nodeToJS(iter, with_id);
1423 if (!this.el.iter_next(iter)) {
1428 if (treepath === false) {
1430 return JSON.parse(JSON.stringify(ar));
1434 // convert the list into a json string..
1440 xtype: Gtk.TreeViewColumn,
1441 pack : "append_column",
1443 XObject.prototype.init.call(this);
1444 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1448 xtype: Gtk.CellRendererText,
1458 id : "LeftTreeMenu",
1461 xtype: Gtk.MenuItem,
1463 label : "Delete Element",
1465 activate : function (self) {
1467 this.get('/LeftTree.model').deleteSelected();
1472 xtype: Gtk.MenuItem,
1474 activate : function (self) {
1476 var tree = this.get('/LeftTree');
1477 var model = this.get('/LeftTree.model');
1478 var el = tree.getActivePath();
1480 var js = model.toJS(el, false);
1481 // print(JSON.stringify(js[0], null,4));
1482 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1487 label : "Save as Template",
1497 id : "LeftProjectTree",
1498 showNoProjectSelected : function() {
1499 this.get('/StandardErrorDialog').show("Select a Project first.");
1501 getActiveProject : function() {
1502 return this.project;
1505 leave_notify_event : function (self, event) {
1512 pack : "pack_start,false,false",
1515 xtype: Gtk.ComboBox,
1517 changed : function (self) {
1518 var fn = this.getValue();
1519 var pm = imports.ProjectManager.ProjectManager;
1520 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1524 getValue : function() {
1525 var ix = this.el.get_active();
1529 var data = imports.ProjectManager.ProjectManager.projects;
1530 if (typeof(data[ix]) == 'undefined') {
1536 XObject.prototype.init.call(this);
1537 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1539 setValue : function(fn)
1543 var data = imports.ProjectManager.ProjectManager.projects;
1544 data.forEach(function(n, ix) {
1553 xtype: Gtk.CellRendererText,
1554 pack : "pack_start,true",
1558 xtype: Gtk.ListStore,
1562 XObject.prototype.init.call(this);
1563 this.el.set_column_types ( 2, [
1564 GObject.TYPE_STRING, // real key
1565 GObject.TYPE_STRING // real type
1569 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1570 var pm = imports.ProjectManager.ProjectManager;
1572 pm.on('changed', function() {
1573 print("caught changed hook on project manager - reloading data");
1574 _this.loadData(pm.projects);
1578 loadData : function(data) {
1579 var ov = this.get('/LeftProjectTree.combo').getValue();
1583 data.forEach(function(p) {
1586 //print(JSON.stringify(XObject.keys(na)));
1587 //print(typeof(na.iter));
1588 //print(JSON.stringify(iter))
1589 el.set_value(na.iter, 0, p.fn);
1590 el.set_value(na.iter, 1, p.name);
1594 this.get('/LeftProjectTree.combo').setValue(ov);
1602 xtype: Gtk.ScrolledWindow,
1604 shadow_type : Gtk.ShadowType.IN,
1606 XObject.prototype.init.call(this);
1607 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
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 XObject.prototype.init.call(this);
1679 this.el.set_column_types ( 3, [
1680 GObject.TYPE_STRING, // title
1681 GObject.TYPE_STRING, // tip
1682 GObject.TYPE_STRING // id..
1686 loadProject : function(pr) {
1687 print("LOAD PROJECT");
1688 var model = this.get('/LeftProjectTree.model');
1689 model.loading = true;
1696 this.get('/LeftProjectTree').project = pr;
1698 this.load(pr.toTree());
1700 this.get('/LeftProjectTree.view').el.expand_all();
1701 model.loading = false;
1704 load : function(tr,iter) {
1705 // console.dump(tr);
1708 console.log('Project tree load: ' + tr.length);
1710 //this.insert(citer,iter,0);
1714 tr.forEach(function (r) {
1716 _this.el.append(cret);
1718 _this.el.insert(cret,iter,-1);
1720 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1721 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1722 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1723 if (r.cn && r.cn.length) {
1724 _this.load(r.cn, cret.iter);
1730 getValue : function(iter, col) {
1731 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1736 xtype: Gtk.TreeViewColumn,
1737 pack : "append_column",
1739 XObject.prototype.init.call(this);
1740 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1744 xtype: Gtk.CellRendererText,
1764 pack : "pack_start,false,true,0",
1771 button_press_event : function (self, event) {
1772 this.get('/MidPropTree.model').showData('props');
1784 stock : Gtk.STOCK_ADD,
1785 icon_size : Gtk.IconSize.MENU
1799 button_press_event : function (self, event) {
1801 if (!this.get('/Editor').save()) {
1802 // popup!! - click handled..
1805 this.get('/MidPropTree.model').showData('events');
1818 stock : Gtk.STOCK_ADD,
1819 icon_size : Gtk.IconSize.MENU
1833 button_press_event : function (self, ev) {
1835 if (!this.get('/Editor').save()) {
1836 // popup!! - click handled..
1840 var p = this.get('/AddPropertyPopup');
1844 p.el.set_screen(Gdk.Screen.get_default());
1846 p.el.popup(null, null, null, null, 3, ev.button.time);
1859 stock : Gtk.STOCK_ADD,
1860 icon_size : Gtk.IconSize.MENU
1872 id : "AddPropertyPopup",
1875 xtype: Gtk.MenuItem,
1877 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1880 activate : function (self) {
1882 this.get('/LeftPanel.model').add( {
1893 xtype: Gtk.MenuItem,
1895 tooltip_markup : "Add what type of packing is to be used",
1898 activate : function (self) {
1900 this.get('/LeftPanel.model').add( {
1910 xtype: Gtk.MenuItem,
1912 tooltip_markup : "Override the init method",
1915 activate : function (self) {
1917 this.get('/LeftPanel.model').add( {
1920 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1927 xtype: Gtk.SeparatorMenuItem,
1931 xtype: Gtk.MenuItem,
1933 tooltip_markup : "Add a user defined string property",
1936 activate : function (self) {
1938 this.get('/LeftPanel.model').add( {
1948 xtype: Gtk.MenuItem,
1950 tooltip_markup : "Add a user defined number property",
1953 activate : function (self) {
1955 this.get('/LeftPanel.model').add( {
1965 xtype: Gtk.MenuItem,
1967 tooltip_markup : "Add a user defined boolean property",
1970 activate : function (self) {
1972 this.get('/LeftPanel.model').add( {
1982 xtype: Gtk.SeparatorMenuItem,
1986 xtype: Gtk.MenuItem,
1988 tooltip_markup : "Add a user function boolean property",
1991 activate : function (self) {
1993 this.get('/LeftPanel.model').add( {
1996 val : "function() {\n \n}\n",
2009 xtype: Gtk.ScrolledWindow,
2014 XObject.prototype.init.call(this);
2015 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2017 shadow_type : Gtk.ShadowType.IN,
2020 xtype: Gtk.TreeView,
2022 button_press_event : function (self, ev) {
2025 if (!this.get('/Editor').save()) {
2026 // popup!! - click handled..
2031 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2032 return false; //not on a element.
2036 if (ev.button.button == 3) {
2038 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2041 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2042 var p = this.get('/LeftPanelPopup');
2047 p.el.set_screen(Gdk.Screen.get_default());
2049 p.el.popup(null, null, null, null, 3, ev.button.time);
2050 //Seed.print("click:" + res.column.title);
2057 if (res.column.title != 'value') {
2058 // XObject.error("column is not value?");
2059 return false; // ignore.. - key click.. ??? should we do this??
2062 // currently editing???
2063 // if ( this.activePath) {
2065 // this.activePath = false;
2067 if (this.get('/Editor').dirty) {
2068 //if (!this.get('/Editor.buffer').checkSyntax()) {
2069 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2073 if (!this.get('/Editor.view').save()) {
2077 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2078 this.get('/LeftPanel').editing = false;
2080 // XObject.error("Currently editing?");
2084 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2086 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2088 // get options for this type -- this is to support option lists etc..
2089 var provider = this.get('/LeftTree').getPaleteProvider();
2090 var opts = provider.findOptions(type);
2092 if (opts === false) {
2094 this.get('/LeftPanel').editableColumn.setOptions([]);
2095 renderer.has_entry = true;
2097 this.get('/LeftPanel').editableColumn.setOptions(opts);
2098 renderer.has_entry = false;
2100 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2102 //Seed.print("click" + ev.type);
2103 //console.dump(res);
2112 enable_tree_lines : true,
2113 headers_visible : false,
2115 XObject.prototype.init.call(this);
2117 this.selection = this.el.get_selection();
2118 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2121 var description = new Pango.FontDescription.c_new();
2122 description.set_size(8000);
2123 this.el.modify_font(description);
2127 xtype: Gtk.TreeStore,
2131 add : function(info) {
2132 // info includes key, val, skel, etype..
2134 type = info.type.toLowerCase();
2135 var data = this.toJS();
2137 if (info.etype == 'events') {
2138 data.listeners = data.listeners || { };
2139 if (typeof(data.listeners[info.key]) != 'undefined') {
2140 return; //already set!
2143 if (typeof(data[info.key]) != 'undefined') {
2148 if (typeof(info.val) == 'undefined') {
2151 if (info.type.toLowerCase() == 'boolean') {
2154 if (type == 'number') {
2162 if (info.etype == 'events') {
2164 data.listeners[info.key] = info.val;
2167 data[info.key] = info.val;
2171 var map = this.load(data);
2173 // flag it as changed to the interface..
2174 this.get('/LeftTree.model').setFromNode(false,node);
2175 this.get('/LeftTree.model').changed(true);
2178 this.startEditing(map[k]);
2181 LeftPanel.get('view').el.row_activated(
2182 new Gtk.TreePath.from_string(map[k]),
2183 LeftPanel.editableColumn.el
2187 changed : function(str, doRefresh) {
2188 if (!this.activePath) {
2189 print("NO active path when changed")
2193 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2195 this.el.set_value(ret.iter, 1, '' +str);
2196 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2197 var type = this.getIterValue(ret.iter, 4);
2199 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2200 // update the tree...
2201 print("new data: " + JSON.stringify(this.toJS() , null,4));
2202 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2203 this.get('/LeftTree.model').changed(doRefresh);
2206 deleteSelected : function() {
2207 var data = this.toJS();
2209 var s = this.get('/LeftPanel.view').selection;
2210 s.get_selected( ret);
2213 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2215 if (val[0] == '!') {
2217 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2220 delete data.listeners[ val.substring(1)];
2221 if (!XObject.keys(data.listeners).length) {
2222 delete data.listeners;
2226 if (typeof(data[val]) == 'undefined') {
2236 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2237 this.get('/LeftTree.model').changed(true);
2241 getIterValue : function(iter, col) {
2242 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2245 getType : function(treepath) {
2246 return this.getValue(treepath, 4);
2248 getValue : function(treepath_str, col)
2250 // get's the value in a row.. - keys - returns string, values - formats it..
2252 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2254 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2259 var type = this.getType(this.el.get_path(ret.iter).to_string());
2260 //print("TYPE: " +type + " - val:" + val);
2261 switch(type.toLowerCase()) {
2265 return parseFloat(val); // Nan ?? invalid!!?
2268 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2270 return val == 'true' ? true : false;
2272 var nv = parseFloat(val);
2273 if (!isNaN(nv) && (val == ''+nv)) {
2281 XObject.prototype.init.call(this);
2282 this.el.set_column_types ( 6, [
2283 GObject.TYPE_STRING, // 0 real key
2284 GObject.TYPE_STRING, // 1 real value
2285 GObject.TYPE_STRING, // 2 visable key
2286 GObject.TYPE_STRING, // 3 visable value
2287 GObject.TYPE_STRING, // 4 need to store type of!!!
2288 GObject.TYPE_STRING // 5 tooltip
2292 load : function(ar) {
2293 // might casue problesm..
2294 // this.get('/Editor.RightEditor').save();
2296 this.get('/Editor').el.hide();
2297 this.get('/Editor').activePath = false;
2302 //this.get('/RightEditor').el.hide();
2309 var provider = this.get('/LeftTree').getPaleteProvider();
2313 var keys = XObject.keys(ar);
2315 ar.listeners = ar.listeners || {};
2317 for (var i in ar.listeners ) {
2319 this.el.append(iret);
2320 var p = this.el.get_path(iret.iter).to_string();
2323 this.el.set_value(iret.iter, 0, '!'+ i );
2324 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2325 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2327 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2328 this.el.set_value(iret.iter, 4, 'function');
2329 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2335 keys.forEach(function(i) {
2336 if (typeof(ar[i]) == 'object') {
2340 var type = provider.findType(ar, i, ar[i]);
2342 _this.el.append(iret);
2343 var p = _this.el.get_path(iret.iter).to_string();
2345 _this.el.set_value(iret.iter, 0, ''+i);
2346 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2347 _this.el.set_value(iret.iter, 2, ''+i);
2348 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2349 _this.el.set_value(iret.iter, 4, ''+type);
2350 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2354 startEditing : function(path,col) {
2356 // alled by menu 'edit' currently..
2358 * start editing path (or selected if not set..)
2359 * @param {String|false} path (optional) treepath to edit - selected tree gets
2360 * edited by default.
2361 * @param {Number} 0 or 1 (optional)- column to edit.
2363 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2365 if (typeof(path) == 'string') {
2366 tp = new Gtk.TreePath.from_string(path);
2369 var s = this.get('/LeftPanel.view').selection;
2370 s.get_selected( itr);
2371 tp = this.el.get_path(itr.iter);
2372 path = tp.to_string();
2376 // which colum is to be edited..
2379 // not sure what this does..
2381 if (typeof(col) == 'undefined') {
2382 var k = this.getValue(path, 0);
2384 colObj = (!k.length || k == '|') ?
2385 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2387 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2390 // make sure the pulldown is set correctly..
2391 // not really needed for second col...
2392 var showEditor = false;
2393 this.get('/Editor').activePath = false;
2394 this.get('/Editor').el.hide();
2397 var provider = this.get('/LeftTree').getPaleteProvider();
2398 var type = this.get('/LeftPanel.model').getType(path);
2399 var opts = provider.findOptions(type);
2400 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2402 if (opts === false) {
2403 this.get('/LeftPanel').editableColumn.setOptions([]);
2404 renderer.has_entry = true;
2406 this.get('/LeftPanel').editableColumn.setOptions(opts);
2407 renderer.has_entry = false;/// - pulldowns do not have entries
2409 // determine if we should use the Text editor...
2410 var keyname = this.getValue(path, 0);
2411 var data_value = this.getValue(path, 1);
2413 if ((keyname[0] == '|') ||
2415 (typeof(data_value) == 'string' ) &&
2416 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2420 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2425 // this.get('/BottomPane').el.hide();
2426 //this.get('/RightEditor').el.hide();
2431 this.activePath = false;
2433 _this.get('/Editor').el.show_all();
2434 GLib.timeout_add(0, 1, function() {
2436 //_this.get('/BottomPane').el.show();
2437 //_this.get('/RightEditor').el.show();
2439 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2441 _this.get('/Editor').activePath = path;
2442 _this.activePath = path ;
2452 // iter now has row...
2453 GLib.timeout_add(0, 100, function() {
2454 _this.activePath = path;
2455 colObj.items[0].el.editable = true; // esp. need for col 0..
2456 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2467 this.get('/LeftPanel.model').el.get_iter_first(iret);
2473 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2476 ar.listeners = ar.listeners || {};
2477 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2480 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2483 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2489 //print(JSON.stringify(ar));
2493 toShort : function(str) {
2494 var a = typeof(str) == 'string' ? str.split("\n") : [];
2495 return a.length > 1 ? a[0] + '....' : '' + str;
2499 xtype: Gtk.TreeViewColumn,
2500 pack : "append_column",
2502 XObject.prototype.init.call(this);
2504 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2505 this.get('/LeftPanel').propertyColumn = this;
2510 xtype: Gtk.CellRendererText,
2511 pack : "pack_start",
2513 editing_started : function (self, editable, path) {
2515 this.get('/LeftPanel.model').activePath = path;
2518 edited : function (self, object, p0) {
2520 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2522 var model = this.get('/LeftPanel.model');
2523 var path = model.activePath;
2525 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2526 model.el.set_value(iret.iter, 0, p0);
2527 model.el.set_value(iret.iter, 2, p0);
2529 model.activePath = false;
2530 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2531 this.get('/LeftTree.model').changed(true);
2533 this.el.editable = false;
2540 xtype: Gtk.TreeViewColumn,
2541 pack : "append_column",
2544 XObject.prototype.init.call(this);
2545 this.el.add_attribute(this.items[0].el , 'text', 3 );
2546 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2547 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2548 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2550 this.get('/LeftPanel').editableColumn= this;
2552 setOptions : function(ar) {
2553 var m = this.items[0].el.model;
2556 ar.forEach(function(i) {
2560 m.set_value(iret.iter, 0, i);
2566 xtype: Gtk.CellRendererCombo,
2568 edited : function (self, object, p0) {
2570 this.get('/LeftPanel').editing = false;
2571 var ap = this.get('/LeftPanel.model').activePath
2572 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2573 this.get('/LeftPanel.model').changed(p0, true);
2574 this.get('/LeftPanel.model').activePath = false;
2575 this.el.editable = false;
2577 editing_started : function (self, editable, path) {
2578 this.get('/LeftPanel').editing = true;
2579 // console.log('editing started');
2580 // r.has_entry = false;
2582 this.el.editable = false; // make sure it's not editor...
2587 pack : "pack_start",
2591 XObject.prototype.init.call(this);
2592 this.el.model = new Gtk.ListStore();
2593 this.el.model.set_column_types ( 1, [
2594 GObject.TYPE_STRING // 0 real key
2605 id : "LeftPanelPopup",
2608 xtype: Gtk.MenuItem,
2612 activate : function (self) {
2613 this.get('/LeftPanel.model').deleteSelected();
2618 xtype: Gtk.MenuItem,
2622 activate : function (self) {
2623 this.get('/LeftPanel.model').startEditing(false, 0);
2636 xtype: Gtk.ScrolledWindow,
2637 pack : "pack_end,false,true,0",
2640 shadow_type : Gtk.ShadowType.IN,
2642 XObject.prototype.init.call(this);
2643 XObject.prototype.init.call(this);
2644 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2645 this.el.set_size_request ( 150, -1 );
2648 activeElement : false,
2649 hideWin : function() {
2652 print("HIDEWIN - currently not shown")
2657 if (this.get('/Window.left').el.position < 160) {
2658 print("HIDEWIN - small already.")
2662 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2663 print("HIDEWIN attempting to hide.")
2670 xtype: Gtk.TreeView,
2672 cursor_changed : function (self) {
2673 // this is getting fired when we are loading elements..
2674 if (this.get('/MidPropTree.model').loading) {
2680 //console.log('changed');
2681 var m = this.get('model');
2682 if (!this.selection){
2683 this.selection = this.el.get_selection();
2686 var s = this.selection;
2687 if (!s.get_selected(iret)) {
2690 var tp = m.el.get_path(iret.iter).to_string();
2695 var key = m.getValue(tp, 0);
2697 var type = m.getValue(tp, 1);
2698 var skel = m.getValue(tp, 3);
2699 var etype = m.getValue(tp, 5);
2702 this.get('/MidPropTree').hideWin();
2704 if (type.toLowerCase() == 'function') {
2706 if (etype != 'events') {
2709 print("cursor_changed: ADDding to left panel model");
2710 this.get('/LeftPanel.model').add({
2718 // has dot in name, and is boolean???? this does not make sense..
2719 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2722 print("cursor_changed: ADDding to left panel model");
2723 this.get('/LeftPanel.model').add( {
2733 enable_tree_lines : true,
2734 headers_visible : false,
2736 XObject.prototype.init.call(this);
2738 var description = new Pango.FontDescription.c_new();
2739 description.set_size(8000);
2740 this.el.modify_font(description);
2742 //this.selection = this.el.get_selection();
2743 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2752 xtype: Gtk.ListStore,
2756 getValue : function(treepath, col)
2758 var tp = new Gtk.TreePath.from_string (treepath);
2760 this.el.get_iter (iret, tp);
2761 var value = this.el.get_value(iret.iter, col);
2762 return ''+ value.value.get_string();
2766 XObject.prototype.init.call(this);
2767 this.el.set_column_types ( 6, [
2768 GObject.TYPE_STRING, // real key
2769 GObject.TYPE_STRING, // real type
2770 GObject.TYPE_STRING, // docs ?
2771 GObject.TYPE_STRING, // visable desc
2772 GObject.TYPE_STRING, // function desc
2773 GObject.TYPE_STRING // element type (event|prop)
2777 showData : function(type) {
2780 this.loading = true;
2782 if (!this.get('/MidPropTree').activeElement || !type) {
2783 this.loading = false;
2784 return; // no active element
2787 var fullpath = this.get('/LeftTree.model').file.guessName(
2788 this.get('/MidPropTree').activeElement);
2789 var palete = this.get('/LeftTree').getPaleteProvider();
2793 Seed.print('Showing right?');
2794 if (!this.get('/MidPropTree').shown) {
2796 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2797 this.get('/MidPropTree').el.show();
2798 this.get('/MidPropTree').shown = true;
2801 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2802 return a.name > b.name ? 1 : -1;
2804 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2805 // console.dump(elementList);
2807 // scope of this is off..??
2810 for(var i =0 ; i < elementList.length; i++) {
2812 var p=elementList[i];
2813 this.el.append(iret);
2814 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2815 //GObject.TYPE_STRING, // real key
2816 // GObject.TYPE_STRING, // real type
2817 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2818 // GObject.TYPE_STRING // func def?
2821 this.el.set_value(iret.iter, 0, p.name);
2822 this.el.set_value(iret.iter, 1, p.type);
2823 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2824 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2825 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2826 this.el.set_value(iret.iter, 5, type);
2829 this.loading = false;
2833 xtype: Gtk.TreeViewColumn,
2836 this.el = new Gtk.TreeViewColumn();
2837 this.parent.el.append_column(this.el);
2839 XObject.prototype.init.call(this);
2840 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2844 xtype: Gtk.CellRendererText,
2845 pack : "pack_start,true"
2872 xtype: Gtk.Notebook,
2873 pack : "pack_start,true,true",
2874 id : "view-help-nb",
2876 XObject.prototype.init.call(this);
2877 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2878 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2882 xtype: Gtk.Notebook,
2883 id : "view-notebook",
2887 XObject.prototype.init.call(this);
2888 this.el.set_current_page(0);
2889 //print("SET LABEL?")
2890 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2891 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2897 id : "RightBrowser",
2902 pack : "pack_start,false,true,0",
2907 clicked : function (self) {
2908 this.get('/RightBrowser.view').renderJS(null,true);
2912 pack : "pack_start,false,false,0"
2915 xtype: Gtk.CheckButton,
2917 toggled : function (self, state) {
2918 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2923 label : "Auto Redraw On",
2924 pack : "pack_start,false,false,0"
2929 clicked : function (self) {
2931 var view = this.get('/RightBrowser.view');
2932 //this.get('/RightBrowser.view').redraws = 99;
2933 view.refreshRequired = true;
2934 view.lastRedraw = false;
2935 view.renderedData = false;
2936 view.renderJS(null,true);
2940 label : "Full Redraw",
2941 pack : "pack_start,false,false,0"
2946 xtype: Gtk.ScrolledWindow,
2949 XObject.prototype.init.call(this);
2950 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2952 shadow_type : Gtk.ShadowType.IN,
2955 xtype: WebKit.WebView,
2957 load_finished : function (self, object) {
2958 print("load finished");
2959 // print("load_finished"); return;
2960 // if (this.ready) { // dont do it twice!
2963 if (!this.inspectorShown) {
2964 this.el.get_inspector().show();
2965 this.inspectorShown = true;
2970 //if (this.pendingRedraw) {
2971 // this.pendingRedraw = false;
2972 // this.refreshRequired = true;
2974 //var js = this.get('/LeftTree.model').toJS();
2975 //if (js && js[0]) {
2976 // this.renderJS(js[0]);
2980 script_alert : function (self, object, p0) {
2983 return true; // do not display anything...
2985 console_message : function (self, object, p0, p1) {
2987 // console.log(object);
2990 if (object.match(/variable/) && object.match(/Builder/)) {
2991 print("got builder missing message");
2992 this.refreshRequired = true;
2993 this.lastRedraw = 0;
2999 if (!object.match(/^\{/)) {
3001 //this.get('/Terminal').feed(object);
3002 return true; // do not handle!!! -> later maybe in console..
3008 // console.log(object);
3009 var val = JSON.parse(object);
3011 if (typeof(val['hover-node']) != 'undefined') {
3012 this.activeNode = val['hover-node'];
3013 console.log('active node: ' + this.activeNode);
3018 if (typeof(val['id']) != 'undefined') {
3019 // this.activeNode = val['id'];
3020 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
3021 if (!tg || typeof(tg[0]) == 'undefined') {
3024 print("SELECT node " + tg[0]);
3026 this.get('/LeftTree.view').selectNode(tg[0]);
3031 if (ret && typeof(val['set']) != 'undefined') {
3032 print("console messages: ADDding to left panel model");
3034 //this.get('/LeftPanel.model').add({
3035 // key : val['set'],
3036 // val : val['value']
3038 //console.log('active node: ' + this.activeNode);
3041 //Seed.print('a:'+a);
3042 //Seed.print('b:'+b);
3043 //Seed.print('c:'+c);
3046 drag_motion : function (w, ctx, x, y, time, ud) {
3047 // console.log('DRAG MOTION');
3049 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3050 this.targetData = [];
3051 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3053 // A) find out from drag all the places that node could be dropped.
3054 var src = Gtk.drag_get_source_widget(ctx);
3055 if (!src.dropList) {
3056 Gdk.drag_status(ctx,0, time);
3059 // b) get what we are over.. (from activeNode)
3060 // tree is empty.. - list should be correct..
3061 if (!this.get('/LeftTree.model').currentTree) {
3062 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3066 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3068 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3071 Gdk.drag_status(ctx, 0,time);
3072 this.get('/LeftTree.view').highlight(false);
3076 // if we have a target..
3077 // -> highlight it! (in browser)
3078 // -> highlight it! (in tree)
3080 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3081 this.get('/LeftTree.view').highlight(tg);
3082 this.targetData = tg;
3083 // for tree we should handle this...
3086 drag_drop : function (w, ctx, x, y,time, ud) {
3087 print("TARGET: drag-drop");
3088 var is_valid_drop_site = true;
3092 ( /* will receive 'drag-data-received' signal */
3093 ctx, /* represents the current state of the DnD */
3094 imports.Builder3.Main.atoms["STRING"], /* the target type we want */
3095 time /* time stamp */
3099 /* No target offered by source => error */
3102 return is_valid_drop_site;
3104 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3106 print("Browser: drag-data-received");
3107 var delete_selection_data = false;
3108 vardnd_success = false;
3109 /* Deal with what we are given from source */
3110 if( sel_data && sel_data.length ) {
3112 if (ctx.action == Gdk.DragAction.ASK) {
3113 /* Ask the user to move or copy, then set the ctx action. */
3116 if (ctx.action == Gdk.DragAction.MOVE) {
3117 delete_selection_data = true;
3119 var source = Gtk.drag_get_source_widget(ctx);
3121 print("Browser: source.DRAGDATA? " + source.dragData);
3122 if (this.targetData) {
3123 print(this.targetData);
3124 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3133 if (dnd_success == false)
3135 Seed.print ("DnD data transfer failed!\n");
3138 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3141 create_web_view : function (self, object) {
3142 print("CREATE WEB VIEW");
3143 return null; //new WebKit.WebView();
3150 XObject.prototype.init.call(this);
3151 // this may not work!?
3152 var settings = this.el.get_settings();
3153 settings.enable_developer_extras = true;
3155 // this was an attempt to change the url perms.. did not work..
3156 // settings.enable_file_access_from_file_uris = true;
3157 // settings.enable_offline_web_application_cache - true;
3158 // settings.enable_universal_access_from_file_uris = true;
3162 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3163 _this.get('/BottomPane.inspector').el.show();
3164 return _this.get('/BottomPane.inspector').el;
3168 // FIXME - base url of script..
3169 // we need it so some of the database features work.
3170 this.el.load_html_string( "Render not ready" ,
3171 //fixme - should be a config option!
3172 // or should we catch stuff and fix it up..
3173 'http://localhost/app.Builder/'
3177 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3179 this.el.drag_dest_set
3180 ( /* widget that will accept a drop */
3181 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3182 null, /* lists of target to support */
3183 0, /* size of list */
3184 Gdk.DragAction.COPY /* what to do with data after dropped */
3187 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3188 this.el.drag_dest_set_target_list( imports.Builder3.Main.targetList);
3190 GLib.timeout_add_seconds(0, 1, function() {
3191 // print("run refresh?");
3198 renderJS : function(data, force) {
3200 // this is the public redraw call..
3201 // we refresh in a loop privately..
3202 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3203 if (!autodraw && !force) {
3204 print("Skipping redraw - no force, and autodraw off");
3207 this.refreshRequired = true;
3209 runRefresh : function()
3211 // this is run every 2 seconds from the init..
3215 if (!this.refreshRequired) {
3216 // print("no refresh required");
3220 if (this.lastRedraw) {
3221 // do not redraw if last redraw was less that 5 seconds ago.
3222 if (((new Date()) - this.lastRedraw) < 5000) {
3230 if (!this.get('/Window.LeftTree').getActiveFile()) {
3233 this.refreshRequired = false;
3234 // print("HTML RENDERING");
3236 this.get('/BottomPane').el.show();
3237 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3244 var js = this.get('/LeftTree.model').toJS();
3245 if (!js || !js.length) {
3254 var project = this.get('/Window.LeftTree').getActiveFile().project;
3255 //print (project.fn);
3256 // set it to non-empty.
3257 project.runhtml = project.runhtml || '';
3258 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3261 this.runhtml = this.runhtml || '';
3263 var file = this.get('/LeftTree.model').file;
3264 var items = file.items;
3265 file.items = this.get('/LeftTree.model').toJS(false, false);
3266 //file.items[0].background = false;
3267 //var p = file.parent;
3268 //file.parent = false;
3270 var js_src = file.toSourcePreview();
3271 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3272 // unless it' sforced..
3277 this.renderedData = js_src;
3280 //file.items = items;
3281 //print("send source as " + js_src);
3284 "Roo.onReady(function() {\n" +
3285 "if (" + file.name +".show) " + file.name +".show({});\n" +
3286 "Roo.XComponent.build();\n" +
3293 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3294 // then we need to reload the browser using
3295 // load_html_string..
3297 // then trigger a redraw once it's loaded..
3298 this.pendingRedraw = true;
3299 var runhtml = '<script type="text/javascript">' + "\n" ;
3300 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3301 runhtml += '</script>'+ "\n" ;
3303 this.runhtml = project.runhtml;
3304 // need to modify paths
3307 this.lastRedraw= new Date();
3308 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3309 html = html.replace('</head>',
3312 '<script type="text/javascript">' + "\n" +
3317 //print("LOAD HTML " + html);
3318 this.el.load_html_string( html ,
3319 //fixme - should be a config option!
3320 'http://localhost/app.Builder/'
3323 // should trigger load_finished! - which in truns shoudl set refresh Required;
3328 //this.renderedData = data;
3329 //var str = JSON.stringify(data) ;
3332 console.log('not loaded yet');
3334 this.lastRedraw = new Date();
3336 this.el.execute_script("Builder.render(" +
3337 JSON.stringify(js_src) +
3339 JSON.stringify(file.name) +
3342 print( "before render" + this.lastRedraw);
3343 print( "after render" + (new Date()));
3353 id : "RightGtkView",
3355 redraw : function() {
3356 this.highlightWidget = false;
3357 print("REDRAW CALLED");
3358 this.activePath = this.get('/LeftTree').getActivePath();
3359 if (this.renderedEl) {
3360 print("QUEUE DRAW CALLING");
3361 this.renderedEl.queue_draw();
3364 renderJS : function(data, withDebug)
3366 this.highlightWidget = false;
3368 this.withDebug = false;
3369 while (this.get('view').el.get_children().length) {
3370 var c = this.get('view').el.get_children()[0];
3371 this.get('view').el.remove(c);
3378 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3379 // in theory tree is actually window..
3382 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3388 this.get('view').el.set_size_request(
3389 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3391 if (this.renderedEl) {
3392 this.renderedEl.set_size_request(
3393 tree.default_width || 600,
3394 tree.default_height || 400
3397 this.get('view').el.show_all();
3402 showInWindow : function() {
3403 print("GET PROEJCT");
3404 var pr = this.get('/LeftProjectTree').getActiveProject();
3406 console.log(pr.paths);
3409 var src= this.buildJS(
3410 this.get('/LeftTree.model').toJS()[0],
3415 //var x = new imports.sandbox.Context();
3419 Seed.check_syntax('var e = ' + src);
3422 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3423 this.get('/Terminal').feed(console._dump(e)+"\n");
3425 var lines = src.split("\n");
3426 var start = Math.max(0, e.line - 10);
3427 var end = Math.min(lines.length, e.line + 10);
3428 for (var i =start ; i < end; i++) {
3430 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3433 this.get('/Terminal').feed(lines[i] + "\n");
3440 this.get('/BottomPane').el.set_current_page(1);
3441 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3442 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3443 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3445 var _top = x.get_global_object()._top;
3447 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3449 if (_top.el.popup) {
3450 _top.el.popup(null, null, null, null, 3, null);
3454 viewAdd : function(item, par)
3457 // does something similar to xobject..
3458 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3460 // pack is forced to 'false'
3461 if (item.pack===false || item.pack === 'false') { // no ;
3465 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3468 var type = item['|xns'] + '.' + item['xtype'];
3470 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3474 var ns = imports.gi[item['|xns']];
3475 var ctr = ns[item['xtype']]; // why are we using array here..?
3480 for(var k in item) {
3482 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3496 // value is a function..
3497 if (k[0] == '|' && typeof(kv) == 'string') {
3499 if (kv.match(new RegExp('function'))) {
3502 print("WASL " + k + '=' + kv);
3504 eval( 'kv = ' + kv);
3505 } catch(e) { continue; }
3508 // print(k + '=' + kv);
3510 if (k[0] == '|') { // should be boolean or number..
3512 //print(k + '=' + kv);
3515 if (k == 'show_tabs') { // force tab showing for notebooks.
3518 print(k + '=' + typeof(kv) + " : " + kv);
3522 var altctr = XObject.baseXObject({ xtype: ctr} );
3524 if (!item.pack && altctr) {
3526 print("SETTING PACK TO XObjectBase method");
3527 pack_m = altctr.prototype.pack;
3532 var el = new ctr(ctr_args);
3534 print("PACK" + item.pack);
3535 //console.dump(item.pack);
3542 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3543 if (typeof(item.pack) == 'string') {
3545 item.pack.split(',').forEach(function(e, i) {
3547 if (e == 'false') { args.push( false); return; }
3548 if (e == 'true') { args.push( true); return; }
3549 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3552 //print(args.join(","));
3554 pack_m = args.shift();
3556 pack_m = item.pack.shift();
3561 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3563 name: "ArgumentError",
3564 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3565 "ADDING : " + item.id + " " + el
3572 //console.dump(args);
3574 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3575 //Seed.print('args: ' + args.length);
3576 if (typeof(pack_m) == 'string') {
3577 par[pack_m].apply(par, args);
3578 } else if (pack_m) {
3579 pack_m.call(item, par, item);
3583 item.items = item.items || [];
3584 item.items.forEach(function(ch,n) {
3586 print ("type:" + type);
3588 print ("ch.pack:" + ch.pack);
3591 if (type == 'Gtk.Table' && ch.pack == 'add') {
3592 var c = n % item.n_columns;
3593 var r = Math.floor(n/item.n_columns);
3594 ch.pack = [ 'attach', c, c+1, r, r+1,
3595 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3596 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3597 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3598 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3602 _this.viewAdd(ch, el);
3607 // add the signal handlers.
3608 // is it a widget!?!!?
3614 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3615 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3616 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3617 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3618 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3628 widgetDragDropEvent : function() {
3629 print("WIDGET DRAGDROP");
3632 widgetDragMotionEvent : function() {
3633 print("WIDGET DRAGMOTION");
3636 widgetExposeEvent : function(w, evt, ud, item) {
3638 if (this.inRender) {
3642 if ( this.highlightWidget) {
3643 this.inRender = true;
3644 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3645 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3647 this.inRender = false;
3652 if (this.activePath != item.xtreepath) {
3656 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3657 // work out the coords of the window..
3659 var dr = widget.window;
3660 this.gc = (new Gdk.GC.c_new(dr));
3661 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3662 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3666 var r = evt.expose.area;
3667 // console.dump([r.x, r.y, r.width, r.height ] );
3669 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3670 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3671 // happens with gtkscrollview embedded stuff..
3672 var np =this.activePath.split(':');
3674 this.activePath = np.join(':');
3675 this.renderedEl.queue_draw();
3691 this.inRender = true;
3694 this.highlightWidget = widget;
3699 // print("DRAW BOX");
3700 //console.dump(this.box);
3701 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3702 this.inRender = false;
3705 widgetPressEvent : function(w,e,u,d) {
3706 if (this.get('view').pressed) {
3709 this.get('view').pressed = true;
3710 print("WIDGET PRESS " + d.xtreepath );
3711 this.get('/LeftTree.view').selectNode( d.xtreepath );
3714 widgetReleaseEvent : function() {
3715 this.get('view').pressed = false;
3721 pack : "pack_start,false,true,0",
3725 pack : "pack_start,false,false,0",
3726 label : "Run The Application",
3728 button_press_event : function (self, event) {
3729 // call render on left tree - with special option!?!
3731 //print("GET PROEJCT");
3732 var pr = this.get('/LeftProjectTree').getActiveProject();
3735 for (var i in pr.paths) {
3739 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3740 this.get('/Terminal').feed("RUN DIR:" + dir);
3743 this.get('/Terminal').el.fork_command_full(
3744 Vte.PtyFlags.DEFAULT,
3745 GLib.path_get_dirname (__script_path__) ,
3746 [ 'echo' , "hello"], //argv
3750 null, // child setupdata
3754 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3755 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3765 xtype: Gtk.ScrolledWindow,
3768 shadow_type : Gtk.ShadowType.IN,
3770 XObject.prototype.init.call(this);
3771 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3775 xtype: Gtk.EventBox,
3776 pack : "add_with_viewport",
3778 XObject.prototype.init.call(this);
3779 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3780 red: 0x9F00, green: 0xB800 , blue : 0xA800
3788 XObject.prototype.init.call(this);
3789 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3790 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3795 xtype: Gtk.EventBox,
3798 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3799 XObject.prototype.init.call(this);
3801 this.el.drag_dest_set
3802 ( /* widget that will accept a drop */
3803 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3804 null, /* lists of target to support */
3805 0, /* size of list */
3806 Gdk.DragAction.COPY /* what to do with data after dropped */
3809 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3810 this.el.drag_dest_set_target_list( imports.Builder3.Main.targetList);
3813 getActiveNode : function(x,y)
3815 // workout what node is here..
3816 return '0'; // top..
3820 drag_motion : function (self, ctx, x, y, time) {
3822 // A) find out from drag all the places that node could be dropped.
3823 var src = Gtk.drag_get_source_widget(ctx);
3824 if (!src.dropList) {
3825 Gdk.drag_status(ctx, 0, time);
3828 // b) get what we are over.. (from activeNode)
3829 // tree is empty.. - list should be correct..
3830 if (!this.get('/LeftTree.model').currentTree) {
3831 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3835 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3836 var activeNode = this.getActiveNode(x, y);
3839 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3842 Gdk.drag_status(ctx, 0,time);
3843 this.get('/LeftTree.view').highlight(false);
3847 // if we have a target..
3848 // -> highlight it! (in browser)
3849 // -> highlight it! (in tree)
3851 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3852 this.get('/LeftTree.view').highlight(tg);
3853 this.targetData = tg;
3854 // for tree we should handle this...
3857 drag_drop : function (self,ctx, x, y, time) {
3858 Seed.print("TARGET: drag-drop");
3859 var is_valid_drop_site = true;
3863 ( /* will receive 'drag-data-received' signal */
3864 ctx, /* represents the current state of the this.gDnD */
3865 imports.Builder3.Main.atoms["STRING"], /* the target type we want */
3866 time /* time stamp */
3870 /* No target offered by source => error */
3873 return is_valid_drop_site;
3876 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3878 Seed.print("GtkView: drag-data-received");
3879 var delete_selection_data = false;
3880 var dnd_success = false;
3881 /* Deal with what we are given from source */
3882 if( sel_data && sel_data.length ) {
3884 if (ctx.action == Gdk.DragAction.ASK) {
3885 /* Ask the user to move or copy, then set the ctx action. */
3888 if (ctx.action == Gdk.DragAction.MOVE) {
3889 delete_selection_data = true;
3891 var source = Gtk.drag_get_source_widget( ctx );
3893 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3894 if (this.targetData) {
3895 Seed.print(this.targetData);
3896 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3905 if (dnd_success == false)
3907 Seed.print ("DnD data transfer failed!\n");
3910 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3913 button_press_event : function (self, event) {
3914 this.pressed = false;
3930 xtype: Gtk.ScrolledWindow,
3935 var file = this.get('/LeftTree').getActiveFile();
3939 var activeEl = this.get('/LeftTree').getActiveElement();
3940 var xtype = file.guessName( activeEl )
3941 if (!xtype || !xtype.length) {
3944 //this.get('/Window.view-help-nb').el.set_current_page(1);
3946 // get the active element being edited.
3947 var helpurl = file.getHelpUrl(xtype);
3949 // now load the help info in the page..
3950 this.get('help-view').el.open(helpurl);
3954 xtype: WebKit.WebView,
3958 XObject.prototype.init.call(this);
3959 this.get('/Window.help-view').el.open(
3960 "http://devel.akbkhome.com/seed/");
3972 xtype: Gtk.Notebook,
3976 XObject.prototype.init.call(this);
3977 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3978 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3979 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3983 xtype: Gtk.ScrolledWindow,
3987 xtype: Vte.Terminal,
3990 feed : function(istr) {
3991 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3992 // we should make ourselves visable!!!
3993 this.get('/BottomPane').el.show();
3994 this.get('/BottomPane').el.set_current_page(1);
3996 this.el.feed(str ,str.length);
3998 scroll_on_output : true,
4000 XObject.prototype.init.call(this);
4001 this.el.set_size (80, 1000);
4003 scrollback_lines : 1000
4008 xtype: Gtk.ScrolledWindow,
4012 xtype: WebKit.WebView,
4028 this.get('buttonbar').el.show();
4029 this.get('viewbox').el.hide();
4030 var ce = this.get('/Window.centereast').el;
4032 ce.set_position(ce.get_allocated_width() - 30);
4034 print("TRIED TO HIDE");
4037 this.get('buttonbar').el.hide();
4038 this.get('viewbox').el.show();
4039 var ce = this.get('/Window.centereast').el;
4040 print(JSON.stringify(XObject.keys(ce) ,null,4));
4041 ce.set_position(ce.get_allocated_width() - 150);
4043 // this.get('model').expanded();
4055 pack : "pack_start,false,true",
4057 clicked : function (self) {
4058 this.get('/RightPalete').show();
4065 stock : Gtk.STOCK_GOTO_FIRST,
4066 icon_size : Gtk.IconSize.MENU
4076 XObject.prototype.init.call(this);
4077 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4080 enter_notify_event : function (self, event) {
4081 this.get('/RightPalete').show();
4095 pack : "pack_start,false,true",
4104 pack : "pack_start,false,true",
4106 clicked : function (self) {
4107 this.get('/RightPalete').hide();
4114 stock : Gtk.STOCK_GOTO_LAST,
4115 icon_size : Gtk.IconSize.MENU
4122 xtype: Gtk.ScrolledWindow,
4125 XObject.prototype.init.call(this);
4126 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4127 this.el.set_size_request(-1,200);
4129 shadow_type : Gtk.ShadowType.IN,
4132 xtype: Gtk.TreeView,
4134 drag_begin : function (self, ctx) {
4135 // we could fill this in now...
4136 Seed.print('SOURCE: drag-begin');
4141 var s = this.selection;
4142 s.get_selected(iret);
4143 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4145 var pix = this.el.create_row_drag_icon ( path);
4148 if (Gtk.drag_set_icon_surface) {
4149 Gtk.drag_set_icon_surface( ctx, pix );
4151 Gtk.drag_set_icon_pixmap (ctx,
4152 pix.get_colormap(), pix, null, -10, -10);
4155 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4156 if (!this.get('/RightPalete').provider) {
4159 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4160 this.el.dragData = value;
4167 drag_data_get : function (self, drag_context, selection_data, info, time) {
4168 //Seed.print('Palete: drag-data-get: ' + target_type);
4169 if (this.el.dragData && this.el.dragData.length ) {
4170 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4174 //this.el.dragData = "TEST from source widget";
4178 drag_end : function (self, drag_context) {
4179 Seed.print('SOURCE: drag-end');
4180 this.el.dragData = false;
4181 this.el.dropList = false;
4182 this.get('/LeftTree.view').highlight(false);
4185 button_press_event : function (self, event) {
4187 if (!this.get('/Editor').save()) {
4188 // popup!! - click handled..
4195 enable_tree_lines : true,
4196 headers_visible : false,
4198 XObject.prototype.init.call(this);
4199 this.el.set_size_request(150,-1);
4200 // set_reorderable: [1]
4202 var description = new Pango.FontDescription.c_new();
4203 description.set_size(8000);
4204 this.el.modify_font(description);
4206 this.selection = this.el.get_selection();
4207 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4208 // this.selection.signal['changed'].connect(function() {
4209 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4211 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4213 this.el.drag_source_set ( /* widget will be drag-able */
4214 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4215 null, /* lists of target to support */
4216 0, /* size of list */
4217 Gdk.DragAction.COPY /* what to do with data after dropped */
4219 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4221 this.el.drag_source_set_target_list( imports.Builder3.Main.targetList);
4222 this.el.drag_source_add_text_targets( );
4224 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4225 targets = new Gtk.TargetList();
4226 targets.add( LeftTree.atoms["STRING"], 0, 0);
4227 targets.add_text_targets( 1 );
4228 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4230 //if you want to allow text to be output elsewhere..
4231 //Gtk.drag_source_add_text_targets(this.el);
4237 xtype: Gtk.ListStore,
4240 XObject.prototype.init.call(this);
4241 this.el.set_column_types ( 2, [
4242 GObject.TYPE_STRING, // title
4243 GObject.TYPE_STRING // tip
4248 load : function(tr,iter)
4253 //console.log('Project tree load: ' + tr.length);
4255 //this.insert(citer,iter,0);
4256 for(var i =0 ; i < tr.length; i++) {
4259 this.el.append(cret);
4261 this.el.insert(cret,iter,-1);
4266 this.el.set_value(cret.iter, 0, '' + r ); // title
4268 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4269 //if (r.cn && r.cn.length) {
4270 // this.load(r.cn, citer);
4276 getValue : function (iter, col) {
4277 return this.el.get_value(iter, col).value.get_string();
4284 xtype: Gtk.TreeViewColumn,
4285 pack : "append_column",
4287 XObject.prototype.init.call(this);
4288 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4292 xtype: Gtk.CellRendererText,
4314 XObject.cache['/Window'] = Window;