3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
14 type : Gtk.WindowType.TOPLEVEL,
15 title : "Application Builder",
19 "STRING" : Gdk.atom_intern("STRING")
21 this.targetList = new Gtk.TargetList();
22 this.targetList.add( this.atoms["STRING"], 0, 0);
23 //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
25 "style \"gtkcombobox-style\" {\n" +
26 " GtkComboBox::appears-as-list = 1\n" +
28 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
29 XObject.prototype.init.call(this);
38 setTitle : function(str) {
39 this.el.set_title(this.title + ' - ' + str);
42 delete_event : function (self, event) {
45 destroy : function (self) {
48 show : function (self) {
49 print("WINDOW SHOWING - trying to hide");
50 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
51 this.get('/MidPropTree').hideWin();
52 this.get('/RightPalete').hide();
53 this.get('/BottomPane').el.hide();
64 pack : "pack_start,false,false",
78 label : "New _Project",
80 activate : function (self) {
82 this.get('/EditProject').show({
83 success : function(pr) {
84 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
95 activate : function (self) {
96 var fn = this.get('/LeftProjectTree.combo').getValue();
98 this.get('/LeftProjectTree').showNoProjectSelected();
101 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
102 this.get('/DialogNewComponent').show({
103 project : pm.getByFn(fn)
109 xtype: Gtk.SeparatorMenuItem,
114 use_underline : true,
116 label : "D_elete Project",
118 activate : function (self) {
120 var fn = this.get('/LeftProjectTree').get('combo').getValue();
122 this.get('/StandardErrorDialog').show("Select a project")
125 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
126 var pr = pm.getByFn(fn);
129 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
130 pm.deleteProject(fn);
138 xtype: Gtk.SeparatorMenuItem,
145 use_underline : true,
147 activate : function (self) {
159 use_underline : true,
164 pack : "set_submenu",
172 activate : function (self) {
173 var fn = this.get('/LeftTree').getActiveFile();
175 this.get('/StandardErrorDialog').show("No File active");
179 this.get('/DialogNewComponent').show(fn);
183 label : "File _Properties",
190 activate : function (self, event) {
191 this.get('/RooProjectProperties').show();
195 label : "Modify Project HTML ",
206 use_underline : true,
210 pack : "set_submenu",
218 activate : function (self, event) {
219 var js = this.get('/LeftTree.model').toJS();
221 this.get('/RightBrowser.view').renderJS(js[0]);
226 label : "_Redraw (Roo)",
233 activate : function (self, event)
235 /* Firefox testing for debugging..
236 - we can create a /tmp directory, and put.
237 builder.html, builder.html.js, link roojs1
238 add at the end of builder.html Roo.onload(function() {
240 if (!this.get('/Window.LeftTree').getActiveFile()) {
244 var js = this.get('/LeftTree.model').toJS();
248 var project = this.get('/Window.LeftTree').getActiveFile().project;
249 //print (project.fn);
251 project.runhtml = project.runhtml || '';
254 var File = imports.File.File;
256 var target = "/tmp/firetest"; // fixme..
257 if (!File.isDirectory(target)) {
260 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
261 if (!File.exists( target+ '/roojs1')) {
262 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
267 var html = imports.File.File.read(__script_path__ + '/../builder.html');
268 html = html.replace('</head>', project.runhtml + '</head>');
271 var jsstr = JSON.stringify(js[0]);
273 var runbuilder = '<script type="text/javascript">' + "\n" +
274 " Builder.render(" + jsstr + ");\n" +
277 html = html.replace('</body>', runbuilder + '</body>');
279 File.write( target+ '/builder.html', html);
281 this.get('/Terminal').feed("RUN DIR:" + target);
283 this.get('/Terminal').el.fork_command( null , [], [], target
284 , false,false,false);
285 var cmd = "firefox file://" + target + "/builder.html \n";
286 this.get('/Terminal').el.feed_child(cmd, cmd.length);
290 label : "_Test in Firefox (Roo)",
301 use_underline : true,
309 pack : "set_submenu",
318 use_underline : true,
320 activate : function (self) {
321 this.get('/About').el.run();
350 label : "Select Project",
352 pack : "pack_start,false,true",
354 XObject.prototype.init.call(this);
355 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
358 activate : function (self) {
359 var nb = this.get('/LeftTopPanel.notebook');
360 if (this.el.expanded) {
363 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
366 var model = this.get('/LeftProjectTree.combomodel');
367 // print ("loading Projects?")
368 //console.dump(pm.projects);
369 model.loadData(pm.projects);
372 nb.el.set_current_page(1);
373 //pm.on('changed', function() {
374 //console.log("CAUGHT project manager change");
375 // _combo.model.loadData(pm.projects);
379 nb.el.set_current_page(0);
381 enter_notify_event : function (self, event) {
382 this.el.expanded = !this.el.expanded;
383 //if (this.el.expanded ) {
384 this.listeners.activate.call(this);
396 pack : "pack_start,true,true",
398 XObject.prototype.init.call(this);
399 this.el.set_current_page(0);
404 xtype: Gtk.ScrolledWindow,
407 getActiveElement : function() { // return path to actie node.
409 var path = this.getActivePath();
413 var iter = new Gtk.TreeIter();
414 this.get('model').el.get_iter_from_string(iter, path);
416 var value = new GObject.Value('');
417 this.get('model').el.get_value(iter, 2, value);
419 return JSON.parse(value.value);
421 getActiveFile : function() {
422 return this.get('model').file;
424 getActivePath : function() {
425 var model = this.get('model');
426 var view = this.get('view');
427 if (view.selection.count_selected_rows() < 1) {
430 var iter = new Gtk.TreeIter();
432 view.selection.get_selected(model.el, iter);
433 return model.el.get_path(iter).to_string();
435 getPaleteProvider : function() {
436 var model = this.get('model');
437 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
438 return pm.getPalete(model.file.getType());
440 getRenderer : function() {
442 switch( this.getActiveFile().getType()) {
444 return this.get('/RightBrowser.view');
446 return this.get('/RightGtkView');
451 XObject.prototype.init.call(this);
452 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
454 renderView : function() {
455 var render = this.getRenderer();
456 var model = this.get('model');
458 render.renderJS(model.toJS(false,true)[0]);
460 print("NO RENDER JS METHOD?");
463 shadow_type : Gtk.ShadowType.IN,
469 headers_visible : false,
470 enable_tree_lines : true,
473 XObject.prototype.init.call(this);
474 var description = new Pango.FontDescription.c_new();
475 description.set_size(8000);
476 this.el.modify_font(description);
478 this.selection = this.el.get_selection();
479 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
482 // is this really needed??
483 this.selection.signal['changed'].connect(function() {
484 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
485 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
489 Gtk.drag_source_set (
490 this.el, /* widget will be drag-able */
491 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
492 null, /* lists of target to support */
493 0, /* size of list */
494 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
497 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
499 Gtk.drag_source_add_text_targets(this.el);
502 this.el, /* widget that will accept a drop */
503 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
504 null, /* lists of target to support */
505 0, /* size of list */
506 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
509 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
510 Gtk.drag_dest_add_text_targets(this.el);
512 highlight : function(treepath_ar) {
514 // highlighting for drag/drop
515 if (treepath_ar.length && treepath_ar[0].length ) {
516 this.el.set_drag_dest_row(
517 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
519 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
523 selectNode : function(treepath_str) {
524 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
525 var tp = new Gtk.TreePath.from_string(treepath_str);
526 this.el.set_cursor(tp, null, false);
527 this.el.scroll_to_cell(tp, null, false, 0,0);
530 button_press_event : function (self, ev) {
531 console.log("button press?");
532 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
533 print("click" + ev.type);
539 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
541 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
543 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
544 this.get('/LeftTreeMenu').el.show_all();
545 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
546 print("click:" + res.path.to_string());
549 drag_begin : function (self, drag_context) {
550 print('SOURCE: drag-begin');
551 this.targetData = false;
552 // find what is selected in our tree...
553 var iter = new Gtk.TreeIter();
554 var s = this.selection;
555 s.get_selected(this.get('/LeftTree.model').el, iter);
557 // set some properties of the tree for use by the dropped element.
558 var value = new GObject.Value('');
559 this.get('/LeftTree.model').el.get_value(iter, 2, value);
560 var data = JSON.parse(value.value);
561 var xname = this.get('/LeftTree.model').file.guessName(data);
563 this.el.dragData = xname;
564 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
567 // make the drag icon a picture of the node that was selected
568 var path = this.get('/LeftTree.model').el.get_path(iter);
569 this.el.treepath = path.to_string();
571 var pix = this.el.create_row_drag_icon ( path);
573 Gtk.drag_set_icon_pixmap (ctx,
582 drag_end : function (self, drag_context) {
583 Seed.print('LEFT-TREE: drag-end');
584 this.el.dragData = false;
585 this.el.dropList = false;
586 this.targetData = false;
587 this.get('/LeftTree.view').highlight(false);
590 drag_motion : function (self, ctx, x, y, time) {
591 console.log("LEFT-TREE: drag-motion");
592 var src = Gtk.drag_get_source_widget(ctx);
594 // a drag from elsewhere...- prevent drop..
596 print("no drag data!");
597 Gdk.drag_status(ctx, 0, time);
598 this.targetData = false;
601 var action = Gdk.DragAction.COPY;
602 if (src == this.el) {
603 // unless we are copying!!! ctl button..
604 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
608 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
609 // no children.. -- asume it's ok..
610 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
611 Gdk.drag_status(ctx, action ,time);
615 print("GETTING POS");
616 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
617 print("ISOVER? " + isOver);
619 Gdk.drag_status(ctx, 0 ,time);
620 return false; // not over apoint!?!
622 // drag node is parent of child..
623 console.log("SRC TREEPATH: " + src.treepath);
624 console.log("TARGET TREEPATH: " + data.path.to_string());
626 // nned to check a few here..
627 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
628 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
629 //Gtk.TreeViewDropPosition.AFTER
630 //Gtk.TreeViewDropPosition.BEFORE
632 if (typeof(src.treepath) != 'undefined' &&
633 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
634 print("subpath drag");
635 Gdk.drag_status(ctx, 0 ,time);
640 //print("DUMPING DATA");
641 //console.dump(data);
644 print(data.path.to_string() +' => '+ data.pos);
645 var tg = this.get('/LeftTree.model').findDropNodeByPath(
646 data.path.to_string(), src.dropList, data.pos);
648 this.get('/LeftTree.view').highlight(tg);
650 print("Can not find drop node path");
651 this.targetData = false;
652 Gdk.drag_status(ctx, 0, time);
656 this.targetData = tg;
659 Gdk.drag_status(ctx, action ,time);
663 drag_drop : function (w, ctx, x, y, time) {
664 Seed.print("TARGET: drag-drop");
668 w, /* will receive 'drag-data-received' signal */
669 ctx, /* represents the current state of the DnD */
670 this.get('/Window').atoms["STRING"], /* the target type we want */
671 time /* time stamp */
675 /* No target offered by source => error */
680 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
681 print("Tree: drag-data-received");
683 var delete_selection_data = false;
684 var dnd_success = false;
685 /* Deal with what we are given from source */
686 if( sel_data && sel_data.length ) {
688 if (ctx.action == Gdk.DragAction.ASK) {
689 /* Ask the user to move or copy, then set the ctx action. */
692 if (ctx.action == Gdk.DragAction.MOVE) {
693 //delete_selection_data = true;
696 var source = Gtk.drag_get_source_widget(ctx);
698 if (this.targetData) {
699 if (source != this.el) {
700 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
702 // drag around.. - reorder..
703 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
707 //Seed.print(this.targetData);
713 // we can send stuff to souce here...
719 if (dnd_success == false)
721 Seed.print ("DnD data transfer failed!\n");
724 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
727 cursor_changed : function (self) {
728 if (this.blockChanges) { // probably not needed..
731 var render = this.get('/LeftTree').getRenderer();
734 if (this.selection.count_selected_rows() < 1) {
735 this.get('/LeftPanel.model').load( false);
736 this.get('/MidPropTree').activeElement = false;
737 this.get('/MidPropTree').hideWin();
739 var pm = this.get('/RightPalete.model');
740 if (!this.get('/LeftTree').getPaleteProvider()) {
741 // it may not be loaded yet..
744 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
745 this.get('/LeftTree.model').listAllTypes()));
746 if (render && render.redraw) {
752 //console.log('changed');
753 var s = this.selection;
754 var iter = new Gtk.TreeIter();
755 s.get_selected(this.get('/LeftTree.model').el, iter);
759 var value = new GObject.Value('');
760 this.get('/LeftTree.model').el.get_value(iter, 2, value);
761 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
763 var data = JSON.parse(value.value);
764 this.get('/MidPropTree').activeElement = data;
765 this.get('/MidPropTree').hideWin();
766 this.get('/LeftPanel.model').load( data);
768 console.log(value.value);
769 // _g.button.set_label(''+value.get_string());
771 var pm =this.get('/RightPalete.model');
772 pm.load( this.get('/RightPalete').provider.gatherList(
773 this.get('/LeftTree.model').listAllTypes()));
776 if (render && render.redraw) {
780 //Seed.print( value.get_string());
787 xtype: Gtk.TreeStore,
792 changed : function(n, refresh) {
793 print("MODEL CHANGED CALLED" + this.activePath);
794 if (this.activePath) {
795 var iter = new Gtk.TreeIter();
796 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
797 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
798 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
800 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
802 //this.currentTree = this.toJS(false, true)[0];
803 this.file.items = this.toJS(false, false);
804 print("AFTER CHANGED");
805 //console.dump(this.file.items);
807 this.currentTree = this.file.items[0];
808 //console.log(this.file.toSource());
811 print("REDNER BROWSER?!");
812 this.get('/LeftTree').renderView();
814 var pm = this.get('/RightPalete.model');
815 if (!this.get('/RightPalete').provider) {
821 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
822 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
826 deleteSelected : function() {
827 this.get('/LeftTree.view').blockChanges = true;
828 var old_iter = new Gtk.TreeIter();
829 var s = this.get('/LeftTree.view').selection;
830 s.get_selected(this.el, old_iter);
831 var path = this.el.get_path(old_iter).to_string();
833 this.activePath= false;
836 this.activePath= false;
837 var iter = new Gtk.TreeIter();
838 this.el.get_iter_from_string(iter, path);
839 this.el.remove(iter);
841 // rebuild treemap. -- depreciated.!!
844 //this.toJS(null, true) // does not do anything?
845 this.activePath= false;
846 this.changed(false,true);
847 this.get('/LeftTree.view').blockChanges = false;
849 dropNode : function(target_data, node) {
852 console.dump(target_data);
853 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
855 print("add " + tp + "@" + target_data[1] );
858 if (tp && target_data[1] < 2) { // before or after..
859 var ar = target_data[0].split(':');
861 parent = new Gtk.TreePath.from_string( ar.join(':') );
864 var n_iter = new Gtk.TreeIter();
865 var iter_par = new Gtk.TreeIter();
866 var iter_after = after ? new Gtk.TreeIter() : false;
870 if (parent !== false) {
871 this.el.get_iter(iter_par, parent);
878 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
879 this.el.get_iter(iter_after, after);
880 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
881 n_iter, iter_par, iter_after);
884 this.el.append(n_iter, iter_par);
888 if (typeof(node) == 'string') {
889 var ar = node.split('.');
890 var xtype = ar.pop();
893 '|xns' : ar.join('.'),
896 if (target_data.length == 3 && target_data[2].length) {
897 node['*prop'] = target_data[2];
901 // work out what kind of packing to use..
902 if (typeof(node.pack) == 'undefined' && parent !== false) {
903 var pal = this.get('/LeftTree').getPaleteProvider();
905 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
906 print ("PNAME : " + pname);
907 var cname = pal.guessName(node);
908 print ("CNAME : " + cname);
909 node.pack = pal.getDefaultPack(pname, cname);
920 // load children - if it has any..
923 this.load(xitems, n_iter);
925 if (tp && (xitems || after)) {
926 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
928 // wee need to get the empty proptypes from somewhere..
930 //var olditer = this.activeIter;
931 this.activePath = this.el.get_path(n_iter).to_string();
933 // changed actually set's the node data..
934 this.changed(node, true);
938 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
940 //Builder.MidPropTree._model.load(node);
941 //Builder.MidPropTree._win.hideWin();
942 //Builder.LeftPanel._model.load( node);
946 findDropNode : function(treepath_str, targets) {
948 // this is used by the dragdrop code in the roo version AFAIR..
950 var path = treepath_str.replace(/^builder-/, '');
951 // treemap is depreciated... - should really check if model has any entries..
953 if (!this.el.iter_n_children(null)) {
955 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
957 print("FIND treepath: " + path);
958 //console.dump(this.treemap);
960 if (!treepath_str.match(/^builder-/)) {
961 return []; // nothing!
963 if (targets === true) {
966 return this.findDropNodeByPath(path,targets)
968 findDropNodeByPath : function(treepath_str, targets, pref) {
969 var path = treepath_str + ''; // dupe it..
970 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
972 //console.dump(this.treemap);
973 while (path.length) {
974 print("LOOKING FOR PATH: " + path);
975 var node_data = this.singleNodeToJS(path);
976 if (node_data === false) {
977 print("node not found");
981 var xname = this.get('/LeftTree.model').file.guessName(node_data);
984 targets.forEach(function(tg) {
988 if ((tg == xname) ) {
991 if (tg.indexOf(xname +':') === 0) {
993 prop = tg.split(':').pop();
998 if (last) { // pref is after/before..
999 // then it's after last
1001 return []; // do not allow..
1003 return [ last, pref , prop];
1006 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1008 var par = path.split(':');
1011 path = par.join(':');
1017 getIterValue : function (iter, col) {
1018 var gval = new GObject.Value('');
1019 this.el.get_value(iter, col ,gval);
1025 XObject.prototype.init.call(this);
1026 this.el.set_column_types ( 3, [
1027 GObject.TYPE_STRING, // title
1028 GObject.TYPE_STRING, // tip
1029 GObject.TYPE_STRING // source..
1032 listAllTypes : function() {
1033 var s = this.get('/LeftTree.view').selection;
1034 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1036 if (s.count_selected_rows() > 0) {
1037 var iter = new Gtk.TreeIter();
1038 s.get_selected(this.el, iter);
1040 // set some properties of the tree for use by the dropped element.
1041 var value = new GObject.Value('');
1042 this.el.get_value(iter, 2, value);
1043 var data = JSON.parse(value.value);
1046 var xname = this.get('/LeftTree.model').file.guessName(data);
1047 console.log('selected:' + xname);
1051 return []; // could not find it..
1059 li.forEach(function(el) {
1060 // this is specific to roo!!!?
1062 var fullpath = _this.file.guessName(el);
1063 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1068 if (el.items && el.items.length) {
1077 addall([this.currentTree]);
1079 // only if we have nothing, should we add '*top'
1083 //console.log('all types in tree');
1084 //console.dump(ret);
1089 load : function(tr,iter)
1091 var citer = new Gtk.TreeIter();
1092 //this.insert(citer,iter,0);
1093 for(var i =0 ; i < tr.length; i++) {
1095 this.el.insert(citer,iter,-1);
1097 this.el.append(citer);
1100 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1101 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1102 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1103 if (tr[i].items && tr[i].items.length) {
1104 this.load(tr[i].items, citer);
1108 loadFile : function(f) {
1114 console.log('missing file');
1118 // load the file if not loaded..
1119 if (f.items === false) {
1121 f.loadItems(function() {
1127 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1129 if (f.items.length && typeof(f.items[0]) == 'string') {
1131 this.get('/RightEditor').el.show();
1132 this.get('/RightEditor.view').load( f.items[0]);
1136 //console.dump(f.items);
1138 this.get('/LeftTree.view').el.expand_all();
1140 if (!f.items.length) {
1143 this.get('/Window.leftvpaned').el.set_position(80);
1145 this.get('/LeftTree.view').el.set_cursor(
1146 new Gtk.TreePath.from_string('0'), null, false);
1150 this.get('/Window.leftvpaned').el.set_position(200);
1154 //print("hide right editior");
1155 this.get('/RightEditor').el.hide();
1156 //print("set current tree");
1157 this.currentTree = this.toJS(false, false)[0];
1158 //console.dump(this.currentTree);
1159 this.currentTree = this.currentTree || { items: [] };
1160 this.get('/LeftTree').renderView();
1161 //console.dump(this.map);
1162 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1163 var pm = this.get('/RightPalete.model');
1164 // set up provider..
1166 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1168 if (!this.get('/RightPalete').provider) {
1169 print ("********* PALETE PROVIDER MISSING?!!");
1171 this.get('/LeftTree').renderView();
1173 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1177 this.get('/Window.view-notebook').el.set_current_page(
1178 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1181 moveNode : function(target_data, action) {
1182 //print("MOVE NODE");
1183 // console.dump(target_data);
1184 var old_iter = new Gtk.TreeIter();
1185 var s = this.get('/LeftTree.view').selection;
1186 s.get_selected(this.el, old_iter);
1187 var node = this.nodeToJS(old_iter,false);
1188 //console.dump(node);
1191 // needs to drop first, otherwise the target_data
1192 // treepath will be invalid.
1194 this.dropNode(target_data, node);
1195 if (action & Gdk.DragAction.MOVE) {
1196 // print("REMOVING OLD NODE");
1197 this.el.remove(old_iter);
1201 this.activePath= false;
1202 this.changed(false,true);
1204 nodeTip : function(c) {
1205 var ret = this.nodeTitle(c,true);
1211 if (!i.length || i[0] != '|') {
1217 if (typeof(c[i]) != 'string') {
1220 //print("prop : " + i + ':' + c[i]);
1221 if (!c[i].match(new RegExp('function'))) {
1224 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1228 ret+="\n\nMethods:" + funcs;
1233 nodeTitle : function(c, renderfull) {
1236 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1237 if (sr) txt.push('<s>');
1238 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1240 if (renderfull && c['|xns']) {
1241 txt.push(c['|xns']);
1244 if (c.xtype) { txt.push(c.xtype); }
1245 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1246 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1247 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1250 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1251 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1252 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1253 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1254 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1255 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1256 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1257 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1258 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1260 // for flat classes...
1261 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1262 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1265 if (sr) txt.push('</s>');
1266 return (txt.length == 0 ? "Element" : txt.join(" "));
1268 nodeToJS : function (treepath, with_id)
1271 var iter = treepath; // API used to be iter here..
1272 if (typeof(iter) == 'string') {
1273 iter = new Gtk.TreeIter();
1274 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1278 var par = new Gtk.TreeIter();
1279 var iv = this.getIterValue(iter, 2);
1280 // print("IV" + iv);
1281 var k = JSON.parse(iv);
1282 if (k.json && !this.el.iter_parent( par, iter )) {
1287 var treepath_str = this.el.get_path(iter).to_string();
1288 // not sure how we can handle mixed id stuff..
1289 if (typeof(k.id) == 'undefined') {
1290 k.id = 'builder-'+ treepath_str ;
1294 this.treemap[ treepath_str ] = k;
1295 k.xtreepath = treepath_str ;
1298 if (this.el.iter_has_child(iter)) {
1299 citer = new Gtk.TreeIter();
1300 this.el.iter_children(citer, iter);
1301 k.items = this.toJS(citer,with_id);
1305 nodeToJSON : function(c) {
1313 return JSON.stringify(o);
1315 singleNodeToJS : function (treepath)
1317 var iter = new Gtk.TreeIter();
1318 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1322 var iv = this.getIterValue(iter, 2);
1324 return JSON.parse(iv);
1327 toJS : function(iter, with_id)
1329 //Seed.print("WITHID: "+ with_id);
1336 iter = new Gtk.TreeIter();
1337 if (!this.el.get_iter_first(iter)) {
1347 var k = this.nodeToJS(iter, with_id);
1351 if (!this.el.iter_next(iter)) {
1357 // convert the list into a json string..
1363 xtype: Gtk.TreeViewColumn,
1364 pack : "append_column",
1366 XObject.prototype.init.call(this);
1367 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1371 xtype: Gtk.CellRendererText,
1381 id : "LeftTreeMenu",
1384 xtype: Gtk.MenuItem,
1386 label : "Delete Element",
1388 activate : function (self) {
1390 this.get('/LeftTree.model').deleteSelected();
1395 xtype: Gtk.MenuItem,
1397 activate : function (self) {
1399 var tree = this.get('/LeftTree');
1400 var model = this.get('/LeftTree.model');
1401 var el = tree.getActivePath();
1403 var js = model.toJS(el, false);
1404 print(JSON.stringify(js));
1408 label : "Save as Template",
1418 id : "LeftProjectTree",
1419 showNoProjectSelected : function() {
1420 this.get('/StandardErrorDialog').show("Select a Project first.");
1422 getActiveProject : function() {
1423 return this.project;
1426 leave_notify_event : function (self, event) {
1433 pack : "pack_start,false,false",
1436 xtype: Gtk.ComboBox,
1439 XObject.prototype.init.call(this);
1440 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1442 getValue : function() {
1443 var ix = this.el.get_active();
1447 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1448 if (typeof(data[ix]) == 'undefined') {
1453 setValue : function(fn)
1457 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1458 data.forEach(function(n, ix) {
1466 changed : function (self) {
1467 var fn = this.getValue();
1468 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1469 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1474 xtype: Gtk.CellRendererText,
1475 pack : "pack_start,true",
1479 xtype: Gtk.ListStore,
1482 XObject.prototype.init.call(this);
1483 this.el.set_column_types ( 2, [
1484 GObject.TYPE_STRING, // real key
1485 GObject.TYPE_STRING // real type
1489 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1491 pm.on('changed', function() {
1492 print("caught changed hook on project manager - reloading data");
1493 _this.loadData(pm.projects);
1497 loadData : function(data) {
1498 var ov = this.get('/LeftProjectTree.combo').getValue();
1500 var iter = new Gtk.TreeIter();
1502 data.forEach(function(p) {
1507 el.set_value(iter, 0, p.fn);
1508 el.set_value(iter, 1, p.name);
1512 this.get('/LeftProjectTree.combo').setValue(ov);
1521 xtype: Gtk.ScrolledWindow,
1523 shadow_type : Gtk.ShadowType.IN,
1525 XObject.prototype.init.call(this);
1526 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1530 xtype: Gtk.TreeView,
1531 headers_visible : false,
1532 enable_tree_lines : true,
1535 XObject.prototype.init.call(this);
1536 var description = new Pango.FontDescription.c_new();
1537 description.set_size(8000);
1538 this.el.modify_font(description);
1540 this.selection = this.el.get_selection();
1541 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1545 cursor_changed : function (self) {
1546 var iter = new Gtk.TreeIter();
1548 if (this.selection.count_selected_rows() < 1) {
1549 //XN.get('Builder.LeftTree.model').
1550 this.get('/LeftTree.model').load( false);
1554 var model = this.get('/LeftProjectTree.model');
1555 //console.log('changed');
1556 var s = this.selection;
1557 s.get_selected(model, iter);
1558 value = new GObject.Value('');
1559 model.el.get_value(iter, 2, value);
1561 console.log(value.value);// id..
1563 var file = this.get('/LeftProjectTree').project.getById(value.value);
1570 var nb = this.get('/LeftTopPanel.expander');
1571 nb.el.expanded = false;
1572 nb.listeners.activate.call(nb);
1573 //_expander.el.set_expanded(false);
1575 var ltm = this.get('/LeftTree.model');
1583 xtype: Gtk.TreeStore,
1587 XObject.prototype.init.call(this);
1588 this.el.set_column_types ( 3, [
1589 GObject.TYPE_STRING, // title
1590 GObject.TYPE_STRING, // tip
1591 GObject.TYPE_STRING // id..
1595 loadProject : function(pr) {
1596 print("LOAD PROJECT");
1602 this.get('/LeftProjectTree').project = pr;
1603 this.load(pr.toTree());
1604 this.get('/LeftProjectTree.view').el.expand_all();
1606 load : function(tr,iter) {
1607 // console.dump(tr);
1608 console.log('Project tree load: ' + tr.length);
1609 var citer = new Gtk.TreeIter();
1610 //this.insert(citer,iter,0);
1613 tr.forEach(function (r) {
1615 _this.el.append(citer);
1617 _this.el.insert(citer,iter,-1);
1619 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1620 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1621 _this.el.set_value(citer, 2, '' + r.id ); //id
1622 if (r.cn && r.cn.length) {
1623 _this.load(r.cn, citer);
1628 getValue : function(iter, col) {
1629 var gval = new GObject.Value('');
1630 this.el.get_value(iter, col ,gval);
1631 return '' + gval.value;
1635 xtype: Gtk.TreeViewColumn,
1636 pack : "append_column",
1638 XObject.prototype.init.call(this);
1639 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1643 xtype: Gtk.CellRendererText,
1666 pack : "pack_start,false,true,0",
1673 button_press_event : function (self, event) {
1674 this.get('/MidPropTree.model').showData('props');
1686 stock : Gtk.STOCK_ADD,
1687 icon_size : Gtk.IconSize.MENU
1702 button_press_event : function (self, event) {
1703 this.get('/MidPropTree.model').showData('events');
1715 stock : Gtk.STOCK_ADD,
1716 icon_size : Gtk.IconSize.MENU
1731 button_press_event : function (self, ev) {
1732 var p = this.get('/AddPropertyPopup');
1736 p.el.set_screen(Gdk.Screen.get_default());
1738 p.el.popup(null, null, null, null, 3, ev.button.time);
1750 stock : Gtk.STOCK_ADD,
1751 icon_size : Gtk.IconSize.MENU
1763 id : "AddPropertyPopup",
1766 xtype: Gtk.MenuItem,
1768 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1771 activate : function (self) {
1773 this.get('/LeftPanel.model').add( {
1784 xtype: Gtk.MenuItem,
1786 tooltip_markup : "Add what type of packing is to be used",
1789 activate : function (self) {
1791 this.get('/LeftPanel.model').add( {
1801 xtype: Gtk.MenuItem,
1803 tooltip_markup : "Override the init method",
1806 activate : function (self) {
1808 this.get('/LeftPanel.model').add( {
1811 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1818 xtype: Gtk.SeparatorMenuItem,
1822 xtype: Gtk.MenuItem,
1824 tooltip_markup : "Add a user defined string property",
1827 activate : function (self) {
1829 this.get('/LeftPanel.model').add( {
1839 xtype: Gtk.MenuItem,
1841 tooltip_markup : "Add a user defined number property",
1844 activate : function (self) {
1846 this.get('/LeftPanel.model').add( {
1856 xtype: Gtk.MenuItem,
1858 tooltip_markup : "Add a user defined boolean property",
1861 activate : function (self) {
1863 this.get('/LeftPanel.model').add( {
1873 xtype: Gtk.SeparatorMenuItem,
1877 xtype: Gtk.MenuItem,
1879 tooltip_markup : "Add a user function boolean property",
1882 activate : function (self) {
1884 this.get('/LeftPanel.model').add( {
1887 val : "function() {\n \n}\n",
1900 xtype: Gtk.ScrolledWindow,
1903 shadow_type : Gtk.ShadowType.IN,
1906 XObject.prototype.init.call(this);
1907 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1911 xtype: Gtk.TreeView,
1914 headers_visible : false,
1915 enable_tree_lines : true,
1917 XObject.prototype.init.call(this);
1919 this.selection = this.el.get_selection();
1920 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1923 var description = new Pango.FontDescription.c_new();
1924 description.set_size(8000);
1925 this.el.modify_font(description);
1928 button_press_event : function (self, ev) {
1932 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1933 return false; //not on a element.
1937 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1939 if (res.column.title != 'value') {
1940 return false; // ignore..
1942 if ( this.get('/LeftPanel').editing) {
1945 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1946 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1947 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1951 var provider = this.get('/LeftTree').getPaleteProvider();
1953 var opts = provider.findOptions(type);
1955 if (opts === false) {
1956 this.get('/LeftPanel').editableColumn.setOptions([]);
1957 renderer.has_entry = true;
1959 LeftPanel.editableColumn.setOptions(opts);
1960 renderer.has_entry = false;
1964 //Seed.print("click" + ev.type);
1965 //console.dump(res);
1971 if (res.column.title == 'value') {
1974 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1975 var p = this.get('/LeftPanelPopup');
1980 p.el.set_screen(Gdk.Screen.get_default());
1982 p.el.popup(null, null, null, null, 3, ev.button.time);
1983 //Seed.print("click:" + res.column.title);
1991 xtype: Gtk.TreeStore,
1995 getIterValue : function(iter, col) {
1996 var gval = new GObject.Value('');
1997 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
1998 return '' + gval.value;
2000 add : function(info) {
2001 // info includes key, val, skel, etype..
2003 type = info.type.toLowerCase();
2004 var data = this.toJS();
2006 if (info.etype == 'events') {
2007 data.listeners = data.listeners || { };
2008 if (typeof(data.listeners[info.key]) != 'undefined') {
2009 return; //already set!
2012 if (typeof(data[info.key]) != 'undefined') {
2017 if (typeof(info.val) == 'undefined') {
2020 if (info.type == 'boolean') {
2023 if (type == 'number') {
2031 if (info.etype == 'events') {
2033 data.listeners[info.key] = info.val;
2036 data[info.key] = info.val;
2040 var map = this.load(data);
2042 // flag it as changed to the interface..
2044 this.get('/LeftTree.model').changed(data, true);
2047 this.startEditing(map[k]);
2050 LeftPanel.get('view').el.row_activated(
2051 new Gtk.TreePath.from_string(map[k]),
2052 LeftPanel.editableColumn.el
2056 changed : function(str, doRefresh) {
2057 if (!this.activePath) {
2060 var iter = new Gtk.TreeIter();
2061 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2063 this.el.set_value(iter, 1, '' +str);
2064 this.el.set_value(iter, 3, '' + this.toShort(str));
2065 var type = this.getIterValue(iter, 4);
2067 this.el.set_value(iter, 5, type + ' : ' + str);
2068 // update the tree...
2070 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2072 deleteSelected : function() {
2073 var data = this.toJS();
2074 var iter = new Gtk.TreeIter();
2075 var s = this.get('/LeftPanel.view').selection;
2076 s.get_selected(this.el, iter);
2079 var gval = new GObject.Value('');
2080 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2082 var val = gval.value;
2083 if (val[0] == '!') {
2085 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2088 delete data.listeners[ val.substring(1)];
2089 if (!XObject.keys(data.listeners).length) {
2090 delete data.listeners;
2094 if (typeof(data[val]) == 'undefined') {
2102 this.get('/LeftTree.model').changed(data, true);
2105 editSelected : function(e) {
2106 print("EDIT SELECTED?");
2107 var iter = new Gtk.TreeIter();
2108 var s = this.get('/LeftPanel.view').selection;
2109 s.get_selected(this.get('/LeftPanel.model').el, iter);
2110 var m = this.get('/LeftPanel.model')
2112 var gval = new GObject.Value('');
2113 this.el.get_value(iter, 0 ,gval);
2114 var val = '' + gval.value;
2116 gval = new GObject.Value('');
2117 this.el.get_value(iter, 1 ,gval);
2118 var rval = gval.value;
2119 var activePath = this.el.get_path(iter).to_string();
2120 this.activePath = activePath ;
2121 // was activeIter...
2124 var showEditor = false;
2126 if (val[0] == '!') {
2129 if (val[0] == '|') {
2130 if (rval.match(/function/g) || rval.match(/\n/g)) {
2137 this.activePath = false;
2138 GLib.timeout_add(0, 1, function() {
2139 // Gdk.threads_enter();
2140 _this.get('/BottomPane').el.show();
2141 _this.get('/RightEditor').el.show();
2142 _this.get('/RightEditor.view').load( rval );
2146 _this.activePath = activePath ;
2148 // Gdk.threads_leave();
2153 this.get('/BottomPane').el.hide();
2154 this.get('/RightEditor').el.hide();
2156 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2160 getType : function(treepath) {
2161 return this.getValue(treepath, 4);
2163 getValue : function(treepath_str, col) {
2164 var iter = new Gtk.TreeIter();
2165 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2167 var gval = new GObject.Value('');
2168 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2169 var val = '' + gval.value;
2173 var type = this.getType(this.el.get_path(iter).to_string());
2174 print("TYPE: " +type + " - val:" + val);
2175 switch(type.toLowerCase()) {
2179 return parseFloat(val); // Nan ?? invalid!!?
2182 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2184 return val == 'true' ? true : false;
2186 var nv = parseFloat(val);
2187 if (!isNaN(nv) && (val == ''+nv)) {
2195 XObject.prototype.init.call(this);
2196 this.el.set_column_types ( 6, [
2197 GObject.TYPE_STRING, // 0 real key
2198 GObject.TYPE_STRING, // 1 real value
2199 GObject.TYPE_STRING, // 2 visable key
2200 GObject.TYPE_STRING, // 3 visable value
2201 GObject.TYPE_STRING, // 4 need to store type of!!!
2202 GObject.TYPE_STRING // 5 tooltip
2206 load : function(ar) {
2209 this.get('/RightEditor').el.hide();
2216 var provider = this.get('/LeftTree').getPaleteProvider();
2217 var iter = new Gtk.TreeIter();
2220 var keys = XObject.keys(ar);
2222 ar.listeners = ar.listeners || {};
2224 for (var i in ar.listeners ) {
2225 this.el.append(iter);
2226 var p = this.el.get_path(iter).to_string();
2229 this.el.set_value(iter, 0, '!'+ i );
2230 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2231 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2233 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2234 this.el.set_value(iter, 4, 'function');
2235 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2241 keys.forEach(function(i) {
2242 if (typeof(ar[i]) == 'object') {
2246 var type = provider.findType(ar, i, ar[i]);
2248 _this.el.append(iter);
2249 var p = _this.el.get_path(iter).to_string();
2251 _this.el.set_value(iter, 0, ''+i);
2252 _this.el.set_value(iter, 1, '' + ar[i]);
2253 _this.el.set_value(iter, 2, ''+i);
2254 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2255 _this.el.set_value(iter, 4, ''+type);
2256 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2260 startEditing : function(path,col) {
2262 * start editing path (or selected if not set..)
2263 * @param {String|false} path (optional) treepath to edit - selected tree gets
2264 * edited by default.
2265 * @param {Number} 0 or 1 (optional)- column to edit.
2268 if (typeof(path) == 'string') {
2269 tp = new Gtk.TreePath.from_string(path);
2271 var iter = new Gtk.TreeIter();
2272 var s = this.get('/LeftPanel.view').selection;
2273 s.get_selected(this.el, iter);
2274 tp = this.el.get_path(iter);
2275 path = tp.to_string();
2279 // which colum is to be edited..
2281 if (typeof(col) == 'undefined') {
2282 var k = this.getValue(path, 0);
2283 colObj = (!k.length || k == '|') ?
2284 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2286 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2289 // make sure the pulldown is set correctly..
2290 // not really needed for second col...
2292 var provider = this.get('/LeftTree').getPaleteProvider();
2294 var type = this.get('/LeftPanel.model').getType(path);
2295 var opts = provider.findOptions(type);
2296 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2298 if (opts === false) {
2299 this.get('/LeftPanel').editableColumn.setOptions([]);
2300 renderer.has_entry = true; /// probably does not have any effect.
2302 this.get('/LeftPanel').editableColumn.setOptions(opts);
2303 renderer.has_entry = false;
2307 // iter now has row...
2308 GLib.timeout_add(0, 100, function() {
2310 colObj.items[0].el.editable = true; // esp. need for col 0..
2311 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2321 var iter = new Gtk.TreeIter();
2322 this.get('/LeftPanel.model').el.get_iter_first(iter);
2327 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2330 ar.listeners = ar.listeners || {};
2331 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2334 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2337 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2343 //print(JSON.stringify(ar));
2347 toShort : function(str) {
2348 var a = typeof(str) == 'string' ? str.split("\n") : [];
2349 return a.length > 1 ? a[0] + '....' : '' + str;
2353 xtype: Gtk.TreeViewColumn,
2354 pack : "append_column",
2356 XObject.prototype.init.call(this);
2358 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2359 this.get('/LeftPanel').propertyColumn = this;
2364 xtype: Gtk.CellRendererText,
2365 pack : "pack_start",
2367 editing_started : function (self, editable, path) {
2369 this.get('/LeftPanel.model').activePath = path;
2372 edited : function (self, object, p0) {
2373 var model = this.get('/LeftPanel.model');
2374 var path = model.activePath;
2375 var iter = new Gtk.TreeIter();
2376 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2377 model.el.set_value(iter, 0, p0);
2378 model.el.set_value(iter, 2, p0);
2380 model.activePath = false;
2382 this.get('/LeftTree.model').changed(model.toJS(), true);
2383 this.el.editable = false;
2390 xtype: Gtk.TreeViewColumn,
2391 pack : "append_column",
2393 XObject.prototype.init.call(this);
2394 this.el.add_attribute(this.items[0].el , 'text', 3 );
2395 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2396 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2397 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2399 this.get('/LeftPanel').editableColumn= this;
2401 setOptions : function(ar) {
2402 var m = this.items[0].el.model;
2404 var iter = new Gtk.TreeIter();
2405 ar.forEach(function(i) {
2408 m.set_value(iter, 0, i);
2414 xtype: Gtk.CellRendererCombo,
2415 pack : "pack_start",
2420 XObject.prototype.init.call(this);
2421 this.el.model = new Gtk.ListStore();
2422 this.el.model.set_column_types ( 1, [
2423 GObject.TYPE_STRING // 0 real key
2427 edited : function (self, object, p0) {
2428 this.get('/LeftPanel').editing = false;
2429 print("EDITED? p:" + p0 + " t:" + p0);
2430 this.get('/LeftPanel.model').changed(p0, true);
2431 this.get('/LeftPanel.model').activePath = false;
2433 editing_started : function (self, editable, path) {
2434 this.get('/LeftPanel').editing = true;
2435 // console.log('editing started');
2436 // r.has_entry = false;
2437 this.get('/LeftPanel.model').editSelected(editable);
2448 id : "LeftPanelPopup",
2451 xtype: Gtk.MenuItem,
2455 activate : function (self) {
2456 this.get('/LeftPanel.model').deleteSelected();
2461 xtype: Gtk.MenuItem,
2465 activate : function (self) {
2466 this.get('/LeftPanel.model').startEditing(false, 0);
2479 xtype: Gtk.ScrolledWindow,
2480 pack : "pack_end,false,true,0",
2482 shadow_type : Gtk.ShadowType.IN,
2484 XObject.prototype.init.call(this);
2485 XObject.prototype.init.call(this);
2486 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2487 this.el.set_size_request ( 150, -1 );
2490 activeElement : false,
2491 hideWin : function() {
2498 if (this.get('/Window.left').el.position < 160) {
2501 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2508 xtype: Gtk.TreeView,
2509 enable_tree_lines : true,
2510 headers_visible : false,
2513 XObject.prototype.init.call(this);
2515 var description = new Pango.FontDescription.c_new();
2516 description.set_size(8000);
2517 this.el.modify_font(description);
2519 //this.selection = this.el.get_selection();
2520 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2529 cursor_changed : function (self) {
2530 var iter = new Gtk.TreeIter();
2532 //console.log('changed');
2533 var m = this.get('model');
2534 if (!this.selection){
2535 this.selection = this.el.get_selection();
2538 var s = this.selection;
2539 if (!s.get_selected(m.el, iter)) {
2542 var tp = m.el.get_path(iter).to_string();
2547 var key = m.getValue(tp, 0);
2549 var type = m.getValue(tp, 1);
2550 var skel = m.getValue(tp, 3);
2551 var etype = m.getValue(tp, 5);
2554 this.get('/MidPropTree').hideWin();
2556 if (type == 'function') {
2558 if (etype != 'events') {
2562 this.get('/LeftPanel.model').add({
2571 if (type.indexOf('.') > -1 ||
2572 type == 'boolean') {
2576 this.get('/LeftPanel.model').add( {
2586 xtype: Gtk.ListStore,
2589 XObject.prototype.init.call(this);
2590 this.el.set_column_types ( 6, [
2591 GObject.TYPE_STRING, // real key
2592 GObject.TYPE_STRING, // real type
2593 GObject.TYPE_STRING, // docs ?
2594 GObject.TYPE_STRING, // visable desc
2595 GObject.TYPE_STRING, // function desc
2596 GObject.TYPE_STRING // element type (event|prop)
2600 getValue : function(treepath, col)
2602 var tp = new Gtk.TreePath.from_string (treepath);
2603 var iter = new Gtk.TreeIter();
2604 this.el.get_iter (iter, tp);
2605 var value = new GObject.Value('');
2606 this.el.get_value(iter, col, value);
2610 showData : function(type) {
2612 if (!this.get('/MidPropTree').activeElement || !type) {
2613 return; // no active element
2616 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2617 var palete = this.get('/LeftTree').getPaleteProvider();
2621 Seed.print('Showing right?');
2622 if (!this.get('/MidPropTree').shown) {
2624 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2625 this.get('/MidPropTree').el.show();
2626 this.get('/MidPropTree').shown = true;
2629 var elementList = palete.getPropertiesFor(fullpath, type);
2630 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2631 // console.dump(elementList);
2634 var iter = new Gtk.TreeIter();
2635 for(var i =0 ; i < elementList.length; i++) {
2636 var p=elementList[i];
2637 this.el.append(iter);
2638 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2639 //GObject.TYPE_STRING, // real key
2640 // GObject.TYPE_STRING, // real type
2641 // GObject.TYPE_STRING, // docs ?
2642 // GObject.TYPE_STRING // func def?
2645 this.el.set_value(iter, 0, p.name);
2646 this.el.set_value(iter, 1, p.type);
2647 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2648 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2649 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2650 this.el.set_value(iter, 5, type);
2658 xtype: Gtk.TreeViewColumn,
2660 this.el = new Gtk.TreeViewColumn();
2661 this.parent.el.append_column(this.el);
2663 XObject.prototype.init.call(this);
2664 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2669 xtype: Gtk.CellRendererText,
2670 pack : "pack_start,true"
2694 xtype: Gtk.Notebook,
2695 pack : "pack_start,true,true",
2696 id : "view-help-nb",
2698 XObject.prototype.init.call(this);
2699 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2700 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2704 xtype: Gtk.Notebook,
2706 id : "view-notebook",
2709 XObject.prototype.init.call(this);
2710 this.el.set_current_page(0);
2712 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2713 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2720 id : "RightBrowser",
2726 xtype: Gtk.ScrolledWindow,
2728 shadow_type : Gtk.ShadowType.IN,
2730 XObject.prototype.init.call(this);
2731 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2735 xtype: WebKit.WebView,
2739 XObject.prototype.init.call(this);
2740 // this may not work!?
2741 this.el.open('file:///' + __script_path__ + '/../builder.html');
2745 this.el, /* widget that will accept a drop */
2746 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2747 null, /* lists of target to support */
2748 0, /* size of list */
2749 Gdk.DragAction.COPY /* what to do with data after dropped */
2752 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2753 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2755 renderJS : function(data) {
2756 print("HTML RENDERING");
2757 /// prevent looping..
2758 //if (this.pendingRedraw) {
2759 // print("pending redraw active?!");
2764 if (!this.get('/Window.LeftTree').getActiveFile()) {
2768 var project = this.get('/Window.LeftTree').getActiveFile().project;
2769 //print (project.fn);
2771 project.runhtml = project.runhtml || '';
2774 this.runhtml = this.runhtml || '';
2776 if (project.runhtml != this.runhtml) {
2777 // then we need to reload the browser using
2778 // load_html_string..
2780 // then trigger a redraw once it's loaded..
2781 this.pendingRedraw = true;
2783 this.runhtml = project.runhtml;
2785 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2786 html = html.replace('</head>', this.runhtml + '</head>');
2787 print("LOAD HTML " + html);
2788 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2789 // should trigger load_finished!
2794 this.pendingRedraw = false;
2797 this.renderedData = data;
2798 var str = JSON.stringify(data) ;
2801 console.log('not loaded yet');
2803 //Seed.print("RENDER:" + str);
2804 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2806 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2809 load_finished : function (self, object) {
2810 // if (this.ready) { // dont do it twice!
2814 this.pendingRedraw = false;
2815 var js = this.get('/LeftTree.model').toJS();
2817 this.renderJS(js[0]);
2821 script_alert : function (self, object, p0) {
2824 return true; // do not display anything...
2826 console_message : function (self, object, p0, p1) {
2827 // console.log(object);
2828 if (!object.match(/^\{/)) {
2830 this.get('/Terminal').feed(object);
2831 return true; // do not handle!!! -> later maybe in console..
2833 // console.log(object);
2834 var val = JSON.parse(object);
2836 if (typeof(val['hover-node']) != 'undefined') {
2837 this.activeNode = val['hover-node'];
2838 console.log('active node: ' + this.activeNode);
2843 if (typeof(val['id']) != 'undefined') {
2844 // this.activeNode = val['id'];
2845 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2849 this.get('/LeftTree.view').selectNode(tg[0]);
2853 if (ret && typeof(val['set']) != 'undefined') {
2854 this.get('/LeftPanel.model').add({
2858 //console.log('active node: ' + this.activeNode);
2861 //Seed.print('a:'+a);
2862 //Seed.print('b:'+b);
2863 //Seed.print('c:'+c);
2866 drag_motion : function (w, ctx, x, y, time, ud) {
2867 // console.log('DRAG MOTION');
2869 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2870 this.targetData = [];
2871 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2873 // A) find out from drag all the places that node could be dropped.
2874 var src = Gtk.drag_get_source_widget(ctx);
2875 if (!src.dropList) {
2876 Gdk.drag_status(ctx, 0, time);
2879 // b) get what we are over.. (from activeNode)
2880 // tree is empty.. - list should be correct..
2881 if (!this.get('/LeftTree.model').currentTree) {
2882 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2886 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2888 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2891 Gdk.drag_status(ctx, 0,time);
2892 this.get('/LeftTree.view').highlight(false);
2896 // if we have a target..
2897 // -> highlight it! (in browser)
2898 // -> highlight it! (in tree)
2900 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2901 this.get('/LeftTree.view').highlight(tg);
2902 this.targetData = tg;
2903 // for tree we should handle this...
2906 drag_drop : function (w, ctx, x, y,time, ud) {
2907 print("TARGET: drag-drop");
2908 var is_valid_drop_site = true;
2913 w, /* will receive 'drag-data-received' signal */
2914 ctx, /* represents the current state of the DnD */
2915 this.get('/Window').atoms["STRING"], /* the target type we want */
2916 time /* time stamp */
2920 /* No target offered by source => error */
2923 return is_valid_drop_site;
2925 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2927 print("Browser: drag-data-received");
2928 var delete_selection_data = false;
2929 vardnd_success = false;
2930 /* Deal with what we are given from source */
2931 if( sel_data && sel_data.length ) {
2933 if (ctx.action == Gdk.DragAction.ASK) {
2934 /* Ask the user to move or copy, then set the ctx action. */
2937 if (ctx.action == Gdk.DragAction.MOVE) {
2938 delete_selection_data = true;
2940 var source = Gtk.drag_get_source_widget(ctx);
2942 print("Browser: source.DRAGDATA? " + source.dragData);
2943 if (this.targetData) {
2944 print(this.targetData);
2945 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2954 if (dnd_success == false)
2956 Seed.print ("DnD data transfer failed!\n");
2959 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2970 id : "RightGtkView",
2972 redraw : function() {
2973 this.highlightWidget = false;
2974 print("REDRAW CALLED");
2975 this.activePath = this.get('/LeftTree').getActivePath();
2976 if (this.renderedEl) {
2977 print("QUEUE DRAW CALLING");
2978 this.renderedEl.queue_draw();
2981 renderJS : function(data, withDebug)
2983 this.highlightWidget = false;
2987 this.withDebug = false;
2989 if (this.renderedEl) {
2990 this.get('view').el.remove(this.renderedEl);
2991 this.renderedEl.destroy();
2992 this.renderedEl = false;
2995 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
2996 // in theory tree is actually window..
2998 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3003 this.get('view').el.set_size_request(
3004 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3007 this.renderedEl.set_size_request(
3008 tree.default_width || 600,
3009 tree.default_height || 400
3011 this.get('view').el.show_all();
3016 showInWindow : function() {
3017 print("GET PROEJCT");
3018 var pr = this.get('/LeftProjectTree').getActiveProject();
3020 console.log(pr.paths);
3023 var src= this.buildJS(
3024 this.get('/LeftTree.model').toJS()[0],
3029 //var x = new imports.sandbox.Context();
3033 Seed.check_syntax('var e = ' + src);
3036 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3037 this.get('/Terminal').feed(console._dump(e)+"\n");
3039 var lines = src.split("\n");
3040 var start = Math.max(0, e.line - 10);
3041 var end = Math.min(lines.length, e.line + 10);
3042 for (var i =start ; i < end; i++) {
3044 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3047 this.get('/Terminal').feed(lines[i] + "\n");
3054 this.get('/BottomPane').el.set_current_page(1);
3055 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3056 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3057 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3059 var _top = x.get_global_object()._top;
3061 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3063 if (_top.el.popup) {
3064 _top.el.popup(null, null, null, null, 3, null);
3068 viewAdd : function(item, par)
3070 // does something similar to xobject..
3071 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3073 if (item.pack===false || item.pack === 'false') { // no ;
3076 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3077 var type = item['|xns'] + '.' + item['xtype'];
3078 var ns = imports.gi[item['|xns']];
3079 var ctr = ns[item['xtype']];
3081 for(var k in item) {
3083 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3098 if (k[0] == '|' && typeof(kv) == 'string') {
3100 if (kv.match(new RegExp('function'))) {
3103 print("WASL " + k + '=' + kv);
3105 eval( 'kv = ' + kv);
3106 } catch(e) { continue; }
3109 // print(k + '=' + kv);
3111 if (k[0] == '|') { // should be boolean or number..
3113 //print(k + '=' + kv);
3116 if (k == 'show_tabs') { // force tab showing for notebooks.
3119 print(k + '=' + typeof(kv) + " : " + kv);
3125 var el = new ctr(ctr_args);
3127 print("PACK" + item.pack);
3128 //console.dump(item.pack);
3135 if (typeof(item.pack) == 'string') {
3137 item.pack.split(',').forEach(function(e, i) {
3139 if (e == 'false') { args.push( false); return; }
3140 if (e == 'true') { args.push( true); return; }
3141 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3144 //print(args.join(","));
3146 pack_m = args.shift();
3148 pack_m = item.pack.shift();
3153 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3155 name: "ArgumentError",
3156 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3157 "ADDING : " + item.id + " " + el
3166 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3167 //Seed.print('args: ' + args.length);
3169 par[pack_m].apply(par, args);
3173 item.items = item.items || [];
3174 item.items.forEach(function(ch,n) {
3176 print ("type:" + type);
3178 print ("ch.pack:" + ch.pack);
3179 if (type == 'Gtk.Table' && ch.pack == 'add') {
3180 var c = n % item.n_columns;
3181 var r = Math.floor(n/item.n_columns);
3182 ch.pack = [ 'attach', c, c+1, r, r+1,
3183 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3184 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3185 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3186 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3190 _this.viewAdd(ch, el);
3195 // add the signal handlers.
3196 // is it a widget!?!!?
3202 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3203 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3204 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3205 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3206 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3216 widgetDragDropEvent : function() {
3217 print("WIDGET DRAGDROP");
3220 widgetDragMotionEvent : function() {
3221 print("WIDGET DRAGMOTION");
3224 widgetExposeEvent : function(w, evt, ud, item) {
3226 if (this.inRender) {
3230 if ( this.highlightWidget) {
3231 this.inRender = true;
3232 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3233 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3235 this.inRender = false;
3240 if (this.activePath != item.xtreepath) {
3244 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3245 // work out the coords of the window..
3247 var dr = widget.window;
3248 this.gc = (new Gdk.GC.c_new(dr));
3249 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3250 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3254 var r = evt.expose.area;
3255 // console.dump([r.x, r.y, r.width, r.height ] );
3257 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3258 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3259 // happens with gtkscrollview embedded stuff..
3260 var np =this.activePath.split(':');
3262 this.activePath = np.join(':');
3263 this.renderedEl.queue_draw();
3279 this.inRender = true;
3282 this.highlightWidget = widget;
3287 // print("DRAW BOX");
3288 //console.dump(this.box);
3289 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3290 this.inRender = false;
3293 widgetPressEvent : function(w,e,u,d) {
3294 if (this.get('view').pressed) {
3297 this.get('view').pressed = true;
3298 print("WIDGET PRESS " + d.xtreepath );
3299 this.get('/LeftTree.view').selectNode( d.xtreepath );
3302 widgetReleaseEvent : function() {
3303 this.get('view').pressed = false;
3309 pack : "pack_start,false,true,0",
3313 pack : "pack_start,false,false,0",
3314 label : "Run The Application",
3316 button_press_event : function (self, event) {
3317 // call render on left tree - with special option!?!
3319 //print("GET PROEJCT");
3320 var pr = this.get('/LeftProjectTree').getActiveProject();
3323 for (var i in pr.paths) {
3327 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3328 this.get('/Terminal').feed("RUN DIR:" + dir);
3330 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3331 , false,false,false);
3332 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3333 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3343 xtype: Gtk.ScrolledWindow,
3346 shadow_type : Gtk.ShadowType.IN,
3348 XObject.prototype.init.call(this);
3349 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3353 xtype: Gtk.EventBox,
3354 pack : "add_with_viewport",
3356 XObject.prototype.init.call(this);
3357 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3358 red: 0x9F00, green: 0xB800 , blue : 0xA800
3366 XObject.prototype.init.call(this);
3367 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3368 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3373 xtype: Gtk.EventBox,
3376 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3377 XObject.prototype.init.call(this);
3381 this.el, /* widget that will accept a drop */
3382 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3383 null, /* lists of target to support */
3384 0, /* size of list */
3385 Gdk.DragAction.COPY /* what to do with data after dropped */
3388 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3389 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3392 getActiveNode : function(x,y)
3394 // workout what node is here..
3395 return '0'; // top..
3399 drag_motion : function (self, ctx, x, y, time) {
3401 // A) find out from drag all the places that node could be dropped.
3402 var src = Gtk.drag_get_source_widget(ctx);
3403 if (!src.dropList) {
3404 Gdk.drag_status(ctx, 0, time);
3407 // b) get what we are over.. (from activeNode)
3408 // tree is empty.. - list should be correct..
3409 if (!this.get('/LeftTree.model').currentTree) {
3410 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3414 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3415 var activeNode = this.getActiveNode(x, y);
3418 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3421 Gdk.drag_status(ctx, 0,time);
3422 this.get('/LeftTree.view').highlight(false);
3426 // if we have a target..
3427 // -> highlight it! (in browser)
3428 // -> highlight it! (in tree)
3430 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3431 this.get('/LeftTree.view').highlight(tg);
3432 this.targetData = tg;
3433 // for tree we should handle this...
3436 drag_drop : function (self,ctx, x, y, time) {
3437 Seed.print("TARGET: drag-drop");
3438 var is_valid_drop_site = true;
3443 self, /* will receive 'drag-data-received' signal */
3444 ctx, /* represents the current state of the this.gDnD */
3445 this.get('/Window').atoms["STRING"], /* the target type we want */
3446 time /* time stamp */
3450 /* No target offered by source => error */
3453 return is_valid_drop_site;
3456 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3458 Seed.print("GtkView: drag-data-received");
3459 var delete_selection_data = false;
3460 var dnd_success = false;
3461 /* Deal with what we are given from source */
3462 if( sel_data && sel_data.length ) {
3464 if (ctx.action == Gdk.DragAction.ASK) {
3465 /* Ask the user to move or copy, then set the ctx action. */
3468 if (ctx.action == Gdk.DragAction.MOVE) {
3469 delete_selection_data = true;
3471 var source = Gtk.drag_get_source_widget(ctx);
3473 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3474 if (this.targetData) {
3475 Seed.print(this.targetData);
3476 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3485 if (dnd_success == false)
3487 Seed.print ("DnD data transfer failed!\n");
3490 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3493 button_press_event : function (self, event) {
3494 this.pressed = false;
3510 xtype: Gtk.ScrolledWindow,
3515 var file = this.get('/LeftTree').getActiveFile();
3519 var activeEl = this.get('/LeftTree').getActiveElement();
3520 var xtype = file.guessName( activeEl )
3521 if (!xtype || !xtype.length) {
3524 this.get('/Window.view-help-nb').el.set_current_page(1);
3526 // get the active element being edited.
3527 var helpurl = file.getHelpUrl(xtype);
3529 // now load the help info in the page..
3530 this.get('help-view').el.open(helpurl);
3534 xtype: WebKit.WebView,
3538 XObject.prototype.init.call(this);
3539 this.get('/Window.help-view').el.open(
3540 "http://devel.akbkhome.com/seed/");
3552 xtype: Gtk.Notebook,
3555 XObject.prototype.init.call(this);
3556 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3557 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3562 xtype: Gtk.ScrolledWindow,
3567 xtype: GtkSource.View,
3571 XObject.prototype.init.call(this);
3572 var description = Pango.Font.description_from_string("monospace")
3573 description.set_size(8000);
3574 this.el.modify_font(description);
3577 load : function(str) {
3579 // show the help page for the active node..
3580 this.get('/Help').show();
3583 this.get('/BottomPane').el.set_current_page(0);
3584 this.el.get_buffer().set_text(str, str.length);
3585 var lm = GtkSource.LanguageManager.get_default();
3587 this.el.get_buffer().set_language(lm.get_language('js'));
3588 var buf = this.el.get_buffer();
3589 var cursor = buf.get_mark("insert");
3590 var iter= new Gtk.TextIter;
3591 buf.get_iter_at_mark(iter, cursor);
3593 iter.set_line_offset(4);
3594 buf.move_mark(cursor, iter);
3597 cursor = buf.get_mark("selection_bound");
3598 iter= new Gtk.TextIter;
3599 buf.get_iter_at_mark(iter, cursor);
3601 iter.set_line_offset(4);
3602 buf.move_mark(cursor, iter);
3604 this.el.grab_focus();
3606 insert_spaces_instead_of_tabs : true,
3609 show_line_numbers : true,
3612 xtype: GtkSource.Buffer,
3613 pack : "set_buffer",
3615 changed : function (self) {
3616 var s = new Gtk.TextIter();
3617 var e = new Gtk.TextIter();
3618 this.el.get_start_iter(s);
3619 this.el.get_end_iter(e);
3620 var str = this.el.get_text(s,e,true);
3622 Seed.check_syntax('var e = ' + str);
3624 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3625 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3627 print("SYNTAX ERROR IN EDITOR");
3632 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3633 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3636 this.get('/LeftPanel.model').changed( str , false);
3645 xtype: Gtk.ScrolledWindow,
3649 xtype: Vte.Terminal,
3652 feed : function(istr) {
3653 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3654 // we should make ourselves visable!!!
3655 this.get('/BottomPane').el.show();
3656 this.get('/BottomPane').el.set_current_page(1);
3658 this.el.feed(str ,str.length);
3660 scroll_on_output : true,
3662 XObject.prototype.init.call(this);
3663 this.el.set_size (80, 1000);
3665 scrollback_lines : 1000
3675 pack : "pack_start,false,false",
3679 this.get('buttonbar').el.show();
3680 this.get('viewbox').el.hide();
3681 print("TRIED TO HIDE");
3684 this.get('buttonbar').el.hide();
3685 this.get('viewbox').el.show();
3686 // this.get('model').expanded();
3698 pack : "pack_start,false,true",
3700 clicked : function (self) {
3701 this.get('/RightPalete').show();
3708 stock : Gtk.STOCK_GOTO_FIRST,
3709 icon_size : Gtk.IconSize.MENU
3719 XObject.prototype.init.call(this);
3720 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3723 enter_notify_event : function (self, event) {
3724 this.get('/RightPalete').show();
3738 pack : "pack_start,false,true",
3747 pack : "pack_start,false,true",
3749 clicked : function (self) {
3750 this.get('/RightPalete').hide();
3757 stock : Gtk.STOCK_GOTO_LAST,
3758 icon_size : Gtk.IconSize.MENU
3765 xtype: Gtk.ScrolledWindow,
3768 XObject.prototype.init.call(this);
3769 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3770 this.el.set_size_request(-1,200);
3772 shadow_type : Gtk.ShadowType.IN,
3775 xtype: Gtk.TreeView,
3778 XObject.prototype.init.call(this);
3779 this.el.set_size_request(150,-1);
3780 // set_reorderable: [1]
3782 var description = new Pango.FontDescription.c_new();
3783 description.set_size(8000);
3784 this.el.modify_font(description);
3786 this.selection = this.el.get_selection();
3787 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3788 // this.selection.signal['changed'].connect(function() {
3789 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3791 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3793 Gtk.drag_source_set (
3794 this.el, /* widget will be drag-able */
3795 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3796 null, /* lists of target to support */
3797 0, /* size of list */
3798 Gdk.DragAction.COPY /* what to do with data after dropped */
3800 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3802 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3803 Gtk.drag_source_add_text_targets(this.el);
3805 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3806 targets = new Gtk.TargetList();
3807 targets.add( LeftTree.atoms["STRING"], 0, 0);
3808 targets.add_text_targets( 1 );
3809 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3811 //if you want to allow text to be output elsewhere..
3812 //Gtk.drag_source_add_text_targets(this.el);
3816 headers_visible : false,
3817 enable_tree_lines : true,
3819 drag_begin : function (self, ctx) {
3820 // we could fill this in now...
3821 Seed.print('SOURCE: drag-begin');
3825 var iter = new Gtk.TreeIter();
3826 var s = this.selection;
3827 s.get_selected(this.get('/RightPalete.model').el, iter);
3828 var path = this.get('/RightPalete.model').el.get_path(iter);
3830 var pix = this.el.create_row_drag_icon ( path);
3833 Gtk.drag_set_icon_pixmap (ctx,
3840 var value = new GObject.Value('');
3841 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3842 if (!this.get('/RightPalete').provider) {
3845 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3846 this.el.dragData = value.value;
3853 drag_data_get : function (self, drag_context, selection_data, info, time) {
3854 //Seed.print('Palete: drag-data-get: ' + target_type);
3855 if (this.el.dragData && this.el.dragData.length ) {
3856 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3860 //this.el.dragData = "TEST from source widget";
3864 drag_end : function (self, drag_context) {
3865 Seed.print('SOURCE: drag-end');
3866 this.el.dragData = false;
3867 this.el.dropList = false;
3868 this.get('/LeftTree.view').highlight(false);
3874 xtype: Gtk.ListStore,
3877 XObject.prototype.init.call(this);
3878 this.el.set_column_types ( 2, [
3879 GObject.TYPE_STRING, // title
3880 GObject.TYPE_STRING // tip
3885 load : function(tr,iter)
3890 //console.log('Project tree load: ' + tr.length);
3891 var citer = new Gtk.TreeIter();
3892 //this.insert(citer,iter,0);
3893 for(var i =0 ; i < tr.length; i++) {
3896 this.el.append(citer);
3898 this.el.insert(citer,iter,-1);
3903 this.el.set_value(citer, 0, '' + r ); // title
3905 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3906 //if (r.cn && r.cn.length) {
3907 // this.load(r.cn, citer);
3913 getValue : function (iter, col) {
3914 var gval = new GObject.Value('');
3915 this.el.get_value(iter, col ,gval);
3922 xtype: Gtk.TreeViewColumn,
3923 pack : "append_column",
3925 XObject.prototype.init.call(this);
3926 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3930 xtype: Gtk.CellRendererText,
3952 XObject.cache['/Window'] = Window;