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;
14 Globals = imports.Globals;
19 delete_event : function (self, event) {
22 destroy : function (self) {
25 show : function (self) {
27 imports.ProjectManager.ProjectManager.loadConfig();
29 print("HIDEWIN - calling MidPropTree hidewin")
30 this.get('/MidPropTree').hideWin();
31 this.get('/RightPalete').hide();
32 this.get('/BottomPane').el.hide();
33 //this.get('/Editor').el.show_all();
41 title : "Application Builder",
44 //imports.ProjectManager.ProjectManager.loadConfig();
46 XObject.prototype.init.call(this);
52 setTitle : function(str) {
53 this.el.set_title(this.title + ' - ' + str);
55 type : Gtk.WindowType.TOPLEVEL,
63 pack : "pack_start,false,false",
77 label : "New _Project",
79 activate : function (self) {
81 this.get('/EditProject').show({
82 success : function(pr) {
83 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
94 activate : function (self) {
95 var fn = this.get('/LeftProjectTree.combo').getValue();
97 this.get('/LeftProjectTree').showNoProjectSelected();
100 var pm = imports.ProjectManager.ProjectManager;
101 this.get('/DialogNewComponent').show({
102 project : pm.getByFn(fn)
108 xtype: Gtk.SeparatorMenuItem,
113 use_underline : true,
115 label : "D_elete Project",
117 activate : function (self) {
119 var fn = this.get('/LeftProjectTree').get('combo').getValue();
121 this.get('/StandardErrorDialog').show("Select a project")
124 var pm = imports.ProjectManager.ProjectManager;
125 var pr = pm.getByFn(fn);
128 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
129 pm.deleteProject(fn);
137 xtype: Gtk.SeparatorMenuItem,
144 use_underline : true,
146 activate : function (self) {
158 use_underline : true,
163 pack : "set_submenu",
168 activate : function (self) {
169 var fn = this.get('/LeftTree').getActiveFile();
171 this.get('/StandardErrorDialog').show("No File active");
175 this.get('/DialogNewComponent').show(fn);
179 label : "File _Properties",
186 activate : function (self, event) {
187 this.get('/RooProjectProperties').show();
191 label : "Modify Project HTML ",
202 use_underline : true,
206 pack : "set_submenu",
211 activate : function (self, event) {
212 var js = this.get('/LeftTree.model').toJS();
214 this.get('/RightBrowser.view').renderJS(js[0], true);
219 label : "_Redraw (Roo)",
226 activate : function (self, event)
228 /* Firefox testing for debugging..
229 - we can create a /tmp directory, and put.
230 builder.html, builder.html.js, link roojs1
231 add at the end of builder.html Roo.onload(function() {
233 if (!this.get('/Window.LeftTree').getActiveFile()) {
237 var js = this.get('/LeftTree.model').toJS();
241 var project = this.get('/Window.LeftTree').getActiveFile().project;
242 //print (project.fn);
244 project.runhtml = project.runhtml || '';
247 var File = imports.File.File;
249 var target = "/tmp/firetest"; // fixme..
250 if (!File.isDirectory(target)) {
253 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
254 if (!File.exists( target+ '/roojs1')) {
255 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
260 var html = imports.File.File.read(__script_path__ + '/../builder.html');
261 html = html.replace('</head>', project.runhtml + '</head>');
264 var jsstr = JSON.stringify(js[0], null, 4);
266 var runbuilder = '<script type="text/javascript">' + "\n" +
267 " Builder.render(" + jsstr + ");\n" +
270 html = html.replace('</body>', runbuilder + '</body>');
272 File.write( target+ '/builder.html', html);
274 this.get('/Terminal').feed("RUN DIR:" + target);
276 this.get('/Terminal').el.fork_command_full(
277 Vte.PtyFlags.DEFAULT,
283 null, // child setupdata
286 var cmd = "firefox file://" + target + "/builder.html \n";
287 this.get('/Terminal').el.feed_child(cmd, cmd.length);
291 label : "_Test in Firefox (Roo)",
302 use_underline : true,
307 pack : "set_submenu",
313 use_underline : true,
315 activate : function (self) {
316 this.get('/About').el.run();
346 activate : function (self) {
347 // this does not actually expand it..
348 // that is done by GTK..
351 if (!this.get('/Editor').save()) {
352 // popup!! - click handled..
356 if (!this.el.expanded) {
364 enter_notify_event : function (self, event) {
366 this.el.expanded = !this.el.expanded;
367 //if (this.el.expanded ) {
368 this.listeners.activate.call(this);
375 label : "Select Project or File",
376 pack : "pack_start,false,true",
378 XObject.prototype.init.call(this);
379 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
381 onCollapse : function() {
383 var nb = this.get('/LeftTopPanel.notebook');
384 nb.el.set_current_page(0);
386 onExpand : function() {
387 var nb = this.get('/LeftTopPanel.notebook');
388 var pm = imports.ProjectManager.ProjectManager;
391 var model = this.get('/LeftProjectTree.combomodel');
392 // print ("loading Projects?")
393 //console.dump(pm.projects);
394 model.loadData(pm.projects);
397 nb.el.set_current_page(1);
398 //pm.on('changed', function() {
399 //console.log("CAUGHT project manager change");
400 // _combo.model.loadData(pm.projects);
408 pack : "pack_start,true,true",
410 XObject.prototype.init.call(this);
411 this.el.set_current_page(0);
418 xtype: Gtk.ScrolledWindow,
421 getActiveElement : function() { // return path to actie node.
423 var path = this.getActivePath();
428 this.get('model').el.get_iter_from_string(ret, path);
430 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
432 return JSON.parse(value);
434 getActiveFile : function() {
435 return this.get('model').file;
437 getActivePath : function() {
438 var model = this.get('model');
439 var view = this.get('view');
440 if (view.selection.count_selected_rows() < 1) {
444 view.selection.get_selected(ret);
445 return ret.model.get_path(ret.iter).to_string();
447 getPaleteProvider : function() {
448 var model = this.get('model');
449 var pm = imports.ProjectManager.ProjectManager;
450 return pm.getPalete(model.file.getType());
452 getRenderer : function() {
454 switch( this.getActiveFile().getType()) {
456 return this.get('/RightBrowser.view');
458 return this.get('/RightGtkView');
463 XObject.prototype.init.call(this);
464 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
466 renderView : function() {
467 var render = this.getRenderer();
468 var model = this.get('model');
470 render.renderJS(model.toJS(false,true)[0]);
472 print("NO RENDER JS METHOD?");
475 shadow_type : Gtk.ShadowType.IN,
480 button_press_event : function (self, ev) {
481 console.log("button press?");
483 if (!this.get('/Editor').save()) {
484 // popup!! - click handled..
488 if (ev.button.button != 3) {
489 print("click" + ev.button.button);
495 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
497 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
499 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
500 this.get('/LeftTreeMenu').el.show_all();
501 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
502 print("click:" + res.path.to_string());
505 drag_begin : function (self, ctx) {
506 print('SOURCE: drag-begin');
507 this.targetData = false;
508 // find what is selected in our tree...
510 this.selection.get_selected(ret);
512 // set some properties of the tree for use by the dropped element.
513 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
514 var data = JSON.parse(value);
515 var xname = this.get('/LeftTree.model').file.guessName(data);
517 this.el.dragData = xname;
518 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
521 // make the drag icon a picture of the node that was selected
522 var path = ret.model.get_path(ret.iter);
523 this.el.treepath = path.to_string();
525 // returns a cairo surface
526 var pix = this.el.create_row_drag_icon ( path);
528 if (Gtk.drag_set_icon_surface) {
529 Gtk.drag_set_icon_surface( ctx, pix );
531 Gtk.drag_set_icon_pixmap (ctx,
532 pix.get_colormap(), pix, null, -10, -10);
537 drag_end : function (self, drag_context) {
538 Seed.print('LEFT-TREE: drag-end');
539 this.el.dragData = false;
540 this.el.dropList = false;
541 this.targetData = false;
542 this.get('/LeftTree.view').highlight(false);
545 drag_data_get : function(self, ctx, sel_data, info, time)
555 drag_motion : function (self, ctx, x, y, time) {
556 console.log("LEFT-TREE: drag-motion");
557 var src = Gtk.drag_get_source_widget( ctx);
559 // a drag from elsewhere...- prevent drop..
561 print("no drag data!");
562 Gdk.drag_status(ctx, 0, time);
563 this.targetData = false;
566 var action = Gdk.DragAction.COPY;
567 if (src == this.el) {
568 // unless we are copying!!! ctl button..
569 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
573 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
574 // no children.. -- asume it's ok..
575 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
576 Gdk.drag_status(ctx, action ,time);
580 print("GETTING POS");
581 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
582 print("ISOVER? " + isOver);
584 Gdk.drag_status(ctx, 0 ,time);
585 return false; // not over apoint!?!
587 // drag node is parent of child..
588 console.log("SRC TREEPATH: " + src.treepath);
589 console.log("TARGET TREEPATH: " + data.path.to_string());
591 // nned to check a few here..
592 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
593 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
594 //Gtk.TreeViewDropPosition.AFTER
595 //Gtk.TreeViewDropPosition.BEFORE
597 if (typeof(src.treepath) != 'undefined' &&
598 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
599 print("subpath drag");
600 Gdk.drag_status( ctx, 0 ,time);
605 //print("DUMPING DATA");
606 //console.dump(data);
609 print(data.path.to_string() +' => '+ data.pos);
610 var tg = this.get('/LeftTree.model').findDropNodeByPath(
611 data.path.to_string(), src.dropList, data.pos);
613 this.get('/LeftTree.view').highlight(tg);
615 print("Can not find drop node path");
616 this.targetData = false;
617 Gdk.drag_status(ctx, 0, time);
620 print(JSON.stringify(tg,null,4));
622 this.targetData = tg;
625 Gdk.drag_status(ctx, action ,time);
629 drag_drop : function (w, ctx, x, y, time) {
630 Seed.print("TARGET: drag-drop");
631 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
633 ( /* will receive 'drag-data-received' signal */
634 ctx, /* represents the current state of the DnD */
635 Globals.atoms["STRING"], /* the target type we want */
636 time /* time stamp */
640 /* No target offered by source => error */
645 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
646 print("Tree: drag-data-received");
648 var delete_selection_data = false;
649 var dnd_success = false;
650 //print(JSON.stringify(sel_data, null,4));
651 /* Deal with what we are given from source */
653 // simce I can not be bothered to sort out
654 // drag drop = let's assume it worked...
656 if( true || (sel_data && sel_data.length )) {
658 if (ctx.action == Gdk.DragAction.ASK) {
659 /* Ask the user to move or copy, then set the ctx action. */
662 if (ctx.action == Gdk.DragAction.MOVE) {
663 //delete_selection_data = true;
666 var source = Gtk.drag_get_source_widget( ctx );
668 if (this.targetData) {
669 if (source != this.el) {
670 print("DRAG FROM ANOTHER WIDGET");
671 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
673 // drag around.. - reorder..
674 print("DRAG FROM SELF");
675 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
679 //Seed.print(this.targetData);
685 // we can send stuff to souce here...
691 if (dnd_success == false)
693 Seed.print ("DnD data transfer failed!\n");
696 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
699 cursor_changed : function (self) {
700 if (this.blockChanges) { // probably not needed..
703 var render = this.get('/LeftTree').getRenderer();
706 if (this.selection.count_selected_rows() < 1) {
707 this.get('/LeftPanel.model').load( false);
708 this.get('/MidPropTree').activeElement = false;
709 this.get('/MidPropTree').hideWin();
711 var pm = this.get('/RightPalete.model');
712 if (!this.get('/LeftTree').getPaleteProvider()) {
713 // it may not be loaded yet..
717 this.get('/LeftTree').getPaleteProvider().gatherList(
718 this.get('/LeftTree.model').listAllTypes()
721 if (render && render.redraw) {
727 //console.log('changed');
728 var s = this.selection;
733 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
734 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
736 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
739 var data = JSON.parse(value);
740 this.get('/MidPropTree').activeElement = data;
741 this.get('/MidPropTree').hideWin();
742 this.get('/LeftPanel.model').load( data);
745 // _g.button.set_label(''+value.get_string());
747 var pm =this.get('/RightPalete.model');
748 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
749 this.get('/LeftTree.model').listAllTypes()));
752 if (render && render.redraw) {
756 //Seed.print( value.get_string());
764 enable_tree_lines : true,
765 headers_visible : false,
766 highlight : function(treepath_ar) {
768 // highlighting for drag/drop
769 if (treepath_ar.length && treepath_ar[0].length ) {
770 this.el.set_drag_dest_row(
771 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
773 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
779 XObject.prototype.init.call(this);
780 var description = new Pango.FontDescription.c_new();
781 description.set_size(8000);
782 this.el.modify_font(description);
784 this.selection = this.el.get_selection();
785 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
788 // is this really needed??
789 this.selection.signal['changed'].connect(function() {
790 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
791 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
795 this.el.drag_source_set( /* widget will be drag-able */
796 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
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_source_set_target_list(Globals.targetList);
804 this.el.drag_source_add_text_targets();
805 this.el.drag_dest_set
807 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
808 null, /* lists of target to support */
809 0, /* size of list */
810 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
813 this.el.drag_dest_set_target_list( Globals.targetList);
814 this.el.drag_dest_add_text_targets( );
816 selectNode : function(treepath_str) {
817 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
818 var tp = new Gtk.TreePath.from_string(treepath_str);
819 this.el.set_cursor(tp, null, false);
820 this.el.scroll_to_cell(tp, null, false, 0,0);
824 xtype: Gtk.TreeStore,
830 setFromNode : function(tp, n)
833 tp = this.get('/LeftTree').getActivePath();
836 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
837 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
838 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
839 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
843 changed : function( refresh) {
847 print("-------MODEL CHANGED CALLED" );
849 //this.currentTree = this.toJS(false, true)[0];
851 this.file.items = this.toJS(false, false);
852 print ("TO JS in " + ((new Date()) - d) + "ms");
853 // print("AFTER CHANGED");
854 //console.dump(this.file.items);
856 this.currentTree = this.file.items[0];
857 //console.log(this.file.toSource());
860 print("REDNER BROWSER?!");
861 this.get('/LeftTree').renderView();
863 var pm = this.get('/RightPalete.model');
864 if (!this.get('/RightPalete').provider) {
870 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
871 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
875 deleteSelected : function() {
876 this.get('/LeftTree.view').blockChanges = true;
878 var s = this.get('/LeftTree.view').selection;
879 s.get_selected(oret);
880 var path = this.el.get_path(oret.iter).to_string();
882 this.activePath= false;
885 this.activePath= false;
887 this.el.get_iter_from_string(ret, path);
888 this.el.remove(ret.iter);
890 // rebuild treemap. -- depreciated.!!
893 //this.toJS(null, true) // does not do anything?
894 this.activePath= false;
896 this.get('/LeftTree.view').blockChanges = false;
898 dropNode : function(target_data, node) {
900 // console.dump(node);
901 //print(JSON.Stringify(target_data, null, 4));
902 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
904 print("add " + tp + "@" + target_data[1] );
907 if (tp && target_data[1] < 2) { // before or after..
908 var ar = target_data[0].split(':');
910 parent = new Gtk.TreePath.from_string( ar.join(':') );
915 var aret = after ? {} : false;
919 if (parent !== false) {
920 this.el.get_iter(pret, parent);
927 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
928 this.el.get_iter(aret, after);
929 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
930 nret, pret.iter, aret.iter);
933 this.el.append(nret, pret.iter);
936 var new_path = this.el.get_path(nret.iter).to_string();
937 print("new path = " + new_path)
938 if (typeof(node) == 'string') {
939 var ar = node.split('.');
940 var xtype = ar.pop();
943 '|xns' : ar.join('.'),
946 if (target_data.length == 3 && target_data[2].length) {
947 node['*prop'] = target_data[2];
949 node = this.get('/DialogTemplateSelect').show(node);
952 // work out what kind of packing to use..
953 if (typeof(node.pack) == 'undefined' && parent !== false) {
954 var pal = this.get('/LeftTree').getPaleteProvider();
955 if (pal.name == 'Gtk') {
956 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
957 var cname = pal.guessName(node);
958 node.pack = pal.getDefaultPack(pname, cname);
969 // load children - if it has any..
972 this.load(xitems, nret.iter);
973 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
975 if (tp && (xitems || after)) {
976 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
978 // wee need to get the empty proptypes from somewhere..
980 //var olditer = this.activeIter;
981 //this.activePath = new_path;
982 print("calling changed with node data")
983 // changed actually set's the node data..
984 this.setFromNode(new_path,node);
989 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
991 //Builder.MidPropTree._model.load(node);
992 //Builder.MidPropTree._win.hideWin();
993 //Builder.LeftPanel._model.load( node);
997 findDropNode : function(treepath_str, targets) {
999 // this is used by the dragdrop code in the roo version AFAIR..
1001 var path = treepath_str.replace(/^builder-/, '');
1002 // treemap is depreciated... - should really check if model has any entries..
1004 if (!this.el.iter_n_children(null)) {
1006 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
1008 print("FIND treepath: " + path);
1009 //console.dump(this.treemap);
1011 if (!treepath_str.match(/^builder-/)) {
1012 return []; // nothing!
1014 if (targets === true) {
1017 return this.findDropNodeByPath(path,targets)
1019 findDropNodeByPath : function(treepath_str, targets, pref) {
1020 var path = treepath_str + ''; // dupe it..
1021 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1023 //console.dump(this.treemap);
1024 while (path.length) {
1025 print("LOOKING FOR PATH: " + path);
1026 var node_data = this.singleNodeToJS(path);
1027 if (node_data === false) {
1028 print("node not found");
1032 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1035 targets.forEach(function(tg) {
1039 if ((tg == xname) ) {
1042 if (tg.indexOf(xname +':') === 0) {
1044 prop = tg.split(':').pop();
1049 if (last) { // pref is after/before..
1050 // then it's after last
1052 return []; // do not allow..
1054 return [ last, pref , prop];
1057 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1059 var par = path.split(':');
1062 path = par.join(':');
1068 getIterValue : function (iter, col) {
1070 var gval = ''+this.el.get_value(iter, col).value.get_string();
1076 XObject.prototype.init.call(this);
1077 this.el.set_column_types ( 3, [
1078 GObject.TYPE_STRING, // title
1079 GObject.TYPE_STRING, // tip
1080 GObject.TYPE_STRING // source..
1083 listAllTypes : function() {
1084 var s = this.get('/LeftTree.view').selection;
1085 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1087 if (s.count_selected_rows() > 0) {
1089 s.get_selected(ret);
1091 // set some properties of the tree for use by the dropped element.
1092 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1093 var data = JSON.parse(value);
1096 var xname = this.get('/LeftTree.model').file.guessName(data);
1097 console.log('selected:' + xname);
1101 return []; // could not find it..
1110 for (var i =0 ; i < li.length; i++ ) {
1113 // this is specific to roo!!!?
1114 if (!el) { // skip empty?
1117 var fullpath = _this.file.guessName(el);
1118 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1123 if (el.items && el.items.length) {
1132 addall([this.currentTree]);
1134 // only if we have nothing, should we add '*top'
1138 //console.log('all types in tree');
1139 //console.dump(ret);
1144 load : function(tr,iter)
1146 //this.insert(citer,iter,0);
1148 for(var i =0 ; i < tr.length; i++) {
1151 this.el.insert(ret ,iter,-1);
1153 this.el.append(ret);
1155 //print(JSON.stringify(ret,null,4));
1156 //print('call nodeToJSON: ' + tr[i]);
1157 var body = this.nodeToJSON(tr[i]);
1159 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1160 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1161 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1162 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1163 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1164 this.el.set_value(ret.iter, 2, '' + body );
1165 if (tr[i].items && tr[i].items.length) {
1166 this.load(tr[i].items, ret.iter);
1170 loadFile : function(f) {
1177 console.log('missing file');
1181 // load the file if not loaded..
1182 if (f.items === false) {
1184 f.loadItems(function() {
1190 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1192 if (f.items.length && typeof(f.items[0]) == 'string') {
1194 //this.get('/RightEditor').el.show();
1195 //this.get('/RightEditor.view').load( f.items[0]);
1199 //print(JSON.stringify(f.items, null,4));
1200 //console.dump(f.items);
1202 this.get('/LeftTree.view').el.expand_all();
1204 if (!f.items.length) {
1207 this.get('/Window.leftvpaned').el.set_position(80);
1209 this.get('/LeftTree.view').el.set_cursor(
1210 new Gtk.TreePath.from_string('0'), null, false);
1214 this.get('/Window.leftvpaned').el.set_position(200);
1217 //return; -- debuggin
1218 //print("hide right editior");
1219 //this.get('/RightEditor').el.hide();
1220 this.get('/Editor').el.hide();
1221 print("set current tree");
1223 this.currentTree = this.toJS(false, false)[0];
1226 //console.dump(this.currentTree);
1227 this.currentTree = this.currentTree || { items: [] };
1228 this.get('/LeftTree').renderView();
1229 // console.dump(this.map);
1230 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1231 var pm = this.get('/RightPalete.model');
1232 // set up provider..
1234 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1236 if (!this.get('/RightPalete').provider) {
1237 print ("********* PALETE PROVIDER MISSING?!!");
1239 this.get('/LeftTree').renderView();
1241 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1245 this.get('/Window.view-notebook').el.set_current_page(
1246 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1249 moveNode : function(target_data, action) {
1250 //print("MOVE NODE");
1251 // console.dump(target_data);
1253 var s = this.get('/LeftTree.view').selection;
1254 s.get_selected( oret);
1255 var node = this.nodeToJS(oret.iter,false);
1256 //console.dump(node);
1257 print(JSON.stringify(node, null,4));
1259 // needs to drop first, otherwise the target_data
1260 // treepath will be invalid.
1262 this.dropNode(target_data, node);
1263 if (action & Gdk.DragAction.MOVE) {
1264 // print("REMOVING OLD NODE");
1265 this.el.remove(oret.iter);
1269 this.activePath= false;
1272 nodeTip : function(c) {
1273 var ret = this.nodeTitle(c,true);
1279 if (!i.length || i[0] != '|') {
1285 if (typeof(c[i]) != 'string') {
1288 //print("prop : " + i + ':' + c[i]);
1289 if (!c[i].match(new RegExp('function'))) {
1292 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1296 ret+="\n\nMethods:" + funcs;
1301 nodeTitle : function(c, renderfull) {
1304 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1305 if (sr) txt.push('<s>');
1306 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1308 if (renderfull && c['|xns']) {
1309 txt.push(c['|xns']);
1312 if (c.xtype) { txt.push(c.xtype); }
1313 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1314 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1315 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1318 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1319 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1320 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1321 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1322 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1323 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1324 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1325 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1326 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1328 // for flat classes...
1329 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1330 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1333 if (sr) txt.push('</s>');
1334 return (txt.length == 0 ? "Element" : txt.join(" "));
1336 nodeToJS : function (treepath, with_id)
1338 //print("nodeToJS : WITHID: "+ with_id);
1339 var iter = treepath; // API used to be iter here..
1340 if (typeof(iter) == 'string') {
1342 if (!this.el.get_iter(ret,
1343 new Gtk.TreePath.from_string(treepath))) {
1349 var iv = this.getIterValue(iter, 2);
1350 // print("IV" + iv);
1351 var k = JSON.parse(iv);
1352 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1357 var treepath_str = this.el.get_path(iter).to_string();
1358 // not sure how we can handle mixed id stuff..
1359 if (typeof(k.id) == 'undefined') {
1360 k.id = 'builder-'+ treepath_str ;
1364 this.treemap[ treepath_str ] = k;
1365 k.xtreepath = treepath_str ;
1368 if (this.el.iter_has_child(iter)) {
1370 this.el.iter_children(cret, iter);
1371 k.items = this.toJS(cret.iter,with_id);
1375 nodeToJSON : function(c) {
1383 return JSON.stringify(o);
1385 singleNodeToJS : function (treepath)
1388 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1392 var iv = this.getIterValue(ret.iter, 2);
1394 return JSON.parse(iv);
1397 toJS : function(treepath, with_id)
1399 //print("toJS : WITHID: "+ with_id);
1401 var iter = treepath; // API used to be iter here..
1403 if (typeof(iter) == 'string') {
1405 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1417 if (!this.el.get_iter_first(ret)) {
1428 var k = this.nodeToJS(iter, with_id);
1432 if (!this.el.iter_next(iter)) {
1437 if (treepath === false) {
1439 return JSON.parse(JSON.stringify(ar));
1443 // convert the list into a json string..
1449 xtype: Gtk.TreeViewColumn,
1450 pack : "append_column",
1452 XObject.prototype.init.call(this);
1453 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1457 xtype: Gtk.CellRendererText,
1467 id : "LeftTreeMenu",
1470 xtype: Gtk.MenuItem,
1472 label : "Delete Element",
1474 activate : function (self) {
1476 this.get('/LeftTree.model').deleteSelected();
1481 xtype: Gtk.MenuItem,
1483 activate : function (self) {
1485 var tree = this.get('/LeftTree');
1486 var model = this.get('/LeftTree.model');
1487 var el = tree.getActivePath();
1489 var js = model.toJS(el, false);
1490 // print(JSON.stringify(js[0], null,4));
1491 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1496 label : "Save as Template",
1506 id : "LeftProjectTree",
1507 showNoProjectSelected : function() {
1508 this.get('/StandardErrorDialog').show("Select a Project first.");
1510 getActiveProject : function() {
1511 return this.project;
1514 leave_notify_event : function (self, event) {
1521 pack : "pack_start,false,false",
1524 xtype: Gtk.ComboBox,
1526 changed : function (self) {
1527 var fn = this.getValue();
1528 var pm = imports.ProjectManager.ProjectManager;
1529 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1533 getValue : function() {
1534 var ix = this.el.get_active();
1538 var data = imports.ProjectManager.ProjectManager.projects;
1539 if (typeof(data[ix]) == 'undefined') {
1545 XObject.prototype.init.call(this);
1546 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1548 setValue : function(fn)
1552 var data = imports.ProjectManager.ProjectManager.projects;
1553 data.forEach(function(n, ix) {
1562 xtype: Gtk.CellRendererText,
1563 pack : "pack_start,true",
1567 xtype: Gtk.ListStore,
1571 XObject.prototype.init.call(this);
1572 this.el.set_column_types ( 2, [
1573 GObject.TYPE_STRING, // real key
1574 GObject.TYPE_STRING // real type
1578 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1579 var pm = imports.ProjectManager.ProjectManager;
1581 pm.on('changed', function() {
1582 print("caught changed hook on project manager - reloading data");
1583 _this.loadData(pm.projects);
1587 loadData : function(data) {
1588 var ov = this.get('/LeftProjectTree.combo').getValue();
1592 data.forEach(function(p) {
1595 //print(JSON.stringify(XObject.keys(na)));
1596 //print(typeof(na.iter));
1597 //print(JSON.stringify(iter))
1598 el.set_value(na.iter, 0, p.fn);
1599 el.set_value(na.iter, 1, p.name);
1603 this.get('/LeftProjectTree.combo').setValue(ov);
1611 xtype: Gtk.ScrolledWindow,
1613 shadow_type : Gtk.ShadowType.IN,
1615 XObject.prototype.init.call(this);
1616 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1620 xtype: Gtk.TreeView,
1623 cursor_changed : function (self) {
1625 var model = this.get('/LeftProjectTree.model');
1629 if (model.loading) {
1634 print("LOADING IS FALSE");
1636 if (this.selection.count_selected_rows() < 1) {
1637 //XN.get('Builder.LeftTree.model').
1638 this.get('/LeftTree.model').load( false);
1642 //console.log('changed');
1643 var s = this.selection;
1644 s.get_selected(ret);
1645 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1646 //console.log(JSON.stringify(value,null,4));// id..
1647 console.log("OUT?" + value);// id..
1648 var file = this.get('/LeftProjectTree').project.getById(value);
1655 var nb = this.get('/LeftTopPanel.expander');
1656 nb.el.expanded = false;
1658 //nb.listeners.activate.call(nb);
1659 //_expander.el.set_expanded(false);
1661 var ltm = this.get('/LeftTree.model');
1669 enable_tree_lines : true,
1670 headers_visible : false,
1672 XObject.prototype.init.call(this);
1673 var description = new Pango.FontDescription.c_new();
1674 description.set_size(8000);
1675 this.el.modify_font(description);
1677 this.selection = this.el.get_selection();
1678 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1682 xtype: Gtk.TreeStore,
1687 XObject.prototype.init.call(this);
1688 this.el.set_column_types ( 3, [
1689 GObject.TYPE_STRING, // title
1690 GObject.TYPE_STRING, // tip
1691 GObject.TYPE_STRING // id..
1695 loadProject : function(pr) {
1696 print("LOAD PROJECT");
1697 var model = this.get('/LeftProjectTree.model');
1698 model.loading = true;
1705 this.get('/LeftProjectTree').project = pr;
1707 this.load(pr.toTree());
1709 this.get('/LeftProjectTree.view').el.expand_all();
1710 model.loading = false;
1713 load : function(tr,iter) {
1714 // console.dump(tr);
1717 console.log('Project tree load: ' + tr.length);
1719 //this.insert(citer,iter,0);
1723 tr.forEach(function (r) {
1725 _this.el.append(cret);
1727 _this.el.insert(cret,iter,-1);
1729 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1730 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1731 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1732 if (r.cn && r.cn.length) {
1733 _this.load(r.cn, cret.iter);
1739 getValue : function(iter, col) {
1740 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1745 xtype: Gtk.TreeViewColumn,
1746 pack : "append_column",
1748 XObject.prototype.init.call(this);
1749 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1753 xtype: Gtk.CellRendererText,
1773 pack : "pack_start,false,true,0",
1780 button_press_event : function (self, event) {
1781 this.get('/MidPropTree.model').showData('props');
1793 stock : Gtk.STOCK_ADD,
1794 icon_size : Gtk.IconSize.MENU
1808 button_press_event : function (self, event) {
1810 if (!this.get('/Editor').save()) {
1811 // popup!! - click handled..
1814 this.get('/MidPropTree.model').showData('events');
1827 stock : Gtk.STOCK_ADD,
1828 icon_size : Gtk.IconSize.MENU
1842 button_press_event : function (self, ev) {
1844 if (!this.get('/Editor').save()) {
1845 // popup!! - click handled..
1849 var p = this.get('/AddPropertyPopup');
1853 p.el.set_screen(Gdk.Screen.get_default());
1855 p.el.popup(null, null, null, null, 3, ev.button.time);
1868 stock : Gtk.STOCK_ADD,
1869 icon_size : Gtk.IconSize.MENU
1881 id : "AddPropertyPopup",
1884 xtype: Gtk.MenuItem,
1886 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1889 activate : function (self) {
1891 this.get('/LeftPanel.model').add( {
1902 xtype: Gtk.MenuItem,
1904 tooltip_markup : "Add what type of packing is to be used",
1907 activate : function (self) {
1909 this.get('/LeftPanel.model').add( {
1919 xtype: Gtk.MenuItem,
1921 tooltip_markup : "Override the init method",
1924 activate : function (self) {
1926 this.get('/LeftPanel.model').add( {
1929 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1936 xtype: Gtk.SeparatorMenuItem,
1940 xtype: Gtk.MenuItem,
1942 tooltip_markup : "Add a user defined string property",
1945 activate : function (self) {
1947 this.get('/LeftPanel.model').add( {
1957 xtype: Gtk.MenuItem,
1959 tooltip_markup : "Add a user defined number property",
1962 activate : function (self) {
1964 this.get('/LeftPanel.model').add( {
1974 xtype: Gtk.MenuItem,
1976 tooltip_markup : "Add a user defined boolean property",
1979 activate : function (self) {
1981 this.get('/LeftPanel.model').add( {
1991 xtype: Gtk.SeparatorMenuItem,
1995 xtype: Gtk.MenuItem,
1997 tooltip_markup : "Add a user function boolean property",
2000 activate : function (self) {
2002 this.get('/LeftPanel.model').add( {
2005 val : "function() {\n \n}\n",
2018 xtype: Gtk.ScrolledWindow,
2023 XObject.prototype.init.call(this);
2024 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2026 shadow_type : Gtk.ShadowType.IN,
2029 xtype: Gtk.TreeView,
2031 button_press_event : function (self, ev) {
2034 if (!this.get('/Editor').save()) {
2035 // popup!! - click handled..
2040 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2041 return false; //not on a element.
2045 if (ev.button.button == 3) {
2047 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2050 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2051 var p = this.get('/LeftPanelPopup');
2056 p.el.set_screen(Gdk.Screen.get_default());
2058 p.el.popup(null, null, null, null, 3, ev.button.time);
2059 //Seed.print("click:" + res.column.title);
2066 if (res.column.title != 'value') {
2067 // XObject.error("column is not value?");
2068 return false; // ignore.. - key click.. ??? should we do this??
2071 // currently editing???
2072 // if ( this.activePath) {
2074 // this.activePath = false;
2076 if (this.get('/Editor').dirty) {
2077 //if (!this.get('/Editor.buffer').checkSyntax()) {
2078 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2082 if (!this.get('/Editor.view').save()) {
2086 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2087 this.get('/LeftPanel').editing = false;
2089 // XObject.error("Currently editing?");
2093 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2095 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2097 // get options for this type -- this is to support option lists etc..
2098 var provider = this.get('/LeftTree').getPaleteProvider();
2099 var opts = provider.findOptions(type);
2101 if (opts === false) {
2103 this.get('/LeftPanel').editableColumn.setOptions([]);
2104 renderer.has_entry = true;
2106 this.get('/LeftPanel').editableColumn.setOptions(opts);
2107 renderer.has_entry = false;
2109 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2111 //Seed.print("click" + ev.type);
2112 //console.dump(res);
2121 enable_tree_lines : true,
2122 headers_visible : false,
2124 XObject.prototype.init.call(this);
2126 this.selection = this.el.get_selection();
2127 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2130 var description = new Pango.FontDescription.c_new();
2131 description.set_size(8000);
2132 this.el.modify_font(description);
2136 xtype: Gtk.TreeStore,
2140 add : function(info) {
2141 // info includes key, val, skel, etype..
2143 type = info.type.toLowerCase();
2144 var data = this.toJS();
2146 if (info.etype == 'events') {
2147 data.listeners = data.listeners || { };
2148 if (typeof(data.listeners[info.key]) != 'undefined') {
2149 return; //already set!
2152 if (typeof(data[info.key]) != 'undefined') {
2157 if (typeof(info.val) == 'undefined') {
2160 if (info.type.toLowerCase() == 'boolean') {
2163 if (type == 'number') {
2171 if (info.etype == 'events') {
2173 data.listeners[info.key] = info.val;
2176 data[info.key] = info.val;
2180 var map = this.load(data);
2182 // flag it as changed to the interface..
2183 this.get('/LeftTree.model').setFromNode(false,node);
2184 this.get('/LeftTree.model').changed(true);
2187 this.startEditing(map[k]);
2190 LeftPanel.get('view').el.row_activated(
2191 new Gtk.TreePath.from_string(map[k]),
2192 LeftPanel.editableColumn.el
2196 changed : function(str, doRefresh) {
2197 if (!this.activePath) {
2198 print("NO active path when changed")
2202 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2204 this.el.set_value(ret.iter, 1, '' +str);
2205 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2206 var type = this.getIterValue(ret.iter, 4);
2208 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2209 // update the tree...
2210 print("new data: " + JSON.stringify(this.toJS() , null,4));
2211 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2212 this.get('/LeftTree.model').changed(doRefresh);
2215 deleteSelected : function() {
2216 var data = this.toJS();
2218 var s = this.get('/LeftPanel.view').selection;
2219 s.get_selected( ret);
2222 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2224 if (val[0] == '!') {
2226 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2229 delete data.listeners[ val.substring(1)];
2230 if (!XObject.keys(data.listeners).length) {
2231 delete data.listeners;
2235 if (typeof(data[val]) == 'undefined') {
2245 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2246 this.get('/LeftTree.model').changed(true);
2250 getIterValue : function(iter, col) {
2251 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2254 getType : function(treepath) {
2255 return this.getValue(treepath, 4);
2257 getValue : function(treepath_str, col)
2259 // get's the value in a row.. - keys - returns string, values - formats it..
2261 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2263 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2268 var type = this.getType(this.el.get_path(ret.iter).to_string());
2269 //print("TYPE: " +type + " - val:" + val);
2270 switch(type.toLowerCase()) {
2274 return parseFloat(val); // Nan ?? invalid!!?
2277 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2279 return val == 'true' ? true : false;
2281 var nv = parseFloat(val);
2282 if (!isNaN(nv) && (val == ''+nv)) {
2290 XObject.prototype.init.call(this);
2291 this.el.set_column_types ( 6, [
2292 GObject.TYPE_STRING, // 0 real key
2293 GObject.TYPE_STRING, // 1 real value
2294 GObject.TYPE_STRING, // 2 visable key
2295 GObject.TYPE_STRING, // 3 visable value
2296 GObject.TYPE_STRING, // 4 need to store type of!!!
2297 GObject.TYPE_STRING // 5 tooltip
2301 load : function(ar) {
2302 // might casue problesm..
2303 // this.get('/Editor.RightEditor').save();
2305 this.get('/Editor').el.hide();
2306 this.get('/Editor').activePath = false;
2311 //this.get('/RightEditor').el.hide();
2318 var provider = this.get('/LeftTree').getPaleteProvider();
2322 var keys = XObject.keys(ar);
2324 ar.listeners = ar.listeners || {};
2326 for (var i in ar.listeners ) {
2328 this.el.append(iret);
2329 var p = this.el.get_path(iret.iter).to_string();
2332 this.el.set_value(iret.iter, 0, '!'+ i );
2333 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2334 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2336 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2337 this.el.set_value(iret.iter, 4, 'function');
2338 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2344 keys.forEach(function(i) {
2345 if (typeof(ar[i]) == 'object') {
2349 var type = provider.findType(ar, i, ar[i]);
2351 _this.el.append(iret);
2352 var p = _this.el.get_path(iret.iter).to_string();
2354 _this.el.set_value(iret.iter, 0, ''+i);
2355 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2356 _this.el.set_value(iret.iter, 2, ''+i);
2357 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2358 _this.el.set_value(iret.iter, 4, ''+type);
2359 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2363 startEditing : function(path,col) {
2365 // alled by menu 'edit' currently..
2367 * start editing path (or selected if not set..)
2368 * @param {String|false} path (optional) treepath to edit - selected tree gets
2369 * edited by default.
2370 * @param {Number} 0 or 1 (optional)- column to edit.
2372 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2374 if (typeof(path) == 'string') {
2375 tp = new Gtk.TreePath.from_string(path);
2378 var s = this.get('/LeftPanel.view').selection;
2379 s.get_selected( itr);
2380 tp = this.el.get_path(itr.iter);
2381 path = tp.to_string();
2385 // which colum is to be edited..
2388 // not sure what this does..
2390 if (typeof(col) == 'undefined') {
2391 var k = this.getValue(path, 0);
2393 colObj = (!k.length || k == '|') ?
2394 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2396 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2399 // make sure the pulldown is set correctly..
2400 // not really needed for second col...
2401 var showEditor = false;
2402 this.get('/Editor').activePath = false;
2403 this.get('/Editor').el.hide();
2406 var provider = this.get('/LeftTree').getPaleteProvider();
2407 var type = this.get('/LeftPanel.model').getType(path);
2408 var opts = provider.findOptions(type);
2409 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2411 if (opts === false) {
2412 this.get('/LeftPanel').editableColumn.setOptions([]);
2413 renderer.has_entry = true;
2415 this.get('/LeftPanel').editableColumn.setOptions(opts);
2416 renderer.has_entry = false;/// - pulldowns do not have entries
2418 // determine if we should use the Text editor...
2419 var keyname = this.getValue(path, 0);
2420 var data_value = this.getValue(path, 1);
2422 if ((keyname[0] == '|') ||
2424 (typeof(data_value) == 'string' ) &&
2425 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2429 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2434 // this.get('/BottomPane').el.hide();
2435 //this.get('/RightEditor').el.hide();
2440 this.activePath = false;
2442 _this.get('/Editor').el.show_all();
2443 GLib.timeout_add(0, 1, function() {
2445 //_this.get('/BottomPane').el.show();
2446 //_this.get('/RightEditor').el.show();
2448 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2450 _this.get('/Editor').activePath = path;
2451 _this.activePath = path ;
2461 // iter now has row...
2462 GLib.timeout_add(0, 100, function() {
2463 _this.activePath = path;
2464 colObj.items[0].el.editable = true; // esp. need for col 0..
2465 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2476 this.get('/LeftPanel.model').el.get_iter_first(iret);
2482 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2485 ar.listeners = ar.listeners || {};
2486 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2489 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2492 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2498 //print(JSON.stringify(ar));
2502 toShort : function(str) {
2503 var a = typeof(str) == 'string' ? str.split("\n") : [];
2504 return a.length > 1 ? a[0] + '....' : '' + str;
2508 xtype: Gtk.TreeViewColumn,
2509 pack : "append_column",
2511 XObject.prototype.init.call(this);
2513 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2514 this.get('/LeftPanel').propertyColumn = this;
2519 xtype: Gtk.CellRendererText,
2520 pack : "pack_start",
2522 editing_started : function (self, editable, path) {
2524 this.get('/LeftPanel.model').activePath = path;
2527 edited : function (self, object, p0) {
2529 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2531 var model = this.get('/LeftPanel.model');
2532 var path = model.activePath;
2534 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2535 model.el.set_value(iret.iter, 0, p0);
2536 model.el.set_value(iret.iter, 2, p0);
2538 model.activePath = false;
2539 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2540 this.get('/LeftTree.model').changed(true);
2542 this.el.editable = false;
2549 xtype: Gtk.TreeViewColumn,
2550 pack : "append_column",
2553 XObject.prototype.init.call(this);
2554 this.el.add_attribute(this.items[0].el , 'text', 3 );
2555 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2556 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2557 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2559 this.get('/LeftPanel').editableColumn= this;
2561 setOptions : function(ar) {
2562 var m = this.items[0].el.model;
2565 ar.forEach(function(i) {
2569 m.set_value(iret.iter, 0, i);
2575 xtype: Gtk.CellRendererCombo,
2577 edited : function (self, object, p0) {
2579 this.get('/LeftPanel').editing = false;
2580 var ap = this.get('/LeftPanel.model').activePath
2581 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2582 this.get('/LeftPanel.model').changed(p0, true);
2583 this.get('/LeftPanel.model').activePath = false;
2584 this.el.editable = false;
2586 editing_started : function (self, editable, path) {
2587 this.get('/LeftPanel').editing = true;
2588 // console.log('editing started');
2589 // r.has_entry = false;
2591 this.el.editable = false; // make sure it's not editor...
2596 pack : "pack_start",
2600 XObject.prototype.init.call(this);
2601 this.el.model = new Gtk.ListStore();
2602 this.el.model.set_column_types ( 1, [
2603 GObject.TYPE_STRING // 0 real key
2614 id : "LeftPanelPopup",
2617 xtype: Gtk.MenuItem,
2621 activate : function (self) {
2622 this.get('/LeftPanel.model').deleteSelected();
2627 xtype: Gtk.MenuItem,
2631 activate : function (self) {
2632 this.get('/LeftPanel.model').startEditing(false, 0);
2645 xtype: Gtk.ScrolledWindow,
2646 pack : "pack_end,false,true,0",
2649 shadow_type : Gtk.ShadowType.IN,
2651 XObject.prototype.init.call(this);
2652 XObject.prototype.init.call(this);
2653 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2654 this.el.set_size_request ( 150, -1 );
2657 activeElement : false,
2658 hideWin : function() {
2661 print("HIDEWIN - currently not shown")
2666 if (this.get('/Window.left').el.position < 160) {
2667 print("HIDEWIN - small already.")
2671 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2672 print("HIDEWIN attempting to hide.")
2679 xtype: Gtk.TreeView,
2681 cursor_changed : function (self) {
2682 // this is getting fired when we are loading elements..
2683 if (this.get('/MidPropTree.model').loading) {
2689 //console.log('changed');
2690 var m = this.get('model');
2691 if (!this.selection){
2692 this.selection = this.el.get_selection();
2695 var s = this.selection;
2696 if (!s.get_selected(iret)) {
2699 var tp = m.el.get_path(iret.iter).to_string();
2704 var key = m.getValue(tp, 0);
2706 var type = m.getValue(tp, 1);
2707 var skel = m.getValue(tp, 3);
2708 var etype = m.getValue(tp, 5);
2711 this.get('/MidPropTree').hideWin();
2713 if (type.toLowerCase() == 'function') {
2715 if (etype != 'events') {
2718 print("cursor_changed: ADDding to left panel model");
2719 this.get('/LeftPanel.model').add({
2727 // has dot in name, and is boolean???? this does not make sense..
2728 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2731 print("cursor_changed: ADDding to left panel model");
2732 this.get('/LeftPanel.model').add( {
2742 enable_tree_lines : true,
2743 headers_visible : false,
2745 XObject.prototype.init.call(this);
2747 var description = new Pango.FontDescription.c_new();
2748 description.set_size(8000);
2749 this.el.modify_font(description);
2751 //this.selection = this.el.get_selection();
2752 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2761 xtype: Gtk.ListStore,
2765 getValue : function(treepath, col)
2767 var tp = new Gtk.TreePath.from_string (treepath);
2769 this.el.get_iter (iret, tp);
2770 var value = this.el.get_value(iret.iter, col);
2771 return ''+ value.value.get_string();
2775 XObject.prototype.init.call(this);
2776 this.el.set_column_types ( 6, [
2777 GObject.TYPE_STRING, // real key
2778 GObject.TYPE_STRING, // real type
2779 GObject.TYPE_STRING, // docs ?
2780 GObject.TYPE_STRING, // visable desc
2781 GObject.TYPE_STRING, // function desc
2782 GObject.TYPE_STRING // element type (event|prop)
2786 showData : function(type) {
2789 this.loading = true;
2791 if (!this.get('/MidPropTree').activeElement || !type) {
2792 this.loading = false;
2793 return; // no active element
2796 var fullpath = this.get('/LeftTree.model').file.guessName(
2797 this.get('/MidPropTree').activeElement);
2798 var palete = this.get('/LeftTree').getPaleteProvider();
2802 Seed.print('Showing right?');
2803 if (!this.get('/MidPropTree').shown) {
2805 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2806 this.get('/MidPropTree').el.show();
2807 this.get('/MidPropTree').shown = true;
2810 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2811 return a.name > b.name ? 1 : -1;
2813 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2814 // console.dump(elementList);
2816 // scope of this is off..??
2819 for(var i =0 ; i < elementList.length; i++) {
2821 var p=elementList[i];
2822 this.el.append(iret);
2823 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2824 //GObject.TYPE_STRING, // real key
2825 // GObject.TYPE_STRING, // real type
2826 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2827 // GObject.TYPE_STRING // func def?
2830 this.el.set_value(iret.iter, 0, p.name);
2831 this.el.set_value(iret.iter, 1, p.type);
2832 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2833 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2834 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2835 this.el.set_value(iret.iter, 5, type);
2838 this.loading = false;
2842 xtype: Gtk.TreeViewColumn,
2845 this.el = new Gtk.TreeViewColumn();
2846 this.parent.el.append_column(this.el);
2848 XObject.prototype.init.call(this);
2849 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2853 xtype: Gtk.CellRendererText,
2854 pack : "pack_start,true"
2881 xtype: Gtk.Notebook,
2882 pack : "pack_start,true,true",
2883 id : "view-help-nb",
2885 XObject.prototype.init.call(this);
2886 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2887 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2891 xtype: Gtk.Notebook,
2892 id : "view-notebook",
2896 XObject.prototype.init.call(this);
2897 this.el.set_current_page(0);
2898 //print("SET LABEL?")
2899 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2900 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2906 id : "RightBrowser",
2911 pack : "pack_start,false,true,0",
2916 clicked : function (self) {
2917 this.get('/RightBrowser.view').renderJS(null,true);
2921 pack : "pack_start,false,false,0"
2924 xtype: Gtk.CheckButton,
2926 toggled : function (self, state) {
2927 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2932 label : "Auto Redraw On",
2933 pack : "pack_start,false,false,0"
2938 clicked : function (self) {
2940 var view = this.get('/RightBrowser.view');
2941 //this.get('/RightBrowser.view').redraws = 99;
2942 view.refreshRequired = true;
2943 view.lastRedraw = false;
2944 view.renderedData = false;
2945 view.renderJS(null,true);
2949 label : "Full Redraw",
2950 pack : "pack_start,false,false,0"
2955 xtype: Gtk.ScrolledWindow,
2958 XObject.prototype.init.call(this);
2959 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2961 shadow_type : Gtk.ShadowType.IN,
2964 xtype: WebKit.WebView,
2966 load_finished : function (self, object) {
2967 print("load finished");
2968 // print("load_finished"); return;
2969 // if (this.ready) { // dont do it twice!
2972 if (!this.inspectorShown) {
2973 this.el.get_inspector().show();
2974 this.inspectorShown = true;
2979 //if (this.pendingRedraw) {
2980 // this.pendingRedraw = false;
2981 // this.refreshRequired = true;
2983 //var js = this.get('/LeftTree.model').toJS();
2984 //if (js && js[0]) {
2985 // this.renderJS(js[0]);
2989 script_alert : function (self, object, p0) {
2992 return true; // do not display anything...
2994 console_message : function (self, object, p0, p1) {
2996 // console.log(object);
2999 if (object.match(/variable/) && object.match(/Builder/)) {
3000 print("got builder missing message");
3001 this.refreshRequired = true;
3002 this.lastRedraw = 0;
3008 if (!object.match(/^\{/)) {
3010 //this.get('/Terminal').feed(object);
3011 return true; // do not handle!!! -> later maybe in console..
3017 // console.log(object);
3018 var val = JSON.parse(object);
3020 if (typeof(val['hover-node']) != 'undefined') {
3021 this.activeNode = val['hover-node'];
3022 console.log('active node: ' + this.activeNode);
3027 if (typeof(val['id']) != 'undefined') {
3028 // this.activeNode = val['id'];
3029 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
3030 if (!tg || typeof(tg[0]) == 'undefined') {
3033 print("SELECT node " + tg[0]);
3035 this.get('/LeftTree.view').selectNode(tg[0]);
3040 if (ret && typeof(val['set']) != 'undefined') {
3041 print("console messages: ADDding to left panel model");
3043 //this.get('/LeftPanel.model').add({
3044 // key : val['set'],
3045 // val : val['value']
3047 //console.log('active node: ' + this.activeNode);
3050 //Seed.print('a:'+a);
3051 //Seed.print('b:'+b);
3052 //Seed.print('c:'+c);
3055 drag_motion : function (w, ctx, x, y, time, ud) {
3056 // console.log('DRAG MOTION');
3058 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3059 this.targetData = [];
3060 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3062 // A) find out from drag all the places that node could be dropped.
3063 var src = Gtk.drag_get_source_widget(ctx);
3064 if (!src.dropList) {
3065 Gdk.drag_status(ctx,0, time);
3068 // b) get what we are over.. (from activeNode)
3069 // tree is empty.. - list should be correct..
3070 if (!this.get('/LeftTree.model').currentTree) {
3071 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3075 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3077 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3080 Gdk.drag_status(ctx, 0,time);
3081 this.get('/LeftTree.view').highlight(false);
3085 // if we have a target..
3086 // -> highlight it! (in browser)
3087 // -> highlight it! (in tree)
3089 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3090 this.get('/LeftTree.view').highlight(tg);
3091 this.targetData = tg;
3092 // for tree we should handle this...
3095 drag_drop : function (w, ctx, x, y,time, ud) {
3096 print("TARGET: drag-drop");
3097 var is_valid_drop_site = true;
3101 ( /* will receive 'drag-data-received' signal */
3102 ctx, /* represents the current state of the DnD */
3103 Globals.atoms["STRING"], /* the target type we want */
3104 time /* time stamp */
3108 /* No target offered by source => error */
3111 return is_valid_drop_site;
3113 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3115 print("Browser: drag-data-received");
3116 var delete_selection_data = false;
3117 vardnd_success = false;
3118 /* Deal with what we are given from source */
3119 if( sel_data && sel_data.length ) {
3121 if (ctx.action == Gdk.DragAction.ASK) {
3122 /* Ask the user to move or copy, then set the ctx action. */
3125 if (ctx.action == Gdk.DragAction.MOVE) {
3126 delete_selection_data = true;
3128 var source = Gtk.drag_get_source_widget(ctx);
3130 print("Browser: source.DRAGDATA? " + source.dragData);
3131 if (this.targetData) {
3132 print(this.targetData);
3133 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3142 if (dnd_success == false)
3144 Seed.print ("DnD data transfer failed!\n");
3147 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3150 create_web_view : function (self, object) {
3151 print("CREATE WEB VIEW");
3152 return null; //new WebKit.WebView();
3159 XObject.prototype.init.call(this);
3160 // this may not work!?
3161 var settings = this.el.get_settings();
3162 settings.enable_developer_extras = true;
3164 // this was an attempt to change the url perms.. did not work..
3165 // settings.enable_file_access_from_file_uris = true;
3166 // settings.enable_offline_web_application_cache - true;
3167 // settings.enable_universal_access_from_file_uris = true;
3171 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3172 _this.get('/BottomPane.inspector').el.show();
3173 return _this.get('/BottomPane.inspector').el;
3177 // FIXME - base url of script..
3178 // we need it so some of the database features work.
3179 this.el.load_html_string( "Render not ready" ,
3180 //fixme - should be a config option!
3181 // or should we catch stuff and fix it up..
3182 'http://localhost/app.Builder/'
3186 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3188 this.el.drag_dest_set
3189 ( /* widget that will accept a drop */
3190 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3191 null, /* lists of target to support */
3192 0, /* size of list */
3193 Gdk.DragAction.COPY /* what to do with data after dropped */
3196 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3197 this.el.drag_dest_set_target_list( Globals.targetList);
3199 GLib.timeout_add_seconds(0, 1, function() {
3200 // print("run refresh?");
3207 renderJS : function(data, force) {
3209 // this is the public redraw call..
3210 // we refresh in a loop privately..
3211 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3212 if (!autodraw && !force) {
3213 print("Skipping redraw - no force, and autodraw off");
3216 this.refreshRequired = true;
3218 runRefresh : function()
3220 // this is run every 2 seconds from the init..
3224 if (!this.refreshRequired) {
3225 // print("no refresh required");
3229 if (this.lastRedraw) {
3230 // do not redraw if last redraw was less that 5 seconds ago.
3231 if (((new Date()) - this.lastRedraw) < 5000) {
3239 if (!this.get('/Window.LeftTree').getActiveFile()) {
3242 this.refreshRequired = false;
3243 // print("HTML RENDERING");
3245 this.get('/BottomPane').el.show();
3246 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3253 var js = this.get('/LeftTree.model').toJS();
3254 if (!js || !js.length) {
3263 var project = this.get('/Window.LeftTree').getActiveFile().project;
3264 //print (project.fn);
3265 // set it to non-empty.
3266 project.runhtml = project.runhtml || '';
3267 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3270 this.runhtml = this.runhtml || '';
3272 var file = this.get('/LeftTree.model').file;
3273 var items = file.items;
3274 file.items = this.get('/LeftTree.model').toJS(false, false);
3275 //file.items[0].background = false;
3276 //var p = file.parent;
3277 //file.parent = false;
3279 var js_src = file.toSourcePreview();
3280 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3281 // unless it' sforced..
3286 this.renderedData = js_src;
3289 //file.items = items;
3290 //print("send source as " + js_src);
3293 "Roo.onReady(function() {\n" +
3294 "if (" + file.name +".show) " + file.name +".show({});\n" +
3295 "Roo.XComponent.build();\n" +
3302 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3303 // then we need to reload the browser using
3304 // load_html_string..
3306 // then trigger a redraw once it's loaded..
3307 this.pendingRedraw = true;
3308 var runhtml = '<script type="text/javascript">' + "\n" ;
3309 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3310 runhtml += '</script>'+ "\n" ;
3312 this.runhtml = project.runhtml;
3313 // need to modify paths
3316 this.lastRedraw= new Date();
3317 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3318 html = html.replace('</head>',
3321 '<script type="text/javascript">' + "\n" +
3326 //print("LOAD HTML " + html);
3327 this.el.load_html_string( html ,
3328 //fixme - should be a config option!
3329 'http://localhost/app.Builder/'
3332 // should trigger load_finished! - which in truns shoudl set refresh Required;
3337 //this.renderedData = data;
3338 //var str = JSON.stringify(data) ;
3341 console.log('not loaded yet');
3343 this.lastRedraw = new Date();
3345 this.el.execute_script("Builder.render(" +
3346 JSON.stringify(js_src) +
3348 JSON.stringify(file.name) +
3351 print( "before render" + this.lastRedraw);
3352 print( "after render" + (new Date()));
3362 id : "RightGtkView",
3364 redraw : function() {
3365 this.highlightWidget = false;
3366 print("REDRAW CALLED");
3367 this.activePath = this.get('/LeftTree').getActivePath();
3368 if (this.renderedEl) {
3369 print("QUEUE DRAW CALLING");
3370 this.renderedEl.queue_draw();
3373 renderJS : function(data, withDebug)
3375 this.highlightWidget = false;
3377 this.withDebug = false;
3378 while (this.get('view').el.get_children().length) {
3379 var c = this.get('view').el.get_children()[0];
3380 this.get('view').el.remove(c);
3387 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3388 // in theory tree is actually window..
3391 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3397 this.get('view').el.set_size_request(
3398 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3400 if (this.renderedEl) {
3401 this.renderedEl.set_size_request(
3402 tree.default_width || 600,
3403 tree.default_height || 400
3406 this.get('view').el.show_all();
3411 showInWindow : function() {
3412 print("GET PROEJCT");
3413 var pr = this.get('/LeftProjectTree').getActiveProject();
3415 console.log(pr.paths);
3418 var src= this.buildJS(
3419 this.get('/LeftTree.model').toJS()[0],
3424 //var x = new imports.sandbox.Context();
3428 Seed.check_syntax('var e = ' + src);
3431 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3432 this.get('/Terminal').feed(console._dump(e)+"\n");
3434 var lines = src.split("\n");
3435 var start = Math.max(0, e.line - 10);
3436 var end = Math.min(lines.length, e.line + 10);
3437 for (var i =start ; i < end; i++) {
3439 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3442 this.get('/Terminal').feed(lines[i] + "\n");
3449 this.get('/BottomPane').el.set_current_page(1);
3450 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3451 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3452 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3454 var _top = x.get_global_object()._top;
3456 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3458 if (_top.el.popup) {
3459 _top.el.popup(null, null, null, null, 3, null);
3463 viewAdd : function(item, par)
3466 // does something similar to xobject..
3467 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3469 // pack is forced to 'false'
3470 if (item.pack===false || item.pack === 'false') { // no ;
3474 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3477 var type = item['|xns'] + '.' + item['xtype'];
3479 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3483 var ns = imports.gi[item['|xns']];
3484 var ctr = ns[item['xtype']]; // why are we using array here..?
3489 for(var k in item) {
3491 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3505 // value is a function..
3506 if (k[0] == '|' && typeof(kv) == 'string') {
3508 if (kv.match(new RegExp('function'))) {
3511 print("WASL " + k + '=' + kv);
3513 eval( 'kv = ' + kv);
3514 } catch(e) { continue; }
3517 // print(k + '=' + kv);
3519 if (k[0] == '|') { // should be boolean or number..
3521 //print(k + '=' + kv);
3524 if (k == 'show_tabs') { // force tab showing for notebooks.
3527 print(k + '=' + typeof(kv) + " : " + kv);
3531 var altctr = XObject.baseXObject({ xtype: ctr} );
3533 if (!item.pack && altctr) {
3535 print("SETTING PACK TO XObjectBase method");
3536 pack_m = altctr.prototype.pack;
3541 var el = new ctr(ctr_args);
3543 print("PACK" + item.pack);
3544 //console.dump(item.pack);
3551 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3552 if (typeof(item.pack) == 'string') {
3554 item.pack.split(',').forEach(function(e, i) {
3556 if (e == 'false') { args.push( false); return; }
3557 if (e == 'true') { args.push( true); return; }
3558 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3561 //print(args.join(","));
3563 pack_m = args.shift();
3565 pack_m = item.pack.shift();
3570 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3572 name: "ArgumentError",
3573 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3574 "ADDING : " + item.id + " " + el
3581 //console.dump(args);
3583 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3584 //Seed.print('args: ' + args.length);
3585 if (typeof(pack_m) == 'string') {
3586 par[pack_m].apply(par, args);
3587 } else if (pack_m) {
3588 pack_m.call(item, par, item);
3592 item.items = item.items || [];
3593 item.items.forEach(function(ch,n) {
3595 print ("type:" + type);
3597 print ("ch.pack:" + ch.pack);
3600 if (type == 'Gtk.Table' && ch.pack == 'add') {
3601 var c = n % item.n_columns;
3602 var r = Math.floor(n/item.n_columns);
3603 ch.pack = [ 'attach', c, c+1, r, r+1,
3604 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3605 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3606 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3607 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3611 _this.viewAdd(ch, el);
3616 // add the signal handlers.
3617 // is it a widget!?!!?
3623 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3624 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3625 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3626 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3627 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3637 widgetDragDropEvent : function() {
3638 print("WIDGET DRAGDROP");
3641 widgetDragMotionEvent : function() {
3642 print("WIDGET DRAGMOTION");
3645 widgetExposeEvent : function(w, evt, ud, item) {
3647 if (this.inRender) {
3651 if ( this.highlightWidget) {
3652 this.inRender = true;
3653 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3654 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3656 this.inRender = false;
3661 if (this.activePath != item.xtreepath) {
3665 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3666 // work out the coords of the window..
3668 var dr = widget.window;
3669 this.gc = (new Gdk.GC.c_new(dr));
3670 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3671 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3675 var r = evt.expose.area;
3676 // console.dump([r.x, r.y, r.width, r.height ] );
3678 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3679 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3680 // happens with gtkscrollview embedded stuff..
3681 var np =this.activePath.split(':');
3683 this.activePath = np.join(':');
3684 this.renderedEl.queue_draw();
3700 this.inRender = true;
3703 this.highlightWidget = widget;
3708 // print("DRAW BOX");
3709 //console.dump(this.box);
3710 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3711 this.inRender = false;
3714 widgetPressEvent : function(w,e,u,d) {
3715 if (this.get('view').pressed) {
3718 this.get('view').pressed = true;
3719 print("WIDGET PRESS " + d.xtreepath );
3720 this.get('/LeftTree.view').selectNode( d.xtreepath );
3723 widgetReleaseEvent : function() {
3724 this.get('view').pressed = false;
3730 pack : "pack_start,false,true,0",
3734 pack : "pack_start,false,false,0",
3735 label : "Run The Application",
3737 button_press_event : function (self, event) {
3738 // call render on left tree - with special option!?!
3740 //print("GET PROEJCT");
3741 var pr = this.get('/LeftProjectTree').getActiveProject();
3744 for (var i in pr.paths) {
3748 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3749 this.get('/Terminal').feed("RUN DIR:" + dir);
3752 this.get('/Terminal').el.fork_command_full(
3753 Vte.PtyFlags.DEFAULT,
3754 GLib.path_get_dirname (__script_path__) ,
3755 [ 'echo' , "hello"], //argv
3759 null, // child setupdata
3763 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3764 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3774 xtype: Gtk.ScrolledWindow,
3777 shadow_type : Gtk.ShadowType.IN,
3779 XObject.prototype.init.call(this);
3780 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3784 xtype: Gtk.EventBox,
3785 pack : "add_with_viewport",
3787 XObject.prototype.init.call(this);
3788 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3789 red: 0x9F00, green: 0xB800 , blue : 0xA800
3797 XObject.prototype.init.call(this);
3798 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3799 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3804 xtype: Gtk.EventBox,
3807 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3808 XObject.prototype.init.call(this);
3810 this.el.drag_dest_set
3811 ( /* widget that will accept a drop */
3812 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3813 null, /* lists of target to support */
3814 0, /* size of list */
3815 Gdk.DragAction.COPY /* what to do with data after dropped */
3818 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3819 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3822 getActiveNode : function(x,y)
3824 // workout what node is here..
3825 return '0'; // top..
3829 drag_motion : function (self, ctx, x, y, time) {
3831 // A) find out from drag all the places that node could be dropped.
3832 var src = Gtk.drag_get_source_widget(ctx);
3833 if (!src.dropList) {
3834 Gdk.drag_status(ctx, 0, time);
3837 // b) get what we are over.. (from activeNode)
3838 // tree is empty.. - list should be correct..
3839 if (!this.get('/LeftTree.model').currentTree) {
3840 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3844 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3845 var activeNode = this.getActiveNode(x, y);
3848 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3851 Gdk.drag_status(ctx, 0,time);
3852 this.get('/LeftTree.view').highlight(false);
3856 // if we have a target..
3857 // -> highlight it! (in browser)
3858 // -> highlight it! (in tree)
3860 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3861 this.get('/LeftTree.view').highlight(tg);
3862 this.targetData = tg;
3863 // for tree we should handle this...
3866 drag_drop : function (self,ctx, x, y, time) {
3867 Seed.print("TARGET: drag-drop");
3868 var is_valid_drop_site = true;
3872 ( /* will receive 'drag-data-received' signal */
3873 ctx, /* represents the current state of the this.gDnD */
3874 Globals.atoms["STRING"], /* the target type we want */
3875 time /* time stamp */
3879 /* No target offered by source => error */
3882 return is_valid_drop_site;
3885 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3887 Seed.print("GtkView: drag-data-received");
3888 var delete_selection_data = false;
3889 var dnd_success = false;
3890 /* Deal with what we are given from source */
3891 if( sel_data && sel_data.length ) {
3893 if (ctx.action == Gdk.DragAction.ASK) {
3894 /* Ask the user to move or copy, then set the ctx action. */
3897 if (ctx.action == Gdk.DragAction.MOVE) {
3898 delete_selection_data = true;
3900 var source = Gtk.drag_get_source_widget( ctx );
3902 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3903 if (this.targetData) {
3904 Seed.print(this.targetData);
3905 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3914 if (dnd_success == false)
3916 Seed.print ("DnD data transfer failed!\n");
3919 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3922 button_press_event : function (self, event) {
3923 this.pressed = false;
3939 xtype: Gtk.ScrolledWindow,
3944 var file = this.get('/LeftTree').getActiveFile();
3948 var activeEl = this.get('/LeftTree').getActiveElement();
3949 var xtype = file.guessName( activeEl )
3950 if (!xtype || !xtype.length) {
3953 //this.get('/Window.view-help-nb').el.set_current_page(1);
3955 // get the active element being edited.
3956 var helpurl = file.getHelpUrl(xtype);
3958 // now load the help info in the page..
3959 this.get('help-view').el.open(helpurl);
3963 xtype: WebKit.WebView,
3967 XObject.prototype.init.call(this);
3968 this.get('/Window.help-view').el.open(
3969 "http://devel.akbkhome.com/seed/");
3981 xtype: Gtk.Notebook,
3985 XObject.prototype.init.call(this);
3986 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3987 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3988 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3992 xtype: Gtk.ScrolledWindow,
3996 xtype: Vte.Terminal,
3999 feed : function(istr) {
4000 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
4001 // we should make ourselves visable!!!
4002 this.get('/BottomPane').el.show();
4003 this.get('/BottomPane').el.set_current_page(1);
4005 this.el.feed(str ,str.length);
4007 scroll_on_output : true,
4009 XObject.prototype.init.call(this);
4010 this.el.set_size (80, 1000);
4012 scrollback_lines : 1000
4017 xtype: Gtk.ScrolledWindow,
4021 xtype: WebKit.WebView,
4037 this.get('buttonbar').el.show();
4038 this.get('viewbox').el.hide();
4039 var ce = this.get('/Window.centereast').el;
4041 ce.set_position(ce.get_allocated_width() - 30);
4043 print("TRIED TO HIDE");
4046 this.get('buttonbar').el.hide();
4047 this.get('viewbox').el.show();
4048 var ce = this.get('/Window.centereast').el;
4049 print(JSON.stringify(XObject.keys(ce) ,null,4));
4050 ce.set_position(ce.get_allocated_width() - 150);
4052 // this.get('model').expanded();
4064 pack : "pack_start,false,true",
4066 clicked : function (self) {
4067 this.get('/RightPalete').show();
4074 stock : Gtk.STOCK_GOTO_FIRST,
4075 icon_size : Gtk.IconSize.MENU
4085 XObject.prototype.init.call(this);
4086 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4089 enter_notify_event : function (self, event) {
4090 this.get('/RightPalete').show();
4104 pack : "pack_start,false,true",
4113 pack : "pack_start,false,true",
4115 clicked : function (self) {
4116 this.get('/RightPalete').hide();
4123 stock : Gtk.STOCK_GOTO_LAST,
4124 icon_size : Gtk.IconSize.MENU
4131 xtype: Gtk.ScrolledWindow,
4134 XObject.prototype.init.call(this);
4135 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4136 this.el.set_size_request(-1,200);
4138 shadow_type : Gtk.ShadowType.IN,
4141 xtype: Gtk.TreeView,
4143 drag_begin : function (self, ctx) {
4144 // we could fill this in now...
4145 Seed.print('SOURCE: drag-begin');
4150 var s = this.selection;
4151 s.get_selected(iret);
4152 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4154 var pix = this.el.create_row_drag_icon ( path);
4157 if (Gtk.drag_set_icon_surface) {
4158 Gtk.drag_set_icon_surface( ctx, pix );
4160 Gtk.drag_set_icon_pixmap (ctx,
4161 pix.get_colormap(), pix, null, -10, -10);
4164 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4165 if (!this.get('/RightPalete').provider) {
4168 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4169 this.el.dragData = value;
4176 drag_data_get : function (self, drag_context, selection_data, info, time) {
4177 //Seed.print('Palete: drag-data-get: ' + target_type);
4178 if (this.el.dragData && this.el.dragData.length ) {
4179 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4183 //this.el.dragData = "TEST from source widget";
4187 drag_end : function (self, drag_context) {
4188 Seed.print('SOURCE: drag-end');
4189 this.el.dragData = false;
4190 this.el.dropList = false;
4191 this.get('/LeftTree.view').highlight(false);
4194 button_press_event : function (self, event) {
4196 if (!this.get('/Editor').save()) {
4197 // popup!! - click handled..
4204 enable_tree_lines : true,
4205 headers_visible : false,
4207 XObject.prototype.init.call(this);
4208 this.el.set_size_request(150,-1);
4209 // set_reorderable: [1]
4211 var description = new Pango.FontDescription.c_new();
4212 description.set_size(8000);
4213 this.el.modify_font(description);
4215 this.selection = this.el.get_selection();
4216 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4217 // this.selection.signal['changed'].connect(function() {
4218 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4220 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4222 this.el.drag_source_set ( /* widget will be drag-able */
4223 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4224 null, /* lists of target to support */
4225 0, /* size of list */
4226 Gdk.DragAction.COPY /* what to do with data after dropped */
4228 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4230 this.el.drag_source_set_target_list( this.get('/Window').targetList);
4231 this.el.drag_source_add_text_targets( );
4233 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4234 targets = new Gtk.TargetList();
4235 targets.add( LeftTree.atoms["STRING"], 0, 0);
4236 targets.add_text_targets( 1 );
4237 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4239 //if you want to allow text to be output elsewhere..
4240 //Gtk.drag_source_add_text_targets(this.el);
4246 xtype: Gtk.ListStore,
4249 XObject.prototype.init.call(this);
4250 this.el.set_column_types ( 2, [
4251 GObject.TYPE_STRING, // title
4252 GObject.TYPE_STRING // tip
4257 load : function(tr,iter)
4262 //console.log('Project tree load: ' + tr.length);
4264 //this.insert(citer,iter,0);
4265 for(var i =0 ; i < tr.length; i++) {
4268 this.el.append(cret);
4270 this.el.insert(cret,iter,-1);
4275 this.el.set_value(cret.iter, 0, '' + r ); // title
4277 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4278 //if (r.cn && r.cn.length) {
4279 // this.load(r.cn, citer);
4285 getValue : function (iter, col) {
4286 return this.el.get_value(iter, col).value.get_string();
4293 xtype: Gtk.TreeViewColumn,
4294 pack : "append_column",
4296 XObject.prototype.init.call(this);
4297 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4301 xtype: Gtk.CellRendererText,
4323 XObject.cache['/Window'] = Window;