Re: XUL tree views and "PerformAction" again

Neil <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xpfe
Message-ID <[email protected]>
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.
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.