Wednesday, April 23, 2008

NotifyArea Icons done right (hopefully this time!)

I had enough of it. Using the "Traybar" with my NotifyView was a pain in the a.. . I admit it - I'm guilty. So I decided to do it right this time.

My "US NotifyView" package contains a new and natural way to deal with NotifyArea Icons. No need to hassle with views. Simply create one (or many) instance(s) of NotifyAreaIcon and use simply messages like #show, #hide, #icon: and #message. That's it. If you want events simply catch #leftButtonPressed, #leftButtonDoubleClicked, #rightButtonPressed or #rightButtonDoubleClicked.

Using NotifyAreaIcons also gives you two things which are IMHO not part of any other Dolphin Traybar goodie.
  • Survives Image Reload: If you save/close your image with visible Traybar icons they are restored if you reopen the image
  • Explorer crash support: If your explorer crashes and rebuilds it's traybar your icons are re-added as well.

The following code illustrates it a bit more. Simply download the newest version of my goodies (04/23/2008) and enjoy.

| notifyIcon notifyIcons |
"Create your instance. No need to hassle with Views. Simply create an instance"
notifyIcon := NotifyAreaIcon
icon: (Icon fromId: '!APPLICATION')
message: 'My Application'.
"If you want your icon to be displayed, simply send #show"
notifyIcon show.
"You can change the tip message and the icon any time by using #icon: and #message: .
If the icon is currently visible it's automatically updated."

icon: Icon defaultApplication.
notifyIcon message: 'Changed message'.
"You can use this i.e. to display animations"
Icon allInstances asSet
[:each |
icon: each;
message: each identifier displayString].
"The icon triggers several messages which you can intercept using the regular
#when:send:to: mechanism"

when: #leftButtonPressed
send: #value
to: [Sound beep].
when: #leftButtonDoubleClicked
send: #value
[Sound beep.
(Delay forMilliseconds: 500)
Sound beep].
when: #rightButtonPressed
send: #value
to: [Sound bell].
when: #rightButtonDoubleClicked
send: #value
[Sound bell.
(Delay forMilliseconds: 500)
Sound bell].
"If you don't need the icon anymore (e.g. during #onViewClosed) you can simply hide
it or nil the variable and let GC take care of it"

notifyIcon hide.
notifyIcon := nil.

"You can even generate a whole bunch of instances"
notifyIcons := Icon allInstances
asSet collect:
[:each |
NotifyAreaIcon icon: each
message: each identifier displayString].
"If you want to stress test your system, show /all/ icons"
do: [:each | each show].
"Please note, that we don't hide icons here. We simply nil the instance and let GC
take care of it"

notifyIcons := nil.
"You can also force a GC"
MemoryManager current collectGarbage

1 comment:

Tim Mackinnon said...

Thats awesome - I really appreciate your work in helping the Dolphin community use the finer inner details of Windows without having to grapple with its complexity.