HalleyInteractive / brackets-notifications

Brackets - Notifications
MIT License
0 stars 0 forks source link

Create working actions callback #7

Closed GriffinSauce closed 10 years ago

GriffinSauce commented 10 years ago

In the "Actions" branch I have done the initial development for notifs with actions. But there is a problem: the callback to the original script.

It is asynchronous to the creation of the notif, so simply returning the text is a no-go. The second idea is to return an object:

{
notification: <notification_element>
actions:
    [
        <action_element_one>,
        <action_element_two>
    ]
}

The creating script can then add eventlisteners to the whole notification or actions at will. Even for instance using hover to show extra info. That is open to the dev to work on.

One problem: return does not work. The callback function of CommandManager.execute is never called.

Please advise..

HalleyInteractive commented 10 years ago

Passing a function for each action as a callback seems to work. We could still add a general function as callback for creating the notification.

This function can get the elements as parameter as suggested, for adding event listeners or other stuff.

GriffinSauce commented 10 years ago

Like follows?

CommandManager.execute("notifications.notification",
{
    title: "Notification with actions",
    message: txt[Math.round(Math.random()*(txt.length-1))],
    actions:[action1, action2],
    time:0
    callback:function(elements){}
});

Sounds good but then we expect the dev to provide handlers for the actions, but attach his own handlers for clicking the notif. So I will add a "clicked" parameter, with a function that will be fired on click.

Then the callback elements can be purely used for extending/customizing the notif.

GriffinSauce commented 10 years ago

Clicked added in 8dd4da84378bd7ede0d57c8bbe4638ad9b35e07a

GriffinSauce commented 10 years ago

Seperate issue created for the callback.