SVN/Wx/BlameTree.pm untested

filter: Statementstmt 0.0% 0 / 77 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 108 CC 6 SCAR 19.7
CC
6
Cov
0%
populate
20.0
add_child
6.0
_get_next_revNo
6.0
CRAP 7.2
1 package Padre::Plugin::SVN::Wx::BlameTree;
2  
3 use 5.008;
4 use strict;
5 use warnings;
6 use Encode ();
7 use Padre::Constant ();
8 use Padre::Wx ();
9 use Padre::Locale ();
10  
11 use Wx qw(:treectrl :window wxDefaultPosition wxDefaultSize);
12  
13 our $VERSION = '0.05';
14 our @ISA = 'Wx::TreeCtrl';
15  
16  
17 sub new {
18 my $class = shift;
19 my $parent = shift;
20 #my $blame= shift;
21
22
23
24 my $self = $class->SUPER::new(
25 $parent,
26 -1,
27 Wx::wxDefaultPosition,
28 #Wx::wxDefaultSize,
29 [700,450],
30 Wx::wxTR_HAS_BUTTONS | Wx::wxTR_HIDE_ROOT | Wx::wxTR_LINES_AT_ROOT | Wx::wxSUNKEN_BORDER |
31 Wx::wxTR_FULL_ROW_HIGHLIGHT | Wx::wxTR_NO_LINES
32
33 );
34
35 $self->{root} = $self->AddRoot(
36 'Root',
37 -1,
38 -1,
39 Wx::TreeItemData->new('Data'),
40 );
41
42 # set alternate colour
43 $self->{altColor} = Wx::Colour->new(221, 221, 221);
44
45 return $self;
46 }
47  
48  
49 sub populate {
50 my $self = shift;
51 my $blame = shift;
52
53 my $alt = 0;
54 my $setAlt = 0;
55
56 my $lastSeen = -1;
57
58 for(my $i=0; $i < scalar(@$blame); $i++) {
59
60 $setAlt = ($alt % 2 == 0) ? 1 : 0;
61
62 my $line = $blame->[$i];
63 chomp($line);
64 $line =~ s/^\s+//s;
65 $line =~ m/^(\d+)\s/;
66 my $revNo = $1;
67 # print "\n##Revision number for this line: $revNo\n";
68  
69 # grab the next lines revno
70 my $next = $self->_get_next_revNo($i, $blame);
71 # print "Next Rev No: $next\n";
72
73 my $item = $self->AppendItem(
74 $self->{root},
75 $line,
76 1,
77 1,
78 Wx::TreeItemData->new($line)
79 );
80
81 # if we now have a following line that belongs to this revno
82 # then keep working through the log file until
83 # this is no longer the case, then set $i to the
84 # index value of $j.
85 if($next > 0 && $next == $revNo) {
86 # print "This belongs to the same node revNo: $revNo - next: $next\n";
87  
88 # print "Next one: $nr\n";
89  
90 # keep a track of the index for the revNo
91 my $revNoIndex = $i;
92
93 while( $next == $revNo ) {
94 #print "Line: $line\n";
95
96 $i++;
97 $line = $blame->[$i];
98 $self->add_child($item,$line,$i, $revNo, $revNoIndex, $setAlt);
99
100 $next = $self->_get_next_revNo($i, $blame);
101 # print "Next: $next\n";
102 }
103
104 }
105 else {
106 # print "New node $next\n";
107
108 }
109  
110 #if( $alt % 2 == 0 ) {
111 if( $setAlt ) {
112 $self->SetItemBackgroundColour( $item, $self->{altColor} );
113 }
114 $alt++;
115 $lastSeen = $revNo;
116 $self->Expand($item);
117 }
118
119
120 }
121  
122  
123 sub add_child {
124 my( $self, $parent, $line, $index, $revNo, $revNoIndex, $setAlt ) = @_;
125 #print "Adding child $index, $revNo, $revNoIndex - $line\n";
126 #$self->SetIndent(0);
127 my $item = $self->AppendItem(
128 $parent,
129 $line,
130 1,
131 1,
132 Wx::TreeItemData->new($line)
133 );
134 if( $setAlt ) {
135 $self->SetItemBackgroundColour( $item, $self->{altColor} );
136 }
137 my $t = Wx::TreeItemData->new;
138 $t->SetData( $revNo .'-'. $revNoIndex );
139 $self->SetItemData($item,$t);
140
141
142 }
143  
144 sub _get_next_revNo {
145 my($self,$index, $log) = @_;
146 # print "get_next index: $index\n";
147
148 my $next = -1;
149 if( $index + 1 < scalar(@$log) ) {
150 my $line = $log->[$index+1];
151 $line =~ s/^\s+//s;
152 $line =~ m/^(\d+)\s/;
153 $next = $1;
154 # print "_get_next: Next: $next\n";
155 }
156 return $next;
157 }
158  
159 1;