| [1633] | 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| [1895] | 3 | # Copyright (C) 2006-2007 Emmanuel Blot <emmanuel.blot@free.fr> |
|---|
| [1633] | 4 | # All rights reserved. |
|---|
| 5 | # |
|---|
| 6 | # This software is licensed as described in the file COPYING, which |
|---|
| 7 | # you should have received as part of this distribution. The terms |
|---|
| 8 | # are also available at http://trac.edgewall.com/license.html. |
|---|
| 9 | # |
|---|
| 10 | # This software consists of voluntary contributions made by many |
|---|
| 11 | # individuals. For the exact contribution history, see the revision |
|---|
| 12 | # history and logs, available at http://projects.edgewall.com/trac/. |
|---|
| 13 | # |
|---|
| 14 | |
|---|
| [1895] | 15 | from revtree.api import IRevtreeEnhancer |
|---|
| [1633] | 16 | from revtree.svgview import SvgOperation, SvgGroup |
|---|
| [1694] | 17 | from trac.core import * |
|---|
| [1633] | 18 | |
|---|
| [1895] | 19 | __all__ = ['SimpleEnhancer'] |
|---|
| [1633] | 20 | |
|---|
| [1694] | 21 | class SimpleContainer(object): |
|---|
| 22 | """Simple container for enhancer parameters""" |
|---|
| [1633] | 23 | |
|---|
| [1694] | 24 | def __init__(self): |
|---|
| 25 | pass |
|---|
| 26 | |
|---|
| [1633] | 27 | |
|---|
| [1694] | 28 | class SimpleEnhancer(Component): |
|---|
| 29 | """Enhance the appearance of the RevTree with site-specific properties. |
|---|
| 30 | |
|---|
| 31 | Create branch clone operation (on branch/tag operations) |
|---|
| 32 | |
|---|
| 33 | This class is a very basic skeleton that needs to customized, to provide |
|---|
| 34 | SvgOperation, SvgGroup and other widgets in the RevTree graphic |
|---|
| 35 | """ |
|---|
| 36 | |
|---|
| 37 | implements(IRevtreeEnhancer) |
|---|
| 38 | |
|---|
| 39 | def create(self, env, req, repos, svgrevtree): |
|---|
| [1633] | 40 | """Creates the internal data from the repository""" |
|---|
| [1694] | 41 | enhancer = SimpleContainer() |
|---|
| 42 | enhancer.repos = repos |
|---|
| 43 | enhancer.creations = [] |
|---|
| 44 | enhancer.deliveries = [] |
|---|
| 45 | enhancer.groups = [] |
|---|
| 46 | enhancer.svgrevtree = svgrevtree |
|---|
| 47 | # z-depth indexed widgets: back=1, fore=2 |
|---|
| 48 | enhancer.widgets = ([], [], []) |
|---|
| 49 | |
|---|
| 50 | #self._sort() |
|---|
| 51 | for branch in enhancer.repos.branches().values(): |
|---|
| 52 | svgbranch = enhancer.svgrevtree.svgbranch(branch=branch) |
|---|
| [1633] | 53 | if not svgbranch: |
|---|
| 54 | # branch has probably been filtered out |
|---|
| 55 | continue |
|---|
| 56 | firstchgset = branch.oldest() |
|---|
| 57 | # if the first changeset of a branch is a copy of another |
|---|
| 58 | # changeset(from another branch) |
|---|
| 59 | if firstchgset and firstchgset.clone: |
|---|
| [1696] | 60 | # tweak the appearance of this changeset .. |
|---|
| 61 | svgbranch.svgchangeset(firstchgset).mark_first() |
|---|
| [1633] | 62 | (rev, path) = branch.source() |
|---|
| [1694] | 63 | srcchg = enhancer.repos.changeset(rev) |
|---|
| [1633] | 64 | if srcchg is None: |
|---|
| 65 | continue |
|---|
| 66 | # .. and create an operation between both changesets |
|---|
| [1694] | 67 | enhancer.creations.append((srcchg, firstchgset)) |
|---|
| [1633] | 68 | lastchgset = branch.youngest() |
|---|
| 69 | if lastchgset: |
|---|
| 70 | # if the last changeset of the branch is the very last |
|---|
| 71 | if lastchgset.last: |
|---|
| 72 | # tweak the color of this changeset |
|---|
| [1696] | 73 | svgbranch.svgchangeset(lastchgset).mark_last() |
|---|
| [1694] | 74 | return enhancer |
|---|
| [1633] | 75 | |
|---|
| [1694] | 76 | def build(self, enhancer): |
|---|
| [1633] | 77 | """Build the enhanced widgets""" |
|---|
| [1694] | 78 | for (srcchg, dstchg) in enhancer.creations: |
|---|
| 79 | svgsrcbr = enhancer.svgrevtree.svgbranch(branchname=srcchg.branchname) |
|---|
| [1652] | 80 | if svgsrcbr is None: |
|---|
| 81 | continue |
|---|
| [1633] | 82 | svgsrcchg = svgsrcbr.svgchangeset(srcchg) |
|---|
| [1694] | 83 | svgdstbr = enhancer.svgrevtree.svgbranch(branchname=dstchg.branchname) |
|---|
| [1652] | 84 | if svgdstbr is None: |
|---|
| 85 | continue |
|---|
| [1633] | 86 | svgdstchg = svgdstbr.svgchangeset(dstchg) |
|---|
| [1694] | 87 | op = SvgOperation(enhancer.svgrevtree, svgsrcchg, svgdstchg, \ |
|---|
| 88 | '#5faf5f') |
|---|
| 89 | enhancer.widgets[2].append(op) |
|---|
| [1633] | 90 | |
|---|
| [1694] | 91 | for wl in enhancer.widgets: |
|---|
| [1633] | 92 | map(lambda w: w.build(), wl) |
|---|
| 93 | |
|---|
| [1694] | 94 | def render(self, enhancer, level): |
|---|
| 95 | """Renders the widgets, from background plane to foreground plane""" |
|---|
| 96 | if level < len(enhancer.widgets): |
|---|
| 97 | map(lambda w: w.render(), enhancer.widgets[level]) |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|