home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-mac-0.9.sea.hqx / mozilla-mac-0.9 / Chrome / chatzilla.jar / content / chatzilla / lib / js / command-manager.js next >
Text File  |  2001-05-05  |  2KB  |  90 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Mozilla Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/MPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is JSIRC Library
  14.  *
  15.  * The Initial Developer of the Original Code is New Dimensions Consulting,
  16.  * Inc. Portions created by New Dimensions Consulting, Inc. are
  17.  * Copyright (C) 1999 New Dimenstions Consulting, Inc. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s): 
  21.  *
  22.  *
  23.  * Contributor(s):
  24.  *  Robert Ginda, rginda@ndcico.com, original author
  25.  */
  26.  
  27. function CCommandManager ()
  28. {
  29.  
  30.     this.commands = new Array();
  31.  
  32. }
  33.  
  34. CCommandManager.prototype.add =
  35. function cmgr_add (name, func, usage, help)
  36. {
  37.     function compare (a, b)
  38.     {
  39.         if (a.name == b.name)
  40.             return 0;
  41.         else
  42.             if (a.name > b.name)
  43.                 return 1;
  44.             else
  45.                 return -1;
  46.     }
  47.     
  48.     this.commands.push ({name: name, func: func, usage: usage, help: help});
  49.     this.commands = this.commands.sort(compare);
  50.     
  51. }
  52.  
  53. CCommandManager.prototype.list =
  54. function cmgr_list (partialName)
  55. {
  56.     /* returns array of command objects which look like |partialName|, or
  57.      * all commands if |partialName| is not specified */
  58.  
  59.     if ((typeof partialName == "undefined") ||
  60.         (String(partialName) == ""))
  61.         return this.commands;
  62.  
  63.     var ary = new Array();
  64.  
  65.     for (var i in this.commands)
  66.     {
  67.         if (this.commands[i].name.indexOf(partialName) == 0)
  68.             if (partialName.length == this.commands[i].name.length)
  69.                 /* exact match */
  70.                 return [this.commands[i]];
  71.             else
  72.                 ary.push (this.commands[i]);
  73.     }
  74.  
  75.     return ary;
  76.  
  77. }
  78.  
  79. CCommandManager.prototype.listNames =
  80. function cmgr_listnames (partialName)
  81. {
  82.     var cmds = this.list(partialName);
  83.     var cmdNames = new Array();
  84.     
  85.     for (var c in cmds)
  86.         cmdNames.push (cmds[c].name);
  87.  
  88.     return cmdNames.sort();
  89. }
  90.