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;
51 public Palete.Gtk gpalete {
53 return (Palete.Gtk) this.palete;
59 public Gtk(string path) {
64 this.initChildCache();
66 this.palete = new Palete.Gtk(this);
68 this.gir_cache = new Gee.HashMap<string,Palete.GirObject>();
70 //var gid = "project-gtk-%d".printf(gtk_id++);
72 this.packages = new Gee.ArrayList<string>();
73 //this.hidden = new Gee.ArrayList<string>();
74 this.compilegroups = new Gee.HashMap<string,GtkValaSettings>();
78 public void initChildCache()
80 this.child_list_cache = new Gee.HashMap<string,Gee.ArrayList<string>>();
81 this.child_list_cache_props = new Gee.HashMap<string,Gee.ArrayList<string>>();
87 public override void loadJson(Json.Object obj)
89 // load a builder.config JSON file.
91 this.compilegroups = new Gee.HashMap<string,GtkValaSettings>();
93 if (obj.has_member("packages")) {
94 this.packages = this.readArray(obj.get_array_member("packages"));
96 if (obj.has_member("compiler_flags")) {
97 this.compile_flags = obj.get_string_member("compile_flags");
100 if (!obj.has_member("compilegroups") || obj.get_member("compilegroups").get_node_type () != Json.NodeType.ARRAY) {
105 //this.hidden = this.readArray(obj.get_array_member("hidden"));
106 var ar = obj.get_array_member("compilegroups");
107 for(var i= 0;i<ar.get_length();i++) {
108 var el = ar.get_object_element(i);
109 var vs = new GtkValaSettings.from_json(this,el);
111 print("problem loading json file");
115 this.compilegroups.set(vs.name,vs);
119 //GLib.debug("%s\n",this.configToString ());
122 public override void saveJson(Json.Object obj)
124 var ar = new Json.Array();
125 foreach(var cg in this.compilegroups.values) {
126 ar.add_object_element(cg.toJson());
128 obj.set_array_member("compilegroups", ar);
130 obj.set_string_member("compile_flags", this.compile_flags);
131 var par = new Json.Array();
132 foreach(var p in this.packages) {
133 par.add_string_element(p);
135 obj.set_array_member("packages", par);
136 //var hi = new Json.Array();
137 //foreach(var p in this.hidden) {
138 // hi.add_string_element(p);
140 //obj.set_array_member("hidden", hi);
142 this.gir_cache_loaded = false; // force reload of the cache if we change the packages.
143 this.gpalete.loaded = false;
144 this.initChildCache();
145 this.gir_cache = null;
150 * perhaps we should select the default in the window somewhere...
152 public string firstBuildModule()
155 foreach(var cg in this.compilegroups.values) {
162 public string firstBuildModuleWith(JsRender.JsRender file)
164 foreach(var cg in this.compilegroups.values) {
165 if (cg.has_file(file)) {
171 return this.firstBuildModule();
175 public void loadVapiIntoStore(GLib.ListStore ls)
180 var pal = (Palete.Gtk) this.palete;
181 var pkgs = pal.packages(this);
182 foreach (var p in pkgs) {
183 ls.append(new VapiSelection(this.packages, p));
188 public void loadTargetsIntoStore(GLib.ListStore ls)
191 foreach(var cg in this.compilegroups.values) {
200 public string[] vapidirs()
202 return this.pathsMatching("vapi", false);
205 public override void initialize()
231 for(var i = 0; i < dirs.length; i++) {
232 this.makeProjectSubdir( dirs[i]);
234 for(var i = 0; i < vapis.length; i++) {
235 this.packages.add(vapis[i]);
238 // create/// some dummy files?
242 this.makeApplication();
246 var cg = new GtkValaSettings(this, this.name);
247 this.compilegroups.set(this.name, cg);
248 cg.sources.add("src/Main.vala");
249 cg.sources.add("src/%sApplication.vala".printf(this.name));
250 cg.sources.add("src/ui/ui.Window.bjs");
251 // rescan... not needed as it get's selected after initialization.
253 var fn = this.getByPath(this.path + "/src/ui/ui.Window.bjs");
256 } catch (GLib.Error e) { } // do nothing?
265 void makeTemplatedFile(string name, string[] str, string replace)
268 for(var i=0;i< str.length;i++) {
269 o += str[i].replace("%s", replace) + "\n";
271 this.writeFile(name, o);
273 public void writeFile(string name, string o)
275 var f = GLib.File.new_for_path(this.path + "/" + name);
277 var data_out = new GLib.DataOutputStream( f.replace(null, false, GLib.FileCreateFlags.NONE, null) );
278 data_out.put_string(o, null);
279 data_out.close(null);
280 } catch (GLib.Error e) {
281 GLib.debug("Error writing file %s", e.message);
289 "int main (string[] args)",
291 " var app = new %sApplication( args);",
293 " GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR ); ",
294 " app.activate.connect(() => {",
295 " var w = new ui.Window();", // ?? main window as UI window?
296 " w.el.application = app;",
300 " var ret = app.run(args);",
304 this.makeTemplatedFile("src/Main.vala", str, this.name); // fixme name needs to be code friendly!
306 void makeApplication()
311 "public class %sApplication : Gtk.Application",
313 " public %sApplication (string[] args) ",
316 " application_id: \"org.roojs.%s\",",
317 " flags: ApplicationFlags.FLAGS_NONE",
324 this.makeTemplatedFile("src/%sApplication.vala".printf(this.name), str, this.name); // fixme name needs to be code friendly!
330 this.writeFile("src/ui/ui.Window.bjs", """{
335 "| void show" : "() { this.el.show(); }",
340 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
345 "string label" : "Hello World",
355 "name" : "ui.Window",
356 "gen_extended" : false
364 public override void initDatabase()