Fix #8025 - move css to resources
[roobuilder] / src / Application.vala
1
2  /*
3         public class AppSettings : Object
4         {
5
6                 
7                 
8                 // what are we going to have as settings?
9                 public string roo_html_dir { get; set; }
10
11                 public AppSettings()
12                 {
13                         this.notify.connect(() => {
14                                 this.save();
15                         });
16                 }
17  
18                 public static AppSettings factory()
19                 {
20                          
21                         var setting_file = BuilderApplication.configDirectory() + "/builder.settings";
22                         
23                         if (!FileUtils.test(setting_file, FileTest.EXISTS)) {
24                                  return new AppSettings();
25                         }
26                         string data; 
27                         try { 
28                                 FileUtils.get_contents(setting_file, out data);
29                                 return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings;
30                         } catch (Error e) {
31                         }
32                         return new AppSettings();
33                 }
34                 public void save()
35                 {
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");
40                         try {
41                                 FileUtils.set_contents(setting_file,   data);
42                         } catch (Error e) {
43                                 print("Error saving app settings");
44                         }
45                 }
46
47                 
48         }
49         */
50         
51         public static BuilderApplication application = null;
52         
53         public class BuilderApplication : Gtk.Application
54         {
55                 
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..
59                 // 
60                 const OptionEntry[] options = {
61                 
62                         
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 },                 
71             
72             // some testing code.
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 },
82             
83             
84                         { null }
85                 };
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;
96         
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;
105                 
106                 public enum Target {
107                     INT32,
108                     STRING,
109                     ROOTWIN
110                 }
111
112 /*
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 }
119                 };
120                 */
121                 //public AppSettings settings = null;
122
123
124
125                 //public static Palete.ValaCompileQueue valacompilequeue;
126
127         
128                 public BuilderApplication (  string[] args)
129                 {
130                         
131                         try {
132                                 _self = FileUtils.read_link("/proc/self/exe");
133                         } catch (Error e) {
134                                 // this should nto happen!!?
135                                 GLib.error("could not read /proc/self/exe");
136                         }
137                         GLib.debug("SELF = %s", _self);
138                         var f =  File.new_for_path(_self);
139                         var dt = "0000";
140                         try {
141                                 var fi = f.query_info("*",0);
142                                 dt = fi.get_creation_date_time().to_unix().to_string();
143                         } catch (GLib.Error e) {
144                                 // skip.
145                         }
146                         
147                         Object(
148                                 application_id: "org.roojs.%s.ver%s".printf( GLib.Path.get_basename(_self),dt),
149                                 flags: ApplicationFlags.FLAGS_NONE
150                         );
151                         BuilderApplication.windows = new        Gee.ArrayList<Xcls_MainWindow>();
152                         BuilderApplication.windowlist = new GLib.ListStore(typeof(WindowState));
153                         //BuilderApplication.valacompilequeue = new Palete.ValaCompileQueue();
154                         
155                         
156                         configDirectory();
157                 //      this.settings = AppSettings.factory();  
158                         var opt_context = new OptionContext ("Application Builder");
159                         
160                         try {
161                                 opt_context.set_help_enabled (true);
162                                 opt_context.add_main_entries (options, null);
163                                 opt_context.parse (ref args);
164                                  
165                                 
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);
171                                  
172                         }
173                         this.initDebug();
174                         this.runTests();                        
175                         this.pullResources();
176                         
177                 Project.Project.loadAll();
178                         this.listProjects();
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();
187
188                 }
189
190                 public static Settings settings;
191
192                 protected override void activate () 
193                 {
194                         var css = new Gtk.CssProvider();
195                         css.load_from_resource("/css/roobuilder.css");
196                         
197                         
198                         Gtk.StyleContext.add_provider_for_display(
199                                 Gdk.Display.get_default(),
200                                 css     ,
201                                 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
202                         );
203                         BuilderApplication.settings = new Settings();
204                 
205                         var w = new Xcls_MainWindow();
206                     w.initChildren();
207                         BuilderApplication.addWindow(w);
208                         
209                         // it looks like showall after children causes segfault on ubuntu 14.4
210                         w.windowstate.init();
211                 //      w.windowstate.showPopoverFiles(w.open_projects_btn.el, null, false);
212                         w.show();
213                 
214                 }
215                 
216                 public static BuilderApplication  singleton(  string[]? args)
217                 {
218                         if (application==null && args != null) {
219                                 application = new BuilderApplication(  args);
220  
221                         
222                         }
223                         return application;
224                 }
225
226                 
227                 public static string configDirectory()
228                 {
229                         var dirname = GLib.Environment.get_home_dir() + "/.Builder";
230                 
231                         if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
232                                 var dir = File.new_for_path(dirname);
233                                 try {
234                                         dir.make_directory();   
235                                 } catch (Error e) {
236                                         GLib.error("Failed to make directory %s", dirname);
237                                 } 
238                         }
239                         if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
240                                 var dir = File.new_for_path(dirname + "/resources");
241                                 try {
242                                         dir.make_directory();   
243                                 } catch (Error e) {
244                                         GLib.error("Failed to make directory %s", dirname + "/resources");
245                                 } 
246                         }
247
248                 
249                         return dirname;
250                 }
251                 
252                 
253                 // --------------- non static...
254                 
255                 void initDebug() 
256                 {
257                          
258                         
259                         if (BuilderApplication.opt_debug  || BuilderApplication.opt_compile_project == null) {
260                                 GLib.Log.set_default_handler( 
261                                 //      GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING | GLib.LogLevelFlags.LEVEL_CRITICAL, 
262                                         (dom, lvl, msg) => {
263
264                                         print("%s: %s : %s\n", (new DateTime.now_local()).format("%H:%M:%S.%f"), lvl.to_string(), msg);
265                                         
266                                         if (dom== "GtkSourceView") { // seems to be some critical wanrings comming from gtksourceview related to insert?
267                                                 return;
268                                         }
269                                         //if (msg.contains("gdk_popup_present")) { // seems to be problems with the popup present on gtksourceview competion.
270                                         //      return;
271                                         //}
272                                         if (BuilderApplication.opt_debug && lvl ==  GLib.LogLevelFlags.LEVEL_CRITICAL) {
273                                                 GLib.error(msg);
274                                         }
275                                 });
276                         }
277                         
278                         
279                 
280                 }
281                 void listProjects()
282                 {
283                         if (!BuilderApplication.opt_list_projects) {
284                                 return;
285                         }
286                         print("Projects\n %s\n", Project.Project.listAllToString());
287                         GLib.Process.exit(Posix.EXIT_SUCCESS);
288                 
289                 }
290                 Project.Project? compileProject()
291                 {
292                         
293                         if (BuilderApplication.opt_compile_project == null) {
294                                 return null;
295                          }
296                         Project.Project cur_project = null;
297                         cur_project = Project.Project.getProjectByPath( BuilderApplication.opt_compile_project);
298                         
299
300                         
301                         if (cur_project == null) {
302                                 GLib.error("invalid project %s, use --list-projects to show project ids",BuilderApplication.opt_compile_project);
303                         }
304                         cur_project.load();
305
306                         
307
308                         return cur_project;
309                 
310                 }
311                 
312                 void dropList(Project.Project? cur_project) {
313
314
315                         if (cur_project== null || BuilderApplication.opt_drop_list == null) {
316                                 return;
317                         }
318                         
319                         if (BuilderApplication.opt_compile_project == null) {
320                                 GLib.error("need a project %s, to use --drop-list",BuilderApplication.opt_compile_project);
321                          }
322                           if (cur_project.xtype != "Gtk") {
323                                 GLib.error("need a Gtk project %s, to use --drop-list",BuilderApplication.opt_compile_project);
324                          }
325                          var p = (Palete.Gtk) cur_project.palete;
326                         
327                          print("\n\nDropList:\n%s", geeArrayToString(p.getDropList(BuilderApplication.opt_drop_list)));
328                          print("\n\nChildList:\n%s", geeArrayToString(p.getChildList(BuilderApplication.opt_drop_list, false)));
329                          print("\n\nChildList \n(with props): %s", geeArrayToString(p.getChildList(BuilderApplication.opt_drop_list, true)));   
330                          
331                          
332                          print("\n\nPropsList: %s", this.girArrayToString(p.getPropertiesFor( BuilderApplication.opt_drop_list, JsRender.NodePropType.PROP)));
333                          print("\n\nSignalList: %s", this.girArrayToString(p.getPropertiesFor( BuilderApplication.opt_drop_list, JsRender.NodePropType.LISTENER)));
334                          
335                          // ctor.
336                           print("\n\nCtor Values: %s", p.fqnToNode(BuilderApplication.opt_drop_list).toJsonString());
337                          
338                           GLib.Process.exit(Posix.EXIT_SUCCESS);
339                         
340                 }
341                 string geeArrayToString(Gee.ArrayList<string> ar) 
342                 {
343                         var ret = "";
344                         foreach(var n in ar) {
345                                 ret +=   n + "\n";
346                          }
347                          return ret;
348                 }
349                 string girArrayToString(Gee.HashMap<string,Palete.GirObject> map) 
350                 {
351                         var ret = "";
352                         foreach(var gi in map.values) {
353                                  ret += "%s %s (%s)\n".printf(gi.type, gi.name, gi.propertyof);
354                         
355                         }
356                         return ret;
357                 
358                 }
359                  
360                 
361                 void listFiles(Project.Project? cur_project)
362                 {
363                         if (!BuilderApplication.opt_list_files) {
364                                 return;
365                         }
366                         if (cur_project == null) {
367                                 GLib.error("missing project, use --project to select which project");
368                         }
369                         print("Files for %s\n %s\n", cur_project.name, cur_project.listAllFilesToString());
370                         GLib.Process.exit(Posix.EXIT_SUCCESS);
371                         
372                 }
373                 
374                 /**
375                  Test to see if the internal BJS reader/writer still outputs the same files.
376                  -- probably need this for the generator as well.
377                 */
378                 
379                 void testBjs(Project.Project? cur_project)
380                 {
381                         if (!BuilderApplication.opt_bjs_test) {
382                                 return;
383                         }
384                         if (cur_project == null) {
385                                 GLib.error("missing project, use --project to select which project");
386                         }
387                         print("Checking files\n");
388                         try { 
389                                 var ar = cur_project.sortedFiles();
390                                 foreach(var file in ar) {
391                                         string oldstr;
392
393                                         file.loadItems();
394                                         GLib.FileUtils.get_contents(file.path, out oldstr);                             
395                                         var outstr = file.toJsonString();
396                                         if (outstr != oldstr) { 
397                                                 
398                                                 GLib.FileUtils.set_contents("/tmp/" + file.name ,   outstr);
399                                                 print("meld  %s /tmp/%s\n", file.path,  file.name);
400                                                 //GLib.Process.exit(Posix.EXIT_SUCCESS);                
401                                         }
402                                         print("# Files match %s\n", file.name);
403                                         
404                                 }
405                         } catch (FileError e) {
406                                 GLib.debug("Got error %s", e.message);
407                         } catch (Error e) {
408                                 GLib.debug("Got error %s", e.message);
409                         }
410                                 
411                         print("All files pass");
412                         GLib.Process.exit(Posix.EXIT_SUCCESS);
413                 }
414                 
415                 void compileBjs(Project.Project? cur_project)
416                 {
417                         if (BuilderApplication.opt_bjs_compile == null) {
418                                 return;
419                         }
420                         if (cur_project == null) {
421                                 GLib.error("missing project, use --project to select which project");
422                         }
423                         
424                         if (BuilderApplication.opt_bjs_compile == "all") {
425                                 try { 
426                                         var ar = cur_project.sortedFiles();
427                                         
428                                         foreach(var file in ar) {
429                                         
430                                                 if (file is JsRender.PlainFile) {
431                                                         continue;
432                                                 }
433                         
434
435                                                 file.loadItems();
436                                                 var oldfn = file.targetName();
437                                                 
438                                                 print("\n\n\n\nFile : %s\n", oldfn);
439                                                 
440                                                                                 
441                                                 var outstr = file.toSourceCode();
442                                                 
443                                                 /* line number checking
444                                                 var bad = false;
445                                                 // check line numbers:
446                                                 var bits = outstr.split("\n");
447                                                 var end = bits.length;
448                                                 for(var i = 0;i < end; i++) {
449                                                         print("%i : %s\n", i+1 , bits[i]);
450                                                         if (!bad && bits[i].has_prefix("/*") && !bits[i].has_prefix(("/*%d*" +"/").printf(i+1))) {
451                                                                 end = i + 5 > bits.length ? bits.length: (i + 5);
452                                                                 print ("^^^^ mismatch\null");
453                                                                 bad = true;
454                                                         }
455
456                                                 
457                                                 }
458                                                 if (bad) {
459                                                         GLib.error("got bad file");
460                                                 }
461                                                 */
462                                                 // compare files. 
463                                                 string oldstr;
464                                                 GLib.FileUtils.get_contents(oldfn, out oldstr);
465                                                 if (outstr != oldstr) { 
466                                                         
467                                                         GLib.FileUtils.set_contents("/tmp/" + file.name   + ".out",   outstr);
468                                                         print("meld   %s /tmp/%s\n", oldfn,  file.name + ".out");
469                                                         //GLib.Process.exit(Posix.EXIT_SUCCESS);                
470                                                 }                                               
471                                                 //print("# Files match %s\n", file.name);
472                                         }               
473                                 } catch (FileError e) {
474                                         GLib.debug("Got error %s", e.message);
475                                 } catch (Error e) {
476                                         GLib.debug("got error %s", e.message);
477                                 }
478                                 
479                                 GLib.Process.exit(Posix.EXIT_SUCCESS);
480                         
481                         }
482                         
483                         
484                         
485                         var file = cur_project.getByRelPath(BuilderApplication.opt_bjs_compile);
486                         if (file == null) {
487                                 // then compile them all, and compare them...
488                                 
489                          
490                         
491                                 GLib.error("missing file %s in project %s", BuilderApplication.opt_bjs_compile, cur_project.name);
492                         }
493                         try {
494                                 file.loadItems();
495                         } catch(Error e) {
496                                 GLib.debug("Load items failed");
497                         }
498                                         
499                         if (BuilderApplication.opt_bjs_compile_glade) {
500                                 var str = file.toGlade();
501                                 print("%s", str);
502                                 GLib.Process.exit(Posix.EXIT_SUCCESS);
503                         }
504                         
505                         //BuilderApplication.compileBjs();
506
507                         var str = file.toSourceCode();
508                           
509                           
510                         if (!BuilderApplication.opt_debug) {
511                                 print("%s", str);
512                                 GLib.Process.exit(Posix.EXIT_SUCCESS);
513                         }
514                         
515                         // dump the node tree
516                         file.tree.dumpProps();
517                         
518                         
519                         
520                         
521                         
522                         var str_ar = str.split("\n");
523                         for(var i =0;i<str_ar.length;i++) {
524                                 var node = file.tree.lineToNode(i+1);
525                                 var prop = node == null ? null : node.lineToProp(i+1);
526                                 print("%d: %s   :  %s\n", 
527                                         i+1, 
528                                         node == null ? "......"  : (prop == null ? "????????" : prop.name),
529                                         str_ar[i]
530                                 );
531                         }
532                         
533                         GLib.Process.exit(Posix.EXIT_SUCCESS);
534                 }
535                 void languageServer(Project.Project? cur_project)
536                 {
537                         if (BuilderApplication.opt_language_server == null) {
538                                 return;
539                         }
540                         if (cur_project == null) {
541                                 GLib.error("missing project, use --project to select which project");
542                         }
543                         var file = cur_project.getByRelPath(BuilderApplication.opt_language_server);
544                         if (file == null) {
545                                 // then compile them all, and compare them...
546                                  GLib.error("missing file %s in project %s", BuilderApplication.opt_language_server, cur_project.name);
547                         }
548                         
549                         var ls = file.getLanguageServer();
550                         if (ls == null) {
551                                 GLib.error("No langauge server returned for file:%s", file.relpath);
552                         }
553                         
554                         //GLib.debug("started server - sleep 30 secs so you can gdb attach");
555                         //Posix.sleep( 30 );
556                         var loop = new MainLoop();
557                         GLib.Timeout.add_seconds(1, () => {
558                          
559                                 GLib.debug("Sending document_open");
560                                 // it's ready..
561                                  
562                                 ls.document_open(file);
563                                 ls.document_save.begin( file, (o,res) => {
564                                         ls.document_save.end(res);
565                                  });
566                                 
567                                 //ls.syntax.begin(file, (obj,res) => {
568                                 //      ls.syntax.end(res);
569                                 
570                                 //});
571                                 
572                                 
573                                 return false;
574                                 
575                         });
576                         
577                          
578                         loop.run();
579                         GLib.Process.exit(Posix.EXIT_SUCCESS);
580                 }
581                         
582         /*      
583                 void compileVala()
584                 {
585                         if (BuilderApplication.opt_compile_target == null) {
586                                 return;
587                         }
588                         Palete.ValaSourceCompiler.buildApplication();
589                 
590                         GLib.Process.exit(Posix.EXIT_SUCCESS);
591         
592                 }
593                 */
594                 void pullResources()
595                 {
596                         if (!opt_pull_resources) {
597                                 return;
598                         }
599                         var loop = new MainLoop();
600                         Resources.singleton().updateProgress.connect((p,t) => {
601                                 print("Got %d/%d", (int) p,(int)t);
602                                 if (p == t) {
603                                         loop.quit();
604                                 }
605                         });
606                         Resources.singleton().fetchStart();     
607                         loop.run();
608                         GLib.Process.exit(Posix.EXIT_SUCCESS);
609                 }
610                 
611                 
612                 void runTests()
613                 {
614                         if (opt_test == null) {
615                                 return;
616                         }
617                         switch(opt_test) {
618                                 case "help":
619                                         print("""
620 help             - list available tests
621 flutter-project  -  was try and read flutter data (but desnt work.)
622 """);           
623                                         break;
624                                 case "flutter-project":
625                                 Project.Project.loadAll();
626                                         //var p =   Project.Project.factory("Flutter", "/tmp/test-flutter");
627                                         /*var pa = p.palete as Palete.Flutter;
628                                         pa.dumpusage();
629                                          var ar = pa.getChildList("material.Scaffold");
630                                         GLib.debug("childlist for material.Scaffold is %s", 
631                                                 string.joinv( "\n-- ", ar)
632                                         );
633                                         ar = pa.getDropList("material.MaterialApp");
634                                         GLib.debug("droplist for material.MaterialApp is %s", 
635                                                 string.joinv( "\n-- ", ar)
636                                         );
637                                         */
638                                         break;
639                                         
640                                  
641                                         
642                                         
643                                 default:
644                                         print("Invalid test\n");
645                                         break;
646
647
648                         }
649                         GLib.Process.exit(Posix.EXIT_SUCCESS);          
650                 }
651                 
652                 
653                 // move to 'window colletction?
654                 public static Gee.ArrayList<Xcls_MainWindow> windows;
655                 public static GLib.ListStore windowlist;
656                 
657                 public static void addWindow(Xcls_MainWindow w)
658                 {
659                          
660                 windowlist.append(w.windowstate);
661                         BuilderApplication.windows.add(w);
662
663   
664                         
665                 }
666                 
667                 public static void removeWindow(Xcls_MainWindow w)
668                 {
669                         //GLib.debug("remove window before = %d", BuilderApplication.windows.size);
670                         BuilderApplication.windows.remove(w);
671                         for(var i = 0 ; i < windowlist.get_n_items(); i++) {
672                                 var ws = windowlist.get_item(i) as WindowState;
673                                 if (ws.file.path == w.windowstate.file.path && ws.project.path == w.windowstate.project.path) {
674                                         windowlist.remove(i);
675                                         break;
676                                 }
677                         }
678                         
679
680                                 
681                         w.el.hide();
682                         w.el.close();
683                         w.el.destroy();
684                         //GLib.debug("remove window after = %d", BuilderApplication.windows.size);
685                         
686                         
687                 }
688          
689                 public static Xcls_MainWindow? getWindow(JsRender.JsRender file)
690                 {
691                         foreach(var ww in BuilderApplication.windows) {
692                                 if (ww.windowstate != null && ww.windowstate.file != null &&  ww.windowstate.file.path == file.path) {
693                                         return ww;
694                                 }
695                         }
696                         return null;
697                 
698                 }
699                 
700                 public static void newWindow(JsRender.JsRender file, int line)
701                 {
702                     var w = new Xcls_MainWindow();
703                         w.ref();
704                         w.initChildren();
705                         BuilderApplication.addWindow(w);
706                         w.windowstate.init();
707                         w.windowstate.fileViewOpen(file, false, line);
708                         w.el.present();
709                          
710                 
711                 }
712                 
713                 static int queue_update_compile_countdown = -1;
714                 static uint queue_update_compile_id = 0;
715                 
716                 public static void updateCompileResults( )
717                 {
718                         queue_update_compile_countdown = 2; // 1 second after last call.
719                         if (queue_update_compile_id == 0) {
720                                 queue_update_compile_id = GLib.Timeout.add(100, () => {
721                                         if (queue_update_compile_countdown < 0) {
722                                                 return true;
723                                         }
724                                         queue_update_compile_countdown--;
725                                         if (queue_update_compile_countdown < 0) {
726                                                 realUpdateCompileResults();
727                                         }
728                                         
729                                         return true;
730                                 });
731                         }
732                 }
733                 
734                 
735                 public static void realUpdateCompileResults( )
736                 {
737                         
738                         
739                         
740                         foreach(var ww in BuilderApplication.windows) {
741                                 if (ww == null || ww.windowstate == null || ww.windowstate.project ==null) {
742                                         continue;
743                                 }
744                                 
745
746                                 ww.windowstate.updateErrorMarksAll();
747                                  
748                                 GLib.debug("calling udate Errors of window %s", ww.windowstate.file.targetName());
749                                 ww.updateErrors();
750                                 ww.windowstate.left_tree.updateErrors();
751                                 ww.windowstate.left_props.updateErrors();
752                                 
753                         }
754                 
755                 }
756                 
757                 public static void showSpinnerLspLog(Palete.LanguageClientAction action, string message) {
758                         
759                         var msg = action.to_string() + " " + message;
760                         switch(action) {
761                         
762                                         case Palete.LanguageClientAction.INIT:
763                                         case Palete.LanguageClientAction.LAUNCH:
764                                         case Palete.LanguageClientAction.ACCEPT:
765                                                 BuilderApplication.showSpinner( "software-update-available", msg );
766                                                 return;
767                                                 
768                                         case Palete.LanguageClientAction.DIAG:
769                                                 BuilderApplication.showSpinner( "format-justify-fill", msg);                                    
770                                                 return;
771
772                                         case Palete.LanguageClientAction.OPEN:
773                                                 BuilderApplication.showSpinner( "document-open", msg);                                  
774                                                 return;
775                                         case Palete.LanguageClientAction.SAVE:
776                                                 BuilderApplication.showSpinner( "document-save", msg);                                  
777                                                 return;
778                                         case Palete.LanguageClientAction.CLOSE:
779                                                 BuilderApplication.showSpinner( "window.close", msg);                                   
780                                                 return;
781                                         case Palete.LanguageClientAction.CHANGE:
782                                                 BuilderApplication.showSpinner( "format-text-direction-ltr", msg);
783                                                 return;                                         
784                                         case Palete.LanguageClientAction.TERM:
785                                                 BuilderApplication.showSpinner( "media-playback-stop", msg);
786                                                 return;                                         
787                                         case Palete.LanguageClientAction.COMPLETE:
788                                                 BuilderApplication.showSpinner( "mail-send-recieve", msg);
789                                                 return;
790                                         
791                                         case Palete.LanguageClientAction.COMPLETE_REPLY:
792                                                 BuilderApplication.showSpinner( "face-cool", msg);
793                                                 return;
794                                                 
795                                         case Palete.LanguageClientAction.RESTART:
796                                         case Palete.LanguageClientAction.ERROR:
797                                         case Palete.LanguageClientAction.ERROR_START:
798                                         case Palete.LanguageClientAction.ERROR_RPC:
799                                         case Palete.LanguageClientAction.ERROR_REPLY:
800                                                 BuilderApplication.showSpinner( "software-update-urgent", msg );
801                                                 return;
802
803                                         case Palete.LanguageClientAction.EXIT:
804                                                 BuilderApplication.showSpinner( "face-sick", msg);
805                                                 return;
806                                         
807                         
808                         }
809                 }
810                 
811                 public static  void showSpinner(string icon, string tooltip = "")
812                 {
813
814                         // events:
815                         // doc change send: - spinner - 
816                         
817                         
818                         // ?? restart = software-update-urgent - crash?
819
820                         
821                         foreach (var win in BuilderApplication.windows) {
822                                 if (icon != "") {
823                                         win.statusbar_compile_spinner.start(icon, tooltip);
824                                 }  else {
825                                         win.statusbar_compile_spinner.stop();
826                                 }
827                         }
828                 }
829                 
830                 
831                 
832          
833         }
834         
835         
836                 
837
838  
839