src/Builder4/ClutterFiles.bjs
[app.Builder.js] / src / Project / Gtk.vala
index 0bdcf97..706fe68 100644 (file)
@@ -46,7 +46,7 @@ namespace Project {
                        
                        
                        var fn = this.firstPath() + "/config1.builder";
-                       print("load: " + fn );
+                       GLib.debug("load: " + fn );
                        
                        if (!FileUtils.test(fn, FileTest.EXISTS)) {
                                this.compilegroups.set("_default_", new GtkValaSettings("_default_") );
@@ -71,7 +71,7 @@ namespace Project {
                                }
                                this.compilegroups.set(vs.name,vs);
                        }
-                       print("%s\n",this.configToString ());
+                       GLib.debug("%s\n",this.configToString ());
                        
                }
                public string configToString()
@@ -95,7 +95,7 @@ namespace Project {
                public void writeConfig()
                {
                        var fn = this.firstPath() + "/config1.builder";
-                       print("write: " + fn );
+                       GLib.debug("write: " + fn );
 
                         
                        var f = GLib.File.new_for_path(fn);
@@ -106,20 +106,39 @@ namespace Project {
                        data_out.close(null);
                        
                        return ;
-                       
-                       
-
+                        
                }
+               /**
+                *  perhaps we should select the default in the window somewhere...
+                */ 
+               public string firstBuildModule()
+               {
+                       var iter = this.compilegroups.map_iterator();
+                       while(iter.next()) {
+                                
+                                if (iter.get_value().name == "__default__") {
+                                        continue;
+                                }
+                                
+                                return iter.get_value().name;
+                       }
+                       return "";
+               }
+               
+               
                public string relPath(string target)
                {
                        var basename = this.firstPath();
                        // eg. base = /home/xxx/fred/blogs
                        // target = /home/xxx/fred/jones
+                       
+                       // this does not work correctly...
                        var bb = basename;
                        var prefix = "";
                        while (true) {
                                if (    bb.length < target.length &&
                                        target.substring(0, bb.length) == bb) {
+                                       
                                        return prefix + target.substring(bb.length +1);
                                }
                                if (bb.length < 1) {
@@ -132,23 +151,39 @@ namespace Project {
                        }
         
                }
-               public Gee.ArrayList<string> files(string in_path)
+               /**
+                * get a list of files for a folder..
+                * 
+                * - in the project manager this has to list all possible compilable 
+                *   files  - eg. exclue XXX.vala.c or XXX.c with the same name as 
+                *   a vala file (so to ignore the generated files)
+                * 
+                * - for the editor navigation - this should exclude all files that
+                *   are vala based on a bjs file..
+                *  
+                */
+               
+               public Gee.ArrayList<string> filesAll(string in_path)
                {
-                       var ret = new Gee.ArrayList<string>(); 
+                       var ret =  new Gee.ArrayList<string>();
+                       
                        var dirname = this.resolve_path(
                                this.resolve_path_combine_path(this.firstPath(),in_path));
+                       
+                       GLib.debug("SCAN %s", dirname);
                                // scan the directory for files -- ending with vala || c
                        
 
                        var dir = File.new_for_path(dirname);
                        if (!dir.query_exists()) {
+                               GLib.debug("SCAN %s - skip - does not exist\n", dirname);
                                return ret;
                        }
          
           
                        try {
                                var file_enum = dir.enumerate_children(
-                                       GLib.FileAttribute.STANDARD_DISPLAY_NAME
+                                       "standard::*"
                                        GLib.FileQueryInfoFlags.NONE, 
                                        null
                                );
@@ -157,34 +192,176 @@ namespace Project {
                                FileInfo next_file; 
                                while ((next_file = file_enum.next_file(null)) != null) {
                                        var fn = next_file.get_display_name();
+                                       
+                                       if (next_file.get_file_type () == GLib.FileType.DIRECTORY) {
+                                        
+                                               GLib.debug("SKIP %s not regular  ", fn);
+                                               continue;
+                                       }
+                                       if (!Regex.match_simple("^text", next_file.get_content_type())) {
+                                               continue;
+                                       }
+                                       GLib.debug("SCAN ADD %s : %s", fn, next_file.get_content_type());
+                                       ret.add(in_path + "/" + fn);
+                                        
+                                       // any other valid types???
+                               
+                               }
+                               
+                       } catch(Error e) {
+                               GLib.warning("oops - something went wrong scanning the projects\n");
+                       }       
+                       
+                       return ret;
+               }
+               
+               public Gee.ArrayList<string> filesForCompile(string in_path)
+               {
+                       var allfiles = this.filesAll(in_path);
+                       var ret =  new Gee.ArrayList<string>();
+                       
+                       
+                       for (var i = 0; i < allfiles.size; i ++) {
+                               var fn = allfiles.get(i);
+                               try {
                                        if (Regex.match_simple("\\.vala$", fn)) {
-                                               ret.add(dirname + "/" + fn);
+                                               ret.add( fn);
+                                               continue;
+                                       }
+                                       // vala.c -- ignore..
+                                       if (Regex.match_simple("\\.vala\\.c$", fn)) {
+                                               continue;
+                                       }
+                                       // not a c file...
+                                       if (!Regex.match_simple("\\.c$", fn)) {
                                                continue;
                                        }
                                        
+                                       // is the c file the same as a vala file...
                                        
+                                        
                                        
-                                       if (Regex.match_simple("\\.c$", fn)) {
-                                               
-                                               // if we have a vala file with the same name 
-                                               // then do not add it...
-                                               var vv = (new Regex("\\.c$").replace(fn, fn.legnth, 0, ".vala");
+                                       var vv = (new Regex("\\.c$")).replace( fn, fn.length, 0, ".vala");
+                               
+                                       
                                                
-                                               ret.add(dirname + "/" + fn);
+                                       if (allfiles.index_of( vv) > -1) {
                                                continue;
                                        }
-                                       // any other valid types???
-                               
-                               }       
-                       } catch(Error e) {
-                               print("oops - something went wrong scanning the projects\n");
+                                       // add the 'c' file..
+                                       ret.add(fn);
+                               } catch (Error e) {
+                                       continue;
+                               }
                        }
-
-                        
+                       // sort.
+                       ret.sort((fa,fb) => {
+                               return ((string)fa).collate((string) fb);
+                       });
                        return ret;
                        
+               }
+               
+               public Gee.ArrayList<string> filesForOpen(string in_path)
+               {
+                       var allfiles = this.filesAll(in_path);
+                       var ret =  new Gee.ArrayList<string>();
+                       GLib.debug("SCAN %s - %d files",in_path, allfiles.size);
+                       
+                       for (var i = 0; i < allfiles.size; i ++) {
+                               var fn = allfiles.get(i);
+                               var bn  = GLib.Path.get_basename(fn);
+                               try {
+                                       
+                                       if (Regex.match_simple("\\.vala\\.c$", fn)) {
+                                               GLib.debug("SKIP %s - vala.c",fn);
 
+                                               continue;
+                                       }
+                                       
+                                       if (Regex.match_simple("\\.bjs$", fn)) {
+                                               GLib.debug("SKIP %s - .bjs",fn);
+                                               continue;
+                                       }
+                                       
+                                       if (Regex.match_simple("\\~$", fn)) {
+                                               GLib.debug("SKIP %s - ~",fn);
+                                               continue;
+                                       }
+                                       if (Regex.match_simple("\\.stamp$", fn)) {
+                                               GLib.debug("SKIP %s - .o",fn);
+                                               continue;
+                                       }
+                                       if ("stamp-h1" == bn) {
+                                               GLib.debug("SKIP %s - .o",fn);
+                                               continue;
+                                       }
+                                       
+                                       // confgure.am
+                                       if ("config.h" == bn || "config.h.in" == bn || "config.log" == bn  || "configure" == bn ) {
+                                               if (allfiles.index_of( in_path +"/configure.ac") > -1) {
+                                                       continue;
+                                               }
+                                       }
+                                       // makefile
+                                       if ("Makefile" == bn || "Makefile.in" == bn ) {
+                                               if (allfiles.index_of( in_path +"/Makefile.am") > -1) {
+                                                       continue;
+                                               }
+                                       }
+                                       
+                                       if (Regex.match_simple("^\\.", bn)) {
+                                               GLib.debug("SKIP %s - hidden",fn);
+                                               continue;
+                                       }
+                                       if (Regex.match_simple("\\.vala$", fn)) {
+                                               var vv = (new Regex("\\.vala$")).replace( fn, fn.length, 0, ".bjs");
+                                               if (allfiles.index_of( vv) > -1) {
+                                                       GLib.debug("SKIP %s - .vala (got bjs)",fn);
+                                                       continue;
+                                               }
+                                               GLib.debug("ADD %s",fn);
+                                               ret.add( fn);
+                                               continue;
+                                       }
+                                       // vala.c -- ignore..
+                                       
+                                       // not a c file...
+                                       if (Regex.match_simple("\\.c$", fn)) {
+                                               
+                                               var vv = (new Regex("\\.c$")).replace( fn, fn.length, 0, ".vala");
+                                               if (allfiles.index_of( vv) > -1) {
+                                                       GLib.debug("SKIP %s - .c (got vala)",fn);
+                                                       continue;
+                                               }
+                                               GLib.debug("ADD %s",fn);                                                
+                                               ret.add( fn);
+                                               continue;
+                                       }
+                                       
+                                       if (GLib.Path.get_basename( fn) == "config1.builder") {
+                                               continue;
+                                       }
+                                       // not .c / not .vala /not .bjs.. -- other type of file..
+                                       // allow ???
+                                       GLib.debug("ADD %s",fn);
+                                       // add the 'c' file..
+                                       ret.add(fn);
+                               } catch (Error e) {
+                                       GLib.debug("Exception %s",e.message);
+                                       continue;
+                               }
+                       }
+                       // sort.
+                       ret.sort((fa,fb) => {
+                               return ((string)fa).collate((string) fb);
+                       });
+                       return ret;
+                       
                }
+               
+               
+                
  
 
                public   string  resolve_path_combine_path(string first, string second)
@@ -194,6 +371,7 @@ namespace Project {
                        {
                                ret += "/";
                        }
+                       //print("combined path = %s",  ret + second);
                        return ret + second;
                }
                public   string  resolve_path_times(string part, int times, string? clue = null)
@@ -251,7 +429,23 @@ namespace Project {
                        return path;
                }
                
-               
+               public string[] vapidirs()
+               {
+                       string[] ret = {};
+                       var sources = this.compilegroups.get("_default_").sources;
+                       for(var i =0; i< sources.size; i++) {
+                               
+                               var path = this.resolve_path( this.firstPath(), sources.get(i));
+                               
+                               if (Path.get_basename (path) == "vapi") {
+                                       GLib.debug("Adding VAPIDIR: %s\n", path);
+                                       ret += path;
+                               }
+                               
+                       }
+                       return ret;
+                       
+               }
                        
 
        }
@@ -288,6 +482,9 @@ namespace Project {
                        this.packages = this.readArray(el.get_array_member("packages"));
                        
                }
+               
+               
+               
                public Gee.ArrayList<string> readArray(Json.Array ar) 
                {
                        var ret = new Gee.ArrayList<string>();