10
use Padre::Constant ();
11
our $VERSION = '0.92';
13
our $VERSION = '0.94';
15
17
my $config = shift;
17
# Iterate over the specified config elements
18
19
foreach my $name (@_) {
19
next unless $self->can($name);
21
# Get the Wx element for this option
22
my $setting = $config->meta($name);
23
my $value = $config->$name();
24
my $ctrl = $self->$name();
26
# Apply this one setting to this one widget
27
if ( $ctrl->can('config_load') ) {
28
# Allow specialised widgets to load their own setting
29
$ctrl->config_load( $setting, $value );
31
} elsif ( $ctrl->isa('Wx::CheckBox') ) {
32
$ctrl->SetValue($value);
34
} elsif ( $ctrl->isa('Wx::TextCtrl') ) {
35
$ctrl->SetValue($value);
37
} elsif ( $ctrl->isa('Wx::SpinCtrl') ) {
38
$ctrl->SetValue($value);
40
} elsif ( $ctrl->isa('Wx::FilePickerCtrl') ) {
41
$ctrl->SetPath($value);
43
} elsif ( $ctrl->isa('Wx::DirPickerCtrl') ) {
44
$ctrl->SetPath($value);
46
} elsif ( $ctrl->isa('Wx::ColourPickerCtrl') ) {
48
Padre::Wx::color($value)
51
} elsif ( $ctrl->isa('Wx::FontPickerCtrl') ) {
52
my $font = Padre::Wx::native_font($value);
53
$ctrl->SetSelectedFont( $font ) if $font->IsOk;
55
} elsif ( $ctrl->isa('Wx::Choice') ) {
56
my $options = $setting->options;
60
# NOTE: This assumes that the list will not be
61
# sorted in Wx via a style flag and that the
62
# order of the fields should be that of the key
63
# and not of the translated label.
64
# Doing sort in Wx will probably break this.
65
foreach my $option ( sort keys %$options ) {
66
my $label = $options->{$option};
71
next unless $option eq $value;
72
$ctrl->SetSelection( $ctrl->GetCount - 1 );
20
my $meta = $config->meta($name);
21
my $value = $config->$name();
22
$self->config_set( $meta => $value );
32
my $name = $meta->name;
34
# Ignore config elements we don't have
35
unless ( $self->can($name) ) {
39
# Apply to the relevant element
40
my $ctrl = $self->$name();
41
if ( $ctrl->can('config_set') ) {
42
# Allow specialised widgets to load their own setting
43
$ctrl->config_set( $meta, $value );
45
} elsif ( $ctrl->isa('Wx::CheckBox') ) {
46
$ctrl->SetValue($value);
48
} elsif ( $ctrl->isa('Wx::TextCtrl') ) {
49
$ctrl->SetValue($value);
51
} elsif ( $ctrl->isa('Wx::SpinCtrl') ) {
52
$ctrl->SetValue($value);
54
} elsif ( $ctrl->isa('Wx::FilePickerCtrl') ) {
55
$ctrl->SetPath($value);
57
} elsif ( $ctrl->isa('Wx::DirPickerCtrl') ) {
58
$ctrl->SetPath($value);
60
} elsif ( $ctrl->isa('Wx::ColourPickerCtrl') ) {
62
Padre::Wx::color($value)
65
} elsif ( $ctrl->isa('Wx::FontPickerCtrl') ) {
66
my $font = Padre::Wx::native_font($value);
67
$ctrl->SetSelectedFont($font) if $font->IsOk;
69
} elsif ( $ctrl->isa('Wx::Choice') ) {
70
my $options = $meta->options;
74
# NOTE: This assumes that the list will not be
75
# sorted in Wx via a style flag and that the
76
# order of the fields should be that of the key
77
# and not of the translated label.
78
# Doing sort in Wx will probably break this.
79
foreach my $option ( sort keys %$options ) {
80
my $label = $options->{$option};
85
next unless $option eq $value;
86
$ctrl->SetSelection( $ctrl->GetCount - 1 );
111
120
foreach my $name (@_) {
112
next unless $self->can($name);
114
# Get the Wx element for this option
115
my $setting = $config->meta($name);
116
my $old = $config->$name();
117
my $ctrl = $self->$name();
119
# Don't capture options that are not shown,
120
# as this may result in falsely clearing them.
121
next unless $ctrl->IsEnabled;
123
# Extract the value from the control
125
if ( $ctrl->isa('Wx::CheckBox') ) {
126
$value = $ctrl->GetValue ? 1 : 0;
128
} elsif ( $ctrl->isa('Wx::TextCtrl') ) {
129
$value = $ctrl->GetValue;
131
} elsif ( $ctrl->isa('Wx::SpinCtrl') ) {
132
$value = $ctrl->GetValue;
134
} elsif ( $ctrl->isa('Wx::FilePickerCtrl') ) {
135
$value = $ctrl->GetPath;
137
} elsif ( $ctrl->isa('Wx::DirPickerCtrl') ) {
138
$value = $ctrl->GetPath;
140
} elsif ( $ctrl->isa('Wx::ColourPickerCtrl') ) {
141
$value = $ctrl->GetColour->GetAsString(Wx::C2S_HTML_SYNTAX);
142
$value =~ s/^#// if defined $value;
144
} elsif ( $ctrl->isa('Wx::FontPickerCtrl') ) {
145
$value = $ctrl->GetSelectedFont->GetNativeFontInfoUserDesc;
147
} elsif ( $ctrl->isa('Wx::Choice') ) {
148
my $options = $setting->options;
150
my @k = sort keys %$options;
151
my $i = $ctrl->GetSelection;
121
my $meta = $config->meta($name);
123
# Can we get a value from the control
124
my $new = $self->config_get($meta);
125
next unless defined $new;
127
# Change the setting if different
128
unless ( $new eq $config->$name() ) {
160
next unless defined $value;
161
next if $value eq $old;
162
$diff{$name} = $value;
165
133
return unless %diff;
140
my $name = $meta->name;
142
# Ignore config elements we don't have
143
unless ( $self->can($name) ) {
147
# Ignore controls that are disabled
148
my $ctrl = $self->$name();
149
unless ( $ctrl->IsEnabled ) {
153
# Extract the value from the control
155
if ( $ctrl->isa('Wx::CheckBox') ) {
156
$value = $ctrl->GetValue ? 1 : 0;
158
} elsif ( $ctrl->isa('Wx::TextCtrl') ) {
159
$value = $ctrl->GetValue;
161
} elsif ( $ctrl->isa('Wx::SpinCtrl') ) {
162
$value = $ctrl->GetValue;
164
} elsif ( $ctrl->isa('Wx::FilePickerCtrl') ) {
165
$value = $ctrl->GetPath;
167
} elsif ( $ctrl->isa('Wx::DirPickerCtrl') ) {
168
$value = $ctrl->GetPath;
170
} elsif ( $ctrl->isa('Wx::ColourPickerCtrl') ) {
171
$value = $ctrl->GetColour->GetAsString(Wx::C2S_HTML_SYNTAX);
172
$value =~ s/^#// if defined $value;
174
} elsif ( $ctrl->isa('Wx::FontPickerCtrl') ) {
175
$value = $ctrl->GetSelectedFont->GetNativeFontInfoUserDesc;
177
} elsif ( $ctrl->isa('Wx::Choice') ) {
178
my $options = $meta->options;
180
my @k = sort keys %$options;
181
my $i = $ctrl->GetSelection;
185
unless ( defined $value ) {
189
# For various strictly formatted configuration values,
190
# attempt to determine a clean version.
191
my $type = $meta->type;
192
if ( $type == Padre::Constant::POSINT ) {
193
$value =~ s/[^0-9]//g;
195
if ( Params::Util::_POSINT($value) ) {
199
# Fall back to the setting default
200
return $meta->default;
203
# Implement cleaning for many more data types
171
# Copyright 2008-2011 The Padre development team as listed in Padre.pm.
212
# Copyright 2008-2012 The Padre development team as listed in Padre.pm.
173
214
# This program is free software; you can redistribute it and/or
174
215
# modify it under the same terms as Perl 5 itself.