tools/build_gtk_tree.js
[app.Builder.js] / JsRender / Gtk.js
1 //<Script type="text/javascript">
2  
3 Gio = imports.gi.Gio;
4 GLib = imports.gi.GLib;
5
6 XObject = imports.XObject.XObject;
7 File = imports.File.File;
8   
9 //----------------------- our roo verison
10 Base = imports.JsRender.Base.Base;
11
12 var gid = 1;
13
14 Gtk = XObject.define( 
15     
16     
17     function(cfg) {
18         
19         // id ,
20         //"name":"Edit Module Details",
21         // items : 
22         //"btype":"FORM", // was to be components...
23         //"app":"Builder",
24         //"module":"Pman.Tab.BuilderTop2"
25         //console.dump(cfg);
26         cfg.parent = cfg.parent || '';
27         if (!cfg.name || !cfg.fullname ) {
28             
29             // name is in theory filename without .bjs (or .js eventually...)
30             cfg.name = cfg.path.split('/').pop().replace(/\.(bjs|js)$/, '');
31             
32             cfg.fullname = (cfg.parent.length ? (cfg.parent + '.') : '' ) + cfg.name;
33         }
34         
35         
36         this.items = false;
37         if (cfg.json) {
38             var jstr =  JSON.parse(cfg.json);
39             this.items = [ jstr ];
40             //console.log(cfg.items.length);
41             delete cfg.json; // not needed!
42         }
43         this.cn = [];
44          /*
45         var p = cfg.items && cfg.items.length && cfg.items[0].parent ? cfg.items[0].parent : false;
46         
47         // ensure real data is set...
48         Roo.apply(this, {
49             name : cfg.module,
50             parent : p,
51             title : cfg.name,
52             project : cfg.app
53             
54         });
55         
56         this.cn = [];
57         */
58         Gtk.superclass.constructor.call(this, cfg);
59
60         
61         // super?!?!
62         this.id = 'file-gtk-' + gid++;
63         //console.dump(this);
64         // various loader methods..
65        
66     },
67     Base,   
68     {
69         xtype : 'Gtk',
70         setNSID : function(id)
71         {
72             
73             this.items[0]['*class'] = id;
74             
75             
76         },
77         getType: function() {
78             return 'Gtk';
79         },
80         
81         loadItems : function(cb)
82         {
83           
84             print("load Items!");
85             if (this.items !== false) {
86                 return false;
87             }
88             if (!cb) {  
89                 throw {
90                     name: "ArgumentError", 
91                     message : "no callback for loadItems"
92                 };
93             }
94             Seed.print("load: " + this.path);
95             
96             
97
98             
99             var _this = this;     
100             var src = File.read(this.path);
101             
102             var cfg = JSON.parse(src);
103             print("loaded data");
104             //console.dump(cfg);
105             
106             //_this.name = cfg.name; -- this should not happen - name should always match filename!!
107             _this.parent =  cfg.parent;
108             _this.title =  cfg.title;
109             _this.items = cfg.items || []; 
110            
111              cb();
112              
113              
114             
115             
116             
117         },
118         /**
119          * convert xtype for munged output..
120          * 
121          */
122         mungeXtype : function(xtype, els)
123         {
124             els.push('xtype: '+ xtype);
125         },
126         
127         toSource : function()
128         {
129             
130             if (!this.items[0]) {
131                 return false;
132             }
133             var data = JSON.parse(JSON.stringify(this.items[0]));
134             // we should base this on the objects in the tree really..
135             var i = [ 'Gtk', 'Gdk', 'Pango', 'GLib', 'Gio', 'GObject', 
136                 'GtkSource', 'WebKit', 'Vte' ]; //, 'GtkClutter' , 'Gdl'];
137             var src = "";
138             i.forEach(function(e) {
139                 src += e+" = imports.gi." + e +";\n";
140             });
141             
142             src += "console = imports.console;\n"; // path?!!?
143             src += "XObject = imports.XObject.XObject;\n"; // path?!!?
144             
145             
146             src += this.name + '=new XObject('+ this.mungeToString(data) + ");\n";
147             src += this.name + '.init();\n';
148             // register it in the cache
149             src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
150             
151             
152             return src;
153             
154             
155         },
156         save : function() {
157             Base.prototype.save.call(this);
158             this.saveJS();
159         },
160         
161         /** 
162          *  saveJS
163          * 
164          * save as a javascript file.
165          * why is this not save...???
166          * 
167          * 
168          */
169         saveJS: function()
170         {
171              
172             var fn = GLib.path_get_dirname(this.path) + '/' + this.name + '.js';
173             print("WRITE : " + fn);
174             File.write(fn, this.toSource());
175             
176             return fn;
177         },
178         /*
179         getTree : function( o ) {
180             
181             
182             
183         }
184         */
185         getHelpUrl : function(cls)
186         {
187             return 'http://devel.akbkhome.com/seed/' + cls + '.html';
188         }
189         
190     });