aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ManaTools/Shared/GUI/EventRole.pm
diff options
context:
space:
mode:
authorMaarten Vanraes <alien@mageia.org>2016-02-13 11:33:34 +0100
committerMaarten Vanraes <alien@mageia.org>2016-02-13 11:37:12 +0100
commit6c432030a01d6ae0e12b1027eb7e0c84b6c90f3a (patch)
tree7315dda5d1f3e46c214981a5a83cef1fb12b29b6 /lib/ManaTools/Shared/GUI/EventRole.pm
parentcbcb723c55b0ed48f2ed837486d0b3cf2d3252f3 (diff)
downloadmanatools-6c432030a01d6ae0e12b1027eb7e0c84b6c90f3a.tar
manatools-6c432030a01d6ae0e12b1027eb7e0c84b6c90f3a.tar.gz
manatools-6c432030a01d6ae0e12b1027eb7e0c84b6c90f3a.tar.bz2
manatools-6c432030a01d6ae0e12b1027eb7e0c84b6c90f3a.tar.xz
manatools-6c432030a01d6ae0e12b1027eb7e0c84b6c90f3a.zip
optional name for widgets, items, events
the name will now be autogenerated depending on a basename that each EventRole needs to implement, with a numeric suffix increasing in number, it checks this in the already present eventHandler.
Diffstat (limited to 'lib/ManaTools/Shared/GUI/EventRole.pm')
-rw-r--r--lib/ManaTools/Shared/GUI/EventRole.pm47
1 files changed, 44 insertions, 3 deletions
diff --git a/lib/ManaTools/Shared/GUI/EventRole.pm b/lib/ManaTools/Shared/GUI/EventRole.pm
index 6688b582..e8dd2489 100644
--- a/lib/ManaTools/Shared/GUI/EventRole.pm
+++ b/lib/ManaTools/Shared/GUI/EventRole.pm
@@ -70,6 +70,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
use Moose::Role;
requires 'processEvent';
+requires 'basename';
has 'eventHandler' => (
is => 'ro',
@@ -79,11 +80,51 @@ has 'eventHandler' => (
);
has 'name' => (
- is => 'ro',
- isa => 'Str',
- required => 1,
+ is => 'rw',
+ isa => 'Maybe[Str]',
+ lazy => 1,
+ default => undef,
);
+around 'name' => sub {
+ my $orig = shift;
+ my $self = shift;
+ my $name = undef;
+ my $setting = 0;
+
+ # set name if requested
+ if (scalar(@_) > 0) {
+ $name = shift;
+ $setting = 1;
+ }
+ else {
+ $name = $self->$orig();
+ $setting = 1 if (!defined $name);
+ }
+
+ # return the current name
+ # if it's undef, we need to change this...
+ if (!defined $name) {
+ # generate a unique Event name
+ $name = $self->uniqueName($self->eventHandler());
+ }
+
+ # set the name if we were setting it
+ $name = $self->$orig($name) if ($setting);
+ return $name;
+};
+
+sub uniqueName {
+ my $self = shift;
+ my $eventHandler = shift;
+ my $name = $self->basename();
+ my $i = 1;
+ while ($eventHandler->hasEvent($name . $i)) {
+ $i = $i + 1;
+ }
+ return $name;
+}
+
has 'eventType' => (
is => 'ro',
isa => 'Int',