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