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('/Editor').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 this.get('/Editor').el.hide();
1166 //print("set current tree");
1167 this.currentTree = this.toJS(false, false)[0];
1168 //console.dump(this.currentTree);
1169 this.currentTree = this.currentTree || { items: [] };
1170 this.get('/LeftTree').renderView();
1171 //console.dump(this.map);
1172 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1173 var pm = this.get('/RightPalete.model');
1174 // set up provider..
1176 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1178 if (!this.get('/RightPalete').provider) {
1179 print ("********* PALETE PROVIDER MISSING?!!");
1181 this.get('/LeftTree').renderView();
1183 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1187 this.get('/Window.view-notebook').el.set_current_page(
1188 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1191 moveNode : function(target_data, action) {
1192 //print("MOVE NODE");
1193 // console.dump(target_data);
1194 var old_iter = new Gtk.TreeIter();
1195 var s = this.get('/LeftTree.view').selection;
1196 s.get_selected(this.el, old_iter);
1197 var node = this.nodeToJS(old_iter,false);
1198 //console.dump(node);
1201 // needs to drop first, otherwise the target_data
1202 // treepath will be invalid.
1204 this.dropNode(target_data, node);
1205 if (action & Gdk.DragAction.MOVE) {
1206 // print("REMOVING OLD NODE");
1207 this.el.remove(old_iter);
1211 this.activePath= false;
1212 this.changed(false,true);
1214 nodeTip : function(c) {
1215 var ret = this.nodeTitle(c,true);
1221 if (!i.length || i[0] != '|') {
1227 if (typeof(c[i]) != 'string') {
1230 //print("prop : " + i + ':' + c[i]);
1231 if (!c[i].match(new RegExp('function'))) {
1234 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1238 ret+="\n\nMethods:" + funcs;
1243 nodeTitle : function(c, renderfull) {
1246 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1247 if (sr) txt.push('<s>');
1248 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1250 if (renderfull && c['|xns']) {
1251 txt.push(c['|xns']);
1254 if (c.xtype) { txt.push(c.xtype); }
1255 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1256 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1257 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1260 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1261 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1262 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1263 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1264 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1265 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1266 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1267 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1268 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1270 // for flat classes...
1271 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1272 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1275 if (sr) txt.push('</s>');
1276 return (txt.length == 0 ? "Element" : txt.join(" "));
1278 nodeToJS : function (treepath, with_id)
1281 var iter = treepath; // API used to be iter here..
1282 if (typeof(iter) == 'string') {
1283 iter = new Gtk.TreeIter();
1284 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1288 var par = new Gtk.TreeIter();
1289 var iv = this.getIterValue(iter, 2);
1290 // print("IV" + iv);
1291 var k = JSON.parse(iv);
1292 if (k.json && !this.el.iter_parent( par, iter )) {
1297 var treepath_str = this.el.get_path(iter).to_string();
1298 // not sure how we can handle mixed id stuff..
1299 if (typeof(k.id) == 'undefined') {
1300 k.id = 'builder-'+ treepath_str ;
1304 this.treemap[ treepath_str ] = k;
1305 k.xtreepath = treepath_str ;
1308 if (this.el.iter_has_child(iter)) {
1309 citer = new Gtk.TreeIter();
1310 this.el.iter_children(citer, iter);
1311 k.items = this.toJS(citer,with_id);
1315 nodeToJSON : function(c) {
1323 return JSON.stringify(o);
1325 singleNodeToJS : function (treepath)
1327 var iter = new Gtk.TreeIter();
1328 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1332 var iv = this.getIterValue(iter, 2);
1334 return JSON.parse(iv);
1337 toJS : function(treepath, with_id)
1339 //Seed.print("WITHID: "+ with_id);
1340 var iter = treepath; // API used to be iter here..
1341 if (typeof(iter) == 'string') {
1342 iter = new Gtk.TreeIter();
1343 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1352 iter = new Gtk.TreeIter();
1353 if (!this.el.get_iter_first(iter)) {
1363 var k = this.nodeToJS(iter, with_id);
1367 if (!this.el.iter_next(iter)) {
1372 if (treepath === false) {
1374 return JSON.parse(JSON.stringify(ar));
1378 // convert the list into a json string..
1384 xtype: Gtk.TreeViewColumn,
1385 pack : "append_column",
1387 XObject.prototype.init.call(this);
1388 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1392 xtype: Gtk.CellRendererText,
1402 id : "LeftTreeMenu",
1405 xtype: Gtk.MenuItem,
1407 label : "Delete Element",
1409 activate : function (self) {
1411 this.get('/LeftTree.model').deleteSelected();
1416 xtype: Gtk.MenuItem,
1418 activate : function (self) {
1420 var tree = this.get('/LeftTree');
1421 var model = this.get('/LeftTree.model');
1422 var el = tree.getActivePath();
1424 var js = model.toJS(el, false);
1425 // print(JSON.stringify(js[0], null,4));
1426 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1431 label : "Save as Template",
1441 id : "LeftProjectTree",
1442 showNoProjectSelected : function() {
1443 this.get('/StandardErrorDialog').show("Select a Project first.");
1445 getActiveProject : function() {
1446 return this.project;
1449 leave_notify_event : function (self, event) {
1456 pack : "pack_start,false,false",
1459 xtype: Gtk.ComboBox,
1462 XObject.prototype.init.call(this);
1463 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1465 getValue : function() {
1466 var ix = this.el.get_active();
1470 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1471 if (typeof(data[ix]) == 'undefined') {
1476 setValue : function(fn)
1480 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1481 data.forEach(function(n, ix) {
1489 changed : function (self) {
1490 var fn = this.getValue();
1491 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1492 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1497 xtype: Gtk.CellRendererText,
1498 pack : "pack_start,true",
1502 xtype: Gtk.ListStore,
1505 XObject.prototype.init.call(this);
1506 this.el.set_column_types ( 2, [
1507 GObject.TYPE_STRING, // real key
1508 GObject.TYPE_STRING // real type
1512 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1514 pm.on('changed', function() {
1515 print("caught changed hook on project manager - reloading data");
1516 _this.loadData(pm.projects);
1520 loadData : function(data) {
1521 var ov = this.get('/LeftProjectTree.combo').getValue();
1523 var iter = new Gtk.TreeIter();
1525 data.forEach(function(p) {
1530 el.set_value(iter, 0, p.fn);
1531 el.set_value(iter, 1, p.name);
1535 this.get('/LeftProjectTree.combo').setValue(ov);
1544 xtype: Gtk.ScrolledWindow,
1546 shadow_type : Gtk.ShadowType.IN,
1548 XObject.prototype.init.call(this);
1549 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1553 xtype: Gtk.TreeView,
1555 cursor_changed : function (self) {
1556 var iter = new Gtk.TreeIter();
1558 if (this.selection.count_selected_rows() < 1) {
1559 //XN.get('Builder.LeftTree.model').
1560 this.get('/LeftTree.model').load( false);
1564 var model = this.get('/LeftProjectTree.model');
1565 //console.log('changed');
1566 var s = this.selection;
1567 s.get_selected(model, iter);
1568 value = new GObject.Value('');
1569 model.el.get_value(iter, 2, value);
1571 console.log(value.value);// id..
1573 var file = this.get('/LeftProjectTree').project.getById(value.value);
1580 var nb = this.get('/LeftTopPanel.expander');
1581 nb.el.expanded = false;
1583 //nb.listeners.activate.call(nb);
1584 //_expander.el.set_expanded(false);
1586 var ltm = this.get('/LeftTree.model');
1594 enable_tree_lines : true,
1595 headers_visible : false,
1597 XObject.prototype.init.call(this);
1598 var description = new Pango.FontDescription.c_new();
1599 description.set_size(8000);
1600 this.el.modify_font(description);
1602 this.selection = this.el.get_selection();
1603 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1607 xtype: Gtk.TreeStore,
1611 XObject.prototype.init.call(this);
1612 this.el.set_column_types ( 3, [
1613 GObject.TYPE_STRING, // title
1614 GObject.TYPE_STRING, // tip
1615 GObject.TYPE_STRING // id..
1619 loadProject : function(pr) {
1620 print("LOAD PROJECT");
1626 this.get('/LeftProjectTree').project = pr;
1627 this.load(pr.toTree());
1628 this.get('/LeftProjectTree.view').el.expand_all();
1630 load : function(tr,iter) {
1631 // console.dump(tr);
1632 console.log('Project tree load: ' + tr.length);
1633 var citer = new Gtk.TreeIter();
1634 //this.insert(citer,iter,0);
1637 tr.forEach(function (r) {
1639 _this.el.append(citer);
1641 _this.el.insert(citer,iter,-1);
1643 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1644 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1645 _this.el.set_value(citer, 2, '' + r.id ); //id
1646 if (r.cn && r.cn.length) {
1647 _this.load(r.cn, citer);
1652 getValue : function(iter, col) {
1653 var gval = new GObject.Value('');
1654 this.el.get_value(iter, col ,gval);
1655 return '' + gval.value;
1659 xtype: Gtk.TreeViewColumn,
1660 pack : "append_column",
1662 XObject.prototype.init.call(this);
1663 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1667 xtype: Gtk.CellRendererText,
1687 pack : "pack_start,false,true,0",
1694 button_press_event : function (self, event) {
1695 this.get('/MidPropTree.model').showData('props');
1707 stock : Gtk.STOCK_ADD,
1708 icon_size : Gtk.IconSize.MENU
1723 button_press_event : function (self, event) {
1724 this.get('/MidPropTree.model').showData('events');
1736 stock : Gtk.STOCK_ADD,
1737 icon_size : Gtk.IconSize.MENU
1752 button_press_event : function (self, ev) {
1753 var p = this.get('/AddPropertyPopup');
1757 p.el.set_screen(Gdk.Screen.get_default());
1759 p.el.popup(null, null, null, null, 3, ev.button.time);
1771 stock : Gtk.STOCK_ADD,
1772 icon_size : Gtk.IconSize.MENU
1784 id : "AddPropertyPopup",
1787 xtype: Gtk.MenuItem,
1789 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1792 activate : function (self) {
1794 this.get('/LeftPanel.model').add( {
1805 xtype: Gtk.MenuItem,
1807 tooltip_markup : "Add what type of packing is to be used",
1810 activate : function (self) {
1812 this.get('/LeftPanel.model').add( {
1822 xtype: Gtk.MenuItem,
1824 tooltip_markup : "Override the init method",
1827 activate : function (self) {
1829 this.get('/LeftPanel.model').add( {
1832 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1839 xtype: Gtk.SeparatorMenuItem,
1843 xtype: Gtk.MenuItem,
1845 tooltip_markup : "Add a user defined string property",
1848 activate : function (self) {
1850 this.get('/LeftPanel.model').add( {
1860 xtype: Gtk.MenuItem,
1862 tooltip_markup : "Add a user defined number property",
1865 activate : function (self) {
1867 this.get('/LeftPanel.model').add( {
1877 xtype: Gtk.MenuItem,
1879 tooltip_markup : "Add a user defined boolean property",
1882 activate : function (self) {
1884 this.get('/LeftPanel.model').add( {
1894 xtype: Gtk.SeparatorMenuItem,
1898 xtype: Gtk.MenuItem,
1900 tooltip_markup : "Add a user function boolean property",
1903 activate : function (self) {
1905 this.get('/LeftPanel.model').add( {
1908 val : "function() {\n \n}\n",
1921 xtype: Gtk.ScrolledWindow,
1926 XObject.prototype.init.call(this);
1927 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1929 shadow_type : Gtk.ShadowType.IN,
1932 xtype: Gtk.TreeView,
1934 button_press_event : function (self, ev) {
1939 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1940 return false; //not on a element.
1944 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
1946 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
1949 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1950 var p = this.get('/LeftPanelPopup');
1955 p.el.set_screen(Gdk.Screen.get_default());
1957 p.el.popup(null, null, null, null, 3, ev.button.time);
1958 //Seed.print("click:" + res.column.title);
1965 if (res.column.title != 'value') {
1966 // XObject.error("column is not value?");
1967 return false; // ignore.. - key click.. ??? should we do this??
1970 // currently editing???
1971 // if ( this.activePath) {
1973 // this.activePath = false;
1975 if (this.get('/Editor').dirty) {
1976 //if (!this.get('/Editor.buffer').checkSyntax()) {
1977 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
1981 if (!this.get('/Editor.view').save()) {
1985 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1986 this.get('/LeftPanel').editing = false;
1988 // XObject.error("Currently editing?");
1992 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1994 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1996 // get options for this type -- this is to support option lists etc..
1997 var provider = this.get('/LeftTree').getPaleteProvider();
1998 var opts = provider.findOptions(type);
2000 if (opts === false) {
2002 this.get('/LeftPanel').editableColumn.setOptions([]);
2003 renderer.has_entry = true;
2005 this.get('/LeftPanel').editableColumn.setOptions(opts);
2006 renderer.has_entry = false;
2008 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2010 //Seed.print("click" + ev.type);
2011 //console.dump(res);
2020 enable_tree_lines : true,
2021 headers_visible : false,
2023 XObject.prototype.init.call(this);
2025 this.selection = this.el.get_selection();
2026 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2029 var description = new Pango.FontDescription.c_new();
2030 description.set_size(8000);
2031 this.el.modify_font(description);
2035 xtype: Gtk.TreeStore,
2039 add : function(info) {
2040 // info includes key, val, skel, etype..
2042 type = info.type.toLowerCase();
2043 var data = this.toJS();
2045 if (info.etype == 'events') {
2046 data.listeners = data.listeners || { };
2047 if (typeof(data.listeners[info.key]) != 'undefined') {
2048 return; //already set!
2051 if (typeof(data[info.key]) != 'undefined') {
2056 if (typeof(info.val) == 'undefined') {
2059 if (info.type.toLowerCase() == 'boolean') {
2062 if (type == 'number') {
2070 if (info.etype == 'events') {
2072 data.listeners[info.key] = info.val;
2075 data[info.key] = info.val;
2079 var map = this.load(data);
2081 // flag it as changed to the interface..
2083 this.get('/LeftTree.model').changed(data, true);
2086 this.startEditing(map[k]);
2089 LeftPanel.get('view').el.row_activated(
2090 new Gtk.TreePath.from_string(map[k]),
2091 LeftPanel.editableColumn.el
2095 changed : function(str, doRefresh) {
2096 if (!this.activePath) {
2099 var iter = new Gtk.TreeIter();
2100 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2102 this.el.set_value(iter, 1, '' +str);
2103 this.el.set_value(iter, 3, '' + this.toShort(str));
2104 var type = this.getIterValue(iter, 4);
2106 this.el.set_value(iter, 5, type + ' : ' + str);
2107 // update the tree...
2109 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2111 deleteSelected : function() {
2112 var data = this.toJS();
2113 var iter = new Gtk.TreeIter();
2114 var s = this.get('/LeftPanel.view').selection;
2115 s.get_selected(this.el, iter);
2118 var gval = new GObject.Value('');
2119 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2121 var val = gval.value;
2122 if (val[0] == '!') {
2124 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2127 delete data.listeners[ val.substring(1)];
2128 if (!XObject.keys(data.listeners).length) {
2129 delete data.listeners;
2133 if (typeof(data[val]) == 'undefined') {
2141 this.get('/LeftTree.model').changed(data, true);
2144 getIterValue : function(iter, col) {
2145 var gval = new GObject.Value('');
2146 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2147 return '' + gval.value;
2149 getType : function(treepath) {
2150 return this.getValue(treepath, 4);
2152 getValue : function(treepath_str, col)
2154 // get's the value in a row.. - keys - returns string, values - formats it..
2156 var iter = new Gtk.TreeIter();
2157 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2159 var gval = new GObject.Value('');
2160 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2161 var val = '' + gval.value;
2166 var type = this.getType(this.el.get_path(iter).to_string());
2167 //print("TYPE: " +type + " - val:" + val);
2168 switch(type.toLowerCase()) {
2172 return parseFloat(val); // Nan ?? invalid!!?
2175 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2177 return val == 'true' ? true : false;
2179 var nv = parseFloat(val);
2180 if (!isNaN(nv) && (val == ''+nv)) {
2188 XObject.prototype.init.call(this);
2189 this.el.set_column_types ( 6, [
2190 GObject.TYPE_STRING, // 0 real key
2191 GObject.TYPE_STRING, // 1 real value
2192 GObject.TYPE_STRING, // 2 visable key
2193 GObject.TYPE_STRING, // 3 visable value
2194 GObject.TYPE_STRING, // 4 need to store type of!!!
2195 GObject.TYPE_STRING // 5 tooltip
2199 load : function(ar) {
2200 // might casue problesm..
2201 // this.get('/Editor.RightEditor').save();
2203 this.get('/Editor').el.hide();
2204 this.get('/Editor').activePath = false;
2209 //this.get('/RightEditor').el.hide();
2216 var provider = this.get('/LeftTree').getPaleteProvider();
2217 var iter = new Gtk.TreeIter();
2220 var keys = XObject.keys(ar);
2222 ar.listeners = ar.listeners || {};
2224 for (var i in ar.listeners ) {
2225 this.el.append(iter);
2226 var p = this.el.get_path(iter).to_string();
2229 this.el.set_value(iter, 0, '!'+ i );
2230 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2231 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2233 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2234 this.el.set_value(iter, 4, 'function');
2235 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2241 keys.forEach(function(i) {
2242 if (typeof(ar[i]) == 'object') {
2246 var type = provider.findType(ar, i, ar[i]);
2248 _this.el.append(iter);
2249 var p = _this.el.get_path(iter).to_string();
2251 _this.el.set_value(iter, 0, ''+i);
2252 _this.el.set_value(iter, 1, '' + ar[i]);
2253 _this.el.set_value(iter, 2, ''+i);
2254 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2255 _this.el.set_value(iter, 4, ''+type);
2256 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2260 startEditing : function(path,col) {
2262 // alled by menu 'edit' currently..
2264 * start editing path (or selected if not set..)
2265 * @param {String|false} path (optional) treepath to edit - selected tree gets
2266 * edited by default.
2267 * @param {Number} 0 or 1 (optional)- column to edit.
2269 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2271 if (typeof(path) == 'string') {
2272 tp = new Gtk.TreePath.from_string(path);
2274 var iter = new Gtk.TreeIter();
2275 var s = this.get('/LeftPanel.view').selection;
2276 s.get_selected(this.el, iter);
2277 tp = this.el.get_path(iter);
2278 path = tp.to_string();
2282 // which colum is to be edited..
2285 // not sure what this does..
2287 if (typeof(col) == 'undefined') {
2288 var k = this.getValue(path, 0);
2290 colObj = (!k.length || k == '|') ?
2291 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2293 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2296 // make sure the pulldown is set correctly..
2297 // not really needed for second col...
2298 var showEditor = false;
2299 this.get('/Editor').activePath = false;
2300 this.get('/Editor').el.hide();
2303 var provider = this.get('/LeftTree').getPaleteProvider();
2304 var type = this.get('/LeftPanel.model').getType(path);
2305 var opts = provider.findOptions(type);
2306 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2308 if (opts === false) {
2309 this.get('/LeftPanel').editableColumn.setOptions([]);
2310 renderer.has_entry = true;
2312 this.get('/LeftPanel').editableColumn.setOptions(opts);
2313 renderer.has_entry = false;/// - pulldowns do not have entries
2315 // determine if we should use the Text editor...
2316 var keyname = this.getValue(path, 0);
2317 var data_value = this.getValue(path, 1);
2319 if ((keyname[0] == '|') ||
2321 (typeof(data_value) == 'string' ) &&
2322 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2326 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2331 // this.get('/BottomPane').el.hide();
2332 //this.get('/RightEditor').el.hide();
2337 this.activePath = false;
2339 _this.get('/Editor').el.show_all();
2340 GLib.timeout_add(0, 1, function() {
2342 //_this.get('/BottomPane').el.show();
2343 //_this.get('/RightEditor').el.show();
2345 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2347 _this.get('/Editor').activePath = path;
2348 _this.activePath = path ;
2358 // iter now has row...
2359 GLib.timeout_add(0, 100, function() {
2360 _this.activePath = path;
2361 colObj.items[0].el.editable = true; // esp. need for col 0..
2362 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2372 var iter = new Gtk.TreeIter();
2373 this.get('/LeftPanel.model').el.get_iter_first(iter);
2378 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2381 ar.listeners = ar.listeners || {};
2382 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2385 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2388 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2394 //print(JSON.stringify(ar));
2398 toShort : function(str) {
2399 var a = typeof(str) == 'string' ? str.split("\n") : [];
2400 return a.length > 1 ? a[0] + '....' : '' + str;
2404 xtype: Gtk.TreeViewColumn,
2405 pack : "append_column",
2407 XObject.prototype.init.call(this);
2409 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2410 this.get('/LeftPanel').propertyColumn = this;
2415 xtype: Gtk.CellRendererText,
2416 pack : "pack_start",
2418 editing_started : function (self, editable, path) {
2420 this.get('/LeftPanel.model').activePath = path;
2423 edited : function (self, object, p0) {
2424 var model = this.get('/LeftPanel.model');
2425 var path = model.activePath;
2426 var iter = new Gtk.TreeIter();
2427 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2428 model.el.set_value(iter, 0, p0);
2429 model.el.set_value(iter, 2, p0);
2431 model.activePath = false;
2433 this.get('/LeftTree.model').changed(model.toJS(), true);
2434 this.el.editable = false;
2441 xtype: Gtk.TreeViewColumn,
2442 pack : "append_column",
2445 XObject.prototype.init.call(this);
2446 this.el.add_attribute(this.items[0].el , 'text', 3 );
2447 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2448 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2449 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2451 this.get('/LeftPanel').editableColumn= this;
2453 setOptions : function(ar) {
2454 var m = this.items[0].el.model;
2456 var iter = new Gtk.TreeIter();
2457 ar.forEach(function(i) {
2460 m.set_value(iter, 0, i);
2466 xtype: Gtk.CellRendererCombo,
2468 edited : function (self, object, p0) {
2469 this.get('/LeftPanel').editing = false;
2470 var ap = this.get('/LeftPanel.model').activePath
2471 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2472 this.get('/LeftPanel.model').changed(p0, true);
2473 this.get('/LeftPanel.model').activePath = false;
2474 this.el.editable = false;
2476 editing_started : function (self, editable, path) {
2477 this.get('/LeftPanel').editing = true;
2478 // console.log('editing started');
2479 // r.has_entry = false;
2481 this.el.editable = false; // make sure it's not editor...
2486 pack : "pack_start",
2490 XObject.prototype.init.call(this);
2491 this.el.model = new Gtk.ListStore();
2492 this.el.model.set_column_types ( 1, [
2493 GObject.TYPE_STRING // 0 real key
2504 id : "LeftPanelPopup",
2507 xtype: Gtk.MenuItem,
2511 activate : function (self) {
2512 this.get('/LeftPanel.model').deleteSelected();
2517 xtype: Gtk.MenuItem,
2521 activate : function (self) {
2522 this.get('/LeftPanel.model').startEditing(false, 0);
2535 xtype: Gtk.ScrolledWindow,
2536 pack : "pack_end,false,true,0",
2538 shadow_type : Gtk.ShadowType.IN,
2540 XObject.prototype.init.call(this);
2541 XObject.prototype.init.call(this);
2542 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2543 this.el.set_size_request ( 150, -1 );
2546 activeElement : false,
2547 hideWin : function() {
2554 if (this.get('/Window.left').el.position < 160) {
2557 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2564 xtype: Gtk.TreeView,
2566 cursor_changed : function (self) {
2567 var iter = new Gtk.TreeIter();
2569 //console.log('changed');
2570 var m = this.get('model');
2571 if (!this.selection){
2572 this.selection = this.el.get_selection();
2575 var s = this.selection;
2576 if (!s.get_selected(m.el, iter)) {
2579 var tp = m.el.get_path(iter).to_string();
2584 var key = m.getValue(tp, 0);
2586 var type = m.getValue(tp, 1);
2587 var skel = m.getValue(tp, 3);
2588 var etype = m.getValue(tp, 5);
2591 this.get('/MidPropTree').hideWin();
2593 if (type.toLowerCase() == 'function') {
2595 if (etype != 'events') {
2599 this.get('/LeftPanel.model').add({
2607 // has dot in name, and is boolean???? this does not make sense..
2608 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2612 this.get('/LeftPanel.model').add( {
2622 enable_tree_lines : true,
2623 headers_visible : false,
2625 XObject.prototype.init.call(this);
2627 var description = new Pango.FontDescription.c_new();
2628 description.set_size(8000);
2629 this.el.modify_font(description);
2631 //this.selection = this.el.get_selection();
2632 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2641 xtype: Gtk.ListStore,
2644 getValue : function(treepath, col)
2646 var tp = new Gtk.TreePath.from_string (treepath);
2647 var iter = new Gtk.TreeIter();
2648 this.el.get_iter (iter, tp);
2649 var value = new GObject.Value('');
2650 this.el.get_value(iter, col, value);
2655 XObject.prototype.init.call(this);
2656 this.el.set_column_types ( 6, [
2657 GObject.TYPE_STRING, // real key
2658 GObject.TYPE_STRING, // real type
2659 GObject.TYPE_STRING, // docs ?
2660 GObject.TYPE_STRING, // visable desc
2661 GObject.TYPE_STRING, // function desc
2662 GObject.TYPE_STRING // element type (event|prop)
2666 showData : function(type) {
2668 if (!this.get('/MidPropTree').activeElement || !type) {
2669 return; // no active element
2672 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2673 var palete = this.get('/LeftTree').getPaleteProvider();
2677 Seed.print('Showing right?');
2678 if (!this.get('/MidPropTree').shown) {
2680 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2681 this.get('/MidPropTree').el.show();
2682 this.get('/MidPropTree').shown = true;
2685 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2686 return a.name > b.name ? 1 : -1;
2688 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2689 // console.dump(elementList);
2692 var iter = new Gtk.TreeIter();
2693 for(var i =0 ; i < elementList.length; i++) {
2694 var p=elementList[i];
2695 this.el.append(iter);
2696 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2697 //GObject.TYPE_STRING, // real key
2698 // GObject.TYPE_STRING, // real type
2699 // GObject.TYPE_STRING, // docs ?
2700 // GObject.TYPE_STRING // func def?
2703 this.el.set_value(iter, 0, p.name);
2704 this.el.set_value(iter, 1, p.type);
2705 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2706 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2707 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2708 this.el.set_value(iter, 5, type);
2715 xtype: Gtk.TreeViewColumn,
2717 this.el = new Gtk.TreeViewColumn();
2718 this.parent.el.append_column(this.el);
2720 XObject.prototype.init.call(this);
2721 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2726 xtype: Gtk.CellRendererText,
2727 pack : "pack_start,true"
2751 xtype: Gtk.Notebook,
2752 pack : "pack_start,true,true",
2753 id : "view-help-nb",
2755 XObject.prototype.init.call(this);
2756 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2757 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2761 xtype: Gtk.Notebook,
2762 id : "view-notebook",
2766 XObject.prototype.init.call(this);
2767 this.el.set_current_page(0);
2768 //print("SET LABEL?")
2769 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2770 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2776 id : "RightBrowser",
2781 pack : "pack_start,false,true,0",
2786 clicked : function (self) {
2787 this.get('/RightBrowser.view').renderJS(null,true);
2791 pack : "pack_start,false,false,0"
2794 xtype: Gtk.CheckButton,
2796 toggled : function (self, state) {
2797 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2802 label : "Auto Redraw On",
2803 pack : "pack_start,false,false,0"
2808 xtype: Gtk.ScrolledWindow,
2811 XObject.prototype.init.call(this);
2812 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2814 shadow_type : Gtk.ShadowType.IN,
2817 xtype: WebKit.WebView,
2819 load_finished : function (self, object) {
2820 print("load finished");
2821 // print("load_finished"); return;
2822 // if (this.ready) { // dont do it twice!
2825 if (!this.inspectorShown) {
2826 this.el.get_inspector().show();
2827 this.inspectorShown = true;
2832 if (this.pendingRedraw) {
2833 this.pendingRedraw = false;
2834 this.refreshRequired = true;
2836 //var js = this.get('/LeftTree.model').toJS();
2837 //if (js && js[0]) {
2838 // this.renderJS(js[0]);
2842 script_alert : function (self, object, p0) {
2845 return true; // do not display anything...
2847 console_message : function (self, object, p0, p1) {
2849 // console.log(object);
2852 if (object.match(/variable/) && object.match(/Builder/)) {
2853 print("got builder missing message");
2854 this.refreshRequired = true;
2855 this.lastRedraw = 0;
2861 if (!object.match(/^\{/)) {
2863 //this.get('/Terminal').feed(object);
2864 return true; // do not handle!!! -> later maybe in console..
2870 // console.log(object);
2871 var val = JSON.parse(object);
2873 if (typeof(val['hover-node']) != 'undefined') {
2874 this.activeNode = val['hover-node'];
2875 console.log('active node: ' + this.activeNode);
2880 if (typeof(val['id']) != 'undefined') {
2881 // this.activeNode = val['id'];
2882 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2883 if (!tg || typeof(tg[0]) == 'undefined') {
2886 print("SELECT node " + tg[0]);
2888 this.get('/LeftTree.view').selectNode(tg[0]);
2892 if (ret && typeof(val['set']) != 'undefined') {
2893 this.get('/LeftPanel.model').add({
2897 //console.log('active node: ' + this.activeNode);
2900 //Seed.print('a:'+a);
2901 //Seed.print('b:'+b);
2902 //Seed.print('c:'+c);
2905 drag_motion : function (w, ctx, x, y, time, ud) {
2906 // console.log('DRAG MOTION');
2908 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2909 this.targetData = [];
2910 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2912 // A) find out from drag all the places that node could be dropped.
2913 var src = Gtk.drag_get_source_widget(ctx);
2914 if (!src.dropList) {
2915 Gdk.drag_status(ctx, 0, time);
2918 // b) get what we are over.. (from activeNode)
2919 // tree is empty.. - list should be correct..
2920 if (!this.get('/LeftTree.model').currentTree) {
2921 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2925 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2927 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2930 Gdk.drag_status(ctx, 0,time);
2931 this.get('/LeftTree.view').highlight(false);
2935 // if we have a target..
2936 // -> highlight it! (in browser)
2937 // -> highlight it! (in tree)
2939 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2940 this.get('/LeftTree.view').highlight(tg);
2941 this.targetData = tg;
2942 // for tree we should handle this...
2945 drag_drop : function (w, ctx, x, y,time, ud) {
2946 print("TARGET: drag-drop");
2947 var is_valid_drop_site = true;
2952 w, /* will receive 'drag-data-received' signal */
2953 ctx, /* represents the current state of the DnD */
2954 this.get('/Window').atoms["STRING"], /* the target type we want */
2955 time /* time stamp */
2959 /* No target offered by source => error */
2962 return is_valid_drop_site;
2964 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2966 print("Browser: drag-data-received");
2967 var delete_selection_data = false;
2968 vardnd_success = false;
2969 /* Deal with what we are given from source */
2970 if( sel_data && sel_data.length ) {
2972 if (ctx.action == Gdk.DragAction.ASK) {
2973 /* Ask the user to move or copy, then set the ctx action. */
2976 if (ctx.action == Gdk.DragAction.MOVE) {
2977 delete_selection_data = true;
2979 var source = Gtk.drag_get_source_widget(ctx);
2981 print("Browser: source.DRAGDATA? " + source.dragData);
2982 if (this.targetData) {
2983 print(this.targetData);
2984 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2993 if (dnd_success == false)
2995 Seed.print ("DnD data transfer failed!\n");
2998 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3001 create_web_view : function (self, object) {
3002 print("CREATE WEB VIEW");
3003 return null; //new WebKit.WebView();
3010 XObject.prototype.init.call(this);
3011 // this may not work!?
3012 var settings = this.el.get_settings();
3013 settings.enable_developer_extras = true;
3015 // this was an attempt to change the url perms.. did not work..
3016 // settings.enable_file_access_from_file_uris = true;
3017 // settings.enable_offline_web_application_cache - true;
3018 // settings.enable_universal_access_from_file_uris = true;
3022 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3023 _this.get('/BottomPane.inspector').el.show();
3024 return _this.get('/BottomPane.inspector').el;
3028 // FIXME - base url of script..
3029 // we need it so some of the database features work.
3030 this.el.load_html_string( "Render not ready" ,
3031 //fixme - should be a config option!
3032 // or should we catch stuff and fix it up..
3033 'http://localhost/app.Builder/'
3037 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3041 this.el, /* widget that will accept a drop */
3042 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3043 null, /* lists of target to support */
3044 0, /* size of list */
3045 Gdk.DragAction.COPY /* what to do with data after dropped */
3048 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3049 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3051 GLib.timeout_add_seconds(0, 1, function() {
3052 // print("run refresh?");
3059 renderJS : function(data, force) {
3061 // this is the public redraw call..
3062 // we refresh in a loop privately..
3063 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3064 if (!autodraw && !force) {
3065 print("Skipping redraw - no force, and autodraw off");
3068 this.refreshRequired = true;
3070 runRefresh : function()
3072 // this is run every 2 seconds from the init..
3076 if (!this.refreshRequired) {
3077 // print("no refresh required");
3081 if (this.lastRedraw) {
3082 // do not redraw if last redraw was less that 5 seconds ago.
3083 if (((new Date()) - this.lastRedraw) < 5000) {
3091 if (!this.get('/Window.LeftTree').getActiveFile()) {
3094 this.refreshRequired = false;
3095 // print("HTML RENDERING");
3097 this.get('/BottomPane').el.show();
3098 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3101 var js = this.get('/LeftTree.model').toJS();
3102 if (!js || !js.length) {
3109 var project = this.get('/Window.LeftTree').getActiveFile().project;
3110 //print (project.fn);
3111 // set it to non-empty.
3112 project.runhtml = project.runhtml || '';
3113 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3116 this.runhtml = this.runhtml || '';
3118 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3119 // then we need to reload the browser using
3120 // load_html_string..
3122 // then trigger a redraw once it's loaded..
3123 this.pendingRedraw = true;
3124 var runhtml = '<script type="text/javascript">' + "\n" ;
3125 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3126 runhtml += '</script>'+ "\n" ;
3128 this.runhtml = project.runhtml;
3129 // need to modify paths
3133 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3134 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3135 print("LOAD HTML " + html);
3136 this.el.load_html_string( html ,
3137 //fixme - should be a config option!
3138 'http://localhost/app.Builder/'
3141 // should trigger load_finished! - which in truns shoudl set refresh Required;
3147 this.renderedData = data;
3148 var str = JSON.stringify(data) ;
3151 console.log('not loaded yet');
3153 this.lastRedraw = new Date();
3155 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3156 print( "before render" + this.lastRedraw);
3157 print( "after render" + (new Date()));
3167 id : "RightGtkView",
3169 redraw : function() {
3170 this.highlightWidget = false;
3171 print("REDRAW CALLED");
3172 this.activePath = this.get('/LeftTree').getActivePath();
3173 if (this.renderedEl) {
3174 print("QUEUE DRAW CALLING");
3175 this.renderedEl.queue_draw();
3178 renderJS : function(data, withDebug)
3180 this.highlightWidget = false;
3182 this.withDebug = false;
3183 while (this.get('view').el.get_children().length) {
3184 var c = this.get('view').el.get_children()[0];
3185 this.get('view').el.remove(c);
3192 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3193 // in theory tree is actually window..
3196 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3202 this.get('view').el.set_size_request(
3203 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3205 if (this.renderedEl) {
3206 this.renderedEl.set_size_request(
3207 tree.default_width || 600,
3208 tree.default_height || 400
3211 this.get('view').el.show_all();
3216 showInWindow : function() {
3217 print("GET PROEJCT");
3218 var pr = this.get('/LeftProjectTree').getActiveProject();
3220 console.log(pr.paths);
3223 var src= this.buildJS(
3224 this.get('/LeftTree.model').toJS()[0],
3229 //var x = new imports.sandbox.Context();
3233 Seed.check_syntax('var e = ' + src);
3236 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3237 this.get('/Terminal').feed(console._dump(e)+"\n");
3239 var lines = src.split("\n");
3240 var start = Math.max(0, e.line - 10);
3241 var end = Math.min(lines.length, e.line + 10);
3242 for (var i =start ; i < end; i++) {
3244 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3247 this.get('/Terminal').feed(lines[i] + "\n");
3254 this.get('/BottomPane').el.set_current_page(1);
3255 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3256 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3257 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3259 var _top = x.get_global_object()._top;
3261 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3263 if (_top.el.popup) {
3264 _top.el.popup(null, null, null, null, 3, null);
3268 viewAdd : function(item, par)
3270 // does something similar to xobject..
3271 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3273 if (item.pack===false || item.pack === 'false') { // no ;
3276 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3277 var type = item['|xns'] + '.' + item['xtype'];
3279 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3282 var ns = imports.gi[item['|xns']];
3283 var ctr = ns[item['xtype']];
3285 for(var k in item) {
3287 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3302 if (k[0] == '|' && typeof(kv) == 'string') {
3304 if (kv.match(new RegExp('function'))) {
3307 print("WASL " + k + '=' + kv);
3309 eval( 'kv = ' + kv);
3310 } catch(e) { continue; }
3313 // print(k + '=' + kv);
3315 if (k[0] == '|') { // should be boolean or number..
3317 //print(k + '=' + kv);
3320 if (k == 'show_tabs') { // force tab showing for notebooks.
3323 print(k + '=' + typeof(kv) + " : " + kv);
3329 var el = new ctr(ctr_args);
3331 print("PACK" + item.pack);
3332 //console.dump(item.pack);
3339 if (typeof(item.pack) == 'string') {
3341 item.pack.split(',').forEach(function(e, i) {
3343 if (e == 'false') { args.push( false); return; }
3344 if (e == 'true') { args.push( true); return; }
3345 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3348 //print(args.join(","));
3350 pack_m = args.shift();
3352 pack_m = item.pack.shift();
3357 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3359 name: "ArgumentError",
3360 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3361 "ADDING : " + item.id + " " + el
3370 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3371 //Seed.print('args: ' + args.length);
3373 par[pack_m].apply(par, args);
3377 item.items = item.items || [];
3378 item.items.forEach(function(ch,n) {
3380 print ("type:" + type);
3382 print ("ch.pack:" + ch.pack);
3383 if (type == 'Gtk.Table' && ch.pack == 'add') {
3384 var c = n % item.n_columns;
3385 var r = Math.floor(n/item.n_columns);
3386 ch.pack = [ 'attach', c, c+1, r, r+1,
3387 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3388 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3389 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3390 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3394 _this.viewAdd(ch, el);
3399 // add the signal handlers.
3400 // is it a widget!?!!?
3406 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3407 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3408 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3409 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3410 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3420 widgetDragDropEvent : function() {
3421 print("WIDGET DRAGDROP");
3424 widgetDragMotionEvent : function() {
3425 print("WIDGET DRAGMOTION");
3428 widgetExposeEvent : function(w, evt, ud, item) {
3430 if (this.inRender) {
3434 if ( this.highlightWidget) {
3435 this.inRender = true;
3436 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3437 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3439 this.inRender = false;
3444 if (this.activePath != item.xtreepath) {
3448 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3449 // work out the coords of the window..
3451 var dr = widget.window;
3452 this.gc = (new Gdk.GC.c_new(dr));
3453 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3454 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3458 var r = evt.expose.area;
3459 // console.dump([r.x, r.y, r.width, r.height ] );
3461 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3462 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3463 // happens with gtkscrollview embedded stuff..
3464 var np =this.activePath.split(':');
3466 this.activePath = np.join(':');
3467 this.renderedEl.queue_draw();
3483 this.inRender = true;
3486 this.highlightWidget = widget;
3491 // print("DRAW BOX");
3492 //console.dump(this.box);
3493 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3494 this.inRender = false;
3497 widgetPressEvent : function(w,e,u,d) {
3498 if (this.get('view').pressed) {
3501 this.get('view').pressed = true;
3502 print("WIDGET PRESS " + d.xtreepath );
3503 this.get('/LeftTree.view').selectNode( d.xtreepath );
3506 widgetReleaseEvent : function() {
3507 this.get('view').pressed = false;
3513 pack : "pack_start,false,true,0",
3517 pack : "pack_start,false,false,0",
3518 label : "Run The Application",
3520 button_press_event : function (self, event) {
3521 // call render on left tree - with special option!?!
3523 //print("GET PROEJCT");
3524 var pr = this.get('/LeftProjectTree').getActiveProject();
3527 for (var i in pr.paths) {
3531 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3532 this.get('/Terminal').feed("RUN DIR:" + dir);
3534 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3535 , false,false,false);
3536 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3537 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3547 xtype: Gtk.ScrolledWindow,
3550 shadow_type : Gtk.ShadowType.IN,
3552 XObject.prototype.init.call(this);
3553 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3557 xtype: Gtk.EventBox,
3558 pack : "add_with_viewport",
3560 XObject.prototype.init.call(this);
3561 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3562 red: 0x9F00, green: 0xB800 , blue : 0xA800
3570 XObject.prototype.init.call(this);
3571 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3572 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3577 xtype: Gtk.EventBox,
3580 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3581 XObject.prototype.init.call(this);
3585 this.el, /* widget that will accept a drop */
3586 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3587 null, /* lists of target to support */
3588 0, /* size of list */
3589 Gdk.DragAction.COPY /* what to do with data after dropped */
3592 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3593 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3596 getActiveNode : function(x,y)
3598 // workout what node is here..
3599 return '0'; // top..
3603 drag_motion : function (self, ctx, x, y, time) {
3605 // A) find out from drag all the places that node could be dropped.
3606 var src = Gtk.drag_get_source_widget(ctx);
3607 if (!src.dropList) {
3608 Gdk.drag_status(ctx, 0, time);
3611 // b) get what we are over.. (from activeNode)
3612 // tree is empty.. - list should be correct..
3613 if (!this.get('/LeftTree.model').currentTree) {
3614 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3618 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3619 var activeNode = this.getActiveNode(x, y);
3622 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3625 Gdk.drag_status(ctx, 0,time);
3626 this.get('/LeftTree.view').highlight(false);
3630 // if we have a target..
3631 // -> highlight it! (in browser)
3632 // -> highlight it! (in tree)
3634 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3635 this.get('/LeftTree.view').highlight(tg);
3636 this.targetData = tg;
3637 // for tree we should handle this...
3640 drag_drop : function (self,ctx, x, y, time) {
3641 Seed.print("TARGET: drag-drop");
3642 var is_valid_drop_site = true;
3647 self, /* will receive 'drag-data-received' signal */
3648 ctx, /* represents the current state of the this.gDnD */
3649 this.get('/Window').atoms["STRING"], /* the target type we want */
3650 time /* time stamp */
3654 /* No target offered by source => error */
3657 return is_valid_drop_site;
3660 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3662 Seed.print("GtkView: drag-data-received");
3663 var delete_selection_data = false;
3664 var dnd_success = false;
3665 /* Deal with what we are given from source */
3666 if( sel_data && sel_data.length ) {
3668 if (ctx.action == Gdk.DragAction.ASK) {
3669 /* Ask the user to move or copy, then set the ctx action. */
3672 if (ctx.action == Gdk.DragAction.MOVE) {
3673 delete_selection_data = true;
3675 var source = Gtk.drag_get_source_widget(ctx);
3677 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3678 if (this.targetData) {
3679 Seed.print(this.targetData);
3680 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3689 if (dnd_success == false)
3691 Seed.print ("DnD data transfer failed!\n");
3694 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3697 button_press_event : function (self, event) {
3698 this.pressed = false;
3714 xtype: Gtk.ScrolledWindow,
3719 var file = this.get('/LeftTree').getActiveFile();
3723 var activeEl = this.get('/LeftTree').getActiveElement();
3724 var xtype = file.guessName( activeEl )
3725 if (!xtype || !xtype.length) {
3728 //this.get('/Window.view-help-nb').el.set_current_page(1);
3730 // get the active element being edited.
3731 var helpurl = file.getHelpUrl(xtype);
3733 // now load the help info in the page..
3734 this.get('help-view').el.open(helpurl);
3738 xtype: WebKit.WebView,
3742 XObject.prototype.init.call(this);
3743 this.get('/Window.help-view').el.open(
3744 "http://devel.akbkhome.com/seed/");
3756 xtype: Gtk.Notebook,
3760 XObject.prototype.init.call(this);
3761 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3762 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3763 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3767 xtype: Gtk.ScrolledWindow,
3771 xtype: Vte.Terminal,
3774 feed : function(istr) {
3775 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3776 // we should make ourselves visable!!!
3777 this.get('/BottomPane').el.show();
3778 this.get('/BottomPane').el.set_current_page(1);
3780 this.el.feed(str ,str.length);
3782 scroll_on_output : true,
3784 XObject.prototype.init.call(this);
3785 this.el.set_size (80, 1000);
3787 scrollback_lines : 1000
3792 xtype: Gtk.ScrolledWindow,
3796 xtype: WebKit.WebView,
3808 pack : "pack_start,false,false",
3812 this.get('buttonbar').el.show();
3813 this.get('viewbox').el.hide();
3814 print("TRIED TO HIDE");
3817 this.get('buttonbar').el.hide();
3818 this.get('viewbox').el.show();
3819 // this.get('model').expanded();
3831 pack : "pack_start,false,true",
3833 clicked : function (self) {
3834 this.get('/RightPalete').show();
3841 stock : Gtk.STOCK_GOTO_FIRST,
3842 icon_size : Gtk.IconSize.MENU
3852 XObject.prototype.init.call(this);
3853 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3856 enter_notify_event : function (self, event) {
3857 this.get('/RightPalete').show();
3871 pack : "pack_start,false,true",
3880 pack : "pack_start,false,true",
3882 clicked : function (self) {
3883 this.get('/RightPalete').hide();
3890 stock : Gtk.STOCK_GOTO_LAST,
3891 icon_size : Gtk.IconSize.MENU
3898 xtype: Gtk.ScrolledWindow,
3901 XObject.prototype.init.call(this);
3902 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3903 this.el.set_size_request(-1,200);
3905 shadow_type : Gtk.ShadowType.IN,
3908 xtype: Gtk.TreeView,
3911 XObject.prototype.init.call(this);
3912 this.el.set_size_request(150,-1);
3913 // set_reorderable: [1]
3915 var description = new Pango.FontDescription.c_new();
3916 description.set_size(8000);
3917 this.el.modify_font(description);
3919 this.selection = this.el.get_selection();
3920 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3921 // this.selection.signal['changed'].connect(function() {
3922 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3924 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3926 Gtk.drag_source_set (
3927 this.el, /* widget will be drag-able */
3928 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3929 null, /* lists of target to support */
3930 0, /* size of list */
3931 Gdk.DragAction.COPY /* what to do with data after dropped */
3933 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3935 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3936 Gtk.drag_source_add_text_targets(this.el);
3938 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3939 targets = new Gtk.TargetList();
3940 targets.add( LeftTree.atoms["STRING"], 0, 0);
3941 targets.add_text_targets( 1 );
3942 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3944 //if you want to allow text to be output elsewhere..
3945 //Gtk.drag_source_add_text_targets(this.el);
3949 headers_visible : false,
3950 enable_tree_lines : true,
3952 drag_begin : function (self, ctx) {
3953 // we could fill this in now...
3954 Seed.print('SOURCE: drag-begin');
3958 var iter = new Gtk.TreeIter();
3959 var s = this.selection;
3960 s.get_selected(this.get('/RightPalete.model').el, iter);
3961 var path = this.get('/RightPalete.model').el.get_path(iter);
3963 var pix = this.el.create_row_drag_icon ( path);
3966 Gtk.drag_set_icon_pixmap (ctx,
3973 var value = new GObject.Value('');
3974 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3975 if (!this.get('/RightPalete').provider) {
3978 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3979 this.el.dragData = value.value;
3986 drag_data_get : function (self, drag_context, selection_data, info, time) {
3987 //Seed.print('Palete: drag-data-get: ' + target_type);
3988 if (this.el.dragData && this.el.dragData.length ) {
3989 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3993 //this.el.dragData = "TEST from source widget";
3997 drag_end : function (self, drag_context) {
3998 Seed.print('SOURCE: drag-end');
3999 this.el.dragData = false;
4000 this.el.dropList = false;
4001 this.get('/LeftTree.view').highlight(false);
4007 xtype: Gtk.ListStore,
4010 XObject.prototype.init.call(this);
4011 this.el.set_column_types ( 2, [
4012 GObject.TYPE_STRING, // title
4013 GObject.TYPE_STRING // tip
4018 load : function(tr,iter)
4023 //console.log('Project tree load: ' + tr.length);
4024 var citer = new Gtk.TreeIter();
4025 //this.insert(citer,iter,0);
4026 for(var i =0 ; i < tr.length; i++) {
4029 this.el.append(citer);
4031 this.el.insert(citer,iter,-1);
4036 this.el.set_value(citer, 0, '' + r ); // title
4038 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4039 //if (r.cn && r.cn.length) {
4040 // this.load(r.cn, citer);
4046 getValue : function (iter, col) {
4047 var gval = new GObject.Value('');
4048 this.el.get_value(iter, col ,gval);
4055 xtype: Gtk.TreeViewColumn,
4056 pack : "append_column",
4058 XObject.prototype.init.call(this);
4059 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4063 xtype: Gtk.CellRendererText,
4085 XObject.cache['/Window'] = Window;