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..
720 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
721 this.get('/LeftTree.model').listAllTypes()));
722 if (render && render.redraw) {
728 //console.log('changed');
729 var s = this.selection;
734 var value = ''+ret.model.get_value(ret.iter, 2).value.get_string();
735 this.get('/LeftPanel.model').activePath = ret.model.get_path(ret.iter).to_string();
737 print("----------START EDITING: " + this.get('/LeftTree').getActivePath() );
740 var data = JSON.parse(value);
741 this.get('/MidPropTree').activeElement = data;
742 this.get('/MidPropTree').hideWin();
743 this.get('/LeftPanel.model').load( data);
746 // _g.button.set_label(''+value.get_string());
748 var pm =this.get('/RightPalete.model');
749 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
750 this.get('/LeftTree.model').listAllTypes()));
753 if (render && render.redraw) {
757 //Seed.print( value.get_string());
765 enable_tree_lines : true,
766 headers_visible : false,
767 highlight : function(treepath_ar) {
769 // highlighting for drag/drop
770 if (treepath_ar.length && treepath_ar[0].length ) {
771 this.el.set_drag_dest_row(
772 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
774 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
780 XObject.prototype.init.call(this);
781 var description = new Pango.FontDescription.c_new();
782 description.set_size(8000);
783 this.el.modify_font(description);
785 this.selection = this.el.get_selection();
786 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
789 // is this really needed??
790 this.selection.signal['changed'].connect(function() {
791 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
792 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
796 this.el.drag_source_set( /* widget will be drag-able */
797 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
798 null, /* lists of target to support */
799 0, /* size of list */
800 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
803 this.el.drag_source_set_target_list(this.get('/Window').targetList);
805 this.el.drag_source_add_text_targets();
806 this.el.drag_dest_set
808 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
809 null, /* lists of target to support */
810 0, /* size of list */
811 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
814 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
815 this.el.drag_dest_add_text_targets( );
817 selectNode : function(treepath_str) {
818 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
819 var tp = new Gtk.TreePath.from_string(treepath_str);
820 this.el.set_cursor(tp, null, false);
821 this.el.scroll_to_cell(tp, null, false, 0,0);
825 xtype: Gtk.TreeStore,
831 setFromNode : function(tp, n)
834 tp = this.get('/LeftTree').getActivePath();
837 this.el.get_iter(ret, new Gtk.TreePath.from_string( tp ) );
838 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(n));
839 this.el.set_value(ret.iter, 1, '' + this.nodeTitle(n));
840 this.el.set_value(ret.iter, 2, '' + this.nodeToJSON(n));
844 changed : function( refresh) {
848 print("-------MODEL CHANGED CALLED" );
850 //this.currentTree = this.toJS(false, true)[0];
852 this.file.items = this.toJS(false, false);
853 print ("TO JS in " + ((new Date()) - d) + "ms");
854 // print("AFTER CHANGED");
855 //console.dump(this.file.items);
857 this.currentTree = this.file.items[0];
858 //console.log(this.file.toSource());
861 print("REDNER BROWSER?!");
862 this.get('/LeftTree').renderView();
864 var pm = this.get('/RightPalete.model');
865 if (!this.get('/RightPalete').provider) {
871 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
872 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
876 deleteSelected : function() {
877 this.get('/LeftTree.view').blockChanges = true;
879 var s = this.get('/LeftTree.view').selection;
880 s.get_selected(oret);
881 var path = this.el.get_path(oret.iter).to_string();
883 this.activePath= false;
886 this.activePath= false;
888 this.el.get_iter_from_string(ret, path);
889 this.el.remove(ret.iter);
891 // rebuild treemap. -- depreciated.!!
894 //this.toJS(null, true) // does not do anything?
895 this.activePath= false;
897 this.get('/LeftTree.view').blockChanges = false;
899 dropNode : function(target_data, node) {
901 // console.dump(node);
902 //print(JSON.Stringify(target_data, null, 4));
903 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
905 print("add " + tp + "@" + target_data[1] );
908 if (tp && target_data[1] < 2) { // before or after..
909 var ar = target_data[0].split(':');
911 parent = new Gtk.TreePath.from_string( ar.join(':') );
916 var aret = after ? {} : false;
920 if (parent !== false) {
921 this.el.get_iter(pret, parent);
928 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
929 this.el.get_iter(aret, after);
930 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
931 nret, pret.iter, aret.iter);
934 this.el.append(nret, pret.iter);
937 var new_path = this.el.get_path(nret.iter).to_string();
938 print("new path = " + new_path)
939 if (typeof(node) == 'string') {
940 var ar = node.split('.');
941 var xtype = ar.pop();
944 '|xns' : ar.join('.'),
947 if (target_data.length == 3 && target_data[2].length) {
948 node['*prop'] = target_data[2];
950 node = this.get('/DialogTemplateSelect').show(node);
953 // work out what kind of packing to use..
954 if (typeof(node.pack) == 'undefined' && parent !== false) {
955 var pal = this.get('/LeftTree').getPaleteProvider();
956 if (pal.name == 'Gtk') {
957 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
958 var cname = pal.guessName(node);
959 node.pack = pal.getDefaultPack(pname, cname);
970 // load children - if it has any..
973 this.load(xitems, nret.iter);
974 this.get('/LeftTree.view').el.expand_row(this.el.get_path(nret.iter), true);
976 if (tp && (xitems || after)) {
977 this.get('/LeftTree.view').el.expand_row(this.el.get_path(pret.iter), true);
979 // wee need to get the empty proptypes from somewhere..
981 //var olditer = this.activeIter;
982 //this.activePath = new_path;
983 print("calling changed with node data")
984 // changed actually set's the node data..
985 this.setFromNode(new_path,node);
990 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(nret.iter), null, false);
992 //Builder.MidPropTree._model.load(node);
993 //Builder.MidPropTree._win.hideWin();
994 //Builder.LeftPanel._model.load( node);
998 findDropNode : function(treepath_str, targets) {
1000 // this is used by the dragdrop code in the roo version AFAIR..
1002 var path = treepath_str.replace(/^builder-/, '');
1003 // treemap is depreciated... - should really check if model has any entries..
1005 if (!this.el.iter_n_children(null)) {
1007 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
1009 print("FIND treepath: " + path);
1010 //console.dump(this.treemap);
1012 if (!treepath_str.match(/^builder-/)) {
1013 return []; // nothing!
1015 if (targets === true) {
1018 return this.findDropNodeByPath(path,targets)
1020 findDropNodeByPath : function(treepath_str, targets, pref) {
1021 var path = treepath_str + ''; // dupe it..
1022 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
1024 //console.dump(this.treemap);
1025 while (path.length) {
1026 print("LOOKING FOR PATH: " + path);
1027 var node_data = this.singleNodeToJS(path);
1028 if (node_data === false) {
1029 print("node not found");
1033 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1036 targets.forEach(function(tg) {
1040 if ((tg == xname) ) {
1043 if (tg.indexOf(xname +':') === 0) {
1045 prop = tg.split(':').pop();
1050 if (last) { // pref is after/before..
1051 // then it's after last
1053 return []; // do not allow..
1055 return [ last, pref , prop];
1058 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1060 var par = path.split(':');
1063 path = par.join(':');
1069 getIterValue : function (iter, col) {
1071 var gval = ''+this.el.get_value(iter, col).value.get_string();
1077 XObject.prototype.init.call(this);
1078 this.el.set_column_types ( 3, [
1079 GObject.TYPE_STRING, // title
1080 GObject.TYPE_STRING, // tip
1081 GObject.TYPE_STRING // source..
1084 listAllTypes : function() {
1085 var s = this.get('/LeftTree.view').selection;
1086 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1088 if (s.count_selected_rows() > 0) {
1090 s.get_selected(ret);
1092 // set some properties of the tree for use by the dropped element.
1093 var value = ''+ this.el.get_value(ret.iter, 2).value.get_string();
1094 var data = JSON.parse(value);
1097 var xname = this.get('/LeftTree.model').file.guessName(data);
1098 console.log('selected:' + xname);
1102 return []; // could not find it..
1110 li.forEach(function(el) {
1111 // this is specific to roo!!!?
1112 if (!el) { // skip empty?
1115 var fullpath = _this.file.guessName(el);
1116 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1121 if (el.items && el.items.length) {
1130 addall([this.currentTree]);
1132 // only if we have nothing, should we add '*top'
1136 //console.log('all types in tree');
1137 //console.dump(ret);
1142 load : function(tr,iter)
1144 //this.insert(citer,iter,0);
1146 for(var i =0 ; i < tr.length; i++) {
1149 this.el.insert(ret ,iter,-1);
1151 this.el.append(ret);
1153 print(JSON.stringify(ret,null,4));
1154 print('call nodeToJSON: ' + tr[i]);
1155 var body = this.nodeToJSON(tr[i]);
1157 //this.el.set_value(ret.iter, 0, '' _ [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1158 //this.el.set_value(ret.iter, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1159 //this.el.set_value(ret.iter, 2, [GObject.TYPE_STRING, body ]);
1160 this.el.set_value(ret.iter, 0, '' + this.nodeTitle(tr[i]) );
1161 this.el.set_value(ret.iter, 1, '' + this.nodeTip(tr[i]) );
1162 this.el.set_value(ret.iter, 2, '' + body );
1163 if (tr[i].items && tr[i].items.length) {
1164 this.load(tr[i].items, ret.iter);
1168 loadFile : function(f) {
1174 console.log('missing file');
1178 // load the file if not loaded..
1179 if (f.items === false) {
1181 f.loadItems(function() {
1187 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1189 if (f.items.length && typeof(f.items[0]) == 'string') {
1191 //this.get('/RightEditor').el.show();
1192 //this.get('/RightEditor.view').load( f.items[0]);
1196 print(JSON.stringify(f.items, null,4));
1197 //console.dump(f.items);
1199 this.get('/LeftTree.view').el.expand_all();
1201 if (!f.items.length) {
1204 this.get('/Window.leftvpaned').el.set_position(80);
1206 this.get('/LeftTree.view').el.set_cursor(
1207 new Gtk.TreePath.from_string('0'), null, false);
1211 this.get('/Window.leftvpaned').el.set_position(200);
1214 //return; -- debuggin
1215 //print("hide right editior");
1216 //this.get('/RightEditor').el.hide();
1217 this.get('/Editor').el.hide();
1218 print("set current tree");
1220 this.currentTree = this.toJS(false, false)[0];
1223 console.dump(this.currentTree);
1224 this.currentTree = this.currentTree || { items: [] };
1225 this.get('/LeftTree').renderView();
1226 console.dump(this.map);
1227 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1228 var pm = this.get('/RightPalete.model');
1229 // set up provider..
1231 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1233 if (!this.get('/RightPalete').provider) {
1234 print ("********* PALETE PROVIDER MISSING?!!");
1236 this.get('/LeftTree').renderView();
1238 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1242 this.get('/Window.view-notebook').el.set_current_page(
1243 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1246 moveNode : function(target_data, action) {
1247 //print("MOVE NODE");
1248 // console.dump(target_data);
1250 var s = this.get('/LeftTree.view').selection;
1251 s.get_selected( oret);
1252 var node = this.nodeToJS(oret.iter,false);
1253 //console.dump(node);
1254 print(JSON.stringify(node, null,4));
1256 // needs to drop first, otherwise the target_data
1257 // treepath will be invalid.
1259 this.dropNode(target_data, node);
1260 if (action & Gdk.DragAction.MOVE) {
1261 // print("REMOVING OLD NODE");
1262 this.el.remove(oret.iter);
1266 this.activePath= false;
1269 nodeTip : function(c) {
1270 var ret = this.nodeTitle(c,true);
1276 if (!i.length || i[0] != '|') {
1282 if (typeof(c[i]) != 'string') {
1285 //print("prop : " + i + ':' + c[i]);
1286 if (!c[i].match(new RegExp('function'))) {
1289 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1293 ret+="\n\nMethods:" + funcs;
1298 nodeTitle : function(c, renderfull) {
1301 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1302 if (sr) txt.push('<s>');
1303 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1305 if (renderfull && c['|xns']) {
1306 txt.push(c['|xns']);
1309 if (c.xtype) { txt.push(c.xtype); }
1310 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1311 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1312 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1315 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1316 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1317 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1318 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1319 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1320 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1321 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1322 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1323 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1325 // for flat classes...
1326 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1327 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1330 if (sr) txt.push('</s>');
1331 return (txt.length == 0 ? "Element" : txt.join(" "));
1333 nodeToJS : function (treepath, with_id)
1335 print("nodeToJS : WITHID: "+ with_id);
1336 var iter = treepath; // API used to be iter here..
1337 if (typeof(iter) == 'string') {
1339 if (!this.el.get_iter(ret,
1340 new Gtk.TreePath.from_string(treepath))) {
1346 var iv = this.getIterValue(iter, 2);
1347 // print("IV" + iv);
1348 var k = JSON.parse(iv);
1349 if (k && k.json && !this.el.iter_parent( pret, iter )) {
1354 var treepath_str = this.el.get_path(iter).to_string();
1355 // not sure how we can handle mixed id stuff..
1356 if (typeof(k.id) == 'undefined') {
1357 k.id = 'builder-'+ treepath_str ;
1361 this.treemap[ treepath_str ] = k;
1362 k.xtreepath = treepath_str ;
1365 if (this.el.iter_has_child(iter)) {
1367 this.el.iter_children(cret, iter);
1368 k.items = this.toJS(cret.iter,with_id);
1372 nodeToJSON : function(c) {
1380 return JSON.stringify(o);
1382 singleNodeToJS : function (treepath)
1385 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1389 var iv = this.getIterValue(ret.iter, 2);
1391 return JSON.parse(iv);
1394 toJS : function(treepath, with_id)
1396 print("toJS : WITHID: "+ with_id);
1398 var iter = treepath; // API used to be iter here..
1400 if (typeof(iter) == 'string') {
1402 if (!this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath))) {
1414 if (!this.el.get_iter_first(ret)) {
1425 var k = this.nodeToJS(iter, with_id);
1429 if (!this.el.iter_next(iter)) {
1434 if (treepath === false) {
1436 return JSON.parse(JSON.stringify(ar));
1440 // convert the list into a json string..
1446 xtype: Gtk.TreeViewColumn,
1447 pack : "append_column",
1449 XObject.prototype.init.call(this);
1450 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1454 xtype: Gtk.CellRendererText,
1464 id : "LeftTreeMenu",
1467 xtype: Gtk.MenuItem,
1469 label : "Delete Element",
1471 activate : function (self) {
1473 this.get('/LeftTree.model').deleteSelected();
1478 xtype: Gtk.MenuItem,
1480 activate : function (self) {
1482 var tree = this.get('/LeftTree');
1483 var model = this.get('/LeftTree.model');
1484 var el = tree.getActivePath();
1486 var js = model.toJS(el, false);
1487 // print(JSON.stringify(js[0], null,4));
1488 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1493 label : "Save as Template",
1503 id : "LeftProjectTree",
1504 showNoProjectSelected : function() {
1505 this.get('/StandardErrorDialog').show("Select a Project first.");
1507 getActiveProject : function() {
1508 return this.project;
1511 leave_notify_event : function (self, event) {
1518 pack : "pack_start,false,false",
1521 xtype: Gtk.ComboBox,
1523 changed : function (self) {
1524 var fn = this.getValue();
1525 var pm = imports.ProjectManager.ProjectManager;
1526 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1530 getValue : function() {
1531 var ix = this.el.get_active();
1535 var data = imports.ProjectManager.ProjectManager.projects;
1536 if (typeof(data[ix]) == 'undefined') {
1542 XObject.prototype.init.call(this);
1543 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1545 setValue : function(fn)
1549 var data = imports.ProjectManager.ProjectManager.projects;
1550 data.forEach(function(n, ix) {
1559 xtype: Gtk.CellRendererText,
1560 pack : "pack_start,true",
1564 xtype: Gtk.ListStore,
1568 XObject.prototype.init.call(this);
1569 this.el.set_column_types ( 2, [
1570 GObject.TYPE_STRING, // real key
1571 GObject.TYPE_STRING // real type
1575 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1576 var pm = imports.ProjectManager.ProjectManager;
1578 pm.on('changed', function() {
1579 print("caught changed hook on project manager - reloading data");
1580 _this.loadData(pm.projects);
1584 loadData : function(data) {
1585 var ov = this.get('/LeftProjectTree.combo').getValue();
1589 data.forEach(function(p) {
1592 print(JSON.stringify(XObject.keys(na)));
1593 print(typeof(na.iter));
1594 //print(JSON.stringify(iter))
1595 el.set_value(na.iter, 0, p.fn);
1596 el.set_value(na.iter, 1, p.name);
1600 this.get('/LeftProjectTree.combo').setValue(ov);
1608 xtype: Gtk.ScrolledWindow,
1610 shadow_type : Gtk.ShadowType.IN,
1612 XObject.prototype.init.call(this);
1613 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1617 xtype: Gtk.TreeView,
1619 cursor_changed : function (self) {
1621 if (this.selection.count_selected_rows() < 1) {
1622 //XN.get('Builder.LeftTree.model').
1623 this.get('/LeftTree.model').load( false);
1627 var model = this.get('/LeftProjectTree.model');
1628 //console.log('changed');
1629 var s = this.selection;
1630 s.get_selected(ret);
1631 var value = ''+ ret.model.get_value(ret.iter, 2).value.get_string();
1632 //console.log(JSON.stringify(value,null,4));// id..
1633 console.log("OUT?" + value);// id..
1634 var file = this.get('/LeftProjectTree').project.getById(value);
1641 var nb = this.get('/LeftTopPanel.expander');
1642 nb.el.expanded = false;
1644 //nb.listeners.activate.call(nb);
1645 //_expander.el.set_expanded(false);
1647 var ltm = this.get('/LeftTree.model');
1655 enable_tree_lines : true,
1656 headers_visible : false,
1658 XObject.prototype.init.call(this);
1659 var description = new Pango.FontDescription.c_new();
1660 description.set_size(8000);
1661 this.el.modify_font(description);
1663 this.selection = this.el.get_selection();
1664 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1668 xtype: Gtk.TreeStore,
1672 XObject.prototype.init.call(this);
1673 this.el.set_column_types ( 3, [
1674 GObject.TYPE_STRING, // title
1675 GObject.TYPE_STRING, // tip
1676 GObject.TYPE_STRING // id..
1680 loadProject : function(pr) {
1681 print("LOAD PROJECT");
1687 this.get('/LeftProjectTree').project = pr;
1688 this.load(pr.toTree());
1689 this.get('/LeftProjectTree.view').el.expand_all();
1691 load : function(tr,iter) {
1692 // console.dump(tr);
1693 console.log('Project tree load: ' + tr.length);
1695 //this.insert(citer,iter,0);
1698 tr.forEach(function (r) {
1700 _this.el.append(cret);
1702 _this.el.insert(cret,iter,-1);
1704 _this.el.set_value(cret.iter, 0, '' + r.getTitle() ); // title
1705 _this.el.set_value(cret.iter, 1, '' + r.getTitleTip()); // tip
1706 _this.el.set_value(cret.iter, 2, '' + r.id ); //id
1707 if (r.cn && r.cn.length) {
1708 _this.load(r.cn, cret.iter);
1713 getValue : function(iter, col) {
1714 var gval = ''+ this.el.get_value(iter, col).value.get_string();
1719 xtype: Gtk.TreeViewColumn,
1720 pack : "append_column",
1722 XObject.prototype.init.call(this);
1723 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1727 xtype: Gtk.CellRendererText,
1747 pack : "pack_start,false,true,0",
1754 button_press_event : function (self, event) {
1755 this.get('/MidPropTree.model').showData('props');
1767 stock : Gtk.STOCK_ADD,
1768 icon_size : Gtk.IconSize.MENU
1782 button_press_event : function (self, event) {
1784 if (!this.get('/Editor').save()) {
1785 // popup!! - click handled..
1788 this.get('/MidPropTree.model').showData('events');
1801 stock : Gtk.STOCK_ADD,
1802 icon_size : Gtk.IconSize.MENU
1816 button_press_event : function (self, ev) {
1818 if (!this.get('/Editor').save()) {
1819 // popup!! - click handled..
1823 var p = this.get('/AddPropertyPopup');
1827 p.el.set_screen(Gdk.Screen.get_default());
1829 p.el.popup(null, null, null, null, 3, ev.button.time);
1842 stock : Gtk.STOCK_ADD,
1843 icon_size : Gtk.IconSize.MENU
1855 id : "AddPropertyPopup",
1858 xtype: Gtk.MenuItem,
1860 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1863 activate : function (self) {
1865 this.get('/LeftPanel.model').add( {
1876 xtype: Gtk.MenuItem,
1878 tooltip_markup : "Add what type of packing is to be used",
1881 activate : function (self) {
1883 this.get('/LeftPanel.model').add( {
1893 xtype: Gtk.MenuItem,
1895 tooltip_markup : "Override the init method",
1898 activate : function (self) {
1900 this.get('/LeftPanel.model').add( {
1903 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1910 xtype: Gtk.SeparatorMenuItem,
1914 xtype: Gtk.MenuItem,
1916 tooltip_markup : "Add a user defined string property",
1919 activate : function (self) {
1921 this.get('/LeftPanel.model').add( {
1931 xtype: Gtk.MenuItem,
1933 tooltip_markup : "Add a user defined number property",
1936 activate : function (self) {
1938 this.get('/LeftPanel.model').add( {
1948 xtype: Gtk.MenuItem,
1950 tooltip_markup : "Add a user defined boolean property",
1953 activate : function (self) {
1955 this.get('/LeftPanel.model').add( {
1965 xtype: Gtk.SeparatorMenuItem,
1969 xtype: Gtk.MenuItem,
1971 tooltip_markup : "Add a user function boolean property",
1974 activate : function (self) {
1976 this.get('/LeftPanel.model').add( {
1979 val : "function() {\n \n}\n",
1992 xtype: Gtk.ScrolledWindow,
1997 XObject.prototype.init.call(this);
1998 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2000 shadow_type : Gtk.ShadowType.IN,
2003 xtype: Gtk.TreeView,
2005 button_press_event : function (self, ev) {
2008 if (!this.get('/Editor').save()) {
2009 // popup!! - click handled..
2014 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
2015 return false; //not on a element.
2019 if (ev.button.button == 3) {
2021 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
2024 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
2025 var p = this.get('/LeftPanelPopup');
2030 p.el.set_screen(Gdk.Screen.get_default());
2032 p.el.popup(null, null, null, null, 3, ev.button.time);
2033 //Seed.print("click:" + res.column.title);
2040 if (res.column.title != 'value') {
2041 // XObject.error("column is not value?");
2042 return false; // ignore.. - key click.. ??? should we do this??
2045 // currently editing???
2046 // if ( this.activePath) {
2048 // this.activePath = false;
2050 if (this.get('/Editor').dirty) {
2051 //if (!this.get('/Editor.buffer').checkSyntax()) {
2052 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2056 if (!this.get('/Editor.view').save()) {
2060 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2061 this.get('/LeftPanel').editing = false;
2063 // XObject.error("Currently editing?");
2067 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2069 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2071 // get options for this type -- this is to support option lists etc..
2072 var provider = this.get('/LeftTree').getPaleteProvider();
2073 var opts = provider.findOptions(type);
2075 if (opts === false) {
2077 this.get('/LeftPanel').editableColumn.setOptions([]);
2078 renderer.has_entry = true;
2080 this.get('/LeftPanel').editableColumn.setOptions(opts);
2081 renderer.has_entry = false;
2083 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2085 //Seed.print("click" + ev.type);
2086 //console.dump(res);
2095 enable_tree_lines : true,
2096 headers_visible : false,
2098 XObject.prototype.init.call(this);
2100 this.selection = this.el.get_selection();
2101 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2104 var description = new Pango.FontDescription.c_new();
2105 description.set_size(8000);
2106 this.el.modify_font(description);
2110 xtype: Gtk.TreeStore,
2114 add : function(info) {
2115 // info includes key, val, skel, etype..
2117 type = info.type.toLowerCase();
2118 var data = this.toJS();
2120 if (info.etype == 'events') {
2121 data.listeners = data.listeners || { };
2122 if (typeof(data.listeners[info.key]) != 'undefined') {
2123 return; //already set!
2126 if (typeof(data[info.key]) != 'undefined') {
2131 if (typeof(info.val) == 'undefined') {
2134 if (info.type.toLowerCase() == 'boolean') {
2137 if (type == 'number') {
2145 if (info.etype == 'events') {
2147 data.listeners[info.key] = info.val;
2150 data[info.key] = info.val;
2154 var map = this.load(data);
2156 // flag it as changed to the interface..
2157 this.get('/LeftTree.model').setFromNode(false,node);
2158 this.get('/LeftTree.model').changed(true);
2161 this.startEditing(map[k]);
2164 LeftPanel.get('view').el.row_activated(
2165 new Gtk.TreePath.from_string(map[k]),
2166 LeftPanel.editableColumn.el
2170 changed : function(str, doRefresh) {
2171 if (!this.activePath) {
2172 print("NO active path when changed")
2176 this.el.get_iter(ret, new Gtk.TreePath.from_string(this.activePath));
2178 this.el.set_value(ret.iter, 1, '' +str);
2179 this.el.set_value(ret.iter, 3, '' + this.toShort(str));
2180 var type = this.getIterValue(ret.iter, 4);
2182 this.el.set_value(ret.iter, 5, type + ' : ' + str);
2183 // update the tree...
2184 print("new data: " + JSON.stringify(this.toJS() , null,4));
2185 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2186 this.get('/LeftTree.model').changed(doRefresh);
2189 deleteSelected : function() {
2190 var data = this.toJS();
2192 var s = this.get('/LeftPanel.view').selection;
2193 s.get_selected( ret);
2196 var val = this.get('/LeftPanel.model').el.get_value(ret.iter, 0).value.get_string();
2198 if (val[0] == '!') {
2200 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2203 delete data.listeners[ val.substring(1)];
2204 if (!XObject.keys(data.listeners).length) {
2205 delete data.listeners;
2209 if (typeof(data[val]) == 'undefined') {
2219 this.get('/LeftTree.model').setFromNode(false,this.toJS());
2220 this.get('/LeftTree.model').changed(true);
2224 getIterValue : function(iter, col) {
2225 var gval = '' + this.get('/LeftPanel.model').el.get_value(iter, col).value.get_string();
2228 getType : function(treepath) {
2229 return this.getValue(treepath, 4);
2231 getValue : function(treepath_str, col)
2233 // get's the value in a row.. - keys - returns string, values - formats it..
2235 this.el.get_iter(ret, new Gtk.TreePath.from_string(treepath_str));
2237 var val = '' + this.get('/LeftPanel.model').el.get_value(ret.iter, col).value.get_string();
2242 var type = this.getType(this.el.get_path(ret.iter).to_string());
2243 //print("TYPE: " +type + " - val:" + val);
2244 switch(type.toLowerCase()) {
2248 return parseFloat(val); // Nan ?? invalid!!?
2251 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2253 return val == 'true' ? true : false;
2255 var nv = parseFloat(val);
2256 if (!isNaN(nv) && (val == ''+nv)) {
2264 XObject.prototype.init.call(this);
2265 this.el.set_column_types ( 6, [
2266 GObject.TYPE_STRING, // 0 real key
2267 GObject.TYPE_STRING, // 1 real value
2268 GObject.TYPE_STRING, // 2 visable key
2269 GObject.TYPE_STRING, // 3 visable value
2270 GObject.TYPE_STRING, // 4 need to store type of!!!
2271 GObject.TYPE_STRING // 5 tooltip
2275 load : function(ar) {
2276 // might casue problesm..
2277 // this.get('/Editor.RightEditor').save();
2279 this.get('/Editor').el.hide();
2280 this.get('/Editor').activePath = false;
2285 //this.get('/RightEditor').el.hide();
2292 var provider = this.get('/LeftTree').getPaleteProvider();
2296 var keys = XObject.keys(ar);
2298 ar.listeners = ar.listeners || {};
2300 for (var i in ar.listeners ) {
2302 this.el.append(iret);
2303 var p = this.el.get_path(iret.iter).to_string();
2306 this.el.set_value(iret.iter, 0, '!'+ i );
2307 this.el.set_value(iret.iter, 1, '' + ar.listeners[i]);
2308 this.el.set_value(iret.iter, 2, '<b>'+ i + '</b>');
2310 this.el.set_value(iret.iter, 3, '' + this.toShort(ar.listeners[i]));
2311 this.el.set_value(iret.iter, 4, 'function');
2312 this.el.set_value(iret.iter, 5, i + ' : ' + ar.listeners[i]);
2318 keys.forEach(function(i) {
2319 if (typeof(ar[i]) == 'object') {
2323 var type = provider.findType(ar, i, ar[i]);
2325 _this.el.append(iret);
2326 var p = _this.el.get_path(iret.iter).to_string();
2328 _this.el.set_value(iret.iter, 0, ''+i);
2329 _this.el.set_value(iret.iter, 1, '' + ar[i]);
2330 _this.el.set_value(iret.iter, 2, ''+i);
2331 _this.el.set_value(iret.iter, 3, ''+ _this.toShort(ar[i]));
2332 _this.el.set_value(iret.iter, 4, ''+type);
2333 _this.el.set_value(iret.iter, 5, type + ' : ' + ar[i]);
2337 startEditing : function(path,col) {
2339 // alled by menu 'edit' currently..
2341 * start editing path (or selected if not set..)
2342 * @param {String|false} path (optional) treepath to edit - selected tree gets
2343 * edited by default.
2344 * @param {Number} 0 or 1 (optional)- column to edit.
2346 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2348 if (typeof(path) == 'string') {
2349 tp = new Gtk.TreePath.from_string(path);
2352 var s = this.get('/LeftPanel.view').selection;
2353 s.get_selected( itr);
2354 tp = this.el.get_path(itr.iter);
2355 path = tp.to_string();
2359 // which colum is to be edited..
2362 // not sure what this does..
2364 if (typeof(col) == 'undefined') {
2365 var k = this.getValue(path, 0);
2367 colObj = (!k.length || k == '|') ?
2368 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2370 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2373 // make sure the pulldown is set correctly..
2374 // not really needed for second col...
2375 var showEditor = false;
2376 this.get('/Editor').activePath = false;
2377 this.get('/Editor').el.hide();
2380 var provider = this.get('/LeftTree').getPaleteProvider();
2381 var type = this.get('/LeftPanel.model').getType(path);
2382 var opts = provider.findOptions(type);
2383 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2385 if (opts === false) {
2386 this.get('/LeftPanel').editableColumn.setOptions([]);
2387 renderer.has_entry = true;
2389 this.get('/LeftPanel').editableColumn.setOptions(opts);
2390 renderer.has_entry = false;/// - pulldowns do not have entries
2392 // determine if we should use the Text editor...
2393 var keyname = this.getValue(path, 0);
2394 var data_value = this.getValue(path, 1);
2396 if ((keyname[0] == '|') ||
2398 (typeof(data_value) == 'string' ) &&
2399 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2403 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2408 // this.get('/BottomPane').el.hide();
2409 //this.get('/RightEditor').el.hide();
2414 this.activePath = false;
2416 _this.get('/Editor').el.show_all();
2417 GLib.timeout_add(0, 1, function() {
2419 //_this.get('/BottomPane').el.show();
2420 //_this.get('/RightEditor').el.show();
2422 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2424 _this.get('/Editor').activePath = path;
2425 _this.activePath = path ;
2435 // iter now has row...
2436 GLib.timeout_add(0, 100, function() {
2437 _this.activePath = path;
2438 colObj.items[0].el.editable = true; // esp. need for col 0..
2439 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2450 this.get('/LeftPanel.model').el.get_iter_first(iret);
2456 var k = this.getValue(this.el.get_path(iret.iter).to_string(), 0);
2459 ar.listeners = ar.listeners || {};
2460 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2463 ar[ k ] = this.getValue(this.el.get_path(iret.iter).to_string(), 1);
2466 if (! this.get('/LeftPanel.model').el.iter_next(iret.iter)) {
2472 //print(JSON.stringify(ar));
2476 toShort : function(str) {
2477 var a = typeof(str) == 'string' ? str.split("\n") : [];
2478 return a.length > 1 ? a[0] + '....' : '' + str;
2482 xtype: Gtk.TreeViewColumn,
2483 pack : "append_column",
2485 XObject.prototype.init.call(this);
2487 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2488 this.get('/LeftPanel').propertyColumn = this;
2493 xtype: Gtk.CellRendererText,
2494 pack : "pack_start",
2496 editing_started : function (self, editable, path) {
2498 this.get('/LeftPanel.model').activePath = path;
2501 edited : function (self, object, p0) {
2503 //print("CHANGED VALUE:" + JSON.stringify(p0, null,4));
2505 var model = this.get('/LeftPanel.model');
2506 var path = model.activePath;
2508 model.el.get_iter(iret, new Gtk.TreePath.from_string(path));
2509 model.el.set_value(iret.iter, 0, p0);
2510 model.el.set_value(iret.iter, 2, p0);
2512 model.activePath = false;
2513 this.get('/LeftTree.model').setFromNode(false,model.toJS());
2514 this.get('/LeftTree.model').changed(true);
2516 this.el.editable = false;
2523 xtype: Gtk.TreeViewColumn,
2524 pack : "append_column",
2527 XObject.prototype.init.call(this);
2528 this.el.add_attribute(this.items[0].el , 'text', 3 );
2529 //this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2530 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2531 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2533 this.get('/LeftPanel').editableColumn= this;
2535 setOptions : function(ar) {
2536 var m = this.items[0].el.model;
2539 ar.forEach(function(i) {
2543 m.set_value(iret.iter, 0, i);
2549 xtype: Gtk.CellRendererCombo,
2551 edited : function (self, object, p0) {
2553 this.get('/LeftPanel').editing = false;
2554 var ap = this.get('/LeftPanel.model').activePath
2555 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2556 this.get('/LeftPanel.model').changed(p0, true);
2557 this.get('/LeftPanel.model').activePath = false;
2558 this.el.editable = false;
2560 editing_started : function (self, editable, path) {
2561 this.get('/LeftPanel').editing = true;
2562 // console.log('editing started');
2563 // r.has_entry = false;
2565 this.el.editable = false; // make sure it's not editor...
2570 pack : "pack_start",
2574 XObject.prototype.init.call(this);
2575 this.el.model = new Gtk.ListStore();
2576 this.el.model.set_column_types ( 1, [
2577 GObject.TYPE_STRING // 0 real key
2588 id : "LeftPanelPopup",
2591 xtype: Gtk.MenuItem,
2595 activate : function (self) {
2596 this.get('/LeftPanel.model').deleteSelected();
2601 xtype: Gtk.MenuItem,
2605 activate : function (self) {
2606 this.get('/LeftPanel.model').startEditing(false, 0);
2619 xtype: Gtk.ScrolledWindow,
2620 pack : "pack_end,false,true,0",
2623 shadow_type : Gtk.ShadowType.IN,
2625 XObject.prototype.init.call(this);
2626 XObject.prototype.init.call(this);
2627 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2628 this.el.set_size_request ( 150, -1 );
2631 activeElement : false,
2632 hideWin : function() {
2635 print("HIDEWIN - currently not shown")
2640 if (this.get('/Window.left').el.position < 160) {
2641 print("HIDEWIN - small already.")
2645 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2646 print("HIDEWIN attempting to hide.")
2653 xtype: Gtk.TreeView,
2655 cursor_changed : function (self) {
2658 //console.log('changed');
2659 var m = this.get('model');
2660 if (!this.selection){
2661 this.selection = this.el.get_selection();
2664 var s = this.selection;
2665 if (!s.get_selected(iret)) {
2668 var tp = m.el.get_path(iret.iter).to_string();
2673 var key = m.getValue(tp, 0);
2675 var type = m.getValue(tp, 1);
2676 var skel = m.getValue(tp, 3);
2677 var etype = m.getValue(tp, 5);
2680 this.get('/MidPropTree').hideWin();
2682 if (type.toLowerCase() == 'function') {
2684 if (etype != 'events') {
2688 this.get('/LeftPanel.model').add({
2696 // has dot in name, and is boolean???? this does not make sense..
2697 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2701 this.get('/LeftPanel.model').add( {
2711 enable_tree_lines : true,
2712 headers_visible : false,
2714 XObject.prototype.init.call(this);
2716 var description = new Pango.FontDescription.c_new();
2717 description.set_size(8000);
2718 this.el.modify_font(description);
2720 //this.selection = this.el.get_selection();
2721 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2730 xtype: Gtk.ListStore,
2733 getValue : function(treepath, col)
2735 var tp = new Gtk.TreePath.from_string (treepath);
2737 this.el.get_iter (iret, tp);
2738 var value = this.el.get_value(iret.iter, col);
2739 return ''+ value.value.get_string();
2743 XObject.prototype.init.call(this);
2744 this.el.set_column_types ( 6, [
2745 GObject.TYPE_STRING, // real key
2746 GObject.TYPE_STRING, // real type
2747 GObject.TYPE_STRING, // docs ?
2748 GObject.TYPE_STRING, // visable desc
2749 GObject.TYPE_STRING, // function desc
2750 GObject.TYPE_STRING // element type (event|prop)
2754 showData : function(type) {
2756 if (!this.get('/MidPropTree').activeElement || !type) {
2757 return; // no active element
2760 var fullpath = this.get('/LeftTree.model').file.guessName(
2761 this.get('/MidPropTree').activeElement);
2762 var palete = this.get('/LeftTree').getPaleteProvider();
2766 Seed.print('Showing right?');
2767 if (!this.get('/MidPropTree').shown) {
2769 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2770 this.get('/MidPropTree').el.show();
2771 this.get('/MidPropTree').shown = true;
2774 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2775 return a.name > b.name ? 1 : -1;
2777 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2778 // console.dump(elementList);
2782 for(var i =0 ; i < elementList.length; i++) {
2784 var p=elementList[i];
2785 this.el.append(iret);
2786 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2787 //GObject.TYPE_STRING, // real key
2788 // GObject.TYPE_STRING, // real type
2789 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2790 // GObject.TYPE_STRING // func def?
2793 this.el.set_value(iret.iter, 0, p.name);
2794 this.el.set_value(iret.iter, 1, p.type);
2795 this.el.set_value(iret.iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2796 this.el.set_value(iret.iter, 3, p.sig ? p.sig : '');
2797 this.el.set_value(iret.iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2798 this.el.set_value(iret.iter, 5, type);
2805 xtype: Gtk.TreeViewColumn,
2808 this.el = new Gtk.TreeViewColumn();
2809 this.parent.el.append_column(this.el);
2811 XObject.prototype.init.call(this);
2812 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2816 xtype: Gtk.CellRendererText,
2817 pack : "pack_start,true"
2844 xtype: Gtk.Notebook,
2845 pack : "pack_start,true,true",
2846 id : "view-help-nb",
2848 XObject.prototype.init.call(this);
2849 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2850 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2854 xtype: Gtk.Notebook,
2855 id : "view-notebook",
2859 XObject.prototype.init.call(this);
2860 this.el.set_current_page(0);
2861 //print("SET LABEL?")
2862 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2863 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2869 id : "RightBrowser",
2874 pack : "pack_start,false,true,0",
2879 clicked : function (self) {
2880 this.get('/RightBrowser.view').renderJS(null,true);
2884 pack : "pack_start,false,false,0"
2887 xtype: Gtk.CheckButton,
2889 toggled : function (self, state) {
2890 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2895 label : "Auto Redraw On",
2896 pack : "pack_start,false,false,0"
2901 clicked : function (self) {
2902 this.get('/RightBrowser.view').redraws = 99;
2903 this.get('/RightBrowser.view').renderJS(null,true);
2906 label : "Full Redraw",
2907 pack : "pack_start,false,false,0"
2912 xtype: Gtk.ScrolledWindow,
2915 XObject.prototype.init.call(this);
2916 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2918 shadow_type : Gtk.ShadowType.IN,
2921 xtype: WebKit.WebView,
2923 load_finished : function (self, object) {
2924 print("load finished");
2925 // print("load_finished"); return;
2926 // if (this.ready) { // dont do it twice!
2929 if (!this.inspectorShown) {
2930 this.el.get_inspector().show();
2931 this.inspectorShown = true;
2936 //if (this.pendingRedraw) {
2937 // this.pendingRedraw = false;
2938 // this.refreshRequired = true;
2940 //var js = this.get('/LeftTree.model').toJS();
2941 //if (js && js[0]) {
2942 // this.renderJS(js[0]);
2946 script_alert : function (self, object, p0) {
2949 return true; // do not display anything...
2951 console_message : function (self, object, p0, p1) {
2953 // console.log(object);
2956 if (object.match(/variable/) && object.match(/Builder/)) {
2957 print("got builder missing message");
2958 this.refreshRequired = true;
2959 this.lastRedraw = 0;
2965 if (!object.match(/^\{/)) {
2967 //this.get('/Terminal').feed(object);
2968 return true; // do not handle!!! -> later maybe in console..
2974 // console.log(object);
2975 var val = JSON.parse(object);
2977 if (typeof(val['hover-node']) != 'undefined') {
2978 this.activeNode = val['hover-node'];
2979 console.log('active node: ' + this.activeNode);
2984 if (typeof(val['id']) != 'undefined') {
2985 // this.activeNode = val['id'];
2986 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2987 if (!tg || typeof(tg[0]) == 'undefined') {
2990 print("SELECT node " + tg[0]);
2992 this.get('/LeftTree.view').selectNode(tg[0]);
2996 if (ret && typeof(val['set']) != 'undefined') {
2997 this.get('/LeftPanel.model').add({
3001 //console.log('active node: ' + this.activeNode);
3004 //Seed.print('a:'+a);
3005 //Seed.print('b:'+b);
3006 //Seed.print('c:'+c);
3009 drag_motion : function (w, ctx, x, y, time, ud) {
3010 // console.log('DRAG MOTION');
3012 // if lastCurrentNode == this.currentNode.. -- don't change anything..
3013 this.targetData = [];
3014 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
3016 // A) find out from drag all the places that node could be dropped.
3017 var src = Gtk.drag_get_source_widget(ctx);
3018 if (!src.dropList) {
3019 Gdk.drag_status(ctx,0, time);
3022 // b) get what we are over.. (from activeNode)
3023 // tree is empty.. - list should be correct..
3024 if (!this.get('/LeftTree.model').currentTree) {
3025 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3029 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3031 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
3034 Gdk.drag_status(ctx, 0,time);
3035 this.get('/LeftTree.view').highlight(false);
3039 // if we have a target..
3040 // -> highlight it! (in browser)
3041 // -> highlight it! (in tree)
3043 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3044 this.get('/LeftTree.view').highlight(tg);
3045 this.targetData = tg;
3046 // for tree we should handle this...
3049 drag_drop : function (w, ctx, x, y,time, ud) {
3050 print("TARGET: drag-drop");
3051 var is_valid_drop_site = true;
3055 ( /* will receive 'drag-data-received' signal */
3056 ctx, /* represents the current state of the DnD */
3057 this.get('/Window').atoms["STRING"], /* the target type we want */
3058 time /* time stamp */
3062 /* No target offered by source => error */
3065 return is_valid_drop_site;
3067 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3069 print("Browser: drag-data-received");
3070 var delete_selection_data = false;
3071 vardnd_success = false;
3072 /* Deal with what we are given from source */
3073 if( sel_data && sel_data.length ) {
3075 if (ctx.action == Gdk.DragAction.ASK) {
3076 /* Ask the user to move or copy, then set the ctx action. */
3079 if (ctx.action == Gdk.DragAction.MOVE) {
3080 delete_selection_data = true;
3082 var source = Gtk.drag_get_source_widget(ctx);
3084 print("Browser: source.DRAGDATA? " + source.dragData);
3085 if (this.targetData) {
3086 print(this.targetData);
3087 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3096 if (dnd_success == false)
3098 Seed.print ("DnD data transfer failed!\n");
3101 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3104 create_web_view : function (self, object) {
3105 print("CREATE WEB VIEW");
3106 return null; //new WebKit.WebView();
3113 XObject.prototype.init.call(this);
3114 // this may not work!?
3115 var settings = this.el.get_settings();
3116 settings.enable_developer_extras = true;
3118 // this was an attempt to change the url perms.. did not work..
3119 // settings.enable_file_access_from_file_uris = true;
3120 // settings.enable_offline_web_application_cache - true;
3121 // settings.enable_universal_access_from_file_uris = true;
3125 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3126 _this.get('/BottomPane.inspector').el.show();
3127 return _this.get('/BottomPane.inspector').el;
3131 // FIXME - base url of script..
3132 // we need it so some of the database features work.
3133 this.el.load_html_string( "Render not ready" ,
3134 //fixme - should be a config option!
3135 // or should we catch stuff and fix it up..
3136 'http://localhost/app.Builder/'
3140 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3142 this.el.drag_dest_set
3143 ( /* widget that will accept a drop */
3144 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3145 null, /* lists of target to support */
3146 0, /* size of list */
3147 Gdk.DragAction.COPY /* what to do with data after dropped */
3150 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3151 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3153 GLib.timeout_add_seconds(0, 1, function() {
3154 // print("run refresh?");
3161 renderJS : function(data, force) {
3163 // this is the public redraw call..
3164 // we refresh in a loop privately..
3165 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3166 if (!autodraw && !force) {
3167 print("Skipping redraw - no force, and autodraw off");
3170 this.refreshRequired = true;
3172 runRefresh : function()
3174 // this is run every 2 seconds from the init..
3178 if (!this.refreshRequired) {
3179 print("no refresh required");
3183 if (this.lastRedraw) {
3184 // do not redraw if last redraw was less that 5 seconds ago.
3185 if (((new Date()) - this.lastRedraw) < 5000) {
3193 if (!this.get('/Window.LeftTree').getActiveFile()) {
3196 this.refreshRequired = false;
3197 // print("HTML RENDERING");
3199 this.get('/BottomPane').el.show();
3200 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3207 var js = this.get('/LeftTree.model').toJS();
3208 if (!js || !js.length) {
3217 var project = this.get('/Window.LeftTree').getActiveFile().project;
3218 //print (project.fn);
3219 // set it to non-empty.
3220 project.runhtml = project.runhtml || '';
3221 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3224 this.runhtml = this.runhtml || '';
3226 var file = this.get('/LeftTree.model').file;
3227 var items = file.items;
3228 file.items = this.get('/LeftTree.model').toJS(false, false);
3229 file.items[0].background = false;
3230 var p = file.parent;
3231 file.parent = false;
3233 var js_src = file.toSource();
3234 if (this.renderedData && js_src == this.renderedData && project.runhtml == this.runhtml) {
3235 // unless it' sforced..
3240 this.renderedData = js_src;
3244 print("send source as " + js_src);
3247 "Roo.onReady(function( {" +
3248 "if (" + file.name +".show) " + file.name +".show({});\n" +
3249 "Roo.XComponent.build();\n" +
3256 //if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3257 // then we need to reload the browser using
3258 // load_html_string..
3260 // then trigger a redraw once it's loaded..
3261 this.pendingRedraw = true;
3262 var runhtml = '<script type="text/javascript">' + "\n" ;
3263 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3264 runhtml += '</script>'+ "\n" ;
3266 this.runhtml = project.runhtml;
3267 // need to modify paths
3270 this.lastRedraw= new Date();
3271 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3272 html = html.replace('</head>',
3275 '<script type="text/javascript">' + "\n" +
3280 print("LOAD HTML " + html);
3281 this.el.load_html_string( html ,
3282 //fixme - should be a config option!
3283 'http://localhost/app.Builder/'
3286 // should trigger load_finished! - which in truns shoudl set refresh Required;
3291 //this.renderedData = data;
3292 //var str = JSON.stringify(data) ;
3295 console.log('not loaded yet');
3297 this.lastRedraw = new Date();
3299 this.el.execute_script("Builder.render(" +
3300 JSON.stringify(js_src) +
3302 JSON.stringify(file.name) +
3305 print( "before render" + this.lastRedraw);
3306 print( "after render" + (new Date()));
3316 id : "RightGtkView",
3318 redraw : function() {
3319 this.highlightWidget = false;
3320 print("REDRAW CALLED");
3321 this.activePath = this.get('/LeftTree').getActivePath();
3322 if (this.renderedEl) {
3323 print("QUEUE DRAW CALLING");
3324 this.renderedEl.queue_draw();
3327 renderJS : function(data, withDebug)
3329 this.highlightWidget = false;
3331 this.withDebug = false;
3332 while (this.get('view').el.get_children().length) {
3333 var c = this.get('view').el.get_children()[0];
3334 this.get('view').el.remove(c);
3341 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3342 // in theory tree is actually window..
3345 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3351 this.get('view').el.set_size_request(
3352 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3354 if (this.renderedEl) {
3355 this.renderedEl.set_size_request(
3356 tree.default_width || 600,
3357 tree.default_height || 400
3360 this.get('view').el.show_all();
3365 showInWindow : function() {
3366 print("GET PROEJCT");
3367 var pr = this.get('/LeftProjectTree').getActiveProject();
3369 console.log(pr.paths);
3372 var src= this.buildJS(
3373 this.get('/LeftTree.model').toJS()[0],
3378 //var x = new imports.sandbox.Context();
3382 Seed.check_syntax('var e = ' + src);
3385 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3386 this.get('/Terminal').feed(console._dump(e)+"\n");
3388 var lines = src.split("\n");
3389 var start = Math.max(0, e.line - 10);
3390 var end = Math.min(lines.length, e.line + 10);
3391 for (var i =start ; i < end; i++) {
3393 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3396 this.get('/Terminal').feed(lines[i] + "\n");
3403 this.get('/BottomPane').el.set_current_page(1);
3404 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3405 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3406 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3408 var _top = x.get_global_object()._top;
3410 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3412 if (_top.el.popup) {
3413 _top.el.popup(null, null, null, null, 3, null);
3417 viewAdd : function(item, par)
3420 // does something similar to xobject..
3421 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3423 // pack is forced to 'false'
3424 if (item.pack===false || item.pack === 'false') { // no ;
3428 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3431 var type = item['|xns'] + '.' + item['xtype'];
3433 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3437 var ns = imports.gi[item['|xns']];
3438 var ctr = ns[item['xtype']]; // why are we using array here..?
3443 for(var k in item) {
3445 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3459 // value is a function..
3460 if (k[0] == '|' && typeof(kv) == 'string') {
3462 if (kv.match(new RegExp('function'))) {
3465 print("WASL " + k + '=' + kv);
3467 eval( 'kv = ' + kv);
3468 } catch(e) { continue; }
3471 // print(k + '=' + kv);
3473 if (k[0] == '|') { // should be boolean or number..
3475 //print(k + '=' + kv);
3478 if (k == 'show_tabs') { // force tab showing for notebooks.
3481 print(k + '=' + typeof(kv) + " : " + kv);
3485 var altctr = XObject.baseXObject({ xtype: ctr} );
3487 if (!item.pack && altctr) {
3489 print("SETTING PACK TO XObjectBase method");
3490 pack_m = altctr.prototype.pack;
3495 var el = new ctr(ctr_args);
3497 print("PACK" + item.pack);
3498 //console.dump(item.pack);
3505 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3506 if (typeof(item.pack) == 'string') {
3508 item.pack.split(',').forEach(function(e, i) {
3510 if (e == 'false') { args.push( false); return; }
3511 if (e == 'true') { args.push( true); return; }
3512 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3515 //print(args.join(","));
3517 pack_m = args.shift();
3519 pack_m = item.pack.shift();
3524 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3526 name: "ArgumentError",
3527 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3528 "ADDING : " + item.id + " " + el
3537 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3538 //Seed.print('args: ' + args.length);
3539 if (typeof(pack_m) == 'string') {
3540 par[pack_m].apply(par, args);
3541 } else if (pack_m) {
3542 pack_m.call(item, par, item);
3546 item.items = item.items || [];
3547 item.items.forEach(function(ch,n) {
3549 print ("type:" + type);
3551 print ("ch.pack:" + ch.pack);
3554 if (type == 'Gtk.Table' && ch.pack == 'add') {
3555 var c = n % item.n_columns;
3556 var r = Math.floor(n/item.n_columns);
3557 ch.pack = [ 'attach', c, c+1, r, r+1,
3558 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3559 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3560 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3561 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3565 _this.viewAdd(ch, el);
3570 // add the signal handlers.
3571 // is it a widget!?!!?
3577 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3578 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3579 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3580 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3581 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3591 widgetDragDropEvent : function() {
3592 print("WIDGET DRAGDROP");
3595 widgetDragMotionEvent : function() {
3596 print("WIDGET DRAGMOTION");
3599 widgetExposeEvent : function(w, evt, ud, item) {
3601 if (this.inRender) {
3605 if ( this.highlightWidget) {
3606 this.inRender = true;
3607 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3608 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3610 this.inRender = false;
3615 if (this.activePath != item.xtreepath) {
3619 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3620 // work out the coords of the window..
3622 var dr = widget.window;
3623 this.gc = (new Gdk.GC.c_new(dr));
3624 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3625 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3629 var r = evt.expose.area;
3630 // console.dump([r.x, r.y, r.width, r.height ] );
3632 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3633 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3634 // happens with gtkscrollview embedded stuff..
3635 var np =this.activePath.split(':');
3637 this.activePath = np.join(':');
3638 this.renderedEl.queue_draw();
3654 this.inRender = true;
3657 this.highlightWidget = widget;
3662 // print("DRAW BOX");
3663 //console.dump(this.box);
3664 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3665 this.inRender = false;
3668 widgetPressEvent : function(w,e,u,d) {
3669 if (this.get('view').pressed) {
3672 this.get('view').pressed = true;
3673 print("WIDGET PRESS " + d.xtreepath );
3674 this.get('/LeftTree.view').selectNode( d.xtreepath );
3677 widgetReleaseEvent : function() {
3678 this.get('view').pressed = false;
3684 pack : "pack_start,false,true,0",
3688 pack : "pack_start,false,false,0",
3689 label : "Run The Application",
3691 button_press_event : function (self, event) {
3692 // call render on left tree - with special option!?!
3694 //print("GET PROEJCT");
3695 var pr = this.get('/LeftProjectTree').getActiveProject();
3698 for (var i in pr.paths) {
3702 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3703 this.get('/Terminal').feed("RUN DIR:" + dir);
3706 this.get('/Terminal').el.fork_command_full(
3707 Vte.PtyFlags.DEFAULT,
3708 GLib.path_get_dirname (__script_path__) ,
3709 [ 'echo' , "hello"], //argv
3713 null, // child setupdata
3717 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3718 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3728 xtype: Gtk.ScrolledWindow,
3731 shadow_type : Gtk.ShadowType.IN,
3733 XObject.prototype.init.call(this);
3734 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3738 xtype: Gtk.EventBox,
3739 pack : "add_with_viewport",
3741 XObject.prototype.init.call(this);
3742 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3743 red: 0x9F00, green: 0xB800 , blue : 0xA800
3751 XObject.prototype.init.call(this);
3752 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3753 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3758 xtype: Gtk.EventBox,
3761 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3762 XObject.prototype.init.call(this);
3764 this.el.drag_dest_set
3765 ( /* widget that will accept a drop */
3766 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3767 null, /* lists of target to support */
3768 0, /* size of list */
3769 Gdk.DragAction.COPY /* what to do with data after dropped */
3772 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3773 this.el.drag_dest_set_target_list( this.get('/Window').targetList);
3776 getActiveNode : function(x,y)
3778 // workout what node is here..
3779 return '0'; // top..
3783 drag_motion : function (self, ctx, x, y, time) {
3785 // A) find out from drag all the places that node could be dropped.
3786 var src = Gtk.drag_get_source_widget(ctx);
3787 if (!src.dropList) {
3788 Gdk.drag_status(ctx, 0, time);
3791 // b) get what we are over.. (from activeNode)
3792 // tree is empty.. - list should be correct..
3793 if (!this.get('/LeftTree.model').currentTree) {
3794 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3798 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3799 var activeNode = this.getActiveNode(x, y);
3802 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3805 Gdk.drag_status(ctx, 0,time);
3806 this.get('/LeftTree.view').highlight(false);
3810 // if we have a target..
3811 // -> highlight it! (in browser)
3812 // -> highlight it! (in tree)
3814 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3815 this.get('/LeftTree.view').highlight(tg);
3816 this.targetData = tg;
3817 // for tree we should handle this...
3820 drag_drop : function (self,ctx, x, y, time) {
3821 Seed.print("TARGET: drag-drop");
3822 var is_valid_drop_site = true;
3826 ( /* will receive 'drag-data-received' signal */
3827 ctx, /* represents the current state of the this.gDnD */
3828 this.get('/Window').atoms["STRING"], /* the target type we want */
3829 time /* time stamp */
3833 /* No target offered by source => error */
3836 return is_valid_drop_site;
3839 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3841 Seed.print("GtkView: drag-data-received");
3842 var delete_selection_data = false;
3843 var dnd_success = false;
3844 /* Deal with what we are given from source */
3845 if( sel_data && sel_data.length ) {
3847 if (ctx.action == Gdk.DragAction.ASK) {
3848 /* Ask the user to move or copy, then set the ctx action. */
3851 if (ctx.action == Gdk.DragAction.MOVE) {
3852 delete_selection_data = true;
3854 var source = Gtk.drag_get_source_widget( ctx );
3856 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3857 if (this.targetData) {
3858 Seed.print(this.targetData);
3859 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3868 if (dnd_success == false)
3870 Seed.print ("DnD data transfer failed!\n");
3873 Gtk.drag_finish ( ctx, dnd_success, delete_selection_data, time);
3876 button_press_event : function (self, event) {
3877 this.pressed = false;
3893 xtype: Gtk.ScrolledWindow,
3898 var file = this.get('/LeftTree').getActiveFile();
3902 var activeEl = this.get('/LeftTree').getActiveElement();
3903 var xtype = file.guessName( activeEl )
3904 if (!xtype || !xtype.length) {
3907 //this.get('/Window.view-help-nb').el.set_current_page(1);
3909 // get the active element being edited.
3910 var helpurl = file.getHelpUrl(xtype);
3912 // now load the help info in the page..
3913 this.get('help-view').el.open(helpurl);
3917 xtype: WebKit.WebView,
3921 XObject.prototype.init.call(this);
3922 this.get('/Window.help-view').el.open(
3923 "http://devel.akbkhome.com/seed/");
3935 xtype: Gtk.Notebook,
3939 XObject.prototype.init.call(this);
3940 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3941 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3942 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3946 xtype: Gtk.ScrolledWindow,
3950 xtype: Vte.Terminal,
3953 feed : function(istr) {
3954 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3955 // we should make ourselves visable!!!
3956 this.get('/BottomPane').el.show();
3957 this.get('/BottomPane').el.set_current_page(1);
3959 this.el.feed(str ,str.length);
3961 scroll_on_output : true,
3963 XObject.prototype.init.call(this);
3964 this.el.set_size (80, 1000);
3966 scrollback_lines : 1000
3971 xtype: Gtk.ScrolledWindow,
3975 xtype: WebKit.WebView,
3991 this.get('buttonbar').el.show();
3992 this.get('viewbox').el.hide();
3993 var ce = this.get('/Window.centereast').el;
3995 ce.set_position(ce.get_allocated_width() - 30);
3997 print("TRIED TO HIDE");
4000 this.get('buttonbar').el.hide();
4001 this.get('viewbox').el.show();
4002 var ce = this.get('/Window.centereast').el;
4003 print(JSON.stringify(XObject.keys(ce) ,null,4));
4004 ce.set_position(ce.get_allocated_width() - 150);
4006 // this.get('model').expanded();
4018 pack : "pack_start,false,true",
4020 clicked : function (self) {
4021 this.get('/RightPalete').show();
4028 stock : Gtk.STOCK_GOTO_FIRST,
4029 icon_size : Gtk.IconSize.MENU
4039 XObject.prototype.init.call(this);
4040 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
4043 enter_notify_event : function (self, event) {
4044 this.get('/RightPalete').show();
4058 pack : "pack_start,false,true",
4067 pack : "pack_start,false,true",
4069 clicked : function (self) {
4070 this.get('/RightPalete').hide();
4077 stock : Gtk.STOCK_GOTO_LAST,
4078 icon_size : Gtk.IconSize.MENU
4085 xtype: Gtk.ScrolledWindow,
4088 XObject.prototype.init.call(this);
4089 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
4090 this.el.set_size_request(-1,200);
4092 shadow_type : Gtk.ShadowType.IN,
4095 xtype: Gtk.TreeView,
4097 drag_begin : function (self, ctx) {
4098 // we could fill this in now...
4099 Seed.print('SOURCE: drag-begin');
4104 var s = this.selection;
4105 s.get_selected(iret);
4106 var path = this.get('/RightPalete.model').el.get_path(iret.iter);
4108 var pix = this.el.create_row_drag_icon ( path);
4111 if (Gtk.drag_set_icon_surface) {
4112 Gtk.drag_set_icon_surface( ctx, pix );
4114 Gtk.drag_set_icon_pixmap (ctx,
4115 pix.get_colormap(), pix, null, -10, -10);
4118 var value = ''+ this.get('/RightPalete.model').el.get_value(iret.iter, 0).value.get_string();
4119 if (!this.get('/RightPalete').provider) {
4122 this.el.dropList = this.get('/RightPalete').provider.getDropList(value);
4123 this.el.dragData = value;
4130 drag_data_get : function (self, drag_context, selection_data, info, time) {
4131 //Seed.print('Palete: drag-data-get: ' + target_type);
4132 if (this.el.dragData && this.el.dragData.length ) {
4133 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4137 //this.el.dragData = "TEST from source widget";
4141 drag_end : function (self, drag_context) {
4142 Seed.print('SOURCE: drag-end');
4143 this.el.dragData = false;
4144 this.el.dropList = false;
4145 this.get('/LeftTree.view').highlight(false);
4148 button_press_event : function (self, event) {
4150 if (!this.get('/Editor').save()) {
4151 // popup!! - click handled..
4158 enable_tree_lines : true,
4159 headers_visible : false,
4161 XObject.prototype.init.call(this);
4162 this.el.set_size_request(150,-1);
4163 // set_reorderable: [1]
4165 var description = new Pango.FontDescription.c_new();
4166 description.set_size(8000);
4167 this.el.modify_font(description);
4169 this.selection = this.el.get_selection();
4170 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4171 // this.selection.signal['changed'].connect(function() {
4172 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4174 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4176 this.el.drag_source_set ( /* widget will be drag-able */
4177 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4178 null, /* lists of target to support */
4179 0, /* size of list */
4180 Gdk.DragAction.COPY /* what to do with data after dropped */
4182 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4184 this.el.drag_source_set_target_list( this.get('/Window').targetList);
4185 this.el.drag_source_add_text_targets( );
4187 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4188 targets = new Gtk.TargetList();
4189 targets.add( LeftTree.atoms["STRING"], 0, 0);
4190 targets.add_text_targets( 1 );
4191 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4193 //if you want to allow text to be output elsewhere..
4194 //Gtk.drag_source_add_text_targets(this.el);
4200 xtype: Gtk.ListStore,
4203 XObject.prototype.init.call(this);
4204 this.el.set_column_types ( 2, [
4205 GObject.TYPE_STRING, // title
4206 GObject.TYPE_STRING // tip
4211 load : function(tr,iter)
4216 //console.log('Project tree load: ' + tr.length);
4218 //this.insert(citer,iter,0);
4219 for(var i =0 ; i < tr.length; i++) {
4222 this.el.append(cret);
4224 this.el.insert(cret,iter,-1);
4229 this.el.set_value(cret.iter, 0, '' + r ); // title
4231 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4232 //if (r.cn && r.cn.length) {
4233 // this.load(r.cn, citer);
4239 getValue : function (iter, col) {
4240 return this.el.get_value(iter, col).value.get_string();
4247 xtype: Gtk.TreeViewColumn,
4248 pack : "append_column",
4250 XObject.prototype.init.call(this);
4251 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4255 xtype: Gtk.CellRendererText,
4277 XObject.cache['/Window'] = Window;