[Fxruby-users] Connecting multiple listeners to an object
Status: Inactive
Brought to you by:
lyle
|
From: Daniel S. <da...@pr...> - 2004-03-30 03:08:05
|
I've been frustrated with the fact that you can't connect multiple
things to an FXObject. Ie.
=09target =3D FXDataTarget.new()
=09target.connect(SEL_COMMAND) { puts "hello" }
=09target.connect(SEL_COMMAND) { puts "hello2" }
The only thing that gets printed when the target is changed is "hello2".
How do others normally deal with this? Do you have your code such that
all connectors must go through in intermediary? Do you only connect in
the one place?
I've thrown together a module to include in classes that I want to
multi-connect to.=20
module MultiConnect
=20 def self.append_features(mod)
=20 mod.module_eval {
=20 alias_method :connect_orig, :connect
=20 private :connect_orig
=20 }
=20 super
=20 end
=20 def connect_single(messageType, callableObject=3Dnil, &proc)
=20 disconnect_all(messageType)
=20 connect(messageType, callableObject, proc)
=20 end
=20 def disconnect_all(messageType)
=20 @multiConnectHash[messageType] =3D [] if @multiConnectHash
=20 end
=20 def connect(messageType, callableObject=3Dnil, &proc)
=20 proc =3D callableObject unless proc
=20 @multiConnectHash =3D Hash.new unless @multiConnectHash
=20 if(@multiConnectHash.has_key? messageType)
=20 @multiConnectHash[messageType] << proc
=20 else
=20 array =3D [ proc ]=20
=20 connect_orig(messageType) { |a,b,c| array.each { |proc| proc.call=
a,b,c }}
=20 @multiConnectHash[messageType] =3D array
=20 end
=20 end =20
end
#########################################################################=
############
This email has been scanned by MailMarshal, an email content filter.
#########################################################################=
############
|