3 * this is the code represents a File when using the Gtk view..
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.
78 print("load Items!\n");
79 if (this.tree != null) {
84 print("load: %s\n" , this.path);
87 var pa = new Json.Parser();
88 pa.load_from_file(this.path);
89 var node = pa.get_root();
91 if (node.get_node_type () != Json.NodeType.OBJECT) {
92 throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
94 var obj = node.get_object ();
96 this.name = obj.get_string_member("name");
97 this.parent = obj.get_string_member("parent");
98 this.title = obj.get_string_member("title");
100 if (obj.has_member("build_module")) { // should check type really..
101 this.build_module = obj.get_string_member("build_module");
104 // load items[0] ??? into tree...
105 var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
106 bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
108 if (obj.has_member("items")
110 obj.get_member("items").get_node_type() == Json.NodeType.ARRAY
112 obj.get_array_member("items").get_length() > 0
114 var ar = obj.get_array_member("items");
115 var tree_base = ar.get_object_element(0);
116 this.tree = new Node();
117 this.tree.loadFromJson(tree_base, int.parse(bjs_version_str));
120 NodeToVala.mungeFile(this); // force line numbering..
127 public override string toSourcePreview()
131 public override void setSource(string str) {}
133 public override string toSource()
137 if (this.tree == null) {
141 // var data = JSON.parse(JSON.stringify(this.items[0]));
142 // we should base this on the objects in the tree really..
143 string[] inc = { "Gtk", "Gdk", "Pango", "GLib", "Gio", "GObject",
144 "GtkSource", "WebKit", "Vte" }; //, "GtkClutter" , "Gdl"];
147 for (var i=0; i< inc.length; i++) {
149 src += e+" = imports.gi." + e +";\n";
152 src += "console = imports.console;\n"; // path?!!?
153 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
156 src += this.name + "=new XObject("+ this.mungeToString(" ") + ");\n";
157 src += this.name + ".init();\n";
158 // register it in the cache
159 src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
167 public override void save() {
169 // this.saveJS(); - disabled at present.. project settings will probably enable this later..
173 // ignore these calls.
174 public override void saveHTML ( string html ) {}
180 * save as a javascript file.
181 * why is this not save...???
188 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".js";
189 print("WRITE :%s\n " , fn);
190 this.writeFile(fn, this.toSource());
196 if (this.tree == null) {
199 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".vala";
200 print("WRITE :%s\n " , fn);
201 this.writeFile(fn, NodeToVala.mungeFile(this));
206 valaCompileCmd : function()
209 var fn = '/tmp/' + this.name + '.vala';
210 print("WRITE : " + fn);
211 File.write(fn, this.toVala(true));
218 "--pkg" , "gtk+-3.0",
219 "--pkg", "libnotify",
220 "--pkg", "gtksourceview-3.0",
221 "--pkg", "libwnck-3.0",
222 fn , "-o", "/tmp/" + this.name];
231 string getHelpUrl(string cls)
233 return "http://devel.akbkhome.com/seed/" + cls + ".html";
235 public override void findTransStrings(Node? node )