Re: XUL tree views and "PerformAction" again

YuLo <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xpfe
Message-ID <[email protected]>
понедельник, 3 декабря 2012 г., 3:04:35 UTC+4 пользователь Neil написал:
> YuLo wrote:
> 
> 
> 
> >I made XPCOM(c++) implementing nsITreeView interface.
> 
> >I can create its instance in JavaScript and then call method PerformAction("..."). Sure, it works.
> 
> >
> 
> >But can it be done automatically when i press some keys, for instance "Delete"?
> 
> >
> 
> >I have some tree widgets in a window, it could be fine if XULRUNNER call "PerformAction" of the focussed widget.
> 
> >  
> 
> >
> 
> The standard way to make a keypress depend on the focused widget is as 
> 
> follows:
> 
> 
> 
>    1. Create a XUL <key keycode="VK_DELETE"
> 
>       oncommand="goDoCommand('cmd_delete');"/> (I think goDoCommand is
> 
>       in globalOverlay.js)
> 
>    2. Attach an nsIController object to your tree element's controllers
> 
>       property (it may be convenient for your C++ nsITreeView object to
> 
>       implement this interface too, or you could obtain a reference to
> 
>       your tree view in another way).
> 
>    3. The nsIController object should
> 
>          1. only respond true to supportsCommand('cmd_delete') and any
> 
>             other commands that you actually support
> 
>          2. respond true to isCommandEnabled if it's safe to run the command
> 
>          3. actually perform the action when doCommand is called
> 
> 
> 
> Then when the delete key is pressed, the JavaScript code will invoke the 
> 
> cmd_delete command on the focused element. (I use cmd_delete because it 
> 
> works for text elements too.)
> 
> 
> 
> -- 
> 
> Warning: May contain traces of nuts.

Thank you, Neil,
i didn't know about nsIController before.
On weekend, before you answered me, i made as follow:
1. <key keycode="VK_DELETE" oncommand="xpcomComponent.command('VK_DELETE')" and others in XUL file
2. in function "command" of new XPCOM i GetActiveElement and check whether it is "tree". If yes, i take treeView object as you explained me in my previous post. Then i call PerformAction of the tree view object.

I think it is a good idea to use nsIController, i'll learn about it.
Thanks again.
_______________________________________________
dev-tech-xul mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xul
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.