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 console = imports.console;
11 XObject = imports.XObject.XObject;
14 type : Gtk.WindowType.TOPLEVEL,
15 title : "Application Builder",
19 "STRING" : Gdk.atom_intern("STRING")
21 this.targetList = new Gtk.TargetList();
22 this.targetList.add( this.atoms["STRING"], 0, 0);
23 //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
25 "style \"gtkcombobox-style\" {\n" +
26 " GtkComboBox::appears-as-list = 1\n" +
28 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
29 XObject.prototype.init.call(this);
38 setTitle : function(str) {
39 this.el.set_title(this.title + ' - ' + str);
42 delete_event : function (self, event) {
45 destroy : function (self) {
48 show : function (self) {
49 print("WINDOW SHOWING - trying to hide");
50 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
51 this.get('/MidPropTree').hideWin();
52 this.get('/RightPalete').hide();
53 this.get('/BottomPane').el.hide();
64 pack : "pack_start,false,false",
78 label : "New _Project",
80 activate : function (self) {
82 this.get('/EditProject').show({
83 success : function(pr) {
84 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
95 activate : function (self) {
96 var fn = this.get('/LeftProjectTree.combo').getValue();
98 this.get('/LeftProjectTree').showNoProjectSelected();
101 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
102 this.get('/DialogNewComponent').show({
103 project : pm.getByFn(fn)
109 xtype: Gtk.SeparatorMenuItem,
114 use_underline : true,
116 label : "D_elete Project",
118 activate : function (self) {
120 var fn = this.get('/LeftProjectTree').get('combo').getValue();
122 this.get('/StandardErrorDialog').show("Select a project")
125 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
126 var pr = pm.getByFn(fn);
129 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
130 pm.deleteProject(fn);
138 xtype: Gtk.SeparatorMenuItem,
145 use_underline : true,
147 activate : function (self) {
159 use_underline : true,
164 pack : "set_submenu",
169 activate : function (self) {
170 var fn = this.get('/LeftTree').getActiveFile();
172 this.get('/StandardErrorDialog').show("No File active");
176 this.get('/DialogNewComponent').show(fn);
180 label : "File _Properties",
187 activate : function (self, event) {
188 this.get('/RooProjectProperties').show();
192 label : "Modify Project HTML ",
203 use_underline : true,
207 pack : "set_submenu",
212 activate : function (self, event) {
213 var js = this.get('/LeftTree.model').toJS();
215 this.get('/RightBrowser.view').renderJS(js[0]);
220 label : "_Redraw (Roo)",
227 activate : function (self, event)
229 /* Firefox testing for debugging..
230 - we can create a /tmp directory, and put.
231 builder.html, builder.html.js, link roojs1
232 add at the end of builder.html Roo.onload(function() {
234 if (!this.get('/Window.LeftTree').getActiveFile()) {
238 var js = this.get('/LeftTree.model').toJS();
242 var project = this.get('/Window.LeftTree').getActiveFile().project;
243 //print (project.fn);
245 project.runhtml = project.runhtml || '';
248 var File = imports.File.File;
250 var target = "/tmp/firetest"; // fixme..
251 if (!File.isDirectory(target)) {
254 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
255 if (!File.exists( target+ '/roojs1')) {
256 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
261 var html = imports.File.File.read(__script_path__ + '/../builder.html');
262 html = html.replace('</head>', project.runhtml + '</head>');
265 var jsstr = JSON.stringify(js[0], null, 4);
267 var runbuilder = '<script type="text/javascript">' + "\n" +
268 " Builder.render(" + jsstr + ");\n" +
271 html = html.replace('</body>', runbuilder + '</body>');
273 File.write( target+ '/builder.html', html);
275 this.get('/Terminal').feed("RUN DIR:" + target);
277 this.get('/Terminal').el.fork_command( null , [], [], target
278 , false,false,false);
279 var cmd = "firefox file://" + target + "/builder.html \n";
280 this.get('/Terminal').el.feed_child(cmd, cmd.length);
284 label : "_Test in Firefox (Roo)",
295 use_underline : true,
300 pack : "set_submenu",
306 use_underline : true,
308 activate : function (self) {
309 this.get('/About').el.run();
339 activate : function (self) {
340 var nb = this.get('/LeftTopPanel.notebook');
341 if (this.el.expanded) {
344 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
347 var model = this.get('/LeftProjectTree.combomodel');
348 // print ("loading Projects?")
349 //console.dump(pm.projects);
350 model.loadData(pm.projects);
353 nb.el.set_current_page(1);
354 //pm.on('changed', function() {
355 //console.log("CAUGHT project manager change");
356 // _combo.model.loadData(pm.projects);
360 nb.el.set_current_page(0);
362 enter_notify_event : function (self, event) {
363 this.el.expanded = !this.el.expanded;
364 //if (this.el.expanded ) {
365 this.listeners.activate.call(this);
372 label : "Select Project or File",
373 pack : "pack_start,false,true",
375 XObject.prototype.init.call(this);
376 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
384 pack : "pack_start,true,true",
386 XObject.prototype.init.call(this);
387 this.el.set_current_page(0);
392 xtype: Gtk.ScrolledWindow,
395 getActiveElement : function() { // return path to actie node.
397 var path = this.getActivePath();
401 var iter = new Gtk.TreeIter();
402 this.get('model').el.get_iter_from_string(iter, path);
404 var value = new GObject.Value('');
405 this.get('model').el.get_value(iter, 2, value);
407 return JSON.parse(value.value);
409 getActiveFile : function() {
410 return this.get('model').file;
412 getActivePath : function() {
413 var model = this.get('model');
414 var view = this.get('view');
415 if (view.selection.count_selected_rows() < 1) {
418 var iter = new Gtk.TreeIter();
420 view.selection.get_selected(model.el, iter);
421 return model.el.get_path(iter).to_string();
423 getPaleteProvider : function() {
424 var model = this.get('model');
425 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
426 return pm.getPalete(model.file.getType());
428 getRenderer : function() {
430 switch( this.getActiveFile().getType()) {
432 return this.get('/RightBrowser.view');
434 return this.get('/RightGtkView');
439 XObject.prototype.init.call(this);
440 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
442 renderView : function() {
443 var render = this.getRenderer();
444 var model = this.get('model');
446 render.renderJS(model.toJS(false,true)[0]);
448 print("NO RENDER JS METHOD?");
451 shadow_type : Gtk.ShadowType.IN,
457 headers_visible : false,
458 enable_tree_lines : true,
461 XObject.prototype.init.call(this);
462 var description = new Pango.FontDescription.c_new();
463 description.set_size(8000);
464 this.el.modify_font(description);
466 this.selection = this.el.get_selection();
467 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
470 // is this really needed??
471 this.selection.signal['changed'].connect(function() {
472 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
473 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
477 Gtk.drag_source_set (
478 this.el, /* widget will be drag-able */
479 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
480 null, /* lists of target to support */
481 0, /* size of list */
482 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
485 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
487 Gtk.drag_source_add_text_targets(this.el);
490 this.el, /* widget that will accept a drop */
491 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
492 null, /* lists of target to support */
493 0, /* size of list */
494 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
497 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
498 Gtk.drag_dest_add_text_targets(this.el);
500 highlight : function(treepath_ar) {
502 // highlighting for drag/drop
503 if (treepath_ar.length && treepath_ar[0].length ) {
504 this.el.set_drag_dest_row(
505 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
507 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
511 selectNode : function(treepath_str) {
512 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
513 var tp = new Gtk.TreePath.from_string(treepath_str);
514 this.el.set_cursor(tp, null, false);
515 this.el.scroll_to_cell(tp, null, false, 0,0);
518 button_press_event : function (self, ev) {
519 console.log("button press?");
520 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
521 print("click" + ev.type);
527 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
529 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
531 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
532 this.get('/LeftTreeMenu').el.show_all();
533 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
534 print("click:" + res.path.to_string());
537 drag_begin : function (self, drag_context) {
538 print('SOURCE: drag-begin');
539 this.targetData = false;
540 // find what is selected in our tree...
541 var iter = new Gtk.TreeIter();
542 var s = this.selection;
543 s.get_selected(this.get('/LeftTree.model').el, iter);
545 // set some properties of the tree for use by the dropped element.
546 var value = new GObject.Value('');
547 this.get('/LeftTree.model').el.get_value(iter, 2, value);
548 var data = JSON.parse(value.value);
549 var xname = this.get('/LeftTree.model').file.guessName(data);
551 this.el.dragData = xname;
552 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
555 // make the drag icon a picture of the node that was selected
556 var path = this.get('/LeftTree.model').el.get_path(iter);
557 this.el.treepath = path.to_string();
559 var pix = this.el.create_row_drag_icon ( path);
561 Gtk.drag_set_icon_pixmap (ctx,
570 drag_end : function (self, drag_context) {
571 Seed.print('LEFT-TREE: drag-end');
572 this.el.dragData = false;
573 this.el.dropList = false;
574 this.targetData = false;
575 this.get('/LeftTree.view').highlight(false);
578 drag_motion : function (self, ctx, x, y, time) {
579 console.log("LEFT-TREE: drag-motion");
580 var src = Gtk.drag_get_source_widget(ctx);
582 // a drag from elsewhere...- prevent drop..
584 print("no drag data!");
585 Gdk.drag_status(ctx, 0, time);
586 this.targetData = false;
589 var action = Gdk.DragAction.COPY;
590 if (src == this.el) {
591 // unless we are copying!!! ctl button..
592 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
596 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
597 // no children.. -- asume it's ok..
598 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
599 Gdk.drag_status(ctx, action ,time);
603 print("GETTING POS");
604 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
605 print("ISOVER? " + isOver);
607 Gdk.drag_status(ctx, 0 ,time);
608 return false; // not over apoint!?!
610 // drag node is parent of child..
611 console.log("SRC TREEPATH: " + src.treepath);
612 console.log("TARGET TREEPATH: " + data.path.to_string());
614 // nned to check a few here..
615 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
616 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
617 //Gtk.TreeViewDropPosition.AFTER
618 //Gtk.TreeViewDropPosition.BEFORE
620 if (typeof(src.treepath) != 'undefined' &&
621 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
622 print("subpath drag");
623 Gdk.drag_status(ctx, 0 ,time);
628 //print("DUMPING DATA");
629 //console.dump(data);
632 print(data.path.to_string() +' => '+ data.pos);
633 var tg = this.get('/LeftTree.model').findDropNodeByPath(
634 data.path.to_string(), src.dropList, data.pos);
636 this.get('/LeftTree.view').highlight(tg);
638 print("Can not find drop node path");
639 this.targetData = false;
640 Gdk.drag_status(ctx, 0, time);
644 this.targetData = tg;
647 Gdk.drag_status(ctx, action ,time);
651 drag_drop : function (w, ctx, x, y, time) {
652 Seed.print("TARGET: drag-drop");
656 w, /* will receive 'drag-data-received' signal */
657 ctx, /* represents the current state of the DnD */
658 this.get('/Window').atoms["STRING"], /* the target type we want */
659 time /* time stamp */
663 /* No target offered by source => error */
668 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
669 print("Tree: drag-data-received");
671 var delete_selection_data = false;
672 var dnd_success = false;
673 /* Deal with what we are given from source */
674 if( sel_data && sel_data.length ) {
676 if (ctx.action == Gdk.DragAction.ASK) {
677 /* Ask the user to move or copy, then set the ctx action. */
680 if (ctx.action == Gdk.DragAction.MOVE) {
681 //delete_selection_data = true;
684 var source = Gtk.drag_get_source_widget(ctx);
686 if (this.targetData) {
687 if (source != this.el) {
688 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
690 // drag around.. - reorder..
691 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
695 //Seed.print(this.targetData);
701 // we can send stuff to souce here...
707 if (dnd_success == false)
709 Seed.print ("DnD data transfer failed!\n");
712 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
715 cursor_changed : function (self) {
716 if (this.blockChanges) { // probably not needed..
719 var render = this.get('/LeftTree').getRenderer();
722 if (this.selection.count_selected_rows() < 1) {
723 this.get('/LeftPanel.model').load( false);
724 this.get('/MidPropTree').activeElement = false;
725 this.get('/MidPropTree').hideWin();
727 var pm = this.get('/RightPalete.model');
728 if (!this.get('/LeftTree').getPaleteProvider()) {
729 // it may not be loaded yet..
732 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
733 this.get('/LeftTree.model').listAllTypes()));
734 if (render && render.redraw) {
740 //console.log('changed');
741 var s = this.selection;
742 var iter = new Gtk.TreeIter();
743 s.get_selected(this.get('/LeftTree.model').el, iter);
747 var value = new GObject.Value('');
748 this.get('/LeftTree.model').el.get_value(iter, 2, value);
749 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
751 var data = JSON.parse(value.value);
752 this.get('/MidPropTree').activeElement = data;
753 this.get('/MidPropTree').hideWin();
754 this.get('/LeftPanel.model').load( data);
756 console.log(value.value);
757 // _g.button.set_label(''+value.get_string());
759 var pm =this.get('/RightPalete.model');
760 pm.load( this.get('/RightPalete').provider.gatherList(
761 this.get('/LeftTree.model').listAllTypes()));
764 if (render && render.redraw) {
768 //Seed.print( value.get_string());
775 xtype: Gtk.TreeStore,
780 changed : function(n, refresh) {
781 print("MODEL CHANGED CALLED" + this.activePath);
782 if (this.activePath) {
783 var iter = new Gtk.TreeIter();
784 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
785 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
786 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
788 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
790 //this.currentTree = this.toJS(false, true)[0];
791 this.file.items = this.toJS(false, false);
792 print("AFTER CHANGED");
793 //console.dump(this.file.items);
795 this.currentTree = this.file.items[0];
796 //console.log(this.file.toSource());
799 print("REDNER BROWSER?!");
800 this.get('/LeftTree').renderView();
802 var pm = this.get('/RightPalete.model');
803 if (!this.get('/RightPalete').provider) {
809 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
810 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
814 deleteSelected : function() {
815 this.get('/LeftTree.view').blockChanges = true;
816 var old_iter = new Gtk.TreeIter();
817 var s = this.get('/LeftTree.view').selection;
818 s.get_selected(this.el, old_iter);
819 var path = this.el.get_path(old_iter).to_string();
821 this.activePath= false;
824 this.activePath= false;
825 var iter = new Gtk.TreeIter();
826 this.el.get_iter_from_string(iter, path);
827 this.el.remove(iter);
829 // rebuild treemap. -- depreciated.!!
832 //this.toJS(null, true) // does not do anything?
833 this.activePath= false;
834 this.changed(false,true);
835 this.get('/LeftTree.view').blockChanges = false;
837 dropNode : function(target_data, node) {
839 // console.dump(node);
840 // console.dump(target_data);
841 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
843 print("add " + tp + "@" + target_data[1] );
846 if (tp && target_data[1] < 2) { // before or after..
847 var ar = target_data[0].split(':');
849 parent = new Gtk.TreePath.from_string( ar.join(':') );
852 var n_iter = new Gtk.TreeIter();
853 var iter_par = new Gtk.TreeIter();
854 var iter_after = after ? new Gtk.TreeIter() : false;
858 if (parent !== false) {
859 this.el.get_iter(iter_par, parent);
866 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
867 this.el.get_iter(iter_after, after);
868 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
869 n_iter, iter_par, iter_after);
872 this.el.append(n_iter, iter_par);
876 if (typeof(node) == 'string') {
877 var ar = node.split('.');
878 var xtype = ar.pop();
881 '|xns' : ar.join('.'),
884 if (target_data.length == 3 && target_data[2].length) {
885 node['*prop'] = target_data[2];
887 node = this.get('/DialogTemplateSelect').show(node);
890 // work out what kind of packing to use..
891 if (typeof(node.pack) == 'undefined' && parent !== false) {
892 var pal = this.get('/LeftTree').getPaleteProvider();
893 if (pal.name == 'Gtk') {
894 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
895 var cname = pal.guessName(node);
896 node.pack = pal.getDefaultPack(pname, cname);
907 // load children - if it has any..
910 this.load(xitems, n_iter);
911 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
913 if (tp && (xitems || after)) {
914 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
916 // wee need to get the empty proptypes from somewhere..
918 //var olditer = this.activeIter;
919 this.activePath = this.el.get_path(n_iter).to_string();
921 // changed actually set's the node data..
922 this.changed(node, true);
926 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
928 //Builder.MidPropTree._model.load(node);
929 //Builder.MidPropTree._win.hideWin();
930 //Builder.LeftPanel._model.load( node);
934 findDropNode : function(treepath_str, targets) {
936 // this is used by the dragdrop code in the roo version AFAIR..
938 var path = treepath_str.replace(/^builder-/, '');
939 // treemap is depreciated... - should really check if model has any entries..
941 if (!this.el.iter_n_children(null)) {
943 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
945 print("FIND treepath: " + path);
946 //console.dump(this.treemap);
948 if (!treepath_str.match(/^builder-/)) {
949 return []; // nothing!
951 if (targets === true) {
954 return this.findDropNodeByPath(path,targets)
956 findDropNodeByPath : function(treepath_str, targets, pref) {
957 var path = treepath_str + ''; // dupe it..
958 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
960 //console.dump(this.treemap);
961 while (path.length) {
962 print("LOOKING FOR PATH: " + path);
963 var node_data = this.singleNodeToJS(path);
964 if (node_data === false) {
965 print("node not found");
969 var xname = this.get('/LeftTree.model').file.guessName(node_data);
972 targets.forEach(function(tg) {
976 if ((tg == xname) ) {
979 if (tg.indexOf(xname +':') === 0) {
981 prop = tg.split(':').pop();
986 if (last) { // pref is after/before..
987 // then it's after last
989 return []; // do not allow..
991 return [ last, pref , prop];
994 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
996 var par = path.split(':');
999 path = par.join(':');
1005 getIterValue : function (iter, col) {
1006 var gval = new GObject.Value('');
1007 this.el.get_value(iter, col ,gval);
1013 XObject.prototype.init.call(this);
1014 this.el.set_column_types ( 3, [
1015 GObject.TYPE_STRING, // title
1016 GObject.TYPE_STRING, // tip
1017 GObject.TYPE_STRING // source..
1020 listAllTypes : function() {
1021 var s = this.get('/LeftTree.view').selection;
1022 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1024 if (s.count_selected_rows() > 0) {
1025 var iter = new Gtk.TreeIter();
1026 s.get_selected(this.el, iter);
1028 // set some properties of the tree for use by the dropped element.
1029 var value = new GObject.Value('');
1030 this.el.get_value(iter, 2, value);
1031 var data = JSON.parse(value.value);
1034 var xname = this.get('/LeftTree.model').file.guessName(data);
1035 console.log('selected:' + xname);
1039 return []; // could not find it..
1047 li.forEach(function(el) {
1048 // this is specific to roo!!!?
1049 if (!el) { // skip empty?
1052 var fullpath = _this.file.guessName(el);
1053 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1058 if (el.items && el.items.length) {
1067 addall([this.currentTree]);
1069 // only if we have nothing, should we add '*top'
1073 //console.log('all types in tree');
1074 //console.dump(ret);
1079 load : function(tr,iter)
1081 var citer = new Gtk.TreeIter();
1082 //this.insert(citer,iter,0);
1083 for(var i =0 ; i < tr.length; i++) {
1085 this.el.insert(citer,iter,-1);
1087 this.el.append(citer);
1090 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1091 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1092 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1093 if (tr[i].items && tr[i].items.length) {
1094 this.load(tr[i].items, citer);
1098 loadFile : function(f) {
1104 console.log('missing file');
1108 // load the file if not loaded..
1109 if (f.items === false) {
1111 f.loadItems(function() {
1117 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1119 if (f.items.length && typeof(f.items[0]) == 'string') {
1121 this.get('/RightEditor').el.show();
1122 this.get('/RightEditor.view').load( f.items[0]);
1126 //console.dump(f.items);
1128 this.get('/LeftTree.view').el.expand_all();
1130 if (!f.items.length) {
1133 this.get('/Window.leftvpaned').el.set_position(80);
1135 this.get('/LeftTree.view').el.set_cursor(
1136 new Gtk.TreePath.from_string('0'), null, false);
1140 this.get('/Window.leftvpaned').el.set_position(200);
1144 //print("hide right editior");
1145 this.get('/RightEditor').el.hide();
1146 //print("set current tree");
1147 this.currentTree = this.toJS(false, false)[0];
1148 //console.dump(this.currentTree);
1149 this.currentTree = this.currentTree || { items: [] };
1150 this.get('/LeftTree').renderView();
1151 //console.dump(this.map);
1152 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1153 var pm = this.get('/RightPalete.model');
1154 // set up provider..
1156 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1158 if (!this.get('/RightPalete').provider) {
1159 print ("********* PALETE PROVIDER MISSING?!!");
1161 this.get('/LeftTree').renderView();
1163 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1167 this.get('/Window.view-notebook').el.set_current_page(
1168 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1171 moveNode : function(target_data, action) {
1172 //print("MOVE NODE");
1173 // console.dump(target_data);
1174 var old_iter = new Gtk.TreeIter();
1175 var s = this.get('/LeftTree.view').selection;
1176 s.get_selected(this.el, old_iter);
1177 var node = this.nodeToJS(old_iter,false);
1178 //console.dump(node);
1181 // needs to drop first, otherwise the target_data
1182 // treepath will be invalid.
1184 this.dropNode(target_data, node);
1185 if (action & Gdk.DragAction.MOVE) {
1186 // print("REMOVING OLD NODE");
1187 this.el.remove(old_iter);
1191 this.activePath= false;
1192 this.changed(false,true);
1194 nodeTip : function(c) {
1195 var ret = this.nodeTitle(c,true);
1201 if (!i.length || i[0] != '|') {
1207 if (typeof(c[i]) != 'string') {
1210 //print("prop : " + i + ':' + c[i]);
1211 if (!c[i].match(new RegExp('function'))) {
1214 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1218 ret+="\n\nMethods:" + funcs;
1223 nodeTitle : function(c, renderfull) {
1226 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1227 if (sr) txt.push('<s>');
1228 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1230 if (renderfull && c['|xns']) {
1231 txt.push(c['|xns']);
1234 if (c.xtype) { txt.push(c.xtype); }
1235 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1236 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1237 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1240 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1241 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1242 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1243 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1244 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1245 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1246 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1247 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1248 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1250 // for flat classes...
1251 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1252 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1255 if (sr) txt.push('</s>');
1256 return (txt.length == 0 ? "Element" : txt.join(" "));
1258 nodeToJS : function (treepath, with_id)
1261 var iter = treepath; // API used to be iter here..
1262 if (typeof(iter) == 'string') {
1263 iter = new Gtk.TreeIter();
1264 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1268 var par = new Gtk.TreeIter();
1269 var iv = this.getIterValue(iter, 2);
1270 // print("IV" + iv);
1271 var k = JSON.parse(iv);
1272 if (k.json && !this.el.iter_parent( par, iter )) {
1277 var treepath_str = this.el.get_path(iter).to_string();
1278 // not sure how we can handle mixed id stuff..
1279 if (typeof(k.id) == 'undefined') {
1280 k.id = 'builder-'+ treepath_str ;
1284 this.treemap[ treepath_str ] = k;
1285 k.xtreepath = treepath_str ;
1288 if (this.el.iter_has_child(iter)) {
1289 citer = new Gtk.TreeIter();
1290 this.el.iter_children(citer, iter);
1291 k.items = this.toJS(citer,with_id);
1295 nodeToJSON : function(c) {
1303 return JSON.stringify(o);
1305 singleNodeToJS : function (treepath)
1307 var iter = new Gtk.TreeIter();
1308 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1312 var iv = this.getIterValue(iter, 2);
1314 return JSON.parse(iv);
1317 toJS : function(treepath, with_id)
1319 //Seed.print("WITHID: "+ with_id);
1320 var iter = treepath; // API used to be iter here..
1321 if (typeof(iter) == 'string') {
1322 iter = new Gtk.TreeIter();
1323 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1332 iter = new Gtk.TreeIter();
1333 if (!this.el.get_iter_first(iter)) {
1343 var k = this.nodeToJS(iter, with_id);
1347 if (!this.el.iter_next(iter)) {
1353 // convert the list into a json string..
1359 xtype: Gtk.TreeViewColumn,
1360 pack : "append_column",
1362 XObject.prototype.init.call(this);
1363 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1367 xtype: Gtk.CellRendererText,
1377 id : "LeftTreeMenu",
1380 xtype: Gtk.MenuItem,
1382 label : "Delete Element",
1384 activate : function (self) {
1386 this.get('/LeftTree.model').deleteSelected();
1391 xtype: Gtk.MenuItem,
1393 activate : function (self) {
1395 var tree = this.get('/LeftTree');
1396 var model = this.get('/LeftTree.model');
1397 var el = tree.getActivePath();
1399 var js = model.toJS(el, false);
1400 // print(JSON.stringify(js[0], null,4));
1401 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1406 label : "Save as Template",
1416 id : "LeftProjectTree",
1417 showNoProjectSelected : function() {
1418 this.get('/StandardErrorDialog').show("Select a Project first.");
1420 getActiveProject : function() {
1421 return this.project;
1424 leave_notify_event : function (self, event) {
1431 pack : "pack_start,false,false",
1434 xtype: Gtk.ComboBox,
1437 XObject.prototype.init.call(this);
1438 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1440 getValue : function() {
1441 var ix = this.el.get_active();
1445 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1446 if (typeof(data[ix]) == 'undefined') {
1451 setValue : function(fn)
1455 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1456 data.forEach(function(n, ix) {
1464 changed : function (self) {
1465 var fn = this.getValue();
1466 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1467 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1472 xtype: Gtk.CellRendererText,
1473 pack : "pack_start,true",
1477 xtype: Gtk.ListStore,
1480 XObject.prototype.init.call(this);
1481 this.el.set_column_types ( 2, [
1482 GObject.TYPE_STRING, // real key
1483 GObject.TYPE_STRING // real type
1487 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1489 pm.on('changed', function() {
1490 print("caught changed hook on project manager - reloading data");
1491 _this.loadData(pm.projects);
1495 loadData : function(data) {
1496 var ov = this.get('/LeftProjectTree.combo').getValue();
1498 var iter = new Gtk.TreeIter();
1500 data.forEach(function(p) {
1505 el.set_value(iter, 0, p.fn);
1506 el.set_value(iter, 1, p.name);
1510 this.get('/LeftProjectTree.combo').setValue(ov);
1519 xtype: Gtk.ScrolledWindow,
1521 shadow_type : Gtk.ShadowType.IN,
1523 XObject.prototype.init.call(this);
1524 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1528 xtype: Gtk.TreeView,
1529 headers_visible : false,
1530 enable_tree_lines : true,
1533 XObject.prototype.init.call(this);
1534 var description = new Pango.FontDescription.c_new();
1535 description.set_size(8000);
1536 this.el.modify_font(description);
1538 this.selection = this.el.get_selection();
1539 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1543 cursor_changed : function (self) {
1544 var iter = new Gtk.TreeIter();
1546 if (this.selection.count_selected_rows() < 1) {
1547 //XN.get('Builder.LeftTree.model').
1548 this.get('/LeftTree.model').load( false);
1552 var model = this.get('/LeftProjectTree.model');
1553 //console.log('changed');
1554 var s = this.selection;
1555 s.get_selected(model, iter);
1556 value = new GObject.Value('');
1557 model.el.get_value(iter, 2, value);
1559 console.log(value.value);// id..
1561 var file = this.get('/LeftProjectTree').project.getById(value.value);
1568 var nb = this.get('/LeftTopPanel.expander');
1569 nb.el.expanded = false;
1570 nb.listeners.activate.call(nb);
1571 //_expander.el.set_expanded(false);
1573 var ltm = this.get('/LeftTree.model');
1581 xtype: Gtk.TreeStore,
1585 XObject.prototype.init.call(this);
1586 this.el.set_column_types ( 3, [
1587 GObject.TYPE_STRING, // title
1588 GObject.TYPE_STRING, // tip
1589 GObject.TYPE_STRING // id..
1593 loadProject : function(pr) {
1594 print("LOAD PROJECT");
1600 this.get('/LeftProjectTree').project = pr;
1601 this.load(pr.toTree());
1602 this.get('/LeftProjectTree.view').el.expand_all();
1604 load : function(tr,iter) {
1605 // console.dump(tr);
1606 console.log('Project tree load: ' + tr.length);
1607 var citer = new Gtk.TreeIter();
1608 //this.insert(citer,iter,0);
1611 tr.forEach(function (r) {
1613 _this.el.append(citer);
1615 _this.el.insert(citer,iter,-1);
1617 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1618 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1619 _this.el.set_value(citer, 2, '' + r.id ); //id
1620 if (r.cn && r.cn.length) {
1621 _this.load(r.cn, citer);
1626 getValue : function(iter, col) {
1627 var gval = new GObject.Value('');
1628 this.el.get_value(iter, col ,gval);
1629 return '' + gval.value;
1633 xtype: Gtk.TreeViewColumn,
1634 pack : "append_column",
1636 XObject.prototype.init.call(this);
1637 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1641 xtype: Gtk.CellRendererText,
1661 pack : "pack_start,false,true,0",
1668 button_press_event : function (self, event) {
1669 this.get('/MidPropTree.model').showData('props');
1681 stock : Gtk.STOCK_ADD,
1682 icon_size : Gtk.IconSize.MENU
1697 button_press_event : function (self, event) {
1698 this.get('/MidPropTree.model').showData('events');
1710 stock : Gtk.STOCK_ADD,
1711 icon_size : Gtk.IconSize.MENU
1726 button_press_event : function (self, ev) {
1727 var p = this.get('/AddPropertyPopup');
1731 p.el.set_screen(Gdk.Screen.get_default());
1733 p.el.popup(null, null, null, null, 3, ev.button.time);
1745 stock : Gtk.STOCK_ADD,
1746 icon_size : Gtk.IconSize.MENU
1758 id : "AddPropertyPopup",
1761 xtype: Gtk.MenuItem,
1763 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1766 activate : function (self) {
1768 this.get('/LeftPanel.model').add( {
1779 xtype: Gtk.MenuItem,
1781 tooltip_markup : "Add what type of packing is to be used",
1784 activate : function (self) {
1786 this.get('/LeftPanel.model').add( {
1796 xtype: Gtk.MenuItem,
1798 tooltip_markup : "Override the init method",
1801 activate : function (self) {
1803 this.get('/LeftPanel.model').add( {
1806 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1813 xtype: Gtk.SeparatorMenuItem,
1817 xtype: Gtk.MenuItem,
1819 tooltip_markup : "Add a user defined string property",
1822 activate : function (self) {
1824 this.get('/LeftPanel.model').add( {
1834 xtype: Gtk.MenuItem,
1836 tooltip_markup : "Add a user defined number property",
1839 activate : function (self) {
1841 this.get('/LeftPanel.model').add( {
1851 xtype: Gtk.MenuItem,
1853 tooltip_markup : "Add a user defined boolean property",
1856 activate : function (self) {
1858 this.get('/LeftPanel.model').add( {
1868 xtype: Gtk.SeparatorMenuItem,
1872 xtype: Gtk.MenuItem,
1874 tooltip_markup : "Add a user function boolean property",
1877 activate : function (self) {
1879 this.get('/LeftPanel.model').add( {
1882 val : "function() {\n \n}\n",
1895 xtype: Gtk.ScrolledWindow,
1898 shadow_type : Gtk.ShadowType.IN,
1901 XObject.prototype.init.call(this);
1902 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1906 xtype: Gtk.TreeView,
1909 headers_visible : false,
1910 enable_tree_lines : true,
1912 XObject.prototype.init.call(this);
1914 this.selection = this.el.get_selection();
1915 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1918 var description = new Pango.FontDescription.c_new();
1919 description.set_size(8000);
1920 this.el.modify_font(description);
1923 button_press_event : function (self, ev) {
1927 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1928 return false; //not on a element.
1932 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1934 if (res.column.title != 'value') {
1935 return false; // ignore..
1937 if ( this.get('/LeftPanel').editing) {
1940 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1941 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1942 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1946 var provider = this.get('/LeftTree').getPaleteProvider();
1948 var opts = provider.findOptions(type);
1950 if (opts === false) {
1951 this.get('/LeftPanel').editableColumn.setOptions([]);
1952 renderer.has_entry = true;
1954 LeftPanel.editableColumn.setOptions(opts);
1955 renderer.has_entry = false;
1959 //Seed.print("click" + ev.type);
1960 //console.dump(res);
1966 if (res.column.title == 'value') {
1969 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1970 var p = this.get('/LeftPanelPopup');
1975 p.el.set_screen(Gdk.Screen.get_default());
1977 p.el.popup(null, null, null, null, 3, ev.button.time);
1978 //Seed.print("click:" + res.column.title);
1986 xtype: Gtk.TreeStore,
1990 add : function(info) {
1991 // info includes key, val, skel, etype..
1993 type = info.type.toLowerCase();
1994 var data = this.toJS();
1996 if (info.etype == 'events') {
1997 data.listeners = data.listeners || { };
1998 if (typeof(data.listeners[info.key]) != 'undefined') {
1999 return; //already set!
2002 if (typeof(data[info.key]) != 'undefined') {
2007 if (typeof(info.val) == 'undefined') {
2010 if (info.type.toLowerCase() == 'boolean') {
2013 if (type == 'number') {
2021 if (info.etype == 'events') {
2023 data.listeners[info.key] = info.val;
2026 data[info.key] = info.val;
2030 var map = this.load(data);
2032 // flag it as changed to the interface..
2034 this.get('/LeftTree.model').changed(data, true);
2037 this.startEditing(map[k]);
2040 LeftPanel.get('view').el.row_activated(
2041 new Gtk.TreePath.from_string(map[k]),
2042 LeftPanel.editableColumn.el
2046 changed : function(str, doRefresh) {
2047 if (!this.activePath) {
2050 var iter = new Gtk.TreeIter();
2051 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2053 this.el.set_value(iter, 1, '' +str);
2054 this.el.set_value(iter, 3, '' + this.toShort(str));
2055 var type = this.getIterValue(iter, 4);
2057 this.el.set_value(iter, 5, type + ' : ' + str);
2058 // update the tree...
2060 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2062 deleteSelected : function() {
2063 var data = this.toJS();
2064 var iter = new Gtk.TreeIter();
2065 var s = this.get('/LeftPanel.view').selection;
2066 s.get_selected(this.el, iter);
2069 var gval = new GObject.Value('');
2070 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2072 var val = gval.value;
2073 if (val[0] == '!') {
2075 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2078 delete data.listeners[ val.substring(1)];
2079 if (!XObject.keys(data.listeners).length) {
2080 delete data.listeners;
2084 if (typeof(data[val]) == 'undefined') {
2092 this.get('/LeftTree.model').changed(data, true);
2095 editSelected : function(e) {
2096 print("EDIT SELECTED?");
2097 var iter = new Gtk.TreeIter();
2098 var s = this.get('/LeftPanel.view').selection;
2099 s.get_selected(this.get('/LeftPanel.model').el, iter);
2100 var m = this.get('/LeftPanel.model')
2102 var gval = new GObject.Value('');
2103 this.el.get_value(iter, 0 ,gval);
2104 var val = '' + gval.value;
2106 gval = new GObject.Value('');
2107 this.el.get_value(iter, 1 ,gval);
2108 var rval = gval.value;
2109 var activePath = this.el.get_path(iter).to_string();
2110 this.activePath = activePath ;
2111 // was activeIter...
2114 var showEditor = false;
2116 if (val[0] == '!') {
2119 if (val[0] == '|') {
2120 if (rval.match(/function/g) || rval.match(/\n/g)) {
2127 this.activePath = false;
2128 GLib.timeout_add(0, 1, function() {
2129 // Gdk.threads_enter();
2130 _this.get('/BottomPane').el.show();
2131 _this.get('/RightEditor').el.show();
2132 _this.get('/RightEditor.view').load( rval );
2136 _this.activePath = activePath ;
2138 // Gdk.threads_leave();
2143 this.get('/BottomPane').el.hide();
2144 this.get('/RightEditor').el.hide();
2146 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2150 getIterValue : function(iter, col) {
2151 var gval = new GObject.Value('');
2152 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2153 return '' + gval.value;
2155 getType : function(treepath) {
2156 return this.getValue(treepath, 4);
2158 getValue : function(treepath_str, col) {
2159 var iter = new Gtk.TreeIter();
2160 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2162 var gval = new GObject.Value('');
2163 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2164 var val = '' + gval.value;
2168 var type = this.getType(this.el.get_path(iter).to_string());
2169 print("TYPE: " +type + " - val:" + val);
2170 switch(type.toLowerCase()) {
2174 return parseFloat(val); // Nan ?? invalid!!?
2177 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2179 return val == 'true' ? true : false;
2181 var nv = parseFloat(val);
2182 if (!isNaN(nv) && (val == ''+nv)) {
2190 XObject.prototype.init.call(this);
2191 this.el.set_column_types ( 6, [
2192 GObject.TYPE_STRING, // 0 real key
2193 GObject.TYPE_STRING, // 1 real value
2194 GObject.TYPE_STRING, // 2 visable key
2195 GObject.TYPE_STRING, // 3 visable value
2196 GObject.TYPE_STRING, // 4 need to store type of!!!
2197 GObject.TYPE_STRING // 5 tooltip
2201 load : function(ar) {
2204 this.get('/RightEditor').el.hide();
2211 var provider = this.get('/LeftTree').getPaleteProvider();
2212 var iter = new Gtk.TreeIter();
2215 var keys = XObject.keys(ar);
2217 ar.listeners = ar.listeners || {};
2219 for (var i in ar.listeners ) {
2220 this.el.append(iter);
2221 var p = this.el.get_path(iter).to_string();
2224 this.el.set_value(iter, 0, '!'+ i );
2225 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2226 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2228 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2229 this.el.set_value(iter, 4, 'function');
2230 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2236 keys.forEach(function(i) {
2237 if (typeof(ar[i]) == 'object') {
2241 var type = provider.findType(ar, i, ar[i]);
2243 _this.el.append(iter);
2244 var p = _this.el.get_path(iter).to_string();
2246 _this.el.set_value(iter, 0, ''+i);
2247 _this.el.set_value(iter, 1, '' + ar[i]);
2248 _this.el.set_value(iter, 2, ''+i);
2249 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2250 _this.el.set_value(iter, 4, ''+type);
2251 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2255 startEditing : function(path,col) {
2257 * start editing path (or selected if not set..)
2258 * @param {String|false} path (optional) treepath to edit - selected tree gets
2259 * edited by default.
2260 * @param {Number} 0 or 1 (optional)- column to edit.
2263 if (typeof(path) == 'string') {
2264 tp = new Gtk.TreePath.from_string(path);
2266 var iter = new Gtk.TreeIter();
2267 var s = this.get('/LeftPanel.view').selection;
2268 s.get_selected(this.el, iter);
2269 tp = this.el.get_path(iter);
2270 path = tp.to_string();
2274 // which colum is to be edited..
2276 if (typeof(col) == 'undefined') {
2277 var k = this.getValue(path, 0);
2278 colObj = (!k.length || k == '|') ?
2279 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2281 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2284 // make sure the pulldown is set correctly..
2285 // not really needed for second col...
2287 var provider = this.get('/LeftTree').getPaleteProvider();
2289 var type = this.get('/LeftPanel.model').getType(path);
2290 var opts = provider.findOptions(type);
2291 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2293 if (opts === false) {
2294 this.get('/LeftPanel').editableColumn.setOptions([]);
2295 renderer.has_entry = true; /// probably does not have any effect.
2297 this.get('/LeftPanel').editableColumn.setOptions(opts);
2298 renderer.has_entry = false;
2302 // iter now has row...
2303 GLib.timeout_add(0, 100, function() {
2305 colObj.items[0].el.editable = true; // esp. need for col 0..
2306 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2316 var iter = new Gtk.TreeIter();
2317 this.get('/LeftPanel.model').el.get_iter_first(iter);
2322 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2325 ar.listeners = ar.listeners || {};
2326 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2329 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2332 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2338 //print(JSON.stringify(ar));
2342 toShort : function(str) {
2343 var a = typeof(str) == 'string' ? str.split("\n") : [];
2344 return a.length > 1 ? a[0] + '....' : '' + str;
2348 xtype: Gtk.TreeViewColumn,
2349 pack : "append_column",
2351 XObject.prototype.init.call(this);
2353 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2354 this.get('/LeftPanel').propertyColumn = this;
2359 xtype: Gtk.CellRendererText,
2360 pack : "pack_start",
2362 editing_started : function (self, editable, path) {
2364 this.get('/LeftPanel.model').activePath = path;
2367 edited : function (self, object, p0) {
2368 var model = this.get('/LeftPanel.model');
2369 var path = model.activePath;
2370 var iter = new Gtk.TreeIter();
2371 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2372 model.el.set_value(iter, 0, p0);
2373 model.el.set_value(iter, 2, p0);
2375 model.activePath = false;
2377 this.get('/LeftTree.model').changed(model.toJS(), true);
2378 this.el.editable = false;
2385 xtype: Gtk.TreeViewColumn,
2386 pack : "append_column",
2388 XObject.prototype.init.call(this);
2389 this.el.add_attribute(this.items[0].el , 'text', 3 );
2390 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2391 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2392 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2394 this.get('/LeftPanel').editableColumn= this;
2396 setOptions : function(ar) {
2397 var m = this.items[0].el.model;
2399 var iter = new Gtk.TreeIter();
2400 ar.forEach(function(i) {
2403 m.set_value(iter, 0, i);
2409 xtype: Gtk.CellRendererCombo,
2410 pack : "pack_start",
2415 XObject.prototype.init.call(this);
2416 this.el.model = new Gtk.ListStore();
2417 this.el.model.set_column_types ( 1, [
2418 GObject.TYPE_STRING // 0 real key
2422 edited : function (self, object, p0) {
2423 this.get('/LeftPanel').editing = false;
2424 print("EDITED? p:" + p0 + " t:" + p0);
2425 this.get('/LeftPanel.model').changed(p0, true);
2426 this.get('/LeftPanel.model').activePath = false;
2428 editing_started : function (self, editable, path) {
2429 this.get('/LeftPanel').editing = true;
2430 // console.log('editing started');
2431 // r.has_entry = false;
2432 this.get('/LeftPanel.model').editSelected(editable);
2443 id : "LeftPanelPopup",
2446 xtype: Gtk.MenuItem,
2450 activate : function (self) {
2451 this.get('/LeftPanel.model').deleteSelected();
2456 xtype: Gtk.MenuItem,
2460 activate : function (self) {
2461 this.get('/LeftPanel.model').startEditing(false, 0);
2474 xtype: Gtk.ScrolledWindow,
2475 pack : "pack_end,false,true,0",
2477 shadow_type : Gtk.ShadowType.IN,
2479 XObject.prototype.init.call(this);
2480 XObject.prototype.init.call(this);
2481 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2482 this.el.set_size_request ( 150, -1 );
2485 activeElement : false,
2486 hideWin : function() {
2493 if (this.get('/Window.left').el.position < 160) {
2496 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2503 xtype: Gtk.TreeView,
2505 cursor_changed : function (self) {
2506 var iter = new Gtk.TreeIter();
2508 //console.log('changed');
2509 var m = this.get('model');
2510 if (!this.selection){
2511 this.selection = this.el.get_selection();
2514 var s = this.selection;
2515 if (!s.get_selected(m.el, iter)) {
2518 var tp = m.el.get_path(iter).to_string();
2523 var key = m.getValue(tp, 0);
2525 var type = m.getValue(tp, 1);
2526 var skel = m.getValue(tp, 3);
2527 var etype = m.getValue(tp, 5);
2530 this.get('/MidPropTree').hideWin();
2532 if (type.toLowerCase() == 'function') {
2534 if (etype != 'events') {
2538 this.get('/LeftPanel.model').add({
2546 // has dot in name, and is boolean???? this does not make sense..
2547 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2551 this.get('/LeftPanel.model').add( {
2561 enable_tree_lines : true,
2562 headers_visible : false,
2564 XObject.prototype.init.call(this);
2566 var description = new Pango.FontDescription.c_new();
2567 description.set_size(8000);
2568 this.el.modify_font(description);
2570 //this.selection = this.el.get_selection();
2571 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2580 xtype: Gtk.ListStore,
2583 XObject.prototype.init.call(this);
2584 this.el.set_column_types ( 6, [
2585 GObject.TYPE_STRING, // real key
2586 GObject.TYPE_STRING, // real type
2587 GObject.TYPE_STRING, // docs ?
2588 GObject.TYPE_STRING, // visable desc
2589 GObject.TYPE_STRING, // function desc
2590 GObject.TYPE_STRING // element type (event|prop)
2594 getValue : function(treepath, col)
2596 var tp = new Gtk.TreePath.from_string (treepath);
2597 var iter = new Gtk.TreeIter();
2598 this.el.get_iter (iter, tp);
2599 var value = new GObject.Value('');
2600 this.el.get_value(iter, col, value);
2604 showData : function(type) {
2606 if (!this.get('/MidPropTree').activeElement || !type) {
2607 return; // no active element
2610 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2611 var palete = this.get('/LeftTree').getPaleteProvider();
2615 Seed.print('Showing right?');
2616 if (!this.get('/MidPropTree').shown) {
2618 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2619 this.get('/MidPropTree').el.show();
2620 this.get('/MidPropTree').shown = true;
2623 var elementList = palete.getPropertiesFor(fullpath, type);
2624 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2625 // console.dump(elementList);
2628 var iter = new Gtk.TreeIter();
2629 for(var i =0 ; i < elementList.length; i++) {
2630 var p=elementList[i];
2631 this.el.append(iter);
2632 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2633 //GObject.TYPE_STRING, // real key
2634 // GObject.TYPE_STRING, // real type
2635 // GObject.TYPE_STRING, // docs ?
2636 // GObject.TYPE_STRING // func def?
2639 this.el.set_value(iter, 0, p.name);
2640 this.el.set_value(iter, 1, p.type);
2641 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2642 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2643 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2644 this.el.set_value(iter, 5, type);
2652 xtype: Gtk.TreeViewColumn,
2654 this.el = new Gtk.TreeViewColumn();
2655 this.parent.el.append_column(this.el);
2657 XObject.prototype.init.call(this);
2658 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2663 xtype: Gtk.CellRendererText,
2664 pack : "pack_start,true"
2688 xtype: Gtk.Notebook,
2689 pack : "pack_start,true,true",
2690 id : "view-help-nb",
2692 XObject.prototype.init.call(this);
2693 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2694 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2698 xtype: Gtk.Notebook,
2700 id : "view-notebook",
2703 XObject.prototype.init.call(this);
2704 this.el.set_current_page(0);
2706 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2707 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2714 id : "RightBrowser",
2717 xtype: Gtk.ScrolledWindow,
2719 shadow_type : Gtk.ShadowType.IN,
2721 XObject.prototype.init.call(this);
2722 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2726 xtype: WebKit.WebView,
2730 XObject.prototype.init.call(this);
2731 // this may not work!?
2732 this.el.open('file:///' + __script_path__ + '/../builder.html');
2736 this.el, /* widget that will accept a drop */
2737 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2738 null, /* lists of target to support */
2739 0, /* size of list */
2740 Gdk.DragAction.COPY /* what to do with data after dropped */
2743 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2744 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2746 renderJS : function(data) {
2747 print("HTML RENDERING");
2748 /// prevent looping..
2749 //if (this.pendingRedraw) {
2750 // print("pending redraw active?!");
2755 if (!this.get('/Window.LeftTree').getActiveFile()) {
2759 var project = this.get('/Window.LeftTree').getActiveFile().project;
2760 //print (project.fn);
2762 project.runhtml = project.runhtml || '';
2765 this.runhtml = this.runhtml || '';
2767 if (project.runhtml != this.runhtml) {
2768 // then we need to reload the browser using
2769 // load_html_string..
2771 // then trigger a redraw once it's loaded..
2772 this.pendingRedraw = true;
2774 this.runhtml = project.runhtml;
2776 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2777 html = html.replace('</head>', this.runhtml + '</head>');
2778 print("LOAD HTML " + html);
2779 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2780 // should trigger load_finished!
2785 this.pendingRedraw = false;
2788 this.renderedData = data;
2789 var str = JSON.stringify(data) ;
2792 console.log('not loaded yet');
2794 //Seed.print("RENDER:" + str);
2795 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2797 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2800 load_finished : function (self, object) {
2801 // if (this.ready) { // dont do it twice!
2805 this.pendingRedraw = false;
2806 var js = this.get('/LeftTree.model').toJS();
2808 this.renderJS(js[0]);
2812 script_alert : function (self, object, p0) {
2815 return true; // do not display anything...
2817 console_message : function (self, object, p0, p1) {
2818 // console.log(object);
2819 if (!object.match(/^\{/)) {
2821 this.get('/Terminal').feed(object);
2822 return true; // do not handle!!! -> later maybe in console..
2824 // console.log(object);
2825 var val = JSON.parse(object);
2827 if (typeof(val['hover-node']) != 'undefined') {
2828 this.activeNode = val['hover-node'];
2829 console.log('active node: ' + this.activeNode);
2834 if (typeof(val['id']) != 'undefined') {
2835 // this.activeNode = val['id'];
2836 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2840 this.get('/LeftTree.view').selectNode(tg[0]);
2844 if (ret && typeof(val['set']) != 'undefined') {
2845 this.get('/LeftPanel.model').add({
2849 //console.log('active node: ' + this.activeNode);
2852 //Seed.print('a:'+a);
2853 //Seed.print('b:'+b);
2854 //Seed.print('c:'+c);
2857 drag_motion : function (w, ctx, x, y, time, ud) {
2858 // console.log('DRAG MOTION');
2860 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2861 this.targetData = [];
2862 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2864 // A) find out from drag all the places that node could be dropped.
2865 var src = Gtk.drag_get_source_widget(ctx);
2866 if (!src.dropList) {
2867 Gdk.drag_status(ctx, 0, time);
2870 // b) get what we are over.. (from activeNode)
2871 // tree is empty.. - list should be correct..
2872 if (!this.get('/LeftTree.model').currentTree) {
2873 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2877 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2879 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2882 Gdk.drag_status(ctx, 0,time);
2883 this.get('/LeftTree.view').highlight(false);
2887 // if we have a target..
2888 // -> highlight it! (in browser)
2889 // -> highlight it! (in tree)
2891 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2892 this.get('/LeftTree.view').highlight(tg);
2893 this.targetData = tg;
2894 // for tree we should handle this...
2897 drag_drop : function (w, ctx, x, y,time, ud) {
2898 print("TARGET: drag-drop");
2899 var is_valid_drop_site = true;
2904 w, /* will receive 'drag-data-received' signal */
2905 ctx, /* represents the current state of the DnD */
2906 this.get('/Window').atoms["STRING"], /* the target type we want */
2907 time /* time stamp */
2911 /* No target offered by source => error */
2914 return is_valid_drop_site;
2916 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2918 print("Browser: drag-data-received");
2919 var delete_selection_data = false;
2920 vardnd_success = false;
2921 /* Deal with what we are given from source */
2922 if( sel_data && sel_data.length ) {
2924 if (ctx.action == Gdk.DragAction.ASK) {
2925 /* Ask the user to move or copy, then set the ctx action. */
2928 if (ctx.action == Gdk.DragAction.MOVE) {
2929 delete_selection_data = true;
2931 var source = Gtk.drag_get_source_widget(ctx);
2933 print("Browser: source.DRAGDATA? " + source.dragData);
2934 if (this.targetData) {
2935 print(this.targetData);
2936 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2945 if (dnd_success == false)
2947 Seed.print ("DnD data transfer failed!\n");
2950 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2961 id : "RightGtkView",
2963 redraw : function() {
2964 this.highlightWidget = false;
2965 print("REDRAW CALLED");
2966 this.activePath = this.get('/LeftTree').getActivePath();
2967 if (this.renderedEl) {
2968 print("QUEUE DRAW CALLING");
2969 this.renderedEl.queue_draw();
2972 renderJS : function(data, withDebug)
2974 this.highlightWidget = false;
2976 this.withDebug = false;
2978 if (this.renderedEl) {
2979 this.get('view').el.remove(this.renderedEl);
2980 this.renderedEl.destroy();
2981 this.renderedEl = false;
2986 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
2987 // in theory tree is actually window..
2989 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
2994 this.get('view').el.set_size_request(
2995 tree.default_width * 1 || 400, tree.default_height * 1 || 400
2998 this.renderedEl.set_size_request(
2999 tree.default_width || 600,
3000 tree.default_height || 400
3002 this.get('view').el.show_all();
3007 showInWindow : function() {
3008 print("GET PROEJCT");
3009 var pr = this.get('/LeftProjectTree').getActiveProject();
3011 console.log(pr.paths);
3014 var src= this.buildJS(
3015 this.get('/LeftTree.model').toJS()[0],
3020 //var x = new imports.sandbox.Context();
3024 Seed.check_syntax('var e = ' + src);
3027 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3028 this.get('/Terminal').feed(console._dump(e)+"\n");
3030 var lines = src.split("\n");
3031 var start = Math.max(0, e.line - 10);
3032 var end = Math.min(lines.length, e.line + 10);
3033 for (var i =start ; i < end; i++) {
3035 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3038 this.get('/Terminal').feed(lines[i] + "\n");
3045 this.get('/BottomPane').el.set_current_page(1);
3046 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3047 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3048 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3050 var _top = x.get_global_object()._top;
3052 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3054 if (_top.el.popup) {
3055 _top.el.popup(null, null, null, null, 3, null);
3059 viewAdd : function(item, par)
3061 // does something similar to xobject..
3062 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3064 if (item.pack===false || item.pack === 'false') { // no ;
3067 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3068 var type = item['|xns'] + '.' + item['xtype'];
3069 var ns = imports.gi[item['|xns']];
3070 var ctr = ns[item['xtype']];
3072 for(var k in item) {
3074 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3089 if (k[0] == '|' && typeof(kv) == 'string') {
3091 if (kv.match(new RegExp('function'))) {
3094 print("WASL " + k + '=' + kv);
3096 eval( 'kv = ' + kv);
3097 } catch(e) { continue; }
3100 // print(k + '=' + kv);
3102 if (k[0] == '|') { // should be boolean or number..
3104 //print(k + '=' + kv);
3107 if (k == 'show_tabs') { // force tab showing for notebooks.
3110 print(k + '=' + typeof(kv) + " : " + kv);
3116 var el = new ctr(ctr_args);
3118 print("PACK" + item.pack);
3119 //console.dump(item.pack);
3126 if (typeof(item.pack) == 'string') {
3128 item.pack.split(',').forEach(function(e, i) {
3130 if (e == 'false') { args.push( false); return; }
3131 if (e == 'true') { args.push( true); return; }
3132 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3135 //print(args.join(","));
3137 pack_m = args.shift();
3139 pack_m = item.pack.shift();
3144 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3146 name: "ArgumentError",
3147 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3148 "ADDING : " + item.id + " " + el
3157 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3158 //Seed.print('args: ' + args.length);
3160 par[pack_m].apply(par, args);
3164 item.items = item.items || [];
3165 item.items.forEach(function(ch,n) {
3167 print ("type:" + type);
3169 print ("ch.pack:" + ch.pack);
3170 if (type == 'Gtk.Table' && ch.pack == 'add') {
3171 var c = n % item.n_columns;
3172 var r = Math.floor(n/item.n_columns);
3173 ch.pack = [ 'attach', c, c+1, r, r+1,
3174 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3175 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3176 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3177 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3181 _this.viewAdd(ch, el);
3186 // add the signal handlers.
3187 // is it a widget!?!!?
3193 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3194 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3195 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3196 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3197 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3207 widgetDragDropEvent : function() {
3208 print("WIDGET DRAGDROP");
3211 widgetDragMotionEvent : function() {
3212 print("WIDGET DRAGMOTION");
3215 widgetExposeEvent : function(w, evt, ud, item) {
3217 if (this.inRender) {
3221 if ( this.highlightWidget) {
3222 this.inRender = true;
3223 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3224 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3226 this.inRender = false;
3231 if (this.activePath != item.xtreepath) {
3235 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3236 // work out the coords of the window..
3238 var dr = widget.window;
3239 this.gc = (new Gdk.GC.c_new(dr));
3240 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3241 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3245 var r = evt.expose.area;
3246 // console.dump([r.x, r.y, r.width, r.height ] );
3248 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3249 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3250 // happens with gtkscrollview embedded stuff..
3251 var np =this.activePath.split(':');
3253 this.activePath = np.join(':');
3254 this.renderedEl.queue_draw();
3270 this.inRender = true;
3273 this.highlightWidget = widget;
3278 // print("DRAW BOX");
3279 //console.dump(this.box);
3280 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3281 this.inRender = false;
3284 widgetPressEvent : function(w,e,u,d) {
3285 if (this.get('view').pressed) {
3288 this.get('view').pressed = true;
3289 print("WIDGET PRESS " + d.xtreepath );
3290 this.get('/LeftTree.view').selectNode( d.xtreepath );
3293 widgetReleaseEvent : function() {
3294 this.get('view').pressed = false;
3300 pack : "pack_start,false,true,0",
3304 pack : "pack_start,false,false,0",
3305 label : "Run The Application",
3307 button_press_event : function (self, event) {
3308 // call render on left tree - with special option!?!
3310 //print("GET PROEJCT");
3311 var pr = this.get('/LeftProjectTree').getActiveProject();
3314 for (var i in pr.paths) {
3318 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3319 this.get('/Terminal').feed("RUN DIR:" + dir);
3321 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3322 , false,false,false);
3323 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3324 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3334 xtype: Gtk.ScrolledWindow,
3337 shadow_type : Gtk.ShadowType.IN,
3339 XObject.prototype.init.call(this);
3340 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3344 xtype: Gtk.EventBox,
3345 pack : "add_with_viewport",
3347 XObject.prototype.init.call(this);
3348 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3349 red: 0x9F00, green: 0xB800 , blue : 0xA800
3357 XObject.prototype.init.call(this);
3358 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3359 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3364 xtype: Gtk.EventBox,
3367 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3368 XObject.prototype.init.call(this);
3372 this.el, /* widget that will accept a drop */
3373 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3374 null, /* lists of target to support */
3375 0, /* size of list */
3376 Gdk.DragAction.COPY /* what to do with data after dropped */
3379 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3380 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3383 getActiveNode : function(x,y)
3385 // workout what node is here..
3386 return '0'; // top..
3390 drag_motion : function (self, ctx, x, y, time) {
3392 // A) find out from drag all the places that node could be dropped.
3393 var src = Gtk.drag_get_source_widget(ctx);
3394 if (!src.dropList) {
3395 Gdk.drag_status(ctx, 0, time);
3398 // b) get what we are over.. (from activeNode)
3399 // tree is empty.. - list should be correct..
3400 if (!this.get('/LeftTree.model').currentTree) {
3401 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3405 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3406 var activeNode = this.getActiveNode(x, y);
3409 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3412 Gdk.drag_status(ctx, 0,time);
3413 this.get('/LeftTree.view').highlight(false);
3417 // if we have a target..
3418 // -> highlight it! (in browser)
3419 // -> highlight it! (in tree)
3421 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3422 this.get('/LeftTree.view').highlight(tg);
3423 this.targetData = tg;
3424 // for tree we should handle this...
3427 drag_drop : function (self,ctx, x, y, time) {
3428 Seed.print("TARGET: drag-drop");
3429 var is_valid_drop_site = true;
3434 self, /* will receive 'drag-data-received' signal */
3435 ctx, /* represents the current state of the this.gDnD */
3436 this.get('/Window').atoms["STRING"], /* the target type we want */
3437 time /* time stamp */
3441 /* No target offered by source => error */
3444 return is_valid_drop_site;
3447 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3449 Seed.print("GtkView: drag-data-received");
3450 var delete_selection_data = false;
3451 var dnd_success = false;
3452 /* Deal with what we are given from source */
3453 if( sel_data && sel_data.length ) {
3455 if (ctx.action == Gdk.DragAction.ASK) {
3456 /* Ask the user to move or copy, then set the ctx action. */
3459 if (ctx.action == Gdk.DragAction.MOVE) {
3460 delete_selection_data = true;
3462 var source = Gtk.drag_get_source_widget(ctx);
3464 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3465 if (this.targetData) {
3466 Seed.print(this.targetData);
3467 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3476 if (dnd_success == false)
3478 Seed.print ("DnD data transfer failed!\n");
3481 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3484 button_press_event : function (self, event) {
3485 this.pressed = false;
3501 xtype: Gtk.ScrolledWindow,
3506 var file = this.get('/LeftTree').getActiveFile();
3510 var activeEl = this.get('/LeftTree').getActiveElement();
3511 var xtype = file.guessName( activeEl )
3512 if (!xtype || !xtype.length) {
3515 this.get('/Window.view-help-nb').el.set_current_page(1);
3517 // get the active element being edited.
3518 var helpurl = file.getHelpUrl(xtype);
3520 // now load the help info in the page..
3521 this.get('help-view').el.open(helpurl);
3525 xtype: WebKit.WebView,
3529 XObject.prototype.init.call(this);
3530 this.get('/Window.help-view').el.open(
3531 "http://devel.akbkhome.com/seed/");
3543 xtype: Gtk.Notebook,
3546 XObject.prototype.init.call(this);
3547 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3548 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3553 xtype: Gtk.ScrolledWindow,
3558 xtype: GtkSource.View,
3562 XObject.prototype.init.call(this);
3563 var description = Pango.Font.description_from_string("monospace")
3564 description.set_size(8000);
3565 this.el.modify_font(description);
3568 load : function(str) {
3570 // show the help page for the active node..
3571 this.get('/Help').show();
3574 this.get('/BottomPane').el.set_current_page(0);
3575 this.el.get_buffer().set_text(str, str.length);
3576 var lm = GtkSource.LanguageManager.get_default();
3578 this.el.get_buffer().set_language(lm.get_language('js'));
3579 var buf = this.el.get_buffer();
3580 var cursor = buf.get_mark("insert");
3581 var iter= new Gtk.TextIter;
3582 buf.get_iter_at_mark(iter, cursor);
3584 iter.set_line_offset(4);
3585 buf.move_mark(cursor, iter);
3588 cursor = buf.get_mark("selection_bound");
3589 iter= new Gtk.TextIter;
3590 buf.get_iter_at_mark(iter, cursor);
3592 iter.set_line_offset(4);
3593 buf.move_mark(cursor, iter);
3595 this.el.grab_focus();
3597 insert_spaces_instead_of_tabs : true,
3600 show_line_numbers : true,
3603 xtype: GtkSource.Buffer,
3604 pack : "set_buffer",
3606 changed : function (self) {
3607 var s = new Gtk.TextIter();
3608 var e = new Gtk.TextIter();
3609 this.el.get_start_iter(s);
3610 this.el.get_end_iter(e);
3611 var str = this.el.get_text(s,e,true);
3613 Seed.check_syntax('var e = ' + str);
3615 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3616 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3618 print("SYNTAX ERROR IN EDITOR");
3623 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3624 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3627 this.get('/LeftPanel.model').changed( str , false);
3636 xtype: Gtk.ScrolledWindow,
3640 xtype: Vte.Terminal,
3643 feed : function(istr) {
3644 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3645 // we should make ourselves visable!!!
3646 this.get('/BottomPane').el.show();
3647 this.get('/BottomPane').el.set_current_page(1);
3649 this.el.feed(str ,str.length);
3651 scroll_on_output : true,
3653 XObject.prototype.init.call(this);
3654 this.el.set_size (80, 1000);
3656 scrollback_lines : 1000
3666 pack : "pack_start,false,false",
3670 this.get('buttonbar').el.show();
3671 this.get('viewbox').el.hide();
3672 print("TRIED TO HIDE");
3675 this.get('buttonbar').el.hide();
3676 this.get('viewbox').el.show();
3677 // this.get('model').expanded();
3689 pack : "pack_start,false,true",
3691 clicked : function (self) {
3692 this.get('/RightPalete').show();
3699 stock : Gtk.STOCK_GOTO_FIRST,
3700 icon_size : Gtk.IconSize.MENU
3710 XObject.prototype.init.call(this);
3711 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3714 enter_notify_event : function (self, event) {
3715 this.get('/RightPalete').show();
3729 pack : "pack_start,false,true",
3738 pack : "pack_start,false,true",
3740 clicked : function (self) {
3741 this.get('/RightPalete').hide();
3748 stock : Gtk.STOCK_GOTO_LAST,
3749 icon_size : Gtk.IconSize.MENU
3756 xtype: Gtk.ScrolledWindow,
3759 XObject.prototype.init.call(this);
3760 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3761 this.el.set_size_request(-1,200);
3763 shadow_type : Gtk.ShadowType.IN,
3766 xtype: Gtk.TreeView,
3769 XObject.prototype.init.call(this);
3770 this.el.set_size_request(150,-1);
3771 // set_reorderable: [1]
3773 var description = new Pango.FontDescription.c_new();
3774 description.set_size(8000);
3775 this.el.modify_font(description);
3777 this.selection = this.el.get_selection();
3778 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3779 // this.selection.signal['changed'].connect(function() {
3780 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3782 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3784 Gtk.drag_source_set (
3785 this.el, /* widget will be drag-able */
3786 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3787 null, /* lists of target to support */
3788 0, /* size of list */
3789 Gdk.DragAction.COPY /* what to do with data after dropped */
3791 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3793 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3794 Gtk.drag_source_add_text_targets(this.el);
3796 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3797 targets = new Gtk.TargetList();
3798 targets.add( LeftTree.atoms["STRING"], 0, 0);
3799 targets.add_text_targets( 1 );
3800 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3802 //if you want to allow text to be output elsewhere..
3803 //Gtk.drag_source_add_text_targets(this.el);
3807 headers_visible : false,
3808 enable_tree_lines : true,
3810 drag_begin : function (self, ctx) {
3811 // we could fill this in now...
3812 Seed.print('SOURCE: drag-begin');
3816 var iter = new Gtk.TreeIter();
3817 var s = this.selection;
3818 s.get_selected(this.get('/RightPalete.model').el, iter);
3819 var path = this.get('/RightPalete.model').el.get_path(iter);
3821 var pix = this.el.create_row_drag_icon ( path);
3824 Gtk.drag_set_icon_pixmap (ctx,
3831 var value = new GObject.Value('');
3832 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3833 if (!this.get('/RightPalete').provider) {
3836 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3837 this.el.dragData = value.value;
3844 drag_data_get : function (self, drag_context, selection_data, info, time) {
3845 //Seed.print('Palete: drag-data-get: ' + target_type);
3846 if (this.el.dragData && this.el.dragData.length ) {
3847 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3851 //this.el.dragData = "TEST from source widget";
3855 drag_end : function (self, drag_context) {
3856 Seed.print('SOURCE: drag-end');
3857 this.el.dragData = false;
3858 this.el.dropList = false;
3859 this.get('/LeftTree.view').highlight(false);
3865 xtype: Gtk.ListStore,
3868 XObject.prototype.init.call(this);
3869 this.el.set_column_types ( 2, [
3870 GObject.TYPE_STRING, // title
3871 GObject.TYPE_STRING // tip
3876 load : function(tr,iter)
3881 //console.log('Project tree load: ' + tr.length);
3882 var citer = new Gtk.TreeIter();
3883 //this.insert(citer,iter,0);
3884 for(var i =0 ; i < tr.length; i++) {
3887 this.el.append(citer);
3889 this.el.insert(citer,iter,-1);
3894 this.el.set_value(citer, 0, '' + r ); // title
3896 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3897 //if (r.cn && r.cn.length) {
3898 // this.load(r.cn, citer);
3904 getValue : function (iter, col) {
3905 var gval = new GObject.Value('');
3906 this.el.get_value(iter, col ,gval);
3913 xtype: Gtk.TreeViewColumn,
3914 pack : "append_column",
3916 XObject.prototype.init.call(this);
3917 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3921 xtype: Gtk.CellRendererText,
3943 XObject.cache['/Window'] = Window;