Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    listening to menu hide

    Hello,

    I have a menuButton with menu. Just like its done in browser, menuButton should be selected while a menu is opened.

    To implement it, my MenuButton should know if menu is hidden, to change its state.

    How menuButton can know if its menu is hidden? I tried overriding Menu.hide() function, from there I notify a menuButton "listener". However, hide() isn't invoked when user opens a menu, and then clicks outside it.

    I use smartGWT 2.1, below is my code (it uses event listeners to select / unselect a menuButton):
    Code:
    //add listeners to hide/show menu
             menu.addMouseOutHandler(new MouseOutHandler() {
                 public void onMouseOut(MouseOutEvent event) {
                     menuButton.setSelected(false);
                     menu.hide();
                 }
             });
             menu.addClickHandler(new ClickHandler() {
                 public void onClick(ClickEvent event) {
                     menuButton.setSelected(false);
                 }
             });
             menuButton.addMouseDownHandler(new MouseDownHandler() {
                 public void onMouseDown(MouseDownEvent event) {
                    menuButton.setSelected(true);
                     //unselect the rest
                    menu.showNextTo(menuButton, "bottom");
                 }
             });
    
    //menuImpl class - to override hide()
    public class MenuImpl extends Menu {
    
        private MenuButton eventHandler;
        
        public void setListener(MenuButton button){
            eventHandler = button;
        }
    
        public void hide(){
            super.hide();
            eventHandler.setSelected(false);
        }
    }


    thank you

    #2
    Hello,

    I'm also looking for the same thing:
    when a user decides not to choose anything in the menu, by clicking outside it or pressing Escape, something should happen. How can I listen for this event?

    Comment


      #3
      As far as the first poster, there's already a MenuButton in the framework that does that.

      We're looking at adding an event for when visibility changes, however, what action are you trying to take at that time?

      Comment


        #4
        I have some controls which look like a menu. Whenever the menu is showing, the rest of the application should be covered with a transparent mask. This works, but when the menu disappears by an outside click, the mask should disappear again.
        I thought about your recommendation for the menu being a modal window instead, but that doesn't has the right look and feel for that: the menu appearance suits better in this case.

        Comment


          #5
          We've just added a notification method 'visibilityChanged' which will fire when a drawn component's visibility changes (due to show() or hide(), or to a parent showing or hiding)
          This will be present in the next nightly build.

          Comment


            #6
            Thanks, works great in build SC_SNAPSHOT-2010-11-22.

            Comment

            Working...
            X