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",
169 activate : function (self) {
170 var fn = this.get('/LeftTree').getActiveFile();
172 this.get('/StandardErrorDialog').show("No File active");
176 this.get('/DialogNewComponent').show(fn);
180 label : "File _Properties",
187 activate : function (self, event) {
188 this.get('/RooProjectProperties').show();
192 label : "Modify Project HTML ",
203 use_underline : true,
207 pack : "set_submenu",
212 activate : function (self, event) {
213 var js = this.get('/LeftTree.model').toJS();
215 this.get('/RightBrowser.view').renderJS(js[0]);
220 label : "_Redraw (Roo)",
227 activate : function (self, event)
229 /* Firefox testing for debugging..
230 - we can create a /tmp directory, and put.
231 builder.html, builder.html.js, link roojs1
232 add at the end of builder.html Roo.onload(function() {
234 if (!this.get('/Window.LeftTree').getActiveFile()) {
238 var js = this.get('/LeftTree.model').toJS();
242 var project = this.get('/Window.LeftTree').getActiveFile().project;
243 //print (project.fn);
245 project.runhtml = project.runhtml || '';
248 var File = imports.File.File;
250 var target = "/tmp/firetest"; // fixme..
251 if (!File.isDirectory(target)) {
254 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
255 if (!File.exists( target+ '/roojs1')) {
256 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
261 var html = imports.File.File.read(__script_path__ + '/../builder.html');
262 html = html.replace('</head>', project.runhtml + '</head>');
265 var jsstr = JSON.stringify(js[0], null, 4);
267 var runbuilder = '<script type="text/javascript">' + "\n" +
268 " Builder.render(" + jsstr + ");\n" +
271 html = html.replace('</body>', runbuilder + '</body>');
273 File.write( target+ '/builder.html', html);
275 this.get('/Terminal').feed("RUN DIR:" + target);
277 this.get('/Terminal').el.fork_command( null , [], [], target
278 , false,false,false);
279 var cmd = "firefox file://" + target + "/builder.html \n";
280 this.get('/Terminal').el.feed_child(cmd, cmd.length);
284 label : "_Test in Firefox (Roo)",
295 use_underline : true,
300 pack : "set_submenu",
306 use_underline : true,
308 activate : function (self) {
309 this.get('/About').el.run();
339 activate : function (self) {
340 var nb = this.get('/LeftTopPanel.notebook');
341 if (this.el.expanded) {
344 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
347 var model = this.get('/LeftProjectTree.combomodel');
348 // print ("loading Projects?")
349 //console.dump(pm.projects);
350 model.loadData(pm.projects);
353 nb.el.set_current_page(1);
354 //pm.on('changed', function() {
355 //console.log("CAUGHT project manager change");
356 // _combo.model.loadData(pm.projects);
360 nb.el.set_current_page(0);
362 enter_notify_event : function (self, event) {
363 this.el.expanded = !this.el.expanded;
364 //if (this.el.expanded ) {
365 this.listeners.activate.call(this);
372 label : "Select Project or File",
373 pack : "pack_start,false,true",
375 XObject.prototype.init.call(this);
376 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
384 pack : "pack_start,true,true",
386 XObject.prototype.init.call(this);
387 this.el.set_current_page(0);
392 xtype: Gtk.ScrolledWindow,
395 getActiveElement : function() { // return path to actie node.
397 var path = this.getActivePath();
401 var iter = new Gtk.TreeIter();
402 this.get('model').el.get_iter_from_string(iter, path);
404 var value = new GObject.Value('');
405 this.get('model').el.get_value(iter, 2, value);
407 return JSON.parse(value.value);
409 getActiveFile : function() {
410 return this.get('model').file;
412 getActivePath : function() {
413 var model = this.get('model');
414 var view = this.get('view');
415 if (view.selection.count_selected_rows() < 1) {
418 var iter = new Gtk.TreeIter();
420 view.selection.get_selected(model.el, iter);
421 return model.el.get_path(iter).to_string();
423 getPaleteProvider : function() {
424 var model = this.get('model');
425 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
426 return pm.getPalete(model.file.getType());
428 getRenderer : function() {
430 switch( this.getActiveFile().getType()) {
432 return this.get('/RightBrowser.view');
434 return this.get('/RightGtkView');
439 XObject.prototype.init.call(this);
440 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
442 renderView : function() {
443 var render = this.getRenderer();
444 var model = this.get('model');
446 render.renderJS(model.toJS(false,true)[0]);
448 print("NO RENDER JS METHOD?");
451 shadow_type : Gtk.ShadowType.IN,
456 button_press_event : function (self, ev) {
457 console.log("button press?");
458 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
459 print("click" + ev.type);
465 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
467 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
469 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
470 this.get('/LeftTreeMenu').el.show_all();
471 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
472 print("click:" + res.path.to_string());
475 drag_begin : function (self, drag_context) {
476 print('SOURCE: drag-begin');
477 this.targetData = false;
478 // find what is selected in our tree...
479 var iter = new Gtk.TreeIter();
480 var s = this.selection;
481 s.get_selected(this.get('/LeftTree.model').el, iter);
483 // set some properties of the tree for use by the dropped element.
484 var value = new GObject.Value('');
485 this.get('/LeftTree.model').el.get_value(iter, 2, value);
486 var data = JSON.parse(value.value);
487 var xname = this.get('/LeftTree.model').file.guessName(data);
489 this.el.dragData = xname;
490 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
493 // make the drag icon a picture of the node that was selected
494 var path = this.get('/LeftTree.model').el.get_path(iter);
495 this.el.treepath = path.to_string();
497 var pix = this.el.create_row_drag_icon ( path);
499 Gtk.drag_set_icon_pixmap (ctx,
508 drag_end : function (self, drag_context) {
509 Seed.print('LEFT-TREE: drag-end');
510 this.el.dragData = false;
511 this.el.dropList = false;
512 this.targetData = false;
513 this.get('/LeftTree.view').highlight(false);
516 drag_motion : function (self, ctx, x, y, time) {
517 console.log("LEFT-TREE: drag-motion");
518 var src = Gtk.drag_get_source_widget(ctx);
520 // a drag from elsewhere...- prevent drop..
522 print("no drag data!");
523 Gdk.drag_status(ctx, 0, time);
524 this.targetData = false;
527 var action = Gdk.DragAction.COPY;
528 if (src == this.el) {
529 // unless we are copying!!! ctl button..
530 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
534 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
535 // no children.. -- asume it's ok..
536 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
537 Gdk.drag_status(ctx, action ,time);
541 print("GETTING POS");
542 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
543 print("ISOVER? " + isOver);
545 Gdk.drag_status(ctx, 0 ,time);
546 return false; // not over apoint!?!
548 // drag node is parent of child..
549 console.log("SRC TREEPATH: " + src.treepath);
550 console.log("TARGET TREEPATH: " + data.path.to_string());
552 // nned to check a few here..
553 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
554 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
555 //Gtk.TreeViewDropPosition.AFTER
556 //Gtk.TreeViewDropPosition.BEFORE
558 if (typeof(src.treepath) != 'undefined' &&
559 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
560 print("subpath drag");
561 Gdk.drag_status(ctx, 0 ,time);
566 //print("DUMPING DATA");
567 //console.dump(data);
570 print(data.path.to_string() +' => '+ data.pos);
571 var tg = this.get('/LeftTree.model').findDropNodeByPath(
572 data.path.to_string(), src.dropList, data.pos);
574 this.get('/LeftTree.view').highlight(tg);
576 print("Can not find drop node path");
577 this.targetData = false;
578 Gdk.drag_status(ctx, 0, time);
582 this.targetData = tg;
585 Gdk.drag_status(ctx, action ,time);
589 drag_drop : function (w, ctx, x, y, time) {
590 Seed.print("TARGET: drag-drop");
594 w, /* will receive 'drag-data-received' signal */
595 ctx, /* represents the current state of the DnD */
596 this.get('/Window').atoms["STRING"], /* the target type we want */
597 time /* time stamp */
601 /* No target offered by source => error */
606 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
607 print("Tree: drag-data-received");
609 var delete_selection_data = false;
610 var dnd_success = false;
611 /* Deal with what we are given from source */
612 if( sel_data && sel_data.length ) {
614 if (ctx.action == Gdk.DragAction.ASK) {
615 /* Ask the user to move or copy, then set the ctx action. */
618 if (ctx.action == Gdk.DragAction.MOVE) {
619 //delete_selection_data = true;
622 var source = Gtk.drag_get_source_widget(ctx);
624 if (this.targetData) {
625 if (source != this.el) {
626 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
628 // drag around.. - reorder..
629 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
633 //Seed.print(this.targetData);
639 // we can send stuff to souce here...
645 if (dnd_success == false)
647 Seed.print ("DnD data transfer failed!\n");
650 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
653 cursor_changed : function (self) {
654 if (this.blockChanges) { // probably not needed..
657 var render = this.get('/LeftTree').getRenderer();
660 if (this.selection.count_selected_rows() < 1) {
661 this.get('/LeftPanel.model').load( false);
662 this.get('/MidPropTree').activeElement = false;
663 this.get('/MidPropTree').hideWin();
665 var pm = this.get('/RightPalete.model');
666 if (!this.get('/LeftTree').getPaleteProvider()) {
667 // it may not be loaded yet..
670 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
671 this.get('/LeftTree.model').listAllTypes()));
672 if (render && render.redraw) {
678 //console.log('changed');
679 var s = this.selection;
680 var iter = new Gtk.TreeIter();
681 s.get_selected(this.get('/LeftTree.model').el, iter);
685 var value = new GObject.Value('');
686 this.get('/LeftTree.model').el.get_value(iter, 2, value);
687 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
689 var data = JSON.parse(value.value);
690 this.get('/MidPropTree').activeElement = data;
691 this.get('/MidPropTree').hideWin();
692 this.get('/LeftPanel.model').load( data);
694 console.log(value.value);
695 // _g.button.set_label(''+value.get_string());
697 var pm =this.get('/RightPalete.model');
698 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
699 this.get('/LeftTree.model').listAllTypes()));
702 if (render && render.redraw) {
706 //Seed.print( value.get_string());
714 enable_tree_lines : true,
715 headers_visible : false,
716 highlight : function(treepath_ar) {
718 // highlighting for drag/drop
719 if (treepath_ar.length && treepath_ar[0].length ) {
720 this.el.set_drag_dest_row(
721 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
723 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
728 XObject.prototype.init.call(this);
729 var description = new Pango.FontDescription.c_new();
730 description.set_size(8000);
731 this.el.modify_font(description);
733 this.selection = this.el.get_selection();
734 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
737 // is this really needed??
738 this.selection.signal['changed'].connect(function() {
739 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
740 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
744 Gtk.drag_source_set (
745 this.el, /* widget will be drag-able */
746 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
747 null, /* lists of target to support */
748 0, /* size of list */
749 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
752 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
754 Gtk.drag_source_add_text_targets(this.el);
757 this.el, /* widget that will accept a drop */
758 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
759 null, /* lists of target to support */
760 0, /* size of list */
761 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
764 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
765 Gtk.drag_dest_add_text_targets(this.el);
767 selectNode : function(treepath_str) {
768 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
769 var tp = new Gtk.TreePath.from_string(treepath_str);
770 this.el.set_cursor(tp, null, false);
771 this.el.scroll_to_cell(tp, null, false, 0,0);
775 xtype: Gtk.TreeStore,
780 changed : function(n, refresh) {
781 print("MODEL CHANGED CALLED" + this.activePath);
782 if (this.activePath) {
783 var iter = new Gtk.TreeIter();
784 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
785 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
786 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
788 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
790 //this.currentTree = this.toJS(false, true)[0];
791 this.file.items = this.toJS(false, false);
792 print("AFTER CHANGED");
793 //console.dump(this.file.items);
795 this.currentTree = this.file.items[0];
796 //console.log(this.file.toSource());
799 print("REDNER BROWSER?!");
800 this.get('/LeftTree').renderView();
802 var pm = this.get('/RightPalete.model');
803 if (!this.get('/RightPalete').provider) {
809 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
810 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
814 deleteSelected : function() {
815 this.get('/LeftTree.view').blockChanges = true;
816 var old_iter = new Gtk.TreeIter();
817 var s = this.get('/LeftTree.view').selection;
818 s.get_selected(this.el, old_iter);
819 var path = this.el.get_path(old_iter).to_string();
821 this.activePath= false;
824 this.activePath= false;
825 var iter = new Gtk.TreeIter();
826 this.el.get_iter_from_string(iter, path);
827 this.el.remove(iter);
829 // rebuild treemap. -- depreciated.!!
832 //this.toJS(null, true) // does not do anything?
833 this.activePath= false;
834 this.changed(false,true);
835 this.get('/LeftTree.view').blockChanges = false;
837 dropNode : function(target_data, node) {
839 // console.dump(node);
840 // console.dump(target_data);
841 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
843 print("add " + tp + "@" + target_data[1] );
846 if (tp && target_data[1] < 2) { // before or after..
847 var ar = target_data[0].split(':');
849 parent = new Gtk.TreePath.from_string( ar.join(':') );
852 var n_iter = new Gtk.TreeIter();
853 var iter_par = new Gtk.TreeIter();
854 var iter_after = after ? new Gtk.TreeIter() : false;
858 if (parent !== false) {
859 this.el.get_iter(iter_par, parent);
866 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
867 this.el.get_iter(iter_after, after);
868 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
869 n_iter, iter_par, iter_after);
872 this.el.append(n_iter, iter_par);
876 if (typeof(node) == 'string') {
877 var ar = node.split('.');
878 var xtype = ar.pop();
881 '|xns' : ar.join('.'),
884 if (target_data.length == 3 && target_data[2].length) {
885 node['*prop'] = target_data[2];
887 node = this.get('/DialogTemplateSelect').show(node);
890 // work out what kind of packing to use..
891 if (typeof(node.pack) == 'undefined' && parent !== false) {
892 var pal = this.get('/LeftTree').getPaleteProvider();
893 if (pal.name == 'Gtk') {
894 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
895 var cname = pal.guessName(node);
896 node.pack = pal.getDefaultPack(pname, cname);
907 // load children - if it has any..
910 this.load(xitems, n_iter);
911 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
913 if (tp && (xitems || after)) {
914 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
916 // wee need to get the empty proptypes from somewhere..
918 //var olditer = this.activeIter;
919 this.activePath = this.el.get_path(n_iter).to_string();
921 // changed actually set's the node data..
922 this.changed(node, true);
926 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
928 //Builder.MidPropTree._model.load(node);
929 //Builder.MidPropTree._win.hideWin();
930 //Builder.LeftPanel._model.load( node);
934 findDropNode : function(treepath_str, targets) {
936 // this is used by the dragdrop code in the roo version AFAIR..
938 var path = treepath_str.replace(/^builder-/, '');
939 // treemap is depreciated... - should really check if model has any entries..
941 if (!this.el.iter_n_children(null)) {
943 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
945 print("FIND treepath: " + path);
946 //console.dump(this.treemap);
948 if (!treepath_str.match(/^builder-/)) {
949 return []; // nothing!
951 if (targets === true) {
954 return this.findDropNodeByPath(path,targets)
956 findDropNodeByPath : function(treepath_str, targets, pref) {
957 var path = treepath_str + ''; // dupe it..
958 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
960 //console.dump(this.treemap);
961 while (path.length) {
962 print("LOOKING FOR PATH: " + path);
963 var node_data = this.singleNodeToJS(path);
964 if (node_data === false) {
965 print("node not found");
969 var xname = this.get('/LeftTree.model').file.guessName(node_data);
972 targets.forEach(function(tg) {
976 if ((tg == xname) ) {
979 if (tg.indexOf(xname +':') === 0) {
981 prop = tg.split(':').pop();
986 if (last) { // pref is after/before..
987 // then it's after last
989 return []; // do not allow..
991 return [ last, pref , prop];
994 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
996 var par = path.split(':');
999 path = par.join(':');
1005 getIterValue : function (iter, col) {
1006 var gval = new GObject.Value('');
1007 this.el.get_value(iter, col ,gval);
1013 XObject.prototype.init.call(this);
1014 this.el.set_column_types ( 3, [
1015 GObject.TYPE_STRING, // title
1016 GObject.TYPE_STRING, // tip
1017 GObject.TYPE_STRING // source..
1020 listAllTypes : function() {
1021 var s = this.get('/LeftTree.view').selection;
1022 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1024 if (s.count_selected_rows() > 0) {
1025 var iter = new Gtk.TreeIter();
1026 s.get_selected(this.el, iter);
1028 // set some properties of the tree for use by the dropped element.
1029 var value = new GObject.Value('');
1030 this.el.get_value(iter, 2, value);
1031 var data = JSON.parse(value.value);
1034 var xname = this.get('/LeftTree.model').file.guessName(data);
1035 console.log('selected:' + xname);
1039 return []; // could not find it..
1047 li.forEach(function(el) {
1048 // this is specific to roo!!!?
1049 if (!el) { // skip empty?
1052 var fullpath = _this.file.guessName(el);
1053 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1058 if (el.items && el.items.length) {
1067 addall([this.currentTree]);
1069 // only if we have nothing, should we add '*top'
1073 //console.log('all types in tree');
1074 //console.dump(ret);
1079 load : function(tr,iter)
1081 var citer = new Gtk.TreeIter();
1082 //this.insert(citer,iter,0);
1083 for(var i =0 ; i < tr.length; i++) {
1085 this.el.insert(citer,iter,-1);
1087 this.el.append(citer);
1090 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1091 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1092 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1093 if (tr[i].items && tr[i].items.length) {
1094 this.load(tr[i].items, citer);
1098 loadFile : function(f) {
1104 console.log('missing file');
1108 // load the file if not loaded..
1109 if (f.items === false) {
1111 f.loadItems(function() {
1117 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1119 if (f.items.length && typeof(f.items[0]) == 'string') {
1121 this.get('/RightEditor').el.show();
1122 this.get('/RightEditor.view').load( f.items[0]);
1126 print(JSON.stringify(f.items, null,4));
1127 //console.dump(f.items);
1129 this.get('/LeftTree.view').el.expand_all();
1131 if (!f.items.length) {
1134 this.get('/Window.leftvpaned').el.set_position(80);
1136 this.get('/LeftTree.view').el.set_cursor(
1137 new Gtk.TreePath.from_string('0'), null, false);
1141 this.get('/Window.leftvpaned').el.set_position(200);
1145 //print("hide right editior");
1146 this.get('/RightEditor').el.hide();
1147 //print("set current tree");
1148 this.currentTree = this.toJS(false, false)[0];
1149 //console.dump(this.currentTree);
1150 this.currentTree = this.currentTree || { items: [] };
1151 this.get('/LeftTree').renderView();
1152 //console.dump(this.map);
1153 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1154 var pm = this.get('/RightPalete.model');
1155 // set up provider..
1157 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1159 if (!this.get('/RightPalete').provider) {
1160 print ("********* PALETE PROVIDER MISSING?!!");
1162 this.get('/LeftTree').renderView();
1164 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1168 this.get('/Window.view-notebook').el.set_current_page(
1169 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1172 moveNode : function(target_data, action) {
1173 //print("MOVE NODE");
1174 // console.dump(target_data);
1175 var old_iter = new Gtk.TreeIter();
1176 var s = this.get('/LeftTree.view').selection;
1177 s.get_selected(this.el, old_iter);
1178 var node = this.nodeToJS(old_iter,false);
1179 //console.dump(node);
1182 // needs to drop first, otherwise the target_data
1183 // treepath will be invalid.
1185 this.dropNode(target_data, node);
1186 if (action & Gdk.DragAction.MOVE) {
1187 // print("REMOVING OLD NODE");
1188 this.el.remove(old_iter);
1192 this.activePath= false;
1193 this.changed(false,true);
1195 nodeTip : function(c) {
1196 var ret = this.nodeTitle(c,true);
1202 if (!i.length || i[0] != '|') {
1208 if (typeof(c[i]) != 'string') {
1211 //print("prop : " + i + ':' + c[i]);
1212 if (!c[i].match(new RegExp('function'))) {
1215 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1219 ret+="\n\nMethods:" + funcs;
1224 nodeTitle : function(c, renderfull) {
1227 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1228 if (sr) txt.push('<s>');
1229 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1231 if (renderfull && c['|xns']) {
1232 txt.push(c['|xns']);
1235 if (c.xtype) { txt.push(c.xtype); }
1236 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1237 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1238 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1241 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1242 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1243 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1244 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1245 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1246 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1247 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1248 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1249 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1251 // for flat classes...
1252 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1253 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1256 if (sr) txt.push('</s>');
1257 return (txt.length == 0 ? "Element" : txt.join(" "));
1259 nodeToJS : function (treepath, with_id)
1262 var iter = treepath; // API used to be iter here..
1263 if (typeof(iter) == 'string') {
1264 iter = new Gtk.TreeIter();
1265 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1269 var par = new Gtk.TreeIter();
1270 var iv = this.getIterValue(iter, 2);
1271 // print("IV" + iv);
1272 var k = JSON.parse(iv);
1273 if (k.json && !this.el.iter_parent( par, iter )) {
1278 var treepath_str = this.el.get_path(iter).to_string();
1279 // not sure how we can handle mixed id stuff..
1280 if (typeof(k.id) == 'undefined') {
1281 k.id = 'builder-'+ treepath_str ;
1285 this.treemap[ treepath_str ] = k;
1286 k.xtreepath = treepath_str ;
1289 if (this.el.iter_has_child(iter)) {
1290 citer = new Gtk.TreeIter();
1291 this.el.iter_children(citer, iter);
1292 k.items = this.toJS(citer,with_id);
1296 nodeToJSON : function(c) {
1304 return JSON.stringify(o);
1306 singleNodeToJS : function (treepath)
1308 var iter = new Gtk.TreeIter();
1309 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1313 var iv = this.getIterValue(iter, 2);
1315 return JSON.parse(iv);
1318 toJS : function(treepath, with_id)
1320 //Seed.print("WITHID: "+ with_id);
1321 var iter = treepath; // API used to be iter here..
1322 if (typeof(iter) == 'string') {
1323 iter = new Gtk.TreeIter();
1324 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1333 iter = new Gtk.TreeIter();
1334 if (!this.el.get_iter_first(iter)) {
1344 var k = this.nodeToJS(iter, with_id);
1348 if (!this.el.iter_next(iter)) {
1353 if (treepath === false) {
1355 return JSON.parse(JSON.stringify(ar));
1359 // convert the list into a json string..
1365 xtype: Gtk.TreeViewColumn,
1366 pack : "append_column",
1368 XObject.prototype.init.call(this);
1369 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1373 xtype: Gtk.CellRendererText,
1383 id : "LeftTreeMenu",
1386 xtype: Gtk.MenuItem,
1388 label : "Delete Element",
1390 activate : function (self) {
1392 this.get('/LeftTree.model').deleteSelected();
1397 xtype: Gtk.MenuItem,
1399 activate : function (self) {
1401 var tree = this.get('/LeftTree');
1402 var model = this.get('/LeftTree.model');
1403 var el = tree.getActivePath();
1405 var js = model.toJS(el, false);
1406 // print(JSON.stringify(js[0], null,4));
1407 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1412 label : "Save as Template",
1422 id : "LeftProjectTree",
1423 showNoProjectSelected : function() {
1424 this.get('/StandardErrorDialog').show("Select a Project first.");
1426 getActiveProject : function() {
1427 return this.project;
1430 leave_notify_event : function (self, event) {
1437 pack : "pack_start,false,false",
1440 xtype: Gtk.ComboBox,
1443 XObject.prototype.init.call(this);
1444 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1446 getValue : function() {
1447 var ix = this.el.get_active();
1451 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1452 if (typeof(data[ix]) == 'undefined') {
1457 setValue : function(fn)
1461 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1462 data.forEach(function(n, ix) {
1470 changed : function (self) {
1471 var fn = this.getValue();
1472 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1473 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1478 xtype: Gtk.CellRendererText,
1479 pack : "pack_start,true",
1483 xtype: Gtk.ListStore,
1486 XObject.prototype.init.call(this);
1487 this.el.set_column_types ( 2, [
1488 GObject.TYPE_STRING, // real key
1489 GObject.TYPE_STRING // real type
1493 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1495 pm.on('changed', function() {
1496 print("caught changed hook on project manager - reloading data");
1497 _this.loadData(pm.projects);
1501 loadData : function(data) {
1502 var ov = this.get('/LeftProjectTree.combo').getValue();
1504 var iter = new Gtk.TreeIter();
1506 data.forEach(function(p) {
1511 el.set_value(iter, 0, p.fn);
1512 el.set_value(iter, 1, p.name);
1516 this.get('/LeftProjectTree.combo').setValue(ov);
1525 xtype: Gtk.ScrolledWindow,
1527 shadow_type : Gtk.ShadowType.IN,
1529 XObject.prototype.init.call(this);
1530 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1534 xtype: Gtk.TreeView,
1536 cursor_changed : function (self) {
1537 var iter = new Gtk.TreeIter();
1539 if (this.selection.count_selected_rows() < 1) {
1540 //XN.get('Builder.LeftTree.model').
1541 this.get('/LeftTree.model').load( false);
1545 var model = this.get('/LeftProjectTree.model');
1546 //console.log('changed');
1547 var s = this.selection;
1548 s.get_selected(model, iter);
1549 value = new GObject.Value('');
1550 model.el.get_value(iter, 2, value);
1552 console.log(value.value);// id..
1554 var file = this.get('/LeftProjectTree').project.getById(value.value);
1561 var nb = this.get('/LeftTopPanel.expander');
1562 nb.el.expanded = false;
1563 nb.listeners.activate.call(nb);
1564 //_expander.el.set_expanded(false);
1566 var ltm = this.get('/LeftTree.model');
1574 enable_tree_lines : true,
1575 headers_visible : false,
1577 XObject.prototype.init.call(this);
1578 var description = new Pango.FontDescription.c_new();
1579 description.set_size(8000);
1580 this.el.modify_font(description);
1582 this.selection = this.el.get_selection();
1583 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1587 xtype: Gtk.TreeStore,
1591 XObject.prototype.init.call(this);
1592 this.el.set_column_types ( 3, [
1593 GObject.TYPE_STRING, // title
1594 GObject.TYPE_STRING, // tip
1595 GObject.TYPE_STRING // id..
1599 loadProject : function(pr) {
1600 print("LOAD PROJECT");
1606 this.get('/LeftProjectTree').project = pr;
1607 this.load(pr.toTree());
1608 this.get('/LeftProjectTree.view').el.expand_all();
1610 load : function(tr,iter) {
1611 // console.dump(tr);
1612 console.log('Project tree load: ' + tr.length);
1613 var citer = new Gtk.TreeIter();
1614 //this.insert(citer,iter,0);
1617 tr.forEach(function (r) {
1619 _this.el.append(citer);
1621 _this.el.insert(citer,iter,-1);
1623 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1624 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1625 _this.el.set_value(citer, 2, '' + r.id ); //id
1626 if (r.cn && r.cn.length) {
1627 _this.load(r.cn, citer);
1632 getValue : function(iter, col) {
1633 var gval = new GObject.Value('');
1634 this.el.get_value(iter, col ,gval);
1635 return '' + gval.value;
1639 xtype: Gtk.TreeViewColumn,
1640 pack : "append_column",
1642 XObject.prototype.init.call(this);
1643 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1647 xtype: Gtk.CellRendererText,
1667 pack : "pack_start,false,true,0",
1674 button_press_event : function (self, event) {
1675 this.get('/MidPropTree.model').showData('props');
1687 stock : Gtk.STOCK_ADD,
1688 icon_size : Gtk.IconSize.MENU
1703 button_press_event : function (self, event) {
1704 this.get('/MidPropTree.model').showData('events');
1716 stock : Gtk.STOCK_ADD,
1717 icon_size : Gtk.IconSize.MENU
1732 button_press_event : function (self, ev) {
1733 var p = this.get('/AddPropertyPopup');
1737 p.el.set_screen(Gdk.Screen.get_default());
1739 p.el.popup(null, null, null, null, 3, ev.button.time);
1751 stock : Gtk.STOCK_ADD,
1752 icon_size : Gtk.IconSize.MENU
1764 id : "AddPropertyPopup",
1767 xtype: Gtk.MenuItem,
1769 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1772 activate : function (self) {
1774 this.get('/LeftPanel.model').add( {
1785 xtype: Gtk.MenuItem,
1787 tooltip_markup : "Add what type of packing is to be used",
1790 activate : function (self) {
1792 this.get('/LeftPanel.model').add( {
1802 xtype: Gtk.MenuItem,
1804 tooltip_markup : "Override the init method",
1807 activate : function (self) {
1809 this.get('/LeftPanel.model').add( {
1812 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1819 xtype: Gtk.SeparatorMenuItem,
1823 xtype: Gtk.MenuItem,
1825 tooltip_markup : "Add a user defined string property",
1828 activate : function (self) {
1830 this.get('/LeftPanel.model').add( {
1840 xtype: Gtk.MenuItem,
1842 tooltip_markup : "Add a user defined number property",
1845 activate : function (self) {
1847 this.get('/LeftPanel.model').add( {
1857 xtype: Gtk.MenuItem,
1859 tooltip_markup : "Add a user defined boolean property",
1862 activate : function (self) {
1864 this.get('/LeftPanel.model').add( {
1874 xtype: Gtk.SeparatorMenuItem,
1878 xtype: Gtk.MenuItem,
1880 tooltip_markup : "Add a user function boolean property",
1883 activate : function (self) {
1885 this.get('/LeftPanel.model').add( {
1888 val : "function() {\n \n}\n",
1901 xtype: Gtk.ScrolledWindow,
1904 shadow_type : Gtk.ShadowType.IN,
1907 XObject.prototype.init.call(this);
1908 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1912 xtype: Gtk.TreeView,
1915 headers_visible : false,
1916 enable_tree_lines : true,
1918 XObject.prototype.init.call(this);
1920 this.selection = this.el.get_selection();
1921 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1924 var description = new Pango.FontDescription.c_new();
1925 description.set_size(8000);
1926 this.el.modify_font(description);
1929 button_press_event : function (self, ev) {
1933 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1934 return false; //not on a element.
1938 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1940 if (res.column.title != 'value') {
1941 return false; // ignore..
1943 if ( this.get('/LeftPanel').editing) {
1946 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1947 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1948 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1952 var provider = this.get('/LeftTree').getPaleteProvider();
1954 var opts = provider.findOptions(type);
1956 if (opts === false) {
1957 this.get('/LeftPanel').editableColumn.setOptions([]);
1958 renderer.has_entry = true;
1960 LeftPanel.editableColumn.setOptions(opts);
1961 renderer.has_entry = false;
1965 //Seed.print("click" + ev.type);
1966 //console.dump(res);
1972 if (res.column.title == 'value') {
1975 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1976 var p = this.get('/LeftPanelPopup');
1981 p.el.set_screen(Gdk.Screen.get_default());
1983 p.el.popup(null, null, null, null, 3, ev.button.time);
1984 //Seed.print("click:" + res.column.title);
1992 xtype: Gtk.TreeStore,
1996 add : function(info) {
1997 // info includes key, val, skel, etype..
1999 type = info.type.toLowerCase();
2000 var data = this.toJS();
2002 if (info.etype == 'events') {
2003 data.listeners = data.listeners || { };
2004 if (typeof(data.listeners[info.key]) != 'undefined') {
2005 return; //already set!
2008 if (typeof(data[info.key]) != 'undefined') {
2013 if (typeof(info.val) == 'undefined') {
2016 if (info.type.toLowerCase() == 'boolean') {
2019 if (type == 'number') {
2027 if (info.etype == 'events') {
2029 data.listeners[info.key] = info.val;
2032 data[info.key] = info.val;
2036 var map = this.load(data);
2038 // flag it as changed to the interface..
2040 this.get('/LeftTree.model').changed(data, true);
2043 this.startEditing(map[k]);
2046 LeftPanel.get('view').el.row_activated(
2047 new Gtk.TreePath.from_string(map[k]),
2048 LeftPanel.editableColumn.el
2052 changed : function(str, doRefresh) {
2053 if (!this.activePath) {
2056 var iter = new Gtk.TreeIter();
2057 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2059 this.el.set_value(iter, 1, '' +str);
2060 this.el.set_value(iter, 3, '' + this.toShort(str));
2061 var type = this.getIterValue(iter, 4);
2063 this.el.set_value(iter, 5, type + ' : ' + str);
2064 // update the tree...
2066 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2068 deleteSelected : function() {
2069 var data = this.toJS();
2070 var iter = new Gtk.TreeIter();
2071 var s = this.get('/LeftPanel.view').selection;
2072 s.get_selected(this.el, iter);
2075 var gval = new GObject.Value('');
2076 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2078 var val = gval.value;
2079 if (val[0] == '!') {
2081 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2084 delete data.listeners[ val.substring(1)];
2085 if (!XObject.keys(data.listeners).length) {
2086 delete data.listeners;
2090 if (typeof(data[val]) == 'undefined') {
2098 this.get('/LeftTree.model').changed(data, true);
2101 editSelected : function(e) {
2102 print("EDIT SELECTED?");
2103 var iter = new Gtk.TreeIter();
2104 var s = this.get('/LeftPanel.view').selection;
2105 s.get_selected(this.get('/LeftPanel.model').el, iter);
2106 var m = this.get('/LeftPanel.model')
2108 var gval = new GObject.Value('');
2109 this.el.get_value(iter, 0 ,gval);
2110 var val = '' + gval.value;
2112 gval = new GObject.Value('');
2113 this.el.get_value(iter, 1 ,gval);
2114 var rval = gval.value;
2115 var activePath = this.el.get_path(iter).to_string();
2116 this.activePath = activePath ;
2117 // was activeIter...
2120 var showEditor = false;
2122 if (val[0] == '!') {
2125 if (val[0] == '|') {
2126 if (rval.match(/function/g) || rval.match(/\n/g)) {
2133 this.activePath = false;
2134 GLib.timeout_add(0, 1, function() {
2135 // Gdk.threads_enter();
2136 _this.get('/BottomPane').el.show();
2137 _this.get('/RightEditor').el.show();
2138 _this.get('/RightEditor.view').load( rval );
2142 _this.activePath = activePath ;
2144 // Gdk.threads_leave();
2149 this.get('/BottomPane').el.hide();
2150 this.get('/RightEditor').el.hide();
2152 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2156 getIterValue : function(iter, col) {
2157 var gval = new GObject.Value('');
2158 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2159 return '' + gval.value;
2161 getType : function(treepath) {
2162 return this.getValue(treepath, 4);
2164 getValue : function(treepath_str, col) {
2165 var iter = new Gtk.TreeIter();
2166 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2168 var gval = new GObject.Value('');
2169 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2170 var val = '' + gval.value;
2174 var type = this.getType(this.el.get_path(iter).to_string());
2175 print("TYPE: " +type + " - val:" + val);
2176 switch(type.toLowerCase()) {
2180 return parseFloat(val); // Nan ?? invalid!!?
2183 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2185 return val == 'true' ? true : false;
2187 var nv = parseFloat(val);
2188 if (!isNaN(nv) && (val == ''+nv)) {
2196 XObject.prototype.init.call(this);
2197 this.el.set_column_types ( 6, [
2198 GObject.TYPE_STRING, // 0 real key
2199 GObject.TYPE_STRING, // 1 real value
2200 GObject.TYPE_STRING, // 2 visable key
2201 GObject.TYPE_STRING, // 3 visable value
2202 GObject.TYPE_STRING, // 4 need to store type of!!!
2203 GObject.TYPE_STRING // 5 tooltip
2207 load : function(ar) {
2210 this.get('/RightEditor').el.hide();
2217 var provider = this.get('/LeftTree').getPaleteProvider();
2218 var iter = new Gtk.TreeIter();
2221 var keys = XObject.keys(ar);
2223 ar.listeners = ar.listeners || {};
2225 for (var i in ar.listeners ) {
2226 this.el.append(iter);
2227 var p = this.el.get_path(iter).to_string();
2230 this.el.set_value(iter, 0, '!'+ i );
2231 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2232 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2234 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2235 this.el.set_value(iter, 4, 'function');
2236 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2242 keys.forEach(function(i) {
2243 if (typeof(ar[i]) == 'object') {
2247 var type = provider.findType(ar, i, ar[i]);
2249 _this.el.append(iter);
2250 var p = _this.el.get_path(iter).to_string();
2252 _this.el.set_value(iter, 0, ''+i);
2253 _this.el.set_value(iter, 1, '' + ar[i]);
2254 _this.el.set_value(iter, 2, ''+i);
2255 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2256 _this.el.set_value(iter, 4, ''+type);
2257 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2261 startEditing : function(path,col) {
2263 * start editing path (or selected if not set..)
2264 * @param {String|false} path (optional) treepath to edit - selected tree gets
2265 * edited by default.
2266 * @param {Number} 0 or 1 (optional)- column to edit.
2269 if (typeof(path) == 'string') {
2270 tp = new Gtk.TreePath.from_string(path);
2272 var iter = new Gtk.TreeIter();
2273 var s = this.get('/LeftPanel.view').selection;
2274 s.get_selected(this.el, iter);
2275 tp = this.el.get_path(iter);
2276 path = tp.to_string();
2280 // which colum is to be edited..
2282 if (typeof(col) == 'undefined') {
2283 var k = this.getValue(path, 0);
2284 colObj = (!k.length || k == '|') ?
2285 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2287 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2290 // make sure the pulldown is set correctly..
2291 // not really needed for second col...
2293 var provider = this.get('/LeftTree').getPaleteProvider();
2295 var type = this.get('/LeftPanel.model').getType(path);
2296 var opts = provider.findOptions(type);
2297 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2299 if (opts === false) {
2300 this.get('/LeftPanel').editableColumn.setOptions([]);
2301 renderer.has_entry = true; /// probably does not have any effect.
2303 this.get('/LeftPanel').editableColumn.setOptions(opts);
2304 renderer.has_entry = false;
2308 // iter now has row...
2309 GLib.timeout_add(0, 100, function() {
2311 colObj.items[0].el.editable = true; // esp. need for col 0..
2312 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2322 var iter = new Gtk.TreeIter();
2323 this.get('/LeftPanel.model').el.get_iter_first(iter);
2328 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2331 ar.listeners = ar.listeners || {};
2332 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2335 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2338 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2344 //print(JSON.stringify(ar));
2348 toShort : function(str) {
2349 var a = typeof(str) == 'string' ? str.split("\n") : [];
2350 return a.length > 1 ? a[0] + '....' : '' + str;
2354 xtype: Gtk.TreeViewColumn,
2355 pack : "append_column",
2357 XObject.prototype.init.call(this);
2359 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2360 this.get('/LeftPanel').propertyColumn = this;
2365 xtype: Gtk.CellRendererText,
2366 pack : "pack_start",
2368 editing_started : function (self, editable, path) {
2370 this.get('/LeftPanel.model').activePath = path;
2373 edited : function (self, object, p0) {
2374 var model = this.get('/LeftPanel.model');
2375 var path = model.activePath;
2376 var iter = new Gtk.TreeIter();
2377 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2378 model.el.set_value(iter, 0, p0);
2379 model.el.set_value(iter, 2, p0);
2381 model.activePath = false;
2383 this.get('/LeftTree.model').changed(model.toJS(), true);
2384 this.el.editable = false;
2391 xtype: Gtk.TreeViewColumn,
2392 pack : "append_column",
2394 XObject.prototype.init.call(this);
2395 this.el.add_attribute(this.items[0].el , 'text', 3 );
2396 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2397 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2398 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2400 this.get('/LeftPanel').editableColumn= this;
2402 setOptions : function(ar) {
2403 var m = this.items[0].el.model;
2405 var iter = new Gtk.TreeIter();
2406 ar.forEach(function(i) {
2409 m.set_value(iter, 0, i);
2415 xtype: Gtk.CellRendererCombo,
2416 pack : "pack_start",
2421 XObject.prototype.init.call(this);
2422 this.el.model = new Gtk.ListStore();
2423 this.el.model.set_column_types ( 1, [
2424 GObject.TYPE_STRING // 0 real key
2428 edited : function (self, object, p0) {
2429 this.get('/LeftPanel').editing = false;
2430 print("EDITED? p:" + p0 + " t:" + p0);
2431 this.get('/LeftPanel.model').changed(p0, true);
2432 this.get('/LeftPanel.model').activePath = false;
2434 editing_started : function (self, editable, path) {
2435 this.get('/LeftPanel').editing = true;
2436 // console.log('editing started');
2437 // r.has_entry = false;
2438 this.get('/LeftPanel.model').editSelected(editable);
2449 id : "LeftPanelPopup",
2452 xtype: Gtk.MenuItem,
2456 activate : function (self) {
2457 this.get('/LeftPanel.model').deleteSelected();
2462 xtype: Gtk.MenuItem,
2466 activate : function (self) {
2467 this.get('/LeftPanel.model').startEditing(false, 0);
2480 xtype: Gtk.ScrolledWindow,
2481 pack : "pack_end,false,true,0",
2483 shadow_type : Gtk.ShadowType.IN,
2485 XObject.prototype.init.call(this);
2486 XObject.prototype.init.call(this);
2487 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2488 this.el.set_size_request ( 150, -1 );
2491 activeElement : false,
2492 hideWin : function() {
2499 if (this.get('/Window.left').el.position < 160) {
2502 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2509 xtype: Gtk.TreeView,
2511 cursor_changed : function (self) {
2512 var iter = new Gtk.TreeIter();
2514 //console.log('changed');
2515 var m = this.get('model');
2516 if (!this.selection){
2517 this.selection = this.el.get_selection();
2520 var s = this.selection;
2521 if (!s.get_selected(m.el, iter)) {
2524 var tp = m.el.get_path(iter).to_string();
2529 var key = m.getValue(tp, 0);
2531 var type = m.getValue(tp, 1);
2532 var skel = m.getValue(tp, 3);
2533 var etype = m.getValue(tp, 5);
2536 this.get('/MidPropTree').hideWin();
2538 if (type.toLowerCase() == 'function') {
2540 if (etype != 'events') {
2544 this.get('/LeftPanel.model').add({
2552 // has dot in name, and is boolean???? this does not make sense..
2553 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2557 this.get('/LeftPanel.model').add( {
2567 enable_tree_lines : true,
2568 headers_visible : false,
2570 XObject.prototype.init.call(this);
2572 var description = new Pango.FontDescription.c_new();
2573 description.set_size(8000);
2574 this.el.modify_font(description);
2576 //this.selection = this.el.get_selection();
2577 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
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,
2705 id : "view-notebook",
2709 XObject.prototype.init.call(this);
2710 this.el.set_current_page(0);
2711 //print("SET LABEL?")
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" }));
2719 id : "RightBrowser",
2723 xtype: Gtk.ScrolledWindow,
2725 shadow_type : Gtk.ShadowType.IN,
2727 XObject.prototype.init.call(this);
2728 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2732 xtype: WebKit.WebView,
2734 load_finished : function (self, object) {
2735 // if (this.ready) { // dont do it twice!
2738 this.el.get_inspector().show();
2740 this.pendingRedraw = false;
2741 var js = this.get('/LeftTree.model').toJS();
2743 this.renderJS(js[0]);
2747 script_alert : function (self, object, p0) {
2750 return true; // do not display anything...
2752 console_message : function (self, object, p0, p1) {
2753 // console.log(object);
2754 if (!object.match(/^\{/)) {
2756 //this.get('/Terminal').feed(object);
2757 return true; // do not handle!!! -> later maybe in console..
2759 // console.log(object);
2760 var val = JSON.parse(object);
2762 if (typeof(val['hover-node']) != 'undefined') {
2763 this.activeNode = val['hover-node'];
2764 console.log('active node: ' + this.activeNode);
2769 if (typeof(val['id']) != 'undefined') {
2770 // this.activeNode = val['id'];
2771 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2772 if (!tg || typeof(tg[0]) == 'undefined') {
2775 print("SELECT node " + tg[0]);
2777 this.get('/LeftTree.view').selectNode(tg[0]);
2781 if (ret && typeof(val['set']) != 'undefined') {
2782 this.get('/LeftPanel.model').add({
2786 //console.log('active node: ' + this.activeNode);
2789 //Seed.print('a:'+a);
2790 //Seed.print('b:'+b);
2791 //Seed.print('c:'+c);
2794 drag_motion : function (w, ctx, x, y, time, ud) {
2795 // console.log('DRAG MOTION');
2797 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2798 this.targetData = [];
2799 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2801 // A) find out from drag all the places that node could be dropped.
2802 var src = Gtk.drag_get_source_widget(ctx);
2803 if (!src.dropList) {
2804 Gdk.drag_status(ctx, 0, time);
2807 // b) get what we are over.. (from activeNode)
2808 // tree is empty.. - list should be correct..
2809 if (!this.get('/LeftTree.model').currentTree) {
2810 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2814 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2816 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2819 Gdk.drag_status(ctx, 0,time);
2820 this.get('/LeftTree.view').highlight(false);
2824 // if we have a target..
2825 // -> highlight it! (in browser)
2826 // -> highlight it! (in tree)
2828 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2829 this.get('/LeftTree.view').highlight(tg);
2830 this.targetData = tg;
2831 // for tree we should handle this...
2834 drag_drop : function (w, ctx, x, y,time, ud) {
2835 print("TARGET: drag-drop");
2836 var is_valid_drop_site = true;
2841 w, /* will receive 'drag-data-received' signal */
2842 ctx, /* represents the current state of the DnD */
2843 this.get('/Window').atoms["STRING"], /* the target type we want */
2844 time /* time stamp */
2848 /* No target offered by source => error */
2851 return is_valid_drop_site;
2853 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2855 print("Browser: drag-data-received");
2856 var delete_selection_data = false;
2857 vardnd_success = false;
2858 /* Deal with what we are given from source */
2859 if( sel_data && sel_data.length ) {
2861 if (ctx.action == Gdk.DragAction.ASK) {
2862 /* Ask the user to move or copy, then set the ctx action. */
2865 if (ctx.action == Gdk.DragAction.MOVE) {
2866 delete_selection_data = true;
2868 var source = Gtk.drag_get_source_widget(ctx);
2870 print("Browser: source.DRAGDATA? " + source.dragData);
2871 if (this.targetData) {
2872 print(this.targetData);
2873 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2882 if (dnd_success == false)
2884 Seed.print ("DnD data transfer failed!\n");
2887 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2890 create_web_view : function (self, object) {
2891 print("CREATE WEB VIEW");
2892 return null; //new WebKit.WebView();
2898 XObject.prototype.init.call(this);
2899 // this may not work!?
2900 var settings = this.el.get_settings();
2901 settings.enable_developer_extras = true;
2902 // settings.enable_file_access_from_file_uris = true;
2903 // settings.enable_offline_web_application_cache - true;
2904 // settings.enable_universal_access_from_file_uris = true;
2907 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
2908 _this.get('/BottomPane.inspector').el.show();
2909 return _this.get('/BottomPane.inspector').el;
2910 //create_inspector_cb
2914 this.el.open('file:///' + __script_path__ + '/../builder.html');
2918 this.el, /* widget that will accept a drop */
2919 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2920 null, /* lists of target to support */
2921 0, /* size of list */
2922 Gdk.DragAction.COPY /* what to do with data after dropped */
2925 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2926 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2928 renderJS : function(data) {
2929 print("HTML RENDERING");
2930 this.get('/BottomPane').el.show();
2931 this.get('/BottomPane').el.set_current_page(2);// webkit view!
2932 /// prevent looping..
2933 //if (this.pendingRedraw) {
2934 // print("pending redraw active?!");
2939 if (!this.get('/Window.LeftTree').getActiveFile()) {
2943 var project = this.get('/Window.LeftTree').getActiveFile().project;
2944 //print (project.fn);
2946 project.runhtml = project.runhtml || '';
2949 this.runhtml = this.runhtml || '';
2951 if (project.runhtml != this.runhtml) {
2952 // then we need to reload the browser using
2953 // load_html_string..
2955 // then trigger a redraw once it's loaded..
2956 this.pendingRedraw = true;
2957 var runhtml = '<script type="text/javascript">' + "\n" ;
2958 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
2959 runhtml += '</script>'+ "\n" ;
2960 // this.runhtml = '<link rel="stylesheet" type="text/css" href="file://' + __script_path__ + '/../roojs1/cssX/roojs-all.css" />'+ "\n" ;
2961 // this.runhtml += '<script type="text/javascript" src="file://' + __script_path__ + '/../roojs1/roojs-debug.js"></script>'+ "\n" ;
2962 // this.runhtml += '<script type="text/javascript">' + "\n" ;
2963 // this.runhtml += 'Ext=Roo; // bc' + "\n" ;
2964 // this.runhtml += 'Roo.BLANK_IMAGE_URL = "file://' + __script_path__ + '/../roojs1/images/gray/s.gif";'+ "\n" ;
2965 // this.runhtml += 'Roo.rootURL = "file://' + __script_path__ + '/../roojs1/";'+ "\n" ;
2966 // this.runhtml += '</script>'+ "\n" ;
2968 this.runhtml = project.runhtml;
2969 // need to modify paths
2973 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2974 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
2975 print("LOAD HTML " + html);
2976 this.el.load_html_string( html ,
2977 //fixme - should be a config option!
2978 'http://www.akbkhome.com/e/'
2980 // should trigger load_finished!
2985 this.pendingRedraw = false;
2988 this.renderedData = data;
2989 var str = JSON.stringify(data) ;
2992 console.log('not loaded yet');
2994 //Seed.print("RENDER:" + str);
2995 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2997 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3007 id : "RightGtkView",
3009 redraw : function() {
3010 this.highlightWidget = false;
3011 print("REDRAW CALLED");
3012 this.activePath = this.get('/LeftTree').getActivePath();
3013 if (this.renderedEl) {
3014 print("QUEUE DRAW CALLING");
3015 this.renderedEl.queue_draw();
3018 renderJS : function(data, withDebug)
3020 this.highlightWidget = false;
3022 this.withDebug = false;
3024 if (this.renderedEl) {
3025 this.get('view').el.remove(this.renderedEl);
3026 this.renderedEl.destroy();
3027 this.renderedEl = false;
3033 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3034 // in theory tree is actually window..
3036 if (tree['|xns'] == 'GtkClutter') {
3037 GtkClutter = imports.gi.GtkClutter;
3038 GtkClutter.init(null,null);
3039 this.renderedEl = new GtkClutter.Embed();
3041 //this.renderedEl..set_size_request(500,500);
3042 this.get('view').el.add(this.renderedEl);
3044 this.viewAdd(tree.items[0], this.renderedEl);
3045 this.renderedEl.show_all();
3048 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3054 this.get('view').el.set_size_request(
3055 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3058 this.renderedEl.set_size_request(
3059 tree.default_width || 600,
3060 tree.default_height || 400
3062 this.get('view').el.show_all();
3067 showInWindow : function() {
3068 print("GET PROEJCT");
3069 var pr = this.get('/LeftProjectTree').getActiveProject();
3071 console.log(pr.paths);
3074 var src= this.buildJS(
3075 this.get('/LeftTree.model').toJS()[0],
3080 //var x = new imports.sandbox.Context();
3084 Seed.check_syntax('var e = ' + src);
3087 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3088 this.get('/Terminal').feed(console._dump(e)+"\n");
3090 var lines = src.split("\n");
3091 var start = Math.max(0, e.line - 10);
3092 var end = Math.min(lines.length, e.line + 10);
3093 for (var i =start ; i < end; i++) {
3095 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3098 this.get('/Terminal').feed(lines[i] + "\n");
3105 this.get('/BottomPane').el.set_current_page(1);
3106 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3107 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3108 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3110 var _top = x.get_global_object()._top;
3112 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3114 if (_top.el.popup) {
3115 _top.el.popup(null, null, null, null, 3, null);
3119 viewAdd : function(item, par)
3121 // does something similar to xobject..
3122 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3124 if (item.pack===false || item.pack === 'false') { // no ;
3127 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3128 var type = item['|xns'] + '.' + item['xtype'];
3129 var ns = imports.gi[item['|xns']];
3130 var ctr = ns[item['xtype']];
3132 for(var k in item) {
3134 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3149 if (k[0] == '|' && typeof(kv) == 'string') {
3151 if (kv.match(new RegExp('function'))) {
3154 print("WASL " + k + '=' + kv);
3156 eval( 'kv = ' + kv);
3157 } catch(e) { continue; }
3160 // print(k + '=' + kv);
3162 if (k[0] == '|') { // should be boolean or number..
3164 //print(k + '=' + kv);
3167 if (k == 'show_tabs') { // force tab showing for notebooks.
3170 print(k + '=' + typeof(kv) + " : " + kv);
3176 var el = new ctr(ctr_args);
3178 print("PACK" + item.pack);
3179 //console.dump(item.pack);
3186 if (typeof(item.pack) == 'string') {
3188 item.pack.split(',').forEach(function(e, i) {
3190 if (e == 'false') { args.push( false); return; }
3191 if (e == 'true') { args.push( true); return; }
3192 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3195 //print(args.join(","));
3197 pack_m = args.shift();
3199 pack_m = item.pack.shift();
3204 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3206 name: "ArgumentError",
3207 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3208 "ADDING : " + item.id + " " + el
3217 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3218 //Seed.print('args: ' + args.length);
3220 par[pack_m].apply(par, args);
3224 item.items = item.items || [];
3225 item.items.forEach(function(ch,n) {
3227 print ("type:" + type);
3229 print ("ch.pack:" + ch.pack);
3230 if (type == 'Gtk.Table' && ch.pack == 'add') {
3231 var c = n % item.n_columns;
3232 var r = Math.floor(n/item.n_columns);
3233 ch.pack = [ 'attach', c, c+1, r, r+1,
3234 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3235 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3236 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3237 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3241 _this.viewAdd(ch, el);
3246 // add the signal handlers.
3247 // is it a widget!?!!?
3253 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3254 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3255 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3256 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3257 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3267 widgetDragDropEvent : function() {
3268 print("WIDGET DRAGDROP");
3271 widgetDragMotionEvent : function() {
3272 print("WIDGET DRAGMOTION");
3275 widgetExposeEvent : function(w, evt, ud, item) {
3277 if (this.inRender) {
3281 if ( this.highlightWidget) {
3282 this.inRender = true;
3283 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3284 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3286 this.inRender = false;
3291 if (this.activePath != item.xtreepath) {
3295 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3296 // work out the coords of the window..
3298 var dr = widget.window;
3299 this.gc = (new Gdk.GC.c_new(dr));
3300 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3301 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3305 var r = evt.expose.area;
3306 // console.dump([r.x, r.y, r.width, r.height ] );
3308 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3309 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3310 // happens with gtkscrollview embedded stuff..
3311 var np =this.activePath.split(':');
3313 this.activePath = np.join(':');
3314 this.renderedEl.queue_draw();
3330 this.inRender = true;
3333 this.highlightWidget = widget;
3338 // print("DRAW BOX");
3339 //console.dump(this.box);
3340 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3341 this.inRender = false;
3344 widgetPressEvent : function(w,e,u,d) {
3345 if (this.get('view').pressed) {
3348 this.get('view').pressed = true;
3349 print("WIDGET PRESS " + d.xtreepath );
3350 this.get('/LeftTree.view').selectNode( d.xtreepath );
3353 widgetReleaseEvent : function() {
3354 this.get('view').pressed = false;
3360 pack : "pack_start,false,true,0",
3364 pack : "pack_start,false,false,0",
3365 label : "Run The Application",
3367 button_press_event : function (self, event) {
3368 // call render on left tree - with special option!?!
3370 //print("GET PROEJCT");
3371 var pr = this.get('/LeftProjectTree').getActiveProject();
3374 for (var i in pr.paths) {
3378 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3379 this.get('/Terminal').feed("RUN DIR:" + dir);
3381 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3382 , false,false,false);
3383 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3384 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3394 xtype: Gtk.ScrolledWindow,
3397 shadow_type : Gtk.ShadowType.IN,
3399 XObject.prototype.init.call(this);
3400 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3404 xtype: Gtk.EventBox,
3405 pack : "add_with_viewport",
3407 XObject.prototype.init.call(this);
3408 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3409 red: 0x9F00, green: 0xB800 , blue : 0xA800
3417 XObject.prototype.init.call(this);
3418 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3419 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3424 xtype: Gtk.EventBox,
3427 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3428 XObject.prototype.init.call(this);
3432 this.el, /* widget that will accept a drop */
3433 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3434 null, /* lists of target to support */
3435 0, /* size of list */
3436 Gdk.DragAction.COPY /* what to do with data after dropped */
3439 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3440 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3443 getActiveNode : function(x,y)
3445 // workout what node is here..
3446 return '0'; // top..
3450 drag_motion : function (self, ctx, x, y, time) {
3452 // A) find out from drag all the places that node could be dropped.
3453 var src = Gtk.drag_get_source_widget(ctx);
3454 if (!src.dropList) {
3455 Gdk.drag_status(ctx, 0, time);
3458 // b) get what we are over.. (from activeNode)
3459 // tree is empty.. - list should be correct..
3460 if (!this.get('/LeftTree.model').currentTree) {
3461 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3465 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3466 var activeNode = this.getActiveNode(x, y);
3469 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3472 Gdk.drag_status(ctx, 0,time);
3473 this.get('/LeftTree.view').highlight(false);
3477 // if we have a target..
3478 // -> highlight it! (in browser)
3479 // -> highlight it! (in tree)
3481 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3482 this.get('/LeftTree.view').highlight(tg);
3483 this.targetData = tg;
3484 // for tree we should handle this...
3487 drag_drop : function (self,ctx, x, y, time) {
3488 Seed.print("TARGET: drag-drop");
3489 var is_valid_drop_site = true;
3494 self, /* will receive 'drag-data-received' signal */
3495 ctx, /* represents the current state of the this.gDnD */
3496 this.get('/Window').atoms["STRING"], /* the target type we want */
3497 time /* time stamp */
3501 /* No target offered by source => error */
3504 return is_valid_drop_site;
3507 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3509 Seed.print("GtkView: drag-data-received");
3510 var delete_selection_data = false;
3511 var dnd_success = false;
3512 /* Deal with what we are given from source */
3513 if( sel_data && sel_data.length ) {
3515 if (ctx.action == Gdk.DragAction.ASK) {
3516 /* Ask the user to move or copy, then set the ctx action. */
3519 if (ctx.action == Gdk.DragAction.MOVE) {
3520 delete_selection_data = true;
3522 var source = Gtk.drag_get_source_widget(ctx);
3524 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3525 if (this.targetData) {
3526 Seed.print(this.targetData);
3527 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3536 if (dnd_success == false)
3538 Seed.print ("DnD data transfer failed!\n");
3541 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3544 button_press_event : function (self, event) {
3545 this.pressed = false;
3561 xtype: Gtk.ScrolledWindow,
3566 var file = this.get('/LeftTree').getActiveFile();
3570 var activeEl = this.get('/LeftTree').getActiveElement();
3571 var xtype = file.guessName( activeEl )
3572 if (!xtype || !xtype.length) {
3575 //this.get('/Window.view-help-nb').el.set_current_page(1);
3577 // get the active element being edited.
3578 var helpurl = file.getHelpUrl(xtype);
3580 // now load the help info in the page..
3581 this.get('help-view').el.open(helpurl);
3585 xtype: WebKit.WebView,
3589 XObject.prototype.init.call(this);
3590 this.get('/Window.help-view').el.open(
3591 "http://devel.akbkhome.com/seed/");
3603 xtype: Gtk.Notebook,
3607 XObject.prototype.init.call(this);
3608 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3609 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3610 this.el.set_tab_label(this.items[2].el, new Gtk.Label({ label : "Inspector" }));
3614 xtype: Gtk.ScrolledWindow,
3619 xtype: GtkSource.View,
3623 XObject.prototype.init.call(this);
3624 var description = Pango.Font.description_from_string("monospace")
3625 description.set_size(8000);
3626 this.el.modify_font(description);
3629 load : function(str) {
3631 // show the help page for the active node..
3632 this.get('/Help').show();
3635 this.get('/BottomPane').el.set_current_page(0);
3636 this.el.get_buffer().set_text(str, str.length);
3637 var lm = GtkSource.LanguageManager.get_default();
3639 this.el.get_buffer().set_language(lm.get_language('js'));
3640 var buf = this.el.get_buffer();
3641 var cursor = buf.get_mark("insert");
3642 var iter= new Gtk.TextIter;
3643 buf.get_iter_at_mark(iter, cursor);
3645 iter.set_line_offset(4);
3646 buf.move_mark(cursor, iter);
3649 cursor = buf.get_mark("selection_bound");
3650 iter= new Gtk.TextIter;
3651 buf.get_iter_at_mark(iter, cursor);
3653 iter.set_line_offset(4);
3654 buf.move_mark(cursor, iter);
3656 this.el.grab_focus();
3658 insert_spaces_instead_of_tabs : true,
3661 show_line_numbers : true,
3664 xtype: GtkSource.Buffer,
3665 pack : "set_buffer",
3667 changed : function (self) {
3668 var s = new Gtk.TextIter();
3669 var e = new Gtk.TextIter();
3670 this.el.get_start_iter(s);
3671 this.el.get_end_iter(e);
3672 var str = this.el.get_text(s,e,true);
3674 Seed.check_syntax('var e = ' + str);
3676 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3677 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3679 print("SYNTAX ERROR IN EDITOR");
3684 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3685 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3688 this.get('/LeftPanel.model').changed( str , false);
3697 xtype: Gtk.ScrolledWindow,
3701 xtype: Vte.Terminal,
3704 feed : function(istr) {
3705 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3706 // we should make ourselves visable!!!
3707 this.get('/BottomPane').el.show();
3708 this.get('/BottomPane').el.set_current_page(1);
3710 this.el.feed(str ,str.length);
3712 scroll_on_output : true,
3714 XObject.prototype.init.call(this);
3715 this.el.set_size (80, 1000);
3717 scrollback_lines : 1000
3722 xtype: Gtk.ScrolledWindow,
3726 xtype: WebKit.WebView,
3738 pack : "pack_start,false,false",
3742 this.get('buttonbar').el.show();
3743 this.get('viewbox').el.hide();
3744 print("TRIED TO HIDE");
3747 this.get('buttonbar').el.hide();
3748 this.get('viewbox').el.show();
3749 // this.get('model').expanded();
3761 pack : "pack_start,false,true",
3763 clicked : function (self) {
3764 this.get('/RightPalete').show();
3771 stock : Gtk.STOCK_GOTO_FIRST,
3772 icon_size : Gtk.IconSize.MENU
3782 XObject.prototype.init.call(this);
3783 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3786 enter_notify_event : function (self, event) {
3787 this.get('/RightPalete').show();
3801 pack : "pack_start,false,true",
3810 pack : "pack_start,false,true",
3812 clicked : function (self) {
3813 this.get('/RightPalete').hide();
3820 stock : Gtk.STOCK_GOTO_LAST,
3821 icon_size : Gtk.IconSize.MENU
3828 xtype: Gtk.ScrolledWindow,
3831 XObject.prototype.init.call(this);
3832 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3833 this.el.set_size_request(-1,200);
3835 shadow_type : Gtk.ShadowType.IN,
3838 xtype: Gtk.TreeView,
3841 XObject.prototype.init.call(this);
3842 this.el.set_size_request(150,-1);
3843 // set_reorderable: [1]
3845 var description = new Pango.FontDescription.c_new();
3846 description.set_size(8000);
3847 this.el.modify_font(description);
3849 this.selection = this.el.get_selection();
3850 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3851 // this.selection.signal['changed'].connect(function() {
3852 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3854 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3856 Gtk.drag_source_set (
3857 this.el, /* widget will be drag-able */
3858 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3859 null, /* lists of target to support */
3860 0, /* size of list */
3861 Gdk.DragAction.COPY /* what to do with data after dropped */
3863 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3865 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3866 Gtk.drag_source_add_text_targets(this.el);
3868 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3869 targets = new Gtk.TargetList();
3870 targets.add( LeftTree.atoms["STRING"], 0, 0);
3871 targets.add_text_targets( 1 );
3872 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3874 //if you want to allow text to be output elsewhere..
3875 //Gtk.drag_source_add_text_targets(this.el);
3879 headers_visible : false,
3880 enable_tree_lines : true,
3882 drag_begin : function (self, ctx) {
3883 // we could fill this in now...
3884 Seed.print('SOURCE: drag-begin');
3888 var iter = new Gtk.TreeIter();
3889 var s = this.selection;
3890 s.get_selected(this.get('/RightPalete.model').el, iter);
3891 var path = this.get('/RightPalete.model').el.get_path(iter);
3893 var pix = this.el.create_row_drag_icon ( path);
3896 Gtk.drag_set_icon_pixmap (ctx,
3903 var value = new GObject.Value('');
3904 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3905 if (!this.get('/RightPalete').provider) {
3908 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3909 this.el.dragData = value.value;
3916 drag_data_get : function (self, drag_context, selection_data, info, time) {
3917 //Seed.print('Palete: drag-data-get: ' + target_type);
3918 if (this.el.dragData && this.el.dragData.length ) {
3919 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3923 //this.el.dragData = "TEST from source widget";
3927 drag_end : function (self, drag_context) {
3928 Seed.print('SOURCE: drag-end');
3929 this.el.dragData = false;
3930 this.el.dropList = false;
3931 this.get('/LeftTree.view').highlight(false);
3937 xtype: Gtk.ListStore,
3940 XObject.prototype.init.call(this);
3941 this.el.set_column_types ( 2, [
3942 GObject.TYPE_STRING, // title
3943 GObject.TYPE_STRING // tip
3948 load : function(tr,iter)
3953 //console.log('Project tree load: ' + tr.length);
3954 var citer = new Gtk.TreeIter();
3955 //this.insert(citer,iter,0);
3956 for(var i =0 ; i < tr.length; i++) {
3959 this.el.append(citer);
3961 this.el.insert(citer,iter,-1);
3966 this.el.set_value(citer, 0, '' + r ); // title
3968 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3969 //if (r.cn && r.cn.length) {
3970 // this.load(r.cn, citer);
3976 getValue : function (iter, col) {
3977 var gval = new GObject.Value('');
3978 this.el.get_value(iter, col ,gval);
3985 xtype: Gtk.TreeViewColumn,
3986 pack : "append_column",
3988 XObject.prototype.init.call(this);
3989 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3993 xtype: Gtk.CellRendererText,
4015 XObject.cache['/Window'] = Window;