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");
102 if (!obj.has_member("compilegroups") || obj.get_member("compilegroups").get_node_type () != Json.NodeType.ARRAY) {
107 //this.hidden = this.readArray(obj.get_array_member("hidden"));
108 var ar = obj.get_array_member("compilegroups");
109 for(var i= 0;i<ar.get_length();i++) {
110 var el = ar.get_object_element(i);
111 var vs = new GtkValaSettings.from_json(this,el);
113 print("problem loading json file");
117 this.compilegroups.set(vs.name,vs);
121 //GLib.debug("%s\n",this.configToString ());
124 public override void saveJson(Json.Object obj)
126 var ar = new Json.Array();
127 foreach(var cg in this.compilegroups.values) {
128 ar.add_object_element(cg.toJson());
130 obj.set_array_member("compilegroups", ar);
132 obj.set_string_member("compile_flags", this.compile_flags);
133 var par = new Json.Array();
134 foreach(var p in this.packages) {
135 par.add_string_element(p);
137 obj.set_array_member("packages", par);
138 //var hi = new Json.Array();
139 //foreach(var p in this.hidden) {
140 // hi.add_string_element(p);
142 //obj.set_array_member("hidden", hi);
144 this.gir_cache_loaded = false; // force reload of the cache if we change the packages.
145 this.gpalete.loaded = false;
146 this.initChildCache();
147 this.gir_cache = null;
150 public override void onSave()
153 var vl = this.language_servers.get("vala");
155 vl.initialize_server(); // hopefully better than exit?
160 * perhaps we should select the default in the window somewhere...
162 public string firstBuildModule()
165 foreach(var cg in this.compilegroups.values) {
172 public string firstBuildModuleWith(JsRender.JsRender file)
174 foreach(var cg in this.compilegroups.values) {
175 if (cg.has_file(file)) {
181 return this.firstBuildModule();
185 public void loadVapiIntoStore(GLib.ListStore ls)
190 var pal = (Palete.Gtk) this.palete;
191 var pkgs = pal.packages(this);
192 foreach (var p in pkgs) {
193 ls.append(new VapiSelection(this.packages, p));
198 public void loadTargetsIntoStore(GLib.ListStore ls)
201 foreach(var cg in this.compilegroups.values) {
210 public string[] vapidirs()
212 return this.pathsMatching("vapi", false);
217 public override Palete.LanguageClient getLanguageServer(string lang)
219 if (this.language_servers.has_key(lang)) {
220 return this.language_servers.get(lang);
224 var ls = new Palete.LanguageClientVala(this);
225 ls.log.connect((act, msg) => {
226 //GLib.debug("log %s: %s", act.to_string(), msg);
227 BuilderApplication.showSpinnerLspLog(act,msg);
229 this.language_servers.set(lang, ls);
232 return this.language_servers.get("dummy");
235 return this.language_servers.get(lang);
244 // ------------------ new project stufff
245 public override void initialize()
271 for(var i = 0; i < dirs.length; i++) {
272 this.makeProjectSubdir( dirs[i]);
274 for(var i = 0; i < vapis.length; i++) {
275 this.packages.add(vapis[i]);
278 // create/// some dummy files?
282 this.makeApplication();
284 this.makeGitIgnore();
286 var cg = new GtkValaSettings(this, this.name);
287 this.compilegroups.set(this.name, cg);
288 cg.sources.add("src/Main.vala");
289 cg.sources.add("src/%sApplication.vala".printf(this.name));
290 cg.sources.add("src/ui/ui.Window.bjs");
291 // rescan... not needed as it get's selected after initialization.
293 var fn = this.getByPath(this.path + "/src/ui/ui.Window.bjs");
296 } catch (GLib.Error e) { } // do nothing?
305 void makeTemplatedFile(string name, string[] str, string replace)
308 for(var i=0;i< str.length;i++) {
309 o += str[i].replace("%s", replace) + "\n";
311 this.writeFile(name, o);
313 public void writeFile(string name, string o)
315 var f = GLib.File.new_for_path(this.path + "/" + name);
317 var data_out = new GLib.DataOutputStream( f.replace(null, false, GLib.FileCreateFlags.NONE, null) );
318 data_out.put_string(o, null);
319 data_out.close(null);
320 } catch (GLib.Error e) {
321 GLib.debug("Error writing file %s", e.message);
329 "int main (string[] args)",
331 " var app = new %sApplication( args);",
333 " GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR ); ",
334 " app.activate.connect(() => {",
335 " var w = new ui.Window();", // ?? main window as UI window?
336 " w.el.application = app;",
340 " var ret = app.run(args);",
344 this.makeTemplatedFile("src/Main.vala", str, this.name); // fixme name needs to be code friendly!
346 void makeApplication()
351 "public class %sApplication : Gtk.Application",
353 " public %sApplication (string[] args) ",
356 " application_id: \"org.roojs.%s\",",
357 " flags: ApplicationFlags.FLAGS_NONE",
364 this.makeTemplatedFile("src/%sApplication.vala".printf(this.name), str, this.name); // fixme name needs to be code friendly!
370 this.writeFile("src/ui/ui.Window.bjs", """{
375 "| void show" : "() { this.el.show(); }",
380 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
385 "string label" : "Hello World",
395 "name" : "ui.Window",
396 "gen_extended" : false
402 this.writeFile(".gitignore", """
408 public override void initDatabase()