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();
351 activate : function (self) {
352 var nb = this.get('/LeftTopPanel.notebook');
353 if (this.el.expanded) {
356 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
359 var model = this.get('/LeftProjectTree.combomodel');
360 // print ("loading Projects?")
361 //console.dump(pm.projects);
362 model.loadData(pm.projects);
365 nb.el.set_current_page(1);
366 //pm.on('changed', function() {
367 //console.log("CAUGHT project manager change");
368 // _combo.model.loadData(pm.projects);
372 nb.el.set_current_page(0);
374 enter_notify_event : function (self, event) {
375 this.el.expanded = !this.el.expanded;
376 //if (this.el.expanded ) {
377 this.listeners.activate.call(this);
384 label : "Select Project or File",
385 pack : "pack_start,false,true",
387 XObject.prototype.init.call(this);
388 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
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) {
851 // console.dump(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];
899 node = this.get('/DialogTemplateSelect').show(node);
902 // work out what kind of packing to use..
903 if (typeof(node.pack) == 'undefined' && parent !== false) {
904 var pal = this.get('/LeftTree').getPaleteProvider();
905 if (pal.name == 'Gtk') {
906 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
907 var cname = pal.guessName(node);
908 node.pack = pal.getDefaultPack(pname, cname);
919 // load children - if it has any..
922 this.load(xitems, n_iter);
924 if (tp && (xitems || after)) {
925 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
927 // wee need to get the empty proptypes from somewhere..
929 //var olditer = this.activeIter;
930 this.activePath = this.el.get_path(n_iter).to_string();
932 // changed actually set's the node data..
933 this.changed(node, true);
937 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
939 //Builder.MidPropTree._model.load(node);
940 //Builder.MidPropTree._win.hideWin();
941 //Builder.LeftPanel._model.load( node);
945 findDropNode : function(treepath_str, targets) {
947 // this is used by the dragdrop code in the roo version AFAIR..
949 var path = treepath_str.replace(/^builder-/, '');
950 // treemap is depreciated... - should really check if model has any entries..
952 if (!this.el.iter_n_children(null)) {
954 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
956 print("FIND treepath: " + path);
957 //console.dump(this.treemap);
959 if (!treepath_str.match(/^builder-/)) {
960 return []; // nothing!
962 if (targets === true) {
965 return this.findDropNodeByPath(path,targets)
967 findDropNodeByPath : function(treepath_str, targets, pref) {
968 var path = treepath_str + ''; // dupe it..
969 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
971 //console.dump(this.treemap);
972 while (path.length) {
973 print("LOOKING FOR PATH: " + path);
974 var node_data = this.singleNodeToJS(path);
975 if (node_data === false) {
976 print("node not found");
980 var xname = this.get('/LeftTree.model').file.guessName(node_data);
983 targets.forEach(function(tg) {
987 if ((tg == xname) ) {
990 if (tg.indexOf(xname +':') === 0) {
992 prop = tg.split(':').pop();
997 if (last) { // pref is after/before..
998 // then it's after last
1000 return []; // do not allow..
1002 return [ last, pref , prop];
1005 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1007 var par = path.split(':');
1010 path = par.join(':');
1016 getIterValue : function (iter, col) {
1017 var gval = new GObject.Value('');
1018 this.el.get_value(iter, col ,gval);
1024 XObject.prototype.init.call(this);
1025 this.el.set_column_types ( 3, [
1026 GObject.TYPE_STRING, // title
1027 GObject.TYPE_STRING, // tip
1028 GObject.TYPE_STRING // source..
1031 listAllTypes : function() {
1032 var s = this.get('/LeftTree.view').selection;
1033 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1035 if (s.count_selected_rows() > 0) {
1036 var iter = new Gtk.TreeIter();
1037 s.get_selected(this.el, iter);
1039 // set some properties of the tree for use by the dropped element.
1040 var value = new GObject.Value('');
1041 this.el.get_value(iter, 2, value);
1042 var data = JSON.parse(value.value);
1045 var xname = this.get('/LeftTree.model').file.guessName(data);
1046 console.log('selected:' + xname);
1050 return []; // could not find it..
1058 li.forEach(function(el) {
1059 // this is specific to roo!!!?
1061 var fullpath = _this.file.guessName(el);
1062 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1067 if (el.items && el.items.length) {
1076 addall([this.currentTree]);
1078 // only if we have nothing, should we add '*top'
1082 //console.log('all types in tree');
1083 //console.dump(ret);
1088 load : function(tr,iter)
1090 var citer = new Gtk.TreeIter();
1091 //this.insert(citer,iter,0);
1092 for(var i =0 ; i < tr.length; i++) {
1094 this.el.insert(citer,iter,-1);
1096 this.el.append(citer);
1099 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1100 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1101 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1102 if (tr[i].items && tr[i].items.length) {
1103 this.load(tr[i].items, citer);
1107 loadFile : function(f) {
1113 console.log('missing file');
1117 // load the file if not loaded..
1118 if (f.items === false) {
1120 f.loadItems(function() {
1126 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1128 if (f.items.length && typeof(f.items[0]) == 'string') {
1130 this.get('/RightEditor').el.show();
1131 this.get('/RightEditor.view').load( f.items[0]);
1135 //console.dump(f.items);
1137 this.get('/LeftTree.view').el.expand_all();
1139 if (!f.items.length) {
1142 this.get('/Window.leftvpaned').el.set_position(80);
1144 this.get('/LeftTree.view').el.set_cursor(
1145 new Gtk.TreePath.from_string('0'), null, false);
1149 this.get('/Window.leftvpaned').el.set_position(200);
1153 //print("hide right editior");
1154 this.get('/RightEditor').el.hide();
1155 //print("set current tree");
1156 this.currentTree = this.toJS(false, false)[0];
1157 //console.dump(this.currentTree);
1158 this.currentTree = this.currentTree || { items: [] };
1159 this.get('/LeftTree').renderView();
1160 //console.dump(this.map);
1161 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1162 var pm = this.get('/RightPalete.model');
1163 // set up provider..
1165 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1167 if (!this.get('/RightPalete').provider) {
1168 print ("********* PALETE PROVIDER MISSING?!!");
1170 this.get('/LeftTree').renderView();
1172 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1176 this.get('/Window.view-notebook').el.set_current_page(
1177 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1180 moveNode : function(target_data, action) {
1181 //print("MOVE NODE");
1182 // console.dump(target_data);
1183 var old_iter = new Gtk.TreeIter();
1184 var s = this.get('/LeftTree.view').selection;
1185 s.get_selected(this.el, old_iter);
1186 var node = this.nodeToJS(old_iter,false);
1187 //console.dump(node);
1190 // needs to drop first, otherwise the target_data
1191 // treepath will be invalid.
1193 this.dropNode(target_data, node);
1194 if (action & Gdk.DragAction.MOVE) {
1195 // print("REMOVING OLD NODE");
1196 this.el.remove(old_iter);
1200 this.activePath= false;
1201 this.changed(false,true);
1203 nodeTip : function(c) {
1204 var ret = this.nodeTitle(c,true);
1210 if (!i.length || i[0] != '|') {
1216 if (typeof(c[i]) != 'string') {
1219 //print("prop : " + i + ':' + c[i]);
1220 if (!c[i].match(new RegExp('function'))) {
1223 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1227 ret+="\n\nMethods:" + funcs;
1232 nodeTitle : function(c, renderfull) {
1235 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1236 if (sr) txt.push('<s>');
1237 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1239 if (renderfull && c['|xns']) {
1240 txt.push(c['|xns']);
1243 if (c.xtype) { txt.push(c.xtype); }
1244 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1245 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1246 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1249 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1250 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1251 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1252 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1253 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1254 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1255 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1256 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1257 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1259 // for flat classes...
1260 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1261 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1264 if (sr) txt.push('</s>');
1265 return (txt.length == 0 ? "Element" : txt.join(" "));
1267 nodeToJS : function (treepath, with_id)
1270 var iter = treepath; // API used to be iter here..
1271 if (typeof(iter) == 'string') {
1272 iter = new Gtk.TreeIter();
1273 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1277 var par = new Gtk.TreeIter();
1278 var iv = this.getIterValue(iter, 2);
1279 // print("IV" + iv);
1280 var k = JSON.parse(iv);
1281 if (k.json && !this.el.iter_parent( par, iter )) {
1286 var treepath_str = this.el.get_path(iter).to_string();
1287 // not sure how we can handle mixed id stuff..
1288 if (typeof(k.id) == 'undefined') {
1289 k.id = 'builder-'+ treepath_str ;
1293 this.treemap[ treepath_str ] = k;
1294 k.xtreepath = treepath_str ;
1297 if (this.el.iter_has_child(iter)) {
1298 citer = new Gtk.TreeIter();
1299 this.el.iter_children(citer, iter);
1300 k.items = this.toJS(citer,with_id);
1304 nodeToJSON : function(c) {
1312 return JSON.stringify(o);
1314 singleNodeToJS : function (treepath)
1316 var iter = new Gtk.TreeIter();
1317 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1321 var iv = this.getIterValue(iter, 2);
1323 return JSON.parse(iv);
1326 toJS : function(treepath, with_id)
1328 //Seed.print("WITHID: "+ with_id);
1329 var iter = treepath; // API used to be iter here..
1330 if (typeof(iter) == 'string') {
1331 iter = new Gtk.TreeIter();
1332 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1341 iter = new Gtk.TreeIter();
1342 if (!this.el.get_iter_first(iter)) {
1352 var k = this.nodeToJS(iter, with_id);
1356 if (!this.el.iter_next(iter)) {
1362 // convert the list into a json string..
1368 xtype: Gtk.TreeViewColumn,
1369 pack : "append_column",
1371 XObject.prototype.init.call(this);
1372 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1376 xtype: Gtk.CellRendererText,
1386 id : "LeftTreeMenu",
1389 xtype: Gtk.MenuItem,
1391 label : "Delete Element",
1393 activate : function (self) {
1395 this.get('/LeftTree.model').deleteSelected();
1400 xtype: Gtk.MenuItem,
1402 activate : function (self) {
1404 var tree = this.get('/LeftTree');
1405 var model = this.get('/LeftTree.model');
1406 var el = tree.getActivePath();
1408 var js = model.toJS(el, false);
1409 // print(JSON.stringify(js[0], null,4));
1410 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1415 label : "Save as Template",
1425 id : "LeftProjectTree",
1426 showNoProjectSelected : function() {
1427 this.get('/StandardErrorDialog').show("Select a Project first.");
1429 getActiveProject : function() {
1430 return this.project;
1433 leave_notify_event : function (self, event) {
1440 pack : "pack_start,false,false",
1443 xtype: Gtk.ComboBox,
1446 XObject.prototype.init.call(this);
1447 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1449 getValue : function() {
1450 var ix = this.el.get_active();
1454 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1455 if (typeof(data[ix]) == 'undefined') {
1460 setValue : function(fn)
1464 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1465 data.forEach(function(n, ix) {
1473 changed : function (self) {
1474 var fn = this.getValue();
1475 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1476 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1481 xtype: Gtk.CellRendererText,
1482 pack : "pack_start,true",
1486 xtype: Gtk.ListStore,
1489 XObject.prototype.init.call(this);
1490 this.el.set_column_types ( 2, [
1491 GObject.TYPE_STRING, // real key
1492 GObject.TYPE_STRING // real type
1496 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1498 pm.on('changed', function() {
1499 print("caught changed hook on project manager - reloading data");
1500 _this.loadData(pm.projects);
1504 loadData : function(data) {
1505 var ov = this.get('/LeftProjectTree.combo').getValue();
1507 var iter = new Gtk.TreeIter();
1509 data.forEach(function(p) {
1514 el.set_value(iter, 0, p.fn);
1515 el.set_value(iter, 1, p.name);
1519 this.get('/LeftProjectTree.combo').setValue(ov);
1528 xtype: Gtk.ScrolledWindow,
1530 shadow_type : Gtk.ShadowType.IN,
1532 XObject.prototype.init.call(this);
1533 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1537 xtype: Gtk.TreeView,
1538 headers_visible : false,
1539 enable_tree_lines : true,
1542 XObject.prototype.init.call(this);
1543 var description = new Pango.FontDescription.c_new();
1544 description.set_size(8000);
1545 this.el.modify_font(description);
1547 this.selection = this.el.get_selection();
1548 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1552 cursor_changed : function (self) {
1553 var iter = new Gtk.TreeIter();
1555 if (this.selection.count_selected_rows() < 1) {
1556 //XN.get('Builder.LeftTree.model').
1557 this.get('/LeftTree.model').load( false);
1561 var model = this.get('/LeftProjectTree.model');
1562 //console.log('changed');
1563 var s = this.selection;
1564 s.get_selected(model, iter);
1565 value = new GObject.Value('');
1566 model.el.get_value(iter, 2, value);
1568 console.log(value.value);// id..
1570 var file = this.get('/LeftProjectTree').project.getById(value.value);
1577 var nb = this.get('/LeftTopPanel.expander');
1578 nb.el.expanded = false;
1579 nb.listeners.activate.call(nb);
1580 //_expander.el.set_expanded(false);
1582 var ltm = this.get('/LeftTree.model');
1590 xtype: Gtk.TreeStore,
1594 XObject.prototype.init.call(this);
1595 this.el.set_column_types ( 3, [
1596 GObject.TYPE_STRING, // title
1597 GObject.TYPE_STRING, // tip
1598 GObject.TYPE_STRING // id..
1602 loadProject : function(pr) {
1603 print("LOAD PROJECT");
1609 this.get('/LeftProjectTree').project = pr;
1610 this.load(pr.toTree());
1611 this.get('/LeftProjectTree.view').el.expand_all();
1613 load : function(tr,iter) {
1614 // console.dump(tr);
1615 console.log('Project tree load: ' + tr.length);
1616 var citer = new Gtk.TreeIter();
1617 //this.insert(citer,iter,0);
1620 tr.forEach(function (r) {
1622 _this.el.append(citer);
1624 _this.el.insert(citer,iter,-1);
1626 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1627 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1628 _this.el.set_value(citer, 2, '' + r.id ); //id
1629 if (r.cn && r.cn.length) {
1630 _this.load(r.cn, citer);
1635 getValue : function(iter, col) {
1636 var gval = new GObject.Value('');
1637 this.el.get_value(iter, col ,gval);
1638 return '' + gval.value;
1642 xtype: Gtk.TreeViewColumn,
1643 pack : "append_column",
1645 XObject.prototype.init.call(this);
1646 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1650 xtype: Gtk.CellRendererText,
1673 pack : "pack_start,false,true,0",
1680 button_press_event : function (self, event) {
1681 this.get('/MidPropTree.model').showData('props');
1693 stock : Gtk.STOCK_ADD,
1694 icon_size : Gtk.IconSize.MENU
1709 button_press_event : function (self, event) {
1710 this.get('/MidPropTree.model').showData('events');
1722 stock : Gtk.STOCK_ADD,
1723 icon_size : Gtk.IconSize.MENU
1738 button_press_event : function (self, ev) {
1739 var p = this.get('/AddPropertyPopup');
1743 p.el.set_screen(Gdk.Screen.get_default());
1745 p.el.popup(null, null, null, null, 3, ev.button.time);
1757 stock : Gtk.STOCK_ADD,
1758 icon_size : Gtk.IconSize.MENU
1770 id : "AddPropertyPopup",
1773 xtype: Gtk.MenuItem,
1775 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1778 activate : function (self) {
1780 this.get('/LeftPanel.model').add( {
1791 xtype: Gtk.MenuItem,
1793 tooltip_markup : "Add what type of packing is to be used",
1796 activate : function (self) {
1798 this.get('/LeftPanel.model').add( {
1808 xtype: Gtk.MenuItem,
1810 tooltip_markup : "Override the init method",
1813 activate : function (self) {
1815 this.get('/LeftPanel.model').add( {
1818 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1825 xtype: Gtk.SeparatorMenuItem,
1829 xtype: Gtk.MenuItem,
1831 tooltip_markup : "Add a user defined string property",
1834 activate : function (self) {
1836 this.get('/LeftPanel.model').add( {
1846 xtype: Gtk.MenuItem,
1848 tooltip_markup : "Add a user defined number property",
1851 activate : function (self) {
1853 this.get('/LeftPanel.model').add( {
1863 xtype: Gtk.MenuItem,
1865 tooltip_markup : "Add a user defined boolean property",
1868 activate : function (self) {
1870 this.get('/LeftPanel.model').add( {
1880 xtype: Gtk.SeparatorMenuItem,
1884 xtype: Gtk.MenuItem,
1886 tooltip_markup : "Add a user function boolean property",
1889 activate : function (self) {
1891 this.get('/LeftPanel.model').add( {
1894 val : "function() {\n \n}\n",
1907 xtype: Gtk.ScrolledWindow,
1910 shadow_type : Gtk.ShadowType.IN,
1913 XObject.prototype.init.call(this);
1914 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1918 xtype: Gtk.TreeView,
1921 headers_visible : false,
1922 enable_tree_lines : true,
1924 XObject.prototype.init.call(this);
1926 this.selection = this.el.get_selection();
1927 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1930 var description = new Pango.FontDescription.c_new();
1931 description.set_size(8000);
1932 this.el.modify_font(description);
1935 button_press_event : function (self, ev) {
1939 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1940 return false; //not on a element.
1944 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1946 if (res.column.title != 'value') {
1947 return false; // ignore..
1949 if ( this.get('/LeftPanel').editing) {
1952 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1953 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1954 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1958 var provider = this.get('/LeftTree').getPaleteProvider();
1960 var opts = provider.findOptions(type);
1962 if (opts === false) {
1963 this.get('/LeftPanel').editableColumn.setOptions([]);
1964 renderer.has_entry = true;
1966 LeftPanel.editableColumn.setOptions(opts);
1967 renderer.has_entry = false;
1971 //Seed.print("click" + ev.type);
1972 //console.dump(res);
1978 if (res.column.title == 'value') {
1981 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1982 var p = this.get('/LeftPanelPopup');
1987 p.el.set_screen(Gdk.Screen.get_default());
1989 p.el.popup(null, null, null, null, 3, ev.button.time);
1990 //Seed.print("click:" + res.column.title);
1998 xtype: Gtk.TreeStore,
2002 getIterValue : function(iter, col) {
2003 var gval = new GObject.Value('');
2004 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2005 return '' + gval.value;
2007 add : function(info) {
2008 // info includes key, val, skel, etype..
2010 type = info.type.toLowerCase();
2011 var data = this.toJS();
2013 if (info.etype == 'events') {
2014 data.listeners = data.listeners || { };
2015 if (typeof(data.listeners[info.key]) != 'undefined') {
2016 return; //already set!
2019 if (typeof(data[info.key]) != 'undefined') {
2024 if (typeof(info.val) == 'undefined') {
2027 if (info.type == 'boolean') {
2030 if (type == 'number') {
2038 if (info.etype == 'events') {
2040 data.listeners[info.key] = info.val;
2043 data[info.key] = info.val;
2047 var map = this.load(data);
2049 // flag it as changed to the interface..
2051 this.get('/LeftTree.model').changed(data, true);
2054 this.startEditing(map[k]);
2057 LeftPanel.get('view').el.row_activated(
2058 new Gtk.TreePath.from_string(map[k]),
2059 LeftPanel.editableColumn.el
2063 changed : function(str, doRefresh) {
2064 if (!this.activePath) {
2067 var iter = new Gtk.TreeIter();
2068 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2070 this.el.set_value(iter, 1, '' +str);
2071 this.el.set_value(iter, 3, '' + this.toShort(str));
2072 var type = this.getIterValue(iter, 4);
2074 this.el.set_value(iter, 5, type + ' : ' + str);
2075 // update the tree...
2077 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2079 deleteSelected : function() {
2080 var data = this.toJS();
2081 var iter = new Gtk.TreeIter();
2082 var s = this.get('/LeftPanel.view').selection;
2083 s.get_selected(this.el, iter);
2086 var gval = new GObject.Value('');
2087 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2089 var val = gval.value;
2090 if (val[0] == '!') {
2092 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2095 delete data.listeners[ val.substring(1)];
2096 if (!XObject.keys(data.listeners).length) {
2097 delete data.listeners;
2101 if (typeof(data[val]) == 'undefined') {
2109 this.get('/LeftTree.model').changed(data, true);
2112 editSelected : function(e) {
2113 print("EDIT SELECTED?");
2114 var iter = new Gtk.TreeIter();
2115 var s = this.get('/LeftPanel.view').selection;
2116 s.get_selected(this.get('/LeftPanel.model').el, iter);
2117 var m = this.get('/LeftPanel.model')
2119 var gval = new GObject.Value('');
2120 this.el.get_value(iter, 0 ,gval);
2121 var val = '' + gval.value;
2123 gval = new GObject.Value('');
2124 this.el.get_value(iter, 1 ,gval);
2125 var rval = gval.value;
2126 var activePath = this.el.get_path(iter).to_string();
2127 this.activePath = activePath ;
2128 // was activeIter...
2131 var showEditor = false;
2133 if (val[0] == '!') {
2136 if (val[0] == '|') {
2137 if (rval.match(/function/g) || rval.match(/\n/g)) {
2144 this.activePath = false;
2145 GLib.timeout_add(0, 1, function() {
2146 // Gdk.threads_enter();
2147 _this.get('/BottomPane').el.show();
2148 _this.get('/RightEditor').el.show();
2149 _this.get('/RightEditor.view').load( rval );
2153 _this.activePath = activePath ;
2155 // Gdk.threads_leave();
2160 this.get('/BottomPane').el.hide();
2161 this.get('/RightEditor').el.hide();
2163 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2167 getType : function(treepath) {
2168 return this.getValue(treepath, 4);
2170 getValue : function(treepath_str, col) {
2171 var iter = new Gtk.TreeIter();
2172 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2174 var gval = new GObject.Value('');
2175 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2176 var val = '' + gval.value;
2180 var type = this.getType(this.el.get_path(iter).to_string());
2181 print("TYPE: " +type + " - val:" + val);
2182 switch(type.toLowerCase()) {
2186 return parseFloat(val); // Nan ?? invalid!!?
2189 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2191 return val == 'true' ? true : false;
2193 var nv = parseFloat(val);
2194 if (!isNaN(nv) && (val == ''+nv)) {
2202 XObject.prototype.init.call(this);
2203 this.el.set_column_types ( 6, [
2204 GObject.TYPE_STRING, // 0 real key
2205 GObject.TYPE_STRING, // 1 real value
2206 GObject.TYPE_STRING, // 2 visable key
2207 GObject.TYPE_STRING, // 3 visable value
2208 GObject.TYPE_STRING, // 4 need to store type of!!!
2209 GObject.TYPE_STRING // 5 tooltip
2213 load : function(ar) {
2216 this.get('/RightEditor').el.hide();
2223 var provider = this.get('/LeftTree').getPaleteProvider();
2224 var iter = new Gtk.TreeIter();
2227 var keys = XObject.keys(ar);
2229 ar.listeners = ar.listeners || {};
2231 for (var i in ar.listeners ) {
2232 this.el.append(iter);
2233 var p = this.el.get_path(iter).to_string();
2236 this.el.set_value(iter, 0, '!'+ i );
2237 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2238 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2240 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2241 this.el.set_value(iter, 4, 'function');
2242 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2248 keys.forEach(function(i) {
2249 if (typeof(ar[i]) == 'object') {
2253 var type = provider.findType(ar, i, ar[i]);
2255 _this.el.append(iter);
2256 var p = _this.el.get_path(iter).to_string();
2258 _this.el.set_value(iter, 0, ''+i);
2259 _this.el.set_value(iter, 1, '' + ar[i]);
2260 _this.el.set_value(iter, 2, ''+i);
2261 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2262 _this.el.set_value(iter, 4, ''+type);
2263 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2267 startEditing : function(path,col) {
2269 * start editing path (or selected if not set..)
2270 * @param {String|false} path (optional) treepath to edit - selected tree gets
2271 * edited by default.
2272 * @param {Number} 0 or 1 (optional)- column to edit.
2275 if (typeof(path) == 'string') {
2276 tp = new Gtk.TreePath.from_string(path);
2278 var iter = new Gtk.TreeIter();
2279 var s = this.get('/LeftPanel.view').selection;
2280 s.get_selected(this.el, iter);
2281 tp = this.el.get_path(iter);
2282 path = tp.to_string();
2286 // which colum is to be edited..
2288 if (typeof(col) == 'undefined') {
2289 var k = this.getValue(path, 0);
2290 colObj = (!k.length || k == '|') ?
2291 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2293 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2296 // make sure the pulldown is set correctly..
2297 // not really needed for second col...
2299 var provider = this.get('/LeftTree').getPaleteProvider();
2301 var type = this.get('/LeftPanel.model').getType(path);
2302 var opts = provider.findOptions(type);
2303 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2305 if (opts === false) {
2306 this.get('/LeftPanel').editableColumn.setOptions([]);
2307 renderer.has_entry = true; /// probably does not have any effect.
2309 this.get('/LeftPanel').editableColumn.setOptions(opts);
2310 renderer.has_entry = false;
2314 // iter now has row...
2315 GLib.timeout_add(0, 100, function() {
2317 colObj.items[0].el.editable = true; // esp. need for col 0..
2318 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2328 var iter = new Gtk.TreeIter();
2329 this.get('/LeftPanel.model').el.get_iter_first(iter);
2334 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2337 ar.listeners = ar.listeners || {};
2338 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2341 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2344 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2350 //print(JSON.stringify(ar));
2354 toShort : function(str) {
2355 var a = typeof(str) == 'string' ? str.split("\n") : [];
2356 return a.length > 1 ? a[0] + '....' : '' + str;
2360 xtype: Gtk.TreeViewColumn,
2361 pack : "append_column",
2363 XObject.prototype.init.call(this);
2365 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2366 this.get('/LeftPanel').propertyColumn = this;
2371 xtype: Gtk.CellRendererText,
2372 pack : "pack_start",
2374 editing_started : function (self, editable, path) {
2376 this.get('/LeftPanel.model').activePath = path;
2379 edited : function (self, object, p0) {
2380 var model = this.get('/LeftPanel.model');
2381 var path = model.activePath;
2382 var iter = new Gtk.TreeIter();
2383 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2384 model.el.set_value(iter, 0, p0);
2385 model.el.set_value(iter, 2, p0);
2387 model.activePath = false;
2389 this.get('/LeftTree.model').changed(model.toJS(), true);
2390 this.el.editable = false;
2397 xtype: Gtk.TreeViewColumn,
2398 pack : "append_column",
2400 XObject.prototype.init.call(this);
2401 this.el.add_attribute(this.items[0].el , 'text', 3 );
2402 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2403 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2404 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2406 this.get('/LeftPanel').editableColumn= this;
2408 setOptions : function(ar) {
2409 var m = this.items[0].el.model;
2411 var iter = new Gtk.TreeIter();
2412 ar.forEach(function(i) {
2415 m.set_value(iter, 0, i);
2421 xtype: Gtk.CellRendererCombo,
2422 pack : "pack_start",
2427 XObject.prototype.init.call(this);
2428 this.el.model = new Gtk.ListStore();
2429 this.el.model.set_column_types ( 1, [
2430 GObject.TYPE_STRING // 0 real key
2434 edited : function (self, object, p0) {
2435 this.get('/LeftPanel').editing = false;
2436 print("EDITED? p:" + p0 + " t:" + p0);
2437 this.get('/LeftPanel.model').changed(p0, true);
2438 this.get('/LeftPanel.model').activePath = false;
2440 editing_started : function (self, editable, path) {
2441 this.get('/LeftPanel').editing = true;
2442 // console.log('editing started');
2443 // r.has_entry = false;
2444 this.get('/LeftPanel.model').editSelected(editable);
2455 id : "LeftPanelPopup",
2458 xtype: Gtk.MenuItem,
2462 activate : function (self) {
2463 this.get('/LeftPanel.model').deleteSelected();
2468 xtype: Gtk.MenuItem,
2472 activate : function (self) {
2473 this.get('/LeftPanel.model').startEditing(false, 0);
2486 xtype: Gtk.ScrolledWindow,
2487 pack : "pack_end,false,true,0",
2489 shadow_type : Gtk.ShadowType.IN,
2491 XObject.prototype.init.call(this);
2492 XObject.prototype.init.call(this);
2493 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2494 this.el.set_size_request ( 150, -1 );
2497 activeElement : false,
2498 hideWin : function() {
2505 if (this.get('/Window.left').el.position < 160) {
2508 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2515 xtype: Gtk.TreeView,
2516 enable_tree_lines : true,
2517 headers_visible : false,
2520 XObject.prototype.init.call(this);
2522 var description = new Pango.FontDescription.c_new();
2523 description.set_size(8000);
2524 this.el.modify_font(description);
2526 //this.selection = this.el.get_selection();
2527 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2536 cursor_changed : function (self) {
2537 var iter = new Gtk.TreeIter();
2539 //console.log('changed');
2540 var m = this.get('model');
2541 if (!this.selection){
2542 this.selection = this.el.get_selection();
2545 var s = this.selection;
2546 if (!s.get_selected(m.el, iter)) {
2549 var tp = m.el.get_path(iter).to_string();
2554 var key = m.getValue(tp, 0);
2556 var type = m.getValue(tp, 1);
2557 var skel = m.getValue(tp, 3);
2558 var etype = m.getValue(tp, 5);
2561 this.get('/MidPropTree').hideWin();
2563 if (type == 'function') {
2565 if (etype != 'events') {
2569 this.get('/LeftPanel.model').add({
2578 if (type.indexOf('.') > -1 ||
2579 type == 'boolean') {
2583 this.get('/LeftPanel.model').add( {
2593 xtype: Gtk.ListStore,
2596 XObject.prototype.init.call(this);
2597 this.el.set_column_types ( 6, [
2598 GObject.TYPE_STRING, // real key
2599 GObject.TYPE_STRING, // real type
2600 GObject.TYPE_STRING, // docs ?
2601 GObject.TYPE_STRING, // visable desc
2602 GObject.TYPE_STRING, // function desc
2603 GObject.TYPE_STRING // element type (event|prop)
2607 getValue : function(treepath, col)
2609 var tp = new Gtk.TreePath.from_string (treepath);
2610 var iter = new Gtk.TreeIter();
2611 this.el.get_iter (iter, tp);
2612 var value = new GObject.Value('');
2613 this.el.get_value(iter, col, value);
2617 showData : function(type) {
2619 if (!this.get('/MidPropTree').activeElement || !type) {
2620 return; // no active element
2623 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2624 var palete = this.get('/LeftTree').getPaleteProvider();
2628 Seed.print('Showing right?');
2629 if (!this.get('/MidPropTree').shown) {
2631 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2632 this.get('/MidPropTree').el.show();
2633 this.get('/MidPropTree').shown = true;
2636 var elementList = palete.getPropertiesFor(fullpath, type);
2637 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2638 // console.dump(elementList);
2641 var iter = new Gtk.TreeIter();
2642 for(var i =0 ; i < elementList.length; i++) {
2643 var p=elementList[i];
2644 this.el.append(iter);
2645 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2646 //GObject.TYPE_STRING, // real key
2647 // GObject.TYPE_STRING, // real type
2648 // GObject.TYPE_STRING, // docs ?
2649 // GObject.TYPE_STRING // func def?
2652 this.el.set_value(iter, 0, p.name);
2653 this.el.set_value(iter, 1, p.type);
2654 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2655 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2656 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2657 this.el.set_value(iter, 5, type);
2665 xtype: Gtk.TreeViewColumn,
2667 this.el = new Gtk.TreeViewColumn();
2668 this.parent.el.append_column(this.el);
2670 XObject.prototype.init.call(this);
2671 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2676 xtype: Gtk.CellRendererText,
2677 pack : "pack_start,true"
2701 xtype: Gtk.Notebook,
2702 pack : "pack_start,true,true",
2703 id : "view-help-nb",
2705 XObject.prototype.init.call(this);
2706 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2707 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2711 xtype: Gtk.Notebook,
2713 id : "view-notebook",
2716 XObject.prototype.init.call(this);
2717 this.el.set_current_page(0);
2719 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2720 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2727 id : "RightBrowser",
2733 xtype: Gtk.ScrolledWindow,
2735 shadow_type : Gtk.ShadowType.IN,
2737 XObject.prototype.init.call(this);
2738 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2742 xtype: WebKit.WebView,
2746 XObject.prototype.init.call(this);
2747 // this may not work!?
2748 this.el.open('file:///' + __script_path__ + '/../builder.html');
2752 this.el, /* widget that will accept a drop */
2753 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2754 null, /* lists of target to support */
2755 0, /* size of list */
2756 Gdk.DragAction.COPY /* what to do with data after dropped */
2759 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2760 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2762 renderJS : function(data) {
2763 print("HTML RENDERING");
2764 /// prevent looping..
2765 //if (this.pendingRedraw) {
2766 // print("pending redraw active?!");
2771 if (!this.get('/Window.LeftTree').getActiveFile()) {
2775 var project = this.get('/Window.LeftTree').getActiveFile().project;
2776 //print (project.fn);
2778 project.runhtml = project.runhtml || '';
2781 this.runhtml = this.runhtml || '';
2783 if (project.runhtml != this.runhtml) {
2784 // then we need to reload the browser using
2785 // load_html_string..
2787 // then trigger a redraw once it's loaded..
2788 this.pendingRedraw = true;
2790 this.runhtml = project.runhtml;
2792 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2793 html = html.replace('</head>', this.runhtml + '</head>');
2794 print("LOAD HTML " + html);
2795 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2796 // should trigger load_finished!
2801 this.pendingRedraw = false;
2804 this.renderedData = data;
2805 var str = JSON.stringify(data) ;
2808 console.log('not loaded yet');
2810 //Seed.print("RENDER:" + str);
2811 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2813 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2816 load_finished : function (self, object) {
2817 // if (this.ready) { // dont do it twice!
2821 this.pendingRedraw = false;
2822 var js = this.get('/LeftTree.model').toJS();
2824 this.renderJS(js[0]);
2828 script_alert : function (self, object, p0) {
2831 return true; // do not display anything...
2833 console_message : function (self, object, p0, p1) {
2834 // console.log(object);
2835 if (!object.match(/^\{/)) {
2837 this.get('/Terminal').feed(object);
2838 return true; // do not handle!!! -> later maybe in console..
2840 // console.log(object);
2841 var val = JSON.parse(object);
2843 if (typeof(val['hover-node']) != 'undefined') {
2844 this.activeNode = val['hover-node'];
2845 console.log('active node: ' + this.activeNode);
2850 if (typeof(val['id']) != 'undefined') {
2851 // this.activeNode = val['id'];
2852 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2856 this.get('/LeftTree.view').selectNode(tg[0]);
2860 if (ret && typeof(val['set']) != 'undefined') {
2861 this.get('/LeftPanel.model').add({
2865 //console.log('active node: ' + this.activeNode);
2868 //Seed.print('a:'+a);
2869 //Seed.print('b:'+b);
2870 //Seed.print('c:'+c);
2873 drag_motion : function (w, ctx, x, y, time, ud) {
2874 // console.log('DRAG MOTION');
2876 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2877 this.targetData = [];
2878 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2880 // A) find out from drag all the places that node could be dropped.
2881 var src = Gtk.drag_get_source_widget(ctx);
2882 if (!src.dropList) {
2883 Gdk.drag_status(ctx, 0, time);
2886 // b) get what we are over.. (from activeNode)
2887 // tree is empty.. - list should be correct..
2888 if (!this.get('/LeftTree.model').currentTree) {
2889 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2893 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2895 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2898 Gdk.drag_status(ctx, 0,time);
2899 this.get('/LeftTree.view').highlight(false);
2903 // if we have a target..
2904 // -> highlight it! (in browser)
2905 // -> highlight it! (in tree)
2907 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2908 this.get('/LeftTree.view').highlight(tg);
2909 this.targetData = tg;
2910 // for tree we should handle this...
2913 drag_drop : function (w, ctx, x, y,time, ud) {
2914 print("TARGET: drag-drop");
2915 var is_valid_drop_site = true;
2920 w, /* will receive 'drag-data-received' signal */
2921 ctx, /* represents the current state of the DnD */
2922 this.get('/Window').atoms["STRING"], /* the target type we want */
2923 time /* time stamp */
2927 /* No target offered by source => error */
2930 return is_valid_drop_site;
2932 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2934 print("Browser: drag-data-received");
2935 var delete_selection_data = false;
2936 vardnd_success = false;
2937 /* Deal with what we are given from source */
2938 if( sel_data && sel_data.length ) {
2940 if (ctx.action == Gdk.DragAction.ASK) {
2941 /* Ask the user to move or copy, then set the ctx action. */
2944 if (ctx.action == Gdk.DragAction.MOVE) {
2945 delete_selection_data = true;
2947 var source = Gtk.drag_get_source_widget(ctx);
2949 print("Browser: source.DRAGDATA? " + source.dragData);
2950 if (this.targetData) {
2951 print(this.targetData);
2952 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2961 if (dnd_success == false)
2963 Seed.print ("DnD data transfer failed!\n");
2966 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2977 id : "RightGtkView",
2979 redraw : function() {
2980 this.highlightWidget = false;
2981 print("REDRAW CALLED");
2982 this.activePath = this.get('/LeftTree').getActivePath();
2983 if (this.renderedEl) {
2984 print("QUEUE DRAW CALLING");
2985 this.renderedEl.queue_draw();
2988 renderJS : function(data, withDebug)
2990 this.highlightWidget = false;
2992 this.withDebug = false;
2994 if (this.renderedEl) {
2995 this.get('view').el.remove(this.renderedEl);
2996 this.renderedEl.destroy();
2997 this.renderedEl = false;
3002 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3003 // in theory tree is actually window..
3005 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3010 this.get('view').el.set_size_request(
3011 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3014 this.renderedEl.set_size_request(
3015 tree.default_width || 600,
3016 tree.default_height || 400
3018 this.get('view').el.show_all();
3023 showInWindow : function() {
3024 print("GET PROEJCT");
3025 var pr = this.get('/LeftProjectTree').getActiveProject();
3027 console.log(pr.paths);
3030 var src= this.buildJS(
3031 this.get('/LeftTree.model').toJS()[0],
3036 //var x = new imports.sandbox.Context();
3040 Seed.check_syntax('var e = ' + src);
3043 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3044 this.get('/Terminal').feed(console._dump(e)+"\n");
3046 var lines = src.split("\n");
3047 var start = Math.max(0, e.line - 10);
3048 var end = Math.min(lines.length, e.line + 10);
3049 for (var i =start ; i < end; i++) {
3051 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3054 this.get('/Terminal').feed(lines[i] + "\n");
3061 this.get('/BottomPane').el.set_current_page(1);
3062 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3063 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3064 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3066 var _top = x.get_global_object()._top;
3068 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3070 if (_top.el.popup) {
3071 _top.el.popup(null, null, null, null, 3, null);
3075 viewAdd : function(item, par)
3077 // does something similar to xobject..
3078 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3080 if (item.pack===false || item.pack === 'false') { // no ;
3083 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3084 var type = item['|xns'] + '.' + item['xtype'];
3085 var ns = imports.gi[item['|xns']];
3086 var ctr = ns[item['xtype']];
3088 for(var k in item) {
3090 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3105 if (k[0] == '|' && typeof(kv) == 'string') {
3107 if (kv.match(new RegExp('function'))) {
3110 print("WASL " + k + '=' + kv);
3112 eval( 'kv = ' + kv);
3113 } catch(e) { continue; }
3116 // print(k + '=' + kv);
3118 if (k[0] == '|') { // should be boolean or number..
3120 //print(k + '=' + kv);
3123 if (k == 'show_tabs') { // force tab showing for notebooks.
3126 print(k + '=' + typeof(kv) + " : " + kv);
3132 var el = new ctr(ctr_args);
3134 print("PACK" + item.pack);
3135 //console.dump(item.pack);
3142 if (typeof(item.pack) == 'string') {
3144 item.pack.split(',').forEach(function(e, i) {
3146 if (e == 'false') { args.push( false); return; }
3147 if (e == 'true') { args.push( true); return; }
3148 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3151 //print(args.join(","));
3153 pack_m = args.shift();
3155 pack_m = item.pack.shift();
3160 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3162 name: "ArgumentError",
3163 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3164 "ADDING : " + item.id + " " + el
3173 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3174 //Seed.print('args: ' + args.length);
3176 par[pack_m].apply(par, args);
3180 item.items = item.items || [];
3181 item.items.forEach(function(ch,n) {
3183 print ("type:" + type);
3185 print ("ch.pack:" + ch.pack);
3186 if (type == 'Gtk.Table' && ch.pack == 'add') {
3187 var c = n % item.n_columns;
3188 var r = Math.floor(n/item.n_columns);
3189 ch.pack = [ 'attach', c, c+1, r, r+1,
3190 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3191 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3192 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3193 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3197 _this.viewAdd(ch, el);
3202 // add the signal handlers.
3203 // is it a widget!?!!?
3209 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3210 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3211 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3212 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3213 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3223 widgetDragDropEvent : function() {
3224 print("WIDGET DRAGDROP");
3227 widgetDragMotionEvent : function() {
3228 print("WIDGET DRAGMOTION");
3231 widgetExposeEvent : function(w, evt, ud, item) {
3233 if (this.inRender) {
3237 if ( this.highlightWidget) {
3238 this.inRender = true;
3239 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3240 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3242 this.inRender = false;
3247 if (this.activePath != item.xtreepath) {
3251 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3252 // work out the coords of the window..
3254 var dr = widget.window;
3255 this.gc = (new Gdk.GC.c_new(dr));
3256 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3257 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3261 var r = evt.expose.area;
3262 // console.dump([r.x, r.y, r.width, r.height ] );
3264 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3265 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3266 // happens with gtkscrollview embedded stuff..
3267 var np =this.activePath.split(':');
3269 this.activePath = np.join(':');
3270 this.renderedEl.queue_draw();
3286 this.inRender = true;
3289 this.highlightWidget = widget;
3294 // print("DRAW BOX");
3295 //console.dump(this.box);
3296 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3297 this.inRender = false;
3300 widgetPressEvent : function(w,e,u,d) {
3301 if (this.get('view').pressed) {
3304 this.get('view').pressed = true;
3305 print("WIDGET PRESS " + d.xtreepath );
3306 this.get('/LeftTree.view').selectNode( d.xtreepath );
3309 widgetReleaseEvent : function() {
3310 this.get('view').pressed = false;
3316 pack : "pack_start,false,true,0",
3320 pack : "pack_start,false,false,0",
3321 label : "Run The Application",
3323 button_press_event : function (self, event) {
3324 // call render on left tree - with special option!?!
3326 //print("GET PROEJCT");
3327 var pr = this.get('/LeftProjectTree').getActiveProject();
3330 for (var i in pr.paths) {
3334 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3335 this.get('/Terminal').feed("RUN DIR:" + dir);
3337 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3338 , false,false,false);
3339 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3340 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3350 xtype: Gtk.ScrolledWindow,
3353 shadow_type : Gtk.ShadowType.IN,
3355 XObject.prototype.init.call(this);
3356 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3360 xtype: Gtk.EventBox,
3361 pack : "add_with_viewport",
3363 XObject.prototype.init.call(this);
3364 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3365 red: 0x9F00, green: 0xB800 , blue : 0xA800
3373 XObject.prototype.init.call(this);
3374 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3375 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3380 xtype: Gtk.EventBox,
3383 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3384 XObject.prototype.init.call(this);
3388 this.el, /* widget that will accept a drop */
3389 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3390 null, /* lists of target to support */
3391 0, /* size of list */
3392 Gdk.DragAction.COPY /* what to do with data after dropped */
3395 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3396 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3399 getActiveNode : function(x,y)
3401 // workout what node is here..
3402 return '0'; // top..
3406 drag_motion : function (self, ctx, x, y, time) {
3408 // A) find out from drag all the places that node could be dropped.
3409 var src = Gtk.drag_get_source_widget(ctx);
3410 if (!src.dropList) {
3411 Gdk.drag_status(ctx, 0, time);
3414 // b) get what we are over.. (from activeNode)
3415 // tree is empty.. - list should be correct..
3416 if (!this.get('/LeftTree.model').currentTree) {
3417 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3421 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3422 var activeNode = this.getActiveNode(x, y);
3425 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3428 Gdk.drag_status(ctx, 0,time);
3429 this.get('/LeftTree.view').highlight(false);
3433 // if we have a target..
3434 // -> highlight it! (in browser)
3435 // -> highlight it! (in tree)
3437 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3438 this.get('/LeftTree.view').highlight(tg);
3439 this.targetData = tg;
3440 // for tree we should handle this...
3443 drag_drop : function (self,ctx, x, y, time) {
3444 Seed.print("TARGET: drag-drop");
3445 var is_valid_drop_site = true;
3450 self, /* will receive 'drag-data-received' signal */
3451 ctx, /* represents the current state of the this.gDnD */
3452 this.get('/Window').atoms["STRING"], /* the target type we want */
3453 time /* time stamp */
3457 /* No target offered by source => error */
3460 return is_valid_drop_site;
3463 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3465 Seed.print("GtkView: drag-data-received");
3466 var delete_selection_data = false;
3467 var dnd_success = false;
3468 /* Deal with what we are given from source */
3469 if( sel_data && sel_data.length ) {
3471 if (ctx.action == Gdk.DragAction.ASK) {
3472 /* Ask the user to move or copy, then set the ctx action. */
3475 if (ctx.action == Gdk.DragAction.MOVE) {
3476 delete_selection_data = true;
3478 var source = Gtk.drag_get_source_widget(ctx);
3480 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3481 if (this.targetData) {
3482 Seed.print(this.targetData);
3483 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3492 if (dnd_success == false)
3494 Seed.print ("DnD data transfer failed!\n");
3497 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3500 button_press_event : function (self, event) {
3501 this.pressed = false;
3517 xtype: Gtk.ScrolledWindow,
3522 var file = this.get('/LeftTree').getActiveFile();
3526 var activeEl = this.get('/LeftTree').getActiveElement();
3527 var xtype = file.guessName( activeEl )
3528 if (!xtype || !xtype.length) {
3531 this.get('/Window.view-help-nb').el.set_current_page(1);
3533 // get the active element being edited.
3534 var helpurl = file.getHelpUrl(xtype);
3536 // now load the help info in the page..
3537 this.get('help-view').el.open(helpurl);
3541 xtype: WebKit.WebView,
3545 XObject.prototype.init.call(this);
3546 this.get('/Window.help-view').el.open(
3547 "http://devel.akbkhome.com/seed/");
3559 xtype: Gtk.Notebook,
3562 XObject.prototype.init.call(this);
3563 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3564 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3569 xtype: Gtk.ScrolledWindow,
3574 xtype: GtkSource.View,
3578 XObject.prototype.init.call(this);
3579 var description = Pango.Font.description_from_string("monospace")
3580 description.set_size(8000);
3581 this.el.modify_font(description);
3584 load : function(str) {
3586 // show the help page for the active node..
3587 this.get('/Help').show();
3590 this.get('/BottomPane').el.set_current_page(0);
3591 this.el.get_buffer().set_text(str, str.length);
3592 var lm = GtkSource.LanguageManager.get_default();
3594 this.el.get_buffer().set_language(lm.get_language('js'));
3595 var buf = this.el.get_buffer();
3596 var cursor = buf.get_mark("insert");
3597 var iter= new Gtk.TextIter;
3598 buf.get_iter_at_mark(iter, cursor);
3600 iter.set_line_offset(4);
3601 buf.move_mark(cursor, iter);
3604 cursor = buf.get_mark("selection_bound");
3605 iter= new Gtk.TextIter;
3606 buf.get_iter_at_mark(iter, cursor);
3608 iter.set_line_offset(4);
3609 buf.move_mark(cursor, iter);
3611 this.el.grab_focus();
3613 insert_spaces_instead_of_tabs : true,
3616 show_line_numbers : true,
3619 xtype: GtkSource.Buffer,
3620 pack : "set_buffer",
3622 changed : function (self) {
3623 var s = new Gtk.TextIter();
3624 var e = new Gtk.TextIter();
3625 this.el.get_start_iter(s);
3626 this.el.get_end_iter(e);
3627 var str = this.el.get_text(s,e,true);
3629 Seed.check_syntax('var e = ' + str);
3631 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3632 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3634 print("SYNTAX ERROR IN EDITOR");
3639 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3640 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3643 this.get('/LeftPanel.model').changed( str , false);
3652 xtype: Gtk.ScrolledWindow,
3656 xtype: Vte.Terminal,
3659 feed : function(istr) {
3660 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3661 // we should make ourselves visable!!!
3662 this.get('/BottomPane').el.show();
3663 this.get('/BottomPane').el.set_current_page(1);
3665 this.el.feed(str ,str.length);
3667 scroll_on_output : true,
3669 XObject.prototype.init.call(this);
3670 this.el.set_size (80, 1000);
3672 scrollback_lines : 1000
3682 pack : "pack_start,false,false",
3686 this.get('buttonbar').el.show();
3687 this.get('viewbox').el.hide();
3688 print("TRIED TO HIDE");
3691 this.get('buttonbar').el.hide();
3692 this.get('viewbox').el.show();
3693 // this.get('model').expanded();
3705 pack : "pack_start,false,true",
3707 clicked : function (self) {
3708 this.get('/RightPalete').show();
3715 stock : Gtk.STOCK_GOTO_FIRST,
3716 icon_size : Gtk.IconSize.MENU
3726 XObject.prototype.init.call(this);
3727 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3730 enter_notify_event : function (self, event) {
3731 this.get('/RightPalete').show();
3745 pack : "pack_start,false,true",
3754 pack : "pack_start,false,true",
3756 clicked : function (self) {
3757 this.get('/RightPalete').hide();
3764 stock : Gtk.STOCK_GOTO_LAST,
3765 icon_size : Gtk.IconSize.MENU
3772 xtype: Gtk.ScrolledWindow,
3775 XObject.prototype.init.call(this);
3776 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3777 this.el.set_size_request(-1,200);
3779 shadow_type : Gtk.ShadowType.IN,
3782 xtype: Gtk.TreeView,
3785 XObject.prototype.init.call(this);
3786 this.el.set_size_request(150,-1);
3787 // set_reorderable: [1]
3789 var description = new Pango.FontDescription.c_new();
3790 description.set_size(8000);
3791 this.el.modify_font(description);
3793 this.selection = this.el.get_selection();
3794 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3795 // this.selection.signal['changed'].connect(function() {
3796 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3798 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3800 Gtk.drag_source_set (
3801 this.el, /* widget will be drag-able */
3802 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3803 null, /* lists of target to support */
3804 0, /* size of list */
3805 Gdk.DragAction.COPY /* what to do with data after dropped */
3807 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3809 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3810 Gtk.drag_source_add_text_targets(this.el);
3812 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3813 targets = new Gtk.TargetList();
3814 targets.add( LeftTree.atoms["STRING"], 0, 0);
3815 targets.add_text_targets( 1 );
3816 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3818 //if you want to allow text to be output elsewhere..
3819 //Gtk.drag_source_add_text_targets(this.el);
3823 headers_visible : false,
3824 enable_tree_lines : true,
3826 drag_begin : function (self, ctx) {
3827 // we could fill this in now...
3828 Seed.print('SOURCE: drag-begin');
3832 var iter = new Gtk.TreeIter();
3833 var s = this.selection;
3834 s.get_selected(this.get('/RightPalete.model').el, iter);
3835 var path = this.get('/RightPalete.model').el.get_path(iter);
3837 var pix = this.el.create_row_drag_icon ( path);
3840 Gtk.drag_set_icon_pixmap (ctx,
3847 var value = new GObject.Value('');
3848 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3849 if (!this.get('/RightPalete').provider) {
3852 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3853 this.el.dragData = value.value;
3860 drag_data_get : function (self, drag_context, selection_data, info, time) {
3861 //Seed.print('Palete: drag-data-get: ' + target_type);
3862 if (this.el.dragData && this.el.dragData.length ) {
3863 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3867 //this.el.dragData = "TEST from source widget";
3871 drag_end : function (self, drag_context) {
3872 Seed.print('SOURCE: drag-end');
3873 this.el.dragData = false;
3874 this.el.dropList = false;
3875 this.get('/LeftTree.view').highlight(false);
3881 xtype: Gtk.ListStore,
3884 XObject.prototype.init.call(this);
3885 this.el.set_column_types ( 2, [
3886 GObject.TYPE_STRING, // title
3887 GObject.TYPE_STRING // tip
3892 load : function(tr,iter)
3897 //console.log('Project tree load: ' + tr.length);
3898 var citer = new Gtk.TreeIter();
3899 //this.insert(citer,iter,0);
3900 for(var i =0 ; i < tr.length; i++) {
3903 this.el.append(citer);
3905 this.el.insert(citer,iter,-1);
3910 this.el.set_value(citer, 0, '' + r ); // title
3912 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3913 //if (r.cn && r.cn.length) {
3914 // this.load(r.cn, citer);
3920 getValue : function (iter, col) {
3921 var gval = new GObject.Value('');
3922 this.el.get_value(iter, col ,gval);
3929 xtype: Gtk.TreeViewColumn,
3930 pack : "append_column",
3932 XObject.prototype.init.call(this);
3933 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3937 xtype: Gtk.CellRendererText,
3959 XObject.cache['/Window'] = Window;