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();
350 label : "Select Project",
352 pack : "pack_start,false,true",
354 XObject.prototype.init.call(this);
355 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
358 activate : function (self) {
359 var nb = this.get('/LeftTopPanel.notebook');
360 if (this.el.expanded) {
363 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
366 var model = this.get('/LeftProjectTree.combomodel');
367 // print ("loading Projects?")
368 //console.dump(pm.projects);
369 model.loadData(pm.projects);
372 nb.el.set_current_page(1);
373 //pm.on('changed', function() {
374 //console.log("CAUGHT project manager change");
375 // _combo.model.loadData(pm.projects);
379 nb.el.set_current_page(0);
381 enter_notify_event : function (self, event) {
382 this.el.expanded = !this.el.expanded;
383 //if (this.el.expanded ) {
384 this.listeners.activate.call(this);
396 pack : "pack_start,true,true",
398 XObject.prototype.init.call(this);
399 this.el.set_current_page(0);
404 xtype: Gtk.ScrolledWindow,
406 shadow_type : Gtk.ShadowType.IN,
408 XObject.prototype.init.call(this);
409 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
412 getPaleteProvider : function() {
413 var model = this.get('model');
414 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
415 return pm.getPalete(model.file.getType());
417 renderView : function() {
418 var render = this.getRenderer();
419 var model = this.get('model');
421 render.renderJS(model.toJS(false,true)[0]);
423 print("NO RENDER JS METHOD?");
426 getRenderer : function() {
428 switch( this.getActiveFile().getType()) {
430 return this.get('/RightBrowser.view');
432 return this.get('/RightGtkView');
436 getActivePath : function() {
437 var model = this.get('model');
438 var view = this.get('view');
439 if (view.selection.count_selected_rows() < 1) {
442 var iter = new Gtk.TreeIter();
444 view.selection.get_selected(model.el, iter);
445 return model.el.get_path(iter).to_string();
447 getActiveFile : function() {
448 return this.get('model').file;
450 getActiveElement : function() {
452 var path = this.getActivePath();
456 var iter = new Gtk.TreeIter();
457 this.get('model').el.get_iter_from_string(iter, path);
459 var value = new GObject.Value('');
460 this.get('model').el.get_value(iter, 2, value);
462 return JSON.parse(value.value);
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,
791 XObject.prototype.init.call(this);
792 this.el.set_column_types ( 3, [
793 GObject.TYPE_STRING, // title
794 GObject.TYPE_STRING, // tip
795 GObject.TYPE_STRING // source..
799 changed : function(n, refresh) {
800 print("MODEL CHANGED CALLED" + this.activePath);
801 if (this.activePath) {
802 var iter = new Gtk.TreeIter();
803 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
804 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
805 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
807 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
809 //this.currentTree = this.toJS(false, true)[0];
810 this.file.items = this.toJS(false, false);
811 print("AFTER CHANGED");
812 //console.dump(this.file.items);
814 this.currentTree = this.file.items[0];
815 //console.log(this.file.toSource());
818 print("REDNER BROWSER?!");
819 this.get('/LeftTree').renderView();
821 var pm = this.get('/RightPalete.model');
822 if (!this.get('/RightPalete').provider) {
828 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
829 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
833 loadFile : function(f) {
839 console.log('missing file');
843 // load the file if not loaded..
844 if (f.items === false) {
846 f.loadItems(function() {
852 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
854 if (f.items.length && typeof(f.items[0]) == 'string') {
856 this.get('/RightEditor').el.show();
857 this.get('/RightEditor.view').load( f.items[0]);
861 //console.dump(f.items);
863 this.get('/LeftTree.view').el.expand_all();
865 if (!f.items.length) {
868 this.get('/Window.leftvpaned').el.set_position(80);
870 this.get('/LeftTree.view').el.set_cursor(
871 new Gtk.TreePath.from_string('0'), null, false);
875 this.get('/Window.leftvpaned').el.set_position(200);
879 //print("hide right editior");
880 this.get('/RightEditor').el.hide();
881 //print("set current tree");
882 this.currentTree = this.toJS(false, false)[0];
883 //console.dump(this.currentTree);
884 this.currentTree = this.currentTree || { items: [] };
885 this.get('/LeftTree').renderView();
886 //console.dump(this.map);
887 //var RightPalete = imports.Builder.RightPalete.RightPalete;
888 var pm = this.get('/RightPalete.model');
891 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
893 if (!this.get('/RightPalete').provider) {
894 print ("********* PALETE PROVIDER MISSING?!!");
896 this.get('/LeftTree').renderView();
898 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
902 this.get('/Window.view-notebook').el.set_current_page(
903 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
906 findDropNode : function(treepath_str, targets) {
908 // this is used by the dragdrop code in the roo version AFAIR..
910 var path = treepath_str.replace(/^builder-/, '');
911 // treemap is depreciated... - should really check if model has any entries..
913 if (!this.el.iter_n_children(null)) {
915 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
917 print("FIND treepath: " + path);
918 //console.dump(this.treemap);
920 if (!treepath_str.match(/^builder-/)) {
921 return []; // nothing!
923 if (targets === true) {
926 return this.findDropNodeByPath(path,targets)
928 findDropNodeByPath : function(treepath_str, targets, pref) {
929 var path = treepath_str + ''; // dupe it..
930 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
932 //console.dump(this.treemap);
933 while (path.length) {
934 print("LOOKING FOR PATH: " + path);
935 var node_data = this.singleNodeToJS(path);
936 if (node_data === false) {
937 print("node not found");
941 var xname = this.get('/LeftTree.model').file.guessName(node_data);
944 targets.forEach(function(tg) {
948 if ((tg == xname) ) {
951 if (tg.indexOf(xname +':') === 0) {
953 prop = tg.split(':').pop();
958 if (last) { // pref is after/before..
959 // then it's after last
961 return []; // do not allow..
963 return [ last, pref , prop];
966 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
968 var par = path.split(':');
971 path = par.join(':');
977 dropNode : function(target_data, node) {
980 console.dump(target_data);
981 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
983 print("add " + tp + "@" + target_data[1] );
986 if (tp && target_data[1] < 2) { // before or after..
987 var ar = target_data[0].split(':');
989 parent = new Gtk.TreePath.from_string( ar.join(':') );
992 var n_iter = new Gtk.TreeIter();
993 var iter_par = new Gtk.TreeIter();
994 var iter_after = after ? new Gtk.TreeIter() : false;
998 if (parent !== false) {
999 this.el.get_iter(iter_par, parent);
1006 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
1007 this.el.get_iter(iter_after, after);
1008 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
1009 n_iter, iter_par, iter_after);
1012 this.el.append(n_iter, iter_par);
1016 if (typeof(node) == 'string') {
1017 var ar = node.split('.');
1018 var xtype = ar.pop();
1021 '|xns' : ar.join('.'),
1024 if (target_data.length == 3 && target_data[2].length) {
1025 node['*prop'] = target_data[2];
1029 // work out what kind of packing to use..
1030 if (typeof(node.pack) == 'undefined' && parent !== false) {
1031 var pal = this.get('/LeftTree').getPaleteProvider();
1033 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
1034 print ("PNAME : " + pname);
1035 var cname = pal.guessName(node);
1036 print ("CNAME : " + cname);
1037 node.pack = pal.getDefaultPack(pname, cname);
1045 xitems = node.items;
1048 // load children - if it has any..
1051 this.load(xitems, n_iter);
1053 if (tp && (xitems || after)) {
1054 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
1056 // wee need to get the empty proptypes from somewhere..
1058 //var olditer = this.activeIter;
1059 this.activePath = this.el.get_path(n_iter).to_string();
1061 // changed actually set's the node data..
1062 this.changed(node, true);
1066 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
1068 //Builder.MidPropTree._model.load(node);
1069 //Builder.MidPropTree._win.hideWin();
1070 //Builder.LeftPanel._model.load( node);
1074 moveNode : function(target_data, action) {
1075 //print("MOVE NODE");
1076 // console.dump(target_data);
1077 var old_iter = new Gtk.TreeIter();
1078 var s = this.get('/LeftTree.view').selection;
1079 s.get_selected(this.el, old_iter);
1080 var node = this.nodeToJS(old_iter,false);
1081 //console.dump(node);
1084 // needs to drop first, otherwise the target_data
1085 // treepath will be invalid.
1087 this.dropNode(target_data, node);
1088 if (action & Gdk.DragAction.MOVE) {
1089 // print("REMOVING OLD NODE");
1090 this.el.remove(old_iter);
1094 this.activePath= false;
1095 this.changed(false,true);
1097 deleteSelected : function() {
1098 this.get('/LeftTree.view').blockChanges = true;
1099 var old_iter = new Gtk.TreeIter();
1100 var s = this.get('/LeftTree.view').selection;
1101 s.get_selected(this.el, old_iter);
1102 var path = this.el.get_path(old_iter).to_string();
1104 this.activePath= false;
1107 this.activePath= false;
1108 var iter = new Gtk.TreeIter();
1109 this.el.get_iter_from_string(iter, path);
1110 this.el.remove(iter);
1112 // rebuild treemap. -- depreciated.!!
1115 //this.toJS(null, true) // does not do anything?
1116 this.activePath= false;
1117 this.changed(false,true);
1118 this.get('/LeftTree.view').blockChanges = false;
1120 currentTree : false,
1121 listAllTypes : function() {
1122 var s = this.get('/LeftTree.view').selection;
1123 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1125 if (s.count_selected_rows() > 0) {
1126 var iter = new Gtk.TreeIter();
1127 s.get_selected(this.el, iter);
1129 // set some properties of the tree for use by the dropped element.
1130 var value = new GObject.Value('');
1131 this.el.get_value(iter, 2, value);
1132 var data = JSON.parse(value.value);
1135 var xname = this.get('/LeftTree.model').file.guessName(data);
1136 console.log('selected:' + xname);
1140 return []; // could not find it..
1148 li.forEach(function(el) {
1149 // this is specific to roo!!!?
1151 var fullpath = _this.file.guessName(el);
1152 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1157 if (el.items && el.items.length) {
1166 addall([this.currentTree]);
1168 // only if we have nothing, should we add '*top'
1172 //console.log('all types in tree');
1173 //console.dump(ret);
1178 singleNodeToJS : function (treepath)
1180 var iter = new Gtk.TreeIter();
1181 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1185 var iv = this.getIterValue(iter, 2);
1187 return JSON.parse(iv);
1190 nodeToJS : function (iter, with_id)
1192 var par = new Gtk.TreeIter();
1193 var iv = this.getIterValue(iter, 2);
1194 // print("IV" + iv);
1195 var k = JSON.parse(iv);
1196 if (k.json && !this.el.iter_parent( par, iter )) {
1201 var treepath_str = this.el.get_path(iter).to_string();
1202 // not sure how we can handle mixed id stuff..
1203 if (typeof(k.id) == 'undefined') {
1204 k.id = 'builder-'+ treepath_str ;
1208 this.treemap[ treepath_str ] = k;
1209 k.xtreepath = treepath_str ;
1212 if (this.el.iter_has_child(iter)) {
1213 citer = new Gtk.TreeIter();
1214 this.el.iter_children(citer, iter);
1215 k.items = this.toJS(citer,with_id);
1219 toJS : function(iter, with_id)
1221 //Seed.print("WITHID: "+ with_id);
1228 iter = new Gtk.TreeIter();
1229 if (!this.el.get_iter_first(iter)) {
1239 var k = this.nodeToJS(iter, with_id);
1243 if (!this.el.iter_next(iter)) {
1249 // convert the list into a json string..
1253 getIterValue : function (iter, col) {
1254 var gval = new GObject.Value('');
1255 this.el.get_value(iter, col ,gval);
1260 nodeTitle : function(c, renderfull) {
1263 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1264 if (sr) txt.push('<s>');
1265 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1267 if (renderfull && c['|xns']) {
1268 txt.push(c['|xns']);
1271 if (c.xtype) { txt.push(c.xtype); }
1272 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1273 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1274 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1277 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1278 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1279 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1280 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1281 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1282 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1283 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1284 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1285 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1287 // for flat classes...
1288 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1289 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1292 if (sr) txt.push('</s>');
1293 return (txt.length == 0 ? "Element" : txt.join(" "));
1295 nodeToJSON : function(c) {
1303 return JSON.stringify(o);
1305 load : function(tr,iter)
1307 var citer = new Gtk.TreeIter();
1308 //this.insert(citer,iter,0);
1309 for(var i =0 ; i < tr.length; i++) {
1311 this.el.insert(citer,iter,-1);
1313 this.el.append(citer);
1316 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1317 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1318 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1319 if (tr[i].items && tr[i].items.length) {
1320 this.load(tr[i].items, citer);
1324 nodeTip : function(c) {
1325 var ret = this.nodeTitle(c,true);
1331 if (!i.length || i[0] != '|') {
1337 if (typeof(c[i]) != 'string') {
1340 //print("prop : " + i + ':' + c[i]);
1341 if (!c[i].match(new RegExp('function'))) {
1344 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1348 ret+="\n\nMethods:" + funcs;
1355 xtype: Gtk.TreeViewColumn,
1356 pack : "append_column",
1358 XObject.prototype.init.call(this);
1359 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1363 xtype: Gtk.CellRendererText,
1373 id : "LeftTreeMenu",
1376 xtype: Gtk.MenuItem,
1378 label : "Delete Element",
1380 activate : function (self) {
1382 this.get('/LeftTree.model').deleteSelected();
1393 id : "LeftProjectTree",
1394 showNoProjectSelected : function() {
1395 this.get('/StandardErrorDialog').show("Select a Project first.");
1397 getActiveProject : function() {
1398 return this.project;
1401 leave_notify_event : function (self, event) {
1408 pack : "pack_start,false,false",
1411 xtype: Gtk.ComboBox,
1414 XObject.prototype.init.call(this);
1415 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1417 getValue : function() {
1418 var ix = this.el.get_active();
1422 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1423 if (typeof(data[ix]) == 'undefined') {
1428 setValue : function(fn)
1432 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1433 data.forEach(function(n, ix) {
1441 changed : function (self) {
1442 var fn = this.getValue();
1443 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1444 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1449 xtype: Gtk.CellRendererText,
1450 pack : "pack_start,true",
1454 xtype: Gtk.ListStore,
1457 XObject.prototype.init.call(this);
1458 this.el.set_column_types ( 2, [
1459 GObject.TYPE_STRING, // real key
1460 GObject.TYPE_STRING // real type
1464 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1466 pm.on('changed', function() {
1467 print("caught changed hook on project manager - reloading data");
1468 _this.loadData(pm.projects);
1472 loadData : function(data) {
1473 var ov = this.get('/LeftProjectTree.combo').getValue();
1475 var iter = new Gtk.TreeIter();
1477 data.forEach(function(p) {
1482 el.set_value(iter, 0, p.fn);
1483 el.set_value(iter, 1, p.name);
1487 this.get('/LeftProjectTree.combo').setValue(ov);
1496 xtype: Gtk.ScrolledWindow,
1498 shadow_type : Gtk.ShadowType.IN,
1500 XObject.prototype.init.call(this);
1501 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1505 xtype: Gtk.TreeView,
1506 headers_visible : false,
1507 enable_tree_lines : true,
1510 XObject.prototype.init.call(this);
1511 var description = new Pango.FontDescription.c_new();
1512 description.set_size(8000);
1513 this.el.modify_font(description);
1515 this.selection = this.el.get_selection();
1516 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1520 cursor_changed : function (self) {
1521 var iter = new Gtk.TreeIter();
1523 if (this.selection.count_selected_rows() < 1) {
1524 //XN.get('Builder.LeftTree.model').
1525 this.get('/LeftTree.model').load( false);
1529 var model = this.get('/LeftProjectTree.model');
1530 //console.log('changed');
1531 var s = this.selection;
1532 s.get_selected(model, iter);
1533 value = new GObject.Value('');
1534 model.el.get_value(iter, 2, value);
1536 console.log(value.value);// id..
1538 var file = this.get('/LeftProjectTree').project.getById(value.value);
1545 var nb = this.get('/LeftTopPanel.expander');
1546 nb.el.expanded = false;
1547 nb.listeners.activate.call(nb);
1548 //_expander.el.set_expanded(false);
1550 var ltm = this.get('/LeftTree.model');
1558 xtype: Gtk.TreeStore,
1562 XObject.prototype.init.call(this);
1563 this.el.set_column_types ( 3, [
1564 GObject.TYPE_STRING, // title
1565 GObject.TYPE_STRING, // tip
1566 GObject.TYPE_STRING // id..
1570 loadProject : function(pr) {
1571 print("LOAD PROJECT");
1577 this.get('/LeftProjectTree').project = pr;
1578 this.load(pr.toTree());
1579 this.get('/LeftProjectTree.view').el.expand_all();
1581 load : function(tr,iter) {
1582 // console.dump(tr);
1583 console.log('Project tree load: ' + tr.length);
1584 var citer = new Gtk.TreeIter();
1585 //this.insert(citer,iter,0);
1588 tr.forEach(function (r) {
1590 _this.el.append(citer);
1592 _this.el.insert(citer,iter,-1);
1594 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1595 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1596 _this.el.set_value(citer, 2, '' + r.id ); //id
1597 if (r.cn && r.cn.length) {
1598 _this.load(r.cn, citer);
1603 getValue : function(iter, col) {
1604 var gval = new GObject.Value('');
1605 this.el.get_value(iter, col ,gval);
1606 return '' + gval.value;
1610 xtype: Gtk.TreeViewColumn,
1611 pack : "append_column",
1613 XObject.prototype.init.call(this);
1614 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1618 xtype: Gtk.CellRendererText,
1641 pack : "pack_start,false,true,0",
1648 button_press_event : function (self, event) {
1649 this.get('/MidPropTree.model').showData('props');
1661 stock : Gtk.STOCK_ADD,
1662 icon_size : Gtk.IconSize.MENU
1677 button_press_event : function (self, event) {
1678 this.get('/MidPropTree.model').showData('events');
1690 stock : Gtk.STOCK_ADD,
1691 icon_size : Gtk.IconSize.MENU
1706 button_press_event : function (self, ev) {
1707 var p = this.get('/AddPropertyPopup');
1711 p.el.set_screen(Gdk.Screen.get_default());
1713 p.el.popup(null, null, null, null, 3, ev.button.time);
1725 stock : Gtk.STOCK_ADD,
1726 icon_size : Gtk.IconSize.MENU
1738 id : "AddPropertyPopup",
1741 xtype: Gtk.MenuItem,
1743 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1746 activate : function (self) {
1748 this.get('/LeftPanel.model').add( {
1759 xtype: Gtk.MenuItem,
1761 tooltip_markup : "Add what type of packing is to be used",
1764 activate : function (self) {
1766 this.get('/LeftPanel.model').add( {
1776 xtype: Gtk.MenuItem,
1778 tooltip_markup : "Override the init method",
1781 activate : function (self) {
1783 this.get('/LeftPanel.model').add( {
1786 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1793 xtype: Gtk.SeparatorMenuItem,
1797 xtype: Gtk.MenuItem,
1799 tooltip_markup : "Add a user defined string property",
1802 activate : function (self) {
1804 this.get('/LeftPanel.model').add( {
1814 xtype: Gtk.MenuItem,
1816 tooltip_markup : "Add a user defined number property",
1819 activate : function (self) {
1821 this.get('/LeftPanel.model').add( {
1831 xtype: Gtk.MenuItem,
1833 tooltip_markup : "Add a user defined boolean property",
1836 activate : function (self) {
1838 this.get('/LeftPanel.model').add( {
1848 xtype: Gtk.SeparatorMenuItem,
1852 xtype: Gtk.MenuItem,
1854 tooltip_markup : "Add a user function boolean property",
1857 activate : function (self) {
1859 this.get('/LeftPanel.model').add( {
1862 val : "function() {\n \n}\n",
1875 xtype: Gtk.ScrolledWindow,
1878 shadow_type : Gtk.ShadowType.IN,
1881 XObject.prototype.init.call(this);
1882 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1886 xtype: Gtk.TreeView,
1889 headers_visible : false,
1890 enable_tree_lines : true,
1892 XObject.prototype.init.call(this);
1894 this.selection = this.el.get_selection();
1895 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1898 var description = new Pango.FontDescription.c_new();
1899 description.set_size(8000);
1900 this.el.modify_font(description);
1903 button_press_event : function (self, ev) {
1907 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1908 return false; //not on a element.
1912 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1914 if (res.column.title != 'value') {
1915 return false; // ignore..
1917 if ( this.get('/LeftPanel').editing) {
1920 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1921 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1922 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1926 var provider = this.get('/LeftTree').getPaleteProvider();
1928 var opts = provider.findOptions(type);
1930 if (opts === false) {
1931 this.get('/LeftPanel').editableColumn.setOptions([]);
1932 renderer.has_entry = true;
1934 LeftPanel.editableColumn.setOptions(opts);
1935 renderer.has_entry = false;
1939 //Seed.print("click" + ev.type);
1940 //console.dump(res);
1946 if (res.column.title == 'value') {
1949 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1950 var p = this.get('/LeftPanelPopup');
1955 p.el.set_screen(Gdk.Screen.get_default());
1957 p.el.popup(null, null, null, null, 3, ev.button.time);
1958 //Seed.print("click:" + res.column.title);
1966 xtype: Gtk.TreeStore,
1970 getIterValue : function(iter, col) {
1971 var gval = new GObject.Value('');
1972 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
1973 return '' + gval.value;
1975 add : function(info) {
1976 // info includes key, val, skel, etype..
1978 type = info.type.toLowerCase();
1979 var data = this.toJS();
1981 if (info.etype == 'events') {
1982 data.listeners = data.listeners || { };
1983 if (typeof(data.listeners[info.key]) != 'undefined') {
1984 return; //already set!
1987 if (typeof(data[info.key]) != 'undefined') {
1992 if (typeof(info.val) == 'undefined') {
1995 if (info.type == 'boolean') {
1998 if (type == 'number') {
2006 if (info.etype == 'events') {
2008 data.listeners[info.key] = info.val;
2011 data[info.key] = info.val;
2015 var map = this.load(data);
2017 // flag it as changed to the interface..
2019 this.get('/LeftTree.model').changed(data, true);
2022 this.startEditing(map[k]);
2025 LeftPanel.get('view').el.row_activated(
2026 new Gtk.TreePath.from_string(map[k]),
2027 LeftPanel.editableColumn.el
2031 changed : function(str, doRefresh) {
2032 if (!this.activePath) {
2035 var iter = new Gtk.TreeIter();
2036 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2038 this.el.set_value(iter, 1, '' +str);
2039 this.el.set_value(iter, 3, '' + this.toShort(str));
2040 var type = this.getIterValue(iter, 4);
2042 this.el.set_value(iter, 5, type + ' : ' + str);
2043 // update the tree...
2045 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2047 deleteSelected : function() {
2048 var data = this.toJS();
2049 var iter = new Gtk.TreeIter();
2050 var s = this.get('/LeftPanel.view').selection;
2051 s.get_selected(this.el, iter);
2054 var gval = new GObject.Value('');
2055 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2057 var val = gval.value;
2058 if (val[0] == '!') {
2060 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2063 delete data.listeners[ val.substring(1)];
2064 if (!XObject.keys(data.listeners).length) {
2065 delete data.listeners;
2069 if (typeof(data[val]) == 'undefined') {
2077 this.get('/LeftTree.model').changed(data, true);
2080 editSelected : function(e) {
2081 print("EDIT SELECTED?");
2082 var iter = new Gtk.TreeIter();
2083 var s = this.get('/LeftPanel.view').selection;
2084 s.get_selected(this.get('/LeftPanel.model').el, iter);
2085 var m = this.get('/LeftPanel.model')
2087 var gval = new GObject.Value('');
2088 this.el.get_value(iter, 0 ,gval);
2089 var val = '' + gval.value;
2091 gval = new GObject.Value('');
2092 this.el.get_value(iter, 1 ,gval);
2093 var rval = gval.value;
2094 var activePath = this.el.get_path(iter).to_string();
2095 this.activePath = activePath ;
2096 // was activeIter...
2099 var showEditor = false;
2101 if (val[0] == '!') {
2104 if (val[0] == '|') {
2105 if (rval.match(/function/g) || rval.match(/\n/g)) {
2112 this.activePath = false;
2113 GLib.timeout_add(0, 1, function() {
2114 // Gdk.threads_enter();
2115 _this.get('/BottomPane').el.show();
2116 _this.get('/RightEditor').el.show();
2117 _this.get('/RightEditor.view').load( rval );
2121 _this.activePath = activePath ;
2123 // Gdk.threads_leave();
2128 this.get('/BottomPane').el.hide();
2129 this.get('/RightEditor').el.hide();
2131 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2135 getType : function(treepath) {
2136 return this.getValue(treepath, 4);
2138 getValue : function(treepath_str, col) {
2139 var iter = new Gtk.TreeIter();
2140 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2142 var gval = new GObject.Value('');
2143 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2144 var val = '' + gval.value;
2148 var type = this.getType(this.el.get_path(iter).to_string());
2149 print("TYPE: " +type + " - val:" + val);
2150 switch(type.toLowerCase()) {
2154 return parseFloat(val); // Nan ?? invalid!!?
2157 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2159 return val == 'true' ? true : false;
2161 var nv = parseFloat(val);
2162 if (!isNaN(nv) && (val == ''+nv)) {
2170 XObject.prototype.init.call(this);
2171 this.el.set_column_types ( 6, [
2172 GObject.TYPE_STRING, // 0 real key
2173 GObject.TYPE_STRING, // 1 real value
2174 GObject.TYPE_STRING, // 2 visable key
2175 GObject.TYPE_STRING, // 3 visable value
2176 GObject.TYPE_STRING, // 4 need to store type of!!!
2177 GObject.TYPE_STRING // 5 tooltip
2181 load : function(ar) {
2184 this.get('/RightEditor').el.hide();
2191 var provider = this.get('/LeftTree').getPaleteProvider();
2192 var iter = new Gtk.TreeIter();
2195 var keys = XObject.keys(ar);
2197 ar.listeners = ar.listeners || {};
2199 for (var i in ar.listeners ) {
2200 this.el.append(iter);
2201 var p = this.el.get_path(iter).to_string();
2204 this.el.set_value(iter, 0, '!'+ i );
2205 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2206 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2208 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2209 this.el.set_value(iter, 4, 'function');
2210 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2216 keys.forEach(function(i) {
2217 if (typeof(ar[i]) == 'object') {
2221 var type = provider.findType(ar, i, ar[i]);
2223 _this.el.append(iter);
2224 var p = _this.el.get_path(iter).to_string();
2226 _this.el.set_value(iter, 0, ''+i);
2227 _this.el.set_value(iter, 1, '' + ar[i]);
2228 _this.el.set_value(iter, 2, ''+i);
2229 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2230 _this.el.set_value(iter, 4, ''+type);
2231 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2235 startEditing : function(path,col) {
2237 * start editing path (or selected if not set..)
2238 * @param {String|false} path (optional) treepath to edit - selected tree gets
2239 * edited by default.
2240 * @param {Number} 0 or 1 (optional)- column to edit.
2243 if (typeof(path) == 'string') {
2244 tp = new Gtk.TreePath.from_string(path);
2246 var iter = new Gtk.TreeIter();
2247 var s = this.get('/LeftPanel.view').selection;
2248 s.get_selected(this.el, iter);
2249 tp = this.el.get_path(iter);
2250 path = tp.to_string();
2254 // which colum is to be edited..
2256 if (typeof(col) == 'undefined') {
2257 var k = this.getValue(path, 0);
2258 colObj = (!k.length || k == '|') ?
2259 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2261 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2264 // make sure the pulldown is set correctly..
2265 // not really needed for second col...
2267 var provider = this.get('/LeftTree').getPaleteProvider();
2269 var type = this.get('/LeftPanel.model').getType(path);
2270 var opts = provider.findOptions(type);
2271 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2273 if (opts === false) {
2274 this.get('/LeftPanel').editableColumn.setOptions([]);
2275 renderer.has_entry = true; /// probably does not have any effect.
2277 this.get('/LeftPanel').editableColumn.setOptions(opts);
2278 renderer.has_entry = false;
2282 // iter now has row...
2283 GLib.timeout_add(0, 100, function() {
2285 colObj.items[0].el.editable = true; // esp. need for col 0..
2286 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2296 var iter = new Gtk.TreeIter();
2297 this.get('/LeftPanel.model').el.get_iter_first(iter);
2302 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2305 ar.listeners = ar.listeners || {};
2306 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2309 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2312 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2318 //print(JSON.stringify(ar));
2322 toShort : function(str) {
2323 var a = typeof(str) == 'string' ? str.split("\n") : [];
2324 return a.length > 1 ? a[0] + '....' : '' + str;
2328 xtype: Gtk.TreeViewColumn,
2329 pack : "append_column",
2331 XObject.prototype.init.call(this);
2333 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2334 this.get('/LeftPanel').propertyColumn = this;
2339 xtype: Gtk.CellRendererText,
2340 pack : "pack_start",
2342 editing_started : function (self, editable, path) {
2344 this.get('/LeftPanel.model').activePath = path;
2347 edited : function (self, object, p0) {
2348 var model = this.get('/LeftPanel.model');
2349 var path = model.activePath;
2350 var iter = new Gtk.TreeIter();
2351 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2352 model.el.set_value(iter, 0, p0);
2353 model.el.set_value(iter, 2, p0);
2355 model.activePath = false;
2357 this.get('/LeftTree.model').changed(model.toJS(), true);
2358 this.el.editable = false;
2365 xtype: Gtk.TreeViewColumn,
2366 pack : "append_column",
2368 XObject.prototype.init.call(this);
2369 this.el.add_attribute(this.items[0].el , 'text', 3 );
2370 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2371 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2372 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2374 this.get('/LeftPanel').editableColumn= this;
2376 setOptions : function(ar) {
2377 var m = this.items[0].el.model;
2379 var iter = new Gtk.TreeIter();
2380 ar.forEach(function(i) {
2383 m.set_value(iter, 0, i);
2389 xtype: Gtk.CellRendererCombo,
2390 pack : "pack_start",
2395 XObject.prototype.init.call(this);
2396 this.el.model = new Gtk.ListStore();
2397 this.el.model.set_column_types ( 1, [
2398 GObject.TYPE_STRING // 0 real key
2402 edited : function (self, object, p0) {
2403 this.get('/LeftPanel').editing = false;
2404 print("EDITED? p:" + p0 + " t:" + p0);
2405 this.get('/LeftPanel.model').changed(p0, true);
2406 this.get('/LeftPanel.model').activePath = false;
2408 editing_started : function (self, editable, path) {
2409 this.get('/LeftPanel').editing = true;
2410 // console.log('editing started');
2411 // r.has_entry = false;
2412 this.get('/LeftPanel.model').editSelected(editable);
2423 id : "LeftPanelPopup",
2426 xtype: Gtk.MenuItem,
2430 activate : function (self) {
2431 this.get('/LeftPanel.model').deleteSelected();
2436 xtype: Gtk.MenuItem,
2440 activate : function (self) {
2441 this.get('/LeftPanel.model').startEditing(false, 0);
2454 xtype: Gtk.ScrolledWindow,
2455 pack : "pack_end,false,true,0",
2457 shadow_type : Gtk.ShadowType.IN,
2459 XObject.prototype.init.call(this);
2460 XObject.prototype.init.call(this);
2461 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2462 this.el.set_size_request ( 150, -1 );
2465 activeElement : false,
2466 hideWin : function() {
2473 if (this.get('/Window.left').el.position < 160) {
2476 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2483 xtype: Gtk.TreeView,
2484 enable_tree_lines : true,
2485 headers_visible : false,
2488 XObject.prototype.init.call(this);
2490 var description = new Pango.FontDescription.c_new();
2491 description.set_size(8000);
2492 this.el.modify_font(description);
2494 //this.selection = this.el.get_selection();
2495 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2504 cursor_changed : function (self) {
2505 var iter = new Gtk.TreeIter();
2507 //console.log('changed');
2508 var m = this.get('model');
2509 if (!this.selection){
2510 this.selection = this.el.get_selection();
2513 var s = this.selection;
2514 if (!s.get_selected(m.el, iter)) {
2517 var tp = m.el.get_path(iter).to_string();
2522 var key = m.getValue(tp, 0);
2524 var type = m.getValue(tp, 1);
2525 var skel = m.getValue(tp, 3);
2526 var etype = m.getValue(tp, 5);
2529 this.get('/MidPropTree').hideWin();
2531 if (type == 'function') {
2533 if (etype != 'events') {
2537 this.get('/LeftPanel.model').add({
2546 if (type.indexOf('.') > -1 ||
2547 type == 'boolean') {
2551 this.get('/LeftPanel.model').add( {
2561 xtype: Gtk.ListStore,
2564 XObject.prototype.init.call(this);
2565 this.el.set_column_types ( 6, [
2566 GObject.TYPE_STRING, // real key
2567 GObject.TYPE_STRING, // real type
2568 GObject.TYPE_STRING, // docs ?
2569 GObject.TYPE_STRING, // visable desc
2570 GObject.TYPE_STRING, // function desc
2571 GObject.TYPE_STRING // element type (event|prop)
2575 getValue : function(treepath, col)
2577 var tp = new Gtk.TreePath.from_string (treepath);
2578 var iter = new Gtk.TreeIter();
2579 this.el.get_iter (iter, tp);
2580 var value = new GObject.Value('');
2581 this.el.get_value(iter, col, value);
2585 showData : function(type) {
2587 if (!this.get('/MidPropTree').activeElement || !type) {
2588 return; // no active element
2591 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2592 var palete = this.get('/LeftTree').getPaleteProvider();
2596 Seed.print('Showing right?');
2597 if (!this.get('/MidPropTree').shown) {
2599 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2600 this.get('/MidPropTree').el.show();
2601 this.get('/MidPropTree').shown = true;
2604 var elementList = palete.getPropertiesFor(fullpath, type);
2605 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2606 // console.dump(elementList);
2609 var iter = new Gtk.TreeIter();
2610 for(var i =0 ; i < elementList.length; i++) {
2611 var p=elementList[i];
2612 this.el.append(iter);
2613 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2614 //GObject.TYPE_STRING, // real key
2615 // GObject.TYPE_STRING, // real type
2616 // GObject.TYPE_STRING, // docs ?
2617 // GObject.TYPE_STRING // func def?
2620 this.el.set_value(iter, 0, p.name);
2621 this.el.set_value(iter, 1, p.type);
2622 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2623 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2624 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2625 this.el.set_value(iter, 5, type);
2633 xtype: Gtk.TreeViewColumn,
2635 this.el = new Gtk.TreeViewColumn();
2636 this.parent.el.append_column(this.el);
2638 XObject.prototype.init.call(this);
2639 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2644 xtype: Gtk.CellRendererText,
2645 pack : "pack_start,true"
2669 xtype: Gtk.Notebook,
2670 pack : "pack_start,true,true",
2671 id : "view-help-nb",
2673 XObject.prototype.init.call(this);
2674 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2675 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2679 xtype: Gtk.Notebook,
2681 id : "view-notebook",
2684 XObject.prototype.init.call(this);
2685 this.el.set_current_page(0);
2687 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2688 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2695 id : "RightBrowser",
2702 pack : "pack_start,false,true,0",
2706 pack : "pack_start,false,false,0",
2709 button_press_event : function (self, event) {
2710 var js = this.get('/LeftTree.model').toJS();
2712 this.get('/RightBrowser.view').renderJS(js[0]);
2721 button_press_event : function (self, event) {
2722 this.get('/RooProjectProperties').show();
2726 label : "Set extra HTML in renderer",
2727 pack : "pack_start,false,false,0"
2732 button_press_event : function (self, event)
2734 /* Firefox testing for debugging..
2735 - we can create a /tmp directory, and put.
2736 builder.html, builder.html.js, link roojs1
2737 add at the end of builder.html Roo.onload(function() {
2739 if (!this.get('/Window.LeftTree').getActiveFile()) {
2743 var js = this.get('/LeftTree.model').toJS();
2744 if (!js || !js[0]) {
2747 var project = this.get('/Window.LeftTree').getActiveFile().project;
2748 //print (project.fn);
2750 project.runhtml = project.runhtml || '';
2753 var File = imports.File.File;
2755 var target = "/tmp/firetest"; // fixme..
2756 if (!File.isDirectory(target)) {
2759 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
2760 if (!File.exists( target+ '/roojs1')) {
2761 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
2766 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2767 html = html.replace('</head>', project.runhtml + '</head>');
2770 var jsstr = JSON.stringify(js[0]);
2772 var runbuilder = '<script type="text/javascript">' + "\n" +
2773 " Builder.render(" + jsstr + ");\n" +
2776 html = html.replace('</body>', runbuilder + '</body>');
2778 File.write( target+ '/builder.html', html);
2780 this.get('/Terminal').feed("RUN DIR:" + target);
2782 this.get('/Terminal').el.fork_command( null , [], [], target
2783 , false,false,false);
2784 var cmd = "firefox file://" + target + "/builder.html \n";
2785 this.get('/Terminal').el.feed_child(cmd, cmd.length);
2789 label : "Test in Firefox",
2790 pack : "pack_start,false,false,0"
2795 xtype: Gtk.ScrolledWindow,
2797 shadow_type : Gtk.ShadowType.IN,
2799 XObject.prototype.init.call(this);
2800 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2804 xtype: WebKit.WebView,
2808 XObject.prototype.init.call(this);
2809 // this may not work!?
2810 this.el.open('file:///' + __script_path__ + '/../builder.html');
2814 this.el, /* widget that will accept a drop */
2815 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2816 null, /* lists of target to support */
2817 0, /* size of list */
2818 Gdk.DragAction.COPY /* what to do with data after dropped */
2821 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2822 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2824 renderJS : function(data) {
2825 print("HTML RENDERING");
2826 /// prevent looping..
2827 //if (this.pendingRedraw) {
2828 // print("pending redraw active?!");
2833 if (!this.get('/Window.LeftTree').getActiveFile()) {
2837 var project = this.get('/Window.LeftTree').getActiveFile().project;
2838 //print (project.fn);
2840 project.runhtml = project.runhtml || '';
2843 this.runhtml = this.runhtml || '';
2845 if (project.runhtml != this.runhtml) {
2846 // then we need to reload the browser using
2847 // load_html_string..
2849 // then trigger a redraw once it's loaded..
2850 this.pendingRedraw = true;
2852 this.runhtml = project.runhtml;
2854 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2855 html = html.replace('</head>', this.runhtml + '</head>');
2856 print("LOAD HTML " + html);
2857 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2858 // should trigger load_finished!
2863 this.pendingRedraw = false;
2866 this.renderedData = data;
2867 var str = JSON.stringify(data) ;
2870 console.log('not loaded yet');
2872 //Seed.print("RENDER:" + str);
2873 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2875 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2878 load_finished : function (self, object) {
2879 // if (this.ready) { // dont do it twice!
2883 this.pendingRedraw = false;
2884 var js = this.get('/LeftTree.model').toJS();
2886 this.renderJS(js[0]);
2890 script_alert : function (self, object, p0) {
2893 return true; // do not display anything...
2895 console_message : function (self, object, p0, p1) {
2896 // console.log(object);
2897 if (!object.match(/^\{/)) {
2899 this.get('/Terminal').feed(object);
2900 return true; // do not handle!!! -> later maybe in console..
2902 // console.log(object);
2903 var val = JSON.parse(object);
2905 if (typeof(val['hover-node']) != 'undefined') {
2906 this.activeNode = val['hover-node'];
2907 console.log('active node: ' + this.activeNode);
2912 if (typeof(val['id']) != 'undefined') {
2913 // this.activeNode = val['id'];
2914 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2918 this.get('/LeftTree.view').selectNode(tg[0]);
2922 if (ret && typeof(val['set']) != 'undefined') {
2923 this.get('/LeftPanel.model').add({
2927 //console.log('active node: ' + this.activeNode);
2930 //Seed.print('a:'+a);
2931 //Seed.print('b:'+b);
2932 //Seed.print('c:'+c);
2935 drag_motion : function (w, ctx, x, y, time, ud) {
2936 // console.log('DRAG MOTION');
2938 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2939 this.targetData = [];
2940 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2942 // A) find out from drag all the places that node could be dropped.
2943 var src = Gtk.drag_get_source_widget(ctx);
2944 if (!src.dropList) {
2945 Gdk.drag_status(ctx, 0, time);
2948 // b) get what we are over.. (from activeNode)
2949 // tree is empty.. - list should be correct..
2950 if (!this.get('/LeftTree.model').currentTree) {
2951 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2955 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2957 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2960 Gdk.drag_status(ctx, 0,time);
2961 this.get('/LeftTree.view').highlight(false);
2965 // if we have a target..
2966 // -> highlight it! (in browser)
2967 // -> highlight it! (in tree)
2969 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2970 this.get('/LeftTree.view').highlight(tg);
2971 this.targetData = tg;
2972 // for tree we should handle this...
2975 drag_drop : function (w, ctx, x, y,time, ud) {
2976 print("TARGET: drag-drop");
2977 var is_valid_drop_site = true;
2982 w, /* will receive 'drag-data-received' signal */
2983 ctx, /* represents the current state of the DnD */
2984 this.get('/Window').atoms["STRING"], /* the target type we want */
2985 time /* time stamp */
2989 /* No target offered by source => error */
2992 return is_valid_drop_site;
2994 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2996 print("Browser: drag-data-received");
2997 var delete_selection_data = false;
2998 vardnd_success = false;
2999 /* Deal with what we are given from source */
3000 if( sel_data && sel_data.length ) {
3002 if (ctx.action == Gdk.DragAction.ASK) {
3003 /* Ask the user to move or copy, then set the ctx action. */
3006 if (ctx.action == Gdk.DragAction.MOVE) {
3007 delete_selection_data = true;
3009 var source = Gtk.drag_get_source_widget(ctx);
3011 print("Browser: source.DRAGDATA? " + source.dragData);
3012 if (this.targetData) {
3013 print(this.targetData);
3014 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3023 if (dnd_success == false)
3025 Seed.print ("DnD data transfer failed!\n");
3028 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3039 id : "RightGtkView",
3041 redraw : function() {
3042 this.highlightWidget = false;
3043 print("REDRAW CALLED");
3044 this.activePath = this.get('/LeftTree').getActivePath();
3045 if (this.renderedEl) {
3046 print("QUEUE DRAW CALLING");
3047 this.renderedEl.queue_draw();
3050 renderJS : function(data, withDebug)
3052 this.highlightWidget = false;
3056 this.withDebug = false;
3058 if (this.renderedEl) {
3059 this.get('view').el.remove(this.renderedEl);
3060 this.renderedEl.destroy();
3061 this.renderedEl = false;
3064 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3065 // in theory tree is actually window..
3067 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3072 this.get('view').el.set_size_request(
3073 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3076 this.renderedEl.set_size_request(
3077 tree.default_width || 600,
3078 tree.default_height || 400
3080 this.get('view').el.show_all();
3085 showInWindow : function() {
3086 print("GET PROEJCT");
3087 var pr = this.get('/LeftProjectTree').getActiveProject();
3089 console.log(pr.paths);
3092 var src= this.buildJS(
3093 this.get('/LeftTree.model').toJS()[0],
3098 //var x = new imports.sandbox.Context();
3102 Seed.check_syntax('var e = ' + src);
3105 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3106 this.get('/Terminal').feed(console._dump(e)+"\n");
3108 var lines = src.split("\n");
3109 var start = Math.max(0, e.line - 10);
3110 var end = Math.min(lines.length, e.line + 10);
3111 for (var i =start ; i < end; i++) {
3113 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3116 this.get('/Terminal').feed(lines[i] + "\n");
3123 this.get('/BottomPane').el.set_current_page(1);
3124 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3125 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3126 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3128 var _top = x.get_global_object()._top;
3130 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3132 if (_top.el.popup) {
3133 _top.el.popup(null, null, null, null, 3, null);
3137 viewAdd : function(item, par)
3139 // does something similar to xobject..
3140 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3142 if (item.pack===false || item.pack === 'false') { // no ;
3145 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3146 var type = item['|xns'] + '.' + item['xtype'];
3147 var ns = imports.gi[item['|xns']];
3148 var ctr = ns[item['xtype']];
3150 for(var k in item) {
3152 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3167 if (k[0] == '|' && typeof(kv) == 'string') {
3169 if (kv.match(new RegExp('function'))) {
3172 print("WASL " + k + '=' + kv);
3174 eval( 'kv = ' + kv);
3175 } catch(e) { continue; }
3178 // print(k + '=' + kv);
3180 if (k[0] == '|') { // should be boolean or number..
3182 //print(k + '=' + kv);
3185 if (k == 'show_tabs') { // force tab showing for notebooks.
3188 print(k + '=' + typeof(kv) + " : " + kv);
3194 var el = new ctr(ctr_args);
3196 print("PACK" + item.pack);
3197 //console.dump(item.pack);
3204 if (typeof(item.pack) == 'string') {
3206 item.pack.split(',').forEach(function(e, i) {
3208 if (e == 'false') { args.push( false); return; }
3209 if (e == 'true') { args.push( true); return; }
3210 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3213 //print(args.join(","));
3215 pack_m = args.shift();
3217 pack_m = item.pack.shift();
3222 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3224 name: "ArgumentError",
3225 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3226 "ADDING : " + item.id + " " + el
3235 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3236 //Seed.print('args: ' + args.length);
3238 par[pack_m].apply(par, args);
3242 item.items = item.items || [];
3243 item.items.forEach(function(ch,n) {
3245 print ("type:" + type);
3247 print ("ch.pack:" + ch.pack);
3248 if (type == 'Gtk.Table' && ch.pack == 'add') {
3249 var c = n % item.n_columns;
3250 var r = Math.floor(n/item.n_columns);
3251 ch.pack = [ 'attach', c, c+1, r, r+1,
3252 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3253 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3254 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3255 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3259 _this.viewAdd(ch, el);
3264 // add the signal handlers.
3265 // is it a widget!?!!?
3271 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3272 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3273 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3274 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3275 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3285 widgetDragDropEvent : function() {
3286 print("WIDGET DRAGDROP");
3289 widgetDragMotionEvent : function() {
3290 print("WIDGET DRAGMOTION");
3293 widgetExposeEvent : function(w, evt, ud, item) {
3295 if (this.inRender) {
3299 if ( this.highlightWidget) {
3300 this.inRender = true;
3301 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3302 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3304 this.inRender = false;
3309 if (this.activePath != item.xtreepath) {
3313 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3314 // work out the coords of the window..
3316 var dr = widget.window;
3317 this.gc = (new Gdk.GC.c_new(dr));
3318 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3319 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3323 var r = evt.expose.area;
3324 // console.dump([r.x, r.y, r.width, r.height ] );
3326 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3327 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3328 // happens with gtkscrollview embedded stuff..
3329 var np =this.activePath.split(':');
3331 this.activePath = np.join(':');
3332 this.renderedEl.queue_draw();
3348 this.inRender = true;
3351 this.highlightWidget = widget;
3356 // print("DRAW BOX");
3357 //console.dump(this.box);
3358 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3359 this.inRender = false;
3362 widgetPressEvent : function(w,e,u,d) {
3363 if (this.get('view').pressed) {
3366 this.get('view').pressed = true;
3367 print("WIDGET PRESS " + d.xtreepath );
3368 this.get('/LeftTree.view').selectNode( d.xtreepath );
3371 widgetReleaseEvent : function() {
3372 this.get('view').pressed = false;
3378 pack : "pack_start,false,true,0",
3382 pack : "pack_start,false,false,0",
3383 label : "Run The Application",
3385 button_press_event : function (self, event) {
3386 // call render on left tree - with special option!?!
3388 //print("GET PROEJCT");
3389 var pr = this.get('/LeftProjectTree').getActiveProject();
3392 for (var i in pr.paths) {
3396 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3397 this.get('/Terminal').feed("RUN DIR:" + dir);
3399 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3400 , false,false,false);
3401 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3402 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3412 xtype: Gtk.ScrolledWindow,
3415 shadow_type : Gtk.ShadowType.IN,
3417 XObject.prototype.init.call(this);
3418 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3422 xtype: Gtk.EventBox,
3423 pack : "add_with_viewport",
3425 XObject.prototype.init.call(this);
3426 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3427 red: 0x9F00, green: 0xB800 , blue : 0xA800
3435 XObject.prototype.init.call(this);
3436 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3437 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3442 xtype: Gtk.EventBox,
3445 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3446 XObject.prototype.init.call(this);
3450 this.el, /* widget that will accept a drop */
3451 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3452 null, /* lists of target to support */
3453 0, /* size of list */
3454 Gdk.DragAction.COPY /* what to do with data after dropped */
3457 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3458 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3461 getActiveNode : function(x,y)
3463 // workout what node is here..
3464 return '0'; // top..
3468 drag_motion : function (self, ctx, x, y, time) {
3470 // A) find out from drag all the places that node could be dropped.
3471 var src = Gtk.drag_get_source_widget(ctx);
3472 if (!src.dropList) {
3473 Gdk.drag_status(ctx, 0, time);
3476 // b) get what we are over.. (from activeNode)
3477 // tree is empty.. - list should be correct..
3478 if (!this.get('/LeftTree.model').currentTree) {
3479 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3483 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3484 var activeNode = this.getActiveNode(x, y);
3487 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3490 Gdk.drag_status(ctx, 0,time);
3491 this.get('/LeftTree.view').highlight(false);
3495 // if we have a target..
3496 // -> highlight it! (in browser)
3497 // -> highlight it! (in tree)
3499 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3500 this.get('/LeftTree.view').highlight(tg);
3501 this.targetData = tg;
3502 // for tree we should handle this...
3505 drag_drop : function (self,ctx, x, y, time) {
3506 Seed.print("TARGET: drag-drop");
3507 var is_valid_drop_site = true;
3512 self, /* will receive 'drag-data-received' signal */
3513 ctx, /* represents the current state of the this.gDnD */
3514 this.get('/Window').atoms["STRING"], /* the target type we want */
3515 time /* time stamp */
3519 /* No target offered by source => error */
3522 return is_valid_drop_site;
3525 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3527 Seed.print("GtkView: drag-data-received");
3528 var delete_selection_data = false;
3529 var dnd_success = false;
3530 /* Deal with what we are given from source */
3531 if( sel_data && sel_data.length ) {
3533 if (ctx.action == Gdk.DragAction.ASK) {
3534 /* Ask the user to move or copy, then set the ctx action. */
3537 if (ctx.action == Gdk.DragAction.MOVE) {
3538 delete_selection_data = true;
3540 var source = Gtk.drag_get_source_widget(ctx);
3542 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3543 if (this.targetData) {
3544 Seed.print(this.targetData);
3545 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3554 if (dnd_success == false)
3556 Seed.print ("DnD data transfer failed!\n");
3559 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3562 button_press_event : function (self, event) {
3563 this.pressed = false;
3579 xtype: Gtk.ScrolledWindow,
3584 var file = this.get('/LeftTree').getActiveFile();
3588 var activeEl = this.get('/LeftTree').getActiveElement();
3589 var xtype = file.guessName( activeEl )
3590 if (!xtype || !xtype.length) {
3593 this.get('/Window.view-help-nb').el.set_current_page(1);
3595 // get the active element being edited.
3596 var helpurl = file.getHelpUrl(xtype);
3598 // now load the help info in the page..
3599 this.get('help-view').el.open(helpurl);
3603 xtype: WebKit.WebView,
3607 XObject.prototype.init.call(this);
3608 this.get('/Window.help-view').el.open(
3609 "http://devel.akbkhome.com/seed/");
3621 xtype: Gtk.Notebook,
3624 XObject.prototype.init.call(this);
3625 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3626 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3631 xtype: Gtk.ScrolledWindow,
3636 xtype: GtkSource.View,
3640 XObject.prototype.init.call(this);
3641 var description = Pango.Font.description_from_string("monospace")
3642 description.set_size(8000);
3643 this.el.modify_font(description);
3646 load : function(str) {
3648 // show the help page for the active node..
3649 this.get('/Help').show();
3652 this.get('/BottomPane').el.set_current_page(0);
3653 this.el.get_buffer().set_text(str, str.length);
3654 var lm = GtkSource.LanguageManager.get_default();
3656 this.el.get_buffer().set_language(lm.get_language('js'));
3657 var buf = this.el.get_buffer();
3658 var cursor = buf.get_mark("insert");
3659 var iter= new Gtk.TextIter;
3660 buf.get_iter_at_mark(iter, cursor);
3662 iter.set_line_offset(4);
3663 buf.move_mark(cursor, iter);
3666 cursor = buf.get_mark("selection_bound");
3667 iter= new Gtk.TextIter;
3668 buf.get_iter_at_mark(iter, cursor);
3670 iter.set_line_offset(4);
3671 buf.move_mark(cursor, iter);
3673 this.el.grab_focus();
3675 insert_spaces_instead_of_tabs : true,
3678 show_line_numbers : true,
3681 xtype: GtkSource.Buffer,
3682 pack : "set_buffer",
3684 changed : function (self) {
3685 var s = new Gtk.TextIter();
3686 var e = new Gtk.TextIter();
3687 this.el.get_start_iter(s);
3688 this.el.get_end_iter(e);
3689 var str = this.el.get_text(s,e,true);
3691 Seed.check_syntax('var e = ' + str);
3693 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3694 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3696 print("SYNTAX ERROR IN EDITOR");
3701 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3702 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3705 this.get('/LeftPanel.model').changed( str , false);
3714 xtype: Gtk.ScrolledWindow,
3718 xtype: Vte.Terminal,
3721 feed : function(istr) {
3722 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3723 // we should make ourselves visable!!!
3724 this.get('/BottomPane').el.show();
3725 this.get('/BottomPane').el.set_current_page(1);
3727 this.el.feed(str ,str.length);
3729 scroll_on_output : true,
3731 XObject.prototype.init.call(this);
3732 this.el.set_size (80, 1000);
3734 scrollback_lines : 1000
3744 pack : "pack_start,false,false",
3748 this.get('buttonbar').el.show();
3749 this.get('viewbox').el.hide();
3750 print("TRIED TO HIDE");
3753 this.get('buttonbar').el.hide();
3754 this.get('viewbox').el.show();
3755 // this.get('model').expanded();
3767 pack : "pack_start,false,true",
3769 clicked : function (self) {
3770 this.get('/RightPalete').show();
3777 stock : Gtk.STOCK_GOTO_FIRST,
3778 icon_size : Gtk.IconSize.MENU
3788 XObject.prototype.init.call(this);
3789 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3792 enter_notify_event : function (self, event) {
3793 this.get('/RightPalete').show();
3807 pack : "pack_start,false,true",
3816 pack : "pack_start,false,true",
3818 clicked : function (self) {
3819 this.get('/RightPalete').hide();
3826 stock : Gtk.STOCK_GOTO_LAST,
3827 icon_size : Gtk.IconSize.MENU
3834 xtype: Gtk.ScrolledWindow,
3837 XObject.prototype.init.call(this);
3838 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3839 this.el.set_size_request(-1,200);
3841 shadow_type : Gtk.ShadowType.IN,
3844 xtype: Gtk.TreeView,
3847 XObject.prototype.init.call(this);
3848 this.el.set_size_request(150,-1);
3849 // set_reorderable: [1]
3851 var description = new Pango.FontDescription.c_new();
3852 description.set_size(8000);
3853 this.el.modify_font(description);
3855 this.selection = this.el.get_selection();
3856 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3857 // this.selection.signal['changed'].connect(function() {
3858 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3860 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3862 Gtk.drag_source_set (
3863 this.el, /* widget will be drag-able */
3864 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3865 null, /* lists of target to support */
3866 0, /* size of list */
3867 Gdk.DragAction.COPY /* what to do with data after dropped */
3869 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3871 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3872 Gtk.drag_source_add_text_targets(this.el);
3874 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3875 targets = new Gtk.TargetList();
3876 targets.add( LeftTree.atoms["STRING"], 0, 0);
3877 targets.add_text_targets( 1 );
3878 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3880 //if you want to allow text to be output elsewhere..
3881 //Gtk.drag_source_add_text_targets(this.el);
3885 headers_visible : false,
3886 enable_tree_lines : true,
3888 drag_begin : function (self, ctx) {
3889 // we could fill this in now...
3890 Seed.print('SOURCE: drag-begin');
3894 var iter = new Gtk.TreeIter();
3895 var s = this.selection;
3896 s.get_selected(this.get('/RightPalete.model').el, iter);
3897 var path = this.get('/RightPalete.model').el.get_path(iter);
3899 var pix = this.el.create_row_drag_icon ( path);
3902 Gtk.drag_set_icon_pixmap (ctx,
3909 var value = new GObject.Value('');
3910 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3911 if (!this.get('/RightPalete').provider) {
3914 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3915 this.el.dragData = value.value;
3922 drag_data_get : function (self, drag_context, selection_data, info, time) {
3923 //Seed.print('Palete: drag-data-get: ' + target_type);
3924 if (this.el.dragData && this.el.dragData.length ) {
3925 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3929 //this.el.dragData = "TEST from source widget";
3933 drag_end : function (self, drag_context) {
3934 Seed.print('SOURCE: drag-end');
3935 this.el.dragData = false;
3936 this.el.dropList = false;
3937 this.get('/LeftTree.view').highlight(false);
3943 xtype: Gtk.ListStore,
3946 XObject.prototype.init.call(this);
3947 this.el.set_column_types ( 2, [
3948 GObject.TYPE_STRING, // title
3949 GObject.TYPE_STRING // tip
3954 load : function(tr,iter)
3959 //console.log('Project tree load: ' + tr.length);
3960 var citer = new Gtk.TreeIter();
3961 //this.insert(citer,iter,0);
3962 for(var i =0 ; i < tr.length; i++) {
3965 this.el.append(citer);
3967 this.el.insert(citer,iter,-1);
3972 this.el.set_value(citer, 0, '' + r ); // title
3974 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3975 //if (r.cn && r.cn.length) {
3976 // this.load(r.cn, citer);
3982 getValue : function (iter, col) {
3983 var gval = new GObject.Value('');
3984 this.el.get_value(iter, col ,gval);
3991 xtype: Gtk.TreeViewColumn,
3992 pack : "append_column",
3994 XObject.prototype.init.call(this);
3995 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3999 xtype: Gtk.CellRendererText,
4021 XObject.cache['/Window'] = Window;