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