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()
156 * perhaps we should select the default in the window somewhere...
158 public string firstBuildModule()
161 foreach(var cg in this.compilegroups.values) {
168 public string firstBuildModuleWith(JsRender.JsRender file)
170 foreach(var cg in this.compilegroups.values) {
171 if (cg.has_file(file)) {
177 return this.firstBuildModule();
181 public void loadVapiIntoStore(GLib.ListStore ls)
186 var pal = (Palete.Gtk) this.palete;
187 var pkgs = pal.packages(this);
188 foreach (var p in pkgs) {
189 ls.append(new VapiSelection(this.packages, p));
194 public void loadTargetsIntoStore(GLib.ListStore ls)
197 foreach(var cg in this.compilegroups.values) {
206 public string[] vapidirs()
208 return this.pathsMatching("vapi", false);
213 public override Palete.LanguageClient getLanguageServer(string lang)
215 if (this.language_servers.has_key(lang)) {
216 return this.language_servers.get(lang);
220 this.language_servers.set(lang, new Palete.LanguageClientVala(this));
223 return this.language_servers.get("dummy");
226 return this.language_servers.get(lang);
235 // ------------------ new project stufff
236 public override void initialize()
262 for(var i = 0; i < dirs.length; i++) {
263 this.makeProjectSubdir( dirs[i]);
265 for(var i = 0; i < vapis.length; i++) {
266 this.packages.add(vapis[i]);
269 // create/// some dummy files?
273 this.makeApplication();
277 var cg = new GtkValaSettings(this, this.name);
278 this.compilegroups.set(this.name, cg);
279 cg.sources.add("src/Main.vala");
280 cg.sources.add("src/%sApplication.vala".printf(this.name));
281 cg.sources.add("src/ui/ui.Window.bjs");
282 // rescan... not needed as it get's selected after initialization.
284 var fn = this.getByPath(this.path + "/src/ui/ui.Window.bjs");
287 } catch (GLib.Error e) { } // do nothing?
296 void makeTemplatedFile(string name, string[] str, string replace)
299 for(var i=0;i< str.length;i++) {
300 o += str[i].replace("%s", replace) + "\n";
302 this.writeFile(name, o);
304 public void writeFile(string name, string o)
306 var f = GLib.File.new_for_path(this.path + "/" + name);
308 var data_out = new GLib.DataOutputStream( f.replace(null, false, GLib.FileCreateFlags.NONE, null) );
309 data_out.put_string(o, null);
310 data_out.close(null);
311 } catch (GLib.Error e) {
312 GLib.debug("Error writing file %s", e.message);
320 "int main (string[] args)",
322 " var app = new %sApplication( args);",
324 " GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR ); ",
325 " app.activate.connect(() => {",
326 " var w = new ui.Window();", // ?? main window as UI window?
327 " w.el.application = app;",
331 " var ret = app.run(args);",
335 this.makeTemplatedFile("src/Main.vala", str, this.name); // fixme name needs to be code friendly!
337 void makeApplication()
342 "public class %sApplication : Gtk.Application",
344 " public %sApplication (string[] args) ",
347 " application_id: \"org.roojs.%s\",",
348 " flags: ApplicationFlags.FLAGS_NONE",
355 this.makeTemplatedFile("src/%sApplication.vala".printf(this.name), str, this.name); // fixme name needs to be code friendly!
361 this.writeFile("src/ui/ui.Window.bjs", """{
366 "| void show" : "() { this.el.show(); }",
371 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
376 "string label" : "Hello World",
386 "name" : "ui.Window",
387 "gen_extended" : false
395 public override void initDatabase()