Perl6/Preferences.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 84 CC 3 SCAR 14.2
CC
3
Cov
0%
_on_ok_button_clicked
12.0
BEGIN
2.0
new
2.0
CRAP 4.1
1 package Padre::Plugin::Perl6::Preferences;
2 BEGIN {
3 $Padre::Plugin::Perl6::Preferences::VERSION = '0.71';
4 }
5  
6 # ABSTRACT: Preferences Dialog
7  
8 use warnings;
9 use strict;
10  
11 use Class::XSAccessor accessors => {
12 _plugin => '_plugin', # plugin to be configured
13 _sizer => '_sizer', # window sizer
14 _colorizer_cb => '_colorizer_cb', # colorizer on/off checkbox
15 };
16  
17 use Padre::Current;
18 use Padre::Wx ();
19  
20 use base 'Wx::Dialog';
21  
22  
23 # -- constructor
24  
25 sub new {
26 my ( $class, $plugin ) = @_;
27  
28 # create object
29 my $self = $class->SUPER::new(
30 Padre::Current->main,
31 -1,
32 Wx::gettext('Perl 6 preferences'),
33 Wx::wxDefaultPosition,
34 Wx::wxDefaultSize,
35 Wx::wxDEFAULT_FRAME_STYLE | Wx::wxTAB_TRAVERSAL,
36 );
37 $self->_plugin($plugin);
38  
39 # create dialog
40 $self->_create;
41  
42 # Dialog's icon as is the same as plugin's
43 $self->SetIcon( $plugin->logo_icon );
44  
45 return $self;
46 }
47  
48  
49 # -- event handler
50  
51 #
52 # $self->_on_ok_button_clicked;
53 #
54 # handler called when the ok button has been clicked.
55 #
56 sub _on_ok_button_clicked {
57 my $self = shift;
58  
59 my $plugin = $self->_plugin;
60  
61 # read plugin preferences
62 my $prefs = $plugin->config;
63  
64 # update configuration
65 my $old_p6_highlight = $prefs->{p6_highlight};
66 my $old_colorizer = $prefs->{colorizer};
67 $prefs->{p6_highlight} = $self->_colorizer_cb->GetValue();
68  
69 # store plugin preferences
70 $plugin->config_write($prefs);
71  
72 if ( $old_p6_highlight != $prefs->{p6_highlight} || $old_colorizer ne $prefs->{colorizer} ) {
73  
74 # a configuration change for colorizer
75 if ( $prefs->{p6_highlight} ) {
76 $plugin->highlight;
77 }
78 }
79  
80 $self->Destroy;
81 }
82  
83  
84 # -- private methods
85  
86 #
87 # create the dialog itself.
88 #
89 sub _create {
90 my $self = shift;
91  
92 # create sizer that will host all controls
93 my $sizer = Wx::BoxSizer->new(Wx::wxVERTICAL);
94 $self->_sizer($sizer);
95  
96 # create the controls
97 $self->_create_controls;
98 $self->_create_buttons;
99  
100 # wrap everything in a vbox to add some padding
101 $self->SetSizerAndFit($sizer);
102 $sizer->SetSizeHints($self);
103 }
104  
105 #
106 # create the buttons pane.
107 #
108 sub _create_buttons {
109 my $self = shift;
110 my $sizer = $self->_sizer;
111  
112 my $butsizer = $self->CreateStdDialogButtonSizer( Wx::wxOK | Wx::wxCANCEL );
113 $sizer->Add( $butsizer, 0, Wx::wxALL | Wx::wxEXPAND | Wx::wxALIGN_CENTER, 5 );
114 Wx::Event::EVT_BUTTON( $self, Wx::wxID_OK, \&_on_ok_button_clicked );
115 }
116  
117 #
118 # create the pane to choose the various configuration parameters.
119 #
120 sub _create_controls {
121 my $self = shift;
122  
123 $self->_colorizer_cb( Wx::CheckBox->new( $self, -1, Wx::gettext('Enable coloring') ) );
124  
125 # Select based on configuration parameters
126 my $config = $self->_plugin->config;
127 $self->_colorizer_cb->SetValue( $config->{p6_highlight} );
128  
129 # pack the controls in a box
130 my $box;
131 $box = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
132 $box->Add( $self->_colorizer_cb, 1, Wx::wxALL | Wx::wxEXPAND | Wx::wxALIGN_CENTER, 5 );
133 $self->_sizer->Add( $box, 0, Wx::wxALL | Wx::wxEXPAND | Wx::wxALIGN_CENTER, 5 );
134  
135 }
136  
137  
138 1;
139  
140 __END__