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,
166 pack : "set_submenu",
175 use_underline : true,
177 activate : function (self) {
178 this.get('/About').el.run();
207 label : "Select Project",
209 pack : "pack_start,false,true",
211 XObject.prototype.init.call(this);
212 this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
215 activate : function (self) {
216 var nb = this.get('/LeftTopPanel.notebook');
217 if (this.el.expanded) {
220 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
223 var model = this.get('/LeftProjectTree.combomodel');
224 // print ("loading Projects?")
225 //console.dump(pm.projects);
226 model.loadData(pm.projects);
229 nb.el.set_current_page(1);
230 //pm.on('changed', function() {
231 //console.log("CAUGHT project manager change");
232 // _combo.model.loadData(pm.projects);
236 nb.el.set_current_page(0);
238 enter_notify_event : function (self, event) {
239 this.el.expanded = !this.el.expanded;
240 //if (this.el.expanded ) {
241 this.listeners.activate.call(this);
253 pack : "pack_start,true,true",
255 XObject.prototype.init.call(this);
256 this.el.set_current_page(0);
261 xtype: Gtk.ScrolledWindow,
263 shadow_type : Gtk.ShadowType.IN,
265 XObject.prototype.init.call(this);
266 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
269 getPaleteProvider : function() {
270 var model = this.get('model');
271 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
272 return pm.getPalete(model.file.getType());
274 renderView : function() {
275 var render = this.getRenderer();
276 var model = this.get('model');
278 render.renderJS(model.toJS(false,true)[0]);
280 print("NO RENDER JS METHOD?");
283 getRenderer : function() {
285 switch( this.getActiveFile().getType()) {
287 return this.get('/RightBrowser.view');
289 return this.get('/RightGtkView');
293 getActivePath : function() {
294 var model = this.get('model');
295 var view = this.get('view');
296 if (view.selection.count_selected_rows() < 1) {
299 var iter = new Gtk.TreeIter();
301 view.selection.get_selected(model.el, iter);
302 return model.el.get_path(iter).to_string();
304 getActiveFile : function() {
305 return this.get('model').file;
307 getActiveElement : function() {
309 var path = this.getActivePath();
313 var iter = new Gtk.TreeIter();
314 this.get('model').el.get_iter_from_string(iter, path);
316 var value = new GObject.Value('');
317 this.get('model').el.get_value(iter, 2, value);
319 return JSON.parse(value.value);
326 headers_visible : false,
327 enable_tree_lines : true,
330 XObject.prototype.init.call(this);
331 var description = new Pango.FontDescription.c_new();
332 description.set_size(8000);
333 this.el.modify_font(description);
335 this.selection = this.el.get_selection();
336 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
339 // is this really needed??
340 this.selection.signal['changed'].connect(function() {
341 _this.get('/LeftTree.view').listeners.cursor_changed.apply(
342 _this.get('/LeftTree.view'), [ _this.get('/LeftTree.view'), '']
346 Gtk.drag_source_set (
347 this.el, /* widget will be drag-able */
348 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
349 null, /* lists of target to support */
350 0, /* size of list */
351 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
354 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
356 Gtk.drag_source_add_text_targets(this.el);
359 this.el, /* widget that will accept a drop */
360 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
361 null, /* lists of target to support */
362 0, /* size of list */
363 Gdk.DragAction.COPY | Gdk.DragAction.MOVE /* what to do with data after dropped */
366 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
367 Gtk.drag_dest_add_text_targets(this.el);
369 highlight : function(treepath_ar) {
371 // highlighting for drag/drop
372 if (treepath_ar.length && treepath_ar[0].length ) {
373 this.el.set_drag_dest_row(
374 new Gtk.TreePath.from_string( treepath_ar[0] ), treepath_ar[1]);
376 this.el.set_drag_dest_row(null, Gtk.TreeViewDropPosition.INTO_OR_AFTER);
380 selectNode : function(treepath_str) {
381 //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str));
382 var tp = new Gtk.TreePath.from_string(treepath_str);
383 this.el.set_cursor(tp, null, false);
384 this.el.scroll_to_cell(tp, null, false, 0,0);
387 button_press_event : function (self, ev) {
388 console.log("button press?");
389 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
390 print("click" + ev.type);
396 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
398 if (!this.get('/LeftTreeMenu').el) this.get('/LeftTreeMenu').init();
400 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
401 this.get('/LeftTreeMenu').el.show_all();
402 this.get('/LeftTreeMenu').el.popup(null, null, null, null, 3, ev.button.time);
403 print("click:" + res.path.to_string());
406 drag_begin : function (self, drag_context) {
407 print('SOURCE: drag-begin');
408 this.targetData = false;
409 // find what is selected in our tree...
410 var iter = new Gtk.TreeIter();
411 var s = this.selection;
412 s.get_selected(this.get('/LeftTree.model').el, iter);
414 // set some properties of the tree for use by the dropped element.
415 var value = new GObject.Value('');
416 this.get('/LeftTree.model').el.get_value(iter, 2, value);
417 var data = JSON.parse(value.value);
418 var xname = this.get('/LeftTree.model').file.guessName(data);
420 this.el.dragData = xname;
421 this.el.dropList = this.get('/LeftTree').getPaleteProvider().getDropList(xname);
424 // make the drag icon a picture of the node that was selected
425 var path = this.get('/LeftTree.model').el.get_path(iter);
426 this.el.treepath = path.to_string();
428 var pix = this.el.create_row_drag_icon ( path);
430 Gtk.drag_set_icon_pixmap (ctx,
439 drag_end : function (self, drag_context) {
440 Seed.print('LEFT-TREE: drag-end');
441 this.el.dragData = false;
442 this.el.dropList = false;
443 this.targetData = false;
444 this.get('/LeftTree.view').highlight(false);
447 drag_motion : function (self, ctx, x, y, time) {
448 console.log("LEFT-TREE: drag-motion");
449 var src = Gtk.drag_get_source_widget(ctx);
451 // a drag from elsewhere...- prevent drop..
453 print("no drag data!");
454 Gdk.drag_status(ctx, 0, time);
455 this.targetData = false;
458 var action = Gdk.DragAction.COPY;
459 if (src == this.el) {
460 // unless we are copying!!! ctl button..
461 action = ctx.actions & Gdk.DragAction.MOVE ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
465 if (!this.get('/LeftTree.model').el.iter_n_children(null)) {
466 // no children.. -- asume it's ok..
467 this.targetData = [ '' , Gtk.TreeViewDropPosition.INTO_OR_AFTER , ''];
468 Gdk.drag_status(ctx, action ,time);
472 print("GETTING POS");
473 var isOver = this.get('/LeftTree.view').el.get_dest_row_at_pos(x,y, data);
474 print("ISOVER? " + isOver);
476 Gdk.drag_status(ctx, 0 ,time);
477 return false; // not over apoint!?!
479 // drag node is parent of child..
480 console.log("SRC TREEPATH: " + src.treepath);
481 console.log("TARGET TREEPATH: " + data.path.to_string());
483 // nned to check a few here..
484 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
485 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
486 //Gtk.TreeViewDropPosition.AFTER
487 //Gtk.TreeViewDropPosition.BEFORE
489 if (typeof(src.treepath) != 'undefined' &&
490 src.treepath == data.path.to_string().substring(0,src.treepath.length)) {
491 print("subpath drag");
492 Gdk.drag_status(ctx, 0 ,time);
497 //print("DUMPING DATA");
498 //console.dump(data);
501 print(data.path.to_string() +' => '+ data.pos);
502 var tg = this.get('/LeftTree.model').findDropNodeByPath(
503 data.path.to_string(), src.dropList, data.pos);
505 this.get('/LeftTree.view').highlight(tg);
507 print("Can not find drop node path");
508 this.targetData = false;
509 Gdk.drag_status(ctx, 0, time);
513 this.targetData = tg;
516 Gdk.drag_status(ctx, action ,time);
520 drag_drop : function (w, ctx, x, y, time) {
521 Seed.print("TARGET: drag-drop");
525 w, /* will receive 'drag-data-received' signal */
526 ctx, /* represents the current state of the DnD */
527 this.get('/Window').atoms["STRING"], /* the target type we want */
528 time /* time stamp */
532 /* No target offered by source => error */
537 drag_data_received : function (self, ctx, x, y, sel_data, info, time) {
538 print("Tree: drag-data-received");
540 var delete_selection_data = false;
541 var dnd_success = false;
542 /* Deal with what we are given from source */
543 if( sel_data && sel_data.length ) {
545 if (ctx.action == Gdk.DragAction.ASK) {
546 /* Ask the user to move or copy, then set the ctx action. */
549 if (ctx.action == Gdk.DragAction.MOVE) {
550 //delete_selection_data = true;
553 var source = Gtk.drag_get_source_widget(ctx);
555 if (this.targetData) {
556 if (source != this.el) {
557 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
559 // drag around.. - reorder..
560 this.get('/LeftTree.model').moveNode(this.targetData, ctx.action);
564 //Seed.print(this.targetData);
570 // we can send stuff to souce here...
576 if (dnd_success == false)
578 Seed.print ("DnD data transfer failed!\n");
581 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
584 cursor_changed : function (self) {
585 if (this.blockChanges) { // probably not needed..
588 var render = this.get('/LeftTree').getRenderer();
591 if (this.selection.count_selected_rows() < 1) {
592 this.get('/LeftPanel.model').load( false);
593 this.get('/MidPropTree').activeElement = false;
594 this.get('/MidPropTree').hideWin();
596 var pm = this.get('/RightPalete.model');
597 if (!this.get('/LeftTree').getPaleteProvider()) {
598 // it may not be loaded yet..
601 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(
602 this.get('/LeftTree.model').listAllTypes()));
603 if (render && render.redraw) {
609 //console.log('changed');
610 var s = this.selection;
611 var iter = new Gtk.TreeIter();
612 s.get_selected(this.get('/LeftTree.model').el, iter);
616 var value = new GObject.Value('');
617 this.get('/LeftTree.model').el.get_value(iter, 2, value);
618 this.get('/LeftTree.model').activePath = this.get('/LeftTree.model').el.get_path(iter).to_string();
620 var data = JSON.parse(value.value);
621 this.get('/MidPropTree').activeElement = data;
622 this.get('/MidPropTree').hideWin();
623 this.get('/LeftPanel.model').load( data);
625 console.log(value.value);
626 // _g.button.set_label(''+value.get_string());
628 var pm =this.get('/RightPalete.model');
629 pm.load( this.get('/RightPalete').provider.gatherList(
630 this.get('/LeftTree.model').listAllTypes()));
633 if (render && render.redraw) {
637 //Seed.print( value.get_string());
644 xtype: Gtk.TreeStore,
648 XObject.prototype.init.call(this);
649 this.el.set_column_types ( 3, [
650 GObject.TYPE_STRING, // title
651 GObject.TYPE_STRING, // tip
652 GObject.TYPE_STRING // source..
656 changed : function(n, refresh) {
657 print("MODEL CHANGED CALLED" + this.activePath);
658 if (this.activePath) {
659 var iter = new Gtk.TreeIter();
660 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath))
661 this.el.set_value(iter, 0, [GObject.TYPE_STRING, this.nodeTitle(n)]);
662 this.el.set_value(iter, 1, [GObject.TYPE_STRING, this.nodeTitle(n)]);
664 this.el.set_value(iter, 2, [GObject.TYPE_STRING, this.nodeToJSON(n)]);
666 //this.currentTree = this.toJS(false, true)[0];
667 this.file.items = this.toJS(false, false);
668 print("AFTER CHANGED");
669 //console.dump(this.file.items);
671 this.currentTree = this.file.items[0];
672 //console.log(this.file.toSource());
675 print("REDNER BROWSER?!");
676 this.get('/LeftTree').renderView();
678 var pm = this.get('/RightPalete.model');
679 if (!this.get('/RightPalete').provider) {
685 pm.load( this.get('/RightPalete').provider.gatherList(this.listAllTypes()));
686 //imports['Builder/RightBrowser.js'].renderJS(this.toJS());
690 loadFile : function(f) {
696 console.log('missing file');
700 // load the file if not loaded..
701 if (f.items === false) {
703 f.loadItems(function() {
709 this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name);
711 if (f.items.length && typeof(f.items[0]) == 'string') {
713 this.get('/RightEditor').el.show();
714 this.get('/RightEditor.view').load( f.items[0]);
718 //console.dump(f.items);
720 this.get('/LeftTree.view').el.expand_all();
722 if (!f.items.length) {
725 this.get('/Window.leftvpaned').el.set_position(80);
727 this.get('/LeftTree.view').el.set_cursor(
728 new Gtk.TreePath.from_string('0'), null, false);
732 this.get('/Window.leftvpaned').el.set_position(200);
736 //print("hide right editior");
737 this.get('/RightEditor').el.hide();
738 //print("set current tree");
739 this.currentTree = this.toJS(false, false)[0];
740 //console.dump(this.currentTree);
741 this.currentTree = this.currentTree || { items: [] };
742 this.get('/LeftTree').renderView();
743 //console.dump(this.map);
744 //var RightPalete = imports.Builder.RightPalete.RightPalete;
745 var pm = this.get('/RightPalete.model');
748 this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider();
750 if (!this.get('/RightPalete').provider) {
751 print ("********* PALETE PROVIDER MISSING?!!");
753 this.get('/LeftTree').renderView();
755 pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes()));
759 this.get('/Window.view-notebook').el.set_current_page(
760 this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1);
763 findDropNode : function(treepath_str, targets) {
765 // this is used by the dragdrop code in the roo version AFAIR..
767 var path = treepath_str.replace(/^builder-/, '');
768 // treemap is depreciated... - should really check if model has any entries..
770 if (!this.el.iter_n_children(null)) {
772 return [ '', Gtk.TreeViewDropPosition.INTO_OR_AFTER];
774 print("FIND treepath: " + path);
775 //console.dump(this.treemap);
777 if (!treepath_str.match(/^builder-/)) {
778 return []; // nothing!
780 if (targets === true) {
783 return this.findDropNodeByPath(path,targets)
785 findDropNodeByPath : function(treepath_str, targets, pref) {
786 var path = treepath_str + ''; // dupe it..
787 pref = typeof(pref) == 'undefined' ? Gtk.TreeViewDropPosition.INTO_OR_AFTER : pref;
789 //console.dump(this.treemap);
790 while (path.length) {
791 print("LOOKING FOR PATH: " + path);
792 var node_data = this.singleNodeToJS(path);
793 if (node_data === false) {
794 print("node not found");
798 var xname = this.get('/LeftTree.model').file.guessName(node_data);
801 targets.forEach(function(tg) {
805 if ((tg == xname) ) {
808 if (tg.indexOf(xname +':') === 0) {
810 prop = tg.split(':').pop();
815 if (last) { // pref is after/before..
816 // then it's after last
818 return []; // do not allow..
820 return [ last, pref , prop];
823 return [ path , Gtk.TreeViewDropPosition.INTO_OR_AFTER , prop];
825 var par = path.split(':');
828 path = par.join(':');
834 dropNode : function(target_data, node) {
837 console.dump(target_data);
838 var tp = target_data[0].length ? new Gtk.TreePath.from_string( target_data[0] ) : false;
840 print("add " + tp + "@" + target_data[1] );
843 if (tp && target_data[1] < 2) { // before or after..
844 var ar = target_data[0].split(':');
846 parent = new Gtk.TreePath.from_string( ar.join(':') );
849 var n_iter = new Gtk.TreeIter();
850 var iter_par = new Gtk.TreeIter();
851 var iter_after = after ? new Gtk.TreeIter() : false;
855 if (parent !== false) {
856 this.el.get_iter(iter_par, parent);
863 print(target_data[1] > 0 ? 'insert_after' : 'insert_before');
864 this.el.get_iter(iter_after, after);
865 this.el[ target_data[1] > 0 ? 'insert_after' : 'insert_before'](
866 n_iter, iter_par, iter_after);
869 this.el.append(n_iter, iter_par);
873 if (typeof(node) == 'string') {
874 var ar = node.split('.');
875 var xtype = ar.pop();
878 '|xns' : ar.join('.'),
881 if (target_data.length == 3 && target_data[2].length) {
882 node['*prop'] = target_data[2];
886 // work out what kind of packing to use..
887 if (typeof(node.pack) == 'undefined' && parent !== false) {
888 var pal = this.get('/LeftTree').getPaleteProvider();
890 var pname = pal.guessName(this.singleNodeToJS(parent.to_string()));
891 print ("PNAME : " + pname);
892 var cname = pal.guessName(node);
893 print ("CNAME : " + cname);
894 node.pack = pal.getDefaultPack(pname, cname);
905 // load children - if it has any..
908 this.load(xitems, n_iter);
910 if (tp && (xitems || after)) {
911 this.get('/LeftTree.view').el.expand_row(this.el.get_path(iter_par), true);
913 // wee need to get the empty proptypes from somewhere..
915 //var olditer = this.activeIter;
916 this.activePath = this.el.get_path(n_iter).to_string();
918 // changed actually set's the node data..
919 this.changed(node, true);
923 this.get('/LeftTree.view').el.set_cursor(this.el.get_path(n_iter), null, false);
925 //Builder.MidPropTree._model.load(node);
926 //Builder.MidPropTree._win.hideWin();
927 //Builder.LeftPanel._model.load( node);
931 moveNode : function(target_data, action) {
932 //print("MOVE NODE");
933 // console.dump(target_data);
934 var old_iter = new Gtk.TreeIter();
935 var s = this.get('/LeftTree.view').selection;
936 s.get_selected(this.el, old_iter);
937 var node = this.nodeToJS(old_iter,false);
938 //console.dump(node);
941 // needs to drop first, otherwise the target_data
942 // treepath will be invalid.
944 this.dropNode(target_data, node);
945 if (action & Gdk.DragAction.MOVE) {
946 // print("REMOVING OLD NODE");
947 this.el.remove(old_iter);
951 this.activePath= false;
952 this.changed(false,true);
954 deleteSelected : function() {
955 this.get('/LeftTree.view').blockChanges = true;
956 var old_iter = new Gtk.TreeIter();
957 var s = this.get('/LeftTree.view').selection;
958 s.get_selected(this.el, old_iter);
959 var path = this.el.get_path(old_iter).to_string();
961 this.activePath= false;
964 this.activePath= false;
965 var iter = new Gtk.TreeIter();
966 this.el.get_iter_from_string(iter, path);
967 this.el.remove(iter);
969 // rebuild treemap. -- depreciated.!!
972 //this.toJS(null, true) // does not do anything?
973 this.activePath= false;
974 this.changed(false,true);
975 this.get('/LeftTree.view').blockChanges = false;
978 listAllTypes : function() {
979 var s = this.get('/LeftTree.view').selection;
980 print ("LIST ALL TYPES: " + s.count_selected_rows() );
982 if (s.count_selected_rows() > 0) {
983 var iter = new Gtk.TreeIter();
984 s.get_selected(this.el, iter);
986 // set some properties of the tree for use by the dropped element.
987 var value = new GObject.Value('');
988 this.el.get_value(iter, 2, value);
989 var data = JSON.parse(value.value);
992 var xname = this.get('/LeftTree.model').file.guessName(data);
993 console.log('selected:' + xname);
997 return []; // could not find it..
1005 li.forEach(function(el) {
1006 // this is specific to roo!!!?
1008 var fullpath = _this.file.guessName(el);
1009 if (fullpath.length && ret.indexOf(fullpath) < 0) {
1014 if (el.items && el.items.length) {
1023 addall([this.currentTree]);
1025 // only if we have nothing, should we add '*top'
1029 //console.log('all types in tree');
1030 //console.dump(ret);
1035 singleNodeToJS : function (treepath)
1037 var iter = new Gtk.TreeIter();
1038 if (!this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath))) {
1042 var iv = this.getIterValue(iter, 2);
1044 return JSON.parse(iv);
1047 nodeToJS : function (iter, with_id)
1049 var par = new Gtk.TreeIter();
1050 var iv = this.getIterValue(iter, 2);
1051 // print("IV" + iv);
1052 var k = JSON.parse(iv);
1053 if (k.json && !this.el.iter_parent( par, iter )) {
1058 var treepath_str = this.el.get_path(iter).to_string();
1059 // not sure how we can handle mixed id stuff..
1060 if (typeof(k.id) == 'undefined') {
1061 k.id = 'builder-'+ treepath_str ;
1065 this.treemap[ treepath_str ] = k;
1066 k.xtreepath = treepath_str ;
1069 if (this.el.iter_has_child(iter)) {
1070 citer = new Gtk.TreeIter();
1071 this.el.iter_children(citer, iter);
1072 k.items = this.toJS(citer,with_id);
1076 toJS : function(iter, with_id)
1078 //Seed.print("WITHID: "+ with_id);
1085 iter = new Gtk.TreeIter();
1086 if (!this.el.get_iter_first(iter)) {
1096 var k = this.nodeToJS(iter, with_id);
1100 if (!this.el.iter_next(iter)) {
1106 // convert the list into a json string..
1110 getIterValue : function (iter, col) {
1111 var gval = new GObject.Value('');
1112 this.el.get_value(iter, col ,gval);
1117 nodeTitle : function(c, renderfull) {
1120 var sr = (typeof(c['+buildershow']) != 'undefined') && !c['+buildershow'] ? true : false;
1121 if (sr) txt.push('<s>');
1122 if (typeof(c['*prop']) != 'undefined') { txt.push(c['*prop']+ ':'); }
1124 if (renderfull && c['|xns']) {
1125 txt.push(c['|xns']);
1128 if (c.xtype) { txt.push(c.xtype); }
1129 if (c.id) { txt.push('<b>[id=' + c.id + ']</b>'); }
1130 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
1131 if (c.boxLabel) { txt.push('[' + c.boxLabel + ']'); }
1134 if (c.layout) { txt.push('<i>' + c.layout + '</i>'); }
1135 if (c.title) { txt.push('<b>' + c.title + '</b>'); }
1136 if (c.label) { txt.push('<b>' + c.label+ '</b>'); }
1137 if (c.header) { txt.push('<b>' + c.header + '</b>'); }
1138 if (c.legend) { txt.push('<b>' + c.legend + '</b>'); }
1139 if (c.text) { txt.push('<b>' + c.text + '</b>'); }
1140 if (c.name) { txt.push('<b>' + c.name+ '</b>'); }
1141 if (c.region) { txt.push('<i>(' + c.region + ')</i>'); }
1142 if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
1144 // for flat classes...
1145 if (typeof(c['*class']) != 'undefined') { txt.push('<b>' + c['*class']+ '</b>'); }
1146 if (typeof(c['*extends']) != 'undefined') { txt.push(': <i>' + c['*extends']+ '</i>'); }
1149 if (sr) txt.push('</s>');
1150 return (txt.length == 0 ? "Element" : txt.join(" "));
1152 nodeToJSON : function(c) {
1160 return JSON.stringify(o);
1162 load : function(tr,iter)
1164 var citer = new Gtk.TreeIter();
1165 //this.insert(citer,iter,0);
1166 for(var i =0 ; i < tr.length; i++) {
1168 this.el.insert(citer,iter,-1);
1170 this.el.append(citer);
1173 this.el.set_value(citer, 0, [GObject.TYPE_STRING, this.nodeTitle(tr[i]) ]);
1174 this.el.set_value(citer, 1, [GObject.TYPE_STRING, this.nodeTip(tr[i]) ]);
1175 this.el.set_value(citer, 2, [GObject.TYPE_STRING, this.nodeToJSON(tr[i])]);
1176 if (tr[i].items && tr[i].items.length) {
1177 this.load(tr[i].items, citer);
1181 nodeTip : function(c) {
1182 var ret = this.nodeTitle(c,true);
1188 if (!i.length || i[0] != '|') {
1194 if (typeof(c[i]) != 'string') {
1197 //print("prop : " + i + ':' + c[i]);
1198 if (!c[i].match(new RegExp('function'))) {
1201 funcs += "\n<b>" + i.substring(1) + '</b> : ' + c[i].split(/\n/).shift();
1205 ret+="\n\nMethods:" + funcs;
1212 xtype: Gtk.TreeViewColumn,
1213 pack : "append_column",
1215 XObject.prototype.init.call(this);
1216 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1220 xtype: Gtk.CellRendererText,
1230 id : "LeftTreeMenu",
1233 xtype: Gtk.MenuItem,
1235 label : "Delete Element",
1237 activate : function (self) {
1239 this.get('/LeftTree.model').deleteSelected();
1250 id : "LeftProjectTree",
1251 showNoProjectSelected : function() {
1252 this.get('/StandardErrorDialog').show("Select a Project first.");
1254 getActiveProject : function() {
1255 return this.project;
1258 leave_notify_event : function (self, event) {
1265 pack : "pack_start,false,false",
1268 xtype: Gtk.ComboBox,
1271 XObject.prototype.init.call(this);
1272 this.el.add_attribute(this.get('render').el , 'markup', 1 );
1274 getValue : function() {
1275 var ix = this.el.get_active();
1279 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1280 if (typeof(data[ix]) == 'undefined') {
1285 setValue : function(fn)
1289 var data = imports.Builder.Provider.ProjectManager.ProjectManager.projects;
1290 data.forEach(function(n, ix) {
1298 changed : function (self) {
1299 var fn = this.getValue();
1300 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1301 this.get('/LeftProjectTree.model').loadProject(pm.getByFn(fn))
1306 xtype: Gtk.CellRendererText,
1307 pack : "pack_start,true",
1311 xtype: Gtk.ListStore,
1314 XObject.prototype.init.call(this);
1315 this.el.set_column_types ( 2, [
1316 GObject.TYPE_STRING, // real key
1317 GObject.TYPE_STRING // real type
1321 var pm = imports.Builder.Provider.ProjectManager.ProjectManager;
1323 pm.on('changed', function() {
1324 print("caught changed hook on project manager - reloading data");
1325 _this.loadData(pm.projects);
1329 loadData : function(data) {
1330 var ov = this.get('/LeftProjectTree.combo').getValue();
1332 var iter = new Gtk.TreeIter();
1334 data.forEach(function(p) {
1339 el.set_value(iter, 0, p.fn);
1340 el.set_value(iter, 1, p.name);
1344 this.get('/LeftProjectTree.combo').setValue(ov);
1353 xtype: Gtk.ScrolledWindow,
1355 shadow_type : Gtk.ShadowType.IN,
1357 XObject.prototype.init.call(this);
1358 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC );
1362 xtype: Gtk.TreeView,
1363 headers_visible : false,
1364 enable_tree_lines : true,
1367 XObject.prototype.init.call(this);
1368 var description = new Pango.FontDescription.c_new();
1369 description.set_size(8000);
1370 this.el.modify_font(description);
1372 this.selection = this.el.get_selection();
1373 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1377 cursor_changed : function (self) {
1378 var iter = new Gtk.TreeIter();
1380 if (this.selection.count_selected_rows() < 1) {
1381 //XN.get('Builder.LeftTree.model').
1382 this.get('/LeftTree.model').load( false);
1386 var model = this.get('/LeftProjectTree.model');
1387 //console.log('changed');
1388 var s = this.selection;
1389 s.get_selected(model, iter);
1390 value = new GObject.Value('');
1391 model.el.get_value(iter, 2, value);
1393 console.log(value.value);// id..
1395 var file = this.get('/LeftProjectTree').project.getById(value.value);
1402 var nb = this.get('/LeftTopPanel.expander');
1403 nb.el.expanded = false;
1404 nb.listeners.activate.call(nb);
1405 //_expander.el.set_expanded(false);
1407 var ltm = this.get('/LeftTree.model');
1415 xtype: Gtk.TreeStore,
1419 XObject.prototype.init.call(this);
1420 this.el.set_column_types ( 3, [
1421 GObject.TYPE_STRING, // title
1422 GObject.TYPE_STRING, // tip
1423 GObject.TYPE_STRING // id..
1427 loadProject : function(pr) {
1428 print("LOAD PROJECT");
1434 this.get('/LeftProjectTree').project = pr;
1435 this.load(pr.toTree());
1436 this.get('/LeftProjectTree.view').el.expand_all();
1438 load : function(tr,iter) {
1439 // console.dump(tr);
1440 console.log('Project tree load: ' + tr.length);
1441 var citer = new Gtk.TreeIter();
1442 //this.insert(citer,iter,0);
1445 tr.forEach(function (r) {
1447 _this.el.append(citer);
1449 _this.el.insert(citer,iter,-1);
1451 _this.el.set_value(citer, 0, '' + r.getTitle() ); // title
1452 _this.el.set_value(citer, 1, '' + r.getTitleTip()); // tip
1453 _this.el.set_value(citer, 2, '' + r.id ); //id
1454 if (r.cn && r.cn.length) {
1455 _this.load(r.cn, citer);
1460 getValue : function(iter, col) {
1461 var gval = new GObject.Value('');
1462 this.el.get_value(iter, col ,gval);
1463 return '' + gval.value;
1467 xtype: Gtk.TreeViewColumn,
1468 pack : "append_column",
1470 XObject.prototype.init.call(this);
1471 this.el.add_attribute(this.items[0].el , 'markup', 0 );
1475 xtype: Gtk.CellRendererText,
1498 pack : "pack_start,false,true,0",
1505 button_press_event : function (self, event) {
1506 this.get('/MidPropTree.model').showData('props');
1518 stock : Gtk.STOCK_ADD,
1519 icon_size : Gtk.IconSize.MENU
1534 button_press_event : function (self, event) {
1535 this.get('/MidPropTree.model').showData('events');
1547 stock : Gtk.STOCK_ADD,
1548 icon_size : Gtk.IconSize.MENU
1563 button_press_event : function (self, ev) {
1564 var p = this.get('/AddPropertyPopup');
1568 p.el.set_screen(Gdk.Screen.get_default());
1570 p.el.popup(null, null, null, null, 3, ev.button.time);
1582 stock : Gtk.STOCK_ADD,
1583 icon_size : Gtk.IconSize.MENU
1595 id : "AddPropertyPopup",
1598 xtype: Gtk.MenuItem,
1600 tooltip_markup : "Using this.get('*someid') will find any id in an application.",
1603 activate : function (self) {
1605 this.get('/LeftPanel.model').add( {
1616 xtype: Gtk.MenuItem,
1618 tooltip_markup : "Add what type of packing is to be used",
1621 activate : function (self) {
1623 this.get('/LeftPanel.model').add( {
1633 xtype: Gtk.MenuItem,
1635 tooltip_markup : "Override the init method",
1638 activate : function (self) {
1640 this.get('/LeftPanel.model').add( {
1643 val : "function() {\n XObject.prototype.init.call(this);\n}\n",
1650 xtype: Gtk.SeparatorMenuItem,
1654 xtype: Gtk.MenuItem,
1656 tooltip_markup : "Add a user defined string property",
1659 activate : function (self) {
1661 this.get('/LeftPanel.model').add( {
1671 xtype: Gtk.MenuItem,
1673 tooltip_markup : "Add a user defined number property",
1676 activate : function (self) {
1678 this.get('/LeftPanel.model').add( {
1688 xtype: Gtk.MenuItem,
1690 tooltip_markup : "Add a user defined boolean property",
1693 activate : function (self) {
1695 this.get('/LeftPanel.model').add( {
1705 xtype: Gtk.SeparatorMenuItem,
1709 xtype: Gtk.MenuItem,
1711 tooltip_markup : "Add a user function boolean property",
1714 activate : function (self) {
1716 this.get('/LeftPanel.model').add( {
1719 val : "function() {\n \n}\n",
1732 xtype: Gtk.ScrolledWindow,
1735 shadow_type : Gtk.ShadowType.IN,
1738 XObject.prototype.init.call(this);
1739 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1743 xtype: Gtk.TreeView,
1746 headers_visible : false,
1747 enable_tree_lines : true,
1749 XObject.prototype.init.call(this);
1751 this.selection = this.el.get_selection();
1752 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
1755 var description = new Pango.FontDescription.c_new();
1756 description.set_size(8000);
1757 this.el.modify_font(description);
1760 button_press_event : function (self, ev) {
1764 if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
1765 return false; //not on a element.
1769 if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button.button != 3) {
1771 if (res.column.title != 'value') {
1772 return false; // ignore..
1774 if ( this.get('/LeftPanel').editing) {
1777 var renderer = this.get('/LeftPanel').editableColumn.items[0].el; // set has_entry..
1778 this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
1779 var type = this.get('/LeftPanel.model').getType(res.path.to_string());
1783 var provider = this.get('/LeftTree').getPaleteProvider();
1785 var opts = provider.findOptions(type);
1787 if (opts === false) {
1788 this.get('/LeftPanel').editableColumn.setOptions([]);
1789 renderer.has_entry = true;
1791 LeftPanel.editableColumn.setOptions(opts);
1792 renderer.has_entry = false;
1796 //Seed.print("click" + ev.type);
1797 //console.dump(res);
1803 if (res.column.title == 'value') {
1806 //if (! this.get('/LeftPanelPopup')LeftPanelPopup.el) LeftPanelPopup.init();
1807 var p = this.get('/LeftPanelPopup');
1812 p.el.set_screen(Gdk.Screen.get_default());
1814 p.el.popup(null, null, null, null, 3, ev.button.time);
1815 //Seed.print("click:" + res.column.title);
1823 xtype: Gtk.TreeStore,
1827 getIterValue : function(iter, col) {
1828 var gval = new GObject.Value('');
1829 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
1830 return '' + gval.value;
1832 add : function(info) {
1833 // info includes key, val, skel, etype..
1835 type = info.type.toLowerCase();
1836 var data = this.toJS();
1838 if (info.etype == 'events') {
1839 data.listeners = data.listeners || { };
1840 if (typeof(data.listeners[info.key]) != 'undefined') {
1841 return; //already set!
1844 if (typeof(data[info.key]) != 'undefined') {
1849 if (typeof(info.val) == 'undefined') {
1852 if (info.type == 'boolean') {
1855 if (type == 'number') {
1863 if (info.etype == 'events') {
1865 data.listeners[info.key] = info.val;
1868 data[info.key] = info.val;
1872 var map = this.load(data);
1874 // flag it as changed to the interface..
1876 this.get('/LeftTree.model').changed(data, true);
1879 this.startEditing(map[k]);
1882 LeftPanel.get('view').el.row_activated(
1883 new Gtk.TreePath.from_string(map[k]),
1884 LeftPanel.editableColumn.el
1888 changed : function(str, doRefresh) {
1889 if (!this.activePath) {
1892 var iter = new Gtk.TreeIter();
1893 this.el.get_iter(iter, new Gtk.TreePath.from_string(this.activePath));
1895 this.el.set_value(iter, 1, '' +str);
1896 this.el.set_value(iter, 3, '' + this.toShort(str));
1897 var type = this.getIterValue(iter, 4);
1899 this.el.set_value(iter, 5, type + ' : ' + str);
1900 // update the tree...
1902 this.get('/LeftTree.model').changed(this.toJS(), doRefresh);
1904 deleteSelected : function() {
1905 var data = this.toJS();
1906 var iter = new Gtk.TreeIter();
1907 var s = this.get('/LeftPanel.view').selection;
1908 s.get_selected(this.el, iter);
1911 var gval = new GObject.Value('');
1912 this.get('/LeftPanel.model').el.get_value(iter, 0 ,gval);
1914 var val = gval.value;
1915 if (val[0] == '!') {
1917 if (!data.listeners || typeof(data.listeners[ val.substring(1)]) == 'undefined') {
1920 delete data.listeners[ val.substring(1)];
1921 if (!XObject.keys(data.listeners).length) {
1922 delete data.listeners;
1926 if (typeof(data[val]) == 'undefined') {
1934 this.get('/LeftTree.model').changed(data, true);
1937 editSelected : function(e) {
1938 print("EDIT SELECTED?");
1939 var iter = new Gtk.TreeIter();
1940 var s = this.get('/LeftPanel.view').selection;
1941 s.get_selected(this.get('/LeftPanel.model').el, iter);
1942 var m = this.get('/LeftPanel.model')
1944 var gval = new GObject.Value('');
1945 this.el.get_value(iter, 0 ,gval);
1946 var val = '' + gval.value;
1948 gval = new GObject.Value('');
1949 this.el.get_value(iter, 1 ,gval);
1950 var rval = gval.value;
1951 var activePath = this.el.get_path(iter).to_string();
1952 this.activePath = activePath ;
1953 // was activeIter...
1956 var showEditor = false;
1958 if (val[0] == '!') {
1961 if (val[0] == '|') {
1962 if (rval.match(/function/g) || rval.match(/\n/g)) {
1969 this.activePath = false;
1970 GLib.timeout_add(0, 1, function() {
1971 // Gdk.threads_enter();
1972 _this.get('/BottomPane').el.show();
1973 _this.get('/RightEditor').el.show();
1974 _this.get('/RightEditor.view').load( rval );
1978 _this.activePath = activePath ;
1980 // Gdk.threads_leave();
1985 this.get('/BottomPane').el.hide();
1986 this.get('/RightEditor').el.hide();
1988 //var type = this.getValue(this.el.get_path(iter).to_string(),4);
1992 getType : function(treepath) {
1993 return this.getValue(treepath, 4);
1995 getValue : function(treepath_str, col) {
1996 var iter = new Gtk.TreeIter();
1997 this.el.get_iter(iter, new Gtk.TreePath.from_string(treepath_str));
1999 var gval = new GObject.Value('');
2000 this.get('/LeftPanel.model').el.get_value(iter, col ,gval);
2001 var val = '' + gval.value;
2005 var type = this.getType(this.el.get_path(iter).to_string());
2006 print("TYPE: " +type + " - val:" + val);
2007 switch(type.toLowerCase()) {
2011 return parseFloat(val); // Nan ?? invalid!!?
2014 return 1.0 * parseFloat(val); // Nan ?? invalid!!?
2016 return val == 'true' ? true : false;
2018 var nv = parseFloat(val);
2019 if (!isNaN(nv) && (val == ''+nv)) {
2027 XObject.prototype.init.call(this);
2028 this.el.set_column_types ( 6, [
2029 GObject.TYPE_STRING, // 0 real key
2030 GObject.TYPE_STRING, // 1 real value
2031 GObject.TYPE_STRING, // 2 visable key
2032 GObject.TYPE_STRING, // 3 visable value
2033 GObject.TYPE_STRING, // 4 need to store type of!!!
2034 GObject.TYPE_STRING // 5 tooltip
2038 load : function(ar) {
2041 this.get('/RightEditor').el.hide();
2048 var provider = this.get('/LeftTree').getPaleteProvider();
2049 var iter = new Gtk.TreeIter();
2052 var keys = XObject.keys(ar);
2054 ar.listeners = ar.listeners || {};
2056 for (var i in ar.listeners ) {
2057 this.el.append(iter);
2058 var p = this.el.get_path(iter).to_string();
2061 this.el.set_value(iter, 0, '!'+ i );
2062 this.el.set_value(iter, 1, '' + ar.listeners[i]);
2063 this.el.set_value(iter, 2, '<b>'+ i + '</b>');
2065 this.el.set_value(iter, 3, '' + this.toShort(ar.listeners[i]));
2066 this.el.set_value(iter, 4, 'function');
2067 this.el.set_value(iter, 5, i + ' : ' + ar.listeners[i]);
2073 keys.forEach(function(i) {
2074 if (typeof(ar[i]) == 'object') {
2078 var type = provider.findType(ar, i, ar[i]);
2080 _this.el.append(iter);
2081 var p = _this.el.get_path(iter).to_string();
2083 _this.el.set_value(iter, 0, ''+i);
2084 _this.el.set_value(iter, 1, '' + ar[i]);
2085 _this.el.set_value(iter, 2, ''+i);
2086 _this.el.set_value(iter, 3, ''+ _this.toShort(ar[i]));
2087 _this.el.set_value(iter, 4, ''+type);
2088 _this.el.set_value(iter, 5, type + ' : ' + ar[i]);
2092 startEditing : function(path,col) {
2094 * start editing path (or selected if not set..)
2095 * @param {String|false} path (optional) treepath to edit - selected tree gets
2096 * edited by default.
2097 * @param {Number} 0 or 1 (optional)- column to edit.
2100 if (typeof(path) == 'string') {
2101 tp = new Gtk.TreePath.from_string(path);
2103 var iter = new Gtk.TreeIter();
2104 var s = this.get('/LeftPanel.view').selection;
2105 s.get_selected(this.el, iter);
2106 tp = this.el.get_path(iter);
2107 path = tp.to_string();
2111 // which colum is to be edited..
2113 if (typeof(col) == 'undefined') {
2114 var k = this.getValue(path, 0);
2115 colObj = (!k.length || k == '|') ?
2116 this.get('/LeftPanel').propertyColumn : this.get('/LeftPanel').editableColumn;
2118 colObj = col ? this.get('/LeftPanel').editableColumn : this.get('/LeftPanel').propertyColumn;
2121 // make sure the pulldown is set correctly..
2122 // not really needed for second col...
2124 var provider = this.get('/LeftTree').getPaleteProvider();
2126 var type = this.get('/LeftPanel.model').getType(path);
2127 var opts = provider.findOptions(type);
2128 var renderer = this.get('/LeftPanel').editableColumn.items[0].el;
2130 if (opts === false) {
2131 this.get('/LeftPanel').editableColumn.setOptions([]);
2132 renderer.has_entry = true; /// probably does not have any effect.
2134 this.get('/LeftPanel').editableColumn.setOptions(opts);
2135 renderer.has_entry = false;
2139 // iter now has row...
2140 GLib.timeout_add(0, 100, function() {
2142 colObj.items[0].el.editable = true; // esp. need for col 0..
2143 _this.get('/LeftPanel.view').el.set_cursor_on_cell(
2153 var iter = new Gtk.TreeIter();
2154 this.get('/LeftPanel.model').el.get_iter_first(iter);
2159 var k = this.getValue(this.el.get_path(iter).to_string(), 0);
2162 ar.listeners = ar.listeners || {};
2163 ar.listeners[ k.substring(1)] = this.getValue(this.el.get_path(iter).to_string(), 1);
2166 ar[ k ] = this.getValue(this.el.get_path(iter).to_string(), 1);
2169 if (! this.get('/LeftPanel.model').el.iter_next(iter)) {
2175 //print(JSON.stringify(ar));
2179 toShort : function(str) {
2180 var a = typeof(str) == 'string' ? str.split("\n") : [];
2181 return a.length > 1 ? a[0] + '....' : '' + str;
2185 xtype: Gtk.TreeViewColumn,
2186 pack : "append_column",
2188 XObject.prototype.init.call(this);
2190 this.el.add_attribute(this.items[0].el , 'markup', 2 );
2191 this.get('/LeftPanel').propertyColumn = this;
2196 xtype: Gtk.CellRendererText,
2197 pack : "pack_start",
2199 editing_started : function (self, editable, path) {
2201 this.get('/LeftPanel.model').activePath = path;
2204 edited : function (self, object, p0) {
2205 var model = this.get('/LeftPanel.model');
2206 var path = model.activePath;
2207 var iter = new Gtk.TreeIter();
2208 model.el.get_iter(iter, new Gtk.TreePath.from_string(path));
2209 model.el.set_value(iter, 0, p0);
2210 model.el.set_value(iter, 2, p0);
2212 model.activePath = false;
2214 this.get('/LeftTree.model').changed(model.toJS(), true);
2215 this.el.editable = false;
2222 xtype: Gtk.TreeViewColumn,
2223 pack : "append_column",
2225 XObject.prototype.init.call(this);
2226 this.el.add_attribute(this.items[0].el , 'text', 3 );
2227 this.el.add_attribute(this.items[0].el , 'sensitive', 3 );
2228 this.el.add_attribute(this.items[0].el , 'editable', 3 );
2229 // this.el.set_cell_data_func(cell, age_cell_data_func, NULL, NULL);
2231 this.get('/LeftPanel').editableColumn= this;
2233 setOptions : function(ar) {
2234 var m = this.items[0].el.model;
2236 var iter = new Gtk.TreeIter();
2237 ar.forEach(function(i) {
2240 m.set_value(iter, 0, i);
2246 xtype: Gtk.CellRendererCombo,
2247 pack : "pack_start",
2252 XObject.prototype.init.call(this);
2253 this.el.model = new Gtk.ListStore();
2254 this.el.model.set_column_types ( 1, [
2255 GObject.TYPE_STRING // 0 real key
2259 edited : function (self, object, p0) {
2260 this.get('/LeftPanel').editing = false;
2261 print("EDITED? p:" + p0 + " t:" + p0);
2262 this.get('/LeftPanel.model').changed(p0, true);
2263 this.get('/LeftPanel.model').activePath = false;
2265 editing_started : function (self, editable, path) {
2266 this.get('/LeftPanel').editing = true;
2267 // console.log('editing started');
2268 // r.has_entry = false;
2269 this.get('/LeftPanel.model').editSelected(editable);
2280 id : "LeftPanelPopup",
2283 xtype: Gtk.MenuItem,
2287 activate : function (self) {
2288 this.get('/LeftPanel.model').deleteSelected();
2293 xtype: Gtk.MenuItem,
2297 activate : function (self) {
2298 this.get('/LeftPanel.model').startEditing(false, 0);
2311 xtype: Gtk.ScrolledWindow,
2312 pack : "pack_end,false,true,0",
2314 shadow_type : Gtk.ShadowType.IN,
2316 XObject.prototype.init.call(this);
2317 XObject.prototype.init.call(this);
2318 this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2319 this.el.set_size_request ( 150, -1 );
2322 activeElement : false,
2323 hideWin : function() {
2330 if (this.get('/Window.left').el.position < 160) {
2333 this.get('/Window.left').el.position = this.get('/Window.left').el.position - 150;
2340 xtype: Gtk.TreeView,
2341 enable_tree_lines : true,
2342 headers_visible : false,
2345 XObject.prototype.init.call(this);
2347 var description = new Pango.FontDescription.c_new();
2348 description.set_size(8000);
2349 this.el.modify_font(description);
2351 //this.selection = this.el.get_selection();
2352 // this.selection.set_mode( Gtk.SelectionMode.SINGLE);
2361 cursor_changed : function (self) {
2362 var iter = new Gtk.TreeIter();
2364 //console.log('changed');
2365 var m = this.get('model');
2366 if (!this.selection){
2367 this.selection = this.el.get_selection();
2370 var s = this.selection;
2371 if (!s.get_selected(m.el, iter)) {
2374 var tp = m.el.get_path(iter).to_string();
2379 var key = m.getValue(tp, 0);
2381 var type = m.getValue(tp, 1);
2382 var skel = m.getValue(tp, 3);
2383 var etype = m.getValue(tp, 5);
2386 this.get('/MidPropTree').hideWin();
2388 if (type == 'function') {
2390 if (etype != 'events') {
2394 this.get('/LeftPanel.model').add({
2403 if (type.indexOf('.') > -1 ||
2404 type == 'boolean') {
2408 this.get('/LeftPanel.model').add( {
2418 xtype: Gtk.ListStore,
2421 XObject.prototype.init.call(this);
2422 this.el.set_column_types ( 6, [
2423 GObject.TYPE_STRING, // real key
2424 GObject.TYPE_STRING, // real type
2425 GObject.TYPE_STRING, // docs ?
2426 GObject.TYPE_STRING, // visable desc
2427 GObject.TYPE_STRING, // function desc
2428 GObject.TYPE_STRING // element type (event|prop)
2432 getValue : function(treepath, col)
2434 var tp = new Gtk.TreePath.from_string (treepath);
2435 var iter = new Gtk.TreeIter();
2436 this.el.get_iter (iter, tp);
2437 var value = new GObject.Value('');
2438 this.el.get_value(iter, col, value);
2442 showData : function(type) {
2444 if (!this.get('/MidPropTree').activeElement || !type) {
2445 return; // no active element
2448 var fullpath = this.get('/LeftTree.model').file.guessName(this.get('/MidPropTree').activeElement);
2449 var palete = this.get('/LeftTree').getPaleteProvider();
2453 Seed.print('Showing right?');
2454 if (!this.get('/MidPropTree').shown) {
2456 this.get('/Window.left').el.position = this.get('/Window.left').el.position + 150;
2457 this.get('/MidPropTree').el.show();
2458 this.get('/MidPropTree').shown = true;
2461 var elementList = palete.getPropertiesFor(fullpath, type);
2462 print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
2463 // console.dump(elementList);
2466 var iter = new Gtk.TreeIter();
2467 for(var i =0 ; i < elementList.length; i++) {
2468 var p=elementList[i];
2469 this.el.append(iter);
2470 // console.log( '<b>' + p.name +'</b> ['+p.type+']');
2471 //GObject.TYPE_STRING, // real key
2472 // GObject.TYPE_STRING, // real type
2473 // GObject.TYPE_STRING, // docs ?
2474 // GObject.TYPE_STRING // func def?
2477 this.el.set_value(iter, 0, p.name);
2478 this.el.set_value(iter, 1, p.type);
2479 this.el.set_value(iter, 2, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>' + "\n" + p.desc);
2480 this.el.set_value(iter, 3, p.sig ? p.sig : '');
2481 this.el.set_value(iter, 4, '<span size="small"><b>' + p.name +'</b> ['+p.type+']</span>');
2482 this.el.set_value(iter, 5, type);
2490 xtype: Gtk.TreeViewColumn,
2492 this.el = new Gtk.TreeViewColumn();
2493 this.parent.el.append_column(this.el);
2495 XObject.prototype.init.call(this);
2496 this.el.add_attribute(this.items[0].el , 'markup', 4 );
2501 xtype: Gtk.CellRendererText,
2502 pack : "pack_start,true"
2526 xtype: Gtk.Notebook,
2527 pack : "pack_start,true,true",
2528 id : "view-help-nb",
2530 XObject.prototype.init.call(this);
2531 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Preview" }));
2532 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Help" }));
2536 xtype: Gtk.Notebook,
2538 id : "view-notebook",
2541 XObject.prototype.init.call(this);
2542 this.el.set_current_page(0);
2544 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Roo View" }));
2545 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Gtk View" }));
2552 id : "RightBrowser",
2559 pack : "pack_start,false,true,0",
2563 pack : "pack_start,false,false,0",
2566 button_press_event : function (self, event) {
2567 var js = this.get('/LeftTree.model').toJS();
2569 this.get('/RightBrowser.view').renderJS(js[0]);
2578 button_press_event : function (self, event) {
2579 this.get('/RooProjectProperties').show();
2583 label : "Set extra HTML in renderer",
2584 pack : "pack_start,false,false,0"
2589 button_press_event : function (self, event)
2591 /* Firefox testing for debugging..
2592 - we can create a /tmp directory, and put.
2593 builder.html, builder.html.js, link roojs1
2594 add at the end of builder.html Roo.onload(function() {
2596 if (!this.get('/Window.LeftTree').getActiveFile()) {
2600 var js = this.get('/LeftTree.model').toJS();
2601 if (!js || !js[0]) {
2604 var project = this.get('/Window.LeftTree').getActiveFile().project;
2605 //print (project.fn);
2607 project.runhtml = project.runhtml || '';
2610 var File = imports.File.File;
2612 var target = "/tmp/firetest"; // fixme..
2613 if (!File.isDirectory(target)) {
2616 File.copy(__script_path__ + '/../builder.html.js', target+ '/builder.html.js', Gio.FileCopyFlags.OVERWRITE);
2617 if (!File.exists( target+ '/roojs1')) {
2618 File.link( target+ '/roojs1', __script_path__ + '/../roojs1');
2623 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2624 html = html.replace('</head>', project.runhtml + '</head>');
2627 var jsstr = JSON.stringify(js[0]);
2629 var runbuilder = '<script type="text/javascript">' + "\n" +
2630 " Builder.render(" + jsstr + ");\n" +
2633 html = html.replace('</body>', runbuilder + '</body>');
2635 File.write( target+ '/builder.html', html);
2637 this.get('/Terminal').feed("RUN DIR:" + target);
2639 this.get('/Terminal').el.fork_command( null , [], [], target
2640 , false,false,false);
2641 var cmd = "firefox file://" + target + "/builder.html \n";
2642 this.get('/Terminal').el.feed_child(cmd, cmd.length);
2646 label : "Test in Firefox",
2647 pack : "pack_start,false,false,0"
2652 xtype: Gtk.ScrolledWindow,
2654 shadow_type : Gtk.ShadowType.IN,
2656 XObject.prototype.init.call(this);
2657 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
2661 xtype: WebKit.WebView,
2665 XObject.prototype.init.call(this);
2666 // this may not work!?
2667 this.el.open('file:///' + __script_path__ + '/../builder.html');
2671 this.el, /* widget that will accept a drop */
2672 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
2673 null, /* lists of target to support */
2674 0, /* size of list */
2675 Gdk.DragAction.COPY /* what to do with data after dropped */
2678 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
2679 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
2681 renderJS : function(data) {
2682 print("HTML RENDERING");
2683 /// prevent looping..
2684 //if (this.pendingRedraw) {
2685 // print("pending redraw active?!");
2690 if (!this.get('/Window.LeftTree').getActiveFile()) {
2694 var project = this.get('/Window.LeftTree').getActiveFile().project;
2695 //print (project.fn);
2697 project.runhtml = project.runhtml || '';
2700 this.runhtml = this.runhtml || '';
2702 if (project.runhtml != this.runhtml) {
2703 // then we need to reload the browser using
2704 // load_html_string..
2706 // then trigger a redraw once it's loaded..
2707 this.pendingRedraw = true;
2709 this.runhtml = project.runhtml;
2711 var html = imports.File.File.read(__script_path__ + '/../builder.html');
2712 html = html.replace('</head>', this.runhtml + '</head>');
2713 print("LOAD HTML " + html);
2714 this.el.load_html_string( html , 'file:///' + __script_path__ + '/../builder.html');
2715 // should trigger load_finished!
2720 this.pendingRedraw = false;
2723 this.renderedData = data;
2724 var str = JSON.stringify(data) ;
2727 console.log('not loaded yet');
2729 //Seed.print("RENDER:" + str);
2730 //imports.File.File.write('/tmp/builder.debug.js', "Builder.render(" + JSON.stringify(data) + ");");
2732 this.el.execute_script("Builder.render(" + JSON.stringify(data) + ");");
2735 load_finished : function (self, object) {
2736 // if (this.ready) { // dont do it twice!
2740 this.pendingRedraw = false;
2741 var js = this.get('/LeftTree.model').toJS();
2743 this.renderJS(js[0]);
2747 script_alert : function (self, object, p0) {
2750 return true; // do not display anything...
2752 console_message : function (self, object, p0, p1) {
2753 // console.log(object);
2754 if (!object.match(/^\{/)) {
2756 this.get('/Terminal').feed(object);
2757 return true; // do not handle!!! -> later maybe in console..
2759 // console.log(object);
2760 var val = JSON.parse(object);
2762 if (typeof(val['hover-node']) != 'undefined') {
2763 this.activeNode = val['hover-node'];
2764 console.log('active node: ' + this.activeNode);
2769 if (typeof(val['id']) != 'undefined') {
2770 // this.activeNode = val['id'];
2771 var tg = this.get('/LeftTree.model').findDropNode(val['id'], true);
2775 this.get('/LeftTree.view').selectNode(tg[0]);
2779 if (ret && typeof(val['set']) != 'undefined') {
2780 this.get('/LeftPanel.model').add({
2784 //console.log('active node: ' + this.activeNode);
2787 //Seed.print('a:'+a);
2788 //Seed.print('b:'+b);
2789 //Seed.print('c:'+c);
2792 drag_motion : function (w, ctx, x, y, time, ud) {
2793 // console.log('DRAG MOTION');
2795 // if lastCurrentNode == this.currentNode.. -- don't change anything..
2796 this.targetData = [];
2797 this.el.execute_script("Builder.overPos(" + x +','+ y + ");");
2799 // A) find out from drag all the places that node could be dropped.
2800 var src = Gtk.drag_get_source_widget(ctx);
2801 if (!src.dropList) {
2802 Gdk.drag_status(ctx, 0, time);
2805 // b) get what we are over.. (from activeNode)
2806 // tree is empty.. - list should be correct..
2807 if (!this.get('/LeftTree.model').currentTree) {
2808 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2812 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
2814 var tg = this.get('/LeftTree.model').findDropNode(this.activeNode, src.dropList);
2817 Gdk.drag_status(ctx, 0,time);
2818 this.get('/LeftTree.view').highlight(false);
2822 // if we have a target..
2823 // -> highlight it! (in browser)
2824 // -> highlight it! (in tree)
2826 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
2827 this.get('/LeftTree.view').highlight(tg);
2828 this.targetData = tg;
2829 // for tree we should handle this...
2832 drag_drop : function (w, ctx, x, y,time, ud) {
2833 print("TARGET: drag-drop");
2834 var is_valid_drop_site = true;
2839 w, /* will receive 'drag-data-received' signal */
2840 ctx, /* represents the current state of the DnD */
2841 this.get('/Window').atoms["STRING"], /* the target type we want */
2842 time /* time stamp */
2846 /* No target offered by source => error */
2849 return is_valid_drop_site;
2851 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
2853 print("Browser: drag-data-received");
2854 var delete_selection_data = false;
2855 vardnd_success = false;
2856 /* Deal with what we are given from source */
2857 if( sel_data && sel_data.length ) {
2859 if (ctx.action == Gdk.DragAction.ASK) {
2860 /* Ask the user to move or copy, then set the ctx action. */
2863 if (ctx.action == Gdk.DragAction.MOVE) {
2864 delete_selection_data = true;
2866 var source = Gtk.drag_get_source_widget(ctx);
2868 print("Browser: source.DRAGDATA? " + source.dragData);
2869 if (this.targetData) {
2870 print(this.targetData);
2871 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
2880 if (dnd_success == false)
2882 Seed.print ("DnD data transfer failed!\n");
2885 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
2896 id : "RightGtkView",
2898 redraw : function() {
2899 this.highlightWidget = false;
2900 print("REDRAW CALLED");
2901 this.activePath = this.get('/LeftTree').getActivePath();
2902 if (this.renderedEl) {
2903 print("QUEUE DRAW CALLING");
2904 this.renderedEl.queue_draw();
2907 renderJS : function(data, withDebug)
2909 this.highlightWidget = false;
2913 this.withDebug = false;
2915 if (this.renderedEl) {
2916 this.get('view').el.remove(this.renderedEl);
2917 this.renderedEl.destroy();
2918 this.renderedEl = false;
2921 var tree = this.get('/LeftTree.model').toJS(false,true)[0];
2922 // in theory tree is actually window..
2924 this.renderedEl = this.viewAdd(tree.items[0], this.get('view').el);
2929 this.get('view').el.set_size_request(
2930 tree.default_width * 1 || 400, tree.default_height * 1 || 400
2933 this.renderedEl.set_size_request(
2934 tree.default_width || 600,
2935 tree.default_height || 400
2937 this.get('view').el.show_all();
2942 showInWindow : function() {
2943 print("GET PROEJCT");
2944 var pr = this.get('/LeftProjectTree').getActiveProject();
2946 console.log(pr.paths);
2949 var src= this.buildJS(
2950 this.get('/LeftTree.model').toJS()[0],
2955 //var x = new imports.sandbox.Context();
2959 Seed.check_syntax('var e = ' + src);
2962 this.get('/Terminal').feed(e.message || e.toString() + "\n");
2963 this.get('/Terminal').feed(console._dump(e)+"\n");
2965 var lines = src.split("\n");
2966 var start = Math.max(0, e.line - 10);
2967 var end = Math.min(lines.length, e.line + 10);
2968 for (var i =start ; i < end; i++) {
2970 this.get('/Terminal').feed(">>>>>" + lines[i] + "\n");
2973 this.get('/Terminal').feed(lines[i] + "\n");
2980 this.get('/BottomPane').el.set_current_page(1);
2981 this.get('/Terminal').el.fork_command( null , [], [], "/tmp", false,false,false);
2982 var cmd = "/usr/bin/seed /tmp/BuilderGtkView.js\n";
2983 this.get('/Terminal').el.feed_child(cmd, cmd.length);
2985 var _top = x.get_global_object()._top;
2987 _top.el.set_screen(Gdk.Screen.get_default()); // just in case..
2989 if (_top.el.popup) {
2990 _top.el.popup(null, null, null, null, 3, null);
2994 viewAdd : function(item, par)
2996 // does something similar to xobject..
2997 item.pack = (typeof(item.pack) == 'undefined') ? 'add' : item.pack;
2999 if (item.pack===false || item.pack === 'false') { // no ;
3002 print("CREATE: " + item['|xns'] + '.' + item['xtype']);
3003 var type = item['|xns'] + '.' + item['xtype'];
3004 var ns = imports.gi[item['|xns']];
3005 var ctr = ns[item['xtype']];
3007 for(var k in item) {
3009 if (typeof(kv) == 'object' || typeof(kv) == 'function') {
3024 if (k[0] == '|' && typeof(kv) == 'string') {
3026 if (kv.match(new RegExp('function'))) {
3029 print("WASL " + k + '=' + kv);
3031 eval( 'kv = ' + kv);
3032 } catch(e) { continue; }
3035 // print(k + '=' + kv);
3037 if (k[0] == '|') { // should be boolean or number..
3039 //print(k + '=' + kv);
3042 if (k == 'show_tabs') { // force tab showing for notebooks.
3045 print(k + '=' + typeof(kv) + " : " + kv);
3051 var el = new ctr(ctr_args);
3053 print("PACK" + item.pack);
3054 //console.dump(item.pack);
3061 if (typeof(item.pack) == 'string') {
3063 item.pack.split(',').forEach(function(e, i) {
3065 if (e == 'false') { args.push( false); return; }
3066 if (e == 'true') { args.push( true); return; }
3067 if (!isNaN(parseInt(e))) { args.push( parseInt(e)); return; }
3070 //print(args.join(","));
3072 pack_m = args.shift();
3074 pack_m = item.pack.shift();
3079 if (pack_m && typeof(par[pack_m]) == 'undefined') {
3081 name: "ArgumentError",
3082 message : 'pack method not available : ' + par.id + " : " + par + '.' + pack_m +
3083 "ADDING : " + item.id + " " + el
3092 //if (XObject.debug) print(pack_m + '[' + args.join(',') +']');
3093 //Seed.print('args: ' + args.length);
3095 par[pack_m].apply(par, args);
3099 item.items = item.items || [];
3100 item.items.forEach(function(ch,n) {
3102 print ("type:" + type);
3104 print ("ch.pack:" + ch.pack);
3105 if (type == 'Gtk.Table' && ch.pack == 'add') {
3106 var c = n % item.n_columns;
3107 var r = Math.floor(n/item.n_columns);
3108 ch.pack = [ 'attach', c, c+1, r, r+1,
3109 typeof(ch.x_options) == 'undefined' ? 5 : ch.x_options,
3110 typeof(ch.y_options) == 'undefined' ? 5 : ch.y_options,
3111 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding,
3112 typeof(ch.x_padding) == 'undefined' ? 0 : ch.x_padding
3116 _this.viewAdd(ch, el);
3121 // add the signal handlers.
3122 // is it a widget!?!!?
3128 el.signal.expose_event.connect(XObject.createDelegate(this.widgetExposeEvent, this, [ item ], true));
3129 el.signal.drag_motion.connect(XObject.createDelegate(this.widgetDragMotionEvent, this,[ item ], true));
3130 el.signal.drag_drop.connect(XObject.createDelegate(this.widgetDragDropEvent, this, [ item ], true));
3131 el.signal.button_press_event.connect(XObject.createDelegate(this.widgetPressEvent, this, [ item ], true ));
3132 el.signal.button_release_event.connect(XObject.createDelegate(this.widgetReleaseEvent, this, [ item ], true ));
3142 widgetDragDropEvent : function() {
3143 print("WIDGET DRAGDROP");
3146 widgetDragMotionEvent : function() {
3147 print("WIDGET DRAGMOTION");
3150 widgetExposeEvent : function(w, evt, ud, item) {
3152 if (this.inRender) {
3156 if ( this.highlightWidget) {
3157 this.inRender = true;
3158 if (item.xtreepath.substring(0, this.activePath.length) == this.activePath) {
3159 Gdk.draw_rectangle(this.highlightWidget.window, this.gc, false, this.box.x , this.box.y, this.box.w, this.box.h);
3161 this.inRender = false;
3166 if (this.activePath != item.xtreepath) {
3170 // print("HIGHLIGHT: " + item.xtreepath ); // draw highlight??
3171 // work out the coords of the window..
3173 var dr = widget.window;
3174 this.gc = (new Gdk.GC.c_new(dr));
3175 this.gc.set_rgb_fg_color(new Gdk.Color({ red: 0xFFFF, green: 0, blue : 0 }));
3176 this.gc.set_line_attributes(4, Gdk.LineStyle.SOLID, Gdk.CapStyle.ROUND , Gdk.JoinStyle.ROUND);
3180 var r = evt.expose.area;
3181 // console.dump([r.x, r.y, r.width, r.height ] );
3183 // print(widget.get_parent().toString().match(/GtkScrolledWindow/);
3184 if (widget.get_parent().toString().match(/GtkScrolledWindow/)) { // eak
3185 // happens with gtkscrollview embedded stuff..
3186 var np =this.activePath.split(':');
3188 this.activePath = np.join(':');
3189 this.renderedEl.queue_draw();
3205 this.inRender = true;
3208 this.highlightWidget = widget;
3213 // print("DRAW BOX");
3214 //console.dump(this.box);
3215 Gdk.draw_rectangle(widget.window, this.gc, false, this.box.x , this.box.y, this.box.w,this.box.h);
3216 this.inRender = false;
3219 widgetPressEvent : function(w,e,u,d) {
3220 if (this.get('view').pressed) {
3223 this.get('view').pressed = true;
3224 print("WIDGET PRESS " + d.xtreepath );
3225 this.get('/LeftTree.view').selectNode( d.xtreepath );
3228 widgetReleaseEvent : function() {
3229 this.get('view').pressed = false;
3235 pack : "pack_start,false,true,0",
3239 pack : "pack_start,false,false,0",
3240 label : "Run The Application",
3242 button_press_event : function (self, event) {
3243 // call render on left tree - with special option!?!
3245 //print("GET PROEJCT");
3246 var pr = this.get('/LeftProjectTree').getActiveProject();
3249 for (var i in pr.paths) {
3253 var runner = GLib.path_get_dirname (__script_path__) + '/gtkrun.js';
3254 this.get('/Terminal').feed("RUN DIR:" + dir);
3256 this.get('/Terminal').el.fork_command( null , [], [], GLib.path_get_dirname (__script_path__)
3257 , false,false,false);
3258 var cmd = "/usr/bin/seed " + runner + " " + dir + "\n";
3259 this.get('/Terminal').el.feed_child(cmd, cmd.length);
3269 xtype: Gtk.ScrolledWindow,
3272 shadow_type : Gtk.ShadowType.IN,
3274 XObject.prototype.init.call(this);
3275 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3279 xtype: Gtk.EventBox,
3280 pack : "add_with_viewport",
3282 XObject.prototype.init.call(this);
3283 this.el.modify_bg(Gtk.StateType.NORMAL, new Gdk.Color({
3284 red: 0x9F00, green: 0xB800 , blue : 0xA800
3292 XObject.prototype.init.call(this);
3293 //this.el.set_hadjustment(this.parent.el.get_hadjustment());
3294 //this.el.set_vadjustment(this.parent.el.get_vadjustment());
3299 xtype: Gtk.EventBox,
3302 //this.el = new Gtk.Image.from_stock (Gtk.STOCK_HOME, Gtk.IconSize.MENU);
3303 XObject.prototype.init.call(this);
3307 this.el, /* widget that will accept a drop */
3308 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
3309 null, /* lists of target to support */
3310 0, /* size of list */
3311 Gdk.DragAction.COPY /* what to do with data after dropped */
3314 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
3315 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
3318 getActiveNode : function(x,y)
3320 // workout what node is here..
3321 return '0'; // top..
3325 drag_motion : function (self, ctx, x, y, time) {
3327 // A) find out from drag all the places that node could be dropped.
3328 var src = Gtk.drag_get_source_widget(ctx);
3329 if (!src.dropList) {
3330 Gdk.drag_status(ctx, 0, time);
3333 // b) get what we are over.. (from activeNode)
3334 // tree is empty.. - list should be correct..
3335 if (!this.get('/LeftTree.model').currentTree) {
3336 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3340 // c) ask tree where it should be dropped... - eg. parent.. (after node ontop)
3341 var activeNode = this.getActiveNode(x, y);
3344 var tg = this.get('/LeftTree.model').findDropNode(activeNode, src.dropList);
3347 Gdk.drag_status(ctx, 0,time);
3348 this.get('/LeftTree.view').highlight(false);
3352 // if we have a target..
3353 // -> highlight it! (in browser)
3354 // -> highlight it! (in tree)
3356 Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
3357 this.get('/LeftTree.view').highlight(tg);
3358 this.targetData = tg;
3359 // for tree we should handle this...
3362 drag_drop : function (self,ctx, x, y, time) {
3363 Seed.print("TARGET: drag-drop");
3364 var is_valid_drop_site = true;
3369 self, /* will receive 'drag-data-received' signal */
3370 ctx, /* represents the current state of the this.gDnD */
3371 this.get('/Window').atoms["STRING"], /* the target type we want */
3372 time /* time stamp */
3376 /* No target offered by source => error */
3379 return is_valid_drop_site;
3382 drag_data_received : function (w, ctx, x, y, sel_data, target_type, time, ud)
3384 Seed.print("GtkView: drag-data-received");
3385 var delete_selection_data = false;
3386 var dnd_success = false;
3387 /* Deal with what we are given from source */
3388 if( sel_data && sel_data.length ) {
3390 if (ctx.action == Gdk.DragAction.ASK) {
3391 /* Ask the user to move or copy, then set the ctx action. */
3394 if (ctx.action == Gdk.DragAction.MOVE) {
3395 delete_selection_data = true;
3397 var source = Gtk.drag_get_source_widget(ctx);
3399 Seed.print("Browser: source.DRAGDATA? " + source.dragData);
3400 if (this.targetData) {
3401 Seed.print(this.targetData);
3402 this.get('/LeftTree.model').dropNode(this.targetData, source.dragData);
3411 if (dnd_success == false)
3413 Seed.print ("DnD data transfer failed!\n");
3416 Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
3419 button_press_event : function (self, event) {
3420 this.pressed = false;
3436 xtype: Gtk.ScrolledWindow,
3441 var file = this.get('/LeftTree').getActiveFile();
3445 var activeEl = this.get('/LeftTree').getActiveElement();
3446 var xtype = file.guessName( activeEl )
3447 if (!xtype || !xtype.length) {
3450 this.get('/Window.view-help-nb').el.set_current_page(1);
3452 // get the active element being edited.
3453 var helpurl = file.getHelpUrl(xtype);
3455 // now load the help info in the page..
3456 this.get('help-view').el.open(helpurl);
3460 xtype: WebKit.WebView,
3464 XObject.prototype.init.call(this);
3465 this.get('/Window.help-view').el.open(
3466 "http://devel.akbkhome.com/seed/");
3478 xtype: Gtk.Notebook,
3481 XObject.prototype.init.call(this);
3482 this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
3483 this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
3488 xtype: Gtk.ScrolledWindow,
3493 xtype: GtkSource.View,
3497 XObject.prototype.init.call(this);
3498 var description = Pango.Font.description_from_string("monospace")
3499 description.set_size(8000);
3500 this.el.modify_font(description);
3503 load : function(str) {
3505 // show the help page for the active node..
3506 this.get('/Help').show();
3509 this.get('/BottomPane').el.set_current_page(0);
3510 this.el.get_buffer().set_text(str, str.length);
3511 var lm = GtkSource.LanguageManager.get_default();
3513 this.el.get_buffer().set_language(lm.get_language('js'));
3514 var buf = this.el.get_buffer();
3515 var cursor = buf.get_mark("insert");
3516 var iter= new Gtk.TextIter;
3517 buf.get_iter_at_mark(iter, cursor);
3519 iter.set_line_offset(4);
3520 buf.move_mark(cursor, iter);
3523 cursor = buf.get_mark("selection_bound");
3524 iter= new Gtk.TextIter;
3525 buf.get_iter_at_mark(iter, cursor);
3527 iter.set_line_offset(4);
3528 buf.move_mark(cursor, iter);
3530 this.el.grab_focus();
3532 insert_spaces_instead_of_tabs : true,
3535 show_line_numbers : true,
3538 xtype: GtkSource.Buffer,
3539 pack : "set_buffer",
3541 changed : function (self) {
3542 var s = new Gtk.TextIter();
3543 var e = new Gtk.TextIter();
3544 this.el.get_start_iter(s);
3545 this.el.get_end_iter(e);
3546 var str = this.el.get_text(s,e,true);
3548 Seed.check_syntax('var e = ' + str);
3550 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3551 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
3553 print("SYNTAX ERROR IN EDITOR");
3558 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
3559 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
3562 this.get('/LeftPanel.model').changed( str , false);
3571 xtype: Gtk.ScrolledWindow,
3575 xtype: Vte.Terminal,
3578 feed : function(istr) {
3579 var str = istr.replace(/\n/g, "\r\n") + "\r\n";
3580 // we should make ourselves visable!!!
3581 this.get('/BottomPane').el.show();
3582 this.get('/BottomPane').el.set_current_page(1);
3584 this.el.feed(str ,str.length);
3586 scroll_on_output : true,
3588 XObject.prototype.init.call(this);
3589 this.el.set_size (80, 1000);
3591 scrollback_lines : 1000
3601 pack : "pack_start,false,false",
3605 this.get('buttonbar').el.show();
3606 this.get('viewbox').el.hide();
3607 print("TRIED TO HIDE");
3610 this.get('buttonbar').el.hide();
3611 this.get('viewbox').el.show();
3612 // this.get('model').expanded();
3624 pack : "pack_start,false,true",
3626 clicked : function (self) {
3627 this.get('/RightPalete').show();
3634 stock : Gtk.STOCK_GOTO_FIRST,
3635 icon_size : Gtk.IconSize.MENU
3645 XObject.prototype.init.call(this);
3646 this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
3649 enter_notify_event : function (self, event) {
3650 this.get('/RightPalete').show();
3664 pack : "pack_start,false,true",
3673 pack : "pack_start,false,true",
3675 clicked : function (self) {
3676 this.get('/RightPalete').hide();
3683 stock : Gtk.STOCK_GOTO_LAST,
3684 icon_size : Gtk.IconSize.MENU
3691 xtype: Gtk.ScrolledWindow,
3694 XObject.prototype.init.call(this);
3695 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
3696 this.el.set_size_request(-1,200);
3698 shadow_type : Gtk.ShadowType.IN,
3701 xtype: Gtk.TreeView,
3704 XObject.prototype.init.call(this);
3705 this.el.set_size_request(150,-1);
3706 // set_reorderable: [1]
3708 var description = new Pango.FontDescription.c_new();
3709 description.set_size(8000);
3710 this.el.modify_font(description);
3712 this.selection = this.el.get_selection();
3713 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
3714 // this.selection.signal['changed'].connect(function() {
3715 // _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
3717 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
3719 Gtk.drag_source_set (
3720 this.el, /* widget will be drag-able */
3721 Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */
3722 null, /* lists of target to support */
3723 0, /* size of list */
3724 Gdk.DragAction.COPY /* what to do with data after dropped */
3726 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
3728 Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
3729 Gtk.drag_source_add_text_targets(this.el);
3731 print("RP: TARGET:" + LeftTree.atoms["STRING"]);
3732 targets = new Gtk.TargetList();
3733 targets.add( LeftTree.atoms["STRING"], 0, 0);
3734 targets.add_text_targets( 1 );
3735 Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
3737 //if you want to allow text to be output elsewhere..
3738 //Gtk.drag_source_add_text_targets(this.el);
3742 headers_visible : false,
3743 enable_tree_lines : true,
3745 drag_begin : function (self, ctx) {
3746 // we could fill this in now...
3747 Seed.print('SOURCE: drag-begin');
3751 var iter = new Gtk.TreeIter();
3752 var s = this.selection;
3753 s.get_selected(this.get('/RightPalete.model').el, iter);
3754 var path = this.get('/RightPalete.model').el.get_path(iter);
3756 var pix = this.el.create_row_drag_icon ( path);
3759 Gtk.drag_set_icon_pixmap (ctx,
3766 var value = new GObject.Value('');
3767 this.get('/RightPalete.model').el.get_value(iter, 0, value);
3768 if (!this.get('/RightPalete').provider) {
3771 this.el.dropList = this.get('/RightPalete').provider.getDropList(value.value);
3772 this.el.dragData = value.value;
3779 drag_data_get : function (self, drag_context, selection_data, info, time) {
3780 //Seed.print('Palete: drag-data-get: ' + target_type);
3781 if (this.el.dragData && this.el.dragData.length ) {
3782 selection_data.set_text(this.el.dragData ,this.el.dragData.length);
3786 //this.el.dragData = "TEST from source widget";
3790 drag_end : function (self, drag_context) {
3791 Seed.print('SOURCE: drag-end');
3792 this.el.dragData = false;
3793 this.el.dropList = false;
3794 this.get('/LeftTree.view').highlight(false);
3800 xtype: Gtk.ListStore,
3803 XObject.prototype.init.call(this);
3804 this.el.set_column_types ( 2, [
3805 GObject.TYPE_STRING, // title
3806 GObject.TYPE_STRING // tip
3811 load : function(tr,iter)
3816 //console.log('Project tree load: ' + tr.length);
3817 var citer = new Gtk.TreeIter();
3818 //this.insert(citer,iter,0);
3819 for(var i =0 ; i < tr.length; i++) {
3822 this.el.append(citer);
3824 this.el.insert(citer,iter,-1);
3829 this.el.set_value(citer, 0, '' + r ); // title
3831 //this.el.set_value(citer, 1, new GObject.Value( r)); //id
3832 //if (r.cn && r.cn.length) {
3833 // this.load(r.cn, citer);
3839 getValue : function (iter, col) {
3840 var gval = new GObject.Value('');
3841 this.el.get_value(iter, col ,gval);
3848 xtype: Gtk.TreeViewColumn,
3849 pack : "append_column",
3851 XObject.prototype.init.call(this);
3852 this.el.add_attribute(this.items[0].el , 'markup', 0 );
3856 xtype: Gtk.CellRendererText,
3878 XObject.cache['/Window'] = Window;