3 * this is the code represents a File when using the Gtk view..
17 public class Gtk : JsRender
21 public Project.Gtk gproject {
23 return (Project.Gtk) this.project;
28 public Gtk(Project.Project project, string path) {
32 this.language = "vala";
37 // var jstr = JSON.parse(cfg.json);
38 // this.items = [ jstr ];
39 // //console.log(cfg.items.length);
40 // delete cfg.json; // not needed!
46 this.id = "file-gtk-%d".printf(gid++);
48 // various loader methods..
50 // Class = list of arguments ... and which property to use as a value.
59 setNSID : function(id)
62 this.items[0]['*class'] = id;
71 public override void removeFiles() {
72 var js = GLib.Path.get_dirname(this.path) +"/" + name + ".js";
73 if (FileUtils.test(js, FileTest.EXISTS)) {
74 GLib.FileUtils.remove(js);
76 var vala = GLib.Path.get_dirname(this.path) +"/" + name + ".vala";
77 if (FileUtils.test(vala, FileTest.EXISTS)) {
78 GLib.FileUtils.remove(vala);
82 public override void loadItems() throws GLib.Error // : function(cb, sync) == original was async.
85 print("load Items!\n");
86 if (this.tree != null) {
92 print("load: %s\n" , this.path);
93 if (!GLib.FileUtils.test(this.path, GLib.FileTest.EXISTS)) {
101 var pa = new Json.Parser();
102 pa.load_from_file(this.path);
103 var node = pa.get_root();
105 if (node.get_node_type () != Json.NodeType.OBJECT) {
106 throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
108 var obj = node.get_object ();
110 this.name = obj.get_string_member("name");
113 if (obj.has_member("build_module")) { // should check type really..
114 this.build_module = obj.get_string_member("build_module");
116 if (obj.has_member("gen_extended")) { // should check type really..
117 this.gen_extended = obj.get_boolean_member("gen_extended");
122 // load items[0] ??? into tree...
123 var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
124 bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
126 if (obj.has_member("items")
128 obj.get_member("items").get_node_type() == Json.NodeType.ARRAY
130 obj.get_array_member("items").get_length() > 0
132 var ar = obj.get_array_member("items");
133 var tree_base = ar.get_object_element(0);
134 this.tree = new Node();
135 this.tree.loadFromJson(tree_base, int.parse(bjs_version_str));
139 NodeToValaExtended.mungeFile(this) :
140 NodeToValaWrapped.mungeFile(this); // force line numbering..?? should we call toSourceCode???
147 public override string toSourcePreview()
151 public override void setSource(string str) {}
153 int last_source_version = -2;
155 public override string toSourceCode() // no seed support currently.
157 if (this.version == this.last_source_version) {
158 GLib.debug("toSource - using Cache");
159 return this.last_source;
161 GLib.debug("toSource - generating %s", this.gen_extended ? "Extended": "Wrapped");
163 this.last_source = this.gen_extended ?
164 NodeToValaExtended.mungeFile(this) :
165 NodeToValaWrapped.mungeFile(this);
166 this.last_source_version = this.version;
167 return this.last_source;
171 // this is only used by dumping code...
172 public override string toSource() // no seed support currently.
175 return this.toSourceCode();
180 public override void save() {
182 // this.saveJS(); - disabled at present.. project settings will probably enable this later..
186 this.getLanguageServer().document_save.begin(this, (obj, res) => {
187 this.getLanguageServer().document_save.end(res);
189 BuilderApplication.showSpinner("spinner", "document save send");
191 // ignore these calls.
192 public override void saveHTML ( string html ) {}
198 * save as a javascript file. - not used currently
199 * why is this not save...???
206 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".js";
207 print("WRITE :%s\n " , fn);
208 this.writeFile(fn, this.toSource());
213 public override string targetName()
215 return GLib.Path.get_dirname(this.path) + "/" + this.name + ".vala";
220 if (this.tree == null) {
223 var fn = this.targetName();
224 GLib.debug("WRITE :%s\n " , fn);
226 this.writeFile(fn, this.toSourceCode());
227 } catch (GLib.Error e) {}
233 public void updateCompileGroup(string old_target, string new_target)
235 if (old_target == new_target) {
238 if (old_target != "") {
239 if (this.gproject.compilegroups.has_key(old_target)) {
240 var cg = this.gproject.compilegroups.get(old_target);
241 if (cg.sources.contains(this.relpath)) {
242 cg.sources.remove(this.relpath);
246 if (new_target != "") {
247 if (this.gproject.compilegroups.has_key(new_target)) {
248 var cg = this.gproject.compilegroups.get(new_target);
249 if (!cg.sources.contains(this.relpath)) {
250 cg.sources.add(this.relpath);
259 valaCompileCmd : function()
262 var fn = '/tmp/' + this.name + '.vala';
263 print("WRITE : " + fn);
264 File.write(fn, this.toVala(true));
271 "--pkg" , "gtk+-3.0",
272 "--pkg", "libnotify",
273 "--pkg", "gtksourceview-3.0",
274 "--pkg", "libwnck-3.0",
275 fn , "-o", "/tmp/" + this.name];
283 public override void findTransStrings(Node? node )
288 public override string toGlade()
290 return NodeToGlade.mungeFile(this);
292 public override string language_id()