| 1 | package Gapp::RadioMenuItem; | ||
| 2 | { | ||
| 3 | $Gapp::RadioMenuItem::VERSION = '0.60'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use MooseX::StrictConstructor; | ||
| 8 | use MooseX::SemiAffordanceAccessor; | ||
| 9 | |||
| 10 | extends 'Gapp::CheckMenuItem'; | ||
| 11 | with 'Gapp::Meta::Widget::Native::Role::FormField'; | ||
| 12 | |||
| 13 | has '+gclass' => ( | ||
| 14 | default => 'Gtk2::RadioMenuItem', | ||
| 15 | ); | ||
| 16 | |||
| 17 | has 'value' => ( | ||
| 18 | is => 'rw', | ||
| 19 | isa => 'Str', | ||
| 20 | default => '1', | ||
| 21 | ); | ||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | # create and set the actual gobject | ||
| 26 | sub _construct_gobject { | ||
| 27 | my ( $self ) = @_; | ||
| 28 | |||
| 29 | my $gtk_class = $self->gclass; | ||
| 30 | my $gtk_constructor = $self->constructor; | ||
| 31 | |||
| 32 | # determine the radio group | ||
| 33 | my $group = $self->field && $self->parent ? | ||
| 34 | $self->parent->{_rdo_groups}{ $self->field } : | ||
| 35 | undef; | ||
| 36 | |||
| 37 | # use any build-arguments if they exist | ||
| 38 | my $w = $gtk_class->$gtk_constructor( $group, $self->args ? @{$self->args} : ( ) ); | ||
| 39 | $self->set_gobject( $w ); | ||
| 40 | |||
| 41 | # save the radio group in the parent | ||
| 42 | if ( $self->parent ) { | ||
| 43 | $self->parent->{_rdo_groups}{ $self->field } ||= $w->get_group; | ||
| 44 | } | ||
| 45 | |||
| 46 | return $w; | ||
| 47 | } | ||
| 48 | |||
| 49 | sub get_field_value { | ||
| 50 | my $self = shift; | ||
| 51 | my $state = $self->gobject->get_active; | ||
| 52 | if ( $state ) { | ||
| 53 | return $self->value; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | sub widget_to_stash { | ||
| 58 | my ( $self, $stash ) = @_; | ||
| 59 | my $state = $self->gobject->get_active; | ||
| 60 | if ( $state ) { | ||
| 61 | $stash->store( $self->field, $self->get_field_value ); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | sub stash_to_widget { | ||
| 66 | my ( $self, $stash ) = @_; | ||
| 67 | $self->set_field_value( $stash->fetch( $self->field ) ); | ||
| 68 | } | ||
| 69 | |||
| 70 | #sub _connect_changed_handler { | ||
| 71 | # my ( $self ) = @_; | ||
| 72 | # | ||
| 73 | # $self->gobject->signal_connect ( | ||
| 74 | # released => sub { $self->_widget_value_changed; } | ||
| 75 | # ); | ||
| 76 | #} | ||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | 1; | ||
| 86 | |||
| 87 | |||
| 88 | __END__ |