Allow to be used without a command.

Alternatively, I could create a DataComboBox that just does the cool
'data' stuff, and have CommandComboBox extend that.
Comment cleanups.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@746 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2008-12-18 01:18:31 +00:00
parent 2d0070a940
commit 2817021c56
@@ -30,16 +30,15 @@ import com.threerings.util.CommandEvent;
import com.threerings.util.Util; import com.threerings.util.Util;
/** /**
* A combo box that dispatches a command (or calls a function) when it is toggled. NOTE: Unlike the * A combo box that dispatches a command (or calls a callback) when an item is selected.
* other Command* controls, CommandComboBox does not guarantee that the CommandEvent is dispatched * The argument will be the 'data' value of the selected item.
* after notifying all other listeners. * NOTE: Unlike the other Command* controls, CommandComboBox allows a null cmd/callback
* to be specified.
*/ */
public class CommandComboBox extends ComboBox public class CommandComboBox extends ComboBox
{ {
/** /** The field of the selectedItem object used as the 'data'. If this property is null,
* The field of the selectedItem object used as the argument to the * then the item is the data. */
* command or function. If null, the entire selectedItem is passed as the argument.
*/
public var dataField :String = "data"; public var dataField :String = "data";
/** /**
@@ -103,12 +102,12 @@ public class CommandComboBox extends ComboBox
*/ */
protected function itemToData (item :Object) :Object protected function itemToData (item :Object) :Object
{ {
return (dataField == null) ? item : ((item == null) ? null : item[dataField]); return (item == null || dataField == null) ? item : item[dataField];
} }
protected function handleChange (event :ListEvent) :void protected function handleChange (event :ListEvent) :void
{ {
if (this.selectedIndex != -1) { if (_cmdOrFn != null && this.selectedIndex != -1) {
CommandEvent.dispatch(this, _cmdOrFn, selectedData); CommandEvent.dispatch(this, _cmdOrFn, selectedData);
} }
} }