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], true);
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];
807 this.file.items = this.toJS(false, false);
808 print ("TO JS in " + ((new Date()) - d) + "ms");
809 // print("AFTER CHANGED");
810 //console.dump(this.file.items);
812 this.currentTree = this.file.items[0];
813 //console.log(this.file.toSource());
816 print("REDNER BROWSER?!");
817 this.get('/LeftTree').renderView();
819 var pm = this.get('/RightPalete.model');
820 if (!this.get('/RightPalete').provider) {
826 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
827 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
831 deleteSelected : function() {
832 this.get('/LeftTree.view').blockChanges = true;
833 var old_iter = new Gtk.TreeIter();
834 var s = this.get('/LeftTree.view').selection;
835 s.get_selected(this.el, old_iter);
836 var path = this.el.get_path(old_iter).to_string();
838 this.activePath= false;
841 this.activePath= false;
842 var iter = new Gtk.TreeIter();
843 this.el.get_iter_from_string(iter, path);
844 this.el.remove(iter);
846 // rebuild treemap. -- depreciated.!!
849 //this.toJS(null, true) // does not do anything?
850 this.activePath= false;
851 this.changed(false,true);
852 this.get('/LeftTree.view').blockChanges = false;
854 dropNode : function(target_data, node) {
856 // console.dump(node);
857 // console.dump(target_data);
858 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
860 print("add " + tp + "@" + target_data[1] );
863 if (tp && target_data[1] < 2) { // before or after..
864 var ar = target_data[0].split(':');
866 parent = new Gtk.TreePath.from_string( ar.join(':') );
869 var n_iter = new Gtk.TreeIter();
870 var iter_par = new Gtk.TreeIter();
871 var iter_after = after ? new Gtk.TreeIter() : false;
875 if (parent !== false) {
876 this.el.get_iter(iter_par, parent);
883 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
884 this.el.get_iter(iter_after, after);
885 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
886 n_iter, iter_par, iter_after);
889 this.el.append(n_iter, iter_par);
893 if (typeof(node) == 'string') {
894 var ar = node.split('.');
895 var xtype = ar.pop();
898 '|xns' : ar.join('.'),
901 if (target_data.length == 3 && target_data[2].length) {
902 node['*prop'] = target_data[2];
904 node = this.get('/DialogTemplateSelect').show(node);
907 // work out what kind of packing to use..
908 if (typeof(node.pack) == 'undefined' && parent !== false) {
909 var pal = this.get('/LeftTree').getPaleteProvider();
910 if (pal.name == 'Gtk') {
911 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
912 var cname = pal.guessName(node);
913 node.pack = pal.getDefaultPack(pname, cname);
924 // load children - if it has any..
927 this.load(xitems, n_iter);
928 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
930 if (tp && (xitems || after)) {
931 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
933 // wee need to get the empty proptypes from somewhere..
935 //var olditer = this.activeIter;
936 this.activePath = this.el.get_path(n_iter).to_string();
938 // changed actually set's the node data..
939 this.changed(node, true);
943 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
945 //Builder.MidPropTree._model.load(node);
946 //Builder.MidPropTree._win.hideWin();
947 //Builder.LeftPanel._model.load( node);
951 findDropNode : function(treepath_str, targets) {
953 // this is used by the dragdrop code in the roo version AFAIR..
955 var path = treepath_str.replace(/^builder-/, '');
956 // treemap is depreciated... - should really check if model has any entries..
958 if (!this.el.iter_n_children(null)) {
960 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
962 print("FIND treepath: " + path);
963 //console.dump(this.treemap);
965 if (!treepath_str.match(/^builder-/)) {
966 return []; // nothing!
968 if (targets === true) {
971 return this.findDropNodeByPath(path,targets)
973 findDropNodeByPath : function(treepath_str, targets, pref) {
974 var path = treepath_str + ''; // dupe it..
975 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
977 //console.dump(this.treemap);
978 while (path.length) {
979 print("LOOKING FOR PATH: " + path);
980 var node_data = this.singleNodeToJS(path);
981 if (node_data === false) {
982 print("node not found");
986 var xname = this.get('/LeftTree.model').file.guessName(node_data);
989 targets.forEach(function(tg) {
993 if ((tg == xname) ) {
996 if (tg.indexOf(xname +':') === 0) {
998 prop = tg.split(':').pop();
1003 if (last) { // pref is after/before..
1004 // then it's after last
1006 return []; // do not allow..
1008 return [ last, pref , prop];
1011 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1013 var par = path.split(':');
1016 path = par.join(':');
1022 getIterValue : function (iter, col) {
1023 var gval = new GObject.Value('');
1024 this.el.get_value(iter, col ,gval);
1030 XObject.prototype.init.call(this);
1031 this.el.set_column_types ( 3, [
1032 GObject.TYPE_STRING, // title
1033 GObject.TYPE_STRING, // tip
1034 GObject.TYPE_STRING // source..
1037 listAllTypes : function() {
1038 var s = this.get('/LeftTree.view').selection;
1039 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1041 if (s.count_selected_rows() > 0) {
1042 var iter = new Gtk.TreeIter();
1043 s.get_selected(this.el, iter);
1045 // set some properties of the tree for use by the dropped element.
1046 var value = new GObject.Value('');
1047 this.el.get_value(iter, 2, value);
1048 var data = JSON.parse(value.value);
1051 var xname = this.get('/LeftTree.model').file.guessName(data);
1052 console.log('selected:' + xname);
1056 return []; // could not find it..
1064 li.forEach(function(el) {
1065 // this is specific to roo!!!?
1066 if (!el) { // skip empty?
1069 var fullpath = _this.file.guessName(el);
1070 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1075 if (el.items && el.items.length) {
1084 addall([this.currentTree]);
1086 // only if we have nothing, should we add '*top'
1090 //console.log('all types in tree');
1091 //console.dump(ret);
1096 load : function(tr,iter)
1098 var citer = new Gtk.TreeIter();
1099 //this.insert(citer,iter,0);
1100 for(var i =0 ; i < tr.length; i++) {
1102 this.el.insert(citer,iter,-1);
1104 this.el.append(citer);
1107 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1108 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1109 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1110 if (tr[i].items && tr[i].items.length) {
1111 this.load(tr[i].items, citer);
1115 loadFile : function(f) {
1121 console.log('missing file');
1125 // load the file if not loaded..
1126 if (f.items === false) {
1128 f.loadItems(function() {
1134 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1136 if (f.items.length && typeof(f.items[0]) == 'string') {
1138 this.get('/RightEditor').el.show();
1139 this.get('/RightEditor.view').load( f.items[0]);
1143 print(JSON.stringify(f.items, null,4));
1144 //console.dump(f.items);
1146 this.get('/LeftTree.view').el.expand_all();
1148 if (!f.items.length) {
1151 this.get('/Window.leftvpaned').el.set_position(80);
1153 this.get('/LeftTree.view').el.set_cursor(
1154 new Gtk.TreePath.from_string('0'), null, false);
1158 this.get('/Window.leftvpaned').el.set_position(200);
1162 //print("hide right editior");
1163 this.get('/RightEditor').el.hide();
1164 //print("set current tree");
1165 this.currentTree = this.toJS(false, false)[0];
1166 //console.dump(this.currentTree);
1167 this.currentTree = this.currentTree || { items: [] };
1168 this.get('/LeftTree').renderView();
1169 //console.dump(this.map);
1170 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1171 var pm = this.get('/RightPalete.model');
1172 // set up provider..
1174 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1176 if (!this.get('/RightPalete').provider) {
1177 print ("********* PALETE PROVIDER MISSING?!!");
1179 this.get('/LeftTree').renderView();
1181 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1185 this.get('/Window.view-notebook').el.set_current_page(
1186 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1189 moveNode : function(target_data, action) {
1190 //print("MOVE NODE");
1191 // console.dump(target_data);
1192 var old_iter = new Gtk.TreeIter();
1193 var s = this.get('/LeftTree.view').selection;
1194 s.get_selected(this.el, old_iter);
1195 var node = this.nodeToJS(old_iter,false);
1196 //console.dump(node);
1199 // needs to drop first, otherwise the target_data
1200 // treepath will be invalid.
1202 this.dropNode(target_data, node);
1203 if (action & Gdk.DragAction.MOVE) {
1204 // print("REMOVING OLD NODE");
1205 this.el.remove(old_iter);
1209 this.activePath= false;
1210 this.changed(false,true);
1212 nodeTip : function(c) {
1213 var ret = this.nodeTitle(c,true);
1219 if (!i.length || i[0] != '|') {
1225 if (typeof(c[i]) != 'string') {
1228 //print("prop : " + i + ':' + c[i]);
1229 if (!c[i].match(new RegExp('function'))) {
1232 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1236 ret+="\n\nMethods:" + funcs;
1241 nodeTitle : function(c, renderfull) {
1244 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1245 if (sr) txt.push('<s>');
1246 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1248 if (renderfull && c['|xns']) {
1249 txt.push(c['|xns']);
1252 if (c.xtype) { txt.push(c.xtype); }
1253 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1254 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1255 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1258 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1259 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1260 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1261 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1262 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1263 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1264 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1265 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1266 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1268 // for flat classes...
1269 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1270 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1273 if (sr) txt.push('</s>');
1274 return (txt.length == 0 ? "Element" : txt.join(" "));
1276 nodeToJS : function (treepath, with_id)
1279 var iter = treepath; // API used to be iter here..
1280 if (typeof(iter) == 'string') {
1281 iter = new Gtk.TreeIter();
1282 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1286 var par = new Gtk.TreeIter();
1287 var iv = this.getIterValue(iter, 2);
1288 // print("IV" + iv);
1289 var k = JSON.parse(iv);
1290 if (k.json && !this.el.iter_parent( par, iter )) {
1295 var treepath_str = this.el.get_path(iter).to_string();
1296 // not sure how we can handle mixed id stuff..
1297 if (typeof(k.id) == 'undefined') {
1298 k.id = 'builder-'+ treepath_str ;
1302 this.treemap[ treepath_str ] = k;
1303 k.xtreepath = treepath_str ;
1306 if (this.el.iter_has_child(iter)) {
1307 citer = new Gtk.TreeIter();
1308 this.el.iter_children(citer, iter);
1309 k.items = this.toJS(citer,with_id);
1313 nodeToJSON : function(c) {
1321 return JSON.stringify(o);
1323 singleNodeToJS : function (treepath)
1325 var iter = new Gtk.TreeIter();
1326 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1330 var iv = this.getIterValue(iter, 2);
1332 return JSON.parse(iv);
1335 toJS : function(treepath, with_id)
1337 //Seed.print("WITHID: "+ with_id);
1338 var iter = treepath; // API used to be iter here..
1339 if (typeof(iter) == 'string') {
1340 iter = new Gtk.TreeIter();
1341 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1350 iter = new Gtk.TreeIter();
1351 if (!this.el.get_iter_first(iter)) {
1361 var k = this.nodeToJS(iter, with_id);
1365 if (!this.el.iter_next(iter)) {
1370 if (treepath === false) {
1372 return JSON.parse(JSON.stringify(ar));
1376 // convert the list into a json string..
1382 xtype: Gtk.TreeViewColumn,
1383 pack : "append_column",
1385 XObject.prototype.init.call(this);
1386 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1390 xtype: Gtk.CellRendererText,
1400 id : "LeftTreeMenu",
1403 xtype: Gtk.MenuItem,
1405 label : "Delete Element",
1407 activate : function (self) {
1409 this.get('/LeftTree.model').deleteSelected();
1414 xtype: Gtk.MenuItem,
1416 activate : function (self) {
1418 var tree = this.get('/LeftTree');
1419 var model = this.get('/LeftTree.model');
1420 var el = tree.getActivePath();
1422 var js = model.toJS(el, false);
1423 // print(JSON.stringify(js[0], null,4));
1424 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1429 label : "Save as Template",
1439 id : "LeftProjectTree",
1440 showNoProjectSelected : function() {
1441 this.get('/StandardErrorDialog').show("Select a Project first.");
1443 getActiveProject : function() {
1444 return this.project;
1447 leave_notify_event : function (self, event) {
1454 pack : "pack_start,false,false",
1457 xtype: Gtk.ComboBox,
1460 XObject.prototype.init.call(this);
1461 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1463 getValue : function() {
1464 var ix = this.el.get_active();
1468 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1469 if (typeof(data[ix]) == 'undefined') {
1474 setValue : function(fn)
1478 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1479 data.forEach(function(n, ix) {
1487 changed : function (self) {
1488 var fn = this.getValue();
1489 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1490 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1495 xtype: Gtk.CellRendererText,
1496 pack : "pack_start,true",
1500 xtype: Gtk.ListStore,
1503 XObject.prototype.init.call(this);
1504 this.el.set_column_types ( 2, [
1505 GObject.TYPE_STRING, // real key
1506 GObject.TYPE_STRING // real type
1510 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1512 pm.on('changed', function() {
1513 print("caught changed hook on project manager - reloading data");
1514 _this.loadData(pm.projects);
1518 loadData : function(data) {
1519 var ov = this.get('/LeftProjectTree.combo').getValue();
1521 var iter = new Gtk.TreeIter();
1523 data.forEach(function(p) {
1528 el.set_value(iter, 0, p.fn);
1529 el.set_value(iter, 1, p.name);
1533 this.get('/LeftProjectTree.combo').setValue(ov);
1542 xtype: Gtk.ScrolledWindow,
1544 shadow_type : Gtk.ShadowType.IN,
1546 XObject.prototype.init.call(this);
1547 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1551 xtype: Gtk.TreeView,
1553 cursor_changed : function (self) {
1554 var iter = new Gtk.TreeIter();
1556 if (this.selection.count_selected_rows() < 1) {
1557 //XN.get('Builder.LeftTree.model').
1558 this.get('/LeftTree.model').load( false);
1562 var model = this.get('/LeftProjectTree.model');
1563 //console.log('changed');
1564 var s = this.selection;
1565 s.get_selected(model, iter);
1566 value = new GObject.Value('');
1567 model.el.get_value(iter, 2, value);
1569 console.log(value.value);// id..
1571 var file = this.get('/LeftProjectTree').project.getById(value.value);
1578 var nb = this.get('/LeftTopPanel.expander');
1579 nb.el.expanded = false;
1581 //nb.listeners.activate.call(nb);
1582 //_expander.el.set_expanded(false);
1584 var ltm = this.get('/LeftTree.model');
1592 enable_tree_lines : true,
1593 headers_visible : false,
1595 XObject.prototype.init.call(this);
1596 var description = new Pango.FontDescription.c_new();
1597 description.set_size(8000);
1598 this.el.modify_font(description);
1600 this.selection = this.el.get_selection();
1601 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1605 xtype: Gtk.TreeStore,
1609 XObject.prototype.init.call(this);
1610 this.el.set_column_types ( 3, [
1611 GObject.TYPE_STRING, // title
1612 GObject.TYPE_STRING, // tip
1613 GObject.TYPE_STRING // id..
1617 loadProject : function(pr) {
1618 print("LOAD PROJECT");
1624 this.get('/LeftProjectTree').project = pr;
1625 this.load(pr.toTree());
1626 this.get('/LeftProjectTree.view').el.expand_all();
1628 load : function(tr,iter) {
1629 // console.dump(tr);
1630 console.log('Project tree load: ' + tr.length);
1631 var citer = new Gtk.TreeIter();
1632 //this.insert(citer,iter,0);
1635 tr.forEach(function (r) {
1637 _this.el.append(citer);
1639 _this.el.insert(citer,iter,-1);
1641 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1642 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1643 _this.el.set_value(citer, 2, '' + r.id ); //id
1644 if (r.cn && r.cn.length) {
1645 _this.load(r.cn, citer);
1650 getValue : function(iter, col) {
1651 var gval = new GObject.Value('');
1652 this.el.get_value(iter, col ,gval);
1653 return '' + gval.value;
1657 xtype: Gtk.TreeViewColumn,
1658 pack : "append_column",
1660 XObject.prototype.init.call(this);
1661 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1665 xtype: Gtk.CellRendererText,
1685 pack : "pack_start,false,true,0",
1692 button_press_event : function (self, event) {
1693 this.get('/MidPropTree.model').showData('props');
1705 stock : Gtk.STOCK_ADD,
1706 icon_size : Gtk.IconSize.MENU
1721 button_press_event : function (self, event) {
1722 this.get('/MidPropTree.model').showData('events');
1734 stock : Gtk.STOCK_ADD,
1735 icon_size : Gtk.IconSize.MENU
1750 button_press_event : function (self, ev) {
1751 var p = this.get('/AddPropertyPopup');
1755 p.el.set_screen(Gdk.Screen.get_default());
1757 p.el.popup(null, null, null, null, 3, ev.button.time);
1769 stock : Gtk.STOCK_ADD,
1770 icon_size : Gtk.IconSize.MENU
1782 id : "AddPropertyPopup",
1785 xtype: Gtk.MenuItem,
1787 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1790 activate : function (self) {
1792 this.get('/LeftPanel.model').add( {
1803 xtype: Gtk.MenuItem,
1805 tooltip_markup : "Add what type of packing is to be used",
1808 activate : function (self) {
1810 this.get('/LeftPanel.model').add( {
1820 xtype: Gtk.MenuItem,
1822 tooltip_markup : "Override the init method",
1825 activate : function (self) {
1827 this.get('/LeftPanel.model').add( {
1830 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1837 xtype: Gtk.SeparatorMenuItem,
1841 xtype: Gtk.MenuItem,
1843 tooltip_markup : "Add a user defined string property",
1846 activate : function (self) {
1848 this.get('/LeftPanel.model').add( {
1858 xtype: Gtk.MenuItem,
1860 tooltip_markup : "Add a user defined number property",
1863 activate : function (self) {
1865 this.get('/LeftPanel.model').add( {
1875 xtype: Gtk.MenuItem,
1877 tooltip_markup : "Add a user defined boolean property",
1880 activate : function (self) {
1882 this.get('/LeftPanel.model').add( {
1892 xtype: Gtk.SeparatorMenuItem,
1896 xtype: Gtk.MenuItem,
1898 tooltip_markup : "Add a user function boolean property",
1901 activate : function (self) {
1903 this.get('/LeftPanel.model').add( {
1906 val : "function() {\n \n}\n",
1919 xtype: Gtk.ScrolledWindow,
1924 XObject.prototype.init.call(this);
1925 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1927 shadow_type : Gtk.ShadowType.IN,
1930 xtype: Gtk.TreeView,
1932 button_press_event : function (self, ev) {
1937 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1938 return false; //not on a element.
1942 if (ev.type == Gdk.EventType.BUTTON_PRESS && ev.button.button == 3) {
1944 if (res.column.title == 'value' && this.get('/LeftPanel').editing) {
1947 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1948 var p = this.get('/LeftPanelPopup');
1953 p.el.set_screen(Gdk.Screen.get_default());
1955 p.el.popup(null, null, null, null, 3, ev.button.time);
1956 //Seed.print("click:" + res.column.title);
1963 if (res.column.title != 'value') {
1964 // XObject.error("column is not value?");
1965 return false; // ignore.. - key click.. ??? should we do this??
1968 // currently editing???
1969 // if ( this.activePath) {
1971 // this.activePath = false;
1973 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1974 this.get('/LeftPanel').editing = false;
1976 // XObject.error("Currently editing?");
1980 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1982 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1984 // get options for this type -- this is to support option lists etc..
1985 var provider = this.get('/LeftTree').getPaleteProvider();
1986 var opts = provider.findOptions(type);
1988 if (opts === false) {
1990 this.get('/LeftPanel').editableColumn.setOptions([]);
1991 renderer.has_entry = true;
1993 this.get('/LeftPanel').editableColumn.setOptions(opts);
1994 renderer.has_entry = false;
1996 this.get('/LeftPanel.model').startEditing(res.path.to_string(), 1);
1998 //Seed.print("click" + ev.type);
1999 //console.dump(res);
2008 enable_tree_lines : true,
2009 headers_visible : false,
2011 XObject.prototype.init.call(this);
2013 this.selection = this.el.get_selection();
2014 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2017 var description = new Pango.FontDescription.c_new();
2018 description.set_size(8000);
2019 this.el.modify_font(description);
2023 xtype: Gtk.TreeStore,
2027 add : function(info) {
2028 // info includes key, val, skel, etype..
2030 type = info.type.toLowerCase();
2031 var data = this.toJS();
2033 if (info.etype == 'events') {
2034 data.listeners = data.listeners || { };
2035 if (typeof(data.listeners[info.key]) != 'undefined') {
2036 return; //already set!
2039 if (typeof(data[info.key]) != 'undefined') {
2044 if (typeof(info.val) == 'undefined') {
2047 if (info.type.toLowerCase() == 'boolean') {
2050 if (type == 'number') {
2058 if (info.etype == 'events') {
2060 data.listeners[info.key] = info.val;
2063 data[info.key] = info.val;
2067 var map = this.load(data);
2069 // flag it as changed to the interface..
2071 this.get('/LeftTree.model').changed(data, true);
2074 this.startEditing(map[k]);
2077 LeftPanel.get('view').el.row_activated(
2078 new Gtk.TreePath.from_string(map[k]),
2079 LeftPanel.editableColumn.el
2083 changed : function(str, doRefresh) {
2084 if (!this.activePath) {
2087 var iter = new Gtk.TreeIter();
2088 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2090 this.el.set_value(iter, 1, '' +str);
2091 this.el.set_value(iter, 3, '' + this.toShort(str));
2092 var type = this.getIterValue(iter, 4);
2094 this.el.set_value(iter, 5, type + ' : ' + str);
2095 // update the tree...
2097 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2099 deleteSelected : function() {
2100 var data = this.toJS();
2101 var iter = new Gtk.TreeIter();
2102 var s = this.get('/LeftPanel.view').selection;
2103 s.get_selected(this.el, iter);
2106 var gval = new GObject.Value('');
2107 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2109 var val = gval.value;
2110 if (val[0] == '!') {
2112 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2115 delete data.listeners[ val.substring(1)];
2116 if (!XObject.keys(data.listeners).length) {
2117 delete data.listeners;
2121 if (typeof(data[val]) == 'undefined') {
2129 this.get('/LeftTree.model').changed(data, true);
2132 getIterValue : function(iter, col) {
2133 var gval = new GObject.Value('');
2134 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2135 return '' + gval.value;
2137 getType : function(treepath) {
2138 return this.getValue(treepath, 4);
2140 getValue : function(treepath_str, col)
2142 // get's the value in a row.. - keys - returns string, values - formats it..
2144 var iter = new Gtk.TreeIter();
2145 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2147 var gval = new GObject.Value('');
2148 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2149 var val = '' + gval.value;
2154 var type = this.getType(this.el.get_path(iter).to_string());
2155 //print("TYPE: " +type + " - val:" + val);
2156 switch(type.toLowerCase()) {
2160 return parseFloat(val); // Nan ?? invalid!!?
2163 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2165 return val == 'true' ? true : false;
2167 var nv = parseFloat(val);
2168 if (!isNaN(nv) && (val == ''+nv)) {
2176 XObject.prototype.init.call(this);
2177 this.el.set_column_types ( 6, [
2178 GObject.TYPE_STRING, // 0 real key
2179 GObject.TYPE_STRING, // 1 real value
2180 GObject.TYPE_STRING, // 2 visable key
2181 GObject.TYPE_STRING, // 3 visable value
2182 GObject.TYPE_STRING, // 4 need to store type of!!!
2183 GObject.TYPE_STRING // 5 tooltip
2187 load : function(ar) {
2190 this.get('/RightEditor').el.hide();
2197 var provider = this.get('/LeftTree').getPaleteProvider();
2198 var iter = new Gtk.TreeIter();
2201 var keys = XObject.keys(ar);
2203 ar.listeners = ar.listeners || {};
2205 for (var i in ar.listeners ) {
2206 this.el.append(iter);
2207 var p = this.el.get_path(iter).to_string();
2210 this.el.set_value(iter, 0, '!'+ i );
2211 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2212 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2214 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2215 this.el.set_value(iter, 4, 'function');
2216 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2222 keys.forEach(function(i) {
2223 if (typeof(ar[i]) == 'object') {
2227 var type = provider.findType(ar, i, ar[i]);
2229 _this.el.append(iter);
2230 var p = _this.el.get_path(iter).to_string();
2232 _this.el.set_value(iter, 0, ''+i);
2233 _this.el.set_value(iter, 1, '' + ar[i]);
2234 _this.el.set_value(iter, 2, ''+i);
2235 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2236 _this.el.set_value(iter, 4, ''+type);
2237 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2241 startEditing : function(path,col) {
2242 // alled by menu 'edit' currently..
2244 * start editing path (or selected if not set..)
2245 * @param {String|false} path (optional) treepath to edit - selected tree gets
2246 * edited by default.
2247 * @param {Number} 0 or 1 (optional)- column to edit.
2249 // fix tp to be the 'treepath' string (eg. 0/1/2...)
2251 if (typeof(path) == 'string') {
2252 tp = new Gtk.TreePath.from_string(path);
2254 var iter = new Gtk.TreeIter();
2255 var s = this.get('/LeftPanel.view').selection;
2256 s.get_selected(this.el, iter);
2257 tp = this.el.get_path(iter);
2258 path = tp.to_string();
2262 // which colum is to be edited..
2265 // not sure what this does..
2267 if (typeof(col) == 'undefined') {
2268 var k = this.getValue(path, 0);
2270 colObj = (!k.length || k == '|') ?
2271 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2273 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2276 // make sure the pulldown is set correctly..
2277 // not really needed for second col...
2278 var showEditor = false;
2281 var provider = this.get('/LeftTree').getPaleteProvider();
2282 var type = this.get('/LeftPanel.model').getType(path);
2283 var opts = provider.findOptions(type);
2284 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2286 if (opts === false) {
2287 this.get('/LeftPanel').editableColumn.setOptions([]);
2288 renderer.has_entry = true;
2290 this.get('/LeftPanel').editableColumn.setOptions(opts);
2291 renderer.has_entry = false;/// - pulldowns do not have entries
2293 // determine if we should use the Text editor...
2294 var keyname = this.getValue(path, 0);
2295 var data_value = this.getValue(path, 1);
2297 if ((keyname[0] == '|') ||
2299 (typeof(data_value) == 'string' ) &&
2300 ( data_value.match(/function/g) || data_value.match(/\n/g)) // || (data_value.length > 20))
2304 print("SHOW EDITOR" + showEditor ? 'YES' :'no');
2309 this.get('/BottomPane').el.hide();
2310 this.get('/RightEditor').el.hide();
2315 this.activePath = false;
2316 GLib.timeout_add(0, 1, function() {
2318 _this.get('/BottomPane').el.show();
2319 _this.get('/RightEditor').el.show();
2320 _this.get('/RightEditor.view').load( _this.getValue(path, 1) );
2323 //e.remove_widget();
2324 _this.activePath = path ;
2334 // iter now has row...
2335 GLib.timeout_add(0, 100, function() {
2336 _this.activePath = path;
2337 colObj.items[0].el.editable = true; // esp. need for col 0..
2338 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2348 var iter = new Gtk.TreeIter();
2349 this.get('/LeftPanel.model').el.get_iter_first(iter);
2354 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2357 ar.listeners = ar.listeners || {};
2358 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2361 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2364 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2370 //print(JSON.stringify(ar));
2374 toShort : function(str) {
2375 var a = typeof(str) == 'string' ? str.split("\n") : [];
2376 return a.length > 1 ? a[0] + '....' : '' + str;
2380 xtype: Gtk.TreeViewColumn,
2381 pack : "append_column",
2383 XObject.prototype.init.call(this);
2385 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2386 this.get('/LeftPanel').propertyColumn = this;
2391 xtype: Gtk.CellRendererText,
2392 pack : "pack_start",
2394 editing_started : function (self, editable, path) {
2396 this.get('/LeftPanel.model').activePath = path;
2399 edited : function (self, object, p0) {
2400 var model = this.get('/LeftPanel.model');
2401 var path = model.activePath;
2402 var iter = new Gtk.TreeIter();
2403 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2404 model.el.set_value(iter, 0, p0);
2405 model.el.set_value(iter, 2, p0);
2407 model.activePath = false;
2409 this.get('/LeftTree.model').changed(model.toJS(), true);
2410 this.el.editable = false;
2417 xtype: Gtk.TreeViewColumn,
2418 pack : "append_column",
2421 XObject.prototype.init.call(this);
2422 this.el.add_attribute(this.items[0].el , 'text', 3 );
2423 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2424 //this.el.add_attribute(this.items[0].el , 'editable', 3 );
2425 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2427 this.get('/LeftPanel').editableColumn= this;
2429 setOptions : function(ar) {
2430 var m = this.items[0].el.model;
2432 var iter = new Gtk.TreeIter();
2433 ar.forEach(function(i) {
2436 m.set_value(iter, 0, i);
2442 xtype: Gtk.CellRendererCombo,
2444 edited : function (self, object, p0) {
2445 this.get('/LeftPanel').editing = false;
2446 var ap = this.get('/LeftPanel.model').activePath
2447 print("EDITED? " + ap + " - p:" + p0 + " t:" + p0);
2448 this.get('/LeftPanel.model').changed(p0, true);
2449 this.get('/LeftPanel.model').activePath = false;
2450 this.el.editable = false;
2452 editing_started : function (self, editable, path) {
2453 this.get('/LeftPanel').editing = true;
2454 // console.log('editing started');
2455 // r.has_entry = false;
2457 this.el.editable = false; // make sure it's not editor...
2461 pack : "pack_start",
2466 XObject.prototype.init.call(this);
2467 this.el.model = new Gtk.ListStore();
2468 this.el.model.set_column_types ( 1, [
2469 GObject.TYPE_STRING // 0 real key
2480 id : "LeftPanelPopup",
2483 xtype: Gtk.MenuItem,
2487 activate : function (self) {
2488 this.get('/LeftPanel.model').deleteSelected();
2493 xtype: Gtk.MenuItem,
2497 activate : function (self) {
2498 this.get('/LeftPanel.model').startEditing(false, 0);
2511 xtype: Gtk.ScrolledWindow,
2512 pack : "pack_end,false,true,0",
2514 shadow_type : Gtk.ShadowType.IN,
2516 XObject.prototype.init.call(this);
2517 XObject.prototype.init.call(this);
2518 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2519 this.el.set_size_request ( 150, -1 );
2522 activeElement : false,
2523 hideWin : function() {
2530 if (this.get('/Window.left').el.position < 160) {
2533 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2540 xtype: Gtk.TreeView,
2542 cursor_changed : function (self) {
2543 var iter = new Gtk.TreeIter();
2545 //console.log('changed');
2546 var m = this.get('model');
2547 if (!this.selection){
2548 this.selection = this.el.get_selection();
2551 var s = this.selection;
2552 if (!s.get_selected(m.el, iter)) {
2555 var tp = m.el.get_path(iter).to_string();
2560 var key = m.getValue(tp, 0);
2562 var type = m.getValue(tp, 1);
2563 var skel = m.getValue(tp, 3);
2564 var etype = m.getValue(tp, 5);
2567 this.get('/MidPropTree').hideWin();
2569 if (type.toLowerCase() == 'function') {
2571 if (etype != 'events') {
2575 this.get('/LeftPanel.model').add({
2583 // has dot in name, and is boolean???? this does not make sense..
2584 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2588 this.get('/LeftPanel.model').add( {
2598 enable_tree_lines : true,
2599 headers_visible : false,
2601 XObject.prototype.init.call(this);
2603 var description = new Pango.FontDescription.c_new();
2604 description.set_size(8000);
2605 this.el.modify_font(description);
2607 //this.selection = this.el.get_selection();
2608 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2617 xtype: Gtk.ListStore,
2620 getValue : function(treepath, col)
2622 var tp = new Gtk.TreePath.from_string (treepath);
2623 var iter = new Gtk.TreeIter();
2624 this.el.get_iter (iter, tp);
2625 var value = new GObject.Value('');
2626 this.el.get_value(iter, col, value);
2631 XObject.prototype.init.call(this);
2632 this.el.set_column_types ( 6, [
2633 GObject.TYPE_STRING, // real key
2634 GObject.TYPE_STRING, // real type
2635 GObject.TYPE_STRING, // docs ?
2636 GObject.TYPE_STRING, // visable desc
2637 GObject.TYPE_STRING, // function desc
2638 GObject.TYPE_STRING // element type (event|prop)
2642 showData : function(type) {
2644 if (!this.get('/MidPropTree').activeElement || !type) {
2645 return; // no active element
2648 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2649 var palete = this.get('/LeftTree').getPaleteProvider();
2653 Seed.print('Showing right?');
2654 if (!this.get('/MidPropTree').shown) {
2656 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2657 this.get('/MidPropTree').el.show();
2658 this.get('/MidPropTree').shown = true;
2661 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2662 return a.name > b.name ? 1 : -1;
2664 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2665 // console.dump(elementList);
2668 var iter = new Gtk.TreeIter();
2669 for(var i =0 ; i < elementList.length; i++) {
2670 var p=elementList[i];
2671 this.el.append(iter);
2672 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2673 //GObject.TYPE_STRING, // real key
2674 // GObject.TYPE_STRING, // real type
2675 // GObject.TYPE_STRING, // docs ?
2676 // GObject.TYPE_STRING // func def?
2679 this.el.set_value(iter, 0, p.name);
2680 this.el.set_value(iter, 1, p.type);
2681 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2682 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2683 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2684 this.el.set_value(iter, 5, type);
2691 xtype: Gtk.TreeViewColumn,
2693 this.el = new Gtk.TreeViewColumn();
2694 this.parent.el.append_column(this.el);
2696 XObject.prototype.init.call(this);
2697 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2702 xtype: Gtk.CellRendererText,
2703 pack : "pack_start,true"
2727 xtype: Gtk.Notebook,
2728 pack : "pack_start,true,true",
2729 id : "view-help-nb",
2731 XObject.prototype.init.call(this);
2732 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2733 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2737 xtype: Gtk.Notebook,
2738 id : "view-notebook",
2742 XObject.prototype.init.call(this);
2743 this.el.set_current_page(0);
2744 //print("SET LABEL?")
2745 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2746 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2752 id : "RightBrowser",
2757 pack : "pack_start,false,true,0",
2762 clicked : function (self) {
2763 this.get('/RightBrowser.view').renderJS(null,true);
2767 pack : "pack_start,false,false,0"
2770 xtype: Gtk.CheckButton,
2772 toggled : function (self, state) {
2773 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
2778 label : "Auto Redraw On",
2779 pack : "pack_start,false,false,0"
2784 xtype: Gtk.ScrolledWindow,
2787 XObject.prototype.init.call(this);
2788 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2790 shadow_type : Gtk.ShadowType.IN,
2793 xtype: WebKit.WebView,
2795 load_finished : function (self, object) {
2796 print("load finished");
2797 // print("load_finished"); return;
2798 // if (this.ready) { // dont do it twice!
2801 if (!this.inspectorShown) {
2802 this.el.get_inspector().show();
2803 this.inspectorShown = true;
2808 if (this.pendingRedraw) {
2809 this.pendingRedraw = false;
2810 this.refreshRequired = true;
2812 //var js = this.get('/LeftTree.model').toJS();
2813 //if (js && js[0]) {
2814 // this.renderJS(js[0]);
2818 script_alert : function (self, object, p0) {
2821 return true; // do not display anything...
2823 console_message : function (self, object, p0, p1) {
2825 // console.log(object);
2826 if (!object.match(/^\{/)) {
2828 //this.get('/Terminal').feed(object);
2829 return true; // do not handle!!! -> later maybe in console..
2831 // console.log(object);
2832 var val = JSON.parse(object);
2834 if (typeof(val['hover-node']) != 'undefined') {
2835 this.activeNode = val['hover-node'];
2836 console.log('active node: ' + this.activeNode);
2841 if (typeof(val['id']) != 'undefined') {
2842 // this.activeNode = val['id'];
2843 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2844 if (!tg || typeof(tg[0]) == 'undefined') {
2847 print("SELECT node " + tg[0]);
2849 this.get('/LeftTree.view').selectNode(tg[0]);
2853 if (ret && typeof(val['set']) != 'undefined') {
2854 this.get('/LeftPanel.model').add({
2858 //console.log('active node: ' + this.activeNode);
2861 //Seed.print('a:'+a);
2862 //Seed.print('b:'+b);
2863 //Seed.print('c:'+c);
2866 drag_motion : function (w, ctx, x, y, time, ud) {
2867 // console.log('DRAG MOTION');
2869 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2870 this.targetData = [];
2871 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2873 // A) find out from drag all the places that node could be dropped.
2874 var src = Gtk.drag_get_source_widget(ctx);
2875 if (!src.dropList) {
2876 Gdk.drag_status(ctx, 0, time);
2879 // b) get what we are over.. (from activeNode)
2880 // tree is empty.. - list should be correct..
2881 if (!this.get('/LeftTree.model').currentTree) {
2882 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2886 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2888 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2891 Gdk.drag_status(ctx, 0,time);
2892 this.get('/LeftTree.view').highlight(false);
2896 // if we have a target..
2897 // -> highlight it! (in browser)
2898 // -> highlight it! (in tree)
2900 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2901 this.get('/LeftTree.view').highlight(tg);
2902 this.targetData = tg;
2903 // for tree we should handle this...
2906 drag_drop : function (w, ctx, x, y,time, ud) {
2907 print("TARGET: drag-drop");
2908 var is_valid_drop_site = true;
2913 w, /* will receive 'drag-data-received' signal */
2914 ctx, /* represents the current state of the DnD */
2915 this.get('/Window').atoms["STRING"], /* the target type we want */
2916 time /* time stamp */
2920 /* No target offered by source => error */
2923 return is_valid_drop_site;
2925 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2927 print("Browser: drag-data-received");
2928 var delete_selection_data = false;
2929 vardnd_success = false;
2930 /* Deal with what we are given from source */
2931 if( sel_data && sel_data.length ) {
2933 if (ctx.action == Gdk.DragAction.ASK) {
2934 /* Ask the user to move or copy, then set the ctx action. */
2937 if (ctx.action == Gdk.DragAction.MOVE) {
2938 delete_selection_data = true;
2940 var source = Gtk.drag_get_source_widget(ctx);
2942 print("Browser: source.DRAGDATA? " + source.dragData);
2943 if (this.targetData) {
2944 print(this.targetData);
2945 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2954 if (dnd_success == false)
2956 Seed.print ("DnD data transfer failed!\n");
2959 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2962 create_web_view : function (self, object) {
2963 print("CREATE WEB VIEW");
2964 return null; //new WebKit.WebView();
2971 XObject.prototype.init.call(this);
2972 // this may not work!?
2973 var settings = this.el.get_settings();
2974 settings.enable_developer_extras = true;
2976 // this was an attempt to change the url perms.. did not work..
2977 // settings.enable_file_access_from_file_uris = true;
2978 // settings.enable_offline_web_application_cache - true;
2979 // settings.enable_universal_access_from_file_uris = true;
2983 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
2984 _this.get('/BottomPane.inspector').el.show();
2985 return _this.get('/BottomPane.inspector').el;
2989 // FIXME - base url of script..
2990 // we need it so some of the database features work.
2991 this.el.load_html_string( "Render not ready" ,
2992 //fixme - should be a config option!
2993 // or should we catch stuff and fix it up..
2994 'http://localhost/app.Builder/'
2998 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3002 this.el, /* widget that will accept a drop */
3003 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3004 null, /* lists of target to support */
3005 0, /* size of list */
3006 Gdk.DragAction.COPY /* what to do with data after dropped */
3009 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3010 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3012 GLib.timeout_add_seconds(0, 1, function() {
3013 // print("run refresh?");
3020 renderJS : function(data, force) {
3022 // this is the public redraw call..
3023 // we refresh in a loop privately..
3024 var autodraw = this.get('/RightBrowser.AutoRedraw').el.active;
3025 if (!autodraw && !force) {
3026 print("Skipping redraw - no force, and autodraw off");
3029 this.refreshRequired = true;
3031 runRefresh : function()
3033 // this is run every 2 seconds from the init..
3037 if (!this.refreshRequired) {
3038 // print("no refresh required");
3042 if (this.lastRedraw) {
3043 // do not redraw if last redraw was less that 5 seconds ago.
3044 if (((new Date()) - this.lastRedraw) < 5000) {
3052 if (!this.get('/Window.LeftTree').getActiveFile()) {
3055 this.refreshRequired = false;
3056 // print("HTML RENDERING");
3058 this.get('/BottomPane').el.show();
3059 this.get('/BottomPane').el.set_current_page(2);// webkit inspector
3062 var js = this.get('/LeftTree.model').toJS();
3063 if (!js || !js.length) {
3070 var project = this.get('/Window.LeftTree').getActiveFile().project;
3071 //print (project.fn);
3072 // set it to non-empty.
3073 project.runhtml = project.runhtml || '';
3074 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
3077 this.runhtml = this.runhtml || '';
3079 if ((project.runhtml != this.runhtml) || (this.redraws > 10)) {
3080 // then we need to reload the browser using
3081 // load_html_string..
3083 // then trigger a redraw once it's loaded..
3084 this.pendingRedraw = true;
3085 var runhtml = '<script type="text/javascript">' + "\n" ;
3086 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
3087 runhtml += '</script>'+ "\n" ;
3089 this.runhtml = project.runhtml;
3090 // need to modify paths
3094 var html = imports.File.File.read(__script_path__ + '/../builder.html');
3095 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
3096 print("LOAD HTML " + html);
3097 this.el.load_html_string( html ,
3098 //fixme - should be a config option!
3099 'http://localhost/app.Builder/'
3102 // should trigger load_finished! - which in truns shoudl set refresh Required;
3108 this.renderedData = data;
3109 var str = JSON.stringify(data) ;
3112 console.log('not loaded yet');
3114 this.lastRedraw = new Date();
3116 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
3117 print( "before render" + this.lastRedraw);
3118 print( "after render" + (new Date()));
3128 id : "RightGtkView",
3130 redraw : function() {
3131 this.highlightWidget = false;
3132 print("REDRAW CALLED");
3133 this.activePath = this.get('/LeftTree').getActivePath();
3134 if (this.renderedEl) {
3135 print("QUEUE DRAW CALLING");
3136 this.renderedEl.queue_draw();
3139 renderJS : function(data, withDebug)
3141 this.highlightWidget = false;
3143 this.withDebug = false;
3144 while (this.get('view').el.get_children().length) {
3145 var c = this.get('view').el.get_children()[0];
3146 this.get('view').el.remove(c);
3153 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3154 // in theory tree is actually window..
3157 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3163 this.get('view').el.set_size_request(
3164 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3166 if (this.renderedEl) {
3167 this.renderedEl.set_size_request(
3168 tree.default_width || 600,
3169 tree.default_height || 400
3172 this.get('view').el.show_all();
3177 showInWindow : function() {
3178 print("GET PROEJCT");
3179 var pr = this.get('/LeftProjectTree').getActiveProject();
3181 console.log(pr.paths);
3184 var src= this.buildJS(
3185 this.get('/LeftTree.model').toJS()[0],
3190 //var x = new imports.sandbox.Context();
3194 Seed.check_syntax('var e = ' + src);
3197 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3198 this.get('/Terminal').feed(console._dump(e)+"\n");
3200 var lines = src.split("\n");
3201 var start = Math.max(0, e.line - 10);
3202 var end = Math.min(lines.length, e.line + 10);
3203 for (var i =start ; i < end; i++) {
3205 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3208 this.get('/Terminal').feed(lines[i] + "\n");
3215 this.get('/BottomPane').el.set_current_page(1);
3216 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3217 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3218 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3220 var _top = x.get_global_object()._top;
3222 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3224 if (_top.el.popup) {
3225 _top.el.popup(null, null, null, null, 3, null);
3229 viewAdd : function(item, par)
3231 // does something similar to xobject..
3232 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3234 if (item.pack===false || item.pack === 'false') { // no ;
3237 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3238 var type = item['|xns'] + '.' + item['xtype'];
3240 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3243 var ns = imports.gi[item['|xns']];
3244 var ctr = ns[item['xtype']];
3246 for(var k in item) {
3248 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3263 if (k[0] == '|' && typeof(kv) == 'string') {
3265 if (kv.match(new RegExp('function'))) {
3268 print("WASL " + k + '=' + kv);
3270 eval( 'kv = ' + kv);
3271 } catch(e) { continue; }
3274 // print(k + '=' + kv);
3276 if (k[0] == '|') { // should be boolean or number..
3278 //print(k + '=' + kv);
3281 if (k == 'show_tabs') { // force tab showing for notebooks.
3284 print(k + '=' + typeof(kv) + " : " + kv);
3290 var el = new ctr(ctr_args);
3292 print("PACK" + item.pack);
3293 //console.dump(item.pack);
3300 if (typeof(item.pack) == 'string') {
3302 item.pack.split(',').forEach(function(e, i) {
3304 if (e == 'false') { args.push( false); return; }
3305 if (e == 'true') { args.push( true); return; }
3306 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3309 //print(args.join(","));
3311 pack_m = args.shift();
3313 pack_m = item.pack.shift();
3318 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3320 name: "ArgumentError",
3321 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3322 "ADDING : " + item.id + " " + el
3331 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3332 //Seed.print('args: ' + args.length);
3334 par[pack_m].apply(par, args);
3338 item.items = item.items || [];
3339 item.items.forEach(function(ch,n) {
3341 print ("type:" + type);
3343 print ("ch.pack:" + ch.pack);
3344 if (type == 'Gtk.Table' && ch.pack == 'add') {
3345 var c = n % item.n_columns;
3346 var r = Math.floor(n/item.n_columns);
3347 ch.pack = [ 'attach', c, c+1, r, r+1,
3348 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3349 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3350 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3351 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3355 _this.viewAdd(ch, el);
3360 // add the signal handlers.
3361 // is it a widget!?!!?
3367 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3368 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3369 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3370 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3371 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3381 widgetDragDropEvent : function() {
3382 print("WIDGET DRAGDROP");
3385 widgetDragMotionEvent : function() {
3386 print("WIDGET DRAGMOTION");
3389 widgetExposeEvent : function(w, evt, ud, item) {
3391 if (this.inRender) {
3395 if ( this.highlightWidget) {
3396 this.inRender = true;
3397 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3398 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3400 this.inRender = false;
3405 if (this.activePath != item.xtreepath) {
3409 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3410 // work out the coords of the window..
3412 var dr = widget.window;
3413 this.gc = (new Gdk.GC.c_new(dr));
3414 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3415 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3419 var r = evt.expose.area;
3420 // console.dump([r.x, r.y, r.width, r.height ] );
3422 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3423 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3424 // happens with gtkscrollview embedded stuff..
3425 var np =this.activePath.split(':');
3427 this.activePath = np.join(':');
3428 this.renderedEl.queue_draw();
3444 this.inRender = true;
3447 this.highlightWidget = widget;
3452 // print("DRAW BOX");
3453 //console.dump(this.box);
3454 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3455 this.inRender = false;
3458 widgetPressEvent : function(w,e,u,d) {
3459 if (this.get('view').pressed) {
3462 this.get('view').pressed = true;
3463 print("WIDGET PRESS " + d.xtreepath );
3464 this.get('/LeftTree.view').selectNode( d.xtreepath );
3467 widgetReleaseEvent : function() {
3468 this.get('view').pressed = false;
3474 pack : "pack_start,false,true,0",
3478 pack : "pack_start,false,false,0",
3479 label : "Run The Application",
3481 button_press_event : function (self, event) {
3482 // call render on left tree - with special option!?!
3484 //print("GET PROEJCT");
3485 var pr = this.get('/LeftProjectTree').getActiveProject();
3488 for (var i in pr.paths) {
3492 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3493 this.get('/Terminal').feed("RUN DIR:" + dir);
3495 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3496 , false,false,false);
3497 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3498 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3508 xtype: Gtk.ScrolledWindow,
3511 shadow_type : Gtk.ShadowType.IN,
3513 XObject.prototype.init.call(this);
3514 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3518 xtype: Gtk.EventBox,
3519 pack : "add_with_viewport",
3521 XObject.prototype.init.call(this);
3522 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3523 red: 0x9F00, green: 0xB800 , blue : 0xA800
3531 XObject.prototype.init.call(this);
3532 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3533 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3538 xtype: Gtk.EventBox,
3541 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3542 XObject.prototype.init.call(this);
3546 this.el, /* widget that will accept a drop */
3547 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3548 null, /* lists of target to support */
3549 0, /* size of list */
3550 Gdk.DragAction.COPY /* what to do with data after dropped */
3553 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3554 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3557 getActiveNode : function(x,y)
3559 // workout what node is here..
3560 return '0'; // top..
3564 drag_motion : function (self, ctx, x, y, time) {
3566 // A) find out from drag all the places that node could be dropped.
3567 var src = Gtk.drag_get_source_widget(ctx);
3568 if (!src.dropList) {
3569 Gdk.drag_status(ctx, 0, time);
3572 // b) get what we are over.. (from activeNode)
3573 // tree is empty.. - list should be correct..
3574 if (!this.get('/LeftTree.model').currentTree) {
3575 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3579 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3580 var activeNode = this.getActiveNode(x, y);
3583 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3586 Gdk.drag_status(ctx, 0,time);
3587 this.get('/LeftTree.view').highlight(false);
3591 // if we have a target..
3592 // -> highlight it! (in browser)
3593 // -> highlight it! (in tree)
3595 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3596 this.get('/LeftTree.view').highlight(tg);
3597 this.targetData = tg;
3598 // for tree we should handle this...
3601 drag_drop : function (self,ctx, x, y, time) {
3602 Seed.print("TARGET: drag-drop");
3603 var is_valid_drop_site = true;
3608 self, /* will receive 'drag-data-received' signal */
3609 ctx, /* represents the current state of the this.gDnD */
3610 this.get('/Window').atoms["STRING"], /* the target type we want */
3611 time /* time stamp */
3615 /* No target offered by source => error */
3618 return is_valid_drop_site;
3621 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3623 Seed.print("GtkView: drag-data-received");
3624 var delete_selection_data = false;
3625 var dnd_success = false;
3626 /* Deal with what we are given from source */
3627 if( sel_data && sel_data.length ) {
3629 if (ctx.action == Gdk.DragAction.ASK) {
3630 /* Ask the user to move or copy, then set the ctx action. */
3633 if (ctx.action == Gdk.DragAction.MOVE) {
3634 delete_selection_data = true;
3636 var source = Gtk.drag_get_source_widget(ctx);
3638 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3639 if (this.targetData) {
3640 Seed.print(this.targetData);
3641 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3650 if (dnd_success == false)
3652 Seed.print ("DnD data transfer failed!\n");
3655 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3658 button_press_event : function (self, event) {
3659 this.pressed = false;
3675 xtype: Gtk.ScrolledWindow,
3680 var file = this.get('/LeftTree').getActiveFile();
3684 var activeEl = this.get('/LeftTree').getActiveElement();
3685 var xtype = file.guessName( activeEl )
3686 if (!xtype || !xtype.length) {
3689 //this.get('/Window.view-help-nb').el.set_current_page(1);
3691 // get the active element being edited.
3692 var helpurl = file.getHelpUrl(xtype);
3694 // now load the help info in the page..
3695 this.get('help-view').el.open(helpurl);
3699 xtype: WebKit.WebView,
3703 XObject.prototype.init.call(this);
3704 this.get('/Window.help-view').el.open(
3705 "http://devel.akbkhome.com/seed/");
3717 xtype: Gtk.Notebook,
3721 XObject.prototype.init.call(this);
3722 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3723 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3724 this.el.set_tab_label(this.items[2].el, new Gtk.Label({ label : "Inspector" }));
3728 xtype: Gtk.ScrolledWindow,
3733 xtype: GtkSource.View,
3737 XObject.prototype.init.call(this);
3738 var description = Pango.Font.description_from_string("monospace")
3739 description.set_size(8000);
3740 this.el.modify_font(description);
3743 load : function(str) {
3745 // show the help page for the active node..
3746 this.get('/Help').show();
3749 this.get('/BottomPane').el.set_current_page(0);
3750 this.el.get_buffer().set_text(str, str.length);
3751 var lm = GtkSource.LanguageManager.get_default();
3753 this.el.get_buffer().set_language(lm.get_language('js'));
3754 var buf = this.el.get_buffer();
3755 var cursor = buf.get_mark("insert");
3756 var iter= new Gtk.TextIter;
3757 buf.get_iter_at_mark(iter, cursor);
3759 iter.set_line_offset(4);
3760 buf.move_mark(cursor, iter);
3763 cursor = buf.get_mark("selection_bound");
3764 iter= new Gtk.TextIter;
3765 buf.get_iter_at_mark(iter, cursor);
3767 iter.set_line_offset(4);
3768 buf.move_mark(cursor, iter);
3770 this.el.grab_focus();
3772 insert_spaces_instead_of_tabs : true,
3775 show_line_numbers : true,
3778 xtype: GtkSource.Buffer,
3780 changed : function (self) {
3781 var s = new Gtk.TextIter();
3782 var e = new Gtk.TextIter();
3783 this.el.get_start_iter(s);
3784 this.el.get_end_iter(e);
3785 var str = this.el.get_text(s,e,true);
3787 Seed.check_syntax('var e = ' + str);
3789 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3790 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3792 //print("SYNTAX ERROR IN EDITOR");
3797 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3798 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3801 this.get('/LeftPanel.model').changed( str , false);
3811 xtype: Gtk.ScrolledWindow,
3815 xtype: Vte.Terminal,
3818 feed : function(istr) {
3819 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3820 // we should make ourselves visable!!!
3821 this.get('/BottomPane').el.show();
3822 this.get('/BottomPane').el.set_current_page(1);
3824 this.el.feed(str ,str.length);
3826 scroll_on_output : true,
3828 XObject.prototype.init.call(this);
3829 this.el.set_size (80, 1000);
3831 scrollback_lines : 1000
3836 xtype: Gtk.ScrolledWindow,
3840 xtype: WebKit.WebView,
3852 pack : "pack_start,false,false",
3856 this.get('buttonbar').el.show();
3857 this.get('viewbox').el.hide();
3858 print("TRIED TO HIDE");
3861 this.get('buttonbar').el.hide();
3862 this.get('viewbox').el.show();
3863 // this.get('model').expanded();
3875 pack : "pack_start,false,true",
3877 clicked : function (self) {
3878 this.get('/RightPalete').show();
3885 stock : Gtk.STOCK_GOTO_FIRST,
3886 icon_size : Gtk.IconSize.MENU
3896 XObject.prototype.init.call(this);
3897 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3900 enter_notify_event : function (self, event) {
3901 this.get('/RightPalete').show();
3915 pack : "pack_start,false,true",
3924 pack : "pack_start,false,true",
3926 clicked : function (self) {
3927 this.get('/RightPalete').hide();
3934 stock : Gtk.STOCK_GOTO_LAST,
3935 icon_size : Gtk.IconSize.MENU
3942 xtype: Gtk.ScrolledWindow,
3945 XObject.prototype.init.call(this);
3946 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3947 this.el.set_size_request(-1,200);
3949 shadow_type : Gtk.ShadowType.IN,
3952 xtype: Gtk.TreeView,
3955 XObject.prototype.init.call(this);
3956 this.el.set_size_request(150,-1);
3957 // set_reorderable: [1]
3959 var description = new Pango.FontDescription.c_new();
3960 description.set_size(8000);
3961 this.el.modify_font(description);
3963 this.selection = this.el.get_selection();
3964 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3965 // this.selection.signal['changed'].connect(function() {
3966 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3968 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3970 Gtk.drag_source_set (
3971 this.el, /* widget will be drag-able */
3972 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3973 null, /* lists of target to support */
3974 0, /* size of list */
3975 Gdk.DragAction.COPY /* what to do with data after dropped */
3977 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3979 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3980 Gtk.drag_source_add_text_targets(this.el);
3982 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3983 targets = new Gtk.TargetList();
3984 targets.add( LeftTree.atoms["STRING"], 0, 0);
3985 targets.add_text_targets( 1 );
3986 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3988 //if you want to allow text to be output elsewhere..
3989 //Gtk.drag_source_add_text_targets(this.el);
3993 headers_visible : false,
3994 enable_tree_lines : true,
3996 drag_begin : function (self, ctx) {
3997 // we could fill this in now...
3998 Seed.print('SOURCE: drag-begin');
4002 var iter = new Gtk.TreeIter();
4003 var s = this.selection;
4004 s.get_selected(this.get('/RightPalete.model').el, iter);
4005 var path = this.get('/RightPalete.model').el.get_path(iter);
4007 var pix = this.el.create_row_drag_icon ( path);
4010 Gtk.drag_set_icon_pixmap (ctx,
4017 var value = new GObject.Value('');
4018 this.get('/RightPalete.model').el.get_value(iter, 0, value);
4019 if (!this.get('/RightPalete').provider) {
4022 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
4023 this.el.dragData = value.value;
4030 drag_data_get : function (self, drag_context, selection_data, info, time) {
4031 //Seed.print('Palete: drag-data-get: ' + target_type);
4032 if (this.el.dragData && this.el.dragData.length ) {
4033 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
4037 //this.el.dragData = "TEST from source widget";
4041 drag_end : function (self, drag_context) {
4042 Seed.print('SOURCE: drag-end');
4043 this.el.dragData = false;
4044 this.el.dropList = false;
4045 this.get('/LeftTree.view').highlight(false);
4051 xtype: Gtk.ListStore,
4054 XObject.prototype.init.call(this);
4055 this.el.set_column_types ( 2, [
4056 GObject.TYPE_STRING, // title
4057 GObject.TYPE_STRING // tip
4062 load : function(tr,iter)
4067 //console.log('Project tree load: ' + tr.length);
4068 var citer = new Gtk.TreeIter();
4069 //this.insert(citer,iter,0);
4070 for(var i =0 ; i < tr.length; i++) {
4073 this.el.append(citer);
4075 this.el.insert(citer,iter,-1);
4080 this.el.set_value(citer, 0, '' + r ); // title
4082 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4083 //if (r.cn && r.cn.length) {
4084 // this.load(r.cn, citer);
4090 getValue : function (iter, col) {
4091 var gval = new GObject.Value('');
4092 this.el.get_value(iter, col ,gval);
4099 xtype: Gtk.TreeViewColumn,
4100 pack : "append_column",
4102 XObject.prototype.init.call(this);
4103 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4107 xtype: Gtk.CellRendererText,
4129 XObject.cache['/Window'] = Window;