1
0
forked from 0ad/0ad

Added more functions. Changed addItem to insertItem

This was SVN commit r2522.
This commit is contained in:
Gee 2005-07-23 20:17:36 +00:00
parent b50d9f529a
commit 4ad8de51bb

View File

@ -59,4 +59,58 @@ function addItem (objectName, pos, value)
}
}
// ====================================================================
// Adds an element to the end of the list
function pushItem(objectName, value)
{
var list = getGUIObjectByName(objectName).list;
list.push(value);
getGUIObjectByName(objectName).list = list;
// No need to update selection
}
// ====================================================================
// Removes the last element
function popItem(objectName)
{
var selected = getGUIObjectByName(objectName).selected;
removeItem(objectName, getNumItems(objectName)-1);
If (selected == getNumItems(objectName)-1)
{
getGUIObjectByName(objectName).selected = -1;
}
}
// ====================================================================
// Retrieves the number of elements in the list
function getNumItems(objectName)
{
var list = getGUIObjectByName(objectName).list;
return list.length;
}
// ====================================================================
// Retrieves the value of the item at 'pos'
function getItemValue(objectName, pos)
{
var list = getGUIObjectByName(objectName).list;
return list[pos];
}
// ====================================================================
// Retrieves the value of the currently selected item
function getCurItemValue(objectName)
{
if (getGUIObjectByName(objectName).selected == -1)
return "";
var list = getGUIObjectByName(objectName).list;
return list[getGUIObjectByName(objectName).selected];
}
// ====================================================================