Fix #7315 - change to single compiler - and notify all windows
authorAlan <alan@roojs.com>
Tue, 19 Jul 2022 09:11:33 +0000 (17:11 +0800)
committerAlan <alan@roojs.com>
Tue, 19 Jul 2022 09:11:33 +0000 (17:11 +0800)
src/Application.vala
src/Builder4/Editor.bjs
src/Builder4/Editor.vala
src/Builder4/MainWindow.bjs
src/Builder4/MainWindow.vala
src/Builder4/ValaCompileResults.bjs
src/Builder4/ValaCompileResults.vala
src/Builder4/WindowState.vala
src/Palete/Palete.vala
src/Palete/ValaSource.vala

index fc463fb..dc46873 100644 (file)
                };
                public AppSettings settings = null;
 
+
+
+               public static Palete.ValaSource valasource;
+
        
                public BuilderApplication (  string[] args)
                {
                               application_id: "org.roojs.app-builder",
                                flags: ApplicationFlags.FLAGS_NONE
                        );
-                       BuilderApplication.windows = new        Gee.ArrayList<Xcls_MainWindow>();                
+                       BuilderApplication.windows = new        Gee.ArrayList<Xcls_MainWindow>();
+                       BuilderApplication.valasource = new Palete.ValaSource();
+                       
+                       
                        configDirectory();
                        this.settings = AppSettings.factory();  
                        var opt_context = new OptionContext ("Application Builder");
@@ -424,6 +431,8 @@ flutter-project  - create a flutter project in /tmp/test-flutter
                         
                        BuilderApplication.windows.add(w);
                        BuilderApplication.updateWindows();
+  
+                       
                }
                
                public static void removeWindow(Xcls_MainWindow w)
@@ -431,6 +440,10 @@ flutter-project  - create a flutter project in /tmp/test-flutter
                
                        BuilderApplication.windows.remove(w);
                        BuilderApplication.updateWindows();
+                       BuilderApplication.valasource.compiled.disconnect(w.windowstate.showCompileResult);
+                       BuilderApplication.valasource.compile_output.disconnect(w.windowstate.compile_results.addLine);                 
+                       
+                       
                }
                public static void updateWindows()
                {
index bc3ef1f..e556870 100644 (file)
           ]
          },
          "xtype" : "SourceBuffer",
-         "|   bool checkSyntax" : [
+         "| bool checkSyntax" : [
           " () {",
           " ",
           "    if (this.check_running) {",
           "        // assume it's gtk...",
           "           this.check_running = true;",
           " ",
-          "         if (!_this.window.windowstate.valasource.checkPlainFileSpawn(",
+          "         if (!BuilderApplication.valasource.checkPlainFileSpawn(",
           "\t   _this.file,",
           "\t    str",
           "\t )) {",
           "    // clear the buttons.",
           " ",
           "    ",
-          "   if (! _this.window.windowstate.valasource.checkFileWithNodePropChange(",
+          "   if (! BuilderApplication.valasource.checkFileWithNodePropChange(",
           "        _this.file,",
           "        _this.node,",
           "         _this.prop,        ",
           "}",
           ""
          ],
-         "|   string toString" : [
-          "  () {",
-          "    ",
-          "    Gtk.TextIter s;",
-          "    Gtk.TextIter e;",
-          "    this.el.get_start_iter(out s);",
-          "    this.el.get_end_iter(out e);",
-          "    var ret = this.el.get_text(s,e,true);",
-          "    //print(\"TO STRING? \" + ret);",
-          "    return ret;",
-          "}",
-          " "
-         ],
          "| bool highlightErrors" : [
           "( Gee.HashMap<int,string> validate_res) {",
           "         ",
           "",
           "}",
           ""
+         ],
+         "| string toString" : [
+          "  () {",
+          "    ",
+          "    Gtk.TextIter s;",
+          "    Gtk.TextIter e;",
+          "    this.el.get_start_iter(out s);",
+          "    this.el.get_end_iter(out e);",
+          "    var ret = this.el.get_text(s,e,true);",
+          "    //print(\"TO STRING? \" + ret);",
+          "    return ret;",
+          "}",
+          " "
          ]
         }
        ],
        },
        "uint tab_width" : 4,
        "xtype" : "SourceView",
-       "|   void load" : [
+       "| void load" : [
         " (string str) {",
         "",
         "// show the help page for the active node..",
     }
    ],
    "xtype" : "Box",
