3 public class AppSettings : Object
8 // what are we going to have as settings?
9 public string roo_html_dir { get; set; }
13 this.notify.connect(() => {
18 public static AppSettings factory()
21 var setting_file = BuilderApplication.configDirectory() + "/builder.settings";
23 if (!FileUtils.test(setting_file, FileTest.EXISTS)) {
24 return new AppSettings();
28 FileUtils.get_contents(setting_file, out data);
29 return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings;
32 return new AppSettings();
36 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
37 var setting_file = dirname + "/builder.settings";
38 string data = Json.gobject_to_data (this, null);
39 GLib.debug("saving application settings\n");
41 FileUtils.set_contents(setting_file, data);
43 print("Error saving app settings");
51 public static BuilderApplication application = null;
53 public class BuilderApplication : Gtk.Application
56 // options - used when builder is run as a compiler
57 // we have to spawn ourself as a compiler as just running libvala
58 // as a task to check syntax causes memory leakage..
60 const OptionEntry[] options = {
63 { "project", 0, 0, OptionArg.STRING, ref opt_compile_project, "select a project", null },
64 { "target", 0, 0, OptionArg.STRING, ref opt_compile_target, "Target to build", null },
65 { "skip-linking", 0, 0, OptionArg.NONE, ref opt_skip_linking, "Do not link the files and make a binary - used to do syntax checking", null },
66 { "skip-file", 0, 0, OptionArg.STRING, ref opt_compile_skip ,"For test compiles do not add this (usually used in conjunction with add-file ", null },
67 { "add-file", 0, 0, OptionArg.STRING, ref opt_compile_add, "Add this file to compile list", null },
68 { "output", 0, 0, OptionArg.STRING, ref opt_compile_output, "output binary file path", null },
69 { "debug", 0, 0, OptionArg.NONE, ref opt_debug, "Show debug messages for non-ui, or crash on warnings for gdb ", null },
70 { "pull-resources", 0, 0, OptionArg.NONE, ref opt_pull_resources, "Fetch the online resources", null },
73 { "list-projects", 0, 0, OptionArg.NONE, ref opt_list_projects, "List Projects", null },
74 { "list-files", 0, 0, OptionArg.NONE, ref opt_list_files, "List Files (in a project", null},
75 { "bjs", 0, 0, OptionArg.STRING, ref opt_bjs_compile, "convert bjs file (use all to convert all of them and compare output)", null },
76 { "bjs-glade", 0, 0, OptionArg.NONE, ref opt_bjs_compile_glade, "output glade", null },
77 { "bjs-test-all", 0, 0, OptionArg.NONE, ref opt_bjs_test, "Test all the BJS files to see if the new parser/writer would change anything", null },
78 { "bjs-target", 0, 0, OptionArg.STRING, ref opt_bjs_compile_target, "convert bjs file to tareet : vala / js", null },
79 { "test", 0, 0, OptionArg.STRING, ref opt_test, "run a test use 'help' to list the available tests", null },
80 { "language-server", 0, 0, OptionArg.STRING, ref opt_language_server, "run language server on this file", null },
81 { "drop-list", 0, 0, OptionArg.STRING, ref opt_drop_list, "show droplist / children for a Gtk type (eg. Gtk.Widget)", null },
86 public static string opt_compile_project;
87 public static string opt_compile_target;
88 public static string opt_compile_skip;
89 public static string opt_compile_add;
90 public static string opt_compile_output;
91 public static string opt_bjs_compile;
92 public static string opt_bjs_compile_target;
93 public static string opt_test;
94 public static string opt_drop_list;
95 public static string opt_language_server;
97 public static bool opt_skip_linking = false;
98 public static bool opt_debug = false;
99 public static bool opt_list_projects = false;
100 public static bool opt_list_files = false;
101 public static bool opt_pull_resources = false;
102 public static bool opt_bjs_compile_glade = false;
103 public static bool opt_bjs_test = false;
104 public static string _self;
113 public const Gtk.TargetEntry[] targetList = {
114 { "INTEGER", 0, Target.INT32 },
115 { "STRING", 0, Target.STRING },
116 { "application/json", 0, Target.STRING },
117 { "text/plain", 0, Target.STRING },
118 { "application/x-rootwindow-drop", 0, Target.ROOTWIN }
121 public AppSettings settings = null;
125 //public static Palete.ValaCompileQueue valacompilequeue;
128 public BuilderApplication ( string[] args)
132 _self = FileUtils.read_link("/proc/self/exe");
134 // this should nto happen!!?
135 GLib.error("could not read /proc/self/exe");
137 GLib.debug("SELF = %s", _self);
138 var f = File.new_for_path(_self);
141 var fi = f.query_info("*",0);
142 dt = fi.get_creation_date_time().to_unix().to_string();
143 } catch (GLib.Error e) {
148 application_id: "org.roojs.%s.ver%s".printf( GLib.Path.get_basename(_self),dt),
149 flags: ApplicationFlags.FLAGS_NONE
151 BuilderApplication.windows = new Gee.ArrayList<Xcls_MainWindow>();
152 //BuilderApplication.valacompilequeue = new Palete.ValaCompileQueue();
156 this.settings = AppSettings.factory();
157 var opt_context = new OptionContext ("Application Builder");
160 opt_context.set_help_enabled (true);
161 opt_context.add_main_entries (options, null);
162 opt_context.parse (ref args);
165 } catch (OptionError e) {
166 stdout.printf ("error: %s\n", e.message);
167 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
168 args[0], opt_context.get_help(true,null));
169 GLib.Process.exit(Posix.EXIT_FAILURE);
174 this.pullResources();
176 Project.Project.loadAll();
178 var cur_project = this.compileProject();
179 this.dropList(cur_project); // --drop-list
180 this.languageServer(cur_project); // --language-server
181 this.listFiles(cur_project);
182 this.testBjs(cur_project);
183 this.languageServer(cur_project);
184 this.compileBjs(cur_project);
191 public static BuilderApplication singleton( string[]? args)
193 if (application==null && args != null) {
194 application = new BuilderApplication( args);
202 public static string configDirectory()
204 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
206 if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
207 var dir = File.new_for_path(dirname);
209 dir.make_directory();
211 GLib.error("Failed to make directory %s", dirname);
214 if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
215 var dir = File.new_for_path(dirname + "/resources");
217 dir.make_directory();
219 GLib.error("Failed to make directory %s", dirname + "/resources");
228 // --------------- non static...
234 if (BuilderApplication.opt_debug || BuilderApplication.opt_compile_project == null) {
235 GLib.Log.set_default_handler(
236 // GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING | GLib.LogLevelFlags.LEVEL_CRITICAL,
239 print("%s: %s : %s\n", (new DateTime.now_local()).format("%H:%M:%S.%f"), lvl.to_string(), msg);
241 if (dom== "GtkSourceView") { // seems to be some critical wanrings comming from gtksourceview related to insert?
244 //if (msg.contains("gdk_popup_present")) { // seems to be problems with the popup present on gtksourceview competion.
247 if (BuilderApplication.opt_debug && lvl == GLib.LogLevelFlags.LEVEL_CRITICAL) {
257 if (!BuilderApplication.opt_list_projects) {
260 print("Projects\n %s\n", Project.Project.listAllToString());
261 GLib.Process.exit(Posix.EXIT_SUCCESS);
264 Project.Project? compileProject()
267 if (BuilderApplication.opt_compile_project == null) {
270 Project.Project cur_project = null;
271 cur_project = Project.Project.getProjectByPath( BuilderApplication.opt_compile_project);
275 if (cur_project == null) {
276 GLib.error("invalid project %s, use --list-projects to show project ids",BuilderApplication.opt_compile_project);
286 void dropList(Project.Project? cur_project) {
289 if (cur_project== null || BuilderApplication.opt_drop_list == null) {
293 if (BuilderApplication.opt_compile_project == null) {
294 GLib.error("need a project %s, to use --drop-list",BuilderApplication.opt_compile_project);
296 if (cur_project.xtype != "Gtk") {
297 GLib.error("need a Gtk project %s, to use --drop-list",BuilderApplication.opt_compile_project);
299 var p = (Palete.Gtk) cur_project.palete;
301 print("\n\nDropList:\n%s", geeArrayToString(p.getDropList(BuilderApplication.opt_drop_list)));
302 print("\n\nChildList:\n%s", geeArrayToString(p.getChildList(BuilderApplication.opt_drop_list, false)));
303 print("\n\nChildList \n(with props): %s", geeArrayToString(p.getChildList(BuilderApplication.opt_drop_list, true)));
306 print("\n\nPropsList: %s", this.girArrayToString(p.getPropertiesFor( BuilderApplication.opt_drop_list, JsRender.NodePropType.PROP)));
307 print("\n\nSignalList: %s", this.girArrayToString(p.getPropertiesFor( BuilderApplication.opt_drop_list, JsRender.NodePropType.LISTENER)));
310 print("\n\nCtor Values: %s", p.fqnToNode(BuilderApplication.opt_drop_list).toJsonString());
312 GLib.Process.exit(Posix.EXIT_SUCCESS);
315 string geeArrayToString(Gee.ArrayList<string> ar)
318 foreach(var n in ar) {
323 string girArrayToString(Gee.HashMap<string,Palete.GirObject> map)
326 foreach(var gi in map.values) {
327 ret += "%s %s (%s)\n".printf(gi.type, gi.name, gi.propertyof);
335 void listFiles(Project.Project? cur_project)
337 if (!BuilderApplication.opt_list_files) {
340 if (cur_project == null) {
341 GLib.error("missing project, use --project to select which project");
343 print("Files for %s\n %s\n", cur_project.name, cur_project.listAllFilesToString());
344 GLib.Process.exit(Posix.EXIT_SUCCESS);
349 Test to see if the internal BJS reader/writer still outputs the same files.
350 -- probably need this for the generator as well.
353 void testBjs(Project.Project? cur_project)
355 if (!BuilderApplication.opt_bjs_test) {
358 if (cur_project == null) {
359 GLib.error("missing project, use --project to select which project");
361 print("Checking files\n");
363 var ar = cur_project.sortedFiles();
364 foreach(var file in ar) {
368 GLib.FileUtils.get_contents(file.path, out oldstr);
369 var outstr = file.toJsonString();
370 if (outstr != oldstr) {
372 GLib.FileUtils.set_contents("/tmp/" + file.name , outstr);
373 print("meld %s /tmp/%s\n", file.path, file.name);
374 //GLib.Process.exit(Posix.EXIT_SUCCESS);
376 print("# Files match %s\n", file.name);
379 } catch (FileError e) {
380 GLib.debug("Got error %s", e.message);
382 GLib.debug("Got error %s", e.message);
385 print("All files pass");
386 GLib.Process.exit(Posix.EXIT_SUCCESS);
389 void compileBjs(Project.Project? cur_project)
391 if (BuilderApplication.opt_bjs_compile == null) {
394 if (cur_project == null) {
395 GLib.error("missing project, use --project to select which project");
398 if (BuilderApplication.opt_bjs_compile == "all") {
400 var ar = cur_project.sortedFiles();
402 foreach(var file in ar) {
406 var oldfn = file.targetName();
407 GLib.FileUtils.get_contents(oldfn, out oldstr);
409 var outstr = file.toSourceCode();
410 if (outstr != oldstr) {
412 GLib.FileUtils.set_contents("/tmp/" + file.name + ".out", outstr);
413 print("meld %s /tmp/%s\n", oldfn, file.name + ".out");
414 //GLib.Process.exit(Posix.EXIT_SUCCESS);
416 print("# Files match %s\n", file.name);
418 } catch (FileError e) {
419 GLib.debug("Got error %s", e.message);
421 GLib.debug("got error %s", e.message);
424 GLib.Process.exit(Posix.EXIT_SUCCESS);
430 var file = cur_project.getByRelPath(BuilderApplication.opt_bjs_compile);
432 // then compile them all, and compare them...
439 GLib.error("missing file %s in project %s", BuilderApplication.opt_bjs_compile, cur_project.name);
444 GLib.debug("Load items failed");
447 if (BuilderApplication.opt_bjs_compile_glade) {
448 var str = file.toGlade();
450 GLib.Process.exit(Posix.EXIT_SUCCESS);
453 //BuilderApplication.compileBjs();
455 var str = file.toSourceCode();
458 if (!BuilderApplication.opt_debug) {
460 GLib.Process.exit(Posix.EXIT_SUCCESS);
463 // dump the node tree
464 file.tree.dumpProps();
470 var str_ar = str.split("\n");
471 for(var i =0;i<str_ar.length;i++) {
472 var node = file.tree.lineToNode(i+1);
473 var prop = node == null ? null : node.lineToProp(i+1);
474 print("%d: %s : %s\n",
476 node == null ? "......" : (prop == null ? "????????" : prop.name),
481 GLib.Process.exit(Posix.EXIT_SUCCESS);
483 void languageServer(Project.Project? cur_project)
485 if (BuilderApplication.opt_language_server == null) {
488 if (cur_project == null) {
489 GLib.error("missing project, use --project to select which project");
491 var file = cur_project.getByRelPath(BuilderApplication.opt_language_server);
493 // then compile them all, and compare them...
494 GLib.error("missing file %s in project %s", BuilderApplication.opt_language_server, cur_project.name);
497 var ls = file.getLanguageServer();
499 GLib.error("No langauge server returned for file:%s", file.relpath);
501 var loop = new MainLoop();
502 GLib.Timeout.add_seconds(1, () => {
504 GLib.debug("waiting for server to be ready");
507 GLib.debug("Sending document_open");
510 ls.document_open(file);
517 GLib.Process.exit(Posix.EXIT_SUCCESS);
523 if (BuilderApplication.opt_compile_target == null) {
526 Palete.ValaSourceCompiler.buildApplication();
528 GLib.Process.exit(Posix.EXIT_SUCCESS);
533 if (!opt_pull_resources) {
536 var loop = new MainLoop();
537 Resources.singleton().updateProgress.connect((p,t) => {
538 print("Got %d/%d", (int) p,(int)t);
543 Resources.singleton().fetchStart();
545 GLib.Process.exit(Posix.EXIT_SUCCESS);
551 if (opt_test == null) {
557 help - list available tests
558 flutter-project - was try and read flutter data (but desnt work.)
561 case "flutter-project":
562 Project.Project.loadAll();
563 //var p = Project.Project.factory("Flutter", "/tmp/test-flutter");
564 /*var pa = p.palete as Palete.Flutter;
566 var ar = pa.getChildList("material.Scaffold");
567 GLib.debug("childlist for material.Scaffold is %s",
568 string.joinv( "\n-- ", ar)
570 ar = pa.getDropList("material.MaterialApp");
571 GLib.debug("droplist for material.MaterialApp is %s",
572 string.joinv( "\n-- ", ar)
581 print("Invalid test\n");
586 GLib.Process.exit(Posix.EXIT_SUCCESS);
590 // move to 'window colletction?
591 public static Gee.ArrayList<Xcls_MainWindow> windows;
593 public static void addWindow(Xcls_MainWindow w)
596 BuilderApplication.windows.add(w);
597 BuilderApplication.updateWindows();
602 public static void removeWindow(Xcls_MainWindow w)
604 //GLib.debug("remove window before = %d", BuilderApplication.windows.size);
605 BuilderApplication.windows.remove(w);
606 BuilderApplication.updateWindows();
611 //GLib.debug("remove window after = %d", BuilderApplication.windows.size);
615 public static void updateWindows()
617 foreach(var ww in BuilderApplication.windows) {
618 ww.windowbtn.updateMenu();
621 public static Xcls_MainWindow? getWindow(JsRender.JsRender file)
623 foreach(var ww in BuilderApplication.windows) {
624 if (ww.windowstate != null && ww.windowstate.file != null && ww.windowstate.file.path == file.path) {
632 public static void newWindow(JsRender.JsRender file, int line)
634 var w = new Xcls_MainWindow();
636 BuilderApplication.addWindow(w);
638 w.windowstate.fileViewOpen(file, false, line);
644 public static void updateCompileResults( )
646 foreach(var ww in BuilderApplication.windows) {
647 if (ww == null || ww.windowstate == null || ww.windowstate.project ==null) {
651 ww.windowstate.updateErrorMarksAll();
653 GLib.debug("calling udate Errors of window %s", ww.windowstate.file.targetName());
660 public static void showSpinner(bool state)
662 foreach (var win in BuilderApplication.windows) {
664 win.statusbar_compile_spinner.start();
666 win.statusbar_compile_spinner.stop();