3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 GtkClutter = imports.gi.GtkClutter;
11 console = imports.console;
12 XObject = imports.XObject.XObject;
15 type : Gtk.WindowType.TOPLEVEL,
16 title : "Application Builder",
20 "STRING" : Gdk.atom_intern("STRING")
22 this.targetList = new Gtk.TargetList();
23 this.targetList.add( this.atoms["STRING"], 0, 0);
24 //imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
26 "style \"gtkcombobox-style\" {\n" +
27 " GtkComboBox::appears-as-list = 1\n" +
29 "class \"GtkComboBox\" style \"gtkcombobox-style\"\n");
30 XObject.prototype.init.call(this);
39 setTitle : function(str) {
40 this.el.set_title(this.title + ' - ' + str);
43 delete_event : function (self, event) {
46 destroy : function (self) {
49 show : function (self) {
50 print("WINDOW SHOWING - trying to hide");
51 imports.Builder.Provider.ProjectManager.ProjectManager.loadConfig();
52 this.get('/MidPropTree').hideWin();
53 this.get('/RightPalete').hide();
54 this.get('/BottomPane').el.hide();
65 pack : "pack_start,false,false",
79 label : "New _Project",
81 activate : function (self) {
83 this.get('/EditProject').show({
84 success : function(pr) {
85 _this.get('/LeftProjectTree').get('combo').setValue(pr.fn);
96 activate : function (self) {
97 var fn = this.get('/LeftProjectTree.combo').getValue();
99 this.get('/LeftProjectTree').showNoProjectSelected();
102 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
103 this.get('/DialogNewComponent').show({
104 project : pm.getByFn(fn)
110 xtype: Gtk.SeparatorMenuItem,
115 use_underline : true,
117 label : "D_elete Project",
119 activate : function (self) {
121 var fn = this.get('/LeftProjectTree').get('combo').getValue();
123 this.get('/StandardErrorDialog').show("Select a project")
126 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
127 var pr = pm.getByFn(fn);
130 this.get('/DialogConfirm').show("Are you sure you want to delete project '" + pr.name + "'", function() {
131 pm.deleteProject(fn);
139 xtype: Gtk.SeparatorMenuItem,
146 use_underline : true,
148 activate : function (self) {
160 use_underline : true,
165 pack : "set_submenu",
170 activate : function (self) {
171 var fn = this.get('/LeftTree').getActiveFile();
173 this.get('/StandardErrorDialog').show("No File active");
177 this.get('/DialogNewComponent').show(fn);
181 label : "File _Properties",
188 activate : function (self, event) {
189 this.get('/RooProjectProperties').show();
193 label : "Modify Project HTML ",
204 use_underline : true,
208 pack : "set_submenu",
213 activate : function (self, event) {
214 var js = this.get('/LeftTree.model').toJS();
216 this.get('/RightBrowser.view').renderJS(js[0]);
221 label : "_Redraw (Roo)",
228 activate : function (self, event)
230 /* Firefox testing for debugging..
231 - we can create a /tmp directory, and put.
232 builder.html, builder.html.js, link roojs1
233 add at the end of builder.html Roo.onload(function() {
235 if (!this.get('/Window.LeftTree').getActiveFile()) {
239 var js = this.get('/LeftTree.model').toJS();
243 var project = this.get('/Window.LeftTree').getActiveFile().project;
244 //print (project.fn);
246 project.runhtml = project.runhtml || '';
249 var File = imports.File.File;
251 var target = "/tmp/firetest"; // fixme..
252 if (!File.isDirectory(target)) {
255 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
256 if (!File.exists( target+ '/roojs1')) {
257 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
262 var html = imports.File.File.read(__script_path__ + '/../builder.html');
263 html = html.replace('</head>', project.runhtml + '</head>');
266 var jsstr = JSON.stringify(js[0], null, 4);
268 var runbuilder = '<script type="text/javascript">' + "\n" +
269 " Builder.render(" + jsstr + ");\n" +
272 html = html.replace('</body>', runbuilder + '</body>');
274 File.write( target+ '/builder.html', html);
276 this.get('/Terminal').feed("RUN DIR:" + target);
278 this.get('/Terminal').el.fork_command( null , [], [], target
279 , false,false,false);
280 var cmd = "firefox file://" + target + "/builder.html \n";
281 this.get('/Terminal').el.feed_child(cmd, cmd.length);
285 label : "_Test in Firefox (Roo)",
296 use_underline : true,
301 pack : "set_submenu",
307 use_underline : true,
309 activate : function (self) {
310 this.get('/About').el.run();
340 activate : function (self) {
341 var nb = this.get('/LeftTopPanel.notebook');
342 if (this.el.expanded) {
345 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
348 var model = this.get('/LeftProjectTree.combomodel');
349 // print ("loading Projects?")
350 //console.dump(pm.projects);
351 model.loadData(pm.projects);
354 nb.el.set_current_page(1);
355 //pm.on('changed', function() {
356 //console.log("CAUGHT project manager change");
357 // _combo.model.loadData(pm.projects);
361 nb.el.set_current_page(0);
363 enter_notify_event : function (self, event) {
364 this.el.expanded = !this.el.expanded;
365 //if (this.el.expanded ) {
366 this.listeners.activate.call(this);
373 label : "Select Project or File",
374 pack : "pack_start,false,true",
376 XObject.prototype.init.call(this);
377 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
385 pack : "pack_start,true,true",
387 XObject.prototype.init.call(this);
388 this.el.set_current_page(0);
393 xtype: Gtk.ScrolledWindow,
396 getActiveElement : function() { // return path to actie node.
398 var path = this.getActivePath();
402 var iter = new Gtk.TreeIter();
403 this.get('model').el.get_iter_from_string(iter, path);
405 var value = new GObject.Value('');
406 this.get('model').el.get_value(iter, 2, value);
408 return JSON.parse(value.value);
410 getActiveFile : function() {
411 return this.get('model').file;
413 getActivePath : function() {
414 var model = this.get('model');
415 var view = this.get('view');
416 if (view.selection.count_selected_rows() < 1) {
419 var iter = new Gtk.TreeIter();
421 view.selection.get_selected(model.el, iter);
422 return model.el.get_path(iter).to_string();
424 getPaleteProvider : function() {
425 var model = this.get('model');
426 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
427 return pm.getPalete(model.file.getType());
429 getRenderer : function() {
431 switch( this.getActiveFile().getType()) {
433 return this.get('/RightBrowser.view');
435 return this.get('/RightGtkView');
440 XObject.prototype.init.call(this);
441 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
443 renderView : function() {
444 var render = this.getRenderer();
445 var model = this.get('model');
447 render.renderJS(model.toJS(false,true)[0]);
449 print("NO RENDER JS METHOD?");
452 shadow_type : Gtk.ShadowType.IN,
457 button_press_event : function (self, ev) {
458 console.log("button press?");
459 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
460 print("click" + ev.type);
466 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
468 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
470 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
471 this.get('/LeftTreeMenu').el.show_all();
472 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
473 print("click:" + res.path.to_string());
476 drag_begin : function (self, drag_context) {
477 print('SOURCE: drag-begin');
478 this.targetData = false;
479 // find what is selected in our tree...
480 var iter = new Gtk.TreeIter();
481 var s = this.selection;
482 s.get_selected(this.get('/LeftTree.model').el, iter);
484 // set some properties of the tree for use by the dropped element.
485 var value = new GObject.Value('');
486 this.get('/LeftTree.model').el.get_value(iter, 2, value);
487 var data = JSON.parse(value.value);
488 var xname = this.get('/LeftTree.model').file.guessName(data);
490 this.el.dragData = xname;
491 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
494 // make the drag icon a picture of the node that was selected
495 var path = this.get('/LeftTree.model').el.get_path(iter);
496 this.el.treepath = path.to_string();
498 var pix = this.el.create_row_drag_icon ( path);
500 Gtk.drag_set_icon_pixmap (ctx,
509 drag_end : function (self, drag_context) {
510 Seed.print('LEFT-TREE: drag-end');
511 this.el.dragData = false;
512 this.el.dropList = false;
513 this.targetData = false;
514 this.get('/LeftTree.view').highlight(false);
517 drag_motion : function (self, ctx, x, y, time) {
518 console.log("LEFT-TREE: drag-motion");
519 var src = Gtk.drag_get_source_widget(ctx);
521 // a drag from elsewhere...- prevent drop..
523 print("no drag data!");
524 Gdk.drag_status(ctx, 0, time);
525 this.targetData = false;
528 var action = Gdk.DragAction.COPY;
529 if (src == this.el) {
530 // unless we are copying!!! ctl button..
531 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
535 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
536 // no children.. -- asume it's ok..
537 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
538 Gdk.drag_status(ctx, action ,time);
542 print("GETTING POS");
543 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
544 print("ISOVER? " + isOver);
546 Gdk.drag_status(ctx, 0 ,time);
547 return false; // not over apoint!?!
549 // drag node is parent of child..
550 console.log("SRC TREEPATH: " + src.treepath);
551 console.log("TARGET TREEPATH: " + data.path.to_string());
553 // nned to check a few here..
554 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
555 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
556 //Gtk.TreeViewDropPosition.AFTER
557 //Gtk.TreeViewDropPosition.BEFORE
559 if (typeof(src.treepath) != 'undefined' &&
560 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
561 print("subpath drag");
562 Gdk.drag_status(ctx, 0 ,time);
567 //print("DUMPING DATA");
568 //console.dump(data);
571 print(data.path.to_string() +' => '+ data.pos);
572 var tg = this.get('/LeftTree.model').findDropNodeByPath(
573 data.path.to_string(), src.dropList, data.pos);
575 this.get('/LeftTree.view').highlight(tg);
577 print("Can not find drop node path");
578 this.targetData = false;
579 Gdk.drag_status(ctx, 0, time);
583 this.targetData = tg;
586 Gdk.drag_status(ctx, action ,time);
590 drag_drop : function (w, ctx, x, y, time) {
591 Seed.print("TARGET: drag-drop");
595 w, /* will receive 'drag-data-received' signal */
596 ctx, /* represents the current state of the DnD */
597 this.get('/Window').atoms["STRING"], /* the target type we want */
598 time /* time stamp */
602 /* No target offered by source => error */
607 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
608 print("Tree: drag-data-received");
610 var delete_selection_data = false;
611 var dnd_success = false;
612 /* Deal with what we are given from source */
613 if( sel_data && sel_data.length ) {
615 if (ctx.action == Gdk.DragAction.ASK) {
616 /* Ask the user to move or copy, then set the ctx action. */
619 if (ctx.action == Gdk.DragAction.MOVE) {
620 //delete_selection_data = true;
623 var source = Gtk.drag_get_source_widget(ctx);
625 if (this.targetData) {
626 if (source != this.el) {
627 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
629 // drag around.. - reorder..
630 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
634 //Seed.print(this.targetData);
640 // we can send stuff to souce here...
646 if (dnd_success == false)
648 Seed.print ("DnD data transfer failed!\n");
651 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
654 cursor_changed : function (self) {
655 if (this.blockChanges) { // probably not needed..
658 var render = this.get('/LeftTree').getRenderer();
661 if (this.selection.count_selected_rows() < 1) {
662 this.get('/LeftPanel.model').load( false);
663 this.get('/MidPropTree').activeElement = false;
664 this.get('/MidPropTree').hideWin();
666 var pm = this.get('/RightPalete.model');
667 if (!this.get('/LeftTree').getPaleteProvider()) {
668 // it may not be loaded yet..
671 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
672 this.get('/LeftTree.model').listAllTypes()));
673 if (render && render.redraw) {
679 //console.log('changed');
680 var s = this.selection;
681 var iter = new Gtk.TreeIter();
682 s.get_selected(this.get('/LeftTree.model').el, iter);
686 var value = new GObject.Value('');
687 this.get('/LeftTree.model').el.get_value(iter, 2, value);
688 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
690 var data = JSON.parse(value.value);
691 this.get('/MidPropTree').activeElement = data;
692 this.get('/MidPropTree').hideWin();
693 this.get('/LeftPanel.model').load( data);
695 console.log(value.value);
696 // _g.button.set_label(''+value.get_string());
698 var pm =this.get('/RightPalete.model');
699 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
700 this.get('/LeftTree.model').listAllTypes()));
703 if (render && render.redraw) {
707 //Seed.print( value.get_string());
715 enable_tree_lines : true,
716 headers_visible : false,
717 highlight : function(treepath_ar) {
719 // highlighting for drag/drop
720 if (treepath_ar.length && treepath_ar[0].length ) {
721 this.el.set_drag_dest_row(
722 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
724 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
729 XObject.prototype.init.call(this);
730 var description = new Pango.FontDescription.c_new();
731 description.set_size(8000);
732 this.el.modify_font(description);
734 this.selection = this.el.get_selection();
735 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
738 // is this really needed??
739 this.selection.signal['changed'].connect(function() {
740 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
741 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
745 Gtk.drag_source_set (
746 this.el, /* widget will be drag-able */
747 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
748 null, /* lists of target to support */
749 0, /* size of list */
750 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
753 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
755 Gtk.drag_source_add_text_targets(this.el);
758 this.el, /* widget that will accept a drop */
759 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
760 null, /* lists of target to support */
761 0, /* size of list */
762 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
765 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
766 Gtk.drag_dest_add_text_targets(this.el);
768 selectNode : function(treepath_str) {
769 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
770 var tp = new Gtk.TreePath.from_string(treepath_str);
771 this.el.set_cursor(tp, null, false);
772 this.el.scroll_to_cell(tp, null, false, 0,0);
776 xtype: Gtk.TreeStore,
781 changed : function(n, refresh) {
782 print("MODEL CHANGED CALLED" + this.activePath);
783 if (this.activePath) {
784 var iter = new Gtk.TreeIter();
785 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
786 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
787 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
789 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
791 //this.currentTree = this.toJS(false, true)[0];
792 this.file.items = this.toJS(false, false);
793 print("AFTER CHANGED");
794 //console.dump(this.file.items);
796 this.currentTree = this.file.items[0];
797 //console.log(this.file.toSource());
800 print("REDNER BROWSER?!");
801 this.get('/LeftTree').renderView();
803 var pm = this.get('/RightPalete.model');
804 if (!this.get('/RightPalete').provider) {
810 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
811 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
815 deleteSelected : function() {
816 this.get('/LeftTree.view').blockChanges = true;
817 var old_iter = new Gtk.TreeIter();
818 var s = this.get('/LeftTree.view').selection;
819 s.get_selected(this.el, old_iter);
820 var path = this.el.get_path(old_iter).to_string();
822 this.activePath= false;
825 this.activePath= false;
826 var iter = new Gtk.TreeIter();
827 this.el.get_iter_from_string(iter, path);
828 this.el.remove(iter);
830 // rebuild treemap. -- depreciated.!!
833 //this.toJS(null, true) // does not do anything?
834 this.activePath= false;
835 this.changed(false,true);
836 this.get('/LeftTree.view').blockChanges = false;
838 dropNode : function(target_data, node) {
840 // console.dump(node);
841 // console.dump(target_data);
842 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
844 print("add " + tp + "@" + target_data[1] );
847 if (tp && target_data[1] < 2) { // before or after..
848 var ar = target_data[0].split(':');
850 parent = new Gtk.TreePath.from_string( ar.join(':') );
853 var n_iter = new Gtk.TreeIter();
854 var iter_par = new Gtk.TreeIter();
855 var iter_after = after ? new Gtk.TreeIter() : false;
859 if (parent !== false) {
860 this.el.get_iter(iter_par, parent);
867 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
868 this.el.get_iter(iter_after, after);
869 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
870 n_iter, iter_par, iter_after);
873 this.el.append(n_iter, iter_par);
877 if (typeof(node) == 'string') {
878 var ar = node.split('.');
879 var xtype = ar.pop();
882 '|xns' : ar.join('.'),
885 if (target_data.length == 3 && target_data[2].length) {
886 node['*prop'] = target_data[2];
888 node = this.get('/DialogTemplateSelect').show(node);
891 // work out what kind of packing to use..
892 if (typeof(node.pack) == 'undefined' && parent !== false) {
893 var pal = this.get('/LeftTree').getPaleteProvider();
894 if (pal.name == 'Gtk') {
895 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
896 var cname = pal.guessName(node);
897 node.pack = pal.getDefaultPack(pname, cname);
908 // load children - if it has any..
911 this.load(xitems, n_iter);
912 this.get('/LeftTree.view').el.expand_row(this.el.get_path(n_iter), true);
914 if (tp && (xitems || after)) {
915 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
917 // wee need to get the empty proptypes from somewhere..
919 //var olditer = this.activeIter;
920 this.activePath = this.el.get_path(n_iter).to_string();
922 // changed actually set's the node data..
923 this.changed(node, true);
927 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
929 //Builder.MidPropTree._model.load(node);
930 //Builder.MidPropTree._win.hideWin();
931 //Builder.LeftPanel._model.load( node);
935 findDropNode : function(treepath_str, targets) {
937 // this is used by the dragdrop code in the roo version AFAIR..
939 var path = treepath_str.replace(/^builder-/, '');
940 // treemap is depreciated... - should really check if model has any entries..
942 if (!this.el.iter_n_children(null)) {
944 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
946 print("FIND treepath: " + path);
947 //console.dump(this.treemap);
949 if (!treepath_str.match(/^builder-/)) {
950 return []; // nothing!
952 if (targets === true) {
955 return this.findDropNodeByPath(path,targets)
957 findDropNodeByPath : function(treepath_str, targets, pref) {
958 var path = treepath_str + ''; // dupe it..
959 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
961 //console.dump(this.treemap);
962 while (path.length) {
963 print("LOOKING FOR PATH: " + path);
964 var node_data = this.singleNodeToJS(path);
965 if (node_data === false) {
966 print("node not found");
970 var xname = this.get('/LeftTree.model').file.guessName(node_data);
973 targets.forEach(function(tg) {
977 if ((tg == xname) ) {
980 if (tg.indexOf(xname +':') === 0) {
982 prop = tg.split(':').pop();
987 if (last) { // pref is after/before..
988 // then it's after last
990 return []; // do not allow..
992 return [ last, pref , prop];
995 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
997 var par = path.split(':');
1000 path = par.join(':');
1006 getIterValue : function (iter, col) {
1007 var gval = new GObject.Value('');
1008 this.el.get_value(iter, col ,gval);
1014 XObject.prototype.init.call(this);
1015 this.el.set_column_types ( 3, [
1016 GObject.TYPE_STRING, // title
1017 GObject.TYPE_STRING, // tip
1018 GObject.TYPE_STRING // source..
1021 listAllTypes : function() {
1022 var s = this.get('/LeftTree.view').selection;
1023 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1025 if (s.count_selected_rows() > 0) {
1026 var iter = new Gtk.TreeIter();
1027 s.get_selected(this.el, iter);
1029 // set some properties of the tree for use by the dropped element.
1030 var value = new GObject.Value('');
1031 this.el.get_value(iter, 2, value);
1032 var data = JSON.parse(value.value);
1035 var xname = this.get('/LeftTree.model').file.guessName(data);
1036 console.log('selected:' + xname);
1040 return []; // could not find it..
1048 li.forEach(function(el) {
1049 // this is specific to roo!!!?
1050 if (!el) { // skip empty?
1053 var fullpath = _this.file.guessName(el);
1054 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1059 if (el.items && el.items.length) {
1068 addall([this.currentTree]);
1070 // only if we have nothing, should we add '*top'
1074 //console.log('all types in tree');
1075 //console.dump(ret);
1080 load : function(tr,iter)
1082 var citer = new Gtk.TreeIter();
1083 //this.insert(citer,iter,0);
1084 for(var i =0 ; i < tr.length; i++) {
1086 this.el.insert(citer,iter,-1);
1088 this.el.append(citer);
1091 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1092 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1093 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1094 if (tr[i].items && tr[i].items.length) {
1095 this.load(tr[i].items, citer);
1099 loadFile : function(f) {
1105 console.log('missing file');
1109 // load the file if not loaded..
1110 if (f.items === false) {
1112 f.loadItems(function() {
1118 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
1120 if (f.items.length && typeof(f.items[0]) == 'string') {
1122 this.get('/RightEditor').el.show();
1123 this.get('/RightEditor.view').load( f.items[0]);
1127 print(JSON.stringify(f.items, null,4));
1128 //console.dump(f.items);
1130 this.get('/LeftTree.view').el.expand_all();
1132 if (!f.items.length) {
1135 this.get('/Window.leftvpaned').el.set_position(80);
1137 this.get('/LeftTree.view').el.set_cursor(
1138 new Gtk.TreePath.from_string('0'), null, false);
1142 this.get('/Window.leftvpaned').el.set_position(200);
1146 //print("hide right editior");
1147 this.get('/RightEditor').el.hide();
1148 //print("set current tree");
1149 this.currentTree = this.toJS(false, false)[0];
1150 //console.dump(this.currentTree);
1151 this.currentTree = this.currentTree || { items: [] };
1152 this.get('/LeftTree').renderView();
1153 //console.dump(this.map);
1154 //var RightPalete = imports.Builder.RightPalete.RightPalete;
1155 var pm = this.get('/RightPalete.model');
1156 // set up provider..
1158 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
1160 if (!this.get('/RightPalete').provider) {
1161 print ("********* PALETE PROVIDER MISSING?!!");
1163 this.get('/LeftTree').renderView();
1165 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
1169 this.get('/Window.view-notebook').el.set_current_page(
1170 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
1173 moveNode : function(target_data, action) {
1174 //print("MOVE NODE");
1175 // console.dump(target_data);
1176 var old_iter = new Gtk.TreeIter();
1177 var s = this.get('/LeftTree.view').selection;
1178 s.get_selected(this.el, old_iter);
1179 var node = this.nodeToJS(old_iter,false);
1180 //console.dump(node);
1183 // needs to drop first, otherwise the target_data
1184 // treepath will be invalid.
1186 this.dropNode(target_data, node);
1187 if (action & Gdk.DragAction.MOVE) {
1188 // print("REMOVING OLD NODE");
1189 this.el.remove(old_iter);
1193 this.activePath= false;
1194 this.changed(false,true);
1196 nodeTip : function(c) {
1197 var ret = this.nodeTitle(c,true);
1203 if (!i.length || i[0] != '|') {
1209 if (typeof(c[i]) != 'string') {
1212 //print("prop : " + i + ':' + c[i]);
1213 if (!c[i].match(new RegExp('function'))) {
1216 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1220 ret+="\n\nMethods:" + funcs;
1225 nodeTitle : function(c, renderfull) {
1228 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1229 if (sr) txt.push('<s>');
1230 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1232 if (renderfull && c['|xns']) {
1233 txt.push(c['|xns']);
1236 if (c.xtype) { txt.push(c.xtype); }
1237 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1238 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1239 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1242 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1243 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1244 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1245 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1246 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1247 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1248 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1249 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1250 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1252 // for flat classes...
1253 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1254 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1257 if (sr) txt.push('</s>');
1258 return (txt.length == 0 ? "Element" : txt.join(" "));
1260 nodeToJS : function (treepath, with_id)
1263 var iter = treepath; // API used to be iter here..
1264 if (typeof(iter) == 'string') {
1265 iter = new Gtk.TreeIter();
1266 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1270 var par = new Gtk.TreeIter();
1271 var iv = this.getIterValue(iter, 2);
1272 // print("IV" + iv);
1273 var k = JSON.parse(iv);
1274 if (k.json && !this.el.iter_parent( par, iter )) {
1279 var treepath_str = this.el.get_path(iter).to_string();
1280 // not sure how we can handle mixed id stuff..
1281 if (typeof(k.id) == 'undefined') {
1282 k.id = 'builder-'+ treepath_str ;
1286 this.treemap[ treepath_str ] = k;
1287 k.xtreepath = treepath_str ;
1290 if (this.el.iter_has_child(iter)) {
1291 citer = new Gtk.TreeIter();
1292 this.el.iter_children(citer, iter);
1293 k.items = this.toJS(citer,with_id);
1297 nodeToJSON : function(c) {
1305 return JSON.stringify(o);
1307 singleNodeToJS : function (treepath)
1309 var iter = new Gtk.TreeIter();
1310 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1314 var iv = this.getIterValue(iter, 2);
1316 return JSON.parse(iv);
1319 toJS : function(treepath, with_id)
1321 //Seed.print("WITHID: "+ with_id);
1322 var iter = treepath; // API used to be iter here..
1323 if (typeof(iter) == 'string') {
1324 iter = new Gtk.TreeIter();
1325 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1334 iter = new Gtk.TreeIter();
1335 if (!this.el.get_iter_first(iter)) {
1345 var k = this.nodeToJS(iter, with_id);
1349 if (!this.el.iter_next(iter)) {
1354 if (treepath === false) {
1356 return JSON.parse(JSON.stringify(ar));
1360 // convert the list into a json string..
1366 xtype: Gtk.TreeViewColumn,
1367 pack : "append_column",
1369 XObject.prototype.init.call(this);
1370 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1374 xtype: Gtk.CellRendererText,
1384 id : "LeftTreeMenu",
1387 xtype: Gtk.MenuItem,
1389 label : "Delete Element",
1391 activate : function (self) {
1393 this.get('/LeftTree.model').deleteSelected();
1398 xtype: Gtk.MenuItem,
1400 activate : function (self) {
1402 var tree = this.get('/LeftTree');
1403 var model = this.get('/LeftTree.model');
1404 var el = tree.getActivePath();
1406 var js = model.toJS(el, false);
1407 // print(JSON.stringify(js[0], null,4));
1408 this.get('/DialogSaveTemplate').show(JSON.stringify(js[0], null,4));
1413 label : "Save as Template",
1423 id : "LeftProjectTree",
1424 showNoProjectSelected : function() {
1425 this.get('/StandardErrorDialog').show("Select a Project first.");
1427 getActiveProject : function() {
1428 return this.project;
1431 leave_notify_event : function (self, event) {
1438 pack : "pack_start,false,false",
1441 xtype: Gtk.ComboBox,
1444 XObject.prototype.init.call(this);
1445 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1447 getValue : function() {
1448 var ix = this.el.get_active();
1452 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1453 if (typeof(data[ix]) == 'undefined') {
1458 setValue : function(fn)
1462 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1463 data.forEach(function(n, ix) {
1471 changed : function (self) {
1472 var fn = this.getValue();
1473 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1474 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1479 xtype: Gtk.CellRendererText,
1480 pack : "pack_start,true",
1484 xtype: Gtk.ListStore,
1487 XObject.prototype.init.call(this);
1488 this.el.set_column_types ( 2, [
1489 GObject.TYPE_STRING, // real key
1490 GObject.TYPE_STRING // real type
1494 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1496 pm.on('changed', function() {
1497 print("caught changed hook on project manager - reloading data");
1498 _this.loadData(pm.projects);
1502 loadData : function(data) {
1503 var ov = this.get('/LeftProjectTree.combo').getValue();
1505 var iter = new Gtk.TreeIter();
1507 data.forEach(function(p) {
1512 el.set_value(iter, 0, p.fn);
1513 el.set_value(iter, 1, p.name);
1517 this.get('/LeftProjectTree.combo').setValue(ov);
1526 xtype: Gtk.ScrolledWindow,
1528 shadow_type : Gtk.ShadowType.IN,
1530 XObject.prototype.init.call(this);
1531 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1535 xtype: Gtk.TreeView,
1537 cursor_changed : function (self) {
1538 var iter = new Gtk.TreeIter();
1540 if (this.selection.count_selected_rows() < 1) {
1541 //XN.get('Builder.LeftTree.model').
1542 this.get('/LeftTree.model').load( false);
1546 var model = this.get('/LeftProjectTree.model');
1547 //console.log('changed');
1548 var s = this.selection;
1549 s.get_selected(model, iter);
1550 value = new GObject.Value('');
1551 model.el.get_value(iter, 2, value);
1553 console.log(value.value);// id..
1555 var file = this.get('/LeftProjectTree').project.getById(value.value);
1562 var nb = this.get('/LeftTopPanel.expander');
1563 nb.el.expanded = false;
1564 nb.listeners.activate.call(nb);
1565 //_expander.el.set_expanded(false);
1567 var ltm = this.get('/LeftTree.model');
1575 enable_tree_lines : true,
1576 headers_visible : false,
1578 XObject.prototype.init.call(this);
1579 var description = new Pango.FontDescription.c_new();
1580 description.set_size(8000);
1581 this.el.modify_font(description);
1583 this.selection = this.el.get_selection();
1584 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1588 xtype: Gtk.TreeStore,
1592 XObject.prototype.init.call(this);
1593 this.el.set_column_types ( 3, [
1594 GObject.TYPE_STRING, // title
1595 GObject.TYPE_STRING, // tip
1596 GObject.TYPE_STRING // id..
1600 loadProject : function(pr) {
1601 print("LOAD PROJECT");
1607 this.get('/LeftProjectTree').project = pr;
1608 this.load(pr.toTree());
1609 this.get('/LeftProjectTree.view').el.expand_all();
1611 load : function(tr,iter) {
1612 // console.dump(tr);
1613 console.log('Project tree load: ' + tr.length);
1614 var citer = new Gtk.TreeIter();
1615 //this.insert(citer,iter,0);
1618 tr.forEach(function (r) {
1620 _this.el.append(citer);
1622 _this.el.insert(citer,iter,-1);
1624 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1625 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1626 _this.el.set_value(citer, 2, '' + r.id ); //id
1627 if (r.cn && r.cn.length) {
1628 _this.load(r.cn, citer);
1633 getValue : function(iter, col) {
1634 var gval = new GObject.Value('');
1635 this.el.get_value(iter, col ,gval);
1636 return '' + gval.value;
1640 xtype: Gtk.TreeViewColumn,
1641 pack : "append_column",
1643 XObject.prototype.init.call(this);
1644 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1648 xtype: Gtk.CellRendererText,
1668 pack : "pack_start,false,true,0",
1675 button_press_event : function (self, event) {
1676 this.get('/MidPropTree.model').showData('props');
1688 stock : Gtk.STOCK_ADD,
1689 icon_size : Gtk.IconSize.MENU
1704 button_press_event : function (self, event) {
1705 this.get('/MidPropTree.model').showData('events');
1717 stock : Gtk.STOCK_ADD,
1718 icon_size : Gtk.IconSize.MENU
1733 button_press_event : function (self, ev) {
1734 var p = this.get('/AddPropertyPopup');
1738 p.el.set_screen(Gdk.Screen.get_default());
1740 p.el.popup(null, null, null, null, 3, ev.button.time);
1752 stock : Gtk.STOCK_ADD,
1753 icon_size : Gtk.IconSize.MENU
1765 id : "AddPropertyPopup",
1768 xtype: Gtk.MenuItem,
1770 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1773 activate : function (self) {
1775 this.get('/LeftPanel.model').add( {
1786 xtype: Gtk.MenuItem,
1788 tooltip_markup : "Add what type of packing is to be used",
1791 activate : function (self) {
1793 this.get('/LeftPanel.model').add( {
1803 xtype: Gtk.MenuItem,
1805 tooltip_markup : "Override the init method",
1808 activate : function (self) {
1810 this.get('/LeftPanel.model').add( {
1813 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1820 xtype: Gtk.SeparatorMenuItem,
1824 xtype: Gtk.MenuItem,
1826 tooltip_markup : "Add a user defined string property",
1829 activate : function (self) {
1831 this.get('/LeftPanel.model').add( {
1841 xtype: Gtk.MenuItem,
1843 tooltip_markup : "Add a user defined number property",
1846 activate : function (self) {
1848 this.get('/LeftPanel.model').add( {
1858 xtype: Gtk.MenuItem,
1860 tooltip_markup : "Add a user defined boolean property",
1863 activate : function (self) {
1865 this.get('/LeftPanel.model').add( {
1875 xtype: Gtk.SeparatorMenuItem,
1879 xtype: Gtk.MenuItem,
1881 tooltip_markup : "Add a user function boolean property",
1884 activate : function (self) {
1886 this.get('/LeftPanel.model').add( {
1889 val : "function() {\n \n}\n",
1902 xtype: Gtk.ScrolledWindow,
1905 shadow_type : Gtk.ShadowType.IN,
1908 XObject.prototype.init.call(this);
1909 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1913 xtype: Gtk.TreeView,
1916 headers_visible : false,
1917 enable_tree_lines : true,
1919 XObject.prototype.init.call(this);
1921 this.selection = this.el.get_selection();
1922 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1925 var description = new Pango.FontDescription.c_new();
1926 description.set_size(8000);
1927 this.el.modify_font(description);
1930 button_press_event : function (self, ev) {
1934 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1935 return false; //not on a element.
1939 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1941 if (res.column.title != 'value') {
1942 return false; // ignore..
1944 if ( this.get('/LeftPanel').editing) {
1947 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1948 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1949 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1953 var provider = this.get('/LeftTree').getPaleteProvider();
1955 var opts = provider.findOptions(type);
1957 if (opts === false) {
1958 this.get('/LeftPanel').editableColumn.setOptions([]);
1959 renderer.has_entry = true;
1961 LeftPanel.editableColumn.setOptions(opts);
1962 renderer.has_entry = false;
1966 //Seed.print("click" + ev.type);
1967 //console.dump(res);
1973 if (res.column.title == 'value') {
1976 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1977 var p = this.get('/LeftPanelPopup');
1982 p.el.set_screen(Gdk.Screen.get_default());
1984 p.el.popup(null, null, null, null, 3, ev.button.time);
1985 //Seed.print("click:" + res.column.title);
1993 xtype: Gtk.TreeStore,
1997 add : function(info) {
1998 // info includes key, val, skel, etype..
2000 type = info.type.toLowerCase();
2001 var data = this.toJS();
2003 if (info.etype == 'events') {
2004 data.listeners = data.listeners || { };
2005 if (typeof(data.listeners[info.key]) != 'undefined') {
2006 return; //already set!
2009 if (typeof(data[info.key]) != 'undefined') {
2014 if (typeof(info.val) == 'undefined') {
2017 if (info.type.toLowerCase() == 'boolean') {
2020 if (type == 'number') {
2028 if (info.etype == 'events') {
2030 data.listeners[info.key] = info.val;
2033 data[info.key] = info.val;
2037 var map = this.load(data);
2039 // flag it as changed to the interface..
2041 this.get('/LeftTree.model').changed(data, true);
2044 this.startEditing(map[k]);
2047 LeftPanel.get('view').el.row_activated(
2048 new Gtk.TreePath.from_string(map[k]),
2049 LeftPanel.editableColumn.el
2053 changed : function(str, doRefresh) {
2054 if (!this.activePath) {
2057 var iter = new Gtk.TreeIter();
2058 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
2060 this.el.set_value(iter, 1, '' +str);
2061 this.el.set_value(iter, 3, '' + this.toShort(str));
2062 var type = this.getIterValue(iter, 4);
2064 this.el.set_value(iter, 5, type + ' : ' + str);
2065 // update the tree...
2067 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
2069 deleteSelected : function() {
2070 var data = this.toJS();
2071 var iter = new Gtk.TreeIter();
2072 var s = this.get('/LeftPanel.view').selection;
2073 s.get_selected(this.el, iter);
2076 var gval = new GObject.Value('');
2077 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
2079 var val = gval.value;
2080 if (val[0] == '!') {
2082 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
2085 delete data.listeners[ val.substring(1)];
2086 if (!XObject.keys(data.listeners).length) {
2087 delete data.listeners;
2091 if (typeof(data[val]) == 'undefined') {
2099 this.get('/LeftTree.model').changed(data, true);
2102 editSelected : function(e) {
2103 print("EDIT SELECTED?");
2104 var iter = new Gtk.TreeIter();
2105 var s = this.get('/LeftPanel.view').selection;
2106 s.get_selected(this.get('/LeftPanel.model').el, iter);
2107 var m = this.get('/LeftPanel.model')
2109 var gval = new GObject.Value('');
2110 this.el.get_value(iter, 0 ,gval);
2111 var val = '' + gval.value;
2113 gval = new GObject.Value('');
2114 this.el.get_value(iter, 1 ,gval);
2115 var rval = gval.value;
2116 var activePath = this.el.get_path(iter).to_string();
2117 this.activePath = activePath ;
2118 // was activeIter...
2121 var showEditor = false;
2123 if (val[0] == '!') {
2126 if (val[0] == '|') {
2127 if (rval.match(/function/g) || rval.match(/\n/g) || rval.length > 20) {
2134 this.activePath = false;
2135 GLib.timeout_add(0, 1, function() {
2136 // Gdk.threads_enter();
2137 _this.get('/BottomPane').el.show();
2138 _this.get('/RightEditor').el.show();
2139 _this.get('/RightEditor.view').load( rval );
2143 _this.activePath = activePath ;
2145 // Gdk.threads_leave();
2150 this.get('/BottomPane').el.hide();
2151 this.get('/RightEditor').el.hide();
2153 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2157 getIterValue : function(iter, col) {
2158 var gval = new GObject.Value('');
2159 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2160 return '' + gval.value;
2162 getType : function(treepath) {
2163 return this.getValue(treepath, 4);
2165 getValue : function(treepath_str, col) {
2166 var iter = new Gtk.TreeIter();
2167 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2169 var gval = new GObject.Value('');
2170 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2171 var val = '' + gval.value;
2175 var type = this.getType(this.el.get_path(iter).to_string());
2176 print("TYPE: " +type + " - val:" + val);
2177 switch(type.toLowerCase()) {
2181 return parseFloat(val); // Nan ?? invalid!!?
2184 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2186 return val == 'true' ? true : false;
2188 var nv = parseFloat(val);
2189 if (!isNaN(nv) && (val == ''+nv)) {
2197 XObject.prototype.init.call(this);
2198 this.el.set_column_types ( 6, [
2199 GObject.TYPE_STRING, // 0 real key
2200 GObject.TYPE_STRING, // 1 real value
2201 GObject.TYPE_STRING, // 2 visable key
2202 GObject.TYPE_STRING, // 3 visable value
2203 GObject.TYPE_STRING, // 4 need to store type of!!!
2204 GObject.TYPE_STRING // 5 tooltip
2208 load : function(ar) {
2211 this.get('/RightEditor').el.hide();
2218 var provider = this.get('/LeftTree').getPaleteProvider();
2219 var iter = new Gtk.TreeIter();
2222 var keys = XObject.keys(ar);
2224 ar.listeners = ar.listeners || {};
2226 for (var i in ar.listeners ) {
2227 this.el.append(iter);
2228 var p = this.el.get_path(iter).to_string();
2231 this.el.set_value(iter, 0, '!'+ i );
2232 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2233 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2235 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2236 this.el.set_value(iter, 4, 'function');
2237 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2243 keys.forEach(function(i) {
2244 if (typeof(ar[i]) == 'object') {
2248 var type = provider.findType(ar, i, ar[i]);
2250 _this.el.append(iter);
2251 var p = _this.el.get_path(iter).to_string();
2253 _this.el.set_value(iter, 0, ''+i);
2254 _this.el.set_value(iter, 1, '' + ar[i]);
2255 _this.el.set_value(iter, 2, ''+i);
2256 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2257 _this.el.set_value(iter, 4, ''+type);
2258 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2262 startEditing : function(path,col) {
2264 * start editing path (or selected if not set..)
2265 * @param {String|false} path (optional) treepath to edit - selected tree gets
2266 * edited by default.
2267 * @param {Number} 0 or 1 (optional)- column to edit.
2270 if (typeof(path) == 'string') {
2271 tp = new Gtk.TreePath.from_string(path);
2273 var iter = new Gtk.TreeIter();
2274 var s = this.get('/LeftPanel.view').selection;
2275 s.get_selected(this.el, iter);
2276 tp = this.el.get_path(iter);
2277 path = tp.to_string();
2281 // which colum is to be edited..
2283 if (typeof(col) == 'undefined') {
2284 var k = this.getValue(path, 0);
2285 colObj = (!k.length || k == '|') ?
2286 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2288 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2291 // make sure the pulldown is set correctly..
2292 // not really needed for second col...
2294 var provider = this.get('/LeftTree').getPaleteProvider();
2296 var type = this.get('/LeftPanel.model').getType(path);
2297 var opts = provider.findOptions(type);
2298 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2300 if (opts === false) {
2301 this.get('/LeftPanel').editableColumn.setOptions([]);
2302 renderer.has_entry = true; /// probably does not have any effect.
2304 this.get('/LeftPanel').editableColumn.setOptions(opts);
2305 renderer.has_entry = false;
2309 // iter now has row...
2310 GLib.timeout_add(0, 100, function() {
2312 colObj.items[0].el.editable = true; // esp. need for col 0..
2313 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2323 var iter = new Gtk.TreeIter();
2324 this.get('/LeftPanel.model').el.get_iter_first(iter);
2329 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2332 ar.listeners = ar.listeners || {};
2333 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2336 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2339 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2345 //print(JSON.stringify(ar));
2349 toShort : function(str) {
2350 var a = typeof(str) == 'string' ? str.split("\n") : [];
2351 return a.length > 1 ? a[0] + '....' : '' + str;
2355 xtype: Gtk.TreeViewColumn,
2356 pack : "append_column",
2358 XObject.prototype.init.call(this);
2360 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2361 this.get('/LeftPanel').propertyColumn = this;
2366 xtype: Gtk.CellRendererText,
2367 pack : "pack_start",
2369 editing_started : function (self, editable, path) {
2371 this.get('/LeftPanel.model').activePath = path;
2374 edited : function (self, object, p0) {
2375 var model = this.get('/LeftPanel.model');
2376 var path = model.activePath;
2377 var iter = new Gtk.TreeIter();
2378 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2379 model.el.set_value(iter, 0, p0);
2380 model.el.set_value(iter, 2, p0);
2382 model.activePath = false;
2384 this.get('/LeftTree.model').changed(model.toJS(), true);
2385 this.el.editable = false;
2392 xtype: Gtk.TreeViewColumn,
2393 pack : "append_column",
2395 XObject.prototype.init.call(this);
2396 this.el.add_attribute(this.items[0].el , 'text', 3 );
2397 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2398 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2399 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2401 this.get('/LeftPanel').editableColumn= this;
2403 setOptions : function(ar) {
2404 var m = this.items[0].el.model;
2406 var iter = new Gtk.TreeIter();
2407 ar.forEach(function(i) {
2410 m.set_value(iter, 0, i);
2416 xtype: Gtk.CellRendererCombo,
2417 pack : "pack_start",
2422 XObject.prototype.init.call(this);
2423 this.el.model = new Gtk.ListStore();
2424 this.el.model.set_column_types ( 1, [
2425 GObject.TYPE_STRING // 0 real key
2429 edited : function (self, object, p0) {
2430 this.get('/LeftPanel').editing = false;
2431 print("EDITED? p:" + p0 + " t:" + p0);
2432 this.get('/LeftPanel.model').changed(p0, true);
2433 this.get('/LeftPanel.model').activePath = false;
2435 editing_started : function (self, editable, path) {
2436 this.get('/LeftPanel').editing = true;
2437 // console.log('editing started');
2438 // r.has_entry = false;
2439 this.get('/LeftPanel.model').editSelected(editable);
2450 id : "LeftPanelPopup",
2453 xtype: Gtk.MenuItem,
2457 activate : function (self) {
2458 this.get('/LeftPanel.model').deleteSelected();
2463 xtype: Gtk.MenuItem,
2467 activate : function (self) {
2468 this.get('/LeftPanel.model').startEditing(false, 0);
2481 xtype: Gtk.ScrolledWindow,
2482 pack : "pack_end,false,true,0",
2484 shadow_type : Gtk.ShadowType.IN,
2486 XObject.prototype.init.call(this);
2487 XObject.prototype.init.call(this);
2488 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2489 this.el.set_size_request ( 150, -1 );
2492 activeElement : false,
2493 hideWin : function() {
2500 if (this.get('/Window.left').el.position < 160) {
2503 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2510 xtype: Gtk.TreeView,
2512 cursor_changed : function (self) {
2513 var iter = new Gtk.TreeIter();
2515 //console.log('changed');
2516 var m = this.get('model');
2517 if (!this.selection){
2518 this.selection = this.el.get_selection();
2521 var s = this.selection;
2522 if (!s.get_selected(m.el, iter)) {
2525 var tp = m.el.get_path(iter).to_string();
2530 var key = m.getValue(tp, 0);
2532 var type = m.getValue(tp, 1);
2533 var skel = m.getValue(tp, 3);
2534 var etype = m.getValue(tp, 5);
2537 this.get('/MidPropTree').hideWin();
2539 if (type.toLowerCase() == 'function') {
2541 if (etype != 'events') {
2545 this.get('/LeftPanel.model').add({
2553 // has dot in name, and is boolean???? this does not make sense..
2554 //if (type.indexOf('.') > -1 || type.toLowerCase() == 'boolean') {
2558 this.get('/LeftPanel.model').add( {
2568 enable_tree_lines : true,
2569 headers_visible : false,
2571 XObject.prototype.init.call(this);
2573 var description = new Pango.FontDescription.c_new();
2574 description.set_size(8000);
2575 this.el.modify_font(description);
2577 //this.selection = this.el.get_selection();
2578 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2587 xtype: Gtk.ListStore,
2590 getValue : function(treepath, col)
2592 var tp = new Gtk.TreePath.from_string (treepath);
2593 var iter = new Gtk.TreeIter();
2594 this.el.get_iter (iter, tp);
2595 var value = new GObject.Value('');
2596 this.el.get_value(iter, col, value);
2601 XObject.prototype.init.call(this);
2602 this.el.set_column_types ( 6, [
2603 GObject.TYPE_STRING, // real key
2604 GObject.TYPE_STRING, // real type
2605 GObject.TYPE_STRING, // docs ?
2606 GObject.TYPE_STRING, // visable desc
2607 GObject.TYPE_STRING, // function desc
2608 GObject.TYPE_STRING // element type (event|prop)
2612 showData : function(type) {
2614 if (!this.get('/MidPropTree').activeElement || !type) {
2615 return; // no active element
2618 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2619 var palete = this.get('/LeftTree').getPaleteProvider();
2623 Seed.print('Showing right?');
2624 if (!this.get('/MidPropTree').shown) {
2626 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2627 this.get('/MidPropTree').el.show();
2628 this.get('/MidPropTree').shown = true;
2631 var elementList = palete.getPropertiesFor(fullpath, type).sort(function(a,b) {
2632 return a.name > b.name ? 1 : -1;
2634 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2635 // console.dump(elementList);
2638 var iter = new Gtk.TreeIter();
2639 for(var i =0 ; i < elementList.length; i++) {
2640 var p=elementList[i];
2641 this.el.append(iter);
2642 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2643 //GObject.TYPE_STRING, // real key
2644 // GObject.TYPE_STRING, // real type
2645 // GObject.TYPE_STRING, // docs ?
2646 // GObject.TYPE_STRING // func def?
2649 this.el.set_value(iter, 0, p.name);
2650 this.el.set_value(iter, 1, p.type);
2651 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2652 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2653 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2654 this.el.set_value(iter, 5, type);
2661 xtype: Gtk.TreeViewColumn,
2663 this.el = new Gtk.TreeViewColumn();
2664 this.parent.el.append_column(this.el);
2666 XObject.prototype.init.call(this);
2667 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2672 xtype: Gtk.CellRendererText,
2673 pack : "pack_start,true"
2697 xtype: Gtk.Notebook,
2698 pack : "pack_start,true,true",
2699 id : "view-help-nb",
2701 XObject.prototype.init.call(this);
2702 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2703 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2707 xtype: Gtk.Notebook,
2708 id : "view-notebook",
2712 XObject.prototype.init.call(this);
2713 this.el.set_current_page(0);
2714 //print("SET LABEL?")
2715 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2716 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2722 id : "RightBrowser",
2726 xtype: Gtk.ScrolledWindow,
2729 XObject.prototype.init.call(this);
2730 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2732 shadow_type : Gtk.ShadowType.IN,
2735 xtype: WebKit.WebView,
2737 load_finished : function (self, object) {
2738 print("load finished");
2739 // print("load_finished"); return;
2740 // if (this.ready) { // dont do it twice!
2743 if (!this.inspectorShown) {
2744 this.el.get_inspector().show();
2745 this.inspectorShown = true;
2749 this.pendingRedraw = false;
2751 this.refreshRequired = true;
2752 //var js = this.get('/LeftTree.model').toJS();
2753 //if (js && js[0]) {
2754 // this.renderJS(js[0]);
2758 script_alert : function (self, object, p0) {
2761 return true; // do not display anything...
2763 console_message : function (self, object, p0, p1) {
2765 // console.log(object);
2766 if (!object.match(/^\{/)) {
2768 //this.get('/Terminal').feed(object);
2769 return true; // do not handle!!! -> later maybe in console..
2771 // console.log(object);
2772 var val = JSON.parse(object);
2774 if (typeof(val['hover-node']) != 'undefined') {
2775 this.activeNode = val['hover-node'];
2776 console.log('active node: ' + this.activeNode);
2781 if (typeof(val['id']) != 'undefined') {
2782 // this.activeNode = val['id'];
2783 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2784 if (!tg || typeof(tg[0]) == 'undefined') {
2787 print("SELECT node " + tg[0]);
2789 this.get('/LeftTree.view').selectNode(tg[0]);
2793 if (ret && typeof(val['set']) != 'undefined') {
2794 this.get('/LeftPanel.model').add({
2798 //console.log('active node: ' + this.activeNode);
2801 //Seed.print('a:'+a);
2802 //Seed.print('b:'+b);
2803 //Seed.print('c:'+c);
2806 drag_motion : function (w, ctx, x, y, time, ud) {
2807 // console.log('DRAG MOTION');
2809 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2810 this.targetData = [];
2811 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2813 // A) find out from drag all the places that node could be dropped.
2814 var src = Gtk.drag_get_source_widget(ctx);
2815 if (!src.dropList) {
2816 Gdk.drag_status(ctx, 0, time);
2819 // b) get what we are over.. (from activeNode)
2820 // tree is empty.. - list should be correct..
2821 if (!this.get('/LeftTree.model').currentTree) {
2822 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2826 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2828 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2831 Gdk.drag_status(ctx, 0,time);
2832 this.get('/LeftTree.view').highlight(false);
2836 // if we have a target..
2837 // -> highlight it! (in browser)
2838 // -> highlight it! (in tree)
2840 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2841 this.get('/LeftTree.view').highlight(tg);
2842 this.targetData = tg;
2843 // for tree we should handle this...
2846 drag_drop : function (w, ctx, x, y,time, ud) {
2847 print("TARGET: drag-drop");
2848 var is_valid_drop_site = true;
2853 w, /* will receive 'drag-data-received' signal */
2854 ctx, /* represents the current state of the DnD */
2855 this.get('/Window').atoms["STRING"], /* the target type we want */
2856 time /* time stamp */
2860 /* No target offered by source => error */
2863 return is_valid_drop_site;
2865 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2867 print("Browser: drag-data-received");
2868 var delete_selection_data = false;
2869 vardnd_success = false;
2870 /* Deal with what we are given from source */
2871 if( sel_data && sel_data.length ) {
2873 if (ctx.action == Gdk.DragAction.ASK) {
2874 /* Ask the user to move or copy, then set the ctx action. */
2877 if (ctx.action == Gdk.DragAction.MOVE) {
2878 delete_selection_data = true;
2880 var source = Gtk.drag_get_source_widget(ctx);
2882 print("Browser: source.DRAGDATA? " + source.dragData);
2883 if (this.targetData) {
2884 print(this.targetData);
2885 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2894 if (dnd_success == false)
2896 Seed.print ("DnD data transfer failed!\n");
2899 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2902 create_web_view : function (self, object) {
2903 print("CREATE WEB VIEW");
2904 return null; //new WebKit.WebView();
2909 runRefresh : function()
2911 // this is run every 2 seconds from the init..
2913 if (!this.refreshRequired) {
2914 print("no refresh required");
2921 if (!this.get('/Window.LeftTree').getActiveFile()) {
2924 this.refreshRequired = false;
2925 print("HTML RENDERING");
2927 this.get('/BottomPane').el.show();
2928 this.get('/BottomPane').el.set_current_page(2);// webkit view!
2931 var js = this.get('/LeftTree.model').toJS();
2932 if (!js || !js.length) {
2939 var project = this.get('/Window.LeftTree').getActiveFile().project;
2940 //print (project.fn);
2941 // set it to non-empty.
2942 project.runhtml = project.runhtml || '';
2943 project.runhtml = project.runhtml.length ? project.runhtml : '<script type="text/javascript"></script>';
2946 this.runhtml = this.runhtml || '';
2948 if (project.runhtml != this.runhtml) {
2949 // then we need to reload the browser using
2950 // load_html_string..
2952 // then trigger a redraw once it's loaded..
2953 this.pendingRedraw = true;
2954 var runhtml = '<script type="text/javascript">' + "\n" ;
2955 runhtml +=imports.File.File.read(__script_path__ + '/../builder.html.js') + "\n";
2956 runhtml += '</script>'+ "\n" ;
2958 this.runhtml = project.runhtml;
2959 // need to modify paths
2963 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2964 html = html.replace('</head>', runhtml + this.runhtml + '</head>');
2965 print("LOAD HTML " + html);
2966 this.el.load_html_string( html ,
2967 //fixme - should be a config option!
2968 'http://www.akbkhome.com/e/'
2971 // should trigger load_finished! - which in truns shoudl set refresh Required;
2977 this.renderedData = data;
2978 var str = JSON.stringify(data) ;
2981 console.log('not loaded yet');
2984 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2988 XObject.prototype.init.call(this);
2989 // this may not work!?
2990 var settings = this.el.get_settings();
2991 settings.enable_developer_extras = true;
2993 // this was an attempt to change the url perms.. did not work..
2994 // settings.enable_file_access_from_file_uris = true;
2995 // settings.enable_offline_web_application_cache - true;
2996 // settings.enable_universal_access_from_file_uris = true;
3000 this.el.get_inspector().signal.inspect_web_view.connect(function(wi, pg) {
3001 _this.get('/BottomPane.inspector').el.show();
3002 return _this.get('/BottomPane.inspector').el;
3006 // FIXME - base url of script..
3007 // we need it so some of the database features work.
3008 this.el.load_html_string( "Render not ready" ,
3009 //fixme - should be a config option!
3010 'http://www.akbkhome.com/e/'
3014 //this.el.open('file:///' + __script_path__ + '/../builder.html');
3018 this.el, /* widget that will accept a drop */
3019 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3020 null, /* lists of target to support */
3021 0, /* size of list */
3022 Gdk.DragAction.COPY /* what to do with data after dropped */
3025 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3026 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3028 GLib.timeout_add_seconds(0, 2, function() {
3029 print("run refresh?");
3036 renderJS : function(data) {
3037 this.refreshRequired = true;
3046 id : "RightGtkView",
3048 redraw : function() {
3049 this.highlightWidget = false;
3050 print("REDRAW CALLED");
3051 this.activePath = this.get('/LeftTree').getActivePath();
3052 if (this.renderedEl) {
3053 print("QUEUE DRAW CALLING");
3054 this.renderedEl.queue_draw();
3057 renderJS : function(data, withDebug)
3059 this.highlightWidget = false;
3061 this.withDebug = false;
3062 while (this.get('view').el.get_children().length) {
3063 var c = this.get('view').el.get_children()[0];
3064 this.get('view').el.remove(c);
3071 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
3072 // in theory tree is actually window..
3075 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
3081 this.get('view').el.set_size_request(
3082 tree.default_width * 1 || 400, tree.default_height * 1 || 400
3084 if (this.renderedEl) {
3085 this.renderedEl.set_size_request(
3086 tree.default_width || 600,
3087 tree.default_height || 400
3090 this.get('view').el.show_all();
3095 showInWindow : function() {
3096 print("GET PROEJCT");
3097 var pr = this.get('/LeftProjectTree').getActiveProject();
3099 console.log(pr.paths);
3102 var src= this.buildJS(
3103 this.get('/LeftTree.model').toJS()[0],
3108 //var x = new imports.sandbox.Context();
3112 Seed.check_syntax('var e = ' + src);
3115 this.get('/Terminal').feed(e.message || e.toString() + "\n");
3116 this.get('/Terminal').feed(console._dump(e)+"\n");
3118 var lines = src.split("\n");
3119 var start = Math.max(0, e.line - 10);
3120 var end = Math.min(lines.length, e.line + 10);
3121 for (var i =start ; i < end; i++) {
3123 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3126 this.get('/Terminal').feed(lines[i] + "\n");
3133 this.get('/BottomPane').el.set_current_page(1);
3134 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3135 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3136 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3138 var _top = x.get_global_object()._top;
3140 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3142 if (_top.el.popup) {
3143 _top.el.popup(null, null, null, null, 3, null);
3147 viewAdd : function(item, par)
3149 // does something similar to xobject..
3150 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3152 if (item.pack===false || item.pack === 'false') { // no ;
3155 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3156 var type = item['|xns'] + '.' + item['xtype'];
3158 if (item['|xns'] == 'GtkClutter') { // we can not add this yet!
3161 var ns = imports.gi[item['|xns']];
3162 var ctr = ns[item['xtype']];
3164 for(var k in item) {
3166 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3181 if (k[0] == '|' && typeof(kv) == 'string') {
3183 if (kv.match(new RegExp('function'))) {
3186 print("WASL " + k + '=' + kv);
3188 eval( 'kv = ' + kv);
3189 } catch(e) { continue; }
3192 // print(k + '=' + kv);
3194 if (k[0] == '|') { // should be boolean or number..
3196 //print(k + '=' + kv);
3199 if (k == 'show_tabs') { // force tab showing for notebooks.
3202 print(k + '=' + typeof(kv) + " : " + kv);
3208 var el = new ctr(ctr_args);
3210 print("PACK" + item.pack);
3211 //console.dump(item.pack);
3218 if (typeof(item.pack) == 'string') {
3220 item.pack.split(',').forEach(function(e, i) {
3222 if (e == 'false') { args.push( false); return; }
3223 if (e == 'true') { args.push( true); return; }
3224 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3227 //print(args.join(","));
3229 pack_m = args.shift();
3231 pack_m = item.pack.shift();
3236 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3238 name: "ArgumentError",
3239 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3240 "ADDING : " + item.id + " " + el
3249 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3250 //Seed.print('args: ' + args.length);
3252 par[pack_m].apply(par, args);
3256 item.items = item.items || [];
3257 item.items.forEach(function(ch,n) {
3259 print ("type:" + type);
3261 print ("ch.pack:" + ch.pack);
3262 if (type == 'Gtk.Table' && ch.pack == 'add') {
3263 var c = n % item.n_columns;
3264 var r = Math.floor(n/item.n_columns);
3265 ch.pack = [ 'attach', c, c+1, r, r+1,
3266 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3267 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3268 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3269 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3273 _this.viewAdd(ch, el);
3278 // add the signal handlers.
3279 // is it a widget!?!!?
3285 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3286 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3287 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3288 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3289 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3299 widgetDragDropEvent : function() {
3300 print("WIDGET DRAGDROP");
3303 widgetDragMotionEvent : function() {
3304 print("WIDGET DRAGMOTION");
3307 widgetExposeEvent : function(w, evt, ud, item) {
3309 if (this.inRender) {
3313 if ( this.highlightWidget) {
3314 this.inRender = true;
3315 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3316 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3318 this.inRender = false;
3323 if (this.activePath != item.xtreepath) {
3327 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3328 // work out the coords of the window..
3330 var dr = widget.window;
3331 this.gc = (new Gdk.GC.c_new(dr));
3332 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3333 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3337 var r = evt.expose.area;
3338 // console.dump([r.x, r.y, r.width, r.height ] );
3340 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3341 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3342 // happens with gtkscrollview embedded stuff..
3343 var np =this.activePath.split(':');
3345 this.activePath = np.join(':');
3346 this.renderedEl.queue_draw();
3362 this.inRender = true;
3365 this.highlightWidget = widget;
3370 // print("DRAW BOX");
3371 //console.dump(this.box);
3372 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3373 this.inRender = false;
3376 widgetPressEvent : function(w,e,u,d) {
3377 if (this.get('view').pressed) {
3380 this.get('view').pressed = true;
3381 print("WIDGET PRESS " + d.xtreepath );
3382 this.get('/LeftTree.view').selectNode( d.xtreepath );
3385 widgetReleaseEvent : function() {
3386 this.get('view').pressed = false;
3392 pack : "pack_start,false,true,0",
3396 pack : "pack_start,false,false,0",
3397 label : "Run The Application",
3399 button_press_event : function (self, event) {
3400 // call render on left tree - with special option!?!
3402 //print("GET PROEJCT");
3403 var pr = this.get('/LeftProjectTree').getActiveProject();
3406 for (var i in pr.paths) {
3410 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3411 this.get('/Terminal').feed("RUN DIR:" + dir);
3413 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3414 , false,false,false);
3415 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3416 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3426 xtype: Gtk.ScrolledWindow,
3429 shadow_type : Gtk.ShadowType.IN,
3431 XObject.prototype.init.call(this);
3432 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3436 xtype: Gtk.EventBox,
3437 pack : "add_with_viewport",
3439 XObject.prototype.init.call(this);
3440 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3441 red: 0x9F00, green: 0xB800 , blue : 0xA800
3449 XObject.prototype.init.call(this);
3450 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3451 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3456 xtype: Gtk.EventBox,
3459 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3460 XObject.prototype.init.call(this);
3464 this.el, /* widget that will accept a drop */
3465 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3466 null, /* lists of target to support */
3467 0, /* size of list */
3468 Gdk.DragAction.COPY /* what to do with data after dropped */
3471 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3472 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3475 getActiveNode : function(x,y)
3477 // workout what node is here..
3478 return '0'; // top..
3482 drag_motion : function (self, ctx, x, y, time) {
3484 // A) find out from drag all the places that node could be dropped.
3485 var src = Gtk.drag_get_source_widget(ctx);
3486 if (!src.dropList) {
3487 Gdk.drag_status(ctx, 0, time);
3490 // b) get what we are over.. (from activeNode)
3491 // tree is empty.. - list should be correct..
3492 if (!this.get('/LeftTree.model').currentTree) {
3493 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3497 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3498 var activeNode = this.getActiveNode(x, y);
3501 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3504 Gdk.drag_status(ctx, 0,time);
3505 this.get('/LeftTree.view').highlight(false);
3509 // if we have a target..
3510 // -> highlight it! (in browser)
3511 // -> highlight it! (in tree)
3513 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3514 this.get('/LeftTree.view').highlight(tg);
3515 this.targetData = tg;
3516 // for tree we should handle this...
3519 drag_drop : function (self,ctx, x, y, time) {
3520 Seed.print("TARGET: drag-drop");
3521 var is_valid_drop_site = true;
3526 self, /* will receive 'drag-data-received' signal */
3527 ctx, /* represents the current state of the this.gDnD */
3528 this.get('/Window').atoms["STRING"], /* the target type we want */
3529 time /* time stamp */
3533 /* No target offered by source => error */
3536 return is_valid_drop_site;
3539 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3541 Seed.print("GtkView: drag-data-received");
3542 var delete_selection_data = false;
3543 var dnd_success = false;
3544 /* Deal with what we are given from source */
3545 if( sel_data && sel_data.length ) {
3547 if (ctx.action == Gdk.DragAction.ASK) {
3548 /* Ask the user to move or copy, then set the ctx action. */
3551 if (ctx.action == Gdk.DragAction.MOVE) {
3552 delete_selection_data = true;
3554 var source = Gtk.drag_get_source_widget(ctx);
3556 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3557 if (this.targetData) {
3558 Seed.print(this.targetData);
3559 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3568 if (dnd_success == false)
3570 Seed.print ("DnD data transfer failed!\n");
3573 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3576 button_press_event : function (self, event) {
3577 this.pressed = false;
3593 xtype: Gtk.ScrolledWindow,
3598 var file = this.get('/LeftTree').getActiveFile();
3602 var activeEl = this.get('/LeftTree').getActiveElement();
3603 var xtype = file.guessName( activeEl )
3604 if (!xtype || !xtype.length) {
3607 //this.get('/Window.view-help-nb').el.set_current_page(1);
3609 // get the active element being edited.
3610 var helpurl = file.getHelpUrl(xtype);
3612 // now load the help info in the page..
3613 this.get('help-view').el.open(helpurl);
3617 xtype: WebKit.WebView,
3621 XObject.prototype.init.call(this);
3622 this.get('/Window.help-view').el.open(
3623 "http://devel.akbkhome.com/seed/");
3635 xtype: Gtk.Notebook,
3639 XObject.prototype.init.call(this);
3640 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3641 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3642 this.el.set_tab_label(this.items[2].el, new Gtk.Label({ label : "Inspector" }));
3646 xtype: Gtk.ScrolledWindow,
3651 xtype: GtkSource.View,
3655 XObject.prototype.init.call(this);
3656 var description = Pango.Font.description_from_string("monospace")
3657 description.set_size(8000);
3658 this.el.modify_font(description);
3661 load : function(str) {
3663 // show the help page for the active node..
3664 this.get('/Help').show();
3667 this.get('/BottomPane').el.set_current_page(0);
3668 this.el.get_buffer().set_text(str, str.length);
3669 var lm = GtkSource.LanguageManager.get_default();
3671 this.el.get_buffer().set_language(lm.get_language('js'));
3672 var buf = this.el.get_buffer();
3673 var cursor = buf.get_mark("insert");
3674 var iter= new Gtk.TextIter;
3675 buf.get_iter_at_mark(iter, cursor);
3677 iter.set_line_offset(4);
3678 buf.move_mark(cursor, iter);
3681 cursor = buf.get_mark("selection_bound");
3682 iter= new Gtk.TextIter;
3683 buf.get_iter_at_mark(iter, cursor);
3685 iter.set_line_offset(4);
3686 buf.move_mark(cursor, iter);
3688 this.el.grab_focus();
3690 insert_spaces_instead_of_tabs : true,
3693 show_line_numbers : true,
3696 xtype: GtkSource.Buffer,
3697 pack : "set_buffer",
3699 changed : function (self) {
3700 var s = new Gtk.TextIter();
3701 var e = new Gtk.TextIter();
3702 this.el.get_start_iter(s);
3703 this.el.get_end_iter(e);
3704 var str = this.el.get_text(s,e,true);
3706 Seed.check_syntax('var e = ' + str);
3708 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3709 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3711 print("SYNTAX ERROR IN EDITOR");
3716 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3717 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3720 this.get('/LeftPanel.model').changed( str , false);
3729 xtype: Gtk.ScrolledWindow,
3733 xtype: Vte.Terminal,
3736 feed : function(istr) {
3737 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3738 // we should make ourselves visable!!!
3739 this.get('/BottomPane').el.show();
3740 this.get('/BottomPane').el.set_current_page(1);
3742 this.el.feed(str ,str.length);
3744 scroll_on_output : true,
3746 XObject.prototype.init.call(this);
3747 this.el.set_size (80, 1000);
3749 scrollback_lines : 1000
3754 xtype: Gtk.ScrolledWindow,
3758 xtype: WebKit.WebView,
3770 pack : "pack_start,false,false",
3774 this.get('buttonbar').el.show();
3775 this.get('viewbox').el.hide();
3776 print("TRIED TO HIDE");
3779 this.get('buttonbar').el.hide();
3780 this.get('viewbox').el.show();
3781 // this.get('model').expanded();
3793 pack : "pack_start,false,true",
3795 clicked : function (self) {
3796 this.get('/RightPalete').show();
3803 stock : Gtk.STOCK_GOTO_FIRST,
3804 icon_size : Gtk.IconSize.MENU
3814 XObject.prototype.init.call(this);
3815 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3818 enter_notify_event : function (self, event) {
3819 this.get('/RightPalete').show();
3833 pack : "pack_start,false,true",
3842 pack : "pack_start,false,true",
3844 clicked : function (self) {
3845 this.get('/RightPalete').hide();
3852 stock : Gtk.STOCK_GOTO_LAST,
3853 icon_size : Gtk.IconSize.MENU
3860 xtype: Gtk.ScrolledWindow,
3863 XObject.prototype.init.call(this);
3864 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3865 this.el.set_size_request(-1,200);
3867 shadow_type : Gtk.ShadowType.IN,
3870 xtype: Gtk.TreeView,
3873 XObject.prototype.init.call(this);
3874 this.el.set_size_request(150,-1);
3875 // set_reorderable: [1]
3877 var description = new Pango.FontDescription.c_new();
3878 description.set_size(8000);
3879 this.el.modify_font(description);
3881 this.selection = this.el.get_selection();
3882 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3883 // this.selection.signal['changed'].connect(function() {
3884 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3886 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3888 Gtk.drag_source_set (
3889 this.el, /* widget will be drag-able */
3890 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3891 null, /* lists of target to support */
3892 0, /* size of list */
3893 Gdk.DragAction.COPY /* what to do with data after dropped */
3895 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3897 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3898 Gtk.drag_source_add_text_targets(this.el);
3900 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3901 targets = new Gtk.TargetList();
3902 targets.add( LeftTree.atoms["STRING"], 0, 0);
3903 targets.add_text_targets( 1 );
3904 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3906 //if you want to allow text to be output elsewhere..
3907 //Gtk.drag_source_add_text_targets(this.el);
3911 headers_visible : false,
3912 enable_tree_lines : true,
3914 drag_begin : function (self, ctx) {
3915 // we could fill this in now...
3916 Seed.print('SOURCE: drag-begin');
3920 var iter = new Gtk.TreeIter();
3921 var s = this.selection;
3922 s.get_selected(this.get('/RightPalete.model').el, iter);
3923 var path = this.get('/RightPalete.model').el.get_path(iter);
3925 var pix = this.el.create_row_drag_icon ( path);
3928 Gtk.drag_set_icon_pixmap (ctx,
3935 var value = new GObject.Value('');
3936 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3937 if (!this.get('/RightPalete').provider) {
3940 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3941 this.el.dragData = value.value;
3948 drag_data_get : function (self, drag_context, selection_data, info, time) {
3949 //Seed.print('Palete: drag-data-get: ' + target_type);
3950 if (this.el.dragData && this.el.dragData.length ) {
3951 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3955 //this.el.dragData = "TEST from source widget";
3959 drag_end : function (self, drag_context) {
3960 Seed.print('SOURCE: drag-end');
3961 this.el.dragData = false;
3962 this.el.dropList = false;
3963 this.get('/LeftTree.view').highlight(false);
3969 xtype: Gtk.ListStore,
3972 XObject.prototype.init.call(this);
3973 this.el.set_column_types ( 2, [
3974 GObject.TYPE_STRING, // title
3975 GObject.TYPE_STRING // tip
3980 load : function(tr,iter)
3985 //console.log('Project tree load: ' + tr.length);
3986 var citer = new Gtk.TreeIter();
3987 //this.insert(citer,iter,0);
3988 for(var i =0 ; i < tr.length; i++) {
3991 this.el.append(citer);
3993 this.el.insert(citer,iter,-1);
3998 this.el.set_value(citer, 0, '' + r ); // title
4000 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
4001 //if (r.cn && r.cn.length) {
4002 // this.load(r.cn, citer);
4008 getValue : function (iter, col) {
4009 var gval = new GObject.Value('');
4010 this.el.get_value(iter, col ,gval);
4017 xtype: Gtk.TreeViewColumn,
4018 pack : "append_column",
4020 XObject.prototype.init.call(this);
4021 this.el.add_attribute(this.items[0].el , 'markup', 0 );
4025 xtype: Gtk.CellRendererText,
4047 XObject.cache['/Window'] = Window;