| 1 | package Gapp::FileChooserButton; | ||
| 2 | { | ||
| 3 | $Gapp::FileChooserButton::VERSION = '0.60'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use Moose; | ||
| 7 | |||
| 8 | extends 'Gapp::Widget'; | ||
| 9 | with 'Gapp::Meta::Widget::Native::Role::FormField'; | ||
| 10 | with 'Gapp::Meta::Widget::Native::Role::FileChooser'; | ||
| 11 | |||
| 12 | has '+gclass' => ( | ||
| 13 | default => 'Gtk2::FileChooserButton', | ||
| 14 | ); | ||
| 15 | |||
| 16 | |||
| 17 | before '_build_gobject' => sub { | ||
| 18 | my $self = shift; | ||
| 19 | $self->set_args( [ $self->properties->{title} ? $self->properties->{title} : '' , $self->action ] ); | ||
| 20 | }; | ||
| 21 | |||
| 22 | |||
| 23 | # returns the value of the widget | ||
| 24 | sub get_field_value { | ||
| 25 | $_[0]->gobject->get_filename; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub set_field_value { | ||
| 29 | my ( $self, $value ) = @_; | ||
| 30 | $self->gobject->set_filename( defined $value ? $value : '' ); | ||
| 31 | } | ||
| 32 | |||
| 33 | sub widget_to_stash { | ||
| 34 | my ( $self, $stash ) = @_; | ||
| 35 | $stash->store( $self->field, $self->get_field_value ); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub stash_to_widget { | ||
| 39 | my ( $self, $stash ) = @_; | ||
| 40 | $self->set_field_value( $stash->fetch( $self->field ) ); | ||
| 41 | } | ||
| 42 | |||
| 43 | sub _connect_changed_handler { | ||
| 44 | my ( $self ) = @_; | ||
| 45 | |||
| 46 | $self->gobject->signal_connect ( | ||
| 47 | file_set => sub { $self->_widget_value_changed }, | ||
| 48 | ); | ||
| 49 | } | ||
| 50 | |||
| 51 | |||
| 52 | 1; | ||
| 53 | |||
| 54 | __END__ |