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(treepath, with_id)
1329 //Seed.print("WITHID: "+ with_id);
1330 var iter = treepath; // API used to be iter here..
1331 if (typeof(iter) == 'string') {
1332 iter = new Gtk.TreeIter();
1333 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1342 iter = new Gtk.TreeIter();
1343 if (!this.el.get_iter_first(iter)) {
1353 var k = this.nodeToJS(iter, with_id);
1357 if (!this.el.iter_next(iter)) {
1363 // convert the list into a json string..
1369 xtype: Gtk.TreeViewColumn,
1370 pack : "append_column",
1372 XObject.prototype.init.call(this);
1373 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1377 xtype: Gtk.CellRendererText,
1387 id : "LeftTreeMenu",
1390 xtype: Gtk.MenuItem,
1392 label : "Delete Element",
1394 activate : function (self) {
1396 this.get('/LeftTree.model').deleteSelected();
1401 xtype: Gtk.MenuItem,
1403 activate : function (self) {
1405 var tree = this.get('/LeftTree');
1406 var model = this.get('/LeftTree.model');
1407 var el = tree.getActivePath();
1409 var js = model.toJS(el, false);
1410 print(JSON.stringify(js[0], null,4));
1411 this.get('/DialogSaveTemplate').el.show_all();
1416 label : "Save as Template",
1426 id : "LeftProjectTree",
1427 showNoProjectSelected : function() {
1428 this.get('/StandardErrorDialog').show("Select a Project first.");
1430 getActiveProject : function() {
1431 return this.project;
1434 leave_notify_event : function (self, event) {
1441 pack : "pack_start,false,false",
1444 xtype: Gtk.ComboBox,
1447 XObject.prototype.init.call(this);
1448 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1450 getValue : function() {
1451 var ix = this.el.get_active();
1455 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1456 if (typeof(data[ix]) == 'undefined') {
1461 setValue : function(fn)
1465 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1466 data.forEach(function(n, ix) {
1474 changed : function (self) {
1475 var fn = this.getValue();
1476 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1477 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1482 xtype: Gtk.CellRendererText,
1483 pack : "pack_start,true",
1487 xtype: Gtk.ListStore,
1490 XObject.prototype.init.call(this);
1491 this.el.set_column_types ( 2, [
1492 GObject.TYPE_STRING, // real key
1493 GObject.TYPE_STRING // real type
1497 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1499 pm.on('changed', function() {
1500 print("caught changed hook on project manager - reloading data");
1501 _this.loadData(pm.projects);
1505 loadData : function(data) {
1506 var ov = this.get('/LeftProjectTree.combo').getValue();
1508 var iter = new Gtk.TreeIter();
1510 data.forEach(function(p) {
1515 el.set_value(iter, 0, p.fn);
1516 el.set_value(iter, 1, p.name);
1520 this.get('/LeftProjectTree.combo').setValue(ov);
1529 xtype: Gtk.ScrolledWindow,
1531 shadow_type : Gtk.ShadowType.IN,
1533 XObject.prototype.init.call(this);
1534 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1538 xtype: Gtk.TreeView,
1539 headers_visible : false,
1540 enable_tree_lines : true,
1543 XObject.prototype.init.call(this);
1544 var description = new Pango.FontDescription.c_new();
1545 description.set_size(8000);
1546 this.el.modify_font(description);
1548 this.selection = this.el.get_selection();
1549 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1553 cursor_changed : function (self) {
1554 var iter = new Gtk.TreeIter();
1556 if (this.selection.count_selected_rows() < 1) {
1557 //XN.get('Builder.LeftTree.model').
1558 this.get('/LeftTree.model').load( false);
1562 var model = this.get('/LeftProjectTree.model');
1563 //console.log('changed');
1564 var s = this.selection;
1565 s.get_selected(model, iter);
1566 value = new GObject.Value('');
1567 model.el.get_value(iter, 2, value);
1569 console.log(value.value);// id..
1571 var file = this.get('/LeftProjectTree').project.getById(value.value);
1578 var nb = this.get('/LeftTopPanel.expander');
1579 nb.el.expanded = false;
1580 nb.listeners.activate.call(nb);
1581 //_expander.el.set_expanded(false);
1583 var ltm = this.get('/LeftTree.model');
1591 xtype: Gtk.TreeStore,
1595 XObject.prototype.init.call(this);
1596 this.el.set_column_types ( 3, [
1597 GObject.TYPE_STRING, // title
1598 GObject.TYPE_STRING, // tip
1599 GObject.TYPE_STRING // id..
1603 loadProject : function(pr) {
1604 print("LOAD PROJECT");
1610 this.get('/LeftProjectTree').project = pr;
1611 this.load(pr.toTree());
1612 this.get('/LeftProjectTree.view').el.expand_all();
1614 load : function(tr,iter) {
1615 // console.dump(tr);
1616 console.log('Project tree load: ' + tr.length);
1617 var citer = new Gtk.TreeIter();
1618 //this.insert(citer,iter,0);
1621 tr.forEach(function (r) {
1623 _this.el.append(citer);
1625 _this.el.insert(citer,iter,-1);
1627 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1628 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1629 _this.el.set_value(citer, 2, '' + r.id ); //id
1630 if (r.cn && r.cn.length) {
1631 _this.load(r.cn, citer);
1636 getValue : function(iter, col) {
1637 var gval = new GObject.Value('');
1638 this.el.get_value(iter, col ,gval);
1639 return '' + gval.value;
1643 xtype: Gtk.TreeViewColumn,
1644 pack : "append_column",
1646 XObject.prototype.init.call(this);
1647 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1651 xtype: Gtk.CellRendererText,
1674 pack : "pack_start,false,true,0",
1681 button_press_event : function (self, event) {
1682 this.get('/MidPropTree.model').showData('props');
1694 stock : Gtk.STOCK_ADD,
1695 icon_size : Gtk.IconSize.MENU
1710 button_press_event : function (self, event) {
1711 this.get('/MidPropTree.model').showData('events');
1723 stock : Gtk.STOCK_ADD,
1724 icon_size : Gtk.IconSize.MENU
1739 button_press_event : function (self, ev) {
1740 var p = this.get('/AddPropertyPopup');
1744 p.el.set_screen(Gdk.Screen.get_default());
1746 p.el.popup(null, null, null, null, 3, ev.button.time);
1758 stock : Gtk.STOCK_ADD,
1759 icon_size : Gtk.IconSize.MENU
1771 id : "AddPropertyPopup",
1774 xtype: Gtk.MenuItem,
1776 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1779 activate : function (self) {
1781 this.get('/LeftPanel.model').add( {
1792 xtype: Gtk.MenuItem,
1794 tooltip_markup : "Add what type of packing is to be used",
1797 activate : function (self) {
1799 this.get('/LeftPanel.model').add( {
1809 xtype: Gtk.MenuItem,
1811 tooltip_markup : "Override the init method",
1814 activate : function (self) {
1816 this.get('/LeftPanel.model').add( {
1819 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1826 xtype: Gtk.SeparatorMenuItem,
1830 xtype: Gtk.MenuItem,
1832 tooltip_markup : "Add a user defined string property",
1835 activate : function (self) {
1837 this.get('/LeftPanel.model').add( {
1847 xtype: Gtk.MenuItem,
1849 tooltip_markup : "Add a user defined number property",
1852 activate : function (self) {
1854 this.get('/LeftPanel.model').add( {
1864 xtype: Gtk.MenuItem,
1866 tooltip_markup : "Add a user defined boolean property",
1869 activate : function (self) {
1871 this.get('/LeftPanel.model').add( {
1881 xtype: Gtk.SeparatorMenuItem,
1885 xtype: Gtk.MenuItem,
1887 tooltip_markup : "Add a user function boolean property",
1890 activate : function (self) {
1892 this.get('/LeftPanel.model').add( {
1895 val : "function() {\n \n}\n",
1908 xtype: Gtk.ScrolledWindow,
1911 shadow_type : Gtk.ShadowType.IN,
1914 XObject.prototype.init.call(this);
1915 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1919 xtype: Gtk.TreeView,
1922 headers_visible : false,
1923 enable_tree_lines : true,
1925 XObject.prototype.init.call(this);
1927 this.selection = this.el.get_selection();
1928 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1931 var description = new Pango.FontDescription.c_new();
1932 description.set_size(8000);
1933 this.el.modify_font(description);
1936 button_press_event : function (self, ev) {
1940 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1941 return false; //not on a element.
1945 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1947 if (res.column.title != 'value') {
1948 return false; // ignore..
1950 if ( this.get('/LeftPanel').editing) {
1953 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1954 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1955 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1959 var provider = this.get('/LeftTree').getPaleteProvider();
1961 var opts = provider.findOptions(type);
1963 if (opts === false) {
1964 this.get('/LeftPanel').editableColumn.setOptions([]);
1965 renderer.has_entry = true;
1967 LeftPanel.editableColumn.setOptions(opts);
1968 renderer.has_entry = false;
1972 //Seed.print("click" + ev.type);
1973 //console.dump(res);
1979 if (res.column.title == 'value') {
1982 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1983 var p = this.get('/LeftPanelPopup');
1988 p.el.set_screen(Gdk.Screen.get_default());
1990 p.el.popup(null, null, null, null, 3, ev.button.time);
1991 //Seed.print("click:" + res.column.title);
1999 xtype: Gtk.TreeStore,
2003 getIterValue : function(iter, col) {
2004 var gval = new GObject.Value('');
2005 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2006 return '' + gval.value;
2008 add : function(info) {
2009 // info includes key, val, skel, etype..
2011 type = info.type.toLowerCase();
2012 var data = this.toJS();
2014 if (info.etype == 'events') {
2015 data.listeners = data.listeners || { };
2016 if (typeof(data.listeners[info.key]) != 'undefined') {
2017 return; //already set!
2020 if (typeof(data[info.key]) != 'undefined') {
2025 if (typeof(info.val) == 'undefined') {
2028 if (info.type == 'boolean') {
2031 if (type == 'number') {
2039 if (info.etype == 'events') {
2041 data.listeners[info.key] = info.val;
2044 data[info.key] = info.val;
2048 var map = this.load(data);
2050 // flag it as changed to the interface..
2052 this.get('/LeftTree.model').changed(data, true);
2055 this.startEditing(map[k]);
2058 LeftPanel.get('view').el.row_activated(
2059 new Gtk.TreePath.from_string(map[k]),
2060 LeftPanel.editableColumn.el
2064 changed : function(str, doRefresh) {
2065 if (!this.activePath) {
2068 var iter = new Gtk.TreeIter();
2069 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2071 this.el.set_value(iter, 1, '' +str);
2072 this.el.set_value(iter, 3, '' + this.toShort(str));
2073 var type = this.getIterValue(iter, 4);
2075 this.el.set_value(iter, 5, type + ' : ' + str);
2076 // update the tree...
2078 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2080 deleteSelected : function() {
2081 var data = this.toJS();
2082 var iter = new Gtk.TreeIter();
2083 var s = this.get('/LeftPanel.view').selection;
2084 s.get_selected(this.el, iter);
2087 var gval = new GObject.Value('');
2088 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2090 var val = gval.value;
2091 if (val[0] == '!') {
2093 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2096 delete data.listeners[ val.substring(1)];
2097 if (!XObject.keys(data.listeners).length) {
2098 delete data.listeners;
2102 if (typeof(data[val]) == 'undefined') {
2110 this.get('/LeftTree.model').changed(data, true);
2113 editSelected : function(e) {
2114 print("EDIT SELECTED?");
2115 var iter = new Gtk.TreeIter();
2116 var s = this.get('/LeftPanel.view').selection;
2117 s.get_selected(this.get('/LeftPanel.model').el, iter);
2118 var m = this.get('/LeftPanel.model')
2120 var gval = new GObject.Value('');
2121 this.el.get_value(iter, 0 ,gval);
2122 var val = '' + gval.value;
2124 gval = new GObject.Value('');
2125 this.el.get_value(iter, 1 ,gval);
2126 var rval = gval.value;
2127 var activePath = this.el.get_path(iter).to_string();
2128 this.activePath = activePath ;
2129 // was activeIter...
2132 var showEditor = false;
2134 if (val[0] == '!') {
2137 if (val[0] == '|') {
2138 if (rval.match(/function/g) || rval.match(/\n/g)) {
2145 this.activePath = false;
2146 GLib.timeout_add(0, 1, function() {
2147 // Gdk.threads_enter();
2148 _this.get('/BottomPane').el.show();
2149 _this.get('/RightEditor').el.show();
2150 _this.get('/RightEditor.view').load( rval );
2154 _this.activePath = activePath ;
2156 // Gdk.threads_leave();
2161 this.get('/BottomPane').el.hide();
2162 this.get('/RightEditor').el.hide();
2164 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2168 getType : function(treepath) {
2169 return this.getValue(treepath, 4);
2171 getValue : function(treepath_str, col) {
2172 var iter = new Gtk.TreeIter();
2173 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2175 var gval = new GObject.Value('');
2176 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2177 var val = '' + gval.value;
2181 var type = this.getType(this.el.get_path(iter).to_string());
2182 print("TYPE: " +type + " - val:" + val);
2183 switch(type.toLowerCase()) {
2187 return parseFloat(val); // Nan ?? invalid!!?
2190 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2192 return val == 'true' ? true : false;
2194 var nv = parseFloat(val);
2195 if (!isNaN(nv) && (val == ''+nv)) {
2203 XObject.prototype.init.call(this);
2204 this.el.set_column_types ( 6, [
2205 GObject.TYPE_STRING, // 0 real key
2206 GObject.TYPE_STRING, // 1 real value
2207 GObject.TYPE_STRING, // 2 visable key
2208 GObject.TYPE_STRING, // 3 visable value
2209 GObject.TYPE_STRING, // 4 need to store type of!!!
2210 GObject.TYPE_STRING // 5 tooltip
2214 load : function(ar) {
2217 this.get('/RightEditor').el.hide();
2224 var provider = this.get('/LeftTree').getPaleteProvider();
2225 var iter = new Gtk.TreeIter();
2228 var keys = XObject.keys(ar);
2230 ar.listeners = ar.listeners || {};
2232 for (var i in ar.listeners ) {
2233 this.el.append(iter);
2234 var p = this.el.get_path(iter).to_string();
2237 this.el.set_value(iter, 0, '!'+ i );
2238 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2239 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2241 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2242 this.el.set_value(iter, 4, 'function');
2243 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2249 keys.forEach(function(i) {
2250 if (typeof(ar[i]) == 'object') {
2254 var type = provider.findType(ar, i, ar[i]);
2256 _this.el.append(iter);
2257 var p = _this.el.get_path(iter).to_string();
2259 _this.el.set_value(iter, 0, ''+i);
2260 _this.el.set_value(iter, 1, '' + ar[i]);
2261 _this.el.set_value(iter, 2, ''+i);
2262 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2263 _this.el.set_value(iter, 4, ''+type);
2264 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2268 startEditing : function(path,col) {
2270 * start editing path (or selected if not set..)
2271 * @param {String|false} path (optional) treepath to edit - selected tree gets
2272 * edited by default.
2273 * @param {Number} 0 or 1 (optional)- column to edit.
2276 if (typeof(path) == 'string') {
2277 tp = new Gtk.TreePath.from_string(path);
2279 var iter = new Gtk.TreeIter();
2280 var s = this.get('/LeftPanel.view').selection;
2281 s.get_selected(this.el, iter);
2282 tp = this.el.get_path(iter);
2283 path = tp.to_string();
2287 // which colum is to be edited..
2289 if (typeof(col) == 'undefined') {
2290 var k = this.getValue(path, 0);
2291 colObj = (!k.length || k == '|') ?
2292 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2294 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2297 // make sure the pulldown is set correctly..
2298 // not really needed for second col...
2300 var provider = this.get('/LeftTree').getPaleteProvider();
2302 var type = this.get('/LeftPanel.model').getType(path);
2303 var opts = provider.findOptions(type);
2304 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2306 if (opts === false) {
2307 this.get('/LeftPanel').editableColumn.setOptions([]);
2308 renderer.has_entry = true; /// probably does not have any effect.
2310 this.get('/LeftPanel').editableColumn.setOptions(opts);
2311 renderer.has_entry = false;
2315 // iter now has row...
2316 GLib.timeout_add(0, 100, function() {
2318 colObj.items[0].el.editable = true; // esp. need for col 0..
2319 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2329 var iter = new Gtk.TreeIter();
2330 this.get('/LeftPanel.model').el.get_iter_first(iter);
2335 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2338 ar.listeners = ar.listeners || {};
2339 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2342 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2345 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2351 //print(JSON.stringify(ar));
2355 toShort : function(str) {
2356 var a = typeof(str) == 'string' ? str.split("\n") : [];
2357 return a.length > 1 ? a[0] + '....' : '' + str;
2361 xtype: Gtk.TreeViewColumn,
2362 pack : "append_column",
2364 XObject.prototype.init.call(this);
2366 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2367 this.get('/LeftPanel').propertyColumn = this;
2372 xtype: Gtk.CellRendererText,
2373 pack : "pack_start",
2375 editing_started : function (self, editable, path) {
2377 this.get('/LeftPanel.model').activePath = path;
2380 edited : function (self, object, p0) {
2381 var model = this.get('/LeftPanel.model');
2382 var path = model.activePath;
2383 var iter = new Gtk.TreeIter();
2384 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2385 model.el.set_value(iter, 0, p0);
2386 model.el.set_value(iter, 2, p0);
2388 model.activePath = false;
2390 this.get('/LeftTree.model').changed(model.toJS(), true);
2391 this.el.editable = false;
2398 xtype: Gtk.TreeViewColumn,
2399 pack : "append_column",
2401 XObject.prototype.init.call(this);
2402 this.el.add_attribute(this.items[0].el , 'text', 3 );
2403 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2404 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2405 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2407 this.get('/LeftPanel').editableColumn= this;
2409 setOptions : function(ar) {
2410 var m = this.items[0].el.model;
2412 var iter = new Gtk.TreeIter();
2413 ar.forEach(function(i) {
2416 m.set_value(iter, 0, i);
2422 xtype: Gtk.CellRendererCombo,
2423 pack : "pack_start",
2428 XObject.prototype.init.call(this);
2429 this.el.model = new Gtk.ListStore();
2430 this.el.model.set_column_types ( 1, [
2431 GObject.TYPE_STRING // 0 real key
2435 edited : function (self, object, p0) {
2436 this.get('/LeftPanel').editing = false;
2437 print("EDITED? p:" + p0 + " t:" + p0);
2438 this.get('/LeftPanel.model').changed(p0, true);
2439 this.get('/LeftPanel.model').activePath = false;
2441 editing_started : function (self, editable, path) {
2442 this.get('/LeftPanel').editing = true;
2443 // console.log('editing started');
2444 // r.has_entry = false;
2445 this.get('/LeftPanel.model').editSelected(editable);
2456 id : "LeftPanelPopup",
2459 xtype: Gtk.MenuItem,
2463 activate : function (self) {
2464 this.get('/LeftPanel.model').deleteSelected();
2469 xtype: Gtk.MenuItem,
2473 activate : function (self) {
2474 this.get('/LeftPanel.model').startEditing(false, 0);
2487 xtype: Gtk.ScrolledWindow,
2488 pack : "pack_end,false,true,0",
2490 shadow_type : Gtk.ShadowType.IN,
2492 XObject.prototype.init.call(this);
2493 XObject.prototype.init.call(this);
2494 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2495 this.el.set_size_request ( 150, -1 );
2498 activeElement : false,
2499 hideWin : function() {
2506 if (this.get('/Window.left').el.position < 160) {
2509 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2516 xtype: Gtk.TreeView,
2517 enable_tree_lines : true,
2518 headers_visible : false,
2521 XObject.prototype.init.call(this);
2523 var description = new Pango.FontDescription.c_new();
2524 description.set_size(8000);
2525 this.el.modify_font(description);
2527 //this.selection = this.el.get_selection();
2528 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2537 cursor_changed : function (self) {
2538 var iter = new Gtk.TreeIter();
2540 //console.log('changed');
2541 var m = this.get('model');
2542 if (!this.selection){
2543 this.selection = this.el.get_selection();
2546 var s = this.selection;
2547 if (!s.get_selected(m.el, iter)) {
2550 var tp = m.el.get_path(iter).to_string();
2555 var key = m.getValue(tp, 0);
2557 var type = m.getValue(tp, 1);
2558 var skel = m.getValue(tp, 3);
2559 var etype = m.getValue(tp, 5);
2562 this.get('/MidPropTree').hideWin();
2564 if (type == 'function') {
2566 if (etype != 'events') {
2570 this.get('/LeftPanel.model').add({
2579 if (type.indexOf('.') > -1 ||
2580 type == 'boolean') {
2584 this.get('/LeftPanel.model').add( {
2594 xtype: Gtk.ListStore,
2597 XObject.prototype.init.call(this);
2598 this.el.set_column_types ( 6, [
2599 GObject.TYPE_STRING, // real key
2600 GObject.TYPE_STRING, // real type
2601 GObject.TYPE_STRING, // docs ?
2602 GObject.TYPE_STRING, // visable desc
2603 GObject.TYPE_STRING, // function desc
2604 GObject.TYPE_STRING // element type (event|prop)
2608 getValue : function(treepath, col)
2610 var tp = new Gtk.TreePath.from_string (treepath);
2611 var iter = new Gtk.TreeIter();
2612 this.el.get_iter (iter, tp);
2613 var value = new GObject.Value('');
2614 this.el.get_value(iter, col, value);
2618 showData : function(type) {
2620 if (!this.get('/MidPropTree').activeElement || !type) {
2621 return; // no active element
2624 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2625 var palete = this.get('/LeftTree').getPaleteProvider();
2629 Seed.print('Showing right?');
2630 if (!this.get('/MidPropTree').shown) {
2632 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2633 this.get('/MidPropTree').el.show();
2634 this.get('/MidPropTree').shown = true;
2637 var elementList = palete.getPropertiesFor(fullpath, type);
2638 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2639 // console.dump(elementList);
2642 var iter = new Gtk.TreeIter();
2643 for(var i =0 ; i < elementList.length; i++) {
2644 var p=elementList[i];
2645 this.el.append(iter);
2646 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2647 //GObject.TYPE_STRING, // real key
2648 // GObject.TYPE_STRING, // real type
2649 // GObject.TYPE_STRING, // docs ?
2650 // GObject.TYPE_STRING // func def?
2653 this.el.set_value(iter, 0, p.name);
2654 this.el.set_value(iter, 1, p.type);
2655 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2656 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2657 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2658 this.el.set_value(iter, 5, type);
2666 xtype: Gtk.TreeViewColumn,
2668 this.el = new Gtk.TreeViewColumn();
2669 this.parent.el.append_column(this.el);
2671 XObject.prototype.init.call(this);
2672 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2677 xtype: Gtk.CellRendererText,
2678 pack : "pack_start,true"
2702 xtype: Gtk.Notebook,
2703 pack : "pack_start,true,true",
2704 id : "view-help-nb",
2706 XObject.prototype.init.call(this);
2707 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2708 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2712 xtype: Gtk.Notebook,
2714 id : "view-notebook",
2717 XObject.prototype.init.call(this);
2718 this.el.set_current_page(0);
2720 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2721 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2728 id : "RightBrowser",
2734 xtype: Gtk.ScrolledWindow,
2736 shadow_type : Gtk.ShadowType.IN,
2738 XObject.prototype.init.call(this);
2739 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2743 xtype: WebKit.WebView,
2747 XObject.prototype.init.call(this);
2748 // this may not work!?
2749 this.el.open('file:///' + __script_path__ + '/../builder.html');
2753 this.el, /* widget that will accept a drop */
2754 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2755 null, /* lists of target to support */
2756 0, /* size of list */
2757 Gdk.DragAction.COPY /* what to do with data after dropped */
2760 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2761 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2763 renderJS : function(data) {
2764 print("HTML RENDERING");
2765 /// prevent looping..
2766 //if (this.pendingRedraw) {
2767 // print("pending redraw active?!");
2772 if (!this.get('/Window.LeftTree').getActiveFile()) {
2776 var project = this.get('/Window.LeftTree').getActiveFile().project;
2777 //print (project.fn);
2779 project.runhtml = project.runhtml || '';
2782 this.runhtml = this.runhtml || '';
2784 if (project.runhtml != this.runhtml) {
2785 // then we need to reload the browser using
2786 // load_html_string..
2788 // then trigger a redraw once it's loaded..
2789 this.pendingRedraw = true;
2791 this.runhtml = project.runhtml;
2793 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2794 html = html.replace('</head>', this.runhtml + '</head>');
2795 print("LOAD HTML " + html);
2796 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2797 // should trigger load_finished!
2802 this.pendingRedraw = false;
2805 this.renderedData = data;
2806 var str = JSON.stringify(data) ;
2809 console.log('not loaded yet');
2811 //Seed.print("RENDER:" + str);
2812 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2814 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2817 load_finished : function (self, object) {
2818 // if (this.ready) { // dont do it twice!
2822 this.pendingRedraw = false;
2823 var js = this.get('/LeftTree.model').toJS();
2825 this.renderJS(js[0]);
2829 script_alert : function (self, object, p0) {
2832 return true; // do not display anything...
2834 console_message : function (self, object, p0, p1) {
2835 // console.log(object);
2836 if (!object.match(/^\{/)) {
2838 this.get('/Terminal').feed(object);
2839 return true; // do not handle!!! -> later maybe in console..
2841 // console.log(object);
2842 var val = JSON.parse(object);
2844 if (typeof(val['hover-node']) != 'undefined') {
2845 this.activeNode = val['hover-node'];
2846 console.log('active node: ' + this.activeNode);
2851 if (typeof(val['id']) != 'undefined') {
2852 // this.activeNode = val['id'];
2853 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2857 this.get('/LeftTree.view').selectNode(tg[0]);
2861 if (ret && typeof(val['set']) != 'undefined') {
2862 this.get('/LeftPanel.model').add({
2866 //console.log('active node: ' + this.activeNode);
2869 //Seed.print('a:'+a);
2870 //Seed.print('b:'+b);
2871 //Seed.print('c:'+c);
2874 drag_motion : function (w, ctx, x, y, time, ud) {
2875 // console.log('DRAG MOTION');
2877 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2878 this.targetData = [];
2879 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2881 // A) find out from drag all the places that node could be dropped.
2882 var src = Gtk.drag_get_source_widget(ctx);
2883 if (!src.dropList) {
2884 Gdk.drag_status(ctx, 0, time);
2887 // b) get what we are over.. (from activeNode)
2888 // tree is empty.. - list should be correct..
2889 if (!this.get('/LeftTree.model').currentTree) {
2890 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2894 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2896 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2899 Gdk.drag_status(ctx, 0,time);
2900 this.get('/LeftTree.view').highlight(false);
2904 // if we have a target..
2905 // -> highlight it! (in browser)
2906 // -> highlight it! (in tree)
2908 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2909 this.get('/LeftTree.view').highlight(tg);
2910 this.targetData = tg;
2911 // for tree we should handle this...
2914 drag_drop : function (w, ctx, x, y,time, ud) {
2915 print("TARGET: drag-drop");
2916 var is_valid_drop_site = true;
2921 w, /* will receive 'drag-data-received' signal */
2922 ctx, /* represents the current state of the DnD */
2923 this.get('/Window').atoms["STRING"], /* the target type we want */
2924 time /* time stamp */
2928 /* No target offered by source => error */
2931 return is_valid_drop_site;
2933 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2935 print("Browser: drag-data-received");
2936 var delete_selection_data = false;
2937 vardnd_success = false;
2938 /* Deal with what we are given from source */
2939 if( sel_data && sel_data.length ) {
2941 if (ctx.action == Gdk.DragAction.ASK) {
2942 /* Ask the user to move or copy, then set the ctx action. */
2945 if (ctx.action == Gdk.DragAction.MOVE) {
2946 delete_selection_data = true;
2948 var source = Gtk.drag_get_source_widget(ctx);
2950 print("Browser: source.DRAGDATA? " + source.dragData);
2951 if (this.targetData) {
2952 print(this.targetData);
2953 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2962 if (dnd_success == false)
2964 Seed.print ("DnD data transfer failed!\n");
2967 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2978 id : "RightGtkView",
2980 redraw : function() {
2981 this.highlightWidget = false;
2982 print("REDRAW CALLED");
2983 this.activePath = this.get('/LeftTree').getActivePath();
2984 if (this.renderedEl) {
2985 print("QUEUE DRAW CALLING");
2986 this.renderedEl.queue_draw();
2989 renderJS : function(data, withDebug)
2991 this.highlightWidget = false;
2993 this.withDebug = false;
2995 if (this.renderedEl) {
2996 this.get('view').el.remove(this.renderedEl);
2997 this.renderedEl.destroy();
2998 this.renderedEl = false;
3003 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3004 // in theory tree is actually window..
3006 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3011 this.get('view').el.set_size_request(
3012 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3015 this.renderedEl.set_size_request(
3016 tree.default_width || 600,
3017 tree.default_height || 400
3019 this.get('view').el.show_all();
3024 showInWindow : function() {
3025 print("GET PROEJCT");
3026 var pr = this.get('/LeftProjectTree').getActiveProject();
3028 console.log(pr.paths);
3031 var src= this.buildJS(
3032 this.get('/LeftTree.model').toJS()[0],
3037 //var x = new imports.sandbox.Context();
3041 Seed.check_syntax('var e = ' + src);
3044 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3045 this.get('/Terminal').feed(console._dump(e)+"\n");
3047 var lines = src.split("\n");
3048 var start = Math.max(0, e.line - 10);
3049 var end = Math.min(lines.length, e.line + 10);
3050 for (var i =start ; i < end; i++) {
3052 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3055 this.get('/Terminal').feed(lines[i] + "\n");
3062 this.get('/BottomPane').el.set_current_page(1);
3063 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3064 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3065 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3067 var _top = x.get_global_object()._top;
3069 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3071 if (_top.el.popup) {
3072 _top.el.popup(null, null, null, null, 3, null);
3076 viewAdd : function(item, par)
3078 // does something similar to xobject..
3079 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3081 if (item.pack===false || item.pack === 'false') { // no ;
3084 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3085 var type = item['|xns'] + '.' + item['xtype'];
3086 var ns = imports.gi[item['|xns']];
3087 var ctr = ns[item['xtype']];
3089 for(var k in item) {
3091 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3106 if (k[0] == '|' && typeof(kv) == 'string') {
3108 if (kv.match(new RegExp('function'))) {
3111 print("WASL " + k + '=' + kv);
3113 eval( 'kv = ' + kv);
3114 } catch(e) { continue; }
3117 // print(k + '=' + kv);
3119 if (k[0] == '|') { // should be boolean or number..
3121 //print(k + '=' + kv);
3124 if (k == 'show_tabs') { // force tab showing for notebooks.
3127 print(k + '=' + typeof(kv) + " : " + kv);
3133 var el = new ctr(ctr_args);
3135 print("PACK" + item.pack);
3136 //console.dump(item.pack);
3143 if (typeof(item.pack) == 'string') {
3145 item.pack.split(',').forEach(function(e, i) {
3147 if (e == 'false') { args.push( false); return; }
3148 if (e == 'true') { args.push( true); return; }
3149 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3152 //print(args.join(","));
3154 pack_m = args.shift();
3156 pack_m = item.pack.shift();
3161 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3163 name: "ArgumentError",
3164 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3165 "ADDING : " + item.id + " " + el
3174 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3175 //Seed.print('args: ' + args.length);
3177 par[pack_m].apply(par, args);
3181 item.items = item.items || [];
3182 item.items.forEach(function(ch,n) {
3184 print ("type:" + type);
3186 print ("ch.pack:" + ch.pack);
3187 if (type == 'Gtk.Table' && ch.pack == 'add') {
3188 var c = n % item.n_columns;
3189 var r = Math.floor(n/item.n_columns);
3190 ch.pack = [ 'attach', c, c+1, r, r+1,
3191 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3192 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3193 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3194 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3198 _this.viewAdd(ch, el);
3203 // add the signal handlers.
3204 // is it a widget!?!!?
3210 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3211 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3212 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3213 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3214 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3224 widgetDragDropEvent : function() {
3225 print("WIDGET DRAGDROP");
3228 widgetDragMotionEvent : function() {
3229 print("WIDGET DRAGMOTION");
3232 widgetExposeEvent : function(w, evt, ud, item) {
3234 if (this.inRender) {
3238 if ( this.highlightWidget) {
3239 this.inRender = true;
3240 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3241 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3243 this.inRender = false;
3248 if (this.activePath != item.xtreepath) {
3252 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3253 // work out the coords of the window..
3255 var dr = widget.window;
3256 this.gc = (new Gdk.GC.c_new(dr));
3257 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3258 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3262 var r = evt.expose.area;
3263 // console.dump([r.x, r.y, r.width, r.height ] );
3265 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3266 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3267 // happens with gtkscrollview embedded stuff..
3268 var np =this.activePath.split(':');
3270 this.activePath = np.join(':');
3271 this.renderedEl.queue_draw();
3287 this.inRender = true;
3290 this.highlightWidget = widget;
3295 // print("DRAW BOX");
3296 //console.dump(this.box);
3297 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3298 this.inRender = false;
3301 widgetPressEvent : function(w,e,u,d) {
3302 if (this.get('view').pressed) {
3305 this.get('view').pressed = true;
3306 print("WIDGET PRESS " + d.xtreepath );
3307 this.get('/LeftTree.view').selectNode( d.xtreepath );
3310 widgetReleaseEvent : function() {
3311 this.get('view').pressed = false;
3317 pack : "pack_start,false,true,0",
3321 pack : "pack_start,false,false,0",
3322 label : "Run The Application",
3324 button_press_event : function (self, event) {
3325 // call render on left tree - with special option!?!
3327 //print("GET PROEJCT");
3328 var pr = this.get('/LeftProjectTree').getActiveProject();
3331 for (var i in pr.paths) {
3335 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3336 this.get('/Terminal').feed("RUN DIR:" + dir);
3338 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3339 , false,false,false);
3340 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3341 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3351 xtype: Gtk.ScrolledWindow,
3354 shadow_type : Gtk.ShadowType.IN,
3356 XObject.prototype.init.call(this);
3357 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3361 xtype: Gtk.EventBox,
3362 pack : "add_with_viewport",
3364 XObject.prototype.init.call(this);
3365 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3366 red: 0x9F00, green: 0xB800 , blue : 0xA800
3374 XObject.prototype.init.call(this);
3375 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3376 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3381 xtype: Gtk.EventBox,
3384 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3385 XObject.prototype.init.call(this);
3389 this.el, /* widget that will accept a drop */
3390 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3391 null, /* lists of target to support */
3392 0, /* size of list */
3393 Gdk.DragAction.COPY /* what to do with data after dropped */
3396 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3397 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3400 getActiveNode : function(x,y)
3402 // workout what node is here..
3403 return '0'; // top..
3407 drag_motion : function (self, ctx, x, y, time) {
3409 // A) find out from drag all the places that node could be dropped.
3410 var src = Gtk.drag_get_source_widget(ctx);
3411 if (!src.dropList) {
3412 Gdk.drag_status(ctx, 0, time);
3415 // b) get what we are over.. (from activeNode)
3416 // tree is empty.. - list should be correct..
3417 if (!this.get('/LeftTree.model').currentTree) {
3418 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3422 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3423 var activeNode = this.getActiveNode(x, y);
3426 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3429 Gdk.drag_status(ctx, 0,time);
3430 this.get('/LeftTree.view').highlight(false);
3434 // if we have a target..
3435 // -> highlight it! (in browser)
3436 // -> highlight it! (in tree)
3438 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3439 this.get('/LeftTree.view').highlight(tg);
3440 this.targetData = tg;
3441 // for tree we should handle this...
3444 drag_drop : function (self,ctx, x, y, time) {
3445 Seed.print("TARGET: drag-drop");
3446 var is_valid_drop_site = true;
3451 self, /* will receive 'drag-data-received' signal */
3452 ctx, /* represents the current state of the this.gDnD */
3453 this.get('/Window').atoms["STRING"], /* the target type we want */
3454 time /* time stamp */
3458 /* No target offered by source => error */
3461 return is_valid_drop_site;
3464 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3466 Seed.print("GtkView: drag-data-received");
3467 var delete_selection_data = false;
3468 var dnd_success = false;
3469 /* Deal with what we are given from source */
3470 if( sel_data && sel_data.length ) {
3472 if (ctx.action == Gdk.DragAction.ASK) {
3473 /* Ask the user to move or copy, then set the ctx action. */
3476 if (ctx.action == Gdk.DragAction.MOVE) {
3477 delete_selection_data = true;
3479 var source = Gtk.drag_get_source_widget(ctx);
3481 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3482 if (this.targetData) {
3483 Seed.print(this.targetData);
3484 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3493 if (dnd_success == false)
3495 Seed.print ("DnD data transfer failed!\n");
3498 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3501 button_press_event : function (self, event) {
3502 this.pressed = false;
3518 xtype: Gtk.ScrolledWindow,
3523 var file = this.get('/LeftTree').getActiveFile();
3527 var activeEl = this.get('/LeftTree').getActiveElement();
3528 var xtype = file.guessName( activeEl )
3529 if (!xtype || !xtype.length) {
3532 this.get('/Window.view-help-nb').el.set_current_page(1);
3534 // get the active element being edited.
3535 var helpurl = file.getHelpUrl(xtype);
3537 // now load the help info in the page..
3538 this.get('help-view').el.open(helpurl);
3542 xtype: WebKit.WebView,
3546 XObject.prototype.init.call(this);
3547 this.get('/Window.help-view').el.open(
3548 "http://devel.akbkhome.com/seed/");
3560 xtype: Gtk.Notebook,
3563 XObject.prototype.init.call(this);
3564 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3565 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3570 xtype: Gtk.ScrolledWindow,
3575 xtype: GtkSource.View,
3579 XObject.prototype.init.call(this);
3580 var description = Pango.Font.description_from_string("monospace")
3581 description.set_size(8000);
3582 this.el.modify_font(description);
3585 load : function(str) {
3587 // show the help page for the active node..
3588 this.get('/Help').show();
3591 this.get('/BottomPane').el.set_current_page(0);
3592 this.el.get_buffer().set_text(str, str.length);
3593 var lm = GtkSource.LanguageManager.get_default();
3595 this.el.get_buffer().set_language(lm.get_language('js'));
3596 var buf = this.el.get_buffer();
3597 var cursor = buf.get_mark("insert");
3598 var iter= new Gtk.TextIter;
3599 buf.get_iter_at_mark(iter, cursor);
3601 iter.set_line_offset(4);
3602 buf.move_mark(cursor, iter);
3605 cursor = buf.get_mark("selection_bound");
3606 iter= new Gtk.TextIter;
3607 buf.get_iter_at_mark(iter, cursor);
3609 iter.set_line_offset(4);
3610 buf.move_mark(cursor, iter);
3612 this.el.grab_focus();
3614 insert_spaces_instead_of_tabs : true,
3617 show_line_numbers : true,
3620 xtype: GtkSource.Buffer,
3621 pack : "set_buffer",
3623 changed : function (self) {
3624 var s = new Gtk.TextIter();
3625 var e = new Gtk.TextIter();
3626 this.el.get_start_iter(s);
3627 this.el.get_end_iter(e);
3628 var str = this.el.get_text(s,e,true);
3630 Seed.check_syntax('var e = ' + str);
3632 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3633 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3635 print("SYNTAX ERROR IN EDITOR");
3640 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3641 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3644 this.get('/LeftPanel.model').changed( str , false);
3653 xtype: Gtk.ScrolledWindow,
3657 xtype: Vte.Terminal,
3660 feed : function(istr) {
3661 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3662 // we should make ourselves visable!!!
3663 this.get('/BottomPane').el.show();
3664 this.get('/BottomPane').el.set_current_page(1);
3666 this.el.feed(str ,str.length);
3668 scroll_on_output : true,
3670 XObject.prototype.init.call(this);
3671 this.el.set_size (80, 1000);
3673 scrollback_lines : 1000
3683 pack : "pack_start,false,false",
3687 this.get('buttonbar').el.show();
3688 this.get('viewbox').el.hide();
3689 print("TRIED TO HIDE");
3692 this.get('buttonbar').el.hide();
3693 this.get('viewbox').el.show();
3694 // this.get('model').expanded();
3706 pack : "pack_start,false,true",
3708 clicked : function (self) {
3709 this.get('/RightPalete').show();
3716 stock : Gtk.STOCK_GOTO_FIRST,
3717 icon_size : Gtk.IconSize.MENU
3727 XObject.prototype.init.call(this);
3728 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3731 enter_notify_event : function (self, event) {
3732 this.get('/RightPalete').show();
3746 pack : "pack_start,false,true",
3755 pack : "pack_start,false,true",
3757 clicked : function (self) {
3758 this.get('/RightPalete').hide();
3765 stock : Gtk.STOCK_GOTO_LAST,
3766 icon_size : Gtk.IconSize.MENU
3773 xtype: Gtk.ScrolledWindow,
3776 XObject.prototype.init.call(this);
3777 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3778 this.el.set_size_request(-1,200);
3780 shadow_type : Gtk.ShadowType.IN,
3783 xtype: Gtk.TreeView,
3786 XObject.prototype.init.call(this);
3787 this.el.set_size_request(150,-1);
3788 // set_reorderable: [1]
3790 var description = new Pango.FontDescription.c_new();
3791 description.set_size(8000);
3792 this.el.modify_font(description);
3794 this.selection = this.el.get_selection();
3795 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3796 // this.selection.signal['changed'].connect(function() {
3797 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3799 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3801 Gtk.drag_source_set (
3802 this.el, /* widget will be drag-able */
3803 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3804 null, /* lists of target to support */
3805 0, /* size of list */
3806 Gdk.DragAction.COPY /* what to do with data after dropped */
3808 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3810 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3811 Gtk.drag_source_add_text_targets(this.el);
3813 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3814 targets = new Gtk.TargetList();
3815 targets.add( LeftTree.atoms["STRING"], 0, 0);
3816 targets.add_text_targets( 1 );
3817 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3819 //if you want to allow text to be output elsewhere..
3820 //Gtk.drag_source_add_text_targets(this.el);
3824 headers_visible : false,
3825 enable_tree_lines : true,
3827 drag_begin : function (self, ctx) {
3828 // we could fill this in now...
3829 Seed.print('SOURCE: drag-begin');
3833 var iter = new Gtk.TreeIter();
3834 var s = this.selection;
3835 s.get_selected(this.get('/RightPalete.model').el, iter);
3836 var path = this.get('/RightPalete.model').el.get_path(iter);
3838 var pix = this.el.create_row_drag_icon ( path);
3841 Gtk.drag_set_icon_pixmap (ctx,
3848 var value = new GObject.Value('');
3849 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3850 if (!this.get('/RightPalete').provider) {
3853 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3854 this.el.dragData = value.value;
3861 drag_data_get : function (self, drag_context, selection_data, info, time) {
3862 //Seed.print('Palete: drag-data-get: ' + target_type);
3863 if (this.el.dragData && this.el.dragData.length ) {
3864 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3868 //this.el.dragData = "TEST from source widget";
3872 drag_end : function (self, drag_context) {
3873 Seed.print('SOURCE: drag-end');
3874 this.el.dragData = false;
3875 this.el.dropList = false;
3876 this.get('/LeftTree.view').highlight(false);
3882 xtype: Gtk.ListStore,
3885 XObject.prototype.init.call(this);
3886 this.el.set_column_types ( 2, [
3887 GObject.TYPE_STRING, // title
3888 GObject.TYPE_STRING // tip
3893 load : function(tr,iter)
3898 //console.log('Project tree load: ' + tr.length);
3899 var citer = new Gtk.TreeIter();
3900 //this.insert(citer,iter,0);
3901 for(var i =0 ; i < tr.length; i++) {
3904 this.el.append(citer);
3906 this.el.insert(citer,iter,-1);
3911 this.el.set_value(citer, 0, '' + r ); // title
3913 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3914 //if (r.cn && r.cn.length) {
3915 // this.load(r.cn, citer);
3921 getValue : function (iter, col) {
3922 var gval = new GObject.Value('');
3923 this.el.get_value(iter, col ,gval);
3930 xtype: Gtk.TreeViewColumn,
3931 pack : "append_column",
3933 XObject.prototype.init.call(this);
3934 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3938 xtype: Gtk.CellRendererText,
3960 XObject.cache['/Window'] = Window;