-   "|   void show" : [
-    "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
-    "{",
-    "    this.reset();",
-    "    this.file = file;    ",
-    "    ",
-    "    if (file.xtype != \"PlainFile\") {",
-    "    \tthis.prop = prop;",
-    "        this.node = node;",
-    "",
-    "        // find the text for the node..",
-    "        this.view.load( prop.val );",
-    "        this.close_btn.el.show();       ",
-    "    ",
-    "    } else {",
-    "        this.view.load(        file.toSource() );",
-    "        this.close_btn.el.hide();",
-    "    }",
-    " ",
-    "}"
-   ],
    "| bool saveContents" : [
     "  ()  {",
     "    ",
     "\t});   ",
     "}",
     ""
+   ],
+   "| void show" : [
+    "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
+    "{",
+    "    this.reset();",
+    "    this.file = file;    ",
+    "    ",
+    "    if (file.xtype != \"PlainFile\") {",
+    "    \tthis.prop = prop;",
+    "        this.node = node;",
+    "",
+    "        // find the text for the node..",
+    "        this.view.load( prop.val );",
+    "        this.close_btn.el.show();       ",
+    "    ",
+    "    } else {",
+    "        this.view.load(        file.toSource() );",
+    "        this.close_btn.el.hide();",
+    "    }",
+    " ",
+    "}"
    ]
   }
  ],
index 47357be..c923be0 100644 (file)
@@ -20,17 +20,17 @@ public class Editor : Object
 
         // my vars (def)
     public Xcls_MainWindow window;
-    public string activeEditor;
-    public JsRender.NodeProp? prop;
     public int pos_root_x;
-    public JsRender.JsRender? file;
+    public bool dirty;
     public int pos_root_y;
-    public int last_search_end;
-    public Gtk.SourceSearchContext searchcontext;
     public bool pos;
-    public bool dirty;
-    public signal void save ();
+    public Gtk.SourceSearchContext searchcontext;
+    public int last_search_end;
+    public JsRender.NodeProp? prop;
+    public JsRender.JsRender? file;
     public JsRender.Node node;
+    public signal void save ();
+    public string activeEditor;
 
     // ctor
     public Editor()
@@ -40,14 +40,14 @@ public class Editor : Object
 
         // my vars (dec)
         this.window = null;
-        this.activeEditor = "";
+        this.dirty = false;
+        this.pos = false;
+        this.searchcontext = null;
+        this.last_search_end = 0;
         this.prop = null;
         this.file = null;
-        this.last_search_end = 0;
-        this.searchcontext = null;
-        this.pos = false;
-        this.dirty = false;
         this.node = null;
+        this.activeEditor = "";
 
         // set gobject values
         this.el.homogeneous = false;
@@ -62,59 +62,6 @@ public class Editor : Object
     }
 
     // user defined functions
-    public void scroll_to_line (int line) {
-    
-       GLib.Timeout.add(500, () => {
-       
-               var buf = this.view.el.get_buffer();
-    
-               var sbuf = (Gtk.SourceBuffer) buf;
-    
-    
-               Gtk.TextIter iter;   
-               sbuf.get_iter_at_line(out iter,  line);
-               this.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
-               return false;
-       });   
-    }
-    public int search (string txt) {
-    
-       var s = new Gtk.SourceSearchSettings();
-       
-       this.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);
-       this.searchcontext .set_highlight(true);
-       s.set_search_text(txt);
-       Gtk.TextIter beg, st,en;
-        
-       this.buffer.el.get_start_iter(out beg);
-       this.searchcontext.forward(beg, out st, out en);
-       this.last_search_end = 0;
-       
-       return this.searchcontext.get_occurrences_count();
-    
-     
-       
-    
-    }
-    public   void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
-    {
-        this.reset();
-        this.file = file;    
-        
-        if (file.xtype != "PlainFile") {
-               this.prop = prop;
-            this.node = node;
-    
-            // find the text for the node..
-            this.view.load( prop.val );
-            this.close_btn.el.show();       
-        
-        } else {
-            this.view.load(        file.toSource() );
-            this.close_btn.el.hide();
-        }
-     
-    }
     public bool saveContents ()  {
         
         
@@ -148,6 +95,25 @@ public class Editor : Object
         
         return true;
     
+    }
+    public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
+    {
+        this.reset();
+        this.file = file;    
+        
+        if (file.xtype != "PlainFile") {
+               this.prop = prop;
+            this.node = node;
+    
+            // find the text for the node..
+            this.view.load( prop.val );
+            this.close_btn.el.show();       
+        
+        } else {
+            this.view.load(        file.toSource() );
+            this.close_btn.el.hide();
+        }
+     
     }
     public void forwardSearch (bool change_focus) {
     
@@ -170,6 +136,25 @@ public class Editor : Object
                this.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);
        }
      
