Changeset 719

Show
Ignore:
Timestamp:
07/29/07 03:20:40 (1 year ago)
Author:
Gregor
Message:

dsssps/dps.d: Improved components list.

dsssps/newfile.d: Now can create subdirs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • other/dps/trunk/dsssps/dps.d

    r716 r719  
    1313import tango.sys.Process; 
    1414 
     15import tango.text.Util; 
    1516import tango.text.stream.LineIterator; 
    1617 
     
    3839    // IDs for important elements 
    3940    enum Elem { Tree, MenuBar, MenuPreferences, MenuQuit }; 
     41 
     42    /// Add a file list in a tree 
     43    void addFileList(wxTreeItemId top, char[][] flist, char[] prefix = "") 
     44    { 
     45        // first convert the file list to a list of directories and files in this dir 
     46        char[][][char[]] subdirs; 
     47        char[][] dirfiles; 
     48 
     49        // remove the prefix if applicable 
     50        if (prefix != "") { 
     51            Cout(prefix).newline; 
     52            flist = flist.dup; 
     53            foreach (k, f; flist) { 
     54                if (f.length >= prefix.length && 
     55                    f[0 .. prefix.length] == prefix) { 
     56                    flist[k] = f[prefix.length .. $]; 
     57                } 
     58            } 
     59        } 
     60 
     61        /// Subfunction to convert a path to the head and tail components 
     62        char[][] pathHeadTail(char[] p) 
     63        { 
     64            char[][] elems = split(p, "/"); 
     65            return [elems[0], join(elems[1..$], "/")]; 
     66        } 
     67 
     68        foreach (f; flist) { 
     69            FilePath fp = new FilePath(f); 
     70            if (fp.path() == "") { 
     71                // file in this dir 
     72                dirfiles ~= f; 
     73            } else { 
     74                auto pht = pathHeadTail(f); 
     75                subdirs[pht[0]] ~= pht[1]; 
     76            } 
     77        } 
     78 
     79        // Now, for each subdir, call recursively 
     80        foreach (sd; subdirs.keys.dup.sort) { 
     81            wxTreeItemId sdti = components.AppendItem(top, sd, 0); 
     82            addFileList(sdti, subdirs[sd]); 
     83        } 
     84 
     85        // Then, add the files 
     86        foreach (f; dirfiles.sort) { 
     87            components.AppendItem(top, f, 1, -1, new CompFile(f)); 
     88        } 
     89    } 
    4090     
    4191    /// Load the top dsss.conf file into the components tree 
     
    69119                    sect ~ " [" ~ conf.settings[sect]["type"] ~ "]", 0, -1, 
    70120                    new CompLibSect(sect)); 
    71                 char[][] fs = targetToFiles(sect, conf); 
    72                 foreach (f; fs) { 
    73                     tree.AppendItem(comp, f, 1, -1, new CompFile(f)); 
    74                 } 
     121                addFileList(comp, targetToFiles(sect, conf), sect ~ "/"); 
    75122 
    76123                // and add a button for adding new files 
     
    100147                p.wait(); 
    101148 
    102                 // now sort the list 
    103                 flist.sort; 
    104                 // and add each item 
    105                 foreach (file; flist) { 
    106                     tree.AppendItem(comp, 
    107                         file, 1, -1, 
    108                         new CompFile(file)); 
    109                 } 
     149                // now add the list 
     150                addFileList(comp, flist); 
    110151 
    111152                // then use rebuild to get the list of non-existing files 
     
    118159                p.wait(); 
    119160 
    120                 // sort it 
    121                 flist.sort; 
     161                // are there any non-existing files? 
    122162                if (flist.length != 0) { 
    123163                    // OK, need to add a not-found section 
     
    125165                        tree.AppendItem(comp, 
    126166                            "Non-existent files", 0, -1); 
    127  
    128                     foreach (file; flist) { 
    129                         tree.AppendItem(notfound, 
    130                             file, 1, -1, 
    131                             new CompFileNew(file)); 
    132                     } 
     167                    addFileList(notfound, flist); 
    133168                } 
    134169 
  • other/dps/trunk/dsssps/newfile.d

    r713 r719  
    22 
    33import tango.io.File; 
     4import tango.io.FilePath; 
    45 
    56import wx.wx; 
     7 
     8import hcf.path; 
    69 
    710import dsssps.dps; 
     
    5053        } 
    5154 
     55        // then make sure the directory exists 
     56        mkdirP((new FilePath(name)).path()); 
     57 
    5258        // then fill out the basic file 
    5359        (new File(name)).write("module " ~ mod ~ ";\n");