3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 ////GtkClutter = imports.gi.GtkClutter;
11 ////Gdl = imports.gi.Gdl;
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 + ' != ' + Gdk.EventType.BUTTON_PRESS);
487 print("click button " + ev.button.button);
493 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
495 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
497 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
498 this.get('/LeftTreeMenu').el.show_all();
499 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
500 print("click:" + res.path.to_string());
503 drag_begin : function (self, drag_context) {
504 print('SOURCE: drag-begin');
505 this.targetData = false;
506 // find what is selected in our tree...
507 var iter = new Gtk.TreeIter();
508 var s = this.selection;
509 s.get_selected(this.get('/LeftTree.model').el, iter);
511 // set some properties of the tree for use by the dropped element.
512 var value = new GObject.Value('');
513 this.get('/LeftTree.model').el.get_value(iter, 2, value);
514 var data = JSON.parse(value.value);
515 var xname = this.get('/LeftTree.model').file.guessName(data);
517 this.el.dragData = xname;
518 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
521 // make the drag icon a picture of the node that was selected
522 var path = this.get('/LeftTree.model').el.get_path(iter);
523 this.el.treepath = path.to_string();
525 var pix = this.el.create_row_drag_icon ( path);
527 Gtk.drag_set_icon_pixmap (ctx,
536 drag_end : function (self, drag_context) {
537 Seed.print('LEFT-TREE: drag-end');
538 this.el.dragData = false;
539 this.el.dropList = false;
540 this.targetData = false;
541 this.get('/LeftTree.view').highlight(false);
544 drag_motion : function (self, ctx, x, y, time) {
545 console.log("LEFT-TREE: drag-motion");
546 var src = Gtk.drag_get_source_widget(ctx);
548 // a drag from elsewhere...- prevent drop..
550 print("no drag data!");
551 Gdk.drag_status(ctx, 0, time);
552 this.targetData = false;
555 var action = Gdk.DragAction.COPY;
556 if (src == this.el) {
557 // unless we are copying!!! ctl button..
558 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
562 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
563 // no children.. -- asume it's ok..
564 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
565 Gdk.drag_status(ctx, action ,time);
569 print("GETTING POS");
570 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
571 print("ISOVER? " + isOver);
573 Gdk.drag_status(ctx, 0 ,time);
574 return false; // not over apoint!?!
576 // drag node is parent of child..
577 console.log("SRC TREEPATH: " + src.treepath);
578 console.log("TARGET TREEPATH: " + data.path.to_string());
580 // nned to check a few here..
581 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
582 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
583 //Gtk.TreeViewDropPosition.AFTER
584 //Gtk.TreeViewDropPosition.BEFORE
586 if (typeof(src.treepath) != 'undefined' &&
587 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
588 print("subpath drag");
589 Gdk.drag_status(ctx, 0 ,time);
594 //print("DUMPING DATA");
595 //console.dump(data);
598 print(data.path.to_string() +' => '+ data.pos);
599 var tg = this.get('/LeftTree.model').findDropNodeByPath(
600 data.path.to_string(), src.dropList, data.pos);
602 this.get('/LeftTree.view').highlight(tg);
604 print("Can not find drop node path");
605 this.targetData = false;
606 Gdk.drag_status(ctx, 0, time);
610 this.targetData = tg;
613 Gdk.drag_status(ctx, action ,time);
617 drag_drop : function (w, ctx, x, y, time) {
618 Seed.print("TARGET: drag-drop");
622 w, /* will receive 'drag-data-received' signal */
623 ctx, /* represents the current state of the DnD */
624 this.get('/Window').atoms["STRING"], /* the target type we want */
625 time /* time stamp */
629 /* No target offered by source => error */
634 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
635 print("Tree: drag-data-received");
637 var delete_selection_data = false;
638 var dnd_success = false;
639 /* Deal with what we are given from source */
640 if( sel_data && sel_data.length ) {
642 if (ctx.action == Gdk.DragAction.ASK) {
643 /* Ask the user to move or copy, then set the ctx action. */
646 if (ctx.action == Gdk.DragAction.MOVE) {
647 //delete_selection_data = true;
650 var source = Gtk.drag_get_source_widget(ctx);
652 if (this.targetData) {
653 if (source != this.el) {
654 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
656 // drag around.. - reorder..
657 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
661 //Seed.print(this.targetData);
667 // we can send stuff to souce here...
673 if (dnd_success == false)
675 Seed.print ("DnD data transfer failed!\n");
678 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
681 cursor_changed : function (self) {
682 if (this.blockChanges) { // probably not needed..
685 var render = this.get('/LeftTree').getRenderer();
688 if (this.selection.count_selected_rows() < 1) {
689 this.get('/LeftPanel.model').load( false);
690 this.get('/MidPropTree').activeElement = false;
691 this.get('/MidPropTree').hideWin();
693 var pm = this.get('/RightPalete.model');
694 if (!this.get('/LeftTree').getPaleteProvider()) {
695 // it may not be loaded yet..
698 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
699 this.get('/LeftTree.model').listAllTypes()));
700 if (render && render.redraw) {
706 //console.log('changed');
707 var s = this.selection;
708 var iter = new Gtk.TreeIter();
709 s.get_selected(this.get('/LeftTree.model').el, iter);
713 var value = new GObject.Value('');
714 this.get('/LeftTree.model').el.get_value(iter, 2, value);
715 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
717 var data = JSON.parse(value.value);
718 this.get('/MidPropTree').activeElement = data;
719 this.get('/MidPropTree').hideWin();
720 this.get('/LeftPanel.model').load( data);
722 console.log(value.value);
723 // _g.button.set_label(''+value.get_string());
725 var pm =this.get('/RightPalete.model');
726 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
727 this.get('/LeftTree.model').listAllTypes()));
730 if (render && render.redraw) {
734 //Seed.print( value.get_string());
742 enable_tree_lines : true,
743 headers_visible : false,
744 highlight : function(treepath_ar) {
746 // highlighting for drag/drop
747 if (treepath_ar.length && treepath_ar[0].length ) {
748 this.el.set_drag_dest_row(
749 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
751 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
756 XObject.prototype.init.call(this);
757 var description = new Pango.FontDescription.c_new();
758 description.set_size(8000);
759 this.el.modify_font(description);
761 this.selection = this.el.get_selection();
762 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
765 // is this really needed??
766 this.selection.signal['changed'].connect(function() {
767 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
768 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
772 Gtk.drag_source_set (
773 this.el, /* widget will be drag-able */
774 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
775 null, /* lists of target to support */
776 0, /* size of list */
777 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
780 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
782 Gtk.drag_source_add_text_targets(this.el);
785 this.el, /* widget that will accept a drop */
786 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
787 null, /* lists of target to support */
788 0, /* size of list */
789 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
792 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
793 Gtk.drag_dest_add_text_targets(this.el);
795 selectNode : function(treepath_str) {
796 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
797 var tp = new Gtk.TreePath.from_string(treepath_str);
798 this.el.set_cursor(tp, null, false);
799 this.el.scroll_to_cell(tp, null, false, 0,0);
803 xtype: Gtk.TreeStore,
808 changed : function(n, refresh) {
809 // print("MODEL CHANGED CALLED" + this.activePath);
810 if (this.activePath) {
811 var iter = new Gtk.TreeIter();
812 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
813 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
814 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
816 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
818 //this.currentTree = this.toJS(false, true)[0];
820 this.file.items = this.toJS(false, false);
821 print ("TO JS in " + ((new Date()) - d) + "ms");
822 // print("AFTER CHANGED");
823 //console.dump(this.file.items);
825 this.currentTree = this.file.items[0];
826 //console.log(this.file.toSource());
829 print("REDNER BROWSER?!");
830 this.get('/LeftTree').renderView();
832 var pm = this.get('/RightPalete.model');
833 if (!this.get('/RightPalete').provider) {
839 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
840 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
844 deleteSelected : function() {
845 this.get('/LeftTree.view').blockChanges = true;
846 var old_iter = new Gtk.TreeIter();
847 var s = this.get('/LeftTree.view').selection;
848 s.get_selected(this.el, old_iter);
849 var path = this.el.get_path(old_iter).to_string();
851 this.activePath= false;
854 this.activePath= false;
855 var iter = new Gtk.TreeIter();
856 this.el.get_iter_from_string(iter, path);
857 this.el.remove(iter);
859 // rebuild treemap. -- depreciated.!!
862 //this.toJS(null, true) // does not do anything?
863 this.activePath= false;
864 this.changed(false,true);
865 this.get('/LeftTree.view').blockChanges = false;
867 dropNode : function(target_data, node) {
869 // console.dump(node);
870 // console.dump(target_data);
871 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
873 print("add " + tp + "@" + target_data[1] );
876 if (tp && target_data[1] < 2) { // before or after..
877 var ar = target_data[0].split(':');
879 parent = new Gtk.TreePath.from_string( ar.join(':') );
882 var n_iter = new Gtk.TreeIter();
883 var iter_par = new Gtk.TreeIter();
884 var iter_after = after ? new Gtk.TreeIter() : false;
888 if (parent !== false) {
889 this.el.get_iter(iter_par, parent);
896 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
897 this.el.get_iter(iter_after, after);
898 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
899 n_iter, iter_par, iter_after);
902 this.el.append(n_iter, iter_par);
906 if (typeof(node) == 'string') {
907 var ar = node.split('.');
908 var xtype = ar.pop();
911 '|xns' : ar.join('.'),
914 if (target_data.length == 3 && target_data[2].length) {
915 node['*prop'] = target_data[2];
917 node = this.get('/DialogTemplateSelect').show(node);
920 // work out what kind of packing to use..
921 if (typeof(node.pack) == 'undefined' && parent !== false) {
922 var pal = this.get('/LeftTree').getPaleteProvider();
923 if (pal.name == 'Gtk') {
924 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
925 var cname = pal.guessName(node);
926 node.pack = pal.getDefaultPack(pname, cname);
937 // load children - if it has any..
940 this.load(xitems, n_iter);
941 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
943 if (tp && (xitems || after)) {
944 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
946 // wee need to get the empty proptypes from somewhere..
948 //var olditer = this.activeIter;
949 this.activePath = this.el.get_path(n_iter).to_string();
951 // changed actually set's the node data..
952 this.changed(node, true);
956 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
958 //Builder.MidPropTree._model.load(node);
959 //Builder.MidPropTree._win.hideWin();
960 //Builder.LeftPanel._model.load( node);
964 findDropNode : function(treepath_str, targets) {
966 // this is used by the dragdrop code in the roo version AFAIR..
968 var path = treepath_str.replace(/^builder-/, '');
969 // treemap is depreciated... - should really check if model has any entries..
971 if (!this.el.iter_n_children(null)) {
973 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
975 print("FIND treepath: " + path);
976 //console.dump(this.treemap);
978 if (!treepath_str.match(/^builder-/)) {
979 return []; // nothing!
981 if (targets === true) {
984 return this.findDropNodeByPath(path,targets)
986 findDropNodeByPath : function(treepath_str, targets, pref) {
987 var path = treepath_str + ''; // dupe it..
988 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
990 //console.dump(this.treemap);
991 while (path.length) {
992 print("LOOKING FOR PATH: " + path);
993 var node_data = this.singleNodeToJS(path);
994 if (node_data === false) {
995 print("node not found");
999 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1002 targets.forEach(function(tg) {
1006 if ((tg == xname) ) {
1009 if (tg.indexOf(xname +':') === 0) {
1011 prop = tg.split(':').pop();
1016 if (last) { // pref is after/before..
1017 // then it's after last
1019 return []; // do not allow..
1021 return [ last, pref , prop];
1024 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1026 var par = path.split(':');
1029 path = par.join(':');
1035 getIterValue : function (iter, col) {
1036 var gval = new GObject.Value('');
1037 this.el.get_value(iter, col ,gval);
1043 XObject.prototype.init.call(this);
1044 this.el.set_column_types ( 3, [
1045 GObject.TYPE_STRING, // title
1046 GObject.TYPE_STRING, // tip
1047 GObject.TYPE_STRING // source..
1050 listAllTypes : function() {
1051 var s = this.get('/LeftTree.view').selection;
1052 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1054 if (s.count_selected_rows() > 0) {
1055 var iter = new Gtk.TreeIter();
1056 s.get_selected(this.el, iter);
1058 // set some properties of the tree for use by the dropped element.
1059 var value = new GObject.Value('');
1060 this.el.get_value(iter, 2, value);
1061 var data = JSON.parse(value.value);
1064 var xname = this.get('/LeftTree.model').file.guessName(data);
1065 console.log('selected:' + xname);
1069 return []; // could not find it..
1077 li.forEach(function(el) {
1078 // this is specific to roo!!!?
1079 if (!el) { // skip empty?
1082 var fullpath = _this.file.guessName(el);
1083 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1088 if (el.items && el.items.length) {
1097 addall([this.currentTree]);
1099 // only if we have nothing, should we add '*top'
1103 //console.log('all types in tree');
1104 //console.dump(ret);
1109 load : function(tr,iter)
1111 var citer = new Gtk.TreeIter();
1112 //this.insert(citer,iter,0);
1113 for(var i =0 ; i < tr.length; i++) {
1115 this.el.insert(citer,iter,-1);
1117 this.el.append(citer);
1120 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1121 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1122 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1123 if (tr[i].items && tr[i].items.length) {
1124 this.load(tr[i].items, citer);
1128 loadFile : function(f) {
1134 console.log('missing file');
1138 // load the file if not loaded..
1139 if (f.items === false) {
1141 f.loadItems(function() {
1147 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1149 if (f.items.length && typeof(f.items[0]) == 'string') {
1151 //this.get('/RightEditor').el.show();
1152 //this.get('/RightEditor.view').load( f.items[0]);
1156 print(JSON.stringify(f.items, null,4));
1157 //console.dump(f.items);
1159 this.get('/LeftTree.view').el.expand_all();
1161 if (!f.items.length) {
1164 this.get('/Window.leftvpaned').el.set_position(80);
1166 this.get('/LeftTree.view').el.set_cursor(
1167 new Gtk.TreePath.from_string('0'), null, false);
1171 this.get('/Window.leftvpaned').el.set_position(200);
1175 //print("hide right editior");
1176 //this.get('/RightEditor').el.hide();
1177 this.get('/Editor').el.hide();
1178 //print("set current tree");
1179 this.currentTree = this.toJS(false, false)[0];
1180 //console.dump(this.currentTree);
1181 this.currentTree = this.currentTree || { items: [] };
1182 this.get('/LeftTree').renderView();
1183 //console.dump(this.map);
1184 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1185 var pm = this.get('/RightPalete.model');
1186 // set up provider..
1188 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1190 if (!this.get('/RightPalete').provider) {
1191 print ("********* PALETE PROVIDER MISSING?!!");
1193 this.get('/LeftTree').renderView();
1195 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1199 this.get('/Window.view-notebook').el.set_current_page(
1200 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1203 moveNode : function(target_data, action) {
1204 //print("MOVE NODE");
1205 // console.dump(target_data);
1206 var old_iter = new Gtk.TreeIter();
1207 var s = this.get('/LeftTree.view').selection;
1208 s.get_selected(this.el, old_iter);
1209 var node = this.nodeToJS(old_iter,false);
1210 //console.dump(node);
1213 // needs to drop first, otherwise the target_data
1214 // treepath will be invalid.
1216 this.dropNode(target_data, node);
1217 if (action & Gdk.DragAction.MOVE) {
1218 // print("REMOVING OLD NODE");
1219 this.el.remove(old_iter);
1223 this.activePath= false;
1224 this.changed(false,true);
1226 nodeTip : function(c) {
1227 var ret = this.nodeTitle(c,true);
1233 if (!i.length || i[0] != '|') {
1239 if (typeof(c[i]) != 'string') {
1242 //print("prop : " + i + ':' + c[i]);
1243 if (!c[i].match(new RegExp('function'))) {
1246 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1250 ret+="\n\nMethods:" + funcs;
1255 nodeTitle : function(c, renderfull) {
1258 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1259 if (sr) txt.push('<s>');
1260 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1262 if (renderfull && c['|xns']) {
1263 txt.push(c['|xns']);
1266 if (c.xtype) { txt.push(c.xtype); }
1267 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1268 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1269 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1272 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1273 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1274 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1275 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1276 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1277 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1278 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1279 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1280 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1282 // for flat classes...
1283 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1284 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1287 if (sr) txt.push('</s>');
1288 return (txt.length == 0 ? "Element" : txt.join(" "));
1290 nodeToJS : function (treepath, with_id)
1293 var iter = treepath; // API used to be iter here..
1294 if (typeof(iter) == 'string') {
1295 iter = new Gtk.TreeIter();
1296 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1300 var par = new Gtk.TreeIter();
1301 var iv = this.getIterValue(iter, 2);
1302 // print("IV" + iv);
1303 var k = JSON.parse(iv);
1304 if (k.json && !this.el.iter_parent( par, iter )) {
1309 var treepath_str = this.el.get_path(iter).to_string();
1310 // not sure how we can handle mixed id stuff..
1311 if (typeof(k.id) == 'undefined') {
1312 k.id = 'builder-'+ treepath_str ;
1316 this.treemap[ treepath_str ] = k;
1317 k.xtreepath = treepath_str ;
1320 if (this.el.iter_has_child(iter)) {
1321 citer = new Gtk.TreeIter();
1322 this.el.iter_children(citer, iter);
1323 k.items = this.toJS(citer,with_id);
1327 nodeToJSON : function(c) {
1335 return JSON.stringify(o);
1337 singleNodeToJS : function (treepath)
1339 var iter = new Gtk.TreeIter();
1340 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1344 var iv = this.getIterValue(iter, 2);
1346 return JSON.parse(iv);
1349 toJS : function(treepath, with_id)
1351 //Seed.print("WITHID: "+ with_id);
1352 var iter = treepath; // API used to be iter here..
1353 if (typeof(iter) == 'string') {
1354 iter = new Gtk.TreeIter();
1355 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1364 iter = new Gtk.TreeIter();
1365 if (!this.el.get_iter_first(iter)) {
1375 var k = this.nodeToJS(iter, with_id);
1379 if (!this.el.iter_next(iter)) {
1384 if (treepath === false) {
1386 return JSON.parse(JSON.stringify(ar));
1390 // convert the list into a json string..
1396 xtype: Gtk.TreeViewColumn,
1397 pack : "append_column",
1399 XObject.prototype.init.call(this);
1400 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1404 xtype: Gtk.CellRendererText,
1414 id : "LeftTreeMenu",
1417 xtype: Gtk.MenuItem,
1419 label : "Delete Element",
1421 activate : function (self) {
1423 this.get('/LeftTree.model').deleteSelected();
1428 xtype: Gtk.MenuItem,
1430 activate : function (self) {
1432 var tree = this.get('/LeftTree');
1433 var model = this.get('/LeftTree.model');
1434 var el = tree.getActivePath();
1436 var js = model.toJS(el, false);
1437 // print(JSON.stringify(js[0], null,4));
1438 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1443 label : "Save as Template",
1453 id : "LeftProjectTree",
1454 showNoProjectSelected : function() {
1455 this.get('/StandardErrorDialog').show("Select a Project first.");
1457 getActiveProject : function() {
1458 return this.project;
1461 leave_notify_event : function (self, event) {
1468 pack : "pack_start,false,false",
1471 xtype: Gtk.ComboBox,
1473 changed : function (self) {
1474 var fn = this.getValue();
1475 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1476 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1480 getValue : function() {
1481 var ix = this.el.get_active();
1485 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1486 if (typeof(data[ix]) == 'undefined') {
1492 XObject.prototype.init.call(this);
1493 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1495 setValue : function(fn)
1499 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1500 data.forEach(function(n, ix) {
1509 xtype: Gtk.CellRendererText,
1510 pack : "pack_start,true",
1514 xtype: Gtk.ListStore,
1518 XObject.prototype.init.call(this);
1519 this.el.set_column_types ( 2, [
1520 GObject.TYPE_STRING, // real key
1521 GObject.TYPE_STRING // real type
1525 // this.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
1526 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1528 pm.on('changed', function() {
1529 print("caught changed hook on project manager - reloading data");
1530 _this.loadData(pm.projects);
1534 loadData : function(data) {
1535 var ov = this.get('/LeftProjectTree.combo').getValue();
1537 var iter = new Gtk.TreeIter();
1539 data.forEach(function(p) {
1544 el.set_value(iter, 0, p.fn);
1545 el.set_value(iter, 1, p.name);
1549 this.get('/LeftProjectTree.combo').setValue(ov);
1557 xtype: Gtk.ScrolledWindow,
1559 shadow_type : Gtk.ShadowType.IN,
1561 XObject.prototype.init.call(this);
1562 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1566 xtype: Gtk.TreeView,
1568 cursor_changed : function (self) {
1569 var iter = new Gtk.TreeIter();
1571 if (this.selection.count_selected_rows() < 1) {
1572 //XN.get('Builder.LeftTree.model').
1573 this.get('/LeftTree.model').load( false);
1577 var model = this.get('/LeftProjectTree.model');
1578 //console.log('changed');
1579 var s = this.selection;
1580 s.get_selected(model, iter);
1581 value = new GObject.Value('');
1582 model.el.get_value(iter, 2, value);
1584 console.log(value.value);// id..
1586 var file = this.get('/LeftProjectTree').project.getById(value.value);
1593 var nb = this.get('/LeftTopPanel.expander');
1594 nb.el.expanded = false;
1596 //nb.listeners.activate.call(nb);
1597 //_expander.el.set_expanded(false);
1599 var ltm = this.get('/LeftTree.model');
1607 enable_tree_lines : true,
1608 headers_visible : false,
1610 XObject.prototype.init.call(this);
1611 var description = new Pango.FontDescription.c_new();
1612 description.set_size(8000);
1613 this.el.modify_font(description);
1615 this.selection = this.el.get_selection();
1616 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1620 xtype: Gtk.TreeStore,
1624 XObject.prototype.init.call(this);
1625 this.el.set_column_types ( 3, [
1626 GObject.TYPE_STRING, // title
1627 GObject.TYPE_STRING, // tip
1628 GObject.TYPE_STRING // id..
1632 loadProject : function(pr) {
1633 print("LOAD PROJECT");
1639 this.get('/LeftProjectTree').project = pr;
1640 this.load(pr.toTree());
1641 this.get('/LeftProjectTree.view').el.expand_all();
1643 load : function(tr,iter) {
1644 // console.dump(tr);
1645 console.log('Project tree load: ' + tr.length);
1646 var citer = new Gtk.TreeIter();
1647 //this.insert(citer,iter,0);
1650 tr.forEach(function (r) {
1652 _this.el.append(citer);
1654 _this.el.insert(citer,iter,-1);
1656 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1657 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1658 _this.el.set_value(citer, 2, '' + r.id ); //id
1659 if (r.cn && r.cn.length) {
1660 _this.load(r.cn, citer);
1665 getValue : function(iter, col) {
1666 var gval = new GObject.Value('');
1667 this.el.get_value(iter, col ,gval);
1668 return '' + gval.value;
1672 xtype: Gtk.TreeViewColumn,
1673 pack : "append_column",
1675 XObject.prototype.init.call(this);
1676 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1680 xtype: Gtk.CellRendererText,
1700 pack : "pack_start,false,true,0",
1707 button_press_event : function (self, event) {
1708 this.get('/MidPropTree.model').showData('props');
1720 stock : Gtk.STOCK_ADD,
1721 icon_size : Gtk.IconSize.MENU
1735 button_press_event : function (self, event) {
1737 if (!this.get('/Editor').save()) {
1738 // popup!! - click handled..
1741 this.get('/MidPropTree.model').showData('events');
1754 stock : Gtk.STOCK_ADD,
1755 icon_size : Gtk.IconSize.MENU
1769 button_press_event : function (self, ev) {
1771 if (!this.get('/Editor').save()) {
1772 // popup!! - click handled..
1776 var p = this.get('/AddPropertyPopup');
1780 p.el.set_screen(Gdk.Screen.get_default());
1782 p.el.popup(null, null, null, null, 3, ev.button.time);
1795 stock : Gtk.STOCK_ADD,
1796 icon_size : Gtk.IconSize.MENU
1808 id : "AddPropertyPopup",
1811 xtype: Gtk.MenuItem,
1813 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1816 activate : function (self) {
1818 this.get('/LeftPanel.model').add( {
1829 xtype: Gtk.MenuItem,
1831 tooltip_markup : "Add what type of packing is to be used",
1834 activate : function (self) {
1836 this.get('/LeftPanel.model').add( {
1846 xtype: Gtk.MenuItem,
1848 tooltip_markup : "Override the init method",
1851 activate : function (self) {
1853 this.get('/LeftPanel.model').add( {
1856 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1863 xtype: Gtk.SeparatorMenuItem,
1867 xtype: Gtk.MenuItem,
1869 tooltip_markup : "Add a user defined string property",
1872 activate : function (self) {
1874 this.get('/LeftPanel.model').add( {
1884 xtype: Gtk.MenuItem,
1886 tooltip_markup : "Add a user defined number property",
1889 activate : function (self) {
1891 this.get('/LeftPanel.model').add( {
1901 xtype: Gtk.MenuItem,
1903 tooltip_markup : "Add a user defined boolean property",
1906 activate : function (self) {
1908 this.get('/LeftPanel.model').add( {
1918 xtype: Gtk.SeparatorMenuItem,
1922 xtype: Gtk.MenuItem,
1924 tooltip_markup : "Add a user function boolean property",
1927 activate : function (self) {
1929 this.get('/LeftPanel.model').add( {
1932 val : "function() {\n \n}\n",
1945 xtype: Gtk.ScrolledWindow,
1950 XObject.prototype.init.call(this);
1951 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1953 shadow_type : Gtk.ShadowType.IN,
1956 xtype: Gtk.TreeView,
1958 button_press_event : function (self, ev) {
1961 if (!this.get('/Editor').save()) {
1962 // popup!! - click handled..
1967 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1968 return false; //not on a element.
1972 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
1974 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
1977 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1978 var p = this.get('/LeftPanelPopup');
1983 p.el.set_screen(Gdk.Screen.get_default());
1985 p.el.popup(null, null, null, null, 3, ev.button.time);
1986 //Seed.print("click:" + res.column.title);
1993 if (res.column.title != 'value') {
1994 // XObject.error("column is not value?");
1995 return false; // ignore.. - key click.. ??? should we do this??
1998 // currently editing???
1999 // if ( this.activePath) {
2001 // this.activePath = false;
2003 if (this.get('/Editor').dirty) {
2004 //if (!this.get('/Editor.buffer').checkSyntax()) {
2005 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2009 if (!this.get('/Editor.view').save()) {
2013 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2014 this.get('/LeftPanel').editing = false;
2016 // XObject.error("Currently editing?");
2020 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2022 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2024 // get options for this type -- this is to support option lists etc..
2025 var provider = this.get('/LeftTree').getPaleteProvider();
2026 var opts = provider.findOptions(type);
2028 if (opts === false) {
2030 this.get('/LeftPanel').editableColumn.setOptions([]);
2031 renderer.has_entry = true;
2033 this.get('/LeftPanel').editableColumn.setOptions(opts);
2034 renderer.has_entry = false;
2036 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2038 //Seed.print("click" + ev.type);
2039 //console.dump(res);
2048 enable_tree_lines : true,
2049 headers_visible : false,
2051 XObject.prototype.init.call(this);
2053 this.selection = this.el.get_selection();
2054 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2057 var description = new Pango.FontDescription.c_new();
2058 description.set_size(8000);
2059 this.el.modify_font(description);
2063 xtype: Gtk.TreeStore,
2067 add : function(info) {
2068 // info includes key, val, skel, etype..
2070 type = info.type.toLowerCase();
2071 var data = this.toJS();
2073 if (info.etype == 'events') {
2074 data.listeners = data.listeners || { };
2075 if (typeof(data.listeners[info.key]) != 'undefined') {
2076 return; //already set!
2079 if (typeof(data[info.key]) != 'undefined') {
2084 if (typeof(info.val) == 'undefined') {
2087 if (info.type.toLowerCase() == 'boolean') {
2090 if (type == 'number') {
2098 if (info.etype == 'events') {
2100 data.listeners[info.key] = info.val;
2103 data[info.key] = info.val;
2107 var map = this.load(data);
2109 // flag it as changed to the interface..
2111 this.get('/LeftTree.model').changed(data, true);
2114 this.startEditing(map[k]);
2117 LeftPanel.get('view').el.row_activated(
2118 new Gtk.TreePath.from_string(map[k]),
2119 LeftPanel.editableColumn.el
2123 changed : function(str, doRefresh) {
2124 if (!this.activePath) {
2127 var iter = new Gtk.TreeIter();
2128 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2130 this.el.set_value(iter, 1, '' +str);
2131 this.el.set_value(iter, 3, '' + this.toShort(str));
2132 var type = this.getIterValue(iter, 4);
2134 this.el.set_value(iter, 5, type + ' : ' + str);
2135 // update the tree...
2137 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2139 deleteSelected : function() {
2140 var data = this.toJS();
2141 var iter = new Gtk.TreeIter();
2142 var s = this.get('/LeftPanel.view').selection;
2143 s.get_selected(this.el, iter);
2146 var gval = new GObject.Value('');
2147 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2149 var val = gval.value;
2150 if (val[0] == '!') {
2152 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2155 delete data.listeners[ val.substring(1)];
2156 if (!XObject.keys(data.listeners).length) {
2157 delete data.listeners;
2161 if (typeof(data[val]) == 'undefined') {
2169 this.get('/LeftTree.model').changed(data, true);
2172 getIterValue : function(iter, col) {
2173 var gval = new GObject.Value('');
2174 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2175 return '' + gval.value;
2177 getType : function(treepath) {
2178 return this.getValue(treepath, 4);
2180 getValue : function(treepath_str, col)
2182 // get's the value in a row.. - keys - returns string, values - formats it..
2184 var iter = new Gtk.TreeIter();
2185 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2187 var gval = new GObject.Value('');
2188 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2189 var val = '' + gval.value;
2194 var type = this.getType(this.el.get_path(iter).to_string());
2195 //print("TYPE: " +type + " - val:" + val);
2196 switch(type.toLowerCase()) {
2200 return parseFloat(val); // Nan ?? invalid!!?
2203 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2205 return val == 'true' ? true : false;
2207 var nv = parseFloat(val);
2208 if (!isNaN(nv) && (val == ''+nv)) {
2216 XObject.prototype.init.call(this);
2217 this.el.set_column_types ( 6, [
2218 GObject.TYPE_STRING, // 0 real key
2219 GObject.TYPE_STRING, // 1 real value
2220 GObject.TYPE_STRING, // 2 visable key
2221 GObject.TYPE_STRING, // 3 visable value
2222 GObject.TYPE_STRING, // 4 need to store type of!!!
2223 GObject.TYPE_STRING // 5 tooltip
2227 load : function(ar) {
2228 // might casue problesm..
2229 // this.get('/Editor.RightEditor').save();
2231 this.get('/Editor').el.hide();
2232 this.get('/Editor').activePath = false;
2237 //this.get('/RightEditor').el.hide();
2244 var provider = this.get('/LeftTree').getPaleteProvider();
2245 var iter = new Gtk.TreeIter();
2248 var keys = XObject.keys(ar);
2250 ar.listeners = ar.listeners || {};
2252 for (var i in ar.listeners ) {
2253 this.el.append(iter);
2254 var p = this.el.get_path(iter).to_string();
2257 this.el.set_value(iter, 0, '!'+ i );
2258 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2259 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2261 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2262 this.el.set_value(iter, 4, 'function');
2263 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2269 keys.forEach(function(i) {
2270 if (typeof(ar[i]) == 'object') {
2274 var type = provider.findType(ar, i, ar[i]);
2276 _this.el.append(iter);
2277 var p = _this.el.get_path(iter).to_string();
2279 _this.el.set_value(iter, 0, ''+i);
2280 _this.el.set_value(iter, 1, '' + ar[i]);
2281 _this.el.set_value(iter, 2, ''+i);
2282 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2283 _this.el.set_value(iter, 4, ''+type);
2284 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2288 startEditing : function(path,col) {
2290 // alled by menu 'edit' currently..
2292 * start editing path (or selected if not set..)
2293 * @param {String|false} path (optional) treepath to edit - selected tree gets
2294 * edited by default.
2295 * @param {Number} 0 or 1 (optional)- column to edit.
2297 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2299 if (typeof(path) == 'string') {
2300 tp = new Gtk.TreePath.from_string(path);
2302 var iter = new Gtk.TreeIter();
2303 var s = this.get('/LeftPanel.view').selection;
2304 s.get_selected(this.el, iter);
2305 tp = this.el.get_path(iter);
2306 path = tp.to_string();
2310 // which colum is to be edited..
2313 // not sure what this does..
2315 if (typeof(col) == 'undefined') {
2316 var k = this.getValue(path, 0);
2318 colObj = (!k.length || k == '|') ?
2319 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2321 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2324 // make sure the pulldown is set correctly..
2325 // not really needed for second col...
2326 var showEditor = false;
2327 this.get('/Editor').activePath = false;
2328 this.get('/Editor').el.hide();
2331 var provider = this.get('/LeftTree').getPaleteProvider();
2332 var type = this.get('/LeftPanel.model').getType(path);
2333 var opts = provider.findOptions(type);
2334 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2336 if (opts === false) {
2337 this.get('/LeftPanel').editableColumn.setOptions([]);
2338 renderer.has_entry = true;
2340 this.get('/LeftPanel').editableColumn.setOptions(opts);
2341 renderer.has_entry = false;/// - pulldowns do not have entries
2343 // determine if we should use the Text editor...
2344 var keyname = this.getValue(path, 0);
2345 var data_value = this.getValue(path, 1);
2347 if ((keyname[0] == '|') ||
2349 (typeof(data_value) == 'string' ) &&
2350 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2354 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2359 // this.get('/BottomPane').el.hide();
2360 //this.get('/RightEditor').el.hide();
2365 this.activePath = false;
2367 _this.get('/Editor').el.show_all();
2368 GLib.timeout_add(0, 1, function() {
2370 //_this.get('/BottomPane').el.show();
2371 //_this.get('/RightEditor').el.show();
2373 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2375 _this.get('/Editor').activePath = path;
2376 _this.activePath = path ;
2386 // iter now has row...
2387 GLib.timeout_add(0, 100, function() {
2388 _this.activePath = path;
2389 colObj.items[0].el.editable = true; // esp. need for col 0..
2390 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2400 var iter = new Gtk.TreeIter();
2401 this.get('/LeftPanel.model').el.get_iter_first(iter);
2406 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2409 ar.listeners = ar.listeners || {};
2410 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2413 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2416 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2422 //print(JSON.stringify(ar));
2426 toShort : function(str) {
2427 var a = typeof(str) == 'string' ? str.split("\n") : [];
2428 return a.length > 1 ? a[0] + '....' : '' + str;
2432 xtype: Gtk.TreeViewColumn,
2433 pack : "append_column",
2435 XObject.prototype.init.call(this);
2437 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2438 this.get('/LeftPanel').propertyColumn = this;
2443 xtype: Gtk.CellRendererText,
2444 pack : "pack_start",
2446 editing_started : function (self, editable, path) {
2448 this.get('/LeftPanel.model').activePath = path;
2451 edited : function (self, object, p0) {
2452 var model = this.get('/LeftPanel.model');
2453 var path = model.activePath;
2454 var iter = new Gtk.TreeIter();
2455 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2456 model.el.set_value(iter, 0, p0);
2457 model.el.set_value(iter, 2, p0);
2459 model.activePath = false;
2461 this.get('/LeftTree.model').changed(model.toJS(), true);
2462 this.el.editable = false;
2469 xtype: Gtk.TreeViewColumn,
2470 pack : "append_column",
2473 XObject.prototype.init.call(this);
2474 this.el.add_attribute(this.items[0].el , 'text', 3 );
2475 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2476 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2477 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2479 this.get('/LeftPanel').editableColumn= this;
2481 setOptions : function(ar) {
2482 var m = this.items[0].el.model;
2484 var iter = new Gtk.TreeIter();
2485 ar.forEach(function(i) {
2488 m.set_value(iter, 0, i);
2494 xtype: Gtk.CellRendererCombo,
2496 edited : function (self, object, p0) {
2497 this.get('/LeftPanel').editing = false;
2498 var ap = this.get('/LeftPanel.model').activePath
2499 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2500 this.get('/LeftPanel.model').changed(p0, true);
2501 this.get('/LeftPanel.model').activePath = false;
2502 this.el.editable = false;
2504 editing_started : function (self, editable, path) {
2505 this.get('/LeftPanel').editing = true;
2506 // console.log('editing started');
2507 // r.has_entry = false;
2509 this.el.editable = false; // make sure it's not editor...
2514 pack : "pack_start",
2518 XObject.prototype.init.call(this);
2519 this.el.model = new Gtk.ListStore();
2520 this.el.model.set_column_types ( 1, [
2521 GObject.TYPE_STRING // 0 real key
2532 id : "LeftPanelPopup",
2535 xtype: Gtk.MenuItem,
2539 activate : function (self) {
2540 this.get('/LeftPanel.model').deleteSelected();
2545 xtype: Gtk.MenuItem,
2549 activate : function (self) {
2550 this.get('/LeftPanel.model').startEditing(false, 0);
2563 xtype: Gtk.ScrolledWindow,
2564 pack : "pack_end,false,true,0",
2566 shadow_type : Gtk.ShadowType.IN,
2568 XObject.prototype.init.call(this);
2569 XObject.prototype.init.call(this);
2570 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2571 this.el.set_size_request ( 150, -1 );
2574 activeElement : false,
2575 hideWin : function() {
2582 if (this.get('/Window.left').el.position < 160) {
2585 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2592 xtype: Gtk.TreeView,
2594 cursor_changed : function (self) {
2595 var iter = new Gtk.TreeIter();
2597 //console.log('changed');
2598 var m = this.get('model');
2599 if (!this.selection){
2600 this.selection = this.el.get_selection();
2603 var s = this.selection;
2604 if (!s.get_selected(m.el, iter)) {
2607 var tp = m.el.get_path(iter).to_string();
2612 var key = m.getValue(tp, 0);
2614 var type = m.getValue(tp, 1);
2615 var skel = m.getValue(tp, 3);
2616 var etype = m.getValue(tp, 5);
2619 this.get('/MidPropTree').hideWin();
2621 if (type.toLowerCase() == 'function') {
2623 if (etype != 'events') {
2627 this.get('/LeftPanel.model').add({
2635 // has dot in name, and is boolean???? this does not make sense..
2636 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2640 this.get('/LeftPanel.model').add( {
2650 enable_tree_lines : true,
2651 headers_visible : false,
2653 XObject.prototype.init.call(this);
2655 var description = new Pango.FontDescription.c_new();
2656 description.set_size(8000);
2657 this.el.modify_font(description);
2659 //this.selection = this.el.get_selection();
2660 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2669 xtype: Gtk.ListStore,
2672 getValue : function(treepath, col)
2674 var tp = new Gtk.TreePath.from_string (treepath);
2675 var iter = new Gtk.TreeIter();
2676 this.el.get_iter (iter, tp);
2677 var value = new GObject.Value('');
2678 this.el.get_value(iter, col, value);
2683 XObject.prototype.init.call(this);
2684 this.el.set_column_types ( 6, [
2685 GObject.TYPE_STRING, // real key
2686 GObject.TYPE_STRING, // real type
2687 GObject.TYPE_STRING, // docs ?
2688 GObject.TYPE_STRING, // visable desc
2689 GObject.TYPE_STRING, // function desc
2690 GObject.TYPE_STRING // element type (event|prop)
2694 showData : function(type) {
2696 if (!this.get('/MidPropTree').activeElement || !type) {
2697 return; // no active element
2700 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2701 var palete = this.get('/LeftTree').getPaleteProvider();
2705 Seed.print('Showing right?');
2706 if (!this.get('/MidPropTree').shown) {
2708 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2709 this.get('/MidPropTree').el.show();
2710 this.get('/MidPropTree').shown = true;
2713 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2714 return a.name > b.name ? 1 : -1;
2716 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2717 // console.dump(elementList);
2720 var iter = new Gtk.TreeIter();
2721 for(var i =0 ; i < elementList.length; i++) {
2722 var p=elementList[i];
2723 this.el.append(iter);
2724 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2725 //GObject.TYPE_STRING, // real key
2726 // GObject.TYPE_STRING, // real type
2727 // GObject.TYPE_STRING, // docs ?this.el.set_value(iter, 0, p.name);et_value(iter, 0, p.name);
2728 // GObject.TYPE_STRING // func def?
2731 this.el.set_value(iter, 0, p.name);
2732 this.el.set_value(iter, 1, p.type);
2733 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2734 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2735 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2736 this.el.set_value(iter, 5, type);
2743 xtype: Gtk.TreeViewColumn,
2746 this.el = new Gtk.TreeViewColumn();
2747 this.parent.el.append_column(this.el);
2749 XObject.prototype.init.call(this);
2750 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2754 xtype: Gtk.CellRendererText,
2755 pack : "pack_start,true"
2779 xtype: Gtk.Notebook,
2780 pack : "pack_start,true,true",
2781 id : "view-help-nb",
2783 XObject.prototype.init.call(this);
2784 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2785 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2789 xtype: Gtk.Notebook,
2790 id : "view-notebook",
2794 XObject.prototype.init.call(this);
2795 this.el.set_current_page(0);
2796 //print("SET LABEL?")
2797 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2798 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2804 id : "RightBrowser",
2809 pack : "pack_start,false,true,0",
2814 clicked : function (self) {
2815 this.get('/RightBrowser.view').renderJS(null,true);
2819 pack : "pack_start,false,false,0"
2822 xtype: Gtk.CheckButton,
2824 toggled : function (self, state) {
2825 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2830 label : "Auto Redraw On",
2831 pack : "pack_start,false,false,0"
2836 clicked : function (self) {
2837 this.get('/RightBrowser.view').redraws = 99;
2838 this.get('/RightBrowser.view').renderJS(null,true);
2841 label : "Full Redraw",
2842 pack : "pack_start,false,false,0"
2847 xtype: Gtk.ScrolledWindow,
2850 XObject.prototype.init.call(this);
2851 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2853 shadow_type : Gtk.ShadowType.IN,
2856 xtype: WebKit.WebView,
2858 load_finished : function (self, object) {
2859 print("load finished");
2860 // print("load_finished"); return;
2861 // if (this.ready) { // dont do it twice!
2864 if (!this.inspectorShown) {
2865 this.el.get_inspector().show();
2866 this.inspectorShown = true;
2871 if (this.pendingRedraw) {
2872 this.pendingRedraw = false;
2873 this.refreshRequired = true;
2875 //var js = this.get('/LeftTree.model').toJS();
2876 //if (js && js[0]) {
2877 // this.renderJS(js[0]);
2881 script_alert : function (self, object, p0) {
2884 return true; // do not display anything...
2886 console_message : function (self, object, p0, p1) {
2888 // console.log(object);
2891 if (object.match(/variable/) && object.match(/Builder/)) {
2892 print("got builder missing message");
2893 this.refreshRequired = true;
2894 this.lastRedraw = 0;
2900 if (!object.match(/^\{/)) {
2902 //this.get('/Terminal').feed(object);
2903 return true; // do not handle!!! -> later maybe in console..
2909 // console.log(object);
2910 var val = JSON.parse(object);
2912 if (typeof(val['hover-node']) != 'undefined') {
2913 this.activeNode = val['hover-node'];
2914 console.log('active node: ' + this.activeNode);
2919 if (typeof(val['id']) != 'undefined') {
2920 // this.activeNode = val['id'];
2921 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2922 if (!tg || typeof(tg[0]) == 'undefined') {
2925 print("SELECT node " + tg[0]);
2927 this.get('/LeftTree.view').selectNode(tg[0]);
2931 if (ret && typeof(val['set']) != 'undefined') {
2932 this.get('/LeftPanel.model').add({
2936 //console.log('active node: ' + this.activeNode);
2939 //Seed.print('a:'+a);
2940 //Seed.print('b:'+b);
2941 //Seed.print('c:'+c);
2944 drag_motion : function (w, ctx, x, y, time, ud) {
2945 // console.log('DRAG MOTION');
2947 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2948 this.targetData = [];
2949 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2951 // A) find out from drag all the places that node could be dropped.
2952 var src = Gtk.drag_get_source_widget(ctx);
2953 if (!src.dropList) {
2954 Gdk.drag_status(ctx, 0, time);
2957 // b) get what we are over.. (from activeNode)
2958 // tree is empty.. - list should be correct..
2959 if (!this.get('/LeftTree.model').currentTree) {
2960 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2964 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2966 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2969 Gdk.drag_status(ctx, 0,time);
2970 this.get('/LeftTree.view').highlight(false);
2974 // if we have a target..
2975 // -> highlight it! (in browser)
2976 // -> highlight it! (in tree)
2978 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2979 this.get('/LeftTree.view').highlight(tg);
2980 this.targetData = tg;
2981 // for tree we should handle this...
2984 drag_drop : function (w, ctx, x, y,time, ud) {
2985 print("TARGET: drag-drop");
2986 var is_valid_drop_site = true;
2991 w, /* will receive 'drag-data-received' signal */
2992 ctx, /* represents the current state of the DnD */
2993 this.get('/Window').atoms["STRING"], /* the target type we want */
2994 time /* time stamp */
2998 /* No target offered by source => error */
3001 return is_valid_drop_site;
3003 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3005 print("Browser: drag-data-received");
3006 var delete_selection_data = false;
3007 vardnd_success = false;
3008 /* Deal with what we are given from source */
3009 if( sel_data && sel_data.length ) {
3011 if (ctx.action == Gdk.DragAction.ASK) {
3012 /* Ask the user to move or copy, then set the ctx action. */
3015 if (ctx.action == Gdk.DragAction.MOVE) {
3016 delete_selection_data = true;
3018 var source = Gtk.drag_get_source_widget(ctx);
3020 print("Browser: source.DRAGDATA? " + source.dragData);
3021 if (this.targetData) {
3022 print(this.targetData);
3023 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3032 if (dnd_success == false)
3034 Seed.print ("DnD data transfer failed!\n");
3037 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3040 create_web_view : function (self, object) {
3041 print("CREATE WEB VIEW");
3042 return null; //new WebKit.WebView();
3049 XObject.prototype.init.call(this);
3050 // this may not work!?
3051 var settings = this.el.get_settings();
3052 settings.enable_developer_extras = true;
3054 // this was an attempt to change the url perms.. did not work..
3055 // settings.enable_file_access_from_file_uris = true;
3056 // settings.enable_offline_web_application_cache - true;
3057 // settings.enable_universal_access_from_file_uris = true;
3061 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3062 _this.get('/BottomPane.inspector').el.show();
3063 return _this.get('/BottomPane.inspector').el;
3067 // FIXME - base url of script..
3068 // we need it so some of the database features work.
3069 this.el.load_html_string( "Render not ready" ,
3070 //fixme - should be a config option!
3071 // or should we catch stuff and fix it up..
3072 'http://localhost/app.Builder/'
3076 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3080 this.el, /* widget that will accept a drop */
3081 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3082 null, /* lists of target to support */
3083 0, /* size of list */
3084 Gdk.DragAction.COPY /* what to do with data after dropped */
3087 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3088 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3090 GLib.timeout_add_seconds(0, 1, function() {
3091 // print("run refresh?");
3098 renderJS : function(data, force) {
3100 // this is the public redraw call..
3101 // we refresh in a loop privately..
3102 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3103 if (!autodraw && !force) {
3104 print("Skipping redraw - no force, and autodraw off");
3107 this.refreshRequired = true;
3109 runRefresh : function()
3111 // this is run every 2 seconds from the init..
3115 if (!this.refreshRequired) {
3116 // print("no refresh required");
3120 if (this.lastRedraw) {
3121 // do not redraw if last redraw was less that 5 seconds ago.
3122 if (((new Date()) - this.lastRedraw) < 5000) {
3130 if (!this.get('/Window.LeftTree').getActiveFile()) {
3133 this.refreshRequired = false;
3134 // print("HTML RENDERING");
3136 this.get('/BottomPane').el.show();
3137 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3140 var js = this.get('/LeftTree.model').toJS();
3141 if (!js || !js.length) {
3148 var project = this.get('/Window.LeftTree').getActiveFile().project;
3149 //print (project.fn);
3150 // set it to non-empty.
3151 project.runhtml = project.runhtml || '';
3152 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3155 this.runhtml = this.runhtml || '';
3157 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3158 // then we need to reload the browser using
3159 // load_html_string..
3161 // then trigger a redraw once it's loaded..
3162 this.pendingRedraw = true;
3163 var runhtml = '<script type="text/javascript">' + "\n" ;
3164 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3165 runhtml += '</script>'+ "\n" ;
3167 this.runhtml = project.runhtml;
3168 // need to modify paths
3172 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3173 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3174 print("LOAD HTML " + html);
3175 this.el.load_html_string( html ,
3176 //fixme - should be a config option!
3177 'http://localhost/app.Builder/'
3180 // should trigger load_finished! - which in truns shoudl set refresh Required;
3186 this.renderedData = data;
3187 var str = JSON.stringify(data) ;
3190 console.log('not loaded yet');
3192 this.lastRedraw = new Date();
3194 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3195 print( "before render" + this.lastRedraw);
3196 print( "after render" + (new Date()));
3206 id : "RightGtkView",
3208 redraw : function() {
3209 this.highlightWidget = false;
3210 print("REDRAW CALLED");
3211 this.activePath = this.get('/LeftTree').getActivePath();
3212 if (this.renderedEl) {
3213 print("QUEUE DRAW CALLING");
3214 this.renderedEl.queue_draw();
3217 renderJS : function(data, withDebug)
3219 this.highlightWidget = false;
3221 this.withDebug = false;
3222 while (this.get('view').el.get_children().length) {
3223 var c = this.get('view').el.get_children()[0];
3224 this.get('view').el.remove(c);
3231 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3232 // in theory tree is actually window..
3235 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3241 this.get('view').el.set_size_request(
3242 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3244 if (this.renderedEl) {
3245 this.renderedEl.set_size_request(
3246 tree.default_width || 600,
3247 tree.default_height || 400
3250 this.get('view').el.show_all();
3255 showInWindow : function() {
3256 print("GET PROEJCT");
3257 var pr = this.get('/LeftProjectTree').getActiveProject();
3259 console.log(pr.paths);
3262 var src= this.buildJS(
3263 this.get('/LeftTree.model').toJS()[0],
3268 //var x = new imports.sandbox.Context();
3272 Seed.check_syntax('var e = ' + src);
3275 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3276 this.get('/Terminal').feed(console._dump(e)+"\n");
3278 var lines = src.split("\n");
3279 var start = Math.max(0, e.line - 10);
3280 var end = Math.min(lines.length, e.line + 10);
3281 for (var i =start ; i < end; i++) {
3283 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3286 this.get('/Terminal').feed(lines[i] + "\n");
3293 this.get('/BottomPane').el.set_current_page(1);
3294 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3295 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3296 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3298 var _top = x.get_global_object()._top;
3300 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3302 if (_top.el.popup) {
3303 _top.el.popup(null, null, null, null, 3, null);
3307 viewAdd : function(item, par)
3310 // does something similar to xobject..
3311 //item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3313 // pack is forced to 'false'
3314 if (item.pack===false || item.pack === 'false') { // no ;
3318 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3321 var type = item['|xns'] + '.' + item['xtype'];
3323 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3327 var ns = imports.gi[item['|xns']];
3328 var ctr = ns[item['xtype']]; // why are we using array here..?
3333 for(var k in item) {
3335 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3349 // value is a function..
3350 if (k[0] == '|' && typeof(kv) == 'string') {
3352 if (kv.match(new RegExp('function'))) {
3355 print("WASL " + k + '=' + kv);
3357 eval( 'kv = ' + kv);
3358 } catch(e) { continue; }
3361 // print(k + '=' + kv);
3363 if (k[0] == '|') { // should be boolean or number..
3365 //print(k + '=' + kv);
3368 if (k == 'show_tabs') { // force tab showing for notebooks.
3371 print(k + '=' + typeof(kv) + " : " + kv);
3375 var altctr = XObject.baseXObject({ xtype: ctr} );
3377 if (!item.pack && altctr) {
3379 print("SETTING PACK TO XObjectBase method");
3380 pack_m = altctr.prototype.pack;
3385 var el = new ctr(ctr_args);
3387 print("PACK" + item.pack);
3388 //console.dump(item.pack);
3395 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3396 if (typeof(item.pack) == 'string') {
3398 item.pack.split(',').forEach(function(e, i) {
3400 if (e == 'false') { args.push( false); return; }
3401 if (e == 'true') { args.push( true); return; }
3402 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3405 //print(args.join(","));
3407 pack_m = args.shift();
3409 pack_m = item.pack.shift();
3414 if (typeof(pack_m) == 'string' && typeof(par[pack_m]) == 'undefined') {
3416 name: "ArgumentError",
3417 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3418 "ADDING : " + item.id + " " + el
3427 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3428 //Seed.print('args: ' + args.length);
3429 if (typeof(pack_m) == 'string') {
3430 par[pack_m].apply(par, args);
3431 } else if (pack_m) {
3432 pack_m.call(item, par, item);
3436 item.items = item.items || [];
3437 item.items.forEach(function(ch,n) {
3439 print ("type:" + type);
3441 print ("ch.pack:" + ch.pack);
3444 if (type == 'Gtk.Table' && ch.pack == 'add') {
3445 var c = n % item.n_columns;
3446 var r = Math.floor(n/item.n_columns);
3447 ch.pack = [ 'attach', c, c+1, r, r+1,
3448 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3449 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3450 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3451 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3455 _this.viewAdd(ch, el);
3460 // add the signal handlers.
3461 // is it a widget!?!!?
3467 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3468 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3469 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3470 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3471 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3481 widgetDragDropEvent : function() {
3482 print("WIDGET DRAGDROP");
3485 widgetDragMotionEvent : function() {
3486 print("WIDGET DRAGMOTION");
3489 widgetExposeEvent : function(w, evt, ud, item) {
3491 if (this.inRender) {
3495 if ( this.highlightWidget) {
3496 this.inRender = true;
3497 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3498 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3500 this.inRender = false;
3505 if (this.activePath != item.xtreepath) {
3509 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3510 // work out the coords of the window..
3512 var dr = widget.window;
3513 this.gc = (new Gdk.GC.c_new(dr));
3514 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3515 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3519 var r = evt.expose.area;
3520 // console.dump([r.x, r.y, r.width, r.height ] );
3522 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3523 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3524 // happens with gtkscrollview embedded stuff..
3525 var np =this.activePath.split(':');
3527 this.activePath = np.join(':');
3528 this.renderedEl.queue_draw();
3544 this.inRender = true;
3547 this.highlightWidget = widget;
3552 // print("DRAW BOX");
3553 //console.dump(this.box);
3554 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3555 this.inRender = false;
3558 widgetPressEvent : function(w,e,u,d) {
3559 if (this.get('view').pressed) {
3562 this.get('view').pressed = true;
3563 print("WIDGET PRESS " + d.xtreepath );
3564 this.get('/LeftTree.view').selectNode( d.xtreepath );
3567 widgetReleaseEvent : function() {
3568 this.get('view').pressed = false;
3574 pack : "pack_start,false,true,0",
3578 pack : "pack_start,false,false,0",
3579 label : "Run The Application",
3581 button_press_event : function (self, event) {
3582 // call render on left tree - with special option!?!
3584 //print("GET PROEJCT");
3585 var pr = this.get('/LeftProjectTree').getActiveProject();
3588 for (var i in pr.paths) {
3592 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3593 this.get('/Terminal').feed("RUN DIR:" + dir);
3595 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3596 , false,false,false);
3597 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3598 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3608 xtype: Gtk.ScrolledWindow,
3611 shadow_type : Gtk.ShadowType.IN,
3613 XObject.prototype.init.call(this);
3614 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3618 xtype: Gtk.EventBox,
3619 pack : "add_with_viewport",
3621 XObject.prototype.init.call(this);
3622 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3623 red: 0x9F00, green: 0xB800 , blue : 0xA800
3631 XObject.prototype.init.call(this);
3632 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3633 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3638 xtype: Gtk.EventBox,
3641 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3642 XObject.prototype.init.call(this);
3646 this.el, /* widget that will accept a drop */
3647 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3648 null, /* lists of target to support */
3649 0, /* size of list */
3650 Gdk.DragAction.COPY /* what to do with data after dropped */
3653 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3654 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3657 getActiveNode : function(x,y)
3659 // workout what node is here..
3660 return '0'; // top..
3664 drag_motion : function (self, ctx, x, y, time) {
3666 // A) find out from drag all the places that node could be dropped.
3667 var src = Gtk.drag_get_source_widget(ctx);
3668 if (!src.dropList) {
3669 Gdk.drag_status(ctx, 0, time);
3672 // b) get what we are over.. (from activeNode)
3673 // tree is empty.. - list should be correct..
3674 if (!this.get('/LeftTree.model').currentTree) {
3675 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3679 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3680 var activeNode = this.getActiveNode(x, y);
3683 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3686 Gdk.drag_status(ctx, 0,time);
3687 this.get('/LeftTree.view').highlight(false);
3691 // if we have a target..
3692 // -> highlight it! (in browser)
3693 // -> highlight it! (in tree)
3695 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3696 this.get('/LeftTree.view').highlight(tg);
3697 this.targetData = tg;
3698 // for tree we should handle this...
3701 drag_drop : function (self,ctx, x, y, time) {
3702 Seed.print("TARGET: drag-drop");
3703 var is_valid_drop_site = true;
3708 self, /* will receive 'drag-data-received' signal */
3709 ctx, /* represents the current state of the this.gDnD */
3710 this.get('/Window').atoms["STRING"], /* the target type we want */
3711 time /* time stamp */
3715 /* No target offered by source => error */
3718 return is_valid_drop_site;
3721 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3723 Seed.print("GtkView: drag-data-received");
3724 var delete_selection_data = false;
3725 var dnd_success = false;
3726 /* Deal with what we are given from source */
3727 if( sel_data && sel_data.length ) {
3729 if (ctx.action == Gdk.DragAction.ASK) {
3730 /* Ask the user to move or copy, then set the ctx action. */
3733 if (ctx.action == Gdk.DragAction.MOVE) {
3734 delete_selection_data = true;
3736 var source = Gtk.drag_get_source_widget(ctx);
3738 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3739 if (this.targetData) {
3740 Seed.print(this.targetData);
3741 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3750 if (dnd_success == false)
3752 Seed.print ("DnD data transfer failed!\n");
3755 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3758 button_press_event : function (self, event) {
3759 this.pressed = false;
3775 xtype: Gtk.ScrolledWindow,
3780 var file = this.get('/LeftTree').getActiveFile();
3784 var activeEl = this.get('/LeftTree').getActiveElement();
3785 var xtype = file.guessName( activeEl )
3786 if (!xtype || !xtype.length) {
3789 //this.get('/Window.view-help-nb').el.set_current_page(1);
3791 // get the active element being edited.
3792 var helpurl = file.getHelpUrl(xtype);
3794 // now load the help info in the page..
3795 this.get('help-view').el.open(helpurl);
3799 xtype: WebKit.WebView,
3803 XObject.prototype.init.call(this);
3804 this.get('/Window.help-view').el.open(
3805 "http://devel.akbkhome.com/seed/");
3817 xtype: Gtk.Notebook,
3821 XObject.prototype.init.call(this);
3822 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3823 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3824 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3828 xtype: Gtk.ScrolledWindow,
3832 xtype: Vte.Terminal,
3835 feed : function(istr) {
3836 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3837 // we should make ourselves visable!!!
3838 this.get('/BottomPane').el.show();
3839 this.get('/BottomPane').el.set_current_page(1);
3841 this.el.feed(str ,str.length);
3843 scroll_on_output : true,
3845 XObject.prototype.init.call(this);
3846 this.el.set_size (80, 1000);
3848 scrollback_lines : 1000
3853 xtype: Gtk.ScrolledWindow,
3857 xtype: WebKit.WebView,
3869 pack : "pack_start,false,false",
3873 this.get('buttonbar').el.show();
3874 this.get('viewbox').el.hide();
3875 print("TRIED TO HIDE");
3878 this.get('buttonbar').el.hide();
3879 this.get('viewbox').el.show();
3880 // this.get('model').expanded();
3892 pack : "pack_start,false,true",
3894 clicked : function (self) {
3895 this.get('/RightPalete').show();
3902 stock : Gtk.STOCK_GOTO_FIRST,
3903 icon_size : Gtk.IconSize.MENU
3913 XObject.prototype.init.call(this);
3914 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3917 enter_notify_event : function (self, event) {
3918 this.get('/RightPalete').show();
3932 pack : "pack_start,false,true",
3941 pack : "pack_start,false,true",
3943 clicked : function (self) {
3944 this.get('/RightPalete').hide();
3951 stock : Gtk.STOCK_GOTO_LAST,
3952 icon_size : Gtk.IconSize.MENU
3959 xtype: Gtk.ScrolledWindow,
3962 XObject.prototype.init.call(this);
3963 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3964 this.el.set_size_request(-1,200);
3966 shadow_type : Gtk.ShadowType.IN,
3969 xtype: Gtk.TreeView,
3971 drag_begin : function (self, ctx) {
3972 // we could fill this in now...
3973 Seed.print('SOURCE: drag-begin');
3977 var iter = new Gtk.TreeIter();
3978 var s = this.selection;
3979 s.get_selected(this.get('/RightPalete.model').el, iter);
3980 var path = this.get('/RightPalete.model').el.get_path(iter);
3982 var pix = this.el.create_row_drag_icon ( path);
3985 Gtk.drag_set_icon_pixmap (ctx,
3992 var value = new GObject.Value('');
3993 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3994 if (!this.get('/RightPalete').provider) {
3997 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3998 this.el.dragData = value.value;
4005 drag_data_get : function (self, drag_context, selection_data, info, time) {
4006 //Seed.print('Palete: drag-data-get: ' + target_type);
4007 if (this.el.dragData && this.el.dragData.length ) {
4008 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4012 //this.el.dragData = "TEST from source widget";
4016 drag_end : function (self, drag_context) {
4017 Seed.print('SOURCE: drag-end');
4018 this.el.dragData = false;
4019 this.el.dropList = false;
4020 this.get('/LeftTree.view').highlight(false);
4023 button_press_event : function (self, event) {
4025 if (!this.get('/Editor').save()) {
4026 // popup!! - click handled..
4033 enable_tree_lines : true,
4034 headers_visible : false,
4036 XObject.prototype.init.call(this);
4037 this.el.set_size_request(150,-1);
4038 // set_reorderable: [1]
4040 var description = new Pango.FontDescription.c_new();
4041 description.set_size(8000);
4042 this.el.modify_font(description);
4044 this.selection = this.el.get_selection();
4045 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4046 // this.selection.signal['changed'].connect(function() {
4047 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4049 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4051 Gtk.drag_source_set (
4052 this.el, /* widget will be drag-able */
4053 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4054 null, /* lists of target to support */
4055 0, /* size of list */
4056 Gdk.DragAction.COPY /* what to do with data after dropped */
4058 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4060 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
4061 Gtk.drag_source_add_text_targets(this.el);
4063 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4064 targets = new Gtk.TargetList();
4065 targets.add( LeftTree.atoms["STRING"], 0, 0);
4066 targets.add_text_targets( 1 );
4067 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4069 //if you want to allow text to be output elsewhere..
4070 //Gtk.drag_source_add_text_targets(this.el);
4076 xtype: Gtk.ListStore,
4079 XObject.prototype.init.call(this);
4080 this.el.set_column_types ( 2, [
4081 GObject.TYPE_STRING, // title
4082 GObject.TYPE_STRING // tip
4087 load : function(tr,iter)
4092 //console.log('Project tree load: ' + tr.length);
4093 var citer = new Gtk.TreeIter();
4094 //this.insert(citer,iter,0);
4095 for(var i =0 ; i < tr.length; i++) {
4098 this.el.append(citer);
4100 this.el.insert(citer,iter,-1);
4105 this.el.set_value(citer, 0, '' + r ); // title
4107 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4108 //if (r.cn && r.cn.length) {
4109 // this.load(r.cn, citer);
4115 getValue : function (iter, col) {
4116 var gval = new GObject.Value('');
4117 this.el.get_value(iter, col ,gval);
4124 xtype: Gtk.TreeViewColumn,
4125 pack : "append_column",
4127 XObject.prototype.init.call(this);
4128 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4132 xtype: Gtk.CellRendererText,
4154 XObject.cache['/Window'] = Window;