aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ManaTools
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ManaTools')
-rw-r--r--lib/ManaTools/Shared/GUI/Event.pm6
-rw-r--r--lib/ManaTools/Shared/GUI/EventHandlerRole.pm4
-rw-r--r--lib/ManaTools/Shared/GUI/EventRole.pm47
-rw-r--r--lib/ManaTools/Shared/GUI/ExtTab.pm6
4 files changed, 58 insertions, 5 deletions
diff --git a/lib/ManaTools/Shared/GUI/Event.pm b/lib/ManaTools/Shared/GUI/Event.pm
index c51a39fd..49aa2f33 100644
--- a/lib/ManaTools/Shared/GUI/Event.pm
+++ b/lib/ManaTools/Shared/GUI/Event.pm
@@ -68,6 +68,12 @@ use Moose;
use diagnostics;
use utf8;
+has 'basename' => (
+ is => 'ro',
+ isa => 'Str',
+ default => 'Event',
+);
+
with 'ManaTools::Shared::GUI::EventRole';
use yui;
diff --git a/lib/ManaTools/Shared/GUI/EventHandlerRole.pm b/lib/ManaTools/Shared/GUI/EventHandlerRole.pm
index 852c97a1..09e18e47 100644
--- a/lib/ManaTools/Shared/GUI/EventHandlerRole.pm
+++ b/lib/ManaTools/Shared/GUI/EventHandlerRole.pm
@@ -326,7 +326,7 @@ sub addWidget {
my $widget = shift;
my $event = shift;
my $backend = shift;
- return ManaTools::Shared::GUI::Event->new(name => $name, eventHandler => $self, eventType => $yui::YEvent::WidgetEvent, widget => $widget, event => $event, backend => $backend);
+ return ManaTools::Shared::GUI::Event->new(basename => 'widget', name => $name, eventHandler => $self, eventType => $yui::YEvent::WidgetEvent, widget => $widget, event => $event, backend => $backend);
}
#=============================================================
@@ -431,7 +431,7 @@ sub addItem {
my $item = shift;
my $event = shift;
my $backend = shift;
- return ManaTools::Shared::GUI::Event->new(name => $name, eventHandler => $self, eventType => $yui::YEvent::MenuEvent, item => $item, event => $event, backend => $backend);
+ return ManaTools::Shared::GUI::Event->new(basename => 'Item', name => $name, eventHandler => $self, eventType => $yui::YEvent::MenuEvent, item => $item, event => $event, backend => $backend);
}
#=============================================================
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',
diff --git a/lib/ManaTools/Shared/GUI/ExtTab.pm b/lib/ManaTools/Shared/GUI/ExtTab.pm
index 66a14690..66f242bb 100644
--- a/lib/ManaTools/Shared/GUI/ExtTab.pm
+++ b/lib/ManaTools/Shared/GUI/ExtTab.pm
@@ -78,6 +78,12 @@ use Moose;
use diagnostics;
use utf8;
+has 'basename' => (
+ is => 'ro',
+ isa => 'Str',
+ default => 'ExtTab',
+);
+
with 'ManaTools::Shared::GUI::EventRole';
use yui;