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 //GtkClutter = imports.gi.GtkClutter;
11 console = imports.console;
12 XObject = imports.XObject.XObject;
16 delete_event : function (self, event) {
19 destroy : function (self) {
22 show : function (self) {
24 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
26 print("HIDEWIN - calling MidPropTree hidewin")
27 this.get('/MidPropTree').hideWin();
28 this.get('/RightPalete').hide();
29 this.get('/BottomPane').el.hide();
30 //this.get('/Editor').el.show_all();
38 title : "Application Builder",
41 "STRING" : Gdk.atom_intern("STRING")
43 this.targetList = new Gtk.TargetList();
44 this.targetList.add( this.atoms["STRING"], 0, 0);
45 //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
47 "style \"gtkcombobox-style\" {\n" +
48 " GtkComboBox::appears-as-list = 1\n" +
50 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
51 XObject.prototype.init.call(this);
57 setTitle : function(str) {
58 this.el.set_title(this.title + ' - ' + str);
60 type : Gtk.WindowType.TOPLEVEL,
68 pack : "pack_start,false,false",
82 label : "New _Project",
84 activate : function (self) {
86 this.get('/EditProject').show({
87 success : function(pr) {
88 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
99 activate : function (self) {
100 var fn = this.get('/LeftProjectTree.combo').getValue();
102 this.get('/LeftProjectTree').showNoProjectSelected();
105 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
106 this.get('/DialogNewComponent').show({
107 project : pm.getByFn(fn)
113 xtype: Gtk.SeparatorMenuItem,
118 use_underline : true,
120 label : "D_elete Project",
122 activate : function (self) {
124 var fn = this.get('/LeftProjectTree').get('combo').getValue();
126 this.get('/StandardErrorDialog').show("Select a project")
129 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
130 var pr = pm.getByFn(fn);
133 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
134 pm.deleteProject(fn);
142 xtype: Gtk.SeparatorMenuItem,
149 use_underline : true,
151 activate : function (self) {
163 use_underline : true,
168 pack : "set_submenu",
173 activate : function (self) {
174 var fn = this.get('/LeftTree').getActiveFile();
176 this.get('/StandardErrorDialog').show("No File active");
180 this.get('/DialogNewComponent').show(fn);
184 label : "File _Properties",
191 activate : function (self, event) {
192 this.get('/RooProjectProperties').show();
196 label : "Modify Project HTML ",
207 use_underline : true,
211 pack : "set_submenu",
216 activate : function (self, event) {
217 var js = this.get('/LeftTree.model').toJS();
219 this.get('/RightBrowser.view').renderJS(js[0], true);
224 label : "_Redraw (Roo)",
231 activate : function (self, event)
233 /* Firefox testing for debugging..
234 - we can create a /tmp directory, and put.
235 builder.html, builder.html.js, link roojs1
236 add at the end of builder.html Roo.onload(function() {
238 if (!this.get('/Window.LeftTree').getActiveFile()) {
242 var js = this.get('/LeftTree.model').toJS();
246 var project = this.get('/Window.LeftTree').getActiveFile().project;
247 //print (project.fn);
249 project.runhtml = project.runhtml || '';
252 var File = imports.File.File;
254 var target = "/tmp/firetest"; // fixme..
255 if (!File.isDirectory(target)) {
258 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
259 if (!File.exists( target+ '/roojs1')) {
260 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
265 var html = imports.File.File.read(__script_path__ + '/../builder.html');
266 html = html.replace('</head>', project.runhtml + '</head>');
269 var jsstr = JSON.stringify(js[0], null, 4);
271 var runbuilder = '<script type="text/javascript">' + "\n" +
272 " Builder.render(" + jsstr + ");\n" +
275 html = html.replace('</body>', runbuilder + '</body>');
277 File.write( target+ '/builder.html', html);
279 this.get('/Terminal').feed("RUN DIR:" + target);
281 this.get('/Terminal').el.fork_command( null , [], [], target
282 , false,false,false);
283 var cmd = "firefox file://" + target + "/builder.html \n";
284 this.get('/Terminal').el.feed_child(cmd, cmd.length);
288 label : "_Test in Firefox (Roo)",
299 use_underline : true,
304 pack : "set_submenu",
310 use_underline : true,
312 activate : function (self) {
313 this.get('/About').el.run();
343 activate : function (self) {
344 // this does not actually expand it..
345 // that is done by GTK..
348 if (!this.get('/Editor').save()) {
349 // popup!! - click handled..
353 if (!this.el.expanded) {
361 enter_notify_event : function (self, event) {
363 this.el.expanded = !this.el.expanded;
364 //if (this.el.expanded ) {
365 this.listeners.activate.call(this);
372 label : "Select Project or File",
373 pack : "pack_start,false,true",
375 XObject.prototype.init.call(this);
376 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
378 onCollapse : function() {
380 var nb = this.get('/LeftTopPanel.notebook');
381 nb.el.set_current_page(0);
383 onExpand : function() {
384 var nb = this.get('/LeftTopPanel.notebook');
385 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
388 var model = this.get('/LeftProjectTree.combomodel');
389 // print ("loading Projects?")
390 //console.dump(pm.projects);
391 model.loadData(pm.projects);
394 nb.el.set_current_page(1);
395 //pm.on('changed', function() {
396 //console.log("CAUGHT project manager change");
397 // _combo.model.loadData(pm.projects);
405 pack : "pack_start,true,true",
407 XObject.prototype.init.call(this);
408 this.el.set_current_page(0);
415 xtype: Gtk.ScrolledWindow,
418 getActiveElement : function() { // return path to actie node.
420 var path = this.getActivePath();
425 this.get('model').el.get_iter_from_string(ret, path);
427 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
429 return JSON.parse(value);
431 getActiveFile : function() {
432 return this.get('model').file;
434 getActivePath : function() {
435 var model = this.get('model');
436 var view = this.get('view');
437 if (view.selection.count_selected_rows() < 1) {
441 view.selection.get_selected(ret);
442 return ret.model.get_path(ret.iter).to_string();
444 getPaleteProvider : function() {
445 var model = this.get('model');
446 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
447 return pm.getPalete(model.file.getType());
449 getRenderer : function() {
451 switch( this.getActiveFile().getType()) {
453 return this.get('/RightBrowser.view');
455 return this.get('/RightGtkView');
460 XObject.prototype.init.call(this);
461 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
463 renderView : function() {
464 var render = this.getRenderer();
465 var model = this.get('model');
467 render.renderJS(model.toJS(false,true)[0]);
469 print("NO RENDER JS METHOD?");
472 shadow_type : Gtk.ShadowType.IN,
477 button_press_event : function (self, ev) {
478 console.log("button press?");
480 if (!this.get('/Editor').save()) {
481 // popup!! - click handled..
485 if (ev.button.button != 3) {
486 print("click" + ev.button.button);
492 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
494 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
496 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
497 this.get('/LeftTreeMenu').el.show_all();
498 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
499 print("click:" + res.path.to_string());
502 drag_begin : function (self, ctx) {
503 print('SOURCE: drag-begin');
504 this.targetData = false;
505 // find what is selected in our tree...
507 this.selection.get_selected(ret);
509 // set some properties of the tree for use by the dropped element.
510 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
511 var data = JSON.parse(value);
512 var xname = this.get('/LeftTree.model').file.guessName(data);
514 this.el.dragData = xname;
515 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
518 // make the drag icon a picture of the node that was selected
519 var path = ret.model.get_path(ret.iter);
520 this.el.treepath = path.to_string();
522 // returns a cairo surface
523 var pix = this.el.create_row_drag_icon ( path);
525 if (Gtk.drag_set_icon_surface) {
526 Gtk.drag_set_icon_surface( ctx, pix );
528 Gtk.drag_set_icon_pixmap (ctx,
529 pix.get_colormap(), pix, null, -10, -10);
534 drag_end : function (self, drag_context) {
535 Seed.print('LEFT-TREE: drag-end');
536 this.el.dragData = false;
537 this.el.dropList = false;
538 this.targetData = false;
539 this.get('/LeftTree.view').highlight(false);
542 drag_data_get : function(self, ctx, sel_data, info, time)
552 drag_motion : function (self, ctx, x, y, time) {
553 console.log("LEFT-TREE: drag-motion");
554 var src = Gtk.drag_get_source_widget( ctx);
556 // a drag from elsewhere...- prevent drop..
558 print("no drag data!");
559 Gdk.drag_status(ctx, 0, time);
560 this.targetData = false;
563 var action = Gdk.DragAction.COPY;
564 if (src == this.el) {
565 // unless we are copying!!! ctl button..
566 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
570 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
571 // no children.. -- asume it's ok..
572 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
573 Gdk.drag_status(ctx, action ,time);
577 print("GETTING POS");
578 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
579 print("ISOVER? " + isOver);
581 Gdk.drag_status(ctx, 0 ,time);
582 return false; // not over apoint!?!
584 // drag node is parent of child..
585 console.log("SRC TREEPATH: " + src.treepath);
586 console.log("TARGET TREEPATH: " + data.path.to_string());
588 // nned to check a few here..
589 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
590 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
591 //Gtk.TreeViewDropPosition.AFTER
592 //Gtk.TreeViewDropPosition.BEFORE
594 if (typeof(src.treepath) != 'undefined' &&
595 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
596 print("subpath drag");
597 Gdk.drag_status( ctx, 0 ,time);
602 //print("DUMPING DATA");
603 //console.dump(data);
606 print(data.path.to_string() +' => '+ data.pos);
607 var tg = this.get('/LeftTree.model').findDropNodeByPath(
608 data.path.to_string(), src.dropList, data.pos);
610 this.get('/LeftTree.view').highlight(tg);
612 print("Can not find drop node path");
613 this.targetData = false;
614 Gdk.drag_status(ctx, 0, time);
617 print(JSON.stringify(tg,null,4));
619 this.targetData = tg;
622 Gdk.drag_status(ctx, action ,time);
626 drag_drop : function (w, ctx, x, y, time) {
627 Seed.print("TARGET: drag-drop");
628 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
630 ( /* will receive 'drag-data-received' signal */
631 ctx, /* represents the current state of the DnD */
632 this.get('/Window').atoms["STRING"], /* the target type we want */
633 time /* time stamp */
637 /* No target offered by source => error */
642 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
643 print("Tree: drag-data-received");
645 var delete_selection_data = false;
646 var dnd_success = false;
647 //print(JSON.stringify(sel_data, null,4));
648 /* Deal with what we are given from source */
650 // simce I can not be bothered to sort out
651 // drag drop = let's assume it worked...
653 if( true || (sel_data && sel_data.length )) {
655 if (ctx.action == Gdk.DragAction.ASK) {
656 /* Ask the user to move or copy, then set the ctx action. */
659 if (ctx.action == Gdk.DragAction.MOVE) {
660 //delete_selection_data = true;
663 var source = Gtk.drag_get_source_widget( ctx );
665 if (this.targetData) {
666 if (source != this.el) {
667 print("DRAG FROM ANOTHER WIDGET");
668 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
670 // drag around.. - reorder..
671 print("DRAG FROM SELF");
672 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
676 //Seed.print(this.targetData);
682 // we can send stuff to souce here...
688 if (dnd_success == false)
690 Seed.print ("DnD data transfer failed!\n");
693 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
696 cursor_changed : function (self) {
697 if (this.blockChanges) { // probably not needed..
700 var render = this.get('/LeftTree').getRenderer();
703 if (this.selection.count_selected_rows() < 1) {
704 this.get('/LeftPanel.model').load( false);
705 this.get('/MidPropTree').activeElement = false;
706 this.get('/MidPropTree').hideWin();
708 var pm = this.get('/RightPalete.model');
709 if (!this.get('/LeftTree').getPaleteProvider()) {
710 // it may not be loaded yet..
713 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
714 this.get('/LeftTree.model').listAllTypes()));
715 if (render && render.redraw) {
721 //console.log('changed');
722 var s = this.selection;
727 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
728 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
730 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
733 var data = JSON.parse(value);
734 this.get('/MidPropTree').activeElement = data;
735 this.get('/MidPropTree').hideWin();
736 this.get('/LeftPanel.model').load( data);
739 // _g.button.set_label(''+value.get_string());
741 var pm =this.get('/RightPalete.model');
742 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
743 this.get('/LeftTree.model').listAllTypes()));
746 if (render && render.redraw) {
750 //Seed.print( value.get_string());
758 enable_tree_lines : true,
759 headers_visible : false,
760 highlight : function(treepath_ar) {
762 // highlighting for drag/drop
763 if (treepath_ar.length && treepath_ar[0].length ) {
764 this.el.set_drag_dest_row(
765 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
767 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
773 XObject.prototype.init.call(this);
774 var description = new Pango.FontDescription.c_new();
775 description.set_size(8000);
776 this.el.modify_font(description);
778 this.selection = this.el.get_selection();
779 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
782 // is this really needed??
783 this.selection.signal['changed'].connect(function() {
784 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
785 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
789 this.el.drag_source_set( /* widget will be drag-able */
790 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
791 null, /* lists of target to support */
792 0, /* size of list */
793 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
796 this.el.drag_source_set_target_list(this.get('/Window').targetList);
798 this.el.drag_source_add_text_targets();
799 this.el.drag_dest_set
801 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
802 null, /* lists of target to support */
803 0, /* size of list */
804 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
807 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
808 this.el.drag_dest_add_text_targets( );
810 selectNode : function(treepath_str) {
811 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
812 var tp = new Gtk.TreePath.from_string(treepath_str);
813 this.el.set_cursor(tp, null, false);
814 this.el.scroll_to_cell(tp, null, false, 0,0);
818 xtype: Gtk.TreeStore,
824 setFromNode : function(tp, n)
827 tp = this.get('/LeftTree').getActivePath();
830 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
831 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
832 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
833 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
837 changed : function( refresh) {
841 print("-------MODEL CHANGED CALLED" );
843 //this.currentTree = this.toJS(false, true)[0];
845 this.file.items = this.toJS(false, false);
846 print ("TO JS in " + ((new Date()) - d) + "ms");
847 // print("AFTER CHANGED");
848 //console.dump(this.file.items);
850 this.currentTree = this.file.items[0];
851 //console.log(this.file.toSource());
854 print("REDNER BROWSER?!");
855 this.get('/LeftTree').renderView();
857 var pm = this.get('/RightPalete.model');
858 if (!this.get('/RightPalete').provider) {
864 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
865 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
869 deleteSelected : function() {
870 this.get('/LeftTree.view').blockChanges = true;
872 var s = this.get('/LeftTree.view').selection;
873 s.get_selected(oret);
874 var path = this.el.get_path(oret.iter).to_string();
876 this.activePath= false;
879 this.activePath= false;
881 this.el.get_iter_from_string(ret, path);
882 this.el.remove(ret.iter);
884 // rebuild treemap. -- depreciated.!!
887 //this.toJS(null, true) // does not do anything?
888 this.activePath= false;
890 this.get('/LeftTree.view').blockChanges = false;
892 dropNode : function(target_data, node) {
894 // console.dump(node);
895 //print(JSON.Stringify(target_data, null, 4));
896 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
898 print("add " + tp + "@" + target_data[1] );
901 if (tp && target_data[1] < 2) { // before or after..
902 var ar = target_data[0].split(':');
904 parent = new Gtk.TreePath.from_string( ar.join(':') );
909 var aret = after ? {} : false;
913 if (parent !== false) {
914 this.el.get_iter(pret, parent);
921 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
922 this.el.get_iter(aret, after);
923 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
924 nret, pret.iter, aret.iter);
927 this.el.append(nret, pret.iter);
930 var new_path = this.el.get_path(nret.iter).to_string();
931 print("new path = " + new_path)
932 if (typeof(node) == 'string') {
933 var ar = node.split('.');
934 var xtype = ar.pop();
937 '|xns' : ar.join('.'),
940 if (target_data.length == 3 && target_data[2].length) {
941 node['*prop'] = target_data[2];
943 node = this.get('/DialogTemplateSelect').show(node);
946 // work out what kind of packing to use..
947 if (typeof(node.pack) == 'undefined' && parent !== false) {
948 var pal = this.get('/LeftTree').getPaleteProvider();
949 if (pal.name == 'Gtk') {
950 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
951 var cname = pal.guessName(node);
952 node.pack = pal.getDefaultPack(pname, cname);
963 // load children - if it has any..
966 this.load(xitems, nret.iter);
967 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
969 if (tp && (xitems || after)) {
970 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
972 // wee need to get the empty proptypes from somewhere..
974 //var olditer = this.activeIter;
975 //this.activePath = new_path;
976 print("calling changed with node data")
977 // changed actually set's the node data..
978 this.setFromNode(new_path,node);
983 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
985 //Builder.MidPropTree._model.load(node);
986 //Builder.MidPropTree._win.hideWin();
987 //Builder.LeftPanel._model.load( node);
991 findDropNode : function(treepath_str, targets) {
993 // this is used by the dragdrop code in the roo version AFAIR..
995 var path = treepath_str.replace(/^builder-/, '');
996 // treemap is depreciated... - should really check if model has any entries..
998 if (!this.el.iter_n_children(null)) {
1000 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
1002 print("FIND treepath: " + path);
1003 //console.dump(this.treemap);
1005 if (!treepath_str.match(/^builder-/)) {
1006 return []; // nothing!
1008 if (targets === true) {
1011 return this.findDropNodeByPath(path,targets)
1013 findDropNodeByPath : function(treepath_str, targets, pref) {
1014 var path = treepath_str + ''; // dupe it..
1015 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1017 //console.dump(this.treemap);
1018 while (path.length) {
1019 print("LOOKING FOR PATH: " + path);
1020 var node_data = this.singleNodeToJS(path);
1021 if (node_data === false) {
1022 print("node not found");
1026 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1029 targets.forEach(function(tg) {
1033 if ((tg == xname) ) {
1036 if (tg.indexOf(xname +':') === 0) {
1038 prop = tg.split(':').pop();
1043 if (last) { // pref is after/before..
1044 // then it's after last
1046 return []; // do not allow..
1048 return [ last, pref , prop];
1051 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1053 var par = path.split(':');
1056 path = par.join(':');
1062 getIterValue : function (iter, col) {
1064 var gval = ''+this.el.get_value(iter, col).value.get_string();
1070 XObject.prototype.init.call(this);
1071 this.el.set_column_types ( 3, [
1072 GObject.TYPE_STRING, // title
1073 GObject.TYPE_STRING, // tip
1074 GObject.TYPE_STRING // source..
1077 listAllTypes : function() {
1078 var s = this.get('/LeftTree.view').selection;
1079 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1081 if (s.count_selected_rows() > 0) {
1083 s.get_selected(ret);
1085 // set some properties of the tree for use by the dropped element.
1086 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1087 var data = JSON.parse(value);
1090 var xname = this.get('/LeftTree.model').file.guessName(data);
1091 console.log('selected:' + xname);
1095 return []; // could not find it..
1103 li.forEach(function(el) {
1104 // this is specific to roo!!!?
1105 if (!el) { // skip empty?
1108 var fullpath = _this.file.guessName(el);
1109 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1114 if (el.items && el.items.length) {
1123 addall([this.currentTree]);
1125 // only if we have nothing, should we add '*top'
1129 //console.log('all types in tree');
1130 //console.dump(ret);
1135 load : function(tr,iter)
1137 //this.insert(citer,iter,0);
1139 for(var i =0 ; i < tr.length; i++) {
1142 this.el.insert(ret ,iter,-1);
1144 this.el.append(ret);
1146 print(JSON.stringify(ret,null,4));
1147 print('call nodeToJSON: ' + tr[i]);
1148 var body = this.nodeToJSON(tr[i]);
1150 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1151 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1152 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1153 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1154 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1155 this.el.set_value(ret.iter, 2, '' + body );
1156 if (tr[i].items && tr[i].items.length) {
1157 this.load(tr[i].items, ret.iter);
1161 loadFile : function(f) {
1167 console.log('missing file');
1171 // load the file if not loaded..
1172 if (f.items === false) {
1174 f.loadItems(function() {
1180 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1182 if (f.items.length && typeof(f.items[0]) == 'string') {
1184 //this.get('/RightEditor').el.show();
1185 //this.get('/RightEditor.view').load( f.items[0]);
1189 print(JSON.stringify(f.items, null,4));
1190 //console.dump(f.items);
1192 this.get('/LeftTree.view').el.expand_all();
1194 if (!f.items.length) {
1197 this.get('/Window.leftvpaned').el.set_position(80);
1199 this.get('/LeftTree.view').el.set_cursor(
1200 new Gtk.TreePath.from_string('0'), null, false);
1204 this.get('/Window.leftvpaned').el.set_position(200);
1207 //return; -- debuggin
1208 //print("hide right editior");
1209 //this.get('/RightEditor').el.hide();
1210 this.get('/Editor').el.hide();
1211 print("set current tree");
1212 this.currentTree = this.toJS(false, false)[0];
1213 console.dump(this.currentTree);
1214 this.currentTree = this.currentTree || { items: [] };
1215 this.get('/LeftTree').renderView();
1216 console.dump(this.map);
1217 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1218 var pm = this.get('/RightPalete.model');
1219 // set up provider..
1221 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1223 if (!this.get('/RightPalete').provider) {
1224 print ("********* PALETE PROVIDER MISSING?!!");
1226 this.get('/LeftTree').renderView();
1228 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1232 this.get('/Window.view-notebook').el.set_current_page(
1233 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1236 moveNode : function(target_data, action) {
1237 //print("MOVE NODE");
1238 // console.dump(target_data);
1240 var s = this.get('/LeftTree.view').selection;
1241 s.get_selected( oret);
1242 var node = this.nodeToJS(oret.iter,false);
1243 //console.dump(node);
1244 print(JSON.stringify(node, null,4));
1246 // needs to drop first, otherwise the target_data
1247 // treepath will be invalid.
1249 this.dropNode(target_data, node);
1250 if (action & Gdk.DragAction.MOVE) {
1251 // print("REMOVING OLD NODE");
1252 this.el.remove(oret.iter);
1256 this.activePath= false;
1259 nodeTip : function(c) {
1260 var ret = this.nodeTitle(c,true);
1266 if (!i.length || i[0] != '|') {
1272 if (typeof(c[i]) != 'string') {
1275 //print("prop : " + i + ':' + c[i]);
1276 if (!c[i].match(new RegExp('function'))) {
1279 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1283 ret+="\n\nMethods:" + funcs;
1288 nodeTitle : function(c, renderfull) {
1291 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1292 if (sr) txt.push('<s>');
1293 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1295 if (renderfull && c['|xns']) {
1296 txt.push(c['|xns']);
1299 if (c.xtype) { txt.push(c.xtype); }
1300 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1301 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1302 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1305 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1306 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1307 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1308 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1309 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1310 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1311 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1312 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1313 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1315 // for flat classes...
1316 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1317 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1320 if (sr) txt.push('</s>');
1321 return (txt.length == 0 ? "Element" : txt.join(" "));
1323 nodeToJS : function (treepath, with_id)
1325 print("nodeToJS : WITHID: "+ with_id);
1326 var iter = treepath; // API used to be iter here..
1327 if (typeof(iter) == 'string') {
1329 if (!this.el.get_iter(ret,
1330 new Gtk.TreePath.from_string(treepath))) {
1336 var iv = this.getIterValue(iter, 2);
1337 // print("IV" + iv);
1338 var k = JSON.parse(iv);
1339 if (k.json && !this.el.iter_parent( pret, iter )) {
1344 var treepath_str = this.el.get_path(iter).to_string();
1345 // not sure how we can handle mixed id stuff..
1346 if (typeof(k.id) == 'undefined') {
1347 k.id = 'builder-'+ treepath_str ;
1351 this.treemap[ treepath_str ] = k;
1352 k.xtreepath = treepath_str ;
1355 if (this.el.iter_has_child(iter)) {
1357 this.el.iter_children(cret, iter);
1358 k.items = this.toJS(cret.iter,with_id);
1362 nodeToJSON : function(c) {
1370 return JSON.stringify(o);
1372 singleNodeToJS : function (treepath)
1375 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1379 var iv = this.getIterValue(ret.iter, 2);
1381 return JSON.parse(iv);
1384 toJS : function(treepath, with_id)
1386 print("toJS : WITHID: "+ with_id);
1387 var iter = treepath; // API used to be iter here..
1388 if (typeof(iter) == 'string') {
1390 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1400 if (!this.el.get_iter_first(ret)) {
1411 var k = this.nodeToJS(iter, with_id);
1415 if (!this.el.iter_next(iter)) {
1420 if (treepath === false) {
1422 return JSON.parse(JSON.stringify(ar));
1426 // convert the list into a json string..
1432 xtype: Gtk.TreeViewColumn,
1433 pack : "append_column",
1435 XObject.prototype.init.call(this);
1436 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1440 xtype: Gtk.CellRendererText,
1450 id : "LeftTreeMenu",
1453 xtype: Gtk.MenuItem,
1455 label : "Delete Element",
1457 activate : function (self) {
1459 this.get('/LeftTree.model').deleteSelected();
1464 xtype: Gtk.MenuItem,
1466 activate : function (self) {
1468 var tree = this.get('/LeftTree');
1469 var model = this.get('/LeftTree.model');
1470 var el = tree.getActivePath();
1472 var js = model.toJS(el, false);
1473 // print(JSON.stringify(js[0], null,4));
1474 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1479 label : "Save as Template",
1489 id : "LeftProjectTree",
1490 showNoProjectSelected : function() {
1491 this.get('/StandardErrorDialog').show("Select a Project first.");
1493 getActiveProject : function() {
1494 return this.project;
1497 leave_notify_event : function (self, event) {
1504 pack : "pack_start,false,false",
1507 xtype: Gtk.ComboBox,
1509 changed : function (self) {
1510 var fn = this.getValue();
1511 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1512 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1516 getValue : function() {
1517 var ix = this.el.get_active();
1521 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1522 if (typeof(data[ix]) == 'undefined') {
1528 XObject.prototype.init.call(this);
1529 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1531 setValue : function(fn)
1535 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1536 data.forEach(function(n, ix) {
1545 xtype: Gtk.CellRendererText,
1546 pack : "pack_start,true",
1550 xtype: Gtk.ListStore,
1554 XObject.prototype.init.call(this);
1555 this.el.set_column_types ( 2, [
1556 GObject.TYPE_STRING, // real key
1557 GObject.TYPE_STRING // real type
1561 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1562 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1564 pm.on('changed', function() {
1565 print("caught changed hook on project manager - reloading data");
1566 _this.loadData(pm.projects);
1570 loadData : function(data) {
1571 var ov = this.get('/LeftProjectTree.combo').getValue();
1575 data.forEach(function(p) {
1578 print(JSON.stringify(XObject.keys(na)));
1579 print(typeof(na.iter));
1580 //print(JSON.stringify(iter))
1581 el.set_value(na.iter, 0, p.fn);
1582 el.set_value(na.iter, 1, p.name);
1586 this.get('/LeftProjectTree.combo').setValue(ov);
1594 xtype: Gtk.ScrolledWindow,
1596 shadow_type : Gtk.ShadowType.IN,
1598 XObject.prototype.init.call(this);
1599 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1603 xtype: Gtk.TreeView,
1605 cursor_changed : function (self) {
1607 if (this.selection.count_selected_rows() < 1) {
1608 //XN.get('Builder.LeftTree.model').
1609 this.get('/LeftTree.model').load( false);
1613 var model = this.get('/LeftProjectTree.model');
1614 //console.log('changed');
1615 var s = this.selection;
1616 s.get_selected(ret);
1617 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1618 //console.log(JSON.stringify(value,null,4));// id..
1619 console.log("OUT?" + value);// id..
1620 var file = this.get('/LeftProjectTree').project.getById(value);
1627 var nb = this.get('/LeftTopPanel.expander');
1628 nb.el.expanded = false;
1630 //nb.listeners.activate.call(nb);
1631 //_expander.el.set_expanded(false);
1633 var ltm = this.get('/LeftTree.model');
1641 enable_tree_lines : true,
1642 headers_visible : false,
1644 XObject.prototype.init.call(this);
1645 var description = new Pango.FontDescription.c_new();
1646 description.set_size(8000);
1647 this.el.modify_font(description);
1649 this.selection = this.el.get_selection();
1650 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1654 xtype: Gtk.TreeStore,
1658 XObject.prototype.init.call(this);
1659 this.el.set_column_types ( 3, [
1660 GObject.TYPE_STRING, // title
1661 GObject.TYPE_STRING, // tip
1662 GObject.TYPE_STRING // id..
1666 loadProject : function(pr) {
1667 print("LOAD PROJECT");
1673 this.get('/LeftProjectTree').project = pr;
1674 this.load(pr.toTree());
1675 this.get('/LeftProjectTree.view').el.expand_all();
1677 load : function(tr,iter) {
1678 // console.dump(tr);
1679 console.log('Project tree load: ' + tr.length);
1681 //this.insert(citer,iter,0);
1684 tr.forEach(function (r) {
1686 _this.el.append(cret);
1688 _this.el.insert(cret,iter,-1);
1690 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1691 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1692 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1693 if (r.cn && r.cn.length) {
1694 _this.load(r.cn, cret.iter);
1699 getValue : function(iter, col) {
1700 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1705 xtype: Gtk.TreeViewColumn,
1706 pack : "append_column",
1708 XObject.prototype.init.call(this);
1709 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1713 xtype: Gtk.CellRendererText,
1733 pack : "pack_start,false,true,0",
1740 button_press_event : function (self, event) {
1741 this.get('/MidPropTree.model').showData('props');
1753 stock : Gtk.STOCK_ADD,
1754 icon_size : Gtk.IconSize.MENU
1768 button_press_event : function (self, event) {
1770 if (!this.get('/Editor').save()) {
1771 // popup!! - click handled..
1774 this.get('/MidPropTree.model').showData('events');
1787 stock : Gtk.STOCK_ADD,
1788 icon_size : Gtk.IconSize.MENU
1802 button_press_event : function (self, ev) {
1804 if (!this.get('/Editor').save()) {
1805 // popup!! - click handled..
1809 var p = this.get('/AddPropertyPopup');
1813 p.el.set_screen(Gdk.Screen.get_default());
1815 p.el.popup(null, null, null, null, 3, ev.button.time);
1828 stock : Gtk.STOCK_ADD,
1829 icon_size : Gtk.IconSize.MENU
1841 id : "AddPropertyPopup",
1844 xtype: Gtk.MenuItem,
1846 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1849 activate : function (self) {
1851 this.get('/LeftPanel.model').add( {
1862 xtype: Gtk.MenuItem,
1864 tooltip_markup : "Add what type of packing is to be used",
1867 activate : function (self) {
1869 this.get('/LeftPanel.model').add( {
1879 xtype: Gtk.MenuItem,
1881 tooltip_markup : "Override the init method",
1884 activate : function (self) {
1886 this.get('/LeftPanel.model').add( {
1889 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1896 xtype: Gtk.SeparatorMenuItem,
1900 xtype: Gtk.MenuItem,
1902 tooltip_markup : "Add a user defined string property",
1905 activate : function (self) {
1907 this.get('/LeftPanel.model').add( {
1917 xtype: Gtk.MenuItem,
1919 tooltip_markup : "Add a user defined number property",
1922 activate : function (self) {
1924 this.get('/LeftPanel.model').add( {
1934 xtype: Gtk.MenuItem,
1936 tooltip_markup : "Add a user defined boolean property",
1939 activate : function (self) {
1941 this.get('/LeftPanel.model').add( {
1951 xtype: Gtk.SeparatorMenuItem,
1955 xtype: Gtk.MenuItem,
1957 tooltip_markup : "Add a user function boolean property",
1960 activate : function (self) {
1962 this.get('/LeftPanel.model').add( {
1965 val : "function() {\n \n}\n",
1978 xtype: Gtk.ScrolledWindow,
1983 XObject.prototype.init.call(this);
1984 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1986 shadow_type : Gtk.ShadowType.IN,
1989 xtype: Gtk.TreeView,
1991 button_press_event : function (self, ev) {
1994 if (!this.get('/Editor').save()) {
1995 // popup!! - click handled..
2000 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2001 return false; //not on a element.
2005 if (ev.button.button == 3) {
2007 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2010 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2011 var p = this.get('/LeftPanelPopup');
2016 p.el.set_screen(Gdk.Screen.get_default());
2018 p.el.popup(null, null, null, null, 3, ev.button.time);
2019 //Seed.print("click:" + res.column.title);
2026 if (res.column.title != 'value') {
2027 // XObject.error("column is not value?");
2028 return false; // ignore.. - key click.. ??? should we do this??
2031 // currently editing???
2032 // if ( this.activePath) {
2034 // this.activePath = false;
2036 if (this.get('/Editor').dirty) {
2037 //if (!this.get('/Editor.buffer').checkSyntax()) {
2038 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2042 if (!this.get('/Editor.view').save()) {
2046 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2047 this.get('/LeftPanel').editing = false;
2049 // XObject.error("Currently editing?");
2053 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2055 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2057 // get options for this type -- this is to support option lists etc..
2058 var provider = this.get('/LeftTree').getPaleteProvider();
2059 var opts = provider.findOptions(type);
2061 if (opts === false) {
2063 this.get('/LeftPanel').editableColumn.setOptions([]);
2064 renderer.has_entry = true;
2066 this.get('/LeftPanel').editableColumn.setOptions(opts);
2067 renderer.has_entry = false;
2069 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2071 //Seed.print("click" + ev.type);
2072 //console.dump(res);
2081 enable_tree_lines : true,
2082 headers_visible : false,
2084 XObject.prototype.init.call(this);
2086 this.selection = this.el.get_selection();
2087 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2090 var description = new Pango.FontDescription.c_new();
2091 description.set_size(8000);
2092 this.el.modify_font(description);
2096 xtype: Gtk.TreeStore,
2100 add : function(info) {
2101 // info includes key, val, skel, etype..
2103 type = info.type.toLowerCase();
2104 var data = this.toJS();
2106 if (info.etype == 'events') {
2107 data.listeners = data.listeners || { };
2108 if (typeof(data.listeners[info.key]) != 'undefined') {
2109 return; //already set!
2112 if (typeof(data[info.key]) != 'undefined') {
2117 if (typeof(info.val) == 'undefined') {
2120 if (info.type.toLowerCase() == 'boolean') {
2123 if (type == 'number') {
2131 if (info.etype == 'events') {
2133 data.listeners[info.key] = info.val;
2136 data[info.key] = info.val;
2140 var map = this.load(data);
2142 // flag it as changed to the interface..
2143 this.get('/LeftTree.model').setFromNode(false,node);
2144 this.get('/LeftTree.model').changed(true);
2147 this.startEditing(map[k]);
2150 LeftPanel.get('view').el.row_activated(
2151 new Gtk.TreePath.from_string(map[k]),
2152 LeftPanel.editableColumn.el
2156 changed : function(str, doRefresh) {
2157 if (!this.activePath) {
2158 print("NO active path when changed")
2162 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2164 this.el.set_value(ret.iter, 1, '' +str);
2165 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2166 var type = this.getIterValue(ret.iter, 4);
2168 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2169 // update the tree...
2170 print("new data: " + JSON.stringify(this.toJS() , null,4));
2171 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2172 this.get('/LeftTree.model').changed(doRefresh);
2175 deleteSelected : function() {
2176 var data = this.toJS();
2178 var s = this.get('/LeftPanel.view').selection;
2179 s.get_selected( ret);
2182 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2184 if (val[0] == '!') {
2186 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2189 delete data.listeners[ val.substring(1)];
2190 if (!XObject.keys(data.listeners).length) {
2191 delete data.listeners;
2195 if (typeof(data[val]) == 'undefined') {
2203 this.get('/LeftTree.model').changed(data, true);
2206 getIterValue : function(iter, col) {
2207 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2210 getType : function(treepath) {
2211 return this.getValue(treepath, 4);
2213 getValue : function(treepath_str, col)
2215 // get's the value in a row.. - keys - returns string, values - formats it..
2217 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2219 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2224 var type = this.getType(this.el.get_path(ret.iter).to_string());
2225 //print("TYPE: " +type + " - val:" + val);
2226 switch(type.toLowerCase()) {
2230 return parseFloat(val); // Nan ?? invalid!!?
2233 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2235 return val == 'true' ? true : false;
2237 var nv = parseFloat(val);
2238 if (!isNaN(nv) && (val == ''+nv)) {
2246 XObject.prototype.init.call(this);
2247 this.el.set_column_types ( 6, [
2248 GObject.TYPE_STRING, // 0 real key
2249 GObject.TYPE_STRING, // 1 real value
2250 GObject.TYPE_STRING, // 2 visable key
2251 GObject.TYPE_STRING, // 3 visable value
2252 GObject.TYPE_STRING, // 4 need to store type of!!!
2253 GObject.TYPE_STRING // 5 tooltip
2257 load : function(ar) {
2258 // might casue problesm..
2259 // this.get('/Editor.RightEditor').save();
2261 this.get('/Editor').el.hide();
2262 this.get('/Editor').activePath = false;
2267 //this.get('/RightEditor').el.hide();
2274 var provider = this.get('/LeftTree').getPaleteProvider();
2278 var keys = XObject.keys(ar);
2280 ar.listeners = ar.listeners || {};
2282 for (var i in ar.listeners ) {
2284 this.el.append(iret);
2285 var p = this.el.get_path(iret.iter).to_string();
2288 this.el.set_value(iret.iter, 0, '!'+ i );
2289 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2290 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2292 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2293 this.el.set_value(iret.iter, 4, 'function');
2294 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2300 keys.forEach(function(i) {
2301 if (typeof(ar[i]) == 'object') {
2305 var type = provider.findType(ar, i, ar[i]);
2307 _this.el.append(iret);
2308 var p = _this.el.get_path(iret.iter).to_string();
2310 _this.el.set_value(iret.iter, 0, ''+i);
2311 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2312 _this.el.set_value(iret.iter, 2, ''+i);
2313 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2314 _this.el.set_value(iret.iter, 4, ''+type);
2315 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2319 startEditing : function(path,col) {
2321 // alled by menu 'edit' currently..
2323 * start editing path (or selected if not set..)
2324 * @param {String|false} path (optional) treepath to edit - selected tree gets
2325 * edited by default.
2326 * @param {Number} 0 or 1 (optional)- column to edit.
2328 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2330 if (typeof(path) == 'string') {
2331 tp = new Gtk.TreePath.from_string(path);
2334 var s = this.get('/LeftPanel.view').selection;
2335 s.get_selected( itr);
2336 tp = this.el.get_path(itr.iter);
2337 path = tp.to_string();
2341 // which colum is to be edited..
2344 // not sure what this does..
2346 if (typeof(col) == 'undefined') {
2347 var k = this.getValue(path, 0);
2349 colObj = (!k.length || k == '|') ?
2350 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2352 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2355 // make sure the pulldown is set correctly..
2356 // not really needed for second col...
2357 var showEditor = false;
2358 this.get('/Editor').activePath = false;
2359 this.get('/Editor').el.hide();
2362 var provider = this.get('/LeftTree').getPaleteProvider();
2363 var type = this.get('/LeftPanel.model').getType(path);
2364 var opts = provider.findOptions(type);
2365 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2367 if (opts === false) {
2368 this.get('/LeftPanel').editableColumn.setOptions([]);
2369 renderer.has_entry = true;
2371 this.get('/LeftPanel').editableColumn.setOptions(opts);
2372 renderer.has_entry = false;/// - pulldowns do not have entries
2374 // determine if we should use the Text editor...
2375 var keyname = this.getValue(path, 0);
2376 var data_value = this.getValue(path, 1);
2378 if ((keyname[0] == '|') ||
2380 (typeof(data_value) == 'string' ) &&
2381 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2385 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2390 // this.get('/BottomPane').el.hide();
2391 //this.get('/RightEditor').el.hide();
2396 this.activePath = false;
2398 _this.get('/Editor').el.show_all();
2399 GLib.timeout_add(0, 1, function() {
2401 //_this.get('/BottomPane').el.show();
2402 //_this.get('/RightEditor').el.show();
2404 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2406 _this.get('/Editor').activePath = path;
2407 _this.activePath = path ;
2417 // iter now has row...
2418 GLib.timeout_add(0, 100, function() {
2419 _this.activePath = path;
2420 colObj.items[0].el.editable = true; // esp. need for col 0..
2421 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2432 this.get('/LeftPanel.model').el.get_iter_first(iret);
2438 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2441 ar.listeners = ar.listeners || {};
2442 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2445 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2448 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2454 //print(JSON.stringify(ar));
2458 toShort : function(str) {
2459 var a = typeof(str) == 'string' ? str.split("\n") : [];
2460 return a.length > 1 ? a[0] + '....' : '' + str;
2464 xtype: Gtk.TreeViewColumn,
2465 pack : "append_column",
2467 XObject.prototype.init.call(this);
2469 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2470 this.get('/LeftPanel').propertyColumn = this;
2475 xtype: Gtk.CellRendererText,
2476 pack : "pack_start",
2478 editing_started : function (self, editable, path) {
2480 this.get('/LeftPanel.model').activePath = path;
2483 edited : function (self, object, p0) {
2485 print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2487 var model = this.get('/LeftPanel.model');
2488 var path = model.activePath;
2490 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2491 model.el.set_value(iret.iter, 0, p0);
2492 model.el.set_value(iret.iter, 2, p0);
2494 model.activePath = false;
2496 this.get('/LeftTree.model').changed(model.toJS(), true);
2497 this.el.editable = false;
2504 xtype: Gtk.TreeViewColumn,
2505 pack : "append_column",
2508 XObject.prototype.init.call(this);
2509 this.el.add_attribute(this.items[0].el , 'text', 3 );
2510 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2511 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2512 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2514 this.get('/LeftPanel').editableColumn= this;
2516 setOptions : function(ar) {
2517 var m = this.items[0].el.model;
2520 ar.forEach(function(i) {
2524 m.set_value(iret.iter, 0, i);
2530 xtype: Gtk.CellRendererCombo,
2532 edited : function (self, object, p0) {
2534 this.get('/LeftPanel').editing = false;
2535 var ap = this.get('/LeftPanel.model').activePath
2536 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2537 this.get('/LeftPanel.model').changed(p0, true);
2538 this.get('/LeftPanel.model').activePath = false;
2539 this.el.editable = false;
2541 editing_started : function (self, editable, path) {
2542 this.get('/LeftPanel').editing = true;
2543 // console.log('editing started');
2544 // r.has_entry = false;
2546 this.el.editable = false; // make sure it's not editor...
2551 pack : "pack_start",
2555 XObject.prototype.init.call(this);
2556 this.el.model = new Gtk.ListStore();
2557 this.el.model.set_column_types ( 1, [
2558 GObject.TYPE_STRING // 0 real key
2569 id : "LeftPanelPopup",
2572 xtype: Gtk.MenuItem,
2576 activate : function (self) {
2577 this.get('/LeftPanel.model').deleteSelected();
2582 xtype: Gtk.MenuItem,
2586 activate : function (self) {
2587 this.get('/LeftPanel.model').startEditing(false, 0);
2600 xtype: Gtk.ScrolledWindow,
2601 pack : "pack_end,false,true,0",
2604 shadow_type : Gtk.ShadowType.IN,
2606 XObject.prototype.init.call(this);
2607 XObject.prototype.init.call(this);
2608 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2609 this.el.set_size_request ( 150, -1 );
2612 activeElement : false,
2613 hideWin : function() {
2616 print("HIDEWIN - currently not shown")
2621 if (this.get('/Window.left').el.position < 160) {
2622 print("HIDEWIN - small already.")
2626 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2627 print("HIDEWIN attempting to hide.")
2634 xtype: Gtk.TreeView,
2636 cursor_changed : function (self) {
2639 //console.log('changed');
2640 var m = this.get('model');
2641 if (!this.selection){
2642 this.selection = this.el.get_selection();
2645 var s = this.selection;
2646 if (!s.get_selected(iret)) {
2649 var tp = m.el.get_path(iret.iter).to_string();
2654 var key = m.getValue(tp, 0);
2656 var type = m.getValue(tp, 1);
2657 var skel = m.getValue(tp, 3);
2658 var etype = m.getValue(tp, 5);
2661 this.get('/MidPropTree').hideWin();
2663 if (type.toLowerCase() == 'function') {
2665 if (etype != 'events') {
2669 this.get('/LeftPanel.model').add({
2677 // has dot in name, and is boolean???? this does not make sense..
2678 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2682 this.get('/LeftPanel.model').add( {
2692 enable_tree_lines : true,
2693 headers_visible : false,
2695 XObject.prototype.init.call(this);
2697 var description = new Pango.FontDescription.c_new();
2698 description.set_size(8000);
2699 this.el.modify_font(description);
2701 //this.selection = this.el.get_selection();
2702 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2711 xtype: Gtk.ListStore,
2714 getValue : function(treepath, col)
2716 var tp = new Gtk.TreePath.from_string (treepath);
2718 this.el.get_iter (iret, tp);
2719 var value = this.el.get_value(iret.iter, col);
2720 return ''+ value.value.get_string();
2724 XObject.prototype.init.call(this);
2725 this.el.set_column_types ( 6, [
2726 GObject.TYPE_STRING, // real key
2727 GObject.TYPE_STRING, // real type
2728 GObject.TYPE_STRING, // docs ?
2729 GObject.TYPE_STRING, // visable desc
2730 GObject.TYPE_STRING, // function desc
2731 GObject.TYPE_STRING // element type (event|prop)
2735 showData : function(type) {
2737 if (!this.get('/MidPropTree').activeElement || !type) {
2738 return; // no active element
2741 var fullpath = this.get('/LeftTree.model').file.guessName(
2742 this.get('/MidPropTree').activeElement);
2743 var palete = this.get('/LeftTree').getPaleteProvider();
2747 Seed.print('Showing right?');
2748 if (!this.get('/MidPropTree').shown) {
2750 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2751 this.get('/MidPropTree').el.show();
2752 this.get('/MidPropTree').shown = true;
2755 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2756 return a.name > b.name ? 1 : -1;
2758 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2759 // console.dump(elementList);
2763 for(var i =0 ; i < elementList.length; i++) {
2765 var p=elementList[i];
2766 this.el.append(iret);
2767 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2768 //GObject.TYPE_STRING, // real key
2769 // GObject.TYPE_STRING, // real type
2770 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2771 // GObject.TYPE_STRING // func def?
2774 this.el.set_value(iret.iter, 0, p.name);
2775 this.el.set_value(iret.iter, 1, p.type);
2776 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2777 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2778 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2779 this.el.set_value(iret.iter, 5, type);
2786 xtype: Gtk.TreeViewColumn,
2789 this.el = new Gtk.TreeViewColumn();
2790 this.parent.el.append_column(this.el);
2792 XObject.prototype.init.call(this);
2793 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2797 xtype: Gtk.CellRendererText,
2798 pack : "pack_start,true"
2825 xtype: Gtk.Notebook,
2826 pack : "pack_start,true,true",
2827 id : "view-help-nb",
2829 XObject.prototype.init.call(this);
2830 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2831 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2835 xtype: Gtk.Notebook,
2836 id : "view-notebook",
2840 XObject.prototype.init.call(this);
2841 this.el.set_current_page(0);
2842 //print("SET LABEL?")
2843 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2844 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2850 id : "RightBrowser",
2855 pack : "pack_start,false,true,0",
2860 clicked : function (self) {
2861 this.get('/RightBrowser.view').renderJS(null,true);
2865 pack : "pack_start,false,false,0"
2868 xtype: Gtk.CheckButton,
2870 toggled : function (self, state) {
2871 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2876 label : "Auto Redraw On",
2877 pack : "pack_start,false,false,0"
2882 clicked : function (self) {
2883 this.get('/RightBrowser.view').redraws = 99;
2884 this.get('/RightBrowser.view').renderJS(null,true);
2887 label : "Full Redraw",
2888 pack : "pack_start,false,false,0"
2893 xtype: Gtk.ScrolledWindow,
2896 XObject.prototype.init.call(this);
2897 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2899 shadow_type : Gtk.ShadowType.IN,
2902 xtype: WebKit.WebView,
2904 load_finished : function (self, object) {
2905 print("load finished");
2906 // print("load_finished"); return;
2907 // if (this.ready) { // dont do it twice!
2910 if (!this.inspectorShown) {
2911 this.el.get_inspector().show();
2912 this.inspectorShown = true;
2917 if (this.pendingRedraw) {
2918 this.pendingRedraw = false;
2919 this.refreshRequired = true;
2921 //var js = this.get('/LeftTree.model').toJS();
2922 //if (js && js[0]) {
2923 // this.renderJS(js[0]);
2927 script_alert : function (self, object, p0) {
2930 return true; // do not display anything...
2932 console_message : function (self, object, p0, p1) {
2934 // console.log(object);
2937 if (object.match(/variable/) && object.match(/Builder/)) {
2938 print("got builder missing message");
2939 this.refreshRequired = true;
2940 this.lastRedraw = 0;
2946 if (!object.match(/^\{/)) {
2948 //this.get('/Terminal').feed(object);
2949 return true; // do not handle!!! -> later maybe in console..
2955 // console.log(object);
2956 var val = JSON.parse(object);
2958 if (typeof(val['hover-node']) != 'undefined') {
2959 this.activeNode = val['hover-node'];
2960 console.log('active node: ' + this.activeNode);
2965 if (typeof(val['id']) != 'undefined') {
2966 // this.activeNode = val['id'];
2967 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2968 if (!tg || typeof(tg[0]) == 'undefined') {
2971 print("SELECT node " + tg[0]);
2973 this.get('/LeftTree.view').selectNode(tg[0]);
2977 if (ret && typeof(val['set']) != 'undefined') {
2978 this.get('/LeftPanel.model').add({
2982 //console.log('active node: ' + this.activeNode);
2985 //Seed.print('a:'+a);
2986 //Seed.print('b:'+b);
2987 //Seed.print('c:'+c);
2990 drag_motion : function (w, ctx, x, y, time, ud) {
2991 // console.log('DRAG MOTION');
2993 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2994 this.targetData = [];
2995 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2997 // A) find out from drag all the places that node could be dropped.
2998 var src = Gtk.drag_get_source_widget(ctx);
2999 if (!src.dropList) {
3000 Gdk.drag_status(ctx,0, time);
3003 // b) get what we are over.. (from activeNode)
3004 // tree is empty.. - list should be correct..
3005 if (!this.get('/LeftTree.model').currentTree) {
3006 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3010 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3012 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3015 Gdk.drag_status(ctx, 0,time);
3016 this.get('/LeftTree.view').highlight(false);
3020 // if we have a target..
3021 // -> highlight it! (in browser)
3022 // -> highlight it! (in tree)
3024 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3025 this.get('/LeftTree.view').highlight(tg);
3026 this.targetData = tg;
3027 // for tree we should handle this...
3030 drag_drop : function (w, ctx, x, y,time, ud) {
3031 print("TARGET: drag-drop");
3032 var is_valid_drop_site = true;
3036 ( /* will receive 'drag-data-received' signal */
3037 ctx, /* represents the current state of the DnD */
3038 this.get('/Window').atoms["STRING"], /* the target type we want */
3039 time /* time stamp */
3043 /* No target offered by source => error */
3046 return is_valid_drop_site;
3048 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3050 print("Browser: drag-data-received");
3051 var delete_selection_data = false;
3052 vardnd_success = false;
3053 /* Deal with what we are given from source */
3054 if( sel_data && sel_data.length ) {
3056 if (ctx.action == Gdk.DragAction.ASK) {
3057 /* Ask the user to move or copy, then set the ctx action. */
3060 if (ctx.action == Gdk.DragAction.MOVE) {
3061 delete_selection_data = true;
3063 var source = Gtk.drag_get_source_widget(ctx);
3065 print("Browser: source.DRAGDATA? " + source.dragData);
3066 if (this.targetData) {
3067 print(this.targetData);
3068 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3077 if (dnd_success == false)
3079 Seed.print ("DnD data transfer failed!\n");
3082 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3085 create_web_view : function (self, object) {
3086 print("CREATE WEB VIEW");
3087 return null; //new WebKit.WebView();
3094 XObject.prototype.init.call(this);
3095 // this may not work!?
3096 var settings = this.el.get_settings();
3097 settings.enable_developer_extras = true;
3099 // this was an attempt to change the url perms.. did not work..
3100 // settings.enable_file_access_from_file_uris = true;
3101 // settings.enable_offline_web_application_cache - true;
3102 // settings.enable_universal_access_from_file_uris = true;
3106 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3107 _this.get('/BottomPane.inspector').el.show();
3108 return _this.get('/BottomPane.inspector').el;
3112 // FIXME - base url of script..
3113 // we need it so some of the database features work.
3114 this.el.load_html_string( "Render not ready" ,
3115 //fixme - should be a config option!
3116 // or should we catch stuff and fix it up..
3117 'http://localhost/app.Builder/'
3121 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3123 this.el.drag_dest_set
3124 ( /* widget that will accept a drop */
3125 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3126 null, /* lists of target to support */
3127 0, /* size of list */
3128 Gdk.DragAction.COPY /* what to do with data after dropped */
3131 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3132 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3134 GLib.timeout_add_seconds(0, 1, function() {
3135 // print("run refresh?");
3142 renderJS : function(data, force) {
3144 // this is the public redraw call..
3145 // we refresh in a loop privately..
3146 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3147 if (!autodraw && !force) {
3148 print("Skipping redraw - no force, and autodraw off");
3151 this.refreshRequired = true;
3153 runRefresh : function()
3155 // this is run every 2 seconds from the init..
3159 if (!this.refreshRequired) {
3160 // print("no refresh required");
3164 if (this.lastRedraw) {
3165 // do not redraw if last redraw was less that 5 seconds ago.
3166 if (((new Date()) - this.lastRedraw) < 5000) {
3174 if (!this.get('/Window.LeftTree').getActiveFile()) {
3177 this.refreshRequired = false;
3178 // print("HTML RENDERING");
3180 this.get('/BottomPane').el.show();
3181 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3184 var js = this.get('/LeftTree.model').toJS();
3185 if (!js || !js.length) {
3192 var project = this.get('/Window.LeftTree').getActiveFile().project;
3193 //print (project.fn);
3194 // set it to non-empty.
3195 project.runhtml = project.runhtml || '';
3196 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3199 this.runhtml = this.runhtml || '';
3201 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3202 // then we need to reload the browser using
3203 // load_html_string..
3205 // then trigger a redraw once it's loaded..
3206 this.pendingRedraw = true;
3207 var runhtml = '<script type="text/javascript">' + "\n" ;
3208 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3209 runhtml += '</script>'+ "\n" ;
3211 this.runhtml = project.runhtml;
3212 // need to modify paths
3216 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3217 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3218 print("LOAD HTML " + html);
3219 this.el.load_html_string( html ,
3220 //fixme - should be a config option!
3221 'http://localhost/app.Builder/'
3224 // should trigger load_finished! - which in truns shoudl set refresh Required;
3230 this.renderedData = data;
3231 var str = JSON.stringify(data) ;
3234 console.log('not loaded yet');
3236 this.lastRedraw = new Date();
3238 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3239 print( "before render" + this.lastRedraw);
3240 print( "after render" + (new Date()));
3250 id : "RightGtkView",
3252 redraw : function() {
3253 this.highlightWidget = false;
3254 print("REDRAW CALLED");
3255 this.activePath = this.get('/LeftTree').getActivePath();
3256 if (this.renderedEl) {
3257 print("QUEUE DRAW CALLING");
3258 this.renderedEl.queue_draw();
3261 renderJS : function(data, withDebug)
3263 this.highlightWidget = false;
3265 this.withDebug = false;
3266 while (this.get('view').el.get_children().length) {
3267 var c = this.get('view').el.get_children()[0];
3268 this.get('view').el.remove(c);
3275 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3276 // in theory tree is actually window..
3279 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3285 this.get('view').el.set_size_request(
3286 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3288 if (this.renderedEl) {
3289 this.renderedEl.set_size_request(
3290 tree.default_width || 600,
3291 tree.default_height || 400
3294 this.get('view').el.show_all();
3299 showInWindow : function() {
3300 print("GET PROEJCT");
3301 var pr = this.get('/LeftProjectTree').getActiveProject();
3303 console.log(pr.paths);
3306 var src= this.buildJS(
3307 this.get('/LeftTree.model').toJS()[0],
3312 //var x = new imports.sandbox.Context();
3316 Seed.check_syntax('var e = ' + src);
3319 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3320 this.get('/Terminal').feed(console._dump(e)+"\n");
3322 var lines = src.split("\n");
3323 var start = Math.max(0, e.line - 10);
3324 var end = Math.min(lines.length, e.line + 10);
3325 for (var i =start ; i < end; i++) {
3327 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3330 this.get('/Terminal').feed(lines[i] + "\n");
3337 this.get('/BottomPane').el.set_current_page(1);
3338 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3339 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3340 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3342 var _top = x.get_global_object()._top;
3344 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3346 if (_top.el.popup) {
3347 _top.el.popup(null, null, null, null, 3, null);
3351 viewAdd : function(item, par)
3354 // does something similar to xobject..
3355 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3357 // pack is forced to 'false'
3358 if (item.pack===false || item.pack === 'false') { // no ;
3362 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3365 var type = item['|xns'] + '.' + item['xtype'];
3367 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3371 var ns = imports.gi[item['|xns']];
3372 var ctr = ns[item['xtype']]; // why are we using array here..?
3377 for(var k in item) {
3379 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3393 // value is a function..
3394 if (k[0] == '|' && typeof(kv) == 'string') {
3396 if (kv.match(new RegExp('function'))) {
3399 print("WASL " + k + '=' + kv);
3401 eval( 'kv = ' + kv);
3402 } catch(e) { continue; }
3405 // print(k + '=' + kv);
3407 if (k[0] == '|') { // should be boolean or number..
3409 //print(k + '=' + kv);
3412 if (k == 'show_tabs') { // force tab showing for notebooks.
3415 print(k + '=' + typeof(kv) + " : " + kv);
3419 var altctr = XObject.baseXObject({ xtype: ctr} );
3421 if (!item.pack && altctr) {
3423 print("SETTING PACK TO XObjectBase method");
3424 pack_m = altctr.prototype.pack;
3429 var el = new ctr(ctr_args);
3431 print("PACK" + item.pack);
3432 //console.dump(item.pack);
3439 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3440 if (typeof(item.pack) == 'string') {
3442 item.pack.split(',').forEach(function(e, i) {
3444 if (e == 'false') { args.push( false); return; }
3445 if (e == 'true') { args.push( true); return; }
3446 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3449 //print(args.join(","));
3451 pack_m = args.shift();
3453 pack_m = item.pack.shift();
3458 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3460 name: "ArgumentError",
3461 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3462 "ADDING : " + item.id + " " + el
3471 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3472 //Seed.print('args: ' + args.length);
3473 if (typeof(pack_m) == 'string') {
3474 par[pack_m].apply(par, args);
3475 } else if (pack_m) {
3476 pack_m.call(item, par, item);
3480 item.items = item.items || [];
3481 item.items.forEach(function(ch,n) {
3483 print ("type:" + type);
3485 print ("ch.pack:" + ch.pack);
3488 if (type == 'Gtk.Table' && ch.pack == 'add') {
3489 var c = n % item.n_columns;
3490 var r = Math.floor(n/item.n_columns);
3491 ch.pack = [ 'attach', c, c+1, r, r+1,
3492 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3493 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3494 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3495 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3499 _this.viewAdd(ch, el);
3504 // add the signal handlers.
3505 // is it a widget!?!!?
3511 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3512 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3513 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3514 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3515 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3525 widgetDragDropEvent : function() {
3526 print("WIDGET DRAGDROP");
3529 widgetDragMotionEvent : function() {
3530 print("WIDGET DRAGMOTION");
3533 widgetExposeEvent : function(w, evt, ud, item) {
3535 if (this.inRender) {
3539 if ( this.highlightWidget) {
3540 this.inRender = true;
3541 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3542 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3544 this.inRender = false;
3549 if (this.activePath != item.xtreepath) {
3553 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3554 // work out the coords of the window..
3556 var dr = widget.window;
3557 this.gc = (new Gdk.GC.c_new(dr));
3558 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3559 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3563 var r = evt.expose.area;
3564 // console.dump([r.x, r.y, r.width, r.height ] );
3566 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3567 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3568 // happens with gtkscrollview embedded stuff..
3569 var np =this.activePath.split(':');
3571 this.activePath = np.join(':');
3572 this.renderedEl.queue_draw();
3588 this.inRender = true;
3591 this.highlightWidget = widget;
3596 // print("DRAW BOX");
3597 //console.dump(this.box);
3598 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3599 this.inRender = false;
3602 widgetPressEvent : function(w,e,u,d) {
3603 if (this.get('view').pressed) {
3606 this.get('view').pressed = true;
3607 print("WIDGET PRESS " + d.xtreepath );
3608 this.get('/LeftTree.view').selectNode( d.xtreepath );
3611 widgetReleaseEvent : function() {
3612 this.get('view').pressed = false;
3618 pack : "pack_start,false,true,0",
3622 pack : "pack_start,false,false,0",
3623 label : "Run The Application",
3625 button_press_event : function (self, event) {
3626 // call render on left tree - with special option!?!
3628 //print("GET PROEJCT");
3629 var pr = this.get('/LeftProjectTree').getActiveProject();
3632 for (var i in pr.paths) {
3636 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3637 this.get('/Terminal').feed("RUN DIR:" + dir);
3639 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3640 , false,false,false);
3641 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3642 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3652 xtype: Gtk.ScrolledWindow,
3655 shadow_type : Gtk.ShadowType.IN,
3657 XObject.prototype.init.call(this);
3658 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3662 xtype: Gtk.EventBox,
3663 pack : "add_with_viewport",
3665 XObject.prototype.init.call(this);
3666 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3667 red: 0x9F00, green: 0xB800 , blue : 0xA800
3675 XObject.prototype.init.call(this);
3676 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3677 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3682 xtype: Gtk.EventBox,
3685 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3686 XObject.prototype.init.call(this);
3688 this.el.drag_dest_set
3689 ( /* widget that will accept a drop */
3690 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3691 null, /* lists of target to support */
3692 0, /* size of list */
3693 Gdk.DragAction.COPY /* what to do with data after dropped */
3696 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3697 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3700 getActiveNode : function(x,y)
3702 // workout what node is here..
3703 return '0'; // top..
3707 drag_motion : function (self, ctx, x, y, time) {
3709 // A) find out from drag all the places that node could be dropped.
3710 var src = Gtk.drag_get_source_widget(ctx);
3711 if (!src.dropList) {
3712 Gdk.drag_status(ctx, 0, time);
3715 // b) get what we are over.. (from activeNode)
3716 // tree is empty.. - list should be correct..
3717 if (!this.get('/LeftTree.model').currentTree) {
3718 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3722 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3723 var activeNode = this.getActiveNode(x, y);
3726 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3729 Gdk.drag_status(ctx, 0,time);
3730 this.get('/LeftTree.view').highlight(false);
3734 // if we have a target..
3735 // -> highlight it! (in browser)
3736 // -> highlight it! (in tree)
3738 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3739 this.get('/LeftTree.view').highlight(tg);
3740 this.targetData = tg;
3741 // for tree we should handle this...
3744 drag_drop : function (self,ctx, x, y, time) {
3745 Seed.print("TARGET: drag-drop");
3746 var is_valid_drop_site = true;
3750 ( /* will receive 'drag-data-received' signal */
3751 ctx, /* represents the current state of the this.gDnD */
3752 this.get('/Window').atoms["STRING"], /* the target type we want */
3753 time /* time stamp */
3757 /* No target offered by source => error */
3760 return is_valid_drop_site;
3763 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3765 Seed.print("GtkView: drag-data-received");
3766 var delete_selection_data = false;
3767 var dnd_success = false;
3768 /* Deal with what we are given from source */
3769 if( sel_data && sel_data.length ) {
3771 if (ctx.action == Gdk.DragAction.ASK) {
3772 /* Ask the user to move or copy, then set the ctx action. */
3775 if (ctx.action == Gdk.DragAction.MOVE) {
3776 delete_selection_data = true;
3778 var source = Gtk.drag_get_source_widget( ctx );
3780 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3781 if (this.targetData) {
3782 Seed.print(this.targetData);
3783 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3792 if (dnd_success == false)
3794 Seed.print ("DnD data transfer failed!\n");
3797 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3800 button_press_event : function (self, event) {
3801 this.pressed = false;
3817 xtype: Gtk.ScrolledWindow,
3822 var file = this.get('/LeftTree').getActiveFile();
3826 var activeEl = this.get('/LeftTree').getActiveElement();
3827 var xtype = file.guessName( activeEl )
3828 if (!xtype || !xtype.length) {
3831 //this.get('/Window.view-help-nb').el.set_current_page(1);
3833 // get the active element being edited.
3834 var helpurl = file.getHelpUrl(xtype);
3836 // now load the help info in the page..
3837 this.get('help-view').el.open(helpurl);
3841 xtype: WebKit.WebView,
3845 XObject.prototype.init.call(this);
3846 this.get('/Window.help-view').el.open(
3847 "http://devel.akbkhome.com/seed/");
3859 xtype: Gtk.Notebook,
3863 XObject.prototype.init.call(this);
3864 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3865 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3866 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3870 xtype: Gtk.ScrolledWindow,
3874 xtype: Vte.Terminal,
3877 feed : function(istr) {
3878 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3879 // we should make ourselves visable!!!
3880 this.get('/BottomPane').el.show();
3881 this.get('/BottomPane').el.set_current_page(1);
3883 this.el.feed(str ,str.length);
3885 scroll_on_output : true,
3887 XObject.prototype.init.call(this);
3888 this.el.set_size (80, 1000);
3890 scrollback_lines : 1000
3895 xtype: Gtk.ScrolledWindow,
3899 xtype: WebKit.WebView,
3915 this.get('buttonbar').el.show();
3916 this.get('viewbox').el.hide();
3917 var ce = this.get('/Window.centereast').el;
3919 ce.set_position(ce.get_allocated_width() - 30);
3921 print("TRIED TO HIDE");
3924 this.get('buttonbar').el.hide();
3925 this.get('viewbox').el.show();
3926 var ce = this.get('/Window.centereast').el;
3927 print(JSON.stringify(XObject.keys(ce) ,null,4));
3928 ce.set_position(ce.get_allocated_width() - 150);
3930 // this.get('model').expanded();
3942 pack : "pack_start,false,true",
3944 clicked : function (self) {
3945 this.get('/RightPalete').show();
3952 stock : Gtk.STOCK_GOTO_FIRST,
3953 icon_size : Gtk.IconSize.MENU
3963 XObject.prototype.init.call(this);
3964 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3967 enter_notify_event : function (self, event) {
3968 this.get('/RightPalete').show();
3982 pack : "pack_start,false,true",
3991 pack : "pack_start,false,true",
3993 clicked : function (self) {
3994 this.get('/RightPalete').hide();
4001 stock : Gtk.STOCK_GOTO_LAST,
4002 icon_size : Gtk.IconSize.MENU
4009 xtype: Gtk.ScrolledWindow,
4012 XObject.prototype.init.call(this);
4013 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4014 this.el.set_size_request(-1,200);
4016 shadow_type : Gtk.ShadowType.IN,
4019 xtype: Gtk.TreeView,
4021 drag_begin : function (self, ctx) {
4022 // we could fill this in now...
4023 Seed.print('SOURCE: drag-begin');
4028 var s = this.selection;
4029 s.get_selected(iret);
4030 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4032 var pix = this.el.create_row_drag_icon ( path);
4035 if (Gtk.drag_set_icon_surface) {
4036 Gtk.drag_set_icon_surface( ctx, pix );
4038 Gtk.drag_set_icon_pixmap (ctx,
4039 pix.get_colormap(), pix, null, -10, -10);
4042 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4043 if (!this.get('/RightPalete').provider) {
4046 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4047 this.el.dragData = value;
4054 drag_data_get : function (self, drag_context, selection_data, info, time) {
4055 //Seed.print('Palete: drag-data-get: ' + target_type);
4056 if (this.el.dragData && this.el.dragData.length ) {
4057 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4061 //this.el.dragData = "TEST from source widget";
4065 drag_end : function (self, drag_context) {
4066 Seed.print('SOURCE: drag-end');
4067 this.el.dragData = false;
4068 this.el.dropList = false;
4069 this.get('/LeftTree.view').highlight(false);
4072 button_press_event : function (self, event) {
4074 if (!this.get('/Editor').save()) {
4075 // popup!! - click handled..
4082 enable_tree_lines : true,
4083 headers_visible : false,
4085 XObject.prototype.init.call(this);
4086 this.el.set_size_request(150,-1);
4087 // set_reorderable: [1]
4089 var description = new Pango.FontDescription.c_new();
4090 description.set_size(8000);
4091 this.el.modify_font(description);
4093 this.selection = this.el.get_selection();
4094 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4095 // this.selection.signal['changed'].connect(function() {
4096 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4098 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4100 this.el.drag_source_set ( /* widget will be drag-able */
4101 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4102 null, /* lists of target to support */
4103 0, /* size of list */
4104 Gdk.DragAction.COPY /* what to do with data after dropped */
4106 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4108 this.el.drag_source_set_target_list( this.get('/Window').targetList);
4109 this.el.drag_source_add_text_targets( );
4111 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4112 targets = new Gtk.TargetList();
4113 targets.add( LeftTree.atoms["STRING"], 0, 0);
4114 targets.add_text_targets( 1 );
4115 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4117 //if you want to allow text to be output elsewhere..
4118 //Gtk.drag_source_add_text_targets(this.el);
4124 xtype: Gtk.ListStore,
4127 XObject.prototype.init.call(this);
4128 this.el.set_column_types ( 2, [
4129 GObject.TYPE_STRING, // title
4130 GObject.TYPE_STRING // tip
4135 load : function(tr,iter)
4140 //console.log('Project tree load: ' + tr.length);
4142 //this.insert(citer,iter,0);
4143 for(var i =0 ; i < tr.length; i++) {
4146 this.el.append(cret);
4148 this.el.insert(cret,iter,-1);
4153 this.el.set_value(cret.iter, 0, '' + r ); // title
4155 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4156 //if (r.cn && r.cn.length) {
4157 // this.load(r.cn, citer);
4163 getValue : function (iter, col) {
4164 return this.el.get_value(iter, col).value.get_string();
4171 xtype: Gtk.TreeViewColumn,
4172 pack : "append_column",
4174 XObject.prototype.init.call(this);
4175 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4179 xtype: Gtk.CellRendererText,
4201 XObject.cache['/Window'] = Window;