package Gapp::Action; use Moose; with 'MooseX::Clone'; use MooseX::SemiAffordanceAccessor; use MooseX::StrictConstructor; use MooseX::Types::Moose qw( CodeRef HashRef Object Str ); has 'code' => ( is => 'rw', isa => 'Maybe[CodeRef]', clearer => 'clear_code', predicate => 'has_code', ); has 'icon' => ( is => 'rw', isa => 'Maybe[Str]', clearer => 'clear_icon', predicate => 'has_icon', ); has [qw( label name mnemonic accelerator )] => ( is => 'rw', isa => 'Maybe[Str]', default => '', ); has 'tooltip' => ( is => 'rw', isa => 'Maybe[Str]', clearer => 'clear_tooltip', predicate => 'has_tooltip', ); sub create_gtk_action { my ( $self, @args ) = @_; my %opts = ( name => $self->name, label => $self->label, tooltip => $self->tooltip, icon => $self->icon, args => [], @args ); if ( $opts{icon} ) { $opts{'stock-id'} = $opts{icon}; } delete $opts{icon}; my $args = delete $opts{args}; my $gtk_action = Gtk2::Action->new( %opts ); $gtk_action->signal_connect( activate => sub { my ( $w, @gtkargs ) = @_; $self->perform( $self, $args, $w, \@gtkargs ); }); return $gtk_action; } sub create_gapp_image { my ( $self, @args ) = @_; Gapp::Image->new( gobject => Gtk2::Image->new_from_stock( $self->icon , $args[0] ) ); } sub create_gtk_image { my ( $self, @args ) = @_; Gtk2::Image->new_from_stock( $self->icon , $args[0] ); } sub perform { my ( $self, @args ) = @_; return $self->code->( $self, @args ) if $self->has_code; } 1; __END__ =pod =head1 NAME Gapp::Action - Action object =head1 DESCRIPTION Actions are callbacks that know how to display themselves on Gapp widgets. See L for more information. =head1 OBJECT HIERARCHY =over 4 =item L =back =head1 PROVIDED ATTRIBUTES =over 4 =item B =over 4 =item is rw =item isa CodeRef =back The code-block to be executed. =item B =over 4 =item is rw =item isa Str =back The stock id of the icon to apply to the widget. =item B