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.windowlist = new GLib.ListStore(typeof(WindowState));
153 //BuilderApplication.valacompilequeue = new Palete.ValaCompileQueue();
157 this.settings = AppSettings.factory();
158 var opt_context = new OptionContext ("Application Builder");
161 opt_context.set_help_enabled (true);
162 opt_context.add_main_entries (options, null);
163 opt_context.parse (ref args);
166 } catch (OptionError e) {
167 stdout.printf ("error: %s\n", e.message);
168 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
169 args[0], opt_context.get_help(true,null));
170 GLib.Process.exit(Posix.EXIT_FAILURE);
175 this.pullResources();
177 Project.Project.loadAll();
179 var cur_project = this.compileProject();
180 this.dropList(cur_project); // --drop-list
181 this.languageServer(cur_project); // --language-server
182 this.listFiles(cur_project);
183 this.testBjs(cur_project);
184 this.languageServer(cur_project);
185 this.compileBjs(cur_project);
186 //this.compileVala();
192 public static BuilderApplication singleton( string[]? args)
194 if (application==null && args != null) {
195 application = new BuilderApplication( args);
203 public static string configDirectory()
205 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
207 if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
208 var dir = File.new_for_path(dirname);
210 dir.make_directory();
212 GLib.error("Failed to make directory %s", dirname);
215 if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
216 var dir = File.new_for_path(dirname + "/resources");
218 dir.make_directory();
220 GLib.error("Failed to make directory %s", dirname + "/resources");
229 // --------------- non static...
235 if (BuilderApplication.opt_debug || BuilderApplication.opt_compile_project == null) {
236 GLib.Log.set_default_handler(
237 // GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING | GLib.LogLevelFlags.LEVEL_CRITICAL,
240 print("%s: %s : %s\n", (new DateTime.now_local()).format("%H:%M:%S.%f"), lvl.to_string(), msg);
242 if (dom== "GtkSourceView") { // seems to be some critical wanrings comming from gtksourceview related to insert?
245 //if (msg.contains("gdk_popup_present")) { // seems to be problems with the popup present on gtksourceview competion.
248 if (BuilderApplication.opt_debug && lvl == GLib.LogLevelFlags.LEVEL_CRITICAL) {
259 if (!BuilderApplication.opt_list_projects) {
262 print("Projects\n %s\n", Project.Project.listAllToString());
263 GLib.Process.exit(Posix.EXIT_SUCCESS);
266 Project.Project? compileProject()
269 if (BuilderApplication.opt_compile_project == null) {
272 Project.Project cur_project = null;
273 cur_project = Project.Project.getProjectByPath( BuilderApplication.opt_compile_project);
277 if (cur_project == null) {
278 GLib.error("invalid project %s, use --list-projects to show project ids",BuilderApplication.opt_compile_project);
288 void dropList(Project.Project? cur_project) {
291 if (cur_project== null || BuilderApplication.opt_drop_list == null) {
295 if (BuilderApplication.opt_compile_project == null) {
296 GLib.error("need a project %s, to use --drop-list",BuilderApplication.opt_compile_project);
298 if (cur_project.xtype != "Gtk") {
299 GLib.error("need a Gtk project %s, to use --drop-list",BuilderApplication.opt_compile_project);
301 var p = (Palete.Gtk) cur_project.palete;
303 print("\n\nDropList:\n%s", geeArrayToString(p.getDropList(BuilderApplication.opt_drop_list)));
304 print("\n\nChildList:\n%s", geeArrayToString(p.getChildList(BuilderApplication.opt_drop_list, false)));
305 print("\n\nChildList \n(with props): %s", geeArrayToString(p.getChildList(BuilderApplication.opt_drop_list, true)));
308 print("\n\nPropsList: %s", this.girArrayToString(p.getPropertiesFor( BuilderApplication.opt_drop_list, JsRender.NodePropType.PROP)));
309 print("\n\nSignalList: %s", this.girArrayToString(p.getPropertiesFor( BuilderApplication.opt_drop_list, JsRender.NodePropType.LISTENER)));
312 print("\n\nCtor Values: %s", p.fqnToNode(BuilderApplication.opt_drop_list).toJsonString());
314 GLib.Process.exit(Posix.EXIT_SUCCESS);
317 string geeArrayToString(Gee.ArrayList<string> ar)
320 foreach(var n in ar) {
325 string girArrayToString(Gee.HashMap<string,Palete.GirObject> map)
328 foreach(var gi in map.values) {
329 ret += "%s %s (%s)\n".printf(gi.type, gi.name, gi.propertyof);
337 void listFiles(Project.Project? cur_project)
339 if (!BuilderApplication.opt_list_files) {
342 if (cur_project == null) {
343 GLib.error("missing project, use --project to select which project");
345 print("Files for %s\n %s\n", cur_project.name, cur_project.listAllFilesToString());
346 GLib.Process.exit(Posix.EXIT_SUCCESS);
351 Test to see if the internal BJS reader/writer still outputs the same files.
352 -- probably need this for the generator as well.
355 void testBjs(Project.Project? cur_project)
357 if (!BuilderApplication.opt_bjs_test) {
360 if (cur_project == null) {
361 GLib.error("missing project, use --project to select which project");
363 print("Checking files\n");
365 var ar = cur_project.sortedFiles();
366 foreach(var file in ar) {
370 GLib.FileUtils.get_contents(file.path, out oldstr);
371 var outstr = file.toJsonString();
372 if (outstr != oldstr) {
374 GLib.FileUtils.set_contents("/tmp/" + file.name , outstr);
375 print("meld %s /tmp/%s\n", file.path, file.name);
376 //GLib.Process.exit(Posix.EXIT_SUCCESS);
378 print("# Files match %s\n", file.name);
381 } catch (FileError e) {
382 GLib.debug("Got error %s", e.message);
384 GLib.debug("Got error %s", e.message);
387 print("All files pass");
388 GLib.Process.exit(Posix.EXIT_SUCCESS);
391 void compileBjs(Project.Project? cur_project)
393 if (BuilderApplication.opt_bjs_compile == null) {
396 if (cur_project == null) {
397 GLib.error("missing project, use --project to select which project");
400 if (BuilderApplication.opt_bjs_compile == "all") {
402 var ar = cur_project.sortedFiles();
404 foreach(var file in ar) {
406 if (file is JsRender.PlainFile) {
412 var oldfn = file.targetName();
414 print("\n\n\n\nFile : %s\n", oldfn);
417 var outstr = file.toSourceCode();
419 /* line number checking
421 // check line numbers:
422 var bits = outstr.split("\n");
423 var end = bits.length;
424 for(var i = 0;i < end; i++) {
425 print("%i : %s\n", i+1 , bits[i]);
426 if (!bad && bits[i].has_prefix("/*") && !bits[i].has_prefix(("/*%d*" +"/").printf(i+1))) {
427 end = i + 5 > bits.length ? bits.length: (i + 5);
428 print ("^^^^ mismatch\null");
435 GLib.error("got bad file");
440 GLib.FileUtils.get_contents(oldfn, out oldstr);
441 if (outstr != oldstr) {
443 GLib.FileUtils.set_contents("/tmp/" + file.name + ".out", outstr);
444 print("meld %s /tmp/%s\n", oldfn, file.name + ".out");
445 //GLib.Process.exit(Posix.EXIT_SUCCESS);
447 //print("# Files match %s\n", file.name);
449 } catch (FileError e) {
450 GLib.debug("Got error %s", e.message);
452 GLib.debug("got error %s", e.message);
455 GLib.Process.exit(Posix.EXIT_SUCCESS);
461 var file = cur_project.getByRelPath(BuilderApplication.opt_bjs_compile);
463 // then compile them all, and compare them...
467 GLib.error("missing file %s in project %s", BuilderApplication.opt_bjs_compile, cur_project.name);
472 GLib.debug("Load items failed");
475 if (BuilderApplication.opt_bjs_compile_glade) {
476 var str = file.toGlade();
478 GLib.Process.exit(Posix.EXIT_SUCCESS);
481 //BuilderApplication.compileBjs();
483 var str = file.toSourceCode();
486 if (!BuilderApplication.opt_debug) {
488 GLib.Process.exit(Posix.EXIT_SUCCESS);
491 // dump the node tree
492 file.tree.dumpProps();
498 var str_ar = str.split("\n");
499 for(var i =0;i<str_ar.length;i++) {
500 var node = file.tree.lineToNode(i+1);
501 var prop = node == null ? null : node.lineToProp(i+1);
502 print("%d: %s : %s\n",
504 node == null ? "......" : (prop == null ? "????????" : prop.name),
509 GLib.Process.exit(Posix.EXIT_SUCCESS);
511 void languageServer(Project.Project? cur_project)
513 if (BuilderApplication.opt_language_server == null) {
516 if (cur_project == null) {
517 GLib.error("missing project, use --project to select which project");
519 var file = cur_project.getByRelPath(BuilderApplication.opt_language_server);
521 // then compile them all, and compare them...
522 GLib.error("missing file %s in project %s", BuilderApplication.opt_language_server, cur_project.name);
525 var ls = file.getLanguageServer();
527 GLib.error("No langauge server returned for file:%s", file.relpath);
530 //GLib.debug("started server - sleep 30 secs so you can gdb attach");
532 var loop = new MainLoop();
533 GLib.Timeout.add_seconds(1, () => {
535 GLib.debug("Sending document_open");
538 ls.document_open(file);
539 ls.document_save.begin( file, (o,res) => {
540 ls.document_save.end(res);
543 //ls.syntax.begin(file, (obj,res) => {
544 // ls.syntax.end(res);
555 GLib.Process.exit(Posix.EXIT_SUCCESS);
561 if (BuilderApplication.opt_compile_target == null) {
564 Palete.ValaSourceCompiler.buildApplication();
566 GLib.Process.exit(Posix.EXIT_SUCCESS);
572 if (!opt_pull_resources) {
575 var loop = new MainLoop();
576 Resources.singleton().updateProgress.connect((p,t) => {
577 print("Got %d/%d", (int) p,(int)t);
582 Resources.singleton().fetchStart();
584 GLib.Process.exit(Posix.EXIT_SUCCESS);
590 if (opt_test == null) {
596 help - list available tests
597 flutter-project - was try and read flutter data (but desnt work.)
600 case "flutter-project":
601 Project.Project.loadAll();
602 //var p = Project.Project.factory("Flutter", "/tmp/test-flutter");
603 /*var pa = p.palete as Palete.Flutter;
605 var ar = pa.getChildList("material.Scaffold");
606 GLib.debug("childlist for material.Scaffold is %s",
607 string.joinv( "\n-- ", ar)
609 ar = pa.getDropList("material.MaterialApp");
610 GLib.debug("droplist for material.MaterialApp is %s",
611 string.joinv( "\n-- ", ar)
620 print("Invalid test\n");
625 GLib.Process.exit(Posix.EXIT_SUCCESS);
629 // move to 'window colletction?
630 public static Gee.ArrayList<Xcls_MainWindow> windows;
631 public static GLib.ListStore windowlist;
633 public static void addWindow(Xcls_MainWindow w)
636 windowlist.append(w.windowstate);
637 BuilderApplication.windows.add(w);
643 public static void removeWindow(Xcls_MainWindow w)
645 //GLib.debug("remove window before = %d", BuilderApplication.windows.size);
646 BuilderApplication.windows.remove(w);
647 for(var i = 0 ; i < windowlist.get_n_items(); i++) {
648 var ws = windowlist.get_item(i) as WindowState;
649 if (ws.file.path == w.windowstate.file.path && ws.project.path == w.windowstate.project.path) {
650 windowlist.remove(i);
660 //GLib.debug("remove window after = %d", BuilderApplication.windows.size);
665 public static Xcls_MainWindow? getWindow(JsRender.JsRender file)
667 foreach(var ww in BuilderApplication.windows) {
668 if (ww.windowstate != null && ww.windowstate.file != null && ww.windowstate.file.path == file.path) {
676 public static void newWindow(JsRender.JsRender file, int line)
678 var w = new Xcls_MainWindow();
681 BuilderApplication.addWindow(w);
682 w.windowstate.init();
683 w.windowstate.fileViewOpen(file, false, line);
689 static int queue_update_compile_countdown = -1;
690 static uint queue_update_compile_id = 0;
692 public static void updateCompileResults( )
694 queue_update_compile_countdown = 2; // 1 second after last call.
695 if (queue_update_compile_id == 0) {
696 queue_update_compile_id = GLib.Timeout.add(100, () => {
697 if (queue_update_compile_countdown < 0) {
700 queue_update_compile_countdown--;
701 if (queue_update_compile_countdown < 0) {
702 realUpdateCompileResults();
711 public static void realUpdateCompileResults( )
716 foreach(var ww in BuilderApplication.windows) {
717 if (ww == null || ww.windowstate == null || ww.windowstate.project ==null) {
722 ww.windowstate.updateErrorMarksAll();
724 GLib.debug("calling udate Errors of window %s", ww.windowstate.file.targetName());
726 ww.windowstate.left_tree.updateErrors();
727 ww.windowstate.left_props.updateErrors();
733 public static void showSpinnerLspLog(Palete.LanguageClientAction action, string message) {
735 var msg = action.to_string() + " " + message;
738 case Palete.LanguageClientAction.INIT:
739 case Palete.LanguageClientAction.LAUNCH:
740 case Palete.LanguageClientAction.ACCEPT:
741 BuilderApplication.showSpinner( "software-update-available", msg );
744 case Palete.LanguageClientAction.DIAG:
745 BuilderApplication.showSpinner( "format-justify-fill", msg);
748 case Palete.LanguageClientAction.OPEN:
749 BuilderApplication.showSpinner( "document-open", msg);
751 case Palete.LanguageClientAction.SAVE:
752 BuilderApplication.showSpinner( "document-save", msg);
754 case Palete.LanguageClientAction.CLOSE:
755 BuilderApplication.showSpinner( "window.close", msg);
757 case Palete.LanguageClientAction.CHANGE:
758 BuilderApplication.showSpinner( "format-text-direction-ltr", msg);
760 case Palete.LanguageClientAction.TERM:
761 BuilderApplication.showSpinner( "media-playback-stop", msg);
763 case Palete.LanguageClientAction.COMPLETE:
764 BuilderApplication.showSpinner( "mail-send-recieve", msg);
767 case Palete.LanguageClientAction.COMPLETE_REPLY:
768 BuilderApplication.showSpinner( "face-cool", msg);
771 case Palete.LanguageClientAction.RESTART:
772 case Palete.LanguageClientAction.ERROR:
773 case Palete.LanguageClientAction.ERROR_START:
774 case Palete.LanguageClientAction.ERROR_RPC:
775 case Palete.LanguageClientAction.ERROR_REPLY:
776 BuilderApplication.showSpinner( "software-update-urgent", msg );
779 case Palete.LanguageClientAction.EXIT:
780 BuilderApplication.showSpinner( "face-sick", msg);
787 public static void showSpinner(string icon, string tooltip = "")
791 // doc change send: - spinner -
794 // ?? restart = software-update-urgent - crash?
797 foreach (var win in BuilderApplication.windows) {
799 win.statusbar_compile_spinner.start(icon, tooltip);
801 win.statusbar_compile_spinner.stop();