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 console = imports.console;
12 XObject = imports.XObject.XObject;
15 type : Gtk.WindowType.TOPLEVEL,
16 title : "Application Builder",
20 "STRING" : Gdk.atom_intern("STRING")
22 this.targetList = new Gtk.TargetList();
23 this.targetList.add( this.atoms["STRING"], 0, 0);
24 //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
26 "style \"gtkcombobox-style\" {\n" +
27 " GtkComboBox::appears-as-list = 1\n" +
29 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
30 XObject.prototype.init.call(this);
39 setTitle : function(str) {
40 this.el.set_title(this.title + ' - ' + str);
43 delete_event : function (self, event) {
46 destroy : function (self) {
49 show : function (self) {
50 print("WINDOW SHOWING - trying to hide");
51 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
52 this.get('/MidPropTree').hideWin();
53 this.get('/RightPalete').hide();
54 this.get('/BottomPane').el.hide();
65 pack : "pack_start,false,false",
79 label : "New _Project",
81 activate : function (self) {
83 this.get('/EditProject').show({
84 success : function(pr) {
85 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
96 activate : function (self) {
97 var fn = this.get('/LeftProjectTree.combo').getValue();
99 this.get('/LeftProjectTree').showNoProjectSelected();
102 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
103 this.get('/DialogNewComponent').show({
104 project : pm.getByFn(fn)
110 xtype: Gtk.SeparatorMenuItem,
115 use_underline : true,
117 label : "D_elete Project",
119 activate : function (self) {
121 var fn = this.get('/LeftProjectTree').get('combo').getValue();
123 this.get('/StandardErrorDialog').show("Select a project")
126 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
127 var pr = pm.getByFn(fn);
130 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
131 pm.deleteProject(fn);
139 xtype: Gtk.SeparatorMenuItem,
146 use_underline : true,
148 activate : function (self) {
160 use_underline : true,
165 pack : "set_submenu",
170 activate : function (self) {
171 var fn = this.get('/LeftTree').getActiveFile();
173 this.get('/StandardErrorDialog').show("No File active");
177 this.get('/DialogNewComponent').show(fn);
181 label : "File _Properties",
188 activate : function (self, event) {
189 this.get('/RooProjectProperties').show();
193 label : "Modify Project HTML ",
204 use_underline : true,
208 pack : "set_submenu",
213 activate : function (self, event) {
214 var js = this.get('/LeftTree.model').toJS();
216 this.get('/RightBrowser.view').renderJS(js[0], true);
221 label : "_Redraw (Roo)",
228 activate : function (self, event)
230 /* Firefox testing for debugging..
231 - we can create a /tmp directory, and put.
232 builder.html, builder.html.js, link roojs1
233 add at the end of builder.html Roo.onload(function() {
235 if (!this.get('/Window.LeftTree').getActiveFile()) {
239 var js = this.get('/LeftTree.model').toJS();
243 var project = this.get('/Window.LeftTree').getActiveFile().project;
244 //print (project.fn);
246 project.runhtml = project.runhtml || '';
249 var File = imports.File.File;
251 var target = "/tmp/firetest"; // fixme..
252 if (!File.isDirectory(target)) {
255 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
256 if (!File.exists( target+ '/roojs1')) {
257 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
262 var html = imports.File.File.read(__script_path__ + '/../builder.html');
263 html = html.replace('</head>', project.runhtml + '</head>');
266 var jsstr = JSON.stringify(js[0], null, 4);
268 var runbuilder = '<script type="text/javascript">' + "\n" +
269 " Builder.render(" + jsstr + ");\n" +
272 html = html.replace('</body>', runbuilder + '</body>');
274 File.write( target+ '/builder.html', html);
276 this.get('/Terminal').feed("RUN DIR:" + target);
278 this.get('/Terminal').el.fork_command( null , [], [], target
279 , false,false,false);
280 var cmd = "firefox file://" + target + "/builder.html \n";
281 this.get('/Terminal').el.feed_child(cmd, cmd.length);
285 label : "_Test in Firefox (Roo)",
296 use_underline : true,
301 pack : "set_submenu",
307 use_underline : true,
309 activate : function (self) {
310 this.get('/About').el.run();
340 activate : function (self) {
341 // this does not actually expand it..
342 // that is done by GTK..
346 if (!this.el.expanded) {
353 enter_notify_event : function (self, event) {
355 this.el.expanded = !this.el.expanded;
356 //if (this.el.expanded ) {
357 this.listeners.activate.call(this);
364 label : "Select Project or File",
365 pack : "pack_start,false,true",
366 onCollapse : function() {
368 var nb = this.get('/LeftTopPanel.notebook');
369 nb.el.set_current_page(0);
372 XObject.prototype.init.call(this);
373 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
375 onExpand : function() {
376 var nb = this.get('/LeftTopPanel.notebook');
377 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
380 var model = this.get('/LeftProjectTree.combomodel');
381 // print ("loading Projects?")
382 //console.dump(pm.projects);
383 model.loadData(pm.projects);
386 nb.el.set_current_page(1);
387 //pm.on('changed', function() {
388 //console.log("CAUGHT project manager change");
389 // _combo.model.loadData(pm.projects);
397 pack : "pack_start,true,true",
399 XObject.prototype.init.call(this);
400 this.el.set_current_page(0);
407 xtype: Gtk.ScrolledWindow,
410 getActiveElement : function() { // return path to actie node.
412 var path = this.getActivePath();
416 var iter = new Gtk.TreeIter();
417 this.get('model').el.get_iter_from_string(iter, path);
419 var value = new GObject.Value('');
420 this.get('model').el.get_value(iter, 2, value);
422 return JSON.parse(value.value);
424 getActiveFile : function() {
425 return this.get('model').file;
427 getActivePath : function() {
428 var model = this.get('model');
429 var view = this.get('view');
430 if (view.selection.count_selected_rows() < 1) {
433 var iter = new Gtk.TreeIter();
435 view.selection.get_selected(model.el, iter);
436 return model.el.get_path(iter).to_string();
438 getPaleteProvider : function() {
439 var model = this.get('model');
440 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
441 return pm.getPalete(model.file.getType());
443 getRenderer : function() {
445 switch( this.getActiveFile().getType()) {
447 return this.get('/RightBrowser.view');
449 return this.get('/RightGtkView');
454 XObject.prototype.init.call(this);
455 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
457 renderView : function() {
458 var render = this.getRenderer();
459 var model = this.get('model');
461 render.renderJS(model.toJS(false,true)[0]);
463 print("NO RENDER JS METHOD?");
466 shadow_type : Gtk.ShadowType.IN,
471 button_press_event : function (self, ev) {
472 console.log("button press?");
473 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
474 print("click" + ev.type);
480 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
482 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
484 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
485 this.get('/LeftTreeMenu').el.show_all();
486 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
487 print("click:" + res.path.to_string());
490 drag_begin : function (self, drag_context) {
491 print('SOURCE: drag-begin');
492 this.targetData = false;
493 // find what is selected in our tree...
494 var iter = new Gtk.TreeIter();
495 var s = this.selection;
496 s.get_selected(this.get('/LeftTree.model').el, iter);
498 // set some properties of the tree for use by the dropped element.
499 var value = new GObject.Value('');
500 this.get('/LeftTree.model').el.get_value(iter, 2, value);
501 var data = JSON.parse(value.value);
502 var xname = this.get('/LeftTree.model').file.guessName(data);
504 this.el.dragData = xname;
505 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
508 // make the drag icon a picture of the node that was selected
509 var path = this.get('/LeftTree.model').el.get_path(iter);
510 this.el.treepath = path.to_string();
512 var pix = this.el.create_row_drag_icon ( path);
514 Gtk.drag_set_icon_pixmap (ctx,
523 drag_end : function (self, drag_context) {
524 Seed.print('LEFT-TREE: drag-end');
525 this.el.dragData = false;
526 this.el.dropList = false;
527 this.targetData = false;
528 this.get('/LeftTree.view').highlight(false);
531 drag_motion : function (self, ctx, x, y, time) {
532 console.log("LEFT-TREE: drag-motion");
533 var src = Gtk.drag_get_source_widget(ctx);
535 // a drag from elsewhere...- prevent drop..
537 print("no drag data!");
538 Gdk.drag_status(ctx, 0, time);
539 this.targetData = false;
542 var action = Gdk.DragAction.COPY;
543 if (src == this.el) {
544 // unless we are copying!!! ctl button..
545 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
549 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
550 // no children.. -- asume it's ok..
551 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
552 Gdk.drag_status(ctx, action ,time);
556 print("GETTING POS");
557 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
558 print("ISOVER? " + isOver);
560 Gdk.drag_status(ctx, 0 ,time);
561 return false; // not over apoint!?!
563 // drag node is parent of child..
564 console.log("SRC TREEPATH: " + src.treepath);
565 console.log("TARGET TREEPATH: " + data.path.to_string());
567 // nned to check a few here..
568 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
569 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
570 //Gtk.TreeViewDropPosition.AFTER
571 //Gtk.TreeViewDropPosition.BEFORE
573 if (typeof(src.treepath) != 'undefined' &&
574 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
575 print("subpath drag");
576 Gdk.drag_status(ctx, 0 ,time);
581 //print("DUMPING DATA");
582 //console.dump(data);
585 print(data.path.to_string() +' => '+ data.pos);
586 var tg = this.get('/LeftTree.model').findDropNodeByPath(
587 data.path.to_string(), src.dropList, data.pos);
589 this.get('/LeftTree.view').highlight(tg);
591 print("Can not find drop node path");
592 this.targetData = false;
593 Gdk.drag_status(ctx, 0, time);
597 this.targetData = tg;
600 Gdk.drag_status(ctx, action ,time);
604 drag_drop : function (w, ctx, x, y, time) {
605 Seed.print("TARGET: drag-drop");
609 w, /* will receive 'drag-data-received' signal */
610 ctx, /* represents the current state of the DnD */
611 this.get('/Window').atoms["STRING"], /* the target type we want */
612 time /* time stamp */
616 /* No target offered by source => error */
621 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
622 print("Tree: drag-data-received");
624 var delete_selection_data = false;
625 var dnd_success = false;
626 /* Deal with what we are given from source */
627 if( sel_data && sel_data.length ) {
629 if (ctx.action == Gdk.DragAction.ASK) {
630 /* Ask the user to move or copy, then set the ctx action. */
633 if (ctx.action == Gdk.DragAction.MOVE) {
634 //delete_selection_data = true;
637 var source = Gtk.drag_get_source_widget(ctx);
639 if (this.targetData) {
640 if (source != this.el) {
641 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
643 // drag around.. - reorder..
644 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
648 //Seed.print(this.targetData);
654 // we can send stuff to souce here...
660 if (dnd_success == false)
662 Seed.print ("DnD data transfer failed!\n");
665 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
668 cursor_changed : function (self) {
669 if (this.blockChanges) { // probably not needed..
672 var render = this.get('/LeftTree').getRenderer();
675 if (this.selection.count_selected_rows() < 1) {
676 this.get('/LeftPanel.model').load( false);
677 this.get('/MidPropTree').activeElement = false;
678 this.get('/MidPropTree').hideWin();
680 var pm = this.get('/RightPalete.model');
681 if (!this.get('/LeftTree').getPaleteProvider()) {
682 // it may not be loaded yet..
685 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
686 this.get('/LeftTree.model').listAllTypes()));
687 if (render && render.redraw) {
693 //console.log('changed');
694 var s = this.selection;
695 var iter = new Gtk.TreeIter();
696 s.get_selected(this.get('/LeftTree.model').el, iter);
700 var value = new GObject.Value('');
701 this.get('/LeftTree.model').el.get_value(iter, 2, value);
702 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
704 var data = JSON.parse(value.value);
705 this.get('/MidPropTree').activeElement = data;
706 this.get('/MidPropTree').hideWin();
707 this.get('/LeftPanel.model').load( data);
709 console.log(value.value);
710 // _g.button.set_label(''+value.get_string());
712 var pm =this.get('/RightPalete.model');
713 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
714 this.get('/LeftTree.model').listAllTypes()));
717 if (render && render.redraw) {
721 //Seed.print( value.get_string());
729 enable_tree_lines : true,
730 headers_visible : false,
731 highlight : function(treepath_ar) {
733 // highlighting for drag/drop
734 if (treepath_ar.length && treepath_ar[0].length ) {
735 this.el.set_drag_dest_row(
736 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
738 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
743 XObject.prototype.init.call(this);
744 var description = new Pango.FontDescription.c_new();
745 description.set_size(8000);
746 this.el.modify_font(description);
748 this.selection = this.el.get_selection();
749 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
752 // is this really needed??
753 this.selection.signal['changed'].connect(function() {
754 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
755 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
759 Gtk.drag_source_set (
760 this.el, /* widget will be drag-able */
761 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
762 null, /* lists of target to support */
763 0, /* size of list */
764 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
767 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
769 Gtk.drag_source_add_text_targets(this.el);
772 this.el, /* widget that will accept a drop */
773 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
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_dest_set_target_list(this.el, this.get('/Window').targetList);
780 Gtk.drag_dest_add_text_targets(this.el);
782 selectNode : function(treepath_str) {
783 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
784 var tp = new Gtk.TreePath.from_string(treepath_str);
785 this.el.set_cursor(tp, null, false);
786 this.el.scroll_to_cell(tp, null, false, 0,0);
790 xtype: Gtk.TreeStore,
795 changed : function(n, refresh) {
796 // print("MODEL CHANGED CALLED" + this.activePath);
797 if (this.activePath) {
798 var iter = new Gtk.TreeIter();
799 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
800 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
801 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
803 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
805 //this.currentTree = this.toJS(false, true)[0];
806 this.file.items = this.toJS(false, false);
807 // print("AFTER CHANGED");
808 //console.dump(this.file.items);
810 this.currentTree = this.file.items[0];
811 //console.log(this.file.toSource());
814 print("REDNER BROWSER?!");
815 this.get('/LeftTree').renderView();
817 var pm = this.get('/RightPalete.model');
818 if (!this.get('/RightPalete').provider) {
824 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
825 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
829 deleteSelected : function() {
830 this.get('/LeftTree.view').blockChanges = true;
831 var old_iter = new Gtk.TreeIter();
832 var s = this.get('/LeftTree.view').selection;
833 s.get_selected(this.el, old_iter);
834 var path = this.el.get_path(old_iter).to_string();
836 this.activePath= false;
839 this.activePath= false;
840 var iter = new Gtk.TreeIter();
841 this.el.get_iter_from_string(iter, path);
842 this.el.remove(iter);
844 // rebuild treemap. -- depreciated.!!
847 //this.toJS(null, true) // does not do anything?
848 this.activePath= false;
849 this.changed(false,true);
850 this.get('/LeftTree.view').blockChanges = false;
852 dropNode : function(target_data, node) {
854 // console.dump(node);
855 // console.dump(target_data);
856 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
858 print("add " + tp + "@" + target_data[1] );
861 if (tp && target_data[1] < 2) { // before or after..
862 var ar = target_data[0].split(':');
864 parent = new Gtk.TreePath.from_string( ar.join(':') );
867 var n_iter = new Gtk.TreeIter();
868 var iter_par = new Gtk.TreeIter();
869 var iter_after = after ? new Gtk.TreeIter() : false;
873 if (parent !== false) {
874 this.el.get_iter(iter_par, parent);
881 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
882 this.el.get_iter(iter_after, after);
883 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
884 n_iter, iter_par, iter_after);
887 this.el.append(n_iter, iter_par);
891 if (typeof(node) == 'string') {
892 var ar = node.split('.');
893 var xtype = ar.pop();
896 '|xns' : ar.join('.'),
899 if (target_data.length == 3 && target_data[2].length) {
900 node['*prop'] = target_data[2];
902 node = this.get('/DialogTemplateSelect').show(node);
905 // work out what kind of packing to use..
906 if (typeof(node.pack) == 'undefined' && parent !== false) {
907 var pal = this.get('/LeftTree').getPaleteProvider();
908 if (pal.name == 'Gtk') {
909 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
910 var cname = pal.guessName(node);
911 node.pack = pal.getDefaultPack(pname, cname);
922 // load children - if it has any..
925 this.load(xitems, n_iter);
926 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
928 if (tp && (xitems || after)) {
929 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
931 // wee need to get the empty proptypes from somewhere..
933 //var olditer = this.activeIter;
934 this.activePath = this.el.get_path(n_iter).to_string();
936 // changed actually set's the node data..
937 this.changed(node, true);
941 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
943 //Builder.MidPropTree._model.load(node);
944 //Builder.MidPropTree._win.hideWin();
945 //Builder.LeftPanel._model.load( node);
949 findDropNode : function(treepath_str, targets) {
951 // this is used by the dragdrop code in the roo version AFAIR..
953 var path = treepath_str.replace(/^builder-/, '');
954 // treemap is depreciated... - should really check if model has any entries..
956 if (!this.el.iter_n_children(null)) {
958 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
960 print("FIND treepath: " + path);
961 //console.dump(this.treemap);
963 if (!treepath_str.match(/^builder-/)) {
964 return []; // nothing!
966 if (targets === true) {
969 return this.findDropNodeByPath(path,targets)
971 findDropNodeByPath : function(treepath_str, targets, pref) {
972 var path = treepath_str + ''; // dupe it..
973 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
975 //console.dump(this.treemap);
976 while (path.length) {
977 print("LOOKING FOR PATH: " + path);
978 var node_data = this.singleNodeToJS(path);
979 if (node_data === false) {
980 print("node not found");
984 var xname = this.get('/LeftTree.model').file.guessName(node_data);
987 targets.forEach(function(tg) {
991 if ((tg == xname) ) {
994 if (tg.indexOf(xname +':') === 0) {
996 prop = tg.split(':').pop();
1001 if (last) { // pref is after/before..
1002 // then it's after last
1004 return []; // do not allow..
1006 return [ last, pref , prop];
1009 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1011 var par = path.split(':');
1014 path = par.join(':');
1020 getIterValue : function (iter, col) {
1021 var gval = new GObject.Value('');
1022 this.el.get_value(iter, col ,gval);
1028 XObject.prototype.init.call(this);
1029 this.el.set_column_types ( 3, [
1030 GObject.TYPE_STRING, // title
1031 GObject.TYPE_STRING, // tip
1032 GObject.TYPE_STRING // source..
1035 listAllTypes : function() {
1036 var s = this.get('/LeftTree.view').selection;
1037 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1039 if (s.count_selected_rows() > 0) {
1040 var iter = new Gtk.TreeIter();
1041 s.get_selected(this.el, iter);
1043 // set some properties of the tree for use by the dropped element.
1044 var value = new GObject.Value('');
1045 this.el.get_value(iter, 2, value);
1046 var data = JSON.parse(value.value);
1049 var xname = this.get('/LeftTree.model').file.guessName(data);
1050 console.log('selected:' + xname);
1054 return []; // could not find it..
1062 li.forEach(function(el) {
1063 // this is specific to roo!!!?
1064 if (!el) { // skip empty?
1067 var fullpath = _this.file.guessName(el);
1068 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1073 if (el.items && el.items.length) {
1082 addall([this.currentTree]);
1084 // only if we have nothing, should we add '*top'
1088 //console.log('all types in tree');
1089 //console.dump(ret);
1094 load : function(tr,iter)
1096 var citer = new Gtk.TreeIter();
1097 //this.insert(citer,iter,0);
1098 for(var i =0 ; i < tr.length; i++) {
1100 this.el.insert(citer,iter,-1);
1102 this.el.append(citer);
1105 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1106 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1107 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1108 if (tr[i].items && tr[i].items.length) {
1109 this.load(tr[i].items, citer);
1113 loadFile : function(f) {
1119 console.log('missing file');
1123 // load the file if not loaded..
1124 if (f.items === false) {
1126 f.loadItems(function() {
1132 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1134 if (f.items.length && typeof(f.items[0]) == 'string') {
1136 this.get('/RightEditor').el.show();
1137 this.get('/RightEditor.view').load( f.items[0]);
1141 print(JSON.stringify(f.items, null,4));
1142 //console.dump(f.items);
1144 this.get('/LeftTree.view').el.expand_all();
1146 if (!f.items.length) {
1149 this.get('/Window.leftvpaned').el.set_position(80);
1151 this.get('/LeftTree.view').el.set_cursor(
1152 new Gtk.TreePath.from_string('0'), null, false);
1156 this.get('/Window.leftvpaned').el.set_position(200);
1160 //print("hide right editior");
1161 this.get('/RightEditor').el.hide();
1162 //print("set current tree");
1163 this.currentTree = this.toJS(false, false)[0];
1164 //console.dump(this.currentTree);
1165 this.currentTree = this.currentTree || { items: [] };
1166 this.get('/LeftTree').renderView();
1167 //console.dump(this.map);
1168 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1169 var pm = this.get('/RightPalete.model');
1170 // set up provider..
1172 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1174 if (!this.get('/RightPalete').provider) {
1175 print ("********* PALETE PROVIDER MISSING?!!");
1177 this.get('/LeftTree').renderView();
1179 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1183 this.get('/Window.view-notebook').el.set_current_page(
1184 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1187 moveNode : function(target_data, action) {
1188 //print("MOVE NODE");
1189 // console.dump(target_data);
1190 var old_iter = new Gtk.TreeIter();
1191 var s = this.get('/LeftTree.view').selection;
1192 s.get_selected(this.el, old_iter);
1193 var node = this.nodeToJS(old_iter,false);
1194 //console.dump(node);
1197 // needs to drop first, otherwise the target_data
1198 // treepath will be invalid.
1200 this.dropNode(target_data, node);
1201 if (action & Gdk.DragAction.MOVE) {
1202 // print("REMOVING OLD NODE");
1203 this.el.remove(old_iter);
1207 this.activePath= false;
1208 this.changed(false,true);
1210 nodeTip : function(c) {
1211 var ret = this.nodeTitle(c,true);
1217 if (!i.length || i[0] != '|') {
1223 if (typeof(c[i]) != 'string') {
1226 //print("prop : " + i + ':' + c[i]);
1227 if (!c[i].match(new RegExp('function'))) {
1230 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1234 ret+="\n\nMethods:" + funcs;
1239 nodeTitle : function(c, renderfull) {
1242 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1243 if (sr) txt.push('<s>');
1244 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1246 if (renderfull && c['|xns']) {
1247 txt.push(c['|xns']);
1250 if (c.xtype) { txt.push(c.xtype); }
1251 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1252 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1253 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1256 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1257 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1258 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1259 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1260 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1261 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1262 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1263 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1264 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1266 // for flat classes...
1267 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1268 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1271 if (sr) txt.push('</s>');
1272 return (txt.length == 0 ? "Element" : txt.join(" "));
1274 nodeToJS : function (treepath, with_id)
1277 var iter = treepath; // API used to be iter here..
1278 if (typeof(iter) == 'string') {
1279 iter = new Gtk.TreeIter();
1280 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1284 var par = new Gtk.TreeIter();
1285 var iv = this.getIterValue(iter, 2);
1286 // print("IV" + iv);
1287 var k = JSON.parse(iv);
1288 if (k.json && !this.el.iter_parent( par, iter )) {
1293 var treepath_str = this.el.get_path(iter).to_string();
1294 // not sure how we can handle mixed id stuff..
1295 if (typeof(k.id) == 'undefined') {
1296 k.id = 'builder-'+ treepath_str ;
1300 this.treemap[ treepath_str ] = k;
1301 k.xtreepath = treepath_str ;
1304 if (this.el.iter_has_child(iter)) {
1305 citer = new Gtk.TreeIter();
1306 this.el.iter_children(citer, iter);
1307 k.items = this.toJS(citer,with_id);
1311 nodeToJSON : function(c) {
1319 return JSON.stringify(o);
1321 singleNodeToJS : function (treepath)
1323 var iter = new Gtk.TreeIter();
1324 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1328 var iv = this.getIterValue(iter, 2);
1330 return JSON.parse(iv);
1333 toJS : function(treepath, with_id)
1335 //Seed.print("WITHID: "+ with_id);
1336 var iter = treepath; // API used to be iter here..
1337 if (typeof(iter) == 'string') {
1338 iter = new Gtk.TreeIter();
1339 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1348 iter = new Gtk.TreeIter();
1349 if (!this.el.get_iter_first(iter)) {
1359 var k = this.nodeToJS(iter, with_id);
1363 if (!this.el.iter_next(iter)) {
1368 if (treepath === false) {
1370 return JSON.parse(JSON.stringify(ar));
1374 // convert the list into a json string..
1380 xtype: Gtk.TreeViewColumn,
1381 pack : "append_column",
1383 XObject.prototype.init.call(this);
1384 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1388 xtype: Gtk.CellRendererText,
1398 id : "LeftTreeMenu",
1401 xtype: Gtk.MenuItem,
1403 label : "Delete Element",
1405 activate : function (self) {
1407 this.get('/LeftTree.model').deleteSelected();
1412 xtype: Gtk.MenuItem,
1414 activate : function (self) {
1416 var tree = this.get('/LeftTree');
1417 var model = this.get('/LeftTree.model');
1418 var el = tree.getActivePath();
1420 var js = model.toJS(el, false);
1421 // print(JSON.stringify(js[0], null,4));
1422 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1427 label : "Save as Template",
1437 id : "LeftProjectTree",
1438 showNoProjectSelected : function() {
1439 this.get('/StandardErrorDialog').show("Select a Project first.");
1441 getActiveProject : function() {
1442 return this.project;
1445 leave_notify_event : function (self, event) {
1452 pack : "pack_start,false,false",
1455 xtype: Gtk.ComboBox,
1458 XObject.prototype.init.call(this);
1459 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1461 getValue : function() {
1462 var ix = this.el.get_active();
1466 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1467 if (typeof(data[ix]) == 'undefined') {
1472 setValue : function(fn)
1476 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1477 data.forEach(function(n, ix) {
1485 changed : function (self) {
1486 var fn = this.getValue();
1487 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1488 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1493 xtype: Gtk.CellRendererText,
1494 pack : "pack_start,true",
1498 xtype: Gtk.ListStore,
1501 XObject.prototype.init.call(this);
1502 this.el.set_column_types ( 2, [
1503 GObject.TYPE_STRING, // real key
1504 GObject.TYPE_STRING // real type
1508 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1510 pm.on('changed', function() {
1511 print("caught changed hook on project manager - reloading data");
1512 _this.loadData(pm.projects);
1516 loadData : function(data) {
1517 var ov = this.get('/LeftProjectTree.combo').getValue();
1519 var iter = new Gtk.TreeIter();
1521 data.forEach(function(p) {
1526 el.set_value(iter, 0, p.fn);
1527 el.set_value(iter, 1, p.name);
1531 this.get('/LeftProjectTree.combo').setValue(ov);
1540 xtype: Gtk.ScrolledWindow,
1542 shadow_type : Gtk.ShadowType.IN,
1544 XObject.prototype.init.call(this);
1545 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1549 xtype: Gtk.TreeView,
1551 cursor_changed : function (self) {
1552 var iter = new Gtk.TreeIter();
1554 if (this.selection.count_selected_rows() < 1) {
1555 //XN.get('Builder.LeftTree.model').
1556 this.get('/LeftTree.model').load( false);
1560 var model = this.get('/LeftProjectTree.model');
1561 //console.log('changed');
1562 var s = this.selection;
1563 s.get_selected(model, iter);
1564 value = new GObject.Value('');
1565 model.el.get_value(iter, 2, value);
1567 console.log(value.value);// id..
1569 var file = this.get('/LeftProjectTree').project.getById(value.value);
1576 var nb = this.get('/LeftTopPanel.expander');
1577 nb.el.expanded = false;
1579 //nb.listeners.activate.call(nb);
1580 //_expander.el.set_expanded(false);
1582 var ltm = this.get('/LeftTree.model');
1590 enable_tree_lines : true,
1591 headers_visible : false,
1593 XObject.prototype.init.call(this);
1594 var description = new Pango.FontDescription.c_new();
1595 description.set_size(8000);
1596 this.el.modify_font(description);
1598 this.selection = this.el.get_selection();
1599 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1603 xtype: Gtk.TreeStore,
1607 XObject.prototype.init.call(this);
1608 this.el.set_column_types ( 3, [
1609 GObject.TYPE_STRING, // title
1610 GObject.TYPE_STRING, // tip
1611 GObject.TYPE_STRING // id..
1615 loadProject : function(pr) {
1616 print("LOAD PROJECT");
1622 this.get('/LeftProjectTree').project = pr;
1623 this.load(pr.toTree());
1624 this.get('/LeftProjectTree.view').el.expand_all();
1626 load : function(tr,iter) {
1627 // console.dump(tr);
1628 console.log('Project tree load: ' + tr.length);
1629 var citer = new Gtk.TreeIter();
1630 //this.insert(citer,iter,0);
1633 tr.forEach(function (r) {
1635 _this.el.append(citer);
1637 _this.el.insert(citer,iter,-1);
1639 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1640 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1641 _this.el.set_value(citer, 2, '' + r.id ); //id
1642 if (r.cn && r.cn.length) {
1643 _this.load(r.cn, citer);
1648 getValue : function(iter, col) {
1649 var gval = new GObject.Value('');
1650 this.el.get_value(iter, col ,gval);
1651 return '' + gval.value;
1655 xtype: Gtk.TreeViewColumn,
1656 pack : "append_column",
1658 XObject.prototype.init.call(this);
1659 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1663 xtype: Gtk.CellRendererText,
1683 pack : "pack_start,false,true,0",
1690 button_press_event : function (self, event) {
1691 this.get('/MidPropTree.model').showData('props');
1703 stock : Gtk.STOCK_ADD,
1704 icon_size : Gtk.IconSize.MENU
1719 button_press_event : function (self, event) {
1720 this.get('/MidPropTree.model').showData('events');
1732 stock : Gtk.STOCK_ADD,
1733 icon_size : Gtk.IconSize.MENU
1748 button_press_event : function (self, ev) {
1749 var p = this.get('/AddPropertyPopup');
1753 p.el.set_screen(Gdk.Screen.get_default());
1755 p.el.popup(null, null, null, null, 3, ev.button.time);
1767 stock : Gtk.STOCK_ADD,
1768 icon_size : Gtk.IconSize.MENU
1780 id : "AddPropertyPopup",
1783 xtype: Gtk.MenuItem,
1785 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1788 activate : function (self) {
1790 this.get('/LeftPanel.model').add( {
1801 xtype: Gtk.MenuItem,
1803 tooltip_markup : "Add what type of packing is to be used",
1806 activate : function (self) {
1808 this.get('/LeftPanel.model').add( {
1818 xtype: Gtk.MenuItem,
1820 tooltip_markup : "Override the init method",
1823 activate : function (self) {
1825 this.get('/LeftPanel.model').add( {
1828 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1835 xtype: Gtk.SeparatorMenuItem,
1839 xtype: Gtk.MenuItem,
1841 tooltip_markup : "Add a user defined string property",
1844 activate : function (self) {
1846 this.get('/LeftPanel.model').add( {
1856 xtype: Gtk.MenuItem,
1858 tooltip_markup : "Add a user defined number property",
1861 activate : function (self) {
1863 this.get('/LeftPanel.model').add( {
1873 xtype: Gtk.MenuItem,
1875 tooltip_markup : "Add a user defined boolean property",
1878 activate : function (self) {
1880 this.get('/LeftPanel.model').add( {
1890 xtype: Gtk.SeparatorMenuItem,
1894 xtype: Gtk.MenuItem,
1896 tooltip_markup : "Add a user function boolean property",
1899 activate : function (self) {
1901 this.get('/LeftPanel.model').add( {
1904 val : "function() {\n \n}\n",
1917 xtype: Gtk.ScrolledWindow,
1922 XObject.prototype.init.call(this);
1923 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1925 shadow_type : Gtk.ShadowType.IN,
1928 xtype: Gtk.TreeView,
1930 button_press_event : function (self, ev) {
1935 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1936 return false; //not on a element.
1940 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
1942 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
1945 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1946 var p = this.get('/LeftPanelPopup');
1951 p.el.set_screen(Gdk.Screen.get_default());
1953 p.el.popup(null, null, null, null, 3, ev.button.time);
1954 //Seed.print("click:" + res.column.title);
1961 if (res.column.title != 'value') {
1962 // XObject.error("column is not value?");
1963 return false; // ignore.. - key click.. ??? should we do this??
1966 // currently editing???
1967 // if ( this.activePath) {
1969 // this.activePath = false;
1971 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1972 this.get('/LeftPanel').editing = false;
1974 // XObject.error("Currently editing?");
1978 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1980 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1982 // get options for this type -- this is to support option lists etc..
1983 var provider = this.get('/LeftTree').getPaleteProvider();
1984 var opts = provider.findOptions(type);
1986 if (opts === false) {
1988 this.get('/LeftPanel').editableColumn.setOptions([]);
1989 renderer.has_entry = true;
1991 this.get('/LeftPanel').editableColumn.setOptions(opts);
1992 renderer.has_entry = false;
1994 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
1996 //Seed.print("click" + ev.type);
1997 //console.dump(res);
2006 enable_tree_lines : true,
2007 headers_visible : false,
2009 XObject.prototype.init.call(this);
2011 this.selection = this.el.get_selection();
2012 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2015 var description = new Pango.FontDescription.c_new();
2016 description.set_size(8000);
2017 this.el.modify_font(description);
2021 xtype: Gtk.TreeStore,
2025 add : function(info) {
2026 // info includes key, val, skel, etype..
2028 type = info.type.toLowerCase();
2029 var data = this.toJS();
2031 if (info.etype == 'events') {
2032 data.listeners = data.listeners || { };
2033 if (typeof(data.listeners[info.key]) != 'undefined') {
2034 return; //already set!
2037 if (typeof(data[info.key]) != 'undefined') {
2042 if (typeof(info.val) == 'undefined') {
2045 if (info.type.toLowerCase() == 'boolean') {
2048 if (type == 'number') {
2056 if (info.etype == 'events') {
2058 data.listeners[info.key] = info.val;
2061 data[info.key] = info.val;
2065 var map = this.load(data);
2067 // flag it as changed to the interface..
2069 this.get('/LeftTree.model').changed(data, true);
2072 this.startEditing(map[k]);
2075 LeftPanel.get('view').el.row_activated(
2076 new Gtk.TreePath.from_string(map[k]),
2077 LeftPanel.editableColumn.el
2081 changed : function(str, doRefresh) {
2082 if (!this.activePath) {
2085 var iter = new Gtk.TreeIter();
2086 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2088 this.el.set_value(iter, 1, '' +str);
2089 this.el.set_value(iter, 3, '' + this.toShort(str));
2090 var type = this.getIterValue(iter, 4);
2092 this.el.set_value(iter, 5, type + ' : ' + str);
2093 // update the tree...
2095 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2097 deleteSelected : function() {
2098 var data = this.toJS();
2099 var iter = new Gtk.TreeIter();
2100 var s = this.get('/LeftPanel.view').selection;
2101 s.get_selected(this.el, iter);
2104 var gval = new GObject.Value('');
2105 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2107 var val = gval.value;
2108 if (val[0] == '!') {
2110 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2113 delete data.listeners[ val.substring(1)];
2114 if (!XObject.keys(data.listeners).length) {
2115 delete data.listeners;
2119 if (typeof(data[val]) == 'undefined') {
2127 this.get('/LeftTree.model').changed(data, true);
2130 getIterValue : function(iter, col) {
2131 var gval = new GObject.Value('');
2132 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2133 return '' + gval.value;
2135 getType : function(treepath) {
2136 return this.getValue(treepath, 4);
2138 getValue : function(treepath_str, col)
2140 // get's the value in a row.. - keys - returns string, values - formats it..
2142 var iter = new Gtk.TreeIter();
2143 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2145 var gval = new GObject.Value('');
2146 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2147 var val = '' + gval.value;
2152 var type = this.getType(this.el.get_path(iter).to_string());
2153 //print("TYPE: " +type + " - val:" + val);
2154 switch(type.toLowerCase()) {
2158 return parseFloat(val); // Nan ?? invalid!!?
2161 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2163 return val == 'true' ? true : false;
2165 var nv = parseFloat(val);
2166 if (!isNaN(nv) && (val == ''+nv)) {
2174 XObject.prototype.init.call(this);
2175 this.el.set_column_types ( 6, [
2176 GObject.TYPE_STRING, // 0 real key
2177 GObject.TYPE_STRING, // 1 real value
2178 GObject.TYPE_STRING, // 2 visable key
2179 GObject.TYPE_STRING, // 3 visable value
2180 GObject.TYPE_STRING, // 4 need to store type of!!!
2181 GObject.TYPE_STRING // 5 tooltip
2185 load : function(ar) {
2188 this.get('/RightEditor').el.hide();
2195 var provider = this.get('/LeftTree').getPaleteProvider();
2196 var iter = new Gtk.TreeIter();
2199 var keys = XObject.keys(ar);
2201 ar.listeners = ar.listeners || {};
2203 for (var i in ar.listeners ) {
2204 this.el.append(iter);
2205 var p = this.el.get_path(iter).to_string();
2208 this.el.set_value(iter, 0, '!'+ i );
2209 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2210 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2212 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2213 this.el.set_value(iter, 4, 'function');
2214 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2220 keys.forEach(function(i) {
2221 if (typeof(ar[i]) == 'object') {
2225 var type = provider.findType(ar, i, ar[i]);
2227 _this.el.append(iter);
2228 var p = _this.el.get_path(iter).to_string();
2230 _this.el.set_value(iter, 0, ''+i);
2231 _this.el.set_value(iter, 1, '' + ar[i]);
2232 _this.el.set_value(iter, 2, ''+i);
2233 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2234 _this.el.set_value(iter, 4, ''+type);
2235 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2239 startEditing : function(path,col) {
2240 // alled by menu 'edit' currently..
2242 * start editing path (or selected if not set..)
2243 * @param {String|false} path (optional) treepath to edit - selected tree gets
2244 * edited by default.
2245 * @param {Number} 0 or 1 (optional)- column to edit.
2247 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2249 if (typeof(path) == 'string') {
2250 tp = new Gtk.TreePath.from_string(path);
2252 var iter = new Gtk.TreeIter();
2253 var s = this.get('/LeftPanel.view').selection;
2254 s.get_selected(this.el, iter);
2255 tp = this.el.get_path(iter);
2256 path = tp.to_string();
2260 // which colum is to be edited..
2263 // not sure what this does..
2265 if (typeof(col) == 'undefined') {
2266 var k = this.getValue(path, 0);
2268 colObj = (!k.length || k == '|') ?
2269 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2271 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2274 // make sure the pulldown is set correctly..
2275 // not really needed for second col...
2276 var showEditor = false;
2279 var provider = this.get('/LeftTree').getPaleteProvider();
2280 var type = this.get('/LeftPanel.model').getType(path);
2281 var opts = provider.findOptions(type);
2282 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2284 if (opts === false) {
2285 this.get('/LeftPanel').editableColumn.setOptions([]);
2286 renderer.has_entry = true;
2288 this.get('/LeftPanel').editableColumn.setOptions(opts);
2289 renderer.has_entry = false;/// - pulldowns do not have entries
2291 // determine if we should use the Text editor...
2292 var keyname = this.getValue(path, 0);
2293 var data_value = this.getValue(path, 1);
2295 if ((keyname[0] == '|') ||
2297 (typeof(data_value) == 'string' ) &&
2298 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2302 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2307 this.get('/BottomPane').el.hide();
2308 this.get('/RightEditor').el.hide();
2313 this.activePath = false;
2314 GLib.timeout_add(0, 1, function() {
2316 _this.get('/BottomPane').el.show();
2317 _this.get('/RightEditor').el.show();
2318 _this.get('/RightEditor.view').load( _this.getValue(path, 1) );
2321 //e.remove_widget();
2322 _this.activePath = path ;
2332 // iter now has row...
2333 GLib.timeout_add(0, 100, function() {
2334 _this.activePath = path;
2335 colObj.items[0].el.editable = true; // esp. need for col 0..
2336 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2346 var iter = new Gtk.TreeIter();
2347 this.get('/LeftPanel.model').el.get_iter_first(iter);
2352 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2355 ar.listeners = ar.listeners || {};
2356 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2359 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2362 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2368 //print(JSON.stringify(ar));
2372 toShort : function(str) {
2373 var a = typeof(str) == 'string' ? str.split("\n") : [];
2374 return a.length > 1 ? a[0] + '....' : '' + str;
2378 xtype: Gtk.TreeViewColumn,
2379 pack : "append_column",
2381 XObject.prototype.init.call(this);
2383 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2384 this.get('/LeftPanel').propertyColumn = this;
2389 xtype: Gtk.CellRendererText,
2390 pack : "pack_start",
2392 editing_started : function (self, editable, path) {
2394 this.get('/LeftPanel.model').activePath = path;
2397 edited : function (self, object, p0) {
2398 var model = this.get('/LeftPanel.model');
2399 var path = model.activePath;
2400 var iter = new Gtk.TreeIter();
2401 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2402 model.el.set_value(iter, 0, p0);
2403 model.el.set_value(iter, 2, p0);
2405 model.activePath = false;
2407 this.get('/LeftTree.model').changed(model.toJS(), true);
2408 this.el.editable = false;
2415 xtype: Gtk.TreeViewColumn,
2416 pack : "append_column",
2419 XObject.prototype.init.call(this);
2420 this.el.add_attribute(this.items[0].el , 'text', 3 );
2421 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2422 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2423 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2425 this.get('/LeftPanel').editableColumn= this;
2427 setOptions : function(ar) {
2428 var m = this.items[0].el.model;
2430 var iter = new Gtk.TreeIter();
2431 ar.forEach(function(i) {
2434 m.set_value(iter, 0, i);
2440 xtype: Gtk.CellRendererCombo,
2442 edited : function (self, object, p0) {
2443 this.get('/LeftPanel').editing = false;
2444 var ap = this.get('/LeftPanel.model').activePath
2445 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2446 this.get('/LeftPanel.model').changed(p0, true);
2447 this.get('/LeftPanel.model').activePath = false;
2448 this.el.editable = false;
2450 editing_started : function (self, editable, path) {
2451 this.get('/LeftPanel').editing = true;
2452 // console.log('editing started');
2453 // r.has_entry = false;
2455 this.el.editable = false; // make sure it's not editor...
2459 pack : "pack_start",
2464 XObject.prototype.init.call(this);
2465 this.el.model = new Gtk.ListStore();
2466 this.el.model.set_column_types ( 1, [
2467 GObject.TYPE_STRING // 0 real key
2478 id : "LeftPanelPopup",
2481 xtype: Gtk.MenuItem,
2485 activate : function (self) {
2486 this.get('/LeftPanel.model').deleteSelected();
2491 xtype: Gtk.MenuItem,
2495 activate : function (self) {
2496 this.get('/LeftPanel.model').startEditing(false, 0);
2509 xtype: Gtk.ScrolledWindow,
2510 pack : "pack_end,false,true,0",
2512 shadow_type : Gtk.ShadowType.IN,
2514 XObject.prototype.init.call(this);
2515 XObject.prototype.init.call(this);
2516 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2517 this.el.set_size_request ( 150, -1 );
2520 activeElement : false,
2521 hideWin : function() {
2528 if (this.get('/Window.left').el.position < 160) {
2531 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2538 xtype: Gtk.TreeView,
2540 cursor_changed : function (self) {
2541 var iter = new Gtk.TreeIter();
2543 //console.log('changed');
2544 var m = this.get('model');
2545 if (!this.selection){
2546 this.selection = this.el.get_selection();
2549 var s = this.selection;
2550 if (!s.get_selected(m.el, iter)) {
2553 var tp = m.el.get_path(iter).to_string();
2558 var key = m.getValue(tp, 0);
2560 var type = m.getValue(tp, 1);
2561 var skel = m.getValue(tp, 3);
2562 var etype = m.getValue(tp, 5);
2565 this.get('/MidPropTree').hideWin();
2567 if (type.toLowerCase() == 'function') {
2569 if (etype != 'events') {
2573 this.get('/LeftPanel.model').add({
2581 // has dot in name, and is boolean???? this does not make sense..
2582 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2586 this.get('/LeftPanel.model').add( {
2596 enable_tree_lines : true,
2597 headers_visible : false,
2599 XObject.prototype.init.call(this);
2601 var description = new Pango.FontDescription.c_new();
2602 description.set_size(8000);
2603 this.el.modify_font(description);
2605 //this.selection = this.el.get_selection();
2606 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2615 xtype: Gtk.ListStore,
2618 getValue : function(treepath, col)
2620 var tp = new Gtk.TreePath.from_string (treepath);
2621 var iter = new Gtk.TreeIter();
2622 this.el.get_iter (iter, tp);
2623 var value = new GObject.Value('');
2624 this.el.get_value(iter, col, value);
2629 XObject.prototype.init.call(this);
2630 this.el.set_column_types ( 6, [
2631 GObject.TYPE_STRING, // real key
2632 GObject.TYPE_STRING, // real type
2633 GObject.TYPE_STRING, // docs ?
2634 GObject.TYPE_STRING, // visable desc
2635 GObject.TYPE_STRING, // function desc
2636 GObject.TYPE_STRING // element type (event|prop)
2640 showData : function(type) {
2642 if (!this.get('/MidPropTree').activeElement || !type) {
2643 return; // no active element
2646 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2647 var palete = this.get('/LeftTree').getPaleteProvider();
2651 Seed.print('Showing right?');
2652 if (!this.get('/MidPropTree').shown) {
2654 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2655 this.get('/MidPropTree').el.show();
2656 this.get('/MidPropTree').shown = true;
2659 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2660 return a.name > b.name ? 1 : -1;
2662 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2663 // console.dump(elementList);
2666 var iter = new Gtk.TreeIter();
2667 for(var i =0 ; i < elementList.length; i++) {
2668 var p=elementList[i];
2669 this.el.append(iter);
2670 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2671 //GObject.TYPE_STRING, // real key
2672 // GObject.TYPE_STRING, // real type
2673 // GObject.TYPE_STRING, // docs ?
2674 // GObject.TYPE_STRING // func def?
2677 this.el.set_value(iter, 0, p.name);
2678 this.el.set_value(iter, 1, p.type);
2679 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2680 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2681 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2682 this.el.set_value(iter, 5, type);
2689 xtype: Gtk.TreeViewColumn,
2691 this.el = new Gtk.TreeViewColumn();
2692 this.parent.el.append_column(this.el);
2694 XObject.prototype.init.call(this);
2695 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2700 xtype: Gtk.CellRendererText,
2701 pack : "pack_start,true"
2725 xtype: Gtk.Notebook,
2726 pack : "pack_start,true,true",
2727 id : "view-help-nb",
2729 XObject.prototype.init.call(this);
2730 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2731 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2735 xtype: Gtk.Notebook,
2736 id : "view-notebook",
2740 XObject.prototype.init.call(this);
2741 this.el.set_current_page(0);
2742 //print("SET LABEL?")
2743 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2744 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2750 id : "RightBrowser",
2755 pack : "pack_start,false,true,0",
2760 activate : function (self) {
2761 this.get('/RightBrowser.view').renderJS(null,true);
2765 pack : "pack_start,false,false,0"
2768 xtype: Gtk.CheckButton,
2770 toggled : function (self, state) {
2771 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2776 label : "Auto Redraw On",
2777 pack : "pack_start,false,false,0"
2782 xtype: Gtk.ScrolledWindow,
2785 XObject.prototype.init.call(this);
2786 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2788 shadow_type : Gtk.ShadowType.IN,
2791 xtype: WebKit.WebView,
2793 load_finished : function (self, object) {
2794 print("load finished");
2795 // print("load_finished"); return;
2796 // if (this.ready) { // dont do it twice!
2799 if (!this.inspectorShown) {
2800 this.el.get_inspector().show();
2801 this.inspectorShown = true;
2806 if (this.pendingRedraw) {
2807 this.pendingRedraw = false;
2808 this.refreshRequired = true;
2810 //var js = this.get('/LeftTree.model').toJS();
2811 //if (js && js[0]) {
2812 // this.renderJS(js[0]);
2816 script_alert : function (self, object, p0) {
2819 return true; // do not display anything...
2821 console_message : function (self, object, p0, p1) {
2823 // console.log(object);
2824 if (!object.match(/^\{/)) {
2826 //this.get('/Terminal').feed(object);
2827 return true; // do not handle!!! -> later maybe in console..
2829 // console.log(object);
2830 var val = JSON.parse(object);
2832 if (typeof(val['hover-node']) != 'undefined') {
2833 this.activeNode = val['hover-node'];
2834 console.log('active node: ' + this.activeNode);
2839 if (typeof(val['id']) != 'undefined') {
2840 // this.activeNode = val['id'];
2841 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2842 if (!tg || typeof(tg[0]) == 'undefined') {
2845 print("SELECT node " + tg[0]);
2847 this.get('/LeftTree.view').selectNode(tg[0]);
2851 if (ret && typeof(val['set']) != 'undefined') {
2852 this.get('/LeftPanel.model').add({
2856 //console.log('active node: ' + this.activeNode);
2859 //Seed.print('a:'+a);
2860 //Seed.print('b:'+b);
2861 //Seed.print('c:'+c);
2864 drag_motion : function (w, ctx, x, y, time, ud) {
2865 // console.log('DRAG MOTION');
2867 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2868 this.targetData = [];
2869 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2871 // A) find out from drag all the places that node could be dropped.
2872 var src = Gtk.drag_get_source_widget(ctx);
2873 if (!src.dropList) {
2874 Gdk.drag_status(ctx, 0, time);
2877 // b) get what we are over.. (from activeNode)
2878 // tree is empty.. - list should be correct..
2879 if (!this.get('/LeftTree.model').currentTree) {
2880 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2884 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2886 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2889 Gdk.drag_status(ctx, 0,time);
2890 this.get('/LeftTree.view').highlight(false);
2894 // if we have a target..
2895 // -> highlight it! (in browser)
2896 // -> highlight it! (in tree)
2898 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2899 this.get('/LeftTree.view').highlight(tg);
2900 this.targetData = tg;
2901 // for tree we should handle this...
2904 drag_drop : function (w, ctx, x, y,time, ud) {
2905 print("TARGET: drag-drop");
2906 var is_valid_drop_site = true;
2911 w, /* will receive 'drag-data-received' signal */
2912 ctx, /* represents the current state of the DnD */
2913 this.get('/Window').atoms["STRING"], /* the target type we want */
2914 time /* time stamp */
2918 /* No target offered by source => error */
2921 return is_valid_drop_site;
2923 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2925 print("Browser: drag-data-received");
2926 var delete_selection_data = false;
2927 vardnd_success = false;
2928 /* Deal with what we are given from source */
2929 if( sel_data && sel_data.length ) {
2931 if (ctx.action == Gdk.DragAction.ASK) {
2932 /* Ask the user to move or copy, then set the ctx action. */
2935 if (ctx.action == Gdk.DragAction.MOVE) {
2936 delete_selection_data = true;
2938 var source = Gtk.drag_get_source_widget(ctx);
2940 print("Browser: source.DRAGDATA? " + source.dragData);
2941 if (this.targetData) {
2942 print(this.targetData);
2943 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2952 if (dnd_success == false)
2954 Seed.print ("DnD data transfer failed!\n");
2957 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2960 create_web_view : function (self, object) {
2961 print("CREATE WEB VIEW");
2962 return null; //new WebKit.WebView();
2968 XObject.prototype.init.call(this);
2969 // this may not work!?
2970 var settings = this.el.get_settings();
2971 settings.enable_developer_extras = true;
2973 // this was an attempt to change the url perms.. did not work..
2974 // settings.enable_file_access_from_file_uris = true;
2975 // settings.enable_offline_web_application_cache - true;
2976 // settings.enable_universal_access_from_file_uris = true;
2980 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
2981 _this.get('/BottomPane.inspector').el.show();
2982 return _this.get('/BottomPane.inspector').el;
2986 // FIXME - base url of script..
2987 // we need it so some of the database features work.
2988 this.el.load_html_string( "Render not ready" ,
2989 //fixme - should be a config option!
2990 // or should we catch stuff and fix it up..
2991 'http://localhost/app.Builder/'
2995 //this.el.open('file:///' + __script_path__ + '/../builder.html');
2999 this.el, /* widget that will accept a drop */
3000 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3001 null, /* lists of target to support */
3002 0, /* size of list */
3003 Gdk.DragAction.COPY /* what to do with data after dropped */
3006 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3007 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3009 GLib.timeout_add_seconds(0, 1, function() {
3010 // print("run refresh?");
3017 renderJS : function(data, force) {
3019 // this is the public redraw call..
3020 // we refresh in a loop privately..
3021 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3022 if (!autodraw && !force) {
3025 this.refreshRequired = true;
3027 runRefresh : function()
3029 // this is run every 2 seconds from the init..
3033 if (!this.refreshRequired) {
3034 // print("no refresh required");
3038 if (this.lastRedraw) {
3039 // do not redraw if last redraw was less that 5 seconds ago.
3040 if (((new Date()) - this.lastRedraw) < 5000) {
3048 if (!this.get('/Window.LeftTree').getActiveFile()) {
3051 this.refreshRequired = false;
3052 // print("HTML RENDERING");
3054 this.get('/BottomPane').el.show();
3055 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3058 var js = this.get('/LeftTree.model').toJS();
3059 if (!js || !js.length) {
3066 var project = this.get('/Window.LeftTree').getActiveFile().project;
3067 //print (project.fn);
3068 // set it to non-empty.
3069 project.runhtml = project.runhtml || '';
3070 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3073 this.runhtml = this.runhtml || '';
3075 if (project.runhtml != this.runhtml) {
3076 // then we need to reload the browser using
3077 // load_html_string..
3079 // then trigger a redraw once it's loaded..
3080 this.pendingRedraw = true;
3081 var runhtml = '<script type="text/javascript">' + "\n" ;
3082 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3083 runhtml += '</script>'+ "\n" ;
3085 this.runhtml = project.runhtml;
3086 // need to modify paths
3090 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3091 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3092 print("LOAD HTML " + html);
3093 this.el.load_html_string( html ,
3094 //fixme - should be a config option!
3095 'http://localhost/app.Builder/'
3098 // should trigger load_finished! - which in truns shoudl set refresh Required;
3104 this.renderedData = data;
3105 var str = JSON.stringify(data) ;
3108 console.log('not loaded yet');
3110 this.lastRedraw = new Date();
3112 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3113 print( "before render" + this.lastRedraw);
3114 print( "after render" + (new Date()));
3124 id : "RightGtkView",
3126 redraw : function() {
3127 this.highlightWidget = false;
3128 print("REDRAW CALLED");
3129 this.activePath = this.get('/LeftTree').getActivePath();
3130 if (this.renderedEl) {
3131 print("QUEUE DRAW CALLING");
3132 this.renderedEl.queue_draw();
3135 renderJS : function(data, withDebug)
3137 this.highlightWidget = false;
3139 this.withDebug = false;
3140 while (this.get('view').el.get_children().length) {
3141 var c = this.get('view').el.get_children()[0];
3142 this.get('view').el.remove(c);
3149 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3150 // in theory tree is actually window..
3153 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3159 this.get('view').el.set_size_request(
3160 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3162 if (this.renderedEl) {
3163 this.renderedEl.set_size_request(
3164 tree.default_width || 600,
3165 tree.default_height || 400
3168 this.get('view').el.show_all();
3173 showInWindow : function() {
3174 print("GET PROEJCT");
3175 var pr = this.get('/LeftProjectTree').getActiveProject();
3177 console.log(pr.paths);
3180 var src= this.buildJS(
3181 this.get('/LeftTree.model').toJS()[0],
3186 //var x = new imports.sandbox.Context();
3190 Seed.check_syntax('var e = ' + src);
3193 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3194 this.get('/Terminal').feed(console._dump(e)+"\n");
3196 var lines = src.split("\n");
3197 var start = Math.max(0, e.line - 10);
3198 var end = Math.min(lines.length, e.line + 10);
3199 for (var i =start ; i < end; i++) {
3201 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3204 this.get('/Terminal').feed(lines[i] + "\n");
3211 this.get('/BottomPane').el.set_current_page(1);
3212 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3213 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3214 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3216 var _top = x.get_global_object()._top;
3218 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3220 if (_top.el.popup) {
3221 _top.el.popup(null, null, null, null, 3, null);
3225 viewAdd : function(item, par)
3227 // does something similar to xobject..
3228 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3230 if (item.pack===false || item.pack === 'false') { // no ;
3233 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3234 var type = item['|xns'] + '.' + item['xtype'];
3236 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3239 var ns = imports.gi[item['|xns']];
3240 var ctr = ns[item['xtype']];
3242 for(var k in item) {
3244 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3259 if (k[0] == '|' && typeof(kv) == 'string') {
3261 if (kv.match(new RegExp('function'))) {
3264 print("WASL " + k + '=' + kv);
3266 eval( 'kv = ' + kv);
3267 } catch(e) { continue; }
3270 // print(k + '=' + kv);
3272 if (k[0] == '|') { // should be boolean or number..
3274 //print(k + '=' + kv);
3277 if (k == 'show_tabs') { // force tab showing for notebooks.
3280 print(k + '=' + typeof(kv) + " : " + kv);
3286 var el = new ctr(ctr_args);
3288 print("PACK" + item.pack);
3289 //console.dump(item.pack);
3296 if (typeof(item.pack) == 'string') {
3298 item.pack.split(',').forEach(function(e, i) {
3300 if (e == 'false') { args.push( false); return; }
3301 if (e == 'true') { args.push( true); return; }
3302 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3305 //print(args.join(","));
3307 pack_m = args.shift();
3309 pack_m = item.pack.shift();
3314 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3316 name: "ArgumentError",
3317 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3318 "ADDING : " + item.id + " " + el
3327 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3328 //Seed.print('args: ' + args.length);
3330 par[pack_m].apply(par, args);
3334 item.items = item.items || [];
3335 item.items.forEach(function(ch,n) {
3337 print ("type:" + type);
3339 print ("ch.pack:" + ch.pack);
3340 if (type == 'Gtk.Table' && ch.pack == 'add') {
3341 var c = n % item.n_columns;
3342 var r = Math.floor(n/item.n_columns);
3343 ch.pack = [ 'attach', c, c+1, r, r+1,
3344 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3345 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3346 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3347 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3351 _this.viewAdd(ch, el);
3356 // add the signal handlers.
3357 // is it a widget!?!!?
3363 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3364 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3365 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3366 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3367 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3377 widgetDragDropEvent : function() {
3378 print("WIDGET DRAGDROP");
3381 widgetDragMotionEvent : function() {
3382 print("WIDGET DRAGMOTION");
3385 widgetExposeEvent : function(w, evt, ud, item) {
3387 if (this.inRender) {
3391 if ( this.highlightWidget) {
3392 this.inRender = true;
3393 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3394 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3396 this.inRender = false;
3401 if (this.activePath != item.xtreepath) {
3405 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3406 // work out the coords of the window..
3408 var dr = widget.window;
3409 this.gc = (new Gdk.GC.c_new(dr));
3410 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3411 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3415 var r = evt.expose.area;
3416 // console.dump([r.x, r.y, r.width, r.height ] );
3418 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3419 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3420 // happens with gtkscrollview embedded stuff..
3421 var np =this.activePath.split(':');
3423 this.activePath = np.join(':');
3424 this.renderedEl.queue_draw();
3440 this.inRender = true;
3443 this.highlightWidget = widget;
3448 // print("DRAW BOX");
3449 //console.dump(this.box);
3450 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3451 this.inRender = false;
3454 widgetPressEvent : function(w,e,u,d) {
3455 if (this.get('view').pressed) {
3458 this.get('view').pressed = true;
3459 print("WIDGET PRESS " + d.xtreepath );
3460 this.get('/LeftTree.view').selectNode( d.xtreepath );
3463 widgetReleaseEvent : function() {
3464 this.get('view').pressed = false;
3470 pack : "pack_start,false,true,0",
3474 pack : "pack_start,false,false,0",
3475 label : "Run The Application",
3477 button_press_event : function (self, event) {
3478 // call render on left tree - with special option!?!
3480 //print("GET PROEJCT");
3481 var pr = this.get('/LeftProjectTree').getActiveProject();
3484 for (var i in pr.paths) {
3488 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3489 this.get('/Terminal').feed("RUN DIR:" + dir);
3491 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3492 , false,false,false);
3493 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3494 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3504 xtype: Gtk.ScrolledWindow,
3507 shadow_type : Gtk.ShadowType.IN,
3509 XObject.prototype.init.call(this);
3510 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3514 xtype: Gtk.EventBox,
3515 pack : "add_with_viewport",
3517 XObject.prototype.init.call(this);
3518 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3519 red: 0x9F00, green: 0xB800 , blue : 0xA800
3527 XObject.prototype.init.call(this);
3528 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3529 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3534 xtype: Gtk.EventBox,
3537 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3538 XObject.prototype.init.call(this);
3542 this.el, /* widget that will accept a drop */
3543 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3544 null, /* lists of target to support */
3545 0, /* size of list */
3546 Gdk.DragAction.COPY /* what to do with data after dropped */
3549 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3550 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3553 getActiveNode : function(x,y)
3555 // workout what node is here..
3556 return '0'; // top..
3560 drag_motion : function (self, ctx, x, y, time) {
3562 // A) find out from drag all the places that node could be dropped.
3563 var src = Gtk.drag_get_source_widget(ctx);
3564 if (!src.dropList) {
3565 Gdk.drag_status(ctx, 0, time);
3568 // b) get what we are over.. (from activeNode)
3569 // tree is empty.. - list should be correct..
3570 if (!this.get('/LeftTree.model').currentTree) {
3571 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3575 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3576 var activeNode = this.getActiveNode(x, y);
3579 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3582 Gdk.drag_status(ctx, 0,time);
3583 this.get('/LeftTree.view').highlight(false);
3587 // if we have a target..
3588 // -> highlight it! (in browser)
3589 // -> highlight it! (in tree)
3591 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3592 this.get('/LeftTree.view').highlight(tg);
3593 this.targetData = tg;
3594 // for tree we should handle this...
3597 drag_drop : function (self,ctx, x, y, time) {
3598 Seed.print("TARGET: drag-drop");
3599 var is_valid_drop_site = true;
3604 self, /* will receive 'drag-data-received' signal */
3605 ctx, /* represents the current state of the this.gDnD */
3606 this.get('/Window').atoms["STRING"], /* the target type we want */
3607 time /* time stamp */
3611 /* No target offered by source => error */
3614 return is_valid_drop_site;
3617 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3619 Seed.print("GtkView: drag-data-received");
3620 var delete_selection_data = false;
3621 var dnd_success = false;
3622 /* Deal with what we are given from source */
3623 if( sel_data && sel_data.length ) {
3625 if (ctx.action == Gdk.DragAction.ASK) {
3626 /* Ask the user to move or copy, then set the ctx action. */
3629 if (ctx.action == Gdk.DragAction.MOVE) {
3630 delete_selection_data = true;
3632 var source = Gtk.drag_get_source_widget(ctx);
3634 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3635 if (this.targetData) {
3636 Seed.print(this.targetData);
3637 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3646 if (dnd_success == false)
3648 Seed.print ("DnD data transfer failed!\n");
3651 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3654 button_press_event : function (self, event) {
3655 this.pressed = false;
3671 xtype: Gtk.ScrolledWindow,
3676 var file = this.get('/LeftTree').getActiveFile();
3680 var activeEl = this.get('/LeftTree').getActiveElement();
3681 var xtype = file.guessName( activeEl )
3682 if (!xtype || !xtype.length) {
3685 //this.get('/Window.view-help-nb').el.set_current_page(1);
3687 // get the active element being edited.
3688 var helpurl = file.getHelpUrl(xtype);
3690 // now load the help info in the page..
3691 this.get('help-view').el.open(helpurl);
3695 xtype: WebKit.WebView,
3699 XObject.prototype.init.call(this);
3700 this.get('/Window.help-view').el.open(
3701 "http://devel.akbkhome.com/seed/");
3713 xtype: Gtk.Notebook,
3717 XObject.prototype.init.call(this);
3718 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3719 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3720 this.el.set_tab_label(this.items[2].el, new Gtk.Label({ label : "Inspector" }));
3724 xtype: Gtk.ScrolledWindow,
3729 xtype: GtkSource.View,
3733 XObject.prototype.init.call(this);
3734 var description = Pango.Font.description_from_string("monospace")
3735 description.set_size(8000);
3736 this.el.modify_font(description);
3739 load : function(str) {
3741 // show the help page for the active node..
3742 this.get('/Help').show();
3745 this.get('/BottomPane').el.set_current_page(0);
3746 this.el.get_buffer().set_text(str, str.length);
3747 var lm = GtkSource.LanguageManager.get_default();
3749 this.el.get_buffer().set_language(lm.get_language('js'));
3750 var buf = this.el.get_buffer();
3751 var cursor = buf.get_mark("insert");
3752 var iter= new Gtk.TextIter;
3753 buf.get_iter_at_mark(iter, cursor);
3755 iter.set_line_offset(4);
3756 buf.move_mark(cursor, iter);
3759 cursor = buf.get_mark("selection_bound");
3760 iter= new Gtk.TextIter;
3761 buf.get_iter_at_mark(iter, cursor);
3763 iter.set_line_offset(4);
3764 buf.move_mark(cursor, iter);
3766 this.el.grab_focus();
3768 insert_spaces_instead_of_tabs : true,
3771 show_line_numbers : true,
3774 xtype: GtkSource.Buffer,
3776 changed : function (self) {
3777 var s = new Gtk.TextIter();
3778 var e = new Gtk.TextIter();
3779 this.el.get_start_iter(s);
3780 this.el.get_end_iter(e);
3781 var str = this.el.get_text(s,e,true);
3783 Seed.check_syntax('var e = ' + str);
3785 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3786 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3788 //print("SYNTAX ERROR IN EDITOR");
3793 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3794 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3797 this.get('/LeftPanel.model').changed( str , false);
3807 xtype: Gtk.ScrolledWindow,
3811 xtype: Vte.Terminal,
3814 feed : function(istr) {
3815 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3816 // we should make ourselves visable!!!
3817 this.get('/BottomPane').el.show();
3818 this.get('/BottomPane').el.set_current_page(1);
3820 this.el.feed(str ,str.length);
3822 scroll_on_output : true,
3824 XObject.prototype.init.call(this);
3825 this.el.set_size (80, 1000);
3827 scrollback_lines : 1000
3832 xtype: Gtk.ScrolledWindow,
3836 xtype: WebKit.WebView,
3848 pack : "pack_start,false,false",
3852 this.get('buttonbar').el.show();
3853 this.get('viewbox').el.hide();
3854 print("TRIED TO HIDE");
3857 this.get('buttonbar').el.hide();
3858 this.get('viewbox').el.show();
3859 // this.get('model').expanded();
3871 pack : "pack_start,false,true",
3873 clicked : function (self) {
3874 this.get('/RightPalete').show();
3881 stock : Gtk.STOCK_GOTO_FIRST,
3882 icon_size : Gtk.IconSize.MENU
3892 XObject.prototype.init.call(this);
3893 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3896 enter_notify_event : function (self, event) {
3897 this.get('/RightPalete').show();
3911 pack : "pack_start,false,true",
3920 pack : "pack_start,false,true",
3922 clicked : function (self) {
3923 this.get('/RightPalete').hide();
3930 stock : Gtk.STOCK_GOTO_LAST,
3931 icon_size : Gtk.IconSize.MENU
3938 xtype: Gtk.ScrolledWindow,
3941 XObject.prototype.init.call(this);
3942 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3943 this.el.set_size_request(-1,200);
3945 shadow_type : Gtk.ShadowType.IN,
3948 xtype: Gtk.TreeView,
3951 XObject.prototype.init.call(this);
3952 this.el.set_size_request(150,-1);
3953 // set_reorderable: [1]
3955 var description = new Pango.FontDescription.c_new();
3956 description.set_size(8000);
3957 this.el.modify_font(description);
3959 this.selection = this.el.get_selection();
3960 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3961 // this.selection.signal['changed'].connect(function() {
3962 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3964 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3966 Gtk.drag_source_set (
3967 this.el, /* widget will be drag-able */
3968 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3969 null, /* lists of target to support */
3970 0, /* size of list */
3971 Gdk.DragAction.COPY /* what to do with data after dropped */
3973 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3975 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3976 Gtk.drag_source_add_text_targets(this.el);
3978 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3979 targets = new Gtk.TargetList();
3980 targets.add( LeftTree.atoms["STRING"], 0, 0);
3981 targets.add_text_targets( 1 );
3982 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3984 //if you want to allow text to be output elsewhere..
3985 //Gtk.drag_source_add_text_targets(this.el);
3989 headers_visible : false,
3990 enable_tree_lines : true,
3992 drag_begin : function (self, ctx) {
3993 // we could fill this in now...
3994 Seed.print('SOURCE: drag-begin');
3998 var iter = new Gtk.TreeIter();
3999 var s = this.selection;
4000 s.get_selected(this.get('/RightPalete.model').el, iter);
4001 var path = this.get('/RightPalete.model').el.get_path(iter);
4003 var pix = this.el.create_row_drag_icon ( path);
4006 Gtk.drag_set_icon_pixmap (ctx,
4013 var value = new GObject.Value('');
4014 this.get('/RightPalete.model').el.get_value(iter, 0, value);
4015 if (!this.get('/RightPalete').provider) {
4018 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
4019 this.el.dragData = value.value;
4026 drag_data_get : function (self, drag_context, selection_data, info, time) {
4027 //Seed.print('Palete: drag-data-get: ' + target_type);
4028 if (this.el.dragData && this.el.dragData.length ) {
4029 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4033 //this.el.dragData = "TEST from source widget";
4037 drag_end : function (self, drag_context) {
4038 Seed.print('SOURCE: drag-end');
4039 this.el.dragData = false;
4040 this.el.dropList = false;
4041 this.get('/LeftTree.view').highlight(false);
4047 xtype: Gtk.ListStore,
4050 XObject.prototype.init.call(this);
4051 this.el.set_column_types ( 2, [
4052 GObject.TYPE_STRING, // title
4053 GObject.TYPE_STRING // tip
4058 load : function(tr,iter)
4063 //console.log('Project tree load: ' + tr.length);
4064 var citer = new Gtk.TreeIter();
4065 //this.insert(citer,iter,0);
4066 for(var i =0 ; i < tr.length; i++) {
4069 this.el.append(citer);
4071 this.el.insert(citer,iter,-1);
4076 this.el.set_value(citer, 0, '' + r ); // title
4078 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4079 //if (r.cn && r.cn.length) {
4080 // this.load(r.cn, citer);
4086 getValue : function (iter, col) {
4087 var gval = new GObject.Value('');
4088 this.el.get_value(iter, col ,gval);
4095 xtype: Gtk.TreeViewColumn,
4096 pack : "append_column",
4098 XObject.prototype.init.call(this);
4099 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4103 xtype: Gtk.CellRendererText,
4125 XObject.cache['/Window'] = Window;