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.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
486 print("click" + ev.type);
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 Gtk.drag_set_icon_surface (ctx, pix);
529 drag_end : function (self, drag_context) {
530 Seed.print('LEFT-TREE: drag-end');
531 this.el.dragData = false;
532 this.el.dropList = false;
533 this.targetData = false;
534 this.get('/LeftTree.view').highlight(false);
537 drag_data_get : function(self, ctx, sel_data, info, time)
547 drag_motion : function (self, ctx, x, y, time) {
548 console.log("LEFT-TREE: drag-motion");
549 var src = Gtk.drag_get_source_widget( ctx);
551 // a drag from elsewhere...- prevent drop..
553 print("no drag data!");
554 Gdk.drag_status(ctx, 0, time);
555 this.targetData = false;
558 var action = Gdk.DragAction.COPY;
559 if (src == this.el) {
560 // unless we are copying!!! ctl button..
561 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
565 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
566 // no children.. -- asume it's ok..
567 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
568 Gdk.drag_status(ctx, action ,time);
572 print("GETTING POS");
573 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
574 print("ISOVER? " + isOver);
576 Gdk.drag_status(ctx, 0 ,time);
577 return false; // not over apoint!?!
579 // drag node is parent of child..
580 console.log("SRC TREEPATH: " + src.treepath);
581 console.log("TARGET TREEPATH: " + data.path.to_string());
583 // nned to check a few here..
584 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
585 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
586 //Gtk.TreeViewDropPosition.AFTER
587 //Gtk.TreeViewDropPosition.BEFORE
589 if (typeof(src.treepath) != 'undefined' &&
590 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
591 print("subpath drag");
592 Gdk.drag_status( ctx, 0 ,time);
597 //print("DUMPING DATA");
598 //console.dump(data);
601 print(data.path.to_string() +' => '+ data.pos);
602 var tg = this.get('/LeftTree.model').findDropNodeByPath(
603 data.path.to_string(), src.dropList, data.pos);
605 this.get('/LeftTree.view').highlight(tg);
607 print("Can not find drop node path");
608 this.targetData = false;
609 Gdk.drag_status(ctx, 0, time);
612 print(JSON.stringify(tg,null,4));
614 this.targetData = tg;
617 Gdk.drag_status(ctx, action ,time);
621 drag_drop : function (w, ctx, x, y, time) {
622 Seed.print("TARGET: drag-drop");
623 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
625 ( /* will receive 'drag-data-received' signal */
626 ctx, /* represents the current state of the DnD */
627 this.get('/Window').atoms["STRING"], /* the target type we want */
628 time /* time stamp */
632 /* No target offered by source => error */
637 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
638 print("Tree: drag-data-received");
640 var delete_selection_data = false;
641 var dnd_success = false;
642 print(JSON.stringify(sel_data, null,4));
643 /* Deal with what we are given from source */
645 // simce I can not be bothered to sort out
646 // drag drop = let's assume it worked...
648 if( true || (sel_data && sel_data.length )) {
650 if (ctx.action == Gdk.DragAction.ASK) {
651 /* Ask the user to move or copy, then set the ctx action. */
654 if (ctx.action == Gdk.DragAction.MOVE) {
655 //delete_selection_data = true;
658 var source = Gtk.drag_get_source_widget( ctx );
660 if (this.targetData) {
661 if (source != this.el) {
662 print("DRAG FROM ANOTHER WIDGET");
663 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
665 // drag around.. - reorder..
666 print("DRAG FROM SELF");
667 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
671 //Seed.print(this.targetData);
677 // we can send stuff to souce here...
683 if (dnd_success == false)
685 Seed.print ("DnD data transfer failed!\n");
688 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
691 cursor_changed : function (self) {
692 if (this.blockChanges) { // probably not needed..
695 var render = this.get('/LeftTree').getRenderer();
698 if (this.selection.count_selected_rows() < 1) {
699 this.get('/LeftPanel.model').load( false);
700 this.get('/MidPropTree').activeElement = false;
701 this.get('/MidPropTree').hideWin();
703 var pm = this.get('/RightPalete.model');
704 if (!this.get('/LeftTree').getPaleteProvider()) {
705 // it may not be loaded yet..
708 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
709 this.get('/LeftTree.model').listAllTypes()));
710 if (render && render.redraw) {
716 //console.log('changed');
717 var s = this.selection;
722 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
723 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
725 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
728 var data = JSON.parse(value);
729 this.get('/MidPropTree').activeElement = data;
730 this.get('/MidPropTree').hideWin();
731 this.get('/LeftPanel.model').load( data);
734 // _g.button.set_label(''+value.get_string());
736 var pm =this.get('/RightPalete.model');
737 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
738 this.get('/LeftTree.model').listAllTypes()));
741 if (render && render.redraw) {
745 //Seed.print( value.get_string());
753 enable_tree_lines : true,
754 headers_visible : false,
755 highlight : function(treepath_ar) {
757 // highlighting for drag/drop
758 if (treepath_ar.length && treepath_ar[0].length ) {
759 this.el.set_drag_dest_row(
760 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
762 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
768 XObject.prototype.init.call(this);
769 var description = new Pango.FontDescription.c_new();
770 description.set_size(8000);
771 this.el.modify_font(description);
773 this.selection = this.el.get_selection();
774 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
777 // is this really needed??
778 this.selection.signal['changed'].connect(function() {
779 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
780 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
784 this.el.drag_source_set( /* widget will be drag-able */
785 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
786 null, /* lists of target to support */
787 0, /* size of list */
788 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
791 this.el.drag_source_set_target_list(this.get('/Window').targetList);
793 this.el.drag_source_add_text_targets();
794 this.el.drag_dest_set
796 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
797 null, /* lists of target to support */
798 0, /* size of list */
799 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
802 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
803 this.el.drag_dest_add_text_targets( );
805 selectNode : function(treepath_str) {
806 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
807 var tp = new Gtk.TreePath.from_string(treepath_str);
808 this.el.set_cursor(tp, null, false);
809 this.el.scroll_to_cell(tp, null, false, 0,0);
813 xtype: Gtk.TreeStore,
819 setFromNode : function(tp, n)
822 tp = this.get('/LeftTree').getActivePath();
825 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
826 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
827 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
828 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
832 changed : function( refresh) {
836 print("-------MODEL CHANGED CALLED" );
838 //this.currentTree = this.toJS(false, true)[0];
840 this.file.items = this.toJS(false, false);
841 print ("TO JS in " + ((new Date()) - d) + "ms");
842 // print("AFTER CHANGED");
843 //console.dump(this.file.items);
845 this.currentTree = this.file.items[0];
846 //console.log(this.file.toSource());
849 print("REDNER BROWSER?!");
850 this.get('/LeftTree').renderView();
852 var pm = this.get('/RightPalete.model');
853 if (!this.get('/RightPalete').provider) {
859 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
860 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
864 deleteSelected : function() {
865 this.get('/LeftTree.view').blockChanges = true;
867 var s = this.get('/LeftTree.view').selection;
868 s.get_selected(oret);
869 var path = this.el.get_path(oret.iter).to_string();
871 this.activePath= false;
874 this.activePath= false;
876 this.el.get_iter_from_string(ret, path);
877 this.el.remove(ret.iter);
879 // rebuild treemap. -- depreciated.!!
882 //this.toJS(null, true) // does not do anything?
883 this.activePath= false;
885 this.get('/LeftTree.view').blockChanges = false;
887 dropNode : function(target_data, node) {
889 // console.dump(node);
890 //print(JSON.Stringify(target_data, null, 4));
891 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
893 print("add " + tp + "@" + target_data[1] );
896 if (tp && target_data[1] < 2) { // before or after..
897 var ar = target_data[0].split(':');
899 parent = new Gtk.TreePath.from_string( ar.join(':') );
904 var aret = after ? {} : false;
908 if (parent !== false) {
909 this.el.get_iter(pret, parent);
916 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
917 this.el.get_iter(aret, after);
918 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
919 nret, pret.iter, aret.iter);
922 this.el.append(nret, pret.iter);
925 var new_path = this.el.get_path(nret.iter).to_string();
926 print("new path = " + new_path)
927 if (typeof(node) == 'string') {
928 var ar = node.split('.');
929 var xtype = ar.pop();
932 '|xns' : ar.join('.'),
935 if (target_data.length == 3 && target_data[2].length) {
936 node['*prop'] = target_data[2];
938 node = this.get('/DialogTemplateSelect').show(node);
941 // work out what kind of packing to use..
942 if (typeof(node.pack) == 'undefined' && parent !== false) {
943 var pal = this.get('/LeftTree').getPaleteProvider();
944 if (pal.name == 'Gtk') {
945 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
946 var cname = pal.guessName(node);
947 node.pack = pal.getDefaultPack(pname, cname);
958 // load children - if it has any..
961 this.load(xitems, nret.iter);
962 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
964 if (tp && (xitems || after)) {
965 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
967 // wee need to get the empty proptypes from somewhere..
969 //var olditer = this.activeIter;
970 //this.activePath = new_path;
971 print("calling changed with node data")
972 // changed actually set's the node data..
973 this.setFromNode(new_path,node);
978 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
980 //Builder.MidPropTree._model.load(node);
981 //Builder.MidPropTree._win.hideWin();
982 //Builder.LeftPanel._model.load( node);
986 findDropNode : function(treepath_str, targets) {
988 // this is used by the dragdrop code in the roo version AFAIR..
990 var path = treepath_str.replace(/^builder-/, '');
991 // treemap is depreciated... - should really check if model has any entries..
993 if (!this.el.iter_n_children(null)) {
995 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
997 print("FIND treepath: " + path);
998 //console.dump(this.treemap);
1000 if (!treepath_str.match(/^builder-/)) {
1001 return []; // nothing!
1003 if (targets === true) {
1006 return this.findDropNodeByPath(path,targets)
1008 findDropNodeByPath : function(treepath_str, targets, pref) {
1009 var path = treepath_str + ''; // dupe it..
1010 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1012 //console.dump(this.treemap);
1013 while (path.length) {
1014 print("LOOKING FOR PATH: " + path);
1015 var node_data = this.singleNodeToJS(path);
1016 if (node_data === false) {
1017 print("node not found");
1021 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1024 targets.forEach(function(tg) {
1028 if ((tg == xname) ) {
1031 if (tg.indexOf(xname +':') === 0) {
1033 prop = tg.split(':').pop();
1038 if (last) { // pref is after/before..
1039 // then it's after last
1041 return []; // do not allow..
1043 return [ last, pref , prop];
1046 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1048 var par = path.split(':');
1051 path = par.join(':');
1057 getIterValue : function (iter, col) {
1059 var gval = ''+this.el.get_value(iter, col).value.get_string();
1065 XObject.prototype.init.call(this);
1066 this.el.set_column_types ( 3, [
1067 GObject.TYPE_STRING, // title
1068 GObject.TYPE_STRING, // tip
1069 GObject.TYPE_STRING // source..
1072 listAllTypes : function() {
1073 var s = this.get('/LeftTree.view').selection;
1074 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1076 if (s.count_selected_rows() > 0) {
1078 s.get_selected(ret);
1080 // set some properties of the tree for use by the dropped element.
1081 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1082 var data = JSON.parse(value);
1085 var xname = this.get('/LeftTree.model').file.guessName(data);
1086 console.log('selected:' + xname);
1090 return []; // could not find it..
1098 li.forEach(function(el) {
1099 // this is specific to roo!!!?
1100 if (!el) { // skip empty?
1103 var fullpath = _this.file.guessName(el);
1104 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1109 if (el.items && el.items.length) {
1118 addall([this.currentTree]);
1120 // only if we have nothing, should we add '*top'
1124 //console.log('all types in tree');
1125 //console.dump(ret);
1130 load : function(tr,iter)
1132 //this.insert(citer,iter,0);
1134 for(var i =0 ; i < tr.length; i++) {
1137 this.el.insert(ret ,iter,-1);
1139 this.el.append(ret);
1141 print(JSON.stringify(ret,null,4));
1142 print('call nodeToJSON: ' + tr[i]);
1143 var body = this.nodeToJSON(tr[i]);
1145 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1146 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1147 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1148 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1149 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1150 this.el.set_value(ret.iter, 2, '' + body );
1151 if (tr[i].items && tr[i].items.length) {
1152 this.load(tr[i].items, ret.iter);
1156 loadFile : function(f) {
1162 console.log('missing file');
1166 // load the file if not loaded..
1167 if (f.items === false) {
1169 f.loadItems(function() {
1175 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1177 if (f.items.length && typeof(f.items[0]) == 'string') {
1179 //this.get('/RightEditor').el.show();
1180 //this.get('/RightEditor.view').load( f.items[0]);
1184 print(JSON.stringify(f.items, null,4));
1185 //console.dump(f.items);
1187 this.get('/LeftTree.view').el.expand_all();
1189 if (!f.items.length) {
1192 this.get('/Window.leftvpaned').el.set_position(80);
1194 this.get('/LeftTree.view').el.set_cursor(
1195 new Gtk.TreePath.from_string('0'), null, false);
1199 this.get('/Window.leftvpaned').el.set_position(200);
1202 //return; -- debuggin
1203 //print("hide right editior");
1204 //this.get('/RightEditor').el.hide();
1205 this.get('/Editor').el.hide();
1206 print("set current tree");
1207 this.currentTree = this.toJS(false, false)[0];
1208 console.dump(this.currentTree);
1209 this.currentTree = this.currentTree || { items: [] };
1210 this.get('/LeftTree').renderView();
1211 console.dump(this.map);
1212 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1213 var pm = this.get('/RightPalete.model');
1214 // set up provider..
1216 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1218 if (!this.get('/RightPalete').provider) {
1219 print ("********* PALETE PROVIDER MISSING?!!");
1221 this.get('/LeftTree').renderView();
1223 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1227 this.get('/Window.view-notebook').el.set_current_page(
1228 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1231 moveNode : function(target_data, action) {
1232 //print("MOVE NODE");
1233 // console.dump(target_data);
1235 var s = this.get('/LeftTree.view').selection;
1236 s.get_selected( oret);
1237 var node = this.nodeToJS(oret.iter,false);
1238 //console.dump(node);
1239 print(JSON.stringify(node, null,4));
1241 // needs to drop first, otherwise the target_data
1242 // treepath will be invalid.
1244 this.dropNode(target_data, node);
1245 if (action & Gdk.DragAction.MOVE) {
1246 // print("REMOVING OLD NODE");
1247 this.el.remove(oret.iter);
1251 this.activePath= false;
1254 nodeTip : function(c) {
1255 var ret = this.nodeTitle(c,true);
1261 if (!i.length || i[0] != '|') {
1267 if (typeof(c[i]) != 'string') {
1270 //print("prop : " + i + ':' + c[i]);
1271 if (!c[i].match(new RegExp('function'))) {
1274 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1278 ret+="\n\nMethods:" + funcs;
1283 nodeTitle : function(c, renderfull) {
1286 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1287 if (sr) txt.push('<s>');
1288 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1290 if (renderfull && c['|xns']) {
1291 txt.push(c['|xns']);
1294 if (c.xtype) { txt.push(c.xtype); }
1295 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1296 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1297 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1300 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1301 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1302 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1303 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1304 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1305 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1306 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1307 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1308 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1310 // for flat classes...
1311 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1312 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1315 if (sr) txt.push('</s>');
1316 return (txt.length == 0 ? "Element" : txt.join(" "));
1318 nodeToJS : function (treepath, with_id)
1320 print("nodeToJS : WITHID: "+ with_id);
1321 var iter = treepath; // API used to be iter here..
1322 if (typeof(iter) == 'string') {
1324 if (!this.el.get_iter(ret,
1325 new Gtk.TreePath.from_string(treepath))) {
1331 var iv = this.getIterValue(iter, 2);
1332 // print("IV" + iv);
1333 var k = JSON.parse(iv);
1334 if (k.json && !this.el.iter_parent( pret, iter )) {
1339 var treepath_str = this.el.get_path(iter).to_string();
1340 // not sure how we can handle mixed id stuff..
1341 if (typeof(k.id) == 'undefined') {
1342 k.id = 'builder-'+ treepath_str ;
1346 this.treemap[ treepath_str ] = k;
1347 k.xtreepath = treepath_str ;
1350 if (this.el.iter_has_child(iter)) {
1352 this.el.iter_children(cret, iter);
1353 k.items = this.toJS(cret.iter,with_id);
1357 nodeToJSON : function(c) {
1365 return JSON.stringify(o);
1367 singleNodeToJS : function (treepath)
1370 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1374 var iv = this.getIterValue(ret.iter, 2);
1376 return JSON.parse(iv);
1379 toJS : function(treepath, with_id)
1381 print("toJS : WITHID: "+ with_id);
1382 var iter = treepath; // API used to be iter here..
1383 if (typeof(iter) == 'string') {
1385 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1395 if (!this.el.get_iter_first(ret)) {
1406 var k = this.nodeToJS(iter, with_id);
1410 if (!this.el.iter_next(iter)) {
1415 if (treepath === false) {
1417 return JSON.parse(JSON.stringify(ar));
1421 // convert the list into a json string..
1427 xtype: Gtk.TreeViewColumn,
1428 pack : "append_column",
1430 XObject.prototype.init.call(this);
1431 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1435 xtype: Gtk.CellRendererText,
1445 id : "LeftTreeMenu",
1448 xtype: Gtk.MenuItem,
1450 label : "Delete Element",
1452 activate : function (self) {
1454 this.get('/LeftTree.model').deleteSelected();
1459 xtype: Gtk.MenuItem,
1461 activate : function (self) {
1463 var tree = this.get('/LeftTree');
1464 var model = this.get('/LeftTree.model');
1465 var el = tree.getActivePath();
1467 var js = model.toJS(el, false);
1468 // print(JSON.stringify(js[0], null,4));
1469 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1474 label : "Save as Template",
1484 id : "LeftProjectTree",
1485 showNoProjectSelected : function() {
1486 this.get('/StandardErrorDialog').show("Select a Project first.");
1488 getActiveProject : function() {
1489 return this.project;
1492 leave_notify_event : function (self, event) {
1499 pack : "pack_start,false,false",
1502 xtype: Gtk.ComboBox,
1504 changed : function (self) {
1505 var fn = this.getValue();
1506 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1507 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1511 getValue : function() {
1512 var ix = this.el.get_active();
1516 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1517 if (typeof(data[ix]) == 'undefined') {
1523 XObject.prototype.init.call(this);
1524 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1526 setValue : function(fn)
1530 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1531 data.forEach(function(n, ix) {
1540 xtype: Gtk.CellRendererText,
1541 pack : "pack_start,true",
1545 xtype: Gtk.ListStore,
1549 XObject.prototype.init.call(this);
1550 this.el.set_column_types ( 2, [
1551 GObject.TYPE_STRING, // real key
1552 GObject.TYPE_STRING // real type
1556 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1557 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1559 pm.on('changed', function() {
1560 print("caught changed hook on project manager - reloading data");
1561 _this.loadData(pm.projects);
1565 loadData : function(data) {
1566 var ov = this.get('/LeftProjectTree.combo').getValue();
1570 data.forEach(function(p) {
1573 print(JSON.stringify(XObject.keys(na)));
1574 print(typeof(na.iter));
1575 //print(JSON.stringify(iter))
1576 el.set_value(na.iter, 0, p.fn);
1577 el.set_value(na.iter, 1, p.name);
1581 this.get('/LeftProjectTree.combo').setValue(ov);
1589 xtype: Gtk.ScrolledWindow,
1591 shadow_type : Gtk.ShadowType.IN,
1593 XObject.prototype.init.call(this);
1594 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1598 xtype: Gtk.TreeView,
1600 cursor_changed : function (self) {
1602 if (this.selection.count_selected_rows() < 1) {
1603 //XN.get('Builder.LeftTree.model').
1604 this.get('/LeftTree.model').load( false);
1608 var model = this.get('/LeftProjectTree.model');
1609 //console.log('changed');
1610 var s = this.selection;
1611 s.get_selected(ret);
1612 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1613 //console.log(JSON.stringify(value,null,4));// id..
1614 console.log("OUT?" + value);// id..
1615 var file = this.get('/LeftProjectTree').project.getById(value);
1622 var nb = this.get('/LeftTopPanel.expander');
1623 nb.el.expanded = false;
1625 //nb.listeners.activate.call(nb);
1626 //_expander.el.set_expanded(false);
1628 var ltm = this.get('/LeftTree.model');
1636 enable_tree_lines : true,
1637 headers_visible : false,
1639 XObject.prototype.init.call(this);
1640 var description = new Pango.FontDescription.c_new();
1641 description.set_size(8000);
1642 this.el.modify_font(description);
1644 this.selection = this.el.get_selection();
1645 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1649 xtype: Gtk.TreeStore,
1653 XObject.prototype.init.call(this);
1654 this.el.set_column_types ( 3, [
1655 GObject.TYPE_STRING, // title
1656 GObject.TYPE_STRING, // tip
1657 GObject.TYPE_STRING // id..
1661 loadProject : function(pr) {
1662 print("LOAD PROJECT");
1668 this.get('/LeftProjectTree').project = pr;
1669 this.load(pr.toTree());
1670 this.get('/LeftProjectTree.view').el.expand_all();
1672 load : function(tr,iter) {
1673 // console.dump(tr);
1674 console.log('Project tree load: ' + tr.length);
1676 //this.insert(citer,iter,0);
1679 tr.forEach(function (r) {
1681 _this.el.append(cret);
1683 _this.el.insert(cret,iter,-1);
1685 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1686 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1687 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1688 if (r.cn && r.cn.length) {
1689 _this.load(r.cn, cret.iter);
1694 getValue : function(iter, col) {
1695 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1700 xtype: Gtk.TreeViewColumn,
1701 pack : "append_column",
1703 XObject.prototype.init.call(this);
1704 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1708 xtype: Gtk.CellRendererText,
1728 pack : "pack_start,false,true,0",
1735 button_press_event : function (self, event) {
1736 this.get('/MidPropTree.model').showData('props');
1748 stock : Gtk.STOCK_ADD,
1749 icon_size : Gtk.IconSize.MENU
1763 button_press_event : function (self, event) {
1765 if (!this.get('/Editor').save()) {
1766 // popup!! - click handled..
1769 this.get('/MidPropTree.model').showData('events');
1782 stock : Gtk.STOCK_ADD,
1783 icon_size : Gtk.IconSize.MENU
1797 button_press_event : function (self, ev) {
1799 if (!this.get('/Editor').save()) {
1800 // popup!! - click handled..
1804 var p = this.get('/AddPropertyPopup');
1808 p.el.set_screen(Gdk.Screen.get_default());
1810 p.el.popup(null, null, null, null, 3, ev.button.time);
1823 stock : Gtk.STOCK_ADD,
1824 icon_size : Gtk.IconSize.MENU
1836 id : "AddPropertyPopup",
1839 xtype: Gtk.MenuItem,
1841 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1844 activate : function (self) {
1846 this.get('/LeftPanel.model').add( {
1857 xtype: Gtk.MenuItem,
1859 tooltip_markup : "Add what type of packing is to be used",
1862 activate : function (self) {
1864 this.get('/LeftPanel.model').add( {
1874 xtype: Gtk.MenuItem,
1876 tooltip_markup : "Override the init method",
1879 activate : function (self) {
1881 this.get('/LeftPanel.model').add( {
1884 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1891 xtype: Gtk.SeparatorMenuItem,
1895 xtype: Gtk.MenuItem,
1897 tooltip_markup : "Add a user defined string property",
1900 activate : function (self) {
1902 this.get('/LeftPanel.model').add( {
1912 xtype: Gtk.MenuItem,
1914 tooltip_markup : "Add a user defined number property",
1917 activate : function (self) {
1919 this.get('/LeftPanel.model').add( {
1929 xtype: Gtk.MenuItem,
1931 tooltip_markup : "Add a user defined boolean property",
1934 activate : function (self) {
1936 this.get('/LeftPanel.model').add( {
1946 xtype: Gtk.SeparatorMenuItem,
1950 xtype: Gtk.MenuItem,
1952 tooltip_markup : "Add a user function boolean property",
1955 activate : function (self) {
1957 this.get('/LeftPanel.model').add( {
1960 val : "function() {\n \n}\n",
1973 xtype: Gtk.ScrolledWindow,
1978 XObject.prototype.init.call(this);
1979 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1981 shadow_type : Gtk.ShadowType.IN,
1984 xtype: Gtk.TreeView,
1986 button_press_event : function (self, ev) {
1989 if (!this.get('/Editor').save()) {
1990 // popup!! - click handled..
1995 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1996 return false; //not on a element.
2000 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
2002 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2005 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2006 var p = this.get('/LeftPanelPopup');
2011 p.el.set_screen(Gdk.Screen.get_default());
2013 p.el.popup(null, null, null, null, 3, ev.button.time);
2014 //Seed.print("click:" + res.column.title);
2021 if (res.column.title != 'value') {
2022 // XObject.error("column is not value?");
2023 return false; // ignore.. - key click.. ??? should we do this??
2026 // currently editing???
2027 // if ( this.activePath) {
2029 // this.activePath = false;
2031 if (this.get('/Editor').dirty) {
2032 //if (!this.get('/Editor.buffer').checkSyntax()) {
2033 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2037 if (!this.get('/Editor.view').save()) {
2041 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2042 this.get('/LeftPanel').editing = false;
2044 // XObject.error("Currently editing?");
2048 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2050 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2052 // get options for this type -- this is to support option lists etc..
2053 var provider = this.get('/LeftTree').getPaleteProvider();
2054 var opts = provider.findOptions(type);
2056 if (opts === false) {
2058 this.get('/LeftPanel').editableColumn.setOptions([]);
2059 renderer.has_entry = true;
2061 this.get('/LeftPanel').editableColumn.setOptions(opts);
2062 renderer.has_entry = false;
2064 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2066 //Seed.print("click" + ev.type);
2067 //console.dump(res);
2076 enable_tree_lines : true,
2077 headers_visible : false,
2079 XObject.prototype.init.call(this);
2081 this.selection = this.el.get_selection();
2082 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2085 var description = new Pango.FontDescription.c_new();
2086 description.set_size(8000);
2087 this.el.modify_font(description);
2091 xtype: Gtk.TreeStore,
2095 add : function(info) {
2096 // info includes key, val, skel, etype..
2098 type = info.type.toLowerCase();
2099 var data = this.toJS();
2101 if (info.etype == 'events') {
2102 data.listeners = data.listeners || { };
2103 if (typeof(data.listeners[info.key]) != 'undefined') {
2104 return; //already set!
2107 if (typeof(data[info.key]) != 'undefined') {
2112 if (typeof(info.val) == 'undefined') {
2115 if (info.type.toLowerCase() == 'boolean') {
2118 if (type == 'number') {
2126 if (info.etype == 'events') {
2128 data.listeners[info.key] = info.val;
2131 data[info.key] = info.val;
2135 var map = this.load(data);
2137 // flag it as changed to the interface..
2138 this.get('/LeftTree.model').setFromNode(false,node);
2139 this.get('/LeftTree.model').changed(true);
2142 this.startEditing(map[k]);
2145 LeftPanel.get('view').el.row_activated(
2146 new Gtk.TreePath.from_string(map[k]),
2147 LeftPanel.editableColumn.el
2151 changed : function(str, doRefresh) {
2152 if (!this.activePath) {
2153 print("NO active path when changed")
2157 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2159 this.el.set_value(ret.iter, 1, '' +str);
2160 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2161 var type = this.getIterValue(ret.iter, 4);
2163 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2164 // update the tree...
2165 print("new data: " + JSON.stringify(this.toJS() , null,4));
2166 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2167 this.get('/LeftTree.model').changed(doRefresh);
2170 deleteSelected : function() {
2171 var data = this.toJS();
2173 var s = this.get('/LeftPanel.view').selection;
2174 s.get_selected( ret);
2177 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2179 if (val[0] == '!') {
2181 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2184 delete data.listeners[ val.substring(1)];
2185 if (!XObject.keys(data.listeners).length) {
2186 delete data.listeners;
2190 if (typeof(data[val]) == 'undefined') {
2198 this.get('/LeftTree.model').changed(data, true);
2201 getIterValue : function(iter, col) {
2202 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2205 getType : function(treepath) {
2206 return this.getValue(treepath, 4);
2208 getValue : function(treepath_str, col)
2210 // get's the value in a row.. - keys - returns string, values - formats it..
2212 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2214 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2219 var type = this.getType(this.el.get_path(ret.iter).to_string());
2220 //print("TYPE: " +type + " - val:" + val);
2221 switch(type.toLowerCase()) {
2225 return parseFloat(val); // Nan ?? invalid!!?
2228 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2230 return val == 'true' ? true : false;
2232 var nv = parseFloat(val);
2233 if (!isNaN(nv) && (val == ''+nv)) {
2241 XObject.prototype.init.call(this);
2242 this.el.set_column_types ( 6, [
2243 GObject.TYPE_STRING, // 0 real key
2244 GObject.TYPE_STRING, // 1 real value
2245 GObject.TYPE_STRING, // 2 visable key
2246 GObject.TYPE_STRING, // 3 visable value
2247 GObject.TYPE_STRING, // 4 need to store type of!!!
2248 GObject.TYPE_STRING // 5 tooltip
2252 load : function(ar) {
2253 // might casue problesm..
2254 // this.get('/Editor.RightEditor').save();
2256 this.get('/Editor').el.hide();
2257 this.get('/Editor').activePath = false;
2262 //this.get('/RightEditor').el.hide();
2269 var provider = this.get('/LeftTree').getPaleteProvider();
2273 var keys = XObject.keys(ar);
2275 ar.listeners = ar.listeners || {};
2277 for (var i in ar.listeners ) {
2279 this.el.append(iret);
2280 var p = this.el.get_path(iret.iter).to_string();
2283 this.el.set_value(iret.iter, 0, '!'+ i );
2284 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2285 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2287 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2288 this.el.set_value(iret.iter, 4, 'function');
2289 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2295 keys.forEach(function(i) {
2296 if (typeof(ar[i]) == 'object') {
2300 var type = provider.findType(ar, i, ar[i]);
2302 _this.el.append(iret);
2303 var p = _this.el.get_path(iret.iter).to_string();
2305 _this.el.set_value(iret.iter, 0, ''+i);
2306 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2307 _this.el.set_value(iret.iter, 2, ''+i);
2308 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2309 _this.el.set_value(iret.iter, 4, ''+type);
2310 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2314 startEditing : function(path,col) {
2316 // alled by menu 'edit' currently..
2318 * start editing path (or selected if not set..)
2319 * @param {String|false} path (optional) treepath to edit - selected tree gets
2320 * edited by default.
2321 * @param {Number} 0 or 1 (optional)- column to edit.
2323 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2325 if (typeof(path) == 'string') {
2326 tp = new Gtk.TreePath.from_string(path);
2329 var s = this.get('/LeftPanel.view').selection;
2330 s.get_selected( itr);
2331 tp = this.el.get_path(itr.iter);
2332 path = tp.to_string();
2336 // which colum is to be edited..
2339 // not sure what this does..
2341 if (typeof(col) == 'undefined') {
2342 var k = this.getValue(path, 0);
2344 colObj = (!k.length || k == '|') ?
2345 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2347 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2350 // make sure the pulldown is set correctly..
2351 // not really needed for second col...
2352 var showEditor = false;
2353 this.get('/Editor').activePath = false;
2354 this.get('/Editor').el.hide();
2357 var provider = this.get('/LeftTree').getPaleteProvider();
2358 var type = this.get('/LeftPanel.model').getType(path);
2359 var opts = provider.findOptions(type);
2360 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2362 if (opts === false) {
2363 this.get('/LeftPanel').editableColumn.setOptions([]);
2364 renderer.has_entry = true;
2366 this.get('/LeftPanel').editableColumn.setOptions(opts);
2367 renderer.has_entry = false;/// - pulldowns do not have entries
2369 // determine if we should use the Text editor...
2370 var keyname = this.getValue(path, 0);
2371 var data_value = this.getValue(path, 1);
2373 if ((keyname[0] == '|') ||
2375 (typeof(data_value) == 'string' ) &&
2376 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2380 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2385 // this.get('/BottomPane').el.hide();
2386 //this.get('/RightEditor').el.hide();
2391 this.activePath = false;
2393 _this.get('/Editor').el.show_all();
2394 GLib.timeout_add(0, 1, function() {
2396 //_this.get('/BottomPane').el.show();
2397 //_this.get('/RightEditor').el.show();
2399 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2401 _this.get('/Editor').activePath = path;
2402 _this.activePath = path ;
2412 // iter now has row...
2413 GLib.timeout_add(0, 100, function() {
2414 _this.activePath = path;
2415 colObj.items[0].el.editable = true; // esp. need for col 0..
2416 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2427 this.get('/LeftPanel.model').el.get_iter_first(iret);
2433 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2436 ar.listeners = ar.listeners || {};
2437 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2440 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2443 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2449 //print(JSON.stringify(ar));
2453 toShort : function(str) {
2454 var a = typeof(str) == 'string' ? str.split("\n") : [];
2455 return a.length > 1 ? a[0] + '....' : '' + str;
2459 xtype: Gtk.TreeViewColumn,
2460 pack : "append_column",
2462 XObject.prototype.init.call(this);
2464 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2465 this.get('/LeftPanel').propertyColumn = this;
2470 xtype: Gtk.CellRendererText,
2471 pack : "pack_start",
2473 editing_started : function (self, editable, path) {
2475 this.get('/LeftPanel.model').activePath = path;
2478 edited : function (self, object, p0) {
2480 print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2482 var model = this.get('/LeftPanel.model');
2483 var path = model.activePath;
2485 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2486 model.el.set_value(iret.iter, 0, p0);
2487 model.el.set_value(iret.iter, 2, p0);
2489 model.activePath = false;
2491 this.get('/LeftTree.model').changed(model.toJS(), true);
2492 this.el.editable = false;
2499 xtype: Gtk.TreeViewColumn,
2500 pack : "append_column",
2503 XObject.prototype.init.call(this);
2504 this.el.add_attribute(this.items[0].el , 'text', 3 );
2505 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2506 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2507 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2509 this.get('/LeftPanel').editableColumn= this;
2511 setOptions : function(ar) {
2512 var m = this.items[0].el.model;
2515 ar.forEach(function(i) {
2519 m.set_value(iret.iter, 0, i);
2525 xtype: Gtk.CellRendererCombo,
2527 edited : function (self, object, p0) {
2529 this.get('/LeftPanel').editing = false;
2530 var ap = this.get('/LeftPanel.model').activePath
2531 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2532 this.get('/LeftPanel.model').changed(p0, true);
2533 this.get('/LeftPanel.model').activePath = false;
2534 this.el.editable = false;
2536 editing_started : function (self, editable, path) {
2537 this.get('/LeftPanel').editing = true;
2538 // console.log('editing started');
2539 // r.has_entry = false;
2541 this.el.editable = false; // make sure it's not editor...
2546 pack : "pack_start",
2550 XObject.prototype.init.call(this);
2551 this.el.model = new Gtk.ListStore();
2552 this.el.model.set_column_types ( 1, [
2553 GObject.TYPE_STRING // 0 real key
2564 id : "LeftPanelPopup",
2567 xtype: Gtk.MenuItem,
2571 activate : function (self) {
2572 this.get('/LeftPanel.model').deleteSelected();
2577 xtype: Gtk.MenuItem,
2581 activate : function (self) {
2582 this.get('/LeftPanel.model').startEditing(false, 0);
2595 xtype: Gtk.ScrolledWindow,
2596 pack : "pack_end,false,true,0",
2599 shadow_type : Gtk.ShadowType.IN,
2601 XObject.prototype.init.call(this);
2602 XObject.prototype.init.call(this);
2603 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2604 this.el.set_size_request ( 150, -1 );
2607 activeElement : false,
2608 hideWin : function() {
2611 print("HIDEWIN - currently not shown")
2616 if (this.get('/Window.left').el.position < 160) {
2617 print("HIDEWIN - small already.")
2621 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2622 print("HIDEWIN attempting to hide.")
2629 xtype: Gtk.TreeView,
2631 cursor_changed : function (self) {
2634 //console.log('changed');
2635 var m = this.get('model');
2636 if (!this.selection){
2637 this.selection = this.el.get_selection();
2640 var s = this.selection;
2641 if (!s.get_selected(iret)) {
2644 var tp = m.el.get_path(iret.iter).to_string();
2649 var key = m.getValue(tp, 0);
2651 var type = m.getValue(tp, 1);
2652 var skel = m.getValue(tp, 3);
2653 var etype = m.getValue(tp, 5);
2656 this.get('/MidPropTree').hideWin();
2658 if (type.toLowerCase() == 'function') {
2660 if (etype != 'events') {
2664 this.get('/LeftPanel.model').add({
2672 // has dot in name, and is boolean???? this does not make sense..
2673 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2677 this.get('/LeftPanel.model').add( {
2687 enable_tree_lines : true,
2688 headers_visible : false,
2690 XObject.prototype.init.call(this);
2692 var description = new Pango.FontDescription.c_new();
2693 description.set_size(8000);
2694 this.el.modify_font(description);
2696 //this.selection = this.el.get_selection();
2697 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2706 xtype: Gtk.ListStore,
2709 getValue : function(treepath, col)
2711 var tp = new Gtk.TreePath.from_string (treepath);
2713 this.el.get_iter (iret, tp);
2714 var value = this.el.get_value(iret.iter, col);
2715 return ''+ value.value.get_string();
2719 XObject.prototype.init.call(this);
2720 this.el.set_column_types ( 6, [
2721 GObject.TYPE_STRING, // real key
2722 GObject.TYPE_STRING, // real type
2723 GObject.TYPE_STRING, // docs ?
2724 GObject.TYPE_STRING, // visable desc
2725 GObject.TYPE_STRING, // function desc
2726 GObject.TYPE_STRING // element type (event|prop)
2730 showData : function(type) {
2732 if (!this.get('/MidPropTree').activeElement || !type) {
2733 return; // no active element
2736 var fullpath = this.get('/LeftTree.model').file.guessName(
2737 this.get('/MidPropTree').activeElement);
2738 var palete = this.get('/LeftTree').getPaleteProvider();
2742 Seed.print('Showing right?');
2743 if (!this.get('/MidPropTree').shown) {
2745 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2746 this.get('/MidPropTree').el.show();
2747 this.get('/MidPropTree').shown = true;
2750 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2751 return a.name > b.name ? 1 : -1;
2753 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2754 // console.dump(elementList);
2758 for(var i =0 ; i < elementList.length; i++) {
2760 var p=elementList[i];
2761 this.el.append(iret);
2762 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2763 //GObject.TYPE_STRING, // real key
2764 // GObject.TYPE_STRING, // real type
2765 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2766 // GObject.TYPE_STRING // func def?
2769 this.el.set_value(iret.iter, 0, p.name);
2770 this.el.set_value(iret.iter, 1, p.type);
2771 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2772 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2773 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2774 this.el.set_value(iret.iter, 5, type);
2781 xtype: Gtk.TreeViewColumn,
2784 this.el = new Gtk.TreeViewColumn();
2785 this.parent.el.append_column(this.el);
2787 XObject.prototype.init.call(this);
2788 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2792 xtype: Gtk.CellRendererText,
2793 pack : "pack_start,true"
2820 xtype: Gtk.Notebook,
2821 pack : "pack_start,true,true",
2822 id : "view-help-nb",
2824 XObject.prototype.init.call(this);
2825 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2826 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2830 xtype: Gtk.Notebook,
2831 id : "view-notebook",
2835 XObject.prototype.init.call(this);
2836 this.el.set_current_page(0);
2837 //print("SET LABEL?")
2838 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2839 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2845 id : "RightBrowser",
2850 pack : "pack_start,false,true,0",
2855 clicked : function (self) {
2856 this.get('/RightBrowser.view').renderJS(null,true);
2860 pack : "pack_start,false,false,0"
2863 xtype: Gtk.CheckButton,
2865 toggled : function (self, state) {
2866 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2871 label : "Auto Redraw On",
2872 pack : "pack_start,false,false,0"
2877 clicked : function (self) {
2878 this.get('/RightBrowser.view').redraws = 99;
2879 this.get('/RightBrowser.view').renderJS(null,true);
2882 label : "Full Redraw",
2883 pack : "pack_start,false,false,0"
2888 xtype: Gtk.ScrolledWindow,
2891 XObject.prototype.init.call(this);
2892 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2894 shadow_type : Gtk.ShadowType.IN,
2897 xtype: WebKit.WebView,
2899 load_finished : function (self, object) {
2900 print("load finished");
2901 // print("load_finished"); return;
2902 // if (this.ready) { // dont do it twice!
2905 if (!this.inspectorShown) {
2906 this.el.get_inspector().show();
2907 this.inspectorShown = true;
2912 if (this.pendingRedraw) {
2913 this.pendingRedraw = false;
2914 this.refreshRequired = true;
2916 //var js = this.get('/LeftTree.model').toJS();
2917 //if (js && js[0]) {
2918 // this.renderJS(js[0]);
2922 script_alert : function (self, object, p0) {
2925 return true; // do not display anything...
2927 console_message : function (self, object, p0, p1) {
2929 // console.log(object);
2932 if (object.match(/variable/) && object.match(/Builder/)) {
2933 print("got builder missing message");
2934 this.refreshRequired = true;
2935 this.lastRedraw = 0;
2941 if (!object.match(/^\{/)) {
2943 //this.get('/Terminal').feed(object);
2944 return true; // do not handle!!! -> later maybe in console..
2950 // console.log(object);
2951 var val = JSON.parse(object);
2953 if (typeof(val['hover-node']) != 'undefined') {
2954 this.activeNode = val['hover-node'];
2955 console.log('active node: ' + this.activeNode);
2960 if (typeof(val['id']) != 'undefined') {
2961 // this.activeNode = val['id'];
2962 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2963 if (!tg || typeof(tg[0]) == 'undefined') {
2966 print("SELECT node " + tg[0]);
2968 this.get('/LeftTree.view').selectNode(tg[0]);
2972 if (ret && typeof(val['set']) != 'undefined') {
2973 this.get('/LeftPanel.model').add({
2977 //console.log('active node: ' + this.activeNode);
2980 //Seed.print('a:'+a);
2981 //Seed.print('b:'+b);
2982 //Seed.print('c:'+c);
2985 drag_motion : function (w, ctx, x, y, time, ud) {
2986 // console.log('DRAG MOTION');
2988 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2989 this.targetData = [];
2990 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2992 // A) find out from drag all the places that node could be dropped.
2993 var src = Gtk.drag_get_source_widge(ctx);
2994 if (!src.dropList) {
2995 ctx.drag_status(0, time);
2998 // b) get what we are over.. (from activeNode)
2999 // tree is empty.. - list should be correct..
3000 if (!this.get('/LeftTree.model').currentTree) {
3001 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3005 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3007 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3010 Gdk.drag_status(ctx, 0,time);
3011 this.get('/LeftTree.view').highlight(false);
3015 // if we have a target..
3016 // -> highlight it! (in browser)
3017 // -> highlight it! (in tree)
3019 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3020 this.get('/LeftTree.view').highlight(tg);
3021 this.targetData = tg;
3022 // for tree we should handle this...
3025 drag_drop : function (w, ctx, x, y,time, ud) {
3026 print("TARGET: drag-drop");
3027 var is_valid_drop_site = true;
3031 ( /* will receive 'drag-data-received' signal */
3032 ctx, /* represents the current state of the DnD */
3033 this.get('/Window').atoms["STRING"], /* the target type we want */
3034 time /* time stamp */
3038 /* No target offered by source => error */
3041 return is_valid_drop_site;
3043 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3045 print("Browser: drag-data-received");
3046 var delete_selection_data = false;
3047 vardnd_success = false;
3048 /* Deal with what we are given from source */
3049 if( sel_data && sel_data.length ) {
3051 if (ctx.action == Gdk.DragAction.ASK) {
3052 /* Ask the user to move or copy, then set the ctx action. */
3055 if (ctx.action == Gdk.DragAction.MOVE) {
3056 delete_selection_data = true;
3058 var source = Gtk.drag_get_source_widget(ctx);
3060 print("Browser: source.DRAGDATA? " + source.dragData);
3061 if (this.targetData) {
3062 print(this.targetData);
3063 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3072 if (dnd_success == false)
3074 Seed.print ("DnD data transfer failed!\n");
3077 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3080 create_web_view : function (self, object) {
3081 print("CREATE WEB VIEW");
3082 return null; //new WebKit.WebView();
3089 XObject.prototype.init.call(this);
3090 // this may not work!?
3091 var settings = this.el.get_settings();
3092 settings.enable_developer_extras = true;
3094 // this was an attempt to change the url perms.. did not work..
3095 // settings.enable_file_access_from_file_uris = true;
3096 // settings.enable_offline_web_application_cache - true;
3097 // settings.enable_universal_access_from_file_uris = true;
3101 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3102 _this.get('/BottomPane.inspector').el.show();
3103 return _this.get('/BottomPane.inspector').el;
3107 // FIXME - base url of script..
3108 // we need it so some of the database features work.
3109 this.el.load_html_string( "Render not ready" ,
3110 //fixme - should be a config option!
3111 // or should we catch stuff and fix it up..
3112 'http://localhost/app.Builder/'
3116 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3118 this.el.drag_dest_set
3119 ( /* widget that will accept a drop */
3120 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3121 null, /* lists of target to support */
3122 0, /* size of list */
3123 Gdk.DragAction.COPY /* what to do with data after dropped */
3126 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3127 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3129 GLib.timeout_add_seconds(0, 1, function() {
3130 // print("run refresh?");
3137 renderJS : function(data, force) {
3139 // this is the public redraw call..
3140 // we refresh in a loop privately..
3141 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3142 if (!autodraw && !force) {
3143 print("Skipping redraw - no force, and autodraw off");
3146 this.refreshRequired = true;
3148 runRefresh : function()
3150 // this is run every 2 seconds from the init..
3154 if (!this.refreshRequired) {
3155 // print("no refresh required");
3159 if (this.lastRedraw) {
3160 // do not redraw if last redraw was less that 5 seconds ago.
3161 if (((new Date()) - this.lastRedraw) < 5000) {
3169 if (!this.get('/Window.LeftTree').getActiveFile()) {
3172 this.refreshRequired = false;
3173 // print("HTML RENDERING");
3175 this.get('/BottomPane').el.show();
3176 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3179 var js = this.get('/LeftTree.model').toJS();
3180 if (!js || !js.length) {
3187 var project = this.get('/Window.LeftTree').getActiveFile().project;
3188 //print (project.fn);
3189 // set it to non-empty.
3190 project.runhtml = project.runhtml || '';
3191 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3194 this.runhtml = this.runhtml || '';
3196 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3197 // then we need to reload the browser using
3198 // load_html_string..
3200 // then trigger a redraw once it's loaded..
3201 this.pendingRedraw = true;
3202 var runhtml = '<script type="text/javascript">' + "\n" ;
3203 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3204 runhtml += '</script>'+ "\n" ;
3206 this.runhtml = project.runhtml;
3207 // need to modify paths
3211 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3212 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3213 print("LOAD HTML " + html);
3214 this.el.load_html_string( html ,
3215 //fixme - should be a config option!
3216 'http://localhost/app.Builder/'
3219 // should trigger load_finished! - which in truns shoudl set refresh Required;
3225 this.renderedData = data;
3226 var str = JSON.stringify(data) ;
3229 console.log('not loaded yet');
3231 this.lastRedraw = new Date();
3233 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3234 print( "before render" + this.lastRedraw);
3235 print( "after render" + (new Date()));
3245 id : "RightGtkView",
3247 redraw : function() {
3248 this.highlightWidget = false;
3249 print("REDRAW CALLED");
3250 this.activePath = this.get('/LeftTree').getActivePath();
3251 if (this.renderedEl) {
3252 print("QUEUE DRAW CALLING");
3253 this.renderedEl.queue_draw();
3256 renderJS : function(data, withDebug)
3258 this.highlightWidget = false;
3260 this.withDebug = false;
3261 while (this.get('view').el.get_children().length) {
3262 var c = this.get('view').el.get_children()[0];
3263 this.get('view').el.remove(c);
3270 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3271 // in theory tree is actually window..
3274 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3280 this.get('view').el.set_size_request(
3281 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3283 if (this.renderedEl) {
3284 this.renderedEl.set_size_request(
3285 tree.default_width || 600,
3286 tree.default_height || 400
3289 this.get('view').el.show_all();
3294 showInWindow : function() {
3295 print("GET PROEJCT");
3296 var pr = this.get('/LeftProjectTree').getActiveProject();
3298 console.log(pr.paths);
3301 var src= this.buildJS(
3302 this.get('/LeftTree.model').toJS()[0],
3307 //var x = new imports.sandbox.Context();
3311 Seed.check_syntax('var e = ' + src);
3314 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3315 this.get('/Terminal').feed(console._dump(e)+"\n");
3317 var lines = src.split("\n");
3318 var start = Math.max(0, e.line - 10);
3319 var end = Math.min(lines.length, e.line + 10);
3320 for (var i =start ; i < end; i++) {
3322 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3325 this.get('/Terminal').feed(lines[i] + "\n");
3332 this.get('/BottomPane').el.set_current_page(1);
3333 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3334 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3335 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3337 var _top = x.get_global_object()._top;
3339 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3341 if (_top.el.popup) {
3342 _top.el.popup(null, null, null, null, 3, null);
3346 viewAdd : function(item, par)
3349 // does something similar to xobject..
3350 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3352 // pack is forced to 'false'
3353 if (item.pack===false || item.pack === 'false') { // no ;
3357 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3360 var type = item['|xns'] + '.' + item['xtype'];
3362 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3366 var ns = imports.gi[item['|xns']];
3367 var ctr = ns[item['xtype']]; // why are we using array here..?
3372 for(var k in item) {
3374 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3388 // value is a function..
3389 if (k[0] == '|' && typeof(kv) == 'string') {
3391 if (kv.match(new RegExp('function'))) {
3394 print("WASL " + k + '=' + kv);
3396 eval( 'kv = ' + kv);
3397 } catch(e) { continue; }
3400 // print(k + '=' + kv);
3402 if (k[0] == '|') { // should be boolean or number..
3404 //print(k + '=' + kv);
3407 if (k == 'show_tabs') { // force tab showing for notebooks.
3410 print(k + '=' + typeof(kv) + " : " + kv);
3414 var altctr = XObject.baseXObject({ xtype: ctr} );
3416 if (!item.pack && altctr) {
3418 print("SETTING PACK TO XObjectBase method");
3419 pack_m = altctr.prototype.pack;
3424 var el = new ctr(ctr_args);
3426 print("PACK" + item.pack);
3427 //console.dump(item.pack);
3434 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3435 if (typeof(item.pack) == 'string') {
3437 item.pack.split(',').forEach(function(e, i) {
3439 if (e == 'false') { args.push( false); return; }
3440 if (e == 'true') { args.push( true); return; }
3441 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3444 //print(args.join(","));
3446 pack_m = args.shift();
3448 pack_m = item.pack.shift();
3453 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3455 name: "ArgumentError",
3456 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3457 "ADDING : " + item.id + " " + el
3466 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3467 //Seed.print('args: ' + args.length);
3468 if (typeof(pack_m) == 'string') {
3469 par[pack_m].apply(par, args);
3470 } else if (pack_m) {
3471 pack_m.call(item, par, item);
3475 item.items = item.items || [];
3476 item.items.forEach(function(ch,n) {
3478 print ("type:" + type);
3480 print ("ch.pack:" + ch.pack);
3483 if (type == 'Gtk.Table' && ch.pack == 'add') {
3484 var c = n % item.n_columns;
3485 var r = Math.floor(n/item.n_columns);
3486 ch.pack = [ 'attach', c, c+1, r, r+1,
3487 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3488 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3489 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3490 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3494 _this.viewAdd(ch, el);
3499 // add the signal handlers.
3500 // is it a widget!?!!?
3506 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3507 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3508 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3509 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3510 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3520 widgetDragDropEvent : function() {
3521 print("WIDGET DRAGDROP");
3524 widgetDragMotionEvent : function() {
3525 print("WIDGET DRAGMOTION");
3528 widgetExposeEvent : function(w, evt, ud, item) {
3530 if (this.inRender) {
3534 if ( this.highlightWidget) {
3535 this.inRender = true;
3536 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3537 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3539 this.inRender = false;
3544 if (this.activePath != item.xtreepath) {
3548 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3549 // work out the coords of the window..
3551 var dr = widget.window;
3552 this.gc = (new Gdk.GC.c_new(dr));
3553 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3554 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3558 var r = evt.expose.area;
3559 // console.dump([r.x, r.y, r.width, r.height ] );
3561 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3562 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3563 // happens with gtkscrollview embedded stuff..
3564 var np =this.activePath.split(':');
3566 this.activePath = np.join(':');
3567 this.renderedEl.queue_draw();
3583 this.inRender = true;
3586 this.highlightWidget = widget;
3591 // print("DRAW BOX");
3592 //console.dump(this.box);
3593 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3594 this.inRender = false;
3597 widgetPressEvent : function(w,e,u,d) {
3598 if (this.get('view').pressed) {
3601 this.get('view').pressed = true;
3602 print("WIDGET PRESS " + d.xtreepath );
3603 this.get('/LeftTree.view').selectNode( d.xtreepath );
3606 widgetReleaseEvent : function() {
3607 this.get('view').pressed = false;
3613 pack : "pack_start,false,true,0",
3617 pack : "pack_start,false,false,0",
3618 label : "Run The Application",
3620 button_press_event : function (self, event) {
3621 // call render on left tree - with special option!?!
3623 //print("GET PROEJCT");
3624 var pr = this.get('/LeftProjectTree').getActiveProject();
3627 for (var i in pr.paths) {
3631 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3632 this.get('/Terminal').feed("RUN DIR:" + dir);
3634 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3635 , false,false,false);
3636 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3637 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3647 xtype: Gtk.ScrolledWindow,
3650 shadow_type : Gtk.ShadowType.IN,
3652 XObject.prototype.init.call(this);
3653 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3657 xtype: Gtk.EventBox,
3658 pack : "add_with_viewport",
3660 XObject.prototype.init.call(this);
3661 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3662 red: 0x9F00, green: 0xB800 , blue : 0xA800
3670 XObject.prototype.init.call(this);
3671 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3672 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3677 xtype: Gtk.EventBox,
3680 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3681 XObject.prototype.init.call(this);
3683 this.el.drag_dest_set
3684 ( /* widget that will accept a drop */
3685 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3686 null, /* lists of target to support */
3687 0, /* size of list */
3688 Gdk.DragAction.COPY /* what to do with data after dropped */
3691 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3692 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3695 getActiveNode : function(x,y)
3697 // workout what node is here..
3698 return '0'; // top..
3702 drag_motion : function (self, ctx, x, y, time) {
3704 // A) find out from drag all the places that node could be dropped.
3705 var src = Gtk.drag_get_source_widget(ctx);
3706 if (!src.dropList) {
3707 Gdk.drag_status(ctx, 0, time);
3710 // b) get what we are over.. (from activeNode)
3711 // tree is empty.. - list should be correct..
3712 if (!this.get('/LeftTree.model').currentTree) {
3713 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3717 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3718 var activeNode = this.getActiveNode(x, y);
3721 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3724 Gdk.drag_status(ctx, 0,time);
3725 this.get('/LeftTree.view').highlight(false);
3729 // if we have a target..
3730 // -> highlight it! (in browser)
3731 // -> highlight it! (in tree)
3733 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3734 this.get('/LeftTree.view').highlight(tg);
3735 this.targetData = tg;
3736 // for tree we should handle this...
3739 drag_drop : function (self,ctx, x, y, time) {
3740 Seed.print("TARGET: drag-drop");
3741 var is_valid_drop_site = true;
3745 ( /* will receive 'drag-data-received' signal */
3746 ctx, /* represents the current state of the this.gDnD */
3747 this.get('/Window').atoms["STRING"], /* the target type we want */
3748 time /* time stamp */
3752 /* No target offered by source => error */
3755 return is_valid_drop_site;
3758 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3760 Seed.print("GtkView: drag-data-received");
3761 var delete_selection_data = false;
3762 var dnd_success = false;
3763 /* Deal with what we are given from source */
3764 if( sel_data && sel_data.length ) {
3766 if (ctx.action == Gdk.DragAction.ASK) {
3767 /* Ask the user to move or copy, then set the ctx action. */
3770 if (ctx.action == Gdk.DragAction.MOVE) {
3771 delete_selection_data = true;
3773 var source = Gtk.drag_get_source_widget( ctx );
3775 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3776 if (this.targetData) {
3777 Seed.print(this.targetData);
3778 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3787 if (dnd_success == false)
3789 Seed.print ("DnD data transfer failed!\n");
3792 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3795 button_press_event : function (self, event) {
3796 this.pressed = false;
3812 xtype: Gtk.ScrolledWindow,
3817 var file = this.get('/LeftTree').getActiveFile();
3821 var activeEl = this.get('/LeftTree').getActiveElement();
3822 var xtype = file.guessName( activeEl )
3823 if (!xtype || !xtype.length) {
3826 //this.get('/Window.view-help-nb').el.set_current_page(1);
3828 // get the active element being edited.
3829 var helpurl = file.getHelpUrl(xtype);
3831 // now load the help info in the page..
3832 this.get('help-view').el.open(helpurl);
3836 xtype: WebKit.WebView,
3840 XObject.prototype.init.call(this);
3841 this.get('/Window.help-view').el.open(
3842 "http://devel.akbkhome.com/seed/");
3854 xtype: Gtk.Notebook,
3858 XObject.prototype.init.call(this);
3859 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3860 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3861 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3865 xtype: Gtk.ScrolledWindow,
3869 xtype: Vte.Terminal,
3872 feed : function(istr) {
3873 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3874 // we should make ourselves visable!!!
3875 this.get('/BottomPane').el.show();
3876 this.get('/BottomPane').el.set_current_page(1);
3878 this.el.feed(str ,str.length);
3880 scroll_on_output : true,
3882 XObject.prototype.init.call(this);
3883 this.el.set_size (80, 1000);
3885 scrollback_lines : 1000
3890 xtype: Gtk.ScrolledWindow,
3894 xtype: WebKit.WebView,
3910 this.get('buttonbar').el.show();
3911 this.get('viewbox').el.hide();
3912 var ce = this.get('/Window.centerEast').el;
3914 ce.set_position(ce.get_allocated_width() - 30);
3916 print("TRIED TO HIDE");
3919 this.get('buttonbar').el.hide();
3920 this.get('viewbox').el.show();
3921 var ce = this.get('/Window.centereast').el;
3922 print(JSON.stringify(XObject.keys(ce) ,null,4));
3923 ce.set_position(ce.get_allocated_width() - 100);
3925 // this.get('model').expanded();
3937 pack : "pack_start,false,true",
3939 clicked : function (self) {
3940 this.get('/RightPalete').show();
3947 stock : Gtk.STOCK_GOTO_FIRST,
3948 icon_size : Gtk.IconSize.MENU
3958 XObject.prototype.init.call(this);
3959 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3962 enter_notify_event : function (self, event) {
3963 this.get('/RightPalete').show();
3977 pack : "pack_start,false,true",
3986 pack : "pack_start,false,true",
3988 clicked : function (self) {
3989 this.get('/RightPalete').hide();
3996 stock : Gtk.STOCK_GOTO_LAST,
3997 icon_size : Gtk.IconSize.MENU
4004 xtype: Gtk.ScrolledWindow,
4007 XObject.prototype.init.call(this);
4008 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4009 this.el.set_size_request(-1,200);
4011 shadow_type : Gtk.ShadowType.IN,
4014 xtype: Gtk.TreeView,
4016 drag_begin : function (self, ctx) {
4017 // we could fill this in now...
4018 Seed.print('SOURCE: drag-begin');
4023 var s = this.selection;
4024 s.get_selected(iret);
4025 var path = this.get('/RightPalete.model').el.get_path(iter.iter);
4027 var pix = this.el.create_row_drag_icon ( path);
4030 Gtk.drag_set_icon_surface ( ctx, pix );
4033 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4034 if (!this.get('/RightPalete').provider) {
4037 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4038 this.el.dragData = value;
4045 drag_data_get : function (self, drag_context, selection_data, info, time) {
4046 //Seed.print('Palete: drag-data-get: ' + target_type);
4047 if (this.el.dragData && this.el.dragData.length ) {
4048 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4052 //this.el.dragData = "TEST from source widget";
4056 drag_end : function (self, drag_context) {
4057 Seed.print('SOURCE: drag-end');
4058 this.el.dragData = false;
4059 this.el.dropList = false;
4060 this.get('/LeftTree.view').highlight(false);
4063 button_press_event : function (self, event) {
4065 if (!this.get('/Editor').save()) {
4066 // popup!! - click handled..
4073 enable_tree_lines : true,
4074 headers_visible : false,
4076 XObject.prototype.init.call(this);
4077 this.el.set_size_request(150,-1);
4078 // set_reorderable: [1]
4080 var description = new Pango.FontDescription.c_new();
4081 description.set_size(8000);
4082 this.el.modify_font(description);
4084 this.selection = this.el.get_selection();
4085 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4086 // this.selection.signal['changed'].connect(function() {
4087 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4089 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4091 this.el.drag_source_set ( /* widget will be drag-able */
4092 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4093 null, /* lists of target to support */
4094 0, /* size of list */
4095 Gdk.DragAction.COPY /* what to do with data after dropped */
4097 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4099 this.el.drag_source_set_target_list( this.get('/Window').targetList);
4100 this.el.drag_source_add_text_targets( );
4102 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4103 targets = new Gtk.TargetList();
4104 targets.add( LeftTree.atoms["STRING"], 0, 0);
4105 targets.add_text_targets( 1 );
4106 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4108 //if you want to allow text to be output elsewhere..
4109 //Gtk.drag_source_add_text_targets(this.el);
4115 xtype: Gtk.ListStore,
4118 XObject.prototype.init.call(this);
4119 this.el.set_column_types ( 2, [
4120 GObject.TYPE_STRING, // title
4121 GObject.TYPE_STRING // tip
4126 load : function(tr,iter)
4131 //console.log('Project tree load: ' + tr.length);
4133 //this.insert(citer,iter,0);
4134 for(var i =0 ; i < tr.length; i++) {
4137 this.el.append(cret);
4139 this.el.insert(cret,iter,-1);
4144 this.el.set_value(cret.iter, 0, '' + r ); // title
4146 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4147 //if (r.cn && r.cn.length) {
4148 // this.load(r.cn, citer);
4154 getValue : function (iter, col) {
4155 return this.el.get_value(iter, col).value.get_string();
4162 xtype: Gtk.TreeViewColumn,
4163 pack : "append_column",
4165 XObject.prototype.init.call(this);
4166 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4170 xtype: Gtk.CellRendererText,
4192 XObject.cache['/Window'] = Window;