SVN/Wx/SVNDialog.pm untested

filter: Statementstmt 0.0% 0 / 121 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 157 CC 6 SCAR 18.6
CC
6
Cov
0%
build_dialog
20.0
new
6.0
ok_clicked
6.0
CRAP 6.4
1 package Padre::Plugin::SVN::Wx::SVNDialog;
2  
3  
4 use 5.008;
5 use warnings;
6 use strict;
7  
8 use Padre::Wx ();
9 use Padre::Wx::Dialog ();
10 use Padre::Wx::Icon ();
11  
12 our $VERSION = '0.05';
13 our @ISA = 'Wx::Dialog';
14  
15 sub new {
16 my $class = shift;
17 my $main = shift;
18 my $filePath = shift;
19 my $log = shift;
20 my $type = shift || '';
21 my $getData = shift;
22  
23 my $self = $class->SUPER::new(
24 $main,
25 -1,
26 "SVN $type",
27 [ -1, -1 ], # position
28 [ 700, 600 ], # size - [wide,high]
29 );
30 $self->SetIcon(Padre::Wx::Icon::PADRE);
31
32 if( lc($type) eq 'blame' ) {
33 $self->build_blame_dialog($filePath, $log);
34 }
35 else {
36 $self->build_dialog( $filePath, $log, $getData );
37 }
38  
39 return $self;
40  
41 }
42  
43  
44 sub build_dialog {
45 my ( $self, $file, $log, $getData ) = @_;
46
47
48
49 my $vbox = Wx::BoxSizer->new(Wx::wxVERTICAL);
50  
51 my $stTxtFile = Wx::StaticText->new(
52 $self,
53 -1,
54 Wx::gettext("File: $file"),
55 Wx::wxDefaultPosition,
56 Wx::wxDefaultSize,
57 0,
58 ""
59 );
60  
61 $vbox->Add( $stTxtFile, 0, Wx::wxEXPAND );
62  
63 #print "file: $file\n";
64 #print "Log: $log\n";
65  
66 my $txtCtrl;
67 if ($log) {
68 $txtCtrl = Wx::TextCtrl->new(
69 $self,
70 -1,
71 "$log",
72 Wx::wxDefaultPosition,
73 [ -1, -1 ],
74 Wx::wxTE_MULTILINE | Wx::wxHSCROLL | Wx::wxVSCROLL | Wx::wxTE_WORDWRAP
75 );
76 }
77 if ($getData) {
78  
79 #print "getting data\n";
80 $txtCtrl = Wx::TextCtrl->new(
81 $self,
82 -1,
83 "Commit Message",
84 Wx::wxDefaultPosition,
85 [ -1, -1 ],
86 Wx::wxTE_MULTILINE | Wx::wxHSCROLL | Wx::wxVSCROLL | Wx::wxTE_WORDWRAP
87 );
88 $txtCtrl->SetSelection( -1, -1 );
89 $txtCtrl->SetFocus;
90 $self->{txtctrl} = $txtCtrl;
91 }
92  
93  
94  
95 $vbox->Add( $txtCtrl, 1, Wx::wxEXPAND );
96  
97 my $btnBox = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
98 my $pnlButtons = Wx::Panel->new(
99 $self,
100 -1, # id
101 [ -1, -1 ], # position
102 [ -1, -1 ], # size
103 0 # border style
104 );
105  
106 # button height is set to 40 simply to get them to look the same
107 # in GTK.
108 # not sure what this is going to look like in other window managers.
109 if ($getData) {
110  
111 $self->{cancelled} = 0;
112 my $btnCancel = Wx::Button->new( $pnlButtons, Wx::wxID_CANCEL, "Cancel", [ -1, -1 ], [ -1, 40 ] );
113 Wx::Event::EVT_BUTTON( $self, $btnCancel, \&cancel_clicked );
114 $btnBox->Add( $btnCancel, 1, Wx::wxALIGN_BOTTOM | Wx::wxALIGN_RIGHT );
115  
116 }
117  
118 my $btnOK = Wx::Button->new( $pnlButtons, Wx::wxID_OK, "OK", [ -1, -1 ], [ -1, 40 ] );
119 Wx::Event::EVT_BUTTON( $self, $btnOK, \&ok_clicked );
120  
121 $btnBox->Add( $btnOK, 1, Wx::wxALIGN_BOTTOM | Wx::wxALIGN_RIGHT );
122  
123  
124 $pnlButtons->SetSizer($btnBox);
125  
126 #$btnBox->Add( $pnlButtons, 0, Wx::wxALIGN_BOTTOM | Wx::wxALIGN_RIGHT | Wx::wxEXPAND);
127 $vbox->Add( $pnlButtons, 0, Wx::wxALIGN_BOTTOM | Wx::wxALIGN_RIGHT );
128  
129  
130 $self->SetSizer($vbox);
131  
132 }
133  
134  
135 sub build_blame_dialog {
136
137 my ( $self, $file, $log ) = @_;
138
139 #$self->{_busyCursor} = Wx::BusyCursor->new();
140
141 my $vbox = Wx::BoxSizer->new(Wx::wxVERTICAL);
142  
143 require Padre::Plugin::SVN::Wx::BlameTree;
144 $self->{blame} = Padre::Plugin::SVN::Wx::BlameTree->new($self);
145 $self->{blame}->populate($log);
146 $vbox->Add( $self->{blame}, 0, Wx::wxEXPAND );
147  
148 #print "file: $file\n";
149 #print "Log: $log\n";
150  
151 my $btnBox = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
152 my $pnlButtons = Wx::Panel->new(
153 $self,
154 -1, # id
155 [ -1, -1 ], # position
156 [ -1, -1 ], # size
157 0 # border style
158 );
159  
160 # button height is set to 40 simply to get them to look the same
161 # in GTK.
162 # not sure what this is going to look like in other window managers.
163
164 my $btnExpandAll = Wx::Button->new( $pnlButtons, -1, "Expand", [ -1, -1 ], [ -1, 40 ] );
165 Wx::Event::EVT_BUTTON( $self, $btnExpandAll, \&expand_clicked );
166 $btnBox->Add( $btnExpandAll, 1, Wx::wxALIGN_BOTTOM | Wx::wxALIGN_LEFT );
167
168 my $btnCollapseAll = Wx::Button->new( $pnlButtons, -1, "Collapse", [ -1, -1 ], [ -1, 40 ] );
169 Wx::Event::EVT_BUTTON( $self, $btnCollapseAll, \&collapse_clicked );
170 $btnBox->Add( $btnCollapseAll, 1, Wx::wxALIGN_BOTTOM | Wx::wxALIGN_LEFT );
171
172  
173  
174 my $btnOK = Wx::Button->new( $pnlButtons, Wx::wxID_OK, "OK", [ -1, -1 ], [ -1, 40 ] );
175 Wx::Event::EVT_BUTTON( $self, $btnOK, \&ok_clicked );
176  
177 $btnBox->Add( $btnOK, 1, Wx::wxALIGN_BOTTOM | Wx::wxALIGN_RIGHT );
178  
179  
180 $pnlButtons->SetSizer($btnBox);
181  
182 #$btnBox->Add( $pnlButtons, 0, Wx::wxALIGN_BOTTOM | Wx::wxALIGN_RIGHT | Wx::wxEXPAND);
183 $vbox->Add( $pnlButtons, 0, Wx::wxALIGN_BOTTOM | Wx::wxALIGN_RIGHT );
184  
185  
186 $self->SetSizer($vbox);
187 #$self->{_busyCursor} = undef;
188 }
189  
190 sub collapse_clicked {
191 my( $self ) = @_;
192 $self->{_busyCursor} = Wx::BusyCursor->new();
193 $self->{blame}->CollapseAll();
194 $self->{_busyCursor} = undef;
195 }
196 sub expand_clicked {
197 my ($self) = @_;
198 $self->{_busyCursor} = Wx::BusyCursor->new();
199 $self->{blame}->ExpandAll();
200 $self->{_busyCursor} = undef;
201 }
202  
203 sub ok_clicked {
204 my ($self) = @_;
205  
206 #print "OK Clicked\n";
207 my $txt;
208 if ( $self->{txtctrl} ) {
209  
210 #print "have to return data: " . $self->{txtctrl}->GetValue;
211 $txt = $self->{txtctrl}->GetValue;
212 }
213 $self->Hide();
214 $self->Destroy;
215 return $txt;
216 }
217  
218 sub cancel_clicked {
219 my ($self) = @_;
220  
221 $self->{cancelled} = 1;
222 #print "Cancel Clicked\n";
223 $self->Hide();
224 $self->Destroy;
225 $self->{txtctrl}->SetValue("");
226  
227 return;
228  
229 }
230  
231 sub get_data {
232 my ($self) = @_;
233  
234 #print "Getting Data: " . $self->{txtctrl}->GetValue . "\n";
235 return $self->{txtctrl}->GetValue;
236  
237 #my $txt = $self->{txtctrl}->GetValue;
238 #use Data::Dumper;
239 #print Dumper($txt);
240 #return $txt ;
241  
242 }
243  
244  
245  
246 1;
247  
248 =head1 NAME
249  
250 Padre::Plugin::SVN::Wx::SVNDialog - Dialog for SVN tasks.
251  
252 =head1 SYNOPSIS
253  
254 Provides a Dialog specifically for the SVN Plugin.
255  
256 =head1 REQUIREMENTS
257  
258 Nil
259  
260 =head1 AUTHOR
261  
262 Peter Lavender, C<< <peter.lavender at gmail.com> >>
263  
264 =head1 BUGS
265  
266 Please report any bugs or feature requests to L<http://padre.perlide.org/>
267  
268  
269 =head1 COPYRIGHT & LICENSE
270  
271 Copyright 2008-2009 The Padre development team as listed in Padre.pm.
272 all rights reserved.
273  
274 This program is free software; you can redistribute it and/or modify it
275 under the same terms as Perl itself.
276  
277  
278 =cut
279