On 2.5.2012 18:15, Ryosuke Niwa wrote:
Bear with me...
Delphi (Object Pascal) Visual Component Library has concept of
Actions, some Actions can be assigned to Controls (those would
be here menu/contextmenu items of the browser, would be great
to be able to assign such Action (or some inherited object) to
my own <button>), one Action can be assigned to
unlimited number of controls. Action has 2 important
methods/events (either overriding the method or listening to
the event default method triggers). First one is Execute, that
is called, when Control default activation happens
(click/enter on button, click on menu item), which helps to
utilize functionality for several controls in one place
(essentially one event handler function, we can do that of
course in JS..)
The important thing is, Action also has Update method
(OnUpdate event), that is called every time application gets
to idle state (application receive message (system message
like click, paint, keydown, whatever), application processes
this message and any subsequent messages if any new are in the
queue and goes to idle). And in that idle state application
goes through all the Actions in the application and calls
Update method and then the Action can decide, whether is
enabled or not. And all Controls with this Action assigned
would change this property as well
I could express it in JS as
var deleteUserAction = new Action();
deleteUserAction.addEventHandler('execute', function()
{
//some code to delete all selected users
});
deleteUserAction.addEventHandler('update', function()
{
this.enabled = (myList.selectedUsers.length > 1)
&& havingRightsToDeleteUsers;
});
mainMenuItemDelete.action = "">
contextMenuItemDelete.action = "">
toolbarButtonDelete.action = "">
So the update handler allows you not to care about how many
controls should you disable/enable, just assign this action to
any control, in this action handler set up enabled to this
action and all controls are updated. So except the assignment
of Action to Control, no additional work needed. And the
concept of calling the update method guarantees, the UI is up
to date (user is doing something, messages are queued and
processed, the second there is time, all actions are updated).
Since it is in idle state, programmer does not have to care
when and how to set up all controls.
Action also has e.g. caption, image, etc. when updated again,
all assigned controls are updated to have the same caption,
image, etc...
I'm currently trying to implement this in my web application
(would be handy to have idle event), because it would simplify
UI management on programmers level, but something like this
could help to update browser's UI as well.
- Ryosuke
Basically yes... self updatable state machine (that "self" part is
extremely important to me), but if doing so, it would be great not
to bing it some specific feature (Editing API, browser UI), but make
it more generic = usable.
B.
|