<@interface name="KitCommands" alias="$ENV">
   Extension point for defining kit commands

   <copyright>(c) SAP AG 2003-2006. All rights reserved.</copyright>
</interface@>

<PUBLIC:METHOD   name="defineCommand"/>
<PUBLIC:METHOD   name="getCommand"/>
<PUBLIC:METHOD   name="getCommandsTable"/>
<PUBLIC:METHOD   name="removeCommand"/>
<PUBLIC:METHOD   name="redefineCommand"/>

<SCRIPT language="JavaScript">

//////////////////////////////////////////////////////////////////////////////////////////////////////
// KIT COMMANDS
//////////////////////////////////////////////////////////////////////////////////////////////////////
var _kitCommands = {};

<@method name="defineCommand">
   Defines a new command object
   <param name="def" type="@COMMAND_DEF">The new command object</param>
   <return type="@COMMAND_DEF">The newly defined command</return>

   <remarks>
   <title>Xml definition of a command in a configuration file</title>
   <sample>
   <CONFIGURE type='COMMANDS'>
   ?  <HEADER>
   ?     <PRAGMA># Pragmas section</PRAGMA>
   ?     <SCRIPT># Code section. Place here functions\variables
                   which you want to address from within the command tags
         </SCRIPT>
      </HEADER>
      <COMMANDS>
   +     <COMMAND id="com.sap.mypackage:commandId">
            # For complete description of command
              definition see @env:KitCommands!COMMAND_DEF
   ?        <PROPERTIES>
   *           <propertyName
                 type="[function | ]"/>
                    # Represents a property of the command
                    You can assign the 'type' attribute for
                    evaluating the value of the property
                    as a function
            </PROPERTIES>
         </COMMAND>
      </COMMANDS>
   </CONFIGURE>
   </sample>
   <title>Example</title>
   <sample>
   <CONFIGURE type='COMMANDS'>
      <COMMANDS>
         <COMMAND id='FILE_CLOSE'>
            <PROPERTIES>
               <signal>closeStudio</signal>
               <text>&#35;TEXT[XMIT_CMD_FILE_CLOSE]</text>
               <icon>&#35;URL[~skin:icons.close.gif]</icon>
               <category>STANDARD</category>
           </PROPERTIES>
         </COMMAND>
      </COMMANDS>
   </CONFIGURE>
   </sample>
   </remarks>
</method@>
function defineCommand(def) {
   if (!def) return null;
   if (typeof def != 'object' || !def.id ) return raiseKitError('Invalid command definition near %where%', STR(def));
   if (!isValidId(def.id)) return raiseKitError('Invalid namespace specification of Id:'+ def.id + " in kit :" + _currentPackage);
   var id = UPPER(def.id);
   if (id in _kitCommands) return raiseKitError('Command "'+id+'" is already defined');

   _kitCommands[id] = def;
   return def;
}

<@method name="getCommand">
   Returns a specified command object
   <param name="id:qn">Command Id</param>
   <return type="@COMMAND_DEF">The requested command object</return>
</method@>
function getCommand(id) {
   return _kitCommands[UPPER(id)] || null;
}

<@method name="getCommandsTable">
   Returns the complete commands table
   <return type="@COMMAND_DEF[id]">Table of command objects, indexed by command id</return>
<remarks>
Command id's are stored in uppercase. Use @lib:Basic!UPPER macro to convert the command id to uppercase
before using it as the index in this table.
</remarks>
</method@>
function getCommandsTable() {
   return _kitCommands;
}

<@method name="removeCommand">
   Removes a specified command definition
   <param name="id:qn">The id of the command to remove</param>
</method@>
function removeCommand(id) {
   delete _kitCommands[UPPER(id)];
}

<@method name="redefineCommand" scope="private">
	Defines or redefines a command
</method@>
function redefineCommand(def) {
   if (def) delete _kitCommands[UPPER(def.id)];
   return defineCommand(def);
}

<@method name="parseCommand">
   Parses the given command node and returns a string which represents its details
   <param name="commandNode">Command node to parse</param>
</method@>
function parseCommand(commandNode) {
   var map = getNodeProps(commandNode);
   var res = "$ENV.defineCommand(" + __xmlMap2Str(map) + ");";
   return res;
}


<@struct name="COMMAND_DEF">
   Represents a %STUDIO% command definition
   <remarks>

      The COMMAND_DEF structure is made of:
      <grid class="BOTH">
         Name     | Type                     | Description
         id       | QName                    | Command Id  - must be prefixed with namespace e.g. com.sap.mypackage:id
         signal   | @lib:Global!SIGNAL_DEF   | Signal to raise when the command is invoked
         text     | String                   | Command text label
         icon     | String                   | Command icon's relative url
         key      | String                   | Shortcut key mnemonic (e.g, Ctrl+S)
         category | String                   | The command category (can also be a regular expression)
      </grid>

   </remarks>
</struct@>

</SCRIPT>

