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 xtype: Gtk.ScrolledWindow,
2836 XObject.prototype.init.call(this);
2837 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2839 shadow_type : Gtk.ShadowType.IN,
2842 xtype: WebKit.WebView,
2844 load_finished : function (self, object) {
2845 print("load finished");
2846 // print("load_finished"); return;
2847 // if (this.ready) { // dont do it twice!
2850 if (!this.inspectorShown) {
2851 this.el.get_inspector().show();
2852 this.inspectorShown = true;
2857 if (this.pendingRedraw) {
2858 this.pendingRedraw = false;
2859 this.refreshRequired = true;
2861 //var js = this.get('/LeftTree.model').toJS();
2862 //if (js && js[0]) {
2863 // this.renderJS(js[0]);
2867 script_alert : function (self, object, p0) {
2870 return true; // do not display anything...
2872 console_message : function (self, object, p0, p1) {
2874 // console.log(object);
2877 if (object.match(/variable/) && object.match(/Builder/)) {
2878 print("got builder missing message");
2879 this.refreshRequired = true;
2880 this.lastRedraw = 0;
2886 if (!object.match(/^\{/)) {
2888 //this.get('/Terminal').feed(object);
2889 return true; // do not handle!!! -> later maybe in console..
2895 // console.log(object);
2896 var val = JSON.parse(object);
2898 if (typeof(val['hover-node']) != 'undefined') {
2899 this.activeNode = val['hover-node'];
2900 console.log('active node: ' + this.activeNode);
2905 if (typeof(val['id']) != 'undefined') {
2906 // this.activeNode = val['id'];
2907 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2908 if (!tg || typeof(tg[0]) == 'undefined') {
2911 print("SELECT node " + tg[0]);
2913 this.get('/LeftTree.view').selectNode(tg[0]);
2917 if (ret && typeof(val['set']) != 'undefined') {
2918 this.get('/LeftPanel.model').add({
2922 //console.log('active node: ' + this.activeNode);
2925 //Seed.print('a:'+a);
2926 //Seed.print('b:'+b);
2927 //Seed.print('c:'+c);
2930 drag_motion : function (w, ctx, x, y, time, ud) {
2931 // console.log('DRAG MOTION');
2933 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2934 this.targetData = [];
2935 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2937 // A) find out from drag all the places that node could be dropped.
2938 var src = Gtk.drag_get_source_widget(ctx);
2939 if (!src.dropList) {
2940 Gdk.drag_status(ctx, 0, time);
2943 // b) get what we are over.. (from activeNode)
2944 // tree is empty.. - list should be correct..
2945 if (!this.get('/LeftTree.model').currentTree) {
2946 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2950 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2952 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2955 Gdk.drag_status(ctx, 0,time);
2956 this.get('/LeftTree.view').highlight(false);
2960 // if we have a target..
2961 // -> highlight it! (in browser)
2962 // -> highlight it! (in tree)
2964 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2965 this.get('/LeftTree.view').highlight(tg);
2966 this.targetData = tg;
2967 // for tree we should handle this...
2970 drag_drop : function (w, ctx, x, y,time, ud) {
2971 print("TARGET: drag-drop");
2972 var is_valid_drop_site = true;
2977 w, /* will receive 'drag-data-received' signal */
2978 ctx, /* represents the current state of the DnD */
2979 this.get('/Window').atoms["STRING"], /* the target type we want */
2980 time /* time stamp */
2984 /* No target offered by source => error */
2987 return is_valid_drop_site;
2989 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2991 print("Browser: drag-data-received");
2992 var delete_selection_data = false;
2993 vardnd_success = false;
2994 /* Deal with what we are given from source */
2995 if( sel_data && sel_data.length ) {
2997 if (ctx.action == Gdk.DragAction.ASK) {
2998 /* Ask the user to move or copy, then set the ctx action. */
3001 if (ctx.action == Gdk.DragAction.MOVE) {
3002 delete_selection_data = true;
3004 var source = Gtk.drag_get_source_widget(ctx);
3006 print("Browser: source.DRAGDATA? " + source.dragData);
3007 if (this.targetData) {
3008 print(this.targetData);
3009 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3018 if (dnd_success == false)
3020 Seed.print ("DnD data transfer failed!\n");
3023 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3026 create_web_view : function (self, object) {
3027 print("CREATE WEB VIEW");
3028 return null; //new WebKit.WebView();
3035 XObject.prototype.init.call(this);
3036 // this may not work!?
3037 var settings = this.el.get_settings();
3038 settings.enable_developer_extras = true;
3040 // this was an attempt to change the url perms.. did not work..
3041 // settings.enable_file_access_from_file_uris = true;
3042 // settings.enable_offline_web_application_cache - true;
3043 // settings.enable_universal_access_from_file_uris = true;
3047 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3048 _this.get('/BottomPane.inspector').el.show();
3049 return _this.get('/BottomPane.inspector').el;
3053 // FIXME - base url of script..
3054 // we need it so some of the database features work.
3055 this.el.load_html_string( "Render not ready" ,
3056 //fixme - should be a config option!
3057 // or should we catch stuff and fix it up..
3058 'http://localhost/app.Builder/'
3062 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3066 this.el, /* widget that will accept a drop */
3067 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3068 null, /* lists of target to support */
3069 0, /* size of list */
3070 Gdk.DragAction.COPY /* what to do with data after dropped */
3073 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3074 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3076 GLib.timeout_add_seconds(0, 1, function() {
3077 // print("run refresh?");
3084 renderJS : function(data, force) {
3086 // this is the public redraw call..
3087 // we refresh in a loop privately..
3088 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3089 if (!autodraw && !force) {
3090 print("Skipping redraw - no force, and autodraw off");
3093 this.refreshRequired = true;
3095 runRefresh : function()
3097 // this is run every 2 seconds from the init..
3101 if (!this.refreshRequired) {
3102 // print("no refresh required");
3106 if (this.lastRedraw) {
3107 // do not redraw if last redraw was less that 5 seconds ago.
3108 if (((new Date()) - this.lastRedraw) < 5000) {
3116 if (!this.get('/Window.LeftTree').getActiveFile()) {
3119 this.refreshRequired = false;
3120 // print("HTML RENDERING");
3122 this.get('/BottomPane').el.show();
3123 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3126 var js = this.get('/LeftTree.model').toJS();
3127 if (!js || !js.length) {
3134 var project = this.get('/Window.LeftTree').getActiveFile().project;
3135 //print (project.fn);
3136 // set it to non-empty.
3137 project.runhtml = project.runhtml || '';
3138 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3141 this.runhtml = this.runhtml || '';
3143 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3144 // then we need to reload the browser using
3145 // load_html_string..
3147 // then trigger a redraw once it's loaded..
3148 this.pendingRedraw = true;
3149 var runhtml = '<script type="text/javascript">' + "\n" ;
3150 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3151 runhtml += '</script>'+ "\n" ;
3153 this.runhtml = project.runhtml;
3154 // need to modify paths
3158 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3159 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3160 print("LOAD HTML " + html);
3161 this.el.load_html_string( html ,
3162 //fixme - should be a config option!
3163 'http://localhost/app.Builder/'
3166 // should trigger load_finished! - which in truns shoudl set refresh Required;
3172 this.renderedData = data;
3173 var str = JSON.stringify(data) ;
3176 console.log('not loaded yet');
3178 this.lastRedraw = new Date();
3180 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3181 print( "before render" + this.lastRedraw);
3182 print( "after render" + (new Date()));
3192 id : "RightGtkView",
3194 redraw : function() {
3195 this.highlightWidget = false;
3196 print("REDRAW CALLED");
3197 this.activePath = this.get('/LeftTree').getActivePath();
3198 if (this.renderedEl) {
3199 print("QUEUE DRAW CALLING");
3200 this.renderedEl.queue_draw();
3203 renderJS : function(data, withDebug)
3205 this.highlightWidget = false;
3207 this.withDebug = false;
3208 while (this.get('view').el.get_children().length) {
3209 var c = this.get('view').el.get_children()[0];
3210 this.get('view').el.remove(c);
3217 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3218 // in theory tree is actually window..
3221 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3227 this.get('view').el.set_size_request(
3228 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3230 if (this.renderedEl) {
3231 this.renderedEl.set_size_request(
3232 tree.default_width || 600,
3233 tree.default_height || 400
3236 this.get('view').el.show_all();
3241 showInWindow : function() {
3242 print("GET PROEJCT");
3243 var pr = this.get('/LeftProjectTree').getActiveProject();
3245 console.log(pr.paths);
3248 var src= this.buildJS(
3249 this.get('/LeftTree.model').toJS()[0],
3254 //var x = new imports.sandbox.Context();
3258 Seed.check_syntax('var e = ' + src);
3261 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3262 this.get('/Terminal').feed(console._dump(e)+"\n");
3264 var lines = src.split("\n");
3265 var start = Math.max(0, e.line - 10);
3266 var end = Math.min(lines.length, e.line + 10);
3267 for (var i =start ; i < end; i++) {
3269 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3272 this.get('/Terminal').feed(lines[i] + "\n");
3279 this.get('/BottomPane').el.set_current_page(1);
3280 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3281 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3282 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3284 var _top = x.get_global_object()._top;
3286 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3288 if (_top.el.popup) {
3289 _top.el.popup(null, null, null, null, 3, null);
3293 viewAdd : function(item, par)
3295 // does something similar to xobject..
3296 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3298 if (item.pack===false || item.pack === 'false') { // no ;
3301 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3302 var type = item['|xns'] + '.' + item['xtype'];
3304 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3307 var ns = imports.gi[item['|xns']];
3308 var ctr = ns[item['xtype']];
3310 for(var k in item) {
3312 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3327 if (k[0] == '|' && typeof(kv) == 'string') {
3329 if (kv.match(new RegExp('function'))) {
3332 print("WASL " + k + '=' + kv);
3334 eval( 'kv = ' + kv);
3335 } catch(e) { continue; }
3338 // print(k + '=' + kv);
3340 if (k[0] == '|') { // should be boolean or number..
3342 //print(k + '=' + kv);
3345 if (k == 'show_tabs') { // force tab showing for notebooks.
3348 print(k + '=' + typeof(kv) + " : " + kv);
3354 var el = new ctr(ctr_args);
3356 print("PACK" + item.pack);
3357 //console.dump(item.pack);
3364 if (typeof(item.pack) == 'string') {
3366 item.pack.split(',').forEach(function(e, i) {
3368 if (e == 'false') { args.push( false); return; }
3369 if (e == 'true') { args.push( true); return; }
3370 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3373 //print(args.join(","));
3375 pack_m = args.shift();
3377 pack_m = item.pack.shift();
3382 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3384 name: "ArgumentError",
3385 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3386 "ADDING : " + item.id + " " + el
3395 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3396 //Seed.print('args: ' + args.length);
3398 par[pack_m].apply(par, args);
3402 item.items = item.items || [];
3403 item.items.forEach(function(ch,n) {
3405 print ("type:" + type);
3407 print ("ch.pack:" + ch.pack);
3408 if (type == 'Gtk.Table' && ch.pack == 'add') {
3409 var c = n % item.n_columns;
3410 var r = Math.floor(n/item.n_columns);
3411 ch.pack = [ 'attach', c, c+1, r, r+1,
3412 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3413 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3414 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3415 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3419 _this.viewAdd(ch, el);
3424 // add the signal handlers.
3425 // is it a widget!?!!?
3431 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3432 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3433 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3434 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3435 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3445 widgetDragDropEvent : function() {
3446 print("WIDGET DRAGDROP");
3449 widgetDragMotionEvent : function() {
3450 print("WIDGET DRAGMOTION");
3453 widgetExposeEvent : function(w, evt, ud, item) {
3455 if (this.inRender) {
3459 if ( this.highlightWidget) {
3460 this.inRender = true;
3461 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3462 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3464 this.inRender = false;
3469 if (this.activePath != item.xtreepath) {
3473 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3474 // work out the coords of the window..
3476 var dr = widget.window;
3477 this.gc = (new Gdk.GC.c_new(dr));
3478 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3479 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3483 var r = evt.expose.area;
3484 // console.dump([r.x, r.y, r.width, r.height ] );
3486 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3487 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3488 // happens with gtkscrollview embedded stuff..
3489 var np =this.activePath.split(':');
3491 this.activePath = np.join(':');
3492 this.renderedEl.queue_draw();
3508 this.inRender = true;
3511 this.highlightWidget = widget;
3516 // print("DRAW BOX");
3517 //console.dump(this.box);
3518 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3519 this.inRender = false;
3522 widgetPressEvent : function(w,e,u,d) {
3523 if (this.get('view').pressed) {
3526 this.get('view').pressed = true;
3527 print("WIDGET PRESS " + d.xtreepath );
3528 this.get('/LeftTree.view').selectNode( d.xtreepath );
3531 widgetReleaseEvent : function() {
3532 this.get('view').pressed = false;
3538 pack : "pack_start,false,true,0",
3542 pack : "pack_start,false,false,0",
3543 label : "Run The Application",
3545 button_press_event : function (self, event) {
3546 // call render on left tree - with special option!?!
3548 //print("GET PROEJCT");
3549 var pr = this.get('/LeftProjectTree').getActiveProject();
3552 for (var i in pr.paths) {
3556 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3557 this.get('/Terminal').feed("RUN DIR:" + dir);
3559 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3560 , false,false,false);
3561 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3562 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3572 xtype: Gtk.ScrolledWindow,
3575 shadow_type : Gtk.ShadowType.IN,
3577 XObject.prototype.init.call(this);
3578 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3582 xtype: Gtk.EventBox,
3583 pack : "add_with_viewport",
3585 XObject.prototype.init.call(this);
3586 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3587 red: 0x9F00, green: 0xB800 , blue : 0xA800
3595 XObject.prototype.init.call(this);
3596 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3597 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3602 xtype: Gtk.EventBox,
3605 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3606 XObject.prototype.init.call(this);
3610 this.el, /* widget that will accept a drop */
3611 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3612 null, /* lists of target to support */
3613 0, /* size of list */
3614 Gdk.DragAction.COPY /* what to do with data after dropped */
3617 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3618 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3621 getActiveNode : function(x,y)
3623 // workout what node is here..
3624 return '0'; // top..
3628 drag_motion : function (self, ctx, x, y, time) {
3630 // A) find out from drag all the places that node could be dropped.
3631 var src = Gtk.drag_get_source_widget(ctx);
3632 if (!src.dropList) {
3633 Gdk.drag_status(ctx, 0, time);
3636 // b) get what we are over.. (from activeNode)
3637 // tree is empty.. - list should be correct..
3638 if (!this.get('/LeftTree.model').currentTree) {
3639 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3643 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3644 var activeNode = this.getActiveNode(x, y);
3647 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3650 Gdk.drag_status(ctx, 0,time);
3651 this.get('/LeftTree.view').highlight(false);
3655 // if we have a target..
3656 // -> highlight it! (in browser)
3657 // -> highlight it! (in tree)
3659 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3660 this.get('/LeftTree.view').highlight(tg);
3661 this.targetData = tg;
3662 // for tree we should handle this...
3665 drag_drop : function (self,ctx, x, y, time) {
3666 Seed.print("TARGET: drag-drop");
3667 var is_valid_drop_site = true;
3672 self, /* will receive 'drag-data-received' signal */
3673 ctx, /* represents the current state of the this.gDnD */
3674 this.get('/Window').atoms["STRING"], /* the target type we want */
3675 time /* time stamp */
3679 /* No target offered by source => error */
3682 return is_valid_drop_site;
3685 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3687 Seed.print("GtkView: drag-data-received");
3688 var delete_selection_data = false;
3689 var dnd_success = false;
3690 /* Deal with what we are given from source */
3691 if( sel_data && sel_data.length ) {
3693 if (ctx.action == Gdk.DragAction.ASK) {
3694 /* Ask the user to move or copy, then set the ctx action. */
3697 if (ctx.action == Gdk.DragAction.MOVE) {
3698 delete_selection_data = true;
3700 var source = Gtk.drag_get_source_widget(ctx);
3702 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3703 if (this.targetData) {
3704 Seed.print(this.targetData);
3705 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3714 if (dnd_success == false)
3716 Seed.print ("DnD data transfer failed!\n");
3719 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3722 button_press_event : function (self, event) {
3723 this.pressed = false;
3739 xtype: Gtk.ScrolledWindow,
3744 var file = this.get('/LeftTree').getActiveFile();
3748 var activeEl = this.get('/LeftTree').getActiveElement();
3749 var xtype = file.guessName( activeEl )
3750 if (!xtype || !xtype.length) {
3753 //this.get('/Window.view-help-nb').el.set_current_page(1);
3755 // get the active element being edited.
3756 var helpurl = file.getHelpUrl(xtype);
3758 // now load the help info in the page..
3759 this.get('help-view').el.open(helpurl);
3763 xtype: WebKit.WebView,
3767 XObject.prototype.init.call(this);
3768 this.get('/Window.help-view').el.open(
3769 "http://devel.akbkhome.com/seed/");
3781 xtype: Gtk.Notebook,
3785 XObject.prototype.init.call(this);
3786 //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3787 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
3788 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
3792 xtype: Gtk.ScrolledWindow,
3796 xtype: Vte.Terminal,
3799 feed : function(istr) {
3800 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3801 // we should make ourselves visable!!!
3802 this.get('/BottomPane').el.show();
3803 this.get('/BottomPane').el.set_current_page(1);
3805 this.el.feed(str ,str.length);
3807 scroll_on_output : true,
3809 XObject.prototype.init.call(this);
3810 this.el.set_size (80, 1000);
3812 scrollback_lines : 1000
3817 xtype: Gtk.ScrolledWindow,
3821 xtype: WebKit.WebView,
3833 pack : "pack_start,false,false",
3837 this.get('buttonbar').el.show();
3838 this.get('viewbox').el.hide();
3839 print("TRIED TO HIDE");
3842 this.get('buttonbar').el.hide();
3843 this.get('viewbox').el.show();
3844 // this.get('model').expanded();
3856 pack : "pack_start,false,true",
3858 clicked : function (self) {
3859 this.get('/RightPalete').show();
3866 stock : Gtk.STOCK_GOTO_FIRST,
3867 icon_size : Gtk.IconSize.MENU
3877 XObject.prototype.init.call(this);
3878 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3881 enter_notify_event : function (self, event) {
3882 this.get('/RightPalete').show();
3896 pack : "pack_start,false,true",
3905 pack : "pack_start,false,true",
3907 clicked : function (self) {
3908 this.get('/RightPalete').hide();
3915 stock : Gtk.STOCK_GOTO_LAST,
3916 icon_size : Gtk.IconSize.MENU
3923 xtype: Gtk.ScrolledWindow,
3926 XObject.prototype.init.call(this);
3927 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3928 this.el.set_size_request(-1,200);
3930 shadow_type : Gtk.ShadowType.IN,
3933 xtype: Gtk.TreeView,
3935 drag_begin : function (self, ctx) {
3936 // we could fill this in now...
3937 Seed.print('SOURCE: drag-begin');
3941 var iter = new Gtk.TreeIter();
3942 var s = this.selection;
3943 s.get_selected(this.get('/RightPalete.model').el, iter);
3944 var path = this.get('/RightPalete.model').el.get_path(iter);
3946 var pix = this.el.create_row_drag_icon ( path);
3949 Gtk.drag_set_icon_pixmap (ctx,
3956 var value = new GObject.Value('');
3957 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3958 if (!this.get('/RightPalete').provider) {
3961 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3962 this.el.dragData = value.value;
3969 drag_data_get : function (self, drag_context, selection_data, info, time) {
3970 //Seed.print('Palete: drag-data-get: ' + target_type);
3971 if (this.el.dragData && this.el.dragData.length ) {
3972 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3976 //this.el.dragData = "TEST from source widget";
3980 drag_end : function (self, drag_context) {
3981 Seed.print('SOURCE: drag-end');
3982 this.el.dragData = false;
3983 this.el.dropList = false;
3984 this.get('/LeftTree.view').highlight(false);
3987 button_press_event : function (self, event) {
3989 if (!this.get('/Editor').save()) {
3990 // popup!! - click handled..
3997 enable_tree_lines : true,
3998 headers_visible : false,
4000 XObject.prototype.init.call(this);
4001 this.el.set_size_request(150,-1);
4002 // set_reorderable: [1]
4004 var description = new Pango.FontDescription.c_new();
4005 description.set_size(8000);
4006 this.el.modify_font(description);
4008 this.selection = this.el.get_selection();
4009 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
4010 // this.selection.signal['changed'].connect(function() {
4011 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
4013 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
4015 Gtk.drag_source_set (
4016 this.el, /* widget will be drag-able */
4017 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
4018 null, /* lists of target to support */
4019 0, /* size of list */
4020 Gdk.DragAction.COPY /* what to do with data after dropped */
4022 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
4024 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
4025 Gtk.drag_source_add_text_targets(this.el);
4027 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
4028 targets = new Gtk.TargetList();
4029 targets.add( LeftTree.atoms["STRING"], 0, 0);
4030 targets.add_text_targets( 1 );
4031 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
4033 //if you want to allow text to be output elsewhere..
4034 //Gtk.drag_source_add_text_targets(this.el);
4040 xtype: Gtk.ListStore,
4043 XObject.prototype.init.call(this);
4044 this.el.set_column_types ( 2, [
4045 GObject.TYPE_STRING, // title
4046 GObject.TYPE_STRING // tip
4051 load : function(tr,iter)
4056 //console.log('Project tree load: ' + tr.length);
4057 var citer = new Gtk.TreeIter();
4058 //this.insert(citer,iter,0);
4059 for(var i =0 ; i < tr.length; i++) {
4062 this.el.append(citer);
4064 this.el.insert(citer,iter,-1);
4069 this.el.set_value(citer, 0, '' + r ); // title
4071 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4072 //if (r.cn && r.cn.length) {
4073 // this.load(r.cn, citer);
4079 getValue : function (iter, col) {
4080 var gval = new GObject.Value('');
4081 this.el.get_value(iter, col ,gval);
4088 xtype: Gtk.TreeViewColumn,
4089 pack : "append_column",
4091 XObject.prototype.init.call(this);
4092 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4096 xtype: Gtk.CellRendererText,
4118 XObject.cache['/Window'] = Window;