3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
15 delete_event : function (self, event) {
18 destroy : function (self) {
21 show : function (self) {
23 imports.ProjectManager.ProjectManager.loadConfig();
25 print("HIDEWIN - calling MidPropTree hidewin")
26 this.get('/MidPropTree').hideWin();
27 this.get('/RightPalete').hide();
28 this.get('/BottomPane').el.hide();
29 //this.get('/Editor').el.show_all();
37 title : "Application Builder",
40 "STRING" : Gdk.atom_intern("STRING")
42 this.targetList = new Gtk.TargetList();
43 this.targetList.add( this.atoms["STRING"], 0, 0);
44 //imports.ProjectManager.ProjectManager.loadConfig();
46 "style \"gtkcombobox-style\" {\n" +
47 " GtkComboBox::appears-as-list = 1\n" +
49 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
50 XObject.prototype.init.call(this);
56 setTitle : function(str) {
57 this.el.set_title(this.title + ' - ' + str);
59 type : Gtk.WindowType.TOPLEVEL,
67 pack : "pack_start,false,false",
81 label : "New _Project",
83 activate : function (self) {
85 this.get('/EditProject').show({
86 success : function(pr) {
87 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
98 activate : function (self) {
99 var fn = this.get('/LeftProjectTree.combo').getValue();
101 this.get('/LeftProjectTree').showNoProjectSelected();
104 var pm = imports.ProjectManager.ProjectManager;
105 this.get('/DialogNewComponent').show({
106 project : pm.getByFn(fn)
112 xtype: Gtk.SeparatorMenuItem,
117 use_underline : true,
119 label : "D_elete Project",
121 activate : function (self) {
123 var fn = this.get('/LeftProjectTree').get('combo').getValue();
125 this.get('/StandardErrorDialog').show("Select a project")
128 var pm = imports.ProjectManager.ProjectManager;
129 var pr = pm.getByFn(fn);
132 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
133 pm.deleteProject(fn);
141 xtype: Gtk.SeparatorMenuItem,
148 use_underline : true,
150 activate : function (self) {
162 use_underline : true,
167 pack : "set_submenu",
172 activate : function (self) {
173 var fn = this.get('/LeftTree').getActiveFile();
175 this.get('/StandardErrorDialog').show("No File active");
179 this.get('/DialogNewComponent').show(fn);
183 label : "File _Properties",
190 activate : function (self, event) {
191 this.get('/RooProjectProperties').show();
195 label : "Modify Project HTML ",
206 use_underline : true,
210 pack : "set_submenu",
215 activate : function (self, event) {
216 var js = this.get('/LeftTree.model').toJS();
218 this.get('/RightBrowser.view').renderJS(js[0], true);
223 label : "_Redraw (Roo)",
230 activate : function (self, event)
232 /* Firefox testing for debugging..
233 - we can create a /tmp directory, and put.
234 builder.html, builder.html.js, link roojs1
235 add at the end of builder.html Roo.onload(function() {
237 if (!this.get('/Window.LeftTree').getActiveFile()) {
241 var js = this.get('/LeftTree.model').toJS();
245 var project = this.get('/Window.LeftTree').getActiveFile().project;
246 //print (project.fn);
248 project.runhtml = project.runhtml || '';
251 var File = imports.File.File;
253 var target = "/tmp/firetest"; // fixme..
254 if (!File.isDirectory(target)) {
257 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
258 if (!File.exists( target+ '/roojs1')) {
259 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
264 var html = imports.File.File.read(__script_path__ + '/../builder.html');
265 html = html.replace('</head>', project.runhtml + '</head>');
268 var jsstr = JSON.stringify(js[0], null, 4);
270 var runbuilder = '<script type="text/javascript">' + "\n" +
271 " Builder.render(" + jsstr + ");\n" +
274 html = html.replace('</body>', runbuilder + '</body>');
276 File.write( target+ '/builder.html', html);
278 this.get('/Terminal').feed("RUN DIR:" + target);
280 this.get('/Terminal').el.fork_command_full(
281 Vte.PtyFlags.DEFAULT,
287 null, // child setupdata
290 var cmd = "firefox file://" + target + "/builder.html \n";
291 this.get('/Terminal').el.feed_child(cmd, cmd.length);
295 label : "_Test in Firefox (Roo)",
306 use_underline : true,
311 pack : "set_submenu",
317 use_underline : true,
319 activate : function (self) {
320 this.get('/About').el.run();
350 activate : function (self) {
351 // this does not actually expand it..
352 // that is done by GTK..
355 if (!this.get('/Editor').save()) {
356 // popup!! - click handled..
360 if (!this.el.expanded) {
368 enter_notify_event : function (self, event) {
370 this.el.expanded = !this.el.expanded;
371 //if (this.el.expanded ) {
372 this.listeners.activate.call(this);
379 label : "Select Project or File",
380 pack : "pack_start,false,true",
382 XObject.prototype.init.call(this);
383 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
385 onCollapse : function() {
387 var nb = this.get('/LeftTopPanel.notebook');
388 nb.el.set_current_page(0);
390 onExpand : function() {
391 var nb = this.get('/LeftTopPanel.notebook');
392 var pm = imports.ProjectManager.ProjectManager;
395 var model = this.get('/LeftProjectTree.combomodel');
396 // print ("loading Projects?")
397 //console.dump(pm.projects);
398 model.loadData(pm.projects);
401 nb.el.set_current_page(1);
402 //pm.on('changed', function() {
403 //console.log("CAUGHT project manager change");
404 // _combo.model.loadData(pm.projects);
412 pack : "pack_start,true,true",
414 XObject.prototype.init.call(this);
415 this.el.set_current_page(0);
422 xtype: Gtk.ScrolledWindow,
425 getActiveElement : function() { // return path to actie node.
427 var path = this.getActivePath();
432 this.get('model').el.get_iter_from_string(ret, path);
434 var value = ''+ this.get('model').el.get_value(ret.iter, 2).value.get_string();
436 return JSON.parse(value);
438 getActiveFile : function() {
439 return this.get('model').file;
441 getActivePath : function() {
442 var model = this.get('model');
443 var view = this.get('view');
444 if (view.selection.count_selected_rows() < 1) {
448 view.selection.get_selected(ret);
449 return ret.model.get_path(ret.iter).to_string();
451 getPaleteProvider : function() {
452 var model = this.get('model');
453 var pm = imports.ProjectManager.ProjectManager;
454 return pm.getPalete(model.file.getType());
456 getRenderer : function() {
458 switch( this.getActiveFile().getType()) {
460 return this.get('/RightBrowser.view');
462 return this.get('/RightGtkView');
467 XObject.prototype.init.call(this);
468 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
470 renderView : function() {
471 var render = this.getRenderer();
472 var model = this.get('model');
474 render.renderJS(model.toJS(false,true)[0]);
476 print("NO RENDER JS METHOD?");
479 shadow_type : Gtk.ShadowType.IN,
484 button_press_event : function (self, ev) {
485 console.log("button press?");
487 if (!this.get('/Editor').save()) {
488 // popup!! - click handled..
492 if (ev.button.button != 3) {
493 print("click" + ev.button.button);
499 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
501 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
503 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
504 this.get('/LeftTreeMenu').el.show_all();
505 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
506 print("click:" + res.path.to_string());
509 drag_begin : function (self, ctx) {
510 print('SOURCE: drag-begin');
511 this.targetData = false;
512 // find what is selected in our tree...
514 this.selection.get_selected(ret);
516 // set some properties of the tree for use by the dropped element.
517 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
518 var data = JSON.parse(value);
519 var xname = this.get('/LeftTree.model').file.guessName(data);
521 this.el.dragData = xname;
522 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
525 // make the drag icon a picture of the node that was selected
526 var path = ret.model.get_path(ret.iter);
527 this.el.treepath = path.to_string();
529 // returns a cairo surface
530 var pix = this.el.create_row_drag_icon ( path);
532 if (Gtk.drag_set_icon_surface) {
533 Gtk.drag_set_icon_surface( ctx, pix );
535 Gtk.drag_set_icon_pixmap (ctx,
536 pix.get_colormap(), pix, null, -10, -10);
541 drag_end : function (self, drag_context) {
542 Seed.print('LEFT-TREE: drag-end');
543 this.el.dragData = false;
544 this.el.dropList = false;
545 this.targetData = false;
546 this.get('/LeftTree.view').highlight(false);
549 drag_data_get : function(self, ctx, sel_data, info, time)
559 drag_motion : function (self, ctx, x, y, time) {
560 console.log("LEFT-TREE: drag-motion");
561 var src = Gtk.drag_get_source_widget( ctx);
563 // a drag from elsewhere...- prevent drop..
565 print("no drag data!");
566 Gdk.drag_status(ctx, 0, time);
567 this.targetData = false;
570 var action = Gdk.DragAction.COPY;
571 if (src == this.el) {
572 // unless we are copying!!! ctl button..
573 action = ctx.get_actions() & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
577 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
578 // no children.. -- asume it's ok..
579 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
580 Gdk.drag_status(ctx, action ,time);
584 print("GETTING POS");
585 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
586 print("ISOVER? " + isOver);
588 Gdk.drag_status(ctx, 0 ,time);
589 return false; // not over apoint!?!
591 // drag node is parent of child..
592 console.log("SRC TREEPATH: " + src.treepath);
593 console.log("TARGET TREEPATH: " + data.path.to_string());
595 // nned to check a few here..
596 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
597 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
598 //Gtk.TreeViewDropPosition.AFTER
599 //Gtk.TreeViewDropPosition.BEFORE
601 if (typeof(src.treepath) != 'undefined' &&
602 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
603 print("subpath drag");
604 Gdk.drag_status( ctx, 0 ,time);
609 //print("DUMPING DATA");
610 //console.dump(data);
613 print(data.path.to_string() +' => '+ data.pos);
614 var tg = this.get('/LeftTree.model').findDropNodeByPath(
615 data.path.to_string(), src.dropList, data.pos);
617 this.get('/LeftTree.view').highlight(tg);
619 print("Can not find drop node path");
620 this.targetData = false;
621 Gdk.drag_status(ctx, 0, time);
624 print(JSON.stringify(tg,null,4));
626 this.targetData = tg;
629 Gdk.drag_status(ctx, action ,time);
633 drag_drop : function (w, ctx, x, y, time) {
634 Seed.print("TARGET: drag-drop");
635 //print(JSON.stringify(w.drag_dest_get_target_list(),null,4));
637 ( /* will receive 'drag-data-received' signal */
638 ctx, /* represents the current state of the DnD */
639 this.get('/Window').atoms["STRING"], /* the target type we want */
640 time /* time stamp */
644 /* No target offered by source => error */
649 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
650 print("Tree: drag-data-received");
652 var delete_selection_data = false;
653 var dnd_success = false;
654 //print(JSON.stringify(sel_data, null,4));
655 /* Deal with what we are given from source */
657 // simce I can not be bothered to sort out
658 // drag drop = let's assume it worked...
660 if( true || (sel_data && sel_data.length )) {
662 if (ctx.action == Gdk.DragAction.ASK) {
663 /* Ask the user to move or copy, then set the ctx action. */
666 if (ctx.action == Gdk.DragAction.MOVE) {
667 //delete_selection_data = true;
670 var source = Gtk.drag_get_source_widget( ctx );
672 if (this.targetData) {
673 if (source != this.el) {
674 print("DRAG FROM ANOTHER WIDGET");
675 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
677 // drag around.. - reorder..
678 print("DRAG FROM SELF");
679 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
683 //Seed.print(this.targetData);
689 // we can send stuff to souce here...
695 if (dnd_success == false)
697 Seed.print ("DnD data transfer failed!\n");
700 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
703 cursor_changed : function (self) {
704 if (this.blockChanges) { // probably not needed..
707 var render = this.get('/LeftTree').getRenderer();
710 if (this.selection.count_selected_rows() < 1) {
711 this.get('/LeftPanel.model').load( false);
712 this.get('/MidPropTree').activeElement = false;
713 this.get('/MidPropTree').hideWin();
715 var pm = this.get('/RightPalete.model');
716 if (!this.get('/LeftTree').getPaleteProvider()) {
717 // it may not be loaded yet..
721 this.get('/LeftTree').getPaleteProvider().gatherList(
722 this.get('/LeftTree.model').listAllTypes()
725 if (render && render.redraw) {
731 //console.log('changed');
732 var s = this.selection;
737 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
738 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
740 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
743 var data = JSON.parse(value);
744 this.get('/MidPropTree').activeElement = data;
745 this.get('/MidPropTree').hideWin();
746 this.get('/LeftPanel.model').load( data);
749 // _g.button.set_label(''+value.get_string());
751 var pm =this.get('/RightPalete.model');
752 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
753 this.get('/LeftTree.model').listAllTypes()));
756 if (render && render.redraw) {
760 //Seed.print( value.get_string());
768 enable_tree_lines : true,
769 headers_visible : false,
770 highlight : function(treepath_ar) {
772 // highlighting for drag/drop
773 if (treepath_ar.length && treepath_ar[0].length ) {
774 this.el.set_drag_dest_row(
775 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
777 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
783 XObject.prototype.init.call(this);
784 var description = new Pango.FontDescription.c_new();
785 description.set_size(8000);
786 this.el.modify_font(description);
788 this.selection = this.el.get_selection();
789 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
792 // is this really needed??
793 this.selection.signal['changed'].connect(function() {
794 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
795 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
799 this.el.drag_source_set( /* widget will be drag-able */
800 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
801 null, /* lists of target to support */
802 0, /* size of list */
803 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
806 this.el.drag_source_set_target_list(this.get('/Window').targetList);
808 this.el.drag_source_add_text_targets();
809 this.el.drag_dest_set
811 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
812 null, /* lists of target to support */
813 0, /* size of list */
814 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
817 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
818 this.el.drag_dest_add_text_targets( );
820 selectNode : function(treepath_str) {
821 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
822 var tp = new Gtk.TreePath.from_string(treepath_str);
823 this.el.set_cursor(tp, null, false);
824 this.el.scroll_to_cell(tp, null, false, 0,0);
828 xtype: Gtk.TreeStore,
834 setFromNode : function(tp, n)
837 tp = this.get('/LeftTree').getActivePath();
840 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
841 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
842 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
843 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
847 changed : function( refresh) {
851 print("-------MODEL CHANGED CALLED" );
853 //this.currentTree = this.toJS(false, true)[0];
855 this.file.items = this.toJS(false, false);
856 print ("TO JS in " + ((new Date()) - d) + "ms");
857 // print("AFTER CHANGED");
858 //console.dump(this.file.items);
860 this.currentTree = this.file.items[0];
861 //console.log(this.file.toSource());
864 print("REDNER BROWSER?!");
865 this.get('/LeftTree').renderView();
867 var pm = this.get('/RightPalete.model');
868 if (!this.get('/RightPalete').provider) {
874 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
875 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
879 deleteSelected : function() {
880 this.get('/LeftTree.view').blockChanges = true;
882 var s = this.get('/LeftTree.view').selection;
883 s.get_selected(oret);
884 var path = this.el.get_path(oret.iter).to_string();
886 this.activePath= false;
889 this.activePath= false;
891 this.el.get_iter_from_string(ret, path);
892 this.el.remove(ret.iter);
894 // rebuild treemap. -- depreciated.!!
897 //this.toJS(null, true) // does not do anything?
898 this.activePath= false;
900 this.get('/LeftTree.view').blockChanges = false;
902 dropNode : function(target_data, node) {
904 // console.dump(node);
905 //print(JSON.Stringify(target_data, null, 4));
906 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
908 print("add " + tp + "@" + target_data[1] );
911 if (tp && target_data[1] < 2) { // before or after..
912 var ar = target_data[0].split(':');
914 parent = new Gtk.TreePath.from_string( ar.join(':') );
919 var aret = after ? {} : false;
923 if (parent !== false) {
924 this.el.get_iter(pret, parent);
931 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
932 this.el.get_iter(aret, after);
933 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
934 nret, pret.iter, aret.iter);
937 this.el.append(nret, pret.iter);
940 var new_path = this.el.get_path(nret.iter).to_string();
941 print("new path = " + new_path)
942 if (typeof(node) == 'string') {
943 var ar = node.split('.');
944 var xtype = ar.pop();
947 '|xns' : ar.join('.'),
950 if (target_data.length == 3 && target_data[2].length) {
951 node['*prop'] = target_data[2];
953 node = this.get('/DialogTemplateSelect').show(node);
956 // work out what kind of packing to use..
957 if (typeof(node.pack) == 'undefined' && parent !== false) {
958 var pal = this.get('/LeftTree').getPaleteProvider();
959 if (pal.name == 'Gtk') {
960 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
961 var cname = pal.guessName(node);
962 node.pack = pal.getDefaultPack(pname, cname);
973 // load children - if it has any..
976 this.load(xitems, nret.iter);
977 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
979 if (tp && (xitems || after)) {
980 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
982 // wee need to get the empty proptypes from somewhere..
984 //var olditer = this.activeIter;
985 //this.activePath = new_path;
986 print("calling changed with node data")
987 // changed actually set's the node data..
988 this.setFromNode(new_path,node);
993 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
995 //Builder.MidPropTree._model.load(node);
996 //Builder.MidPropTree._win.hideWin();
997 //Builder.LeftPanel._model.load( node);
1001 findDropNode : function(treepath_str, targets) {
1003 // this is used by the dragdrop code in the roo version AFAIR..
1005 var path = treepath_str.replace(/^builder-/, '');
1006 // treemap is depreciated... - should really check if model has any entries..
1008 if (!this.el.iter_n_children(null)) {
1010 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
1012 print("FIND treepath: " + path);
1013 //console.dump(this.treemap);
1015 if (!treepath_str.match(/^builder-/)) {
1016 return []; // nothing!
1018 if (targets === true) {
1021 return this.findDropNodeByPath(path,targets)
1023 findDropNodeByPath : function(treepath_str, targets, pref) {
1024 var path = treepath_str + ''; // dupe it..
1025 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1027 //console.dump(this.treemap);
1028 while (path.length) {
1029 print("LOOKING FOR PATH: " + path);
1030 var node_data = this.singleNodeToJS(path);
1031 if (node_data === false) {
1032 print("node not found");
1036 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1039 targets.forEach(function(tg) {
1043 if ((tg == xname) ) {
1046 if (tg.indexOf(xname +':') === 0) {
1048 prop = tg.split(':').pop();
1053 if (last) { // pref is after/before..
1054 // then it's after last
1056 return []; // do not allow..
1058 return [ last, pref , prop];
1061 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1063 var par = path.split(':');
1066 path = par.join(':');
1072 getIterValue : function (iter, col) {
1074 var gval = ''+this.el.get_value(iter, col).value.get_string();
1080 XObject.prototype.init.call(this);
1081 this.el.set_column_types ( 3, [
1082 GObject.TYPE_STRING, // title
1083 GObject.TYPE_STRING, // tip
1084 GObject.TYPE_STRING // source..
1087 listAllTypes : function() {
1088 var s = this.get('/LeftTree.view').selection;
1089 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1091 if (s.count_selected_rows() > 0) {
1093 s.get_selected(ret);
1095 // set some properties of the tree for use by the dropped element.
1096 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1097 var data = JSON.parse(value);
1100 var xname = this.get('/LeftTree.model').file.guessName(data);
1101 console.log('selected:' + xname);
1105 return []; // could not find it..
1114 for (var i =0 ; i < li.length; i++ ) {
1117 // this is specific to roo!!!?
1118 if (!el) { // skip empty?
1121 var fullpath = _this.file.guessName(el);
1122 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1127 if (el.items && el.items.length) {
1136 addall([this.currentTree]);
1138 // only if we have nothing, should we add '*top'
1142 //console.log('all types in tree');
1143 //console.dump(ret);
1148 load : function(tr,iter)
1150 //this.insert(citer,iter,0);
1152 for(var i =0 ; i < tr.length; i++) {
1155 this.el.insert(ret ,iter,-1);
1157 this.el.append(ret);
1159 //print(JSON.stringify(ret,null,4));
1160 //print('call nodeToJSON: ' + tr[i]);
1161 var body = this.nodeToJSON(tr[i]);
1163 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1164 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1165 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1166 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1167 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1168 this.el.set_value(ret.iter, 2, '' + body );
1169 if (tr[i].items && tr[i].items.length) {
1170 this.load(tr[i].items, ret.iter);
1174 loadFile : function(f) {
1181 console.log('missing file');
1185 // load the file if not loaded..
1186 if (f.items === false) {
1188 f.loadItems(function() {
1194 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1196 if (f.items.length && typeof(f.items[0]) == 'string') {
1198 //this.get('/RightEditor').el.show();
1199 //this.get('/RightEditor.view').load( f.items[0]);
1203 //print(JSON.stringify(f.items, null,4));
1204 //console.dump(f.items);
1206 this.get('/LeftTree.view').el.expand_all();
1208 if (!f.items.length) {
1211 this.get('/Window.leftvpaned').el.set_position(80);
1213 this.get('/LeftTree.view').el.set_cursor(
1214 new Gtk.TreePath.from_string('0'), null, false);
1218 this.get('/Window.leftvpaned').el.set_position(200);
1221 //return; -- debuggin
1222 //print("hide right editior");
1223 //this.get('/RightEditor').el.hide();
1224 this.get('/Editor').el.hide();
1225 print("set current tree");
1227 this.currentTree = this.toJS(false, false)[0];
1230 //console.dump(this.currentTree);
1231 this.currentTree = this.currentTree || { items: [] };
1232 this.get('/LeftTree').renderView();
1233 // console.dump(this.map);
1234 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1235 var pm = this.get('/RightPalete.model');
1236 // set up provider..
1238 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1240 if (!this.get('/RightPalete').provider) {
1241 print ("********* PALETE PROVIDER MISSING?!!");
1243 this.get('/LeftTree').renderView();
1245 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1249 this.get('/Window.view-notebook').el.set_current_page(
1250 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1253 moveNode : function(target_data, action) {
1254 //print("MOVE NODE");
1255 // console.dump(target_data);
1257 var s = this.get('/LeftTree.view').selection;
1258 s.get_selected( oret);
1259 var node = this.nodeToJS(oret.iter,false);
1260 //console.dump(node);
1261 print(JSON.stringify(node, null,4));
1263 // needs to drop first, otherwise the target_data
1264 // treepath will be invalid.
1266 this.dropNode(target_data, node);
1267 if (action & Gdk.DragAction.MOVE) {
1268 // print("REMOVING OLD NODE");
1269 this.el.remove(oret.iter);
1273 this.activePath= false;
1276 nodeTip : function(c) {
1277 var ret = this.nodeTitle(c,true);
1283 if (!i.length || i[0] != '|') {
1289 if (typeof(c[i]) != 'string') {
1292 //print("prop : " + i + ':' + c[i]);
1293 if (!c[i].match(new RegExp('function'))) {
1296 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1300 ret+="\n\nMethods:" + funcs;
1305 nodeTitle : function(c, renderfull) {
1308 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1309 if (sr) txt.push('<s>');
1310 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1312 if (renderfull && c['|xns']) {
1313 txt.push(c['|xns']);
1316 if (c.xtype) { txt.push(c.xtype); }
1317 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1318 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1319 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1322 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1323 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1324 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1325 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1326 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1327 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1328 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1329 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1330 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1332 // for flat classes...
1333 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1334 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1337 if (sr) txt.push('</s>');
1338 return (txt.length == 0 ? "Element" : txt.join(" "));
1340 nodeToJS : function (treepath, with_id)
1342 //print("nodeToJS : WITHID: "+ with_id);
1343 var iter = treepath; // API used to be iter here..
1344 if (typeof(iter) == 'string') {
1346 if (!this.el.get_iter(ret,
1347 new Gtk.TreePath.from_string(treepath))) {
1353 var iv = this.getIterValue(iter, 2);
1354 // print("IV" + iv);
1355 var k = JSON.parse(iv);
1356 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1361 var treepath_str = this.el.get_path(iter).to_string();
1362 // not sure how we can handle mixed id stuff..
1363 if (typeof(k.id) == 'undefined') {
1364 k.id = 'builder-'+ treepath_str ;
1368 this.treemap[ treepath_str ] = k;
1369 k.xtreepath = treepath_str ;
1372 if (this.el.iter_has_child(iter)) {
1374 this.el.iter_children(cret, iter);
1375 k.items = this.toJS(cret.iter,with_id);
1379 nodeToJSON : function(c) {
1387 return JSON.stringify(o);
1389 singleNodeToJS : function (treepath)
1392 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1396 var iv = this.getIterValue(ret.iter, 2);
1398 return JSON.parse(iv);
1401 toJS : function(treepath, with_id)
1403 //print("toJS : WITHID: "+ with_id);
1405 var iter = treepath; // API used to be iter here..
1407 if (typeof(iter) == 'string') {
1409 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1421 if (!this.el.get_iter_first(ret)) {
1432 var k = this.nodeToJS(iter, with_id);
1436 if (!this.el.iter_next(iter)) {
1441 if (treepath === false) {
1443 return JSON.parse(JSON.stringify(ar));
1447 // convert the list into a json string..
1453 xtype: Gtk.TreeViewColumn,
1454 pack : "append_column",
1456 XObject.prototype.init.call(this);
1457 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1461 xtype: Gtk.CellRendererText,
1471 id : "LeftTreeMenu",
1474 xtype: Gtk.MenuItem,
1476 label : "Delete Element",
1478 activate : function (self) {
1480 this.get('/LeftTree.model').deleteSelected();
1485 xtype: Gtk.MenuItem,
1487 activate : function (self) {
1489 var tree = this.get('/LeftTree');
1490 var model = this.get('/LeftTree.model');
1491 var el = tree.getActivePath();
1493 var js = model.toJS(el, false);
1494 // print(JSON.stringify(js[0], null,4));
1495 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1500 label : "Save as Template",
1510 id : "LeftProjectTree",
1511 showNoProjectSelected : function() {
1512 this.get('/StandardErrorDialog').show("Select a Project first.");
1514 getActiveProject : function() {
1515 return this.project;
1518 leave_notify_event : function (self, event) {
1525 pack : "pack_start,false,false",
1528 xtype: Gtk.ComboBox,
1530 changed : function (self) {
1531 var fn = this.getValue();
1532 var pm = imports.ProjectManager.ProjectManager;
1533 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1537 getValue : function() {
1538 var ix = this.el.get_active();
1542 var data = imports.ProjectManager.ProjectManager.projects;
1543 if (typeof(data[ix]) == 'undefined') {
1549 XObject.prototype.init.call(this);
1550 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1552 setValue : function(fn)
1556 var data = imports.ProjectManager.ProjectManager.projects;
1557 data.forEach(function(n, ix) {
1566 xtype: Gtk.CellRendererText,
1567 pack : "pack_start,true",
1571 xtype: Gtk.ListStore,
1575 XObject.prototype.init.call(this);
1576 this.el.set_column_types ( 2, [
1577 GObject.TYPE_STRING, // real key
1578 GObject.TYPE_STRING // real type
1582 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1583 var pm = imports.ProjectManager.ProjectManager;
1585 pm.on('changed', function() {
1586 print("caught changed hook on project manager - reloading data");
1587 _this.loadData(pm.projects);
1591 loadData : function(data) {
1592 var ov = this.get('/LeftProjectTree.combo').getValue();
1596 data.forEach(function(p) {
1599 //print(JSON.stringify(XObject.keys(na)));
1600 //print(typeof(na.iter));
1601 //print(JSON.stringify(iter))
1602 el.set_value(na.iter, 0, p.fn);
1603 el.set_value(na.iter, 1, p.name);
1607 this.get('/LeftProjectTree.combo').setValue(ov);
1615 xtype: Gtk.ScrolledWindow,
1617 shadow_type : Gtk.ShadowType.IN,
1619 XObject.prototype.init.call(this);
1620 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1624 xtype: Gtk.TreeView,
1627 cursor_changed : function (self) {
1629 var model = this.get('/LeftProjectTree.model');
1633 if (model.loading) {
1635 model.loading = model.loading == 2 ? 0 : 1;
1638 print("LOADING IS FALSE");
1640 if (this.selection.count_selected_rows() < 1) {
1641 //XN.get('Builder.LeftTree.model').
1642 this.get('/LeftTree.model').load( false);
1646 //console.log('changed');
1647 var s = this.selection;
1648 s.get_selected(ret);
1649 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1650 //console.log(JSON.stringify(value,null,4));// id..
1651 console.log("OUT?" + value);// id..
1652 var file = this.get('/LeftProjectTree').project.getById(value);
1659 var nb = this.get('/LeftTopPanel.expander');
1660 nb.el.expanded = false;
1662 //nb.listeners.activate.call(nb);
1663 //_expander.el.set_expanded(false);
1665 var ltm = this.get('/LeftTree.model');
1673 enable_tree_lines : true,
1674 headers_visible : false,
1676 XObject.prototype.init.call(this);
1677 var description = new Pango.FontDescription.c_new();
1678 description.set_size(8000);
1679 this.el.modify_font(description);
1681 this.selection = this.el.get_selection();
1682 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1686 xtype: Gtk.TreeStore,
1691 XObject.prototype.init.call(this);
1692 this.el.set_column_types ( 3, [
1693 GObject.TYPE_STRING, // title
1694 GObject.TYPE_STRING, // tip
1695 GObject.TYPE_STRING // id..
1699 loadProject : function(pr) {
1700 print("LOAD PROJECT");
1701 var model = this.get('/LeftProjectTree.model');
1702 model.loading = true;
1709 this.get('/LeftProjectTree').project = pr;
1711 this.load(pr.toTree());
1713 this.get('/LeftProjectTree.view').el.expand_all();
1714 model.loading = false;
1717 load : function(tr,iter) {
1718 // console.dump(tr);
1721 console.log('Project tree load: ' + tr.length);
1723 //this.insert(citer,iter,0);
1727 tr.forEach(function (r) {
1729 _this.el.append(cret);
1731 _this.el.insert(cret,iter,-1);
1733 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1734 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1735 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1736 if (r.cn && r.cn.length) {
1737 _this.load(r.cn, cret.iter);
1743 getValue : function(iter, col) {
1744 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1749 xtype: Gtk.TreeViewColumn,
1750 pack : "append_column",
1752 XObject.prototype.init.call(this);
1753 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1757 xtype: Gtk.CellRendererText,
1777 pack : "pack_start,false,true,0",
1784 button_press_event : function (self, event) {
1785 this.get('/MidPropTree.model').showData('props');
1797 stock : Gtk.STOCK_ADD,
1798 icon_size : Gtk.IconSize.MENU
1812 button_press_event : function (self, event) {
1814 if (!this.get('/Editor').save()) {
1815 // popup!! - click handled..
1818 this.get('/MidPropTree.model').showData('events');
1831 stock : Gtk.STOCK_ADD,
1832 icon_size : Gtk.IconSize.MENU
1846 button_press_event : function (self, ev) {
1848 if (!this.get('/Editor').save()) {
1849 // popup!! - click handled..
1853 var p = this.get('/AddPropertyPopup');
1857 p.el.set_screen(Gdk.Screen.get_default());
1859 p.el.popup(null, null, null, null, 3, ev.button.time);
1872 stock : Gtk.STOCK_ADD,
1873 icon_size : Gtk.IconSize.MENU
1885 id : "AddPropertyPopup",
1888 xtype: Gtk.MenuItem,
1890 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1893 activate : function (self) {
1895 this.get('/LeftPanel.model').add( {
1906 xtype: Gtk.MenuItem,
1908 tooltip_markup : "Add what type of packing is to be used",
1911 activate : function (self) {
1913 this.get('/LeftPanel.model').add( {
1923 xtype: Gtk.MenuItem,
1925 tooltip_markup : "Override the init method",
1928 activate : function (self) {
1930 this.get('/LeftPanel.model').add( {
1933 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1940 xtype: Gtk.SeparatorMenuItem,
1944 xtype: Gtk.MenuItem,
1946 tooltip_markup : "Add a user defined string property",
1949 activate : function (self) {
1951 this.get('/LeftPanel.model').add( {
1961 xtype: Gtk.MenuItem,
1963 tooltip_markup : "Add a user defined number property",
1966 activate : function (self) {
1968 this.get('/LeftPanel.model').add( {
1978 xtype: Gtk.MenuItem,
1980 tooltip_markup : "Add a user defined boolean property",
1983 activate : function (self) {
1985 this.get('/LeftPanel.model').add( {
1995 xtype: Gtk.SeparatorMenuItem,
1999 xtype: Gtk.MenuItem,
2001 tooltip_markup : "Add a user function boolean property",
2004 activate : function (self) {
2006 this.get('/LeftPanel.model').add( {
2009 val : "function() {\n \n}\n",
2022 xtype: Gtk.ScrolledWindow,
2027 XObject.prototype.init.call(this);
2028 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2030 shadow_type : Gtk.ShadowType.IN,
2033 xtype: Gtk.TreeView,
2035 button_press_event : function (self, ev) {
2038 if (!this.get('/Editor').save()) {
2039 // popup!! - click handled..
2044 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2045 return false; //not on a element.
2049 if (ev.button.button == 3) {
2051 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2054 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2055 var p = this.get('/LeftPanelPopup');
2060 p.el.set_screen(Gdk.Screen.get_default());
2062 p.el.popup(null, null, null, null, 3, ev.button.time);
2063 //Seed.print("click:" + res.column.title);
2070 if (res.column.title != 'value') {
2071 // XObject.error("column is not value?");
2072 return false; // ignore.. - key click.. ??? should we do this??
2075 // currently editing???
2076 // if ( this.activePath) {
2078 // this.activePath = false;
2080 if (this.get('/Editor').dirty) {
2081 //if (!this.get('/Editor.buffer').checkSyntax()) {
2082 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2086 if (!this.get('/Editor.view').save()) {
2090 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2091 this.get('/LeftPanel').editing = false;
2093 // XObject.error("Currently editing?");
2097 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2099 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2101 // get options for this type -- this is to support option lists etc..
2102 var provider = this.get('/LeftTree').getPaleteProvider();
2103 var opts = provider.findOptions(type);
2105 if (opts === false) {
2107 this.get('/LeftPanel').editableColumn.setOptions([]);
2108 renderer.has_entry = true;
2110 this.get('/LeftPanel').editableColumn.setOptions(opts);
2111 renderer.has_entry = false;
2113 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2115 //Seed.print("click" + ev.type);
2116 //console.dump(res);
2125 enable_tree_lines : true,
2126 headers_visible : false,
2128 XObject.prototype.init.call(this);
2130 this.selection = this.el.get_selection();
2131 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2134 var description = new Pango.FontDescription.c_new();
2135 description.set_size(8000);
2136 this.el.modify_font(description);
2140 xtype: Gtk.TreeStore,
2144 add : function(info) {
2145 // info includes key, val, skel, etype..
2147 type = info.type.toLowerCase();
2148 var data = this.toJS();
2150 if (info.etype == 'events') {
2151 data.listeners = data.listeners || { };
2152 if (typeof(data.listeners[info.key]) != 'undefined') {
2153 return; //already set!
2156 if (typeof(data[info.key]) != 'undefined') {
2161 if (typeof(info.val) == 'undefined') {
2164 if (info.type.toLowerCase() == 'boolean') {
2167 if (type == 'number') {
2175 if (info.etype == 'events') {
2177 data.listeners[info.key] = info.val;
2180 data[info.key] = info.val;
2184 var map = this.load(data);
2186 // flag it as changed to the interface..
2187 this.get('/LeftTree.model').setFromNode(false,node);
2188 this.get('/LeftTree.model').changed(true);
2191 this.startEditing(map[k]);
2194 LeftPanel.get('view').el.row_activated(
2195 new Gtk.TreePath.from_string(map[k]),
2196 LeftPanel.editableColumn.el
2200 changed : function(str, doRefresh) {
2201 if (!this.activePath) {
2202 print("NO active path when changed")
2206 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2208 this.el.set_value(ret.iter, 1, '' +str);
2209 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2210 var type = this.getIterValue(ret.iter, 4);
2212 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2213 // update the tree...
2214 print("new data: " + JSON.stringify(this.toJS() , null,4));
2215 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2216 this.get('/LeftTree.model').changed(doRefresh);
2219 deleteSelected : function() {
2220 var data = this.toJS();
2222 var s = this.get('/LeftPanel.view').selection;
2223 s.get_selected( ret);
2226 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2228 if (val[0] == '!') {
2230 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2233 delete data.listeners[ val.substring(1)];
2234 if (!XObject.keys(data.listeners).length) {
2235 delete data.listeners;
2239 if (typeof(data[val]) == 'undefined') {
2249 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2250 this.get('/LeftTree.model').changed(true);
2254 getIterValue : function(iter, col) {
2255 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2258 getType : function(treepath) {
2259 return this.getValue(treepath, 4);
2261 getValue : function(treepath_str, col)
2263 // get's the value in a row.. - keys - returns string, values - formats it..
2265 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2267 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2272 var type = this.getType(this.el.get_path(ret.iter).to_string());
2273 //print("TYPE: " +type + " - val:" + val);
2274 switch(type.toLowerCase()) {
2278 return parseFloat(val); // Nan ?? invalid!!?
2281 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2283 return val == 'true' ? true : false;
2285 var nv = parseFloat(val);
2286 if (!isNaN(nv) && (val == ''+nv)) {
2294 XObject.prototype.init.call(this);
2295 this.el.set_column_types ( 6, [
2296 GObject.TYPE_STRING, // 0 real key
2297 GObject.TYPE_STRING, // 1 real value
2298 GObject.TYPE_STRING, // 2 visable key
2299 GObject.TYPE_STRING, // 3 visable value
2300 GObject.TYPE_STRING, // 4 need to store type of!!!
2301 GObject.TYPE_STRING // 5 tooltip
2305 load : function(ar) {
2306 // might casue problesm..
2307 // this.get('/Editor.RightEditor').save();
2309 this.get('/Editor').el.hide();
2310 this.get('/Editor').activePath = false;
2315 //this.get('/RightEditor').el.hide();
2322 var provider = this.get('/LeftTree').getPaleteProvider();
2326 var keys = XObject.keys(ar);
2328 ar.listeners = ar.listeners || {};
2330 for (var i in ar.listeners ) {
2332 this.el.append(iret);
2333 var p = this.el.get_path(iret.iter).to_string();
2336 this.el.set_value(iret.iter, 0, '!'+ i );
2337 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2338 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2340 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2341 this.el.set_value(iret.iter, 4, 'function');
2342 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2348 keys.forEach(function(i) {
2349 if (typeof(ar[i]) == 'object') {
2353 var type = provider.findType(ar, i, ar[i]);
2355 _this.el.append(iret);
2356 var p = _this.el.get_path(iret.iter).to_string();
2358 _this.el.set_value(iret.iter, 0, ''+i);
2359 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2360 _this.el.set_value(iret.iter, 2, ''+i);
2361 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2362 _this.el.set_value(iret.iter, 4, ''+type);
2363 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2367 startEditing : function(path,col) {
2369 // alled by menu 'edit' currently..
2371 * start editing path (or selected if not set..)
2372 * @param {String|false} path (optional) treepath to edit - selected tree gets
2373 * edited by default.
2374 * @param {Number} 0 or 1 (optional)- column to edit.
2376 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2378 if (typeof(path) == 'string') {
2379 tp = new Gtk.TreePath.from_string(path);
2382 var s = this.get('/LeftPanel.view').selection;
2383 s.get_selected( itr);
2384 tp = this.el.get_path(itr.iter);
2385 path = tp.to_string();
2389 // which colum is to be edited..
2392 // not sure what this does..
2394 if (typeof(col) == 'undefined') {
2395 var k = this.getValue(path, 0);
2397 colObj = (!k.length || k == '|') ?
2398 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2400 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2403 // make sure the pulldown is set correctly..
2404 // not really needed for second col...
2405 var showEditor = false;
2406 this.get('/Editor').activePath = false;
2407 this.get('/Editor').el.hide();
2410 var provider = this.get('/LeftTree').getPaleteProvider();
2411 var type = this.get('/LeftPanel.model').getType(path);
2412 var opts = provider.findOptions(type);
2413 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2415 if (opts === false) {
2416 this.get('/LeftPanel').editableColumn.setOptions([]);
2417 renderer.has_entry = true;
2419 this.get('/LeftPanel').editableColumn.setOptions(opts);
2420 renderer.has_entry = false;/// - pulldowns do not have entries
2422 // determine if we should use the Text editor...
2423 var keyname = this.getValue(path, 0);
2424 var data_value = this.getValue(path, 1);
2426 if ((keyname[0] == '|') ||
2428 (typeof(data_value) == 'string' ) &&
2429 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2433 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2438 // this.get('/BottomPane').el.hide();
2439 //this.get('/RightEditor').el.hide();
2444 this.activePath = false;
2446 _this.get('/Editor').el.show_all();
2447 GLib.timeout_add(0, 1, function() {
2449 //_this.get('/BottomPane').el.show();
2450 //_this.get('/RightEditor').el.show();
2452 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2454 _this.get('/Editor').activePath = path;
2455 _this.activePath = path ;
2465 // iter now has row...
2466 GLib.timeout_add(0, 100, function() {
2467 _this.activePath = path;
2468 colObj.items[0].el.editable = true; // esp. need for col 0..
2469 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2480 this.get('/LeftPanel.model').el.get_iter_first(iret);
2486 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2489 ar.listeners = ar.listeners || {};
2490 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2493 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2496 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2502 //print(JSON.stringify(ar));
2506 toShort : function(str) {
2507 var a = typeof(str) == 'string' ? str.split("\n") : [];
2508 return a.length > 1 ? a[0] + '....' : '' + str;
2512 xtype: Gtk.TreeViewColumn,
2513 pack : "append_column",
2515 XObject.prototype.init.call(this);
2517 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2518 this.get('/LeftPanel').propertyColumn = this;
2523 xtype: Gtk.CellRendererText,
2524 pack : "pack_start",
2526 editing_started : function (self, editable, path) {
2528 this.get('/LeftPanel.model').activePath = path;
2531 edited : function (self, object, p0) {
2533 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2535 var model = this.get('/LeftPanel.model');
2536 var path = model.activePath;
2538 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2539 model.el.set_value(iret.iter, 0, p0);
2540 model.el.set_value(iret.iter, 2, p0);
2542 model.activePath = false;
2543 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2544 this.get('/LeftTree.model').changed(true);
2546 this.el.editable = false;
2553 xtype: Gtk.TreeViewColumn,
2554 pack : "append_column",
2557 XObject.prototype.init.call(this);
2558 this.el.add_attribute(this.items[0].el , 'text', 3 );
2559 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2560 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2561 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2563 this.get('/LeftPanel').editableColumn= this;
2565 setOptions : function(ar) {
2566 var m = this.items[0].el.model;
2569 ar.forEach(function(i) {
2573 m.set_value(iret.iter, 0, i);
2579 xtype: Gtk.CellRendererCombo,
2581 edited : function (self, object, p0) {
2583 this.get('/LeftPanel').editing = false;
2584 var ap = this.get('/LeftPanel.model').activePath
2585 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2586 this.get('/LeftPanel.model').changed(p0, true);
2587 this.get('/LeftPanel.model').activePath = false;
2588 this.el.editable = false;
2590 editing_started : function (self, editable, path) {
2591 this.get('/LeftPanel').editing = true;
2592 // console.log('editing started');
2593 // r.has_entry = false;
2595 this.el.editable = false; // make sure it's not editor...
2600 pack : "pack_start",
2604 XObject.prototype.init.call(this);
2605 this.el.model = new Gtk.ListStore();
2606 this.el.model.set_column_types ( 1, [
2607 GObject.TYPE_STRING // 0 real key
2618 id : "LeftPanelPopup",
2621 xtype: Gtk.MenuItem,
2625 activate : function (self) {
2626 this.get('/LeftPanel.model').deleteSelected();
2631 xtype: Gtk.MenuItem,
2635 activate : function (self) {
2636 this.get('/LeftPanel.model').startEditing(false, 0);
2649 xtype: Gtk.ScrolledWindow,
2650 pack : "pack_end,false,true,0",
2653 shadow_type : Gtk.ShadowType.IN,
2655 XObject.prototype.init.call(this);
2656 XObject.prototype.init.call(this);
2657 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2658 this.el.set_size_request ( 150, -1 );
2661 activeElement : false,
2662 hideWin : function() {
2665 print("HIDEWIN - currently not shown")
2670 if (this.get('/Window.left').el.position < 160) {
2671 print("HIDEWIN - small already.")
2675 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2676 print("HIDEWIN attempting to hide.")
2683 xtype: Gtk.TreeView,
2685 cursor_changed : function (self) {
2686 // this is getting fired when we are loading elements..
2687 if (this.get('/MidPropTree.model').loading) {
2693 //console.log('changed');
2694 var m = this.get('model');
2695 if (!this.selection){
2696 this.selection = this.el.get_selection();
2699 var s = this.selection;
2700 if (!s.get_selected(iret)) {
2703 var tp = m.el.get_path(iret.iter).to_string();
2708 var key = m.getValue(tp, 0);
2710 var type = m.getValue(tp, 1);
2711 var skel = m.getValue(tp, 3);
2712 var etype = m.getValue(tp, 5);
2715 this.get('/MidPropTree').hideWin();
2717 if (type.toLowerCase() == 'function') {
2719 if (etype != 'events') {
2722 print("cursor_changed: ADDding to left panel model");
2723 this.get('/LeftPanel.model').add({
2731 // has dot in name, and is boolean???? this does not make sense..
2732 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2735 print("cursor_changed: ADDding to left panel model");
2736 this.get('/LeftPanel.model').add( {
2746 enable_tree_lines : true,
2747 headers_visible : false,
2749 XObject.prototype.init.call(this);
2751 var description = new Pango.FontDescription.c_new();
2752 description.set_size(8000);
2753 this.el.modify_font(description);
2755 //this.selection = this.el.get_selection();
2756 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2765 xtype: Gtk.ListStore,
2769 getValue : function(treepath, col)
2771 var tp = new Gtk.TreePath.from_string (treepath);
2773 this.el.get_iter (iret, tp);
2774 var value = this.el.get_value(iret.iter, col);
2775 return ''+ value.value.get_string();
2779 XObject.prototype.init.call(this);
2780 this.el.set_column_types ( 6, [
2781 GObject.TYPE_STRING, // real key
2782 GObject.TYPE_STRING, // real type
2783 GObject.TYPE_STRING, // docs ?
2784 GObject.TYPE_STRING, // visable desc
2785 GObject.TYPE_STRING, // function desc
2786 GObject.TYPE_STRING // element type (event|prop)
2790 showData : function(type) {
2793 this.loading = true;
2795 if (!this.get('/MidPropTree').activeElement || !type) {
2796 this.loading = false;
2797 return; // no active element
2800 var fullpath = this.get('/LeftTree.model').file.guessName(
2801 this.get('/MidPropTree').activeElement);
2802 var palete = this.get('/LeftTree').getPaleteProvider();
2806 Seed.print('Showing right?');
2807 if (!this.get('/MidPropTree').shown) {
2809 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2810 this.get('/MidPropTree').el.show();
2811 this.get('/MidPropTree').shown = true;
2814 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2815 return a.name > b.name ? 1 : -1;
2817 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2818 // console.dump(elementList);
2820 // scope of this is off..??
2823 for(var i =0 ; i < elementList.length; i++) {
2825 var p=elementList[i];
2826 this.el.append(iret);
2827 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2828 //GObject.TYPE_STRING, // real key
2829 // GObject.TYPE_STRING, // real type
2830 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2831 // GObject.TYPE_STRING // func def?
2834 this.el.set_value(iret.iter, 0, p.name);
2835 this.el.set_value(iret.iter, 1, p.type);
2836 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2837 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2838 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2839 this.el.set_value(iret.iter, 5, type);
2842 this.loading = false;
2846 xtype: Gtk.TreeViewColumn,
2849 this.el = new Gtk.TreeViewColumn();
2850 this.parent.el.append_column(this.el);
2852 XObject.prototype.init.call(this);
2853 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2857 xtype: Gtk.CellRendererText,
2858 pack : "pack_start,true"
2885 xtype: Gtk.Notebook,
2886 pack : "pack_start,true,true",
2887 id : "view-help-nb",
2889 XObject.prototype.init.call(this);
2890 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2891 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2895 xtype: Gtk.Notebook,
2896 id : "view-notebook",
2900 XObject.prototype.init.call(this);
2901 this.el.set_current_page(0);
2902 //print("SET LABEL?")
2903 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2904 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2910 id : "RightBrowser",
2915 pack : "pack_start,false,true,0",
2920 clicked : function (self) {
2921 this.get('/RightBrowser.view').renderJS(null,true);
2925 pack : "pack_start,false,false,0"
2928 xtype: Gtk.CheckButton,
2930 toggled : function (self, state) {
2931 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2936 label : "Auto Redraw On",
2937 pack : "pack_start,false,false,0"
2942 clicked : function (self) {
2944 var view = this.get('/RightBrowser.view');
2945 //this.get('/RightBrowser.view').redraws = 99;
2946 view.refreshRequired = true;
2947 view.lastRedraw = false;
2948 view.renderedData = false;
2949 view.renderJS(null,true);
2953 label : "Full Redraw",
2954 pack : "pack_start,false,false,0"
2959 xtype: Gtk.ScrolledWindow,
2962 XObject.prototype.init.call(this);
2963 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2965 shadow_type : Gtk.ShadowType.IN,
2968 xtype: WebKit.WebView,
2970 load_finished : function (self, object) {
2971 print("load finished");
2972 // print("load_finished"); return;
2973 // if (this.ready) { // dont do it twice!
2976 if (!this.inspectorShown) {
2977 this.el.get_inspector().show();
2978 this.inspectorShown = true;
2983 //if (this.pendingRedraw) {
2984 // this.pendingRedraw = false;
2985 // this.refreshRequired = true;
2987 //var js = this.get('/LeftTree.model').toJS();
2988 //if (js && js[0]) {
2989 // this.renderJS(js[0]);
2993 script_alert : function (self, object, p0) {
2996 return true; // do not display anything...
2998 console_message : function (self, object, p0, p1) {
3000 // console.log(object);
3003 if (object.match(/variable/) && object.match(/Builder/)) {
3004 print("got builder missing message");
3005 this.refreshRequired = true;
3006 this.lastRedraw = 0;
3012 if (!object.match(/^\{/)) {
3014 //this.get('/Terminal').feed(object);
3015 return true; // do not handle!!! -> later maybe in console..
3021 // console.log(object);
3022 var val = JSON.parse(object);
3024 if (typeof(val['hover-node']) != 'undefined') {
3025 this.activeNode = val['hover-node'];
3026 console.log('active node: ' + this.activeNode);
3031 if (typeof(val['id']) != 'undefined') {
3032 // this.activeNode = val['id'];
3033 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
3034 if (!tg || typeof(tg[0]) == 'undefined') {
3037 print("SELECT node " + tg[0]);
3039 this.get('/LeftTree.view').selectNode(tg[0]);
3044 if (ret && typeof(val['set']) != 'undefined') {
3045 print("console messages: ADDding to left panel model");
3047 //this.get('/LeftPanel.model').add({
3048 // key : val['set'],
3049 // val : val['value']
3051 //console.log('active node: ' + this.activeNode);
3054 //Seed.print('a:'+a);
3055 //Seed.print('b:'+b);
3056 //Seed.print('c:'+c);
3059 drag_motion : function (w, ctx, x, y, time, ud) {
3060 // console.log('DRAG MOTION');
3062 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3063 this.targetData = [];
3064 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3066 // A) find out from drag all the places that node could be dropped.
3067 var src = Gtk.drag_get_source_widget(ctx);
3068 if (!src.dropList) {
3069 Gdk.drag_status(ctx,0, time);
3072 // b) get what we are over.. (from activeNode)
3073 // tree is empty.. - list should be correct..
3074 if (!this.get('/LeftTree.model').currentTree) {
3075 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3079 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3081 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3084 Gdk.drag_status(ctx, 0,time);
3085 this.get('/LeftTree.view').highlight(false);
3089 // if we have a target..
3090 // -> highlight it! (in browser)
3091 // -> highlight it! (in tree)
3093 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3094 this.get('/LeftTree.view').highlight(tg);
3095 this.targetData = tg;
3096 // for tree we should handle this...
3099 drag_drop : function (w, ctx, x, y,time, ud) {
3100 print("TARGET: drag-drop");
3101 var is_valid_drop_site = true;
3105 ( /* will receive 'drag-data-received' signal */
3106 ctx, /* represents the current state of the DnD */
3107 this.get('/Window').atoms["STRING"], /* the target type we want */
3108 time /* time stamp */
3112 /* No target offered by source => error */
3115 return is_valid_drop_site;
3117 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3119 print("Browser: drag-data-received");
3120 var delete_selection_data = false;
3121 vardnd_success = false;
3122 /* Deal with what we are given from source */
3123 if( sel_data && sel_data.length ) {
3125 if (ctx.action == Gdk.DragAction.ASK) {
3126 /* Ask the user to move or copy, then set the ctx action. */
3129 if (ctx.action == Gdk.DragAction.MOVE) {
3130 delete_selection_data = true;
3132 var source = Gtk.drag_get_source_widget(ctx);
3134 print("Browser: source.DRAGDATA? " + source.dragData);
3135 if (this.targetData) {
3136 print(this.targetData);
3137 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3146 if (dnd_success == false)
3148 Seed.print ("DnD data transfer failed!\n");
3151 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3154 create_web_view : function (self, object) {
3155 print("CREATE WEB VIEW");
3156 return null; //new WebKit.WebView();
3163 XObject.prototype.init.call(this);
3164 // this may not work!?
3165 var settings = this.el.get_settings();
3166 settings.enable_developer_extras = true;
3168 // this was an attempt to change the url perms.. did not work..
3169 // settings.enable_file_access_from_file_uris = true;
3170 // settings.enable_offline_web_application_cache - true;
3171 // settings.enable_universal_access_from_file_uris = true;
3175 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3176 _this.get('/BottomPane.inspector').el.show();
3177 return _this.get('/BottomPane.inspector').el;
3181 // FIXME - base url of script..
3182 // we need it so some of the database features work.
3183 this.el.load_html_string( "Render not ready" ,
3184 //fixme - should be a config option!
3185 // or should we catch stuff and fix it up..
3186 'http://localhost/app.Builder/'
3190 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3192 this.el.drag_dest_set
3193 ( /* widget that will accept a drop */
3194 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3195 null, /* lists of target to support */
3196 0, /* size of list */
3197 Gdk.DragAction.COPY /* what to do with data after dropped */
3200 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3201 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3203 GLib.timeout_add_seconds(0, 1, function() {
3204 // print("run refresh?");
3211 renderJS : function(data, force) {
3213 // this is the public redraw call..
3214 // we refresh in a loop privately..
3215 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3216 if (!autodraw && !force) {
3217 print("Skipping redraw - no force, and autodraw off");
3220 this.refreshRequired = true;
3222 runRefresh : function()
3224 // this is run every 2 seconds from the init..
3228 if (!this.refreshRequired) {
3229 // print("no refresh required");
3233 if (this.lastRedraw) {
3234 // do not redraw if last redraw was less that 5 seconds ago.
3235 if (((new Date()) - this.lastRedraw) < 5000) {
3243 if (!this.get('/Window.LeftTree').getActiveFile()) {
3246 this.refreshRequired = false;
3247 // print("HTML RENDERING");
3249 this.get('/BottomPane').el.show();
3250 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3257 var js = this.get('/LeftTree.model').toJS();
3258 if (!js || !js.length) {
3267 var project = this.get('/Window.LeftTree').getActiveFile().project;
3268 //print (project.fn);
3269 // set it to non-empty.
3270 project.runhtml = project.runhtml || '';
3271 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3274 this.runhtml = this.runhtml || '';
3276 var file = this.get('/LeftTree.model').file;
3277 var items = file.items;
3278 file.items = this.get('/LeftTree.model').toJS(false, false);
3279 //file.items[0].background = false;
3280 //var p = file.parent;
3281 //file.parent = false;
3283 var js_src = file.toSourcePreview();
3284 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3285 // unless it' sforced..
3290 this.renderedData = js_src;
3293 //file.items = items;
3294 //print("send source as " + js_src);
3297 "Roo.onReady(function() {\n" +
3298 "if (" + file.name +".show) " + file.name +".show({});\n" +
3299 "Roo.XComponent.build();\n" +
3306 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3307 // then we need to reload the browser using
3308 // load_html_string..
3310 // then trigger a redraw once it's loaded..
3311 this.pendingRedraw = true;
3312 var runhtml = '<script type="text/javascript">' + "\n" ;
3313 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3314 runhtml += '</script>'+ "\n" ;
3316 this.runhtml = project.runhtml;
3317 // need to modify paths
3320 this.lastRedraw= new Date();
3321 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3322 html = html.replace('</head>',
3325 '<script type="text/javascript">' + "\n" +
3330 //print("LOAD HTML " + html);
3331 this.el.load_html_string( html ,
3332 //fixme - should be a config option!
3333 'http://localhost/app.Builder/'
3336 // should trigger load_finished! - which in truns shoudl set refresh Required;
3341 //this.renderedData = data;
3342 //var str = JSON.stringify(data) ;
3345 console.log('not loaded yet');
3347 this.lastRedraw = new Date();
3349 this.el.execute_script("Builder.render(" +
3350 JSON.stringify(js_src) +
3352 JSON.stringify(file.name) +
3355 print( "before render" + this.lastRedraw);
3356 print( "after render" + (new Date()));
3366 id : "RightGtkView",
3368 redraw : function() {
3369 this.highlightWidget = false;
3370 print("REDRAW CALLED");
3371 this.activePath = this.get('/LeftTree').getActivePath();
3372 if (this.renderedEl) {
3373 print("QUEUE DRAW CALLING");
3374 this.renderedEl.queue_draw();
3377 renderJS : function(data, withDebug)
3379 this.highlightWidget = false;
3381 this.withDebug = false;
3382 while (this.get('view').el.get_children().length) {
3383 var c = this.get('view').el.get_children()[0];
3384 this.get('view').el.remove(c);
3391 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3392 // in theory tree is actually window..
3395 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3401 this.get('view').el.set_size_request(
3402 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3404 if (this.renderedEl) {
3405 this.renderedEl.set_size_request(
3406 tree.default_width || 600,
3407 tree.default_height || 400
3410 this.get('view').el.show_all();
3415 showInWindow : function() {
3416 print("GET PROEJCT");
3417 var pr = this.get('/LeftProjectTree').getActiveProject();
3419 console.log(pr.paths);
3422 var src= this.buildJS(
3423 this.get('/LeftTree.model').toJS()[0],
3428 //var x = new imports.sandbox.Context();
3432 Seed.check_syntax('var e = ' + src);
3435 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3436 this.get('/Terminal').feed(console._dump(e)+"\n");
3438 var lines = src.split("\n");
3439 var start = Math.max(0, e.line - 10);
3440 var end = Math.min(lines.length, e.line + 10);
3441 for (var i =start ; i < end; i++) {
3443 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3446 this.get('/Terminal').feed(lines[i] + "\n");
3453 this.get('/BottomPane').el.set_current_page(1);
3454 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3455 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3456 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3458 var _top = x.get_global_object()._top;
3460 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3462 if (_top.el.popup) {
3463 _top.el.popup(null, null, null, null, 3, null);
3467 viewAdd : function(item, par)
3470 // does something similar to xobject..
3471 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3473 // pack is forced to 'false'
3474 if (item.pack===false || item.pack === 'false') { // no ;
3478 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3481 var type = item['|xns'] + '.' + item['xtype'];
3483 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3487 var ns = imports.gi[item['|xns']];
3488 var ctr = ns[item['xtype']]; // why are we using array here..?
3493 for(var k in item) {
3495 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3509 // value is a function..
3510 if (k[0] == '|' && typeof(kv) == 'string') {
3512 if (kv.match(new RegExp('function'))) {
3515 print("WASL " + k + '=' + kv);
3517 eval( 'kv = ' + kv);
3518 } catch(e) { continue; }
3521 // print(k + '=' + kv);
3523 if (k[0] == '|') { // should be boolean or number..
3525 //print(k + '=' + kv);
3528 if (k == 'show_tabs') { // force tab showing for notebooks.
3531 print(k + '=' + typeof(kv) + " : " + kv);
3535 var altctr = XObject.baseXObject({ xtype: ctr} );
3537 if (!item.pack && altctr) {
3539 print("SETTING PACK TO XObjectBase method");
3540 pack_m = altctr.prototype.pack;
3545 var el = new ctr(ctr_args);
3547 print("PACK" + item.pack);
3548 //console.dump(item.pack);
3555 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3556 if (typeof(item.pack) == 'string') {
3558 item.pack.split(',').forEach(function(e, i) {
3560 if (e == 'false') { args.push( false); return; }
3561 if (e == 'true') { args.push( true); return; }
3562 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3565 //print(args.join(","));
3567 pack_m = args.shift();
3569 pack_m = item.pack.shift();
3574 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3576 name: "ArgumentError",
3577 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3578 "ADDING : " + item.id + " " + el
3585 //console.dump(args);
3587 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3588 //Seed.print('args: ' + args.length);
3589 if (typeof(pack_m) == 'string') {
3590 par[pack_m].apply(par, args);
3591 } else if (pack_m) {
3592 pack_m.call(item, par, item);
3596 item.items = item.items || [];
3597 item.items.forEach(function(ch,n) {
3599 print ("type:" + type);
3601 print ("ch.pack:" + ch.pack);
3604 if (type == 'Gtk.Table' && ch.pack == 'add') {
3605 var c = n % item.n_columns;
3606 var r = Math.floor(n/item.n_columns);
3607 ch.pack = [ 'attach', c, c+1, r, r+1,
3608 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3609 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3610 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3611 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3615 _this.viewAdd(ch, el);
3620 // add the signal handlers.
3621 // is it a widget!?!!?
3627 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3628 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3629 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3630 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3631 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3641 widgetDragDropEvent : function() {
3642 print("WIDGET DRAGDROP");
3645 widgetDragMotionEvent : function() {
3646 print("WIDGET DRAGMOTION");
3649 widgetExposeEvent : function(w, evt, ud, item) {
3651 if (this.inRender) {
3655 if ( this.highlightWidget) {
3656 this.inRender = true;
3657 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3658 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3660 this.inRender = false;
3665 if (this.activePath != item.xtreepath) {
3669 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3670 // work out the coords of the window..
3672 var dr = widget.window;
3673 this.gc = (new Gdk.GC.c_new(dr));
3674 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3675 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3679 var r = evt.expose.area;
3680 // console.dump([r.x, r.y, r.width, r.height ] );
3682 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3683 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3684 // happens with gtkscrollview embedded stuff..
3685 var np =this.activePath.split(':');
3687 this.activePath = np.join(':');
3688 this.renderedEl.queue_draw();
3704 this.inRender = true;
3707 this.highlightWidget = widget;
3712 // print("DRAW BOX");
3713 //console.dump(this.box);
3714 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3715 this.inRender = false;
3718 widgetPressEvent : function(w,e,u,d) {
3719 if (this.get('view').pressed) {
3722 this.get('view').pressed = true;
3723 print("WIDGET PRESS " + d.xtreepath );
3724 this.get('/LeftTree.view').selectNode( d.xtreepath );
3727 widgetReleaseEvent : function() {
3728 this.get('view').pressed = false;
3734 pack : "pack_start,false,true,0",
3738 pack : "pack_start,false,false,0",
3739 label : "Run The Application",
3741 button_press_event : function (self, event) {
3742 // call render on left tree - with special option!?!
3744 //print("GET PROEJCT");
3745 var pr = this.get('/LeftProjectTree').getActiveProject();
3748 for (var i in pr.paths) {
3752 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3753 this.get('/Terminal').feed("RUN DIR:" + dir);
3756 this.get('/Terminal').el.fork_command_full(
3757 Vte.PtyFlags.DEFAULT,
3758 GLib.path_get_dirname (__script_path__) ,
3759 [ 'echo' , "hello"], //argv
3763 null, // child setupdata
3767 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3768 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3778 xtype: Gtk.ScrolledWindow,
3781 shadow_type : Gtk.ShadowType.IN,
3783 XObject.prototype.init.call(this);
3784 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3788 xtype: Gtk.EventBox,
3789 pack : "add_with_viewport",
3791 XObject.prototype.init.call(this);
3792 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3793 red: 0x9F00, green: 0xB800 , blue : 0xA800
3801 XObject.prototype.init.call(this);
3802 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3803 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3808 xtype: Gtk.EventBox,
3811 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3812 XObject.prototype.init.call(this);
3814 this.el.drag_dest_set
3815 ( /* widget that will accept a drop */
3816 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3817 null, /* lists of target to support */
3818 0, /* size of list */
3819 Gdk.DragAction.COPY /* what to do with data after dropped */
3822 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3823 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3826 getActiveNode : function(x,y)
3828 // workout what node is here..
3829 return '0'; // top..
3833 drag_motion : function (self, ctx, x, y, time) {
3835 // A) find out from drag all the places that node could be dropped.
3836 var src = Gtk.drag_get_source_widget(ctx);
3837 if (!src.dropList) {
3838 Gdk.drag_status(ctx, 0, time);
3841 // b) get what we are over.. (from activeNode)
3842 // tree is empty.. - list should be correct..
3843 if (!this.get('/LeftTree.model').currentTree) {
3844 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3848 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3849 var activeNode = this.getActiveNode(x, y);
3852 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3855 Gdk.drag_status(ctx, 0,time);
3856 this.get('/LeftTree.view').highlight(false);
3860 // if we have a target..
3861 // -> highlight it! (in browser)
3862 // -> highlight it! (in tree)
3864 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3865 this.get('/LeftTree.view').highlight(tg);
3866 this.targetData = tg;
3867 // for tree we should handle this...
3870 drag_drop : function (self,ctx, x, y, time) {
3871 Seed.print("TARGET: drag-drop");
3872 var is_valid_drop_site = true;
3876 ( /* will receive 'drag-data-received' signal */
3877 ctx, /* represents the current state of the this.gDnD */
3878 this.get('/Window').atoms["STRING"], /* the target type we want */
3879 time /* time stamp */
3883 /* No target offered by source => error */
3886 return is_valid_drop_site;
3889 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3891 Seed.print("GtkView: drag-data-received");
3892 var delete_selection_data = false;
3893 var dnd_success = false;
3894 /* Deal with what we are given from source */
3895 if( sel_data && sel_data.length ) {
3897 if (ctx.action == Gdk.DragAction.ASK) {
3898 /* Ask the user to move or copy, then set the ctx action. */
3901 if (ctx.action == Gdk.DragAction.MOVE) {
3902 delete_selection_data = true;
3904 var source = Gtk.drag_get_source_widget( ctx );
3906 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3907 if (this.targetData) {
3908 Seed.print(this.targetData);
3909 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3918 if (dnd_success == false)
3920 Seed.print ("DnD data transfer failed!\n");
3923 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3926 button_press_event : function (self, event) {
3927 this.pressed = false;
3943 xtype: Gtk.ScrolledWindow,
3948 var file = this.get('/LeftTree').getActiveFile();
3952 var activeEl = this.get('/LeftTree').getActiveElement();
3953 var xtype = file.guessName( activeEl )
3954 if (!xtype || !xtype.length) {
3957 //this.get('/Window.view-help-nb').el.set_current_page(1);
3959 // get the active element being edited.
3960 var helpurl = file.getHelpUrl(xtype);
3962 // now load the help info in the page..
3963 this.get('help-view').el.open(helpurl);
3967 xtype: WebKit.WebView,
3971 XObject.prototype.init.call(this);
3972 this.get('/Window.help-view').el.open(
3973 "http://devel.akbkhome.com/seed/");
3985 xtype: Gtk.Notebook,
3989 XObject.prototype.init.call(this);
3990 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3991 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3992 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3996 xtype: Gtk.ScrolledWindow,
4000 xtype: Vte.Terminal,
4003 feed : function(istr) {
4004 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
4005 // we should make ourselves visable!!!
4006 this.get('/BottomPane').el.show();
4007 this.get('/BottomPane').el.set_current_page(1);
4009 this.el.feed(str ,str.length);
4011 scroll_on_output : true,
4013 XObject.prototype.init.call(this);
4014 this.el.set_size (80, 1000);
4016 scrollback_lines : 1000
4021 xtype: Gtk.ScrolledWindow,
4025 xtype: WebKit.WebView,
4041 this.get('buttonbar').el.show();
4042 this.get('viewbox').el.hide();
4043 var ce = this.get('/Window.centereast').el;
4045 ce.set_position(ce.get_allocated_width() - 30);
4047 print("TRIED TO HIDE");
4050 this.get('buttonbar').el.hide();
4051 this.get('viewbox').el.show();
4052 var ce = this.get('/Window.centereast').el;
4053 print(JSON.stringify(XObject.keys(ce) ,null,4));
4054 ce.set_position(ce.get_allocated_width() - 150);
4056 // this.get('model').expanded();
4068 pack : "pack_start,false,true",
4070 clicked : function (self) {
4071 this.get('/RightPalete').show();
4078 stock : Gtk.STOCK_GOTO_FIRST,
4079 icon_size : Gtk.IconSize.MENU
4089 XObject.prototype.init.call(this);
4090 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4093 enter_notify_event : function (self, event) {
4094 this.get('/RightPalete').show();
4108 pack : "pack_start,false,true",
4117 pack : "pack_start,false,true",
4119 clicked : function (self) {
4120 this.get('/RightPalete').hide();
4127 stock : Gtk.STOCK_GOTO_LAST,
4128 icon_size : Gtk.IconSize.MENU
4135 xtype: Gtk.ScrolledWindow,
4138 XObject.prototype.init.call(this);
4139 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4140 this.el.set_size_request(-1,200);
4142 shadow_type : Gtk.ShadowType.IN,
4145 xtype: Gtk.TreeView,
4147 drag_begin : function (self, ctx) {
4148 // we could fill this in now...
4149 Seed.print('SOURCE: drag-begin');
4154 var s = this.selection;
4155 s.get_selected(iret);
4156 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4158 var pix = this.el.create_row_drag_icon ( path);
4161 if (Gtk.drag_set_icon_surface) {
4162 Gtk.drag_set_icon_surface( ctx, pix );
4164 Gtk.drag_set_icon_pixmap (ctx,
4165 pix.get_colormap(), pix, null, -10, -10);
4168 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4169 if (!this.get('/RightPalete').provider) {
4172 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4173 this.el.dragData = value;
4180 drag_data_get : function (self, drag_context, selection_data, info, time) {
4181 //Seed.print('Palete: drag-data-get: ' + target_type);
4182 if (this.el.dragData && this.el.dragData.length ) {
4183 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4187 //this.el.dragData = "TEST from source widget";
4191 drag_end : function (self, drag_context) {
4192 Seed.print('SOURCE: drag-end');
4193 this.el.dragData = false;
4194 this.el.dropList = false;
4195 this.get('/LeftTree.view').highlight(false);
4198 button_press_event : function (self, event) {
4200 if (!this.get('/Editor').save()) {
4201 // popup!! - click handled..
4208 enable_tree_lines : true,
4209 headers_visible : false,
4211 XObject.prototype.init.call(this);
4212 this.el.set_size_request(150,-1);
4213 // set_reorderable: [1]
4215 var description = new Pango.FontDescription.c_new();
4216 description.set_size(8000);
4217 this.el.modify_font(description);
4219 this.selection = this.el.get_selection();
4220 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4221 // this.selection.signal['changed'].connect(function() {
4222 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4224 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4226 this.el.drag_source_set ( /* widget will be drag-able */
4227 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4228 null, /* lists of target to support */
4229 0, /* size of list */
4230 Gdk.DragAction.COPY /* what to do with data after dropped */
4232 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4234 this.el.drag_source_set_target_list( this.get('/Window').targetList);
4235 this.el.drag_source_add_text_targets( );
4237 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4238 targets = new Gtk.TargetList();
4239 targets.add( LeftTree.atoms["STRING"], 0, 0);
4240 targets.add_text_targets( 1 );
4241 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4243 //if you want to allow text to be output elsewhere..
4244 //Gtk.drag_source_add_text_targets(this.el);
4250 xtype: Gtk.ListStore,
4253 XObject.prototype.init.call(this);
4254 this.el.set_column_types ( 2, [
4255 GObject.TYPE_STRING, // title
4256 GObject.TYPE_STRING // tip
4261 load : function(tr,iter)
4266 //console.log('Project tree load: ' + tr.length);
4268 //this.insert(citer,iter,0);
4269 for(var i =0 ; i < tr.length; i++) {
4272 this.el.append(cret);
4274 this.el.insert(cret,iter,-1);
4279 this.el.set_value(cret.iter, 0, '' + r ); // title
4281 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4282 //if (r.cn && r.cn.length) {
4283 // this.load(r.cn, citer);
4289 getValue : function (iter, col) {
4290 return this.el.get_value(iter, col).value.get_string();
4297 xtype: Gtk.TreeViewColumn,
4298 pack : "append_column",
4300 XObject.prototype.init.call(this);
4301 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4305 xtype: Gtk.CellRendererText,
4327 XObject.cache['/Window'] = Window;