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 GtkClutter = imports.gi.GtkClutter;
11 console = imports.console;
12 XObject = imports.XObject.XObject;
16 delete_event : function (self, event) {
19 destroy : function (self) {
22 show : function (self) {
23 print("WINDOW SHOWING - trying to hide");
24 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
25 this.get('/MidPropTree').hideWin();
26 this.get('/RightPalete').hide();
27 this.get('/BottomPane').el.hide();
28 this.get('/EditorWindow').el.show_all();
36 title : "Application Builder",
39 "STRING" : Gdk.atom_intern("STRING")
41 this.targetList = new Gtk.TargetList();
42 this.targetList.add( this.atoms["STRING"], 0, 0);
43 //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
45 "style \"gtkcombobox-style\" {\n" +
46 " GtkComboBox::appears-as-list = 1\n" +
48 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
49 XObject.prototype.init.call(this);
55 setTitle : function(str) {
56 this.el.set_title(this.title + ' - ' + str);
58 type : Gtk.WindowType.TOPLEVEL,
66 pack : "pack_start,false,false",
80 label : "New _Project",
82 activate : function (self) {
84 this.get('/EditProject').show({
85 success : function(pr) {
86 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
97 activate : function (self) {
98 var fn = this.get('/LeftProjectTree.combo').getValue();
100 this.get('/LeftProjectTree').showNoProjectSelected();
103 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
104 this.get('/DialogNewComponent').show({
105 project : pm.getByFn(fn)
111 xtype: Gtk.SeparatorMenuItem,
116 use_underline : true,
118 label : "D_elete Project",
120 activate : function (self) {
122 var fn = this.get('/LeftProjectTree').get('combo').getValue();
124 this.get('/StandardErrorDialog').show("Select a project")
127 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
128 var pr = pm.getByFn(fn);
131 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
132 pm.deleteProject(fn);
140 xtype: Gtk.SeparatorMenuItem,
147 use_underline : true,
149 activate : function (self) {
161 use_underline : true,
166 pack : "set_submenu",
171 activate : function (self) {
172 var fn = this.get('/LeftTree').getActiveFile();
174 this.get('/StandardErrorDialog').show("No File active");
178 this.get('/DialogNewComponent').show(fn);
182 label : "File _Properties",
189 activate : function (self, event) {
190 this.get('/RooProjectProperties').show();
194 label : "Modify Project HTML ",
205 use_underline : true,
209 pack : "set_submenu",
214 activate : function (self, event) {
215 var js = this.get('/LeftTree.model').toJS();
217 this.get('/RightBrowser.view').renderJS(js[0], true);
222 label : "_Redraw (Roo)",
229 activate : function (self, event)
231 /* Firefox testing for debugging..
232 - we can create a /tmp directory, and put.
233 builder.html, builder.html.js, link roojs1
234 add at the end of builder.html Roo.onload(function() {
236 if (!this.get('/Window.LeftTree').getActiveFile()) {
240 var js = this.get('/LeftTree.model').toJS();
244 var project = this.get('/Window.LeftTree').getActiveFile().project;
245 //print (project.fn);
247 project.runhtml = project.runhtml || '';
250 var File = imports.File.File;
252 var target = "/tmp/firetest"; // fixme..
253 if (!File.isDirectory(target)) {
256 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
257 if (!File.exists( target+ '/roojs1')) {
258 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
263 var html = imports.File.File.read(__script_path__ + '/../builder.html');
264 html = html.replace('</head>', project.runhtml + '</head>');
267 var jsstr = JSON.stringify(js[0], null, 4);
269 var runbuilder = '<script type="text/javascript">' + "\n" +
270 " Builder.render(" + jsstr + ");\n" +
273 html = html.replace('</body>', runbuilder + '</body>');
275 File.write( target+ '/builder.html', html);
277 this.get('/Terminal').feed("RUN DIR:" + target);
279 this.get('/Terminal').el.fork_command( null , [], [], target
280 , false,false,false);
281 var cmd = "firefox file://" + target + "/builder.html \n";
282 this.get('/Terminal').el.feed_child(cmd, cmd.length);
286 label : "_Test in Firefox (Roo)",
297 use_underline : true,
302 pack : "set_submenu",
308 use_underline : true,
310 activate : function (self) {
311 this.get('/About').el.run();
341 activate : function (self) {
342 // this does not actually expand it..
343 // that is done by GTK..
347 if (!this.el.expanded) {
354 enter_notify_event : function (self, event) {
356 this.el.expanded = !this.el.expanded;
357 //if (this.el.expanded ) {
358 this.listeners.activate.call(this);
365 label : "Select Project or File",
366 pack : "pack_start,false,true",
367 onCollapse : function() {
369 var nb = this.get('/LeftTopPanel.notebook');
370 nb.el.set_current_page(0);
373 XObject.prototype.init.call(this);
374 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
376 onExpand : function() {
377 var nb = this.get('/LeftTopPanel.notebook');
378 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
381 var model = this.get('/LeftProjectTree.combomodel');
382 // print ("loading Projects?")
383 //console.dump(pm.projects);
384 model.loadData(pm.projects);
387 nb.el.set_current_page(1);
388 //pm.on('changed', function() {
389 //console.log("CAUGHT project manager change");
390 // _combo.model.loadData(pm.projects);
398 pack : "pack_start,true,true",
400 XObject.prototype.init.call(this);
401 this.el.set_current_page(0);
408 xtype: Gtk.ScrolledWindow,
411 getActiveElement : function() { // return path to actie node.
413 var path = this.getActivePath();
417 var iter = new Gtk.TreeIter();
418 this.get('model').el.get_iter_from_string(iter, path);
420 var value = new GObject.Value('');
421 this.get('model').el.get_value(iter, 2, value);
423 return JSON.parse(value.value);
425 getActiveFile : function() {
426 return this.get('model').file;
428 getActivePath : function() {
429 var model = this.get('model');
430 var view = this.get('view');
431 if (view.selection.count_selected_rows() < 1) {
434 var iter = new Gtk.TreeIter();
436 view.selection.get_selected(model.el, iter);
437 return model.el.get_path(iter).to_string();
439 getPaleteProvider : function() {
440 var model = this.get('model');
441 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
442 return pm.getPalete(model.file.getType());
444 getRenderer : function() {
446 switch( this.getActiveFile().getType()) {
448 return this.get('/RightBrowser.view');
450 return this.get('/RightGtkView');
455 XObject.prototype.init.call(this);
456 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
458 renderView : function() {
459 var render = this.getRenderer();
460 var model = this.get('model');
462 render.renderJS(model.toJS(false,true)[0]);
464 print("NO RENDER JS METHOD?");
467 shadow_type : Gtk.ShadowType.IN,
472 button_press_event : function (self, ev) {
473 console.log("button press?");
474 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
475 print("click" + ev.type);
481 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
483 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
485 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
486 this.get('/LeftTreeMenu').el.show_all();
487 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
488 print("click:" + res.path.to_string());
491 drag_begin : function (self, drag_context) {
492 print('SOURCE: drag-begin');
493 this.targetData = false;
494 // find what is selected in our tree...
495 var iter = new Gtk.TreeIter();
496 var s = this.selection;
497 s.get_selected(this.get('/LeftTree.model').el, iter);
499 // set some properties of the tree for use by the dropped element.
500 var value = new GObject.Value('');
501 this.get('/LeftTree.model').el.get_value(iter, 2, value);
502 var data = JSON.parse(value.value);
503 var xname = this.get('/LeftTree.model').file.guessName(data);
505 this.el.dragData = xname;
506 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
509 // make the drag icon a picture of the node that was selected
510 var path = this.get('/LeftTree.model').el.get_path(iter);
511 this.el.treepath = path.to_string();
513 var pix = this.el.create_row_drag_icon ( path);
515 Gtk.drag_set_icon_pixmap (ctx,
524 drag_end : function (self, drag_context) {
525 Seed.print('LEFT-TREE: drag-end');
526 this.el.dragData = false;
527 this.el.dropList = false;
528 this.targetData = false;
529 this.get('/LeftTree.view').highlight(false);
532 drag_motion : function (self, ctx, x, y, time) {
533 console.log("LEFT-TREE: drag-motion");
534 var src = Gtk.drag_get_source_widget(ctx);
536 // a drag from elsewhere...- prevent drop..
538 print("no drag data!");
539 Gdk.drag_status(ctx, 0, time);
540 this.targetData = false;
543 var action = Gdk.DragAction.COPY;
544 if (src == this.el) {
545 // unless we are copying!!! ctl button..
546 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
550 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
551 // no children.. -- asume it's ok..
552 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
553 Gdk.drag_status(ctx, action ,time);
557 print("GETTING POS");
558 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
559 print("ISOVER? " + isOver);
561 Gdk.drag_status(ctx, 0 ,time);
562 return false; // not over apoint!?!
564 // drag node is parent of child..
565 console.log("SRC TREEPATH: " + src.treepath);
566 console.log("TARGET TREEPATH: " + data.path.to_string());
568 // nned to check a few here..
569 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
570 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
571 //Gtk.TreeViewDropPosition.AFTER
572 //Gtk.TreeViewDropPosition.BEFORE
574 if (typeof(src.treepath) != 'undefined' &&
575 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
576 print("subpath drag");
577 Gdk.drag_status(ctx, 0 ,time);
582 //print("DUMPING DATA");
583 //console.dump(data);
586 print(data.path.to_string() +' => '+ data.pos);
587 var tg = this.get('/LeftTree.model').findDropNodeByPath(
588 data.path.to_string(), src.dropList, data.pos);
590 this.get('/LeftTree.view').highlight(tg);
592 print("Can not find drop node path");
593 this.targetData = false;
594 Gdk.drag_status(ctx, 0, time);
598 this.targetData = tg;
601 Gdk.drag_status(ctx, action ,time);
605 drag_drop : function (w, ctx, x, y, time) {
606 Seed.print("TARGET: drag-drop");
610 w, /* will receive 'drag-data-received' signal */
611 ctx, /* represents the current state of the DnD */
612 this.get('/Window').atoms["STRING"], /* the target type we want */
613 time /* time stamp */
617 /* No target offered by source => error */
622 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
623 print("Tree: drag-data-received");
625 var delete_selection_data = false;
626 var dnd_success = false;
627 /* Deal with what we are given from source */
628 if( sel_data && sel_data.length ) {
630 if (ctx.action == Gdk.DragAction.ASK) {
631 /* Ask the user to move or copy, then set the ctx action. */
634 if (ctx.action == Gdk.DragAction.MOVE) {
635 //delete_selection_data = true;
638 var source = Gtk.drag_get_source_widget(ctx);
640 if (this.targetData) {
641 if (source != this.el) {
642 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
644 // drag around.. - reorder..
645 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
649 //Seed.print(this.targetData);
655 // we can send stuff to souce here...
661 if (dnd_success == false)
663 Seed.print ("DnD data transfer failed!\n");
666 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
669 cursor_changed : function (self) {
670 if (this.blockChanges) { // probably not needed..
673 var render = this.get('/LeftTree').getRenderer();
676 if (this.selection.count_selected_rows() < 1) {
677 this.get('/LeftPanel.model').load( false);
678 this.get('/MidPropTree').activeElement = false;
679 this.get('/MidPropTree').hideWin();
681 var pm = this.get('/RightPalete.model');
682 if (!this.get('/LeftTree').getPaleteProvider()) {
683 // it may not be loaded yet..
686 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
687 this.get('/LeftTree.model').listAllTypes()));
688 if (render && render.redraw) {
694 //console.log('changed');
695 var s = this.selection;
696 var iter = new Gtk.TreeIter();
697 s.get_selected(this.get('/LeftTree.model').el, iter);
701 var value = new GObject.Value('');
702 this.get('/LeftTree.model').el.get_value(iter, 2, value);
703 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
705 var data = JSON.parse(value.value);
706 this.get('/MidPropTree').activeElement = data;
707 this.get('/MidPropTree').hideWin();
708 this.get('/LeftPanel.model').load( data);
710 console.log(value.value);
711 // _g.button.set_label(''+value.get_string());
713 var pm =this.get('/RightPalete.model');
714 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
715 this.get('/LeftTree.model').listAllTypes()));
718 if (render && render.redraw) {
722 //Seed.print( value.get_string());
730 enable_tree_lines : true,
731 headers_visible : false,
732 highlight : function(treepath_ar) {
734 // highlighting for drag/drop
735 if (treepath_ar.length && treepath_ar[0].length ) {
736 this.el.set_drag_dest_row(
737 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
739 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
744 XObject.prototype.init.call(this);
745 var description = new Pango.FontDescription.c_new();
746 description.set_size(8000);
747 this.el.modify_font(description);
749 this.selection = this.el.get_selection();
750 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
753 // is this really needed??
754 this.selection.signal['changed'].connect(function() {
755 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
756 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
760 Gtk.drag_source_set (
761 this.el, /* widget will be drag-able */
762 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
763 null, /* lists of target to support */
764 0, /* size of list */
765 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
768 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
770 Gtk.drag_source_add_text_targets(this.el);
773 this.el, /* widget that will accept a drop */
774 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
775 null, /* lists of target to support */
776 0, /* size of list */
777 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
780 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
781 Gtk.drag_dest_add_text_targets(this.el);
783 selectNode : function(treepath_str) {
784 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
785 var tp = new Gtk.TreePath.from_string(treepath_str);
786 this.el.set_cursor(tp, null, false);
787 this.el.scroll_to_cell(tp, null, false, 0,0);
791 xtype: Gtk.TreeStore,
796 changed : function(n, refresh) {
797 // print("MODEL CHANGED CALLED" + this.activePath);
798 if (this.activePath) {
799 var iter = new Gtk.TreeIter();
800 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
801 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
802 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
804 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
806 //this.currentTree = this.toJS(false, true)[0];
808 this.file.items = this.toJS(false, false);
809 print ("TO JS in " + ((new Date()) - d) + "ms");
810 // print("AFTER CHANGED");
811 //console.dump(this.file.items);
813 this.currentTree = this.file.items[0];
814 //console.log(this.file.toSource());
817 print("REDNER BROWSER?!");
818 this.get('/LeftTree').renderView();
820 var pm = this.get('/RightPalete.model');
821 if (!this.get('/RightPalete').provider) {
827 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
828 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
832 deleteSelected : function() {
833 this.get('/LeftTree.view').blockChanges = true;
834 var old_iter = new Gtk.TreeIter();
835 var s = this.get('/LeftTree.view').selection;
836 s.get_selected(this.el, old_iter);
837 var path = this.el.get_path(old_iter).to_string();
839 this.activePath= false;
842 this.activePath= false;
843 var iter = new Gtk.TreeIter();
844 this.el.get_iter_from_string(iter, path);
845 this.el.remove(iter);
847 // rebuild treemap. -- depreciated.!!
850 //this.toJS(null, true) // does not do anything?
851 this.activePath= false;
852 this.changed(false,true);
853 this.get('/LeftTree.view').blockChanges = false;
855 dropNode : function(target_data, node) {
857 // console.dump(node);
858 // console.dump(target_data);
859 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
861 print("add " + tp + "@" + target_data[1] );
864 if (tp && target_data[1] < 2) { // before or after..
865 var ar = target_data[0].split(':');
867 parent = new Gtk.TreePath.from_string( ar.join(':') );
870 var n_iter = new Gtk.TreeIter();
871 var iter_par = new Gtk.TreeIter();
872 var iter_after = after ? new Gtk.TreeIter() : false;
876 if (parent !== false) {
877 this.el.get_iter(iter_par, parent);
884 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
885 this.el.get_iter(iter_after, after);
886 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
887 n_iter, iter_par, iter_after);
890 this.el.append(n_iter, iter_par);
894 if (typeof(node) == 'string') {
895 var ar = node.split('.');
896 var xtype = ar.pop();
899 '|xns' : ar.join('.'),
902 if (target_data.length == 3 && target_data[2].length) {
903 node['*prop'] = target_data[2];
905 node = this.get('/DialogTemplateSelect').show(node);
908 // work out what kind of packing to use..
909 if (typeof(node.pack) == 'undefined' && parent !== false) {
910 var pal = this.get('/LeftTree').getPaleteProvider();
911 if (pal.name == 'Gtk') {
912 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
913 var cname = pal.guessName(node);
914 node.pack = pal.getDefaultPack(pname, cname);
925 // load children - if it has any..
928 this.load(xitems, n_iter);
929 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
931 if (tp && (xitems || after)) {
932 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
934 // wee need to get the empty proptypes from somewhere..
936 //var olditer = this.activeIter;
937 this.activePath = this.el.get_path(n_iter).to_string();
939 // changed actually set's the node data..
940 this.changed(node, true);
944 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
946 //Builder.MidPropTree._model.load(node);
947 //Builder.MidPropTree._win.hideWin();
948 //Builder.LeftPanel._model.load( node);
952 findDropNode : function(treepath_str, targets) {
954 // this is used by the dragdrop code in the roo version AFAIR..
956 var path = treepath_str.replace(/^builder-/, '');
957 // treemap is depreciated... - should really check if model has any entries..
959 if (!this.el.iter_n_children(null)) {
961 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
963 print("FIND treepath: " + path);
964 //console.dump(this.treemap);
966 if (!treepath_str.match(/^builder-/)) {
967 return []; // nothing!
969 if (targets === true) {
972 return this.findDropNodeByPath(path,targets)
974 findDropNodeByPath : function(treepath_str, targets, pref) {
975 var path = treepath_str + ''; // dupe it..
976 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
978 //console.dump(this.treemap);
979 while (path.length) {
980 print("LOOKING FOR PATH: " + path);
981 var node_data = this.singleNodeToJS(path);
982 if (node_data === false) {
983 print("node not found");
987 var xname = this.get('/LeftTree.model').file.guessName(node_data);
990 targets.forEach(function(tg) {
994 if ((tg == xname) ) {
997 if (tg.indexOf(xname +':') === 0) {
999 prop = tg.split(':').pop();
1004 if (last) { // pref is after/before..
1005 // then it's after last
1007 return []; // do not allow..
1009 return [ last, pref , prop];
1012 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1014 var par = path.split(':');
1017 path = par.join(':');
1023 getIterValue : function (iter, col) {
1024 var gval = new GObject.Value('');
1025 this.el.get_value(iter, col ,gval);
1031 XObject.prototype.init.call(this);
1032 this.el.set_column_types ( 3, [
1033 GObject.TYPE_STRING, // title
1034 GObject.TYPE_STRING, // tip
1035 GObject.TYPE_STRING // source..
1038 listAllTypes : function() {
1039 var s = this.get('/LeftTree.view').selection;
1040 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1042 if (s.count_selected_rows() > 0) {
1043 var iter = new Gtk.TreeIter();
1044 s.get_selected(this.el, iter);
1046 // set some properties of the tree for use by the dropped element.
1047 var value = new GObject.Value('');
1048 this.el.get_value(iter, 2, value);
1049 var data = JSON.parse(value.value);
1052 var xname = this.get('/LeftTree.model').file.guessName(data);
1053 console.log('selected:' + xname);
1057 return []; // could not find it..
1065 li.forEach(function(el) {
1066 // this is specific to roo!!!?
1067 if (!el) { // skip empty?
1070 var fullpath = _this.file.guessName(el);
1071 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1076 if (el.items && el.items.length) {
1085 addall([this.currentTree]);
1087 // only if we have nothing, should we add '*top'
1091 //console.log('all types in tree');
1092 //console.dump(ret);
1097 load : function(tr,iter)
1099 var citer = new Gtk.TreeIter();
1100 //this.insert(citer,iter,0);
1101 for(var i =0 ; i < tr.length; i++) {
1103 this.el.insert(citer,iter,-1);
1105 this.el.append(citer);
1108 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1109 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1110 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1111 if (tr[i].items && tr[i].items.length) {
1112 this.load(tr[i].items, citer);
1116 loadFile : function(f) {
1122 console.log('missing file');
1126 // load the file if not loaded..
1127 if (f.items === false) {
1129 f.loadItems(function() {
1135 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1137 if (f.items.length && typeof(f.items[0]) == 'string') {
1139 this.get('/RightEditor').el.show();
1140 this.get('/RightEditor.view').load( f.items[0]);
1144 print(JSON.stringify(f.items, null,4));
1145 //console.dump(f.items);
1147 this.get('/LeftTree.view').el.expand_all();
1149 if (!f.items.length) {
1152 this.get('/Window.leftvpaned').el.set_position(80);
1154 this.get('/LeftTree.view').el.set_cursor(
1155 new Gtk.TreePath.from_string('0'), null, false);
1159 this.get('/Window.leftvpaned').el.set_position(200);
1163 //print("hide right editior");
1164 this.get('/RightEditor').el.hide();
1165 //print("set current tree");
1166 this.currentTree = this.toJS(false, false)[0];
1167 //console.dump(this.currentTree);
1168 this.currentTree = this.currentTree || { items: [] };
1169 this.get('/LeftTree').renderView();
1170 //console.dump(this.map);
1171 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1172 var pm = this.get('/RightPalete.model');
1173 // set up provider..
1175 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1177 if (!this.get('/RightPalete').provider) {
1178 print ("********* PALETE PROVIDER MISSING?!!");
1180 this.get('/LeftTree').renderView();
1182 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1186 this.get('/Window.view-notebook').el.set_current_page(
1187 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1190 moveNode : function(target_data, action) {
1191 //print("MOVE NODE");
1192 // console.dump(target_data);
1193 var old_iter = new Gtk.TreeIter();
1194 var s = this.get('/LeftTree.view').selection;
1195 s.get_selected(this.el, old_iter);
1196 var node = this.nodeToJS(old_iter,false);
1197 //console.dump(node);
1200 // needs to drop first, otherwise the target_data
1201 // treepath will be invalid.
1203 this.dropNode(target_data, node);
1204 if (action & Gdk.DragAction.MOVE) {
1205 // print("REMOVING OLD NODE");
1206 this.el.remove(old_iter);
1210 this.activePath= false;
1211 this.changed(false,true);
1213 nodeTip : function(c) {
1214 var ret = this.nodeTitle(c,true);
1220 if (!i.length || i[0] != '|') {
1226 if (typeof(c[i]) != 'string') {
1229 //print("prop : " + i + ':' + c[i]);
1230 if (!c[i].match(new RegExp('function'))) {
1233 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1237 ret+="\n\nMethods:" + funcs;
1242 nodeTitle : function(c, renderfull) {
1245 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1246 if (sr) txt.push('<s>');
1247 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1249 if (renderfull && c['|xns']) {
1250 txt.push(c['|xns']);
1253 if (c.xtype) { txt.push(c.xtype); }
1254 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1255 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1256 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1259 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1260 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1261 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1262 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1263 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1264 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1265 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1266 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1267 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1269 // for flat classes...
1270 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1271 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1274 if (sr) txt.push('</s>');
1275 return (txt.length == 0 ? "Element" : txt.join(" "));
1277 nodeToJS : function (treepath, with_id)
1280 var iter = treepath; // API used to be iter here..
1281 if (typeof(iter) == 'string') {
1282 iter = new Gtk.TreeIter();
1283 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1287 var par = new Gtk.TreeIter();
1288 var iv = this.getIterValue(iter, 2);
1289 // print("IV" + iv);
1290 var k = JSON.parse(iv);
1291 if (k.json && !this.el.iter_parent( par, iter )) {
1296 var treepath_str = this.el.get_path(iter).to_string();
1297 // not sure how we can handle mixed id stuff..
1298 if (typeof(k.id) == 'undefined') {
1299 k.id = 'builder-'+ treepath_str ;
1303 this.treemap[ treepath_str ] = k;
1304 k.xtreepath = treepath_str ;
1307 if (this.el.iter_has_child(iter)) {
1308 citer = new Gtk.TreeIter();
1309 this.el.iter_children(citer, iter);
1310 k.items = this.toJS(citer,with_id);
1314 nodeToJSON : function(c) {
1322 return JSON.stringify(o);
1324 singleNodeToJS : function (treepath)
1326 var iter = new Gtk.TreeIter();
1327 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1331 var iv = this.getIterValue(iter, 2);
1333 return JSON.parse(iv);
1336 toJS : function(treepath, with_id)
1338 //Seed.print("WITHID: "+ with_id);
1339 var iter = treepath; // API used to be iter here..
1340 if (typeof(iter) == 'string') {
1341 iter = new Gtk.TreeIter();
1342 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1351 iter = new Gtk.TreeIter();
1352 if (!this.el.get_iter_first(iter)) {
1362 var k = this.nodeToJS(iter, with_id);
1366 if (!this.el.iter_next(iter)) {
1371 if (treepath === false) {
1373 return JSON.parse(JSON.stringify(ar));
1377 // convert the list into a json string..
1383 xtype: Gtk.TreeViewColumn,
1384 pack : "append_column",
1386 XObject.prototype.init.call(this);
1387 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1391 xtype: Gtk.CellRendererText,
1401 id : "LeftTreeMenu",
1404 xtype: Gtk.MenuItem,
1406 label : "Delete Element",
1408 activate : function (self) {
1410 this.get('/LeftTree.model').deleteSelected();
1415 xtype: Gtk.MenuItem,
1417 activate : function (self) {
1419 var tree = this.get('/LeftTree');
1420 var model = this.get('/LeftTree.model');
1421 var el = tree.getActivePath();
1423 var js = model.toJS(el, false);
1424 // print(JSON.stringify(js[0], null,4));
1425 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1430 label : "Save as Template",
1440 id : "LeftProjectTree",
1441 showNoProjectSelected : function() {
1442 this.get('/StandardErrorDialog').show("Select a Project first.");
1444 getActiveProject : function() {
1445 return this.project;
1448 leave_notify_event : function (self, event) {
1455 pack : "pack_start,false,false",
1458 xtype: Gtk.ComboBox,
1461 XObject.prototype.init.call(this);
1462 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1464 getValue : function() {
1465 var ix = this.el.get_active();
1469 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1470 if (typeof(data[ix]) == 'undefined') {
1475 setValue : function(fn)
1479 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1480 data.forEach(function(n, ix) {
1488 changed : function (self) {
1489 var fn = this.getValue();
1490 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1491 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1496 xtype: Gtk.CellRendererText,
1497 pack : "pack_start,true",
1501 xtype: Gtk.ListStore,
1504 XObject.prototype.init.call(this);
1505 this.el.set_column_types ( 2, [
1506 GObject.TYPE_STRING, // real key
1507 GObject.TYPE_STRING // real type
1511 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1513 pm.on('changed', function() {
1514 print("caught changed hook on project manager - reloading data");
1515 _this.loadData(pm.projects);
1519 loadData : function(data) {
1520 var ov = this.get('/LeftProjectTree.combo').getValue();
1522 var iter = new Gtk.TreeIter();
1524 data.forEach(function(p) {
1529 el.set_value(iter, 0, p.fn);
1530 el.set_value(iter, 1, p.name);
1534 this.get('/LeftProjectTree.combo').setValue(ov);
1543 xtype: Gtk.ScrolledWindow,
1545 shadow_type : Gtk.ShadowType.IN,
1547 XObject.prototype.init.call(this);
1548 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1552 xtype: Gtk.TreeView,
1554 cursor_changed : function (self) {
1555 var iter = new Gtk.TreeIter();
1557 if (this.selection.count_selected_rows() < 1) {
1558 //XN.get('Builder.LeftTree.model').
1559 this.get('/LeftTree.model').load( false);
1563 var model = this.get('/LeftProjectTree.model');
1564 //console.log('changed');
1565 var s = this.selection;
1566 s.get_selected(model, iter);
1567 value = new GObject.Value('');
1568 model.el.get_value(iter, 2, value);
1570 console.log(value.value);// id..
1572 var file = this.get('/LeftProjectTree').project.getById(value.value);
1579 var nb = this.get('/LeftTopPanel.expander');
1580 nb.el.expanded = false;
1582 //nb.listeners.activate.call(nb);
1583 //_expander.el.set_expanded(false);
1585 var ltm = this.get('/LeftTree.model');
1593 enable_tree_lines : true,
1594 headers_visible : false,
1596 XObject.prototype.init.call(this);
1597 var description = new Pango.FontDescription.c_new();
1598 description.set_size(8000);
1599 this.el.modify_font(description);
1601 this.selection = this.el.get_selection();
1602 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1606 xtype: Gtk.TreeStore,
1610 XObject.prototype.init.call(this);
1611 this.el.set_column_types ( 3, [
1612 GObject.TYPE_STRING, // title
1613 GObject.TYPE_STRING, // tip
1614 GObject.TYPE_STRING // id..
1618 loadProject : function(pr) {
1619 print("LOAD PROJECT");
1625 this.get('/LeftProjectTree').project = pr;
1626 this.load(pr.toTree());
1627 this.get('/LeftProjectTree.view').el.expand_all();
1629 load : function(tr,iter) {
1630 // console.dump(tr);
1631 console.log('Project tree load: ' + tr.length);
1632 var citer = new Gtk.TreeIter();
1633 //this.insert(citer,iter,0);
1636 tr.forEach(function (r) {
1638 _this.el.append(citer);
1640 _this.el.insert(citer,iter,-1);
1642 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1643 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1644 _this.el.set_value(citer, 2, '' + r.id ); //id
1645 if (r.cn && r.cn.length) {
1646 _this.load(r.cn, citer);
1651 getValue : function(iter, col) {
1652 var gval = new GObject.Value('');
1653 this.el.get_value(iter, col ,gval);
1654 return '' + gval.value;
1658 xtype: Gtk.TreeViewColumn,
1659 pack : "append_column",
1661 XObject.prototype.init.call(this);
1662 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1666 xtype: Gtk.CellRendererText,
1686 pack : "pack_start,false,true,0",
1693 button_press_event : function (self, event) {
1694 this.get('/MidPropTree.model').showData('props');
1706 stock : Gtk.STOCK_ADD,
1707 icon_size : Gtk.IconSize.MENU
1722 button_press_event : function (self, event) {
1723 this.get('/MidPropTree.model').showData('events');
1735 stock : Gtk.STOCK_ADD,
1736 icon_size : Gtk.IconSize.MENU
1751 button_press_event : function (self, ev) {
1752 var p = this.get('/AddPropertyPopup');
1756 p.el.set_screen(Gdk.Screen.get_default());
1758 p.el.popup(null, null, null, null, 3, ev.button.time);
1770 stock : Gtk.STOCK_ADD,
1771 icon_size : Gtk.IconSize.MENU
1783 id : "AddPropertyPopup",
1786 xtype: Gtk.MenuItem,
1788 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1791 activate : function (self) {
1793 this.get('/LeftPanel.model').add( {
1804 xtype: Gtk.MenuItem,
1806 tooltip_markup : "Add what type of packing is to be used",
1809 activate : function (self) {
1811 this.get('/LeftPanel.model').add( {
1821 xtype: Gtk.MenuItem,
1823 tooltip_markup : "Override the init method",
1826 activate : function (self) {
1828 this.get('/LeftPanel.model').add( {
1831 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1838 xtype: Gtk.SeparatorMenuItem,
1842 xtype: Gtk.MenuItem,
1844 tooltip_markup : "Add a user defined string property",
1847 activate : function (self) {
1849 this.get('/LeftPanel.model').add( {
1859 xtype: Gtk.MenuItem,
1861 tooltip_markup : "Add a user defined number property",
1864 activate : function (self) {
1866 this.get('/LeftPanel.model').add( {
1876 xtype: Gtk.MenuItem,
1878 tooltip_markup : "Add a user defined boolean property",
1881 activate : function (self) {
1883 this.get('/LeftPanel.model').add( {
1893 xtype: Gtk.SeparatorMenuItem,
1897 xtype: Gtk.MenuItem,
1899 tooltip_markup : "Add a user function boolean property",
1902 activate : function (self) {
1904 this.get('/LeftPanel.model').add( {
1907 val : "function() {\n \n}\n",
1920 xtype: Gtk.ScrolledWindow,
1925 XObject.prototype.init.call(this);
1926 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1928 shadow_type : Gtk.ShadowType.IN,
1931 xtype: Gtk.TreeView,
1933 button_press_event : function (self, ev) {
1938 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1939 return false; //not on a element.
1943 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
1945 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
1948 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1949 var p = this.get('/LeftPanelPopup');
1954 p.el.set_screen(Gdk.Screen.get_default());
1956 p.el.popup(null, null, null, null, 3, ev.button.time);
1957 //Seed.print("click:" + res.column.title);
1964 if (res.column.title != 'value') {
1965 // XObject.error("column is not value?");
1966 return false; // ignore.. - key click.. ??? should we do this??
1969 // currently editing???
1970 // if ( this.activePath) {
1972 // this.activePath = false;
1974 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1975 this.get('/LeftPanel').editing = false;
1977 // XObject.error("Currently editing?");
1981 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1983 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1985 // get options for this type -- this is to support option lists etc..
1986 var provider = this.get('/LeftTree').getPaleteProvider();
1987 var opts = provider.findOptions(type);
1989 if (opts === false) {
1991 this.get('/LeftPanel').editableColumn.setOptions([]);
1992 renderer.has_entry = true;
1994 this.get('/LeftPanel').editableColumn.setOptions(opts);
1995 renderer.has_entry = false;
1997 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
1999 //Seed.print("click" + ev.type);
2000 //console.dump(res);
2009 enable_tree_lines : true,
2010 headers_visible : false,
2012 XObject.prototype.init.call(this);
2014 this.selection = this.el.get_selection();
2015 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2018 var description = new Pango.FontDescription.c_new();
2019 description.set_size(8000);
2020 this.el.modify_font(description);
2024 xtype: Gtk.TreeStore,
2028 add : function(info) {
2029 // info includes key, val, skel, etype..
2031 type = info.type.toLowerCase();
2032 var data = this.toJS();
2034 if (info.etype == 'events') {
2035 data.listeners = data.listeners || { };
2036 if (typeof(data.listeners[info.key]) != 'undefined') {
2037 return; //already set!
2040 if (typeof(data[info.key]) != 'undefined') {
2045 if (typeof(info.val) == 'undefined') {
2048 if (info.type.toLowerCase() == 'boolean') {
2051 if (type == 'number') {
2059 if (info.etype == 'events') {
2061 data.listeners[info.key] = info.val;
2064 data[info.key] = info.val;
2068 var map = this.load(data);
2070 // flag it as changed to the interface..
2072 this.get('/LeftTree.model').changed(data, true);
2075 this.startEditing(map[k]);
2078 LeftPanel.get('view').el.row_activated(
2079 new Gtk.TreePath.from_string(map[k]),
2080 LeftPanel.editableColumn.el
2084 changed : function(str, doRefresh) {
2085 if (!this.activePath) {
2088 var iter = new Gtk.TreeIter();
2089 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2091 this.el.set_value(iter, 1, '' +str);
2092 this.el.set_value(iter, 3, '' + this.toShort(str));
2093 var type = this.getIterValue(iter, 4);
2095 this.el.set_value(iter, 5, type + ' : ' + str);
2096 // update the tree...
2098 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2100 deleteSelected : function() {
2101 var data = this.toJS();
2102 var iter = new Gtk.TreeIter();
2103 var s = this.get('/LeftPanel.view').selection;
2104 s.get_selected(this.el, iter);
2107 var gval = new GObject.Value('');
2108 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2110 var val = gval.value;
2111 if (val[0] == '!') {
2113 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2116 delete data.listeners[ val.substring(1)];
2117 if (!XObject.keys(data.listeners).length) {
2118 delete data.listeners;
2122 if (typeof(data[val]) == 'undefined') {
2130 this.get('/LeftTree.model').changed(data, true);
2133 getIterValue : function(iter, col) {
2134 var gval = new GObject.Value('');
2135 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2136 return '' + gval.value;
2138 getType : function(treepath) {
2139 return this.getValue(treepath, 4);
2141 getValue : function(treepath_str, col)
2143 // get's the value in a row.. - keys - returns string, values - formats it..
2145 var iter = new Gtk.TreeIter();
2146 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2148 var gval = new GObject.Value('');
2149 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2150 var val = '' + gval.value;
2155 var type = this.getType(this.el.get_path(iter).to_string());
2156 //print("TYPE: " +type + " - val:" + val);
2157 switch(type.toLowerCase()) {
2161 return parseFloat(val); // Nan ?? invalid!!?
2164 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2166 return val == 'true' ? true : false;
2168 var nv = parseFloat(val);
2169 if (!isNaN(nv) && (val == ''+nv)) {
2177 XObject.prototype.init.call(this);
2178 this.el.set_column_types ( 6, [
2179 GObject.TYPE_STRING, // 0 real key
2180 GObject.TYPE_STRING, // 1 real value
2181 GObject.TYPE_STRING, // 2 visable key
2182 GObject.TYPE_STRING, // 3 visable value
2183 GObject.TYPE_STRING, // 4 need to store type of!!!
2184 GObject.TYPE_STRING // 5 tooltip
2188 load : function(ar) {
2191 this.get('/RightEditor').el.hide();
2198 var provider = this.get('/LeftTree').getPaleteProvider();
2199 var iter = new Gtk.TreeIter();
2202 var keys = XObject.keys(ar);
2204 ar.listeners = ar.listeners || {};
2206 for (var i in ar.listeners ) {
2207 this.el.append(iter);
2208 var p = this.el.get_path(iter).to_string();
2211 this.el.set_value(iter, 0, '!'+ i );
2212 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2213 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2215 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2216 this.el.set_value(iter, 4, 'function');
2217 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2223 keys.forEach(function(i) {
2224 if (typeof(ar[i]) == 'object') {
2228 var type = provider.findType(ar, i, ar[i]);
2230 _this.el.append(iter);
2231 var p = _this.el.get_path(iter).to_string();
2233 _this.el.set_value(iter, 0, ''+i);
2234 _this.el.set_value(iter, 1, '' + ar[i]);
2235 _this.el.set_value(iter, 2, ''+i);
2236 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2237 _this.el.set_value(iter, 4, ''+type);
2238 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2242 startEditing : function(path,col) {
2243 // alled by menu 'edit' currently..
2245 * start editing path (or selected if not set..)
2246 * @param {String|false} path (optional) treepath to edit - selected tree gets
2247 * edited by default.
2248 * @param {Number} 0 or 1 (optional)- column to edit.
2250 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2252 if (typeof(path) == 'string') {
2253 tp = new Gtk.TreePath.from_string(path);
2255 var iter = new Gtk.TreeIter();
2256 var s = this.get('/LeftPanel.view').selection;
2257 s.get_selected(this.el, iter);
2258 tp = this.el.get_path(iter);
2259 path = tp.to_string();
2263 // which colum is to be edited..
2266 // not sure what this does..
2268 if (typeof(col) == 'undefined') {
2269 var k = this.getValue(path, 0);
2271 colObj = (!k.length || k == '|') ?
2272 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2274 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2277 // make sure the pulldown is set correctly..
2278 // not really needed for second col...
2279 var showEditor = false;
2282 var provider = this.get('/LeftTree').getPaleteProvider();
2283 var type = this.get('/LeftPanel.model').getType(path);
2284 var opts = provider.findOptions(type);
2285 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2287 if (opts === false) {
2288 this.get('/LeftPanel').editableColumn.setOptions([]);
2289 renderer.has_entry = true;
2291 this.get('/LeftPanel').editableColumn.setOptions(opts);
2292 renderer.has_entry = false;/// - pulldowns do not have entries
2294 // determine if we should use the Text editor...
2295 var keyname = this.getValue(path, 0);
2296 var data_value = this.getValue(path, 1);
2298 if ((keyname[0] == '|') ||
2300 (typeof(data_value) == 'string' ) &&
2301 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2305 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2310 this.get('/BottomPane').el.hide();
2311 this.get('/RightEditor').el.hide();
2316 this.activePath = false;
2317 GLib.timeout_add(0, 1, function() {
2319 _this.get('/BottomPane').el.show();
2320 _this.get('/RightEditor').el.show();
2321 _this.get('/RightEditor.view').load( _this.getValue(path, 1) );
2324 //e.remove_widget();
2325 _this.activePath = path ;
2335 // iter now has row...
2336 GLib.timeout_add(0, 100, function() {
2337 _this.activePath = path;
2338 colObj.items[0].el.editable = true; // esp. need for col 0..
2339 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2349 var iter = new Gtk.TreeIter();
2350 this.get('/LeftPanel.model').el.get_iter_first(iter);
2355 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2358 ar.listeners = ar.listeners || {};
2359 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2362 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2365 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2371 //print(JSON.stringify(ar));
2375 toShort : function(str) {
2376 var a = typeof(str) == 'string' ? str.split("\n") : [];
2377 return a.length > 1 ? a[0] + '....' : '' + str;
2381 xtype: Gtk.TreeViewColumn,
2382 pack : "append_column",
2384 XObject.prototype.init.call(this);
2386 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2387 this.get('/LeftPanel').propertyColumn = this;
2392 xtype: Gtk.CellRendererText,
2393 pack : "pack_start",
2395 editing_started : function (self, editable, path) {
2397 this.get('/LeftPanel.model').activePath = path;
2400 edited : function (self, object, p0) {
2401 var model = this.get('/LeftPanel.model');
2402 var path = model.activePath;
2403 var iter = new Gtk.TreeIter();
2404 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2405 model.el.set_value(iter, 0, p0);
2406 model.el.set_value(iter, 2, p0);
2408 model.activePath = false;
2410 this.get('/LeftTree.model').changed(model.toJS(), true);
2411 this.el.editable = false;
2418 xtype: Gtk.TreeViewColumn,
2419 pack : "append_column",
2422 XObject.prototype.init.call(this);
2423 this.el.add_attribute(this.items[0].el , 'text', 3 );
2424 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2425 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2426 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2428 this.get('/LeftPanel').editableColumn= this;
2430 setOptions : function(ar) {
2431 var m = this.items[0].el.model;
2433 var iter = new Gtk.TreeIter();
2434 ar.forEach(function(i) {
2437 m.set_value(iter, 0, i);
2443 xtype: Gtk.CellRendererCombo,
2445 edited : function (self, object, p0) {
2446 this.get('/LeftPanel').editing = false;
2447 var ap = this.get('/LeftPanel.model').activePath
2448 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2449 this.get('/LeftPanel.model').changed(p0, true);
2450 this.get('/LeftPanel.model').activePath = false;
2451 this.el.editable = false;
2453 editing_started : function (self, editable, path) {
2454 this.get('/LeftPanel').editing = true;
2455 // console.log('editing started');
2456 // r.has_entry = false;
2458 this.el.editable = false; // make sure it's not editor...
2462 pack : "pack_start",
2467 XObject.prototype.init.call(this);
2468 this.el.model = new Gtk.ListStore();
2469 this.el.model.set_column_types ( 1, [
2470 GObject.TYPE_STRING // 0 real key
2481 id : "LeftPanelPopup",
2484 xtype: Gtk.MenuItem,
2488 activate : function (self) {
2489 this.get('/LeftPanel.model').deleteSelected();
2494 xtype: Gtk.MenuItem,
2498 activate : function (self) {
2499 this.get('/LeftPanel.model').startEditing(false, 0);
2512 xtype: Gtk.ScrolledWindow,
2513 pack : "pack_end,false,true,0",
2515 shadow_type : Gtk.ShadowType.IN,
2517 XObject.prototype.init.call(this);
2518 XObject.prototype.init.call(this);
2519 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2520 this.el.set_size_request ( 150, -1 );
2523 activeElement : false,
2524 hideWin : function() {
2531 if (this.get('/Window.left').el.position < 160) {
2534 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2541 xtype: Gtk.TreeView,
2543 cursor_changed : function (self) {
2544 var iter = new Gtk.TreeIter();
2546 //console.log('changed');
2547 var m = this.get('model');
2548 if (!this.selection){
2549 this.selection = this.el.get_selection();
2552 var s = this.selection;
2553 if (!s.get_selected(m.el, iter)) {
2556 var tp = m.el.get_path(iter).to_string();
2561 var key = m.getValue(tp, 0);
2563 var type = m.getValue(tp, 1);
2564 var skel = m.getValue(tp, 3);
2565 var etype = m.getValue(tp, 5);
2568 this.get('/MidPropTree').hideWin();
2570 if (type.toLowerCase() == 'function') {
2572 if (etype != 'events') {
2576 this.get('/LeftPanel.model').add({
2584 // has dot in name, and is boolean???? this does not make sense..
2585 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2589 this.get('/LeftPanel.model').add( {
2599 enable_tree_lines : true,
2600 headers_visible : false,
2602 XObject.prototype.init.call(this);
2604 var description = new Pango.FontDescription.c_new();
2605 description.set_size(8000);
2606 this.el.modify_font(description);
2608 //this.selection = this.el.get_selection();
2609 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2618 xtype: Gtk.ListStore,
2621 getValue : function(treepath, col)
2623 var tp = new Gtk.TreePath.from_string (treepath);
2624 var iter = new Gtk.TreeIter();
2625 this.el.get_iter (iter, tp);
2626 var value = new GObject.Value('');
2627 this.el.get_value(iter, col, value);
2632 XObject.prototype.init.call(this);
2633 this.el.set_column_types ( 6, [
2634 GObject.TYPE_STRING, // real key
2635 GObject.TYPE_STRING, // real type
2636 GObject.TYPE_STRING, // docs ?
2637 GObject.TYPE_STRING, // visable desc
2638 GObject.TYPE_STRING, // function desc
2639 GObject.TYPE_STRING // element type (event|prop)
2643 showData : function(type) {
2645 if (!this.get('/MidPropTree').activeElement || !type) {
2646 return; // no active element
2649 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2650 var palete = this.get('/LeftTree').getPaleteProvider();
2654 Seed.print('Showing right?');
2655 if (!this.get('/MidPropTree').shown) {
2657 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2658 this.get('/MidPropTree').el.show();
2659 this.get('/MidPropTree').shown = true;
2662 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2663 return a.name > b.name ? 1 : -1;
2665 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2666 // console.dump(elementList);
2669 var iter = new Gtk.TreeIter();
2670 for(var i =0 ; i < elementList.length; i++) {
2671 var p=elementList[i];
2672 this.el.append(iter);
2673 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2674 //GObject.TYPE_STRING, // real key
2675 // GObject.TYPE_STRING, // real type
2676 // GObject.TYPE_STRING, // docs ?
2677 // GObject.TYPE_STRING // func def?
2680 this.el.set_value(iter, 0, p.name);
2681 this.el.set_value(iter, 1, p.type);
2682 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2683 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2684 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2685 this.el.set_value(iter, 5, type);
2692 xtype: Gtk.TreeViewColumn,
2694 this.el = new Gtk.TreeViewColumn();
2695 this.parent.el.append_column(this.el);
2697 XObject.prototype.init.call(this);
2698 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2703 xtype: Gtk.CellRendererText,
2704 pack : "pack_start,true"
2728 xtype: Gtk.Notebook,
2729 pack : "pack_start,true,true",
2730 id : "view-help-nb",
2732 XObject.prototype.init.call(this);
2733 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2734 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2738 xtype: Gtk.Notebook,
2739 id : "view-notebook",
2743 XObject.prototype.init.call(this);
2744 this.el.set_current_page(0);
2745 //print("SET LABEL?")
2746 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2747 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2753 id : "RightBrowser",
2758 pack : "pack_start,false,true,0",
2763 clicked : function (self) {
2764 this.get('/RightBrowser.view').renderJS(null,true);
2768 pack : "pack_start,false,false,0"
2771 xtype: Gtk.CheckButton,
2773 toggled : function (self, state) {
2774 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2779 label : "Auto Redraw On",
2780 pack : "pack_start,false,false,0"
2785 xtype: Gtk.ScrolledWindow,
2788 XObject.prototype.init.call(this);
2789 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2791 shadow_type : Gtk.ShadowType.IN,
2794 xtype: WebKit.WebView,
2796 load_finished : function (self, object) {
2797 print("load finished");
2798 // print("load_finished"); return;
2799 // if (this.ready) { // dont do it twice!
2802 if (!this.inspectorShown) {
2803 this.el.get_inspector().show();
2804 this.inspectorShown = true;
2809 if (this.pendingRedraw) {
2810 this.pendingRedraw = false;
2811 this.refreshRequired = true;
2813 //var js = this.get('/LeftTree.model').toJS();
2814 //if (js && js[0]) {
2815 // this.renderJS(js[0]);
2819 script_alert : function (self, object, p0) {
2822 return true; // do not display anything...
2824 console_message : function (self, object, p0, p1) {
2826 // console.log(object);
2827 if (!object.match(/^\{/)) {
2829 //this.get('/Terminal').feed(object);
2830 return true; // do not handle!!! -> later maybe in console..
2832 // console.log(object);
2833 var val = JSON.parse(object);
2835 if (typeof(val['hover-node']) != 'undefined') {
2836 this.activeNode = val['hover-node'];
2837 console.log('active node: ' + this.activeNode);
2842 if (typeof(val['id']) != 'undefined') {
2843 // this.activeNode = val['id'];
2844 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2845 if (!tg || typeof(tg[0]) == 'undefined') {
2848 print("SELECT node " + tg[0]);
2850 this.get('/LeftTree.view').selectNode(tg[0]);
2854 if (ret && typeof(val['set']) != 'undefined') {
2855 this.get('/LeftPanel.model').add({
2859 //console.log('active node: ' + this.activeNode);
2862 //Seed.print('a:'+a);
2863 //Seed.print('b:'+b);
2864 //Seed.print('c:'+c);
2867 drag_motion : function (w, ctx, x, y, time, ud) {
2868 // console.log('DRAG MOTION');
2870 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2871 this.targetData = [];
2872 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2874 // A) find out from drag all the places that node could be dropped.
2875 var src = Gtk.drag_get_source_widget(ctx);
2876 if (!src.dropList) {
2877 Gdk.drag_status(ctx, 0, time);
2880 // b) get what we are over.. (from activeNode)
2881 // tree is empty.. - list should be correct..
2882 if (!this.get('/LeftTree.model').currentTree) {
2883 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2887 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2889 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2892 Gdk.drag_status(ctx, 0,time);
2893 this.get('/LeftTree.view').highlight(false);
2897 // if we have a target..
2898 // -> highlight it! (in browser)
2899 // -> highlight it! (in tree)
2901 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2902 this.get('/LeftTree.view').highlight(tg);
2903 this.targetData = tg;
2904 // for tree we should handle this...
2907 drag_drop : function (w, ctx, x, y,time, ud) {
2908 print("TARGET: drag-drop");
2909 var is_valid_drop_site = true;
2914 w, /* will receive 'drag-data-received' signal */
2915 ctx, /* represents the current state of the DnD */
2916 this.get('/Window').atoms["STRING"], /* the target type we want */
2917 time /* time stamp */
2921 /* No target offered by source => error */
2924 return is_valid_drop_site;
2926 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2928 print("Browser: drag-data-received");
2929 var delete_selection_data = false;
2930 vardnd_success = false;
2931 /* Deal with what we are given from source */
2932 if( sel_data && sel_data.length ) {
2934 if (ctx.action == Gdk.DragAction.ASK) {
2935 /* Ask the user to move or copy, then set the ctx action. */
2938 if (ctx.action == Gdk.DragAction.MOVE) {
2939 delete_selection_data = true;
2941 var source = Gtk.drag_get_source_widget(ctx);
2943 print("Browser: source.DRAGDATA? " + source.dragData);
2944 if (this.targetData) {
2945 print(this.targetData);
2946 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2955 if (dnd_success == false)
2957 Seed.print ("DnD data transfer failed!\n");
2960 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2963 create_web_view : function (self, object) {
2964 print("CREATE WEB VIEW");
2965 return null; //new WebKit.WebView();
2972 XObject.prototype.init.call(this);
2973 // this may not work!?
2974 var settings = this.el.get_settings();
2975 settings.enable_developer_extras = true;
2977 // this was an attempt to change the url perms.. did not work..
2978 // settings.enable_file_access_from_file_uris = true;
2979 // settings.enable_offline_web_application_cache - true;
2980 // settings.enable_universal_access_from_file_uris = true;
2984 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
2985 _this.get('/BottomPane.inspector').el.show();
2986 return _this.get('/BottomPane.inspector').el;
2990 // FIXME - base url of script..
2991 // we need it so some of the database features work.
2992 this.el.load_html_string( "Render not ready" ,
2993 //fixme - should be a config option!
2994 // or should we catch stuff and fix it up..
2995 'http://localhost/app.Builder/'
2999 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3003 this.el, /* widget that will accept a drop */
3004 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3005 null, /* lists of target to support */
3006 0, /* size of list */
3007 Gdk.DragAction.COPY /* what to do with data after dropped */
3010 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3011 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3013 GLib.timeout_add_seconds(0, 1, function() {
3014 // print("run refresh?");
3021 renderJS : function(data, force) {
3023 // this is the public redraw call..
3024 // we refresh in a loop privately..
3025 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3026 if (!autodraw && !force) {
3027 print("Skipping redraw - no force, and autodraw off");
3030 this.refreshRequired = true;
3032 runRefresh : function()
3034 // this is run every 2 seconds from the init..
3038 if (!this.refreshRequired) {
3039 // print("no refresh required");
3043 if (this.lastRedraw) {
3044 // do not redraw if last redraw was less that 5 seconds ago.
3045 if (((new Date()) - this.lastRedraw) < 5000) {
3053 if (!this.get('/Window.LeftTree').getActiveFile()) {
3056 this.refreshRequired = false;
3057 // print("HTML RENDERING");
3059 this.get('/BottomPane').el.show();
3060 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3063 var js = this.get('/LeftTree.model').toJS();
3064 if (!js || !js.length) {
3071 var project = this.get('/Window.LeftTree').getActiveFile().project;
3072 //print (project.fn);
3073 // set it to non-empty.
3074 project.runhtml = project.runhtml || '';
3075 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3078 this.runhtml = this.runhtml || '';
3080 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3081 // then we need to reload the browser using
3082 // load_html_string..
3084 // then trigger a redraw once it's loaded..
3085 this.pendingRedraw = true;
3086 var runhtml = '<script type="text/javascript">' + "\n" ;
3087 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3088 runhtml += '</script>'+ "\n" ;
3090 this.runhtml = project.runhtml;
3091 // need to modify paths
3095 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3096 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3097 print("LOAD HTML " + html);
3098 this.el.load_html_string( html ,
3099 //fixme - should be a config option!
3100 'http://localhost/app.Builder/'
3103 // should trigger load_finished! - which in truns shoudl set refresh Required;
3109 this.renderedData = data;
3110 var str = JSON.stringify(data) ;
3113 console.log('not loaded yet');
3115 this.lastRedraw = new Date();
3117 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3118 print( "before render" + this.lastRedraw);
3119 print( "after render" + (new Date()));
3129 id : "RightGtkView",
3131 redraw : function() {
3132 this.highlightWidget = false;
3133 print("REDRAW CALLED");
3134 this.activePath = this.get('/LeftTree').getActivePath();
3135 if (this.renderedEl) {
3136 print("QUEUE DRAW CALLING");
3137 this.renderedEl.queue_draw();
3140 renderJS : function(data, withDebug)
3142 this.highlightWidget = false;
3144 this.withDebug = false;
3145 while (this.get('view').el.get_children().length) {
3146 var c = this.get('view').el.get_children()[0];
3147 this.get('view').el.remove(c);
3154 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3155 // in theory tree is actually window..
3158 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3164 this.get('view').el.set_size_request(
3165 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3167 if (this.renderedEl) {
3168 this.renderedEl.set_size_request(
3169 tree.default_width || 600,
3170 tree.default_height || 400
3173 this.get('view').el.show_all();
3178 showInWindow : function() {
3179 print("GET PROEJCT");
3180 var pr = this.get('/LeftProjectTree').getActiveProject();
3182 console.log(pr.paths);
3185 var src= this.buildJS(
3186 this.get('/LeftTree.model').toJS()[0],
3191 //var x = new imports.sandbox.Context();
3195 Seed.check_syntax('var e = ' + src);
3198 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3199 this.get('/Terminal').feed(console._dump(e)+"\n");
3201 var lines = src.split("\n");
3202 var start = Math.max(0, e.line - 10);
3203 var end = Math.min(lines.length, e.line + 10);
3204 for (var i =start ; i < end; i++) {
3206 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3209 this.get('/Terminal').feed(lines[i] + "\n");
3216 this.get('/BottomPane').el.set_current_page(1);
3217 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3218 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3219 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3221 var _top = x.get_global_object()._top;
3223 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3225 if (_top.el.popup) {
3226 _top.el.popup(null, null, null, null, 3, null);
3230 viewAdd : function(item, par)
3232 // does something similar to xobject..
3233 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3235 if (item.pack===false || item.pack === 'false') { // no ;
3238 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3239 var type = item['|xns'] + '.' + item['xtype'];
3241 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3244 var ns = imports.gi[item['|xns']];
3245 var ctr = ns[item['xtype']];
3247 for(var k in item) {
3249 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3264 if (k[0] == '|' && typeof(kv) == 'string') {
3266 if (kv.match(new RegExp('function'))) {
3269 print("WASL " + k + '=' + kv);
3271 eval( 'kv = ' + kv);
3272 } catch(e) { continue; }
3275 // print(k + '=' + kv);
3277 if (k[0] == '|') { // should be boolean or number..
3279 //print(k + '=' + kv);
3282 if (k == 'show_tabs') { // force tab showing for notebooks.
3285 print(k + '=' + typeof(kv) + " : " + kv);
3291 var el = new ctr(ctr_args);
3293 print("PACK" + item.pack);
3294 //console.dump(item.pack);
3301 if (typeof(item.pack) == 'string') {
3303 item.pack.split(',').forEach(function(e, i) {
3305 if (e == 'false') { args.push( false); return; }
3306 if (e == 'true') { args.push( true); return; }
3307 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3310 //print(args.join(","));
3312 pack_m = args.shift();
3314 pack_m = item.pack.shift();
3319 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3321 name: "ArgumentError",
3322 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3323 "ADDING : " + item.id + " " + el
3332 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3333 //Seed.print('args: ' + args.length);
3335 par[pack_m].apply(par, args);
3339 item.items = item.items || [];
3340 item.items.forEach(function(ch,n) {
3342 print ("type:" + type);
3344 print ("ch.pack:" + ch.pack);
3345 if (type == 'Gtk.Table' && ch.pack == 'add') {
3346 var c = n % item.n_columns;
3347 var r = Math.floor(n/item.n_columns);
3348 ch.pack = [ 'attach', c, c+1, r, r+1,
3349 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3350 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3351 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3352 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3356 _this.viewAdd(ch, el);
3361 // add the signal handlers.
3362 // is it a widget!?!!?
3368 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3369 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3370 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3371 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3372 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3382 widgetDragDropEvent : function() {
3383 print("WIDGET DRAGDROP");
3386 widgetDragMotionEvent : function() {
3387 print("WIDGET DRAGMOTION");
3390 widgetExposeEvent : function(w, evt, ud, item) {
3392 if (this.inRender) {
3396 if ( this.highlightWidget) {
3397 this.inRender = true;
3398 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3399 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3401 this.inRender = false;
3406 if (this.activePath != item.xtreepath) {
3410 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3411 // work out the coords of the window..
3413 var dr = widget.window;
3414 this.gc = (new Gdk.GC.c_new(dr));
3415 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3416 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3420 var r = evt.expose.area;
3421 // console.dump([r.x, r.y, r.width, r.height ] );
3423 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3424 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3425 // happens with gtkscrollview embedded stuff..
3426 var np =this.activePath.split(':');
3428 this.activePath = np.join(':');
3429 this.renderedEl.queue_draw();
3445 this.inRender = true;
3448 this.highlightWidget = widget;
3453 // print("DRAW BOX");
3454 //console.dump(this.box);
3455 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3456 this.inRender = false;
3459 widgetPressEvent : function(w,e,u,d) {
3460 if (this.get('view').pressed) {
3463 this.get('view').pressed = true;
3464 print("WIDGET PRESS " + d.xtreepath );
3465 this.get('/LeftTree.view').selectNode( d.xtreepath );
3468 widgetReleaseEvent : function() {
3469 this.get('view').pressed = false;
3475 pack : "pack_start,false,true,0",
3479 pack : "pack_start,false,false,0",
3480 label : "Run The Application",
3482 button_press_event : function (self, event) {
3483 // call render on left tree - with special option!?!
3485 //print("GET PROEJCT");
3486 var pr = this.get('/LeftProjectTree').getActiveProject();
3489 for (var i in pr.paths) {
3493 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3494 this.get('/Terminal').feed("RUN DIR:" + dir);
3496 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3497 , false,false,false);
3498 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3499 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3509 xtype: Gtk.ScrolledWindow,
3512 shadow_type : Gtk.ShadowType.IN,
3514 XObject.prototype.init.call(this);
3515 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3519 xtype: Gtk.EventBox,
3520 pack : "add_with_viewport",
3522 XObject.prototype.init.call(this);
3523 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3524 red: 0x9F00, green: 0xB800 , blue : 0xA800
3532 XObject.prototype.init.call(this);
3533 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3534 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3539 xtype: Gtk.EventBox,
3542 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3543 XObject.prototype.init.call(this);
3547 this.el, /* widget that will accept a drop */
3548 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3549 null, /* lists of target to support */
3550 0, /* size of list */
3551 Gdk.DragAction.COPY /* what to do with data after dropped */
3554 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3555 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3558 getActiveNode : function(x,y)
3560 // workout what node is here..
3561 return '0'; // top..
3565 drag_motion : function (self, ctx, x, y, time) {
3567 // A) find out from drag all the places that node could be dropped.
3568 var src = Gtk.drag_get_source_widget(ctx);
3569 if (!src.dropList) {
3570 Gdk.drag_status(ctx, 0, time);
3573 // b) get what we are over.. (from activeNode)
3574 // tree is empty.. - list should be correct..
3575 if (!this.get('/LeftTree.model').currentTree) {
3576 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3580 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3581 var activeNode = this.getActiveNode(x, y);
3584 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3587 Gdk.drag_status(ctx, 0,time);
3588 this.get('/LeftTree.view').highlight(false);
3592 // if we have a target..
3593 // -> highlight it! (in browser)
3594 // -> highlight it! (in tree)
3596 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3597 this.get('/LeftTree.view').highlight(tg);
3598 this.targetData = tg;
3599 // for tree we should handle this...
3602 drag_drop : function (self,ctx, x, y, time) {
3603 Seed.print("TARGET: drag-drop");
3604 var is_valid_drop_site = true;
3609 self, /* will receive 'drag-data-received' signal */
3610 ctx, /* represents the current state of the this.gDnD */
3611 this.get('/Window').atoms["STRING"], /* the target type we want */
3612 time /* time stamp */
3616 /* No target offered by source => error */
3619 return is_valid_drop_site;
3622 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3624 Seed.print("GtkView: drag-data-received");
3625 var delete_selection_data = false;
3626 var dnd_success = false;
3627 /* Deal with what we are given from source */
3628 if( sel_data && sel_data.length ) {
3630 if (ctx.action == Gdk.DragAction.ASK) {
3631 /* Ask the user to move or copy, then set the ctx action. */
3634 if (ctx.action == Gdk.DragAction.MOVE) {
3635 delete_selection_data = true;
3637 var source = Gtk.drag_get_source_widget(ctx);
3639 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3640 if (this.targetData) {
3641 Seed.print(this.targetData);
3642 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3651 if (dnd_success == false)
3653 Seed.print ("DnD data transfer failed!\n");
3656 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3659 button_press_event : function (self, event) {
3660 this.pressed = false;
3676 xtype: Gtk.ScrolledWindow,
3681 var file = this.get('/LeftTree').getActiveFile();
3685 var activeEl = this.get('/LeftTree').getActiveElement();
3686 var xtype = file.guessName( activeEl )
3687 if (!xtype || !xtype.length) {
3690 //this.get('/Window.view-help-nb').el.set_current_page(1);
3692 // get the active element being edited.
3693 var helpurl = file.getHelpUrl(xtype);
3695 // now load the help info in the page..
3696 this.get('help-view').el.open(helpurl);
3700 xtype: WebKit.WebView,
3704 XObject.prototype.init.call(this);
3705 this.get('/Window.help-view').el.open(
3706 "http://devel.akbkhome.com/seed/");
3718 xtype: Gtk.Notebook,
3722 XObject.prototype.init.call(this);
3723 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3724 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3725 this.el.set_tab_label(this.items[2].el, new Gtk.Label({ label : "Inspector" }));
3729 xtype: Gtk.ScrolledWindow,
3734 xtype: GtkSource.View,
3738 XObject.prototype.init.call(this);
3739 var description = Pango.Font.description_from_string("monospace")
3740 description.set_size(8000);
3741 this.el.modify_font(description);
3744 load : function(str) {
3746 // show the help page for the active node..
3747 this.get('/Help').show();
3750 this.get('/BottomPane').el.set_current_page(0);
3751 this.el.get_buffer().set_text(str, str.length);
3752 var lm = GtkSource.LanguageManager.get_default();
3754 this.el.get_buffer().set_language(lm.get_language('js'));
3755 var buf = this.el.get_buffer();
3756 var cursor = buf.get_mark("insert");
3757 var iter= new Gtk.TextIter;
3758 buf.get_iter_at_mark(iter, cursor);
3760 iter.set_line_offset(4);
3761 buf.move_mark(cursor, iter);
3764 cursor = buf.get_mark("selection_bound");
3765 iter= new Gtk.TextIter;
3766 buf.get_iter_at_mark(iter, cursor);
3768 iter.set_line_offset(4);
3769 buf.move_mark(cursor, iter);
3771 this.el.grab_focus();
3773 insert_spaces_instead_of_tabs : true,
3776 show_line_numbers : true,
3779 xtype: GtkSource.Buffer,
3781 changed : function (self) {
3782 var s = new Gtk.TextIter();
3783 var e = new Gtk.TextIter();
3784 this.el.get_start_iter(s);
3785 this.el.get_end_iter(e);
3786 var str = this.el.get_text(s,e,true);
3788 Seed.check_syntax('var e = ' + str);
3790 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3791 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3793 //print("SYNTAX ERROR IN EDITOR");
3798 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3799 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3802 this.get('/LeftPanel.model').changed( str , false);
3812 xtype: Gtk.ScrolledWindow,
3816 xtype: Vte.Terminal,
3819 feed : function(istr) {
3820 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3821 // we should make ourselves visable!!!
3822 this.get('/BottomPane').el.show();
3823 this.get('/BottomPane').el.set_current_page(1);
3825 this.el.feed(str ,str.length);
3827 scroll_on_output : true,
3829 XObject.prototype.init.call(this);
3830 this.el.set_size (80, 1000);
3832 scrollback_lines : 1000
3837 xtype: Gtk.ScrolledWindow,
3841 xtype: WebKit.WebView,
3853 pack : "pack_start,false,false",
3857 this.get('buttonbar').el.show();
3858 this.get('viewbox').el.hide();
3859 print("TRIED TO HIDE");
3862 this.get('buttonbar').el.hide();
3863 this.get('viewbox').el.show();
3864 // this.get('model').expanded();
3876 pack : "pack_start,false,true",
3878 clicked : function (self) {
3879 this.get('/RightPalete').show();
3886 stock : Gtk.STOCK_GOTO_FIRST,
3887 icon_size : Gtk.IconSize.MENU
3897 XObject.prototype.init.call(this);
3898 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3901 enter_notify_event : function (self, event) {
3902 this.get('/RightPalete').show();
3916 pack : "pack_start,false,true",
3925 pack : "pack_start,false,true",
3927 clicked : function (self) {
3928 this.get('/RightPalete').hide();
3935 stock : Gtk.STOCK_GOTO_LAST,
3936 icon_size : Gtk.IconSize.MENU
3943 xtype: Gtk.ScrolledWindow,
3946 XObject.prototype.init.call(this);
3947 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3948 this.el.set_size_request(-1,200);
3950 shadow_type : Gtk.ShadowType.IN,
3953 xtype: Gtk.TreeView,
3956 XObject.prototype.init.call(this);
3957 this.el.set_size_request(150,-1);
3958 // set_reorderable: [1]
3960 var description = new Pango.FontDescription.c_new();
3961 description.set_size(8000);
3962 this.el.modify_font(description);
3964 this.selection = this.el.get_selection();
3965 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3966 // this.selection.signal['changed'].connect(function() {
3967 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3969 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3971 Gtk.drag_source_set (
3972 this.el, /* widget will be drag-able */
3973 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3974 null, /* lists of target to support */
3975 0, /* size of list */
3976 Gdk.DragAction.COPY /* what to do with data after dropped */
3978 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3980 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3981 Gtk.drag_source_add_text_targets(this.el);
3983 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3984 targets = new Gtk.TargetList();
3985 targets.add( LeftTree.atoms["STRING"], 0, 0);
3986 targets.add_text_targets( 1 );
3987 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3989 //if you want to allow text to be output elsewhere..
3990 //Gtk.drag_source_add_text_targets(this.el);
3994 headers_visible : false,
3995 enable_tree_lines : true,
3997 drag_begin : function (self, ctx) {
3998 // we could fill this in now...
3999 Seed.print('SOURCE: drag-begin');
4003 var iter = new Gtk.TreeIter();
4004 var s = this.selection;
4005 s.get_selected(this.get('/RightPalete.model').el, iter);
4006 var path = this.get('/RightPalete.model').el.get_path(iter);
4008 var pix = this.el.create_row_drag_icon ( path);
4011 Gtk.drag_set_icon_pixmap (ctx,
4018 var value = new GObject.Value('');
4019 this.get('/RightPalete.model').el.get_value(iter, 0, value);
4020 if (!this.get('/RightPalete').provider) {
4023 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
4024 this.el.dragData = value.value;
4031 drag_data_get : function (self, drag_context, selection_data, info, time) {
4032 //Seed.print('Palete: drag-data-get: ' + target_type);
4033 if (this.el.dragData && this.el.dragData.length ) {
4034 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4038 //this.el.dragData = "TEST from source widget";
4042 drag_end : function (self, drag_context) {
4043 Seed.print('SOURCE: drag-end');
4044 this.el.dragData = false;
4045 this.el.dropList = false;
4046 this.get('/LeftTree.view').highlight(false);
4052 xtype: Gtk.ListStore,
4055 XObject.prototype.init.call(this);
4056 this.el.set_column_types ( 2, [
4057 GObject.TYPE_STRING, // title
4058 GObject.TYPE_STRING // tip
4063 load : function(tr,iter)
4068 //console.log('Project tree load: ' + tr.length);
4069 var citer = new Gtk.TreeIter();
4070 //this.insert(citer,iter,0);
4071 for(var i =0 ; i < tr.length; i++) {
4074 this.el.append(citer);
4076 this.el.insert(citer,iter,-1);
4081 this.el.set_value(citer, 0, '' + r ); // title
4083 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4084 //if (r.cn && r.cn.length) {
4085 // this.load(r.cn, citer);
4091 getValue : function (iter, col) {
4092 var gval = new GObject.Value('');
4093 this.el.get_value(iter, col ,gval);
4100 xtype: Gtk.TreeViewColumn,
4101 pack : "append_column",
4103 XObject.prototype.init.call(this);
4104 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4108 xtype: Gtk.CellRendererText,
4130 XObject.cache['/Window'] = Window;