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,
1472 changed : function (self) {
1473 var fn = this.getValue();
1474 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1475 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1479 getValue : function() {
1480 var ix = this.el.get_active();
1484 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1485 if (typeof(data[ix]) == 'undefined') {
1491 XObject.prototype.init.call(this);
1492 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1494 setValue : function(fn)
1498 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1499 data.forEach(function(n, ix) {
1508 xtype: Gtk.CellRendererText,
1509 pack : "pack_start,true",
1513 xtype: Gtk.ListStore,
1517 XObject.prototype.init.call(this);
1518 this.el.set_column_types ( 2, [
1519 GObject.TYPE_STRING, // real key
1520 GObject.TYPE_STRING // real type
1524 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1525 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1527 pm.on('changed', function() {
1528 print("caught changed hook on project manager - reloading data");
1529 _this.loadData(pm.projects);
1533 loadData : function(data) {
1534 var ov = this.get('/LeftProjectTree.combo').getValue();
1536 var iter = new Gtk.TreeIter();
1538 data.forEach(function(p) {
1543 el.set_value(iter, 0, p.fn);
1544 el.set_value(iter, 1, p.name);
1548 this.get('/LeftProjectTree.combo').setValue(ov);
1556 xtype: Gtk.ScrolledWindow,
1558 shadow_type : Gtk.ShadowType.IN,
1560 XObject.prototype.init.call(this);
1561 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1565 xtype: Gtk.TreeView,
1567 cursor_changed : function (self) {
1568 var iter = new Gtk.TreeIter();
1570 if (this.selection.count_selected_rows() < 1) {
1571 //XN.get('Builder.LeftTree.model').
1572 this.get('/LeftTree.model').load( false);
1576 var model = this.get('/LeftProjectTree.model');
1577 //console.log('changed');
1578 var s = this.selection;
1579 s.get_selected(model, iter);
1580 value = new GObject.Value('');
1581 model.el.get_value(iter, 2, value);
1583 console.log(value.value);// id..
1585 var file = this.get('/LeftProjectTree').project.getById(value.value);
1592 var nb = this.get('/LeftTopPanel.expander');
1593 nb.el.expanded = false;
1595 //nb.listeners.activate.call(nb);
1596 //_expander.el.set_expanded(false);
1598 var ltm = this.get('/LeftTree.model');
1606 enable_tree_lines : true,
1607 headers_visible : false,
1609 XObject.prototype.init.call(this);
1610 var description = new Pango.FontDescription.c_new();
1611 description.set_size(8000);
1612 this.el.modify_font(description);
1614 this.selection = this.el.get_selection();
1615 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1619 xtype: Gtk.TreeStore,
1623 XObject.prototype.init.call(this);
1624 this.el.set_column_types ( 3, [
1625 GObject.TYPE_STRING, // title
1626 GObject.TYPE_STRING, // tip
1627 GObject.TYPE_STRING // id..
1631 loadProject : function(pr) {
1632 print("LOAD PROJECT");
1638 this.get('/LeftProjectTree').project = pr;
1639 this.load(pr.toTree());
1640 this.get('/LeftProjectTree.view').el.expand_all();
1642 load : function(tr,iter) {
1643 // console.dump(tr);
1644 console.log('Project tree load: ' + tr.length);
1645 var citer = new Gtk.TreeIter();
1646 //this.insert(citer,iter,0);
1649 tr.forEach(function (r) {
1651 _this.el.append(citer);
1653 _this.el.insert(citer,iter,-1);
1655 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1656 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1657 _this.el.set_value(citer, 2, '' + r.id ); //id
1658 if (r.cn && r.cn.length) {
1659 _this.load(r.cn, citer);
1664 getValue : function(iter, col) {
1665 var gval = new GObject.Value('');
1666 this.el.get_value(iter, col ,gval);
1667 return '' + gval.value;
1671 xtype: Gtk.TreeViewColumn,
1672 pack : "append_column",
1674 XObject.prototype.init.call(this);
1675 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1679 xtype: Gtk.CellRendererText,
1699 pack : "pack_start,false,true,0",
1706 button_press_event : function (self, event) {
1707 this.get('/MidPropTree.model').showData('props');
1719 stock : Gtk.STOCK_ADD,
1720 icon_size : Gtk.IconSize.MENU
1734 button_press_event : function (self, event) {
1736 if (!this.get('/Editor').save()) {
1737 // popup!! - click handled..
1740 this.get('/MidPropTree.model').showData('events');
1753 stock : Gtk.STOCK_ADD,
1754 icon_size : Gtk.IconSize.MENU
1768 button_press_event : function (self, ev) {
1770 if (!this.get('/Editor').save()) {
1771 // popup!! - click handled..
1775 var p = this.get('/AddPropertyPopup');
1779 p.el.set_screen(Gdk.Screen.get_default());
1781 p.el.popup(null, null, null, null, 3, ev.button.time);
1794 stock : Gtk.STOCK_ADD,
1795 icon_size : Gtk.IconSize.MENU
1807 id : "AddPropertyPopup",
1810 xtype: Gtk.MenuItem,
1812 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1815 activate : function (self) {
1817 this.get('/LeftPanel.model').add( {
1828 xtype: Gtk.MenuItem,
1830 tooltip_markup : "Add what type of packing is to be used",
1833 activate : function (self) {
1835 this.get('/LeftPanel.model').add( {
1845 xtype: Gtk.MenuItem,
1847 tooltip_markup : "Override the init method",
1850 activate : function (self) {
1852 this.get('/LeftPanel.model').add( {
1855 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1862 xtype: Gtk.SeparatorMenuItem,
1866 xtype: Gtk.MenuItem,
1868 tooltip_markup : "Add a user defined string property",
1871 activate : function (self) {
1873 this.get('/LeftPanel.model').add( {
1883 xtype: Gtk.MenuItem,
1885 tooltip_markup : "Add a user defined number property",
1888 activate : function (self) {
1890 this.get('/LeftPanel.model').add( {
1900 xtype: Gtk.MenuItem,
1902 tooltip_markup : "Add a user defined boolean property",
1905 activate : function (self) {
1907 this.get('/LeftPanel.model').add( {
1917 xtype: Gtk.SeparatorMenuItem,
1921 xtype: Gtk.MenuItem,
1923 tooltip_markup : "Add a user function boolean property",
1926 activate : function (self) {
1928 this.get('/LeftPanel.model').add( {
1931 val : "function() {\n \n}\n",
1944 xtype: Gtk.ScrolledWindow,
1949 XObject.prototype.init.call(this);
1950 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1952 shadow_type : Gtk.ShadowType.IN,
1955 xtype: Gtk.TreeView,
1957 button_press_event : function (self, ev) {
1960 if (!this.get('/Editor').save()) {
1961 // popup!! - click handled..
1966 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1967 return false; //not on a element.
1971 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
1973 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
1976 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1977 var p = this.get('/LeftPanelPopup');
1982 p.el.set_screen(Gdk.Screen.get_default());
1984 p.el.popup(null, null, null, null, 3, ev.button.time);
1985 //Seed.print("click:" + res.column.title);
1992 if (res.column.title != 'value') {
1993 // XObject.error("column is not value?");
1994 return false; // ignore.. - key click.. ??? should we do this??
1997 // currently editing???
1998 // if ( this.activePath) {
2000 // this.activePath = false;
2002 if (this.get('/Editor').dirty) {
2003 //if (!this.get('/Editor.buffer').checkSyntax()) {
2004 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2008 if (!this.get('/Editor.view').save()) {
2012 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2013 this.get('/LeftPanel').editing = false;
2015 // XObject.error("Currently editing?");
2019 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2021 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2023 // get options for this type -- this is to support option lists etc..
2024 var provider = this.get('/LeftTree').getPaleteProvider();
2025 var opts = provider.findOptions(type);
2027 if (opts === false) {
2029 this.get('/LeftPanel').editableColumn.setOptions([]);
2030 renderer.has_entry = true;
2032 this.get('/LeftPanel').editableColumn.setOptions(opts);
2033 renderer.has_entry = false;
2035 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2037 //Seed.print("click" + ev.type);
2038 //console.dump(res);
2047 enable_tree_lines : true,
2048 headers_visible : false,
2050 XObject.prototype.init.call(this);
2052 this.selection = this.el.get_selection();
2053 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2056 var description = new Pango.FontDescription.c_new();
2057 description.set_size(8000);
2058 this.el.modify_font(description);
2062 xtype: Gtk.TreeStore,
2066 add : function(info) {
2067 // info includes key, val, skel, etype..
2069 type = info.type.toLowerCase();
2070 var data = this.toJS();
2072 if (info.etype == 'events') {
2073 data.listeners = data.listeners || { };
2074 if (typeof(data.listeners[info.key]) != 'undefined') {
2075 return; //already set!
2078 if (typeof(data[info.key]) != 'undefined') {
2083 if (typeof(info.val) == 'undefined') {
2086 if (info.type.toLowerCase() == 'boolean') {
2089 if (type == 'number') {
2097 if (info.etype == 'events') {
2099 data.listeners[info.key] = info.val;
2102 data[info.key] = info.val;
2106 var map = this.load(data);
2108 // flag it as changed to the interface..
2110 this.get('/LeftTree.model').changed(data, true);
2113 this.startEditing(map[k]);
2116 LeftPanel.get('view').el.row_activated(
2117 new Gtk.TreePath.from_string(map[k]),
2118 LeftPanel.editableColumn.el
2122 changed : function(str, doRefresh) {
2123 if (!this.activePath) {
2126 var iter = new Gtk.TreeIter();
2127 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2129 this.el.set_value(iter, 1, '' +str);
2130 this.el.set_value(iter, 3, '' + this.toShort(str));
2131 var type = this.getIterValue(iter, 4);
2133 this.el.set_value(iter, 5, type + ' : ' + str);
2134 // update the tree...
2136 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2138 deleteSelected : function() {
2139 var data = this.toJS();
2140 var iter = new Gtk.TreeIter();
2141 var s = this.get('/LeftPanel.view').selection;
2142 s.get_selected(this.el, iter);
2145 var gval = new GObject.Value('');
2146 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2148 var val = gval.value;
2149 if (val[0] == '!') {
2151 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2154 delete data.listeners[ val.substring(1)];
2155 if (!XObject.keys(data.listeners).length) {
2156 delete data.listeners;
2160 if (typeof(data[val]) == 'undefined') {
2168 this.get('/LeftTree.model').changed(data, true);
2171 getIterValue : function(iter, col) {
2172 var gval = new GObject.Value('');
2173 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2174 return '' + gval.value;
2176 getType : function(treepath) {
2177 return this.getValue(treepath, 4);
2179 getValue : function(treepath_str, col)
2181 // get's the value in a row.. - keys - returns string, values - formats it..
2183 var iter = new Gtk.TreeIter();
2184 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2186 var gval = new GObject.Value('');
2187 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2188 var val = '' + gval.value;
2193 var type = this.getType(this.el.get_path(iter).to_string());
2194 //print("TYPE: " +type + " - val:" + val);
2195 switch(type.toLowerCase()) {
2199 return parseFloat(val); // Nan ?? invalid!!?
2202 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2204 return val == 'true' ? true : false;
2206 var nv = parseFloat(val);
2207 if (!isNaN(nv) && (val == ''+nv)) {
2215 XObject.prototype.init.call(this);
2216 this.el.set_column_types ( 6, [
2217 GObject.TYPE_STRING, // 0 real key
2218 GObject.TYPE_STRING, // 1 real value
2219 GObject.TYPE_STRING, // 2 visable key
2220 GObject.TYPE_STRING, // 3 visable value
2221 GObject.TYPE_STRING, // 4 need to store type of!!!
2222 GObject.TYPE_STRING // 5 tooltip
2226 load : function(ar) {
2227 // might casue problesm..
2228 // this.get('/Editor.RightEditor').save();
2230 this.get('/Editor').el.hide();
2231 this.get('/Editor').activePath = false;
2236 //this.get('/RightEditor').el.hide();
2243 var provider = this.get('/LeftTree').getPaleteProvider();
2244 var iter = new Gtk.TreeIter();
2247 var keys = XObject.keys(ar);
2249 ar.listeners = ar.listeners || {};
2251 for (var i in ar.listeners ) {
2252 this.el.append(iter);
2253 var p = this.el.get_path(iter).to_string();
2256 this.el.set_value(iter, 0, '!'+ i );
2257 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2258 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2260 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2261 this.el.set_value(iter, 4, 'function');
2262 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2268 keys.forEach(function(i) {
2269 if (typeof(ar[i]) == 'object') {
2273 var type = provider.findType(ar, i, ar[i]);
2275 _this.el.append(iter);
2276 var p = _this.el.get_path(iter).to_string();
2278 _this.el.set_value(iter, 0, ''+i);
2279 _this.el.set_value(iter, 1, '' + ar[i]);
2280 _this.el.set_value(iter, 2, ''+i);
2281 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2282 _this.el.set_value(iter, 4, ''+type);
2283 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2287 startEditing : function(path,col) {
2289 // alled by menu 'edit' currently..
2291 * start editing path (or selected if not set..)
2292 * @param {String|false} path (optional) treepath to edit - selected tree gets
2293 * edited by default.
2294 * @param {Number} 0 or 1 (optional)- column to edit.
2296 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2298 if (typeof(path) == 'string') {
2299 tp = new Gtk.TreePath.from_string(path);
2301 var iter = new Gtk.TreeIter();
2302 var s = this.get('/LeftPanel.view').selection;
2303 s.get_selected(this.el, iter);
2304 tp = this.el.get_path(iter);
2305 path = tp.to_string();
2309 // which colum is to be edited..
2312 // not sure what this does..
2314 if (typeof(col) == 'undefined') {
2315 var k = this.getValue(path, 0);
2317 colObj = (!k.length || k == '|') ?
2318 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2320 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2323 // make sure the pulldown is set correctly..
2324 // not really needed for second col...
2325 var showEditor = false;
2326 this.get('/Editor').activePath = false;
2327 this.get('/Editor').el.hide();
2330 var provider = this.get('/LeftTree').getPaleteProvider();
2331 var type = this.get('/LeftPanel.model').getType(path);
2332 var opts = provider.findOptions(type);
2333 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2335 if (opts === false) {
2336 this.get('/LeftPanel').editableColumn.setOptions([]);
2337 renderer.has_entry = true;
2339 this.get('/LeftPanel').editableColumn.setOptions(opts);
2340 renderer.has_entry = false;/// - pulldowns do not have entries
2342 // determine if we should use the Text editor...
2343 var keyname = this.getValue(path, 0);
2344 var data_value = this.getValue(path, 1);
2346 if ((keyname[0] == '|') ||
2348 (typeof(data_value) == 'string' ) &&
2349 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2353 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2358 // this.get('/BottomPane').el.hide();
2359 //this.get('/RightEditor').el.hide();
2364 this.activePath = false;
2366 _this.get('/Editor').el.show_all();
2367 GLib.timeout_add(0, 1, function() {
2369 //_this.get('/BottomPane').el.show();
2370 //_this.get('/RightEditor').el.show();
2372 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2374 _this.get('/Editor').activePath = path;
2375 _this.activePath = path ;
2385 // iter now has row...
2386 GLib.timeout_add(0, 100, function() {
2387 _this.activePath = path;
2388 colObj.items[0].el.editable = true; // esp. need for col 0..
2389 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2399 var iter = new Gtk.TreeIter();
2400 this.get('/LeftPanel.model').el.get_iter_first(iter);
2405 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2408 ar.listeners = ar.listeners || {};
2409 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2412 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2415 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2421 //print(JSON.stringify(ar));
2425 toShort : function(str) {
2426 var a = typeof(str) == 'string' ? str.split("\n") : [];
2427 return a.length > 1 ? a[0] + '....' : '' + str;
2431 xtype: Gtk.TreeViewColumn,
2432 pack : "append_column",
2434 XObject.prototype.init.call(this);
2436 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2437 this.get('/LeftPanel').propertyColumn = this;
2442 xtype: Gtk.CellRendererText,
2443 pack : "pack_start",
2445 editing_started : function (self, editable, path) {
2447 this.get('/LeftPanel.model').activePath = path;
2450 edited : function (self, object, p0) {
2451 var model = this.get('/LeftPanel.model');
2452 var path = model.activePath;
2453 var iter = new Gtk.TreeIter();
2454 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2455 model.el.set_value(iter, 0, p0);
2456 model.el.set_value(iter, 2, p0);
2458 model.activePath = false;
2460 this.get('/LeftTree.model').changed(model.toJS(), true);
2461 this.el.editable = false;
2468 xtype: Gtk.TreeViewColumn,
2469 pack : "append_column",
2472 XObject.prototype.init.call(this);
2473 this.el.add_attribute(this.items[0].el , 'text', 3 );
2474 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2475 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2476 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2478 this.get('/LeftPanel').editableColumn= this;
2480 setOptions : function(ar) {
2481 var m = this.items[0].el.model;
2483 var iter = new Gtk.TreeIter();
2484 ar.forEach(function(i) {
2487 m.set_value(iter, 0, i);
2493 xtype: Gtk.CellRendererCombo,
2495 edited : function (self, object, p0) {
2496 this.get('/LeftPanel').editing = false;
2497 var ap = this.get('/LeftPanel.model').activePath
2498 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2499 this.get('/LeftPanel.model').changed(p0, true);
2500 this.get('/LeftPanel.model').activePath = false;
2501 this.el.editable = false;
2503 editing_started : function (self, editable, path) {
2504 this.get('/LeftPanel').editing = true;
2505 // console.log('editing started');
2506 // r.has_entry = false;
2508 this.el.editable = false; // make sure it's not editor...
2513 pack : "pack_start",
2517 XObject.prototype.init.call(this);
2518 this.el.model = new Gtk.ListStore();
2519 this.el.model.set_column_types ( 1, [
2520 GObject.TYPE_STRING // 0 real key
2531 id : "LeftPanelPopup",
2534 xtype: Gtk.MenuItem,
2538 activate : function (self) {
2539 this.get('/LeftPanel.model').deleteSelected();
2544 xtype: Gtk.MenuItem,
2548 activate : function (self) {
2549 this.get('/LeftPanel.model').startEditing(false, 0);
2562 xtype: Gtk.ScrolledWindow,
2563 pack : "pack_end,false,true,0",
2565 shadow_type : Gtk.ShadowType.IN,
2567 XObject.prototype.init.call(this);
2568 XObject.prototype.init.call(this);
2569 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2570 this.el.set_size_request ( 150, -1 );
2573 activeElement : false,
2574 hideWin : function() {
2581 if (this.get('/Window.left').el.position < 160) {
2584 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2591 xtype: Gtk.TreeView,
2593 cursor_changed : function (self) {
2594 var iter = new Gtk.TreeIter();
2596 //console.log('changed');
2597 var m = this.get('model');
2598 if (!this.selection){
2599 this.selection = this.el.get_selection();
2602 var s = this.selection;
2603 if (!s.get_selected(m.el, iter)) {
2606 var tp = m.el.get_path(iter).to_string();
2611 var key = m.getValue(tp, 0);
2613 var type = m.getValue(tp, 1);
2614 var skel = m.getValue(tp, 3);
2615 var etype = m.getValue(tp, 5);
2618 this.get('/MidPropTree').hideWin();
2620 if (type.toLowerCase() == 'function') {
2622 if (etype != 'events') {
2626 this.get('/LeftPanel.model').add({
2634 // has dot in name, and is boolean???? this does not make sense..
2635 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2639 this.get('/LeftPanel.model').add( {
2649 enable_tree_lines : true,
2650 headers_visible : false,
2652 XObject.prototype.init.call(this);
2654 var description = new Pango.FontDescription.c_new();
2655 description.set_size(8000);
2656 this.el.modify_font(description);
2658 //this.selection = this.el.get_selection();
2659 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2668 xtype: Gtk.ListStore,
2671 getValue : function(treepath, col)
2673 var tp = new Gtk.TreePath.from_string (treepath);
2674 var iter = new Gtk.TreeIter();
2675 this.el.get_iter (iter, tp);
2676 var value = new GObject.Value('');
2677 this.el.get_value(iter, col, value);
2682 XObject.prototype.init.call(this);
2683 this.el.set_column_types ( 6, [
2684 GObject.TYPE_STRING, // real key
2685 GObject.TYPE_STRING, // real type
2686 GObject.TYPE_STRING, // docs ?
2687 GObject.TYPE_STRING, // visable desc
2688 GObject.TYPE_STRING, // function desc
2689 GObject.TYPE_STRING // element type (event|prop)
2693 showData : function(type) {
2695 if (!this.get('/MidPropTree').activeElement || !type) {
2696 return; // no active element
2699 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2700 var palete = this.get('/LeftTree').getPaleteProvider();
2704 Seed.print('Showing right?');
2705 if (!this.get('/MidPropTree').shown) {
2707 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2708 this.get('/MidPropTree').el.show();
2709 this.get('/MidPropTree').shown = true;
2712 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2713 return a.name > b.name ? 1 : -1;
2715 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2716 // console.dump(elementList);
2719 var iter = new Gtk.TreeIter();
2720 for(var i =0 ; i < elementList.length; i++) {
2721 var p=elementList[i];
2722 this.el.append(iter);
2723 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2724 //GObject.TYPE_STRING, // real key
2725 // GObject.TYPE_STRING, // real type
2726 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2727 // GObject.TYPE_STRING // func def?
2730 this.el.set_value(iter, 0, p.name);
2731 this.el.set_value(iter, 1, p.type);
2732 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2733 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2734 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2735 this.el.set_value(iter, 5, type);
2742 xtype: Gtk.TreeViewColumn,
2745 this.el = new Gtk.TreeViewColumn();
2746 this.parent.el.append_column(this.el);
2748 XObject.prototype.init.call(this);
2749 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2753 xtype: Gtk.CellRendererText,
2754 pack : "pack_start,true"
2778 xtype: Gtk.Notebook,
2779 pack : "pack_start,true,true",
2780 id : "view-help-nb",
2782 XObject.prototype.init.call(this);
2783 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2784 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2788 xtype: Gtk.Notebook,
2789 id : "view-notebook",
2793 XObject.prototype.init.call(this);
2794 this.el.set_current_page(0);
2795 //print("SET LABEL?")
2796 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2797 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2803 id : "RightBrowser",
2808 pack : "pack_start,false,true,0",
2813 clicked : function (self) {
2814 this.get('/RightBrowser.view').renderJS(null,true);
2818 pack : "pack_start,false,false,0"
2821 xtype: Gtk.CheckButton,
2823 toggled : function (self, state) {
2824 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2829 label : "Auto Redraw On",
2830 pack : "pack_start,false,false,0"
2835 clicked : function (self) {
2836 this.get('/RightBrowser.view').redraws = 99;
2837 this.get('/RightBrowser.view').renderJS(null,true);
2840 label : "Full Redraw",
2841 pack : "pack_start,false,false,0"
2846 xtype: Gtk.ScrolledWindow,
2849 XObject.prototype.init.call(this);
2850 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2852 shadow_type : Gtk.ShadowType.IN,
2855 xtype: WebKit.WebView,
2857 load_finished : function (self, object) {
2858 print("load finished");
2859 // print("load_finished"); return;
2860 // if (this.ready) { // dont do it twice!
2863 if (!this.inspectorShown) {
2864 this.el.get_inspector().show();
2865 this.inspectorShown = true;
2870 if (this.pendingRedraw) {
2871 this.pendingRedraw = false;
2872 this.refreshRequired = true;
2874 //var js = this.get('/LeftTree.model').toJS();
2875 //if (js && js[0]) {
2876 // this.renderJS(js[0]);
2880 script_alert : function (self, object, p0) {
2883 return true; // do not display anything...
2885 console_message : function (self, object, p0, p1) {
2887 // console.log(object);
2890 if (object.match(/variable/) && object.match(/Builder/)) {
2891 print("got builder missing message");
2892 this.refreshRequired = true;
2893 this.lastRedraw = 0;
2899 if (!object.match(/^\{/)) {
2901 //this.get('/Terminal').feed(object);
2902 return true; // do not handle!!! -> later maybe in console..
2908 // console.log(object);
2909 var val = JSON.parse(object);
2911 if (typeof(val['hover-node']) != 'undefined') {
2912 this.activeNode = val['hover-node'];
2913 console.log('active node: ' + this.activeNode);
2918 if (typeof(val['id']) != 'undefined') {
2919 // this.activeNode = val['id'];
2920 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2921 if (!tg || typeof(tg[0]) == 'undefined') {
2924 print("SELECT node " + tg[0]);
2926 this.get('/LeftTree.view').selectNode(tg[0]);
2930 if (ret && typeof(val['set']) != 'undefined') {
2931 this.get('/LeftPanel.model').add({
2935 //console.log('active node: ' + this.activeNode);
2938 //Seed.print('a:'+a);
2939 //Seed.print('b:'+b);
2940 //Seed.print('c:'+c);
2943 drag_motion : function (w, ctx, x, y, time, ud) {
2944 // console.log('DRAG MOTION');
2946 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2947 this.targetData = [];
2948 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2950 // A) find out from drag all the places that node could be dropped.
2951 var src = Gtk.drag_get_source_widget(ctx);
2952 if (!src.dropList) {
2953 Gdk.drag_status(ctx, 0, time);
2956 // b) get what we are over.. (from activeNode)
2957 // tree is empty.. - list should be correct..
2958 if (!this.get('/LeftTree.model').currentTree) {
2959 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2963 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2965 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2968 Gdk.drag_status(ctx, 0,time);
2969 this.get('/LeftTree.view').highlight(false);
2973 // if we have a target..
2974 // -> highlight it! (in browser)
2975 // -> highlight it! (in tree)
2977 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2978 this.get('/LeftTree.view').highlight(tg);
2979 this.targetData = tg;
2980 // for tree we should handle this...
2983 drag_drop : function (w, ctx, x, y,time, ud) {
2984 print("TARGET: drag-drop");
2985 var is_valid_drop_site = true;
2990 w, /* will receive 'drag-data-received' signal */
2991 ctx, /* represents the current state of the DnD */
2992 this.get('/Window').atoms["STRING"], /* the target type we want */
2993 time /* time stamp */
2997 /* No target offered by source => error */
3000 return is_valid_drop_site;
3002 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3004 print("Browser: drag-data-received");
3005 var delete_selection_data = false;
3006 vardnd_success = false;
3007 /* Deal with what we are given from source */
3008 if( sel_data && sel_data.length ) {
3010 if (ctx.action == Gdk.DragAction.ASK) {
3011 /* Ask the user to move or copy, then set the ctx action. */
3014 if (ctx.action == Gdk.DragAction.MOVE) {
3015 delete_selection_data = true;
3017 var source = Gtk.drag_get_source_widget(ctx);
3019 print("Browser: source.DRAGDATA? " + source.dragData);
3020 if (this.targetData) {
3021 print(this.targetData);
3022 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3031 if (dnd_success == false)
3033 Seed.print ("DnD data transfer failed!\n");
3036 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3039 create_web_view : function (self, object) {
3040 print("CREATE WEB VIEW");
3041 return null; //new WebKit.WebView();
3048 XObject.prototype.init.call(this);
3049 // this may not work!?
3050 var settings = this.el.get_settings();
3051 settings.enable_developer_extras = true;
3053 // this was an attempt to change the url perms.. did not work..
3054 // settings.enable_file_access_from_file_uris = true;
3055 // settings.enable_offline_web_application_cache - true;
3056 // settings.enable_universal_access_from_file_uris = true;
3060 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3061 _this.get('/BottomPane.inspector').el.show();
3062 return _this.get('/BottomPane.inspector').el;
3066 // FIXME - base url of script..
3067 // we need it so some of the database features work.
3068 this.el.load_html_string( "Render not ready" ,
3069 //fixme - should be a config option!
3070 // or should we catch stuff and fix it up..
3071 'http://localhost/app.Builder/'
3075 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3079 this.el, /* widget that will accept a drop */
3080 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3081 null, /* lists of target to support */
3082 0, /* size of list */
3083 Gdk.DragAction.COPY /* what to do with data after dropped */
3086 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3087 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3089 GLib.timeout_add_seconds(0, 1, function() {
3090 // print("run refresh?");
3097 renderJS : function(data, force) {
3099 // this is the public redraw call..
3100 // we refresh in a loop privately..
3101 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3102 if (!autodraw && !force) {
3103 print("Skipping redraw - no force, and autodraw off");
3106 this.refreshRequired = true;
3108 runRefresh : function()
3110 // this is run every 2 seconds from the init..
3114 if (!this.refreshRequired) {
3115 // print("no refresh required");
3119 if (this.lastRedraw) {
3120 // do not redraw if last redraw was less that 5 seconds ago.
3121 if (((new Date()) - this.lastRedraw) < 5000) {
3129 if (!this.get('/Window.LeftTree').getActiveFile()) {
3132 this.refreshRequired = false;
3133 // print("HTML RENDERING");
3135 this.get('/BottomPane').el.show();
3136 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3139 var js = this.get('/LeftTree.model').toJS();
3140 if (!js || !js.length) {
3147 var project = this.get('/Window.LeftTree').getActiveFile().project;
3148 //print (project.fn);
3149 // set it to non-empty.
3150 project.runhtml = project.runhtml || '';
3151 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3154 this.runhtml = this.runhtml || '';
3156 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3157 // then we need to reload the browser using
3158 // load_html_string..
3160 // then trigger a redraw once it's loaded..
3161 this.pendingRedraw = true;
3162 var runhtml = '<script type="text/javascript">' + "\n" ;
3163 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3164 runhtml += '</script>'+ "\n" ;
3166 this.runhtml = project.runhtml;
3167 // need to modify paths
3171 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3172 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3173 print("LOAD HTML " + html);
3174 this.el.load_html_string( html ,
3175 //fixme - should be a config option!
3176 'http://localhost/app.Builder/'
3179 // should trigger load_finished! - which in truns shoudl set refresh Required;
3185 this.renderedData = data;
3186 var str = JSON.stringify(data) ;
3189 console.log('not loaded yet');
3191 this.lastRedraw = new Date();
3193 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3194 print( "before render" + this.lastRedraw);
3195 print( "after render" + (new Date()));
3205 id : "RightGtkView",
3207 redraw : function() {
3208 this.highlightWidget = false;
3209 print("REDRAW CALLED");
3210 this.activePath = this.get('/LeftTree').getActivePath();
3211 if (this.renderedEl) {
3212 print("QUEUE DRAW CALLING");
3213 this.renderedEl.queue_draw();
3216 renderJS : function(data, withDebug)
3218 this.highlightWidget = false;
3220 this.withDebug = false;
3221 while (this.get('view').el.get_children().length) {
3222 var c = this.get('view').el.get_children()[0];
3223 this.get('view').el.remove(c);
3230 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3231 // in theory tree is actually window..
3234 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3240 this.get('view').el.set_size_request(
3241 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3243 if (this.renderedEl) {
3244 this.renderedEl.set_size_request(
3245 tree.default_width || 600,
3246 tree.default_height || 400
3249 this.get('view').el.show_all();
3254 showInWindow : function() {
3255 print("GET PROEJCT");
3256 var pr = this.get('/LeftProjectTree').getActiveProject();
3258 console.log(pr.paths);
3261 var src= this.buildJS(
3262 this.get('/LeftTree.model').toJS()[0],
3267 //var x = new imports.sandbox.Context();
3271 Seed.check_syntax('var e = ' + src);
3274 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3275 this.get('/Terminal').feed(console._dump(e)+"\n");
3277 var lines = src.split("\n");
3278 var start = Math.max(0, e.line - 10);
3279 var end = Math.min(lines.length, e.line + 10);
3280 for (var i =start ; i < end; i++) {
3282 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3285 this.get('/Terminal').feed(lines[i] + "\n");
3292 this.get('/BottomPane').el.set_current_page(1);
3293 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3294 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3295 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3297 var _top = x.get_global_object()._top;
3299 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3301 if (_top.el.popup) {
3302 _top.el.popup(null, null, null, null, 3, null);
3306 viewAdd : function(item, par)
3309 // does something similar to xobject..
3310 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3312 // pack is forced to 'false'
3313 if (item.pack===false || item.pack === 'false') { // no ;
3317 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3320 var type = item['|xns'] + '.' + item['xtype'];
3322 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3326 var ns = imports.gi[item['|xns']];
3327 var ctr = ns[item['xtype']]; // why are we using array here..?
3332 for(var k in item) {
3334 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3348 // value is a function..
3349 if (k[0] == '|' && typeof(kv) == 'string') {
3351 if (kv.match(new RegExp('function'))) {
3354 print("WASL " + k + '=' + kv);
3356 eval( 'kv = ' + kv);
3357 } catch(e) { continue; }
3360 // print(k + '=' + kv);
3362 if (k[0] == '|') { // should be boolean or number..
3364 //print(k + '=' + kv);
3367 if (k == 'show_tabs') { // force tab showing for notebooks.
3370 print(k + '=' + typeof(kv) + " : " + kv);
3374 var altctr = XObject.baseXObject({ xtype: ctr} );
3376 if (!item.pack && altctr) {
3378 print("SETTING PACK TO XObjectBase method");
3379 pack_m = altctr.prototype.pack;
3384 var el = new ctr(ctr_args);
3386 print("PACK" + item.pack);
3387 //console.dump(item.pack);
3394 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3395 if (typeof(item.pack) == 'string') {
3397 item.pack.split(',').forEach(function(e, i) {
3399 if (e == 'false') { args.push( false); return; }
3400 if (e == 'true') { args.push( true); return; }
3401 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3404 //print(args.join(","));
3406 pack_m = args.shift();
3408 pack_m = item.pack.shift();
3413 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3415 name: "ArgumentError",
3416 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3417 "ADDING : " + item.id + " " + el
3426 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3427 //Seed.print('args: ' + args.length);
3428 if (typeof(pack_m) == 'string') {
3429 par[pack_m].apply(par, args);
3430 } else if (pack_m) {
3431 pack_m.call(item, par, item);
3435 item.items = item.items || [];
3436 item.items.forEach(function(ch,n) {
3438 print ("type:" + type);
3440 print ("ch.pack:" + ch.pack);
3443 if (type == 'Gtk.Table' && ch.pack == 'add') {
3444 var c = n % item.n_columns;
3445 var r = Math.floor(n/item.n_columns);
3446 ch.pack = [ 'attach', c, c+1, r, r+1,
3447 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3448 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3449 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3450 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3454 _this.viewAdd(ch, el);
3459 // add the signal handlers.
3460 // is it a widget!?!!?
3466 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3467 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3468 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3469 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3470 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3480 widgetDragDropEvent : function() {
3481 print("WIDGET DRAGDROP");
3484 widgetDragMotionEvent : function() {
3485 print("WIDGET DRAGMOTION");
3488 widgetExposeEvent : function(w, evt, ud, item) {
3490 if (this.inRender) {
3494 if ( this.highlightWidget) {
3495 this.inRender = true;
3496 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3497 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3499 this.inRender = false;
3504 if (this.activePath != item.xtreepath) {
3508 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3509 // work out the coords of the window..
3511 var dr = widget.window;
3512 this.gc = (new Gdk.GC.c_new(dr));
3513 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3514 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3518 var r = evt.expose.area;
3519 // console.dump([r.x, r.y, r.width, r.height ] );
3521 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3522 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3523 // happens with gtkscrollview embedded stuff..
3524 var np =this.activePath.split(':');
3526 this.activePath = np.join(':');
3527 this.renderedEl.queue_draw();
3543 this.inRender = true;
3546 this.highlightWidget = widget;
3551 // print("DRAW BOX");
3552 //console.dump(this.box);
3553 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3554 this.inRender = false;
3557 widgetPressEvent : function(w,e,u,d) {
3558 if (this.get('view').pressed) {
3561 this.get('view').pressed = true;
3562 print("WIDGET PRESS " + d.xtreepath );
3563 this.get('/LeftTree.view').selectNode( d.xtreepath );
3566 widgetReleaseEvent : function() {
3567 this.get('view').pressed = false;
3573 pack : "pack_start,false,true,0",
3577 pack : "pack_start,false,false,0",
3578 label : "Run The Application",
3580 button_press_event : function (self, event) {
3581 // call render on left tree - with special option!?!
3583 //print("GET PROEJCT");
3584 var pr = this.get('/LeftProjectTree').getActiveProject();
3587 for (var i in pr.paths) {
3591 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3592 this.get('/Terminal').feed("RUN DIR:" + dir);
3594 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3595 , false,false,false);
3596 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3597 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3607 xtype: Gtk.ScrolledWindow,
3610 shadow_type : Gtk.ShadowType.IN,
3612 XObject.prototype.init.call(this);
3613 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3617 xtype: Gtk.EventBox,
3618 pack : "add_with_viewport",
3620 XObject.prototype.init.call(this);
3621 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3622 red: 0x9F00, green: 0xB800 , blue : 0xA800
3630 XObject.prototype.init.call(this);
3631 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3632 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3637 xtype: Gtk.EventBox,
3640 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3641 XObject.prototype.init.call(this);
3645 this.el, /* widget that will accept a drop */
3646 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3647 null, /* lists of target to support */
3648 0, /* size of list */
3649 Gdk.DragAction.COPY /* what to do with data after dropped */
3652 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3653 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3656 getActiveNode : function(x,y)
3658 // workout what node is here..
3659 return '0'; // top..
3663 drag_motion : function (self, ctx, x, y, time) {
3665 // A) find out from drag all the places that node could be dropped.
3666 var src = Gtk.drag_get_source_widget(ctx);
3667 if (!src.dropList) {
3668 Gdk.drag_status(ctx, 0, time);
3671 // b) get what we are over.. (from activeNode)
3672 // tree is empty.. - list should be correct..
3673 if (!this.get('/LeftTree.model').currentTree) {
3674 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3678 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3679 var activeNode = this.getActiveNode(x, y);
3682 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3685 Gdk.drag_status(ctx, 0,time);
3686 this.get('/LeftTree.view').highlight(false);
3690 // if we have a target..
3691 // -> highlight it! (in browser)
3692 // -> highlight it! (in tree)
3694 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3695 this.get('/LeftTree.view').highlight(tg);
3696 this.targetData = tg;
3697 // for tree we should handle this...
3700 drag_drop : function (self,ctx, x, y, time) {
3701 Seed.print("TARGET: drag-drop");
3702 var is_valid_drop_site = true;
3707 self, /* will receive 'drag-data-received' signal */
3708 ctx, /* represents the current state of the this.gDnD */
3709 this.get('/Window').atoms["STRING"], /* the target type we want */
3710 time /* time stamp */
3714 /* No target offered by source => error */
3717 return is_valid_drop_site;
3720 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3722 Seed.print("GtkView: drag-data-received");
3723 var delete_selection_data = false;
3724 var dnd_success = false;
3725 /* Deal with what we are given from source */
3726 if( sel_data && sel_data.length ) {
3728 if (ctx.action == Gdk.DragAction.ASK) {
3729 /* Ask the user to move or copy, then set the ctx action. */
3732 if (ctx.action == Gdk.DragAction.MOVE) {
3733 delete_selection_data = true;
3735 var source = Gtk.drag_get_source_widget(ctx);
3737 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3738 if (this.targetData) {
3739 Seed.print(this.targetData);
3740 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3749 if (dnd_success == false)
3751 Seed.print ("DnD data transfer failed!\n");
3754 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3757 button_press_event : function (self, event) {
3758 this.pressed = false;
3774 xtype: Gtk.ScrolledWindow,
3779 var file = this.get('/LeftTree').getActiveFile();
3783 var activeEl = this.get('/LeftTree').getActiveElement();
3784 var xtype = file.guessName( activeEl )
3785 if (!xtype || !xtype.length) {
3788 //this.get('/Window.view-help-nb').el.set_current_page(1);
3790 // get the active element being edited.
3791 var helpurl = file.getHelpUrl(xtype);
3793 // now load the help info in the page..
3794 this.get('help-view').el.open(helpurl);
3798 xtype: WebKit.WebView,
3802 XObject.prototype.init.call(this);
3803 this.get('/Window.help-view').el.open(
3804 "http://devel.akbkhome.com/seed/");
3816 xtype: Gtk.Notebook,
3820 XObject.prototype.init.call(this);
3821 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3822 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3823 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3827 xtype: Gtk.ScrolledWindow,
3831 xtype: Vte.Terminal,
3834 feed : function(istr) {
3835 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3836 // we should make ourselves visable!!!
3837 this.get('/BottomPane').el.show();
3838 this.get('/BottomPane').el.set_current_page(1);
3840 this.el.feed(str ,str.length);
3842 scroll_on_output : true,
3844 XObject.prototype.init.call(this);
3845 this.el.set_size (80, 1000);
3847 scrollback_lines : 1000
3852 xtype: Gtk.ScrolledWindow,
3856 xtype: WebKit.WebView,
3868 pack : "pack_start,false,false",
3872 this.get('buttonbar').el.show();
3873 this.get('viewbox').el.hide();
3874 print("TRIED TO HIDE");
3877 this.get('buttonbar').el.hide();
3878 this.get('viewbox').el.show();
3879 // this.get('model').expanded();
3891 pack : "pack_start,false,true",
3893 clicked : function (self) {
3894 this.get('/RightPalete').show();
3901 stock : Gtk.STOCK_GOTO_FIRST,
3902 icon_size : Gtk.IconSize.MENU
3912 XObject.prototype.init.call(this);
3913 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3916 enter_notify_event : function (self, event) {
3917 this.get('/RightPalete').show();
3931 pack : "pack_start,false,true",
3940 pack : "pack_start,false,true",
3942 clicked : function (self) {
3943 this.get('/RightPalete').hide();
3950 stock : Gtk.STOCK_GOTO_LAST,
3951 icon_size : Gtk.IconSize.MENU
3958 xtype: Gtk.ScrolledWindow,
3961 XObject.prototype.init.call(this);
3962 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3963 this.el.set_size_request(-1,200);
3965 shadow_type : Gtk.ShadowType.IN,
3968 xtype: Gtk.TreeView,
3970 drag_begin : function (self, ctx) {
3971 // we could fill this in now...
3972 Seed.print('SOURCE: drag-begin');
3976 var iter = new Gtk.TreeIter();
3977 var s = this.selection;
3978 s.get_selected(this.get('/RightPalete.model').el, iter);
3979 var path = this.get('/RightPalete.model').el.get_path(iter);
3981 var pix = this.el.create_row_drag_icon ( path);
3984 Gtk.drag_set_icon_pixmap (ctx,
3991 var value = new GObject.Value('');
3992 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3993 if (!this.get('/RightPalete').provider) {
3996 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3997 this.el.dragData = value.value;
4004 drag_data_get : function (self, drag_context, selection_data, info, time) {
4005 //Seed.print('Palete: drag-data-get: ' + target_type);
4006 if (this.el.dragData && this.el.dragData.length ) {
4007 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4011 //this.el.dragData = "TEST from source widget";
4015 drag_end : function (self, drag_context) {
4016 Seed.print('SOURCE: drag-end');
4017 this.el.dragData = false;
4018 this.el.dropList = false;
4019 this.get('/LeftTree.view').highlight(false);
4022 button_press_event : function (self, event) {
4024 if (!this.get('/Editor').save()) {
4025 // popup!! - click handled..
4032 enable_tree_lines : true,
4033 headers_visible : false,
4035 XObject.prototype.init.call(this);
4036 this.el.set_size_request(150,-1);
4037 // set_reorderable: [1]
4039 var description = new Pango.FontDescription.c_new();
4040 description.set_size(8000);
4041 this.el.modify_font(description);
4043 this.selection = this.el.get_selection();
4044 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4045 // this.selection.signal['changed'].connect(function() {
4046 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4048 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4050 Gtk.drag_source_set (
4051 this.el, /* widget will be drag-able */
4052 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4053 null, /* lists of target to support */
4054 0, /* size of list */
4055 Gdk.DragAction.COPY /* what to do with data after dropped */
4057 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4059 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
4060 Gtk.drag_source_add_text_targets(this.el);
4062 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4063 targets = new Gtk.TargetList();
4064 targets.add( LeftTree.atoms["STRING"], 0, 0);
4065 targets.add_text_targets( 1 );
4066 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4068 //if you want to allow text to be output elsewhere..
4069 //Gtk.drag_source_add_text_targets(this.el);
4075 xtype: Gtk.ListStore,
4078 XObject.prototype.init.call(this);
4079 this.el.set_column_types ( 2, [
4080 GObject.TYPE_STRING, // title
4081 GObject.TYPE_STRING // tip
4086 load : function(tr,iter)
4091 //console.log('Project tree load: ' + tr.length);
4092 var citer = new Gtk.TreeIter();
4093 //this.insert(citer,iter,0);
4094 for(var i =0 ; i < tr.length; i++) {
4097 this.el.append(citer);
4099 this.el.insert(citer,iter,-1);
4104 this.el.set_value(citer, 0, '' + r ); // title
4106 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4107 //if (r.cn && r.cn.length) {
4108 // this.load(r.cn, citer);
4114 getValue : function (iter, col) {
4115 var gval = new GObject.Value('');
4116 this.el.get_value(iter, col ,gval);
4123 xtype: Gtk.TreeViewColumn,
4124 pack : "append_column",
4126 XObject.prototype.init.call(this);
4127 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4131 xtype: Gtk.CellRendererText,
4153 XObject.cache['/Window'] = Window;