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..
346 if (!this.get('/Editor').save()) {
347 // popup!! - click handled..
351 if (!this.el.expanded) {
358 enter_notify_event : function (self, event) {
360 this.el.expanded = !this.el.expanded;
361 //if (this.el.expanded ) {
362 this.listeners.activate.call(this);
369 label : "Select Project or File",
370 pack : "pack_start,false,true",
372 XObject.prototype.init.call(this);
373 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
375 onCollapse : function() {
377 var nb = this.get('/LeftTopPanel.notebook');
378 nb.el.set_current_page(0);
380 onExpand : function() {
381 var nb = this.get('/LeftTopPanel.notebook');
382 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
385 var model = this.get('/LeftProjectTree.combomodel');
386 // print ("loading Projects?")
387 //console.dump(pm.projects);
388 model.loadData(pm.projects);
391 nb.el.set_current_page(1);
392 //pm.on('changed', function() {
393 //console.log("CAUGHT project manager change");
394 // _combo.model.loadData(pm.projects);
402 pack : "pack_start,true,true",
404 XObject.prototype.init.call(this);
405 this.el.set_current_page(0);
412 xtype: Gtk.ScrolledWindow,
415 getActiveElement : function() { // return path to actie node.
417 var path = this.getActivePath();
421 var iter = new Gtk.TreeIter();
422 this.get('model').el.get_iter_from_string(iter, path);
424 var value = new GObject.Value('');
425 this.get('model').el.get_value(iter, 2, value);
427 return JSON.parse(value.value);
429 getActiveFile : function() {
430 return this.get('model').file;
432 getActivePath : function() {
433 var model = this.get('model');
434 var view = this.get('view');
435 if (view.selection.count_selected_rows() < 1) {
438 var iter = new Gtk.TreeIter();
440 view.selection.get_selected(model.el, iter);
441 return model.el.get_path(iter).to_string();
443 getPaleteProvider : function() {
444 var model = this.get('model');
445 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
446 return pm.getPalete(model.file.getType());
448 getRenderer : function() {
450 switch( this.getActiveFile().getType()) {
452 return this.get('/RightBrowser.view');
454 return this.get('/RightGtkView');
459 XObject.prototype.init.call(this);
460 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
462 renderView : function() {
463 var render = this.getRenderer();
464 var model = this.get('model');
466 render.renderJS(model.toJS(false,true)[0]);
468 print("NO RENDER JS METHOD?");
471 shadow_type : Gtk.ShadowType.IN,
476 button_press_event : function (self, ev) {
477 console.log("button press?");
479 if (!this.get('/Editor').save()) {
480 // popup!! - click handled..
484 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
485 print("click" + ev.type);
491 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
493 if (!this.get('/LeftTreeMenu').el) { this.get('/LeftTreeMenu').init(); }
495 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
496 this.get('/LeftTreeMenu').el.show_all();
497 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
498 print("click:" + res.path.to_string());
501 drag_begin : function (self, drag_context) {
502 print('SOURCE: drag-begin');
503 this.targetData = false;
504 // find what is selected in our tree...
505 var iter = new Gtk.TreeIter();
506 var s = this.selection;
507 s.get_selected(this.get('/LeftTree.model').el, iter);
509 // set some properties of the tree for use by the dropped element.
510 var value = new GObject.Value('');
511 this.get('/LeftTree.model').el.get_value(iter, 2, value);
512 var data = JSON.parse(value.value);
513 var xname = this.get('/LeftTree.model').file.guessName(data);
515 this.el.dragData = xname;
516 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
519 // make the drag icon a picture of the node that was selected
520 var path = this.get('/LeftTree.model').el.get_path(iter);
521 this.el.treepath = path.to_string();
523 var pix = this.el.create_row_drag_icon ( path);
525 Gtk.drag_set_icon_pixmap (ctx,
534 drag_end : function (self, drag_context) {
535 Seed.print('LEFT-TREE: drag-end');
536 this.el.dragData = false;
537 this.el.dropList = false;
538 this.targetData = false;
539 this.get('/LeftTree.view').highlight(false);
542 drag_motion : function (self, ctx, x, y, time) {
543 console.log("LEFT-TREE: drag-motion");
544 var src = Gtk.drag_get_source_widget(ctx);
546 // a drag from elsewhere...- prevent drop..
548 print("no drag data!");
549 Gdk.drag_status(ctx, 0, time);
550 this.targetData = false;
553 var action = Gdk.DragAction.COPY;
554 if (src == this.el) {
555 // unless we are copying!!! ctl button..
556 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
560 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
561 // no children.. -- asume it's ok..
562 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
563 Gdk.drag_status(ctx, action ,time);
567 print("GETTING POS");
568 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
569 print("ISOVER? " + isOver);
571 Gdk.drag_status(ctx, 0 ,time);
572 return false; // not over apoint!?!
574 // drag node is parent of child..
575 console.log("SRC TREEPATH: " + src.treepath);
576 console.log("TARGET TREEPATH: " + data.path.to_string());
578 // nned to check a few here..
579 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
580 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
581 //Gtk.TreeViewDropPosition.AFTER
582 //Gtk.TreeViewDropPosition.BEFORE
584 if (typeof(src.treepath) != 'undefined' &&
585 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
586 print("subpath drag");
587 Gdk.drag_status(ctx, 0 ,time);
592 //print("DUMPING DATA");
593 //console.dump(data);
596 print(data.path.to_string() +' => '+ data.pos);
597 var tg = this.get('/LeftTree.model').findDropNodeByPath(
598 data.path.to_string(), src.dropList, data.pos);
600 this.get('/LeftTree.view').highlight(tg);
602 print("Can not find drop node path");
603 this.targetData = false;
604 Gdk.drag_status(ctx, 0, time);
608 this.targetData = tg;
611 Gdk.drag_status(ctx, action ,time);
615 drag_drop : function (w, ctx, x, y, time) {
616 Seed.print("TARGET: drag-drop");
620 w, /* will receive 'drag-data-received' signal */
621 ctx, /* represents the current state of the DnD */
622 this.get('/Window').atoms["STRING"], /* the target type we want */
623 time /* time stamp */
627 /* No target offered by source => error */
632 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
633 print("Tree: drag-data-received");
635 var delete_selection_data = false;
636 var dnd_success = false;
637 /* Deal with what we are given from source */
638 if( sel_data && sel_data.length ) {
640 if (ctx.action == Gdk.DragAction.ASK) {
641 /* Ask the user to move or copy, then set the ctx action. */
644 if (ctx.action == Gdk.DragAction.MOVE) {
645 //delete_selection_data = true;
648 var source = Gtk.drag_get_source_widget(ctx);
650 if (this.targetData) {
651 if (source != this.el) {
652 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
654 // drag around.. - reorder..
655 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
659 //Seed.print(this.targetData);
665 // we can send stuff to souce here...
671 if (dnd_success == false)
673 Seed.print ("DnD data transfer failed!\n");
676 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
679 cursor_changed : function (self) {
680 if (this.blockChanges) { // probably not needed..
683 var render = this.get('/LeftTree').getRenderer();
686 if (this.selection.count_selected_rows() < 1) {
687 this.get('/LeftPanel.model').load( false);
688 this.get('/MidPropTree').activeElement = false;
689 this.get('/MidPropTree').hideWin();
691 var pm = this.get('/RightPalete.model');
692 if (!this.get('/LeftTree').getPaleteProvider()) {
693 // it may not be loaded yet..
696 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
697 this.get('/LeftTree.model').listAllTypes()));
698 if (render && render.redraw) {
704 //console.log('changed');
705 var s = this.selection;
706 var iter = new Gtk.TreeIter();
707 s.get_selected(this.get('/LeftTree.model').el, iter);
711 var value = new GObject.Value('');
712 this.get('/LeftTree.model').el.get_value(iter, 2, value);
713 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
715 var data = JSON.parse(value.value);
716 this.get('/MidPropTree').activeElement = data;
717 this.get('/MidPropTree').hideWin();
718 this.get('/LeftPanel.model').load( data);
720 console.log(value.value);
721 // _g.button.set_label(''+value.get_string());
723 var pm =this.get('/RightPalete.model');
724 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
725 this.get('/LeftTree.model').listAllTypes()));
728 if (render && render.redraw) {
732 //Seed.print( value.get_string());
740 enable_tree_lines : true,
741 headers_visible : false,
742 highlight : function(treepath_ar) {
744 // highlighting for drag/drop
745 if (treepath_ar.length && treepath_ar[0].length ) {
746 this.el.set_drag_dest_row(
747 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
749 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
754 XObject.prototype.init.call(this);
755 var description = new Pango.FontDescription.c_new();
756 description.set_size(8000);
757 this.el.modify_font(description);
759 this.selection = this.el.get_selection();
760 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
763 // is this really needed??
764 this.selection.signal['changed'].connect(function() {
765 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
766 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
770 Gtk.drag_source_set (
771 this.el, /* widget will be drag-able */
772 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
773 null, /* lists of target to support */
774 0, /* size of list */
775 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
778 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
780 Gtk.drag_source_add_text_targets(this.el);
783 this.el, /* widget that will accept a drop */
784 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
785 null, /* lists of target to support */
786 0, /* size of list */
787 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
790 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
791 Gtk.drag_dest_add_text_targets(this.el);
793 selectNode : function(treepath_str) {
794 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
795 var tp = new Gtk.TreePath.from_string(treepath_str);
796 this.el.set_cursor(tp, null, false);
797 this.el.scroll_to_cell(tp, null, false, 0,0);
801 xtype: Gtk.TreeStore,
806 changed : function(n, refresh) {
807 // print("MODEL CHANGED CALLED" + this.activePath);
808 if (this.activePath) {
809 var iter = new Gtk.TreeIter();
810 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
811 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
812 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
814 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
816 //this.currentTree = this.toJS(false, true)[0];
818 this.file.items = this.toJS(false, false);
819 print ("TO JS in " + ((new Date()) - d) + "ms");
820 // print("AFTER CHANGED");
821 //console.dump(this.file.items);
823 this.currentTree = this.file.items[0];
824 //console.log(this.file.toSource());
827 print("REDNER BROWSER?!");
828 this.get('/LeftTree').renderView();
830 var pm = this.get('/RightPalete.model');
831 if (!this.get('/RightPalete').provider) {
837 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
838 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
842 deleteSelected : function() {
843 this.get('/LeftTree.view').blockChanges = true;
844 var old_iter = new Gtk.TreeIter();
845 var s = this.get('/LeftTree.view').selection;
846 s.get_selected(this.el, old_iter);
847 var path = this.el.get_path(old_iter).to_string();
849 this.activePath= false;
852 this.activePath= false;
853 var iter = new Gtk.TreeIter();
854 this.el.get_iter_from_string(iter, path);
855 this.el.remove(iter);
857 // rebuild treemap. -- depreciated.!!
860 //this.toJS(null, true) // does not do anything?
861 this.activePath= false;
862 this.changed(false,true);
863 this.get('/LeftTree.view').blockChanges = false;
865 dropNode : function(target_data, node) {
867 // console.dump(node);
868 // console.dump(target_data);
869 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
871 print("add " + tp + "@" + target_data[1] );
874 if (tp && target_data[1] < 2) { // before or after..
875 var ar = target_data[0].split(':');
877 parent = new Gtk.TreePath.from_string( ar.join(':') );
880 var n_iter = new Gtk.TreeIter();
881 var iter_par = new Gtk.TreeIter();
882 var iter_after = after ? new Gtk.TreeIter() : false;
886 if (parent !== false) {
887 this.el.get_iter(iter_par, parent);
894 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
895 this.el.get_iter(iter_after, after);
896 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
897 n_iter, iter_par, iter_after);
900 this.el.append(n_iter, iter_par);
904 if (typeof(node) == 'string') {
905 var ar = node.split('.');
906 var xtype = ar.pop();
909 '|xns' : ar.join('.'),
912 if (target_data.length == 3 && target_data[2].length) {
913 node['*prop'] = target_data[2];
915 node = this.get('/DialogTemplateSelect').show(node);
918 // work out what kind of packing to use..
919 if (typeof(node.pack) == 'undefined' && parent !== false) {
920 var pal = this.get('/LeftTree').getPaleteProvider();
921 if (pal.name == 'Gtk') {
922 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
923 var cname = pal.guessName(node);
924 node.pack = pal.getDefaultPack(pname, cname);
935 // load children - if it has any..
938 this.load(xitems, n_iter);
939 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
941 if (tp && (xitems || after)) {
942 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
944 // wee need to get the empty proptypes from somewhere..
946 //var olditer = this.activeIter;
947 this.activePath = this.el.get_path(n_iter).to_string();
949 // changed actually set's the node data..
950 this.changed(node, true);
954 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
956 //Builder.MidPropTree._model.load(node);
957 //Builder.MidPropTree._win.hideWin();
958 //Builder.LeftPanel._model.load( node);
962 findDropNode : function(treepath_str, targets) {
964 // this is used by the dragdrop code in the roo version AFAIR..
966 var path = treepath_str.replace(/^builder-/, '');
967 // treemap is depreciated... - should really check if model has any entries..
969 if (!this.el.iter_n_children(null)) {
971 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
973 print("FIND treepath: " + path);
974 //console.dump(this.treemap);
976 if (!treepath_str.match(/^builder-/)) {
977 return []; // nothing!
979 if (targets === true) {
982 return this.findDropNodeByPath(path,targets)
984 findDropNodeByPath : function(treepath_str, targets, pref) {
985 var path = treepath_str + ''; // dupe it..
986 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
988 //console.dump(this.treemap);
989 while (path.length) {
990 print("LOOKING FOR PATH: " + path);
991 var node_data = this.singleNodeToJS(path);
992 if (node_data === false) {
993 print("node not found");
997 var xname = this.get('/LeftTree.model').file.guessName(node_data);
1000 targets.forEach(function(tg) {
1004 if ((tg == xname) ) {
1007 if (tg.indexOf(xname +':') === 0) {
1009 prop = tg.split(':').pop();
1014 if (last) { // pref is after/before..
1015 // then it's after last
1017 return []; // do not allow..
1019 return [ last, pref , prop];
1022 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1024 var par = path.split(':');
1027 path = par.join(':');
1033 getIterValue : function (iter, col) {
1034 var gval = new GObject.Value('');
1035 this.el.get_value(iter, col ,gval);
1041 XObject.prototype.init.call(this);
1042 this.el.set_column_types ( 3, [
1043 GObject.TYPE_STRING, // title
1044 GObject.TYPE_STRING, // tip
1045 GObject.TYPE_STRING // source..
1048 listAllTypes : function() {
1049 var s = this.get('/LeftTree.view').selection;
1050 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1052 if (s.count_selected_rows() > 0) {
1053 var iter = new Gtk.TreeIter();
1054 s.get_selected(this.el, iter);
1056 // set some properties of the tree for use by the dropped element.
1057 var value = new GObject.Value('');
1058 this.el.get_value(iter, 2, value);
1059 var data = JSON.parse(value.value);
1062 var xname = this.get('/LeftTree.model').file.guessName(data);
1063 console.log('selected:' + xname);
1067 return []; // could not find it..
1075 li.forEach(function(el) {
1076 // this is specific to roo!!!?
1077 if (!el) { // skip empty?
1080 var fullpath = _this.file.guessName(el);
1081 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1086 if (el.items && el.items.length) {
1095 addall([this.currentTree]);
1097 // only if we have nothing, should we add '*top'
1101 //console.log('all types in tree');
1102 //console.dump(ret);
1107 load : function(tr,iter)
1109 var citer = new Gtk.TreeIter();
1110 //this.insert(citer,iter,0);
1111 for(var i =0 ; i < tr.length; i++) {
1113 this.el.insert(citer,iter,-1);
1115 this.el.append(citer);
1118 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1119 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1120 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1121 if (tr[i].items && tr[i].items.length) {
1122 this.load(tr[i].items, citer);
1126 loadFile : function(f) {
1132 console.log('missing file');
1136 // load the file if not loaded..
1137 if (f.items === false) {
1139 f.loadItems(function() {
1145 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1147 if (f.items.length && typeof(f.items[0]) == 'string') {
1149 //this.get('/RightEditor').el.show();
1150 //this.get('/RightEditor.view').load( f.items[0]);
1154 print(JSON.stringify(f.items, null,4));
1155 //console.dump(f.items);
1157 this.get('/LeftTree.view').el.expand_all();
1159 if (!f.items.length) {
1162 this.get('/Window.leftvpaned').el.set_position(80);
1164 this.get('/LeftTree.view').el.set_cursor(
1165 new Gtk.TreePath.from_string('0'), null, false);
1169 this.get('/Window.leftvpaned').el.set_position(200);
1173 //print("hide right editior");
1174 //this.get('/RightEditor').el.hide();
1175 this.get('/Editor').el.hide();
1176 //print("set current tree");
1177 this.currentTree = this.toJS(false, false)[0];
1178 //console.dump(this.currentTree);
1179 this.currentTree = this.currentTree || { items: [] };
1180 this.get('/LeftTree').renderView();
1181 //console.dump(this.map);
1182 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1183 var pm = this.get('/RightPalete.model');
1184 // set up provider..
1186 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1188 if (!this.get('/RightPalete').provider) {
1189 print ("********* PALETE PROVIDER MISSING?!!");
1191 this.get('/LeftTree').renderView();
1193 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1197 this.get('/Window.view-notebook').el.set_current_page(
1198 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1201 moveNode : function(target_data, action) {
1202 //print("MOVE NODE");
1203 // console.dump(target_data);
1204 var old_iter = new Gtk.TreeIter();
1205 var s = this.get('/LeftTree.view').selection;
1206 s.get_selected(this.el, old_iter);
1207 var node = this.nodeToJS(old_iter,false);
1208 //console.dump(node);
1211 // needs to drop first, otherwise the target_data
1212 // treepath will be invalid.
1214 this.dropNode(target_data, node);
1215 if (action & Gdk.DragAction.MOVE) {
1216 // print("REMOVING OLD NODE");
1217 this.el.remove(old_iter);
1221 this.activePath= false;
1222 this.changed(false,true);
1224 nodeTip : function(c) {
1225 var ret = this.nodeTitle(c,true);
1231 if (!i.length || i[0] != '|') {
1237 if (typeof(c[i]) != 'string') {
1240 //print("prop : " + i + ':' + c[i]);
1241 if (!c[i].match(new RegExp('function'))) {
1244 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1248 ret+="\n\nMethods:" + funcs;
1253 nodeTitle : function(c, renderfull) {
1256 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1257 if (sr) txt.push('<s>');
1258 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1260 if (renderfull && c['|xns']) {
1261 txt.push(c['|xns']);
1264 if (c.xtype) { txt.push(c.xtype); }
1265 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1266 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1267 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1270 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1271 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1272 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1273 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1274 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1275 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1276 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1277 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1278 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1280 // for flat classes...
1281 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1282 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1285 if (sr) txt.push('</s>');
1286 return (txt.length == 0 ? "Element" : txt.join(" "));
1288 nodeToJS : function (treepath, with_id)
1291 var iter = treepath; // API used to be iter here..
1292 if (typeof(iter) == 'string') {
1293 iter = new Gtk.TreeIter();
1294 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1298 var par = new Gtk.TreeIter();
1299 var iv = this.getIterValue(iter, 2);
1300 // print("IV" + iv);
1301 var k = JSON.parse(iv);
1302 if (k.json && !this.el.iter_parent( par, iter )) {
1307 var treepath_str = this.el.get_path(iter).to_string();
1308 // not sure how we can handle mixed id stuff..
1309 if (typeof(k.id) == 'undefined') {
1310 k.id = 'builder-'+ treepath_str ;
1314 this.treemap[ treepath_str ] = k;
1315 k.xtreepath = treepath_str ;
1318 if (this.el.iter_has_child(iter)) {
1319 citer = new Gtk.TreeIter();
1320 this.el.iter_children(citer, iter);
1321 k.items = this.toJS(citer,with_id);
1325 nodeToJSON : function(c) {
1333 return JSON.stringify(o);
1335 singleNodeToJS : function (treepath)
1337 var iter = new Gtk.TreeIter();
1338 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1342 var iv = this.getIterValue(iter, 2);
1344 return JSON.parse(iv);
1347 toJS : function(treepath, with_id)
1349 //Seed.print("WITHID: "+ with_id);
1350 var iter = treepath; // API used to be iter here..
1351 if (typeof(iter) == 'string') {
1352 iter = new Gtk.TreeIter();
1353 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1362 iter = new Gtk.TreeIter();
1363 if (!this.el.get_iter_first(iter)) {
1373 var k = this.nodeToJS(iter, with_id);
1377 if (!this.el.iter_next(iter)) {
1382 if (treepath === false) {
1384 return JSON.parse(JSON.stringify(ar));
1388 // convert the list into a json string..
1394 xtype: Gtk.TreeViewColumn,
1395 pack : "append_column",
1397 XObject.prototype.init.call(this);
1398 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1402 xtype: Gtk.CellRendererText,
1412 id : "LeftTreeMenu",
1415 xtype: Gtk.MenuItem,
1417 label : "Delete Element",
1419 activate : function (self) {
1421 this.get('/LeftTree.model').deleteSelected();
1426 xtype: Gtk.MenuItem,
1428 activate : function (self) {
1430 var tree = this.get('/LeftTree');
1431 var model = this.get('/LeftTree.model');
1432 var el = tree.getActivePath();
1434 var js = model.toJS(el, false);
1435 // print(JSON.stringify(js[0], null,4));
1436 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1441 label : "Save as Template",
1451 id : "LeftProjectTree",
1452 showNoProjectSelected : function() {
1453 this.get('/StandardErrorDialog').show("Select a Project first.");
1455 getActiveProject : function() {
1456 return this.project;
1459 leave_notify_event : function (self, event) {
1466 pack : "pack_start,false,false",
1469 xtype: Gtk.ComboBox,
1472 XObject.prototype.init.call(this);
1473 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1475 getValue : function() {
1476 var ix = this.el.get_active();
1480 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1481 if (typeof(data[ix]) == 'undefined') {
1486 setValue : function(fn)
1490 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1491 data.forEach(function(n, ix) {
1499 changed : function (self) {
1500 var fn = this.getValue();
1501 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1502 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1507 xtype: Gtk.CellRendererText,
1508 pack : "pack_start,true",
1512 xtype: Gtk.ListStore,
1515 XObject.prototype.init.call(this);
1516 this.el.set_column_types ( 2, [
1517 GObject.TYPE_STRING, // real key
1518 GObject.TYPE_STRING // real type
1522 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1524 pm.on('changed', function() {
1525 print("caught changed hook on project manager - reloading data");
1526 _this.loadData(pm.projects);
1530 loadData : function(data) {
1531 var ov = this.get('/LeftProjectTree.combo').getValue();
1533 var iter = new Gtk.TreeIter();
1535 data.forEach(function(p) {
1540 el.set_value(iter, 0, p.fn);
1541 el.set_value(iter, 1, p.name);
1545 this.get('/LeftProjectTree.combo').setValue(ov);
1554 xtype: Gtk.ScrolledWindow,
1556 shadow_type : Gtk.ShadowType.IN,
1558 XObject.prototype.init.call(this);
1559 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1563 xtype: Gtk.TreeView,
1565 cursor_changed : function (self) {
1566 var iter = new Gtk.TreeIter();
1568 if (this.selection.count_selected_rows() < 1) {
1569 //XN.get('Builder.LeftTree.model').
1570 this.get('/LeftTree.model').load( false);
1574 var model = this.get('/LeftProjectTree.model');
1575 //console.log('changed');
1576 var s = this.selection;
1577 s.get_selected(model, iter);
1578 value = new GObject.Value('');
1579 model.el.get_value(iter, 2, value);
1581 console.log(value.value);// id..
1583 var file = this.get('/LeftProjectTree').project.getById(value.value);
1590 var nb = this.get('/LeftTopPanel.expander');
1591 nb.el.expanded = false;
1593 //nb.listeners.activate.call(nb);
1594 //_expander.el.set_expanded(false);
1596 var ltm = this.get('/LeftTree.model');
1604 enable_tree_lines : true,
1605 headers_visible : false,
1607 XObject.prototype.init.call(this);
1608 var description = new Pango.FontDescription.c_new();
1609 description.set_size(8000);
1610 this.el.modify_font(description);
1612 this.selection = this.el.get_selection();
1613 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1617 xtype: Gtk.TreeStore,
1621 XObject.prototype.init.call(this);
1622 this.el.set_column_types ( 3, [
1623 GObject.TYPE_STRING, // title
1624 GObject.TYPE_STRING, // tip
1625 GObject.TYPE_STRING // id..
1629 loadProject : function(pr) {
1630 print("LOAD PROJECT");
1636 this.get('/LeftProjectTree').project = pr;
1637 this.load(pr.toTree());
1638 this.get('/LeftProjectTree.view').el.expand_all();
1640 load : function(tr,iter) {
1641 // console.dump(tr);
1642 console.log('Project tree load: ' + tr.length);
1643 var citer = new Gtk.TreeIter();
1644 //this.insert(citer,iter,0);
1647 tr.forEach(function (r) {
1649 _this.el.append(citer);
1651 _this.el.insert(citer,iter,-1);
1653 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1654 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1655 _this.el.set_value(citer, 2, '' + r.id ); //id
1656 if (r.cn && r.cn.length) {
1657 _this.load(r.cn, citer);
1662 getValue : function(iter, col) {
1663 var gval = new GObject.Value('');
1664 this.el.get_value(iter, col ,gval);
1665 return '' + gval.value;
1669 xtype: Gtk.TreeViewColumn,
1670 pack : "append_column",
1672 XObject.prototype.init.call(this);
1673 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1677 xtype: Gtk.CellRendererText,
1697 pack : "pack_start,false,true,0",
1704 button_press_event : function (self, event) {
1705 this.get('/MidPropTree.model').showData('props');
1717 stock : Gtk.STOCK_ADD,
1718 icon_size : Gtk.IconSize.MENU
1732 button_press_event : function (self, event) {
1734 if (!this.get('/Editor').save()) {
1735 // popup!! - click handled..
1738 this.get('/MidPropTree.model').showData('events');
1751 stock : Gtk.STOCK_ADD,
1752 icon_size : Gtk.IconSize.MENU
1766 button_press_event : function (self, ev) {
1768 if (!this.get('/Editor').save()) {
1769 // popup!! - click handled..
1773 var p = this.get('/AddPropertyPopup');
1777 p.el.set_screen(Gdk.Screen.get_default());
1779 p.el.popup(null, null, null, null, 3, ev.button.time);
1792 stock : Gtk.STOCK_ADD,
1793 icon_size : Gtk.IconSize.MENU
1805 id : "AddPropertyPopup",
1808 xtype: Gtk.MenuItem,
1810 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1813 activate : function (self) {
1815 this.get('/LeftPanel.model').add( {
1826 xtype: Gtk.MenuItem,
1828 tooltip_markup : "Add what type of packing is to be used",
1831 activate : function (self) {
1833 this.get('/LeftPanel.model').add( {
1843 xtype: Gtk.MenuItem,
1845 tooltip_markup : "Override the init method",
1848 activate : function (self) {
1850 this.get('/LeftPanel.model').add( {
1853 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1860 xtype: Gtk.SeparatorMenuItem,
1864 xtype: Gtk.MenuItem,
1866 tooltip_markup : "Add a user defined string property",
1869 activate : function (self) {
1871 this.get('/LeftPanel.model').add( {
1881 xtype: Gtk.MenuItem,
1883 tooltip_markup : "Add a user defined number property",
1886 activate : function (self) {
1888 this.get('/LeftPanel.model').add( {
1898 xtype: Gtk.MenuItem,
1900 tooltip_markup : "Add a user defined boolean property",
1903 activate : function (self) {
1905 this.get('/LeftPanel.model').add( {
1915 xtype: Gtk.SeparatorMenuItem,
1919 xtype: Gtk.MenuItem,
1921 tooltip_markup : "Add a user function boolean property",
1924 activate : function (self) {
1926 this.get('/LeftPanel.model').add( {
1929 val : "function() {\n \n}\n",
1942 xtype: Gtk.ScrolledWindow,
1947 XObject.prototype.init.call(this);
1948 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1950 shadow_type : Gtk.ShadowType.IN,
1953 xtype: Gtk.TreeView,
1955 button_press_event : function (self, ev) {
1958 if (!this.get('/Editor').save()) {
1959 // popup!! - click handled..
1964 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1965 return false; //not on a element.
1969 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
1971 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
1974 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1975 var p = this.get('/LeftPanelPopup');
1980 p.el.set_screen(Gdk.Screen.get_default());
1982 p.el.popup(null, null, null, null, 3, ev.button.time);
1983 //Seed.print("click:" + res.column.title);
1990 if (res.column.title != 'value') {
1991 // XObject.error("column is not value?");
1992 return false; // ignore.. - key click.. ??? should we do this??
1995 // currently editing???
1996 // if ( this.activePath) {
1998 // this.activePath = false;
2000 if (this.get('/Editor').dirty) {
2001 //if (!this.get('/Editor.buffer').checkSyntax()) {
2002 // this.get('/StandardErrorDialog').show("Fix errors in code and save..");
2006 if (!this.get('/Editor.view').save()) {
2010 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
2011 this.get('/LeftPanel').editing = false;
2013 // XObject.error("Currently editing?");
2017 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
2019 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
2021 // get options for this type -- this is to support option lists etc..
2022 var provider = this.get('/LeftTree').getPaleteProvider();
2023 var opts = provider.findOptions(type);
2025 if (opts === false) {
2027 this.get('/LeftPanel').editableColumn.setOptions([]);
2028 renderer.has_entry = true;
2030 this.get('/LeftPanel').editableColumn.setOptions(opts);
2031 renderer.has_entry = false;
2033 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
2035 //Seed.print("click" + ev.type);
2036 //console.dump(res);
2045 enable_tree_lines : true,
2046 headers_visible : false,
2048 XObject.prototype.init.call(this);
2050 this.selection = this.el.get_selection();
2051 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2054 var description = new Pango.FontDescription.c_new();
2055 description.set_size(8000);
2056 this.el.modify_font(description);
2060 xtype: Gtk.TreeStore,
2064 add : function(info) {
2065 // info includes key, val, skel, etype..
2067 type = info.type.toLowerCase();
2068 var data = this.toJS();
2070 if (info.etype == 'events') {
2071 data.listeners = data.listeners || { };
2072 if (typeof(data.listeners[info.key]) != 'undefined') {
2073 return; //already set!
2076 if (typeof(data[info.key]) != 'undefined') {
2081 if (typeof(info.val) == 'undefined') {
2084 if (info.type.toLowerCase() == 'boolean') {
2087 if (type == 'number') {
2095 if (info.etype == 'events') {
2097 data.listeners[info.key] = info.val;
2100 data[info.key] = info.val;
2104 var map = this.load(data);
2106 // flag it as changed to the interface..
2108 this.get('/LeftTree.model').changed(data, true);
2111 this.startEditing(map[k]);
2114 LeftPanel.get('view').el.row_activated(
2115 new Gtk.TreePath.from_string(map[k]),
2116 LeftPanel.editableColumn.el
2120 changed : function(str, doRefresh) {
2121 if (!this.activePath) {
2124 var iter = new Gtk.TreeIter();
2125 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2127 this.el.set_value(iter, 1, '' +str);
2128 this.el.set_value(iter, 3, '' + this.toShort(str));
2129 var type = this.getIterValue(iter, 4);
2131 this.el.set_value(iter, 5, type + ' : ' + str);
2132 // update the tree...
2134 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2136 deleteSelected : function() {
2137 var data = this.toJS();
2138 var iter = new Gtk.TreeIter();
2139 var s = this.get('/LeftPanel.view').selection;
2140 s.get_selected(this.el, iter);
2143 var gval = new GObject.Value('');
2144 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2146 var val = gval.value;
2147 if (val[0] == '!') {
2149 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2152 delete data.listeners[ val.substring(1)];
2153 if (!XObject.keys(data.listeners).length) {
2154 delete data.listeners;
2158 if (typeof(data[val]) == 'undefined') {
2166 this.get('/LeftTree.model').changed(data, true);
2169 getIterValue : function(iter, col) {
2170 var gval = new GObject.Value('');
2171 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2172 return '' + gval.value;
2174 getType : function(treepath) {
2175 return this.getValue(treepath, 4);
2177 getValue : function(treepath_str, col)
2179 // get's the value in a row.. - keys - returns string, values - formats it..
2181 var iter = new Gtk.TreeIter();
2182 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2184 var gval = new GObject.Value('');
2185 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2186 var val = '' + gval.value;
2191 var type = this.getType(this.el.get_path(iter).to_string());
2192 //print("TYPE: " +type + " - val:" + val);
2193 switch(type.toLowerCase()) {
2197 return parseFloat(val); // Nan ?? invalid!!?
2200 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2202 return val == 'true' ? true : false;
2204 var nv = parseFloat(val);
2205 if (!isNaN(nv) && (val == ''+nv)) {
2213 XObject.prototype.init.call(this);
2214 this.el.set_column_types ( 6, [
2215 GObject.TYPE_STRING, // 0 real key
2216 GObject.TYPE_STRING, // 1 real value
2217 GObject.TYPE_STRING, // 2 visable key
2218 GObject.TYPE_STRING, // 3 visable value
2219 GObject.TYPE_STRING, // 4 need to store type of!!!
2220 GObject.TYPE_STRING // 5 tooltip
2224 load : function(ar) {
2225 // might casue problesm..
2226 // this.get('/Editor.RightEditor').save();
2228 this.get('/Editor').el.hide();
2229 this.get('/Editor').activePath = false;
2234 //this.get('/RightEditor').el.hide();
2241 var provider = this.get('/LeftTree').getPaleteProvider();
2242 var iter = new Gtk.TreeIter();
2245 var keys = XObject.keys(ar);
2247 ar.listeners = ar.listeners || {};
2249 for (var i in ar.listeners ) {
2250 this.el.append(iter);
2251 var p = this.el.get_path(iter).to_string();
2254 this.el.set_value(iter, 0, '!'+ i );
2255 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2256 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2258 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2259 this.el.set_value(iter, 4, 'function');
2260 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2266 keys.forEach(function(i) {
2267 if (typeof(ar[i]) == 'object') {
2271 var type = provider.findType(ar, i, ar[i]);
2273 _this.el.append(iter);
2274 var p = _this.el.get_path(iter).to_string();
2276 _this.el.set_value(iter, 0, ''+i);
2277 _this.el.set_value(iter, 1, '' + ar[i]);
2278 _this.el.set_value(iter, 2, ''+i);
2279 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2280 _this.el.set_value(iter, 4, ''+type);
2281 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2285 startEditing : function(path,col) {
2287 // alled by menu 'edit' currently..
2289 * start editing path (or selected if not set..)
2290 * @param {String|false} path (optional) treepath to edit - selected tree gets
2291 * edited by default.
2292 * @param {Number} 0 or 1 (optional)- column to edit.
2294 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2296 if (typeof(path) == 'string') {
2297 tp = new Gtk.TreePath.from_string(path);
2299 var iter = new Gtk.TreeIter();
2300 var s = this.get('/LeftPanel.view').selection;
2301 s.get_selected(this.el, iter);
2302 tp = this.el.get_path(iter);
2303 path = tp.to_string();
2307 // which colum is to be edited..
2310 // not sure what this does..
2312 if (typeof(col) == 'undefined') {
2313 var k = this.getValue(path, 0);
2315 colObj = (!k.length || k == '|') ?
2316 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2318 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2321 // make sure the pulldown is set correctly..
2322 // not really needed for second col...
2323 var showEditor = false;
2324 this.get('/Editor').activePath = false;
2325 this.get('/Editor').el.hide();
2328 var provider = this.get('/LeftTree').getPaleteProvider();
2329 var type = this.get('/LeftPanel.model').getType(path);
2330 var opts = provider.findOptions(type);
2331 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2333 if (opts === false) {
2334 this.get('/LeftPanel').editableColumn.setOptions([]);
2335 renderer.has_entry = true;
2337 this.get('/LeftPanel').editableColumn.setOptions(opts);
2338 renderer.has_entry = false;/// - pulldowns do not have entries
2340 // determine if we should use the Text editor...
2341 var keyname = this.getValue(path, 0);
2342 var data_value = this.getValue(path, 1);
2344 if ((keyname[0] == '|') ||
2346 (typeof(data_value) == 'string' ) &&
2347 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2351 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2356 // this.get('/BottomPane').el.hide();
2357 //this.get('/RightEditor').el.hide();
2362 this.activePath = false;
2364 _this.get('/Editor').el.show_all();
2365 GLib.timeout_add(0, 1, function() {
2367 //_this.get('/BottomPane').el.show();
2368 //_this.get('/RightEditor').el.show();
2370 _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
2372 _this.get('/Editor').activePath = path;
2373 _this.activePath = path ;
2383 // iter now has row...
2384 GLib.timeout_add(0, 100, function() {
2385 _this.activePath = path;
2386 colObj.items[0].el.editable = true; // esp. need for col 0..
2387 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2397 var iter = new Gtk.TreeIter();
2398 this.get('/LeftPanel.model').el.get_iter_first(iter);
2403 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2406 ar.listeners = ar.listeners || {};
2407 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2410 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2413 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2419 //print(JSON.stringify(ar));
2423 toShort : function(str) {
2424 var a = typeof(str) == 'string' ? str.split("\n") : [];
2425 return a.length > 1 ? a[0] + '....' : '' + str;
2429 xtype: Gtk.TreeViewColumn,
2430 pack : "append_column",
2432 XObject.prototype.init.call(this);
2434 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2435 this.get('/LeftPanel').propertyColumn = this;
2440 xtype: Gtk.CellRendererText,
2441 pack : "pack_start",
2443 editing_started : function (self, editable, path) {
2445 this.get('/LeftPanel.model').activePath = path;
2448 edited : function (self, object, p0) {
2449 var model = this.get('/LeftPanel.model');
2450 var path = model.activePath;
2451 var iter = new Gtk.TreeIter();
2452 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2453 model.el.set_value(iter, 0, p0);
2454 model.el.set_value(iter, 2, p0);
2456 model.activePath = false;
2458 this.get('/LeftTree.model').changed(model.toJS(), true);
2459 this.el.editable = false;
2466 xtype: Gtk.TreeViewColumn,
2467 pack : "append_column",
2470 XObject.prototype.init.call(this);
2471 this.el.add_attribute(this.items[0].el , 'text', 3 );
2472 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2473 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2474 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2476 this.get('/LeftPanel').editableColumn= this;
2478 setOptions : function(ar) {
2479 var m = this.items[0].el.model;
2481 var iter = new Gtk.TreeIter();
2482 ar.forEach(function(i) {
2485 m.set_value(iter, 0, i);
2491 xtype: Gtk.CellRendererCombo,
2493 edited : function (self, object, p0) {
2494 this.get('/LeftPanel').editing = false;
2495 var ap = this.get('/LeftPanel.model').activePath
2496 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2497 this.get('/LeftPanel.model').changed(p0, true);
2498 this.get('/LeftPanel.model').activePath = false;
2499 this.el.editable = false;
2501 editing_started : function (self, editable, path) {
2502 this.get('/LeftPanel').editing = true;
2503 // console.log('editing started');
2504 // r.has_entry = false;
2506 this.el.editable = false; // make sure it's not editor...
2511 pack : "pack_start",
2515 XObject.prototype.init.call(this);
2516 this.el.model = new Gtk.ListStore();
2517 this.el.model.set_column_types ( 1, [
2518 GObject.TYPE_STRING // 0 real key
2529 id : "LeftPanelPopup",
2532 xtype: Gtk.MenuItem,
2536 activate : function (self) {
2537 this.get('/LeftPanel.model').deleteSelected();
2542 xtype: Gtk.MenuItem,
2546 activate : function (self) {
2547 this.get('/LeftPanel.model').startEditing(false, 0);
2560 xtype: Gtk.ScrolledWindow,
2561 pack : "pack_end,false,true,0",
2563 shadow_type : Gtk.ShadowType.IN,
2565 XObject.prototype.init.call(this);
2566 XObject.prototype.init.call(this);
2567 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2568 this.el.set_size_request ( 150, -1 );
2571 activeElement : false,
2572 hideWin : function() {
2579 if (this.get('/Window.left').el.position < 160) {
2582 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2589 xtype: Gtk.TreeView,
2591 cursor_changed : function (self) {
2592 var iter = new Gtk.TreeIter();
2594 //console.log('changed');
2595 var m = this.get('model');
2596 if (!this.selection){
2597 this.selection = this.el.get_selection();
2600 var s = this.selection;
2601 if (!s.get_selected(m.el, iter)) {
2604 var tp = m.el.get_path(iter).to_string();
2609 var key = m.getValue(tp, 0);
2611 var type = m.getValue(tp, 1);
2612 var skel = m.getValue(tp, 3);
2613 var etype = m.getValue(tp, 5);
2616 this.get('/MidPropTree').hideWin();
2618 if (type.toLowerCase() == 'function') {
2620 if (etype != 'events') {
2624 this.get('/LeftPanel.model').add({
2632 // has dot in name, and is boolean???? this does not make sense..
2633 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2637 this.get('/LeftPanel.model').add( {
2647 enable_tree_lines : true,
2648 headers_visible : false,
2650 XObject.prototype.init.call(this);
2652 var description = new Pango.FontDescription.c_new();
2653 description.set_size(8000);
2654 this.el.modify_font(description);
2656 //this.selection = this.el.get_selection();
2657 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2666 xtype: Gtk.ListStore,
2669 getValue : function(treepath, col)
2671 var tp = new Gtk.TreePath.from_string (treepath);
2672 var iter = new Gtk.TreeIter();
2673 this.el.get_iter (iter, tp);
2674 var value = new GObject.Value('');
2675 this.el.get_value(iter, col, value);
2680 XObject.prototype.init.call(this);
2681 this.el.set_column_types ( 6, [
2682 GObject.TYPE_STRING, // real key
2683 GObject.TYPE_STRING, // real type
2684 GObject.TYPE_STRING, // docs ?
2685 GObject.TYPE_STRING, // visable desc
2686 GObject.TYPE_STRING, // function desc
2687 GObject.TYPE_STRING // element type (event|prop)
2691 showData : function(type) {
2693 if (!this.get('/MidPropTree').activeElement || !type) {
2694 return; // no active element
2697 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2698 var palete = this.get('/LeftTree').getPaleteProvider();
2702 Seed.print('Showing right?');
2703 if (!this.get('/MidPropTree').shown) {
2705 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2706 this.get('/MidPropTree').el.show();
2707 this.get('/MidPropTree').shown = true;
2710 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2711 return a.name > b.name ? 1 : -1;
2713 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2714 // console.dump(elementList);
2717 var iter = new Gtk.TreeIter();
2718 for(var i =0 ; i < elementList.length; i++) {
2719 var p=elementList[i];
2720 this.el.append(iter);
2721 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2722 //GObject.TYPE_STRING, // real key
2723 // GObject.TYPE_STRING, // real type
2724 // GObject.TYPE_STRING, // docs ?
2725 // GObject.TYPE_STRING // func def?
2728 this.el.set_value(iter, 0, p.name);
2729 this.el.set_value(iter, 1, p.type);
2730 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2731 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2732 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2733 this.el.set_value(iter, 5, type);
2740 xtype: Gtk.TreeViewColumn,
2742 this.el = new Gtk.TreeViewColumn();
2743 this.parent.el.append_column(this.el);
2745 XObject.prototype.init.call(this);
2746 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2751 xtype: Gtk.CellRendererText,
2752 pack : "pack_start,true"
2776 xtype: Gtk.Notebook,
2777 pack : "pack_start,true,true",
2778 id : "view-help-nb",
2780 XObject.prototype.init.call(this);
2781 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2782 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2786 xtype: Gtk.Notebook,
2787 id : "view-notebook",
2791 XObject.prototype.init.call(this);
2792 this.el.set_current_page(0);
2793 //print("SET LABEL?")
2794 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2795 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2801 id : "RightBrowser",
2806 pack : "pack_start,false,true,0",
2811 clicked : function (self) {
2812 this.get('/RightBrowser.view').renderJS(null,true);
2816 pack : "pack_start,false,false,0"
2819 xtype: Gtk.CheckButton,
2821 toggled : function (self, state) {
2822 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2827 label : "Auto Redraw On",
2828 pack : "pack_start,false,false,0"
2833 clicked : function (self) {
2834 this.get('/RightBrowser.view').redraws = 99;
2835 this.get('/RightBrowser.view').renderJS(null,true);
2838 label : "Full Redraw",
2839 pack : "pack_start,false,false,0"
2844 xtype: Gtk.ScrolledWindow,
2847 XObject.prototype.init.call(this);
2848 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2850 shadow_type : Gtk.ShadowType.IN,
2853 xtype: WebKit.WebView,
2855 load_finished : function (self, object) {
2856 print("load finished");
2857 // print("load_finished"); return;
2858 // if (this.ready) { // dont do it twice!
2861 if (!this.inspectorShown) {
2862 this.el.get_inspector().show();
2863 this.inspectorShown = true;
2868 if (this.pendingRedraw) {
2869 this.pendingRedraw = false;
2870 this.refreshRequired = true;
2872 //var js = this.get('/LeftTree.model').toJS();
2873 //if (js && js[0]) {
2874 // this.renderJS(js[0]);
2878 script_alert : function (self, object, p0) {
2881 return true; // do not display anything...
2883 console_message : function (self, object, p0, p1) {
2885 // console.log(object);
2888 if (object.match(/variable/) && object.match(/Builder/)) {
2889 print("got builder missing message");
2890 this.refreshRequired = true;
2891 this.lastRedraw = 0;
2897 if (!object.match(/^\{/)) {
2899 //this.get('/Terminal').feed(object);
2900 return true; // do not handle!!! -> later maybe in console..
2906 // console.log(object);
2907 var val = JSON.parse(object);
2909 if (typeof(val['hover-node']) != 'undefined') {
2910 this.activeNode = val['hover-node'];
2911 console.log('active node: ' + this.activeNode);
2916 if (typeof(val['id']) != 'undefined') {
2917 // this.activeNode = val['id'];
2918 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2919 if (!tg || typeof(tg[0]) == 'undefined') {
2922 print("SELECT node " + tg[0]);
2924 this.get('/LeftTree.view').selectNode(tg[0]);
2928 if (ret && typeof(val['set']) != 'undefined') {
2929 this.get('/LeftPanel.model').add({
2933 //console.log('active node: ' + this.activeNode);
2936 //Seed.print('a:'+a);
2937 //Seed.print('b:'+b);
2938 //Seed.print('c:'+c);
2941 drag_motion : function (w, ctx, x, y, time, ud) {
2942 // console.log('DRAG MOTION');
2944 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2945 this.targetData = [];
2946 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2948 // A) find out from drag all the places that node could be dropped.
2949 var src = Gtk.drag_get_source_widget(ctx);
2950 if (!src.dropList) {
2951 Gdk.drag_status(ctx, 0, time);
2954 // b) get what we are over.. (from activeNode)
2955 // tree is empty.. - list should be correct..
2956 if (!this.get('/LeftTree.model').currentTree) {
2957 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2961 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2963 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2966 Gdk.drag_status(ctx, 0,time);
2967 this.get('/LeftTree.view').highlight(false);
2971 // if we have a target..
2972 // -> highlight it! (in browser)
2973 // -> highlight it! (in tree)
2975 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2976 this.get('/LeftTree.view').highlight(tg);
2977 this.targetData = tg;
2978 // for tree we should handle this...
2981 drag_drop : function (w, ctx, x, y,time, ud) {
2982 print("TARGET: drag-drop");
2983 var is_valid_drop_site = true;
2988 w, /* will receive 'drag-data-received' signal */
2989 ctx, /* represents the current state of the DnD */
2990 this.get('/Window').atoms["STRING"], /* the target type we want */
2991 time /* time stamp */
2995 /* No target offered by source => error */
2998 return is_valid_drop_site;
3000 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3002 print("Browser: drag-data-received");
3003 var delete_selection_data = false;
3004 vardnd_success = false;
3005 /* Deal with what we are given from source */
3006 if( sel_data && sel_data.length ) {
3008 if (ctx.action == Gdk.DragAction.ASK) {
3009 /* Ask the user to move or copy, then set the ctx action. */
3012 if (ctx.action == Gdk.DragAction.MOVE) {
3013 delete_selection_data = true;
3015 var source = Gtk.drag_get_source_widget(ctx);
3017 print("Browser: source.DRAGDATA? " + source.dragData);
3018 if (this.targetData) {
3019 print(this.targetData);
3020 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3029 if (dnd_success == false)
3031 Seed.print ("DnD data transfer failed!\n");
3034 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3037 create_web_view : function (self, object) {
3038 print("CREATE WEB VIEW");
3039 return null; //new WebKit.WebView();
3046 XObject.prototype.init.call(this);
3047 // this may not work!?
3048 var settings = this.el.get_settings();
3049 settings.enable_developer_extras = true;
3051 // this was an attempt to change the url perms.. did not work..
3052 // settings.enable_file_access_from_file_uris = true;
3053 // settings.enable_offline_web_application_cache - true;
3054 // settings.enable_universal_access_from_file_uris = true;
3058 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3059 _this.get('/BottomPane.inspector').el.show();
3060 return _this.get('/BottomPane.inspector').el;
3064 // FIXME - base url of script..
3065 // we need it so some of the database features work.
3066 this.el.load_html_string( "Render not ready" ,
3067 //fixme - should be a config option!
3068 // or should we catch stuff and fix it up..
3069 'http://localhost/app.Builder/'
3073 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3077 this.el, /* widget that will accept a drop */
3078 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3079 null, /* lists of target to support */
3080 0, /* size of list */
3081 Gdk.DragAction.COPY /* what to do with data after dropped */
3084 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3085 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3087 GLib.timeout_add_seconds(0, 1, function() {
3088 // print("run refresh?");
3095 renderJS : function(data, force) {
3097 // this is the public redraw call..
3098 // we refresh in a loop privately..
3099 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3100 if (!autodraw && !force) {
3101 print("Skipping redraw - no force, and autodraw off");
3104 this.refreshRequired = true;
3106 runRefresh : function()
3108 // this is run every 2 seconds from the init..
3112 if (!this.refreshRequired) {
3113 // print("no refresh required");
3117 if (this.lastRedraw) {
3118 // do not redraw if last redraw was less that 5 seconds ago.
3119 if (((new Date()) - this.lastRedraw) < 5000) {
3127 if (!this.get('/Window.LeftTree').getActiveFile()) {
3130 this.refreshRequired = false;
3131 // print("HTML RENDERING");
3133 this.get('/BottomPane').el.show();
3134 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3137 var js = this.get('/LeftTree.model').toJS();
3138 if (!js || !js.length) {
3145 var project = this.get('/Window.LeftTree').getActiveFile().project;
3146 //print (project.fn);
3147 // set it to non-empty.
3148 project.runhtml = project.runhtml || '';
3149 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3152 this.runhtml = this.runhtml || '';
3154 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3155 // then we need to reload the browser using
3156 // load_html_string..
3158 // then trigger a redraw once it's loaded..
3159 this.pendingRedraw = true;
3160 var runhtml = '<script type="text/javascript">' + "\n" ;
3161 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3162 runhtml += '</script>'+ "\n" ;
3164 this.runhtml = project.runhtml;
3165 // need to modify paths
3169 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3170 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3171 print("LOAD HTML " + html);
3172 this.el.load_html_string( html ,
3173 //fixme - should be a config option!
3174 'http://localhost/app.Builder/'
3177 // should trigger load_finished! - which in truns shoudl set refresh Required;
3183 this.renderedData = data;
3184 var str = JSON.stringify(data) ;
3187 console.log('not loaded yet');
3189 this.lastRedraw = new Date();
3191 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3192 print( "before render" + this.lastRedraw);
3193 print( "after render" + (new Date()));
3203 id : "RightGtkView",
3205 redraw : function() {
3206 this.highlightWidget = false;
3207 print("REDRAW CALLED");
3208 this.activePath = this.get('/LeftTree').getActivePath();
3209 if (this.renderedEl) {
3210 print("QUEUE DRAW CALLING");
3211 this.renderedEl.queue_draw();
3214 renderJS : function(data, withDebug)
3216 this.highlightWidget = false;
3218 this.withDebug = false;
3219 while (this.get('view').el.get_children().length) {
3220 var c = this.get('view').el.get_children()[0];
3221 this.get('view').el.remove(c);
3228 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3229 // in theory tree is actually window..
3232 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3238 this.get('view').el.set_size_request(
3239 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3241 if (this.renderedEl) {
3242 this.renderedEl.set_size_request(
3243 tree.default_width || 600,
3244 tree.default_height || 400
3247 this.get('view').el.show_all();
3252 showInWindow : function() {
3253 print("GET PROEJCT");
3254 var pr = this.get('/LeftProjectTree').getActiveProject();
3256 console.log(pr.paths);
3259 var src= this.buildJS(
3260 this.get('/LeftTree.model').toJS()[0],
3265 //var x = new imports.sandbox.Context();
3269 Seed.check_syntax('var e = ' + src);
3272 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3273 this.get('/Terminal').feed(console._dump(e)+"\n");
3275 var lines = src.split("\n");
3276 var start = Math.max(0, e.line - 10);
3277 var end = Math.min(lines.length, e.line + 10);
3278 for (var i =start ; i < end; i++) {
3280 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3283 this.get('/Terminal').feed(lines[i] + "\n");
3290 this.get('/BottomPane').el.set_current_page(1);
3291 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3292 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3293 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3295 var _top = x.get_global_object()._top;
3297 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3299 if (_top.el.popup) {
3300 _top.el.popup(null, null, null, null, 3, null);
3304 viewAdd : function(item, par)
3306 // does something similar to xobject..
3307 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3309 if (item.pack===false || item.pack === 'false') { // no ;
3312 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3313 var type = item['|xns'] + '.' + item['xtype'];
3315 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3318 var ns = imports.gi[item['|xns']];
3319 var ctr = ns[item['xtype']];
3321 for(var k in item) {
3323 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3338 if (k[0] == '|' && typeof(kv) == 'string') {
3340 if (kv.match(new RegExp('function'))) {
3343 print("WASL " + k + '=' + kv);
3345 eval( 'kv = ' + kv);
3346 } catch(e) { continue; }
3349 // print(k + '=' + kv);
3351 if (k[0] == '|') { // should be boolean or number..
3353 //print(k + '=' + kv);
3356 if (k == 'show_tabs') { // force tab showing for notebooks.
3359 print(k + '=' + typeof(kv) + " : " + kv);
3365 var el = new ctr(ctr_args);
3367 print("PACK" + item.pack);
3368 //console.dump(item.pack);
3375 if (typeof(item.pack) == 'string') {
3377 item.pack.split(',').forEach(function(e, i) {
3379 if (e == 'false') { args.push( false); return; }
3380 if (e == 'true') { args.push( true); return; }
3381 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3384 //print(args.join(","));
3386 pack_m = args.shift();
3388 pack_m = item.pack.shift();
3393 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3395 name: "ArgumentError",
3396 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3397 "ADDING : " + item.id + " " + el
3406 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3407 //Seed.print('args: ' + args.length);
3409 par[pack_m].apply(par, args);
3413 item.items = item.items || [];
3414 item.items.forEach(function(ch,n) {
3416 print ("type:" + type);
3418 print ("ch.pack:" + ch.pack);
3419 if (type == 'Gtk.Table' && ch.pack == 'add') {
3420 var c = n % item.n_columns;
3421 var r = Math.floor(n/item.n_columns);
3422 ch.pack = [ 'attach', c, c+1, r, r+1,
3423 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3424 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3425 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3426 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3430 _this.viewAdd(ch, el);
3435 // add the signal handlers.
3436 // is it a widget!?!!?
3442 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3443 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3444 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3445 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3446 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3456 widgetDragDropEvent : function() {
3457 print("WIDGET DRAGDROP");
3460 widgetDragMotionEvent : function() {
3461 print("WIDGET DRAGMOTION");
3464 widgetExposeEvent : function(w, evt, ud, item) {
3466 if (this.inRender) {
3470 if ( this.highlightWidget) {
3471 this.inRender = true;
3472 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3473 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3475 this.inRender = false;
3480 if (this.activePath != item.xtreepath) {
3484 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3485 // work out the coords of the window..
3487 var dr = widget.window;
3488 this.gc = (new Gdk.GC.c_new(dr));
3489 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3490 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3494 var r = evt.expose.area;
3495 // console.dump([r.x, r.y, r.width, r.height ] );
3497 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3498 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3499 // happens with gtkscrollview embedded stuff..
3500 var np =this.activePath.split(':');
3502 this.activePath = np.join(':');
3503 this.renderedEl.queue_draw();
3519 this.inRender = true;
3522 this.highlightWidget = widget;
3527 // print("DRAW BOX");
3528 //console.dump(this.box);
3529 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3530 this.inRender = false;
3533 widgetPressEvent : function(w,e,u,d) {
3534 if (this.get('view').pressed) {
3537 this.get('view').pressed = true;
3538 print("WIDGET PRESS " + d.xtreepath );
3539 this.get('/LeftTree.view').selectNode( d.xtreepath );
3542 widgetReleaseEvent : function() {
3543 this.get('view').pressed = false;
3549 pack : "pack_start,false,true,0",
3553 pack : "pack_start,false,false,0",
3554 label : "Run The Application",
3556 button_press_event : function (self, event) {
3557 // call render on left tree - with special option!?!
3559 //print("GET PROEJCT");
3560 var pr = this.get('/LeftProjectTree').getActiveProject();
3563 for (var i in pr.paths) {
3567 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3568 this.get('/Terminal').feed("RUN DIR:" + dir);
3570 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3571 , false,false,false);
3572 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3573 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3583 xtype: Gtk.ScrolledWindow,
3586 shadow_type : Gtk.ShadowType.IN,
3588 XObject.prototype.init.call(this);
3589 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3593 xtype: Gtk.EventBox,
3594 pack : "add_with_viewport",
3596 XObject.prototype.init.call(this);
3597 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3598 red: 0x9F00, green: 0xB800 , blue : 0xA800
3606 XObject.prototype.init.call(this);
3607 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3608 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3613 xtype: Gtk.EventBox,
3616 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3617 XObject.prototype.init.call(this);
3621 this.el, /* widget that will accept a drop */
3622 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3623 null, /* lists of target to support */
3624 0, /* size of list */
3625 Gdk.DragAction.COPY /* what to do with data after dropped */
3628 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3629 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3632 getActiveNode : function(x,y)
3634 // workout what node is here..
3635 return '0'; // top..
3639 drag_motion : function (self, ctx, x, y, time) {
3641 // A) find out from drag all the places that node could be dropped.
3642 var src = Gtk.drag_get_source_widget(ctx);
3643 if (!src.dropList) {
3644 Gdk.drag_status(ctx, 0, time);
3647 // b) get what we are over.. (from activeNode)
3648 // tree is empty.. - list should be correct..
3649 if (!this.get('/LeftTree.model').currentTree) {
3650 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3654 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3655 var activeNode = this.getActiveNode(x, y);
3658 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3661 Gdk.drag_status(ctx, 0,time);
3662 this.get('/LeftTree.view').highlight(false);
3666 // if we have a target..
3667 // -> highlight it! (in browser)
3668 // -> highlight it! (in tree)
3670 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3671 this.get('/LeftTree.view').highlight(tg);
3672 this.targetData = tg;
3673 // for tree we should handle this...
3676 drag_drop : function (self,ctx, x, y, time) {
3677 Seed.print("TARGET: drag-drop");
3678 var is_valid_drop_site = true;
3683 self, /* will receive 'drag-data-received' signal */
3684 ctx, /* represents the current state of the this.gDnD */
3685 this.get('/Window').atoms["STRING"], /* the target type we want */
3686 time /* time stamp */
3690 /* No target offered by source => error */
3693 return is_valid_drop_site;
3696 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3698 Seed.print("GtkView: drag-data-received");
3699 var delete_selection_data = false;
3700 var dnd_success = false;
3701 /* Deal with what we are given from source */
3702 if( sel_data && sel_data.length ) {
3704 if (ctx.action == Gdk.DragAction.ASK) {
3705 /* Ask the user to move or copy, then set the ctx action. */
3708 if (ctx.action == Gdk.DragAction.MOVE) {
3709 delete_selection_data = true;
3711 var source = Gtk.drag_get_source_widget(ctx);
3713 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3714 if (this.targetData) {
3715 Seed.print(this.targetData);
3716 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3725 if (dnd_success == false)
3727 Seed.print ("DnD data transfer failed!\n");
3730 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3733 button_press_event : function (self, event) {
3734 this.pressed = false;
3750 xtype: Gtk.ScrolledWindow,
3755 var file = this.get('/LeftTree').getActiveFile();
3759 var activeEl = this.get('/LeftTree').getActiveElement();
3760 var xtype = file.guessName( activeEl )
3761 if (!xtype || !xtype.length) {
3764 //this.get('/Window.view-help-nb').el.set_current_page(1);
3766 // get the active element being edited.
3767 var helpurl = file.getHelpUrl(xtype);
3769 // now load the help info in the page..
3770 this.get('help-view').el.open(helpurl);
3774 xtype: WebKit.WebView,
3778 XObject.prototype.init.call(this);
3779 this.get('/Window.help-view').el.open(
3780 "http://devel.akbkhome.com/seed/");
3792 xtype: Gtk.Notebook,
3796 XObject.prototype.init.call(this);
3797 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3798 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3799 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3803 xtype: Gtk.ScrolledWindow,
3807 xtype: Vte.Terminal,
3810 feed : function(istr) {
3811 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3812 // we should make ourselves visable!!!
3813 this.get('/BottomPane').el.show();
3814 this.get('/BottomPane').el.set_current_page(1);
3816 this.el.feed(str ,str.length);
3818 scroll_on_output : true,
3820 XObject.prototype.init.call(this);
3821 this.el.set_size (80, 1000);
3823 scrollback_lines : 1000
3828 xtype: Gtk.ScrolledWindow,
3832 xtype: WebKit.WebView,
3844 pack : "pack_start,false,false",
3848 this.get('buttonbar').el.show();
3849 this.get('viewbox').el.hide();
3850 print("TRIED TO HIDE");
3853 this.get('buttonbar').el.hide();
3854 this.get('viewbox').el.show();
3855 // this.get('model').expanded();
3867 pack : "pack_start,false,true",
3869 clicked : function (self) {
3870 this.get('/RightPalete').show();
3877 stock : Gtk.STOCK_GOTO_FIRST,
3878 icon_size : Gtk.IconSize.MENU
3888 XObject.prototype.init.call(this);
3889 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3892 enter_notify_event : function (self, event) {
3893 this.get('/RightPalete').show();
3907 pack : "pack_start,false,true",
3916 pack : "pack_start,false,true",
3918 clicked : function (self) {
3919 this.get('/RightPalete').hide();
3926 stock : Gtk.STOCK_GOTO_LAST,
3927 icon_size : Gtk.IconSize.MENU
3934 xtype: Gtk.ScrolledWindow,
3937 XObject.prototype.init.call(this);
3938 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3939 this.el.set_size_request(-1,200);
3941 shadow_type : Gtk.ShadowType.IN,
3944 xtype: Gtk.TreeView,
3946 drag_begin : function (self, ctx) {
3947 // we could fill this in now...
3948 Seed.print('SOURCE: drag-begin');
3952 var iter = new Gtk.TreeIter();
3953 var s = this.selection;
3954 s.get_selected(this.get('/RightPalete.model').el, iter);
3955 var path = this.get('/RightPalete.model').el.get_path(iter);
3957 var pix = this.el.create_row_drag_icon ( path);
3960 Gtk.drag_set_icon_pixmap (ctx,
3967 var value = new GObject.Value('');
3968 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3969 if (!this.get('/RightPalete').provider) {
3972 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3973 this.el.dragData = value.value;
3980 drag_data_get : function (self, drag_context, selection_data, info, time) {
3981 //Seed.print('Palete: drag-data-get: ' + target_type);
3982 if (this.el.dragData && this.el.dragData.length ) {
3983 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3987 //this.el.dragData = "TEST from source widget";
3991 drag_end : function (self, drag_context) {
3992 Seed.print('SOURCE: drag-end');
3993 this.el.dragData = false;
3994 this.el.dropList = false;
3995 this.get('/LeftTree.view').highlight(false);
3998 button_press_event : function (self, event) {
4000 if (!this.get('/Editor').save()) {
4001 // popup!! - click handled..
4008 enable_tree_lines : true,
4009 headers_visible : false,
4011 XObject.prototype.init.call(this);
4012 this.el.set_size_request(150,-1);
4013 // set_reorderable: [1]
4015 var description = new Pango.FontDescription.c_new();
4016 description.set_size(8000);
4017 this.el.modify_font(description);
4019 this.selection = this.el.get_selection();
4020 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4021 // this.selection.signal['changed'].connect(function() {
4022 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4024 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4026 Gtk.drag_source_set (
4027 this.el, /* widget will be drag-able */
4028 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4029 null, /* lists of target to support */
4030 0, /* size of list */
4031 Gdk.DragAction.COPY /* what to do with data after dropped */
4033 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4035 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
4036 Gtk.drag_source_add_text_targets(this.el);
4038 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4039 targets = new Gtk.TargetList();
4040 targets.add( LeftTree.atoms["STRING"], 0, 0);
4041 targets.add_text_targets( 1 );
4042 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4044 //if you want to allow text to be output elsewhere..
4045 //Gtk.drag_source_add_text_targets(this.el);
4051 xtype: Gtk.ListStore,
4054 XObject.prototype.init.call(this);
4055 this.el.set_column_types ( 2, [
4056 GObject.TYPE_STRING, // title
4057 GObject.TYPE_STRING // tip
4062 load : function(tr,iter)
4067 //console.log('Project tree load: ' + tr.length);
4068 var citer = new Gtk.TreeIter();
4069 //this.insert(citer,iter,0);
4070 for(var i =0 ; i < tr.length; i++) {
4073 this.el.append(citer);
4075 this.el.insert(citer,iter,-1);
4080 this.el.set_value(citer, 0, '' + r ); // title
4082 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4083 //if (r.cn && r.cn.length) {
4084 // this.load(r.cn, citer);
4090 getValue : function (iter, col) {
4091 var gval = new GObject.Value('');
4092 this.el.get_value(iter, col ,gval);
4099 xtype: Gtk.TreeViewColumn,
4100 pack : "append_column",
4102 XObject.prototype.init.call(this);
4103 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4107 xtype: Gtk.CellRendererText,
4129 XObject.cache['/Window'] = Window;