+    }
+    public int search (string txt) {
+    
+       var s = new Gtk.SourceSearchSettings();
+       
+       this.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);
+       this.searchcontext .set_highlight(true);
+       s.set_search_text(txt);
+       Gtk.TextIter beg, st,en;
+        
+       this.buffer.el.get_start_iter(out beg);
+       this.searchcontext.forward(beg, out st, out en);
+       this.last_search_end = 0;
+       
+       return this.searchcontext.get_occurrences_count();
+    
+     
+       
+    
     }
     public void reset () {
         this.file = null;    
@@ -179,6 +164,21 @@ public class Editor : Object
        this.searchcontext = null;
       
     }
+    public void scroll_to_line (int line) {
+    
+       GLib.Timeout.add(500, () => {
+       
+               var buf = this.view.el.get_buffer();
+    
+               var sbuf = (Gtk.SourceBuffer) buf;
+    
+    
+               Gtk.TextIter iter;   
+               sbuf.get_iter_at_line(out iter,  line);
+               this.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
+               return false;
+       });   
+    }
     public class Xcls_Box2 : Object
     {
         public Gtk.Box el;
@@ -523,7 +523,7 @@ public class Editor : Object
         }
 
         // user defined functions
-        public   void load (string str) {
+        public void load (string str) {
         
         // show the help page for the active node..
            //this.get('/Help').show();
@@ -566,8 +566,8 @@ public class Editor : Object
 
 
             // my vars (def)
-        public bool check_queued;
         public int error_line;
+        public bool check_queued;
         public bool check_running;
 
         // ctor
@@ -578,8 +578,8 @@ public class Editor : Object
             this.el = new Gtk.SourceBuffer( null );
 
             // my vars (dec)
-            this.check_queued = false;
             this.error_line = -1;
+            this.check_queued = false;
             this.check_running = false;
 
             // set gobject values
@@ -600,30 +600,7 @@ public class Editor : Object
         }
 
         // user defined functions
-        public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
-                 
-                this.error_line = validate_res.size;
-        
-                if (this.error_line < 1) {
-                      return true;
-                }
-                var tlines = this.el.get_line_count ();
-                Gtk.TextIter iter;
-                var valiter = validate_res.map_iterator();
-                while (valiter.next()) {
-                
-            //        print("get inter\n");
-                    var eline = valiter.get_key();
-                    if (eline > tlines) {
-                        continue;
-                    }
-                    this.el.get_iter_at_line( out iter, eline);
-                    //print("mark line\n");
-                    this.el.create_source_mark(valiter.get_value(), "ERR", iter);
-                }   
-                return false;
-            }
-        public   bool checkSyntax () {
+        public bool checkSyntax () {
          
             if (this.check_running) {
                 print("Check is running\n");
@@ -663,7 +640,7 @@ public class Editor : Object
                 // assume it's gtk...
                    this.check_running = true;
          
-                 if (!_this.window.windowstate.valasource.checkPlainFileSpawn(
+                 if (!BuilderApplication.valasource.checkPlainFileSpawn(
                   _this.file,
                    str
                 )) {
@@ -703,7 +680,7 @@ public class Editor : Object
             // clear the buttons.
          
             
-           if (! _this.window.windowstate.valasource.checkFileWithNodePropChange(
+           if (! BuilderApplication.valasource.checkFileWithNodePropChange(
                 _this.file,
                 _this.node,
                  _this.prop,        
@@ -718,16 +695,6 @@ public class Editor : Object
              
             return true; // at present allow saving - even if it's invalid..
         }
-        public   string toString () {
-            
-            Gtk.TextIter s;
-            Gtk.TextIter e;
-            this.el.get_start_iter(out s);
-            this.el.get_end_iter(out e);
-            var ret = this.el.get_text(s,e,true);
-            //print("TO STRING? " + ret);
-            return ret;
-        }
         public bool highlightErrorsJson (string type, Json.Object obj) {
               Gtk.TextIter start;
              Gtk.TextIter end;     
@@ -824,6 +791,39 @@ public class Editor : Object
         
         
         
+        }
+        public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
+                 
+                this.error_line = validate_res.size;
+        
+                if (this.error_line < 1) {
+                      return true;
+                }
+                var tlines = this.el.get_line_count ();
+                Gtk.TextIter iter;
+                var valiter = validate_res.map_iterator();
+                while (valiter.next()) {
+                
+            //        print("get inter\n");
+                    var eline = valiter.get_key();
+                    if (eline > tlines) {
+                        continue;
+                    }
+                    this.el.get_iter_at_line( out iter, eline);
+                    //print("mark line\n");
+                    this.el.create_source_mark(valiter.get_value(), "ERR", iter);
+                }   
+                return false;
+            }
+        public string toString () {
+            
+            Gtk.TextIter s;
+            Gtk.TextIter e;
+            this.el.get_start_iter(out s);
+            this.el.get_end_iter(out e);
+            var ret = this.el.get_text(s,e,true);
+            //print("TO STRING? " + ret);
+            return ret;
         }
     }
 
index cc9a7a6..fa6198b 100644 (file)
              "\tif (_this.windowstate.file == null) {",
              "\t\treturn true;",
              "\t}",
-             "\t_this.windowstate.valasource.spawnExecute(_this.windowstate.file);",
+             "\tBuilderApplication.valasource.spawnExecute(_this.windowstate.file);",
              "\t",
              "\t_this.windowstate.compile_results.show(this.el,true);",
              "\t",
index 0d2e287..3c95715 100644 (file)
@@ -35,8 +35,8 @@ public class Xcls_MainWindow : Object
     public Xcls_statusbar_compile_spinner statusbar_compile_spinner;
 
         // my vars (def)
-    public WindowState windowstate;
     public string title;
+    public WindowState windowstate;
     public Project.Project project;
 
     // ctor
@@ -1551,7 +1551,7 @@ public class Xcls_MainWindow : Object
                if (_this.windowstate.file == null) {
                        return true;
                }
-               _this.windowstate.valasource.spawnExecute(_this.windowstate.file);
+               BuilderApplication.valasource.spawnExecute(_this.windowstate.file);
                
                _this.windowstate.compile_results.show(this.el,true);
                
index bfa9976..7e20e43 100644 (file)
    "xtype" : "Popover",
    "| void addLine" : [
     "(string str) {",
+    "\t",
+    "\tif (this.window.windowstate.project.fn != BuilderApplication.valasource.file.project.fn) {",
+    "\t\t// not our project.",
+    "\t\treturn;",
+    "\t}",
+    "\t",
     "\tvar buf = (Gtk.SourceBuffer)this.sourceview.el.get_buffer();",
     "\tGtk.TextIter iter;",
     "\tbuf.get_end_iter (out  iter);",
index 18c4b44..a36bb93 100644 (file)
@@ -72,6 +72,12 @@ public class Xcls_ValaCompileResults : Object
         
     }
     public void addLine (string str) {
+       
+       if (this.window.windowstate.project.fn != BuilderApplication.valasource.file.project.fn) {
+               // not our project.
+               return;
+       }
+       
        var buf = (Gtk.SourceBuffer)this.sourceview.el.get_buffer();
        Gtk.TextIter iter;
        buf.get_end_iter (out  iter);
index a2095fa..1c1208f 100644 (file)
@@ -50,7 +50,7 @@ public class WindowState : Object
        public Xcls_DialogPluginWebkit webkit_plugin;
        
        
-       public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
+       //public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
        public Json.Object last_compile_result;
        
        // ctor 
@@ -88,13 +88,12 @@ public class WindowState : Object
                this.children_loaded = true;
                
                
-               this.valasource = new Palete.ValaSource(this.win);
-
-               this.valasource.compiled.connect(this.showCompileResult);
+                
+               BuilderApplication.valasource.compiled.connect(this.showCompileResult); 
                
-               this.compile_results = new  Xcls_ValaCompileResults();
+               this.compile_results = new  Xcls_ValaCompileResults(); // the poup dialogs with results in.
                this.compile_results.window = this.win;
-               this.valasource.compile_output.connect(this.compile_results.addLine);
+               BuilderApplication.valasource.compile_output.connect(this.compile_results.addLine);
                
                this.win.statusbar_compilestatus_label.el.hide();
                this.win.statusbar_run.el.hide();
@@ -364,7 +363,7 @@ public class WindowState : Object
                        this.left_tree.model.updateSelected();
                        this.file.save();
                        if (this.file.xtype=="Gtk") {
-                               this.valasource.checkFileSpawn(this.file);
+                               BuilderApplication.valasource.checkFileSpawn(this.file);
                        }
                });
         
@@ -918,9 +917,12 @@ public class WindowState : Object
        public void showCompileResult(Json.Object obj)
                {
                        // vala has finished compiling...
-                       print("vala compiled");
+                       GLib.debug("vala compiled");
                        // stop the spinner...
+                       if (this.project.fn != BuilderApplication.valasource.file.project.fn) {
+                               GLib.debug("skip update - not our project");
+                               return;
+                       }
                        
                        var generator = new Json.Generator ();
                        var n  = new Json.Node(Json.NodeType.OBJECT);
index 42dd2c0..589417a 100644 (file)
@@ -363,7 +363,7 @@ namespace Palete
                
                         
                        //var cd = new JSCore.ClassDefinitionEmpty();
-                       state.valasource.checkFileWithNodePropChange(
+                       BuilderApplication.valasource.checkFileWithNodePropChange(
                                        file,
                                        node, 
                                        prop,
index acab164..314d1c3 100644 (file)
@@ -29,16 +29,16 @@ namespace Palete {
                
                public signal void compiled(Json.Object res);
                public signal void compile_output(string str);
-               public Xcls_MainWindow window;
                
-               JsRender.JsRender file;
+               public JsRender.JsRender file;
                public int line_offset = 0;
                
                public Gee.ArrayList<Spawn> children;
-               public ValaSource( Xcls_MainWindow window ) 
+               public ValaSource(   ) 
                {
                        base();
-                       this.window  = window;
+                        
                        this.compiler = null;
                        this.children = new Gee.ArrayList<Spawn>();
                        
@@ -151,12 +151,12 @@ namespace Palete {
                        
                        this.compiler = new Spawn("/tmp", args);
                        this.compiler.complete.connect(spawnResult);
-                       this.window.statusbar_compile_spinner.start();
+               this.spinner(true);
                        try {
                                this.compiler.run(); 
                        } catch (GLib.SpawnError e) {
                                GLib.debug(e.message);
-                               this.window.statusbar_compile_spinner.stop();
+                               this.spinner(false);
                                this.compiler = null;
                                return false;
 
@@ -165,6 +165,18 @@ namespace Palete {
                         
                }
                
+               public void spinner(bool state)
+               {
+                       foreach (var win in BuilderApplication.windows) {
+                               if (state) {
+                                       win.statusbar_compile_spinner.start();
+                               }  else {
+                                       win.statusbar_compile_spinner.stop();
+                               }
+                       }
+               }
+               
+               
                public bool checkFileSpawn(JsRender.JsRender file )
                {
                        // race condition..
@@ -188,13 +200,13 @@ namespace Palete {
                        try {
                            this.compiler = new Spawn("/tmp", args);
                            this.compiler.complete.connect(spawnResult);
-                               this.window.statusbar_compile_spinner.start();
+                       this.spinner(true);
                            this.compiler.run(); 
                        
                         
                        } catch (GLib.Error e) {
                            GLib.debug(e.message);
-                           this.window.statusbar_compile_spinner.stop();
+                       this.spinner(false);
                            this.compiler = null;
                            return false;
                        }
@@ -239,12 +251,12 @@ namespace Palete {
                            this.compiler = new Spawn( GLib.Environment.get_home_dir(), args);
                            this.compiler.output_line.connect(compile_output_line);
                            this.compiler.complete.connect(runResult);
-                           this.window.statusbar_compile_spinner.start();
+                       this.spinner(true);
                            this.compiler.run(); 
                                this.children.add(this.compiler); //keep a reference...
                         
                        } catch (GLib.Error e) {
-                               this.window.statusbar_compile_spinner.stop();
+                       this.spinner(false);
                            GLib.debug(e.message);
                            this.compiler = null;
 
@@ -334,10 +346,10 @@ namespace Palete {
                        try {
                            this.compiler = new Spawn("/tmp", args);
                            this.compiler.complete.connect(spawnResult);
-                           this.window.statusbar_compile_spinner.start();
+                       this.spinner(true);
                            this.compiler.run(); 
                        } catch (GLib.Error e) {
-                           this.window.statusbar_compile_spinner.stop();
+                       this.spinner(false);
                            this.compiler = null;
                            return false;
                        }
@@ -349,7 +361,7 @@ namespace Palete {
                public void spawnResult(int res, string output, string stderr)
                {
                         
-                       this.window.statusbar_compile_spinner.stop();   
+               this.spinner(false);
                        try { 
                                //GLib.debug("GOT output %s", output);