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') {
2205 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2206 this.get('/LeftTree.model').changed(true);
2210 getIterValue : function(iter, col) {
2211 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2214 getType : function(treepath) {
2215 return this.getValue(treepath, 4);
2217 getValue : function(treepath_str, col)
2219 // get's the value in a row.. - keys - returns string, values - formats it..
2221 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2223 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2228 var type = this.getType(this.el.get_path(ret.iter).to_string());
2229 //print("TYPE: " +type + " - val:" + val);
2230 switch(type.toLowerCase()) {
2234 return parseFloat(val); // Nan ?? invalid!!?
2237 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2239 return val == 'true' ? true : false;
2241 var nv = parseFloat(val);
2242 if (!isNaN(nv) && (val == ''+nv)) {
2250 XObject.prototype.init.call(this);
2251 this.el.set_column_types ( 6, [
2252 GObject.TYPE_STRING, // 0 real key
2253 GObject.TYPE_STRING, // 1 real value
2254 GObject.TYPE_STRING, // 2 visable key
2255 GObject.TYPE_STRING, // 3 visable value
2256 GObject.TYPE_STRING, // 4 need to store type of!!!
2257 GObject.TYPE_STRING // 5 tooltip
2261 load : function(ar) {
2262 // might casue problesm..
2263 // this.get('/Editor.RightEditor').save();
2265 this.get('/Editor').el.hide();
2266 this.get('/Editor').activePath = false;
2271 //this.get('/RightEditor').el.hide();
2278 var provider = this.get('/LeftTree').getPaleteProvider();
2282 var keys = XObject.keys(ar);
2284 ar.listeners = ar.listeners || {};
2286 for (var i in ar.listeners ) {
2288 this.el.append(iret);
2289 var p = this.el.get_path(iret.iter).to_string();
2292 this.el.set_value(iret.iter, 0, '!'+ i );
2293 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2294 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2296 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2297 this.el.set_value(iret.iter, 4, 'function');
2298 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2304 keys.forEach(function(i) {
2305 if (typeof(ar[i]) == 'object') {
2309 var type = provider.findType(ar, i, ar[i]);
2311 _this.el.append(iret);
2312 var p = _this.el.get_path(iret.iter).to_string();
2314 _this.el.set_value(iret.iter, 0, ''+i);
2315 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2316 _this.el.set_value(iret.iter, 2, ''+i);
2317 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2318 _this.el.set_value(iret.iter, 4, ''+type);
2319 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2323 startEditing : function(path,col) {
2325 // alled by menu 'edit' currently..
2327 * start editing path (or selected if not set..)
2328 * @param {String|false} path (optional) treepath to edit - selected tree gets
2329 * edited by default.
2330 * @param {Number} 0 or 1 (optional)- column to edit.
2332 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2334 if (typeof(path) == 'string') {
2335 tp = new Gtk.TreePath.from_string(path);
2338 var s = this.get('/LeftPanel.view').selection;
2339 s.get_selected( itr);
2340 tp = this.el.get_path(itr.iter);
2341 path = tp.to_string();
2345 // which colum is to be edited..
2348 // not sure what this does..
2350 if (typeof(col) == 'undefined') {
2351 var k = this.getValue(path, 0);
2353 colObj = (!k.length || k == '|') ?
2354 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2356 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2359 // make sure the pulldown is set correctly..
2360 // not really needed for second col...
2361 var showEditor = false;
2362 this.get('/Editor').activePath = false;
2363 this.get('/Editor').el.hide();
2366 var provider = this.get('/LeftTree').getPaleteProvider();
2367 var type = this.get('/LeftPanel.model').getType(path);
2368 var opts = provider.findOptions(type);
2369 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2371 if (opts === false) {
2372 this.get('/LeftPanel').editableColumn.setOptions([]);
2373 renderer.has_entry = true;
2375 this.get('/LeftPanel').editableColumn.setOptions(opts);
2376 renderer.has_entry = false;/// - pulldowns do not have entries
2378 // determine if we should use the Text editor...
2379 var keyname = this.getValue(path, 0);
2380 var data_value = this.getValue(path, 1);
2382 if ((keyname[0] == '|') ||
2384 (typeof(data_value) == 'string' ) &&
2385 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2389 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2394 // this.get('/BottomPane').el.hide();
2395 //this.get('/RightEditor').el.hide();
2400 this.activePath = false;
2402 _this.get('/Editor').el.show_all();
2403 GLib.timeout_add(0, 1, function() {
2405 //_this.get('/BottomPane').el.show();
2406 //_this.get('/RightEditor').el.show();
2408 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2410 _this.get('/Editor').activePath = path;
2411 _this.activePath = path ;
2421 // iter now has row...
2422 GLib.timeout_add(0, 100, function() {
2423 _this.activePath = path;
2424 colObj.items[0].el.editable = true; // esp. need for col 0..
2425 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2436 this.get('/LeftPanel.model').el.get_iter_first(iret);
2442 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2445 ar.listeners = ar.listeners || {};
2446 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2449 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2452 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2458 //print(JSON.stringify(ar));
2462 toShort : function(str) {
2463 var a = typeof(str) == 'string' ? str.split("\n") : [];
2464 return a.length > 1 ? a[0] + '....' : '' + str;
2468 xtype: Gtk.TreeViewColumn,
2469 pack : "append_column",
2471 XObject.prototype.init.call(this);
2473 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2474 this.get('/LeftPanel').propertyColumn = this;
2479 xtype: Gtk.CellRendererText,
2480 pack : "pack_start",
2482 editing_started : function (self, editable, path) {
2484 this.get('/LeftPanel.model').activePath = path;
2487 edited : function (self, object, p0) {
2489 print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2491 var model = this.get('/LeftPanel.model');
2492 var path = model.activePath;
2494 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2495 model.el.set_value(iret.iter, 0, p0);
2496 model.el.set_value(iret.iter, 2, p0);
2498 model.activePath = false;
2500 this.get('/LeftTree.model').changed(model.toJS(), true);
2501 this.el.editable = false;
2508 xtype: Gtk.TreeViewColumn,
2509 pack : "append_column",
2512 XObject.prototype.init.call(this);
2513 this.el.add_attribute(this.items[0].el , 'text', 3 );
2514 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2515 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2516 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2518 this.get('/LeftPanel').editableColumn= this;
2520 setOptions : function(ar) {
2521 var m = this.items[0].el.model;
2524 ar.forEach(function(i) {
2528 m.set_value(iret.iter, 0, i);
2534 xtype: Gtk.CellRendererCombo,
2536 edited : function (self, object, p0) {
2538 this.get('/LeftPanel').editing = false;
2539 var ap = this.get('/LeftPanel.model').activePath
2540 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2541 this.get('/LeftPanel.model').changed(p0, true);
2542 this.get('/LeftPanel.model').activePath = false;
2543 this.el.editable = false;
2545 editing_started : function (self, editable, path) {
2546 this.get('/LeftPanel').editing = true;
2547 // console.log('editing started');
2548 // r.has_entry = false;
2550 this.el.editable = false; // make sure it's not editor...
2555 pack : "pack_start",
2559 XObject.prototype.init.call(this);
2560 this.el.model = new Gtk.ListStore();
2561 this.el.model.set_column_types ( 1, [
2562 GObject.TYPE_STRING // 0 real key
2573 id : "LeftPanelPopup",
2576 xtype: Gtk.MenuItem,
2580 activate : function (self) {
2581 this.get('/LeftPanel.model').deleteSelected();
2586 xtype: Gtk.MenuItem,
2590 activate : function (self) {
2591 this.get('/LeftPanel.model').startEditing(false, 0);
2604 xtype: Gtk.ScrolledWindow,
2605 pack : "pack_end,false,true,0",
2608 shadow_type : Gtk.ShadowType.IN,
2610 XObject.prototype.init.call(this);
2611 XObject.prototype.init.call(this);
2612 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2613 this.el.set_size_request ( 150, -1 );
2616 activeElement : false,
2617 hideWin : function() {
2620 print("HIDEWIN - currently not shown")
2625 if (this.get('/Window.left').el.position < 160) {
2626 print("HIDEWIN - small already.")
2630 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2631 print("HIDEWIN attempting to hide.")
2638 xtype: Gtk.TreeView,
2640 cursor_changed : function (self) {
2643 //console.log('changed');
2644 var m = this.get('model');
2645 if (!this.selection){
2646 this.selection = this.el.get_selection();
2649 var s = this.selection;
2650 if (!s.get_selected(iret)) {
2653 var tp = m.el.get_path(iret.iter).to_string();
2658 var key = m.getValue(tp, 0);
2660 var type = m.getValue(tp, 1);
2661 var skel = m.getValue(tp, 3);
2662 var etype = m.getValue(tp, 5);
2665 this.get('/MidPropTree').hideWin();
2667 if (type.toLowerCase() == 'function') {
2669 if (etype != 'events') {
2673 this.get('/LeftPanel.model').add({
2681 // has dot in name, and is boolean???? this does not make sense..
2682 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2686 this.get('/LeftPanel.model').add( {
2696 enable_tree_lines : true,
2697 headers_visible : false,
2699 XObject.prototype.init.call(this);
2701 var description = new Pango.FontDescription.c_new();
2702 description.set_size(8000);
2703 this.el.modify_font(description);
2705 //this.selection = this.el.get_selection();
2706 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2715 xtype: Gtk.ListStore,
2718 getValue : function(treepath, col)
2720 var tp = new Gtk.TreePath.from_string (treepath);
2722 this.el.get_iter (iret, tp);
2723 var value = this.el.get_value(iret.iter, col);
2724 return ''+ value.value.get_string();
2728 XObject.prototype.init.call(this);
2729 this.el.set_column_types ( 6, [
2730 GObject.TYPE_STRING, // real key
2731 GObject.TYPE_STRING, // real type
2732 GObject.TYPE_STRING, // docs ?
2733 GObject.TYPE_STRING, // visable desc
2734 GObject.TYPE_STRING, // function desc
2735 GObject.TYPE_STRING // element type (event|prop)
2739 showData : function(type) {
2741 if (!this.get('/MidPropTree').activeElement || !type) {
2742 return; // no active element
2745 var fullpath = this.get('/LeftTree.model').file.guessName(
2746 this.get('/MidPropTree').activeElement);
2747 var palete = this.get('/LeftTree').getPaleteProvider();
2751 Seed.print('Showing right?');
2752 if (!this.get('/MidPropTree').shown) {
2754 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2755 this.get('/MidPropTree').el.show();
2756 this.get('/MidPropTree').shown = true;
2759 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2760 return a.name > b.name ? 1 : -1;
2762 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2763 // console.dump(elementList);
2767 for(var i =0 ; i < elementList.length; i++) {
2769 var p=elementList[i];
2770 this.el.append(iret);
2771 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2772 //GObject.TYPE_STRING, // real key
2773 // GObject.TYPE_STRING, // real type
2774 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2775 // GObject.TYPE_STRING // func def?
2778 this.el.set_value(iret.iter, 0, p.name);
2779 this.el.set_value(iret.iter, 1, p.type);
2780 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2781 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2782 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2783 this.el.set_value(iret.iter, 5, type);
2790 xtype: Gtk.TreeViewColumn,
2793 this.el = new Gtk.TreeViewColumn();
2794 this.parent.el.append_column(this.el);
2796 XObject.prototype.init.call(this);
2797 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2801 xtype: Gtk.CellRendererText,
2802 pack : "pack_start,true"
2829 xtype: Gtk.Notebook,
2830 pack : "pack_start,true,true",
2831 id : "view-help-nb",
2833 XObject.prototype.init.call(this);
2834 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2835 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2839 xtype: Gtk.Notebook,
2840 id : "view-notebook",
2844 XObject.prototype.init.call(this);
2845 this.el.set_current_page(0);
2846 //print("SET LABEL?")
2847 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2848 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2854 id : "RightBrowser",
2859 pack : "pack_start,false,true,0",
2864 clicked : function (self) {
2865 this.get('/RightBrowser.view').renderJS(null,true);
2869 pack : "pack_start,false,false,0"
2872 xtype: Gtk.CheckButton,
2874 toggled : function (self, state) {
2875 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2880 label : "Auto Redraw On",
2881 pack : "pack_start,false,false,0"
2886 clicked : function (self) {
2887 this.get('/RightBrowser.view').redraws = 99;
2888 this.get('/RightBrowser.view').renderJS(null,true);
2891 label : "Full Redraw",
2892 pack : "pack_start,false,false,0"
2897 xtype: Gtk.ScrolledWindow,
2900 XObject.prototype.init.call(this);
2901 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2903 shadow_type : Gtk.ShadowType.IN,
2906 xtype: WebKit.WebView,
2908 load_finished : function (self, object) {
2909 print("load finished");
2910 // print("load_finished"); return;
2911 // if (this.ready) { // dont do it twice!
2914 if (!this.inspectorShown) {
2915 this.el.get_inspector().show();
2916 this.inspectorShown = true;
2921 if (this.pendingRedraw) {
2922 this.pendingRedraw = false;
2923 this.refreshRequired = true;
2925 //var js = this.get('/LeftTree.model').toJS();
2926 //if (js && js[0]) {
2927 // this.renderJS(js[0]);
2931 script_alert : function (self, object, p0) {
2934 return true; // do not display anything...
2936 console_message : function (self, object, p0, p1) {
2938 // console.log(object);
2941 if (object.match(/variable/) && object.match(/Builder/)) {
2942 print("got builder missing message");
2943 this.refreshRequired = true;
2944 this.lastRedraw = 0;
2950 if (!object.match(/^\{/)) {
2952 //this.get('/Terminal').feed(object);
2953 return true; // do not handle!!! -> later maybe in console..
2959 // console.log(object);
2960 var val = JSON.parse(object);
2962 if (typeof(val['hover-node']) != 'undefined') {
2963 this.activeNode = val['hover-node'];
2964 console.log('active node: ' + this.activeNode);
2969 if (typeof(val['id']) != 'undefined') {
2970 // this.activeNode = val['id'];
2971 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2972 if (!tg || typeof(tg[0]) == 'undefined') {
2975 print("SELECT node " + tg[0]);
2977 this.get('/LeftTree.view').selectNode(tg[0]);
2981 if (ret && typeof(val['set']) != 'undefined') {
2982 this.get('/LeftPanel.model').add({
2986 //console.log('active node: ' + this.activeNode);
2989 //Seed.print('a:'+a);
2990 //Seed.print('b:'+b);
2991 //Seed.print('c:'+c);
2994 drag_motion : function (w, ctx, x, y, time, ud) {
2995 // console.log('DRAG MOTION');
2997 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2998 this.targetData = [];
2999 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3001 // A) find out from drag all the places that node could be dropped.
3002 var src = Gtk.drag_get_source_widget(ctx);
3003 if (!src.dropList) {
3004 Gdk.drag_status(ctx,0, time);
3007 // b) get what we are over.. (from activeNode)
3008 // tree is empty.. - list should be correct..
3009 if (!this.get('/LeftTree.model').currentTree) {
3010 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3014 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3016 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3019 Gdk.drag_status(ctx, 0,time);
3020 this.get('/LeftTree.view').highlight(false);
3024 // if we have a target..
3025 // -> highlight it! (in browser)
3026 // -> highlight it! (in tree)
3028 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3029 this.get('/LeftTree.view').highlight(tg);
3030 this.targetData = tg;
3031 // for tree we should handle this...
3034 drag_drop : function (w, ctx, x, y,time, ud) {
3035 print("TARGET: drag-drop");
3036 var is_valid_drop_site = true;
3040 ( /* will receive 'drag-data-received' signal */
3041 ctx, /* represents the current state of the DnD */
3042 this.get('/Window').atoms["STRING"], /* the target type we want */
3043 time /* time stamp */
3047 /* No target offered by source => error */
3050 return is_valid_drop_site;
3052 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3054 print("Browser: drag-data-received");
3055 var delete_selection_data = false;
3056 vardnd_success = false;
3057 /* Deal with what we are given from source */
3058 if( sel_data && sel_data.length ) {
3060 if (ctx.action == Gdk.DragAction.ASK) {
3061 /* Ask the user to move or copy, then set the ctx action. */
3064 if (ctx.action == Gdk.DragAction.MOVE) {
3065 delete_selection_data = true;
3067 var source = Gtk.drag_get_source_widget(ctx);
3069 print("Browser: source.DRAGDATA? " + source.dragData);
3070 if (this.targetData) {
3071 print(this.targetData);
3072 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3081 if (dnd_success == false)
3083 Seed.print ("DnD data transfer failed!\n");
3086 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3089 create_web_view : function (self, object) {
3090 print("CREATE WEB VIEW");
3091 return null; //new WebKit.WebView();
3098 XObject.prototype.init.call(this);
3099 // this may not work!?
3100 var settings = this.el.get_settings();
3101 settings.enable_developer_extras = true;
3103 // this was an attempt to change the url perms.. did not work..
3104 // settings.enable_file_access_from_file_uris = true;
3105 // settings.enable_offline_web_application_cache - true;
3106 // settings.enable_universal_access_from_file_uris = true;
3110 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3111 _this.get('/BottomPane.inspector').el.show();
3112 return _this.get('/BottomPane.inspector').el;
3116 // FIXME - base url of script..
3117 // we need it so some of the database features work.
3118 this.el.load_html_string( "Render not ready" ,
3119 //fixme - should be a config option!
3120 // or should we catch stuff and fix it up..
3121 'http://localhost/app.Builder/'
3125 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3127 this.el.drag_dest_set
3128 ( /* widget that will accept a drop */
3129 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3130 null, /* lists of target to support */
3131 0, /* size of list */
3132 Gdk.DragAction.COPY /* what to do with data after dropped */
3135 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3136 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3138 GLib.timeout_add_seconds(0, 1, function() {
3139 // print("run refresh?");
3146 renderJS : function(data, force) {
3148 // this is the public redraw call..
3149 // we refresh in a loop privately..
3150 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3151 if (!autodraw && !force) {
3152 print("Skipping redraw - no force, and autodraw off");
3155 this.refreshRequired = true;
3157 runRefresh : function()
3159 // this is run every 2 seconds from the init..
3163 if (!this.refreshRequired) {
3164 // print("no refresh required");
3168 if (this.lastRedraw) {
3169 // do not redraw if last redraw was less that 5 seconds ago.
3170 if (((new Date()) - this.lastRedraw) < 5000) {
3178 if (!this.get('/Window.LeftTree').getActiveFile()) {
3181 this.refreshRequired = false;
3182 // print("HTML RENDERING");
3184 this.get('/BottomPane').el.show();
3185 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3188 var js = this.get('/LeftTree.model').toJS();
3189 if (!js || !js.length) {
3196 var project = this.get('/Window.LeftTree').getActiveFile().project;
3197 //print (project.fn);
3198 // set it to non-empty.
3199 project.runhtml = project.runhtml || '';
3200 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3203 this.runhtml = this.runhtml || '';
3205 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3206 // then we need to reload the browser using
3207 // load_html_string..
3209 // then trigger a redraw once it's loaded..
3210 this.pendingRedraw = true;
3211 var runhtml = '<script type="text/javascript">' + "\n" ;
3212 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3213 runhtml += '</script>'+ "\n" ;
3215 this.runhtml = project.runhtml;
3216 // need to modify paths
3220 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3221 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3222 print("LOAD HTML " + html);
3223 this.el.load_html_string( html ,
3224 //fixme - should be a config option!
3225 'http://localhost/app.Builder/'
3228 // should trigger load_finished! - which in truns shoudl set refresh Required;
3234 this.renderedData = data;
3235 var str = JSON.stringify(data) ;
3238 console.log('not loaded yet');
3240 this.lastRedraw = new Date();
3242 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3243 print( "before render" + this.lastRedraw);
3244 print( "after render" + (new Date()));
3254 id : "RightGtkView",
3256 redraw : function() {
3257 this.highlightWidget = false;
3258 print("REDRAW CALLED");
3259 this.activePath = this.get('/LeftTree').getActivePath();
3260 if (this.renderedEl) {
3261 print("QUEUE DRAW CALLING");
3262 this.renderedEl.queue_draw();
3265 renderJS : function(data, withDebug)
3267 this.highlightWidget = false;
3269 this.withDebug = false;
3270 while (this.get('view').el.get_children().length) {
3271 var c = this.get('view').el.get_children()[0];
3272 this.get('view').el.remove(c);
3279 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3280 // in theory tree is actually window..
3283 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3289 this.get('view').el.set_size_request(
3290 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3292 if (this.renderedEl) {
3293 this.renderedEl.set_size_request(
3294 tree.default_width || 600,
3295 tree.default_height || 400
3298 this.get('view').el.show_all();
3303 showInWindow : function() {
3304 print("GET PROEJCT");
3305 var pr = this.get('/LeftProjectTree').getActiveProject();
3307 console.log(pr.paths);
3310 var src= this.buildJS(
3311 this.get('/LeftTree.model').toJS()[0],
3316 //var x = new imports.sandbox.Context();
3320 Seed.check_syntax('var e = ' + src);
3323 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3324 this.get('/Terminal').feed(console._dump(e)+"\n");
3326 var lines = src.split("\n");
3327 var start = Math.max(0, e.line - 10);
3328 var end = Math.min(lines.length, e.line + 10);
3329 for (var i =start ; i < end; i++) {
3331 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3334 this.get('/Terminal').feed(lines[i] + "\n");
3341 this.get('/BottomPane').el.set_current_page(1);
3342 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3343 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3344 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3346 var _top = x.get_global_object()._top;
3348 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3350 if (_top.el.popup) {
3351 _top.el.popup(null, null, null, null, 3, null);
3355 viewAdd : function(item, par)
3358 // does something similar to xobject..
3359 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3361 // pack is forced to 'false'
3362 if (item.pack===false || item.pack === 'false') { // no ;
3366 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3369 var type = item['|xns'] + '.' + item['xtype'];
3371 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3375 var ns = imports.gi[item['|xns']];
3376 var ctr = ns[item['xtype']]; // why are we using array here..?
3381 for(var k in item) {
3383 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3397 // value is a function..
3398 if (k[0] == '|' && typeof(kv) == 'string') {
3400 if (kv.match(new RegExp('function'))) {
3403 print("WASL " + k + '=' + kv);
3405 eval( 'kv = ' + kv);
3406 } catch(e) { continue; }
3409 // print(k + '=' + kv);
3411 if (k[0] == '|') { // should be boolean or number..
3413 //print(k + '=' + kv);
3416 if (k == 'show_tabs') { // force tab showing for notebooks.
3419 print(k + '=' + typeof(kv) + " : " + kv);
3423 var altctr = XObject.baseXObject({ xtype: ctr} );
3425 if (!item.pack && altctr) {
3427 print("SETTING PACK TO XObjectBase method");
3428 pack_m = altctr.prototype.pack;
3433 var el = new ctr(ctr_args);
3435 print("PACK" + item.pack);
3436 //console.dump(item.pack);
3443 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3444 if (typeof(item.pack) == 'string') {
3446 item.pack.split(',').forEach(function(e, i) {
3448 if (e == 'false') { args.push( false); return; }
3449 if (e == 'true') { args.push( true); return; }
3450 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3453 //print(args.join(","));
3455 pack_m = args.shift();
3457 pack_m = item.pack.shift();
3462 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3464 name: "ArgumentError",
3465 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3466 "ADDING : " + item.id + " " + el
3475 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3476 //Seed.print('args: ' + args.length);
3477 if (typeof(pack_m) == 'string') {
3478 par[pack_m].apply(par, args);
3479 } else if (pack_m) {
3480 pack_m.call(item, par, item);
3484 item.items = item.items || [];
3485 item.items.forEach(function(ch,n) {
3487 print ("type:" + type);
3489 print ("ch.pack:" + ch.pack);
3492 if (type == 'Gtk.Table' && ch.pack == 'add') {
3493 var c = n % item.n_columns;
3494 var r = Math.floor(n/item.n_columns);
3495 ch.pack = [ 'attach', c, c+1, r, r+1,
3496 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3497 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3498 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3499 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3503 _this.viewAdd(ch, el);
3508 // add the signal handlers.
3509 // is it a widget!?!!?
3515 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3516 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3517 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3518 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3519 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3529 widgetDragDropEvent : function() {
3530 print("WIDGET DRAGDROP");
3533 widgetDragMotionEvent : function() {
3534 print("WIDGET DRAGMOTION");
3537 widgetExposeEvent : function(w, evt, ud, item) {
3539 if (this.inRender) {
3543 if ( this.highlightWidget) {
3544 this.inRender = true;
3545 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3546 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3548 this.inRender = false;
3553 if (this.activePath != item.xtreepath) {
3557 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3558 // work out the coords of the window..
3560 var dr = widget.window;
3561 this.gc = (new Gdk.GC.c_new(dr));
3562 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3563 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3567 var r = evt.expose.area;
3568 // console.dump([r.x, r.y, r.width, r.height ] );
3570 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3571 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3572 // happens with gtkscrollview embedded stuff..
3573 var np =this.activePath.split(':');
3575 this.activePath = np.join(':');
3576 this.renderedEl.queue_draw();
3592 this.inRender = true;
3595 this.highlightWidget = widget;
3600 // print("DRAW BOX");
3601 //console.dump(this.box);
3602 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3603 this.inRender = false;
3606 widgetPressEvent : function(w,e,u,d) {
3607 if (this.get('view').pressed) {
3610 this.get('view').pressed = true;
3611 print("WIDGET PRESS " + d.xtreepath );
3612 this.get('/LeftTree.view').selectNode( d.xtreepath );
3615 widgetReleaseEvent : function() {
3616 this.get('view').pressed = false;
3622 pack : "pack_start,false,true,0",
3626 pack : "pack_start,false,false,0",
3627 label : "Run The Application",
3629 button_press_event : function (self, event) {
3630 // call render on left tree - with special option!?!
3632 //print("GET PROEJCT");
3633 var pr = this.get('/LeftProjectTree').getActiveProject();
3636 for (var i in pr.paths) {
3640 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3641 this.get('/Terminal').feed("RUN DIR:" + dir);
3643 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3644 , false,false,false);
3645 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3646 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3656 xtype: Gtk.ScrolledWindow,
3659 shadow_type : Gtk.ShadowType.IN,
3661 XObject.prototype.init.call(this);
3662 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3666 xtype: Gtk.EventBox,
3667 pack : "add_with_viewport",
3669 XObject.prototype.init.call(this);
3670 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3671 red: 0x9F00, green: 0xB800 , blue : 0xA800
3679 XObject.prototype.init.call(this);
3680 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3681 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3686 xtype: Gtk.EventBox,
3689 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3690 XObject.prototype.init.call(this);
3692 this.el.drag_dest_set
3693 ( /* widget that will accept a drop */
3694 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3695 null, /* lists of target to support */
3696 0, /* size of list */
3697 Gdk.DragAction.COPY /* what to do with data after dropped */
3700 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3701 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3704 getActiveNode : function(x,y)
3706 // workout what node is here..
3707 return '0'; // top..
3711 drag_motion : function (self, ctx, x, y, time) {
3713 // A) find out from drag all the places that node could be dropped.
3714 var src = Gtk.drag_get_source_widget(ctx);
3715 if (!src.dropList) {
3716 Gdk.drag_status(ctx, 0, time);
3719 // b) get what we are over.. (from activeNode)
3720 // tree is empty.. - list should be correct..
3721 if (!this.get('/LeftTree.model').currentTree) {
3722 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3726 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3727 var activeNode = this.getActiveNode(x, y);
3730 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3733 Gdk.drag_status(ctx, 0,time);
3734 this.get('/LeftTree.view').highlight(false);
3738 // if we have a target..
3739 // -> highlight it! (in browser)
3740 // -> highlight it! (in tree)
3742 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3743 this.get('/LeftTree.view').highlight(tg);
3744 this.targetData = tg;
3745 // for tree we should handle this...
3748 drag_drop : function (self,ctx, x, y, time) {
3749 Seed.print("TARGET: drag-drop");
3750 var is_valid_drop_site = true;
3754 ( /* will receive 'drag-data-received' signal */
3755 ctx, /* represents the current state of the this.gDnD */
3756 this.get('/Window').atoms["STRING"], /* the target type we want */
3757 time /* time stamp */
3761 /* No target offered by source => error */
3764 return is_valid_drop_site;
3767 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3769 Seed.print("GtkView: drag-data-received");
3770 var delete_selection_data = false;
3771 var dnd_success = false;
3772 /* Deal with what we are given from source */
3773 if( sel_data && sel_data.length ) {
3775 if (ctx.action == Gdk.DragAction.ASK) {
3776 /* Ask the user to move or copy, then set the ctx action. */
3779 if (ctx.action == Gdk.DragAction.MOVE) {
3780 delete_selection_data = true;
3782 var source = Gtk.drag_get_source_widget( ctx );
3784 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3785 if (this.targetData) {
3786 Seed.print(this.targetData);
3787 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3796 if (dnd_success == false)
3798 Seed.print ("DnD data transfer failed!\n");
3801 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3804 button_press_event : function (self, event) {
3805 this.pressed = false;
3821 xtype: Gtk.ScrolledWindow,
3826 var file = this.get('/LeftTree').getActiveFile();
3830 var activeEl = this.get('/LeftTree').getActiveElement();
3831 var xtype = file.guessName( activeEl )
3832 if (!xtype || !xtype.length) {
3835 //this.get('/Window.view-help-nb').el.set_current_page(1);
3837 // get the active element being edited.
3838 var helpurl = file.getHelpUrl(xtype);
3840 // now load the help info in the page..
3841 this.get('help-view').el.open(helpurl);
3845 xtype: WebKit.WebView,
3849 XObject.prototype.init.call(this);
3850 this.get('/Window.help-view').el.open(
3851 "http://devel.akbkhome.com/seed/");
3863 xtype: Gtk.Notebook,
3867 XObject.prototype.init.call(this);
3868 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3869 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3870 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3874 xtype: Gtk.ScrolledWindow,
3878 xtype: Vte.Terminal,
3881 feed : function(istr) {
3882 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3883 // we should make ourselves visable!!!
3884 this.get('/BottomPane').el.show();
3885 this.get('/BottomPane').el.set_current_page(1);
3887 this.el.feed(str ,str.length);
3889 scroll_on_output : true,
3891 XObject.prototype.init.call(this);
3892 this.el.set_size (80, 1000);
3894 scrollback_lines : 1000
3899 xtype: Gtk.ScrolledWindow,
3903 xtype: WebKit.WebView,
3919 this.get('buttonbar').el.show();
3920 this.get('viewbox').el.hide();
3921 var ce = this.get('/Window.centereast').el;
3923 ce.set_position(ce.get_allocated_width() - 30);
3925 print("TRIED TO HIDE");
3928 this.get('buttonbar').el.hide();
3929 this.get('viewbox').el.show();
3930 var ce = this.get('/Window.centereast').el;
3931 print(JSON.stringify(XObject.keys(ce) ,null,4));
3932 ce.set_position(ce.get_allocated_width() - 150);
3934 // this.get('model').expanded();
3946 pack : "pack_start,false,true",
3948 clicked : function (self) {
3949 this.get('/RightPalete').show();
3956 stock : Gtk.STOCK_GOTO_FIRST,
3957 icon_size : Gtk.IconSize.MENU
3967 XObject.prototype.init.call(this);
3968 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3971 enter_notify_event : function (self, event) {
3972 this.get('/RightPalete').show();
3986 pack : "pack_start,false,true",
3995 pack : "pack_start,false,true",
3997 clicked : function (self) {
3998 this.get('/RightPalete').hide();
4005 stock : Gtk.STOCK_GOTO_LAST,
4006 icon_size : Gtk.IconSize.MENU
4013 xtype: Gtk.ScrolledWindow,
4016 XObject.prototype.init.call(this);
4017 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4018 this.el.set_size_request(-1,200);
4020 shadow_type : Gtk.ShadowType.IN,
4023 xtype: Gtk.TreeView,
4025 drag_begin : function (self, ctx) {
4026 // we could fill this in now...
4027 Seed.print('SOURCE: drag-begin');
4032 var s = this.selection;
4033 s.get_selected(iret);
4034 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4036 var pix = this.el.create_row_drag_icon ( path);
4039 if (Gtk.drag_set_icon_surface) {
4040 Gtk.drag_set_icon_surface( ctx, pix );
4042 Gtk.drag_set_icon_pixmap (ctx,
4043 pix.get_colormap(), pix, null, -10, -10);
4046 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4047 if (!this.get('/RightPalete').provider) {
4050 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4051 this.el.dragData = value;
4058 drag_data_get : function (self, drag_context, selection_data, info, time) {
4059 //Seed.print('Palete: drag-data-get: ' + target_type);
4060 if (this.el.dragData && this.el.dragData.length ) {
4061 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4065 //this.el.dragData = "TEST from source widget";
4069 drag_end : function (self, drag_context) {
4070 Seed.print('SOURCE: drag-end');
4071 this.el.dragData = false;
4072 this.el.dropList = false;
4073 this.get('/LeftTree.view').highlight(false);
4076 button_press_event : function (self, event) {
4078 if (!this.get('/Editor').save()) {
4079 // popup!! - click handled..
4086 enable_tree_lines : true,
4087 headers_visible : false,
4089 XObject.prototype.init.call(this);
4090 this.el.set_size_request(150,-1);
4091 // set_reorderable: [1]
4093 var description = new Pango.FontDescription.c_new();
4094 description.set_size(8000);
4095 this.el.modify_font(description);
4097 this.selection = this.el.get_selection();
4098 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4099 // this.selection.signal['changed'].connect(function() {
4100 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4102 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4104 this.el.drag_source_set ( /* widget will be drag-able */
4105 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4106 null, /* lists of target to support */
4107 0, /* size of list */
4108 Gdk.DragAction.COPY /* what to do with data after dropped */
4110 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4112 this.el.drag_source_set_target_list( this.get('/Window').targetList);
4113 this.el.drag_source_add_text_targets( );
4115 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4116 targets = new Gtk.TargetList();
4117 targets.add( LeftTree.atoms["STRING"], 0, 0);
4118 targets.add_text_targets( 1 );
4119 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4121 //if you want to allow text to be output elsewhere..
4122 //Gtk.drag_source_add_text_targets(this.el);
4128 xtype: Gtk.ListStore,
4131 XObject.prototype.init.call(this);
4132 this.el.set_column_types ( 2, [
4133 GObject.TYPE_STRING, // title
4134 GObject.TYPE_STRING // tip
4139 load : function(tr,iter)
4144 //console.log('Project tree load: ' + tr.length);
4146 //this.insert(citer,iter,0);
4147 for(var i =0 ; i < tr.length; i++) {
4150 this.el.append(cret);
4152 this.el.insert(cret,iter,-1);
4157 this.el.set_value(cret.iter, 0, '' + r ); // title
4159 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4160 //if (r.cn && r.cn.length) {
4161 // this.load(r.cn, citer);
4167 getValue : function (iter, col) {
4168 return this.el.get_value(iter, col).value.get_string();
4175 xtype: Gtk.TreeViewColumn,
4176 pack : "append_column",
4178 XObject.prototype.init.call(this);
4179 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4183 xtype: Gtk.CellRendererText,
4205 XObject.cache['/Window'] = Window;