source: revtreeplugin/0.11/revtree/enhancer.py

Last change on this file was 4695, checked in by Emmanuel Blot, 15 years ago

Fixes #3442. Thanks to erik for the patch

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2006-2008 Emmanuel Blot <emmanuel.blot@free.fr>
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
15from revtree.api import IRevtreeEnhancer, RevtreeEnhancer
16from revtree.svgview import SvgOperation, SvgGroup
17from trac.core import *
18
19__all__ = ['SimpleEnhancerModule']
20
21
22class SimpleEnhancer(RevtreeEnhancer):
23    """This class is a very basic skeleton that needs to customized, to
24       provide SvgOperation, SvgGroup and other widgets in the RevTree graphic
25    """
26       
27    def __init__(self, env, req, repos, svgrevtree):
28        """Creates the internal data from the repository"""
29        self.repos = repos
30        self.creations = []
31        self.svgrevtree = svgrevtree
32        # z-depth indexed widgets
33        self._widgets = [[] for l in IRevtreeEnhancer.ZLEVELS]
34       
35        for branch in self.repos.branches().values():
36            svgbranch = self.svgrevtree.svgbranch(branch=branch)
37            if not svgbranch:
38                # branch has probably been filtered out
39                continue
40            firstchgset = branch.oldest()
41            # if the first changeset of a branch is a copy of another
42            # changeset(from another branch)
43            if firstchgset and firstchgset.clone:
44                # tweak the appearance of this changeset ..
45                svgbranch.svgchangeset(firstchgset).mark_first()
46                (rev, path) = branch.source()
47                srcchg = self.repos.changeset(rev)
48                if srcchg is None:
49                    continue
50                # .. and create an operation between both changesets
51                self.creations.append((srcchg, firstchgset))
52            lastchgset = branch.youngest()
53            if lastchgset:
54                # if the last changeset of the branch is the very last
55                if lastchgset.last:
56                    # tweak the color of this changeset
57                    svgbranch.svgchangeset(lastchgset).mark_last()
58
59    def build(self):
60        """Build the enhanced widgets"""
61        for (srcchg, dstchg) in self.creations:
62            svgsrcbr = self.svgrevtree.svgbranch(branchname=srcchg.branchname)
63            if svgsrcbr is None:
64                continue
65            svgsrcchg = svgsrcbr.svgchangeset(srcchg)
66            svgdstbr = self.svgrevtree.svgbranch(branchname=dstchg.branchname)
67            if svgdstbr is None:
68                continue
69            svgdstchg = svgdstbr.svgchangeset(dstchg)
70            op = SvgOperation(self.svgrevtree, svgsrcchg, svgdstchg, '#3f3f3f')
71            self._widgets[IRevtreeEnhancer.ZFORE].append(op)
72                   
73        for wl in self._widgets:
74            map(lambda w: w.build(), wl)
75       
76    def render(self, level):
77        """Renders the widgets, from background plane to foreground plane"""
78        if level < len(IRevtreeEnhancer.ZLEVELS):
79            map(lambda w: w.render(), self._widgets[level])
80
81
82class SimpleEnhancerModule(Component):
83    """Enhance the appearance of the RevTree with site-specific properties.
84   
85    Create branch clone operation (on branch/tag operations)
86   
87    This class is a very basic skeleton that needs to customized, to provide
88    SvgOperation, SvgGroup and other widgets in the RevTree graphic
89    """
90   
91    implements(IRevtreeEnhancer)   
92
93    def create(self, env, req, repos, svgrevtree):
94        return SimpleEnhancer(env, req, repos, svgrevtree)
Note: See TracBrowser for help on using the repository browser.