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);
211 public override void initialize()
237 for(var i = 0; i < dirs.length; i++) {
238 this.makeProjectSubdir( dirs[i]);
240 for(var i = 0; i < vapis.length; i++) {
241 this.packages.add(vapis[i]);
244 // create/// some dummy files?
248 this.makeApplication();
252 var cg = new GtkValaSettings(this, this.name);
253 this.compilegroups.set(this.name, cg);
254 cg.sources.add("src/Main.vala");
255 cg.sources.add("src/%sApplication.vala".printf(this.name));
256 cg.sources.add("src/ui/ui.Window.bjs");
257 // rescan... not needed as it get's selected after initialization.
259 var fn = this.getByPath(this.path + "/src/ui/ui.Window.bjs");
262 } catch (GLib.Error e) { } // do nothing?
271 void makeTemplatedFile(string name, string[] str, string replace)
274 for(var i=0;i< str.length;i++) {
275 o += str[i].replace("%s", replace) + "\n";
277 this.writeFile(name, o);
279 public void writeFile(string name, string o)
281 var f = GLib.File.new_for_path(this.path + "/" + name);
283 var data_out = new GLib.DataOutputStream( f.replace(null, false, GLib.FileCreateFlags.NONE, null) );
284 data_out.put_string(o, null);
285 data_out.close(null);
286 } catch (GLib.Error e) {
287 GLib.debug("Error writing file %s", e.message);
295 "int main (string[] args)",
297 " var app = new %sApplication( args);",
299 " GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR ); ",
300 " app.activate.connect(() => {",
301 " var w = new ui.Window();", // ?? main window as UI window?
302 " w.el.application = app;",
306 " var ret = app.run(args);",
310 this.makeTemplatedFile("src/Main.vala", str, this.name); // fixme name needs to be code friendly!
312 void makeApplication()
317 "public class %sApplication : Gtk.Application",
319 " public %sApplication (string[] args) ",
322 " application_id: \"org.roojs.%s\",",
323 " flags: ApplicationFlags.FLAGS_NONE",
330 this.makeTemplatedFile("src/%sApplication.vala".printf(this.name), str, this.name); // fixme name needs to be code friendly!
336 this.writeFile("src/ui/ui.Window.bjs", """{
341 "| void show" : "() { this.el.show(); }",
346 "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
351 "string label" : "Hello World",
361 "name" : "ui.Window",
362 "gen_extended" : false
370 public override void initDatabase()