3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
14 type : Gtk.WindowType.TOPLEVEL,
15 title : "Application Builder",
19 "STRING" : Gdk.atom_intern("STRING")
21 this.targetList = new Gtk.TargetList();
22 this.targetList.add( this.atoms["STRING"], 0, 0);
23 //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
25 "style \"gtkcombobox-style\" {\n" +
26 " GtkComboBox::appears-as-list = 1\n" +
28 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
29 XObject.prototype.init.call(this);
38 setTitle : function(str) {
39 this.el.set_title(this.title + ' - ' + str);
42 delete_event : function (self, event) {
45 destroy : function (self) {
48 show : function (self) {
49 print("WINDOW SHOWING - trying to hide");
50 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
51 this.get('/MidPropTree').hideWin();
52 this.get('/RightPalete').hide();
53 this.get('/BottomPane').el.hide();
64 pack : "pack_start,false,false",
78 label : "New _Project",
80 activate : function (self) {
82 this.get('/EditProject').show({
83 success : function(pr) {
84 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
95 activate : function (self) {
96 var fn = this.get('/LeftProjectTree.combo').getValue();
98 this.get('/LeftProjectTree').showNoProjectSelected();
101 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
102 this.get('/DialogNewComponent').show({
103 project : pm.getByFn(fn)
109 xtype: Gtk.SeparatorMenuItem,
114 use_underline : true,
116 label : "D_elete Project",
118 activate : function (self) {
120 var fn = this.get('/LeftProjectTree').get('combo').getValue();
122 this.get('/StandardErrorDialog').show("Select a project")
125 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
126 var pr = pm.getByFn(fn);
129 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
130 pm.deleteProject(fn);
138 xtype: Gtk.SeparatorMenuItem,
145 use_underline : true,
147 activate : function (self) {
159 use_underline : true,
164 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",
218 activate : function (self, event) {
219 var js = this.get('/LeftTree.model').toJS();
221 this.get('/RightBrowser.view').renderJS(js[0]);
226 label : "_Redraw (Roo)",
233 activate : function (self, event)
235 /* Firefox testing for debugging..
236 - we can create a /tmp directory, and put.
237 builder.html, builder.html.js, link roojs1
238 add at the end of builder.html Roo.onload(function() {
240 if (!this.get('/Window.LeftTree').getActiveFile()) {
244 var js = this.get('/LeftTree.model').toJS();
248 var project = this.get('/Window.LeftTree').getActiveFile().project;
249 //print (project.fn);
251 project.runhtml = project.runhtml || '';
254 var File = imports.File.File;
256 var target = "/tmp/firetest"; // fixme..
257 if (!File.isDirectory(target)) {
260 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
261 if (!File.exists( target+ '/roojs1')) {
262 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
267 var html = imports.File.File.read(__script_path__ + '/../builder.html');
268 html = html.replace('</head>', project.runhtml + '</head>');
271 var jsstr = JSON.stringify(js[0]);
273 var runbuilder = '<script type="text/javascript">' + "\n" +
274 " Builder.render(" + jsstr + ");\n" +
277 html = html.replace('</body>', runbuilder + '</body>');
279 File.write( target+ '/builder.html', html);
281 this.get('/Terminal').feed("RUN DIR:" + target);
283 this.get('/Terminal').el.fork_command( null , [], [], target
284 , false,false,false);
285 var cmd = "firefox file://" + target + "/builder.html \n";
286 this.get('/Terminal').el.feed_child(cmd, cmd.length);
290 label : "_Test in Firefox (Roo)",
301 use_underline : true,
309 pack : "set_submenu",
318 use_underline : true,
320 activate : function (self) {
321 this.get('/About').el.run();
350 label : "Select Project",
352 pack : "pack_start,false,true",
354 XObject.prototype.init.call(this);
355 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
358 activate : function (self) {
359 var nb = this.get('/LeftTopPanel.notebook');
360 if (this.el.expanded) {
363 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
366 var model = this.get('/LeftProjectTree.combomodel');
367 // print ("loading Projects?")
368 //console.dump(pm.projects);
369 model.loadData(pm.projects);
372 nb.el.set_current_page(1);
373 //pm.on('changed', function() {
374 //console.log("CAUGHT project manager change");
375 // _combo.model.loadData(pm.projects);
379 nb.el.set_current_page(0);
381 enter_notify_event : function (self, event) {
382 this.el.expanded = !this.el.expanded;
383 //if (this.el.expanded ) {
384 this.listeners.activate.call(this);
396 pack : "pack_start,true,true",
398 XObject.prototype.init.call(this);
399 this.el.set_current_page(0);
404 xtype: Gtk.ScrolledWindow,
407 getActiveElement : function() { // return path to actie node.
409 var path = this.getActivePath();
413 var iter = new Gtk.TreeIter();
414 this.get('model').el.get_iter_from_string(iter, path);
416 var value = new GObject.Value('');
417 this.get('model').el.get_value(iter, 2, value);
419 return JSON.parse(value.value);
421 getActiveFile : function() {
422 return this.get('model').file;
424 getActivePath : function() {
425 var model = this.get('model');
426 var view = this.get('view');
427 if (view.selection.count_selected_rows() < 1) {
430 var iter = new Gtk.TreeIter();
432 view.selection.get_selected(model.el, iter);
433 return model.el.get_path(iter).to_string();
435 getPaleteProvider : function() {
436 var model = this.get('model');
437 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
438 return pm.getPalete(model.file.getType());
440 getRenderer : function() {
442 switch( this.getActiveFile().getType()) {
444 return this.get('/RightBrowser.view');
446 return this.get('/RightGtkView');
451 XObject.prototype.init.call(this);
452 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
454 renderView : function() {
455 var render = this.getRenderer();
456 var model = this.get('model');
458 render.renderJS(model.toJS(false,true)[0]);
460 print("NO RENDER JS METHOD?");
463 shadow_type : Gtk.ShadowType.IN,
469 headers_visible : false,
470 enable_tree_lines : true,
473 XObject.prototype.init.call(this);
474 var description = new Pango.FontDescription.c_new();
475 description.set_size(8000);
476 this.el.modify_font(description);
478 this.selection = this.el.get_selection();
479 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
482 // is this really needed??
483 this.selection.signal['changed'].connect(function() {
484 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
485 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
489 Gtk.drag_source_set (
490 this.el, /* widget will be drag-able */
491 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
492 null, /* lists of target to support */
493 0, /* size of list */
494 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
497 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
499 Gtk.drag_source_add_text_targets(this.el);
502 this.el, /* widget that will accept a drop */
503 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
504 null, /* lists of target to support */
505 0, /* size of list */
506 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
509 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
510 Gtk.drag_dest_add_text_targets(this.el);
512 highlight : function(treepath_ar) {
514 // highlighting for drag/drop
515 if (treepath_ar.length && treepath_ar[0].length ) {
516 this.el.set_drag_dest_row(
517 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
519 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
523 selectNode : function(treepath_str) {
524 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
525 var tp = new Gtk.TreePath.from_string(treepath_str);
526 this.el.set_cursor(tp, null, false);
527 this.el.scroll_to_cell(tp, null, false, 0,0);
530 button_press_event : function (self, ev) {
531 console.log("button press?");
532 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
533 print("click" + ev.type);
539 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
541 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
543 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
544 this.get('/LeftTreeMenu').el.show_all();
545 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
546 print("click:" + res.path.to_string());
549 drag_begin : function (self, drag_context) {
550 print('SOURCE: drag-begin');
551 this.targetData = false;
552 // find what is selected in our tree...
553 var iter = new Gtk.TreeIter();
554 var s = this.selection;
555 s.get_selected(this.get('/LeftTree.model').el, iter);
557 // set some properties of the tree for use by the dropped element.
558 var value = new GObject.Value('');
559 this.get('/LeftTree.model').el.get_value(iter, 2, value);
560 var data = JSON.parse(value.value);
561 var xname = this.get('/LeftTree.model').file.guessName(data);
563 this.el.dragData = xname;
564 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
567 // make the drag icon a picture of the node that was selected
568 var path = this.get('/LeftTree.model').el.get_path(iter);
569 this.el.treepath = path.to_string();
571 var pix = this.el.create_row_drag_icon ( path);
573 Gtk.drag_set_icon_pixmap (ctx,
582 drag_end : function (self, drag_context) {
583 Seed.print('LEFT-TREE: drag-end');
584 this.el.dragData = false;
585 this.el.dropList = false;
586 this.targetData = false;
587 this.get('/LeftTree.view').highlight(false);
590 drag_motion : function (self, ctx, x, y, time) {
591 console.log("LEFT-TREE: drag-motion");
592 var src = Gtk.drag_get_source_widget(ctx);
594 // a drag from elsewhere...- prevent drop..
596 print("no drag data!");
597 Gdk.drag_status(ctx, 0, time);
598 this.targetData = false;
601 var action = Gdk.DragAction.COPY;
602 if (src == this.el) {
603 // unless we are copying!!! ctl button..
604 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
608 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
609 // no children.. -- asume it's ok..
610 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
611 Gdk.drag_status(ctx, action ,time);
615 print("GETTING POS");
616 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
617 print("ISOVER? " + isOver);
619 Gdk.drag_status(ctx, 0 ,time);
620 return false; // not over apoint!?!
622 // drag node is parent of child..
623 console.log("SRC TREEPATH: " + src.treepath);
624 console.log("TARGET TREEPATH: " + data.path.to_string());
626 // nned to check a few here..
627 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
628 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
629 //Gtk.TreeViewDropPosition.AFTER
630 //Gtk.TreeViewDropPosition.BEFORE
632 if (typeof(src.treepath) != 'undefined' &&
633 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
634 print("subpath drag");
635 Gdk.drag_status(ctx, 0 ,time);
640 //print("DUMPING DATA");
641 //console.dump(data);
644 print(data.path.to_string() +' => '+ data.pos);
645 var tg = this.get('/LeftTree.model').findDropNodeByPath(
646 data.path.to_string(), src.dropList, data.pos);
648 this.get('/LeftTree.view').highlight(tg);
650 print("Can not find drop node path");
651 this.targetData = false;
652 Gdk.drag_status(ctx, 0, time);
656 this.targetData = tg;
659 Gdk.drag_status(ctx, action ,time);
663 drag_drop : function (w, ctx, x, y, time) {
664 Seed.print("TARGET: drag-drop");
668 w, /* will receive 'drag-data-received' signal */
669 ctx, /* represents the current state of the DnD */
670 this.get('/Window').atoms["STRING"], /* the target type we want */
671 time /* time stamp */
675 /* No target offered by source => error */
680 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
681 print("Tree: drag-data-received");
683 var delete_selection_data = false;
684 var dnd_success = false;
685 /* Deal with what we are given from source */
686 if( sel_data && sel_data.length ) {
688 if (ctx.action == Gdk.DragAction.ASK) {
689 /* Ask the user to move or copy, then set the ctx action. */
692 if (ctx.action == Gdk.DragAction.MOVE) {
693 //delete_selection_data = true;
696 var source = Gtk.drag_get_source_widget(ctx);
698 if (this.targetData) {
699 if (source != this.el) {
700 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
702 // drag around.. - reorder..
703 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
707 //Seed.print(this.targetData);
713 // we can send stuff to souce here...
719 if (dnd_success == false)
721 Seed.print ("DnD data transfer failed!\n");
724 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
727 cursor_changed : function (self) {
728 if (this.blockChanges) { // probably not needed..
731 var render = this.get('/LeftTree').getRenderer();
734 if (this.selection.count_selected_rows() < 1) {
735 this.get('/LeftPanel.model').load( false);
736 this.get('/MidPropTree').activeElement = false;
737 this.get('/MidPropTree').hideWin();
739 var pm = this.get('/RightPalete.model');
740 if (!this.get('/LeftTree').getPaleteProvider()) {
741 // it may not be loaded yet..
744 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
745 this.get('/LeftTree.model').listAllTypes()));
746 if (render && render.redraw) {
752 //console.log('changed');
753 var s = this.selection;
754 var iter = new Gtk.TreeIter();
755 s.get_selected(this.get('/LeftTree.model').el, iter);
759 var value = new GObject.Value('');
760 this.get('/LeftTree.model').el.get_value(iter, 2, value);
761 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
763 var data = JSON.parse(value.value);
764 this.get('/MidPropTree').activeElement = data;
765 this.get('/MidPropTree').hideWin();
766 this.get('/LeftPanel.model').load( data);
768 console.log(value.value);
769 // _g.button.set_label(''+value.get_string());
771 var pm =this.get('/RightPalete.model');
772 pm.load( this.get('/RightPalete').provider.gatherList(
773 this.get('/LeftTree.model').listAllTypes()));
776 if (render && render.redraw) {
780 //Seed.print( value.get_string());
787 xtype: Gtk.TreeStore,
792 changed : function(n, refresh) {
793 print("MODEL CHANGED CALLED" + this.activePath);
794 if (this.activePath) {
795 var iter = new Gtk.TreeIter();
796 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
797 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
798 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
800 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
802 //this.currentTree = this.toJS(false, true)[0];
803 this.file.items = this.toJS(false, false);
804 print("AFTER CHANGED");
805 //console.dump(this.file.items);
807 this.currentTree = this.file.items[0];
808 //console.log(this.file.toSource());
811 print("REDNER BROWSER?!");
812 this.get('/LeftTree').renderView();
814 var pm = this.get('/RightPalete.model');
815 if (!this.get('/RightPalete').provider) {
821 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
822 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
826 deleteSelected : function() {
827 this.get('/LeftTree.view').blockChanges = true;
828 var old_iter = new Gtk.TreeIter();
829 var s = this.get('/LeftTree.view').selection;
830 s.get_selected(this.el, old_iter);
831 var path = this.el.get_path(old_iter).to_string();
833 this.activePath= false;
836 this.activePath= false;
837 var iter = new Gtk.TreeIter();
838 this.el.get_iter_from_string(iter, path);
839 this.el.remove(iter);
841 // rebuild treemap. -- depreciated.!!
844 //this.toJS(null, true) // does not do anything?
845 this.activePath= false;
846 this.changed(false,true);
847 this.get('/LeftTree.view').blockChanges = false;
849 dropNode : function(target_data, node) {
852 console.dump(target_data);
853 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
855 print("add " + tp + "@" + target_data[1] );
858 if (tp && target_data[1] < 2) { // before or after..
859 var ar = target_data[0].split(':');
861 parent = new Gtk.TreePath.from_string( ar.join(':') );
864 var n_iter = new Gtk.TreeIter();
865 var iter_par = new Gtk.TreeIter();
866 var iter_after = after ? new Gtk.TreeIter() : false;
870 if (parent !== false) {
871 this.el.get_iter(iter_par, parent);
878 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
879 this.el.get_iter(iter_after, after);
880 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
881 n_iter, iter_par, iter_after);
884 this.el.append(n_iter, iter_par);
888 if (typeof(node) == 'string') {
889 var ar = node.split('.');
890 var xtype = ar.pop();
893 '|xns' : ar.join('.'),
896 if (target_data.length == 3 && target_data[2].length) {
897 node['*prop'] = target_data[2];
901 // work out what kind of packing to use..
902 if (typeof(node.pack) == 'undefined' && parent !== false) {
903 var pal = this.get('/LeftTree').getPaleteProvider();
905 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
906 print ("PNAME : " + pname);
907 var cname = pal.guessName(node);
908 print ("CNAME : " + cname);
909 node.pack = pal.getDefaultPack(pname, cname);
920 // load children - if it has any..
923 this.load(xitems, n_iter);
925 if (tp && (xitems || after)) {
926 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
928 // wee need to get the empty proptypes from somewhere..
930 //var olditer = this.activeIter;
931 this.activePath = this.el.get_path(n_iter).to_string();
933 // changed actually set's the node data..
934 this.changed(node, true);
938 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
940 //Builder.MidPropTree._model.load(node);
941 //Builder.MidPropTree._win.hideWin();
942 //Builder.LeftPanel._model.load( node);
946 findDropNode : function(treepath_str, targets) {
948 // this is used by the dragdrop code in the roo version AFAIR..
950 var path = treepath_str.replace(/^builder-/, '');
951 // treemap is depreciated... - should really check if model has any entries..
953 if (!this.el.iter_n_children(null)) {
955 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
957 print("FIND treepath: " + path);
958 //console.dump(this.treemap);
960 if (!treepath_str.match(/^builder-/)) {
961 return []; // nothing!
963 if (targets === true) {
966 return this.findDropNodeByPath(path,targets)
968 findDropNodeByPath : function(treepath_str, targets, pref) {
969 var path = treepath_str + ''; // dupe it..
970 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
972 //console.dump(this.treemap);
973 while (path.length) {
974 print("LOOKING FOR PATH: " + path);
975 var node_data = this.singleNodeToJS(path);
976 if (node_data === false) {
977 print("node not found");
981 var xname = this.get('/LeftTree.model').file.guessName(node_data);
984 targets.forEach(function(tg) {
988 if ((tg == xname) ) {
991 if (tg.indexOf(xname +':') === 0) {
993 prop = tg.split(':').pop();
998 if (last) { // pref is after/before..
999 // then it's after last
1001 return []; // do not allow..
1003 return [ last, pref , prop];
1006 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1008 var par = path.split(':');
1011 path = par.join(':');
1017 getIterValue : function (iter, col) {
1018 var gval = new GObject.Value('');
1019 this.el.get_value(iter, col ,gval);
1025 XObject.prototype.init.call(this);
1026 this.el.set_column_types ( 3, [
1027 GObject.TYPE_STRING, // title
1028 GObject.TYPE_STRING, // tip
1029 GObject.TYPE_STRING // source..
1032 listAllTypes : function() {
1033 var s = this.get('/LeftTree.view').selection;
1034 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1036 if (s.count_selected_rows() > 0) {
1037 var iter = new Gtk.TreeIter();
1038 s.get_selected(this.el, iter);
1040 // set some properties of the tree for use by the dropped element.
1041 var value = new GObject.Value('');
1042 this.el.get_value(iter, 2, value);
1043 var data = JSON.parse(value.value);
1046 var xname = this.get('/LeftTree.model').file.guessName(data);
1047 console.log('selected:' + xname);
1051 return []; // could not find it..
1059 li.forEach(function(el) {
1060 // this is specific to roo!!!?
1062 var fullpath = _this.file.guessName(el);
1063 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1068 if (el.items && el.items.length) {
1077 addall([this.currentTree]);
1079 // only if we have nothing, should we add '*top'
1083 //console.log('all types in tree');
1084 //console.dump(ret);
1089 load : function(tr,iter)
1091 var citer = new Gtk.TreeIter();
1092 //this.insert(citer,iter,0);
1093 for(var i =0 ; i < tr.length; i++) {
1095 this.el.insert(citer,iter,-1);
1097 this.el.append(citer);
1100 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1101 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1102 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1103 if (tr[i].items && tr[i].items.length) {
1104 this.load(tr[i].items, citer);
1108 loadFile : function(f) {
1114 console.log('missing file');
1118 // load the file if not loaded..
1119 if (f.items === false) {
1121 f.loadItems(function() {
1127 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1129 if (f.items.length && typeof(f.items[0]) == 'string') {
1131 this.get('/RightEditor').el.show();
1132 this.get('/RightEditor.view').load( f.items[0]);
1136 //console.dump(f.items);
1138 this.get('/LeftTree.view').el.expand_all();
1140 if (!f.items.length) {
1143 this.get('/Window.leftvpaned').el.set_position(80);
1145 this.get('/LeftTree.view').el.set_cursor(
1146 new Gtk.TreePath.from_string('0'), null, false);
1150 this.get('/Window.leftvpaned').el.set_position(200);
1154 //print("hide right editior");
1155 this.get('/RightEditor').el.hide();
1156 //print("set current tree");
1157 this.currentTree = this.toJS(false, false)[0];
1158 //console.dump(this.currentTree);
1159 this.currentTree = this.currentTree || { items: [] };
1160 this.get('/LeftTree').renderView();
1161 //console.dump(this.map);
1162 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1163 var pm = this.get('/RightPalete.model');
1164 // set up provider..
1166 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1168 if (!this.get('/RightPalete').provider) {
1169 print ("********* PALETE PROVIDER MISSING?!!");
1171 this.get('/LeftTree').renderView();
1173 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1177 this.get('/Window.view-notebook').el.set_current_page(
1178 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1181 moveNode : function(target_data, action) {
1182 //print("MOVE NODE");
1183 // console.dump(target_data);
1184 var old_iter = new Gtk.TreeIter();
1185 var s = this.get('/LeftTree.view').selection;
1186 s.get_selected(this.el, old_iter);
1187 var node = this.nodeToJS(old_iter,false);
1188 //console.dump(node);
1191 // needs to drop first, otherwise the target_data
1192 // treepath will be invalid.
1194 this.dropNode(target_data, node);
1195 if (action & Gdk.DragAction.MOVE) {
1196 // print("REMOVING OLD NODE");
1197 this.el.remove(old_iter);
1201 this.activePath= false;
1202 this.changed(false,true);
1204 nodeTip : function(c) {
1205 var ret = this.nodeTitle(c,true);
1211 if (!i.length || i[0] != '|') {
1217 if (typeof(c[i]) != 'string') {
1220 //print("prop : " + i + ':' + c[i]);
1221 if (!c[i].match(new RegExp('function'))) {
1224 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1228 ret+="\n\nMethods:" + funcs;
1233 nodeTitle : function(c, renderfull) {
1236 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1237 if (sr) txt.push('<s>');
1238 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1240 if (renderfull && c['|xns']) {
1241 txt.push(c['|xns']);
1244 if (c.xtype) { txt.push(c.xtype); }
1245 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1246 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1247 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1250 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1251 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1252 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1253 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1254 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1255 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1256 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1257 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1258 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1260 // for flat classes...
1261 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1262 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1265 if (sr) txt.push('</s>');
1266 return (txt.length == 0 ? "Element" : txt.join(" "));
1268 nodeToJS : function (treepath, with_id)
1271 var iter = treepath; // API used to be iter here..
1272 if (typeof(iter) == 'string') {
1273 iter = new Gtk.TreeIter();
1274 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1278 var par = new Gtk.TreeIter();
1279 var iv = this.getIterValue(iter, 2);
1280 // print("IV" + iv);
1281 var k = JSON.parse(iv);
1282 if (k.json && !this.el.iter_parent( par, iter )) {
1287 var treepath_str = this.el.get_path(iter).to_string();
1288 // not sure how we can handle mixed id stuff..
1289 if (typeof(k.id) == 'undefined') {
1290 k.id = 'builder-'+ treepath_str ;
1294 this.treemap[ treepath_str ] = k;
1295 k.xtreepath = treepath_str ;
1298 if (this.el.iter_has_child(iter)) {
1299 citer = new Gtk.TreeIter();
1300 this.el.iter_children(citer, iter);
1301 k.items = this.toJS(citer,with_id);
1305 nodeToJSON : function(c) {
1313 return JSON.stringify(o);
1315 singleNodeToJS : function (treepath)
1317 var iter = new Gtk.TreeIter();
1318 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1322 var iv = this.getIterValue(iter, 2);
1324 return JSON.parse(iv);
1327 toJS : function(iter, with_id)
1329 //Seed.print("WITHID: "+ with_id);
1336 iter = new Gtk.TreeIter();
1337 if (!this.el.get_iter_first(iter)) {
1347 var k = this.nodeToJS(iter, with_id);
1351 if (!this.el.iter_next(iter)) {
1357 // convert the list into a json string..
1363 xtype: Gtk.TreeViewColumn,
1364 pack : "append_column",
1366 XObject.prototype.init.call(this);
1367 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1371 xtype: Gtk.CellRendererText,
1381 id : "LeftTreeMenu",
1384 xtype: Gtk.MenuItem,
1386 label : "Delete Element",
1388 activate : function (self) {
1390 this.get('/LeftTree.model').deleteSelected();
1395 xtype: Gtk.MenuItem,
1397 activate : function (self) {
1399 var tree = this.get('/LeftTree');
1400 var model = this.get('/LeftTree.model');
1401 var el = tree.getActivePath();
1402 var js = model.toJS(el, false);
1403 print(JSON.stringify(js));
1407 label : "Save as Template",
1417 id : "LeftProjectTree",
1418 showNoProjectSelected : function() {
1419 this.get('/StandardErrorDialog').show("Select a Project first.");
1421 getActiveProject : function() {
1422 return this.project;
1425 leave_notify_event : function (self, event) {
1432 pack : "pack_start,false,false",
1435 xtype: Gtk.ComboBox,
1438 XObject.prototype.init.call(this);
1439 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1441 getValue : function() {
1442 var ix = this.el.get_active();
1446 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1447 if (typeof(data[ix]) == 'undefined') {
1452 setValue : function(fn)
1456 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1457 data.forEach(function(n, ix) {
1465 changed : function (self) {
1466 var fn = this.getValue();
1467 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1468 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1473 xtype: Gtk.CellRendererText,
1474 pack : "pack_start,true",
1478 xtype: Gtk.ListStore,
1481 XObject.prototype.init.call(this);
1482 this.el.set_column_types ( 2, [
1483 GObject.TYPE_STRING, // real key
1484 GObject.TYPE_STRING // real type
1488 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1490 pm.on('changed', function() {
1491 print("caught changed hook on project manager - reloading data");
1492 _this.loadData(pm.projects);
1496 loadData : function(data) {
1497 var ov = this.get('/LeftProjectTree.combo').getValue();
1499 var iter = new Gtk.TreeIter();
1501 data.forEach(function(p) {
1506 el.set_value(iter, 0, p.fn);
1507 el.set_value(iter, 1, p.name);
1511 this.get('/LeftProjectTree.combo').setValue(ov);
1520 xtype: Gtk.ScrolledWindow,
1522 shadow_type : Gtk.ShadowType.IN,
1524 XObject.prototype.init.call(this);
1525 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1529 xtype: Gtk.TreeView,
1530 headers_visible : false,
1531 enable_tree_lines : true,
1534 XObject.prototype.init.call(this);
1535 var description = new Pango.FontDescription.c_new();
1536 description.set_size(8000);
1537 this.el.modify_font(description);
1539 this.selection = this.el.get_selection();
1540 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1544 cursor_changed : function (self) {
1545 var iter = new Gtk.TreeIter();
1547 if (this.selection.count_selected_rows() < 1) {
1548 //XN.get('Builder.LeftTree.model').
1549 this.get('/LeftTree.model').load( false);
1553 var model = this.get('/LeftProjectTree.model');
1554 //console.log('changed');
1555 var s = this.selection;
1556 s.get_selected(model, iter);
1557 value = new GObject.Value('');
1558 model.el.get_value(iter, 2, value);
1560 console.log(value.value);// id..
1562 var file = this.get('/LeftProjectTree').project.getById(value.value);
1569 var nb = this.get('/LeftTopPanel.expander');
1570 nb.el.expanded = false;
1571 nb.listeners.activate.call(nb);
1572 //_expander.el.set_expanded(false);
1574 var ltm = this.get('/LeftTree.model');
1582 xtype: Gtk.TreeStore,
1586 XObject.prototype.init.call(this);
1587 this.el.set_column_types ( 3, [
1588 GObject.TYPE_STRING, // title
1589 GObject.TYPE_STRING, // tip
1590 GObject.TYPE_STRING // id..
1594 loadProject : function(pr) {
1595 print("LOAD PROJECT");
1601 this.get('/LeftProjectTree').project = pr;
1602 this.load(pr.toTree());
1603 this.get('/LeftProjectTree.view').el.expand_all();
1605 load : function(tr,iter) {
1606 // console.dump(tr);
1607 console.log('Project tree load: ' + tr.length);
1608 var citer = new Gtk.TreeIter();
1609 //this.insert(citer,iter,0);
1612 tr.forEach(function (r) {
1614 _this.el.append(citer);
1616 _this.el.insert(citer,iter,-1);
1618 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1619 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1620 _this.el.set_value(citer, 2, '' + r.id ); //id
1621 if (r.cn && r.cn.length) {
1622 _this.load(r.cn, citer);
1627 getValue : function(iter, col) {
1628 var gval = new GObject.Value('');
1629 this.el.get_value(iter, col ,gval);
1630 return '' + gval.value;
1634 xtype: Gtk.TreeViewColumn,
1635 pack : "append_column",
1637 XObject.prototype.init.call(this);
1638 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1642 xtype: Gtk.CellRendererText,
1665 pack : "pack_start,false,true,0",
1672 button_press_event : function (self, event) {
1673 this.get('/MidPropTree.model').showData('props');
1685 stock : Gtk.STOCK_ADD,
1686 icon_size : Gtk.IconSize.MENU
1701 button_press_event : function (self, event) {
1702 this.get('/MidPropTree.model').showData('events');
1714 stock : Gtk.STOCK_ADD,
1715 icon_size : Gtk.IconSize.MENU
1730 button_press_event : function (self, ev) {
1731 var p = this.get('/AddPropertyPopup');
1735 p.el.set_screen(Gdk.Screen.get_default());
1737 p.el.popup(null, null, null, null, 3, ev.button.time);
1749 stock : Gtk.STOCK_ADD,
1750 icon_size : Gtk.IconSize.MENU
1762 id : "AddPropertyPopup",
1765 xtype: Gtk.MenuItem,
1767 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1770 activate : function (self) {
1772 this.get('/LeftPanel.model').add( {
1783 xtype: Gtk.MenuItem,
1785 tooltip_markup : "Add what type of packing is to be used",
1788 activate : function (self) {
1790 this.get('/LeftPanel.model').add( {
1800 xtype: Gtk.MenuItem,
1802 tooltip_markup : "Override the init method",
1805 activate : function (self) {
1807 this.get('/LeftPanel.model').add( {
1810 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1817 xtype: Gtk.SeparatorMenuItem,
1821 xtype: Gtk.MenuItem,
1823 tooltip_markup : "Add a user defined string property",
1826 activate : function (self) {
1828 this.get('/LeftPanel.model').add( {
1838 xtype: Gtk.MenuItem,
1840 tooltip_markup : "Add a user defined number property",
1843 activate : function (self) {
1845 this.get('/LeftPanel.model').add( {
1855 xtype: Gtk.MenuItem,
1857 tooltip_markup : "Add a user defined boolean property",
1860 activate : function (self) {
1862 this.get('/LeftPanel.model').add( {
1872 xtype: Gtk.SeparatorMenuItem,
1876 xtype: Gtk.MenuItem,
1878 tooltip_markup : "Add a user function boolean property",
1881 activate : function (self) {
1883 this.get('/LeftPanel.model').add( {
1886 val : "function() {\n \n}\n",
1899 xtype: Gtk.ScrolledWindow,
1902 shadow_type : Gtk.ShadowType.IN,
1905 XObject.prototype.init.call(this);
1906 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1910 xtype: Gtk.TreeView,
1913 headers_visible : false,
1914 enable_tree_lines : true,
1916 XObject.prototype.init.call(this);
1918 this.selection = this.el.get_selection();
1919 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1922 var description = new Pango.FontDescription.c_new();
1923 description.set_size(8000);
1924 this.el.modify_font(description);
1927 button_press_event : function (self, ev) {
1931 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1932 return false; //not on a element.
1936 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1938 if (res.column.title != 'value') {
1939 return false; // ignore..
1941 if ( this.get('/LeftPanel').editing) {
1944 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1945 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1946 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1950 var provider = this.get('/LeftTree').getPaleteProvider();
1952 var opts = provider.findOptions(type);
1954 if (opts === false) {
1955 this.get('/LeftPanel').editableColumn.setOptions([]);
1956 renderer.has_entry = true;
1958 LeftPanel.editableColumn.setOptions(opts);
1959 renderer.has_entry = false;
1963 //Seed.print("click" + ev.type);
1964 //console.dump(res);
1970 if (res.column.title == 'value') {
1973 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1974 var p = this.get('/LeftPanelPopup');
1979 p.el.set_screen(Gdk.Screen.get_default());
1981 p.el.popup(null, null, null, null, 3, ev.button.time);
1982 //Seed.print("click:" + res.column.title);
1990 xtype: Gtk.TreeStore,
1994 getIterValue : function(iter, col) {
1995 var gval = new GObject.Value('');
1996 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
1997 return '' + gval.value;
1999 add : function(info) {
2000 // info includes key, val, skel, etype..
2002 type = info.type.toLowerCase();
2003 var data = this.toJS();
2005 if (info.etype == 'events') {
2006 data.listeners = data.listeners || { };
2007 if (typeof(data.listeners[info.key]) != 'undefined') {
2008 return; //already set!
2011 if (typeof(data[info.key]) != 'undefined') {
2016 if (typeof(info.val) == 'undefined') {
2019 if (info.type == 'boolean') {
2022 if (type == 'number') {
2030 if (info.etype == 'events') {
2032 data.listeners[info.key] = info.val;
2035 data[info.key] = info.val;
2039 var map = this.load(data);
2041 // flag it as changed to the interface..
2043 this.get('/LeftTree.model').changed(data, true);
2046 this.startEditing(map[k]);
2049 LeftPanel.get('view').el.row_activated(
2050 new Gtk.TreePath.from_string(map[k]),
2051 LeftPanel.editableColumn.el
2055 changed : function(str, doRefresh) {
2056 if (!this.activePath) {
2059 var iter = new Gtk.TreeIter();
2060 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2062 this.el.set_value(iter, 1, '' +str);
2063 this.el.set_value(iter, 3, '' + this.toShort(str));
2064 var type = this.getIterValue(iter, 4);
2066 this.el.set_value(iter, 5, type + ' : ' + str);
2067 // update the tree...
2069 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2071 deleteSelected : function() {
2072 var data = this.toJS();
2073 var iter = new Gtk.TreeIter();
2074 var s = this.get('/LeftPanel.view').selection;
2075 s.get_selected(this.el, iter);
2078 var gval = new GObject.Value('');
2079 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2081 var val = gval.value;
2082 if (val[0] == '!') {
2084 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2087 delete data.listeners[ val.substring(1)];
2088 if (!XObject.keys(data.listeners).length) {
2089 delete data.listeners;
2093 if (typeof(data[val]) == 'undefined') {
2101 this.get('/LeftTree.model').changed(data, true);
2104 editSelected : function(e) {
2105 print("EDIT SELECTED?");
2106 var iter = new Gtk.TreeIter();
2107 var s = this.get('/LeftPanel.view').selection;
2108 s.get_selected(this.get('/LeftPanel.model').el, iter);
2109 var m = this.get('/LeftPanel.model')
2111 var gval = new GObject.Value('');
2112 this.el.get_value(iter, 0 ,gval);
2113 var val = '' + gval.value;
2115 gval = new GObject.Value('');
2116 this.el.get_value(iter, 1 ,gval);
2117 var rval = gval.value;
2118 var activePath = this.el.get_path(iter).to_string();
2119 this.activePath = activePath ;
2120 // was activeIter...
2123 var showEditor = false;
2125 if (val[0] == '!') {
2128 if (val[0] == '|') {
2129 if (rval.match(/function/g) || rval.match(/\n/g)) {
2136 this.activePath = false;
2137 GLib.timeout_add(0, 1, function() {
2138 // Gdk.threads_enter();
2139 _this.get('/BottomPane').el.show();
2140 _this.get('/RightEditor').el.show();
2141 _this.get('/RightEditor.view').load( rval );
2145 _this.activePath = activePath ;
2147 // Gdk.threads_leave();
2152 this.get('/BottomPane').el.hide();
2153 this.get('/RightEditor').el.hide();
2155 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2159 getType : function(treepath) {
2160 return this.getValue(treepath, 4);
2162 getValue : function(treepath_str, col) {
2163 var iter = new Gtk.TreeIter();
2164 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2166 var gval = new GObject.Value('');
2167 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2168 var val = '' + gval.value;
2172 var type = this.getType(this.el.get_path(iter).to_string());
2173 print("TYPE: " +type + " - val:" + val);
2174 switch(type.toLowerCase()) {
2178 return parseFloat(val); // Nan ?? invalid!!?
2181 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2183 return val == 'true' ? true : false;
2185 var nv = parseFloat(val);
2186 if (!isNaN(nv) && (val == ''+nv)) {
2194 XObject.prototype.init.call(this);
2195 this.el.set_column_types ( 6, [
2196 GObject.TYPE_STRING, // 0 real key
2197 GObject.TYPE_STRING, // 1 real value
2198 GObject.TYPE_STRING, // 2 visable key
2199 GObject.TYPE_STRING, // 3 visable value
2200 GObject.TYPE_STRING, // 4 need to store type of!!!
2201 GObject.TYPE_STRING // 5 tooltip
2205 load : function(ar) {
2208 this.get('/RightEditor').el.hide();
2215 var provider = this.get('/LeftTree').getPaleteProvider();
2216 var iter = new Gtk.TreeIter();
2219 var keys = XObject.keys(ar);
2221 ar.listeners = ar.listeners || {};
2223 for (var i in ar.listeners ) {
2224 this.el.append(iter);
2225 var p = this.el.get_path(iter).to_string();
2228 this.el.set_value(iter, 0, '!'+ i );
2229 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2230 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2232 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2233 this.el.set_value(iter, 4, 'function');
2234 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2240 keys.forEach(function(i) {
2241 if (typeof(ar[i]) == 'object') {
2245 var type = provider.findType(ar, i, ar[i]);
2247 _this.el.append(iter);
2248 var p = _this.el.get_path(iter).to_string();
2250 _this.el.set_value(iter, 0, ''+i);
2251 _this.el.set_value(iter, 1, '' + ar[i]);
2252 _this.el.set_value(iter, 2, ''+i);
2253 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2254 _this.el.set_value(iter, 4, ''+type);
2255 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2259 startEditing : function(path,col) {
2261 * start editing path (or selected if not set..)
2262 * @param {String|false} path (optional) treepath to edit - selected tree gets
2263 * edited by default.
2264 * @param {Number} 0 or 1 (optional)- column to edit.
2267 if (typeof(path) == 'string') {
2268 tp = new Gtk.TreePath.from_string(path);
2270 var iter = new Gtk.TreeIter();
2271 var s = this.get('/LeftPanel.view').selection;
2272 s.get_selected(this.el, iter);
2273 tp = this.el.get_path(iter);
2274 path = tp.to_string();
2278 // which colum is to be edited..
2280 if (typeof(col) == 'undefined') {
2281 var k = this.getValue(path, 0);
2282 colObj = (!k.length || k == '|') ?
2283 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2285 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2288 // make sure the pulldown is set correctly..
2289 // not really needed for second col...
2291 var provider = this.get('/LeftTree').getPaleteProvider();
2293 var type = this.get('/LeftPanel.model').getType(path);
2294 var opts = provider.findOptions(type);
2295 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2297 if (opts === false) {
2298 this.get('/LeftPanel').editableColumn.setOptions([]);
2299 renderer.has_entry = true; /// probably does not have any effect.
2301 this.get('/LeftPanel').editableColumn.setOptions(opts);
2302 renderer.has_entry = false;
2306 // iter now has row...
2307 GLib.timeout_add(0, 100, function() {
2309 colObj.items[0].el.editable = true; // esp. need for col 0..
2310 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2320 var iter = new Gtk.TreeIter();
2321 this.get('/LeftPanel.model').el.get_iter_first(iter);
2326 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2329 ar.listeners = ar.listeners || {};
2330 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2333 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2336 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2342 //print(JSON.stringify(ar));
2346 toShort : function(str) {
2347 var a = typeof(str) == 'string' ? str.split("\n") : [];
2348 return a.length > 1 ? a[0] + '....' : '' + str;
2352 xtype: Gtk.TreeViewColumn,
2353 pack : "append_column",
2355 XObject.prototype.init.call(this);
2357 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2358 this.get('/LeftPanel').propertyColumn = this;
2363 xtype: Gtk.CellRendererText,
2364 pack : "pack_start",
2366 editing_started : function (self, editable, path) {
2368 this.get('/LeftPanel.model').activePath = path;
2371 edited : function (self, object, p0) {
2372 var model = this.get('/LeftPanel.model');
2373 var path = model.activePath;
2374 var iter = new Gtk.TreeIter();
2375 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2376 model.el.set_value(iter, 0, p0);
2377 model.el.set_value(iter, 2, p0);
2379 model.activePath = false;
2381 this.get('/LeftTree.model').changed(model.toJS(), true);
2382 this.el.editable = false;
2389 xtype: Gtk.TreeViewColumn,
2390 pack : "append_column",
2392 XObject.prototype.init.call(this);
2393 this.el.add_attribute(this.items[0].el , 'text', 3 );
2394 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2395 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2396 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2398 this.get('/LeftPanel').editableColumn= this;
2400 setOptions : function(ar) {
2401 var m = this.items[0].el.model;
2403 var iter = new Gtk.TreeIter();
2404 ar.forEach(function(i) {
2407 m.set_value(iter, 0, i);
2413 xtype: Gtk.CellRendererCombo,
2414 pack : "pack_start",
2419 XObject.prototype.init.call(this);
2420 this.el.model = new Gtk.ListStore();
2421 this.el.model.set_column_types ( 1, [
2422 GObject.TYPE_STRING // 0 real key
2426 edited : function (self, object, p0) {
2427 this.get('/LeftPanel').editing = false;
2428 print("EDITED? p:" + p0 + " t:" + p0);
2429 this.get('/LeftPanel.model').changed(p0, true);
2430 this.get('/LeftPanel.model').activePath = false;
2432 editing_started : function (self, editable, path) {
2433 this.get('/LeftPanel').editing = true;
2434 // console.log('editing started');
2435 // r.has_entry = false;
2436 this.get('/LeftPanel.model').editSelected(editable);
2447 id : "LeftPanelPopup",
2450 xtype: Gtk.MenuItem,
2454 activate : function (self) {
2455 this.get('/LeftPanel.model').deleteSelected();
2460 xtype: Gtk.MenuItem,
2464 activate : function (self) {
2465 this.get('/LeftPanel.model').startEditing(false, 0);
2478 xtype: Gtk.ScrolledWindow,
2479 pack : "pack_end,false,true,0",
2481 shadow_type : Gtk.ShadowType.IN,
2483 XObject.prototype.init.call(this);
2484 XObject.prototype.init.call(this);
2485 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2486 this.el.set_size_request ( 150, -1 );
2489 activeElement : false,
2490 hideWin : function() {
2497 if (this.get('/Window.left').el.position < 160) {
2500 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2507 xtype: Gtk.TreeView,
2508 enable_tree_lines : true,
2509 headers_visible : false,
2512 XObject.prototype.init.call(this);
2514 var description = new Pango.FontDescription.c_new();
2515 description.set_size(8000);
2516 this.el.modify_font(description);
2518 //this.selection = this.el.get_selection();
2519 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2528 cursor_changed : function (self) {
2529 var iter = new Gtk.TreeIter();
2531 //console.log('changed');
2532 var m = this.get('model');
2533 if (!this.selection){
2534 this.selection = this.el.get_selection();
2537 var s = this.selection;
2538 if (!s.get_selected(m.el, iter)) {
2541 var tp = m.el.get_path(iter).to_string();
2546 var key = m.getValue(tp, 0);
2548 var type = m.getValue(tp, 1);
2549 var skel = m.getValue(tp, 3);
2550 var etype = m.getValue(tp, 5);
2553 this.get('/MidPropTree').hideWin();
2555 if (type == 'function') {
2557 if (etype != 'events') {
2561 this.get('/LeftPanel.model').add({
2570 if (type.indexOf('.') > -1 ||
2571 type == 'boolean') {
2575 this.get('/LeftPanel.model').add( {
2585 xtype: Gtk.ListStore,
2588 XObject.prototype.init.call(this);
2589 this.el.set_column_types ( 6, [
2590 GObject.TYPE_STRING, // real key
2591 GObject.TYPE_STRING, // real type
2592 GObject.TYPE_STRING, // docs ?
2593 GObject.TYPE_STRING, // visable desc
2594 GObject.TYPE_STRING, // function desc
2595 GObject.TYPE_STRING // element type (event|prop)
2599 getValue : function(treepath, col)
2601 var tp = new Gtk.TreePath.from_string (treepath);
2602 var iter = new Gtk.TreeIter();
2603 this.el.get_iter (iter, tp);
2604 var value = new GObject.Value('');
2605 this.el.get_value(iter, col, value);
2609 showData : function(type) {
2611 if (!this.get('/MidPropTree').activeElement || !type) {
2612 return; // no active element
2615 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2616 var palete = this.get('/LeftTree').getPaleteProvider();
2620 Seed.print('Showing right?');
2621 if (!this.get('/MidPropTree').shown) {
2623 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2624 this.get('/MidPropTree').el.show();
2625 this.get('/MidPropTree').shown = true;
2628 var elementList = palete.getPropertiesFor(fullpath, type);
2629 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2630 // console.dump(elementList);
2633 var iter = new Gtk.TreeIter();
2634 for(var i =0 ; i < elementList.length; i++) {
2635 var p=elementList[i];
2636 this.el.append(iter);
2637 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2638 //GObject.TYPE_STRING, // real key
2639 // GObject.TYPE_STRING, // real type
2640 // GObject.TYPE_STRING, // docs ?
2641 // GObject.TYPE_STRING // func def?
2644 this.el.set_value(iter, 0, p.name);
2645 this.el.set_value(iter, 1, p.type);
2646 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2647 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2648 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2649 this.el.set_value(iter, 5, type);
2657 xtype: Gtk.TreeViewColumn,
2659 this.el = new Gtk.TreeViewColumn();
2660 this.parent.el.append_column(this.el);
2662 XObject.prototype.init.call(this);
2663 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2668 xtype: Gtk.CellRendererText,
2669 pack : "pack_start,true"
2693 xtype: Gtk.Notebook,
2694 pack : "pack_start,true,true",
2695 id : "view-help-nb",
2697 XObject.prototype.init.call(this);
2698 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2699 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2703 xtype: Gtk.Notebook,
2705 id : "view-notebook",
2708 XObject.prototype.init.call(this);
2709 this.el.set_current_page(0);
2711 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2712 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2719 id : "RightBrowser",
2725 xtype: Gtk.ScrolledWindow,
2727 shadow_type : Gtk.ShadowType.IN,
2729 XObject.prototype.init.call(this);
2730 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2734 xtype: WebKit.WebView,
2738 XObject.prototype.init.call(this);
2739 // this may not work!?
2740 this.el.open('file:///' + __script_path__ + '/../builder.html');
2744 this.el, /* widget that will accept a drop */
2745 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2746 null, /* lists of target to support */
2747 0, /* size of list */
2748 Gdk.DragAction.COPY /* what to do with data after dropped */
2751 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2752 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2754 renderJS : function(data) {
2755 print("HTML RENDERING");
2756 /// prevent looping..
2757 //if (this.pendingRedraw) {
2758 // print("pending redraw active?!");
2763 if (!this.get('/Window.LeftTree').getActiveFile()) {
2767 var project = this.get('/Window.LeftTree').getActiveFile().project;
2768 //print (project.fn);
2770 project.runhtml = project.runhtml || '';
2773 this.runhtml = this.runhtml || '';
2775 if (project.runhtml != this.runhtml) {
2776 // then we need to reload the browser using
2777 // load_html_string..
2779 // then trigger a redraw once it's loaded..
2780 this.pendingRedraw = true;
2782 this.runhtml = project.runhtml;
2784 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2785 html = html.replace('</head>', this.runhtml + '</head>');
2786 print("LOAD HTML " + html);
2787 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2788 // should trigger load_finished!
2793 this.pendingRedraw = false;
2796 this.renderedData = data;
2797 var str = JSON.stringify(data) ;
2800 console.log('not loaded yet');
2802 //Seed.print("RENDER:" + str);
2803 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2805 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2808 load_finished : function (self, object) {
2809 // if (this.ready) { // dont do it twice!
2813 this.pendingRedraw = false;
2814 var js = this.get('/LeftTree.model').toJS();
2816 this.renderJS(js[0]);
2820 script_alert : function (self, object, p0) {
2823 return true; // do not display anything...
2825 console_message : function (self, object, p0, p1) {
2826 // console.log(object);
2827 if (!object.match(/^\{/)) {
2829 this.get('/Terminal').feed(object);
2830 return true; // do not handle!!! -> later maybe in console..
2832 // console.log(object);
2833 var val = JSON.parse(object);
2835 if (typeof(val['hover-node']) != 'undefined') {
2836 this.activeNode = val['hover-node'];
2837 console.log('active node: ' + this.activeNode);
2842 if (typeof(val['id']) != 'undefined') {
2843 // this.activeNode = val['id'];
2844 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2848 this.get('/LeftTree.view').selectNode(tg[0]);
2852 if (ret && typeof(val['set']) != 'undefined') {
2853 this.get('/LeftPanel.model').add({
2857 //console.log('active node: ' + this.activeNode);
2860 //Seed.print('a:'+a);
2861 //Seed.print('b:'+b);
2862 //Seed.print('c:'+c);
2865 drag_motion : function (w, ctx, x, y, time, ud) {
2866 // console.log('DRAG MOTION');
2868 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2869 this.targetData = [];
2870 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2872 // A) find out from drag all the places that node could be dropped.
2873 var src = Gtk.drag_get_source_widget(ctx);
2874 if (!src.dropList) {
2875 Gdk.drag_status(ctx, 0, time);
2878 // b) get what we are over.. (from activeNode)
2879 // tree is empty.. - list should be correct..
2880 if (!this.get('/LeftTree.model').currentTree) {
2881 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2885 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2887 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2890 Gdk.drag_status(ctx, 0,time);
2891 this.get('/LeftTree.view').highlight(false);
2895 // if we have a target..
2896 // -> highlight it! (in browser)
2897 // -> highlight it! (in tree)
2899 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2900 this.get('/LeftTree.view').highlight(tg);
2901 this.targetData = tg;
2902 // for tree we should handle this...
2905 drag_drop : function (w, ctx, x, y,time, ud) {
2906 print("TARGET: drag-drop");
2907 var is_valid_drop_site = true;
2912 w, /* will receive 'drag-data-received' signal */
2913 ctx, /* represents the current state of the DnD */
2914 this.get('/Window').atoms["STRING"], /* the target type we want */
2915 time /* time stamp */
2919 /* No target offered by source => error */
2922 return is_valid_drop_site;
2924 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2926 print("Browser: drag-data-received");
2927 var delete_selection_data = false;
2928 vardnd_success = false;
2929 /* Deal with what we are given from source */
2930 if( sel_data && sel_data.length ) {
2932 if (ctx.action == Gdk.DragAction.ASK) {
2933 /* Ask the user to move or copy, then set the ctx action. */
2936 if (ctx.action == Gdk.DragAction.MOVE) {
2937 delete_selection_data = true;
2939 var source = Gtk.drag_get_source_widget(ctx);
2941 print("Browser: source.DRAGDATA? " + source.dragData);
2942 if (this.targetData) {
2943 print(this.targetData);
2944 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2953 if (dnd_success == false)
2955 Seed.print ("DnD data transfer failed!\n");
2958 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2969 id : "RightGtkView",
2971 redraw : function() {
2972 this.highlightWidget = false;
2973 print("REDRAW CALLED");
2974 this.activePath = this.get('/LeftTree').getActivePath();
2975 if (this.renderedEl) {
2976 print("QUEUE DRAW CALLING");
2977 this.renderedEl.queue_draw();
2980 renderJS : function(data, withDebug)
2982 this.highlightWidget = false;
2986 this.withDebug = false;
2988 if (this.renderedEl) {
2989 this.get('view').el.remove(this.renderedEl);
2990 this.renderedEl.destroy();
2991 this.renderedEl = false;
2994 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
2995 // in theory tree is actually window..
2997 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3002 this.get('view').el.set_size_request(
3003 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3006 this.renderedEl.set_size_request(
3007 tree.default_width || 600,
3008 tree.default_height || 400
3010 this.get('view').el.show_all();
3015 showInWindow : function() {
3016 print("GET PROEJCT");
3017 var pr = this.get('/LeftProjectTree').getActiveProject();
3019 console.log(pr.paths);
3022 var src= this.buildJS(
3023 this.get('/LeftTree.model').toJS()[0],
3028 //var x = new imports.sandbox.Context();
3032 Seed.check_syntax('var e = ' + src);
3035 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3036 this.get('/Terminal').feed(console._dump(e)+"\n");
3038 var lines = src.split("\n");
3039 var start = Math.max(0, e.line - 10);
3040 var end = Math.min(lines.length, e.line + 10);
3041 for (var i =start ; i < end; i++) {
3043 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3046 this.get('/Terminal').feed(lines[i] + "\n");
3053 this.get('/BottomPane').el.set_current_page(1);
3054 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3055 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3056 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3058 var _top = x.get_global_object()._top;
3060 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3062 if (_top.el.popup) {
3063 _top.el.popup(null, null, null, null, 3, null);
3067 viewAdd : function(item, par)
3069 // does something similar to xobject..
3070 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3072 if (item.pack===false || item.pack === 'false') { // no ;
3075 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3076 var type = item['|xns'] + '.' + item['xtype'];
3077 var ns = imports.gi[item['|xns']];
3078 var ctr = ns[item['xtype']];
3080 for(var k in item) {
3082 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3097 if (k[0] == '|' && typeof(kv) == 'string') {
3099 if (kv.match(new RegExp('function'))) {
3102 print("WASL " + k + '=' + kv);
3104 eval( 'kv = ' + kv);
3105 } catch(e) { continue; }
3108 // print(k + '=' + kv);
3110 if (k[0] == '|') { // should be boolean or number..
3112 //print(k + '=' + kv);
3115 if (k == 'show_tabs') { // force tab showing for notebooks.
3118 print(k + '=' + typeof(kv) + " : " + kv);
3124 var el = new ctr(ctr_args);
3126 print("PACK" + item.pack);
3127 //console.dump(item.pack);
3134 if (typeof(item.pack) == 'string') {
3136 item.pack.split(',').forEach(function(e, i) {
3138 if (e == 'false') { args.push( false); return; }
3139 if (e == 'true') { args.push( true); return; }
3140 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3143 //print(args.join(","));
3145 pack_m = args.shift();
3147 pack_m = item.pack.shift();
3152 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3154 name: "ArgumentError",
3155 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3156 "ADDING : " + item.id + " " + el
3165 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3166 //Seed.print('args: ' + args.length);
3168 par[pack_m].apply(par, args);
3172 item.items = item.items || [];
3173 item.items.forEach(function(ch,n) {
3175 print ("type:" + type);
3177 print ("ch.pack:" + ch.pack);
3178 if (type == 'Gtk.Table' && ch.pack == 'add') {
3179 var c = n % item.n_columns;
3180 var r = Math.floor(n/item.n_columns);
3181 ch.pack = [ 'attach', c, c+1, r, r+1,
3182 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3183 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3184 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3185 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3189 _this.viewAdd(ch, el);
3194 // add the signal handlers.
3195 // is it a widget!?!!?
3201 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3202 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3203 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3204 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3205 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3215 widgetDragDropEvent : function() {
3216 print("WIDGET DRAGDROP");
3219 widgetDragMotionEvent : function() {
3220 print("WIDGET DRAGMOTION");
3223 widgetExposeEvent : function(w, evt, ud, item) {
3225 if (this.inRender) {
3229 if ( this.highlightWidget) {
3230 this.inRender = true;
3231 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3232 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3234 this.inRender = false;
3239 if (this.activePath != item.xtreepath) {
3243 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3244 // work out the coords of the window..
3246 var dr = widget.window;
3247 this.gc = (new Gdk.GC.c_new(dr));
3248 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3249 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3253 var r = evt.expose.area;
3254 // console.dump([r.x, r.y, r.width, r.height ] );
3256 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3257 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3258 // happens with gtkscrollview embedded stuff..
3259 var np =this.activePath.split(':');
3261 this.activePath = np.join(':');
3262 this.renderedEl.queue_draw();
3278 this.inRender = true;
3281 this.highlightWidget = widget;
3286 // print("DRAW BOX");
3287 //console.dump(this.box);
3288 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3289 this.inRender = false;
3292 widgetPressEvent : function(w,e,u,d) {
3293 if (this.get('view').pressed) {
3296 this.get('view').pressed = true;
3297 print("WIDGET PRESS " + d.xtreepath );
3298 this.get('/LeftTree.view').selectNode( d.xtreepath );
3301 widgetReleaseEvent : function() {
3302 this.get('view').pressed = false;
3308 pack : "pack_start,false,true,0",
3312 pack : "pack_start,false,false,0",
3313 label : "Run The Application",
3315 button_press_event : function (self, event) {
3316 // call render on left tree - with special option!?!
3318 //print("GET PROEJCT");
3319 var pr = this.get('/LeftProjectTree').getActiveProject();
3322 for (var i in pr.paths) {
3326 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3327 this.get('/Terminal').feed("RUN DIR:" + dir);
3329 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3330 , false,false,false);
3331 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3332 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3342 xtype: Gtk.ScrolledWindow,
3345 shadow_type : Gtk.ShadowType.IN,
3347 XObject.prototype.init.call(this);
3348 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3352 xtype: Gtk.EventBox,
3353 pack : "add_with_viewport",
3355 XObject.prototype.init.call(this);
3356 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3357 red: 0x9F00, green: 0xB800 , blue : 0xA800
3365 XObject.prototype.init.call(this);
3366 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3367 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3372 xtype: Gtk.EventBox,
3375 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3376 XObject.prototype.init.call(this);
3380 this.el, /* widget that will accept a drop */
3381 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3382 null, /* lists of target to support */
3383 0, /* size of list */
3384 Gdk.DragAction.COPY /* what to do with data after dropped */
3387 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3388 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3391 getActiveNode : function(x,y)
3393 // workout what node is here..
3394 return '0'; // top..
3398 drag_motion : function (self, ctx, x, y, time) {
3400 // A) find out from drag all the places that node could be dropped.
3401 var src = Gtk.drag_get_source_widget(ctx);
3402 if (!src.dropList) {
3403 Gdk.drag_status(ctx, 0, time);
3406 // b) get what we are over.. (from activeNode)
3407 // tree is empty.. - list should be correct..
3408 if (!this.get('/LeftTree.model').currentTree) {
3409 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3413 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3414 var activeNode = this.getActiveNode(x, y);
3417 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3420 Gdk.drag_status(ctx, 0,time);
3421 this.get('/LeftTree.view').highlight(false);
3425 // if we have a target..
3426 // -> highlight it! (in browser)
3427 // -> highlight it! (in tree)
3429 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3430 this.get('/LeftTree.view').highlight(tg);
3431 this.targetData = tg;
3432 // for tree we should handle this...
3435 drag_drop : function (self,ctx, x, y, time) {
3436 Seed.print("TARGET: drag-drop");
3437 var is_valid_drop_site = true;
3442 self, /* will receive 'drag-data-received' signal */
3443 ctx, /* represents the current state of the this.gDnD */
3444 this.get('/Window').atoms["STRING"], /* the target type we want */
3445 time /* time stamp */
3449 /* No target offered by source => error */
3452 return is_valid_drop_site;
3455 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3457 Seed.print("GtkView: drag-data-received");
3458 var delete_selection_data = false;
3459 var dnd_success = false;
3460 /* Deal with what we are given from source */
3461 if( sel_data && sel_data.length ) {
3463 if (ctx.action == Gdk.DragAction.ASK) {
3464 /* Ask the user to move or copy, then set the ctx action. */
3467 if (ctx.action == Gdk.DragAction.MOVE) {
3468 delete_selection_data = true;
3470 var source = Gtk.drag_get_source_widget(ctx);
3472 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3473 if (this.targetData) {
3474 Seed.print(this.targetData);
3475 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3484 if (dnd_success == false)
3486 Seed.print ("DnD data transfer failed!\n");
3489 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3492 button_press_event : function (self, event) {
3493 this.pressed = false;
3509 xtype: Gtk.ScrolledWindow,
3514 var file = this.get('/LeftTree').getActiveFile();
3518 var activeEl = this.get('/LeftTree').getActiveElement();
3519 var xtype = file.guessName( activeEl )
3520 if (!xtype || !xtype.length) {
3523 this.get('/Window.view-help-nb').el.set_current_page(1);
3525 // get the active element being edited.
3526 var helpurl = file.getHelpUrl(xtype);
3528 // now load the help info in the page..
3529 this.get('help-view').el.open(helpurl);
3533 xtype: WebKit.WebView,
3537 XObject.prototype.init.call(this);
3538 this.get('/Window.help-view').el.open(
3539 "http://devel.akbkhome.com/seed/");
3551 xtype: Gtk.Notebook,
3554 XObject.prototype.init.call(this);
3555 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3556 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3561 xtype: Gtk.ScrolledWindow,
3566 xtype: GtkSource.View,
3570 XObject.prototype.init.call(this);
3571 var description = Pango.Font.description_from_string("monospace")
3572 description.set_size(8000);
3573 this.el.modify_font(description);
3576 load : function(str) {
3578 // show the help page for the active node..
3579 this.get('/Help').show();
3582 this.get('/BottomPane').el.set_current_page(0);
3583 this.el.get_buffer().set_text(str, str.length);
3584 var lm = GtkSource.LanguageManager.get_default();
3586 this.el.get_buffer().set_language(lm.get_language('js'));
3587 var buf = this.el.get_buffer();
3588 var cursor = buf.get_mark("insert");
3589 var iter= new Gtk.TextIter;
3590 buf.get_iter_at_mark(iter, cursor);
3592 iter.set_line_offset(4);
3593 buf.move_mark(cursor, iter);
3596 cursor = buf.get_mark("selection_bound");
3597 iter= new Gtk.TextIter;
3598 buf.get_iter_at_mark(iter, cursor);
3600 iter.set_line_offset(4);
3601 buf.move_mark(cursor, iter);
3603 this.el.grab_focus();
3605 insert_spaces_instead_of_tabs : true,
3608 show_line_numbers : true,
3611 xtype: GtkSource.Buffer,
3612 pack : "set_buffer",
3614 changed : function (self) {
3615 var s = new Gtk.TextIter();
3616 var e = new Gtk.TextIter();
3617 this.el.get_start_iter(s);
3618 this.el.get_end_iter(e);
3619 var str = this.el.get_text(s,e,true);
3621 Seed.check_syntax('var e = ' + str);
3623 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3624 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3626 print("SYNTAX ERROR IN EDITOR");
3631 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3632 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3635 this.get('/LeftPanel.model').changed( str , false);
3644 xtype: Gtk.ScrolledWindow,
3648 xtype: Vte.Terminal,
3651 feed : function(istr) {
3652 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3653 // we should make ourselves visable!!!
3654 this.get('/BottomPane').el.show();
3655 this.get('/BottomPane').el.set_current_page(1);
3657 this.el.feed(str ,str.length);
3659 scroll_on_output : true,
3661 XObject.prototype.init.call(this);
3662 this.el.set_size (80, 1000);
3664 scrollback_lines : 1000
3674 pack : "pack_start,false,false",
3678 this.get('buttonbar').el.show();
3679 this.get('viewbox').el.hide();
3680 print("TRIED TO HIDE");
3683 this.get('buttonbar').el.hide();
3684 this.get('viewbox').el.show();
3685 // this.get('model').expanded();
3697 pack : "pack_start,false,true",
3699 clicked : function (self) {
3700 this.get('/RightPalete').show();
3707 stock : Gtk.STOCK_GOTO_FIRST,
3708 icon_size : Gtk.IconSize.MENU
3718 XObject.prototype.init.call(this);
3719 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3722 enter_notify_event : function (self, event) {
3723 this.get('/RightPalete').show();
3737 pack : "pack_start,false,true",
3746 pack : "pack_start,false,true",
3748 clicked : function (self) {
3749 this.get('/RightPalete').hide();
3756 stock : Gtk.STOCK_GOTO_LAST,
3757 icon_size : Gtk.IconSize.MENU
3764 xtype: Gtk.ScrolledWindow,
3767 XObject.prototype.init.call(this);
3768 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3769 this.el.set_size_request(-1,200);
3771 shadow_type : Gtk.ShadowType.IN,
3774 xtype: Gtk.TreeView,
3777 XObject.prototype.init.call(this);
3778 this.el.set_size_request(150,-1);
3779 // set_reorderable: [1]
3781 var description = new Pango.FontDescription.c_new();
3782 description.set_size(8000);
3783 this.el.modify_font(description);
3785 this.selection = this.el.get_selection();
3786 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3787 // this.selection.signal['changed'].connect(function() {
3788 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3790 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3792 Gtk.drag_source_set (
3793 this.el, /* widget will be drag-able */
3794 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3795 null, /* lists of target to support */
3796 0, /* size of list */
3797 Gdk.DragAction.COPY /* what to do with data after dropped */
3799 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3801 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3802 Gtk.drag_source_add_text_targets(this.el);
3804 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3805 targets = new Gtk.TargetList();
3806 targets.add( LeftTree.atoms["STRING"], 0, 0);
3807 targets.add_text_targets( 1 );
3808 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3810 //if you want to allow text to be output elsewhere..
3811 //Gtk.drag_source_add_text_targets(this.el);
3815 headers_visible : false,
3816 enable_tree_lines : true,
3818 drag_begin : function (self, ctx) {
3819 // we could fill this in now...
3820 Seed.print('SOURCE: drag-begin');
3824 var iter = new Gtk.TreeIter();
3825 var s = this.selection;
3826 s.get_selected(this.get('/RightPalete.model').el, iter);
3827 var path = this.get('/RightPalete.model').el.get_path(iter);
3829 var pix = this.el.create_row_drag_icon ( path);
3832 Gtk.drag_set_icon_pixmap (ctx,
3839 var value = new GObject.Value('');
3840 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3841 if (!this.get('/RightPalete').provider) {
3844 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3845 this.el.dragData = value.value;
3852 drag_data_get : function (self, drag_context, selection_data, info, time) {
3853 //Seed.print('Palete: drag-data-get: ' + target_type);
3854 if (this.el.dragData && this.el.dragData.length ) {
3855 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3859 //this.el.dragData = "TEST from source widget";
3863 drag_end : function (self, drag_context) {
3864 Seed.print('SOURCE: drag-end');
3865 this.el.dragData = false;
3866 this.el.dropList = false;
3867 this.get('/LeftTree.view').highlight(false);
3873 xtype: Gtk.ListStore,
3876 XObject.prototype.init.call(this);
3877 this.el.set_column_types ( 2, [
3878 GObject.TYPE_STRING, // title
3879 GObject.TYPE_STRING // tip
3884 load : function(tr,iter)
3889 //console.log('Project tree load: ' + tr.length);
3890 var citer = new Gtk.TreeIter();
3891 //this.insert(citer,iter,0);
3892 for(var i =0 ; i < tr.length; i++) {
3895 this.el.append(citer);
3897 this.el.insert(citer,iter,-1);
3902 this.el.set_value(citer, 0, '' + r ); // title
3904 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3905 //if (r.cn && r.cn.length) {
3906 // this.load(r.cn, citer);
3912 getValue : function (iter, col) {
3913 var gval = new GObject.Value('');
3914 this.el.get_value(iter, col ,gval);
3921 xtype: Gtk.TreeViewColumn,
3922 pack : "append_column",
3924 XObject.prototype.init.call(this);
3925 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3929 xtype: Gtk.CellRendererText,
3951 XObject.cache['/Window'] = Window;