You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2020/02/15 00:23:00 UTC

[royale-asjs] branch develop updated: update selectedItem on delete

This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 7ad6a08  update selectedItem on delete
7ad6a08 is described below

commit 7ad6a08caf5c678ac0580531c1bb360e31608c5b
Author: Alex Harui <ah...@apache.org>
AuthorDate: Fri Feb 14 16:22:41 2020 -0800

    update selectedItem on delete
---
 .../models/SingleSelectionICollectionViewModel.as  | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
index 62a3992..d9080d0 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
@@ -21,6 +21,8 @@ package mx.controls.beads.models
 	import mx.collections.ICollectionView;
 	import mx.collections.IViewCursor;
     import mx.collections.CursorBookmark;
+    import mx.events.CollectionEvent;
+    import mx.events.CollectionEventKind;
 	
 	import org.apache.royale.core.IRollOverModel;
 	import org.apache.royale.core.ISelectionModel;
@@ -92,7 +94,10 @@ package mx.controls.beads.models
 
             _dataProvider = value as ICollectionView;
             if (_dataProvider)
+			{
                 _cursor = _dataProvider.createCursor();
+				dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
+			}
 			if(!_dataProvider || _selectedIndex >= _dataProvider.length)
 				_selectedIndex = -1;
             
@@ -293,5 +298,27 @@ package mx.controls.beads.models
 			dispatchEvent(new Event("selectedItemChanged"));
 			dispatchEvent(new Event("selectedIndexChanged"));
 		}
+		
+		protected function collectionChangeHandler(event:CollectionEvent):void
+		{
+			if (event.kind == CollectionEventKind.ADD)
+			{
+				if (event.location <= _selectedIndex)
+				{
+					_selectedIndex++;
+				}
+			}
+			else if (event.kind == CollectionEventKind.REMOVE)
+			{
+				if (event.location < _selectedIndex)
+				{
+					_selectedIndex--;
+				}
+				else if (event.location == _selectedIndex)
+				{
+					_selectedItem = getItemAt(_selectedIndex);
+				}
+			}
+		}
 	}
 }