Command

A command element can be used to invoke an operation that can come from multiple sources. For example, a clipboard paste operation can be invoked from the Edit menu, a context menu and by pressing a keyboard shortcut. You attach the code to the command using the oncommand attribute. It will be called no matter how it is invoked by the user. In addition, disabling the command will automatically disable the menu items and keyboard shortcuts.

Commands are identified by their id. If you include the script chrome://global/content/globalOverlay.js in your window, you can use the function goDoCommand function to invoke the command. Using this function has the advantage that the command will be sent to the part of the UI which will respond to it. Typically, this will be the currently focused element. For example, the following code will sent a paste command (cmd_paste) to the currently focused element:

  goDoCommand("cmd_paste");  

Like a broadcaster, commands forward attributes to other elements.

More information about command

複数のソースから起動され得る処理には command (コマンド) 要素を利用することができる。例えば、クリップボードのペースト処理は編集メニューやコンテクストメニュー、あるいはキーボードショートカットにより起動され得る。 oncommand 属性を設定して実行コードをコマンドに結びつけることにより、ユーザの呼び出し方にかかわらず、そのコードが呼び出されることになる。更に、コマンドを無効にするとメニュー項目やキーボードショートカットも自動的に無効にされる。

コマンドはその id で識別される。ウィンドウに chrome://global/content/globalOverlay.js というスクリプトをインクルードすると、goDoCommand 関数を用いてコマンドを実行できる。 この関数を使うと、コマンドに反応する一部の UI にそのコマンドが送られる、という利点が得られる。一般にそれは現在フォーカスのある要素で、例えば、次のコードはペーストコマンド (cmd_paste) を現在フォーカスのある要素に送る。

  goDoCommand("cmd_paste");  

broadcaster と同様、command は属性を他の要素に送ることができる。

command の追加情報


属性:

XUL Element から継承:

align
allowevents
allownegativeassertions
class
coalesceduplicatearcs
collapsed
container
containment
context
contextmenu
datasources
debug
dir
empty
equalsize
flags
flex
height
hidden
id
insertafter
insertbefore
left
maxheight
maxwidth
menu
minheight
minwidth
mousethrough
observes
ordinal
orient
pack
persist
popup
position
ref
removeelement
sortDirection
sortResource
sortResource2
statustext
style
template
tooltip
tooltiptext
top
uri
wait-cursor
width

disabled

Type: boolean

If you set the disabled attribute to true, any menu items and keys attached to the command become disabled. If you remove the disabled attribute, the menu items and keys become enabled.

型 : boolean

disabled 属性を true に設定すると、コマンドに結びつけられた全てのメニュー項目とキーが無効化される。disabled 属性を削除すると、メニュー項目とキーは有効になる。

label

Type: string

The label inherited by the menu items and keys that are attached to the command.

型 : 文字列

コマンドに結びつけられたメニュー項目やキーに継承されるラベル。

oncommand

Type: script code

This event handler is called when the command is activated. This occurs when a user selects a menu item or presses a keyboard shortcut attached to the command.

型 : script code

このイベントハンドラは、コマンドが起動されたときに呼ばれる。ユーザがコマンドに結びつけられたメニュー項目を選択したり、キーボードショートカットを押したりしたときに、これが起きる。


プロパティとメソッド:

XUL Element から継承:

align allowEvents blur boxObject boxObject.element
boxObject.getLookAndFeelMetric boxObject.height boxObject.screenX boxObject.screenY boxObject.width
boxObject.x boxObject.y builder className click
collapsed contextMenu controllers database datasources
dir doCommand flex focus getElementsByAttribute
height hidden id left maxHeight
maxWidth menu minHeight minWidth observes
ordinal orient pack persist ref
resource statusText style tooltip tooltipText
top width

Element から継承:

addEventListener
appendChild
attributes
childNodes
cloneNode
dispatchEvent
firstChild
getAttribute
getAttributeNS
getAttributeNode
getAttributeNodeNS
getElementsByTagName
getElementsByTagNameNS
hasAttribute
hasAttributeNS
hasAttributes
hasChildNodes
insertBefore
isSupported
lastChild
localName
namespaceURI
nextSibling
nodeName
nodeType
nodeValue
normalize
ownerDocument
parentNode
prefix
previousSibling
removeAttribute
removeAttributeNS
removeAttributeNode
removeChild
removeEventListener
replaceChild
setAttribute
setAttributeNS
setAttributeNode
setAttributeNodeNS
tagName

Copyright (C) 1999 - 2004 XulPlanet.com