« blib/lib/Gapp/Meta/Widget/Native/Trait/AssistantPage.pm
↑ Summary
blib/lib/Gapp/CheckMenuItem.pm »
| 1 | package Gapp::ToggleToolButton; | ||
| 2 | { | ||
| 3 | $Gapp::ToggleToolButton::VERSION = '0.60'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use MooseX::SemiAffordanceAccessor; | ||
| 8 | extends 'Gapp::ToolButton'; | ||
| 9 | |||
| 10 | with 'Gapp::Meta::Widget::Native::Role::FormField'; | ||
| 11 | |||
| 12 | has '+gclass' => ( | ||
| 13 | default => 'Gtk2::ToggleToolButton', | ||
| 14 | ); | ||
| 15 | |||
| 16 | has 'value' => ( | ||
| 17 | is => 'rw', | ||
| 18 | isa => 'Str', | ||
| 19 | default => '1', | ||
| 20 | ); | ||
| 21 | |||
| 22 | |||
| 23 | sub BUILDARGS { | ||
| 24 | my $class = shift; | ||
| 25 | my %args = @_ == 1 && is_HashRef( $_[0] ) ? %{$_[0]} : @_; | ||
| 26 | |||
| 27 | if ( exists $args{active} ) { | ||
| 28 | $args{properties}{active} = delete $args{active}; | ||
| 29 | } | ||
| 30 | |||
| 31 | __PACKAGE__->SUPER::BUILDARGS( %args ); | ||
| 32 | } | ||
| 33 | |||
| 34 | sub get_field_value { | ||
| 35 | my $self = shift; | ||
| 36 | my $state = $self->gobject->get_active; | ||
| 37 | if ( $state ) { | ||
| 38 | return $self->value; | ||
| 39 | } | ||
| 40 | else { | ||
| 41 | return undef; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | sub set_field_value { | ||
| 46 | my ( $self, $value ) = @_; | ||
| 47 | if ( defined $value && $value eq $self->value ) { | ||
| 48 | $self->gobject->set_active( 1 ) | ||
| 49 | } | ||
| 50 | else { | ||
| 51 | $self->gobject->set_active( 0 ) | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | sub widget_to_stash { | ||
| 56 | my ( $self, $stash ) = @_; | ||
| 57 | $stash->store( $self->field, $self->get_field_value ); | ||
| 58 | } | ||
| 59 | |||
| 60 | sub stash_to_widget { | ||
| 61 | my ( $self, $stash ) = @_; | ||
| 62 | $self->set_field_value( $stash->fetch( $self->field ) ); | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | |||
| 68 | 1; | ||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | __END__ |