Fix #7309 - editing a file should use the best compile group, not the first found...
[roobuilder] / src / Project / GtkValaSettings.vala
1 namespace Project 
2 {
3 // an object describing a build config (or generic ...)
4         public class GtkValaSettings : Object {
5                 public string name;
6                 public GtkValaSettings? parent;
7                 
8                 public string compile_flags; // generic to all.
9                 public Gee.ArrayList<string> packages; // list of packages?? some might be genericly named?
10                 public Gee.ArrayList<string> sources; // list of files+dirs (relative to project)
11                 public string target_bin;
12
13                 public string execute_args;
14                 
15                 
16                 public GtkValaSettings(string name) 
17                 {
18                         this.name = name;
19                         this.compile_flags = "";
20                         this.target_bin = "";
21                         this.packages = new Gee.ArrayList<string>();
22                         this.sources = new Gee.ArrayList<string>();
23                         this.execute_args = "";
24                                 
25                 }
26                 
27                 
28                 public GtkValaSettings.from_json(Json.Object el) {
29
30                         
31                         this.name = el.get_string_member("name");
32                         this.compile_flags = el.get_string_member("compile_flags");
33                         if ( el.has_member("execute_args")) {
34                                 this.execute_args = el.get_string_member("execute_args");
35                         } else {
36                                 this.execute_args = "";
37                         }
38                         this.target_bin = el.get_string_member("target_bin");
39                         // sources and packages.
40                         this.sources = this.readArray(el.get_array_member("sources"));
41                         this.packages = this.readArray(el.get_array_member("packages"));
42
43                 }
44                 
45                 // why not array of strings?
46                 
47                 public Gee.ArrayList<string> readArray(Json.Array ar) 
48                 {
49                         var ret = new Gee.ArrayList<string>();
50                         for(var i =0; i< ar.get_length(); i++) {
51                                 ret.add(ar.get_string_element(i));
52                         }
53                         return ret;
54                 }
55                 
56                 public Json.Object toJson()
57                 {
58                         var ret = new Json.Object();
59                         ret.set_string_member("name", this.name);
60                         ret.set_string_member("compile_flags", this.compile_flags);
61                         ret.set_string_member("execute_args", this.execute_args);
62                         ret.set_string_member("target_bin", this.target_bin);
63                         ret.set_array_member("sources", this.writeArray(this.sources));
64                         ret.set_array_member("packages", this.writeArray(this.packages));
65                         return ret;
66                 }
67                 public Json.Array writeArray(Gee.ArrayList<string> ar) {
68                         var ret = new Json.Array();
69                         for(var i =0; i< ar.size; i++) {
70                                 ret.add_string_element(ar.get(i));
71                         }
72                         return ret;
73                 }
74                 public bool has_file(JsRender.JsRender file)
75                 {
76                         
77                         GLib.debug("Checking %s has file %s", this.name, file.path);
78                         var pr = (Gtk) file.project;
79                         for(var i = 0; i < this.sources.size;i++) {
80                                 var path = pr.resolve_path( pr.resolve_path_combine_path( pr.firstPath(), this.sources.get(i)));
81                                 GLib.debug("check %s", path);
82                                 
83                                 if (path == file.path) {
84                                         GLib.debug("GOT IT");
85                                         return true;
86                                 }
87                         }
88                         GLib.debug("CANT FIND IT");
89                         return false;
90                 
91                 }
92                 
93         }
94  }