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 bool generate_meson = false;
45 public Gee.ArrayList<string> packages; // list of vapi's that are used by this project.
47 //pblic Gee.ArrayList<string> hidden; // list of dirs to be hidden from display...
49 public GtkValaSettings? active_cg = null;
50 public Gee.HashMap<string,GtkValaSettings> compilegroups;
54 public Palete.Gtk gpalete {
56 return (Palete.Gtk) this.palete;
62 public Gtk(string path) {
67 this.initChildCache();
69 this.palete = new Palete.Gtk(this);
71 this.gir_cache = new Gee.HashMap<string,Palete.GirObject>();
73 //var gid = "project-gtk-%d".printf(gtk_id++);
75 this.packages = new Gee.ArrayList<string>();
76 //this.hidden = new Gee.ArrayList<string>();
77 this.compilegroups = new Gee.HashMap<string,GtkValaSettings>();
78 this.meson = new Meson(this);
82 public void initChildCache()
84 this.child_list_cache = new Gee.HashMap<string,Gee.ArrayList<string>>();
85 this.child_list_cache_props = new Gee.HashMap<string,Gee.ArrayList<string>>();
91 public override void loadJson(Json.Object obj)
93 // load a builder.config JSON file.
95 this.compilegroups = new Gee.HashMap<string,GtkValaSettings>();
97 if (obj.has_member("packages")) {
98 this.packages = this.readArray(obj.get_array_member("packages"));
100 if (obj.has_member("compiler_flags")) {
101 this.compile_flags = obj.get_string_member("compile_flags");
103 if (obj.has_member("version")) {
104 this.version = obj.get_string_member("version");
106 if (obj.has_member("licence")) {
107 this.licence = obj.get_string_member("licence");
109 if (obj.has_member("generate_meson")) {
110 this.generate_meson = obj.get_boolean_member("generate_meson");
112 if (!obj.has_member("compilegroups") || obj.get_member("compilegroups").get_node_type () != Json.NodeType.ARRAY) {
117 //this.hidden = this.readArray(obj.get_array_member("hidden"));
118 var ar = obj.get_array_member("compilegroups");
119 for(var i= 0;i<ar.get_length();i++) {
120 var el = ar.get_object_element(i);
121 var vs = new GtkValaSettings.from_json(this,el);
123 print("problem loading json file");
127 this.compilegroups.set(vs.name,vs);
131 //GLib.debug("%s\n",this.configToString ());
134 public override void saveJson(Json.Object obj)
136 var ar = new Json.Array();
137 foreach(var cg in this.compilegroups.values) {
138 ar.add_object_element(cg.toJson());
140 obj.set_array_member("compilegroups", ar);
142 obj.set_string_member("compile_flags", this.compile_flags);
143 obj.set_string_member("version", this.version);
144 obj.set_string_member("licence", this.licence);
145 obj.set_boolean_member("generate_meson",this.generate_meson);
146 var par = new Json.Array();
147 foreach(var p in this.packages) {
148 par.add_string_element(p);
150 obj.set_array_member("packages", par);
151 //var hi = new Json.Array();
152 //foreach(var p in this.hidden) {
153 // hi.add_string_element(p);
155 //obj.set_array_member("hidden", hi);
157 this.gir_cache_loaded = false; // force reload of the cache if we change the packages.
158 this.gpalete.loaded = false;
159 this.initChildCache();
160 this.gir_cache = null;
163 public override void onSave()
165 if (this.generate_meson) {
168 var vl = this.language_servers.get("vala");
170 vl.initialize_server(); // hopefully better than exit?
175 * perhaps we should select the default in the window somewhere...
177 public string firstBuildModule()
180 foreach(var cg in this.compilegroups.values) {
187 public string firstBuildModuleWith(JsRender.JsRender file)
189 foreach(var cg in this.compilegroups.values) {
190 if (cg.has_file(file)) {
196 return this.firstBuildModule();
200 public void loadVapiIntoStore(GLib.ListStore ls)
205 var pal = (Palete.Gtk) this.palete;
206 var pkgs = pal.packages(this);
207 foreach (var p in pkgs) {
208 ls.append(new VapiSelection(this.packages, p));
213 public void loadTargetsIntoStore(GLib.ListStore ls)
216 foreach(var cg in this.compilegroups.values) {
225 public string[] vapidirs()
227 return this.pathsMatching("vapi", false);
232 public override Palete.LanguageClient getLanguageServer(string lang)
234 if (this.language_servers.has_key(lang)) {
235 return this.language_servers.get(lang);
239 var ls = new Palete.LanguageClientVala(this);
240 ls.log.connect((act, msg) => {
241 //GLib.debug("log %s: %s", act.to_string(), msg);
242 BuilderApplication.showSpinnerLspLog(act,msg);
244 this.language_servers.set(lang, ls);
247 return this.language_servers.get("dummy");
250 return this.language_servers.get(lang);
259 // ------------------ new project stufff
260 public override void initialize()
262 this.generate_meson = true; // default to true on new projects.
288 for(var i = 0; i < dirs.length; i++) {
289 this.makeProjectSubdir( dirs[i]);
291 for(var i = 0; i < vapis.length; i++) {
292 this.packages.add(vapis[i]);
295 // create/// some dummy files?
299 this.makeApplication();
301 this.makeGitIgnore();
303 var cg = new GtkValaSettings(this, this.name);
304 this.compilegroups.set(this.name, cg);
305 cg.sources.add("src/Main.vala");
306 cg.sources.add("src/%sApplication.vala".printf(this.name));
307 cg.sources.add("src/ui/ui.Window.bjs");
308 // rescan... not needed as it get's selected after initialization.
310 var fn = this.getByPath(this.path + "/src/ui/ui.Window.bjs");
313 } catch (GLib.Error e) { } // do nothing?
322 void makeTemplatedFile(string name, string[] str, string replace)
325 for(var i=0;i< str.length;i++) {
326 o += str[i].replace("%s", replace) + "\n";
328 this.writeFile(name, o);
330 public void writeFile(string name, string o)
332 var f = GLib.File.new_for_path(this.path + "/" + name);
334 var data_out = new GLib.DataOutputStream( f.replace(null, false, GLib.FileCreateFlags.NONE, null) );
335 data_out.put_string(o, null);
336 data_out.close(null);
337 } catch (GLib.Error e) {
338 GLib.debug("Error writing file %s", e.message);
346 "int main (string[] args)",
348 " var app = new %sApplication( args);",
350 " GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR ); ",
351 " app.activate.connect(() => {",
352 " var w = new ui.Window();", // ?? main window as UI window?
353 " w.el.application = app;",
357 " var ret = app.run(args);",
361 this.makeTemplatedFile("src/Main.vala", str, this.name); // fixme name needs to be code friendly!
363 void makeApplication()
368 "public class %sApplication : Gtk.Application",
370 " public %sApplication (string[] args) ",
373 " application_id: \"org.roojs.%s\",",
374 " flags: ApplicationFlags.FLAGS_NONE",
381 this.makeTemplatedFile("src/%sApplication.vala".printf(this.name), str, this.name); // fixme name needs to be code friendly!
387 this.writeFile("src/ui/ui.Window.bjs", """{
392 "| void show" : "() { this.el.show(); }",
397 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
402 "string label" : "Hello World",
412 "name" : "ui.Window",
413 "gen_extended" : false
419 this.writeFile(".gitignore", """
425 public override void initDatabase()