aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ManaTools
diff options
context:
space:
mode:
authorMaarten Vanraes <alien@mageia.org>2016-01-09 15:26:33 +0100
committerMaarten Vanraes <alien@mageia.org>2016-01-09 15:26:33 +0100
commit1eb1c89cc43ccb16fdc3369851cf828329831147 (patch)
tree02a8f1053bed0f9a17e19c456a2ea3259c26062c /lib/ManaTools
parentc16d101649c18667ae3f47409c0a14fe3347dd60 (diff)
downloadmanatools-1eb1c89cc43ccb16fdc3369851cf828329831147.tar
manatools-1eb1c89cc43ccb16fdc3369851cf828329831147.tar.gz
manatools-1eb1c89cc43ccb16fdc3369851cf828329831147.tar.bz2
manatools-1eb1c89cc43ccb16fdc3369851cf828329831147.tar.xz
manatools-1eb1c89cc43ccb16fdc3369851cf828329831147.zip
Allow child EventHandlers
Diffstat (limited to 'lib/ManaTools')
-rw-r--r--lib/ManaTools/Shared/GUI/EventHandlerRole.pm74
1 files changed, 73 insertions, 1 deletions
diff --git a/lib/ManaTools/Shared/GUI/EventHandlerRole.pm b/lib/ManaTools/Shared/GUI/EventHandlerRole.pm
index 532ca3b5..e01f5c89 100644
--- a/lib/ManaTools/Shared/GUI/EventHandlerRole.pm
+++ b/lib/ManaTools/Shared/GUI/EventHandlerRole.pm
@@ -65,6 +65,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
use Moose::Role;
+has 'eventHandlers' => (
+ is => 'ro',
+ isa => 'ArrayRef[ManaTools::Shared::GUI::EventHandlerRole]',
+ init_arg => undef,
+ default => sub {
+ return [];
+ }
+);
+
has 'events' => (
is => 'ro',
isa => 'HashRef[ManaTools::Shared::GUI::EventRole]',
@@ -75,6 +84,60 @@ has 'events' => (
#=============================================================
+=head2 addEventHandler
+
+=head3 INPUT
+
+ $self: this object
+ $eventHandler: an EventHandlerRole to be added
+
+=head3 DESCRIPTION
+
+ add an EventHandler to the events list
+
+=cut
+
+#=============================================================
+sub addEventHandler {
+ my $self = shift;
+ my $eventHandler = shift;
+ my $eventHandlers = $self->eventHandlers();
+ push @{$eventHandlers}, $eventHandler;
+}
+
+#=============================================================
+
+=head2 delEventHandler
+
+=head3 INPUT
+
+ $self: this object
+ $eventHandler: an EventHandlerRole to be removed
+
+=head3 DESCRIPTION
+
+ del an eventHandler from the events list
+
+=cut
+
+#=============================================================
+sub delEventHandler {
+ my $self = shift;
+ my $eventHandler = shift;
+ my $eventHandlers = $self->eventHandlers();
+ my $i = scalar(@{$eventHandlers});
+ while ($i > 0) {
+ $i = $i - 1;
+ if ($eventHandlers->[$i] == $eventHandler) {
+ # splice the eventHandler out of it
+ splice @{$eventHandlers}, $i, 1;
+ return ;
+ }
+ }
+}
+
+#=============================================================
+
=head2 addEvent
=head3 INPUT
@@ -463,12 +526,21 @@ sub findItem {
sub processEvents {
my $self = shift;
my $yevent = shift;
- my $events = $self->events();
+
+ # first check the other eventHandlers
+ my $eventHandlers = $self->eventHandlers();
+ for my $eventHandler (@{$eventHandlers}) {
+ my $processed = $eventHandler->processEvents($yevent);
+ return $processed if $processed >= 0;
+ }
+
# loop all the items
+ my $events = $self->events();
for my $event (values %{$events}) {
my $processed = $event->processEvent($yevent);
return $processed if $processed >= 0;
}
+
return 1;
}