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