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",
172 activate : function (self) {
173 var fn = this.get('/LeftTree').getActiveFile();
175 this.get('/StandardErrorDialog').show("No File active");
179 this.get('/DialogNewComponent').show(fn);
183 label : "File _Properties",
190 activate : function (self, event) {
191 this.get('/RooProjectProperties').show();
195 label : "Modify Project HTML ",
206 use_underline : true,
210 pack : "set_submenu",
218 activate : function (self, event) {
219 var js = this.get('/LeftTree.model').toJS();
221 this.get('/RightBrowser.view').renderJS(js[0]);
226 label : "_Redraw (Roo)",
233 activate : function (self, event)
235 /* Firefox testing for debugging..
236 - we can create a /tmp directory, and put.
237 builder.html, builder.html.js, link roojs1
238 add at the end of builder.html Roo.onload(function() {
240 if (!this.get('/Window.LeftTree').getActiveFile()) {
244 var js = this.get('/LeftTree.model').toJS();
248 var project = this.get('/Window.LeftTree').getActiveFile().project;
249 //print (project.fn);
251 project.runhtml = project.runhtml || '';
254 var File = imports.File.File;
256 var target = "/tmp/firetest"; // fixme..
257 if (!File.isDirectory(target)) {
260 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
261 if (!File.exists( target+ '/roojs1')) {
262 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
267 var html = imports.File.File.read(__script_path__ + '/../builder.html');
268 html = html.replace('</head>', project.runhtml + '</head>');
271 var jsstr = JSON.stringify(js[0]);
273 var runbuilder = '<script type="text/javascript">' + "\n" +
274 " Builder.render(" + jsstr + ");\n" +
277 html = html.replace('</body>', runbuilder + '</body>');
279 File.write( target+ '/builder.html', html);
281 this.get('/Terminal').feed("RUN DIR:" + target);
283 this.get('/Terminal').el.fork_command( null , [], [], target
284 , false,false,false);
285 var cmd = "firefox file://" + target + "/builder.html \n";
286 this.get('/Terminal').el.feed_child(cmd, cmd.length);
290 label : "_Test in Firefox (Roo)",
301 use_underline : true,
309 pack : "set_submenu",
318 use_underline : true,
320 activate : function (self) {
321 this.get('/About').el.run();
351 activate : function (self) {
352 var nb = this.get('/LeftTopPanel.notebook');
353 if (this.el.expanded) {
356 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
359 var model = this.get('/LeftProjectTree.combomodel');
360 // print ("loading Projects?")
361 //console.dump(pm.projects);
362 model.loadData(pm.projects);
365 nb.el.set_current_page(1);
366 //pm.on('changed', function() {
367 //console.log("CAUGHT project manager change");
368 // _combo.model.loadData(pm.projects);
372 nb.el.set_current_page(0);
374 enter_notify_event : function (self, event) {
375 this.el.expanded = !this.el.expanded;
376 //if (this.el.expanded ) {
377 this.listeners.activate.call(this);
384 label : "Select Project or File",
385 pack : "pack_start,false,true",
387 XObject.prototype.init.call(this);
388 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
396 pack : "pack_start,true,true",
398 XObject.prototype.init.call(this);
399 this.el.set_current_page(0);
404 xtype: Gtk.ScrolledWindow,
407 getActiveElement : function() { // return path to actie node.
409 var path = this.getActivePath();
413 var iter = new Gtk.TreeIter();
414 this.get('model').el.get_iter_from_string(iter, path);
416 var value = new GObject.Value('');
417 this.get('model').el.get_value(iter, 2, value);
419 return JSON.parse(value.value);
421 getActiveFile : function() {
422 return this.get('model').file;
424 getActivePath : function() {
425 var model = this.get('model');
426 var view = this.get('view');
427 if (view.selection.count_selected_rows() < 1) {
430 var iter = new Gtk.TreeIter();
432 view.selection.get_selected(model.el, iter);
433 return model.el.get_path(iter).to_string();
435 getPaleteProvider : function() {
436 var model = this.get('model');
437 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
438 return pm.getPalete(model.file.getType());
440 getRenderer : function() {
442 switch( this.getActiveFile().getType()) {
444 return this.get('/RightBrowser.view');
446 return this.get('/RightGtkView');
451 XObject.prototype.init.call(this);
452 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
454 renderView : function() {
455 var render = this.getRenderer();
456 var model = this.get('model');
458 render.renderJS(model.toJS(false,true)[0]);
460 print("NO RENDER JS METHOD?");
463 shadow_type : Gtk.ShadowType.IN,
469 headers_visible : false,
470 enable_tree_lines : true,
473 XObject.prototype.init.call(this);
474 var description = new Pango.FontDescription.c_new();
475 description.set_size(8000);
476 this.el.modify_font(description);
478 this.selection = this.el.get_selection();
479 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
482 // is this really needed??
483 this.selection.signal['changed'].connect(function() {
484 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
485 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
489 Gtk.drag_source_set (
490 this.el, /* widget will be drag-able */
491 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
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_source_set_target_list(this.el, this.get('/Window').targetList);
499 Gtk.drag_source_add_text_targets(this.el);
502 this.el, /* widget that will accept a drop */
503 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
504 null, /* lists of target to support */
505 0, /* size of list */
506 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
509 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
510 Gtk.drag_dest_add_text_targets(this.el);
512 highlight : function(treepath_ar) {
514 // highlighting for drag/drop
515 if (treepath_ar.length && treepath_ar[0].length ) {
516 this.el.set_drag_dest_row(
517 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
519 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
523 selectNode : function(treepath_str) {
524 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
525 var tp = new Gtk.TreePath.from_string(treepath_str);
526 this.el.set_cursor(tp, null, false);
527 this.el.scroll_to_cell(tp, null, false, 0,0);
530 button_press_event : function (self, ev) {
531 console.log("button press?");
532 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
533 print("click" + ev.type);
539 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
541 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
543 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
544 this.get('/LeftTreeMenu').el.show_all();
545 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
546 print("click:" + res.path.to_string());
549 drag_begin : function (self, drag_context) {
550 print('SOURCE: drag-begin');
551 this.targetData = false;
552 // find what is selected in our tree...
553 var iter = new Gtk.TreeIter();
554 var s = this.selection;
555 s.get_selected(this.get('/LeftTree.model').el, iter);
557 // set some properties of the tree for use by the dropped element.
558 var value = new GObject.Value('');
559 this.get('/LeftTree.model').el.get_value(iter, 2, value);
560 var data = JSON.parse(value.value);
561 var xname = this.get('/LeftTree.model').file.guessName(data);
563 this.el.dragData = xname;
564 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
567 // make the drag icon a picture of the node that was selected
568 var path = this.get('/LeftTree.model').el.get_path(iter);
569 this.el.treepath = path.to_string();
571 var pix = this.el.create_row_drag_icon ( path);
573 Gtk.drag_set_icon_pixmap (ctx,
582 drag_end : function (self, drag_context) {
583 Seed.print('LEFT-TREE: drag-end');
584 this.el.dragData = false;
585 this.el.dropList = false;
586 this.targetData = false;
587 this.get('/LeftTree.view').highlight(false);
590 drag_motion : function (self, ctx, x, y, time) {
591 console.log("LEFT-TREE: drag-motion");
592 var src = Gtk.drag_get_source_widget(ctx);
594 // a drag from elsewhere...- prevent drop..
596 print("no drag data!");
597 Gdk.drag_status(ctx, 0, time);
598 this.targetData = false;
601 var action = Gdk.DragAction.COPY;
602 if (src == this.el) {
603 // unless we are copying!!! ctl button..
604 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
608 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
609 // no children.. -- asume it's ok..
610 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
611 Gdk.drag_status(ctx, action ,time);
615 print("GETTING POS");
616 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
617 print("ISOVER? " + isOver);
619 Gdk.drag_status(ctx, 0 ,time);
620 return false; // not over apoint!?!
622 // drag node is parent of child..
623 console.log("SRC TREEPATH: " + src.treepath);
624 console.log("TARGET TREEPATH: " + data.path.to_string());
626 // nned to check a few here..
627 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
628 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
629 //Gtk.TreeViewDropPosition.AFTER
630 //Gtk.TreeViewDropPosition.BEFORE
632 if (typeof(src.treepath) != 'undefined' &&
633 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
634 print("subpath drag");
635 Gdk.drag_status(ctx, 0 ,time);
640 //print("DUMPING DATA");
641 //console.dump(data);
644 print(data.path.to_string() +' => '+ data.pos);
645 var tg = this.get('/LeftTree.model').findDropNodeByPath(
646 data.path.to_string(), src.dropList, data.pos);
648 this.get('/LeftTree.view').highlight(tg);
650 print("Can not find drop node path");
651 this.targetData = false;
652 Gdk.drag_status(ctx, 0, time);
656 this.targetData = tg;
659 Gdk.drag_status(ctx, action ,time);
663 drag_drop : function (w, ctx, x, y, time) {
664 Seed.print("TARGET: drag-drop");
668 w, /* will receive 'drag-data-received' signal */
669 ctx, /* represents the current state of the DnD */
670 this.get('/Window').atoms["STRING"], /* the target type we want */
671 time /* time stamp */
675 /* No target offered by source => error */
680 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
681 print("Tree: drag-data-received");
683 var delete_selection_data = false;
684 var dnd_success = false;
685 /* Deal with what we are given from source */
686 if( sel_data && sel_data.length ) {
688 if (ctx.action == Gdk.DragAction.ASK) {
689 /* Ask the user to move or copy, then set the ctx action. */
692 if (ctx.action == Gdk.DragAction.MOVE) {
693 //delete_selection_data = true;
696 var source = Gtk.drag_get_source_widget(ctx);
698 if (this.targetData) {
699 if (source != this.el) {
700 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
702 // drag around.. - reorder..
703 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
707 //Seed.print(this.targetData);
713 // we can send stuff to souce here...
719 if (dnd_success == false)
721 Seed.print ("DnD data transfer failed!\n");
724 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
727 cursor_changed : function (self) {
728 if (this.blockChanges) { // probably not needed..
731 var render = this.get('/LeftTree').getRenderer();
734 if (this.selection.count_selected_rows() < 1) {
735 this.get('/LeftPanel.model').load( false);
736 this.get('/MidPropTree').activeElement = false;
737 this.get('/MidPropTree').hideWin();
739 var pm = this.get('/RightPalete.model');
740 if (!this.get('/LeftTree').getPaleteProvider()) {
741 // it may not be loaded yet..
744 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
745 this.get('/LeftTree.model').listAllTypes()));
746 if (render && render.redraw) {
752 //console.log('changed');
753 var s = this.selection;
754 var iter = new Gtk.TreeIter();
755 s.get_selected(this.get('/LeftTree.model').el, iter);
759 var value = new GObject.Value('');
760 this.get('/LeftTree.model').el.get_value(iter, 2, value);
761 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
763 var data = JSON.parse(value.value);
764 this.get('/MidPropTree').activeElement = data;
765 this.get('/MidPropTree').hideWin();
766 this.get('/LeftPanel.model').load( data);
768 console.log(value.value);
769 // _g.button.set_label(''+value.get_string());
771 var pm =this.get('/RightPalete.model');
772 pm.load( this.get('/RightPalete').provider.gatherList(
773 this.get('/LeftTree.model').listAllTypes()));
776 if (render && render.redraw) {
780 //Seed.print( value.get_string());
787 xtype: Gtk.TreeStore,
792 changed : function(n, refresh) {
793 print("MODEL CHANGED CALLED" + this.activePath);
794 if (this.activePath) {
795 var iter = new Gtk.TreeIter();
796 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
797 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
798 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
800 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
802 //this.currentTree = this.toJS(false, true)[0];
803 this.file.items = this.toJS(false, false);
804 print("AFTER CHANGED");
805 //console.dump(this.file.items);
807 this.currentTree = this.file.items[0];
808 //console.log(this.file.toSource());
811 print("REDNER BROWSER?!");
812 this.get('/LeftTree').renderView();
814 var pm = this.get('/RightPalete.model');
815 if (!this.get('/RightPalete').provider) {
821 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
822 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
826 deleteSelected : function() {
827 this.get('/LeftTree.view').blockChanges = true;
828 var old_iter = new Gtk.TreeIter();
829 var s = this.get('/LeftTree.view').selection;
830 s.get_selected(this.el, old_iter);
831 var path = this.el.get_path(old_iter).to_string();
833 this.activePath= false;
836 this.activePath= false;
837 var iter = new Gtk.TreeIter();
838 this.el.get_iter_from_string(iter, path);
839 this.el.remove(iter);
841 // rebuild treemap. -- depreciated.!!
844 //this.toJS(null, true) // does not do anything?
845 this.activePath= false;
846 this.changed(false,true);
847 this.get('/LeftTree.view').blockChanges = false;
849 dropNode : function(target_data, node) {
851 // console.dump(node);
852 // console.dump(target_data);
853 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
855 print("add " + tp + "@" + target_data[1] );
858 if (tp && target_data[1] < 2) { // before or after..
859 var ar = target_data[0].split(':');
861 parent = new Gtk.TreePath.from_string( ar.join(':') );
864 var n_iter = new Gtk.TreeIter();
865 var iter_par = new Gtk.TreeIter();
866 var iter_after = after ? new Gtk.TreeIter() : false;
870 if (parent !== false) {
871 this.el.get_iter(iter_par, parent);
878 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
879 this.el.get_iter(iter_after, after);
880 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
881 n_iter, iter_par, iter_after);
884 this.el.append(n_iter, iter_par);
888 if (typeof(node) == 'string') {
889 var ar = node.split('.');
890 var xtype = ar.pop();
893 '|xns' : ar.join('.'),
896 if (target_data.length == 3 && target_data[2].length) {
897 node['*prop'] = target_data[2];
899 node = this.get('/DialogTemplateSelect').show(node);
902 // work out what kind of packing to use..
903 if (typeof(node.pack) == 'undefined' && parent !== false) {
904 var pal = this.get('/LeftTree').getPaleteProvider();
905 if (pal.name == 'Gtk') {
906 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
907 var cname = pal.guessName(node);
908 node.pack = pal.getDefaultPack(pname, cname);
919 // load children - if it has any..
922 this.load(xitems, n_iter);
923 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
925 if (tp && (xitems || after)) {
926 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
928 // wee need to get the empty proptypes from somewhere..
930 //var olditer = this.activeIter;
931 this.activePath = this.el.get_path(n_iter).to_string();
933 // changed actually set's the node data..
934 this.changed(node, true);
938 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
940 //Builder.MidPropTree._model.load(node);
941 //Builder.MidPropTree._win.hideWin();
942 //Builder.LeftPanel._model.load( node);
946 findDropNode : function(treepath_str, targets) {
948 // this is used by the dragdrop code in the roo version AFAIR..
950 var path = treepath_str.replace(/^builder-/, '');
951 // treemap is depreciated... - should really check if model has any entries..
953 if (!this.el.iter_n_children(null)) {
955 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
957 print("FIND treepath: " + path);
958 //console.dump(this.treemap);
960 if (!treepath_str.match(/^builder-/)) {
961 return []; // nothing!
963 if (targets === true) {
966 return this.findDropNodeByPath(path,targets)
968 findDropNodeByPath : function(treepath_str, targets, pref) {
969 var path = treepath_str + ''; // dupe it..
970 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
972 //console.dump(this.treemap);
973 while (path.length) {
974 print("LOOKING FOR PATH: " + path);
975 var node_data = this.singleNodeToJS(path);
976 if (node_data === false) {
977 print("node not found");
981 var xname = this.get('/LeftTree.model').file.guessName(node_data);
984 targets.forEach(function(tg) {
988 if ((tg == xname) ) {
991 if (tg.indexOf(xname +':') === 0) {
993 prop = tg.split(':').pop();
998 if (last) { // pref is after/before..
999 // then it's after last
1001 return []; // do not allow..
1003 return [ last, pref , prop];
1006 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
1008 var par = path.split(':');
1011 path = par.join(':');
1017 getIterValue : function (iter, col) {
1018 var gval = new GObject.Value('');
1019 this.el.get_value(iter, col ,gval);
1025 XObject.prototype.init.call(this);
1026 this.el.set_column_types ( 3, [
1027 GObject.TYPE_STRING, // title
1028 GObject.TYPE_STRING, // tip
1029 GObject.TYPE_STRING // source..
1032 listAllTypes : function() {
1033 var s = this.get('/LeftTree.view').selection;
1034 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1036 if (s.count_selected_rows() > 0) {
1037 var iter = new Gtk.TreeIter();
1038 s.get_selected(this.el, iter);
1040 // set some properties of the tree for use by the dropped element.
1041 var value = new GObject.Value('');
1042 this.el.get_value(iter, 2, value);
1043 var data = JSON.parse(value.value);
1046 var xname = this.get('/LeftTree.model').file.guessName(data);
1047 console.log('selected:' + xname);
1051 return []; // could not find it..
1059 li.forEach(function(el) {
1060 // this is specific to roo!!!?
1061 if (!el) { // skip empty?
1064 var fullpath = _this.file.guessName(el);
1065 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1070 if (el.items && el.items.length) {
1079 addall([this.currentTree]);
1081 // only if we have nothing, should we add '*top'
1085 //console.log('all types in tree');
1086 //console.dump(ret);
1091 load : function(tr,iter)
1093 var citer = new Gtk.TreeIter();
1094 //this.insert(citer,iter,0);
1095 for(var i =0 ; i < tr.length; i++) {
1097 this.el.insert(citer,iter,-1);
1099 this.el.append(citer);
1102 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1103 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1104 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1105 if (tr[i].items && tr[i].items.length) {
1106 this.load(tr[i].items, citer);
1110 loadFile : function(f) {
1116 console.log('missing file');
1120 // load the file if not loaded..
1121 if (f.items === false) {
1123 f.loadItems(function() {
1129 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1131 if (f.items.length && typeof(f.items[0]) == 'string') {
1133 this.get('/RightEditor').el.show();
1134 this.get('/RightEditor.view').load( f.items[0]);
1138 //console.dump(f.items);
1140 this.get('/LeftTree.view').el.expand_all();
1142 if (!f.items.length) {
1145 this.get('/Window.leftvpaned').el.set_position(80);
1147 this.get('/LeftTree.view').el.set_cursor(
1148 new Gtk.TreePath.from_string('0'), null, false);
1152 this.get('/Window.leftvpaned').el.set_position(200);
1156 //print("hide right editior");
1157 this.get('/RightEditor').el.hide();
1158 //print("set current tree");
1159 this.currentTree = this.toJS(false, false)[0];
1160 //console.dump(this.currentTree);
1161 this.currentTree = this.currentTree || { items: [] };
1162 this.get('/LeftTree').renderView();
1163 //console.dump(this.map);
1164 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1165 var pm = this.get('/RightPalete.model');
1166 // set up provider..
1168 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1170 if (!this.get('/RightPalete').provider) {
1171 print ("********* PALETE PROVIDER MISSING?!!");
1173 this.get('/LeftTree').renderView();
1175 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1179 this.get('/Window.view-notebook').el.set_current_page(
1180 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1183 moveNode : function(target_data, action) {
1184 //print("MOVE NODE");
1185 // console.dump(target_data);
1186 var old_iter = new Gtk.TreeIter();
1187 var s = this.get('/LeftTree.view').selection;
1188 s.get_selected(this.el, old_iter);
1189 var node = this.nodeToJS(old_iter,false);
1190 //console.dump(node);
1193 // needs to drop first, otherwise the target_data
1194 // treepath will be invalid.
1196 this.dropNode(target_data, node);
1197 if (action & Gdk.DragAction.MOVE) {
1198 // print("REMOVING OLD NODE");
1199 this.el.remove(old_iter);
1203 this.activePath= false;
1204 this.changed(false,true);
1206 nodeTip : function(c) {
1207 var ret = this.nodeTitle(c,true);
1213 if (!i.length || i[0] != '|') {
1219 if (typeof(c[i]) != 'string') {
1222 //print("prop : " + i + ':' + c[i]);
1223 if (!c[i].match(new RegExp('function'))) {
1226 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1230 ret+="\n\nMethods:" + funcs;
1235 nodeTitle : function(c, renderfull) {
1238 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1239 if (sr) txt.push('<s>');
1240 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1242 if (renderfull && c['|xns']) {
1243 txt.push(c['|xns']);
1246 if (c.xtype) { txt.push(c.xtype); }
1247 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1248 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1249 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1252 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1253 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1254 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1255 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1256 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1257 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1258 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1259 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1260 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1262 // for flat classes...
1263 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1264 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1267 if (sr) txt.push('</s>');
1268 return (txt.length == 0 ? "Element" : txt.join(" "));
1270 nodeToJS : function (treepath, with_id)
1273 var iter = treepath; // API used to be iter here..
1274 if (typeof(iter) == 'string') {
1275 iter = new Gtk.TreeIter();
1276 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1280 var par = new Gtk.TreeIter();
1281 var iv = this.getIterValue(iter, 2);
1282 // print("IV" + iv);
1283 var k = JSON.parse(iv);
1284 if (k.json && !this.el.iter_parent( par, iter )) {
1289 var treepath_str = this.el.get_path(iter).to_string();
1290 // not sure how we can handle mixed id stuff..
1291 if (typeof(k.id) == 'undefined') {
1292 k.id = 'builder-'+ treepath_str ;
1296 this.treemap[ treepath_str ] = k;
1297 k.xtreepath = treepath_str ;
1300 if (this.el.iter_has_child(iter)) {
1301 citer = new Gtk.TreeIter();
1302 this.el.iter_children(citer, iter);
1303 k.items = this.toJS(citer,with_id);
1307 nodeToJSON : function(c) {
1315 return JSON.stringify(o);
1317 singleNodeToJS : function (treepath)
1319 var iter = new Gtk.TreeIter();
1320 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1324 var iv = this.getIterValue(iter, 2);
1326 return JSON.parse(iv);
1329 toJS : function(treepath, with_id)
1331 //Seed.print("WITHID: "+ with_id);
1332 var iter = treepath; // API used to be iter here..
1333 if (typeof(iter) == 'string') {
1334 iter = new Gtk.TreeIter();
1335 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1344 iter = new Gtk.TreeIter();
1345 if (!this.el.get_iter_first(iter)) {
1355 var k = this.nodeToJS(iter, with_id);
1359 if (!this.el.iter_next(iter)) {
1365 // convert the list into a json string..
1371 xtype: Gtk.TreeViewColumn,
1372 pack : "append_column",
1374 XObject.prototype.init.call(this);
1375 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1379 xtype: Gtk.CellRendererText,
1389 id : "LeftTreeMenu",
1392 xtype: Gtk.MenuItem,
1394 label : "Delete Element",
1396 activate : function (self) {
1398 this.get('/LeftTree.model').deleteSelected();
1403 xtype: Gtk.MenuItem,
1405 activate : function (self) {
1407 var tree = this.get('/LeftTree');
1408 var model = this.get('/LeftTree.model');
1409 var el = tree.getActivePath();
1411 var js = model.toJS(el, false);
1412 // print(JSON.stringify(js[0], null,4));
1413 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1418 label : "Save as Template",
1428 id : "LeftProjectTree",
1429 showNoProjectSelected : function() {
1430 this.get('/StandardErrorDialog').show("Select a Project first.");
1432 getActiveProject : function() {
1433 return this.project;
1436 leave_notify_event : function (self, event) {
1443 pack : "pack_start,false,false",
1446 xtype: Gtk.ComboBox,
1449 XObject.prototype.init.call(this);
1450 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1452 getValue : function() {
1453 var ix = this.el.get_active();
1457 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1458 if (typeof(data[ix]) == 'undefined') {
1463 setValue : function(fn)
1467 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1468 data.forEach(function(n, ix) {
1476 changed : function (self) {
1477 var fn = this.getValue();
1478 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1479 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1484 xtype: Gtk.CellRendererText,
1485 pack : "pack_start,true",
1489 xtype: Gtk.ListStore,
1492 XObject.prototype.init.call(this);
1493 this.el.set_column_types ( 2, [
1494 GObject.TYPE_STRING, // real key
1495 GObject.TYPE_STRING // real type
1499 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1501 pm.on('changed', function() {
1502 print("caught changed hook on project manager - reloading data");
1503 _this.loadData(pm.projects);
1507 loadData : function(data) {
1508 var ov = this.get('/LeftProjectTree.combo').getValue();
1510 var iter = new Gtk.TreeIter();
1512 data.forEach(function(p) {
1517 el.set_value(iter, 0, p.fn);
1518 el.set_value(iter, 1, p.name);
1522 this.get('/LeftProjectTree.combo').setValue(ov);
1531 xtype: Gtk.ScrolledWindow,
1533 shadow_type : Gtk.ShadowType.IN,
1535 XObject.prototype.init.call(this);
1536 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1540 xtype: Gtk.TreeView,
1541 headers_visible : false,
1542 enable_tree_lines : true,
1545 XObject.prototype.init.call(this);
1546 var description = new Pango.FontDescription.c_new();
1547 description.set_size(8000);
1548 this.el.modify_font(description);
1550 this.selection = this.el.get_selection();
1551 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1555 cursor_changed : function (self) {
1556 var iter = new Gtk.TreeIter();
1558 if (this.selection.count_selected_rows() < 1) {
1559 //XN.get('Builder.LeftTree.model').
1560 this.get('/LeftTree.model').load( false);
1564 var model = this.get('/LeftProjectTree.model');
1565 //console.log('changed');
1566 var s = this.selection;
1567 s.get_selected(model, iter);
1568 value = new GObject.Value('');
1569 model.el.get_value(iter, 2, value);
1571 console.log(value.value);// id..
1573 var file = this.get('/LeftProjectTree').project.getById(value.value);
1580 var nb = this.get('/LeftTopPanel.expander');
1581 nb.el.expanded = false;
1582 nb.listeners.activate.call(nb);
1583 //_expander.el.set_expanded(false);
1585 var ltm = this.get('/LeftTree.model');
1593 xtype: Gtk.TreeStore,
1597 XObject.prototype.init.call(this);
1598 this.el.set_column_types ( 3, [
1599 GObject.TYPE_STRING, // title
1600 GObject.TYPE_STRING, // tip
1601 GObject.TYPE_STRING // id..
1605 loadProject : function(pr) {
1606 print("LOAD PROJECT");
1612 this.get('/LeftProjectTree').project = pr;
1613 this.load(pr.toTree());
1614 this.get('/LeftProjectTree.view').el.expand_all();
1616 load : function(tr,iter) {
1617 // console.dump(tr);
1618 console.log('Project tree load: ' + tr.length);
1619 var citer = new Gtk.TreeIter();
1620 //this.insert(citer,iter,0);
1623 tr.forEach(function (r) {
1625 _this.el.append(citer);
1627 _this.el.insert(citer,iter,-1);
1629 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1630 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1631 _this.el.set_value(citer, 2, '' + r.id ); //id
1632 if (r.cn && r.cn.length) {
1633 _this.load(r.cn, citer);
1638 getValue : function(iter, col) {
1639 var gval = new GObject.Value('');
1640 this.el.get_value(iter, col ,gval);
1641 return '' + gval.value;
1645 xtype: Gtk.TreeViewColumn,
1646 pack : "append_column",
1648 XObject.prototype.init.call(this);
1649 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1653 xtype: Gtk.CellRendererText,
1676 pack : "pack_start,false,true,0",
1683 button_press_event : function (self, event) {
1684 this.get('/MidPropTree.model').showData('props');
1696 stock : Gtk.STOCK_ADD,
1697 icon_size : Gtk.IconSize.MENU
1712 button_press_event : function (self, event) {
1713 this.get('/MidPropTree.model').showData('events');
1725 stock : Gtk.STOCK_ADD,
1726 icon_size : Gtk.IconSize.MENU
1741 button_press_event : function (self, ev) {
1742 var p = this.get('/AddPropertyPopup');
1746 p.el.set_screen(Gdk.Screen.get_default());
1748 p.el.popup(null, null, null, null, 3, ev.button.time);
1760 stock : Gtk.STOCK_ADD,
1761 icon_size : Gtk.IconSize.MENU
1773 id : "AddPropertyPopup",
1776 xtype: Gtk.MenuItem,
1778 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1781 activate : function (self) {
1783 this.get('/LeftPanel.model').add( {
1794 xtype: Gtk.MenuItem,
1796 tooltip_markup : "Add what type of packing is to be used",
1799 activate : function (self) {
1801 this.get('/LeftPanel.model').add( {
1811 xtype: Gtk.MenuItem,
1813 tooltip_markup : "Override the init method",
1816 activate : function (self) {
1818 this.get('/LeftPanel.model').add( {
1821 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1828 xtype: Gtk.SeparatorMenuItem,
1832 xtype: Gtk.MenuItem,
1834 tooltip_markup : "Add a user defined string property",
1837 activate : function (self) {
1839 this.get('/LeftPanel.model').add( {
1849 xtype: Gtk.MenuItem,
1851 tooltip_markup : "Add a user defined number property",
1854 activate : function (self) {
1856 this.get('/LeftPanel.model').add( {
1866 xtype: Gtk.MenuItem,
1868 tooltip_markup : "Add a user defined boolean property",
1871 activate : function (self) {
1873 this.get('/LeftPanel.model').add( {
1883 xtype: Gtk.SeparatorMenuItem,
1887 xtype: Gtk.MenuItem,
1889 tooltip_markup : "Add a user function boolean property",
1892 activate : function (self) {
1894 this.get('/LeftPanel.model').add( {
1897 val : "function() {\n \n}\n",
1910 xtype: Gtk.ScrolledWindow,
1913 shadow_type : Gtk.ShadowType.IN,
1916 XObject.prototype.init.call(this);
1917 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1921 xtype: Gtk.TreeView,
1924 headers_visible : false,
1925 enable_tree_lines : true,
1927 XObject.prototype.init.call(this);
1929 this.selection = this.el.get_selection();
1930 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1933 var description = new Pango.FontDescription.c_new();
1934 description.set_size(8000);
1935 this.el.modify_font(description);
1938 button_press_event : function (self, ev) {
1942 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1943 return false; //not on a element.
1947 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1949 if (res.column.title != 'value') {
1950 return false; // ignore..
1952 if ( this.get('/LeftPanel').editing) {
1955 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1956 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1957 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1961 var provider = this.get('/LeftTree').getPaleteProvider();
1963 var opts = provider.findOptions(type);
1965 if (opts === false) {
1966 this.get('/LeftPanel').editableColumn.setOptions([]);
1967 renderer.has_entry = true;
1969 LeftPanel.editableColumn.setOptions(opts);
1970 renderer.has_entry = false;
1974 //Seed.print("click" + ev.type);
1975 //console.dump(res);
1981 if (res.column.title == 'value') {
1984 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1985 var p = this.get('/LeftPanelPopup');
1990 p.el.set_screen(Gdk.Screen.get_default());
1992 p.el.popup(null, null, null, null, 3, ev.button.time);
1993 //Seed.print("click:" + res.column.title);
2001 xtype: Gtk.TreeStore,
2005 getIterValue : function(iter, col) {
2006 var gval = new GObject.Value('');
2007 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2008 return '' + gval.value;
2010 add : function(info) {
2011 // info includes key, val, skel, etype..
2013 type = info.type.toLowerCase();
2014 var data = this.toJS();
2016 if (info.etype == 'events') {
2017 data.listeners = data.listeners || { };
2018 if (typeof(data.listeners[info.key]) != 'undefined') {
2019 return; //already set!
2022 if (typeof(data[info.key]) != 'undefined') {
2027 if (typeof(info.val) == 'undefined') {
2030 if (info.type == 'boolean') {
2033 if (type == 'number') {
2041 if (info.etype == 'events') {
2043 data.listeners[info.key] = info.val;
2046 data[info.key] = info.val;
2050 var map = this.load(data);
2052 // flag it as changed to the interface..
2054 this.get('/LeftTree.model').changed(data, true);
2057 this.startEditing(map[k]);
2060 LeftPanel.get('view').el.row_activated(
2061 new Gtk.TreePath.from_string(map[k]),
2062 LeftPanel.editableColumn.el
2066 changed : function(str, doRefresh) {
2067 if (!this.activePath) {
2070 var iter = new Gtk.TreeIter();
2071 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2073 this.el.set_value(iter, 1, '' +str);
2074 this.el.set_value(iter, 3, '' + this.toShort(str));
2075 var type = this.getIterValue(iter, 4);
2077 this.el.set_value(iter, 5, type + ' : ' + str);
2078 // update the tree...
2080 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2082 deleteSelected : function() {
2083 var data = this.toJS();
2084 var iter = new Gtk.TreeIter();
2085 var s = this.get('/LeftPanel.view').selection;
2086 s.get_selected(this.el, iter);
2089 var gval = new GObject.Value('');
2090 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2092 var val = gval.value;
2093 if (val[0] == '!') {
2095 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2098 delete data.listeners[ val.substring(1)];
2099 if (!XObject.keys(data.listeners).length) {
2100 delete data.listeners;
2104 if (typeof(data[val]) == 'undefined') {
2112 this.get('/LeftTree.model').changed(data, true);
2115 editSelected : function(e) {
2116 print("EDIT SELECTED?");
2117 var iter = new Gtk.TreeIter();
2118 var s = this.get('/LeftPanel.view').selection;
2119 s.get_selected(this.get('/LeftPanel.model').el, iter);
2120 var m = this.get('/LeftPanel.model')
2122 var gval = new GObject.Value('');
2123 this.el.get_value(iter, 0 ,gval);
2124 var val = '' + gval.value;
2126 gval = new GObject.Value('');
2127 this.el.get_value(iter, 1 ,gval);
2128 var rval = gval.value;
2129 var activePath = this.el.get_path(iter).to_string();
2130 this.activePath = activePath ;
2131 // was activeIter...
2134 var showEditor = false;
2136 if (val[0] == '!') {
2139 if (val[0] == '|') {
2140 if (rval.match(/function/g) || rval.match(/\n/g)) {
2147 this.activePath = false;
2148 GLib.timeout_add(0, 1, function() {
2149 // Gdk.threads_enter();
2150 _this.get('/BottomPane').el.show();
2151 _this.get('/RightEditor').el.show();
2152 _this.get('/RightEditor.view').load( rval );
2156 _this.activePath = activePath ;
2158 // Gdk.threads_leave();
2163 this.get('/BottomPane').el.hide();
2164 this.get('/RightEditor').el.hide();
2166 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2170 getType : function(treepath) {
2171 return this.getValue(treepath, 4);
2173 getValue : function(treepath_str, col) {
2174 var iter = new Gtk.TreeIter();
2175 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2177 var gval = new GObject.Value('');
2178 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2179 var val = '' + gval.value;
2183 var type = this.getType(this.el.get_path(iter).to_string());
2184 print("TYPE: " +type + " - val:" + val);
2185 switch(type.toLowerCase()) {
2189 return parseFloat(val); // Nan ?? invalid!!?
2192 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2194 return val == 'true' ? true : false;
2196 var nv = parseFloat(val);
2197 if (!isNaN(nv) && (val == ''+nv)) {
2205 XObject.prototype.init.call(this);
2206 this.el.set_column_types ( 6, [
2207 GObject.TYPE_STRING, // 0 real key
2208 GObject.TYPE_STRING, // 1 real value
2209 GObject.TYPE_STRING, // 2 visable key
2210 GObject.TYPE_STRING, // 3 visable value
2211 GObject.TYPE_STRING, // 4 need to store type of!!!
2212 GObject.TYPE_STRING // 5 tooltip
2216 load : function(ar) {
2219 this.get('/RightEditor').el.hide();
2226 var provider = this.get('/LeftTree').getPaleteProvider();
2227 var iter = new Gtk.TreeIter();
2230 var keys = XObject.keys(ar);
2232 ar.listeners = ar.listeners || {};
2234 for (var i in ar.listeners ) {
2235 this.el.append(iter);
2236 var p = this.el.get_path(iter).to_string();
2239 this.el.set_value(iter, 0, '!'+ i );
2240 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2241 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2243 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2244 this.el.set_value(iter, 4, 'function');
2245 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2251 keys.forEach(function(i) {
2252 if (typeof(ar[i]) == 'object') {
2256 var type = provider.findType(ar, i, ar[i]);
2258 _this.el.append(iter);
2259 var p = _this.el.get_path(iter).to_string();
2261 _this.el.set_value(iter, 0, ''+i);
2262 _this.el.set_value(iter, 1, '' + ar[i]);
2263 _this.el.set_value(iter, 2, ''+i);
2264 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2265 _this.el.set_value(iter, 4, ''+type);
2266 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2270 startEditing : function(path,col) {
2272 * start editing path (or selected if not set..)
2273 * @param {String|false} path (optional) treepath to edit - selected tree gets
2274 * edited by default.
2275 * @param {Number} 0 or 1 (optional)- column to edit.
2278 if (typeof(path) == 'string') {
2279 tp = new Gtk.TreePath.from_string(path);
2281 var iter = new Gtk.TreeIter();
2282 var s = this.get('/LeftPanel.view').selection;
2283 s.get_selected(this.el, iter);
2284 tp = this.el.get_path(iter);
2285 path = tp.to_string();
2289 // which colum is to be edited..
2291 if (typeof(col) == 'undefined') {
2292 var k = this.getValue(path, 0);
2293 colObj = (!k.length || k == '|') ?
2294 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2296 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2299 // make sure the pulldown is set correctly..
2300 // not really needed for second col...
2302 var provider = this.get('/LeftTree').getPaleteProvider();
2304 var type = this.get('/LeftPanel.model').getType(path);
2305 var opts = provider.findOptions(type);
2306 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2308 if (opts === false) {
2309 this.get('/LeftPanel').editableColumn.setOptions([]);
2310 renderer.has_entry = true; /// probably does not have any effect.
2312 this.get('/LeftPanel').editableColumn.setOptions(opts);
2313 renderer.has_entry = false;
2317 // iter now has row...
2318 GLib.timeout_add(0, 100, function() {
2320 colObj.items[0].el.editable = true; // esp. need for col 0..
2321 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2331 var iter = new Gtk.TreeIter();
2332 this.get('/LeftPanel.model').el.get_iter_first(iter);
2337 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2340 ar.listeners = ar.listeners || {};
2341 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2344 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2347 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2353 //print(JSON.stringify(ar));
2357 toShort : function(str) {
2358 var a = typeof(str) == 'string' ? str.split("\n") : [];
2359 return a.length > 1 ? a[0] + '....' : '' + str;
2363 xtype: Gtk.TreeViewColumn,
2364 pack : "append_column",
2366 XObject.prototype.init.call(this);
2368 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2369 this.get('/LeftPanel').propertyColumn = this;
2374 xtype: Gtk.CellRendererText,
2375 pack : "pack_start",
2377 editing_started : function (self, editable, path) {
2379 this.get('/LeftPanel.model').activePath = path;
2382 edited : function (self, object, p0) {
2383 var model = this.get('/LeftPanel.model');
2384 var path = model.activePath;
2385 var iter = new Gtk.TreeIter();
2386 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2387 model.el.set_value(iter, 0, p0);
2388 model.el.set_value(iter, 2, p0);
2390 model.activePath = false;
2392 this.get('/LeftTree.model').changed(model.toJS(), true);
2393 this.el.editable = false;
2400 xtype: Gtk.TreeViewColumn,
2401 pack : "append_column",
2403 XObject.prototype.init.call(this);
2404 this.el.add_attribute(this.items[0].el , 'text', 3 );
2405 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2406 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2407 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2409 this.get('/LeftPanel').editableColumn= this;
2411 setOptions : function(ar) {
2412 var m = this.items[0].el.model;
2414 var iter = new Gtk.TreeIter();
2415 ar.forEach(function(i) {
2418 m.set_value(iter, 0, i);
2424 xtype: Gtk.CellRendererCombo,
2425 pack : "pack_start",
2430 XObject.prototype.init.call(this);
2431 this.el.model = new Gtk.ListStore();
2432 this.el.model.set_column_types ( 1, [
2433 GObject.TYPE_STRING // 0 real key
2437 edited : function (self, object, p0) {
2438 this.get('/LeftPanel').editing = false;
2439 print("EDITED? p:" + p0 + " t:" + p0);
2440 this.get('/LeftPanel.model').changed(p0, true);
2441 this.get('/LeftPanel.model').activePath = false;
2443 editing_started : function (self, editable, path) {
2444 this.get('/LeftPanel').editing = true;
2445 // console.log('editing started');
2446 // r.has_entry = false;
2447 this.get('/LeftPanel.model').editSelected(editable);
2458 id : "LeftPanelPopup",
2461 xtype: Gtk.MenuItem,
2465 activate : function (self) {
2466 this.get('/LeftPanel.model').deleteSelected();
2471 xtype: Gtk.MenuItem,
2475 activate : function (self) {
2476 this.get('/LeftPanel.model').startEditing(false, 0);
2489 xtype: Gtk.ScrolledWindow,
2490 pack : "pack_end,false,true,0",
2492 shadow_type : Gtk.ShadowType.IN,
2494 XObject.prototype.init.call(this);
2495 XObject.prototype.init.call(this);
2496 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2497 this.el.set_size_request ( 150, -1 );
2500 activeElement : false,
2501 hideWin : function() {
2508 if (this.get('/Window.left').el.position < 160) {
2511 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2518 xtype: Gtk.TreeView,
2519 enable_tree_lines : true,
2520 headers_visible : false,
2523 XObject.prototype.init.call(this);
2525 var description = new Pango.FontDescription.c_new();
2526 description.set_size(8000);
2527 this.el.modify_font(description);
2529 //this.selection = this.el.get_selection();
2530 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2539 cursor_changed : function (self) {
2540 var iter = new Gtk.TreeIter();
2542 //console.log('changed');
2543 var m = this.get('model');
2544 if (!this.selection){
2545 this.selection = this.el.get_selection();
2548 var s = this.selection;
2549 if (!s.get_selected(m.el, iter)) {
2552 var tp = m.el.get_path(iter).to_string();
2557 var key = m.getValue(tp, 0);
2559 var type = m.getValue(tp, 1);
2560 var skel = m.getValue(tp, 3);
2561 var etype = m.getValue(tp, 5);
2564 this.get('/MidPropTree').hideWin();
2566 if (type == 'function') {
2568 if (etype != 'events') {
2572 this.get('/LeftPanel.model').add({
2581 if (type.indexOf('.') > -1 ||
2582 type == 'boolean') {
2586 this.get('/LeftPanel.model').add( {
2596 xtype: Gtk.ListStore,
2599 XObject.prototype.init.call(this);
2600 this.el.set_column_types ( 6, [
2601 GObject.TYPE_STRING, // real key
2602 GObject.TYPE_STRING, // real type
2603 GObject.TYPE_STRING, // docs ?
2604 GObject.TYPE_STRING, // visable desc
2605 GObject.TYPE_STRING, // function desc
2606 GObject.TYPE_STRING // element type (event|prop)
2610 getValue : function(treepath, col)
2612 var tp = new Gtk.TreePath.from_string (treepath);
2613 var iter = new Gtk.TreeIter();
2614 this.el.get_iter (iter, tp);
2615 var value = new GObject.Value('');
2616 this.el.get_value(iter, col, value);
2620 showData : function(type) {
2622 if (!this.get('/MidPropTree').activeElement || !type) {
2623 return; // no active element
2626 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2627 var palete = this.get('/LeftTree').getPaleteProvider();
2631 Seed.print('Showing right?');
2632 if (!this.get('/MidPropTree').shown) {
2634 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2635 this.get('/MidPropTree').el.show();
2636 this.get('/MidPropTree').shown = true;
2639 var elementList = palete.getPropertiesFor(fullpath, type);
2640 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2641 // console.dump(elementList);
2644 var iter = new Gtk.TreeIter();
2645 for(var i =0 ; i < elementList.length; i++) {
2646 var p=elementList[i];
2647 this.el.append(iter);
2648 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2649 //GObject.TYPE_STRING, // real key
2650 // GObject.TYPE_STRING, // real type
2651 // GObject.TYPE_STRING, // docs ?
2652 // GObject.TYPE_STRING // func def?
2655 this.el.set_value(iter, 0, p.name);
2656 this.el.set_value(iter, 1, p.type);
2657 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2658 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2659 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2660 this.el.set_value(iter, 5, type);
2668 xtype: Gtk.TreeViewColumn,
2670 this.el = new Gtk.TreeViewColumn();
2671 this.parent.el.append_column(this.el);
2673 XObject.prototype.init.call(this);
2674 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2679 xtype: Gtk.CellRendererText,
2680 pack : "pack_start,true"
2704 xtype: Gtk.Notebook,
2705 pack : "pack_start,true,true",
2706 id : "view-help-nb",
2708 XObject.prototype.init.call(this);
2709 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2710 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2714 xtype: Gtk.Notebook,
2716 id : "view-notebook",
2719 XObject.prototype.init.call(this);
2720 this.el.set_current_page(0);
2722 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2723 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2730 id : "RightBrowser",
2736 xtype: Gtk.ScrolledWindow,
2738 shadow_type : Gtk.ShadowType.IN,
2740 XObject.prototype.init.call(this);
2741 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2745 xtype: WebKit.WebView,
2749 XObject.prototype.init.call(this);
2750 // this may not work!?
2751 this.el.open('file:///' + __script_path__ + '/../builder.html');
2755 this.el, /* widget that will accept a drop */
2756 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2757 null, /* lists of target to support */
2758 0, /* size of list */
2759 Gdk.DragAction.COPY /* what to do with data after dropped */
2762 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2763 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2765 renderJS : function(data) {
2766 print("HTML RENDERING");
2767 /// prevent looping..
2768 //if (this.pendingRedraw) {
2769 // print("pending redraw active?!");
2774 if (!this.get('/Window.LeftTree').getActiveFile()) {
2778 var project = this.get('/Window.LeftTree').getActiveFile().project;
2779 //print (project.fn);
2781 project.runhtml = project.runhtml || '';
2784 this.runhtml = this.runhtml || '';
2786 if (project.runhtml != this.runhtml) {
2787 // then we need to reload the browser using
2788 // load_html_string..
2790 // then trigger a redraw once it's loaded..
2791 this.pendingRedraw = true;
2793 this.runhtml = project.runhtml;
2795 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2796 html = html.replace('</head>', this.runhtml + '</head>');
2797 print("LOAD HTML " + html);
2798 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2799 // should trigger load_finished!
2804 this.pendingRedraw = false;
2807 this.renderedData = data;
2808 var str = JSON.stringify(data) ;
2811 console.log('not loaded yet');
2813 //Seed.print("RENDER:" + str);
2814 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2816 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2819 load_finished : function (self, object) {
2820 // if (this.ready) { // dont do it twice!
2824 this.pendingRedraw = false;
2825 var js = this.get('/LeftTree.model').toJS();
2827 this.renderJS(js[0]);
2831 script_alert : function (self, object, p0) {
2834 return true; // do not display anything...
2836 console_message : function (self, object, p0, p1) {
2837 // console.log(object);
2838 if (!object.match(/^\{/)) {
2840 this.get('/Terminal').feed(object);
2841 return true; // do not handle!!! -> later maybe in console..
2843 // console.log(object);
2844 var val = JSON.parse(object);
2846 if (typeof(val['hover-node']) != 'undefined') {
2847 this.activeNode = val['hover-node'];
2848 console.log('active node: ' + this.activeNode);
2853 if (typeof(val['id']) != 'undefined') {
2854 // this.activeNode = val['id'];
2855 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2859 this.get('/LeftTree.view').selectNode(tg[0]);
2863 if (ret && typeof(val['set']) != 'undefined') {
2864 this.get('/LeftPanel.model').add({
2868 //console.log('active node: ' + this.activeNode);
2871 //Seed.print('a:'+a);
2872 //Seed.print('b:'+b);
2873 //Seed.print('c:'+c);
2876 drag_motion : function (w, ctx, x, y, time, ud) {
2877 // console.log('DRAG MOTION');
2879 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2880 this.targetData = [];
2881 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2883 // A) find out from drag all the places that node could be dropped.
2884 var src = Gtk.drag_get_source_widget(ctx);
2885 if (!src.dropList) {
2886 Gdk.drag_status(ctx, 0, time);
2889 // b) get what we are over.. (from activeNode)
2890 // tree is empty.. - list should be correct..
2891 if (!this.get('/LeftTree.model').currentTree) {
2892 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2896 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2898 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2901 Gdk.drag_status(ctx, 0,time);
2902 this.get('/LeftTree.view').highlight(false);
2906 // if we have a target..
2907 // -> highlight it! (in browser)
2908 // -> highlight it! (in tree)
2910 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2911 this.get('/LeftTree.view').highlight(tg);
2912 this.targetData = tg;
2913 // for tree we should handle this...
2916 drag_drop : function (w, ctx, x, y,time, ud) {
2917 print("TARGET: drag-drop");
2918 var is_valid_drop_site = true;
2923 w, /* will receive 'drag-data-received' signal */
2924 ctx, /* represents the current state of the DnD */
2925 this.get('/Window').atoms["STRING"], /* the target type we want */
2926 time /* time stamp */
2930 /* No target offered by source => error */
2933 return is_valid_drop_site;
2935 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2937 print("Browser: drag-data-received");
2938 var delete_selection_data = false;
2939 vardnd_success = false;
2940 /* Deal with what we are given from source */
2941 if( sel_data && sel_data.length ) {
2943 if (ctx.action == Gdk.DragAction.ASK) {
2944 /* Ask the user to move or copy, then set the ctx action. */
2947 if (ctx.action == Gdk.DragAction.MOVE) {
2948 delete_selection_data = true;
2950 var source = Gtk.drag_get_source_widget(ctx);
2952 print("Browser: source.DRAGDATA? " + source.dragData);
2953 if (this.targetData) {
2954 print(this.targetData);
2955 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2964 if (dnd_success == false)
2966 Seed.print ("DnD data transfer failed!\n");
2969 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2980 id : "RightGtkView",
2982 redraw : function() {
2983 this.highlightWidget = false;
2984 print("REDRAW CALLED");
2985 this.activePath = this.get('/LeftTree').getActivePath();
2986 if (this.renderedEl) {
2987 print("QUEUE DRAW CALLING");
2988 this.renderedEl.queue_draw();
2991 renderJS : function(data, withDebug)
2993 this.highlightWidget = false;
2995 this.withDebug = false;
2997 if (this.renderedEl) {
2998 this.get('view').el.remove(this.renderedEl);
2999 this.renderedEl.destroy();
3000 this.renderedEl = false;
3005 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3006 // in theory tree is actually window..
3008 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3013 this.get('view').el.set_size_request(
3014 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3017 this.renderedEl.set_size_request(
3018 tree.default_width || 600,
3019 tree.default_height || 400
3021 this.get('view').el.show_all();
3026 showInWindow : function() {
3027 print("GET PROEJCT");
3028 var pr = this.get('/LeftProjectTree').getActiveProject();
3030 console.log(pr.paths);
3033 var src= this.buildJS(
3034 this.get('/LeftTree.model').toJS()[0],
3039 //var x = new imports.sandbox.Context();
3043 Seed.check_syntax('var e = ' + src);
3046 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3047 this.get('/Terminal').feed(console._dump(e)+"\n");
3049 var lines = src.split("\n");
3050 var start = Math.max(0, e.line - 10);
3051 var end = Math.min(lines.length, e.line + 10);
3052 for (var i =start ; i < end; i++) {
3054 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3057 this.get('/Terminal').feed(lines[i] + "\n");
3064 this.get('/BottomPane').el.set_current_page(1);
3065 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3066 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3067 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3069 var _top = x.get_global_object()._top;
3071 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3073 if (_top.el.popup) {
3074 _top.el.popup(null, null, null, null, 3, null);
3078 viewAdd : function(item, par)
3080 // does something similar to xobject..
3081 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3083 if (item.pack===false || item.pack === 'false') { // no ;
3086 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3087 var type = item['|xns'] + '.' + item['xtype'];
3088 var ns = imports.gi[item['|xns']];
3089 var ctr = ns[item['xtype']];
3091 for(var k in item) {
3093 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3108 if (k[0] == '|' && typeof(kv) == 'string') {
3110 if (kv.match(new RegExp('function'))) {
3113 print("WASL " + k + '=' + kv);
3115 eval( 'kv = ' + kv);
3116 } catch(e) { continue; }
3119 // print(k + '=' + kv);
3121 if (k[0] == '|') { // should be boolean or number..
3123 //print(k + '=' + kv);
3126 if (k == 'show_tabs') { // force tab showing for notebooks.
3129 print(k + '=' + typeof(kv) + " : " + kv);
3135 var el = new ctr(ctr_args);
3137 print("PACK" + item.pack);
3138 //console.dump(item.pack);
3145 if (typeof(item.pack) == 'string') {
3147 item.pack.split(',').forEach(function(e, i) {
3149 if (e == 'false') { args.push( false); return; }
3150 if (e == 'true') { args.push( true); return; }
3151 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3154 //print(args.join(","));
3156 pack_m = args.shift();
3158 pack_m = item.pack.shift();
3163 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3165 name: "ArgumentError",
3166 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3167 "ADDING : " + item.id + " " + el
3176 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3177 //Seed.print('args: ' + args.length);
3179 par[pack_m].apply(par, args);
3183 item.items = item.items || [];
3184 item.items.forEach(function(ch,n) {
3186 print ("type:" + type);
3188 print ("ch.pack:" + ch.pack);
3189 if (type == 'Gtk.Table' && ch.pack == 'add') {
3190 var c = n % item.n_columns;
3191 var r = Math.floor(n/item.n_columns);
3192 ch.pack = [ 'attach', c, c+1, r, r+1,
3193 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3194 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3195 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3196 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3200 _this.viewAdd(ch, el);
3205 // add the signal handlers.
3206 // is it a widget!?!!?
3212 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3213 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3214 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3215 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3216 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3226 widgetDragDropEvent : function() {
3227 print("WIDGET DRAGDROP");
3230 widgetDragMotionEvent : function() {
3231 print("WIDGET DRAGMOTION");
3234 widgetExposeEvent : function(w, evt, ud, item) {
3236 if (this.inRender) {
3240 if ( this.highlightWidget) {
3241 this.inRender = true;
3242 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3243 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3245 this.inRender = false;
3250 if (this.activePath != item.xtreepath) {
3254 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3255 // work out the coords of the window..
3257 var dr = widget.window;
3258 this.gc = (new Gdk.GC.c_new(dr));
3259 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3260 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3264 var r = evt.expose.area;
3265 // console.dump([r.x, r.y, r.width, r.height ] );
3267 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3268 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3269 // happens with gtkscrollview embedded stuff..
3270 var np =this.activePath.split(':');
3272 this.activePath = np.join(':');
3273 this.renderedEl.queue_draw();
3289 this.inRender = true;
3292 this.highlightWidget = widget;
3297 // print("DRAW BOX");
3298 //console.dump(this.box);
3299 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3300 this.inRender = false;
3303 widgetPressEvent : function(w,e,u,d) {
3304 if (this.get('view').pressed) {
3307 this.get('view').pressed = true;
3308 print("WIDGET PRESS " + d.xtreepath );
3309 this.get('/LeftTree.view').selectNode( d.xtreepath );
3312 widgetReleaseEvent : function() {
3313 this.get('view').pressed = false;
3319 pack : "pack_start,false,true,0",
3323 pack : "pack_start,false,false,0",
3324 label : "Run The Application",
3326 button_press_event : function (self, event) {
3327 // call render on left tree - with special option!?!
3329 //print("GET PROEJCT");
3330 var pr = this.get('/LeftProjectTree').getActiveProject();
3333 for (var i in pr.paths) {
3337 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3338 this.get('/Terminal').feed("RUN DIR:" + dir);
3340 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3341 , false,false,false);
3342 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3343 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3353 xtype: Gtk.ScrolledWindow,
3356 shadow_type : Gtk.ShadowType.IN,
3358 XObject.prototype.init.call(this);
3359 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3363 xtype: Gtk.EventBox,
3364 pack : "add_with_viewport",
3366 XObject.prototype.init.call(this);
3367 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3368 red: 0x9F00, green: 0xB800 , blue : 0xA800
3376 XObject.prototype.init.call(this);
3377 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3378 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3383 xtype: Gtk.EventBox,
3386 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3387 XObject.prototype.init.call(this);
3391 this.el, /* widget that will accept a drop */
3392 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3393 null, /* lists of target to support */
3394 0, /* size of list */
3395 Gdk.DragAction.COPY /* what to do with data after dropped */
3398 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3399 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3402 getActiveNode : function(x,y)
3404 // workout what node is here..
3405 return '0'; // top..
3409 drag_motion : function (self, ctx, x, y, time) {
3411 // A) find out from drag all the places that node could be dropped.
3412 var src = Gtk.drag_get_source_widget(ctx);
3413 if (!src.dropList) {
3414 Gdk.drag_status(ctx, 0, time);
3417 // b) get what we are over.. (from activeNode)
3418 // tree is empty.. - list should be correct..
3419 if (!this.get('/LeftTree.model').currentTree) {
3420 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3424 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3425 var activeNode = this.getActiveNode(x, y);
3428 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3431 Gdk.drag_status(ctx, 0,time);
3432 this.get('/LeftTree.view').highlight(false);
3436 // if we have a target..
3437 // -> highlight it! (in browser)
3438 // -> highlight it! (in tree)
3440 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3441 this.get('/LeftTree.view').highlight(tg);
3442 this.targetData = tg;
3443 // for tree we should handle this...
3446 drag_drop : function (self,ctx, x, y, time) {
3447 Seed.print("TARGET: drag-drop");
3448 var is_valid_drop_site = true;
3453 self, /* will receive 'drag-data-received' signal */
3454 ctx, /* represents the current state of the this.gDnD */
3455 this.get('/Window').atoms["STRING"], /* the target type we want */
3456 time /* time stamp */
3460 /* No target offered by source => error */
3463 return is_valid_drop_site;
3466 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3468 Seed.print("GtkView: drag-data-received");
3469 var delete_selection_data = false;
3470 var dnd_success = false;
3471 /* Deal with what we are given from source */
3472 if( sel_data && sel_data.length ) {
3474 if (ctx.action == Gdk.DragAction.ASK) {
3475 /* Ask the user to move or copy, then set the ctx action. */
3478 if (ctx.action == Gdk.DragAction.MOVE) {
3479 delete_selection_data = true;
3481 var source = Gtk.drag_get_source_widget(ctx);
3483 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3484 if (this.targetData) {
3485 Seed.print(this.targetData);
3486 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3495 if (dnd_success == false)
3497 Seed.print ("DnD data transfer failed!\n");
3500 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3503 button_press_event : function (self, event) {
3504 this.pressed = false;
3520 xtype: Gtk.ScrolledWindow,
3525 var file = this.get('/LeftTree').getActiveFile();
3529 var activeEl = this.get('/LeftTree').getActiveElement();
3530 var xtype = file.guessName( activeEl )
3531 if (!xtype || !xtype.length) {
3534 this.get('/Window.view-help-nb').el.set_current_page(1);
3536 // get the active element being edited.
3537 var helpurl = file.getHelpUrl(xtype);
3539 // now load the help info in the page..
3540 this.get('help-view').el.open(helpurl);
3544 xtype: WebKit.WebView,
3548 XObject.prototype.init.call(this);
3549 this.get('/Window.help-view').el.open(
3550 "http://devel.akbkhome.com/seed/");
3562 xtype: Gtk.Notebook,
3565 XObject.prototype.init.call(this);
3566 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3567 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3572 xtype: Gtk.ScrolledWindow,
3577 xtype: GtkSource.View,
3581 XObject.prototype.init.call(this);
3582 var description = Pango.Font.description_from_string("monospace")
3583 description.set_size(8000);
3584 this.el.modify_font(description);
3587 load : function(str) {
3589 // show the help page for the active node..
3590 this.get('/Help').show();
3593 this.get('/BottomPane').el.set_current_page(0);
3594 this.el.get_buffer().set_text(str, str.length);
3595 var lm = GtkSource.LanguageManager.get_default();
3597 this.el.get_buffer().set_language(lm.get_language('js'));
3598 var buf = this.el.get_buffer();
3599 var cursor = buf.get_mark("insert");
3600 var iter= new Gtk.TextIter;
3601 buf.get_iter_at_mark(iter, cursor);
3603 iter.set_line_offset(4);
3604 buf.move_mark(cursor, iter);
3607 cursor = buf.get_mark("selection_bound");
3608 iter= new Gtk.TextIter;
3609 buf.get_iter_at_mark(iter, cursor);
3611 iter.set_line_offset(4);
3612 buf.move_mark(cursor, iter);
3614 this.el.grab_focus();
3616 insert_spaces_instead_of_tabs : true,
3619 show_line_numbers : true,
3622 xtype: GtkSource.Buffer,
3623 pack : "set_buffer",
3625 changed : function (self) {
3626 var s = new Gtk.TextIter();
3627 var e = new Gtk.TextIter();
3628 this.el.get_start_iter(s);
3629 this.el.get_end_iter(e);
3630 var str = this.el.get_text(s,e,true);
3632 Seed.check_syntax('var e = ' + str);
3634 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3635 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3637 print("SYNTAX ERROR IN EDITOR");
3642 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3643 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3646 this.get('/LeftPanel.model').changed( str , false);
3655 xtype: Gtk.ScrolledWindow,
3659 xtype: Vte.Terminal,
3662 feed : function(istr) {
3663 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3664 // we should make ourselves visable!!!
3665 this.get('/BottomPane').el.show();
3666 this.get('/BottomPane').el.set_current_page(1);
3668 this.el.feed(str ,str.length);
3670 scroll_on_output : true,
3672 XObject.prototype.init.call(this);
3673 this.el.set_size (80, 1000);
3675 scrollback_lines : 1000
3685 pack : "pack_start,false,false",
3689 this.get('buttonbar').el.show();
3690 this.get('viewbox').el.hide();
3691 print("TRIED TO HIDE");
3694 this.get('buttonbar').el.hide();
3695 this.get('viewbox').el.show();
3696 // this.get('model').expanded();
3708 pack : "pack_start,false,true",
3710 clicked : function (self) {
3711 this.get('/RightPalete').show();
3718 stock : Gtk.STOCK_GOTO_FIRST,
3719 icon_size : Gtk.IconSize.MENU
3729 XObject.prototype.init.call(this);
3730 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3733 enter_notify_event : function (self, event) {
3734 this.get('/RightPalete').show();
3748 pack : "pack_start,false,true",
3757 pack : "pack_start,false,true",
3759 clicked : function (self) {
3760 this.get('/RightPalete').hide();
3767 stock : Gtk.STOCK_GOTO_LAST,
3768 icon_size : Gtk.IconSize.MENU
3775 xtype: Gtk.ScrolledWindow,
3778 XObject.prototype.init.call(this);
3779 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3780 this.el.set_size_request(-1,200);
3782 shadow_type : Gtk.ShadowType.IN,
3785 xtype: Gtk.TreeView,
3788 XObject.prototype.init.call(this);
3789 this.el.set_size_request(150,-1);
3790 // set_reorderable: [1]
3792 var description = new Pango.FontDescription.c_new();
3793 description.set_size(8000);
3794 this.el.modify_font(description);
3796 this.selection = this.el.get_selection();
3797 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3798 // this.selection.signal['changed'].connect(function() {
3799 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3801 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3803 Gtk.drag_source_set (
3804 this.el, /* widget will be drag-able */
3805 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3806 null, /* lists of target to support */
3807 0, /* size of list */
3808 Gdk.DragAction.COPY /* what to do with data after dropped */
3810 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3812 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3813 Gtk.drag_source_add_text_targets(this.el);
3815 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3816 targets = new Gtk.TargetList();
3817 targets.add( LeftTree.atoms["STRING"], 0, 0);
3818 targets.add_text_targets( 1 );
3819 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3821 //if you want to allow text to be output elsewhere..
3822 //Gtk.drag_source_add_text_targets(this.el);
3826 headers_visible : false,
3827 enable_tree_lines : true,
3829 drag_begin : function (self, ctx) {
3830 // we could fill this in now...
3831 Seed.print('SOURCE: drag-begin');
3835 var iter = new Gtk.TreeIter();
3836 var s = this.selection;
3837 s.get_selected(this.get('/RightPalete.model').el, iter);
3838 var path = this.get('/RightPalete.model').el.get_path(iter);
3840 var pix = this.el.create_row_drag_icon ( path);
3843 Gtk.drag_set_icon_pixmap (ctx,
3850 var value = new GObject.Value('');
3851 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3852 if (!this.get('/RightPalete').provider) {
3855 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3856 this.el.dragData = value.value;
3863 drag_data_get : function (self, drag_context, selection_data, info, time) {
3864 //Seed.print('Palete: drag-data-get: ' + target_type);
3865 if (this.el.dragData && this.el.dragData.length ) {
3866 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3870 //this.el.dragData = "TEST from source widget";
3874 drag_end : function (self, drag_context) {
3875 Seed.print('SOURCE: drag-end');
3876 this.el.dragData = false;
3877 this.el.dropList = false;
3878 this.get('/LeftTree.view').highlight(false);
3884 xtype: Gtk.ListStore,
3887 XObject.prototype.init.call(this);
3888 this.el.set_column_types ( 2, [
3889 GObject.TYPE_STRING, // title
3890 GObject.TYPE_STRING // tip
3895 load : function(tr,iter)
3900 //console.log('Project tree load: ' + tr.length);
3901 var citer = new Gtk.TreeIter();
3902 //this.insert(citer,iter,0);
3903 for(var i =0 ; i < tr.length; i++) {
3906 this.el.append(citer);
3908 this.el.insert(citer,iter,-1);
3913 this.el.set_value(citer, 0, '' + r ); // title
3915 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3916 //if (r.cn && r.cn.length) {
3917 // this.load(r.cn, citer);
3923 getValue : function (iter, col) {
3924 var gval = new GObject.Value('');
3925 this.el.get_value(iter, col ,gval);
3932 xtype: Gtk.TreeViewColumn,
3933 pack : "append_column",
3935 XObject.prototype.init.call(this);
3936 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3940 xtype: Gtk.CellRendererText,
3962 XObject.cache['/Window'] = Window;