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("compilegroups") || obj.get_member("compilegroups").get_node_type () != Json.NodeType.ARRAY) {
114 //this.hidden = this.readArray(obj.get_array_member("hidden"));
115 var ar = obj.get_array_member("compilegroups");
116 for(var i= 0;i<ar.get_length();i++) {
117 var el = ar.get_object_element(i);
118 var vs = new GtkValaSettings.from_json(this,el);
120 print("problem loading json file");
124 this.compilegroups.set(vs.name,vs);
128 //GLib.debug("%s\n",this.configToString ());
131 public override void saveJson(Json.Object obj)
133 var ar = new Json.Array();
134 foreach(var cg in this.compilegroups.values) {
135 ar.add_object_element(cg.toJson());
137 obj.set_array_member("compilegroups", ar);
139 obj.set_string_member("compile_flags", this.compile_flags);
140 obj.set_string_member("version", this.version);
141 obj.set_string_member("licence", this.licence);
143 var par = new Json.Array();
144 foreach(var p in this.packages) {
145 par.add_string_element(p);
147 obj.set_array_member("packages", par);
148 //var hi = new Json.Array();
149 //foreach(var p in this.hidden) {
150 // hi.add_string_element(p);
152 //obj.set_array_member("hidden", hi);
154 this.gir_cache_loaded = false; // force reload of the cache if we change the packages.
155 this.gpalete.loaded = false;
156 this.initChildCache();
157 this.gir_cache = null;
160 public override void onSave()
162 if (this.generate_meson) {
165 var vl = this.language_servers.get("vala");
167 vl.initialize_server(); // hopefully better than exit?
172 * perhaps we should select the default in the window somewhere...
174 public string firstBuildModule()
177 foreach(var cg in this.compilegroups.values) {
184 public string firstBuildModuleWith(JsRender.JsRender file)
186 foreach(var cg in this.compilegroups.values) {
187 if (cg.has_file(file)) {
193 return this.firstBuildModule();
197 public void loadVapiIntoStore(GLib.ListStore ls)
202 var pal = (Palete.Gtk) this.palete;
203 var pkgs = pal.packages(this);
204 foreach (var p in pkgs) {
205 ls.append(new VapiSelection(this.packages, p));
210 public void loadTargetsIntoStore(GLib.ListStore ls)
213 foreach(var cg in this.compilegroups.values) {
222 public string[] vapidirs()
224 return this.pathsMatching("vapi", false);
229 public override Palete.LanguageClient getLanguageServer(string lang)
231 if (this.language_servers.has_key(lang)) {
232 return this.language_servers.get(lang);
236 var ls = new Palete.LanguageClientVala(this);
237 ls.log.connect((act, msg) => {
238 //GLib.debug("log %s: %s", act.to_string(), msg);
239 BuilderApplication.showSpinnerLspLog(act,msg);
241 this.language_servers.set(lang, ls);
244 return this.language_servers.get("dummy");
247 return this.language_servers.get(lang);
256 // ------------------ new project stufff
257 public override void initialize()
259 this.generate_meson = true; // default to true on new projects.
285 for(var i = 0; i < dirs.length; i++) {
286 this.makeProjectSubdir( dirs[i]);
288 for(var i = 0; i < vapis.length; i++) {
289 this.packages.add(vapis[i]);
292 // create/// some dummy files?
296 this.makeApplication();
298 this.makeGitIgnore();
300 var cg = new GtkValaSettings(this, this.name);
301 this.compilegroups.set(this.name, cg);
302 cg.sources.add("src/Main.vala");
303 cg.sources.add("src/%sApplication.vala".printf(this.name));
304 cg.sources.add("src/ui/ui.Window.bjs");
305 // rescan... not needed as it get's selected after initialization.
307 var fn = this.getByPath(this.path + "/src/ui/ui.Window.bjs");
310 } catch (GLib.Error e) { } // do nothing?
319 void makeTemplatedFile(string name, string[] str, string replace)
322 for(var i=0;i< str.length;i++) {
323 o += str[i].replace("%s", replace) + "\n";
325 this.writeFile(name, o);
327 public void writeFile(string name, string o)
329 var f = GLib.File.new_for_path(this.path + "/" + name);
331 var data_out = new GLib.DataOutputStream( f.replace(null, false, GLib.FileCreateFlags.NONE, null) );
332 data_out.put_string(o, null);
333 data_out.close(null);
334 } catch (GLib.Error e) {
335 GLib.debug("Error writing file %s", e.message);
343 "int main (string[] args)",
345 " var app = new %sApplication( args);",
347 " GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR ); ",
348 " app.activate.connect(() => {",
349 " var w = new ui.Window();", // ?? main window as UI window?
350 " w.el.application = app;",
354 " var ret = app.run(args);",
358 this.makeTemplatedFile("src/Main.vala", str, this.name); // fixme name needs to be code friendly!
360 void makeApplication()
365 "public class %sApplication : Gtk.Application",
367 " public %sApplication (string[] args) ",
370 " application_id: \"org.roojs.%s\",",
371 " flags: ApplicationFlags.FLAGS_NONE",
378 this.makeTemplatedFile("src/%sApplication.vala".printf(this.name), str, this.name); // fixme name needs to be code friendly!
384 this.writeFile("src/ui/ui.Window.bjs", """{
389 "| void show" : "() { this.el.show(); }",
394 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
399 "string label" : "Hello World",
409 "name" : "ui.Window",
410 "gen_extended" : false
416 this.writeFile(".gitignore", """
422 public override void initDatabase()