Merge pull request #962 from scottp/issue_885b

Add defaults into Tooltips from #885
internal-support
Alessandro Ranellucci 2013-03-09 07:48:20 -08:00
commit a2702082b2
1 changed files with 14 additions and 3 deletions

View File

@ -157,6 +157,7 @@ sub _build_field {
$self->_triggers->{$opt_key} = $opt->{on_change} || sub {}; $self->_triggers->{$opt_key} = $opt->{on_change} || sub {};
my $field; my $field;
my $tooltip = $opt->{tooltip};
if ($opt->{type} =~ /^(i|f|s|s@)$/) { if ($opt->{type} =~ /^(i|f|s|s@)$/) {
my $style = 0; my $style = 0;
$style = wxTE_MULTILINE if $opt->{multiline}; $style = wxTE_MULTILINE if $opt->{multiline};
@ -172,11 +173,13 @@ sub _build_field {
$opt->{type} eq 'i' $opt->{type} eq 'i'
? EVT_SPINCTRL ($self->parent, $field, $on_change) ? EVT_SPINCTRL ($self->parent, $field, $on_change)
: EVT_TEXT ($self->parent, $field, $on_change); : EVT_TEXT ($self->parent, $field, $on_change);
$tooltip .= " (default: " . $opt->{default} . ")" if ($opt->{default});
} elsif ($opt->{type} eq 'bool') { } elsif ($opt->{type} eq 'bool') {
$field = Wx::CheckBox->new($self->parent, -1, ""); $field = Wx::CheckBox->new($self->parent, -1, "");
$field->SetValue($opt->{default}); $field->SetValue($opt->{default});
EVT_CHECKBOX($self->parent, $field, sub { $self->_on_change($opt_key, $field->GetValue); }); EVT_CHECKBOX($self->parent, $field, sub { $self->_on_change($opt_key, $field->GetValue); });
$self->_setters->{$opt_key} = sub { $field->SetValue($_[0]) }; $self->_setters->{$opt_key} = sub { $field->SetValue($_[0]) };
$tooltip .= " (default: " . ($opt->{default} ? 'yes' : 'no') . ")" if defined($opt->{default});
} elsif ($opt->{type} eq 'point') { } elsif ($opt->{type} eq 'point') {
$field = Wx::BoxSizer->new(wxHORIZONTAL); $field = Wx::BoxSizer->new(wxHORIZONTAL);
my $field_size = Wx::Size->new(40, -1); my $field_size = Wx::Size->new(40, -1);
@ -187,8 +190,10 @@ sub _build_field {
my $y_field = Wx::TextCtrl->new($self->parent, -1, $opt->{default}->[1], wxDefaultPosition, $field_size), my $y_field = Wx::TextCtrl->new($self->parent, -1, $opt->{default}->[1], wxDefaultPosition, $field_size),
); );
$field->Add($_, 0, wxALIGN_CENTER_VERTICAL, 0) for @items; $field->Add($_, 0, wxALIGN_CENTER_VERTICAL, 0) for @items;
if ($opt->{tooltip}) { if ($tooltip) {
$_->SetToolTipString($opt->{tooltip}) for @items; $_->SetToolTipString(
$tooltip . " (default: " . join(",", @{$opt->{default}}) . ")"
) for @items;
} }
EVT_TEXT($self->parent, $_, sub { $self->_on_change($opt_key, [ $x_field->GetValue, $y_field->GetValue ]) }) EVT_TEXT($self->parent, $_, sub { $self->_on_change($opt_key, [ $x_field->GetValue, $y_field->GetValue ]) })
for $x_field, $y_field; for $x_field, $y_field;
@ -205,10 +210,16 @@ sub _build_field {
$field->SetSelection(grep $opt->{values}[$_] eq $_[0], 0..$#{$opt->{values}}); $field->SetSelection(grep $opt->{values}[$_] eq $_[0], 0..$#{$opt->{values}});
}; };
$self->_setters->{$opt_key}->($opt->{default}); $self->_setters->{$opt_key}->($opt->{default});
$tooltip .= " (default: "
. $opt->{labels}[ first { $opt->{values}[$_] eq $opt->{default} } 0..$#{$opt->{values}} ]
. ")" if ($opt->{default});
} else { } else {
die "Unsupported option type: " . $opt->{type}; die "Unsupported option type: " . $opt->{type};
} }
$field->SetToolTipString($opt->{tooltip}) if $opt->{tooltip} && $field->can('SetToolTipString'); if ($tooltip && $field->can('SetToolTipString')) {
$field->SetToolTipString($tooltip);
}
return $field; return $field;
} }