Codit/CoditTagsEditor.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 94 CC 9 SCAR 38.3
CC
9
Cov
0%
Populate
90.0
Apply
2.0
BEGIN
2.0
CRAP 46.0
1 package App::Codit::CoditTagsEditor;
2  
3 =head1 NAME
4  
5 App::Codit::CoditTagsEditor - Tags editor for the syntax highlight tags of Tk::CodeText
6  
7 =cut
8  
9 use strict;
10 use warnings;
11 use Carp;
12 use vars qw($VERSION);
13 $VERSION = '0.19';
14 use Tk;
15 use Tie::Watch;
16 require Tk::CodeText::TagsEditor;
17  
18 use base qw(Tk::Derived Tk::Frame);
19 Construct Tk::Widget 'CoditTagsEditor';
20  
21 sub Populate {
22 my ($self,$args) = @_;
23
24 my $dbackground = delete $args->{'-defaultbackground'};
25 die 'You must specify the -defaultbackground option' unless defined $dbackground;
26 my $dforeground = delete $args->{'-defaultforeground'};
27 die 'You must specify the -defaultforeground option' unless defined $dforeground;
28 my $dfont = delete $args->{'-defaultfont'};
29 die 'You must specify the -defaultfont option' unless defined $dfont;
30 my $ext = delete $args->{'-extension'};
31 die 'You must specify the -extension option' unless defined $ext;
32 my $hist = delete $args->{'-historyfile'};
33 die 'You must specify the -historyfile option' unless defined $hist;
34 my $themefile = delete $args->{'-themefile'};
35 die 'You must specify the -themefile option' unless defined $themefile;
36
37 $self->SUPER::Populate($args);
38 my $te = $self->TagsEditor(
39 -defaultbackground => $dbackground,
40 -defaultforeground => $dforeground,
41 -defaultfont => $dfont,
42 -historyfile => $hist,
43 )->pack(-expand => 1, -fill => 'both');
44 $self->Advertise(TE => $te);
45  
46 my $toolframe = $self->Frame(
47 )->pack(-fill => 'x');
48 $toolframe->Button(
49 -command => sub {
50 my ($file) = $ext->pickFileSave(
51 -loadfilter => '.ctt',
52 );
53 $te->save($file) if defined $file;
54 },
55 -text => 'Save',
56 )->pack(-side => 'left', -padx => 5, -pady => 5);
57 $toolframe->Button(
58 -text => 'Load',
59 -command => sub {
60 my ($file) = $ext->pickFileOpen(
61 -loadfilter => '.ctt',
62 );
63 if (defined $file) {
64 my $obj = Tk::CodeText::Theme->new;
65 $obj->load($file);
66 $te->put($obj->get);
67 $te->updateAll
68 }
69 },
70 )->pack(-side => 'left', -padx => 5, -pady => 5);
71  
72 $self->{THEMEFILE} = $themefile;
73  
74 $self->ConfigSpecs(
75 -applycall => ['CALLBACK', undef, undef, sub {}],
76 DEFAULT => [$te],
77 );
78  
79 $self->after(50, sub {
80 my $theme = Tk::CodeText::Theme->new;
81 $theme->load($themefile);
82 $te->put($theme->get)
83 });
84 }
85  
86 sub Apply {
87 my $self = shift;
88 my $te = $self->Subwidget('TE');
89 my $themefile = $self->{THEMEFILE};
90 $te->save($themefile);
91 $self->Callback('-applycall', $themefile);
92 }
93  
94 1;
95  
96  
97  
98  
99