On 2.5.2012 15:57, Boris Zbarsky wrote:
On 5/2/12 2:23 AM, Aryeh Gregor wrote:
For the former, I'd suggest onbeforecontextmenu, with some way to
disable specific options
I would think that disabling cut/copy/paste would apply to main menus
too, not just context menus. Most people I know who use menus for
this (which is precious few, btw, for the most part people I know seem
to use keyboard shortcuts for cut/copy/paste) use the main menu, not
the context menu...
One question is whether this use case (which I agree seems worth
addressing) requires a new event. That is, is it better for the
browser to fire events every time a menu is opened, or is it better
for apps that want to maintain state like this to update some property
on the editable area whenever their state changes and for browsers to
just read those properties when opening a menu?
The latter is, from my point of view as a browser implementor,
somewhat simpler to deal with, since it doesn't involve having to
worry about alert() or sync XHR or window.close() in menu-opening
code. But I can see that it might be more complicated to author
against...
-Boris
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 = deleteUserAction;
contextMenuItemDelete.action = deleteUserAction;
toolbarButtonDelete.action = deleteUserAction;
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.
Brona