Added scrollToKey().

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@793 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2009-03-24 22:24:02 +00:00
parent 0a4a690728
commit 6e123c3c8b
+15 -4
View File
@@ -7,6 +7,7 @@ import mx.core.IFactory;
import mx.core.ScrollPolicy; import mx.core.ScrollPolicy;
import mx.collections.ArrayCollection; import mx.collections.ArrayCollection;
import mx.collections.IList;
import mx.collections.Sort; import mx.collections.Sort;
import mx.controls.List; import mx.controls.List;
@@ -66,6 +67,15 @@ public class DSetList extends List
_data.refresh(); _data.refresh();
} }
/**
* Scroll so that the entry with the specified key is visible.
*/
public function scrollToKey (key :Object) :Boolean
{
var scrollIdx :int = findKeyIndex(key, false);
return (scrollIdx == -1) ? false : scrollToIndex(scrollIdx);
}
/** /**
* Initialize listening on the specified object. * Initialize listening on the specified object.
* *
@@ -148,12 +158,13 @@ public class DSetList extends List
} }
/** /**
* Find the index of the specified entry key from the raw list. * Find the index of the specified entry key from the raw or filtered list.
*/ */
protected function findKeyIndex (key :Object) :int protected function findKeyIndex (key :Object, raw :Boolean = true) :int
{ {
for (var ii :int = 0; ii < _data.list.length; ii++) { var list :IList = raw ? _data.list : _data;
if (Util.equals(key, DSet_Entry(_data.list.getItemAt(ii)).getKey())) { for (var ii :int = 0; ii < list.length; ii++) {
if (Util.equals(key, DSet_Entry(list.getItemAt(ii)).getKey())) {
return ii; return ii;
} }
} }