Fix #7309 - editing a file should use the best compile group, not the first found...
authorAlan <alan@roojs.com>
Tue, 12 Jul 2022 10:02:25 +0000 (18:02 +0800)
committerAlan <alan@roojs.com>
Tue, 12 Jul 2022 10:02:25 +0000 (18:02 +0800)
src/Builder4/WindowState.vala
src/Builder4/config1.builder
src/Makefile.am
src/Palete/ValaSource.vala
src/Project/Gtk.vala
src/Project/GtkValaSettings.vala [new file with mode: 0644]

index 79605e4..a2095fa 100644 (file)
@@ -147,7 +147,7 @@ public class WindowState : Object
                });
         
                this.left_tree.changed.connect(() => {
-                       print("LEFT TREE: Changed fired\n");
+                       GLib.debug("LEFT TREE: Changed fired\n");
                        this.file.save();
                        if (this.left_tree.getActiveFile().xtype == "Roo" ) {
                                   this.window_rooview.requestRedraw();
index f23b794..0a5620e 100644 (file)
             "../Builder4/Editor.vala",
             "../Builder4/PopoverFiles.vala",
             "../JsRender/NodeToGlade.vala",
-            "../JsRender/NodeProp.vala"
+            "../JsRender/NodeProp.vala",
+            "../Project/GtkValaSettings.vala"
         ],
         "packages" : []
     },
index d4b920a..6fa845e 100644 (file)
@@ -199,7 +199,8 @@ BUIDERPALETE =  Palete/Gir.vala \
 
 BUIDERPROJECT = Project/Gtk.vala \
                Project/Project.vala \  
-               Project/Roo.vala 
+               Project/Roo.vala \
+               Project/GtkValaSettings.vala
 
 
 BUIDERUI =     Builder4/About.vala \
index 7e1d47e..acab164 100644 (file)
@@ -271,7 +271,7 @@ namespace Palete {
             
                        var pr = (Project.Gtk)(file.project);
                        
-                       var m = pr.firstBuildModule();
+                       var m = pr.firstBuildModuleWith(file);
                        var cg = pr.compilegroups.get(m);
 
                        if (cg == null) {
@@ -322,7 +322,7 @@ namespace Palete {
                        args +=  file.project.fn;
                        args += "--target";
  
-                       args += pr.firstBuildModule();
+                       args += m;
                        args += "--add-file";
                        args +=  tmpfile.get_path();
                        args += "--skip-file";
index 2f7e6ae..67c65c0 100644 (file)
@@ -143,7 +143,23 @@ namespace Project
                        }
                        return "";
                }
-               
+               public string firstBuildModuleWith(JsRender.JsRender file)
+               {
+                       
+                       var iter = this.compilegroups.map_iterator();
+                       while(iter.next()) {
+                                 
+                                if (iter.get_value().name == "_default_") {
+                                        continue;
+                                }
+                                if (iter.get_value().has_file(file)) {
+                                       return iter.get_value().name;
+                                }
+                                
+                                
+                       }
+                       return "";
+               }
                
                public string relPath(string target)
                {
@@ -488,80 +504,6 @@ namespace Project
                }       
 
        }
-       // an object describing a build config (or generic ...)
-       public class GtkValaSettings : Object {
-               public string name;
-               public GtkValaSettings? parent;
-               
-               public string compile_flags; // generic to all.
-               public Gee.ArrayList<string> packages; // list of packages?? some might be genericly named?
-               public Gee.ArrayList<string> sources; // list of files+dirs (relative to project)
-               public string target_bin;
-
-               public string execute_args;
-               
-               
-               public GtkValaSettings(string name) 
-               {
-                       this.name = name;
-                       this.compile_flags = "";
-                       this.target_bin = "";
-                       this.packages = new Gee.ArrayList<string>();
-                       this.sources = new Gee.ArrayList<string>();
-                       this.execute_args = "";
-                               
-               }
-               
-               
-               public GtkValaSettings.from_json(Json.Object el) {
-
-                       
-                       this.name = el.get_string_member("name");
-                       this.compile_flags = el.get_string_member("compile_flags");
-                       if ( el.has_member("execute_args")) {
-                               this.execute_args = el.get_string_member("execute_args");
-                       } else {
-                               this.execute_args = "";
-                       }
-                       this.target_bin = el.get_string_member("target_bin");
-                       // sources and packages.
-                       this.sources = this.readArray(el.get_array_member("sources"));
-                       this.packages = this.readArray(el.get_array_member("packages"));
-
-               }
-               
-               // why not array of strings?
-               
-               public Gee.ArrayList<string> readArray(Json.Array ar) 
-               {
-                       var ret = new Gee.ArrayList<string>();
-                       for(var i =0; i< ar.get_length(); i++) {
-                               ret.add(ar.get_string_element(i));
-                       }
-                       return ret;
-               }
-               
-               public Json.Object toJson()
-               {
-                       var ret = new Json.Object();
-                       ret.set_string_member("name", this.name);
-                       ret.set_string_member("compile_flags", this.compile_flags);
-                       ret.set_string_member("execute_args", this.execute_args);
-                       ret.set_string_member("target_bin", this.target_bin);
-                       ret.set_array_member("sources", this.writeArray(this.sources));
-                       ret.set_array_member("packages", this.writeArray(this.packages));
-                       return ret;
-               }
-               public Json.Array writeArray(Gee.ArrayList<string> ar) {
-                       var ret = new Json.Array();
-                       for(var i =0; i< ar.size; i++) {
-                               ret.add_string_element(ar.get(i));
-                       }
-                       return ret;
-               }
-               
-               
-       }
+       
    
 }
