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 this.id = "file-plain-%d".printf(gid++);
36 // various loader methods..
38 // Class = list of arguments ... and which property to use as a value.
47 setNSID : function(id)
50 this.items[0]['*class'] = id;
59 public override void removeFiles() {
60 var js = GLib.Path.get_dirname(this.path) +"/" + name + ".js";
61 if (FileUtils.test(js, FileTest.EXISTS)) {
62 GLib.FileUtils.remove(js);
64 var vala = GLib.Path.get_dirname(this.path) +"/" + name + ".vala";
65 if (FileUtils.test(vala, FileTest.EXISTS)) {
66 GLib.FileUtils.remove(vala);
70 public override void loadItems() throws GLib.Error // : function(cb, sync) == original was async.
74 if (this.tree != null) {
78 print("load: " + this.path);
81 var pa = new Json.Parser();
82 pa.load_from_file(this.path);
83 var node = pa.get_root();
85 if (node.get_node_type () != Json.NodeType.OBJECT) {
86 throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
88 var obj = node.get_object ();
90 this.name = obj.get_string_member("name");
91 this.parent = obj.get_string_member("parent");
92 this.title = obj.get_string_member("title");
94 if (obj.has_member("build_module")) { // should check type really..
95 this.build_module = obj.get_string_member("build_module");
98 // load items[0] ??? into tree...
99 var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
100 bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
102 if (obj.has_member("items")
104 obj.get_member("items").get_node_type() == Json.NodeType.ARRAY
106 obj.get_array_member("items").get_length() > 0
108 var ar = obj.get_array_member("items");
109 var tree_base = ar.get_object_element(0);
110 this.tree = new Node();
111 this.tree.loadFromJson(tree_base, int.parse(bjs_version_str));
114 NodeToVala.mungeFile(this); // force line numbering..
120 public override string toSourcePreview()
125 public override string toSource()
129 if (this.tree == null) {
133 // var data = JSON.parse(JSON.stringify(this.items[0]));
134 // we should base this on the objects in the tree really..
135 string[] inc = { "Gtk", "Gdk", "Pango", "GLib", "Gio", "GObject",
136 "GtkSource", "WebKit", "Vte" }; //, "GtkClutter" , "Gdl"];
139 for (var i=0; i< inc.length; i++) {
141 src += e+" = imports.gi." + e +";\n";
144 src += "console = imports.console;\n"; // path?!!?
145 src += "XObject = imports.XObject.XObject;\n"; // path?!!?
148 src += this.name + "=new XObject("+ this.mungeToString(" ") + ");\n";
149 src += this.name + ".init();\n";
150 // register it in the cache
151 src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
159 public override void save() {
161 // this.saveJS(); - disabled at present.. project settings will probably enable this later..
165 // ignore these calls.
166 public override void saveHTML ( string html ) {}
172 * save as a javascript file.
173 * why is this not save...???
180 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".js";
181 print("WRITE :%s\n " , fn);
182 this.writeFile(fn, this.toSource());
188 if (this.tree == null) {
191 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".vala";
192 print("WRITE :%s\n " , fn);
193 this.writeFile(fn, NodeToVala.mungeFile(this));
198 valaCompileCmd : function()
201 var fn = '/tmp/' + this.name + '.vala';
202 print("WRITE : " + fn);
203 File.write(fn, this.toVala(true));
210 "--pkg" , "gtk+-3.0",
211 "--pkg", "libnotify",
212 "--pkg", "gtksourceview-3.0",
213 "--pkg", "libwnck-3.0",
214 fn , "-o", "/tmp/" + this.name];
223 string getHelpUrl(string cls)
225 return "http://devel.akbkhome.com/seed/" + cls + ".html";
227 public override void findTransStrings(Node? node )