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

yishayw 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 ef6466d  Fixes #445
ef6466d is described below

commit ef6466d49b95a807658cc9ef3318c49c33d32fdc
Author: DESKTOP-RH4S838\Yishay <yishayj...@hotmail.com>
AuthorDate: Thu Aug 15 22:03:20 2019 +0300

    Fixes #445
---
 .../CascadingMenuSelectionMouseController.as       | 77 +++++++++++++++++++++-
 .../controllers/MenuSelectionMouseController.as    | 19 ++++--
 2 files changed, 87 insertions(+), 9 deletions(-)

diff --git 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/controllers/CascadingMenuSelectionMouseController.as
 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/controllers/CascadingMenuSelectionMouseController.as
index bcb8e2d..e2bfe89 100644
--- 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/controllers/CascadingMenuSelectionMouseController.as
+++ 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/controllers/CascadingMenuSelectionMouseController.as
@@ -26,7 +26,11 @@ package org.apache.royale.html.beads.controllers
        import org.apache.royale.events.ItemClickedEvent;
        import org.apache.royale.html.CascadingMenu;
        import org.apache.royale.html.beads.models.CascadingMenuModel;
-       
+       import org.apache.royale.html.beads.models.MenuModel;
+       import org.apache.royale.html.Menu;
+       import org.apache.royale.core.ISelectionModel;
+       import org.apache.royale.core.UIBase;
+
        COMPILE::JS {
                import org.apache.royale.events.BrowserEvent;
        }
@@ -96,6 +100,21 @@ package org.apache.royale.html.beads.controllers
                                menu.dataProvider = 
getSubMenuDataProvider(node, model);
                                menu.labelField = model.labelField;
                                menu.parentMenuBar = (_strand as 
IMenu).parentMenuBar;
+                               // selected item holds the currently open 
submenu data provider
+                               // check to see if that exists and hide it if 
it does
+                               if (model.selectedItem)
+                               {
+                                       var dp:Object = 
getSubMenuDataProvider(model.selectedItem, model);
+                                       if (dp)
+                                       {
+                                               var nextMenu:CascadingMenu = 
getMenuWithDataProvider(MenuModel.menuList, dp);
+                                               if (nextMenu)
+                                               {
+                                                       
clearSubmenusOnSameLevel(nextMenu, nextMenu.model as ISelectionModel);
+                                               }
+                                       }
+                               }
+                               model.selectedItem = event.data;
                                menu.show(component, component.width, 0);
                        }
                        else {
@@ -103,7 +122,61 @@ package org.apache.royale.html.beads.controllers
                                hideOpenMenus();
                        }
                }
-               
+
+               private function 
clearSubmenusOnSameLevel(menuToBeRemoved:UIBase, model:ISelectionModel):void
+               {
+                       var selectedItem:Object = model.selectedItem;
+                       if (!selectedItem)
+                       {
+                               return removeMenu(menuToBeRemoved);
+                       }
+                       var menuList:Array = MenuModel.menuList;
+                       for (var i:int = 0; i < menuList.length; i++)
+                       {
+                               var menu:UIBase = menuList[i] as UIBase;
+                               var menuModel:ISelectionModel = menu.model as 
ISelectionModel;
+                               if (menuModel && menuModel.selectedItem == 
selectedItem)
+                               {
+                                       var dp:Object = 
getSubMenuDataProvider(selectedItem, menuModel as CascadingMenuModel);
+                                       if (dp)
+                                       {
+                                               // though this is being called 
in a loop, performance shouldn't be a big issue as
+                                               // number of open nested menus 
is expected to be small
+                                               var nextMenu:CascadingMenu = 
getMenuWithDataProvider(menuList, dp);
+                                               if (nextMenu)
+                                               {
+                                                       return 
clearSubmenusOnSameLevel(menu, nextMenu.model as ISelectionModel);
+                                               }
+                                       }
+                               }
+                       }
+                       removeMenu(menuToBeRemoved);
+               }
+
+               /**
+                * @private
+                * 
+                *  Search for an open menu strand according to the given data 
provider.
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.6
+                */
+               protected function getMenuWithDataProvider(menuList:Array, 
dp:Object):CascadingMenu
+               {
+                       // go over open menus and return the one with the given 
data provider
+                       for (var i:int = 0; i < menuList.length; i++)
+                       {
+                               var cascadingMenu:CascadingMenu = menuList[i] 
as CascadingMenu;
+                               if (cascadingMenu && cascadingMenu.dataProvider 
== dp)
+                               {
+                                       return cascadingMenu;
+                               }
+                       }
+                       return null;
+               }
+
                protected function getSubMenuDataProvider(node:Object, 
model:CascadingMenuModel):Object
                {
                        return node[model.submenuField];
diff --git 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/controllers/MenuSelectionMouseController.as
 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/controllers/MenuSelectionMouseController.as
index e130426..02636cf 100644
--- 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/controllers/MenuSelectionMouseController.as
+++ 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/controllers/MenuSelectionMouseController.as
@@ -158,13 +158,7 @@ package org.apache.royale.html.beads.controllers
                        
                        for(var i:int=0; i < copy.length; i++) {
                                var menu:UIBase = copy[i] as UIBase;
-                               if (menu.parent != null) {
-                                       var 
controller:MenuSelectionMouseController = 
menu.getBeadByType(MenuSelectionMouseController) as 
MenuSelectionMouseController;
-                                       controller.removeClickOutHandler(menu);
-                    var host:IPopUpHost = UIUtils.findPopUpHost(menu as 
IUIBase);
-                                       if(host)
-                                               
host.popUpParent.removeElement(menu);
-                               }
+                               removeMenu(menu);
                        }
                        MenuModel.clearMenuList();
                }
@@ -179,6 +173,17 @@ package org.apache.royale.html.beads.controllers
                        hideOpenMenus();
                }
                
+               protected function removeMenu(menu:UIBase):void
+               {
+                       if (menu.parent != null) {
+                               var controller:MenuSelectionMouseController = 
menu.getBeadByType(MenuSelectionMouseController) as 
MenuSelectionMouseController;
+                               controller.removeClickOutHandler(menu);
+                               var host:IPopUpHost = 
UIUtils.findPopUpHost(menu as IUIBase);
+                               if(host)
+                                       host.popUpParent.removeElement(menu);
+                       }
+               }
+
                /**
                 * @private
                 * 

Reply via email to