4 * this is the code represents a File when using the Gtk view..
18 public class PlainFile : JsRender
22 public PlainFile(Project.Project project, string path) {
25 this.xtype = "PlainFile";
29 this.language = "vala";
34 // var jstr = JSON.parse(cfg.json);
35 // this.items = [ jstr ];
36 // //console.log(cfg.items.length);
37 // delete cfg.json; // not needed!
43 this.id = "file-gtk-%d".printf(gid++);
45 // various loader methods..
47 // Class = list of arguments ... and which property to use as a value.
56 setNSID : function(id)
59 this.items[0]['*class'] = id;
68 public override void removeFiles() {
69 var js = GLib.Path.get_dirname(this.path) +"/" + name + ".js";
70 if (FileUtils.test(js, FileTest.EXISTS)) {
71 GLib.FileUtils.remove(js);
73 var vala = GLib.Path.get_dirname(this.path) +"/" + name + ".vala";
74 if (FileUtils.test(vala, FileTest.EXISTS)) {
75 GLib.FileUtils.remove(vala);
79 public override void loadItems() throws GLib.Error // : function(cb, sync) == original was async.
83 if (this.tree != null) {
87 print("load: " + this.path);
90 var pa = new Json.Parser();
91 pa.load_from_file(this.path);
92 var node = pa.get_root();
94 if (node.get_node_type () != Json.NodeType.OBJECT) {
95 throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
97 var obj = node.get_object ();
99 this.name = obj.get_string_member("name");
100 this.parent = obj.get_string_member("parent");
101 this.title = obj.get_string_member("title");
103 if (obj.has_member("build_module")) { // should check type really..
104 this.build_module = obj.get_string_member("build_module");
107 // load items[0] ??? into tree...
108 var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
109 bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
111 if (obj.has_member("items")
113 obj.get_member("items").get_node_type() == Json.NodeType.ARRAY
115 obj.get_array_member("items").get_length() > 0
117 var ar = obj.get_array_member("items");
118 var tree_base = ar.get_object_element(0);
119 this.tree = new Node();
120 this.tree.loadFromJson(tree_base, int.parse(bjs_version_str));
123 NodeToVala.mungeFile(this); // force line numbering..
129 public override string toSourcePreview()
134 public override string toSource()
138 if (this.tree == null) {
142 // var data = JSON.parse(JSON.stringify(this.items[0]));
143 // we should base this on the objects in the tree really..
144 string[] inc = { "Gtk", "Gdk", "Pango", "GLib", "Gio", "GObject",
145 "GtkSource", "WebKit", "Vte" }; //, "GtkClutter" , "Gdl"];
148 for (var i=0; i< inc.length; i++) {
150 src += e+" = imports.gi." + e +";\n";
153 src += "console = imports.console;\n"; // path?!!?
154 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
157 src += this.name + "=new XObject("+ this.mungeToString(" ") + ");\n";
158 src += this.name + ".init();\n";
159 // register it in the cache
160 src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
168 public override void save() {
170 // this.saveJS(); - disabled at present.. project settings will probably enable this later..
174 // ignore these calls.
175 public override void saveHTML ( string html ) {}
181 * save as a javascript file.
182 * why is this not save...???
189 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".js";
190 print("WRITE :%s\n " , fn);
191 this.writeFile(fn, this.toSource());
197 if (this.tree == null) {
200 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".vala";
201 print("WRITE :%s\n " , fn);
202 this.writeFile(fn, NodeToVala.mungeFile(this));
207 valaCompileCmd : function()
210 var fn = '/tmp/' + this.name + '.vala';
211 print("WRITE : " + fn);
212 File.write(fn, this.toVala(true));
219 "--pkg" , "gtk+-3.0",
220 "--pkg", "libnotify",
221 "--pkg", "gtksourceview-3.0",
222 "--pkg", "libwnck-3.0",
223 fn , "-o", "/tmp/" + this.name];
232 string getHelpUrl(string cls)
234 return "http://devel.akbkhome.com/seed/" + cls + ".html";
236 public override void findTransStrings(Node? node )