src/Project/Gtk.vala
[app.Builder.js] / src / Project / Gtk.vala
index 07a159a..0c29891 100644 (file)
@@ -151,7 +151,166 @@ namespace Project {
                        }
         
                }
-                
+               /**
+                * 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 dirname = this.resolve_path(
+                               this.resolve_path_combine_path(this.firstPath(),in_path));
+                       
+                       GLib.debug("SCAN %s\n", 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, 
+                                       GLib.FileQueryInfoFlags.NONE, 
+                                       null
+                               );
+               
+                
+                               FileInfo next_file; 
+                               while ((next_file = file_enum.next_file(null)) != null) {
+                                       var fn = next_file.get_display_name();
+                                       
+                                       GLib.debug("SCAN %s - checking %s\n", dirname, fn);
+                                        
+                                       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 allfile = this.fileAll();
+                       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( 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...
+                                       
+                                        
+                                       
+                                       var vv = (new Regex("\\.c$")).replace( fn, fn, 0, ".vala");
+                               
+                                       
+                                               
+                                       if (allfiles.index_of( vv) > -1) {
+                                               continue;
+                                       }
+                                       // 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.fileAll();
+                       var ret =  new Gee.ArrayList<string>();
+                       
+                       
+                       for (var i = 0; i < allfiles.size; i ++) {
+                               var fn = cfiles.get(i);
+                               try {
+                                       
+                                       if (Regex.match_simple("\\.vala\\.c$", fn)) {
+                                               continue;
+                                       }
+                                       
+                                       if (Regex.match_simple("\\.bjs$", fn)) {
+                                               continue;
+                                       }
+                                       
+                                       if (Regex.match_simple("\\.vala$", fn)) {
+                                               ret.add( fn);
+                                               continue;
+                                       }
+                                       // vala.c -- ignore..
+                                       
+                                       // not a c file...
+                                       if (!Regex.match_simple("\\.c$", fn)) {
+                                               continue;
+                                       }
+                                       
+                                       // is the c file the same as a vala file...
+                                       
+                                       var vv = fn;
+                               
+                                       vv = (new Regex("\\.c$")).replace( fn, fn, 0, ".vala");
+                               
+                                       
+                                               
+                                       if (ret.index_of( vv) > -1) {
+                                               continue;
+                                       }
+                                       // 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> files(string in_path)
                {
@@ -174,7 +333,7 @@ namespace Project {
           
                        try {
                                var file_enum = dir.enumerate_children(
-                                               GLib.FileAttribute.STANDARD_DISPLAY_NAME, 
+                                       GLib.FileAttribute.STANDARD_DISPLAY_NAME, 
                                        GLib.FileQueryInfoFlags.NONE, 
                                        null
                                );
@@ -204,22 +363,31 @@ namespace Project {
                                        // any other valid types???
                                
                                }
+                               
+                       } catch(Error e) {
+                               GLib.warning("oops - something went wrong scanning the projects\n");
+                       }       
+                        
+                                
                                // add the cfiles to ret - if they do not have a vala...
-                               for (var i = 0; i < cfiles.size; i ++) {
-                                       
-                                       var vv = (new Regex("\\.c$")).replace(  
-                                                       cfiles.get(i), cfiles.get(i).length, 0, ".vala");
-                                                       
-                                       if (ret.index_of( vv) > -1) {
-                                               continue;
-                                       }
-                                       ret.add(cfiles.get(i));
+                       for (var i = 0; i < cfiles.size; i ++) {
+                               
+                               var fn = cfiles.get(i);
+                               vv = fn;
+                               try {
+                                       vv = (new Regex("\\.c$")).replace( fn, fn, 0, ".vala");
+                               } catch (Error e) {
+                                       continue;
                                }
+                                       
                                                
-                                      
-                       } catch(Error e) {
-                               GLib.warning("oops - something went wrong scanning the projects\n");
+                               if (ret.index_of( vv) > -1) {
+                                       continue;
+                               }
+                               ret.add(fn);
                        }
+                                               
+                        
                        GLib.debug("SCAN %s = returning %d", dirname, ret.size);
                         
                        return ret;