Codit/Plugins/SplitView.pm untested

filter: Statementstmt 0.0% 0 / 150 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 203 CC 12 SCAR 18.5
CC
12
Cov
0%
splitClose
12.0
splitOpen
12.0
splitSelect
12.0
CRAP 6.3
1 package App::Codit::Plugins::SplitView;
2  
3 =head1 NAME
4  
5 App::Codit::Plugins::SplitView - plugin for App::Codit
6  
7 =cut
8  
9 use strict;
10 use warnings;
11 use vars qw( $VERSION );
12 $VERSION = '0.19';
13  
14 use base qw( Tk::AppWindow::BaseClasses::Plugin );
15  
16 require Tk::Adjuster;
17 require Tk::YANoteBook;
18 require App::Codit::CodeTextManager;
19  
20 =head1 DESCRIPTION
21  
22 Create a secondary document interface for simultaneous reviewing.
23  
24 =head1 DETAILS
25  
26 This plugin creates a secondary document interface that holds all the
27 documents in the primary one in a readonly state. You can create
28 a horizontal or a vertical split through the View menu. Whenever
29 a document is opened or closed in the primary interface it is also
30 opened or closed in the secondary interface.
31  
32 =head1 COMMANDS
33  
34 =over 4
35  
36 =item B<split_cancel>
37  
38 Removes an existing split from view.
39  
40 =item B<split_horizontal>
41  
42 Creates a horizontal split.
43  
44 =item B<split_vertical>
45  
46 Creates a vertical split.
47  
48 =back
49  
50 =cut
51  
52 sub new {
53 my $class = shift;
54 my $self = $class->SUPER::new(@_);
55 return undef unless defined $self;
56
57 $self->{ADJUSTER} = undef;
58 $self->{DOCS} = {};
59 $self->{SPLIT} = undef;
60 $self->{STATE} = 'none';
61 my $w = $self->WorkSpace;
62
63 $self->cmdHookAfter('doc_close', 'splitClose', $self);
64 $self->cmdHookAfter('doc_open', 'splitOpen', $self);
65  
66 $self->cmdConfig(
67 split_cancel => ['splitCancel', $self],
68 split_horizontal => ['splitHorizontal', $self],
69 split_vertical => ['splitVertical', $self],
70 );
71 return $self;
72 }
73  
74 sub MenuItems {
75 my $self = shift;
76 my $path = 'View::Show navigator panel';
77 return (
78 #This table is best viewed with tabsize 3.
79 # type menupath label cmd icon
80 [ 'menu_normal', $path, 'Split ~horizontal', 'split_horizontal', 'view-split-left-right'],
81 [ 'menu_normal', $path, 'Split ~vertical', 'split_vertical', 'view-split-top-bottom'],
82 [ 'menu_normal', $path, 'Split ~cancel', 'split_cancel', ],
83 [ 'menu_separator',$path, 's1'],
84 )
85 }
86  
87 sub split { return $_[0]->{SPLIT} }
88  
89 sub splitCancel {
90 my $self = shift;
91 my $state = $self->{STATE};
92 return if $self->{STATE} eq 'none';
93 $self->splitRemove;
94 $self->{STATE} = 'none';
95 }
96  
97 sub splitClose {
98 my ($self, $name) = @_;
99 my $split = $self->{SPLIT};
100 return unless defined $split;
101 return if $name eq '';
102 my $plit = $self->split;
103 $split->deletePage($name);
104 }
105  
106 sub splitGet {
107 my $self = shift;
108 my $split = $self->{SPLIT};
109 unless (defined $split) {
110 $split = $self->{INTERFACE} = $self->WorkSpace->YANoteBook(
111 -image => $self->getArt('document-multiple', 16),
112 -selecttabcall => ['splitSelect', $self ],
113 );
114 my $mdi = $self->mdi;
115 my $interface = $self->mdi->Interface;
116 my $disp = $interface->{DISPLAYED};
117 my $undisp = $interface->{UNDISPLAYED};
118 for (@$disp, @$undisp) {
119 my ($t) = $mdi->docTitle($_);
120 $split->addPage($_,
121 -title => $t,
122 );
123 }
124 $self->{SPLIT} = $split;
125 my $sel = $mdi->docSelected;
126 $split->selectPage($sel);
127 }
128 return $split
129 }
130  
131 sub splitHorizontal {
132 my $self = shift;
133 $self->splitRemove;
134 my $w = $self->WorkSpace;
135 $w->gridColumnconfigure(2, -weight => 1);
136 my $i = $self->mdi->Interface;
137
138 my $a = $w->Adjuster(
139 -widget => $i,
140 -side => 'left'
141 )->grid(-row => 0, -column => 1, -sticky => 'ns');
142 $self->{ADJUSTER} = $a;
143  
144 my $s = $self->splitGet;
145 $s->grid(-row => 0, -column => 2, -sticky => 'nsew');
146 my $width = $w->width;
147 $i->GeometryRequest(int(($width)/2), $w->height);
148  
149 $self->{STATE} = 'horizontal';
150 }
151  
152 sub splitOpen {
153 my ($self, $name) = @_;
154 my $split = $self->{SPLIT};
155 return unless defined $split;
156 return if $name eq '';
157 my $plit = $self->split;
158 my ($t) = $self->mdi->docTitle($name);
159 $split->addPage($name,
160 -title => $t,
161 );
162 }
163  
164 sub splitRemove {
165 my $self = shift;
166 my $s = $self->{STATE};
167 return if $self->{STATE} eq 'none';
168 my $m = $self->{SPLIT};
169 $m->gridForget;
170 my $a = $self->{ADJUSTER};
171 $a->gridForget;
172 $a->destroy;
173 my $w = $self->WorkSpace;
174 $w->gridColumnconfigure(2, -weight => 0);
175 $w->gridRowconfigure(2, -weight => 0);
176 my $i = $self->mdi->Interface;
177 $w->gridColumnconfigure(0, -weight => 1);
178 $w->gridRowconfigure(0, -weight => 1);
179 $i->grid(-column => 0, -row => 0, -sticky => 'nsew');
180 }
181  
182 sub splitSelect {
183 my ($self, $name) = @_;
184 my $split = $self->split;
185 my $mdi = $self->mdi;
186 my $w;
187 unless (exists $self->{DOCS}->{$name}) {
188 my $page = $split->getPage($name);
189 my $man = $page->CodeTextManager(
190 -extension => $mdi,
191 )->pack(-expand => 1, -fill => 'both');
192 $w = $man->CWidg;
193 $w->configure('-readonly', 1);
194 $self->{DOCS}->{$name} = $w;
195 } else {
196 $w = $self->{DOCS}->{$name}
197 }
198 if ($mdi->deferredExists($name)) {
199 $w->load($name);
200 } else {
201 my $d = $mdi->docGet($name);
202 my $content = $d->get('1.0', 'end - 1c');
203 $w->delete('1.0', 'end');
204 $w->insert('end', $content);
205 $w->ResetRedo;
206 $w->ResetUndo;
207 $w->editModified(0);
208 $w->configure('-syntax', $d->CWidg->cget('-syntax'));
209 }
210 }
211  
212 sub splitVertical {
213 my $self = shift;
214 $self->splitRemove;
215 my $w = $self->WorkSpace;
216 $w->gridRowconfigure(2, -weight => 1);
217 my $i = $self->mdi->Interface;
218
219 my $a = $w->Adjuster(
220 -widget => $i,
221 -side => 'top'
222 )->grid(-row => 1, -column => 0, -sticky => 'ew');
223 $self->{ADJUSTER} = $a;
224  
225 my $s = $self->splitGet;
226 $s->grid(-row => 2, -column => 0, -sticky => 'nsew');
227 my $height = $w->height;
228 $i->GeometryRequest($w->width, int(($height)/2));
229  
230 $self->{STATE} = 'vertical';
231 }
232  
233  
234 sub Unload {
235 my $self = shift;
236
237 #destroy the split window
238 my $split = $self->split;
239 $split->destroy if defined $split;
240  
241 #unhook commands
242 $self->cmdUnhookAfter('doc_close', 'splitClose', $self);
243 $self->cmdUnhookAfter('doc_open', 'splitOpen', $self);
244  
245 #unload commands
246 for (qw/
247 split_horizontal
248 split_vertical
249 split_cancel
250 /) {
251 $self->cmdRemove($_);
252 }
253 return $self->SUPER::Unload
254 }
255  
256 =head1 LICENSE
257  
258 Same as Perl.
259  
260 =head1 AUTHOR
261  
262 Hans Jeuken (hanje at cpan dot org)
263  
264 =head1 TODO
265  
266 =over 4
267  
268 =back
269  
270 =head1 BUGS AND CAVEATS
271  
272 If you find any bugs, please report them here L<https://github.com/haje61/App-Codit/issues>.
273  
274 =head1 SEE ALSO
275  
276 =over 4
277  
278 =back
279  
280 =cut
281  
282  
283  
284 1;
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297