diff --git a/src/Project/GtkValaSettings.vala b/src/Project/GtkValaSettings.vala
new file mode 100644 (file)
index 0000000..eba3c4d
--- /dev/null
@@ -0,0 +1,94 @@
+namespace Project 
+{
+// an object describing a build config (or generic ...)
+       public class GtkValaSettings : Object {
+               public string name;
+               public GtkValaSettings? parent;
+               
+               public string compile_flags; // generic to all.
+               public Gee.ArrayList<string> packages; // list of packages?? some might be genericly named?
+               public Gee.ArrayList<string> sources; // list of files+dirs (relative to project)
+               public string target_bin;
+
+               public string execute_args;
+               
+               
+               public GtkValaSettings(string name) 
+               {
+                       this.name = name;
+                       this.compile_flags = "";
+                       this.target_bin = "";
+                       this.packages = new Gee.ArrayList<string>();
+                       this.sources = new Gee.ArrayList<string>();
+                       this.execute_args = "";
+                               
+               }
+               
+               
+               public GtkValaSettings.from_json(Json.Object el) {
+
+                       
+                       this.name = el.get_string_member("name");
+                       this.compile_flags = el.get_string_member("compile_flags");
+                       if ( el.has_member("execute_args")) {
+                               this.execute_args = el.get_string_member("execute_args");
+                       } else {
+                               this.execute_args = "";
+                       }
+                       this.target_bin = el.get_string_member("target_bin");
+                       // sources and packages.
+                       this.sources = this.readArray(el.get_array_member("sources"));
+                       this.packages = this.readArray(el.get_array_member("packages"));
+
+               }
+               
+               // why not array of strings?
+               
+               public Gee.ArrayList<string> readArray(Json.Array ar) 
+               {
+                       var ret = new Gee.ArrayList<string>();
+                       for(var i =0; i< ar.get_length(); i++) {
+                               ret.add(ar.get_string_element(i));
+                       }
+                       return ret;
+               }
+               
+               public Json.Object toJson()
+               {
+                       var ret = new Json.Object();
+                       ret.set_string_member("name", this.name);
+                       ret.set_string_member("compile_flags", this.compile_flags);
+                       ret.set_string_member("execute_args", this.execute_args);
+                       ret.set_string_member("target_bin", this.target_bin);
+                       ret.set_array_member("sources", this.writeArray(this.sources));
+                       ret.set_array_member("packages", this.writeArray(this.packages));
+                       return ret;
+               }
+               public Json.Array writeArray(Gee.ArrayList<string> ar) {
+                       var ret = new Json.Array();
+                       for(var i =0; i< ar.size; i++) {
+                               ret.add_string_element(ar.get(i));
+                       }
+                       return ret;
+               }
+               public bool has_file(JsRender.JsRender file)
+               {
+                       
+                       GLib.debug("Checking %s has file %s", this.name, file.path);
+                       var pr = (Gtk) file.project;
+                       for(var i = 0; i < this.sources.size;i++) {
+                               var path = pr.resolve_path( pr.resolve_path_combine_path( pr.firstPath(), this.sources.get(i)));
+                               GLib.debug("check %s", path);
+                               
+                               if (path == file.path) {
+                                       GLib.debug("GOT IT");
+                                       return true;
+                               }
+                       }
+                       GLib.debug("CANT FIND IT");
+                       return false;
+               
+               }
+               
+       }
+ }
\ No newline at end of file