3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 GtkClutter = imports.gi.GtkClutter;
12 console = imports.console;
13 XObject = imports.XObject.XObject;
17 delete_event : function (self, event) {
20 destroy : function (self) {
23 show : function (self) {
24 print("WINDOW SHOWING - trying to hide");
25 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
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.Builder.Provider.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.Builder.Provider.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.Builder.Provider.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( null , [], [], target
281 , false,false,false);
282 var cmd = "firefox file://" + target + "/builder.html \n";
283 this.get('/Terminal').el.feed_child(cmd, cmd.length);
287 label : "_Test in Firefox (Roo)",
298 use_underline : true,
303 pack : "set_submenu",
309 use_underline : true,
311 activate : function (self) {
312 this.get('/About').el.run();
342 activate : function (self) {
343 // this does not actually expand it..
344 // that is done by GTK..
347 if (!this.get('/Editor').save()) {
348 // popup!! - click handled..
352 if (!this.el.expanded) {
359 enter_notify_event : function (self, event) {
361 this.el.expanded = !this.el.expanded;
362 //if (this.el.expanded ) {
363 this.listeners.activate.call(this);
370 label : "Select Project or File",
371 pack : "pack_start,false,true",
373 XObject.prototype.init.call(this);
374 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
376 onCollapse : function() {
378 var nb = this.get('/LeftTopPanel.notebook');
379 nb.el.set_current_page(0);
381 onExpand : function() {
382 var nb = this.get('/LeftTopPanel.notebook');
383 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
386 var model = this.get('/LeftProjectTree.combomodel');
387 // print ("loading Projects?")
388 //console.dump(pm.projects);
389 model.loadData(pm.projects);
392 nb.el.set_current_page(1);
393 //pm.on('changed', function() {
394 //console.log("CAUGHT project manager change");
395 // _combo.model.loadData(pm.projects);
403 pack : "pack_start,true,true",
405 XObject.prototype.init.call(this);
406 this.el.set_current_page(0);
413 xtype: Gtk.ScrolledWindow,
416 getActiveElement : function() { // return path to actie node.
418 var path = this.getActivePath();
422 var iter = new Gtk.TreeIter();
423 this.get('model').el.get_iter_from_string(iter, path);
425 var value = new GObject.Value('');
426 this.get('model').el.get_value(iter, 2, value);
428 return JSON.parse(value.value);
430 getActiveFile : function() {
431 return this.get('model').file;
433 getActivePath : function() {
434 var model = this.get('model');
435 var view = this.get('view');
436 if (view.selection.count_selected_rows() < 1) {
439 var iter = new Gtk.TreeIter();
441 view.selection.get_selected(model.el, iter);
442 return model.el.get_path(iter).to_string();
444 getPaleteProvider : function() {
445 var model = this.get('model');
446 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
447 return pm.getPalete(model.file.getType());
449 getRenderer : function() {
451 switch( this.getActiveFile().getType()) {
453 return this.get('/RightBrowser.view');
455 return this.get('/RightGtkView');
460 XObject.prototype.init.call(this);
461 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
463 renderView : function() {
464 var render = this.getRenderer();
465 var model = this.get('model');
467 render.renderJS(model.toJS(false,true)[0]);
469 print("NO RENDER JS METHOD?");
472 shadow_type : Gtk.ShadowType.IN,
477 button_press_event : function (self, ev) {
478 console.log("button press?");
480 if (!this.get('/Editor').save()) {
481 // popup!! - click handled..
485 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
486 print("click" + ev.type);
492 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
494 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
496 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
497 this.get('/LeftTreeMenu').el.show_all();
498 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
499 print("click:" + res.path.to_string());
502 drag_begin : function (self, drag_context) {
503 print('SOURCE: drag-begin');
504 this.targetData = false;
505 // find what is selected in our tree...
506 var iter = new Gtk.TreeIter();
507 var s = this.selection;
508 s.get_selected(this.get('/LeftTree.model').el, iter);
510 // set some properties of the tree for use by the dropped element.
511 var value = new GObject.Value('');
512 this.get('/LeftTree.model').el.get_value(iter, 2, value);
513 var data = JSON.parse(value.value);
514 var xname = this.get('/LeftTree.model').file.guessName(data);
516 this.el.dragData = xname;
517 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
520 // make the drag icon a picture of the node that was selected
521 var path = this.get('/LeftTree.model').el.get_path(iter);
522 this.el.treepath = path.to_string();
524 var pix = this.el.create_row_drag_icon ( path);
526 Gtk.drag_set_icon_pixmap (ctx,
535 drag_end : function (self, drag_context) {
536 Seed.print('LEFT-TREE: drag-end');
537 this.el.dragData = false;
538 this.el.dropList = false;
539 this.targetData = false;
540 this.get('/LeftTree.view').highlight(false);
543 drag_motion : function (self, ctx, x, y, time) {
544 console.log("LEFT-TREE: drag-motion");
545 var src = Gtk.drag_get_source_widget(ctx);
547 // a drag from elsewhere...- prevent drop..
549 print("no drag data!");
550 Gdk.drag_status(ctx, 0, time);
551 this.targetData = false;
554 var action = Gdk.DragAction.COPY;
555 if (src == this.el) {
556 // unless we are copying!!! ctl button..
557 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
561 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
562 // no children.. -- asume it's ok..
563 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
564 Gdk.drag_status(ctx, action ,time);
568 print("GETTING POS");
569 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
570 print("ISOVER? " + isOver);
572 Gdk.drag_status(ctx, 0 ,time);
573 return false; // not over apoint!?!
575 // drag node is parent of child..
576 console.log("SRC TREEPATH: " + src.treepath);
577 console.log("TARGET TREEPATH: " + data.path.to_string());
579 // nned to check a few here..
580 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
581 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
582 //Gtk.TreeViewDropPosition.AFTER
583 //Gtk.TreeViewDropPosition.BEFORE
585 if (typeof(src.treepath) != 'undefined' &&
586 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
587 print("subpath drag");
588 Gdk.drag_status(ctx, 0 ,time);
593 //print("DUMPING DATA");
594 //console.dump(data);
597 print(data.path.to_string() +' => '+ data.pos);
598 var tg = this.get('/LeftTree.model').findDropNodeByPath(
599 data.path.to_string(), src.dropList, data.pos);
601 this.get('/LeftTree.view').highlight(tg);
603 print("Can not find drop node path");
604 this.targetData = false;
605 Gdk.drag_status(ctx, 0, time);
609 this.targetData = tg;
612 Gdk.drag_status(ctx, action ,time);
616 drag_drop : function (w, ctx, x, y, time) {
617 Seed.print("TARGET: drag-drop");
621 w, /* will receive 'drag-data-received' signal */
622 ctx, /* represents the current state of the DnD */
623 this.get('/Window').atoms["STRING"], /* the target type we want */
624 time /* time stamp */
628 /* No target offered by source => error */
633 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
634 print("Tree: drag-data-received");
636 var delete_selection_data = false;
637 var dnd_success = false;
638 /* Deal with what we are given from source */
639 if( sel_data && sel_data.length ) {
641 if (ctx.action == Gdk.DragAction.ASK) {
642 /* Ask the user to move or copy, then set the ctx action. */
645 if (ctx.action == Gdk.DragAction.MOVE) {
646 //delete_selection_data = true;
649 var source = Gtk.drag_get_source_widget(ctx);
651 if (this.targetData) {
652 if (source != this.el) {
653 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
655 // drag around.. - reorder..
656 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
660 //Seed.print(this.targetData);
666 // we can send stuff to souce here...
672 if (dnd_success == false)
674 Seed.print ("DnD data transfer failed!\n");
677 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
680 cursor_changed : function (self) {
681 if (this.blockChanges) { // probably not needed..
684 var render = this.get('/LeftTree').getRenderer();
687 if (this.selection.count_selected_rows() < 1) {
688 this.get('/LeftPanel.model').load( false);
689 this.get('/MidPropTree').activeElement = false;
690 this.get('/MidPropTree').hideWin();
692 var pm = this.get('/RightPalete.model');
693 if (!this.get('/LeftTree').getPaleteProvider()) {
694 // it may not be loaded yet..
697 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
698 this.get('/LeftTree.model').listAllTypes()));
699 if (render && render.redraw) {
705 //console.log('changed');
706 var s = this.selection;
707 var iter = new Gtk.TreeIter();
708 s.get_selected(this.get('/LeftTree.model').el, iter);
712 var value = new GObject.Value('');
713 this.get('/LeftTree.model').el.get_value(iter, 2, value);
714 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
716 var data = JSON.parse(value.value);
717 this.get('/MidPropTree').activeElement = data;
718 this.get('/MidPropTree').hideWin();
719 this.get('/LeftPanel.model').load( data);
721 console.log(value.value);
722 // _g.button.set_label(''+value.get_string());
724 var pm =this.get('/RightPalete.model');
725 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
726 this.get('/LeftTree.model').listAllTypes()));
729 if (render && render.redraw) {
733 //Seed.print( value.get_string());
741 enable_tree_lines : true,
742 headers_visible : false,
743 highlight : function(treepath_ar) {
745 // highlighting for drag/drop
746 if (treepath_ar.length && treepath_ar[0].length ) {
747 this.el.set_drag_dest_row(
748 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
750 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
755 XObject.prototype.init.call(this);
756 var description = new Pango.FontDescription.c_new();
757 description.set_size(8000);
758 this.el.modify_font(description);
760 this.selection = this.el.get_selection();
761 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
764 // is this really needed??
765 this.selection.signal['changed'].connect(function() {
766 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
767 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
771 Gtk.drag_source_set (
772 this.el, /* widget will be drag-able */
773 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
774 null, /* lists of target to support */
775 0, /* size of list */
776 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
779 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
781 Gtk.drag_source_add_text_targets(this.el);
784 this.el, /* widget that will accept a drop */
785 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
786 null, /* lists of target to support */
787 0, /* size of list */
788 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
791 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
792 Gtk.drag_dest_add_text_targets(this.el);
794 selectNode : function(treepath_str) {
795 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
796 var tp = new Gtk.TreePath.from_string(treepath_str);
797 this.el.set_cursor(tp, null, false);
798 this.el.scroll_to_cell(tp, null, false, 0,0);
802 xtype: Gtk.TreeStore,
807 changed : function(n, refresh) {
808 // print("MODEL CHANGED CALLED" + this.activePath);
809 if (this.activePath) {
810 var iter = new Gtk.TreeIter();
811 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
812 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
813 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
815 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
817 //this.currentTree = this.toJS(false, true)[0];
819 this.file.items = this.toJS(false, false);
820 print ("TO JS in " + ((new Date()) - d) + "ms");
821 // print("AFTER CHANGED");
822 //console.dump(this.file.items);
824 this.currentTree = this.file.items[0];
825 //console.log(this.file.toSource());
828 print("REDNER BROWSER?!");
829 this.get('/LeftTree').renderView();
831 var pm = this.get('/RightPalete.model');
832 if (!this.get('/RightPalete').provider) {
838 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
839 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
843 deleteSelected : function() {
844 this.get('/LeftTree.view').blockChanges = true;
845 var old_iter = new Gtk.TreeIter();
846 var s = this.get('/LeftTree.view').selection;
847 s.get_selected(this.el, old_iter);
848 var path = this.el.get_path(old_iter).to_string();
850 this.activePath= false;
853 this.activePath= false;
854 var iter = new Gtk.TreeIter();
855 this.el.get_iter_from_string(iter, path);
856 this.el.remove(iter);
858 // rebuild treemap. -- depreciated.!!
861 //this.toJS(null, true) // does not do anything?
862 this.activePath= false;
863 this.changed(false,true);
864 this.get('/LeftTree.view').blockChanges = false;
866 dropNode : function(target_data, node) {
868 // console.dump(node);
869 // console.dump(target_data);
870 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
872 print("add " + tp + "@" + target_data[1] );
875 if (tp && target_data[1] < 2) { // before or after..
876 var ar = target_data[0].split(':');
878 parent = new Gtk.TreePath.from_string( ar.join(':') );
881 var n_iter = new Gtk.TreeIter();
882 var iter_par = new Gtk.TreeIter();
883 var iter_after = after ? new Gtk.TreeIter() : false;
887 if (parent !== false) {
888 this.el.get_iter(iter_par, parent);
895 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
896 this.el.get_iter(iter_after, after);
897 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
898 n_iter, iter_par, iter_after);
901 this.el.append(n_iter, iter_par);
905 if (typeof(node) == 'string') {
906 var ar = node.split('.');
907 var xtype = ar.pop();
910 '|xns' : ar.join('.'),
913 if (target_data.length == 3 && target_data[2].length) {
914 node['*prop'] = target_data[2];
916 node = this.get('/DialogTemplateSelect').show(node);
919 // work out what kind of packing to use..
920 if (typeof(node.pack) == 'undefined' && parent !== false) {
921 var pal = this.get('/LeftTree').getPaleteProvider();
922 if (pal.name == 'Gtk') {
923 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
924 var cname = pal.guessName(node);
925 node.pack = pal.getDefaultPack(pname, cname);
936 // load children - if it has any..
939 this.load(xitems, n_iter);
940 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
942 if (tp && (xitems || after)) {
943 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
945 // wee need to get the empty proptypes from somewhere..
947 //var olditer = this.activeIter;
948 this.activePath = this.el.get_path(n_iter).to_string();
950 // changed actually set's the node data..
951 this.changed(node, true);
955 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
957 //Builder.MidPropTree._model.load(node);
958 //Builder.MidPropTree._win.hideWin();
959 //Builder.LeftPanel._model.load( node);
963 findDropNode : function(treepath_str, targets) {
965 // this is used by the dragdrop code in the roo version AFAIR..
967 var path = treepath_str.replace(/^builder-/, '');
968 // treemap is depreciated... - should really check if model has any entries..
970 if (!this.el.iter_n_children(null)) {
972 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
974 print("FIND treepath: " + path);
975 //console.dump(this.treemap);
977 if (!treepath_str.match(/^builder-/)) {
978 return []; // nothing!
980 if (targets === true) {
983 return this.findDropNodeByPath(path,targets)
985 findDropNodeByPath : function(treepath_str, targets, pref) {
986 var path = treepath_str + ''; // dupe it..
987 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
989 //console.dump(this.treemap);
990 while (path.length) {
991 print("LOOKING FOR PATH: " + path);
992 var node_data = this.singleNodeToJS(path);
993 if (node_data === false) {
994 print("node not found");
998 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1001 targets.forEach(function(tg) {
1005 if ((tg == xname) ) {
1008 if (tg.indexOf(xname +':') === 0) {
1010 prop = tg.split(':').pop();
1015 if (last) { // pref is after/before..
1016 // then it's after last
1018 return []; // do not allow..
1020 return [ last, pref , prop];
1023 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1025 var par = path.split(':');
1028 path = par.join(':');
1034 getIterValue : function (iter, col) {
1035 var gval = new GObject.Value('');
1036 this.el.get_value(iter, col ,gval);
1042 XObject.prototype.init.call(this);
1043 this.el.set_column_types ( 3, [
1044 GObject.TYPE_STRING, // title
1045 GObject.TYPE_STRING, // tip
1046 GObject.TYPE_STRING // source..
1049 listAllTypes : function() {
1050 var s = this.get('/LeftTree.view').selection;
1051 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1053 if (s.count_selected_rows() > 0) {
1054 var iter = new Gtk.TreeIter();
1055 s.get_selected(this.el, iter);
1057 // set some properties of the tree for use by the dropped element.
1058 var value = new GObject.Value('');
1059 this.el.get_value(iter, 2, value);
1060 var data = JSON.parse(value.value);
1063 var xname = this.get('/LeftTree.model').file.guessName(data);
1064 console.log('selected:' + xname);
1068 return []; // could not find it..
1076 li.forEach(function(el) {
1077 // this is specific to roo!!!?
1078 if (!el) { // skip empty?
1081 var fullpath = _this.file.guessName(el);
1082 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1087 if (el.items && el.items.length) {
1096 addall([this.currentTree]);
1098 // only if we have nothing, should we add '*top'
1102 //console.log('all types in tree');
1103 //console.dump(ret);
1108 load : function(tr,iter)
1110 var citer = new Gtk.TreeIter();
1111 //this.insert(citer,iter,0);
1112 for(var i =0 ; i < tr.length; i++) {
1114 this.el.insert(citer,iter,-1);
1116 this.el.append(citer);
1119 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1120 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1121 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1122 if (tr[i].items && tr[i].items.length) {
1123 this.load(tr[i].items, citer);
1127 loadFile : function(f) {
1133 console.log('missing file');
1137 // load the file if not loaded..
1138 if (f.items === false) {
1140 f.loadItems(function() {
1146 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1148 if (f.items.length && typeof(f.items[0]) == 'string') {
1150 //this.get('/RightEditor').el.show();
1151 //this.get('/RightEditor.view').load( f.items[0]);
1155 print(JSON.stringify(f.items, null,4));
1156 //console.dump(f.items);
1158 this.get('/LeftTree.view').el.expand_all();
1160 if (!f.items.length) {
1163 this.get('/Window.leftvpaned').el.set_position(80);
1165 this.get('/LeftTree.view').el.set_cursor(
1166 new Gtk.TreePath.from_string('0'), null, false);
1170 this.get('/Window.leftvpaned').el.set_position(200);
1174 //print("hide right editior");
1175 //this.get('/RightEditor').el.hide();
1176 this.get('/Editor').el.hide();
1177 //print("set current tree");
1178 this.currentTree = this.toJS(false, false)[0];
1179 //console.dump(this.currentTree);
1180 this.currentTree = this.currentTree || { items: [] };
1181 this.get('/LeftTree').renderView();
1182 //console.dump(this.map);
1183 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1184 var pm = this.get('/RightPalete.model');
1185 // set up provider..
1187 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1189 if (!this.get('/RightPalete').provider) {
1190 print ("********* PALETE PROVIDER MISSING?!!");
1192 this.get('/LeftTree').renderView();
1194 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1198 this.get('/Window.view-notebook').el.set_current_page(
1199 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1202 moveNode : function(target_data, action) {
1203 //print("MOVE NODE");
1204 // console.dump(target_data);
1205 var old_iter = new Gtk.TreeIter();
1206 var s = this.get('/LeftTree.view').selection;
1207 s.get_selected(this.el, old_iter);
1208 var node = this.nodeToJS(old_iter,false);
1209 //console.dump(node);
1212 // needs to drop first, otherwise the target_data
1213 // treepath will be invalid.
1215 this.dropNode(target_data, node);
1216 if (action & Gdk.DragAction.MOVE) {
1217 // print("REMOVING OLD NODE");
1218 this.el.remove(old_iter);
1222 this.activePath= false;
1223 this.changed(false,true);
1225 nodeTip : function(c) {
1226 var ret = this.nodeTitle(c,true);
1232 if (!i.length || i[0] != '|') {
1238 if (typeof(c[i]) != 'string') {
1241 //print("prop : " + i + ':' + c[i]);
1242 if (!c[i].match(new RegExp('function'))) {
1245 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1249 ret+="\n\nMethods:" + funcs;
1254 nodeTitle : function(c, renderfull) {
1257 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1258 if (sr) txt.push('<s>');
1259 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1261 if (renderfull && c['|xns']) {
1262 txt.push(c['|xns']);
1265 if (c.xtype) { txt.push(c.xtype); }
1266 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1267 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1268 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1271 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1272 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1273 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1274 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1275 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1276 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1277 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1278 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1279 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1281 // for flat classes...
1282 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1283 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1286 if (sr) txt.push('</s>');
1287 return (txt.length == 0 ? "Element" : txt.join(" "));
1289 nodeToJS : function (treepath, with_id)
1292 var iter = treepath; // API used to be iter here..
1293 if (typeof(iter) == 'string') {
1294 iter = new Gtk.TreeIter();
1295 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1299 var par = new Gtk.TreeIter();
1300 var iv = this.getIterValue(iter, 2);
1301 // print("IV" + iv);
1302 var k = JSON.parse(iv);
1303 if (k.json && !this.el.iter_parent( par, iter )) {
1308 var treepath_str = this.el.get_path(iter).to_string();
1309 // not sure how we can handle mixed id stuff..
1310 if (typeof(k.id) == 'undefined') {
1311 k.id = 'builder-'+ treepath_str ;
1315 this.treemap[ treepath_str ] = k;
1316 k.xtreepath = treepath_str ;
1319 if (this.el.iter_has_child(iter)) {
1320 citer = new Gtk.TreeIter();
1321 this.el.iter_children(citer, iter);
1322 k.items = this.toJS(citer,with_id);
1326 nodeToJSON : function(c) {
1334 return JSON.stringify(o);
1336 singleNodeToJS : function (treepath)
1338 var iter = new Gtk.TreeIter();
1339 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1343 var iv = this.getIterValue(iter, 2);
1345 return JSON.parse(iv);
1348 toJS : function(treepath, with_id)
1350 //Seed.print("WITHID: "+ with_id);
1351 var iter = treepath; // API used to be iter here..
1352 if (typeof(iter) == 'string') {
1353 iter = new Gtk.TreeIter();
1354 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1363 iter = new Gtk.TreeIter();
1364 if (!this.el.get_iter_first(iter)) {
1374 var k = this.nodeToJS(iter, with_id);
1378 if (!this.el.iter_next(iter)) {
1383 if (treepath === false) {
1385 return JSON.parse(JSON.stringify(ar));
1389 // convert the list into a json string..
1395 xtype: Gtk.TreeViewColumn,
1396 pack : "append_column",
1398 XObject.prototype.init.call(this);
1399 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1403 xtype: Gtk.CellRendererText,
1413 id : "LeftTreeMenu",
1416 xtype: Gtk.MenuItem,
1418 label : "Delete Element",
1420 activate : function (self) {
1422 this.get('/LeftTree.model').deleteSelected();
1427 xtype: Gtk.MenuItem,
1429 activate : function (self) {
1431 var tree = this.get('/LeftTree');
1432 var model = this.get('/LeftTree.model');
1433 var el = tree.getActivePath();
1435 var js = model.toJS(el, false);
1436 // print(JSON.stringify(js[0], null,4));
1437 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1442 label : "Save as Template",
1452 id : "LeftProjectTree",
1453 showNoProjectSelected : function() {
1454 this.get('/StandardErrorDialog').show("Select a Project first.");
1456 getActiveProject : function() {
1457 return this.project;
1460 leave_notify_event : function (self, event) {
1467 pack : "pack_start,false,false",
1470 xtype: Gtk.ComboBox,
1473 XObject.prototype.init.call(this);
1474 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1476 getValue : function() {
1477 var ix = this.el.get_active();
1481 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1482 if (typeof(data[ix]) == 'undefined') {
1487 setValue : function(fn)
1491 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1492 data.forEach(function(n, ix) {
1500 changed : function (self) {
1501 var fn = this.getValue();
1502 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1503 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1508 xtype: Gtk.CellRendererText,
1509 pack : "pack_start,true",
1513 xtype: Gtk.ListStore,
1516 XObject.prototype.init.call(this);
1517 this.el.set_column_types ( 2, [
1518 GObject.TYPE_STRING, // real key
1519 GObject.TYPE_STRING // real type
1523 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1525 pm.on('changed', function() {
1526 print("caught changed hook on project manager - reloading data");
1527 _this.loadData(pm.projects);
1531 loadData : function(data) {
1532 var ov = this.get('/LeftProjectTree.combo').getValue();
1534 var iter = new Gtk.TreeIter();
1536 data.forEach(function(p) {
1541 el.set_value(iter, 0, p.fn);
1542 el.set_value(iter, 1, p.name);
1546 this.get('/LeftProjectTree.combo').setValue(ov);
1555 xtype: Gtk.ScrolledWindow,
1557 shadow_type : Gtk.ShadowType.IN,
1559 XObject.prototype.init.call(this);
1560 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1564 xtype: Gtk.TreeView,
1566 cursor_changed : function (self) {
1567 var iter = new Gtk.TreeIter();
1569 if (this.selection.count_selected_rows() < 1) {
1570 //XN.get('Builder.LeftTree.model').
1571 this.get('/LeftTree.model').load( false);
1575 var model = this.get('/LeftProjectTree.model');
1576 //console.log('changed');
1577 var s = this.selection;
1578 s.get_selected(model, iter);
1579 value = new GObject.Value('');
1580 model.el.get_value(iter, 2, value);
1582 console.log(value.value);// id..
1584 var file = this.get('/LeftProjectTree').project.getById(value.value);
1591 var nb = this.get('/LeftTopPanel.expander');
1592 nb.el.expanded = false;
1594 //nb.listeners.activate.call(nb);
1595 //_expander.el.set_expanded(false);
1597 var ltm = this.get('/LeftTree.model');
1605 enable_tree_lines : true,
1606 headers_visible : false,
1608 XObject.prototype.init.call(this);
1609 var description = new Pango.FontDescription.c_new();
1610 description.set_size(8000);
1611 this.el.modify_font(description);
1613 this.selection = this.el.get_selection();
1614 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1618 xtype: Gtk.TreeStore,
1622 XObject.prototype.init.call(this);
1623 this.el.set_column_types ( 3, [
1624 GObject.TYPE_STRING, // title
1625 GObject.TYPE_STRING, // tip
1626 GObject.TYPE_STRING // id..
1630 loadProject : function(pr) {
1631 print("LOAD PROJECT");
1637 this.get('/LeftProjectTree').project = pr;
1638 this.load(pr.toTree());
1639 this.get('/LeftProjectTree.view').el.expand_all();
1641 load : function(tr,iter) {
1642 // console.dump(tr);
1643 console.log('Project tree load: ' + tr.length);
1644 var citer = new Gtk.TreeIter();
1645 //this.insert(citer,iter,0);
1648 tr.forEach(function (r) {
1650 _this.el.append(citer);
1652 _this.el.insert(citer,iter,-1);
1654 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1655 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1656 _this.el.set_value(citer, 2, '' + r.id ); //id
1657 if (r.cn && r.cn.length) {
1658 _this.load(r.cn, citer);
1663 getValue : function(iter, col) {
1664 var gval = new GObject.Value('');
1665 this.el.get_value(iter, col ,gval);
1666 return '' + gval.value;
1670 xtype: Gtk.TreeViewColumn,
1671 pack : "append_column",
1673 XObject.prototype.init.call(this);
1674 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1678 xtype: Gtk.CellRendererText,
1698 pack : "pack_start,false,true,0",
1705 button_press_event : function (self, event) {
1706 this.get('/MidPropTree.model').showData('props');
1718 stock : Gtk.STOCK_ADD,
1719 icon_size : Gtk.IconSize.MENU
1733 button_press_event : function (self, event) {
1735 if (!this.get('/Editor').save()) {
1736 // popup!! - click handled..
1739 this.get('/MidPropTree.model').showData('events');
1752 stock : Gtk.STOCK_ADD,
1753 icon_size : Gtk.IconSize.MENU
1767 button_press_event : function (self, ev) {
1769 if (!this.get('/Editor').save()) {
1770 // popup!! - click handled..
1774 var p = this.get('/AddPropertyPopup');
1778 p.el.set_screen(Gdk.Screen.get_default());
1780 p.el.popup(null, null, null, null, 3, ev.button.time);
1793 stock : Gtk.STOCK_ADD,
1794 icon_size : Gtk.IconSize.MENU
1806 id : "AddPropertyPopup",
1809 xtype: Gtk.MenuItem,
1811 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1814 activate : function (self) {
1816 this.get('/LeftPanel.model').add( {
1827 xtype: Gtk.MenuItem,
1829 tooltip_markup : "Add what type of packing is to be used",
1832 activate : function (self) {
1834 this.get('/LeftPanel.model').add( {
1844 xtype: Gtk.MenuItem,
1846 tooltip_markup : "Override the init method",
1849 activate : function (self) {
1851 this.get('/LeftPanel.model').add( {
1854 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1861 xtype: Gtk.SeparatorMenuItem,
1865 xtype: Gtk.MenuItem,
1867 tooltip_markup : "Add a user defined string property",
1870 activate : function (self) {
1872 this.get('/LeftPanel.model').add( {
1882 xtype: Gtk.MenuItem,
1884 tooltip_markup : "Add a user defined number property",
1887 activate : function (self) {
1889 this.get('/LeftPanel.model').add( {
1899 xtype: Gtk.MenuItem,
1901 tooltip_markup : "Add a user defined boolean property",
1904 activate : function (self) {
1906 this.get('/LeftPanel.model').add( {
1916 xtype: Gtk.SeparatorMenuItem,
1920 xtype: Gtk.MenuItem,
1922 tooltip_markup : "Add a user function boolean property",
1925 activate : function (self) {
1927 this.get('/LeftPanel.model').add( {
1930 val : "function() {\n \n}\n",
1943 xtype: Gtk.ScrolledWindow,
1948 XObject.prototype.init.call(this);
1949 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1951 shadow_type : Gtk.ShadowType.IN,
1954 xtype: Gtk.TreeView,
1956 button_press_event : function (self, ev) {
1959 if (!this.get('/Editor').save()) {
1960 // popup!! - click handled..
1965 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1966 return false; //not on a element.
1970 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
1972 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
1975 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1976 var p = this.get('/LeftPanelPopup');
1981 p.el.set_screen(Gdk.Screen.get_default());
1983 p.el.popup(null, null, null, null, 3, ev.button.time);
1984 //Seed.print("click:" + res.column.title);
1991 if (res.column.title != 'value') {
1992 // XObject.error("column is not value?");
1993 return false; // ignore.. - key click.. ??? should we do this??
1996 // currently editing???
1997 // if ( this.activePath) {
1999 // this.activePath = false;
2001 if (this.get('/Editor').dirty) {
2002 //if (!this.get('/Editor.buffer').checkSyntax()) {
2003 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2007 if (!this.get('/Editor.view').save()) {
2011 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2012 this.get('/LeftPanel').editing = false;
2014 // XObject.error("Currently editing?");
2018 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2020 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2022 // get options for this type -- this is to support option lists etc..
2023 var provider = this.get('/LeftTree').getPaleteProvider();
2024 var opts = provider.findOptions(type);
2026 if (opts === false) {
2028 this.get('/LeftPanel').editableColumn.setOptions([]);
2029 renderer.has_entry = true;
2031 this.get('/LeftPanel').editableColumn.setOptions(opts);
2032 renderer.has_entry = false;
2034 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2036 //Seed.print("click" + ev.type);
2037 //console.dump(res);
2046 enable_tree_lines : true,
2047 headers_visible : false,
2049 XObject.prototype.init.call(this);
2051 this.selection = this.el.get_selection();
2052 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2055 var description = new Pango.FontDescription.c_new();
2056 description.set_size(8000);
2057 this.el.modify_font(description);
2061 xtype: Gtk.TreeStore,
2065 add : function(info) {
2066 // info includes key, val, skel, etype..
2068 type = info.type.toLowerCase();
2069 var data = this.toJS();
2071 if (info.etype == 'events') {
2072 data.listeners = data.listeners || { };
2073 if (typeof(data.listeners[info.key]) != 'undefined') {
2074 return; //already set!
2077 if (typeof(data[info.key]) != 'undefined') {
2082 if (typeof(info.val) == 'undefined') {
2085 if (info.type.toLowerCase() == 'boolean') {
2088 if (type == 'number') {
2096 if (info.etype == 'events') {
2098 data.listeners[info.key] = info.val;
2101 data[info.key] = info.val;
2105 var map = this.load(data);
2107 // flag it as changed to the interface..
2109 this.get('/LeftTree.model').changed(data, true);
2112 this.startEditing(map[k]);
2115 LeftPanel.get('view').el.row_activated(
2116 new Gtk.TreePath.from_string(map[k]),
2117 LeftPanel.editableColumn.el
2121 changed : function(str, doRefresh) {
2122 if (!this.activePath) {
2125 var iter = new Gtk.TreeIter();
2126 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2128 this.el.set_value(iter, 1, '' +str);
2129 this.el.set_value(iter, 3, '' + this.toShort(str));
2130 var type = this.getIterValue(iter, 4);
2132 this.el.set_value(iter, 5, type + ' : ' + str);
2133 // update the tree...
2135 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2137 deleteSelected : function() {
2138 var data = this.toJS();
2139 var iter = new Gtk.TreeIter();
2140 var s = this.get('/LeftPanel.view').selection;
2141 s.get_selected(this.el, iter);
2144 var gval = new GObject.Value('');
2145 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2147 var val = gval.value;
2148 if (val[0] == '!') {
2150 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2153 delete data.listeners[ val.substring(1)];
2154 if (!XObject.keys(data.listeners).length) {
2155 delete data.listeners;
2159 if (typeof(data[val]) == 'undefined') {
2167 this.get('/LeftTree.model').changed(data, true);
2170 getIterValue : function(iter, col) {
2171 var gval = new GObject.Value('');
2172 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2173 return '' + gval.value;
2175 getType : function(treepath) {
2176 return this.getValue(treepath, 4);
2178 getValue : function(treepath_str, col)
2180 // get's the value in a row.. - keys - returns string, values - formats it..
2182 var iter = new Gtk.TreeIter();
2183 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2185 var gval = new GObject.Value('');
2186 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2187 var val = '' + gval.value;
2192 var type = this.getType(this.el.get_path(iter).to_string());
2193 //print("TYPE: " +type + " - val:" + val);
2194 switch(type.toLowerCase()) {
2198 return parseFloat(val); // Nan ?? invalid!!?
2201 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2203 return val == 'true' ? true : false;
2205 var nv = parseFloat(val);
2206 if (!isNaN(nv) && (val == ''+nv)) {
2214 XObject.prototype.init.call(this);
2215 this.el.set_column_types ( 6, [
2216 GObject.TYPE_STRING, // 0 real key
2217 GObject.TYPE_STRING, // 1 real value
2218 GObject.TYPE_STRING, // 2 visable key
2219 GObject.TYPE_STRING, // 3 visable value
2220 GObject.TYPE_STRING, // 4 need to store type of!!!
2221 GObject.TYPE_STRING // 5 tooltip
2225 load : function(ar) {
2226 // might casue problesm..
2227 // this.get('/Editor.RightEditor').save();
2229 this.get('/Editor').el.hide();
2230 this.get('/Editor').activePath = false;
2235 //this.get('/RightEditor').el.hide();
2242 var provider = this.get('/LeftTree').getPaleteProvider();
2243 var iter = new Gtk.TreeIter();
2246 var keys = XObject.keys(ar);
2248 ar.listeners = ar.listeners || {};
2250 for (var i in ar.listeners ) {
2251 this.el.append(iter);
2252 var p = this.el.get_path(iter).to_string();
2255 this.el.set_value(iter, 0, '!'+ i );
2256 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2257 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2259 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2260 this.el.set_value(iter, 4, 'function');
2261 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2267 keys.forEach(function(i) {
2268 if (typeof(ar[i]) == 'object') {
2272 var type = provider.findType(ar, i, ar[i]);
2274 _this.el.append(iter);
2275 var p = _this.el.get_path(iter).to_string();
2277 _this.el.set_value(iter, 0, ''+i);
2278 _this.el.set_value(iter, 1, '' + ar[i]);
2279 _this.el.set_value(iter, 2, ''+i);
2280 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2281 _this.el.set_value(iter, 4, ''+type);
2282 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2286 startEditing : function(path,col) {
2288 // alled by menu 'edit' currently..
2290 * start editing path (or selected if not set..)
2291 * @param {String|false} path (optional) treepath to edit - selected tree gets
2292 * edited by default.
2293 * @param {Number} 0 or 1 (optional)- column to edit.
2295 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2297 if (typeof(path) == 'string') {
2298 tp = new Gtk.TreePath.from_string(path);
2300 var iter = new Gtk.TreeIter();
2301 var s = this.get('/LeftPanel.view').selection;
2302 s.get_selected(this.el, iter);
2303 tp = this.el.get_path(iter);
2304 path = tp.to_string();
2308 // which colum is to be edited..
2311 // not sure what this does..
2313 if (typeof(col) == 'undefined') {
2314 var k = this.getValue(path, 0);
2316 colObj = (!k.length || k == '|') ?
2317 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2319 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2322 // make sure the pulldown is set correctly..
2323 // not really needed for second col...
2324 var showEditor = false;
2325 this.get('/Editor').activePath = false;
2326 this.get('/Editor').el.hide();
2329 var provider = this.get('/LeftTree').getPaleteProvider();
2330 var type = this.get('/LeftPanel.model').getType(path);
2331 var opts = provider.findOptions(type);
2332 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2334 if (opts === false) {
2335 this.get('/LeftPanel').editableColumn.setOptions([]);
2336 renderer.has_entry = true;
2338 this.get('/LeftPanel').editableColumn.setOptions(opts);
2339 renderer.has_entry = false;/// - pulldowns do not have entries
2341 // determine if we should use the Text editor...
2342 var keyname = this.getValue(path, 0);
2343 var data_value = this.getValue(path, 1);
2345 if ((keyname[0] == '|') ||
2347 (typeof(data_value) == 'string' ) &&
2348 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2352 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2357 // this.get('/BottomPane').el.hide();
2358 //this.get('/RightEditor').el.hide();
2363 this.activePath = false;
2365 _this.get('/Editor').el.show_all();
2366 GLib.timeout_add(0, 1, function() {
2368 //_this.get('/BottomPane').el.show();
2369 //_this.get('/RightEditor').el.show();
2371 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2373 _this.get('/Editor').activePath = path;
2374 _this.activePath = path ;
2384 // iter now has row...
2385 GLib.timeout_add(0, 100, function() {
2386 _this.activePath = path;
2387 colObj.items[0].el.editable = true; // esp. need for col 0..
2388 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2398 var iter = new Gtk.TreeIter();
2399 this.get('/LeftPanel.model').el.get_iter_first(iter);
2404 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2407 ar.listeners = ar.listeners || {};
2408 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2411 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2414 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2420 //print(JSON.stringify(ar));
2424 toShort : function(str) {
2425 var a = typeof(str) == 'string' ? str.split("\n") : [];
2426 return a.length > 1 ? a[0] + '....' : '' + str;
2430 xtype: Gtk.TreeViewColumn,
2431 pack : "append_column",
2433 XObject.prototype.init.call(this);
2435 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2436 this.get('/LeftPanel').propertyColumn = this;
2441 xtype: Gtk.CellRendererText,
2442 pack : "pack_start",
2444 editing_started : function (self, editable, path) {
2446 this.get('/LeftPanel.model').activePath = path;
2449 edited : function (self, object, p0) {
2450 var model = this.get('/LeftPanel.model');
2451 var path = model.activePath;
2452 var iter = new Gtk.TreeIter();
2453 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2454 model.el.set_value(iter, 0, p0);
2455 model.el.set_value(iter, 2, p0);
2457 model.activePath = false;
2459 this.get('/LeftTree.model').changed(model.toJS(), true);
2460 this.el.editable = false;
2467 xtype: Gtk.TreeViewColumn,
2468 pack : "append_column",
2471 XObject.prototype.init.call(this);
2472 this.el.add_attribute(this.items[0].el , 'text', 3 );
2473 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2474 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2475 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2477 this.get('/LeftPanel').editableColumn= this;
2479 setOptions : function(ar) {
2480 var m = this.items[0].el.model;
2482 var iter = new Gtk.TreeIter();
2483 ar.forEach(function(i) {
2486 m.set_value(iter, 0, i);
2492 xtype: Gtk.CellRendererCombo,
2494 edited : function (self, object, p0) {
2495 this.get('/LeftPanel').editing = false;
2496 var ap = this.get('/LeftPanel.model').activePath
2497 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2498 this.get('/LeftPanel.model').changed(p0, true);
2499 this.get('/LeftPanel.model').activePath = false;
2500 this.el.editable = false;
2502 editing_started : function (self, editable, path) {
2503 this.get('/LeftPanel').editing = true;
2504 // console.log('editing started');
2505 // r.has_entry = false;
2507 this.el.editable = false; // make sure it's not editor...
2512 pack : "pack_start",
2516 XObject.prototype.init.call(this);
2517 this.el.model = new Gtk.ListStore();
2518 this.el.model.set_column_types ( 1, [
2519 GObject.TYPE_STRING // 0 real key
2530 id : "LeftPanelPopup",
2533 xtype: Gtk.MenuItem,
2537 activate : function (self) {
2538 this.get('/LeftPanel.model').deleteSelected();
2543 xtype: Gtk.MenuItem,
2547 activate : function (self) {
2548 this.get('/LeftPanel.model').startEditing(false, 0);
2561 xtype: Gtk.ScrolledWindow,
2562 pack : "pack_end,false,true,0",
2564 shadow_type : Gtk.ShadowType.IN,
2566 XObject.prototype.init.call(this);
2567 XObject.prototype.init.call(this);
2568 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2569 this.el.set_size_request ( 150, -1 );
2572 activeElement : false,
2573 hideWin : function() {
2580 if (this.get('/Window.left').el.position < 160) {
2583 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2590 xtype: Gtk.TreeView,
2592 cursor_changed : function (self) {
2593 var iter = new Gtk.TreeIter();
2595 //console.log('changed');
2596 var m = this.get('model');
2597 if (!this.selection){
2598 this.selection = this.el.get_selection();
2601 var s = this.selection;
2602 if (!s.get_selected(m.el, iter)) {
2605 var tp = m.el.get_path(iter).to_string();
2610 var key = m.getValue(tp, 0);
2612 var type = m.getValue(tp, 1);
2613 var skel = m.getValue(tp, 3);
2614 var etype = m.getValue(tp, 5);
2617 this.get('/MidPropTree').hideWin();
2619 if (type.toLowerCase() == 'function') {
2621 if (etype != 'events') {
2625 this.get('/LeftPanel.model').add({
2633 // has dot in name, and is boolean???? this does not make sense..
2634 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2638 this.get('/LeftPanel.model').add( {
2648 enable_tree_lines : true,
2649 headers_visible : false,
2651 XObject.prototype.init.call(this);
2653 var description = new Pango.FontDescription.c_new();
2654 description.set_size(8000);
2655 this.el.modify_font(description);
2657 //this.selection = this.el.get_selection();
2658 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2667 xtype: Gtk.ListStore,
2670 getValue : function(treepath, col)
2672 var tp = new Gtk.TreePath.from_string (treepath);
2673 var iter = new Gtk.TreeIter();
2674 this.el.get_iter (iter, tp);
2675 var value = new GObject.Value('');
2676 this.el.get_value(iter, col, value);
2681 XObject.prototype.init.call(this);
2682 this.el.set_column_types ( 6, [
2683 GObject.TYPE_STRING, // real key
2684 GObject.TYPE_STRING, // real type
2685 GObject.TYPE_STRING, // docs ?
2686 GObject.TYPE_STRING, // visable desc
2687 GObject.TYPE_STRING, // function desc
2688 GObject.TYPE_STRING // element type (event|prop)
2692 showData : function(type) {
2694 if (!this.get('/MidPropTree').activeElement || !type) {
2695 return; // no active element
2698 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2699 var palete = this.get('/LeftTree').getPaleteProvider();
2703 Seed.print('Showing right?');
2704 if (!this.get('/MidPropTree').shown) {
2706 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2707 this.get('/MidPropTree').el.show();
2708 this.get('/MidPropTree').shown = true;
2711 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2712 return a.name > b.name ? 1 : -1;
2714 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2715 // console.dump(elementList);
2718 var iter = new Gtk.TreeIter();
2719 for(var i =0 ; i < elementList.length; i++) {
2720 var p=elementList[i];
2721 this.el.append(iter);
2722 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2723 //GObject.TYPE_STRING, // real key
2724 // GObject.TYPE_STRING, // real type
2725 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2726 // GObject.TYPE_STRING // func def?
2729 this.el.set_value(iter, 0, p.name);
2730 this.el.set_value(iter, 1, p.type);
2731 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2732 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2733 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2734 this.el.set_value(iter, 5, type);
2741 xtype: Gtk.TreeViewColumn,
2743 this.el = new Gtk.TreeViewColumn();
2744 this.parent.el.append_column(this.el);
2746 XObject.prototype.init.call(this);
2747 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2752 xtype: Gtk.CellRendererText,
2753 pack : "pack_start,true"
2777 xtype: Gtk.Notebook,
2778 pack : "pack_start,true,true",
2779 id : "view-help-nb",
2781 XObject.prototype.init.call(this);
2782 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2783 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2787 xtype: Gtk.Notebook,
2788 id : "view-notebook",
2792 XObject.prototype.init.call(this);
2793 this.el.set_current_page(0);
2794 //print("SET LABEL?")
2795 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2796 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2802 id : "RightBrowser",
2807 pack : "pack_start,false,true,0",
2812 clicked : function (self) {
2813 this.get('/RightBrowser.view').renderJS(null,true);
2817 pack : "pack_start,false,false,0"
2820 xtype: Gtk.CheckButton,
2822 toggled : function (self, state) {
2823 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2828 label : "Auto Redraw On",
2829 pack : "pack_start,false,false,0"
2834 clicked : function (self) {
2835 this.get('/RightBrowser.view').redraws = 99;
2836 this.get('/RightBrowser.view').renderJS(null,true);
2839 label : "Full Redraw",
2840 pack : "pack_start,false,false,0"
2845 xtype: Gtk.ScrolledWindow,
2848 XObject.prototype.init.call(this);
2849 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2851 shadow_type : Gtk.ShadowType.IN,
2854 xtype: WebKit.WebView,
2856 load_finished : function (self, object) {
2857 print("load finished");
2858 // print("load_finished"); return;
2859 // if (this.ready) { // dont do it twice!
2862 if (!this.inspectorShown) {
2863 this.el.get_inspector().show();
2864 this.inspectorShown = true;
2869 if (this.pendingRedraw) {
2870 this.pendingRedraw = false;
2871 this.refreshRequired = true;
2873 //var js = this.get('/LeftTree.model').toJS();
2874 //if (js && js[0]) {
2875 // this.renderJS(js[0]);
2879 script_alert : function (self, object, p0) {
2882 return true; // do not display anything...
2884 console_message : function (self, object, p0, p1) {
2886 // console.log(object);
2889 if (object.match(/variable/) && object.match(/Builder/)) {
2890 print("got builder missing message");
2891 this.refreshRequired = true;
2892 this.lastRedraw = 0;
2898 if (!object.match(/^\{/)) {
2900 //this.get('/Terminal').feed(object);
2901 return true; // do not handle!!! -> later maybe in console..
2907 // console.log(object);
2908 var val = JSON.parse(object);
2910 if (typeof(val['hover-node']) != 'undefined') {
2911 this.activeNode = val['hover-node'];
2912 console.log('active node: ' + this.activeNode);
2917 if (typeof(val['id']) != 'undefined') {
2918 // this.activeNode = val['id'];
2919 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2920 if (!tg || typeof(tg[0]) == 'undefined') {
2923 print("SELECT node " + tg[0]);
2925 this.get('/LeftTree.view').selectNode(tg[0]);
2929 if (ret && typeof(val['set']) != 'undefined') {
2930 this.get('/LeftPanel.model').add({
2934 //console.log('active node: ' + this.activeNode);
2937 //Seed.print('a:'+a);
2938 //Seed.print('b:'+b);
2939 //Seed.print('c:'+c);
2942 drag_motion : function (w, ctx, x, y, time, ud) {
2943 // console.log('DRAG MOTION');
2945 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2946 this.targetData = [];
2947 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2949 // A) find out from drag all the places that node could be dropped.
2950 var src = Gtk.drag_get_source_widget(ctx);
2951 if (!src.dropList) {
2952 Gdk.drag_status(ctx, 0, time);
2955 // b) get what we are over.. (from activeNode)
2956 // tree is empty.. - list should be correct..
2957 if (!this.get('/LeftTree.model').currentTree) {
2958 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2962 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2964 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2967 Gdk.drag_status(ctx, 0,time);
2968 this.get('/LeftTree.view').highlight(false);
2972 // if we have a target..
2973 // -> highlight it! (in browser)
2974 // -> highlight it! (in tree)
2976 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2977 this.get('/LeftTree.view').highlight(tg);
2978 this.targetData = tg;
2979 // for tree we should handle this...
2982 drag_drop : function (w, ctx, x, y,time, ud) {
2983 print("TARGET: drag-drop");
2984 var is_valid_drop_site = true;
2989 w, /* will receive 'drag-data-received' signal */
2990 ctx, /* represents the current state of the DnD */
2991 this.get('/Window').atoms["STRING"], /* the target type we want */
2992 time /* time stamp */
2996 /* No target offered by source => error */
2999 return is_valid_drop_site;
3001 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3003 print("Browser: drag-data-received");
3004 var delete_selection_data = false;
3005 vardnd_success = false;
3006 /* Deal with what we are given from source */
3007 if( sel_data && sel_data.length ) {
3009 if (ctx.action == Gdk.DragAction.ASK) {
3010 /* Ask the user to move or copy, then set the ctx action. */
3013 if (ctx.action == Gdk.DragAction.MOVE) {
3014 delete_selection_data = true;
3016 var source = Gtk.drag_get_source_widget(ctx);
3018 print("Browser: source.DRAGDATA? " + source.dragData);
3019 if (this.targetData) {
3020 print(this.targetData);
3021 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3030 if (dnd_success == false)
3032 Seed.print ("DnD data transfer failed!\n");
3035 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3038 create_web_view : function (self, object) {
3039 print("CREATE WEB VIEW");
3040 return null; //new WebKit.WebView();
3047 XObject.prototype.init.call(this);
3048 // this may not work!?
3049 var settings = this.el.get_settings();
3050 settings.enable_developer_extras = true;
3052 // this was an attempt to change the url perms.. did not work..
3053 // settings.enable_file_access_from_file_uris = true;
3054 // settings.enable_offline_web_application_cache - true;
3055 // settings.enable_universal_access_from_file_uris = true;
3059 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3060 _this.get('/BottomPane.inspector').el.show();
3061 return _this.get('/BottomPane.inspector').el;
3065 // FIXME - base url of script..
3066 // we need it so some of the database features work.
3067 this.el.load_html_string( "Render not ready" ,
3068 //fixme - should be a config option!
3069 // or should we catch stuff and fix it up..
3070 'http://localhost/app.Builder/'
3074 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3078 this.el, /* widget that will accept a drop */
3079 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3080 null, /* lists of target to support */
3081 0, /* size of list */
3082 Gdk.DragAction.COPY /* what to do with data after dropped */
3085 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3086 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3088 GLib.timeout_add_seconds(0, 1, function() {
3089 // print("run refresh?");
3096 renderJS : function(data, force) {
3098 // this is the public redraw call..
3099 // we refresh in a loop privately..
3100 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3101 if (!autodraw && !force) {
3102 print("Skipping redraw - no force, and autodraw off");
3105 this.refreshRequired = true;
3107 runRefresh : function()
3109 // this is run every 2 seconds from the init..
3113 if (!this.refreshRequired) {
3114 // print("no refresh required");
3118 if (this.lastRedraw) {
3119 // do not redraw if last redraw was less that 5 seconds ago.
3120 if (((new Date()) - this.lastRedraw) < 5000) {
3128 if (!this.get('/Window.LeftTree').getActiveFile()) {
3131 this.refreshRequired = false;
3132 // print("HTML RENDERING");
3134 this.get('/BottomPane').el.show();
3135 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3138 var js = this.get('/LeftTree.model').toJS();
3139 if (!js || !js.length) {
3146 var project = this.get('/Window.LeftTree').getActiveFile().project;
3147 //print (project.fn);
3148 // set it to non-empty.
3149 project.runhtml = project.runhtml || '';
3150 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3153 this.runhtml = this.runhtml || '';
3155 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3156 // then we need to reload the browser using
3157 // load_html_string..
3159 // then trigger a redraw once it's loaded..
3160 this.pendingRedraw = true;
3161 var runhtml = '<script type="text/javascript">' + "\n" ;
3162 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3163 runhtml += '</script>'+ "\n" ;
3165 this.runhtml = project.runhtml;
3166 // need to modify paths
3170 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3171 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3172 print("LOAD HTML " + html);
3173 this.el.load_html_string( html ,
3174 //fixme - should be a config option!
3175 'http://localhost/app.Builder/'
3178 // should trigger load_finished! - which in truns shoudl set refresh Required;
3184 this.renderedData = data;
3185 var str = JSON.stringify(data) ;
3188 console.log('not loaded yet');
3190 this.lastRedraw = new Date();
3192 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3193 print( "before render" + this.lastRedraw);
3194 print( "after render" + (new Date()));
3204 id : "RightGtkView",
3206 redraw : function() {
3207 this.highlightWidget = false;
3208 print("REDRAW CALLED");
3209 this.activePath = this.get('/LeftTree').getActivePath();
3210 if (this.renderedEl) {
3211 print("QUEUE DRAW CALLING");
3212 this.renderedEl.queue_draw();
3215 renderJS : function(data, withDebug)
3217 this.highlightWidget = false;
3219 this.withDebug = false;
3220 while (this.get('view').el.get_children().length) {
3221 var c = this.get('view').el.get_children()[0];
3222 this.get('view').el.remove(c);
3229 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3230 // in theory tree is actually window..
3233 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3239 this.get('view').el.set_size_request(
3240 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3242 if (this.renderedEl) {
3243 this.renderedEl.set_size_request(
3244 tree.default_width || 600,
3245 tree.default_height || 400
3248 this.get('view').el.show_all();
3253 showInWindow : function() {
3254 print("GET PROEJCT");
3255 var pr = this.get('/LeftProjectTree').getActiveProject();
3257 console.log(pr.paths);
3260 var src= this.buildJS(
3261 this.get('/LeftTree.model').toJS()[0],
3266 //var x = new imports.sandbox.Context();
3270 Seed.check_syntax('var e = ' + src);
3273 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3274 this.get('/Terminal').feed(console._dump(e)+"\n");
3276 var lines = src.split("\n");
3277 var start = Math.max(0, e.line - 10);
3278 var end = Math.min(lines.length, e.line + 10);
3279 for (var i =start ; i < end; i++) {
3281 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3284 this.get('/Terminal').feed(lines[i] + "\n");
3291 this.get('/BottomPane').el.set_current_page(1);
3292 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3293 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3294 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3296 var _top = x.get_global_object()._top;
3298 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3300 if (_top.el.popup) {
3301 _top.el.popup(null, null, null, null, 3, null);
3305 viewAdd : function(item, par)
3308 // does something similar to xobject..
3309 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3311 // pack is forced to 'false'
3312 if (item.pack===false || item.pack === 'false') { // no ;
3316 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3319 var type = item['|xns'] + '.' + item['xtype'];
3321 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3325 var ns = imports.gi[item['|xns']];
3326 var ctr = ns[item['xtype']]; // why are we using array here..?
3331 for(var k in item) {
3333 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3347 // value is a function..
3348 if (k[0] == '|' && typeof(kv) == 'string') {
3350 if (kv.match(new RegExp('function'))) {
3353 print("WASL " + k + '=' + kv);
3355 eval( 'kv = ' + kv);
3356 } catch(e) { continue; }
3359 // print(k + '=' + kv);
3361 if (k[0] == '|') { // should be boolean or number..
3363 //print(k + '=' + kv);
3366 if (k == 'show_tabs') { // force tab showing for notebooks.
3369 print(k + '=' + typeof(kv) + " : " + kv);
3373 var altctr = XObject.baseXObject({ xtype: ctr} );
3375 if (!item.pack && altctr) {
3377 print("SETTING PACK TO XObjectBase method");
3378 pack_m = altctr.prototype.pack;
3383 var el = new ctr(ctr_args);
3385 print("PACK" + item.pack);
3386 //console.dump(item.pack);
3393 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3394 if (typeof(item.pack) == 'string') {
3396 item.pack.split(',').forEach(function(e, i) {
3398 if (e == 'false') { args.push( false); return; }
3399 if (e == 'true') { args.push( true); return; }
3400 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3403 //print(args.join(","));
3405 pack_m = args.shift();
3407 pack_m = item.pack.shift();
3412 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3414 name: "ArgumentError",
3415 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3416 "ADDING : " + item.id + " " + el
3425 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3426 //Seed.print('args: ' + args.length);
3427 if (typeof(pack_m) == 'string') {
3428 par[pack_m].apply(par, args);
3429 } else if (pack_m) {
3430 pack_m.call(item, par, item);
3434 item.items = item.items || [];
3435 item.items.forEach(function(ch,n) {
3437 print ("type:" + type);
3439 print ("ch.pack:" + ch.pack);
3442 if (type == 'Gtk.Table' && ch.pack == 'add') {
3443 var c = n % item.n_columns;
3444 var r = Math.floor(n/item.n_columns);
3445 ch.pack = [ 'attach', c, c+1, r, r+1,
3446 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3447 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3448 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3449 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3453 _this.viewAdd(ch, el);
3458 // add the signal handlers.
3459 // is it a widget!?!!?
3465 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3466 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3467 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3468 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3469 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3479 widgetDragDropEvent : function() {
3480 print("WIDGET DRAGDROP");
3483 widgetDragMotionEvent : function() {
3484 print("WIDGET DRAGMOTION");
3487 widgetExposeEvent : function(w, evt, ud, item) {
3489 if (this.inRender) {
3493 if ( this.highlightWidget) {
3494 this.inRender = true;
3495 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3496 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3498 this.inRender = false;
3503 if (this.activePath != item.xtreepath) {
3507 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3508 // work out the coords of the window..
3510 var dr = widget.window;
3511 this.gc = (new Gdk.GC.c_new(dr));
3512 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3513 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3517 var r = evt.expose.area;
3518 // console.dump([r.x, r.y, r.width, r.height ] );
3520 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3521 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3522 // happens with gtkscrollview embedded stuff..
3523 var np =this.activePath.split(':');
3525 this.activePath = np.join(':');
3526 this.renderedEl.queue_draw();
3542 this.inRender = true;
3545 this.highlightWidget = widget;
3550 // print("DRAW BOX");
3551 //console.dump(this.box);
3552 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3553 this.inRender = false;
3556 widgetPressEvent : function(w,e,u,d) {
3557 if (this.get('view').pressed) {
3560 this.get('view').pressed = true;
3561 print("WIDGET PRESS " + d.xtreepath );
3562 this.get('/LeftTree.view').selectNode( d.xtreepath );
3565 widgetReleaseEvent : function() {
3566 this.get('view').pressed = false;
3572 pack : "pack_start,false,true,0",
3576 pack : "pack_start,false,false,0",
3577 label : "Run The Application",
3579 button_press_event : function (self, event) {
3580 // call render on left tree - with special option!?!
3582 //print("GET PROEJCT");
3583 var pr = this.get('/LeftProjectTree').getActiveProject();
3586 for (var i in pr.paths) {
3590 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3591 this.get('/Terminal').feed("RUN DIR:" + dir);
3593 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3594 , false,false,false);
3595 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3596 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3606 xtype: Gtk.ScrolledWindow,
3609 shadow_type : Gtk.ShadowType.IN,
3611 XObject.prototype.init.call(this);
3612 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3616 xtype: Gtk.EventBox,
3617 pack : "add_with_viewport",
3619 XObject.prototype.init.call(this);
3620 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3621 red: 0x9F00, green: 0xB800 , blue : 0xA800
3629 XObject.prototype.init.call(this);
3630 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3631 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3636 xtype: Gtk.EventBox,
3639 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3640 XObject.prototype.init.call(this);
3644 this.el, /* widget that will accept a drop */
3645 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3646 null, /* lists of target to support */
3647 0, /* size of list */
3648 Gdk.DragAction.COPY /* what to do with data after dropped */
3651 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3652 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3655 getActiveNode : function(x,y)
3657 // workout what node is here..
3658 return '0'; // top..
3662 drag_motion : function (self, ctx, x, y, time) {
3664 // A) find out from drag all the places that node could be dropped.
3665 var src = Gtk.drag_get_source_widget(ctx);
3666 if (!src.dropList) {
3667 Gdk.drag_status(ctx, 0, time);
3670 // b) get what we are over.. (from activeNode)
3671 // tree is empty.. - list should be correct..
3672 if (!this.get('/LeftTree.model').currentTree) {
3673 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3677 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3678 var activeNode = this.getActiveNode(x, y);
3681 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3684 Gdk.drag_status(ctx, 0,time);
3685 this.get('/LeftTree.view').highlight(false);
3689 // if we have a target..
3690 // -> highlight it! (in browser)
3691 // -> highlight it! (in tree)
3693 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3694 this.get('/LeftTree.view').highlight(tg);
3695 this.targetData = tg;
3696 // for tree we should handle this...
3699 drag_drop : function (self,ctx, x, y, time) {
3700 Seed.print("TARGET: drag-drop");
3701 var is_valid_drop_site = true;
3706 self, /* will receive 'drag-data-received' signal */
3707 ctx, /* represents the current state of the this.gDnD */
3708 this.get('/Window').atoms["STRING"], /* the target type we want */
3709 time /* time stamp */
3713 /* No target offered by source => error */
3716 return is_valid_drop_site;
3719 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3721 Seed.print("GtkView: drag-data-received");
3722 var delete_selection_data = false;
3723 var dnd_success = false;
3724 /* Deal with what we are given from source */
3725 if( sel_data && sel_data.length ) {
3727 if (ctx.action == Gdk.DragAction.ASK) {
3728 /* Ask the user to move or copy, then set the ctx action. */
3731 if (ctx.action == Gdk.DragAction.MOVE) {
3732 delete_selection_data = true;
3734 var source = Gtk.drag_get_source_widget(ctx);
3736 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3737 if (this.targetData) {
3738 Seed.print(this.targetData);
3739 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3748 if (dnd_success == false)
3750 Seed.print ("DnD data transfer failed!\n");
3753 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3756 button_press_event : function (self, event) {
3757 this.pressed = false;
3773 xtype: Gtk.ScrolledWindow,
3778 var file = this.get('/LeftTree').getActiveFile();
3782 var activeEl = this.get('/LeftTree').getActiveElement();
3783 var xtype = file.guessName( activeEl )
3784 if (!xtype || !xtype.length) {
3787 //this.get('/Window.view-help-nb').el.set_current_page(1);
3789 // get the active element being edited.
3790 var helpurl = file.getHelpUrl(xtype);
3792 // now load the help info in the page..
3793 this.get('help-view').el.open(helpurl);
3797 xtype: WebKit.WebView,
3801 XObject.prototype.init.call(this);
3802 this.get('/Window.help-view').el.open(
3803 "http://devel.akbkhome.com/seed/");
3815 xtype: Gtk.Notebook,
3819 XObject.prototype.init.call(this);
3820 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3821 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3822 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3826 xtype: Gtk.ScrolledWindow,
3830 xtype: Vte.Terminal,
3833 feed : function(istr) {
3834 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3835 // we should make ourselves visable!!!
3836 this.get('/BottomPane').el.show();
3837 this.get('/BottomPane').el.set_current_page(1);
3839 this.el.feed(str ,str.length);
3841 scroll_on_output : true,
3843 XObject.prototype.init.call(this);
3844 this.el.set_size (80, 1000);
3846 scrollback_lines : 1000
3851 xtype: Gtk.ScrolledWindow,
3855 xtype: WebKit.WebView,
3867 pack : "pack_start,false,false",
3871 this.get('buttonbar').el.show();
3872 this.get('viewbox').el.hide();
3873 print("TRIED TO HIDE");
3876 this.get('buttonbar').el.hide();
3877 this.get('viewbox').el.show();
3878 // this.get('model').expanded();
3890 pack : "pack_start,false,true",
3892 clicked : function (self) {
3893 this.get('/RightPalete').show();
3900 stock : Gtk.STOCK_GOTO_FIRST,
3901 icon_size : Gtk.IconSize.MENU
3911 XObject.prototype.init.call(this);
3912 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3915 enter_notify_event : function (self, event) {
3916 this.get('/RightPalete').show();
3930 pack : "pack_start,false,true",
3939 pack : "pack_start,false,true",
3941 clicked : function (self) {
3942 this.get('/RightPalete').hide();
3949 stock : Gtk.STOCK_GOTO_LAST,
3950 icon_size : Gtk.IconSize.MENU
3957 xtype: Gtk.ScrolledWindow,
3960 XObject.prototype.init.call(this);
3961 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3962 this.el.set_size_request(-1,200);
3964 shadow_type : Gtk.ShadowType.IN,
3967 xtype: Gtk.TreeView,
3969 drag_begin : function (self, ctx) {
3970 // we could fill this in now...
3971 Seed.print('SOURCE: drag-begin');
3975 var iter = new Gtk.TreeIter();
3976 var s = this.selection;
3977 s.get_selected(this.get('/RightPalete.model').el, iter);
3978 var path = this.get('/RightPalete.model').el.get_path(iter);
3980 var pix = this.el.create_row_drag_icon ( path);
3983 Gtk.drag_set_icon_pixmap (ctx,
3990 var value = new GObject.Value('');
3991 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3992 if (!this.get('/RightPalete').provider) {
3995 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3996 this.el.dragData = value.value;
4003 drag_data_get : function (self, drag_context, selection_data, info, time) {
4004 //Seed.print('Palete: drag-data-get: ' + target_type);
4005 if (this.el.dragData && this.el.dragData.length ) {
4006 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4010 //this.el.dragData = "TEST from source widget";
4014 drag_end : function (self, drag_context) {
4015 Seed.print('SOURCE: drag-end');
4016 this.el.dragData = false;
4017 this.el.dropList = false;
4018 this.get('/LeftTree.view').highlight(false);
4021 button_press_event : function (self, event) {
4023 if (!this.get('/Editor').save()) {
4024 // popup!! - click handled..
4031 enable_tree_lines : true,
4032 headers_visible : false,
4034 XObject.prototype.init.call(this);
4035 this.el.set_size_request(150,-1);
4036 // set_reorderable: [1]
4038 var description = new Pango.FontDescription.c_new();
4039 description.set_size(8000);
4040 this.el.modify_font(description);
4042 this.selection = this.el.get_selection();
4043 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4044 // this.selection.signal['changed'].connect(function() {
4045 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4047 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4049 Gtk.drag_source_set (
4050 this.el, /* widget will be drag-able */
4051 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4052 null, /* lists of target to support */
4053 0, /* size of list */
4054 Gdk.DragAction.COPY /* what to do with data after dropped */
4056 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4058 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
4059 Gtk.drag_source_add_text_targets(this.el);
4061 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4062 targets = new Gtk.TargetList();
4063 targets.add( LeftTree.atoms["STRING"], 0, 0);
4064 targets.add_text_targets( 1 );
4065 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4067 //if you want to allow text to be output elsewhere..
4068 //Gtk.drag_source_add_text_targets(this.el);
4074 xtype: Gtk.ListStore,
4077 XObject.prototype.init.call(this);
4078 this.el.set_column_types ( 2, [
4079 GObject.TYPE_STRING, // title
4080 GObject.TYPE_STRING // tip
4085 load : function(tr,iter)
4090 //console.log('Project tree load: ' + tr.length);
4091 var citer = new Gtk.TreeIter();
4092 //this.insert(citer,iter,0);
4093 for(var i =0 ; i < tr.length; i++) {
4096 this.el.append(citer);
4098 this.el.insert(citer,iter,-1);
4103 this.el.set_value(citer, 0, '' + r ); // title
4105 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4106 //if (r.cn && r.cn.length) {
4107 // this.load(r.cn, citer);
4113 getValue : function (iter, col) {
4114 var gval = new GObject.Value('');
4115 this.el.get_value(iter, col ,gval);
4122 xtype: Gtk.TreeViewColumn,
4123 pack : "append_column",
4125 XObject.prototype.init.call(this);
4126 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4130 xtype: Gtk.CellRendererText,
4152 XObject.cache['/Window'] = Window;