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;
15 type : Gtk.WindowType.TOPLEVEL,
16 title : "Application Builder",
20 "STRING" : Gdk.atom_intern("STRING")
22 this.targetList = new Gtk.TargetList();
23 this.targetList.add( this.atoms["STRING"], 0, 0);
24 //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
26 "style \"gtkcombobox-style\" {\n" +
27 " GtkComboBox::appears-as-list = 1\n" +
29 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
30 XObject.prototype.init.call(this);
39 setTitle : function(str) {
40 this.el.set_title(this.title + ' - ' + str);
43 delete_event : function (self, event) {
46 destroy : function (self) {
49 show : function (self) {
50 print("WINDOW SHOWING - trying to hide");
51 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
52 this.get('/MidPropTree').hideWin();
53 this.get('/RightPalete').hide();
54 this.get('/BottomPane').el.hide();
65 pack : "pack_start,false,false",
79 label : "New _Project",
81 activate : function (self) {
83 this.get('/EditProject').show({
84 success : function(pr) {
85 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
96 activate : function (self) {
97 var fn = this.get('/LeftProjectTree.combo').getValue();
99 this.get('/LeftProjectTree').showNoProjectSelected();
102 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
103 this.get('/DialogNewComponent').show({
104 project : pm.getByFn(fn)
110 xtype: Gtk.SeparatorMenuItem,
115 use_underline : true,
117 label : "D_elete Project",
119 activate : function (self) {
121 var fn = this.get('/LeftProjectTree').get('combo').getValue();
123 this.get('/StandardErrorDialog').show("Select a project")
126 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
127 var pr = pm.getByFn(fn);
130 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
131 pm.deleteProject(fn);
139 xtype: Gtk.SeparatorMenuItem,
146 use_underline : true,
148 activate : function (self) {
160 use_underline : true,
165 pack : "set_submenu",
170 activate : function (self) {
171 var fn = this.get('/LeftTree').getActiveFile();
173 this.get('/StandardErrorDialog').show("No File active");
177 this.get('/DialogNewComponent').show(fn);
181 label : "File _Properties",
188 activate : function (self, event) {
189 this.get('/RooProjectProperties').show();
193 label : "Modify Project HTML ",
204 use_underline : true,
208 pack : "set_submenu",
213 activate : function (self, event) {
214 var js = this.get('/LeftTree.model').toJS();
216 this.get('/RightBrowser.view').renderJS(js[0]);
221 label : "_Redraw (Roo)",
228 activate : function (self, event)
230 /* Firefox testing for debugging..
231 - we can create a /tmp directory, and put.
232 builder.html, builder.html.js, link roojs1
233 add at the end of builder.html Roo.onload(function() {
235 if (!this.get('/Window.LeftTree').getActiveFile()) {
239 var js = this.get('/LeftTree.model').toJS();
243 var project = this.get('/Window.LeftTree').getActiveFile().project;
244 //print (project.fn);
246 project.runhtml = project.runhtml || '';
249 var File = imports.File.File;
251 var target = "/tmp/firetest"; // fixme..
252 if (!File.isDirectory(target)) {
255 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
256 if (!File.exists( target+ '/roojs1')) {
257 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
262 var html = imports.File.File.read(__script_path__ + '/../builder.html');
263 html = html.replace('</head>', project.runhtml + '</head>');
266 var jsstr = JSON.stringify(js[0], null, 4);
268 var runbuilder = '<script type="text/javascript">' + "\n" +
269 " Builder.render(" + jsstr + ");\n" +
272 html = html.replace('</body>', runbuilder + '</body>');
274 File.write( target+ '/builder.html', html);
276 this.get('/Terminal').feed("RUN DIR:" + target);
278 this.get('/Terminal').el.fork_command( null , [], [], target
279 , false,false,false);
280 var cmd = "firefox file://" + target + "/builder.html \n";
281 this.get('/Terminal').el.feed_child(cmd, cmd.length);
285 label : "_Test in Firefox (Roo)",
296 use_underline : true,
301 pack : "set_submenu",
307 use_underline : true,
309 activate : function (self) {
310 this.get('/About').el.run();
340 activate : function (self) {
341 // this does not actually expand it..
342 // that is done by GTK..
346 if (!this.el.expanded) {
353 enter_notify_event : function (self, event) {
355 this.el.expanded = !this.el.expanded;
356 //if (this.el.expanded ) {
357 this.listeners.activate.call(this);
364 label : "Select Project or File",
365 pack : "pack_start,false,true",
366 onCollapse : function() {
368 var nb = this.get('/LeftTopPanel.notebook');
369 nb.el.set_current_page(0);
372 XObject.prototype.init.call(this);
373 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
375 onExpand : function() {
376 var nb = this.get('/LeftTopPanel.notebook');
377 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
380 var model = this.get('/LeftProjectTree.combomodel');
381 // print ("loading Projects?")
382 //console.dump(pm.projects);
383 model.loadData(pm.projects);
386 nb.el.set_current_page(1);
387 //pm.on('changed', function() {
388 //console.log("CAUGHT project manager change");
389 // _combo.model.loadData(pm.projects);
397 pack : "pack_start,true,true",
399 XObject.prototype.init.call(this);
400 this.el.set_current_page(0);
407 xtype: Gtk.ScrolledWindow,
410 getActiveElement : function() { // return path to actie node.
412 var path = this.getActivePath();
416 var iter = new Gtk.TreeIter();
417 this.get('model').el.get_iter_from_string(iter, path);
419 var value = new GObject.Value('');
420 this.get('model').el.get_value(iter, 2, value);
422 return JSON.parse(value.value);
424 getActiveFile : function() {
425 return this.get('model').file;
427 getActivePath : function() {
428 var model = this.get('model');
429 var view = this.get('view');
430 if (view.selection.count_selected_rows() < 1) {
433 var iter = new Gtk.TreeIter();
435 view.selection.get_selected(model.el, iter);
436 return model.el.get_path(iter).to_string();
438 getPaleteProvider : function() {
439 var model = this.get('model');
440 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
441 return pm.getPalete(model.file.getType());
443 getRenderer : function() {
445 switch( this.getActiveFile().getType()) {
447 return this.get('/RightBrowser.view');
449 return this.get('/RightGtkView');
454 XObject.prototype.init.call(this);
455 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
457 renderView : function() {
458 var render = this.getRenderer();
459 var model = this.get('model');
461 render.renderJS(model.toJS(false,true)[0]);
463 print("NO RENDER JS METHOD?");
466 shadow_type : Gtk.ShadowType.IN,
471 button_press_event : function (self, ev) {
472 console.log("button press?");
473 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
474 print("click" + ev.type);
480 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
482 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
484 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
485 this.get('/LeftTreeMenu').el.show_all();
486 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
487 print("click:" + res.path.to_string());
490 drag_begin : function (self, drag_context) {
491 print('SOURCE: drag-begin');
492 this.targetData = false;
493 // find what is selected in our tree...
494 var iter = new Gtk.TreeIter();
495 var s = this.selection;
496 s.get_selected(this.get('/LeftTree.model').el, iter);
498 // set some properties of the tree for use by the dropped element.
499 var value = new GObject.Value('');
500 this.get('/LeftTree.model').el.get_value(iter, 2, value);
501 var data = JSON.parse(value.value);
502 var xname = this.get('/LeftTree.model').file.guessName(data);
504 this.el.dragData = xname;
505 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
508 // make the drag icon a picture of the node that was selected
509 var path = this.get('/LeftTree.model').el.get_path(iter);
510 this.el.treepath = path.to_string();
512 var pix = this.el.create_row_drag_icon ( path);
514 Gtk.drag_set_icon_pixmap (ctx,
523 drag_end : function (self, drag_context) {
524 Seed.print('LEFT-TREE: drag-end');
525 this.el.dragData = false;
526 this.el.dropList = false;
527 this.targetData = false;
528 this.get('/LeftTree.view').highlight(false);
531 drag_motion : function (self, ctx, x, y, time) {
532 console.log("LEFT-TREE: drag-motion");
533 var src = Gtk.drag_get_source_widget(ctx);
535 // a drag from elsewhere...- prevent drop..
537 print("no drag data!");
538 Gdk.drag_status(ctx, 0, time);
539 this.targetData = false;
542 var action = Gdk.DragAction.COPY;
543 if (src == this.el) {
544 // unless we are copying!!! ctl button..
545 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
549 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
550 // no children.. -- asume it's ok..
551 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
552 Gdk.drag_status(ctx, action ,time);
556 print("GETTING POS");
557 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
558 print("ISOVER? " + isOver);
560 Gdk.drag_status(ctx, 0 ,time);
561 return false; // not over apoint!?!
563 // drag node is parent of child..
564 console.log("SRC TREEPATH: " + src.treepath);
565 console.log("TARGET TREEPATH: " + data.path.to_string());
567 // nned to check a few here..
568 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
569 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
570 //Gtk.TreeViewDropPosition.AFTER
571 //Gtk.TreeViewDropPosition.BEFORE
573 if (typeof(src.treepath) != 'undefined' &&
574 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
575 print("subpath drag");
576 Gdk.drag_status(ctx, 0 ,time);
581 //print("DUMPING DATA");
582 //console.dump(data);
585 print(data.path.to_string() +' => '+ data.pos);
586 var tg = this.get('/LeftTree.model').findDropNodeByPath(
587 data.path.to_string(), src.dropList, data.pos);
589 this.get('/LeftTree.view').highlight(tg);
591 print("Can not find drop node path");
592 this.targetData = false;
593 Gdk.drag_status(ctx, 0, time);
597 this.targetData = tg;
600 Gdk.drag_status(ctx, action ,time);
604 drag_drop : function (w, ctx, x, y, time) {
605 Seed.print("TARGET: drag-drop");
609 w, /* will receive 'drag-data-received' signal */
610 ctx, /* represents the current state of the DnD */
611 this.get('/Window').atoms["STRING"], /* the target type we want */
612 time /* time stamp */
616 /* No target offered by source => error */
621 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
622 print("Tree: drag-data-received");
624 var delete_selection_data = false;
625 var dnd_success = false;
626 /* Deal with what we are given from source */
627 if( sel_data && sel_data.length ) {
629 if (ctx.action == Gdk.DragAction.ASK) {
630 /* Ask the user to move or copy, then set the ctx action. */
633 if (ctx.action == Gdk.DragAction.MOVE) {
634 //delete_selection_data = true;
637 var source = Gtk.drag_get_source_widget(ctx);
639 if (this.targetData) {
640 if (source != this.el) {
641 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
643 // drag around.. - reorder..
644 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
648 //Seed.print(this.targetData);
654 // we can send stuff to souce here...
660 if (dnd_success == false)
662 Seed.print ("DnD data transfer failed!\n");
665 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
668 cursor_changed : function (self) {
669 if (this.blockChanges) { // probably not needed..
672 var render = this.get('/LeftTree').getRenderer();
675 if (this.selection.count_selected_rows() < 1) {
676 this.get('/LeftPanel.model').load( false);
677 this.get('/MidPropTree').activeElement = false;
678 this.get('/MidPropTree').hideWin();
680 var pm = this.get('/RightPalete.model');
681 if (!this.get('/LeftTree').getPaleteProvider()) {
682 // it may not be loaded yet..
685 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
686 this.get('/LeftTree.model').listAllTypes()));
687 if (render && render.redraw) {
693 //console.log('changed');
694 var s = this.selection;
695 var iter = new Gtk.TreeIter();
696 s.get_selected(this.get('/LeftTree.model').el, iter);
700 var value = new GObject.Value('');
701 this.get('/LeftTree.model').el.get_value(iter, 2, value);
702 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
704 var data = JSON.parse(value.value);
705 this.get('/MidPropTree').activeElement = data;
706 this.get('/MidPropTree').hideWin();
707 this.get('/LeftPanel.model').load( data);
709 console.log(value.value);
710 // _g.button.set_label(''+value.get_string());
712 var pm =this.get('/RightPalete.model');
713 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
714 this.get('/LeftTree.model').listAllTypes()));
717 if (render && render.redraw) {
721 //Seed.print( value.get_string());
729 enable_tree_lines : true,
730 headers_visible : false,
731 highlight : function(treepath_ar) {
733 // highlighting for drag/drop
734 if (treepath_ar.length && treepath_ar[0].length ) {
735 this.el.set_drag_dest_row(
736 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
738 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
743 XObject.prototype.init.call(this);
744 var description = new Pango.FontDescription.c_new();
745 description.set_size(8000);
746 this.el.modify_font(description);
748 this.selection = this.el.get_selection();
749 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
752 // is this really needed??
753 this.selection.signal['changed'].connect(function() {
754 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
755 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
759 Gtk.drag_source_set (
760 this.el, /* widget will be drag-able */
761 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
762 null, /* lists of target to support */
763 0, /* size of list */
764 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
767 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
769 Gtk.drag_source_add_text_targets(this.el);
772 this.el, /* widget that will accept a drop */
773 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
774 null, /* lists of target to support */
775 0, /* size of list */
776 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
779 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
780 Gtk.drag_dest_add_text_targets(this.el);
782 selectNode : function(treepath_str) {
783 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
784 var tp = new Gtk.TreePath.from_string(treepath_str);
785 this.el.set_cursor(tp, null, false);
786 this.el.scroll_to_cell(tp, null, false, 0,0);
790 xtype: Gtk.TreeStore,
795 changed : function(n, refresh) {
796 // print("MODEL CHANGED CALLED" + this.activePath);
797 if (this.activePath) {
798 var iter = new Gtk.TreeIter();
799 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
800 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
801 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
803 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
805 //this.currentTree = this.toJS(false, true)[0];
806 this.file.items = this.toJS(false, false);
807 // print("AFTER CHANGED");
808 //console.dump(this.file.items);
810 this.currentTree = this.file.items[0];
811 //console.log(this.file.toSource());
814 print("REDNER BROWSER?!");
815 this.get('/LeftTree').renderView();
817 var pm = this.get('/RightPalete.model');
818 if (!this.get('/RightPalete').provider) {
824 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
825 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
829 deleteSelected : function() {
830 this.get('/LeftTree.view').blockChanges = true;
831 var old_iter = new Gtk.TreeIter();
832 var s = this.get('/LeftTree.view').selection;
833 s.get_selected(this.el, old_iter);
834 var path = this.el.get_path(old_iter).to_string();
836 this.activePath= false;
839 this.activePath= false;
840 var iter = new Gtk.TreeIter();
841 this.el.get_iter_from_string(iter, path);
842 this.el.remove(iter);
844 // rebuild treemap. -- depreciated.!!
847 //this.toJS(null, true) // does not do anything?
848 this.activePath= false;
849 this.changed(false,true);
850 this.get('/LeftTree.view').blockChanges = false;
852 dropNode : function(target_data, node) {
854 // console.dump(node);
855 // console.dump(target_data);
856 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
858 print("add " + tp + "@" + target_data[1] );
861 if (tp && target_data[1] < 2) { // before or after..
862 var ar = target_data[0].split(':');
864 parent = new Gtk.TreePath.from_string( ar.join(':') );
867 var n_iter = new Gtk.TreeIter();
868 var iter_par = new Gtk.TreeIter();
869 var iter_after = after ? new Gtk.TreeIter() : false;
873 if (parent !== false) {
874 this.el.get_iter(iter_par, parent);
881 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
882 this.el.get_iter(iter_after, after);
883 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
884 n_iter, iter_par, iter_after);
887 this.el.append(n_iter, iter_par);
891 if (typeof(node) == 'string') {
892 var ar = node.split('.');
893 var xtype = ar.pop();
896 '|xns' : ar.join('.'),
899 if (target_data.length == 3 && target_data[2].length) {
900 node['*prop'] = target_data[2];
902 node = this.get('/DialogTemplateSelect').show(node);
905 // work out what kind of packing to use..
906 if (typeof(node.pack) == 'undefined' && parent !== false) {
907 var pal = this.get('/LeftTree').getPaleteProvider();
908 if (pal.name == 'Gtk') {
909 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
910 var cname = pal.guessName(node);
911 node.pack = pal.getDefaultPack(pname, cname);
922 // load children - if it has any..
925 this.load(xitems, n_iter);
926 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
928 if (tp && (xitems || after)) {
929 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
931 // wee need to get the empty proptypes from somewhere..
933 //var olditer = this.activeIter;
934 this.activePath = this.el.get_path(n_iter).to_string();
936 // changed actually set's the node data..
937 this.changed(node, true);
941 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
943 //Builder.MidPropTree._model.load(node);
944 //Builder.MidPropTree._win.hideWin();
945 //Builder.LeftPanel._model.load( node);
949 findDropNode : function(treepath_str, targets) {
951 // this is used by the dragdrop code in the roo version AFAIR..
953 var path = treepath_str.replace(/^builder-/, '');
954 // treemap is depreciated... - should really check if model has any entries..
956 if (!this.el.iter_n_children(null)) {
958 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
960 print("FIND treepath: " + path);
961 //console.dump(this.treemap);
963 if (!treepath_str.match(/^builder-/)) {
964 return []; // nothing!
966 if (targets === true) {
969 return this.findDropNodeByPath(path,targets)
971 findDropNodeByPath : function(treepath_str, targets, pref) {
972 var path = treepath_str + ''; // dupe it..
973 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
975 //console.dump(this.treemap);
976 while (path.length) {
977 print("LOOKING FOR PATH: " + path);
978 var node_data = this.singleNodeToJS(path);
979 if (node_data === false) {
980 print("node not found");
984 var xname = this.get('/LeftTree.model').file.guessName(node_data);
987 targets.forEach(function(tg) {
991 if ((tg == xname) ) {
994 if (tg.indexOf(xname +':') === 0) {
996 prop = tg.split(':').pop();
1001 if (last) { // pref is after/before..
1002 // then it's after last
1004 return []; // do not allow..
1006 return [ last, pref , prop];
1009 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1011 var par = path.split(':');
1014 path = par.join(':');
1020 getIterValue : function (iter, col) {
1021 var gval = new GObject.Value('');
1022 this.el.get_value(iter, col ,gval);
1028 XObject.prototype.init.call(this);
1029 this.el.set_column_types ( 3, [
1030 GObject.TYPE_STRING, // title
1031 GObject.TYPE_STRING, // tip
1032 GObject.TYPE_STRING // source..
1035 listAllTypes : function() {
1036 var s = this.get('/LeftTree.view').selection;
1037 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1039 if (s.count_selected_rows() > 0) {
1040 var iter = new Gtk.TreeIter();
1041 s.get_selected(this.el, iter);
1043 // set some properties of the tree for use by the dropped element.
1044 var value = new GObject.Value('');
1045 this.el.get_value(iter, 2, value);
1046 var data = JSON.parse(value.value);
1049 var xname = this.get('/LeftTree.model').file.guessName(data);
1050 console.log('selected:' + xname);
1054 return []; // could not find it..
1062 li.forEach(function(el) {
1063 // this is specific to roo!!!?
1064 if (!el) { // skip empty?
1067 var fullpath = _this.file.guessName(el);
1068 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1073 if (el.items && el.items.length) {
1082 addall([this.currentTree]);
1084 // only if we have nothing, should we add '*top'
1088 //console.log('all types in tree');
1089 //console.dump(ret);
1094 load : function(tr,iter)
1096 var citer = new Gtk.TreeIter();
1097 //this.insert(citer,iter,0);
1098 for(var i =0 ; i < tr.length; i++) {
1100 this.el.insert(citer,iter,-1);
1102 this.el.append(citer);
1105 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1106 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1107 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1108 if (tr[i].items && tr[i].items.length) {
1109 this.load(tr[i].items, citer);
1113 loadFile : function(f) {
1119 console.log('missing file');
1123 // load the file if not loaded..
1124 if (f.items === false) {
1126 f.loadItems(function() {
1132 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1134 if (f.items.length && typeof(f.items[0]) == 'string') {
1136 this.get('/RightEditor').el.show();
1137 this.get('/RightEditor.view').load( f.items[0]);
1141 print(JSON.stringify(f.items, null,4));
1142 //console.dump(f.items);
1144 this.get('/LeftTree.view').el.expand_all();
1146 if (!f.items.length) {
1149 this.get('/Window.leftvpaned').el.set_position(80);
1151 this.get('/LeftTree.view').el.set_cursor(
1152 new Gtk.TreePath.from_string('0'), null, false);
1156 this.get('/Window.leftvpaned').el.set_position(200);
1160 //print("hide right editior");
1161 this.get('/RightEditor').el.hide();
1162 //print("set current tree");
1163 this.currentTree = this.toJS(false, false)[0];
1164 //console.dump(this.currentTree);
1165 this.currentTree = this.currentTree || { items: [] };
1166 this.get('/LeftTree').renderView();
1167 //console.dump(this.map);
1168 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1169 var pm = this.get('/RightPalete.model');
1170 // set up provider..
1172 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1174 if (!this.get('/RightPalete').provider) {
1175 print ("********* PALETE PROVIDER MISSING?!!");
1177 this.get('/LeftTree').renderView();
1179 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1183 this.get('/Window.view-notebook').el.set_current_page(
1184 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1187 moveNode : function(target_data, action) {
1188 //print("MOVE NODE");
1189 // console.dump(target_data);
1190 var old_iter = new Gtk.TreeIter();
1191 var s = this.get('/LeftTree.view').selection;
1192 s.get_selected(this.el, old_iter);
1193 var node = this.nodeToJS(old_iter,false);
1194 //console.dump(node);
1197 // needs to drop first, otherwise the target_data
1198 // treepath will be invalid.
1200 this.dropNode(target_data, node);
1201 if (action & Gdk.DragAction.MOVE) {
1202 // print("REMOVING OLD NODE");
1203 this.el.remove(old_iter);
1207 this.activePath= false;
1208 this.changed(false,true);
1210 nodeTip : function(c) {
1211 var ret = this.nodeTitle(c,true);
1217 if (!i.length || i[0] != '|') {
1223 if (typeof(c[i]) != 'string') {
1226 //print("prop : " + i + ':' + c[i]);
1227 if (!c[i].match(new RegExp('function'))) {
1230 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1234 ret+="\n\nMethods:" + funcs;
1239 nodeTitle : function(c, renderfull) {
1242 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1243 if (sr) txt.push('<s>');
1244 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1246 if (renderfull && c['|xns']) {
1247 txt.push(c['|xns']);
1250 if (c.xtype) { txt.push(c.xtype); }
1251 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1252 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1253 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1256 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1257 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1258 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1259 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1260 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1261 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1262 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1263 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1264 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1266 // for flat classes...
1267 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1268 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1271 if (sr) txt.push('</s>');
1272 return (txt.length == 0 ? "Element" : txt.join(" "));
1274 nodeToJS : function (treepath, with_id)
1277 var iter = treepath; // API used to be iter here..
1278 if (typeof(iter) == 'string') {
1279 iter = new Gtk.TreeIter();
1280 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1284 var par = new Gtk.TreeIter();
1285 var iv = this.getIterValue(iter, 2);
1286 // print("IV" + iv);
1287 var k = JSON.parse(iv);
1288 if (k.json && !this.el.iter_parent( par, iter )) {
1293 var treepath_str = this.el.get_path(iter).to_string();
1294 // not sure how we can handle mixed id stuff..
1295 if (typeof(k.id) == 'undefined') {
1296 k.id = 'builder-'+ treepath_str ;
1300 this.treemap[ treepath_str ] = k;
1301 k.xtreepath = treepath_str ;
1304 if (this.el.iter_has_child(iter)) {
1305 citer = new Gtk.TreeIter();
1306 this.el.iter_children(citer, iter);
1307 k.items = this.toJS(citer,with_id);
1311 nodeToJSON : function(c) {
1319 return JSON.stringify(o);
1321 singleNodeToJS : function (treepath)
1323 var iter = new Gtk.TreeIter();
1324 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1328 var iv = this.getIterValue(iter, 2);
1330 return JSON.parse(iv);
1333 toJS : function(treepath, with_id)
1335 //Seed.print("WITHID: "+ with_id);
1336 var iter = treepath; // API used to be iter here..
1337 if (typeof(iter) == 'string') {
1338 iter = new Gtk.TreeIter();
1339 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1348 iter = new Gtk.TreeIter();
1349 if (!this.el.get_iter_first(iter)) {
1359 var k = this.nodeToJS(iter, with_id);
1363 if (!this.el.iter_next(iter)) {
1368 if (treepath === false) {
1370 return JSON.parse(JSON.stringify(ar));
1374 // convert the list into a json string..
1380 xtype: Gtk.TreeViewColumn,
1381 pack : "append_column",
1383 XObject.prototype.init.call(this);
1384 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1388 xtype: Gtk.CellRendererText,
1398 id : "LeftTreeMenu",
1401 xtype: Gtk.MenuItem,
1403 label : "Delete Element",
1405 activate : function (self) {
1407 this.get('/LeftTree.model').deleteSelected();
1412 xtype: Gtk.MenuItem,
1414 activate : function (self) {
1416 var tree = this.get('/LeftTree');
1417 var model = this.get('/LeftTree.model');
1418 var el = tree.getActivePath();
1420 var js = model.toJS(el, false);
1421 // print(JSON.stringify(js[0], null,4));
1422 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1427 label : "Save as Template",
1437 id : "LeftProjectTree",
1438 showNoProjectSelected : function() {
1439 this.get('/StandardErrorDialog').show("Select a Project first.");
1441 getActiveProject : function() {
1442 return this.project;
1445 leave_notify_event : function (self, event) {
1452 pack : "pack_start,false,false",
1455 xtype: Gtk.ComboBox,
1458 XObject.prototype.init.call(this);
1459 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1461 getValue : function() {
1462 var ix = this.el.get_active();
1466 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1467 if (typeof(data[ix]) == 'undefined') {
1472 setValue : function(fn)
1476 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1477 data.forEach(function(n, ix) {
1485 changed : function (self) {
1486 var fn = this.getValue();
1487 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1488 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1493 xtype: Gtk.CellRendererText,
1494 pack : "pack_start,true",
1498 xtype: Gtk.ListStore,
1501 XObject.prototype.init.call(this);
1502 this.el.set_column_types ( 2, [
1503 GObject.TYPE_STRING, // real key
1504 GObject.TYPE_STRING // real type
1508 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1510 pm.on('changed', function() {
1511 print("caught changed hook on project manager - reloading data");
1512 _this.loadData(pm.projects);
1516 loadData : function(data) {
1517 var ov = this.get('/LeftProjectTree.combo').getValue();
1519 var iter = new Gtk.TreeIter();
1521 data.forEach(function(p) {
1526 el.set_value(iter, 0, p.fn);
1527 el.set_value(iter, 1, p.name);
1531 this.get('/LeftProjectTree.combo').setValue(ov);
1540 xtype: Gtk.ScrolledWindow,
1542 shadow_type : Gtk.ShadowType.IN,
1544 XObject.prototype.init.call(this);
1545 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1549 xtype: Gtk.TreeView,
1551 cursor_changed : function (self) {
1552 var iter = new Gtk.TreeIter();
1554 if (this.selection.count_selected_rows() < 1) {
1555 //XN.get('Builder.LeftTree.model').
1556 this.get('/LeftTree.model').load( false);
1560 var model = this.get('/LeftProjectTree.model');
1561 //console.log('changed');
1562 var s = this.selection;
1563 s.get_selected(model, iter);
1564 value = new GObject.Value('');
1565 model.el.get_value(iter, 2, value);
1567 console.log(value.value);// id..
1569 var file = this.get('/LeftProjectTree').project.getById(value.value);
1576 var nb = this.get('/LeftTopPanel.expander');
1577 nb.el.expanded = false;
1579 //nb.listeners.activate.call(nb);
1580 //_expander.el.set_expanded(false);
1582 var ltm = this.get('/LeftTree.model');
1590 enable_tree_lines : true,
1591 headers_visible : false,
1593 XObject.prototype.init.call(this);
1594 var description = new Pango.FontDescription.c_new();
1595 description.set_size(8000);
1596 this.el.modify_font(description);
1598 this.selection = this.el.get_selection();
1599 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1603 xtype: Gtk.TreeStore,
1607 XObject.prototype.init.call(this);
1608 this.el.set_column_types ( 3, [
1609 GObject.TYPE_STRING, // title
1610 GObject.TYPE_STRING, // tip
1611 GObject.TYPE_STRING // id..
1615 loadProject : function(pr) {
1616 print("LOAD PROJECT");
1622 this.get('/LeftProjectTree').project = pr;
1623 this.load(pr.toTree());
1624 this.get('/LeftProjectTree.view').el.expand_all();
1626 load : function(tr,iter) {
1627 // console.dump(tr);
1628 console.log('Project tree load: ' + tr.length);
1629 var citer = new Gtk.TreeIter();
1630 //this.insert(citer,iter,0);
1633 tr.forEach(function (r) {
1635 _this.el.append(citer);
1637 _this.el.insert(citer,iter,-1);
1639 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1640 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1641 _this.el.set_value(citer, 2, '' + r.id ); //id
1642 if (r.cn && r.cn.length) {
1643 _this.load(r.cn, citer);
1648 getValue : function(iter, col) {
1649 var gval = new GObject.Value('');
1650 this.el.get_value(iter, col ,gval);
1651 return '' + gval.value;
1655 xtype: Gtk.TreeViewColumn,
1656 pack : "append_column",
1658 XObject.prototype.init.call(this);
1659 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1663 xtype: Gtk.CellRendererText,
1683 pack : "pack_start,false,true,0",
1690 button_press_event : function (self, event) {
1691 this.get('/MidPropTree.model').showData('props');
1703 stock : Gtk.STOCK_ADD,
1704 icon_size : Gtk.IconSize.MENU
1719 button_press_event : function (self, event) {
1720 this.get('/MidPropTree.model').showData('events');
1732 stock : Gtk.STOCK_ADD,
1733 icon_size : Gtk.IconSize.MENU
1748 button_press_event : function (self, ev) {
1749 var p = this.get('/AddPropertyPopup');
1753 p.el.set_screen(Gdk.Screen.get_default());
1755 p.el.popup(null, null, null, null, 3, ev.button.time);
1767 stock : Gtk.STOCK_ADD,
1768 icon_size : Gtk.IconSize.MENU
1780 id : "AddPropertyPopup",
1783 xtype: Gtk.MenuItem,
1785 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1788 activate : function (self) {
1790 this.get('/LeftPanel.model').add( {
1801 xtype: Gtk.MenuItem,
1803 tooltip_markup : "Add what type of packing is to be used",
1806 activate : function (self) {
1808 this.get('/LeftPanel.model').add( {
1818 xtype: Gtk.MenuItem,
1820 tooltip_markup : "Override the init method",
1823 activate : function (self) {
1825 this.get('/LeftPanel.model').add( {
1828 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1835 xtype: Gtk.SeparatorMenuItem,
1839 xtype: Gtk.MenuItem,
1841 tooltip_markup : "Add a user defined string property",
1844 activate : function (self) {
1846 this.get('/LeftPanel.model').add( {
1856 xtype: Gtk.MenuItem,
1858 tooltip_markup : "Add a user defined number property",
1861 activate : function (self) {
1863 this.get('/LeftPanel.model').add( {
1873 xtype: Gtk.MenuItem,
1875 tooltip_markup : "Add a user defined boolean property",
1878 activate : function (self) {
1880 this.get('/LeftPanel.model').add( {
1890 xtype: Gtk.SeparatorMenuItem,
1894 xtype: Gtk.MenuItem,
1896 tooltip_markup : "Add a user function boolean property",
1899 activate : function (self) {
1901 this.get('/LeftPanel.model').add( {
1904 val : "function() {\n \n}\n",
1917 xtype: Gtk.ScrolledWindow,
1922 XObject.prototype.init.call(this);
1923 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1925 shadow_type : Gtk.ShadowType.IN,
1928 xtype: Gtk.TreeView,
1930 button_press_event : function (self, ev) {
1935 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1936 return false; //not on a element.
1940 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
1942 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
1945 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1946 var p = this.get('/LeftPanelPopup');
1951 p.el.set_screen(Gdk.Screen.get_default());
1953 p.el.popup(null, null, null, null, 3, ev.button.time);
1954 //Seed.print("click:" + res.column.title);
1961 if (res.column.title != 'value') {
1962 // XObject.error("column is not value?");
1963 return false; // ignore.. - key click.. ??? should we do this??
1966 // currently editing???
1967 // if ( this.activePath) {
1969 // this.activePath = false;
1971 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1972 this.get('/LeftPanel').editing = false;
1974 // XObject.error("Currently editing?");
1978 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1980 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1982 // get options for this type -- this is to support option lists etc..
1983 var provider = this.get('/LeftTree').getPaleteProvider();
1984 var opts = provider.findOptions(type);
1986 if (opts === false) {
1988 this.get('/LeftPanel').editableColumn.setOptions([]);
1989 renderer.has_entry = true;
1991 this.get('/LeftPanel').editableColumn.setOptions(opts);
1992 renderer.has_entry = false;
1994 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
1996 //Seed.print("click" + ev.type);
1997 //console.dump(res);
2006 enable_tree_lines : true,
2007 headers_visible : false,
2009 XObject.prototype.init.call(this);
2011 this.selection = this.el.get_selection();
2012 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2015 var description = new Pango.FontDescription.c_new();
2016 description.set_size(8000);
2017 this.el.modify_font(description);
2021 xtype: Gtk.TreeStore,
2025 add : function(info) {
2026 // info includes key, val, skel, etype..
2028 type = info.type.toLowerCase();
2029 var data = this.toJS();
2031 if (info.etype == 'events') {
2032 data.listeners = data.listeners || { };
2033 if (typeof(data.listeners[info.key]) != 'undefined') {
2034 return; //already set!
2037 if (typeof(data[info.key]) != 'undefined') {
2042 if (typeof(info.val) == 'undefined') {
2045 if (info.type.toLowerCase() == 'boolean') {
2048 if (type == 'number') {
2056 if (info.etype == 'events') {
2058 data.listeners[info.key] = info.val;
2061 data[info.key] = info.val;
2065 var map = this.load(data);
2067 // flag it as changed to the interface..
2069 this.get('/LeftTree.model').changed(data, true);
2072 this.startEditing(map[k]);
2075 LeftPanel.get('view').el.row_activated(
2076 new Gtk.TreePath.from_string(map[k]),
2077 LeftPanel.editableColumn.el
2081 changed : function(str, doRefresh) {
2082 if (!this.activePath) {
2085 var iter = new Gtk.TreeIter();
2086 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2088 this.el.set_value(iter, 1, '' +str);
2089 this.el.set_value(iter, 3, '' + this.toShort(str));
2090 var type = this.getIterValue(iter, 4);
2092 this.el.set_value(iter, 5, type + ' : ' + str);
2093 // update the tree...
2095 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2097 deleteSelected : function() {
2098 var data = this.toJS();
2099 var iter = new Gtk.TreeIter();
2100 var s = this.get('/LeftPanel.view').selection;
2101 s.get_selected(this.el, iter);
2104 var gval = new GObject.Value('');
2105 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2107 var val = gval.value;
2108 if (val[0] == '!') {
2110 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2113 delete data.listeners[ val.substring(1)];
2114 if (!XObject.keys(data.listeners).length) {
2115 delete data.listeners;
2119 if (typeof(data[val]) == 'undefined') {
2127 this.get('/LeftTree.model').changed(data, true);
2130 getIterValue : function(iter, col) {
2131 var gval = new GObject.Value('');
2132 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2133 return '' + gval.value;
2135 getType : function(treepath) {
2136 return this.getValue(treepath, 4);
2138 getValue : function(treepath_str, col)
2140 // get's the value in a row.. - keys - returns string, values - formats it..
2142 var iter = new Gtk.TreeIter();
2143 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2145 var gval = new GObject.Value('');
2146 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2147 var val = '' + gval.value;
2152 var type = this.getType(this.el.get_path(iter).to_string());
2153 //print("TYPE: " +type + " - val:" + val);
2154 switch(type.toLowerCase()) {
2158 return parseFloat(val); // Nan ?? invalid!!?
2161 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2163 return val == 'true' ? true : false;
2165 var nv = parseFloat(val);
2166 if (!isNaN(nv) && (val == ''+nv)) {
2174 XObject.prototype.init.call(this);
2175 this.el.set_column_types ( 6, [
2176 GObject.TYPE_STRING, // 0 real key
2177 GObject.TYPE_STRING, // 1 real value
2178 GObject.TYPE_STRING, // 2 visable key
2179 GObject.TYPE_STRING, // 3 visable value
2180 GObject.TYPE_STRING, // 4 need to store type of!!!
2181 GObject.TYPE_STRING // 5 tooltip
2185 load : function(ar) {
2188 this.get('/RightEditor').el.hide();
2195 var provider = this.get('/LeftTree').getPaleteProvider();
2196 var iter = new Gtk.TreeIter();
2199 var keys = XObject.keys(ar);
2201 ar.listeners = ar.listeners || {};
2203 for (var i in ar.listeners ) {
2204 this.el.append(iter);
2205 var p = this.el.get_path(iter).to_string();
2208 this.el.set_value(iter, 0, '!'+ i );
2209 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2210 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2212 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2213 this.el.set_value(iter, 4, 'function');
2214 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2220 keys.forEach(function(i) {
2221 if (typeof(ar[i]) == 'object') {
2225 var type = provider.findType(ar, i, ar[i]);
2227 _this.el.append(iter);
2228 var p = _this.el.get_path(iter).to_string();
2230 _this.el.set_value(iter, 0, ''+i);
2231 _this.el.set_value(iter, 1, '' + ar[i]);
2232 _this.el.set_value(iter, 2, ''+i);
2233 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2234 _this.el.set_value(iter, 4, ''+type);
2235 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2239 startEditing : function(path,col) {
2240 // alled by menu 'edit' currently..
2242 * start editing path (or selected if not set..)
2243 * @param {String|false} path (optional) treepath to edit - selected tree gets
2244 * edited by default.
2245 * @param {Number} 0 or 1 (optional)- column to edit.
2247 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2249 if (typeof(path) == 'string') {
2250 tp = new Gtk.TreePath.from_string(path);
2252 var iter = new Gtk.TreeIter();
2253 var s = this.get('/LeftPanel.view').selection;
2254 s.get_selected(this.el, iter);
2255 tp = this.el.get_path(iter);
2256 path = tp.to_string();
2260 // which colum is to be edited..
2263 // not sure what this does..
2265 if (typeof(col) == 'undefined') {
2266 var k = this.getValue(path, 0);
2268 colObj = (!k.length || k == '|') ?
2269 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2271 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2274 // make sure the pulldown is set correctly..
2275 // not really needed for second col...
2276 var showEditor = false;
2279 var provider = this.get('/LeftTree').getPaleteProvider();
2280 var type = this.get('/LeftPanel.model').getType(path);
2281 var opts = provider.findOptions(type);
2282 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2284 if (opts === false) {
2285 this.get('/LeftPanel').editableColumn.setOptions([]);
2286 renderer.has_entry = true;
2288 this.get('/LeftPanel').editableColumn.setOptions(opts);
2289 renderer.has_entry = false;/// - pulldowns do not have entries
2291 // determine if we should use the Text editor...
2292 var keyname = this.getValue(path, 0);
2293 var data_value = this.getValue(path, 1);
2295 if ((keyname[0] == '|') ||
2297 (typeof(data_value) == 'string' ) &&
2298 ( data_value.match(/function/g) || data_value.match(/\n/g) || (data_value.length > 20))
2302 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2307 this.get('/BottomPane').el.hide();
2308 this.get('/RightEditor').el.hide();
2313 this.activePath = false;
2314 GLib.timeout_add(0, 1, function() {
2316 _this.get('/BottomPane').el.show();
2317 _this.get('/RightEditor').el.show();
2318 _this.get('/RightEditor.view').load( _this.getValue(path, 1) );
2321 //e.remove_widget();
2322 _this.activePath = path ;
2332 // iter now has row...
2333 GLib.timeout_add(0, 100, function() {
2334 _this.activePath = path;
2335 colObj.items[0].el.editable = true; // esp. need for col 0..
2336 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2346 var iter = new Gtk.TreeIter();
2347 this.get('/LeftPanel.model').el.get_iter_first(iter);
2352 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2355 ar.listeners = ar.listeners || {};
2356 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2359 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2362 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2368 //print(JSON.stringify(ar));
2372 toShort : function(str) {
2373 var a = typeof(str) == 'string' ? str.split("\n") : [];
2374 return a.length > 1 ? a[0] + '....' : '' + str;
2378 xtype: Gtk.TreeViewColumn,
2379 pack : "append_column",
2381 XObject.prototype.init.call(this);
2383 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2384 this.get('/LeftPanel').propertyColumn = this;
2389 xtype: Gtk.CellRendererText,
2390 pack : "pack_start",
2392 editing_started : function (self, editable, path) {
2394 this.get('/LeftPanel.model').activePath = path;
2397 edited : function (self, object, p0) {
2398 var model = this.get('/LeftPanel.model');
2399 var path = model.activePath;
2400 var iter = new Gtk.TreeIter();
2401 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2402 model.el.set_value(iter, 0, p0);
2403 model.el.set_value(iter, 2, p0);
2405 model.activePath = false;
2407 this.get('/LeftTree.model').changed(model.toJS(), true);
2408 this.el.editable = false;
2415 xtype: Gtk.TreeViewColumn,
2416 pack : "append_column",
2419 XObject.prototype.init.call(this);
2420 this.el.add_attribute(this.items[0].el , 'text', 3 );
2421 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2422 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2423 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2425 this.get('/LeftPanel').editableColumn= this;
2427 setOptions : function(ar) {
2428 var m = this.items[0].el.model;
2430 var iter = new Gtk.TreeIter();
2431 ar.forEach(function(i) {
2434 m.set_value(iter, 0, i);
2440 xtype: Gtk.CellRendererCombo,
2442 edited : function (self, object, p0) {
2443 this.get('/LeftPanel').editing = false;
2444 var ap = this.get('/LeftPanel.model').activePath
2445 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2446 this.get('/LeftPanel.model').changed(p0, true);
2447 this.get('/LeftPanel.model').activePath = false;
2448 this.el.editable = false;
2450 editing_started : function (self, editable, path) {
2451 this.get('/LeftPanel').editing = true;
2452 // console.log('editing started');
2453 // r.has_entry = false;
2455 this.el.editable = false; // make sure it's not editor...
2459 pack : "pack_start",
2464 XObject.prototype.init.call(this);
2465 this.el.model = new Gtk.ListStore();
2466 this.el.model.set_column_types ( 1, [
2467 GObject.TYPE_STRING // 0 real key
2478 id : "LeftPanelPopup",
2481 xtype: Gtk.MenuItem,
2485 activate : function (self) {
2486 this.get('/LeftPanel.model').deleteSelected();
2491 xtype: Gtk.MenuItem,
2495 activate : function (self) {
2496 this.get('/LeftPanel.model').startEditing(false, 0);
2509 xtype: Gtk.ScrolledWindow,
2510 pack : "pack_end,false,true,0",
2512 shadow_type : Gtk.ShadowType.IN,
2514 XObject.prototype.init.call(this);
2515 XObject.prototype.init.call(this);
2516 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2517 this.el.set_size_request ( 150, -1 );
2520 activeElement : false,
2521 hideWin : function() {
2528 if (this.get('/Window.left').el.position < 160) {
2531 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2538 xtype: Gtk.TreeView,
2540 cursor_changed : function (self) {
2541 var iter = new Gtk.TreeIter();
2543 //console.log('changed');
2544 var m = this.get('model');
2545 if (!this.selection){
2546 this.selection = this.el.get_selection();
2549 var s = this.selection;
2550 if (!s.get_selected(m.el, iter)) {
2553 var tp = m.el.get_path(iter).to_string();
2558 var key = m.getValue(tp, 0);
2560 var type = m.getValue(tp, 1);
2561 var skel = m.getValue(tp, 3);
2562 var etype = m.getValue(tp, 5);
2565 this.get('/MidPropTree').hideWin();
2567 if (type.toLowerCase() == 'function') {
2569 if (etype != 'events') {
2573 this.get('/LeftPanel.model').add({
2581 // has dot in name, and is boolean???? this does not make sense..
2582 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2586 this.get('/LeftPanel.model').add( {
2596 enable_tree_lines : true,
2597 headers_visible : false,
2599 XObject.prototype.init.call(this);
2601 var description = new Pango.FontDescription.c_new();
2602 description.set_size(8000);
2603 this.el.modify_font(description);
2605 //this.selection = this.el.get_selection();
2606 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2615 xtype: Gtk.ListStore,
2618 getValue : function(treepath, col)
2620 var tp = new Gtk.TreePath.from_string (treepath);
2621 var iter = new Gtk.TreeIter();
2622 this.el.get_iter (iter, tp);
2623 var value = new GObject.Value('');
2624 this.el.get_value(iter, col, value);
2629 XObject.prototype.init.call(this);
2630 this.el.set_column_types ( 6, [
2631 GObject.TYPE_STRING, // real key
2632 GObject.TYPE_STRING, // real type
2633 GObject.TYPE_STRING, // docs ?
2634 GObject.TYPE_STRING, // visable desc
2635 GObject.TYPE_STRING, // function desc
2636 GObject.TYPE_STRING // element type (event|prop)
2640 showData : function(type) {
2642 if (!this.get('/MidPropTree').activeElement || !type) {
2643 return; // no active element
2646 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2647 var palete = this.get('/LeftTree').getPaleteProvider();
2651 Seed.print('Showing right?');
2652 if (!this.get('/MidPropTree').shown) {
2654 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2655 this.get('/MidPropTree').el.show();
2656 this.get('/MidPropTree').shown = true;
2659 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2660 return a.name > b.name ? 1 : -1;
2662 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2663 // console.dump(elementList);
2666 var iter = new Gtk.TreeIter();
2667 for(var i =0 ; i < elementList.length; i++) {
2668 var p=elementList[i];
2669 this.el.append(iter);
2670 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2671 //GObject.TYPE_STRING, // real key
2672 // GObject.TYPE_STRING, // real type
2673 // GObject.TYPE_STRING, // docs ?
2674 // GObject.TYPE_STRING // func def?
2677 this.el.set_value(iter, 0, p.name);
2678 this.el.set_value(iter, 1, p.type);
2679 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2680 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2681 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2682 this.el.set_value(iter, 5, type);
2689 xtype: Gtk.TreeViewColumn,
2691 this.el = new Gtk.TreeViewColumn();
2692 this.parent.el.append_column(this.el);
2694 XObject.prototype.init.call(this);
2695 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2700 xtype: Gtk.CellRendererText,
2701 pack : "pack_start,true"
2725 xtype: Gtk.Notebook,
2726 pack : "pack_start,true,true",
2727 id : "view-help-nb",
2729 XObject.prototype.init.call(this);
2730 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2731 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2735 xtype: Gtk.Notebook,
2736 id : "view-notebook",
2740 XObject.prototype.init.call(this);
2741 this.el.set_current_page(0);
2742 //print("SET LABEL?")
2743 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2744 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2750 id : "RightBrowser",
2754 xtype: Gtk.ScrolledWindow,
2757 XObject.prototype.init.call(this);
2758 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2760 shadow_type : Gtk.ShadowType.IN,
2763 xtype: WebKit.WebView,
2765 load_finished : function (self, object) {
2766 print("load finished");
2767 // print("load_finished"); return;
2768 // if (this.ready) { // dont do it twice!
2771 if (!this.inspectorShown) {
2772 this.el.get_inspector().show();
2773 this.inspectorShown = true;
2778 if (this.pendingRedraw) {
2779 this.pendingRedraw = false;
2780 this.refreshRequired = true;
2782 //var js = this.get('/LeftTree.model').toJS();
2783 //if (js && js[0]) {
2784 // this.renderJS(js[0]);
2788 script_alert : function (self, object, p0) {
2791 return true; // do not display anything...
2793 console_message : function (self, object, p0, p1) {
2795 // console.log(object);
2796 if (!object.match(/^\{/)) {
2798 //this.get('/Terminal').feed(object);
2799 return true; // do not handle!!! -> later maybe in console..
2801 // console.log(object);
2802 var val = JSON.parse(object);
2804 if (typeof(val['hover-node']) != 'undefined') {
2805 this.activeNode = val['hover-node'];
2806 console.log('active node: ' + this.activeNode);
2811 if (typeof(val['id']) != 'undefined') {
2812 // this.activeNode = val['id'];
2813 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2814 if (!tg || typeof(tg[0]) == 'undefined') {
2817 print("SELECT node " + tg[0]);
2819 this.get('/LeftTree.view').selectNode(tg[0]);
2823 if (ret && typeof(val['set']) != 'undefined') {
2824 this.get('/LeftPanel.model').add({
2828 //console.log('active node: ' + this.activeNode);
2831 //Seed.print('a:'+a);
2832 //Seed.print('b:'+b);
2833 //Seed.print('c:'+c);
2836 drag_motion : function (w, ctx, x, y, time, ud) {
2837 // console.log('DRAG MOTION');
2839 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2840 this.targetData = [];
2841 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2843 // A) find out from drag all the places that node could be dropped.
2844 var src = Gtk.drag_get_source_widget(ctx);
2845 if (!src.dropList) {
2846 Gdk.drag_status(ctx, 0, time);
2849 // b) get what we are over.. (from activeNode)
2850 // tree is empty.. - list should be correct..
2851 if (!this.get('/LeftTree.model').currentTree) {
2852 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2856 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2858 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2861 Gdk.drag_status(ctx, 0,time);
2862 this.get('/LeftTree.view').highlight(false);
2866 // if we have a target..
2867 // -> highlight it! (in browser)
2868 // -> highlight it! (in tree)
2870 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2871 this.get('/LeftTree.view').highlight(tg);
2872 this.targetData = tg;
2873 // for tree we should handle this...
2876 drag_drop : function (w, ctx, x, y,time, ud) {
2877 print("TARGET: drag-drop");
2878 var is_valid_drop_site = true;
2883 w, /* will receive 'drag-data-received' signal */
2884 ctx, /* represents the current state of the DnD */
2885 this.get('/Window').atoms["STRING"], /* the target type we want */
2886 time /* time stamp */
2890 /* No target offered by source => error */
2893 return is_valid_drop_site;
2895 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2897 print("Browser: drag-data-received");
2898 var delete_selection_data = false;
2899 vardnd_success = false;
2900 /* Deal with what we are given from source */
2901 if( sel_data && sel_data.length ) {
2903 if (ctx.action == Gdk.DragAction.ASK) {
2904 /* Ask the user to move or copy, then set the ctx action. */
2907 if (ctx.action == Gdk.DragAction.MOVE) {
2908 delete_selection_data = true;
2910 var source = Gtk.drag_get_source_widget(ctx);
2912 print("Browser: source.DRAGDATA? " + source.dragData);
2913 if (this.targetData) {
2914 print(this.targetData);
2915 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2924 if (dnd_success == false)
2926 Seed.print ("DnD data transfer failed!\n");
2929 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2932 create_web_view : function (self, object) {
2933 print("CREATE WEB VIEW");
2934 return null; //new WebKit.WebView();
2940 XObject.prototype.init.call(this);
2941 // this may not work!?
2942 var settings = this.el.get_settings();
2943 settings.enable_developer_extras = true;
2945 // this was an attempt to change the url perms.. did not work..
2946 // settings.enable_file_access_from_file_uris = true;
2947 // settings.enable_offline_web_application_cache - true;
2948 // settings.enable_universal_access_from_file_uris = true;
2952 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
2953 _this.get('/BottomPane.inspector').el.show();
2954 return _this.get('/BottomPane.inspector').el;
2958 // FIXME - base url of script..
2959 // we need it so some of the database features work.
2960 this.el.load_html_string( "Render not ready" ,
2961 //fixme - should be a config option!
2962 // or should we catch stuff and fix it up..
2963 'http://localhost/app.Builder/'
2967 //this.el.open('file:///' + __script_path__ + '/../builder.html');
2971 this.el, /* widget that will accept a drop */
2972 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2973 null, /* lists of target to support */
2974 0, /* size of list */
2975 Gdk.DragAction.COPY /* what to do with data after dropped */
2978 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2979 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2981 GLib.timeout_add_seconds(0, 1, function() {
2982 // print("run refresh?");
2989 renderJS : function(data) {
2990 this.refreshRequired = true;
2992 runRefresh : function()
2994 // this is run every 2 seconds from the init..
2998 if (!this.refreshRequired) {
2999 // print("no refresh required");
3003 if (this.lastRedraw) {
3004 // do not redraw if last redraw was less that 5 seconds ago.
3005 if (((new Date()) - this.lastRedraw) < 5000) {
3013 if (!this.get('/Window.LeftTree').getActiveFile()) {
3016 this.refreshRequired = false;
3017 // print("HTML RENDERING");
3019 this.get('/BottomPane').el.show();
3020 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3023 var js = this.get('/LeftTree.model').toJS();
3024 if (!js || !js.length) {
3031 var project = this.get('/Window.LeftTree').getActiveFile().project;
3032 //print (project.fn);
3033 // set it to non-empty.
3034 project.runhtml = project.runhtml || '';
3035 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3038 this.runhtml = this.runhtml || '';
3040 if (project.runhtml != this.runhtml) {
3041 // then we need to reload the browser using
3042 // load_html_string..
3044 // then trigger a redraw once it's loaded..
3045 this.pendingRedraw = true;
3046 var runhtml = '<script type="text/javascript">' + "\n" ;
3047 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3048 runhtml += '</script>'+ "\n" ;
3050 this.runhtml = project.runhtml;
3051 // need to modify paths
3055 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3056 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3057 print("LOAD HTML " + html);
3058 this.el.load_html_string( html ,
3059 //fixme - should be a config option!
3060 'http://localhost/app.Builder/'
3063 // should trigger load_finished! - which in truns shoudl set refresh Required;
3069 this.renderedData = data;
3070 var str = JSON.stringify(data) ;
3073 console.log('not loaded yet');
3075 this.lastRedraw = new Date();
3077 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3078 print( "before render" + this.lastRedraw);
3079 print( "after render" + (new Date()));
3089 id : "RightGtkView",
3091 redraw : function() {
3092 this.highlightWidget = false;
3093 print("REDRAW CALLED");
3094 this.activePath = this.get('/LeftTree').getActivePath();
3095 if (this.renderedEl) {
3096 print("QUEUE DRAW CALLING");
3097 this.renderedEl.queue_draw();
3100 renderJS : function(data, withDebug)
3102 this.highlightWidget = false;
3104 this.withDebug = false;
3105 while (this.get('view').el.get_children().length) {
3106 var c = this.get('view').el.get_children()[0];
3107 this.get('view').el.remove(c);
3114 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3115 // in theory tree is actually window..
3118 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3124 this.get('view').el.set_size_request(
3125 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3127 if (this.renderedEl) {
3128 this.renderedEl.set_size_request(
3129 tree.default_width || 600,
3130 tree.default_height || 400
3133 this.get('view').el.show_all();
3138 showInWindow : function() {
3139 print("GET PROEJCT");
3140 var pr = this.get('/LeftProjectTree').getActiveProject();
3142 console.log(pr.paths);
3145 var src= this.buildJS(
3146 this.get('/LeftTree.model').toJS()[0],
3151 //var x = new imports.sandbox.Context();
3155 Seed.check_syntax('var e = ' + src);
3158 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3159 this.get('/Terminal').feed(console._dump(e)+"\n");
3161 var lines = src.split("\n");
3162 var start = Math.max(0, e.line - 10);
3163 var end = Math.min(lines.length, e.line + 10);
3164 for (var i =start ; i < end; i++) {
3166 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3169 this.get('/Terminal').feed(lines[i] + "\n");
3176 this.get('/BottomPane').el.set_current_page(1);
3177 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3178 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3179 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3181 var _top = x.get_global_object()._top;
3183 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3185 if (_top.el.popup) {
3186 _top.el.popup(null, null, null, null, 3, null);
3190 viewAdd : function(item, par)
3192 // does something similar to xobject..
3193 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3195 if (item.pack===false || item.pack === 'false') { // no ;
3198 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3199 var type = item['|xns'] + '.' + item['xtype'];
3201 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3204 var ns = imports.gi[item['|xns']];
3205 var ctr = ns[item['xtype']];
3207 for(var k in item) {
3209 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3224 if (k[0] == '|' && typeof(kv) == 'string') {
3226 if (kv.match(new RegExp('function'))) {
3229 print("WASL " + k + '=' + kv);
3231 eval( 'kv = ' + kv);
3232 } catch(e) { continue; }
3235 // print(k + '=' + kv);
3237 if (k[0] == '|') { // should be boolean or number..
3239 //print(k + '=' + kv);
3242 if (k == 'show_tabs') { // force tab showing for notebooks.
3245 print(k + '=' + typeof(kv) + " : " + kv);
3251 var el = new ctr(ctr_args);
3253 print("PACK" + item.pack);
3254 //console.dump(item.pack);
3261 if (typeof(item.pack) == 'string') {
3263 item.pack.split(',').forEach(function(e, i) {
3265 if (e == 'false') { args.push( false); return; }
3266 if (e == 'true') { args.push( true); return; }
3267 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3270 //print(args.join(","));
3272 pack_m = args.shift();
3274 pack_m = item.pack.shift();
3279 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3281 name: "ArgumentError",
3282 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3283 "ADDING : " + item.id + " " + el
3292 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3293 //Seed.print('args: ' + args.length);
3295 par[pack_m].apply(par, args);
3299 item.items = item.items || [];
3300 item.items.forEach(function(ch,n) {
3302 print ("type:" + type);
3304 print ("ch.pack:" + ch.pack);
3305 if (type == 'Gtk.Table' && ch.pack == 'add') {
3306 var c = n % item.n_columns;
3307 var r = Math.floor(n/item.n_columns);
3308 ch.pack = [ 'attach', c, c+1, r, r+1,
3309 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3310 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3311 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3312 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3316 _this.viewAdd(ch, el);
3321 // add the signal handlers.
3322 // is it a widget!?!!?
3328 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3329 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3330 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3331 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3332 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3342 widgetDragDropEvent : function() {
3343 print("WIDGET DRAGDROP");
3346 widgetDragMotionEvent : function() {
3347 print("WIDGET DRAGMOTION");
3350 widgetExposeEvent : function(w, evt, ud, item) {
3352 if (this.inRender) {
3356 if ( this.highlightWidget) {
3357 this.inRender = true;
3358 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3359 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3361 this.inRender = false;
3366 if (this.activePath != item.xtreepath) {
3370 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3371 // work out the coords of the window..
3373 var dr = widget.window;
3374 this.gc = (new Gdk.GC.c_new(dr));
3375 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3376 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3380 var r = evt.expose.area;
3381 // console.dump([r.x, r.y, r.width, r.height ] );
3383 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3384 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3385 // happens with gtkscrollview embedded stuff..
3386 var np =this.activePath.split(':');
3388 this.activePath = np.join(':');
3389 this.renderedEl.queue_draw();
3405 this.inRender = true;
3408 this.highlightWidget = widget;
3413 // print("DRAW BOX");
3414 //console.dump(this.box);
3415 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3416 this.inRender = false;
3419 widgetPressEvent : function(w,e,u,d) {
3420 if (this.get('view').pressed) {
3423 this.get('view').pressed = true;
3424 print("WIDGET PRESS " + d.xtreepath );
3425 this.get('/LeftTree.view').selectNode( d.xtreepath );
3428 widgetReleaseEvent : function() {
3429 this.get('view').pressed = false;
3435 pack : "pack_start,false,true,0",
3439 pack : "pack_start,false,false,0",
3440 label : "Run The Application",
3442 button_press_event : function (self, event) {
3443 // call render on left tree - with special option!?!
3445 //print("GET PROEJCT");
3446 var pr = this.get('/LeftProjectTree').getActiveProject();
3449 for (var i in pr.paths) {
3453 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3454 this.get('/Terminal').feed("RUN DIR:" + dir);
3456 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3457 , false,false,false);
3458 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3459 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3469 xtype: Gtk.ScrolledWindow,
3472 shadow_type : Gtk.ShadowType.IN,
3474 XObject.prototype.init.call(this);
3475 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3479 xtype: Gtk.EventBox,
3480 pack : "add_with_viewport",
3482 XObject.prototype.init.call(this);
3483 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3484 red: 0x9F00, green: 0xB800 , blue : 0xA800
3492 XObject.prototype.init.call(this);
3493 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3494 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3499 xtype: Gtk.EventBox,
3502 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3503 XObject.prototype.init.call(this);
3507 this.el, /* widget that will accept a drop */
3508 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3509 null, /* lists of target to support */
3510 0, /* size of list */
3511 Gdk.DragAction.COPY /* what to do with data after dropped */
3514 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3515 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3518 getActiveNode : function(x,y)
3520 // workout what node is here..
3521 return '0'; // top..
3525 drag_motion : function (self, ctx, x, y, time) {
3527 // A) find out from drag all the places that node could be dropped.
3528 var src = Gtk.drag_get_source_widget(ctx);
3529 if (!src.dropList) {
3530 Gdk.drag_status(ctx, 0, time);
3533 // b) get what we are over.. (from activeNode)
3534 // tree is empty.. - list should be correct..
3535 if (!this.get('/LeftTree.model').currentTree) {
3536 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3540 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3541 var activeNode = this.getActiveNode(x, y);
3544 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3547 Gdk.drag_status(ctx, 0,time);
3548 this.get('/LeftTree.view').highlight(false);
3552 // if we have a target..
3553 // -> highlight it! (in browser)
3554 // -> highlight it! (in tree)
3556 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3557 this.get('/LeftTree.view').highlight(tg);
3558 this.targetData = tg;
3559 // for tree we should handle this...
3562 drag_drop : function (self,ctx, x, y, time) {
3563 Seed.print("TARGET: drag-drop");
3564 var is_valid_drop_site = true;
3569 self, /* will receive 'drag-data-received' signal */
3570 ctx, /* represents the current state of the this.gDnD */
3571 this.get('/Window').atoms["STRING"], /* the target type we want */
3572 time /* time stamp */
3576 /* No target offered by source => error */
3579 return is_valid_drop_site;
3582 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3584 Seed.print("GtkView: drag-data-received");
3585 var delete_selection_data = false;
3586 var dnd_success = false;
3587 /* Deal with what we are given from source */
3588 if( sel_data && sel_data.length ) {
3590 if (ctx.action == Gdk.DragAction.ASK) {
3591 /* Ask the user to move or copy, then set the ctx action. */
3594 if (ctx.action == Gdk.DragAction.MOVE) {
3595 delete_selection_data = true;
3597 var source = Gtk.drag_get_source_widget(ctx);
3599 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3600 if (this.targetData) {
3601 Seed.print(this.targetData);
3602 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3611 if (dnd_success == false)
3613 Seed.print ("DnD data transfer failed!\n");
3616 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3619 button_press_event : function (self, event) {
3620 this.pressed = false;
3636 xtype: Gtk.ScrolledWindow,
3641 var file = this.get('/LeftTree').getActiveFile();
3645 var activeEl = this.get('/LeftTree').getActiveElement();
3646 var xtype = file.guessName( activeEl )
3647 if (!xtype || !xtype.length) {
3650 //this.get('/Window.view-help-nb').el.set_current_page(1);
3652 // get the active element being edited.
3653 var helpurl = file.getHelpUrl(xtype);
3655 // now load the help info in the page..
3656 this.get('help-view').el.open(helpurl);
3660 xtype: WebKit.WebView,
3664 XObject.prototype.init.call(this);
3665 this.get('/Window.help-view').el.open(
3666 "http://devel.akbkhome.com/seed/");
3678 xtype: Gtk.Notebook,
3682 XObject.prototype.init.call(this);
3683 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3684 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3685 this.el.set_tab_label(this.items[2].el, new Gtk.Label({ label : "Inspector" }));
3689 xtype: Gtk.ScrolledWindow,
3694 xtype: GtkSource.View,
3698 XObject.prototype.init.call(this);
3699 var description = Pango.Font.description_from_string("monospace")
3700 description.set_size(8000);
3701 this.el.modify_font(description);
3704 load : function(str) {
3706 // show the help page for the active node..
3707 this.get('/Help').show();
3710 this.get('/BottomPane').el.set_current_page(0);
3711 this.el.get_buffer().set_text(str, str.length);
3712 var lm = GtkSource.LanguageManager.get_default();
3714 this.el.get_buffer().set_language(lm.get_language('js'));
3715 var buf = this.el.get_buffer();
3716 var cursor = buf.get_mark("insert");
3717 var iter= new Gtk.TextIter;
3718 buf.get_iter_at_mark(iter, cursor);
3720 iter.set_line_offset(4);
3721 buf.move_mark(cursor, iter);
3724 cursor = buf.get_mark("selection_bound");
3725 iter= new Gtk.TextIter;
3726 buf.get_iter_at_mark(iter, cursor);
3728 iter.set_line_offset(4);
3729 buf.move_mark(cursor, iter);
3731 this.el.grab_focus();
3733 insert_spaces_instead_of_tabs : true,
3736 show_line_numbers : true,
3739 xtype: GtkSource.Buffer,
3741 changed : function (self) {
3742 var s = new Gtk.TextIter();
3743 var e = new Gtk.TextIter();
3744 this.el.get_start_iter(s);
3745 this.el.get_end_iter(e);
3746 var str = this.el.get_text(s,e,true);
3748 Seed.check_syntax('var e = ' + str);
3750 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3751 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3753 //print("SYNTAX ERROR IN EDITOR");
3758 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3759 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3762 this.get('/LeftPanel.model').changed( str , false);
3772 xtype: Gtk.ScrolledWindow,
3776 xtype: Vte.Terminal,
3779 feed : function(istr) {
3780 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3781 // we should make ourselves visable!!!
3782 this.get('/BottomPane').el.show();
3783 this.get('/BottomPane').el.set_current_page(1);
3785 this.el.feed(str ,str.length);
3787 scroll_on_output : true,
3789 XObject.prototype.init.call(this);
3790 this.el.set_size (80, 1000);
3792 scrollback_lines : 1000
3797 xtype: Gtk.ScrolledWindow,
3801 xtype: WebKit.WebView,
3813 pack : "pack_start,false,false",
3817 this.get('buttonbar').el.show();
3818 this.get('viewbox').el.hide();
3819 print("TRIED TO HIDE");
3822 this.get('buttonbar').el.hide();
3823 this.get('viewbox').el.show();
3824 // this.get('model').expanded();
3836 pack : "pack_start,false,true",
3838 clicked : function (self) {
3839 this.get('/RightPalete').show();
3846 stock : Gtk.STOCK_GOTO_FIRST,
3847 icon_size : Gtk.IconSize.MENU
3857 XObject.prototype.init.call(this);
3858 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3861 enter_notify_event : function (self, event) {
3862 this.get('/RightPalete').show();
3876 pack : "pack_start,false,true",
3885 pack : "pack_start,false,true",
3887 clicked : function (self) {
3888 this.get('/RightPalete').hide();
3895 stock : Gtk.STOCK_GOTO_LAST,
3896 icon_size : Gtk.IconSize.MENU
3903 xtype: Gtk.ScrolledWindow,
3906 XObject.prototype.init.call(this);
3907 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3908 this.el.set_size_request(-1,200);
3910 shadow_type : Gtk.ShadowType.IN,
3913 xtype: Gtk.TreeView,
3916 XObject.prototype.init.call(this);
3917 this.el.set_size_request(150,-1);
3918 // set_reorderable: [1]
3920 var description = new Pango.FontDescription.c_new();
3921 description.set_size(8000);
3922 this.el.modify_font(description);
3924 this.selection = this.el.get_selection();
3925 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3926 // this.selection.signal['changed'].connect(function() {
3927 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3929 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3931 Gtk.drag_source_set (
3932 this.el, /* widget will be drag-able */
3933 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3934 null, /* lists of target to support */
3935 0, /* size of list */
3936 Gdk.DragAction.COPY /* what to do with data after dropped */
3938 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3940 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3941 Gtk.drag_source_add_text_targets(this.el);
3943 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3944 targets = new Gtk.TargetList();
3945 targets.add( LeftTree.atoms["STRING"], 0, 0);
3946 targets.add_text_targets( 1 );
3947 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3949 //if you want to allow text to be output elsewhere..
3950 //Gtk.drag_source_add_text_targets(this.el);
3954 headers_visible : false,
3955 enable_tree_lines : true,
3957 drag_begin : function (self, ctx) {
3958 // we could fill this in now...
3959 Seed.print('SOURCE: drag-begin');
3963 var iter = new Gtk.TreeIter();
3964 var s = this.selection;
3965 s.get_selected(this.get('/RightPalete.model').el, iter);
3966 var path = this.get('/RightPalete.model').el.get_path(iter);
3968 var pix = this.el.create_row_drag_icon ( path);
3971 Gtk.drag_set_icon_pixmap (ctx,
3978 var value = new GObject.Value('');
3979 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3980 if (!this.get('/RightPalete').provider) {
3983 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3984 this.el.dragData = value.value;
3991 drag_data_get : function (self, drag_context, selection_data, info, time) {
3992 //Seed.print('Palete: drag-data-get: ' + target_type);
3993 if (this.el.dragData && this.el.dragData.length ) {
3994 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3998 //this.el.dragData = "TEST from source widget";
4002 drag_end : function (self, drag_context) {
4003 Seed.print('SOURCE: drag-end');
4004 this.el.dragData = false;
4005 this.el.dropList = false;
4006 this.get('/LeftTree.view').highlight(false);
4012 xtype: Gtk.ListStore,
4015 XObject.prototype.init.call(this);
4016 this.el.set_column_types ( 2, [
4017 GObject.TYPE_STRING, // title
4018 GObject.TYPE_STRING // tip
4023 load : function(tr,iter)
4028 //console.log('Project tree load: ' + tr.length);
4029 var citer = new Gtk.TreeIter();
4030 //this.insert(citer,iter,0);
4031 for(var i =0 ; i < tr.length; i++) {
4034 this.el.append(citer);
4036 this.el.insert(citer,iter,-1);
4041 this.el.set_value(citer, 0, '' + r ); // title
4043 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4044 //if (r.cn && r.cn.length) {
4045 // this.load(r.cn, citer);
4051 getValue : function (iter, col) {
4052 var gval = new GObject.Value('');
4053 this.el.get_value(iter, col ,gval);
4060 xtype: Gtk.TreeViewColumn,
4061 pack : "append_column",
4063 XObject.prototype.init.call(this);
4064 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4068 xtype: Gtk.CellRendererText,
4090 XObject.cache['/Window'] = Window;