3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
18 delete_event : function (self, event) {
21 destroy : function (self) {
24 show : function (self) {
26 imports.ProjectManager.ProjectManager.loadConfig();
28 print("HIDEWIN - calling MidPropTree hidewin")
29 this.get('/MidPropTree').hideWin();
30 this.get('/RightPalete').hide();
31 this.get('/BottomPane').el.hide();
32 //this.get('/Editor').el.show_all();
40 title : "Application Builder",
42 setTitle : function(str) {
43 this.el.set_title(this.title + ' - ' + str);
45 type : Gtk.WindowType.TOPLEVEL,
53 pack : "pack_start,false,false",
67 label : "New _Project",
69 activate : function (self) {
71 this.get('/EditProject').show({
72 success : function(pr) {
73 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
84 activate : function (self) {
85 var fn = this.get('/LeftProjectTree.combo').getValue();
87 this.get('/LeftProjectTree').showNoProjectSelected();
90 var pm = imports.ProjectManager.ProjectManager;
91 this.get('/DialogNewComponent').show({
92 project : pm.getByFn(fn)
98 xtype: Gtk.SeparatorMenuItem,
103 use_underline : true,
105 label : "D_elete Project",
107 activate : function (self) {
109 var fn = this.get('/LeftProjectTree').get('combo').getValue();
111 this.get('/StandardErrorDialog').show("Select a project")
114 var pm = imports.ProjectManager.ProjectManager;
115 var pr = pm.getByFn(fn);
118 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
119 pm.deleteProject(fn);
127 xtype: Gtk.SeparatorMenuItem,
134 use_underline : true,
136 activate : function (self) {
148 use_underline : true,
153 pack : "set_submenu",
158 activate : function (self) {
159 var fn = this.get('/LeftTree').getActiveFile();
161 this.get('/StandardErrorDialog').show("No File active");
165 this.get('/DialogNewComponent').show(fn);
169 label : "File _Properties",
176 activate : function (self, event) {
177 this.get('/RooProjectProperties').show();
181 label : "Modify Project HTML ",
192 use_underline : true,
196 pack : "set_submenu",
201 activate : function (self, event) {
202 var js = this.get('/LeftTree.model').toJS();
204 this.get('/RightBrowser.view').renderJS(js[0], true);
209 label : "_Redraw (Roo)",
216 activate : function (self, event)
218 /* Firefox testing for debugging..
219 - we can create a /tmp directory, and put.
220 builder.html, builder.html.js, link roojs1
221 add at the end of builder.html Roo.onload(function() {
223 if (!this.get('/Window.LeftTree').getActiveFile()) {
227 var js = this.get('/LeftTree.model').toJS();
231 var project = this.get('/Window.LeftTree').getActiveFile().project;
232 //print (project.fn);
234 project.runhtml = project.runhtml || '';
237 var File = imports.File.File;
239 var target = "/tmp/firetest"; // fixme..
240 if (!File.isDirectory(target)) {
243 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
244 if (!File.exists( target+ '/roojs1')) {
245 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
250 var html = imports.File.File.read(__script_path__ + '/../builder.html');
251 html = html.replace('</head>', project.runhtml + '</head>');
254 var jsstr = JSON.stringify(js[0], null, 4);
256 var runbuilder = '<script type="text/javascript">' + "\n" +
257 " Builder.render(" + jsstr + ");\n" +
260 html = html.replace('</body>', runbuilder + '</body>');
262 File.write( target+ '/builder.html', html);
264 this.get('/Terminal').feed("RUN DIR:" + target);
266 this.get('/Terminal').el.fork_command_full(
267 Vte.PtyFlags.DEFAULT,
273 null, // child setupdata
276 var cmd = "firefox file://" + target + "/builder.html \n";
277 this.get('/Terminal').el.feed_child(cmd, cmd.length);
281 label : "_Test in Firefox (Roo)",
292 use_underline : true,
297 pack : "set_submenu",
303 use_underline : true,
305 activate : function (self) {
306 this.get('/About').el.run();
336 Gdk.EventMask.BUTTON_MOTION_MASK
340 activate : function (self) {
341 // this does not actually expand it..
342 // that is done by GTK..
345 if (!this.get('/Editor').save()) {
346 // popup!! - click handled..
350 if (!this.el.expanded) {
358 enter_notify_event : function (self, event) {
360 this.el.expanded = !this.el.expanded;
361 //if (this.el.expanded ) {
362 this.listeners.activate.call(this);
369 label : "Select Project or File",
370 pack : "pack_start,false,true",
372 onCollapse : function() {
374 var nb = this.get('/LeftTopPanel.notebook');
375 nb.el.set_current_page(0);
377 onExpand : function() {
378 var nb = this.get('/LeftTopPanel.notebook');
379 var pm = imports.ProjectManager.ProjectManager;
382 var model = this.get('/LeftProjectTree.combomodel');
383 // print ("loading Projects?")
384 //console.dump(pm.projects);
385 model.loadData(pm.projects);
388 nb.el.set_current_page(1);
389 //pm.on('changed', function() {
390 //console.log("CAUGHT project manager change");
391 // _combo.model.loadData(pm.projects);
399 pack : "pack_start,true,true",
406 xtype: Gtk.ScrolledWindow,
409 getActiveElement : function() { // return path to actie node.
411 var path = this.getActivePath();
416 this.get('model').el.get_iter_from_string(ret, path);
418 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
420 return JSON.parse(value);
422 getActiveFile : function() {
423 return this.get('model').file;
425 getActivePath : function() {
426 var model = this.get('model');
427 var view = this.get('view');
428 if (view.selection.count_selected_rows() < 1) {
432 view.selection.get_selected(ret);
433 return ret.model.get_path(ret.iter).to_string();
435 getPaleteProvider : function() {
436 var model = this.get('model');
437 var pm = imports.ProjectManager.ProjectManager;
438 return pm.getPalete(model.file.getType());
440 getRenderer : function() {
442 switch( this.getActiveFile().getType()) {
444 return this.get('/RightBrowser.view');
446 return this.get('/RightGtkView');
452 renderView : function() {
453 var render = this.getRenderer();
454 var model = this.get('model');
456 render.renderJS(model.toJS(false,true)[0]);
458 print("NO RENDER JS METHOD?");
461 shadow_type : Gtk.ShadowType.IN,
466 button_press_event : function (self, ev) {
467 console.log("button press?");
469 if (!this.get('/Editor').save()) {
470 // popup!! - click handled..
474 if (ev.button.button != 3) {
475 print("click" + ev.button.button);
481 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
483 if (!this.get('/LeftTreeMenu').el) {
484 this.get('/LeftTreeMenu').init();
487 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
488 this.get('/LeftTreeMenu').el.show_all();
489 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
490 print("click:" + res.path.to_string());
493 drag_begin : function (self, ctx) {
494 print('SOURCE: drag-begin');
495 this.targetData = false;
496 // find what is selected in our tree...
498 this.selection.get_selected(ret);
500 // set some properties of the tree for use by the dropped element.
501 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
502 var data = JSON.parse(value);
503 var xname = this.get('/LeftTree.model').file.guessName(data);
505 this.el.dragData = xname;
506 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
509 // make the drag icon a picture of the node that was selected
510 var path = ret.model.get_path(ret.iter);
511 this.el.treepath = path.to_string();
513 // returns a cairo surface
514 var pix = this.el.create_row_drag_icon ( path);
516 if (Gtk.drag_set_icon_surface) {
517 Gtk.drag_set_icon_surface( ctx, pix );
519 Gtk.drag_set_icon_pixmap (ctx,
520 pix.get_colormap(), pix, null, -10, -10);
525 drag_end : function (self, drag_context) {
526 Seed.print('LEFT-TREE: drag-end');
527 this.el.dragData = false;
528 this.el.dropList = false;
529 this.targetData = false;
530 this.get('/LeftTree.view').highlight(false);
533 drag_data_get : function(self, ctx, sel_data, info, time)
543 drag_motion : function (self, ctx, x, y, time) {
544 console.log("LEFT-TREE: drag-motion");
545 var src = Gtk.drag_get_source_widget( ctx);
547 // a drag from elsewhere...- prevent drop..
549 print("no drag data!");
550 Gdk.drag_status(ctx, 0, time);
551 this.targetData = false;
554 var action = Gdk.DragAction.COPY;
555 if (src == this.el) {
556 // unless we are copying!!! ctl button..
557 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
561 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
562 // no children.. -- asume it's ok..
563 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
564 Gdk.drag_status(ctx, action ,time);
568 print("GETTING POS");
569 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
570 print("ISOVER? " + isOver);
572 Gdk.drag_status(ctx, 0 ,time);
573 return false; // not over apoint!?!
575 // drag node is parent of child..
576 console.log("SRC TREEPATH: " + src.treepath);
577 console.log("TARGET TREEPATH: " + data.path.to_string());
579 // nned to check a few here..
580 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
581 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
582 //Gtk.TreeViewDropPosition.AFTER
583 //Gtk.TreeViewDropPosition.BEFORE
585 if (typeof(src.treepath) != 'undefined' &&
586 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
587 print("subpath drag");
588 Gdk.drag_status( ctx, 0 ,time);
593 //print("DUMPING DATA");
594 //console.dump(data);
597 print(data.path.to_string() +' => '+ data.pos);
598 var tg = this.get('/LeftTree.model').findDropNodeByPath(
599 data.path.to_string(), src.dropList, data.pos);
601 this.get('/LeftTree.view').highlight(tg);
603 print("Can not find drop node path");
604 this.targetData = false;
605 Gdk.drag_status(ctx, 0, time);
608 print(JSON.stringify(tg,null,4));
610 this.targetData = tg;
613 Gdk.drag_status(ctx, action ,time);
617 drag_drop : function (w, ctx, x, y, time) {
618 Seed.print("TARGET: drag-drop");
619 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
621 ( /* will receive 'drag-data-received' signal */
622 ctx, /* represents the current state of the DnD */
623 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
624 time /* time stamp */
628 /* No target offered by source => error */
633 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
634 print("Tree: drag-data-received");
636 var delete_selection_data = false;
637 var dnd_success = false;
638 //print(JSON.stringify(sel_data, null,4));
639 /* Deal with what we are given from source */
641 // simce I can not be bothered to sort out
642 // drag drop = let's assume it worked...
644 if( true || (sel_data && sel_data.length )) {
646 if (ctx.action == Gdk.DragAction.ASK) {
647 /* Ask the user to move or copy, then set the ctx action. */
650 if (ctx.action == Gdk.DragAction.MOVE) {
651 //delete_selection_data = true;
654 var source = Gtk.drag_get_source_widget( ctx );
656 if (this.targetData) {
657 if (source != this.el) {
658 print("DRAG FROM ANOTHER WIDGET");
659 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
661 // drag around.. - reorder..
662 print("DRAG FROM SELF");
663 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
667 //Seed.print(this.targetData);
673 // we can send stuff to souce here...
679 if (dnd_success == false)
681 Seed.print ("DnD data transfer failed!\n");
684 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
687 cursor_changed : function (self) {
688 if (this.blockChanges) { // probably not needed..
691 var render = this.get('/LeftTree').getRenderer();
694 if (this.selection.count_selected_rows() < 1) {
695 this.get('/LeftPanel.model').load( false);
696 this.get('/MidPropTree').activeElement = false;
697 this.get('/MidPropTree').hideWin();
699 var pm = this.get('/RightPalete.model');
700 if (!this.get('/LeftTree').getPaleteProvider()) {
701 // it may not be loaded yet..
705 this.get('/LeftTree').getPaleteProvider().gatherList(
706 this.get('/LeftTree.model').listAllTypes()
709 if (render && render.redraw) {
715 //console.log('changed');
716 var s = this.selection;
721 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
722 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
724 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
727 var data = JSON.parse(value);
728 this.get('/MidPropTree').activeElement = data;
729 this.get('/MidPropTree').hideWin();
730 this.get('/LeftPanel.model').load( data);
733 // _g.button.set_label(''+value.get_string());
735 var pm =this.get('/RightPalete.model');
736 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
737 this.get('/LeftTree.model').listAllTypes()));
740 if (render && render.redraw) {
744 //Seed.print( value.get_string());
752 enable_tree_lines : true,
753 headers_visible : false,
754 highlight : function(treepath_ar) {
756 // highlighting for drag/drop
757 if (treepath_ar.length && treepath_ar[0].length ) {
758 this.el.set_drag_dest_row(
759 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
761 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
767 XObject.prototype.init.call(this);
768 var description = new Pango.FontDescription.c_new();
769 description.set_size(8000);
770 this.el.modify_font(description);
772 this.selection = this.el.get_selection();
773 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
776 // is this really needed??
777 this.selection.signal['changed'].connect(function() {
778 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
779 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
783 this.el.drag_source_set( /* widget will be drag-able */
784 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
785 null, /* lists of target to support */
786 0, /* size of list */
787 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
790 this.el.drag_source_set_target_list(imports.Builder3.Globals.targetList);
792 this.el.drag_source_add_text_targets();
793 this.el.drag_dest_set
795 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
796 null, /* lists of target to support */
797 0, /* size of list */
798 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
801 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
802 this.el.drag_dest_add_text_targets( );
804 selectNode : function(treepath_str) {
805 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
806 var tp = new Gtk.TreePath.from_string(treepath_str);
807 this.el.set_cursor(tp, null, false);
808 this.el.scroll_to_cell(tp, null, false, 0,0);
812 xtype: Gtk.TreeStore,
818 setFromNode : function(tp, n)
821 tp = this.get('/LeftTree').getActivePath();
824 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
825 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
826 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
827 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
831 changed : function( refresh) {
835 print("-------MODEL CHANGED CALLED" );
837 //this.currentTree = this.toJS(false, true)[0];
839 this.file.items = this.toJS(false, false);
840 print ("TO JS in " + ((new Date()) - d) + "ms");
841 // print("AFTER CHANGED");
842 //console.dump(this.file.items);
844 this.currentTree = this.file.items[0];
845 //console.log(this.file.toSource());
848 print("REDNER BROWSER?!");
849 this.get('/LeftTree').renderView();
851 var pm = this.get('/RightPalete.model');
852 if (!this.get('/RightPalete').provider) {
858 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
859 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
863 deleteSelected : function() {
864 this.get('/LeftTree.view').blockChanges = true;
866 var s = this.get('/LeftTree.view').selection;
867 s.get_selected(oret);
868 var path = this.el.get_path(oret.iter).to_string();
870 this.activePath= false;
873 this.activePath= false;
875 this.el.get_iter_from_string(ret, path);
876 this.el.remove(ret.iter);
878 // rebuild treemap. -- depreciated.!!
881 //this.toJS(null, true) // does not do anything?
882 this.activePath= false;
884 this.get('/LeftTree.view').blockChanges = false;
886 dropNode : function(target_data, node) {
888 // console.dump(node);
889 //print(JSON.Stringify(target_data, null, 4));
890 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
892 print("add " + tp + "@" + target_data[1] );
895 if (tp && target_data[1] < 2) { // before or after..
896 var ar = target_data[0].split(':');
898 parent = new Gtk.TreePath.from_string( ar.join(':') );
903 var aret = after ? {} : false;
907 if (parent !== false) {
908 this.el.get_iter(pret, parent);
915 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
916 this.el.get_iter(aret, after);
917 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
918 nret, pret.iter, aret.iter);
921 this.el.append(nret, pret.iter);
924 var new_path = this.el.get_path(nret.iter).to_string();
925 print("new path = " + new_path)
926 if (typeof(node) == 'string') {
927 var ar = node.split('.');
928 var xtype = ar.pop();
931 '|xns' : ar.join('.'),
934 if (target_data.length == 3 && target_data[2].length) {
935 node['*prop'] = target_data[2];
937 node = this.get('/DialogTemplateSelect').show(node);
940 // work out what kind of packing to use..
941 if (typeof(node.pack) == 'undefined' && parent !== false) {
942 var pal = this.get('/LeftTree').getPaleteProvider();
943 if (pal.name == 'Gtk') {
944 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
945 var cname = pal.guessName(node);
946 node.pack = pal.getDefaultPack(pname, cname);
957 // load children - if it has any..
960 this.load(xitems, nret.iter);
961 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
963 if (tp && (xitems || after)) {
964 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
966 // wee need to get the empty proptypes from somewhere..
968 //var olditer = this.activeIter;
969 //this.activePath = new_path;
970 print("calling changed with node data")
971 // changed actually set's the node data..
972 this.setFromNode(new_path,node);
977 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
979 //Builder.MidPropTree._model.load(node);
980 //Builder.MidPropTree._win.hideWin();
981 //Builder.LeftPanel._model.load( node);
985 findDropNode : function(treepath_str, targets) {
987 // this is used by the dragdrop code in the roo version AFAIR..
989 var path = treepath_str.replace(/^builder-/, '');
990 // treemap is depreciated... - should really check if model has any entries..
992 if (!this.el.iter_n_children(null)) {
994 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
996 print("FIND treepath: " + path);
997 //console.dump(this.treemap);
999 if (!treepath_str.match(/^builder-/)) {
1000 return []; // nothing!
1002 if (targets === true) {
1005 return this.findDropNodeByPath(path,targets)
1007 findDropNodeByPath : function(treepath_str, targets, pref) {
1008 var path = treepath_str + ''; // dupe it..
1009 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1011 //console.dump(this.treemap);
1012 while (path.length) {
1013 print("LOOKING FOR PATH: " + path);
1014 var node_data = this.singleNodeToJS(path);
1015 if (node_data === false) {
1016 print("node not found");
1020 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1023 targets.forEach(function(tg) {
1027 if ((tg == xname) ) {
1030 if (tg.indexOf(xname +':') === 0) {
1032 prop = tg.split(':').pop();
1037 if (last) { // pref is after/before..
1038 // then it's after last
1040 return []; // do not allow..
1042 return [ last, pref , prop];
1045 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1047 var par = path.split(':');
1050 path = par.join(':');
1056 getIterValue : function (iter, col) {
1058 var gval = ''+this.el.get_value(iter, col).value.get_string();
1064 GObject.TYPE_STRING, // title
1065 GObject.TYPE_STRING, // tip
1066 GObject.TYPE_STRING // source..
1071 listAllTypes : function() {
1072 var s = this.get('/LeftTree.view').selection;
1073 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1075 if (s.count_selected_rows() > 0) {
1077 s.get_selected(ret);
1079 // set some properties of the tree for use by the dropped element.
1080 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1081 var data = JSON.parse(value);
1084 var xname = this.get('/LeftTree.model').file.guessName(data);
1085 console.log('selected:' + xname);
1089 return []; // could not find it..
1098 for (var i =0 ; i < li.length; i++ ) {
1101 // this is specific to roo!!!?
1102 if (!el) { // skip empty?
1105 var fullpath = _this.file.guessName(el);
1106 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1111 if (el.items && el.items.length) {
1120 addall([this.currentTree]);
1122 // only if we have nothing, should we add '*top'
1126 //console.log('all types in tree');
1127 //console.dump(ret);
1132 load : function(tr,iter)
1134 //this.insert(citer,iter,0);
1136 for(var i =0 ; i < tr.length; i++) {
1139 this.el.insert(ret ,iter,-1);
1141 this.el.append(ret);
1143 //print(JSON.stringify(ret,null,4));
1144 //print('call nodeToJSON: ' + tr[i]);
1145 var body = this.nodeToJSON(tr[i]);
1147 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1148 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1149 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1150 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1151 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1152 this.el.set_value(ret.iter, 2, '' + body );
1153 if (tr[i].items && tr[i].items.length) {
1154 this.load(tr[i].items, ret.iter);
1158 loadFile : function(f) {
1165 console.log('missing file');
1169 // load the file if not loaded..
1170 if (f.items === false) {
1172 f.loadItems(function() {
1178 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1180 if (f.items.length && typeof(f.items[0]) == 'string') {
1182 //this.get('/RightEditor').el.show();
1183 //this.get('/RightEditor.view').load( f.items[0]);
1187 //print(JSON.stringify(f.items, null,4));
1188 //console.dump(f.items);
1190 this.get('/LeftTree.view').el.expand_all();
1192 if (!f.items.length) {
1195 this.get('/Window.leftvpaned').el.set_position(80);
1197 this.get('/LeftTree.view').el.set_cursor(
1198 new Gtk.TreePath.from_string('0'), null, false);
1202 this.get('/Window.leftvpaned').el.set_position(200);
1205 //return; -- debuggin
1206 //print("hide right editior");
1207 //this.get('/RightEditor').el.hide();
1208 this.get('/Editor').el.hide();
1209 print("set current tree");
1211 this.currentTree = this.toJS(false, false)[0];
1214 //console.dump(this.currentTree);
1215 this.currentTree = this.currentTree || { items: [] };
1216 this.get('/LeftTree').renderView();
1217 // console.dump(this.map);
1218 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1219 var pm = this.get('/RightPalete.model');
1220 // set up provider..
1222 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1224 if (!this.get('/RightPalete').provider) {
1225 print ("********* PALETE PROVIDER MISSING?!!");
1227 this.get('/LeftTree').renderView();
1229 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1233 this.get('/Window.view-notebook').el.set_current_page(
1234 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1237 moveNode : function(target_data, action) {
1238 //print("MOVE NODE");
1239 // console.dump(target_data);
1241 var s = this.get('/LeftTree.view').selection;
1242 s.get_selected( oret);
1243 var node = this.nodeToJS(oret.iter,false);
1244 //console.dump(node);
1245 print(JSON.stringify(node, null,4));
1247 // needs to drop first, otherwise the target_data
1248 // treepath will be invalid.
1250 this.dropNode(target_data, node);
1251 if (action & Gdk.DragAction.MOVE) {
1252 // print("REMOVING OLD NODE");
1253 this.el.remove(oret.iter);
1257 this.activePath= false;
1260 nodeTip : function(c) {
1261 var ret = this.nodeTitle(c,true);
1267 if (!i.length || i[0] != '|') {
1273 if (typeof(c[i]) != 'string') {
1276 //print("prop : " + i + ':' + c[i]);
1277 if (!c[i].match(new RegExp('function'))) {
1280 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1284 ret+="\n\nMethods:" + funcs;
1289 nodeTitle : function(c, renderfull) {
1292 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1293 if (sr) txt.push('<s>');
1294 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1296 if (renderfull && c['|xns']) {
1297 txt.push(c['|xns']);
1300 if (c.xtype) { txt.push(c.xtype); }
1301 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1302 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1303 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1306 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1307 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1308 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1309 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1310 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1311 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1312 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1313 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1314 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1316 // for flat classes...
1317 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1318 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1321 if (sr) txt.push('</s>');
1322 return (txt.length == 0 ? "Element" : txt.join(" "));
1324 nodeToJS : function (treepath, with_id)
1326 //print("nodeToJS : WITHID: "+ with_id);
1327 var iter = treepath; // API used to be iter here..
1328 if (typeof(iter) == 'string') {
1330 if (!this.el.get_iter(ret,
1331 new Gtk.TreePath.from_string(treepath))) {
1337 var iv = this.getIterValue(iter, 2);
1338 // print("IV" + iv);
1339 var k = JSON.parse(iv);
1340 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1345 var treepath_str = this.el.get_path(iter).to_string();
1346 // not sure how we can handle mixed id stuff..
1347 if (typeof(k.id) == 'undefined') {
1348 k.id = 'builder-'+ treepath_str ;
1352 this.treemap[ treepath_str ] = k;
1353 k.xtreepath = treepath_str ;
1356 if (this.el.iter_has_child(iter)) {
1358 this.el.iter_children(cret, iter);
1359 k.items = this.toJS(cret.iter,with_id);
1363 nodeToJSON : function(c) {
1371 return JSON.stringify(o);
1373 singleNodeToJS : function (treepath)
1376 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1380 var iv = this.getIterValue(ret.iter, 2);
1382 return JSON.parse(iv);
1385 toJS : function(treepath, with_id)
1387 //print("toJS : WITHID: "+ with_id);
1389 var iter = treepath; // API used to be iter here..
1391 if (typeof(iter) == 'string') {
1393 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1405 if (!this.el.get_iter_first(ret)) {
1416 var k = this.nodeToJS(iter, with_id);
1420 if (!this.el.iter_next(iter)) {
1425 if (treepath === false) {
1427 return JSON.parse(JSON.stringify(ar));
1431 // convert the list into a json string..
1437 xtype: Gtk.TreeViewColumn,
1438 pack : "append_column",
1440 XObject.prototype.init.call(this);
1441 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1445 xtype: Gtk.CellRendererText,
1455 id : "LeftTreeMenu",
1458 xtype: Gtk.MenuItem,
1460 label : "Delete Element",
1462 activate : function (self) {
1464 this.get('/LeftTree.model').deleteSelected();
1469 xtype: Gtk.MenuItem,
1471 activate : function (self) {
1473 var tree = this.get('/LeftTree');
1474 var model = this.get('/LeftTree.model');
1475 var el = tree.getActivePath();
1477 var js = model.toJS(el, false);
1478 // print(JSON.stringify(js[0], null,4));
1479 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1484 label : "Save as Template",
1494 id : "LeftProjectTree",
1495 showNoProjectSelected : function() {
1496 this.get('/StandardErrorDialog').show("Select a Project first.");
1498 getActiveProject : function() {
1499 return this.project;
1502 leave_notify_event : function (self, event) {
1509 pack : "pack_start,false,false",
1512 xtype: Gtk.ComboBox,
1514 changed : function (self) {
1515 var fn = this.getValue();
1516 var pm = imports.ProjectManager.ProjectManager;
1517 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1521 getValue : function() {
1522 var ix = this.el.get_active();
1526 var data = imports.ProjectManager.ProjectManager.projects;
1527 if (typeof(data[ix]) == 'undefined') {
1533 XObject.prototype.init.call(this);
1534 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1536 setValue : function(fn)
1540 var data = imports.ProjectManager.ProjectManager.projects;
1541 data.forEach(function(n, ix) {
1550 xtype: Gtk.CellRendererText,
1551 pack : "pack_start,true",
1555 xtype: Gtk.ListStore,
1560 GObject.TYPE_STRING,
1566 loadData : function(data) {
1567 var ov = this.get('/LeftProjectTree.combo').getValue();
1571 data.forEach(function(p) {
1574 //print(JSON.stringify(XObject.keys(na)));
1575 //print(typeof(na.iter));
1576 //print(JSON.stringify(iter))
1577 el.set_value(na.iter, 0, p.fn);
1578 el.set_value(na.iter, 1, p.name);
1582 this.get('/LeftProjectTree.combo').setValue(ov);
1590 xtype: Gtk.ScrolledWindow,
1592 shadow_type : Gtk.ShadowType.IN,
1594 XObject.prototype.init.call(this);
1595 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1599 xtype: Gtk.TreeView,
1602 cursor_changed : function (self) {
1604 var model = this.get('/LeftProjectTree.model');
1608 if (model.loading) {
1613 print("LOADING IS FALSE");
1615 if (this.selection.count_selected_rows() < 1) {
1616 //XN.get('Builder.LeftTree.model').
1617 this.get('/LeftTree.model').load( false);
1621 //console.log('changed');
1622 var s = this.selection;
1623 s.get_selected(ret);
1624 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1625 //console.log(JSON.stringify(value,null,4));// id..
1626 console.log("OUT?" + value);// id..
1627 var file = this.get('/LeftProjectTree').project.getById(value);
1634 var nb = this.get('/LeftTopPanel.expander');
1635 nb.el.expanded = false;
1637 //nb.listeners.activate.call(nb);
1638 //_expander.el.set_expanded(false);
1640 var ltm = this.get('/LeftTree.model');
1648 enable_tree_lines : true,
1649 headers_visible : false,
1651 XObject.prototype.init.call(this);
1652 var description = new Pango.FontDescription.c_new();
1653 description.set_size(8000);
1654 this.el.modify_font(description);
1656 this.selection = this.el.get_selection();
1657 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1661 xtype: Gtk.TreeStore,
1666 XObject.prototype.init.call(this);
1667 this.el.set_column_types ( 3, [
1668 GObject.TYPE_STRING, // title
1669 GObject.TYPE_STRING, // tip
1670 GObject.TYPE_STRING // id..
1674 loadProject : function(pr) {
1675 print("LOAD PROJECT");
1676 var model = this.get('/LeftProjectTree.model');
1677 model.loading = true;
1684 this.get('/LeftProjectTree').project = pr;
1686 this.load(pr.toTree());
1688 this.get('/LeftProjectTree.view').el.expand_all();
1689 model.loading = false;
1692 load : function(tr,iter) {
1693 // console.dump(tr);
1696 console.log('Project tree load: ' + tr.length);
1698 //this.insert(citer,iter,0);
1702 tr.forEach(function (r) {
1704 _this.el.append(cret);
1706 _this.el.insert(cret,iter,-1);
1708 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1709 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1710 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1711 if (r.cn && r.cn.length) {
1712 _this.load(r.cn, cret.iter);
1718 getValue : function(iter, col) {
1719 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1724 xtype: Gtk.TreeViewColumn,
1725 pack : "append_column",
1727 XObject.prototype.init.call(this);
1728 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1732 xtype: Gtk.CellRendererText,
1752 pack : "pack_start,false,true,0",
1759 button_press_event : function (self, event) {
1760 this.get('/MidPropTree.model').showData('props');
1772 stock : Gtk.STOCK_ADD,
1773 icon_size : Gtk.IconSize.MENU
1787 button_press_event : function (self, event) {
1789 if (!this.get('/Editor').save()) {
1790 // popup!! - click handled..
1793 this.get('/MidPropTree.model').showData('events');
1806 stock : Gtk.STOCK_ADD,
1807 icon_size : Gtk.IconSize.MENU
1821 button_press_event : function (self, ev) {
1823 if (!this.get('/Editor').save()) {
1824 // popup!! - click handled..
1828 var p = this.get('/AddPropertyPopup');
1832 p.el.set_screen(Gdk.Screen.get_default());
1834 p.el.popup(null, null, null, null, 3, ev.button.time);
1847 stock : Gtk.STOCK_ADD,
1848 icon_size : Gtk.IconSize.MENU
1860 id : "AddPropertyPopup",
1863 xtype: Gtk.MenuItem,
1865 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1868 activate : function (self) {
1870 this.get('/LeftPanel.model').add( {
1881 xtype: Gtk.MenuItem,
1883 tooltip_markup : "Add what type of packing is to be used",
1886 activate : function (self) {
1888 this.get('/LeftPanel.model').add( {
1898 xtype: Gtk.MenuItem,
1900 tooltip_markup : "Override the init method",
1903 activate : function (self) {
1905 this.get('/LeftPanel.model').add( {
1908 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1915 xtype: Gtk.SeparatorMenuItem,
1919 xtype: Gtk.MenuItem,
1921 tooltip_markup : "Add a user defined string property",
1924 activate : function (self) {
1926 this.get('/LeftPanel.model').add( {
1936 xtype: Gtk.MenuItem,
1938 tooltip_markup : "Add a user defined number property",
1941 activate : function (self) {
1943 this.get('/LeftPanel.model').add( {
1953 xtype: Gtk.MenuItem,
1955 tooltip_markup : "Add a user defined boolean property",
1958 activate : function (self) {
1960 this.get('/LeftPanel.model').add( {
1970 xtype: Gtk.SeparatorMenuItem,
1974 xtype: Gtk.MenuItem,
1976 tooltip_markup : "Add a user function boolean property",
1979 activate : function (self) {
1981 this.get('/LeftPanel.model').add( {
1984 val : "function() {\n \n}\n",
1997 xtype: Gtk.ScrolledWindow,
2002 XObject.prototype.init.call(this);
2003 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2005 shadow_type : Gtk.ShadowType.IN,
2008 xtype: Gtk.TreeView,
2010 button_press_event : function (self, ev) {
2013 if (!this.get('/Editor').save()) {
2014 // popup!! - click handled..
2019 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2020 return false; //not on a element.
2024 if (ev.button.button == 3) {
2026 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2029 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2030 var p = this.get('/LeftPanelPopup');
2035 p.el.set_screen(Gdk.Screen.get_default());
2037 p.el.popup(null, null, null, null, 3, ev.button.time);
2038 //Seed.print("click:" + res.column.title);
2045 if (res.column.title != 'value') {
2046 // XObject.error("column is not value?");
2047 return false; // ignore.. - key click.. ??? should we do this??
2050 // currently editing???
2051 // if ( this.activePath) {
2053 // this.activePath = false;
2055 if (this.get('/Editor').dirty) {
2056 //if (!this.get('/Editor.buffer').checkSyntax()) {
2057 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2061 if (!this.get('/Editor.view').save()) {
2065 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2066 this.get('/LeftPanel').editing = false;
2068 // XObject.error("Currently editing?");
2072 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2074 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2076 // get options for this type -- this is to support option lists etc..
2077 var provider = this.get('/LeftTree').getPaleteProvider();
2078 var opts = provider.findOptions(type);
2080 if (opts === false) {
2082 this.get('/LeftPanel').editableColumn.setOptions([]);
2083 renderer.has_entry = true;
2085 this.get('/LeftPanel').editableColumn.setOptions(opts);
2086 renderer.has_entry = false;
2088 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2090 //Seed.print("click" + ev.type);
2091 //console.dump(res);
2100 enable_tree_lines : true,
2101 headers_visible : false,
2103 XObject.prototype.init.call(this);
2105 this.selection = this.el.get_selection();
2106 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2109 var description = new Pango.FontDescription.c_new();
2110 description.set_size(8000);
2111 this.el.modify_font(description);
2115 xtype: Gtk.TreeStore,
2119 add : function(info) {
2120 // info includes key, val, skel, etype..
2122 type = info.type.toLowerCase();
2123 var data = this.toJS();
2125 if (info.etype == 'events') {
2126 data.listeners = data.listeners || { };
2127 if (typeof(data.listeners[info.key]) != 'undefined') {
2128 return; //already set!
2131 if (typeof(data[info.key]) != 'undefined') {
2136 if (typeof(info.val) == 'undefined') {
2139 if (info.type.toLowerCase() == 'boolean') {
2142 if (type == 'number') {
2150 if (info.etype == 'events') {
2152 data.listeners[info.key] = info.val;
2155 data[info.key] = info.val;
2159 var map = this.load(data);
2161 // flag it as changed to the interface..
2162 this.get('/LeftTree.model').setFromNode(false,node);
2163 this.get('/LeftTree.model').changed(true);
2166 this.startEditing(map[k]);
2169 LeftPanel.get('view').el.row_activated(
2170 new Gtk.TreePath.from_string(map[k]),
2171 LeftPanel.editableColumn.el
2175 changed : function(str, doRefresh) {
2176 if (!this.activePath) {
2177 print("NO active path when changed")
2181 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2183 this.el.set_value(ret.iter, 1, '' +str);
2184 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2185 var type = this.getIterValue(ret.iter, 4);
2187 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2188 // update the tree...
2189 print("new data: " + JSON.stringify(this.toJS() , null,4));
2190 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2191 this.get('/LeftTree.model').changed(doRefresh);
2194 deleteSelected : function() {
2195 var data = this.toJS();
2197 var s = this.get('/LeftPanel.view').selection;
2198 s.get_selected( ret);
2201 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2203 if (val[0] == '!') {
2205 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2208 delete data.listeners[ val.substring(1)];
2209 if (!XObject.keys(data.listeners).length) {
2210 delete data.listeners;
2214 if (typeof(data[val]) == 'undefined') {
2224 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2225 this.get('/LeftTree.model').changed(true);
2229 getIterValue : function(iter, col) {
2230 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2233 getType : function(treepath) {
2234 return this.getValue(treepath, 4);
2236 getValue : function(treepath_str, col)
2238 // get's the value in a row.. - keys - returns string, values - formats it..
2240 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2242 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2247 var type = this.getType(this.el.get_path(ret.iter).to_string());
2248 //print("TYPE: " +type + " - val:" + val);
2249 switch(type.toLowerCase()) {
2253 return parseFloat(val); // Nan ?? invalid!!?
2256 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2258 return val == 'true' ? true : false;
2260 var nv = parseFloat(val);
2261 if (!isNaN(nv) && (val == ''+nv)) {
2269 XObject.prototype.init.call(this);
2270 this.el.set_column_types ( 6, [
2271 GObject.TYPE_STRING, // 0 real key
2272 GObject.TYPE_STRING, // 1 real value
2273 GObject.TYPE_STRING, // 2 visable key
2274 GObject.TYPE_STRING, // 3 visable value
2275 GObject.TYPE_STRING, // 4 need to store type of!!!
2276 GObject.TYPE_STRING // 5 tooltip
2280 load : function(ar) {
2281 // might casue problesm..
2282 // this.get('/Editor.RightEditor').save();
2284 this.get('/Editor').el.hide();
2285 this.get('/Editor').activePath = false;
2290 //this.get('/RightEditor').el.hide();
2297 var provider = this.get('/LeftTree').getPaleteProvider();
2301 var keys = XObject.keys(ar);
2303 ar.listeners = ar.listeners || {};
2305 for (var i in ar.listeners ) {
2307 this.el.append(iret);
2308 var p = this.el.get_path(iret.iter).to_string();
2311 this.el.set_value(iret.iter, 0, '!'+ i );
2312 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2313 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2315 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2316 this.el.set_value(iret.iter, 4, 'function');
2317 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2323 keys.forEach(function(i) {
2324 if (typeof(ar[i]) == 'object') {
2328 var type = provider.findType(ar, i, ar[i]);
2330 _this.el.append(iret);
2331 var p = _this.el.get_path(iret.iter).to_string();
2333 _this.el.set_value(iret.iter, 0, ''+i);
2334 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2335 _this.el.set_value(iret.iter, 2, ''+i);
2336 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2337 _this.el.set_value(iret.iter, 4, ''+type);
2338 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2342 startEditing : function(path,col) {
2344 // alled by menu 'edit' currently..
2346 * start editing path (or selected if not set..)
2347 * @param {String|false} path (optional) treepath to edit - selected tree gets
2348 * edited by default.
2349 * @param {Number} 0 or 1 (optional)- column to edit.
2351 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2353 if (typeof(path) == 'string') {
2354 tp = new Gtk.TreePath.from_string(path);
2357 var s = this.get('/LeftPanel.view').selection;
2358 s.get_selected( itr);
2359 tp = this.el.get_path(itr.iter);
2360 path = tp.to_string();
2364 // which colum is to be edited..
2367 // not sure what this does..
2369 if (typeof(col) == 'undefined') {
2370 var k = this.getValue(path, 0);
2372 colObj = (!k.length || k == '|') ?
2373 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2375 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2378 // make sure the pulldown is set correctly..
2379 // not really needed for second col...
2380 var showEditor = false;
2381 this.get('/Editor').activePath = false;
2382 this.get('/Editor').el.hide();
2385 var provider = this.get('/LeftTree').getPaleteProvider();
2386 var type = this.get('/LeftPanel.model').getType(path);
2387 var opts = provider.findOptions(type);
2388 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2390 if (opts === false) {
2391 this.get('/LeftPanel').editableColumn.setOptions([]);
2392 renderer.has_entry = true;
2394 this.get('/LeftPanel').editableColumn.setOptions(opts);
2395 renderer.has_entry = false;/// - pulldowns do not have entries
2397 // determine if we should use the Text editor...
2398 var keyname = this.getValue(path, 0);
2399 var data_value = this.getValue(path, 1);
2401 if ((keyname[0] == '|') ||
2403 (typeof(data_value) == 'string' ) &&
2404 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2408 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2413 // this.get('/BottomPane').el.hide();
2414 //this.get('/RightEditor').el.hide();
2419 this.activePath = false;
2421 _this.get('/Editor').el.show_all();
2422 GLib.timeout_add(0, 1, function() {
2424 //_this.get('/BottomPane').el.show();
2425 //_this.get('/RightEditor').el.show();
2427 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2429 _this.get('/Editor').activePath = path;
2430 _this.activePath = path ;
2440 // iter now has row...
2441 GLib.timeout_add(0, 100, function() {
2442 _this.activePath = path;
2443 colObj.items[0].el.editable = true; // esp. need for col 0..
2444 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2455 this.get('/LeftPanel.model').el.get_iter_first(iret);
2461 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2464 ar.listeners = ar.listeners || {};
2465 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2468 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2471 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2477 //print(JSON.stringify(ar));
2481 toShort : function(str) {
2482 var a = typeof(str) == 'string' ? str.split("\n") : [];
2483 return a.length > 1 ? a[0] + '....' : '' + str;
2487 xtype: Gtk.TreeViewColumn,
2488 pack : "append_column",
2490 XObject.prototype.init.call(this);
2492 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2493 this.get('/LeftPanel').propertyColumn = this;
2498 xtype: Gtk.CellRendererText,
2499 pack : "pack_start",
2501 editing_started : function (self, editable, path) {
2503 this.get('/LeftPanel.model').activePath = path;
2506 edited : function (self, object, p0) {
2508 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2510 var model = this.get('/LeftPanel.model');
2511 var path = model.activePath;
2513 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2514 model.el.set_value(iret.iter, 0, p0);
2515 model.el.set_value(iret.iter, 2, p0);
2517 model.activePath = false;
2518 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2519 this.get('/LeftTree.model').changed(true);
2521 this.el.editable = false;
2528 xtype: Gtk.TreeViewColumn,
2529 pack : "append_column",
2532 XObject.prototype.init.call(this);
2533 this.el.add_attribute(this.items[0].el , 'text', 3 );
2534 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2535 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2536 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2538 this.get('/LeftPanel').editableColumn= this;
2540 setOptions : function(ar) {
2541 var m = this.items[0].el.model;
2544 ar.forEach(function(i) {
2548 m.set_value(iret.iter, 0, i);
2554 xtype: Gtk.CellRendererCombo,
2556 edited : function (self, object, p0) {
2558 this.get('/LeftPanel').editing = false;
2559 var ap = this.get('/LeftPanel.model').activePath
2560 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2561 this.get('/LeftPanel.model').changed(p0, true);
2562 this.get('/LeftPanel.model').activePath = false;
2563 this.el.editable = false;
2565 editing_started : function (self, editable, path) {
2566 this.get('/LeftPanel').editing = true;
2567 // console.log('editing started');
2568 // r.has_entry = false;
2570 this.el.editable = false; // make sure it's not editor...
2575 pack : "pack_start",
2579 XObject.prototype.init.call(this);
2580 this.el.model = new Gtk.ListStore();
2581 this.el.model.set_column_types ( 1, [
2582 GObject.TYPE_STRING // 0 real key
2593 id : "LeftPanelPopup",
2596 xtype: Gtk.MenuItem,
2600 activate : function (self) {
2601 this.get('/LeftPanel.model').deleteSelected();
2606 xtype: Gtk.MenuItem,
2610 activate : function (self) {
2611 this.get('/LeftPanel.model').startEditing(false, 0);
2624 xtype: Gtk.ScrolledWindow,
2625 pack : "pack_end,false,true,0",
2628 shadow_type : Gtk.ShadowType.IN,
2630 XObject.prototype.init.call(this);
2631 XObject.prototype.init.call(this);
2632 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2633 this.el.set_size_request ( 150, -1 );
2636 activeElement : false,
2637 hideWin : function() {
2640 print("HIDEWIN - currently not shown")
2645 if (this.get('/Window.left').el.position < 160) {
2646 print("HIDEWIN - small already.")
2650 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2651 print("HIDEWIN attempting to hide.")
2658 xtype: Gtk.TreeView,
2660 cursor_changed : function (self) {
2661 // this is getting fired when we are loading elements..
2662 if (this.get('/MidPropTree.model').loading) {
2668 //console.log('changed');
2669 var m = this.get('model');
2670 if (!this.selection){
2671 this.selection = this.el.get_selection();
2674 var s = this.selection;
2675 if (!s.get_selected(iret)) {
2678 var tp = m.el.get_path(iret.iter).to_string();
2683 var key = m.getValue(tp, 0);
2685 var type = m.getValue(tp, 1);
2686 var skel = m.getValue(tp, 3);
2687 var etype = m.getValue(tp, 5);
2690 this.get('/MidPropTree').hideWin();
2692 if (type.toLowerCase() == 'function') {
2694 if (etype != 'events') {
2697 print("cursor_changed: ADDding to left panel model");
2698 this.get('/LeftPanel.model').add({
2706 // has dot in name, and is boolean???? this does not make sense..
2707 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2710 print("cursor_changed: ADDding to left panel model");
2711 this.get('/LeftPanel.model').add( {
2721 enable_tree_lines : true,
2722 headers_visible : false,
2724 XObject.prototype.init.call(this);
2726 var description = new Pango.FontDescription.c_new();
2727 description.set_size(8000);
2728 this.el.modify_font(description);
2730 //this.selection = this.el.get_selection();
2731 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2740 xtype: Gtk.ListStore,
2744 getValue : function(treepath, col)
2746 var tp = new Gtk.TreePath.from_string (treepath);
2748 this.el.get_iter (iret, tp);
2749 var value = this.el.get_value(iret.iter, col);
2750 return ''+ value.value.get_string();
2754 XObject.prototype.init.call(this);
2755 this.el.set_column_types ( 6, [
2756 GObject.TYPE_STRING, // real key
2757 GObject.TYPE_STRING, // real type
2758 GObject.TYPE_STRING, // docs ?
2759 GObject.TYPE_STRING, // visable desc
2760 GObject.TYPE_STRING, // function desc
2761 GObject.TYPE_STRING // element type (event|prop)
2765 showData : function(type) {
2768 this.loading = true;
2770 if (!this.get('/MidPropTree').activeElement || !type) {
2771 this.loading = false;
2772 return; // no active element
2775 var fullpath = this.get('/LeftTree.model').file.guessName(
2776 this.get('/MidPropTree').activeElement);
2777 var palete = this.get('/LeftTree').getPaleteProvider();
2781 Seed.print('Showing right?');
2782 if (!this.get('/MidPropTree').shown) {
2784 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2785 this.get('/MidPropTree').el.show();
2786 this.get('/MidPropTree').shown = true;
2789 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2790 return a.name > b.name ? 1 : -1;
2792 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2793 // console.dump(elementList);
2795 // scope of this is off..??
2798 for(var i =0 ; i < elementList.length; i++) {
2800 var p=elementList[i];
2801 this.el.append(iret);
2802 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2803 //GObject.TYPE_STRING, // real key
2804 // GObject.TYPE_STRING, // real type
2805 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2806 // GObject.TYPE_STRING // func def?
2809 this.el.set_value(iret.iter, 0, p.name);
2810 this.el.set_value(iret.iter, 1, p.type);
2811 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2812 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2813 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2814 this.el.set_value(iret.iter, 5, type);
2817 this.loading = false;
2821 xtype: Gtk.TreeViewColumn,
2824 this.el = new Gtk.TreeViewColumn();
2825 this.parent.el.append_column(this.el);
2827 XObject.prototype.init.call(this);
2828 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2832 xtype: Gtk.CellRendererText,
2833 pack : "pack_start,true"
2860 xtype: Gtk.Notebook,
2861 pack : "pack_start,true,true",
2862 id : "view-help-nb",
2864 XObject.prototype.init.call(this);
2865 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2866 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2870 xtype: Gtk.Notebook,
2871 id : "view-notebook",
2875 XObject.prototype.init.call(this);
2876 this.el.set_current_page(0);
2877 //print("SET LABEL?")
2878 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2879 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2885 id : "RightBrowser",
2890 pack : "pack_start,false,true,0",
2895 clicked : function (self) {
2896 this.get('/RightBrowser.view').renderJS(null,true);
2900 pack : "pack_start,false,false,0"
2903 xtype: Gtk.CheckButton,
2905 toggled : function (self, state) {
2906 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2911 label : "Auto Redraw On",
2912 pack : "pack_start,false,false,0"
2917 clicked : function (self) {
2919 var view = this.get('/RightBrowser.view');
2920 //this.get('/RightBrowser.view').redraws = 99;
2921 view.refreshRequired = true;
2922 view.lastRedraw = false;
2923 view.renderedData = false;
2924 view.renderJS(null,true);
2928 label : "Full Redraw",
2929 pack : "pack_start,false,false,0"
2934 xtype: Gtk.ScrolledWindow,
2937 XObject.prototype.init.call(this);
2938 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2940 shadow_type : Gtk.ShadowType.IN,
2943 xtype: WebKit.WebView,
2945 load_finished : function (self, object) {
2946 print("load finished");
2947 // print("load_finished"); return;
2948 // if (this.ready) { // dont do it twice!
2951 if (!this.inspectorShown) {
2952 this.el.get_inspector().show();
2953 this.inspectorShown = true;
2958 //if (this.pendingRedraw) {
2959 // this.pendingRedraw = false;
2960 // this.refreshRequired = true;
2962 //var js = this.get('/LeftTree.model').toJS();
2963 //if (js && js[0]) {
2964 // this.renderJS(js[0]);
2968 script_alert : function (self, object, p0) {
2971 return true; // do not display anything...
2973 console_message : function (self, object, p0, p1) {
2975 // console.log(object);
2978 if (object.match(/variable/) && object.match(/Builder/)) {
2979 print("got builder missing message");
2980 this.refreshRequired = true;
2981 this.lastRedraw = 0;
2987 if (!object.match(/^\{/)) {
2989 //this.get('/Terminal').feed(object);
2990 return true; // do not handle!!! -> later maybe in console..
2996 // console.log(object);
2997 var val = JSON.parse(object);
2999 if (typeof(val['hover-node']) != 'undefined') {
3000 this.activeNode = val['hover-node'];
3001 console.log('active node: ' + this.activeNode);
3006 if (typeof(val['id']) != 'undefined') {
3007 // this.activeNode = val['id'];
3008 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
3009 if (!tg || typeof(tg[0]) == 'undefined') {
3012 print("SELECT node " + tg[0]);
3014 this.get('/LeftTree.view').selectNode(tg[0]);
3019 if (ret && typeof(val['set']) != 'undefined') {
3020 print("console messages: ADDding to left panel model");
3022 //this.get('/LeftPanel.model').add({
3023 // key : val['set'],
3024 // val : val['value']
3026 //console.log('active node: ' + this.activeNode);
3029 //Seed.print('a:'+a);
3030 //Seed.print('b:'+b);
3031 //Seed.print('c:'+c);
3034 drag_motion : function (w, ctx, x, y, time, ud) {
3035 // console.log('DRAG MOTION');
3037 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3038 this.targetData = [];
3039 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3041 // A) find out from drag all the places that node could be dropped.
3042 var src = Gtk.drag_get_source_widget(ctx);
3043 if (!src.dropList) {
3044 Gdk.drag_status(ctx,0, time);
3047 // b) get what we are over.. (from activeNode)
3048 // tree is empty.. - list should be correct..
3049 if (!this.get('/LeftTree.model').currentTree) {
3050 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3054 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3056 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3059 Gdk.drag_status(ctx, 0,time);
3060 this.get('/LeftTree.view').highlight(false);
3064 // if we have a target..
3065 // -> highlight it! (in browser)
3066 // -> highlight it! (in tree)
3068 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3069 this.get('/LeftTree.view').highlight(tg);
3070 this.targetData = tg;
3071 // for tree we should handle this...
3074 drag_drop : function (w, ctx, x, y,time, ud) {
3075 print("TARGET: drag-drop");
3076 var is_valid_drop_site = true;
3080 ( /* will receive 'drag-data-received' signal */
3081 ctx, /* represents the current state of the DnD */
3082 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3083 time /* time stamp */
3087 /* No target offered by source => error */
3090 return is_valid_drop_site;
3092 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3094 print("Browser: drag-data-received");
3095 var delete_selection_data = false;
3096 vardnd_success = false;
3097 /* Deal with what we are given from source */
3098 if( sel_data && sel_data.length ) {
3100 if (ctx.action == Gdk.DragAction.ASK) {
3101 /* Ask the user to move or copy, then set the ctx action. */
3104 if (ctx.action == Gdk.DragAction.MOVE) {
3105 delete_selection_data = true;
3107 var source = Gtk.drag_get_source_widget(ctx);
3109 print("Browser: source.DRAGDATA? " + source.dragData);
3110 if (this.targetData) {
3111 print(this.targetData);
3112 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3121 if (dnd_success == false)
3123 Seed.print ("DnD data transfer failed!\n");
3126 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3129 create_web_view : function (self, object) {
3130 print("CREATE WEB VIEW");
3131 return null; //new WebKit.WebView();
3138 XObject.prototype.init.call(this);
3139 // this may not work!?
3140 var settings = this.el.get_settings();
3141 settings.enable_developer_extras = true;
3143 // this was an attempt to change the url perms.. did not work..
3144 // settings.enable_file_access_from_file_uris = true;
3145 // settings.enable_offline_web_application_cache - true;
3146 // settings.enable_universal_access_from_file_uris = true;
3150 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3151 _this.get('/BottomPane.inspector').el.show();
3152 return _this.get('/BottomPane.inspector').el;
3156 // FIXME - base url of script..
3157 // we need it so some of the database features work.
3158 this.el.load_html_string( "Render not ready" ,
3159 //fixme - should be a config option!
3160 // or should we catch stuff and fix it up..
3161 'http://localhost/app.Builder/'
3165 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3167 this.el.drag_dest_set
3168 ( /* widget that will accept a drop */
3169 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3170 null, /* lists of target to support */
3171 0, /* size of list */
3172 Gdk.DragAction.COPY /* what to do with data after dropped */
3175 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3176 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3178 GLib.timeout_add_seconds(0, 1, function() {
3179 // print("run refresh?");
3186 renderJS : function(data, force) {
3188 // this is the public redraw call..
3189 // we refresh in a loop privately..
3190 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3191 if (!autodraw && !force) {
3192 print("Skipping redraw - no force, and autodraw off");
3195 this.refreshRequired = true;
3197 runRefresh : function()
3199 // this is run every 2 seconds from the init..
3203 if (!this.refreshRequired) {
3204 // print("no refresh required");
3208 if (this.lastRedraw) {
3209 // do not redraw if last redraw was less that 5 seconds ago.
3210 if (((new Date()) - this.lastRedraw) < 5000) {
3218 if (!this.get('/Window.LeftTree').getActiveFile()) {
3221 this.refreshRequired = false;
3222 // print("HTML RENDERING");
3224 this.get('/BottomPane').el.show();
3225 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3232 var js = this.get('/LeftTree.model').toJS();
3233 if (!js || !js.length) {
3242 var project = this.get('/Window.LeftTree').getActiveFile().project;
3243 //print (project.fn);
3244 // set it to non-empty.
3245 project.runhtml = project.runhtml || '';
3246 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3249 this.runhtml = this.runhtml || '';
3251 var file = this.get('/LeftTree.model').file;
3252 var items = file.items;
3253 file.items = this.get('/LeftTree.model').toJS(false, false);
3254 //file.items[0].background = false;
3255 //var p = file.parent;
3256 //file.parent = false;
3258 var js_src = file.toSourcePreview();
3259 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3260 // unless it' sforced..
3265 this.renderedData = js_src;
3268 //file.items = items;
3269 //print("send source as " + js_src);
3272 "Roo.onReady(function() {\n" +
3273 "if (" + file.name +".show) " + file.name +".show({});\n" +
3274 "Roo.XComponent.build();\n" +
3281 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3282 // then we need to reload the browser using
3283 // load_html_string..
3285 // then trigger a redraw once it's loaded..
3286 this.pendingRedraw = true;
3287 var runhtml = '<script type="text/javascript">' + "\n" ;
3288 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3289 runhtml += '</script>'+ "\n" ;
3291 this.runhtml = project.runhtml;
3292 // need to modify paths
3295 this.lastRedraw= new Date();
3296 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3297 html = html.replace('</head>',
3300 '<script type="text/javascript">' + "\n" +
3305 //print("LOAD HTML " + html);
3306 this.el.load_html_string( html ,
3307 //fixme - should be a config option!
3308 'http://localhost/app.Builder/'
3311 // should trigger load_finished! - which in truns shoudl set refresh Required;
3316 //this.renderedData = data;
3317 //var str = JSON.stringify(data) ;
3320 console.log('not loaded yet');
3322 this.lastRedraw = new Date();
3324 this.el.execute_script("Builder.render(" +
3325 JSON.stringify(js_src) +
3327 JSON.stringify(file.name) +
3330 print( "before render" + this.lastRedraw);
3331 print( "after render" + (new Date()));
3341 id : "RightGtkView",
3343 redraw : function() {
3344 this.highlightWidget = false;
3345 print("REDRAW CALLED");
3346 this.activePath = this.get('/LeftTree').getActivePath();
3347 if (this.renderedEl) {
3348 print("QUEUE DRAW CALLING");
3349 this.renderedEl.queue_draw();
3352 renderJS : function(data, withDebug)
3354 this.highlightWidget = false;
3356 this.withDebug = false;
3357 while (this.get('view').el.get_children().length) {
3358 var c = this.get('view').el.get_children()[0];
3359 this.get('view').el.remove(c);
3366 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3367 // in theory tree is actually window..
3370 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3376 this.get('view').el.set_size_request(
3377 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3379 if (this.renderedEl) {
3380 this.renderedEl.set_size_request(
3381 tree.default_width || 600,
3382 tree.default_height || 400
3385 this.get('view').el.show_all();
3390 showInWindow : function() {
3391 print("GET PROEJCT");
3392 var pr = this.get('/LeftProjectTree').getActiveProject();
3394 console.log(pr.paths);
3397 var src= this.buildJS(
3398 this.get('/LeftTree.model').toJS()[0],
3403 //var x = new imports.sandbox.Context();
3407 Seed.check_syntax('var e = ' + src);
3410 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3411 this.get('/Terminal').feed(console._dump(e)+"\n");
3413 var lines = src.split("\n");
3414 var start = Math.max(0, e.line - 10);
3415 var end = Math.min(lines.length, e.line + 10);
3416 for (var i =start ; i < end; i++) {
3418 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3421 this.get('/Terminal').feed(lines[i] + "\n");
3428 this.get('/BottomPane').el.set_current_page(1);
3429 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3430 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3431 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3433 var _top = x.get_global_object()._top;
3435 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3437 if (_top.el.popup) {
3438 _top.el.popup(null, null, null, null, 3, null);
3442 viewAdd : function(item, par)
3445 // does something similar to xobject..
3446 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3448 // pack is forced to 'false'
3449 if (item.pack===false || item.pack === 'false') { // no ;
3453 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3456 var type = item['|xns'] + '.' + item['xtype'];
3458 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3462 var ns = imports.gi[item['|xns']];
3463 var ctr = ns[item['xtype']]; // why are we using array here..?
3468 for(var k in item) {
3470 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3484 // value is a function..
3485 if (k[0] == '|' && typeof(kv) == 'string') {
3487 if (kv.match(new RegExp('function'))) {
3490 print("WASL " + k + '=' + kv);
3492 eval( 'kv = ' + kv);
3493 } catch(e) { continue; }
3496 // print(k + '=' + kv);
3498 if (k[0] == '|') { // should be boolean or number..
3500 //print(k + '=' + kv);
3503 if (k == 'show_tabs') { // force tab showing for notebooks.
3506 print(k + '=' + typeof(kv) + " : " + kv);
3510 var altctr = XObject.baseXObject({ xtype: ctr} );
3512 if (!item.pack && altctr) {
3514 print("SETTING PACK TO XObjectBase method");
3515 pack_m = altctr.prototype.pack;
3520 var el = new ctr(ctr_args);
3522 print("PACK" + item.pack);
3523 //console.dump(item.pack);
3530 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3531 if (typeof(item.pack) == 'string') {
3533 item.pack.split(',').forEach(function(e, i) {
3535 if (e == 'false') { args.push( false); return; }
3536 if (e == 'true') { args.push( true); return; }
3537 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3540 //print(args.join(","));
3542 pack_m = args.shift();
3544 pack_m = item.pack.shift();
3549 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3551 name: "ArgumentError",
3552 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3553 "ADDING : " + item.id + " " + el
3560 //console.dump(args);
3562 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3563 //Seed.print('args: ' + args.length);
3564 if (typeof(pack_m) == 'string') {
3565 par[pack_m].apply(par, args);
3566 } else if (pack_m) {
3567 pack_m.call(item, par, item);
3571 item.items = item.items || [];
3572 item.items.forEach(function(ch,n) {
3574 print ("type:" + type);
3576 print ("ch.pack:" + ch.pack);
3579 if (type == 'Gtk.Table' && ch.pack == 'add') {
3580 var c = n % item.n_columns;
3581 var r = Math.floor(n/item.n_columns);
3582 ch.pack = [ 'attach', c, c+1, r, r+1,
3583 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3584 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3585 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3586 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3590 _this.viewAdd(ch, el);
3595 // add the signal handlers.
3596 // is it a widget!?!!?
3602 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3603 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3604 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3605 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3606 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3616 widgetDragDropEvent : function() {
3617 print("WIDGET DRAGDROP");
3620 widgetDragMotionEvent : function() {
3621 print("WIDGET DRAGMOTION");
3624 widgetExposeEvent : function(w, evt, ud, item) {
3626 if (this.inRender) {
3630 if ( this.highlightWidget) {
3631 this.inRender = true;
3632 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3633 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3635 this.inRender = false;
3640 if (this.activePath != item.xtreepath) {
3644 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3645 // work out the coords of the window..
3647 var dr = widget.window;
3648 this.gc = (new Gdk.GC.c_new(dr));
3649 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3650 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3654 var r = evt.expose.area;
3655 // console.dump([r.x, r.y, r.width, r.height ] );
3657 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3658 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3659 // happens with gtkscrollview embedded stuff..
3660 var np =this.activePath.split(':');
3662 this.activePath = np.join(':');
3663 this.renderedEl.queue_draw();
3679 this.inRender = true;
3682 this.highlightWidget = widget;
3687 // print("DRAW BOX");
3688 //console.dump(this.box);
3689 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3690 this.inRender = false;
3693 widgetPressEvent : function(w,e,u,d) {
3694 if (this.get('view').pressed) {
3697 this.get('view').pressed = true;
3698 print("WIDGET PRESS " + d.xtreepath );
3699 this.get('/LeftTree.view').selectNode( d.xtreepath );
3702 widgetReleaseEvent : function() {
3703 this.get('view').pressed = false;
3709 pack : "pack_start,false,true,0",
3713 pack : "pack_start,false,false,0",
3714 label : "Run The Application",
3716 button_press_event : function (self, event) {
3717 // call render on left tree - with special option!?!
3719 //print("GET PROEJCT");
3720 var pr = this.get('/LeftProjectTree').getActiveProject();
3723 for (var i in pr.paths) {
3727 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3728 this.get('/Terminal').feed("RUN DIR:" + dir);
3731 this.get('/Terminal').el.fork_command_full(
3732 Vte.PtyFlags.DEFAULT,
3733 GLib.path_get_dirname (__script_path__) ,
3734 [ 'echo' , "hello"], //argv
3738 null, // child setupdata
3742 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3743 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3753 xtype: Gtk.ScrolledWindow,
3756 shadow_type : Gtk.ShadowType.IN,
3758 XObject.prototype.init.call(this);
3759 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3763 xtype: Gtk.EventBox,
3764 pack : "add_with_viewport",
3766 XObject.prototype.init.call(this);
3767 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3768 red: 0x9F00, green: 0xB800 , blue : 0xA800
3776 XObject.prototype.init.call(this);
3777 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3778 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3783 xtype: Gtk.EventBox,
3786 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3787 XObject.prototype.init.call(this);
3789 this.el.drag_dest_set
3790 ( /* widget that will accept a drop */
3791 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3792 null, /* lists of target to support */
3793 0, /* size of list */
3794 Gdk.DragAction.COPY /* what to do with data after dropped */
3797 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3798 this.el.drag_dest_set_target_list( imports.Builder3.Globals.targetList);
3801 getActiveNode : function(x,y)
3803 // workout what node is here..
3804 return '0'; // top..
3808 drag_motion : function (self, ctx, x, y, time) {
3810 // A) find out from drag all the places that node could be dropped.
3811 var src = Gtk.drag_get_source_widget(ctx);
3812 if (!src.dropList) {
3813 Gdk.drag_status(ctx, 0, time);
3816 // b) get what we are over.. (from activeNode)
3817 // tree is empty.. - list should be correct..
3818 if (!this.get('/LeftTree.model').currentTree) {
3819 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3823 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3824 var activeNode = this.getActiveNode(x, y);
3827 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3830 Gdk.drag_status(ctx, 0,time);
3831 this.get('/LeftTree.view').highlight(false);
3835 // if we have a target..
3836 // -> highlight it! (in browser)
3837 // -> highlight it! (in tree)
3839 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3840 this.get('/LeftTree.view').highlight(tg);
3841 this.targetData = tg;
3842 // for tree we should handle this...
3845 drag_drop : function (self,ctx, x, y, time) {
3846 Seed.print("TARGET: drag-drop");
3847 var is_valid_drop_site = true;
3851 ( /* will receive 'drag-data-received' signal */
3852 ctx, /* represents the current state of the this.gDnD */
3853 imports.Builder3.Globals.atoms["STRING"], /* the target type we want */
3854 time /* time stamp */
3858 /* No target offered by source => error */
3861 return is_valid_drop_site;
3864 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3866 Seed.print("GtkView: drag-data-received");
3867 var delete_selection_data = false;
3868 var dnd_success = false;
3869 /* Deal with what we are given from source */
3870 if( sel_data && sel_data.length ) {
3872 if (ctx.action == Gdk.DragAction.ASK) {
3873 /* Ask the user to move or copy, then set the ctx action. */
3876 if (ctx.action == Gdk.DragAction.MOVE) {
3877 delete_selection_data = true;
3879 var source = Gtk.drag_get_source_widget( ctx );
3881 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3882 if (this.targetData) {
3883 Seed.print(this.targetData);
3884 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3893 if (dnd_success == false)
3895 Seed.print ("DnD data transfer failed!\n");
3898 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3901 button_press_event : function (self, event) {
3902 this.pressed = false;
3918 xtype: Gtk.ScrolledWindow,
3923 var file = this.get('/LeftTree').getActiveFile();
3927 var activeEl = this.get('/LeftTree').getActiveElement();
3928 var xtype = file.guessName( activeEl )
3929 if (!xtype || !xtype.length) {
3932 //this.get('/Window.view-help-nb').el.set_current_page(1);
3934 // get the active element being edited.
3935 var helpurl = file.getHelpUrl(xtype);
3937 // now load the help info in the page..
3938 this.get('help-view').el.open(helpurl);
3942 xtype: WebKit.WebView,
3946 XObject.prototype.init.call(this);
3947 this.get('/Window.help-view').el.open(
3948 "http://devel.akbkhome.com/seed/");
3960 xtype: Gtk.Notebook,
3964 XObject.prototype.init.call(this);
3965 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3966 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3967 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3971 xtype: Gtk.ScrolledWindow,
3975 xtype: Vte.Terminal,
3978 feed : function(istr) {
3979 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3980 // we should make ourselves visable!!!
3981 this.get('/BottomPane').el.show();
3982 this.get('/BottomPane').el.set_current_page(1);
3984 this.el.feed(str ,str.length);
3986 scroll_on_output : true,
3988 XObject.prototype.init.call(this);
3989 this.el.set_size (80, 1000);
3991 scrollback_lines : 1000
3996 xtype: Gtk.ScrolledWindow,
4000 xtype: WebKit.WebView,
4016 this.get('buttonbar').el.show();
4017 this.get('viewbox').el.hide();
4018 var ce = this.get('/Window.centereast').el;
4020 ce.set_position(ce.get_allocated_width() - 30);
4022 print("TRIED TO HIDE");
4025 this.get('buttonbar').el.hide();
4026 this.get('viewbox').el.show();
4027 var ce = this.get('/Window.centereast').el;
4028 print(JSON.stringify(XObject.keys(ce) ,null,4));
4029 ce.set_position(ce.get_allocated_width() - 150);
4031 // this.get('model').expanded();
4043 pack : "pack_start,false,true",
4045 clicked : function (self) {
4046 this.get('/RightPalete').show();
4053 stock : Gtk.STOCK_GOTO_FIRST,
4054 icon_size : Gtk.IconSize.MENU
4064 XObject.prototype.init.call(this);
4065 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4068 enter_notify_event : function (self, event) {
4069 this.get('/RightPalete').show();
4083 pack : "pack_start,false,true",
4092 pack : "pack_start,false,true",
4094 clicked : function (self) {
4095 this.get('/RightPalete').hide();
4102 stock : Gtk.STOCK_GOTO_LAST,
4103 icon_size : Gtk.IconSize.MENU
4110 xtype: Gtk.ScrolledWindow,
4113 XObject.prototype.init.call(this);
4114 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4115 this.el.set_size_request(-1,200);
4117 shadow_type : Gtk.ShadowType.IN,
4120 xtype: Gtk.TreeView,
4122 drag_begin : function (self, ctx) {
4123 // we could fill this in now...
4124 Seed.print('SOURCE: drag-begin');
4129 var s = this.selection;
4130 s.get_selected(iret);
4131 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4133 var pix = this.el.create_row_drag_icon ( path);
4136 if (Gtk.drag_set_icon_surface) {
4137 Gtk.drag_set_icon_surface( ctx, pix );
4139 Gtk.drag_set_icon_pixmap (ctx,
4140 pix.get_colormap(), pix, null, -10, -10);
4143 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4144 if (!this.get('/RightPalete').provider) {
4147 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4148 this.el.dragData = value;
4155 drag_data_get : function (self, drag_context, selection_data, info, time) {
4156 //Seed.print('Palete: drag-data-get: ' + target_type);
4157 if (this.el.dragData && this.el.dragData.length ) {
4158 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4162 //this.el.dragData = "TEST from source widget";
4166 drag_end : function (self, drag_context) {
4167 Seed.print('SOURCE: drag-end');
4168 this.el.dragData = false;
4169 this.el.dropList = false;
4170 this.get('/LeftTree.view').highlight(false);
4173 button_press_event : function (self, event) {
4175 if (!this.get('/Editor').save()) {
4176 // popup!! - click handled..
4183 enable_tree_lines : true,
4184 headers_visible : false,
4186 XObject.prototype.init.call(this);
4187 this.el.set_size_request(150,-1);
4188 // set_reorderable: [1]
4190 var description = new Pango.FontDescription.c_new();
4191 description.set_size(8000);
4192 this.el.modify_font(description);
4194 this.selection = this.el.get_selection();
4195 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4196 // this.selection.signal['changed'].connect(function() {
4197 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4199 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4201 this.el.drag_source_set ( /* widget will be drag-able */
4202 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4203 null, /* lists of target to support */
4204 0, /* size of list */
4205 Gdk.DragAction.COPY /* what to do with data after dropped */
4207 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4209 this.el.drag_source_set_target_list( imports.Builder3.Globals.targetList);
4210 this.el.drag_source_add_text_targets( );
4212 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4213 targets = new Gtk.TargetList();
4214 targets.add( LeftTree.atoms["STRING"], 0, 0);
4215 targets.add_text_targets( 1 );
4216 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4218 //if you want to allow text to be output elsewhere..
4219 //Gtk.drag_source_add_text_targets(this.el);
4225 xtype: Gtk.ListStore,
4228 XObject.prototype.init.call(this);
4229 this.el.set_column_types ( 2, [
4230 GObject.TYPE_STRING, // title
4231 GObject.TYPE_STRING // tip
4236 load : function(tr,iter)
4241 //console.log('Project tree load: ' + tr.length);
4243 //this.insert(citer,iter,0);
4244 for(var i =0 ; i < tr.length; i++) {
4247 this.el.append(cret);
4249 this.el.insert(cret,iter,-1);
4254 this.el.set_value(cret.iter, 0, '' + r ); // title
4256 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4257 //if (r.cn && r.cn.length) {
4258 // this.load(r.cn, citer);
4264 getValue : function (iter, col) {
4265 return this.el.get_value(iter, col).value.get_string();
4272 xtype: Gtk.TreeViewColumn,
4273 pack : "append_column",
4275 XObject.prototype.init.call(this);
4276 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4280 xtype: Gtk.CellRendererText,
4302 XObject.cache['/Window'] = Window;