3 * this is the code that creates a rendered view of the Gtk applications
17 public class Gtk : JsRender
21 public Gtk(Project.Project project, string path) {
25 this.language = "vala";
30 // var jstr = JSON.parse(cfg.json);
31 // this.items = [ jstr ];
32 // //console.log(cfg.items.length);
33 // delete cfg.json; // not needed!
39 this.id = "file-gtk-%d".printf(gid++);
41 // various loader methods..
43 // Class = list of arguments ... and which property to use as a value.
52 setNSID : function(id)
55 this.items[0]['*class'] = id;
64 public override void removeFiles() {
65 var js = GLib.Path.get_dirname(this.path) +"/" + name + ".js";
66 if (FileUtils.test(js, FileTest.EXISTS)) {
67 GLib.FileUtils.remove(js);
69 var vala = GLib.Path.get_dirname(this.path) +"/" + name + ".vala";
70 if (FileUtils.test(vala, FileTest.EXISTS)) {
71 GLib.FileUtils.remove(vala);
75 public override void loadItems() throws GLib.Error // : function(cb, sync) == original was async.
79 if (this.tree != null) {
83 print("load: " + this.path);
86 var pa = new Json.Parser();
87 pa.load_from_file(this.path);
88 var node = pa.get_root();
90 if (node.get_node_type () != Json.NodeType.OBJECT) {
91 throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
93 var obj = node.get_object ();
94 //this.modOrder = obj.get_string_member("modOrder");
95 this.name = obj.get_string_member("name");
96 this.parent = obj.get_string_member("parent");
97 //this.permname = obj.get_string_member("permname");
98 this.title = obj.get_string_member("title");
99 //this.modOrder = obj.get_string_member("modOrder");
101 // load items[0] ??? into tree...
102 var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
103 bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
105 if (obj.has_member("items")
107 obj.get_member("items").get_node_type() == Json.NodeType.ARRAY
109 obj.get_array_member("items").get_length() > 0
111 var ar = obj.get_array_member("items");
112 var tree_base = ar.get_object_element(0);
113 this.tree = new Node();
114 this.tree.loadFromJson(tree_base, int.parse(bjs_version_str));
121 // convert xtype for munged output..
124 mungeXtype : function(xtype, els)
126 els.push('xtype: '+ xtype);
130 public override string toSourcePreview()
135 public override string toSource()
139 if (this.tree == null) {
143 // var data = JSON.parse(JSON.stringify(this.items[0]));
144 // we should base this on the objects in the tree really..
145 string[] inc = { "Gtk", "Gdk", "Pango", "GLib", "Gio", "GObject",
146 "GtkSource", "WebKit", "Vte" }; //, "GtkClutter" , "Gdl"];
149 for (var i=0; i< inc.length; i++) {
151 src += e+" = imports.gi." + e +";\n";
154 src += "console = imports.console;\n"; // path?!!?
155 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
158 src += this.name + "=new XObject("+ this.mungeToString(" ") + ");\n";
159 src += this.name + ".init();\n";
160 // register it in the cache
161 src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
169 public override void save() {
171 // this.saveJS(); - disabled at present.. project settings will probably enable this later..
175 // ignore these calls.
176 public override void saveHTML ( string html ) {}
182 * save as a javascript file.
183 * why is this not save...???
190 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".js";
191 print("WRITE :%s\n " , fn);
192 this.writeFile(fn, this.toSource());
198 if (this.tree == null) {
201 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".vala";
202 print("WRITE :%s\n " , fn);
203 this.writeFile(fn, NodeToVala.mungeFile(this));
208 valaCompileCmd : function()
211 var fn = '/tmp/' + this.name + '.vala';
212 print("WRITE : " + fn);
213 File.write(fn, this.toVala(true));
220 "--pkg" , "gtk+-3.0",
221 "--pkg", "libnotify",
222 "--pkg", "gtksourceview-3.0",
223 "--pkg", "libwnck-3.0",
224 fn , "-o", "/tmp/" + this.name];
233 string getHelpUrl(string cls)
235 return "http://devel.akbkhome.com/seed/" + cls + ".html";
237 public override void findTransStrings(Node? node )