Changeset 314:248e3671b39b

Show
Ignore:
Timestamp:
2007-09-02 13:27:27 (1 year ago)
Author:
Stefan Schwarzer <sschwarzer@sschwarzer.net>
branch:
default
Message:
Removed code for displaying navigation links after directories. These
were well-intended but rather confusing. I hope adding a title to each
item's name makes up for the missing navigation links.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • converter.py

    r313 r314  
    110110    add_html('</p>') 
    111111    return "\n".join(html_parts) 
    112  
    113 def _directory_navigation(item, directory_tree, start_level, actual_dir_levels): 
    114     """ 
    115     Return HTML code for the arrow links after directory items. 
    116     The string `item` is assumed to be a path for a directory while 
    117     `directory_tree` is a `dirtree.DirectoryTree` object containing 
    118     relations between items. The integer `start_level` is the 
    119     directory level for the root path the directory is displayed for. 
    120     The integer `actual_dir_levels` is the depth of the directory tree 
    121     as it should be displayed. 
    122     """ 
    123     if dirtree.dir_level(item) - start_level == actual_dir_levels: 
    124         return "" 
    125     item_family = directory_tree.family[item] 
    126     # use text ready for display in HTML code 
    127     link_data = [(item_family.parent, "par"), 
    128                  (item_family.previous, "prev"), 
    129                  (item_family.next, "next")] 
    130     links = [] 
    131     for relative, text in link_data: 
    132         if relative: 
    133             relative = urlpath.to_url(config.root, relative) 
    134             anchor = tools.url_to_anchor(relative) 
    135             links.append('<a href="#%s">%s</a>' % 
    136                          (anchor, text)) 
    137         else: 
    138             links.append(text) 
    139     return '<span class="DirLinks">&nbsp;' + "&nbsp;".join(links) + '</span>' 
    140  
    141 # mask `_directory_navigation` with dummy implementation for now 
    142 def _directory_navigation(*args, **kwargs): 
    143     return "" 
    144112 
    145113def dir_to_html(path, params): 
     
    211179        # HTML for suffix 
    212180        if os.path.isdir(item): 
    213             suffix = u'&nbsp;/%s' % \ 
    214                      _directory_navigation(item, tree, start_level, 
    215                                            actual_dir_levels) 
     181            suffix = u'&nbsp;/' 
    216182        else: 
    217183            suffix = "" 
  • dirtree.py

    r313 r314  
    132132        return False 
    133133 
    134     def _make_family_data(self, depth): 
    135         """ 
    136         Generate family data. That is, for each item store an 
    137         `_ItemFamily` object - with the parent item and the previous 
    138         and next sibling items - in the instance variable `family`. 
    139         If a value can't be determined, e. g. the previous sibling of 
    140         the "first" item in a directory, it's set to `None`. 
    141         """ 
    142         if not self.items: 
    143             return 
    144         # helper generator 
    145         dir_items = [item for item in self.items if os.path.isdir(item)] 
    146         # this helps to make the algorithm simpler 
    147         family = {"": _ItemFamily()} 
    148         # prepare "local" families for items 
    149         for item in dir_items: 
    150             family[item] = _ItemFamily() 
    151         # remember the last item we encountered at each dir level as 
    152         #  mapping {dir_level: item (string)} 
    153         previous_sibling = {} 
    154         for item in dir_items: 
    155             # make an alias for the family of this item 
    156             item_family = family[item] 
    157             ### set parent for this item 
    158             item_family.parent = os.path.dirname(item) 
    159             ### set previous sibling for this item 
    160             # consider siblings at this dir level 
    161             item_level = dir_level(item) 
    162             # set a useful default 
    163             previous_sibling.setdefault(item_level, "") 
    164             # two items aren't siblings if they don't have the same parent 
    165             if item_family.parent != \ 
    166               family[previous_sibling[item_level]].parent: 
    167                 item_family.previous = "" 
    168             else: 
    169                 item_family.previous = previous_sibling[item_level] 
    170             ### make this item the next sibling for its previous sibling 
    171             if item_family.previous: 
    172                 family[item_family.previous].next = item 
    173             # the current item is the previous sibling for the next item 
    174             #  on its dir level 
    175             previous_sibling[item_level] = item 
    176         # make some final corrections 
    177         for item, item_family in family.iteritems(): 
    178             if item_family.parent == self.root: 
    179                 item_family.parent = "" 
    180             # use `None` instead of the empty string in the end result 
    181             item_family.parent = (item_family.parent or None) 
    182             item_family.previous = (item_family.previous or None) 
    183             item_family.next = (item_family.next or None) 
    184         self.family = family 
    185  
    186134    def read(self, depth=sys.maxint): 
    187135        """ 
     
    208156          itertools.ifilterfalse(self._ignore_item, 
    209157                                 self.walk(self.root, depth=depth))) 
    210         # determine parent and sibling items 
    211         #self._make_family_data(depth=depth) 
    212158 
    213159    def __str__(self): 
  • test_dirtree_posix.txt

    r310 r314  
    8080    False 
    8181 
    82 After scanning the directory, the dictionary attribute ``family`` 
    83 contains information on how the file system items are related. For the 
    84 following example, we set the items directly. In reality, the 
    85 generation of the ``family`` data structure would happen upon reading 
    86 the directory tree. 
    87  
    88     >>> dt = dirtree.DirectoryTree("/the/root") 
    89     >>> dt.items = [ 
    90     ... "/the/root/abc", 
    91     ... "/the/root/abc/abc", 
    92     ... "/the/root/abc/def", 
    93     ... "/the/root/abc/ghi", 
    94     ... "/the/root/def", 
    95     ... "/the/root/def/abc", 
    96     ... "/the/root/ghi"] 
    97     >>> dt._make_family_data() 
    98     >>> for item in dt.items: 
    99     ...     family = dt.family[item] 
    100     ...     print item, family.parent, family.previous, family.next 
    101     /the/root/abc None None /the/root/def 
    102     /the/root/abc/abc /the/root/abc None /the/root/abc/def 
    103     /the/root/abc/def /the/root/abc /the/root/abc/abc /the/root/abc/ghi 
    104     /the/root/abc/ghi /the/root/abc /the/root/abc/def None 
    105     /the/root/def None /the/root/abc /the/root/ghi 
    106     /the/root/def/abc /the/root/def None None 
    107     /the/root/ghi None /the/root/def None 
    108  
    109 Note that the root directory isn't considered as parent directory. 
    110 This has to do with the application in Websourcebrowser. (We don't 
    111 want to go "up" beyond the root directory.) 
    112  
  • websourcebrowser.css

    r312 r314  
    1414    padding-left: 3px; padding-right: 3px; } 
    1515span.Indent { color: #b0b0b0; font-size: 10px; } 
    16 span.DirLinks { color: #b0b0b0; } 
    17 span.DirLinks a { color: black; } 
    1816table { margin-top: 0px; padding-top: 0px; margin-bottom: 1em; } 
    1917body, .Main, table { font-size: 12px; }