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,
163 pack : "set_submenu",
171 activate : function (self) {
172 var fn = this.get('/LeftTree').getActiveFile();
174 this.get('/StandardErrorDialog').show("No File active");
178 this.get('/DialogNewComponent').show(fn);
182 label : "File _Properties",
193 use_underline : true,
201 pack : "set_submenu",
210 use_underline : true,
212 activate : function (self) {
213 this.get('/About').el.run();
242 label : "Select Project",
244 pack : "pack_start,false,true",
246 XObject.prototype.init.call(this);
247 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
250 activate : function (self) {
251 var nb = this.get('/LeftTopPanel.notebook');
252 if (this.el.expanded) {
255 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
258 var model = this.get('/LeftProjectTree.combomodel');
259 // print ("loading Projects?")
260 //console.dump(pm.projects);
261 model.loadData(pm.projects);
264 nb.el.set_current_page(1);
265 //pm.on('changed', function() {
266 //console.log("CAUGHT project manager change");
267 // _combo.model.loadData(pm.projects);
271 nb.el.set_current_page(0);
273 enter_notify_event : function (self, event) {
274 this.el.expanded = !this.el.expanded;
275 //if (this.el.expanded ) {
276 this.listeners.activate.call(this);
288 pack : "pack_start,true,true",
290 XObject.prototype.init.call(this);
291 this.el.set_current_page(0);
296 xtype: Gtk.ScrolledWindow,
298 shadow_type : Gtk.ShadowType.IN,
300 XObject.prototype.init.call(this);
301 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
304 getPaleteProvider : function() {
305 var model = this.get('model');
306 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
307 return pm.getPalete(model.file.getType());
309 renderView : function() {
310 var render = this.getRenderer();
311 var model = this.get('model');
313 render.renderJS(model.toJS(false,true)[0]);
315 print("NO RENDER JS METHOD?");
318 getRenderer : function() {
320 switch( this.getActiveFile().getType()) {
322 return this.get('/RightBrowser.view');
324 return this.get('/RightGtkView');
328 getActivePath : function() {
329 var model = this.get('model');
330 var view = this.get('view');
331 if (view.selection.count_selected_rows() < 1) {
334 var iter = new Gtk.TreeIter();
336 view.selection.get_selected(model.el, iter);
337 return model.el.get_path(iter).to_string();
339 getActiveFile : function() {
340 return this.get('model').file;
342 getActiveElement : function() {
344 var path = this.getActivePath();
348 var iter = new Gtk.TreeIter();
349 this.get('model').el.get_iter_from_string(iter, path);
351 var value = new GObject.Value('');
352 this.get('model').el.get_value(iter, 2, value);
354 return JSON.parse(value.value);
361 headers_visible : false,
362 enable_tree_lines : true,
365 XObject.prototype.init.call(this);
366 var description = new Pango.FontDescription.c_new();
367 description.set_size(8000);
368 this.el.modify_font(description);
370 this.selection = this.el.get_selection();
371 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
374 // is this really needed??
375 this.selection.signal['changed'].connect(function() {
376 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
377 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
381 Gtk.drag_source_set (
382 this.el, /* widget will be drag-able */
383 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
384 null, /* lists of target to support */
385 0, /* size of list */
386 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
389 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
391 Gtk.drag_source_add_text_targets(this.el);
394 this.el, /* widget that will accept a drop */
395 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
396 null, /* lists of target to support */
397 0, /* size of list */
398 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
401 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
402 Gtk.drag_dest_add_text_targets(this.el);
404 highlight : function(treepath_ar) {
406 // highlighting for drag/drop
407 if (treepath_ar.length && treepath_ar[0].length ) {
408 this.el.set_drag_dest_row(
409 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
411 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
415 selectNode : function(treepath_str) {
416 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
417 var tp = new Gtk.TreePath.from_string(treepath_str);
418 this.el.set_cursor(tp, null, false);
419 this.el.scroll_to_cell(tp, null, false, 0,0);
422 button_press_event : function (self, ev) {
423 console.log("button press?");
424 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
425 print("click" + ev.type);
431 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
433 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
435 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
436 this.get('/LeftTreeMenu').el.show_all();
437 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
438 print("click:" + res.path.to_string());
441 drag_begin : function (self, drag_context) {
442 print('SOURCE: drag-begin');
443 this.targetData = false;
444 // find what is selected in our tree...
445 var iter = new Gtk.TreeIter();
446 var s = this.selection;
447 s.get_selected(this.get('/LeftTree.model').el, iter);
449 // set some properties of the tree for use by the dropped element.
450 var value = new GObject.Value('');
451 this.get('/LeftTree.model').el.get_value(iter, 2, value);
452 var data = JSON.parse(value.value);
453 var xname = this.get('/LeftTree.model').file.guessName(data);
455 this.el.dragData = xname;
456 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
459 // make the drag icon a picture of the node that was selected
460 var path = this.get('/LeftTree.model').el.get_path(iter);
461 this.el.treepath = path.to_string();
463 var pix = this.el.create_row_drag_icon ( path);
465 Gtk.drag_set_icon_pixmap (ctx,
474 drag_end : function (self, drag_context) {
475 Seed.print('LEFT-TREE: drag-end');
476 this.el.dragData = false;
477 this.el.dropList = false;
478 this.targetData = false;
479 this.get('/LeftTree.view').highlight(false);
482 drag_motion : function (self, ctx, x, y, time) {
483 console.log("LEFT-TREE: drag-motion");
484 var src = Gtk.drag_get_source_widget(ctx);
486 // a drag from elsewhere...- prevent drop..
488 print("no drag data!");
489 Gdk.drag_status(ctx, 0, time);
490 this.targetData = false;
493 var action = Gdk.DragAction.COPY;
494 if (src == this.el) {
495 // unless we are copying!!! ctl button..
496 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
500 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
501 // no children.. -- asume it's ok..
502 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
503 Gdk.drag_status(ctx, action ,time);
507 print("GETTING POS");
508 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
509 print("ISOVER? " + isOver);
511 Gdk.drag_status(ctx, 0 ,time);
512 return false; // not over apoint!?!
514 // drag node is parent of child..
515 console.log("SRC TREEPATH: " + src.treepath);
516 console.log("TARGET TREEPATH: " + data.path.to_string());
518 // nned to check a few here..
519 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
520 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
521 //Gtk.TreeViewDropPosition.AFTER
522 //Gtk.TreeViewDropPosition.BEFORE
524 if (typeof(src.treepath) != 'undefined' &&
525 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
526 print("subpath drag");
527 Gdk.drag_status(ctx, 0 ,time);
532 //print("DUMPING DATA");
533 //console.dump(data);
536 print(data.path.to_string() +' => '+ data.pos);
537 var tg = this.get('/LeftTree.model').findDropNodeByPath(
538 data.path.to_string(), src.dropList, data.pos);
540 this.get('/LeftTree.view').highlight(tg);
542 print("Can not find drop node path");
543 this.targetData = false;
544 Gdk.drag_status(ctx, 0, time);
548 this.targetData = tg;
551 Gdk.drag_status(ctx, action ,time);
555 drag_drop : function (w, ctx, x, y, time) {
556 Seed.print("TARGET: drag-drop");
560 w, /* will receive 'drag-data-received' signal */
561 ctx, /* represents the current state of the DnD */
562 this.get('/Window').atoms["STRING"], /* the target type we want */
563 time /* time stamp */
567 /* No target offered by source => error */
572 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
573 print("Tree: drag-data-received");
575 var delete_selection_data = false;
576 var dnd_success = false;
577 /* Deal with what we are given from source */
578 if( sel_data && sel_data.length ) {
580 if (ctx.action == Gdk.DragAction.ASK) {
581 /* Ask the user to move or copy, then set the ctx action. */
584 if (ctx.action == Gdk.DragAction.MOVE) {
585 //delete_selection_data = true;
588 var source = Gtk.drag_get_source_widget(ctx);
590 if (this.targetData) {
591 if (source != this.el) {
592 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
594 // drag around.. - reorder..
595 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
599 //Seed.print(this.targetData);
605 // we can send stuff to souce here...
611 if (dnd_success == false)
613 Seed.print ("DnD data transfer failed!\n");
616 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
619 cursor_changed : function (self) {
620 if (this.blockChanges) { // probably not needed..
623 var render = this.get('/LeftTree').getRenderer();
626 if (this.selection.count_selected_rows() < 1) {
627 this.get('/LeftPanel.model').load( false);
628 this.get('/MidPropTree').activeElement = false;
629 this.get('/MidPropTree').hideWin();
631 var pm = this.get('/RightPalete.model');
632 if (!this.get('/LeftTree').getPaleteProvider()) {
633 // it may not be loaded yet..
636 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
637 this.get('/LeftTree.model').listAllTypes()));
638 if (render && render.redraw) {
644 //console.log('changed');
645 var s = this.selection;
646 var iter = new Gtk.TreeIter();
647 s.get_selected(this.get('/LeftTree.model').el, iter);
651 var value = new GObject.Value('');
652 this.get('/LeftTree.model').el.get_value(iter, 2, value);
653 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
655 var data = JSON.parse(value.value);
656 this.get('/MidPropTree').activeElement = data;
657 this.get('/MidPropTree').hideWin();
658 this.get('/LeftPanel.model').load( data);
660 console.log(value.value);
661 // _g.button.set_label(''+value.get_string());
663 var pm =this.get('/RightPalete.model');
664 pm.load( this.get('/RightPalete').provider.gatherList(
665 this.get('/LeftTree.model').listAllTypes()));
668 if (render && render.redraw) {
672 //Seed.print( value.get_string());
679 xtype: Gtk.TreeStore,
683 XObject.prototype.init.call(this);
684 this.el.set_column_types ( 3, [
685 GObject.TYPE_STRING, // title
686 GObject.TYPE_STRING, // tip
687 GObject.TYPE_STRING // source..
691 changed : function(n, refresh) {
692 print("MODEL CHANGED CALLED" + this.activePath);
693 if (this.activePath) {
694 var iter = new Gtk.TreeIter();
695 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
696 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
697 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
699 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
701 //this.currentTree = this.toJS(false, true)[0];
702 this.file.items = this.toJS(false, false);
703 print("AFTER CHANGED");
704 //console.dump(this.file.items);
706 this.currentTree = this.file.items[0];
707 //console.log(this.file.toSource());
710 print("REDNER BROWSER?!");
711 this.get('/LeftTree').renderView();
713 var pm = this.get('/RightPalete.model');
714 if (!this.get('/RightPalete').provider) {
720 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
721 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
725 loadFile : function(f) {
731 console.log('missing file');
735 // load the file if not loaded..
736 if (f.items === false) {
738 f.loadItems(function() {
744 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
746 if (f.items.length && typeof(f.items[0]) == 'string') {
748 this.get('/RightEditor').el.show();
749 this.get('/RightEditor.view').load( f.items[0]);
753 //console.dump(f.items);
755 this.get('/LeftTree.view').el.expand_all();
757 if (!f.items.length) {
760 this.get('/Window.leftvpaned').el.set_position(80);
762 this.get('/LeftTree.view').el.set_cursor(
763 new Gtk.TreePath.from_string('0'), null, false);
767 this.get('/Window.leftvpaned').el.set_position(200);
771 //print("hide right editior");
772 this.get('/RightEditor').el.hide();
773 //print("set current tree");
774 this.currentTree = this.toJS(false, false)[0];
775 //console.dump(this.currentTree);
776 this.currentTree = this.currentTree || { items: [] };
777 this.get('/LeftTree').renderView();
778 //console.dump(this.map);
779 //var RightPalete = imports.Builder.RightPalete.RightPalete;
780 var pm = this.get('/RightPalete.model');
783 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
785 if (!this.get('/RightPalete').provider) {
786 print ("********* PALETE PROVIDER MISSING?!!");
788 this.get('/LeftTree').renderView();
790 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
794 this.get('/Window.view-notebook').el.set_current_page(
795 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
798 findDropNode : function(treepath_str, targets) {
800 // this is used by the dragdrop code in the roo version AFAIR..
802 var path = treepath_str.replace(/^builder-/, '');
803 // treemap is depreciated... - should really check if model has any entries..
805 if (!this.el.iter_n_children(null)) {
807 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
809 print("FIND treepath: " + path);
810 //console.dump(this.treemap);
812 if (!treepath_str.match(/^builder-/)) {
813 return []; // nothing!
815 if (targets === true) {
818 return this.findDropNodeByPath(path,targets)
820 findDropNodeByPath : function(treepath_str, targets, pref) {
821 var path = treepath_str + ''; // dupe it..
822 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
824 //console.dump(this.treemap);
825 while (path.length) {
826 print("LOOKING FOR PATH: " + path);
827 var node_data = this.singleNodeToJS(path);
828 if (node_data === false) {
829 print("node not found");
833 var xname = this.get('/LeftTree.model').file.guessName(node_data);
836 targets.forEach(function(tg) {
840 if ((tg == xname) ) {
843 if (tg.indexOf(xname +':') === 0) {
845 prop = tg.split(':').pop();
850 if (last) { // pref is after/before..
851 // then it's after last
853 return []; // do not allow..
855 return [ last, pref , prop];
858 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
860 var par = path.split(':');
863 path = par.join(':');
869 dropNode : function(target_data, node) {
872 console.dump(target_data);
873 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
875 print("add " + tp + "@" + target_data[1] );
878 if (tp && target_data[1] < 2) { // before or after..
879 var ar = target_data[0].split(':');
881 parent = new Gtk.TreePath.from_string( ar.join(':') );
884 var n_iter = new Gtk.TreeIter();
885 var iter_par = new Gtk.TreeIter();
886 var iter_after = after ? new Gtk.TreeIter() : false;
890 if (parent !== false) {
891 this.el.get_iter(iter_par, parent);
898 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
899 this.el.get_iter(iter_after, after);
900 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
901 n_iter, iter_par, iter_after);
904 this.el.append(n_iter, iter_par);
908 if (typeof(node) == 'string') {
909 var ar = node.split('.');
910 var xtype = ar.pop();
913 '|xns' : ar.join('.'),
916 if (target_data.length == 3 && target_data[2].length) {
917 node['*prop'] = target_data[2];
921 // work out what kind of packing to use..
922 if (typeof(node.pack) == 'undefined' && parent !== false) {
923 var pal = this.get('/LeftTree').getPaleteProvider();
925 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
926 print ("PNAME : " + pname);
927 var cname = pal.guessName(node);
928 print ("CNAME : " + cname);
929 node.pack = pal.getDefaultPack(pname, cname);
940 // load children - if it has any..
943 this.load(xitems, n_iter);
945 if (tp && (xitems || after)) {
946 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
948 // wee need to get the empty proptypes from somewhere..
950 //var olditer = this.activeIter;
951 this.activePath = this.el.get_path(n_iter).to_string();
953 // changed actually set's the node data..
954 this.changed(node, true);
958 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
960 //Builder.MidPropTree._model.load(node);
961 //Builder.MidPropTree._win.hideWin();
962 //Builder.LeftPanel._model.load( node);
966 moveNode : function(target_data, action) {
967 //print("MOVE NODE");
968 // console.dump(target_data);
969 var old_iter = new Gtk.TreeIter();
970 var s = this.get('/LeftTree.view').selection;
971 s.get_selected(this.el, old_iter);
972 var node = this.nodeToJS(old_iter,false);
973 //console.dump(node);
976 // needs to drop first, otherwise the target_data
977 // treepath will be invalid.
979 this.dropNode(target_data, node);
980 if (action & Gdk.DragAction.MOVE) {
981 // print("REMOVING OLD NODE");
982 this.el.remove(old_iter);
986 this.activePath= false;
987 this.changed(false,true);
989 deleteSelected : function() {
990 this.get('/LeftTree.view').blockChanges = true;
991 var old_iter = new Gtk.TreeIter();
992 var s = this.get('/LeftTree.view').selection;
993 s.get_selected(this.el, old_iter);
994 var path = this.el.get_path(old_iter).to_string();
996 this.activePath= false;
999 this.activePath= false;
1000 var iter = new Gtk.TreeIter();
1001 this.el.get_iter_from_string(iter, path);
1002 this.el.remove(iter);
1004 // rebuild treemap. -- depreciated.!!
1007 //this.toJS(null, true) // does not do anything?
1008 this.activePath= false;
1009 this.changed(false,true);
1010 this.get('/LeftTree.view').blockChanges = false;
1012 currentTree : false,
1013 listAllTypes : function() {
1014 var s = this.get('/LeftTree.view').selection;
1015 print ("LIST ALL TYPES: " + s.count_selected_rows() );
1017 if (s.count_selected_rows() > 0) {
1018 var iter = new Gtk.TreeIter();
1019 s.get_selected(this.el, iter);
1021 // set some properties of the tree for use by the dropped element.
1022 var value = new GObject.Value('');
1023 this.el.get_value(iter, 2, value);
1024 var data = JSON.parse(value.value);
1027 var xname = this.get('/LeftTree.model').file.guessName(data);
1028 console.log('selected:' + xname);
1032 return []; // could not find it..
1040 li.forEach(function(el) {
1041 // this is specific to roo!!!?
1043 var fullpath = _this.file.guessName(el);
1044 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1049 if (el.items && el.items.length) {
1058 addall([this.currentTree]);
1060 // only if we have nothing, should we add '*top'
1064 //console.log('all types in tree');
1065 //console.dump(ret);
1070 singleNodeToJS : function (treepath)
1072 var iter = new Gtk.TreeIter();
1073 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1077 var iv = this.getIterValue(iter, 2);
1079 return JSON.parse(iv);
1082 nodeToJS : function (iter, with_id)
1084 var par = new Gtk.TreeIter();
1085 var iv = this.getIterValue(iter, 2);
1086 // print("IV" + iv);
1087 var k = JSON.parse(iv);
1088 if (k.json && !this.el.iter_parent( par, iter )) {
1093 var treepath_str = this.el.get_path(iter).to_string();
1094 // not sure how we can handle mixed id stuff..
1095 if (typeof(k.id) == 'undefined') {
1096 k.id = 'builder-'+ treepath_str ;
1100 this.treemap[ treepath_str ] = k;
1101 k.xtreepath = treepath_str ;
1104 if (this.el.iter_has_child(iter)) {
1105 citer = new Gtk.TreeIter();
1106 this.el.iter_children(citer, iter);
1107 k.items = this.toJS(citer,with_id);
1111 toJS : function(iter, with_id)
1113 //Seed.print("WITHID: "+ with_id);
1120 iter = new Gtk.TreeIter();
1121 if (!this.el.get_iter_first(iter)) {
1131 var k = this.nodeToJS(iter, with_id);
1135 if (!this.el.iter_next(iter)) {
1141 // convert the list into a json string..
1145 getIterValue : function (iter, col) {
1146 var gval = new GObject.Value('');
1147 this.el.get_value(iter, col ,gval);
1152 nodeTitle : function(c, renderfull) {
1155 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1156 if (sr) txt.push('<s>');
1157 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1159 if (renderfull && c['|xns']) {
1160 txt.push(c['|xns']);
1163 if (c.xtype) { txt.push(c.xtype); }
1164 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1165 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1166 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1169 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1170 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1171 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1172 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1173 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1174 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1175 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1176 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1177 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1179 // for flat classes...
1180 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1181 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1184 if (sr) txt.push('</s>');
1185 return (txt.length == 0 ? "Element" : txt.join(" "));
1187 nodeToJSON : function(c) {
1195 return JSON.stringify(o);
1197 load : function(tr,iter)
1199 var citer = new Gtk.TreeIter();
1200 //this.insert(citer,iter,0);
1201 for(var i =0 ; i < tr.length; i++) {
1203 this.el.insert(citer,iter,-1);
1205 this.el.append(citer);
1208 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1209 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1210 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1211 if (tr[i].items && tr[i].items.length) {
1212 this.load(tr[i].items, citer);
1216 nodeTip : function(c) {
1217 var ret = this.nodeTitle(c,true);
1223 if (!i.length || i[0] != '|') {
1229 if (typeof(c[i]) != 'string') {
1232 //print("prop : " + i + ':' + c[i]);
1233 if (!c[i].match(new RegExp('function'))) {
1236 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1240 ret+="\n\nMethods:" + funcs;
1247 xtype: Gtk.TreeViewColumn,
1248 pack : "append_column",
1250 XObject.prototype.init.call(this);
1251 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1255 xtype: Gtk.CellRendererText,
1265 id : "LeftTreeMenu",
1268 xtype: Gtk.MenuItem,
1270 label : "Delete Element",
1272 activate : function (self) {
1274 this.get('/LeftTree.model').deleteSelected();
1285 id : "LeftProjectTree",
1286 showNoProjectSelected : function() {
1287 this.get('/StandardErrorDialog').show("Select a Project first.");
1289 getActiveProject : function() {
1290 return this.project;
1293 leave_notify_event : function (self, event) {
1300 pack : "pack_start,false,false",
1303 xtype: Gtk.ComboBox,
1306 XObject.prototype.init.call(this);
1307 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1309 getValue : function() {
1310 var ix = this.el.get_active();
1314 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1315 if (typeof(data[ix]) == 'undefined') {
1320 setValue : function(fn)
1324 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1325 data.forEach(function(n, ix) {
1333 changed : function (self) {
1334 var fn = this.getValue();
1335 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1336 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1341 xtype: Gtk.CellRendererText,
1342 pack : "pack_start,true",
1346 xtype: Gtk.ListStore,
1349 XObject.prototype.init.call(this);
1350 this.el.set_column_types ( 2, [
1351 GObject.TYPE_STRING, // real key
1352 GObject.TYPE_STRING // real type
1356 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1358 pm.on('changed', function() {
1359 print("caught changed hook on project manager - reloading data");
1360 _this.loadData(pm.projects);
1364 loadData : function(data) {
1365 var ov = this.get('/LeftProjectTree.combo').getValue();
1367 var iter = new Gtk.TreeIter();
1369 data.forEach(function(p) {
1374 el.set_value(iter, 0, p.fn);
1375 el.set_value(iter, 1, p.name);
1379 this.get('/LeftProjectTree.combo').setValue(ov);
1388 xtype: Gtk.ScrolledWindow,
1390 shadow_type : Gtk.ShadowType.IN,
1392 XObject.prototype.init.call(this);
1393 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1397 xtype: Gtk.TreeView,
1398 headers_visible : false,
1399 enable_tree_lines : true,
1402 XObject.prototype.init.call(this);
1403 var description = new Pango.FontDescription.c_new();
1404 description.set_size(8000);
1405 this.el.modify_font(description);
1407 this.selection = this.el.get_selection();
1408 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1412 cursor_changed : function (self) {
1413 var iter = new Gtk.TreeIter();
1415 if (this.selection.count_selected_rows() < 1) {
1416 //XN.get('Builder.LeftTree.model').
1417 this.get('/LeftTree.model').load( false);
1421 var model = this.get('/LeftProjectTree.model');
1422 //console.log('changed');
1423 var s = this.selection;
1424 s.get_selected(model, iter);
1425 value = new GObject.Value('');
1426 model.el.get_value(iter, 2, value);
1428 console.log(value.value);// id..
1430 var file = this.get('/LeftProjectTree').project.getById(value.value);
1437 var nb = this.get('/LeftTopPanel.expander');
1438 nb.el.expanded = false;
1439 nb.listeners.activate.call(nb);
1440 //_expander.el.set_expanded(false);
1442 var ltm = this.get('/LeftTree.model');
1450 xtype: Gtk.TreeStore,
1454 XObject.prototype.init.call(this);
1455 this.el.set_column_types ( 3, [
1456 GObject.TYPE_STRING, // title
1457 GObject.TYPE_STRING, // tip
1458 GObject.TYPE_STRING // id..
1462 loadProject : function(pr) {
1463 print("LOAD PROJECT");
1469 this.get('/LeftProjectTree').project = pr;
1470 this.load(pr.toTree());
1471 this.get('/LeftProjectTree.view').el.expand_all();
1473 load : function(tr,iter) {
1474 // console.dump(tr);
1475 console.log('Project tree load: ' + tr.length);
1476 var citer = new Gtk.TreeIter();
1477 //this.insert(citer,iter,0);
1480 tr.forEach(function (r) {
1482 _this.el.append(citer);
1484 _this.el.insert(citer,iter,-1);
1486 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1487 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1488 _this.el.set_value(citer, 2, '' + r.id ); //id
1489 if (r.cn && r.cn.length) {
1490 _this.load(r.cn, citer);
1495 getValue : function(iter, col) {
1496 var gval = new GObject.Value('');
1497 this.el.get_value(iter, col ,gval);
1498 return '' + gval.value;
1502 xtype: Gtk.TreeViewColumn,
1503 pack : "append_column",
1505 XObject.prototype.init.call(this);
1506 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1510 xtype: Gtk.CellRendererText,
1533 pack : "pack_start,false,true,0",
1540 button_press_event : function (self, event) {
1541 this.get('/MidPropTree.model').showData('props');
1553 stock : Gtk.STOCK_ADD,
1554 icon_size : Gtk.IconSize.MENU
1569 button_press_event : function (self, event) {
1570 this.get('/MidPropTree.model').showData('events');
1582 stock : Gtk.STOCK_ADD,
1583 icon_size : Gtk.IconSize.MENU
1598 button_press_event : function (self, ev) {
1599 var p = this.get('/AddPropertyPopup');
1603 p.el.set_screen(Gdk.Screen.get_default());
1605 p.el.popup(null, null, null, null, 3, ev.button.time);
1617 stock : Gtk.STOCK_ADD,
1618 icon_size : Gtk.IconSize.MENU
1630 id : "AddPropertyPopup",
1633 xtype: Gtk.MenuItem,
1635 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1638 activate : function (self) {
1640 this.get('/LeftPanel.model').add( {
1651 xtype: Gtk.MenuItem,
1653 tooltip_markup : "Add what type of packing is to be used",
1656 activate : function (self) {
1658 this.get('/LeftPanel.model').add( {
1668 xtype: Gtk.MenuItem,
1670 tooltip_markup : "Override the init method",
1673 activate : function (self) {
1675 this.get('/LeftPanel.model').add( {
1678 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1685 xtype: Gtk.SeparatorMenuItem,
1689 xtype: Gtk.MenuItem,
1691 tooltip_markup : "Add a user defined string property",
1694 activate : function (self) {
1696 this.get('/LeftPanel.model').add( {
1706 xtype: Gtk.MenuItem,
1708 tooltip_markup : "Add a user defined number property",
1711 activate : function (self) {
1713 this.get('/LeftPanel.model').add( {
1723 xtype: Gtk.MenuItem,
1725 tooltip_markup : "Add a user defined boolean property",
1728 activate : function (self) {
1730 this.get('/LeftPanel.model').add( {
1740 xtype: Gtk.SeparatorMenuItem,
1744 xtype: Gtk.MenuItem,
1746 tooltip_markup : "Add a user function boolean property",
1749 activate : function (self) {
1751 this.get('/LeftPanel.model').add( {
1754 val : "function() {\n \n}\n",
1767 xtype: Gtk.ScrolledWindow,
1770 shadow_type : Gtk.ShadowType.IN,
1773 XObject.prototype.init.call(this);
1774 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1778 xtype: Gtk.TreeView,
1781 headers_visible : false,
1782 enable_tree_lines : true,
1784 XObject.prototype.init.call(this);
1786 this.selection = this.el.get_selection();
1787 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1790 var description = new Pango.FontDescription.c_new();
1791 description.set_size(8000);
1792 this.el.modify_font(description);
1795 button_press_event : function (self, ev) {
1799 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1800 return false; //not on a element.
1804 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1806 if (res.column.title != 'value') {
1807 return false; // ignore..
1809 if ( this.get('/LeftPanel').editing) {
1812 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1813 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1814 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1818 var provider = this.get('/LeftTree').getPaleteProvider();
1820 var opts = provider.findOptions(type);
1822 if (opts === false) {
1823 this.get('/LeftPanel').editableColumn.setOptions([]);
1824 renderer.has_entry = true;
1826 LeftPanel.editableColumn.setOptions(opts);
1827 renderer.has_entry = false;
1831 //Seed.print("click" + ev.type);
1832 //console.dump(res);
1838 if (res.column.title == 'value') {
1841 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1842 var p = this.get('/LeftPanelPopup');
1847 p.el.set_screen(Gdk.Screen.get_default());
1849 p.el.popup(null, null, null, null, 3, ev.button.time);
1850 //Seed.print("click:" + res.column.title);
1858 xtype: Gtk.TreeStore,
1862 getIterValue : function(iter, col) {
1863 var gval = new GObject.Value('');
1864 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
1865 return '' + gval.value;
1867 add : function(info) {
1868 // info includes key, val, skel, etype..
1870 type = info.type.toLowerCase();
1871 var data = this.toJS();
1873 if (info.etype == 'events') {
1874 data.listeners = data.listeners || { };
1875 if (typeof(data.listeners[info.key]) != 'undefined') {
1876 return; //already set!
1879 if (typeof(data[info.key]) != 'undefined') {
1884 if (typeof(info.val) == 'undefined') {
1887 if (info.type == 'boolean') {
1890 if (type == 'number') {
1898 if (info.etype == 'events') {
1900 data.listeners[info.key] = info.val;
1903 data[info.key] = info.val;
1907 var map = this.load(data);
1909 // flag it as changed to the interface..
1911 this.get('/LeftTree.model').changed(data, true);
1914 this.startEditing(map[k]);
1917 LeftPanel.get('view').el.row_activated(
1918 new Gtk.TreePath.from_string(map[k]),
1919 LeftPanel.editableColumn.el
1923 changed : function(str, doRefresh) {
1924 if (!this.activePath) {
1927 var iter = new Gtk.TreeIter();
1928 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
1930 this.el.set_value(iter, 1, '' +str);
1931 this.el.set_value(iter, 3, '' + this.toShort(str));
1932 var type = this.getIterValue(iter, 4);
1934 this.el.set_value(iter, 5, type + ' : ' + str);
1935 // update the tree...
1937 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
1939 deleteSelected : function() {
1940 var data = this.toJS();
1941 var iter = new Gtk.TreeIter();
1942 var s = this.get('/LeftPanel.view').selection;
1943 s.get_selected(this.el, iter);
1946 var gval = new GObject.Value('');
1947 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
1949 var val = gval.value;
1950 if (val[0] == '!') {
1952 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
1955 delete data.listeners[ val.substring(1)];
1956 if (!XObject.keys(data.listeners).length) {
1957 delete data.listeners;
1961 if (typeof(data[val]) == 'undefined') {
1969 this.get('/LeftTree.model').changed(data, true);
1972 editSelected : function(e) {
1973 print("EDIT SELECTED?");
1974 var iter = new Gtk.TreeIter();
1975 var s = this.get('/LeftPanel.view').selection;
1976 s.get_selected(this.get('/LeftPanel.model').el, iter);
1977 var m = this.get('/LeftPanel.model')
1979 var gval = new GObject.Value('');
1980 this.el.get_value(iter, 0 ,gval);
1981 var val = '' + gval.value;
1983 gval = new GObject.Value('');
1984 this.el.get_value(iter, 1 ,gval);
1985 var rval = gval.value;
1986 var activePath = this.el.get_path(iter).to_string();
1987 this.activePath = activePath ;
1988 // was activeIter...
1991 var showEditor = false;
1993 if (val[0] == '!') {
1996 if (val[0] == '|') {
1997 if (rval.match(/function/g) || rval.match(/\n/g)) {
2004 this.activePath = false;
2005 GLib.timeout_add(0, 1, function() {
2006 // Gdk.threads_enter();
2007 _this.get('/BottomPane').el.show();
2008 _this.get('/RightEditor').el.show();
2009 _this.get('/RightEditor.view').load( rval );
2013 _this.activePath = activePath ;
2015 // Gdk.threads_leave();
2020 this.get('/BottomPane').el.hide();
2021 this.get('/RightEditor').el.hide();
2023 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
2027 getType : function(treepath) {
2028 return this.getValue(treepath, 4);
2030 getValue : function(treepath_str, col) {
2031 var iter = new Gtk.TreeIter();
2032 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
2034 var gval = new GObject.Value('');
2035 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2036 var val = '' + gval.value;
2040 var type = this.getType(this.el.get_path(iter).to_string());
2041 print("TYPE: " +type + " - val:" + val);
2042 switch(type.toLowerCase()) {
2046 return parseFloat(val); // Nan ?? invalid!!?
2049 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2051 return val == 'true' ? true : false;
2053 var nv = parseFloat(val);
2054 if (!isNaN(nv) && (val == ''+nv)) {
2062 XObject.prototype.init.call(this);
2063 this.el.set_column_types ( 6, [
2064 GObject.TYPE_STRING, // 0 real key
2065 GObject.TYPE_STRING, // 1 real value
2066 GObject.TYPE_STRING, // 2 visable key
2067 GObject.TYPE_STRING, // 3 visable value
2068 GObject.TYPE_STRING, // 4 need to store type of!!!
2069 GObject.TYPE_STRING // 5 tooltip
2073 load : function(ar) {
2076 this.get('/RightEditor').el.hide();
2083 var provider = this.get('/LeftTree').getPaleteProvider();
2084 var iter = new Gtk.TreeIter();
2087 var keys = XObject.keys(ar);
2089 ar.listeners = ar.listeners || {};
2091 for (var i in ar.listeners ) {
2092 this.el.append(iter);
2093 var p = this.el.get_path(iter).to_string();
2096 this.el.set_value(iter, 0, '!'+ i );
2097 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2098 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2100 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2101 this.el.set_value(iter, 4, 'function');
2102 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2108 keys.forEach(function(i) {
2109 if (typeof(ar[i]) == 'object') {
2113 var type = provider.findType(ar, i, ar[i]);
2115 _this.el.append(iter);
2116 var p = _this.el.get_path(iter).to_string();
2118 _this.el.set_value(iter, 0, ''+i);
2119 _this.el.set_value(iter, 1, '' + ar[i]);
2120 _this.el.set_value(iter, 2, ''+i);
2121 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2122 _this.el.set_value(iter, 4, ''+type);
2123 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2127 startEditing : function(path,col) {
2129 * start editing path (or selected if not set..)
2130 * @param {String|false} path (optional) treepath to edit - selected tree gets
2131 * edited by default.
2132 * @param {Number} 0 or 1 (optional)- column to edit.
2135 if (typeof(path) == 'string') {
2136 tp = new Gtk.TreePath.from_string(path);
2138 var iter = new Gtk.TreeIter();
2139 var s = this.get('/LeftPanel.view').selection;
2140 s.get_selected(this.el, iter);
2141 tp = this.el.get_path(iter);
2142 path = tp.to_string();
2146 // which colum is to be edited..
2148 if (typeof(col) == 'undefined') {
2149 var k = this.getValue(path, 0);
2150 colObj = (!k.length || k == '|') ?
2151 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2153 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2156 // make sure the pulldown is set correctly..
2157 // not really needed for second col...
2159 var provider = this.get('/LeftTree').getPaleteProvider();
2161 var type = this.get('/LeftPanel.model').getType(path);
2162 var opts = provider.findOptions(type);
2163 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2165 if (opts === false) {
2166 this.get('/LeftPanel').editableColumn.setOptions([]);
2167 renderer.has_entry = true; /// probably does not have any effect.
2169 this.get('/LeftPanel').editableColumn.setOptions(opts);
2170 renderer.has_entry = false;
2174 // iter now has row...
2175 GLib.timeout_add(0, 100, function() {
2177 colObj.items[0].el.editable = true; // esp. need for col 0..
2178 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2188 var iter = new Gtk.TreeIter();
2189 this.get('/LeftPanel.model').el.get_iter_first(iter);
2194 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2197 ar.listeners = ar.listeners || {};
2198 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2201 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2204 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2210 //print(JSON.stringify(ar));
2214 toShort : function(str) {
2215 var a = typeof(str) == 'string' ? str.split("\n") : [];
2216 return a.length > 1 ? a[0] + '....' : '' + str;
2220 xtype: Gtk.TreeViewColumn,
2221 pack : "append_column",
2223 XObject.prototype.init.call(this);
2225 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2226 this.get('/LeftPanel').propertyColumn = this;
2231 xtype: Gtk.CellRendererText,
2232 pack : "pack_start",
2234 editing_started : function (self, editable, path) {
2236 this.get('/LeftPanel.model').activePath = path;
2239 edited : function (self, object, p0) {
2240 var model = this.get('/LeftPanel.model');
2241 var path = model.activePath;
2242 var iter = new Gtk.TreeIter();
2243 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2244 model.el.set_value(iter, 0, p0);
2245 model.el.set_value(iter, 2, p0);
2247 model.activePath = false;
2249 this.get('/LeftTree.model').changed(model.toJS(), true);
2250 this.el.editable = false;
2257 xtype: Gtk.TreeViewColumn,
2258 pack : "append_column",
2260 XObject.prototype.init.call(this);
2261 this.el.add_attribute(this.items[0].el , 'text', 3 );
2262 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2263 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2264 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2266 this.get('/LeftPanel').editableColumn= this;
2268 setOptions : function(ar) {
2269 var m = this.items[0].el.model;
2271 var iter = new Gtk.TreeIter();
2272 ar.forEach(function(i) {
2275 m.set_value(iter, 0, i);
2281 xtype: Gtk.CellRendererCombo,
2282 pack : "pack_start",
2287 XObject.prototype.init.call(this);
2288 this.el.model = new Gtk.ListStore();
2289 this.el.model.set_column_types ( 1, [
2290 GObject.TYPE_STRING // 0 real key
2294 edited : function (self, object, p0) {
2295 this.get('/LeftPanel').editing = false;
2296 print("EDITED? p:" + p0 + " t:" + p0);
2297 this.get('/LeftPanel.model').changed(p0, true);
2298 this.get('/LeftPanel.model').activePath = false;
2300 editing_started : function (self, editable, path) {
2301 this.get('/LeftPanel').editing = true;
2302 // console.log('editing started');
2303 // r.has_entry = false;
2304 this.get('/LeftPanel.model').editSelected(editable);
2315 id : "LeftPanelPopup",
2318 xtype: Gtk.MenuItem,
2322 activate : function (self) {
2323 this.get('/LeftPanel.model').deleteSelected();
2328 xtype: Gtk.MenuItem,
2332 activate : function (self) {
2333 this.get('/LeftPanel.model').startEditing(false, 0);
2346 xtype: Gtk.ScrolledWindow,
2347 pack : "pack_end,false,true,0",
2349 shadow_type : Gtk.ShadowType.IN,
2351 XObject.prototype.init.call(this);
2352 XObject.prototype.init.call(this);
2353 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2354 this.el.set_size_request ( 150, -1 );
2357 activeElement : false,
2358 hideWin : function() {
2365 if (this.get('/Window.left').el.position < 160) {
2368 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2375 xtype: Gtk.TreeView,
2376 enable_tree_lines : true,
2377 headers_visible : false,
2380 XObject.prototype.init.call(this);
2382 var description = new Pango.FontDescription.c_new();
2383 description.set_size(8000);
2384 this.el.modify_font(description);
2386 //this.selection = this.el.get_selection();
2387 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2396 cursor_changed : function (self) {
2397 var iter = new Gtk.TreeIter();
2399 //console.log('changed');
2400 var m = this.get('model');
2401 if (!this.selection){
2402 this.selection = this.el.get_selection();
2405 var s = this.selection;
2406 if (!s.get_selected(m.el, iter)) {
2409 var tp = m.el.get_path(iter).to_string();
2414 var key = m.getValue(tp, 0);
2416 var type = m.getValue(tp, 1);
2417 var skel = m.getValue(tp, 3);
2418 var etype = m.getValue(tp, 5);
2421 this.get('/MidPropTree').hideWin();
2423 if (type == 'function') {
2425 if (etype != 'events') {
2429 this.get('/LeftPanel.model').add({
2438 if (type.indexOf('.') > -1 ||
2439 type == 'boolean') {
2443 this.get('/LeftPanel.model').add( {
2453 xtype: Gtk.ListStore,
2456 XObject.prototype.init.call(this);
2457 this.el.set_column_types ( 6, [
2458 GObject.TYPE_STRING, // real key
2459 GObject.TYPE_STRING, // real type
2460 GObject.TYPE_STRING, // docs ?
2461 GObject.TYPE_STRING, // visable desc
2462 GObject.TYPE_STRING, // function desc
2463 GObject.TYPE_STRING // element type (event|prop)
2467 getValue : function(treepath, col)
2469 var tp = new Gtk.TreePath.from_string (treepath);
2470 var iter = new Gtk.TreeIter();
2471 this.el.get_iter (iter, tp);
2472 var value = new GObject.Value('');
2473 this.el.get_value(iter, col, value);
2477 showData : function(type) {
2479 if (!this.get('/MidPropTree').activeElement || !type) {
2480 return; // no active element
2483 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2484 var palete = this.get('/LeftTree').getPaleteProvider();
2488 Seed.print('Showing right?');
2489 if (!this.get('/MidPropTree').shown) {
2491 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2492 this.get('/MidPropTree').el.show();
2493 this.get('/MidPropTree').shown = true;
2496 var elementList = palete.getPropertiesFor(fullpath, type);
2497 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2498 // console.dump(elementList);
2501 var iter = new Gtk.TreeIter();
2502 for(var i =0 ; i < elementList.length; i++) {
2503 var p=elementList[i];
2504 this.el.append(iter);
2505 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2506 //GObject.TYPE_STRING, // real key
2507 // GObject.TYPE_STRING, // real type
2508 // GObject.TYPE_STRING, // docs ?
2509 // GObject.TYPE_STRING // func def?
2512 this.el.set_value(iter, 0, p.name);
2513 this.el.set_value(iter, 1, p.type);
2514 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2515 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2516 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2517 this.el.set_value(iter, 5, type);
2525 xtype: Gtk.TreeViewColumn,
2527 this.el = new Gtk.TreeViewColumn();
2528 this.parent.el.append_column(this.el);
2530 XObject.prototype.init.call(this);
2531 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2536 xtype: Gtk.CellRendererText,
2537 pack : "pack_start,true"
2561 xtype: Gtk.Notebook,
2562 pack : "pack_start,true,true",
2563 id : "view-help-nb",
2565 XObject.prototype.init.call(this);
2566 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2567 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2571 xtype: Gtk.Notebook,
2573 id : "view-notebook",
2576 XObject.prototype.init.call(this);
2577 this.el.set_current_page(0);
2579 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2580 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2587 id : "RightBrowser",
2594 pack : "pack_start,false,true,0",
2598 pack : "pack_start,false,false,0",
2601 button_press_event : function (self, event) {
2602 var js = this.get('/LeftTree.model').toJS();
2604 this.get('/RightBrowser.view').renderJS(js[0]);
2613 button_press_event : function (self, event) {
2614 this.get('/RooProjectProperties').show();
2618 label : "Set extra HTML in renderer",
2619 pack : "pack_start,false,false,0"
2624 button_press_event : function (self, event)
2626 /* Firefox testing for debugging..
2627 - we can create a /tmp directory, and put.
2628 builder.html, builder.html.js, link roojs1
2629 add at the end of builder.html Roo.onload(function() {
2631 if (!this.get('/Window.LeftTree').getActiveFile()) {
2635 var js = this.get('/LeftTree.model').toJS();
2636 if (!js || !js[0]) {
2639 var project = this.get('/Window.LeftTree').getActiveFile().project;
2640 //print (project.fn);
2642 project.runhtml = project.runhtml || '';
2645 var File = imports.File.File;
2647 var target = "/tmp/firetest"; // fixme..
2648 if (!File.isDirectory(target)) {
2651 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
2652 if (!File.exists( target+ '/roojs1')) {
2653 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
2658 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2659 html = html.replace('</head>', project.runhtml + '</head>');
2662 var jsstr = JSON.stringify(js[0]);
2664 var runbuilder = '<script type="text/javascript">' + "\n" +
2665 " Builder.render(" + jsstr + ");\n" +
2668 html = html.replace('</body>', runbuilder + '</body>');
2670 File.write( target+ '/builder.html', html);
2672 this.get('/Terminal').feed("RUN DIR:" + target);
2674 this.get('/Terminal').el.fork_command( null , [], [], target
2675 , false,false,false);
2676 var cmd = "firefox file://" + target + "/builder.html \n";
2677 this.get('/Terminal').el.feed_child(cmd, cmd.length);
2681 label : "Test in Firefox",
2682 pack : "pack_start,false,false,0"
2687 xtype: Gtk.ScrolledWindow,
2689 shadow_type : Gtk.ShadowType.IN,
2691 XObject.prototype.init.call(this);
2692 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2696 xtype: WebKit.WebView,
2700 XObject.prototype.init.call(this);
2701 // this may not work!?
2702 this.el.open('file:///' + __script_path__ + '/../builder.html');
2706 this.el, /* widget that will accept a drop */
2707 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2708 null, /* lists of target to support */
2709 0, /* size of list */
2710 Gdk.DragAction.COPY /* what to do with data after dropped */
2713 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2714 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2716 renderJS : function(data) {
2717 print("HTML RENDERING");
2718 /// prevent looping..
2719 //if (this.pendingRedraw) {
2720 // print("pending redraw active?!");
2725 if (!this.get('/Window.LeftTree').getActiveFile()) {
2729 var project = this.get('/Window.LeftTree').getActiveFile().project;
2730 //print (project.fn);
2732 project.runhtml = project.runhtml || '';
2735 this.runhtml = this.runhtml || '';
2737 if (project.runhtml != this.runhtml) {
2738 // then we need to reload the browser using
2739 // load_html_string..
2741 // then trigger a redraw once it's loaded..
2742 this.pendingRedraw = true;
2744 this.runhtml = project.runhtml;
2746 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2747 html = html.replace('</head>', this.runhtml + '</head>');
2748 print("LOAD HTML " + html);
2749 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2750 // should trigger load_finished!
2755 this.pendingRedraw = false;
2758 this.renderedData = data;
2759 var str = JSON.stringify(data) ;
2762 console.log('not loaded yet');
2764 //Seed.print("RENDER:" + str);
2765 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2767 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2770 load_finished : function (self, object) {
2771 // if (this.ready) { // dont do it twice!
2775 this.pendingRedraw = false;
2776 var js = this.get('/LeftTree.model').toJS();
2778 this.renderJS(js[0]);
2782 script_alert : function (self, object, p0) {
2785 return true; // do not display anything...
2787 console_message : function (self, object, p0, p1) {
2788 // console.log(object);
2789 if (!object.match(/^\{/)) {
2791 this.get('/Terminal').feed(object);
2792 return true; // do not handle!!! -> later maybe in console..
2794 // console.log(object);
2795 var val = JSON.parse(object);
2797 if (typeof(val['hover-node']) != 'undefined') {
2798 this.activeNode = val['hover-node'];
2799 console.log('active node: ' + this.activeNode);
2804 if (typeof(val['id']) != 'undefined') {
2805 // this.activeNode = val['id'];
2806 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2810 this.get('/LeftTree.view').selectNode(tg[0]);
2814 if (ret && typeof(val['set']) != 'undefined') {
2815 this.get('/LeftPanel.model').add({
2819 //console.log('active node: ' + this.activeNode);
2822 //Seed.print('a:'+a);
2823 //Seed.print('b:'+b);
2824 //Seed.print('c:'+c);
2827 drag_motion : function (w, ctx, x, y, time, ud) {
2828 // console.log('DRAG MOTION');
2830 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2831 this.targetData = [];
2832 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2834 // A) find out from drag all the places that node could be dropped.
2835 var src = Gtk.drag_get_source_widget(ctx);
2836 if (!src.dropList) {
2837 Gdk.drag_status(ctx, 0, time);
2840 // b) get what we are over.. (from activeNode)
2841 // tree is empty.. - list should be correct..
2842 if (!this.get('/LeftTree.model').currentTree) {
2843 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2847 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2849 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2852 Gdk.drag_status(ctx, 0,time);
2853 this.get('/LeftTree.view').highlight(false);
2857 // if we have a target..
2858 // -> highlight it! (in browser)
2859 // -> highlight it! (in tree)
2861 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2862 this.get('/LeftTree.view').highlight(tg);
2863 this.targetData = tg;
2864 // for tree we should handle this...
2867 drag_drop : function (w, ctx, x, y,time, ud) {
2868 print("TARGET: drag-drop");
2869 var is_valid_drop_site = true;
2874 w, /* will receive 'drag-data-received' signal */
2875 ctx, /* represents the current state of the DnD */
2876 this.get('/Window').atoms["STRING"], /* the target type we want */
2877 time /* time stamp */
2881 /* No target offered by source => error */
2884 return is_valid_drop_site;
2886 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2888 print("Browser: drag-data-received");
2889 var delete_selection_data = false;
2890 vardnd_success = false;
2891 /* Deal with what we are given from source */
2892 if( sel_data && sel_data.length ) {
2894 if (ctx.action == Gdk.DragAction.ASK) {
2895 /* Ask the user to move or copy, then set the ctx action. */
2898 if (ctx.action == Gdk.DragAction.MOVE) {
2899 delete_selection_data = true;
2901 var source = Gtk.drag_get_source_widget(ctx);
2903 print("Browser: source.DRAGDATA? " + source.dragData);
2904 if (this.targetData) {
2905 print(this.targetData);
2906 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2915 if (dnd_success == false)
2917 Seed.print ("DnD data transfer failed!\n");
2920 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2931 id : "RightGtkView",
2933 redraw : function() {
2934 this.highlightWidget = false;
2935 print("REDRAW CALLED");
2936 this.activePath = this.get('/LeftTree').getActivePath();
2937 if (this.renderedEl) {
2938 print("QUEUE DRAW CALLING");
2939 this.renderedEl.queue_draw();
2942 renderJS : function(data, withDebug)
2944 this.highlightWidget = false;
2948 this.withDebug = false;
2950 if (this.renderedEl) {
2951 this.get('view').el.remove(this.renderedEl);
2952 this.renderedEl.destroy();
2953 this.renderedEl = false;
2956 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
2957 // in theory tree is actually window..
2959 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
2964 this.get('view').el.set_size_request(
2965 tree.default_width * 1 || 400, tree.default_height * 1 || 400
2968 this.renderedEl.set_size_request(
2969 tree.default_width || 600,
2970 tree.default_height || 400
2972 this.get('view').el.show_all();
2977 showInWindow : function() {
2978 print("GET PROEJCT");
2979 var pr = this.get('/LeftProjectTree').getActiveProject();
2981 console.log(pr.paths);
2984 var src= this.buildJS(
2985 this.get('/LeftTree.model').toJS()[0],
2990 //var x = new imports.sandbox.Context();
2994 Seed.check_syntax('var e = ' + src);
2997 this.get('/Terminal').feed(e.message || e.toString() + "\n");
2998 this.get('/Terminal').feed(console._dump(e)+"\n");
3000 var lines = src.split("\n");
3001 var start = Math.max(0, e.line - 10);
3002 var end = Math.min(lines.length, e.line + 10);
3003 for (var i =start ; i < end; i++) {
3005 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
3008 this.get('/Terminal').feed(lines[i] + "\n");
3015 this.get('/BottomPane').el.set_current_page(1);
3016 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
3017 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
3018 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3020 var _top = x.get_global_object()._top;
3022 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
3024 if (_top.el.popup) {
3025 _top.el.popup(null, null, null, null, 3, null);
3029 viewAdd : function(item, par)
3031 // does something similar to xobject..
3032 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
3034 if (item.pack===false || item.pack === 'false') { // no ;
3037 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3038 var type = item['|xns'] + '.' + item['xtype'];
3039 var ns = imports.gi[item['|xns']];
3040 var ctr = ns[item['xtype']];
3042 for(var k in item) {
3044 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3059 if (k[0] == '|' && typeof(kv) == 'string') {
3061 if (kv.match(new RegExp('function'))) {
3064 print("WASL " + k + '=' + kv);
3066 eval( 'kv = ' + kv);
3067 } catch(e) { continue; }
3070 // print(k + '=' + kv);
3072 if (k[0] == '|') { // should be boolean or number..
3074 //print(k + '=' + kv);
3077 if (k == 'show_tabs') { // force tab showing for notebooks.
3080 print(k + '=' + typeof(kv) + " : " + kv);
3086 var el = new ctr(ctr_args);
3088 print("PACK" + item.pack);
3089 //console.dump(item.pack);
3096 if (typeof(item.pack) == 'string') {
3098 item.pack.split(',').forEach(function(e, i) {
3100 if (e == 'false') { args.push( false); return; }
3101 if (e == 'true') { args.push( true); return; }
3102 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3105 //print(args.join(","));
3107 pack_m = args.shift();
3109 pack_m = item.pack.shift();
3114 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3116 name: "ArgumentError",
3117 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3118 "ADDING : " + item.id + " " + el
3127 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3128 //Seed.print('args: ' + args.length);
3130 par[pack_m].apply(par, args);
3134 item.items = item.items || [];
3135 item.items.forEach(function(ch,n) {
3137 print ("type:" + type);
3139 print ("ch.pack:" + ch.pack);
3140 if (type == 'Gtk.Table' && ch.pack == 'add') {
3141 var c = n % item.n_columns;
3142 var r = Math.floor(n/item.n_columns);
3143 ch.pack = [ 'attach', c, c+1, r, r+1,
3144 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3145 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3146 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3147 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3151 _this.viewAdd(ch, el);
3156 // add the signal handlers.
3157 // is it a widget!?!!?
3163 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3164 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3165 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3166 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3167 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3177 widgetDragDropEvent : function() {
3178 print("WIDGET DRAGDROP");
3181 widgetDragMotionEvent : function() {
3182 print("WIDGET DRAGMOTION");
3185 widgetExposeEvent : function(w, evt, ud, item) {
3187 if (this.inRender) {
3191 if ( this.highlightWidget) {
3192 this.inRender = true;
3193 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3194 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3196 this.inRender = false;
3201 if (this.activePath != item.xtreepath) {
3205 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3206 // work out the coords of the window..
3208 var dr = widget.window;
3209 this.gc = (new Gdk.GC.c_new(dr));
3210 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3211 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3215 var r = evt.expose.area;
3216 // console.dump([r.x, r.y, r.width, r.height ] );
3218 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3219 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3220 // happens with gtkscrollview embedded stuff..
3221 var np =this.activePath.split(':');
3223 this.activePath = np.join(':');
3224 this.renderedEl.queue_draw();
3240 this.inRender = true;
3243 this.highlightWidget = widget;
3248 // print("DRAW BOX");
3249 //console.dump(this.box);
3250 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3251 this.inRender = false;
3254 widgetPressEvent : function(w,e,u,d) {
3255 if (this.get('view').pressed) {
3258 this.get('view').pressed = true;
3259 print("WIDGET PRESS " + d.xtreepath );
3260 this.get('/LeftTree.view').selectNode( d.xtreepath );
3263 widgetReleaseEvent : function() {
3264 this.get('view').pressed = false;
3270 pack : "pack_start,false,true,0",
3274 pack : "pack_start,false,false,0",
3275 label : "Run The Application",
3277 button_press_event : function (self, event) {
3278 // call render on left tree - with special option!?!
3280 //print("GET PROEJCT");
3281 var pr = this.get('/LeftProjectTree').getActiveProject();
3284 for (var i in pr.paths) {
3288 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3289 this.get('/Terminal').feed("RUN DIR:" + dir);
3291 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3292 , false,false,false);
3293 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3294 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3304 xtype: Gtk.ScrolledWindow,
3307 shadow_type : Gtk.ShadowType.IN,
3309 XObject.prototype.init.call(this);
3310 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3314 xtype: Gtk.EventBox,
3315 pack : "add_with_viewport",
3317 XObject.prototype.init.call(this);
3318 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3319 red: 0x9F00, green: 0xB800 , blue : 0xA800
3327 XObject.prototype.init.call(this);
3328 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3329 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3334 xtype: Gtk.EventBox,
3337 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3338 XObject.prototype.init.call(this);
3342 this.el, /* widget that will accept a drop */
3343 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3344 null, /* lists of target to support */
3345 0, /* size of list */
3346 Gdk.DragAction.COPY /* what to do with data after dropped */
3349 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3350 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3353 getActiveNode : function(x,y)
3355 // workout what node is here..
3356 return '0'; // top..
3360 drag_motion : function (self, ctx, x, y, time) {
3362 // A) find out from drag all the places that node could be dropped.
3363 var src = Gtk.drag_get_source_widget(ctx);
3364 if (!src.dropList) {
3365 Gdk.drag_status(ctx, 0, time);
3368 // b) get what we are over.. (from activeNode)
3369 // tree is empty.. - list should be correct..
3370 if (!this.get('/LeftTree.model').currentTree) {
3371 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3375 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3376 var activeNode = this.getActiveNode(x, y);
3379 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3382 Gdk.drag_status(ctx, 0,time);
3383 this.get('/LeftTree.view').highlight(false);
3387 // if we have a target..
3388 // -> highlight it! (in browser)
3389 // -> highlight it! (in tree)
3391 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3392 this.get('/LeftTree.view').highlight(tg);
3393 this.targetData = tg;
3394 // for tree we should handle this...
3397 drag_drop : function (self,ctx, x, y, time) {
3398 Seed.print("TARGET: drag-drop");
3399 var is_valid_drop_site = true;
3404 self, /* will receive 'drag-data-received' signal */
3405 ctx, /* represents the current state of the this.gDnD */
3406 this.get('/Window').atoms["STRING"], /* the target type we want */
3407 time /* time stamp */
3411 /* No target offered by source => error */
3414 return is_valid_drop_site;
3417 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3419 Seed.print("GtkView: drag-data-received");
3420 var delete_selection_data = false;
3421 var dnd_success = false;
3422 /* Deal with what we are given from source */
3423 if( sel_data && sel_data.length ) {
3425 if (ctx.action == Gdk.DragAction.ASK) {
3426 /* Ask the user to move or copy, then set the ctx action. */
3429 if (ctx.action == Gdk.DragAction.MOVE) {
3430 delete_selection_data = true;
3432 var source = Gtk.drag_get_source_widget(ctx);
3434 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3435 if (this.targetData) {
3436 Seed.print(this.targetData);
3437 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3446 if (dnd_success == false)
3448 Seed.print ("DnD data transfer failed!\n");
3451 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3454 button_press_event : function (self, event) {
3455 this.pressed = false;
3471 xtype: Gtk.ScrolledWindow,
3476 var file = this.get('/LeftTree').getActiveFile();
3480 var activeEl = this.get('/LeftTree').getActiveElement();
3481 var xtype = file.guessName( activeEl )
3482 if (!xtype || !xtype.length) {
3485 this.get('/Window.view-help-nb').el.set_current_page(1);
3487 // get the active element being edited.
3488 var helpurl = file.getHelpUrl(xtype);
3490 // now load the help info in the page..
3491 this.get('help-view').el.open(helpurl);
3495 xtype: WebKit.WebView,
3499 XObject.prototype.init.call(this);
3500 this.get('/Window.help-view').el.open(
3501 "http://devel.akbkhome.com/seed/");
3513 xtype: Gtk.Notebook,
3516 XObject.prototype.init.call(this);
3517 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3518 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3523 xtype: Gtk.ScrolledWindow,
3528 xtype: GtkSource.View,
3532 XObject.prototype.init.call(this);
3533 var description = Pango.Font.description_from_string("monospace")
3534 description.set_size(8000);
3535 this.el.modify_font(description);
3538 load : function(str) {
3540 // show the help page for the active node..
3541 this.get('/Help').show();
3544 this.get('/BottomPane').el.set_current_page(0);
3545 this.el.get_buffer().set_text(str, str.length);
3546 var lm = GtkSource.LanguageManager.get_default();
3548 this.el.get_buffer().set_language(lm.get_language('js'));
3549 var buf = this.el.get_buffer();
3550 var cursor = buf.get_mark("insert");
3551 var iter= new Gtk.TextIter;
3552 buf.get_iter_at_mark(iter, cursor);
3554 iter.set_line_offset(4);
3555 buf.move_mark(cursor, iter);
3558 cursor = buf.get_mark("selection_bound");
3559 iter= new Gtk.TextIter;
3560 buf.get_iter_at_mark(iter, cursor);
3562 iter.set_line_offset(4);
3563 buf.move_mark(cursor, iter);
3565 this.el.grab_focus();
3567 insert_spaces_instead_of_tabs : true,
3570 show_line_numbers : true,
3573 xtype: GtkSource.Buffer,
3574 pack : "set_buffer",
3576 changed : function (self) {
3577 var s = new Gtk.TextIter();
3578 var e = new Gtk.TextIter();
3579 this.el.get_start_iter(s);
3580 this.el.get_end_iter(e);
3581 var str = this.el.get_text(s,e,true);
3583 Seed.check_syntax('var e = ' + str);
3585 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3586 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3588 print("SYNTAX ERROR IN EDITOR");
3593 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3594 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3597 this.get('/LeftPanel.model').changed( str , false);
3606 xtype: Gtk.ScrolledWindow,
3610 xtype: Vte.Terminal,
3613 feed : function(istr) {
3614 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3615 // we should make ourselves visable!!!
3616 this.get('/BottomPane').el.show();
3617 this.get('/BottomPane').el.set_current_page(1);
3619 this.el.feed(str ,str.length);
3621 scroll_on_output : true,
3623 XObject.prototype.init.call(this);
3624 this.el.set_size (80, 1000);
3626 scrollback_lines : 1000
3636 pack : "pack_start,false,false",
3640 this.get('buttonbar').el.show();
3641 this.get('viewbox').el.hide();
3642 print("TRIED TO HIDE");
3645 this.get('buttonbar').el.hide();
3646 this.get('viewbox').el.show();
3647 // this.get('model').expanded();
3659 pack : "pack_start,false,true",
3661 clicked : function (self) {
3662 this.get('/RightPalete').show();
3669 stock : Gtk.STOCK_GOTO_FIRST,
3670 icon_size : Gtk.IconSize.MENU
3680 XObject.prototype.init.call(this);
3681 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3684 enter_notify_event : function (self, event) {
3685 this.get('/RightPalete').show();
3699 pack : "pack_start,false,true",
3708 pack : "pack_start,false,true",
3710 clicked : function (self) {
3711 this.get('/RightPalete').hide();
3718 stock : Gtk.STOCK_GOTO_LAST,
3719 icon_size : Gtk.IconSize.MENU
3726 xtype: Gtk.ScrolledWindow,
3729 XObject.prototype.init.call(this);
3730 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3731 this.el.set_size_request(-1,200);
3733 shadow_type : Gtk.ShadowType.IN,
3736 xtype: Gtk.TreeView,
3739 XObject.prototype.init.call(this);
3740 this.el.set_size_request(150,-1);
3741 // set_reorderable: [1]
3743 var description = new Pango.FontDescription.c_new();
3744 description.set_size(8000);
3745 this.el.modify_font(description);
3747 this.selection = this.el.get_selection();
3748 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3749 // this.selection.signal['changed'].connect(function() {
3750 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3752 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3754 Gtk.drag_source_set (
3755 this.el, /* widget will be drag-able */
3756 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3757 null, /* lists of target to support */
3758 0, /* size of list */
3759 Gdk.DragAction.COPY /* what to do with data after dropped */
3761 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3763 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3764 Gtk.drag_source_add_text_targets(this.el);
3766 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3767 targets = new Gtk.TargetList();
3768 targets.add( LeftTree.atoms["STRING"], 0, 0);
3769 targets.add_text_targets( 1 );
3770 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3772 //if you want to allow text to be output elsewhere..
3773 //Gtk.drag_source_add_text_targets(this.el);
3777 headers_visible : false,
3778 enable_tree_lines : true,
3780 drag_begin : function (self, ctx) {
3781 // we could fill this in now...
3782 Seed.print('SOURCE: drag-begin');
3786 var iter = new Gtk.TreeIter();
3787 var s = this.selection;
3788 s.get_selected(this.get('/RightPalete.model').el, iter);
3789 var path = this.get('/RightPalete.model').el.get_path(iter);
3791 var pix = this.el.create_row_drag_icon ( path);
3794 Gtk.drag_set_icon_pixmap (ctx,
3801 var value = new GObject.Value('');
3802 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3803 if (!this.get('/RightPalete').provider) {
3806 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3807 this.el.dragData = value.value;
3814 drag_data_get : function (self, drag_context, selection_data, info, time) {
3815 //Seed.print('Palete: drag-data-get: ' + target_type);
3816 if (this.el.dragData && this.el.dragData.length ) {
3817 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3821 //this.el.dragData = "TEST from source widget";
3825 drag_end : function (self, drag_context) {
3826 Seed.print('SOURCE: drag-end');
3827 this.el.dragData = false;
3828 this.el.dropList = false;
3829 this.get('/LeftTree.view').highlight(false);
3835 xtype: Gtk.ListStore,
3838 XObject.prototype.init.call(this);
3839 this.el.set_column_types ( 2, [
3840 GObject.TYPE_STRING, // title
3841 GObject.TYPE_STRING // tip
3846 load : function(tr,iter)
3851 //console.log('Project tree load: ' + tr.length);
3852 var citer = new Gtk.TreeIter();
3853 //this.insert(citer,iter,0);
3854 for(var i =0 ; i < tr.length; i++) {
3857 this.el.append(citer);
3859 this.el.insert(citer,iter,-1);
3864 this.el.set_value(citer, 0, '' + r ); // title
3866 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3867 //if (r.cn && r.cn.length) {
3868 // this.load(r.cn, citer);
3874 getValue : function (iter, col) {
3875 var gval = new GObject.Value('');
3876 this.el.get_value(iter, col ,gval);
3883 xtype: Gtk.TreeViewColumn,
3884 pack : "append_column",
3886 XObject.prototype.init.call(this);
3887 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3891 xtype: Gtk.CellRendererText,
3913 XObject.cache['/Window'] = Window;