resources/RooUsage.txt
[app.Builder.js] / old-javascript / JsRender / Gtk.vala
1
2
3 namespace JsRender {
4
5
6  
7     int gid = 1;
8
9   
10     public  class Gtk : JsRender
11     {
12        
13
14         public Gtk(Project.Project project, string path) {
15         
16             base( project, path);
17             this.xtype = "Gtk";
18             this.language = "vala";
19             
20             
21             //this.items = false;
22             //if (cfg.json) {
23             //    var jstr =  JSON.parse(cfg.json);
24             //    this.items = [ jstr ];
25             //    //console.log(cfg.items.length);
26             //    delete cfg.json; // not needed!
27             // }
28              
29             
30             
31             // super?!?!
32             this.id = "file-gtk-%d".printf(gid++);
33             //console.dump(this);
34             // various loader methods..
35
36             // Class = list of arguments ... and which property to use as a value.
37        
38
39             
40             
41         }
42           
43
44         /*
45         setNSID : function(id)
46         {
47             
48             this.items[0]['*class'] = id;
49             
50             
51         },
52         getType: function() {
53             return 'Gtk';
54         },
55         */
56
57         public   override void   removeFiles() {
58                 var js = GLib.Path.get_dirname(this.path) +"/" +  name + ".js";
59                 if (FileUtils.test(js, FileTest.EXISTS)) {
60                         GLib.FileUtils.remove(js);
61                 }
62                 var vala = GLib.Path.get_dirname(this.path) +"/" + name + ".vala";
63                 if (FileUtils.test(vala, FileTest.EXISTS)) {
64                         GLib.FileUtils.remove(vala);
65                 }
66         }
67         
68          public   override void  loadItems() throws GLib.Error // : function(cb, sync) == original was async.
69         {
70           
71             print("load Items!");
72             if (this.tree != null) {
73                 return;
74             }
75             
76             print("load: " + this.path);
77
78
79             var pa = new Json.Parser();
80             pa.load_from_file(this.path);
81             var node = pa.get_root();
82             
83             if (node.get_node_type () != Json.NodeType.OBJECT) {
84                         throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
85                 }
86             var obj = node.get_object ();
87             //this.modOrder = obj.get_string_member("modOrder");
88             this.name = obj.get_string_member("name");
89             this.parent = obj.get_string_member("parent");
90             //this.permname = obj.get_string_member("permname");
91             this.title = obj.get_string_member("title");
92             //this.modOrder = obj.get_string_member("modOrder");
93              
94             // load items[0] ??? into tree...
95             var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
96             bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
97
98             if (obj.has_member("items") 
99                         && 
100                         obj.get_member("items").get_node_type() == Json.NodeType.ARRAY
101                         &&
102                         obj.get_array_member("items").get_length() > 0
103                 ) {
104                     var ar = obj.get_array_member("items");
105                     var tree_base = ar.get_object_element(0);
106                     this.tree = new Node();
107                     this.tree.loadFromJson(tree_base, int.parse(bjs_version_str));
108
109             }
110             
111             
112         }
113          
114          // convert xtype for munged output..
115          
116          /*
117         mungeXtype : function(xtype, els)
118         {
119             els.push('xtype: '+ xtype);
120         },
121         */
122                 
123         public override string toSourcePreview()
124         {
125                         return "";
126                 }
127       
128         public override string toSource()
129         {
130         
131             
132             if (this.tree == null) {
133                 return "";
134             }
135             
136             // var data = JSON.parse(JSON.stringify(this.items[0]));
137             // we should base this on the objects in the tree really..
138             string[]  inc = { "Gtk", "Gdk", "Pango", "GLib", "Gio", "GObject", 
139                 "GtkSource", "WebKit", "Vte" }; //, "GtkClutter" , "Gdl"];
140             var src = "";
141                          
142             for (var i=0; i< inc.length; i++) {
143                                 var e = inc[i];
144                 src += e+" = imports.gi." + e +";\n";
145             }
146             
147             src += "console = imports.console;\n"; // path?!!?
148             src += "XObject = imports.XObject.XObject;\n"; // path?!!?
149             
150             
151             src += this.name + "=new XObject("+ this.mungeToString("    ") + ");\n";
152             src += this.name + ".init();\n";
153             // register it in the cache
154             src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
155             
156             
157             return src;
158             
159             
160         }
161                 
162         public override void save() {
163             this.saveBJS();
164             // this.saveJS(); - disabled at present.. project settings will probably enable this later..
165                 
166             this.saveVala();
167         }
168             // ignore these calls.
169         public override void saveHTML ( string html ) {}
170             
171                     
172         /** 
173          *  saveJS
174          * 
175          * save as a javascript file.
176          * why is this not save...???
177          * 
178          */ 
179           
180         void saveJS()
181         {
182              
183             var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".js";
184             print("WRITE :%s\n " , fn);
185             this.writeFile(fn, this.toSource());
186             
187         }
188         
189        void  saveVala()
190         {
191                 if (this.tree == null) {
192                         return;
193                 }
194                 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".vala";
195                 print("WRITE :%s\n " , fn);
196                 this.writeFile(fn,  NodeToVala.mungeFile(this));
197             
198             
199         }
200                 /*
201         valaCompileCmd : function()
202         {
203             
204             var fn = '/tmp/' + this.name + '.vala';
205             print("WRITE : " + fn);
206             File.write(fn, this.toVala(true));
207             
208             
209             
210             return ["valac",
211                    "--pkg",  "gio-2.0",
212                    "--pkg" , "posix" ,
213                    "--pkg" , "gtk+-3.0",
214                    "--pkg",  "libnotify",
215                    "--pkg",  "gtksourceview-3.0",
216                    "--pkg", "libwnck-3.0",
217                    fn ,   "-o", "/tmp/" + this.name];
218             
219            
220              
221             
222         },
223         */
224         
225    
226         string getHelpUrl(string cls)
227         {
228             return "http://devel.akbkhome.com/seed/" + cls + ".html";
229         }
230         
231         
232         
233           
234
235                 
236
237         }
238 }
239
240
241