Codit/CodeTextManager.pm untested

filter: Statementstmt 0.0% 0 / 121 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 200 CC 14 SCAR 34.2
CC
14
Cov
0%
configureTags
90.0
log
30.0
Name
6.0
CRAP 30.5
1 package App::Codit::CodeTextManager;
2  
3 =head1 NAME
4  
5 App::Codit::CodeTextManaer - Content manager for App::Codit
6  
7 =cut
8  
9 use strict;
10 use warnings;
11 use Carp;
12 use vars qw($VERSION);
13 $VERSION = '0.21';
14 use Tk;
15 require Tk::CodeText;
16  
17 use base qw(Tk::Derived Tk::AppWindow::BaseClasses::ContentManager);
18 Construct Tk::Widget 'CodeTextManager';
19  
20 sub Populate {
21 my ($self,$args) = @_;
22  
23 $self->SUPER::Populate($args);
24 my $ext = $self->Extension;
25  
26 my $text = $self->CodeText(
27 -contextmenu => $ext->ContextMenu,
28 -height => 8,
29 -keyreleasecall => ['KeyReleased', $self],
30 -logcall => ['log', $self],
31 -modifiedcall => ['Modified', $self],
32 -saveimage => $ext->getArt('document-save', 16),
33 -scrollbars => 'osoe',
34 -width => 8,
35 )->pack(-expand => 1, -fill => 'both');
36 $self->CWidg($text);
37 my $xt = $text->Subwidget('XText');
38 $xt->bind('<Control-f>', sub { $ext->cmdExecute('doc_find') });
39 $xt->bind('<Control-r>', sub { $ext->cmdExecute('doc_replace') });
40 $self->{NAME} = '';
41  
42 $self->ConfigSpecs(
43 -contentacpopsize => [{-acpopsize => $xt}],
44 -contentacscansize => [{-acscansize => $xt}],
45 -contentactivedelay => [{-activedelay => $xt}],
46 -contentautobrackets => [{-autobrackets => $xt}],
47 -contentautocomplete => [{-autocomplete => $xt}],
48 -contentautoindent => [{-autoindent => $xt}],
49 -contentbackground => [{-background => $xt}],
50 -contentbgdspace => [{-spacebackground => $text}],
51 -contentbgdtab => [{-tabbackground => $text}],
52 -contentbookmarkcolor => [{-bookmarkcolor => $text}],
53 -contentfindbg => ['PASSIVE'],
54 -contentfindfg => ['PASSIVE'],
55 -contentmatchbg => ['PASSIVE'],
56 -contentmatchfg => ['PASSIVE'],
57 -contentforeground => [{-foreground => $xt}],
58 # -contentfont => [{-font => $xt}],
59 -contentfontfamily => ['PASSIVE'],
60 -contentfontsize => ['PASSIVE'],
61 -contentindent => [{-indentstyle => $xt}],
62 -contentposition => [{-position => $text}],
63 -contentshowspaces => [{-showspaces => $text}],
64 -contentsyntax => [{-syntax => $text}],
65 -contenttabs => [{-tabs => $xt}],
66 -contentwrap => [{-wrap => $xt}],
67 -showfolds => [$text],
68 -shownumbers => [$text],
69 -showstatus => [$text],
70 -highlight_themefile => [{ -themefile => $text}],
71 DEFAULT => [$text],
72 );
73 $self->Delegates(
74 DEFAULT => $text,
75 );
76 $self->after(10, ['configureTags', $self]);
77 }
78  
79 sub Close {
80 my $self = shift;
81 $self->doClear;
82 return 1;
83 }
84  
85 sub configureTags {
86 my $self = shift;
87 my $widg = $self->CWidg;
88  
89 #configuring the find options
90 my @findoptions = ();
91 my $fbg = $self->cget('-contentfindbg');
92 push @findoptions, '-background', $fbg if (defined $fbg) and ($fbg ne '');
93 my $ffg = $self->cget('-contentfindfg');
94 push @findoptions, '-foreground', $ffg if (defined $ffg) and ($ffg ne '');
95 $widg->configure('-findoptions', \@findoptions) if @findoptions;
96
97 #configuring the match options
98 my @matchoptions = ();
99 my $mbg = $self->cget('-contentmatchbg');
100 push @matchoptions, '-background', $mbg if (defined $mbg) and ($mbg ne '');
101 my $mfg = $self->cget('-contentmatchfg');
102 push @matchoptions, '-foreground', $mfg if (defined $mfg) and ($mfg ne '');;
103 $widg->configure('-matchoptions', \@matchoptions) if @matchoptions;
104
105 #configuring insert background
106 $widg->configure('-insertbackground', $widg->cget('-foreground'));
107
108 #configuring font
109 my $xt = $widg->Subwidget('XText');
110 my $fam = $self->cget('-contentfontfamily');
111 $fam = 'Courier' unless defined $fam;
112 my $siz = $self->cget('-contentfontsize');
113 $siz = 10 unless defined $siz;
114 $widg->configure(-font => "{$fam} $siz");
115  
116 #configuring showspaces. Hack, do not know why this is needed.
117 $widg->configure(-showspaces => $self->Extension->configGet('-contentshowspaces'));
118 }
119  
120 sub doClear {
121 $_[0]->CWidg->clear
122 }
123  
124 sub doExport {
125 my ($self, $file) = @_;
126 return $self->CWidg->exportSave($file);
127 }
128  
129 sub doLoad {
130 my ($self, $file) = @_;
131 $self->Name($file);
132 return $self->CWidg->load($file);
133 }
134  
135 sub doSave {
136 my ($self, $file) = @_;
137 $self->Name($file);
138 return $self->CWidg->save($file);
139 }
140  
141 sub doSelect {
142 $_[0]->CWidg->focus
143 }
144  
145 sub KeyReleased {
146 my ($self, $key) = @_;
147 $self->Extension->cmdExecute('key_released', $self->Name, $key);
148 $self->CWidg->Subwidget('XText')->matchCheck;
149 }
150  
151 sub log {
152 my ($self, $message, $type) = @_;
153 $self->after(20, sub {
154 $type = 'message' unless defined $type;
155 my $ext = $self->Extension;
156 if ($type eq 'message') {
157 $ext->log($message)
158 } elsif ($type eq 'error') {
159 $ext->logError($message)
160 } elsif ($type eq 'warning') {
161 $ext->logWarning($message)
162 }
163 });
164 }
165  
166 sub Modified {
167 my ($self, $index) = @_;
168 $self->Extension->cmdExecute('modified', $self->Name, $index);
169 }
170  
171 sub Name {
172 my $self = shift;
173 $self->{NAME} = shift if @_;
174 return $self->{NAME}
175 }
176  
177 sub IsModified {
178 return $_[0]->CWidg->Subwidget('XText')->editModified;
179 }
180  
181 =head1 LICENSE
182  
183 Same as Perl.
184  
185 =head1 AUTHOR
186  
187 Hans Jeuken (hanje at cpan dot org)
188  
189 =head1 TODO
190  
191 =over 4
192  
193 =back
194  
195 =head1 BUGS AND CAVEATS
196  
197 If you find any bugs, please report them here L<https://github.com/haje61/App-Codit/issues>.
198  
199 =head1 SEE ALSO
200  
201 =over 4
202  
203 =back
204  
205 =cut
206  
207 1;
208  
209  
210  
211  
212  
213