Closed Bug 355663 Opened 18 years ago Closed 18 years ago

Notification system for Composer extensions and sidebars

Categories

(Composer Graveyard :: General, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: glazou, Assigned: glazou)

Details

Attachments

(1 file, 2 obsolete files)

Composer needs a very simple notification system for extensions and sidebars
allowing a given code to register callbacks for a notification type.

For example, a sidebar item could listen to all selection changes without
having to deal with the too complex command system and writing an overlay for
that. It would only have to include a callback function and call something like

top.NotifierUtils.addNotifier("selectionChanged", myCallback);

The list of default notifications will probably include
   selection changed
   style applied
   before switching to source view
   after switching to source view
   before switching from source view
   after switching from source view
   before save/publish
   after load
   attribute changed
   inline CSS styles changed
   embedded CSS sheet changed
   linked CSS sheet changed
   ...
Attached patch fix #1 (obsolete) — Splinter Review
Attached patch fix #2 (obsolete) — Splinter Review
minor nit, one "public" function was in the "private" section.
Neil, can you r= ?
Attachment #241434 - Attachment is obsolete: true
Attachment #241438 - Flags: review?(neil)
Comment on attachment 241438 [details] [diff] [review]
fix #2

I don't see a way to remove a callback. (You would want to do that if your sidebar was closed). I also don't understand why you need cleanNotifiers.
Attachment #241438 - Flags: review?(neil) → review-
Attachment #241438 - Attachment is obsolete: true
Attachment #241684 - Flags: review?(neil)
Comment on attachment 241684 [details] [diff] [review]
fix #3, in answer to Neil's comments

>+      for (var i = 0; i < processes.length; i++)
>+        processes[i](aArg);
You might want to use try/catch here.

Just a thought, you might want to use 
a) processes[i](aKeyword, aArg);
to allow the same callback to be used for multiple keywords, or
b) processes[i].apply(null, arguments);
to allow a variable number (or no) arguments to callbacks
[in this case you wouldn't declare an explicit aArg parameter]
Attachment #241684 - Flags: review?(neil) → review+
(In reply to comment #5)

> You might want to use try/catch here.
> 
> Just a thought, you might want to use 
> a) processes[i](aKeyword, aArg);
> to allow the same callback to be used for multiple keywords, or
> b) processes[i].apply(null, arguments);
> to allow a variable number (or no) arguments to callbacks
> [in this case you wouldn't declare an explicit aArg parameter]

Yes, excellent suggestions indeed ! Thanks Neil.
fixed and checked in (trunk)
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: