From f17fd6a448de34a76c96c160a9ddf88c03d88689 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Fri, 23 Aug 2013 13:59:11 -0700 Subject: [PATCH] Fixed: Menu disappears when opening a submenu Previously when opening a submenu from a menu, the main menu disappears because a issue with the poolMenuWindow. This PR fixes this bug. It also handle more properly the case when an user is making several right clicks on a responder (origin problem with the ghost menu). Fixed #1887 --- AppKit/CPMenu/CPMenu.j | 5 +++-- AppKit/CPMenu/_CPMenuManager.j | 9 +++++++++ AppKit/CPMenu/_CPMenuWindow.j | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index 1940827ee..394c4e952 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -855,6 +855,9 @@ var _CPMenuBarVisible = NO, + (void)popUpContextMenu:(CPMenu)aMenu withEvent:(CPEvent)anEvent forView:(CPView)aView withFont:(CPFont)aFont { + // This is needed when we are making several rights click + [[_CPMenuManager sharedMenuManager] cancelActiveMenu]; + [aMenu _menuWillOpen]; if (!aFont) @@ -863,8 +866,6 @@ var _CPMenuBarVisible = NO, var theWindow = [aView window], menuWindow = [_CPMenuWindow menuWindowWithMenu:aMenu font:aFont]; - [_CPMenuWindow poolMenuWindow:menuWindow]; - [menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle]; var constraintRect = [CPMenu _constraintRectForView:aView], diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index dd5b7abaf..4712a7e7e 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -407,6 +407,15 @@ var STICKY_TIME_INTERVAL = 0.4, [menu cancelTracking]; } +- (void)cancelActiveMenu +{ + if (CPApp._activeMenu) + { + [self completeTracking]; + _menuContainerStack = []; + } +} + - (void)completeTracking { var trackingMenu = [self trackingMenu]; diff --git a/AppKit/CPMenu/_CPMenuWindow.j b/AppKit/CPMenu/_CPMenuWindow.j index 19cf4d6f7..8f8a735db 100644 --- a/AppKit/CPMenu/_CPMenuWindow.j +++ b/AppKit/CPMenu/_CPMenuWindow.j @@ -72,7 +72,8 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2; + (void)poolMenuWindow:(_CPMenuWindow)aMenuWindow { - if (!aMenuWindow || _CPMenuWindowPool.length >= _CPMenuWindowPoolCapacity) + // FIXME :the poolMenuWindow is called too many times somewhere.... + if (!aMenuWindow || _CPMenuWindowPool.length >= _CPMenuWindowPoolCapacity || [_CPMenuWindowPool containsObject:aMenuWindow]) return; _CPMenuWindowPool.push(aMenuWindow);