*/
-namespace Project {
- static int gtk_id = 1;
+namespace Project
+{
+
public class Gtk : Project
{
* Gir cache - it's local as we might want clear it if we modify the packages...
*
*/
- Gee.HashMap<string,Palate.Gir> cache = null;
-
+ // public Gee.HashMap<string,Palete.GirObject> gir_cache = null; ??
+
+ public bool gir_cache_loaded = false; /// set this to false to force a relaod of vapi's?
+
+ // these are loaded / created by the palete.. but are project specific.
+ public Gee.HashMap<string,Gee.ArrayList<string>>? dropList = null;
+ public Gee.HashMap<string,Gee.ArrayList<string>> child_list_cache; // what child can on on what node
+ public Gee.HashMap<string,Gee.ArrayList<string>> child_list_cache_props; // what child can go on what node (with properties included)
+
+ public string compile_flags = ""; // generic to all.
+ public Gee.ArrayList<string> packages; // list of vapi's that are used by this project.
+
+ //pblic Gee.ArrayList<string> hidden; // list of dirs to be hidden from display...
+
+ public GtkValaSettings? active_cg = null;
+ public Gee.HashMap<string,GtkValaSettings> compilegroups;
+ public Meson meson;
+
+
+ public Palete.Gtk gpalete {
+ get {
+ return (Palete.Gtk) this.palete;
+ }
+ set {}
+ }
+
+
public Gtk(string path) {
base(path);
- this.cache = new Gee.HashMap<string,Palate.Gir>()
+
+ this.initChildCache();
+
+ this.palete = new Palete.Gtk(this);
+
+ this.gir_cache = new Gee.HashMap<string,Palete.GirObject>();
this.xtype = "Gtk";
- var gid = "project-gtk-%d".printf(gtk_id++);
- this.id = gid;
- try {
- this.loadConfig();
- } catch (GLib.Error e ) {
- // is tihs ok?
- }
+ //var gid = "project-gtk-%d".printf(gtk_id++);
+ //this.id = gid;
+ this.packages = new Gee.ArrayList<string>();
+ //this.hidden = new Gee.ArrayList<string>();
+ this.compilegroups = new Gee.HashMap<string,GtkValaSettings>();
+ this.meson = new Meson(this);
}
- public Gee.HashMap<string,GtkValaSettings> compilegroups;
- public void loadConfig() throws GLib.Error
+ public void initChildCache()
+ {
+ this.child_list_cache = new Gee.HashMap<string,Gee.ArrayList<string>>();
+ this.child_list_cache_props = new Gee.HashMap<string,Gee.ArrayList<string>>();
+ this.dropList = null;
+ }
+
+
+
+ public override void loadJson(Json.Object obj)
{
// load a builder.config JSON file.
//
this.compilegroups = new Gee.HashMap<string,GtkValaSettings>();
-
- var fn = this.firstPath() + "/config1.builder";
- GLib.debug("load: " + fn );
-
- if (!FileUtils.test(fn, FileTest.EXISTS)) {
- this.compilegroups.set("_default_", new GtkValaSettings("_default_") );
- return;
+ if (obj.has_member("packages")) {
+ this.packages = this.readArray(obj.get_array_member("packages"));
}
-
- var pa = new Json.Parser();
- pa.load_from_file(fn);
- var node = pa.get_root();
-
- // should be an array really.
- if (node.get_node_type () != Json.NodeType.ARRAY) {
- throw new Error.INVALID_FORMAT ("Unexpected element type %s", node.type_name ());
+ if (obj.has_member("compiler_flags")) {
+ this.compile_flags = obj.get_string_member("compile_flags");
}
- var obj = node.get_array ();
- for(var i= 0;i<obj.get_length();i++) {
- var el = obj.get_object_element(i);
- var vs = new GtkValaSettings.from_json(el);
+ if (!obj.has_member("compilegroups") || obj.get_member("compilegroups").get_node_type () != Json.NodeType.ARRAY) {
+ // make _default_ ?
+ return;
+ }
+
+ //this.hidden = this.readArray(obj.get_array_member("hidden"));
+ var ar = obj.get_array_member("compilegroups");
+ for(var i= 0;i<ar.get_length();i++) {
+ var el = ar.get_object_element(i);
+ var vs = new GtkValaSettings.from_json(this,el);
if (vs == null) {
print("problem loading json file");
continue;
}
- if (vs.name != "_default_") {
- vs.parent = this.compilegroups.get("_default_");
- }
+
this.compilegroups.set(vs.name,vs);
}
- GLib.debug("%s\n",this.configToString ());
+
+
+ //GLib.debug("%s\n",this.configToString ());
}
- public string configToString()
+ public override void saveJson(Json.Object obj)
{
var ar = new Json.Array();
- var iter = this.compilegroups.map_iterator();
- while(iter.next()) {
-
- ar.add_object_element(iter.get_value().toJson());
+ foreach(var cg in this.compilegroups.values) {
+ ar.add_object_element(cg.toJson());
}
-
- var generator = new Json.Generator ();
- generator.indent = 4;
- generator.pretty = true;
- var node = new Json.Node(Json.NodeType.ARRAY);
- node.set_array(ar);
- generator.set_root(node);
- return generator.to_data(null);
+ obj.set_array_member("compilegroups", ar);
+
+ obj.set_string_member("compile_flags", this.compile_flags);
+ var par = new Json.Array();
+ foreach(var p in this.packages) {
+ par.add_string_element(p);
+ }
+ obj.set_array_member("packages", par);
+ //var hi = new Json.Array();
+ //foreach(var p in this.hidden) {
+ // hi.add_string_element(p);
+ //}
+ //obj.set_array_member("hidden", hi);
+
+ this.gir_cache_loaded = false; // force reload of the cache if we change the packages.
+ this.gpalete.loaded = false;
+ this.initChildCache();
+ this.gir_cache = null;
}
- public void writeConfig()
+ public override void onSave()
{
- var fn = this.firstPath() + "/config1.builder";
- GLib.debug("write: " + fn );
-
-
- var f = GLib.File.new_for_path(fn);
- var data_out = new GLib.DataOutputStream(
- f.replace(null, false, GLib.FileCreateFlags.NONE, null)
- );
- data_out.put_string(this.configToString(), null);
- data_out.close(null);
-
- return ;
-
+ this.meson.save();
+ var vl = this.language_servers.get("vala");
+ if (vl != null) {
+ vl.initialize_server(); // hopefully better than exit?
+ }
}
+
/**
* perhaps we should select the default in the window somewhere...
*/
public string firstBuildModule()
{
- var iter = this.compilegroups.map_iterator();
- while(iter.next()) {
-
- if (iter.get_value().name == "_default_") {
- continue;
- }
-
- return iter.get_value().name;
+
+ foreach(var cg in this.compilegroups.values) {
+ return cg.name;
+
}
return "";
+
}
-
-
- public string relPath(string target)
+ public string firstBuildModuleWith(JsRender.JsRender file)
{
- var basename = this.firstPath();
- // eg. base = /home/xxx/fred/blogs
- // target = /home/xxx/fred/jones
-
- // this does not work correctly...
- var bb = basename;
- var prefix = "";
- while (true) {
- if ( bb.length < target.length &&
- target.substring(0, bb.length) == bb) {
-
- return prefix + target.substring(bb.length );
- }
- if (bb.length < 1) {
- throw new Error.INVALID_FORMAT ("Could not work out relative path %s to %s",
- basename, target);
- }
- bb = GLib.Path.get_dirname(bb);
- prefix += "../";
-
+ foreach(var cg in this.compilegroups.values) {
+ if (cg.has_file(file)) {
+ return cg.name;
+ }
+
+
}
-
+ return this.firstBuildModule();
+
}
- /**
- * get a list of files for a folder..
- *
- * - in the project manager this has to list all possible compilable
- * files - eg. exclue XXX.vala.c or XXX.c with the same name as
- * a vala file (so to ignore the generated files)
- *
- * - for the editor navigation - this should exclude all files that
- * are vala based on a bjs file..
- *
- */
- public Gee.ArrayList<string> filesAll(string in_path,bool abspath = true)
+ public void loadVapiIntoStore(GLib.ListStore ls)
{
- var ret = new Gee.ArrayList<string>();
-
- var dirname = this.resolve_path(
- this.resolve_path_combine_path(this.firstPath(),in_path));
-
- GLib.debug("SCAN %s", dirname);
- // scan the directory for files -- ending with vala || c
-
-
- var dir = File.new_for_path(dirname);
- if (!dir.query_exists()) {
- GLib.debug("SCAN %s - skip - does not exist\n", dirname);
- return ret;
+ ls.remove_all();
+
+
+ var pal = (Palete.Gtk) this.palete;
+ var pkgs = pal.packages(this);
+ foreach (var p in pkgs) {
+ ls.append(new VapiSelection(this.packages, p));
}
- var pathprefix = abspath ? dirname : in_path;
-
- try {
- var file_enum = dir.enumerate_children(
- "standard::*",
- GLib.FileQueryInfoFlags.NONE,
- null
- );
-
-
- FileInfo next_file;
- while ((next_file = file_enum.next_file(null)) != null) {
- var fn = next_file.get_display_name();
-
- if (next_file.get_file_type () == GLib.FileType.DIRECTORY) {
-
- GLib.debug("SKIP %s not regular ", fn);
- continue;
- }
- if (!Regex.match_simple("^text", next_file.get_content_type())) {
- continue;
- }
- GLib.debug("SCAN ADD %s : %s", fn, next_file.get_content_type());
- ret.add(pathprefix + "/" + fn);
-
- // any other valid types???
-
- }
-
- } catch(Error e) {
- GLib.warning("oops - something went wrong scanning the projects\n");
- }
- return ret;
}
- public Gee.ArrayList<string> filesForCompile(string in_path, bool abspath = true)
+ public void loadTargetsIntoStore(GLib.ListStore ls)
{
- var allfiles = this.filesAll(in_path,abspath);
- var ret = new Gee.ArrayList<string>();
-
-
- for (var i = 0; i < allfiles.size; i ++) {
- var fn = allfiles.get(i);
- try {
- if (Regex.match_simple("\\.vala$", fn)) {
- ret.add( fn);
- continue;
- }
- // vala.c -- ignore..
- if (Regex.match_simple("\\.vala\\.c$", fn)) {
- continue;
- }
- // not a c file...
- if (!Regex.match_simple("\\.c$", fn)) {
- continue;
- }
-
- // is the c file the same as a vala file...
-
-
-
- var vv = (new Regex("\\.c$")).replace( fn, fn.length, 0, ".vala");
-
-
-
- if (allfiles.index_of( vv) > -1) {
- continue;
- }
- // add the 'c' file..
- ret.add(fn);
- } catch (Error e) {
- continue;
- }
+ ls.remove_all();
+ foreach(var cg in this.compilegroups.values) {
+ ls.append(cg);
}
- // sort.
- ret.sort((fa,fb) => {
- return ((string)fa).collate((string) fb);
- });
- return ret;
-
}
- public Gee.ArrayList<string> filesForOpen(string in_path)
+
+
+
+
+ public string[] vapidirs()
{
- var allfiles = this.filesAll(in_path);
- var ret = new Gee.ArrayList<string>();
- GLib.debug("SCAN %s - %d files",in_path, allfiles.size);
-
- for (var i = 0; i < allfiles.size; i ++) {
- var fn = allfiles.get(i);
- var bn = GLib.Path.get_basename(fn);
- try {
-
- if (Regex.match_simple("\\.vala\\.c$", fn)) {
- GLib.debug("SKIP %s - vala.c",fn);
-
- continue;
- }
-
- if (Regex.match_simple("\\.bjs$", fn)) {
- GLib.debug("SKIP %s - .bjs",fn);
- continue;
- }
-
- if (Regex.match_simple("\\~$", fn)) {
- GLib.debug("SKIP %s - ~",fn);
- continue;
- }
- if (Regex.match_simple("\\.stamp$", fn)) {
- GLib.debug("SKIP %s - .o",fn);
- continue;
- }
- if ("stamp-h1" == bn) {
- GLib.debug("SKIP %s - .o",fn);
- continue;
- }
-
- // confgure.am
- if ("config.h" == bn || "config.h.in" == bn || "config.log" == bn || "configure" == bn ) {
- if (allfiles.index_of( in_path +"/configure.ac") > -1) {
- continue;
- }
- }
- // makefile
- if ("Makefile" == bn || "Makefile.in" == bn ) {
- if (allfiles.index_of( in_path +"/Makefile.am") > -1) {
- continue;
- }
- }
-
- if (Regex.match_simple("^\\.", bn)) {
- GLib.debug("SKIP %s - hidden",fn);
- continue;
- }
- if (Regex.match_simple("\\.vala$", fn)) {
- var vv = (new Regex("\\.vala$")).replace( fn, fn.length, 0, ".bjs");
- if (allfiles.index_of( vv) > -1) {
- GLib.debug("SKIP %s - .vala (got bjs)",fn);
- continue;
- }
- GLib.debug("ADD %s",fn);
- ret.add( fn);
- continue;
- }
- // vala.c -- ignore..
-
- // not a c file...
- if (Regex.match_simple("\\.c$", fn)) {
-
- var vv = (new Regex("\\.c$")).replace( fn, fn.length, 0, ".vala");
- if (allfiles.index_of( vv) > -1) {
- GLib.debug("SKIP %s - .c (got vala)",fn);
- continue;
- }
- GLib.debug("ADD %s",fn);
- ret.add( fn);
- continue;
- }
-
- if (GLib.Path.get_basename( fn) == "config1.builder") {
- continue;
- }
- // not .c / not .vala /not .bjs.. -- other type of file..
- // allow ???
- GLib.debug("ADD %s",fn);
- // add the 'c' file..
- ret.add(fn);
- } catch (Error e) {
- GLib.debug("Exception %s",e.message);
- continue;
- }
- }
- // sort.
- ret.sort((fa,fb) => {
- return ((string)fa).collate((string) fb);
- });
- return ret;
-
+ return this.pathsMatching("vapi", false);
}
-
-
- public string resolve_path_combine_path(string first, string second)
- {
- string ret = first;
- if (first.length > 0 && second.length > 0 && !first.has_suffix("/") && !second.has_prefix("/"))
- {
- ret += "/";
+ public override Palete.LanguageClient getLanguageServer(string lang)
+ {
+ if (this.language_servers.has_key(lang)) {
+ return this.language_servers.get(lang);
}
- //print("combined path = %s", ret + second);
- return ret + second;
- }
- public string resolve_path_times(string part, int times, string? clue = null)
- {
- string ret = "";
- for (int i = 0; i < times; i++)
- {
- if (clue != null && i > 0)
- {
- ret += clue;
+ switch( lang ) {
+ case "vala":
+ var ls = new Palete.LanguageClientVala(this);
+ ls.log.connect((act, msg) => {
+ //GLib.debug("log %s: %s", act.to_string(), msg);
+ BuilderApplication.showSpinnerLspLog(act,msg);
+ });
+ this.language_servers.set(lang, ls);
+ break;
+ default :
+ return this.language_servers.get("dummy");
+
}
- ret += part;
- }
- return ret;
- }
- public string resolve_path(string _path, string? relative = null)
+ return this.language_servers.get(lang);
+
+ }
+
+
+
+
+
+
+ // ------------------ new project stufff
+ public override void initialize()
{
- string path = _path;
- if (relative != null)
- {
- path = this.resolve_path_combine_path(path, relative);
- }
- string[] parts = path.split("/");
- string[] ret = {};
- int relative_parts = 0;
-
- foreach (var part in parts)
- {
- if (part.length < 1 || part == ".")
- {
- continue;
- }
-
- if (part == "..")
- {
- if (ret.length > 0)
- {
- ret = ret[0: ret.length -1];
- }
- else
- {
- relative_parts++;
- }
- continue;
- }
-
- ret += part;
+ string[] dirs = {
+ "src",
+ "src/ui"
+ // ?? docs ?
+ //
+ };
+
+
+ string[] vapis = {
+ "gtk4",
+ "gee-0.8",
+ "gio-2.0",
+
+ "glib-2.0",
+ "gobject-2.0",
+
+ // "json-glib-1.0",
+
+ //"libadwaita-1",
+ //"libxml-2.0",
+ "posix"
+
+
+ };
+ for(var i = 0; i < dirs.length; i++) {
+ this.makeProjectSubdir( dirs[i]);
}
+ for(var i = 0; i < vapis.length; i++) {
+ this.packages.add(vapis[i]);
- path = this.resolve_path_combine_path(this.resolve_path_times("..", relative_parts, "/"), string.joinv("/", ret));
- if (_path.has_prefix("/"))
- {
- path = "/" + path;
}
- return path;
+ // create/// some dummy files?
+ // application
+
+ this.makeMain();
+ this.makeApplication();
+ this.makeWindow();
+ this.makeGitIgnore();
+
+ var cg = new GtkValaSettings(this, this.name);
+ this.compilegroups.set(this.name, cg);
+ cg.sources.add("src/Main.vala");
+ cg.sources.add("src/%sApplication.vala".printf(this.name));
+ cg.sources.add("src/ui/ui.Window.bjs");
+ // rescan... not needed as it get's selected after initialization.
+ this.load();
+ var fn = this.getByPath(this.path + "/src/ui/ui.Window.bjs");
+ try {
+ fn.loadItems();
+ } catch (GLib.Error e) { } // do nothing?
+
+ fn.save();
+
+
+
}
- public string[] vapidirs()
+
+ void makeTemplatedFile(string name, string[] str, string replace)
{
- string[] ret = {};
- var sources = this.compilegroups.get("_default_").sources;
- for(var i =0; i< sources.size; i++) {
-
- var path = this.resolve_path( this.firstPath(), sources.get(i));
-
- if (Path.get_basename (path) == "vapi") {
- GLib.debug("Adding VAPIDIR: %s\n", path);
- ret += path;
- }
-
+ var o = "";
+ for(var i=0;i< str.length;i++) {
+ o += str[i].replace("%s", replace) + "\n";
}
- return ret;
-
+ this.writeFile(name, o);
}
- public string[] sourcedirs()
+ public void writeFile(string name, string o)
{
- string[] ret = {};
- var sources = this.compilegroups.get("_default_").sources;
- ret += this.firstPath();
- for(var i =0; i< sources.size; i++) {
-
- var path = this.resolve_path( this.firstPath(), sources.get(i));
- if (path == this.firstPath()) {
- continue;
- }
- if (Path.get_basename (path) == "vapi") {
- continue;
-
- }
- // GLib.debug("Adding VAPIDIR: %s\n", path);
- ret += path;
+ var f = GLib.File.new_for_path(this.path + "/" + name);
+ try {
+ var data_out = new GLib.DataOutputStream( f.replace(null, false, GLib.FileCreateFlags.NONE, null) );
+ data_out.put_string(o, null);
+ data_out.close(null);
+ } catch (GLib.Error e) {
+ GLib.debug("Error writing file %s", e.message);
}
- return ret;
- }
-
- }
- // an object describing a build config (or generic ...)
- public class GtkValaSettings : Object {
- public string name;
- public GtkValaSettings? parent;
-
- public string compile_flags; // generic to all.
- public Gee.ArrayList<string> packages; // list of packages?? some might be genericly named?
- public Gee.ArrayList<string> sources; // list of files+dirs (relative to project)
- public string target_bin;
-
- public string execute_args;
+ }
-
- public GtkValaSettings(string name)
+ void makeMain()
{
- this.name = name;
- this.compile_flags = "";
- this.target_bin = "";
- this.packages = new Gee.ArrayList<string>();
- this.sources = new Gee.ArrayList<string>();
- this.execute_args = "";
-
+ string[] str = {
+ "int main (string[] args)",
+ "{",
+ " var app = new %sApplication( args);",
+ " Gtk.init ();",
+ " GLib.Log.set_always_fatal(LogLevelFlags.LEVEL_ERROR ); ",
+ " app.activate.connect(() => {",
+ " var w = new ui.Window();", // ?? main window as UI window?
+ " w.el.application = app;",
+ " w.ref();",
+ " w.show();",
+ " });",
+ " var ret = app.run(args);",
+ " return ret; ",
+ "}"
+ };
+ this.makeTemplatedFile("src/Main.vala", str, this.name); // fixme name needs to be code friendly!
}
-
-
- public GtkValaSettings.from_json(Json.Object el) {
-
+ void makeApplication()
+ {
+ string[] str = {
- this.name = el.get_string_member("name");
- this.compile_flags = el.get_string_member("compile_flags");
- if ( el.has_member("execute_args")) {
- this.execute_args = el.get_string_member("execute_args");
- } else {
- this.execute_args = "";
- }
- this.target_bin = el.get_string_member("target_bin");
- // sources and packages.
- this.sources = this.readArray(el.get_array_member("sources"));
- this.packages = this.readArray(el.get_array_member("packages"));
-
+
+ "public class %sApplication : Gtk.Application",
+ "{",
+ " public %sApplication (string[] args) ",
+ " {",
+ " Object(",
+ " application_id: \"org.roojs.%s\",",
+ " flags: ApplicationFlags.FLAGS_NONE",
+ " );",
+ " }",
+ "}"
+ };
+
+
+ this.makeTemplatedFile("src/%sApplication.vala".printf(this.name), str, this.name); // fixme name needs to be code friendly!
}
+
- // why not array of strings?
-
- public Gee.ArrayList<string> readArray(Json.Array ar)
+ void makeWindow()
{
- var ret = new Gee.ArrayList<string>();
- for(var i =0; i< ar.get_length(); i++) {
- ret.add(ar.get_string_element(i));
- }
- return ret;
- }
+ this.writeFile("src/ui/ui.Window.bjs", """{
+ "build_module" : "",
+ "items" : [
+ {
+ "$ xns" : "Gtk",
+ "| void show" : "() { this.el.show(); }",
+ "items" : [
+ {
+ "$ xns" : "Gtk",
+ "* prop" : "child",
+ "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
+ "int spacing" : 0,
+ "items" : [
+ {
+ "$ xns" : "Gtk",
+ "string label" : "Hello World",
+ "xtype" : "Label"
+ }
+ ],
+ "xtype" : "Box"
+ }
+ ],
+ "xtype" : "Window"
+ }
+ ],
+ "name" : "ui.Window",
+ "gen_extended" : false
+}
+""");
+ }
+ void makeGitIgnore()
+ {
+ this.writeFile(".gitignore", """
+build/
+""");
+ }
+
- public Json.Object toJson()
+ public override void initDatabase()
{
- var ret = new Json.Object();
- ret.set_string_member("name", this.name);
- ret.set_string_member("compile_flags", this.compile_flags);
- ret.set_string_member("execute_args", this.execute_args);
- ret.set_string_member("target_bin", this.target_bin);
- ret.set_array_member("sources", this.writeArray(this.sources));
- ret.set_array_member("packages", this.writeArray(this.packages));
- return ret;
- }
- public Json.Array writeArray(Gee.ArrayList<string> ar) {
- var ret = new Json.Array();
- for(var i =0; i< ar.size; i++) {
- ret.add_string_element(ar.get(i));
- }
- return ret;
+ // nOOP
}
-
-
}
-
+
}