1 //<Script type="text/javascript">
3 * Gtk projects - normally vala based now..
5 * should have a few extra features..
9 * different versions (eg. different files can compile different versions - eg. for testing.
11 * If we model this like adjuta - then we would need a 'project' file that is actually in
12 * the directory somewhere... - and is revision controlled etc..
27 public class Gtk : Project
30 * Gir cache - it's local as we might want clear it if we modify the packages...
33 // public Gee.HashMap<string,Palete.GirObject> gir_cache = null; ??
35 public bool gir_cache_loaded = false; /// set this to false to force a relaod of vapi's?
37 // these are loaded / created by the palete.. but are project specific.
38 public Gee.HashMap<string,Gee.ArrayList<string>>? dropList = null;
39 public Gee.HashMap<string,Gee.ArrayList<string>> child_list_cache; // what child can on on what node
40 public Gee.HashMap<string,Gee.ArrayList<string>> child_list_cache_props; // what child can go on what node (with properties included)
42 public string compile_flags = ""; // generic to all.
43 public Gee.ArrayList<string> packages; // list of vapi's that are used by this project.
45 //pblic Gee.ArrayList<string> hidden; // list of dirs to be hidden from display...
47 public GtkValaSettings? active_cg = null;
48 public Gee.HashMap<string,GtkValaSettings> compilegroups;
52 public Palete.Gtk gpalete {
54 return (Palete.Gtk) this.palete;
60 public Gtk(string path) {
65 this.initChildCache();
67 this.palete = new Palete.Gtk(this);
69 this.gir_cache = new Gee.HashMap<string,Palete.GirObject>();
71 //var gid = "project-gtk-%d".printf(gtk_id++);
73 this.packages = new Gee.ArrayList<string>();
74 //this.hidden = new Gee.ArrayList<string>();
75 this.compilegroups = new Gee.HashMap<string,GtkValaSettings>();
76 this.meson = new Meson(this);
80 public void initChildCache()
82 this.child_list_cache = new Gee.HashMap<string,Gee.ArrayList<string>>();
83 this.child_list_cache_props = new Gee.HashMap<string,Gee.ArrayList<string>>();
89 public override void loadJson(Json.Object obj)
91 // load a builder.config JSON file.
93 this.compilegroups = new Gee.HashMap<string,GtkValaSettings>();
95 if (obj.has_member("packages")) {
96 this.packages = this.readArray(obj.get_array_member("packages"));
98 if (obj.has_member("compiler_flags")) {
99 this.compile_flags = obj.get_string_member("compile_flags");
101 if (obj.has_member("version")) {
102 this.version = obj.get_string_member("version");
104 if (obj.has_member("licence")) {
105 this.licence = obj.get_string_member("licence");
107 if (!obj.has_member("compilegroups") || obj.get_member("compilegroups").get_node_type () != Json.NodeType.ARRAY) {
112 //this.hidden = this.readArray(obj.get_array_member("hidden"));
113 var ar = obj.get_array_member("compilegroups");
114 for(var i= 0;i<ar.get_length();i++) {
115 var el = ar.get_object_element(i);
116 var vs = new GtkValaSettings.from_json(this,el);
118 print("problem loading json file");
122 this.compilegroups.set(vs.name,vs);
126 //GLib.debug("%s\n",this.configToString ());
129 public override void saveJson(Json.Object obj)
131 var ar = new Json.Array();
132 foreach(var cg in this.compilegroups.values) {
133 ar.add_object_element(cg.toJson());
135 obj.set_array_member("compilegroups", ar);
137 obj.set_string_member("compile_flags", this.compile_flags);
138 obj.set_string_member("version", this.version);
139 obj.set_string_member("licence", this.licence);
141 var par = new Json.Array();
142 foreach(var p in this.packages) {
143 par.add_string_element(p);
145 obj.set_array_member("packages", par);
146 //var hi = new Json.Array();
147 //foreach(var p in this.hidden) {
148 // hi.add_string_element(p);
150 //obj.set_array_member("hidden", hi);
152 this.gir_cache_loaded = false; // force reload of the cache if we change the packages.
153 this.gpalete.loaded = false;
154 this.initChildCache();
155 this.gir_cache = null;
158 public override void onSave()
161 var vl = this.language_servers.get("vala");
163 vl.initialize_server(); // hopefully better than exit?
168 * perhaps we should select the default in the window somewhere...
170 public string firstBuildModule()
173 foreach(var cg in this.compilegroups.values) {
180 public string firstBuildModuleWith(JsRender.JsRender file)
182 foreach(var cg in this.compilegroups.values) {
183 if (cg.has_file(file)) {
189 return this.firstBuildModule();
193 public void loadVapiIntoStore(GLib.ListStore ls)
198 var pal = (Palete.Gtk) this.palete;
199 var pkgs = pal.packages(this);
200 foreach (var p in pkgs) {
201 ls.append(new VapiSelection(this.packages, p));
206 public void loadTargetsIntoStore(GLib.ListStore ls)
209 foreach(var cg in this.compilegroups.values) {
218 public string[] vapidirs()
220 return this.pathsMatching("vapi", false);
225 public override Palete.LanguageClient getLanguageServer(string lang)
227 if (this.language_servers.has_key(lang)) {
228 return this.language_servers.get(lang);
232 var ls = new Palete.LanguageClientVala(this);
233 ls.log.connect((act, msg) => {
234 //GLib.debug("log %s: %s", act.to_string(), msg);
235 BuilderApplication.showSpinnerLspLog(act,msg);
237 this.language_servers.set(lang, ls);
240 return this.language_servers.get("dummy");
243 return this.language_servers.get(lang);
252 // ------------------ new project stufff
253 public override void initialize()
279 for(var i = 0; i < dirs.length; i++) {
280 this.makeProjectSubdir( dirs[i]);
282 for(var i = 0; i < vapis.length; i++) {
283 this.packages.add(vapis[i]);
286 // create/// some dummy files?
290 this.makeApplication();
292 this.makeGitIgnore();
294 var cg = new GtkValaSettings(this, this.name);
295 this.compilegroups.set(this.name, cg);
296 cg.sources.add("src/Main.vala");
297 cg.sources.add("src/%sApplication.vala".printf(this.name));
298 cg.sources.add("src/ui/ui.Window.bjs");
299 // rescan... not needed as it get's selected after initialization.
301 var fn = this.getByPath(this.path + "/src/ui/ui.Window.bjs");
304 } catch (GLib.Error e) { } // do nothing?
313 void makeTemplatedFile(string name, string[] str, string replace)
316 for(var i=0;i< str.length;i++) {
317 o += str[i].replace("%s", replace) + "\n";
319 this.writeFile(name, o);
321 public void writeFile(string name, string o)
323 var f = GLib.File.new_for_path(this.path + "/" + name);
325 var data_out = new GLib.DataOutputStream( f.replace(null, false, GLib.FileCreateFlags.NONE, null) );
326 data_out.put_string(o, null);
327 data_out.close(null);
328 } catch (GLib.Error e) {
329 GLib.debug("Error writing file %s", e.message);
337 "int main (string[] args)",
339 " var app = new %sApplication( args);",
341 " GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR ); ",
342 " app.activate.connect(() => {",
343 " var w = new ui.Window();", // ?? main window as UI window?
344 " w.el.application = app;",
348 " var ret = app.run(args);",
352 this.makeTemplatedFile("src/Main.vala", str, this.name); // fixme name needs to be code friendly!
354 void makeApplication()
359 "public class %sApplication : Gtk.Application",
361 " public %sApplication (string[] args) ",
364 " application_id: \"org.roojs.%s\",",
365 " flags: ApplicationFlags.FLAGS_NONE",
372 this.makeTemplatedFile("src/%sApplication.vala".printf(this.name), str, this.name); // fixme name needs to be code friendly!
378 this.writeFile("src/ui/ui.Window.bjs", """{
383 "| void show" : "() { this.el.show(); }",
388 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
393 "string label" : "Hello World",
403 "name" : "ui.Window",
404 "gen_extended" : false
410 this.writeFile(".gitignore", """
416 public override void initDatabase()