10 public class Gtk : JsRender
14 public Gtk(Project.Project project, string path) {
18 this.language = "vala";
23 // var jstr = JSON.parse(cfg.json);
24 // this.items = [ jstr ];
25 // //console.log(cfg.items.length);
26 // delete cfg.json; // not needed!
32 this.id = "file-gtk-%d".printf(gid++);
34 // various loader methods..
36 // Class = list of arguments ... and which property to use as a value.
45 setNSID : function(id)
48 this.items[0]['*class'] = id;
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);
62 var vala = GLib.Path.get_dirname(this.path) +"/" + name + ".vala";
63 if (FileUtils.test(vala, FileTest.EXISTS)) {
64 GLib.FileUtils.remove(vala);
68 public override void loadItems() throws GLib.Error // : function(cb, sync) == original was async.
72 if (this.tree != null) {
76 print("load: " + this.path);
79 var pa = new Json.Parser();
80 pa.load_from_file(this.path);
81 var node = pa.get_root();
83 if (node.get_node_type () != Json.NodeType.OBJECT) {
84 throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
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");
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;
98 if (obj.has_member("items")
100 obj.get_member("items").get_node_type() == Json.NodeType.ARRAY
102 obj.get_array_member("items").get_length() > 0
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));
114 // convert xtype for munged output..
117 mungeXtype : function(xtype, els)
119 els.push('xtype: '+ xtype);
123 public override string toSourcePreview()
128 public override string toSource()
132 if (this.tree == null) {
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"];
142 for (var i=0; i< inc.length; i++) {
144 src += e+" = imports.gi." + e +";\n";
147 src += "console = imports.console;\n"; // path?!!?
148 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
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";
162 public override void save() {
164 // this.saveJS(); - disabled at present.. project settings will probably enable this later..
168 // ignore these calls.
169 public override void saveHTML ( string html ) {}
175 * save as a javascript file.
176 * why is this not save...???
183 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".js";
184 print("WRITE :%s\n " , fn);
185 this.writeFile(fn, this.toSource());
191 if (this.tree == null) {
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));
201 valaCompileCmd : function()
204 var fn = '/tmp/' + this.name + '.vala';
205 print("WRITE : " + fn);
206 File.write(fn, this.toVala(true));
213 "--pkg" , "gtk+-3.0",
214 "--pkg", "libnotify",
215 "--pkg", "gtksourceview-3.0",
216 "--pkg", "libwnck-3.0",
217 fn , "-o", "/tmp/" + this.name];
226 string getHelpUrl(string cls)
228 return "http://devel.akbkhome.com/seed/" + cls + ".html";
230 public void findTransStrings(Node node )