diff options
author | Jan Djärv <jan.h.d@swipnet.se> | 2013-08-11 16:57:12 +0200 |
---|---|---|
committer | Jan Djärv <jan.h.d@swipnet.se> | 2013-08-11 16:57:12 +0200 |
commit | d2d699ac519599385b2865627db065c0fbfd38f3 (patch) | |
tree | 9f21ec7de67b36c79ef5f41259e7d33e90e26b7f /src/nsmenu.m | |
parent | 7ec326db1dfe07523c8e22fb98f8aed6c8f2ae7e (diff) | |
download | emacs-d2d699ac519599385b2865627db065c0fbfd38f3.tar.gz |
* nsmenu.m (ns_update_menubar): Call fillWithWidgetValue:setDelegate.
(x_activate_menubar): Update the whole menu.
(trackingNotification:): Call ns_check_menu_open if tracking ends.
(menuWillOpen:): Increment trackingMenu. For OSX <= 10.6, exit if
current event is not NSSystemDefined.
Call ns_check_menu_open only if trackingMenu is 2.
(menuDidClose:): New method, decrease trackingMenu.
(fillWithWidgetValue:setDelegate:): New method.
(fillWithWidgetValue:): Call the above.
* nsterm.h (EmacsMenu): Add fillWithWidgetValue:setDelegate:
* nsterm.m (menu_pending_title, ns_get_pending_menu_title): Remove.
(ns_check_menu_open): Handle menu == nil. Remove assignment to
menu_pending_title.
Fixes: debbugs:15001
Diffstat (limited to 'src/nsmenu.m')
-rw-r--r-- | src/nsmenu.m | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/src/nsmenu.m b/src/nsmenu.m index 5b3c21424e9..1ae2a34ab92 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -366,7 +366,7 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu) } else { - [menu fillWithWidgetValue: first_wv->contents]; + [menu fillWithWidgetValue: first_wv->contents setDelegate:YES]; } } @@ -504,21 +504,7 @@ void x_activate_menubar (struct frame *f) { #ifdef NS_IMPL_COCOA - NSArray *a = [[NSApp mainMenu] itemArray]; - /* Update each submenu separately so ns_update_menubar doesn't reset - the delegate. */ - int i = 0; - while (i < [a count]) - { - EmacsMenu *menu = (EmacsMenu *)[[a objectAtIndex:i] submenu]; - const char *title = [[menu title] UTF8String]; - if (strcmp (title, ns_get_pending_menu_title ()) == 0) - { - ns_update_menubar (f, true, menu); - break; - } - ++i; - } + ns_update_menubar (f, true, nil); ns_check_pending_open_menu (); #endif } @@ -576,17 +562,34 @@ extern NSString *NSMenuDidBeginTrackingNotification; /* Update menu in menuNeedsUpdate only while tracking menus. */ trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification ? 1 : 0); + if (! trackingMenu) ns_check_menu_open (nil); } #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 - (void)menuWillOpen:(NSMenu *)menu { - ns_check_menu_open (menu); -} -#endif + ++trackingMenu; +#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_6 + // On 10.6 we get repeated calls, only the one for NSSystemDefined is "real". + if ([[NSApp currentEvent] type] != NSSystemDefined) return; #endif + /* When dragging from one menu to another, we get willOpen followed by didClose, + i.e. trackingMenu == 3 in willOpen and then 2 after didClose. + We have updated all menus, so avoid doing it when trackingMenu == 3. */ + if (trackingMenu == 2) + ns_check_menu_open (menu); +} + +- (void)menuDidClose:(NSMenu *)menu +{ + --trackingMenu; +} +#endif /* OSX >= 10.5 */ + +#endif /* NS_IMPL_COCOA */ + /* delegate method called when a submenu is being opened: run a 'deep' call to set_frame_menubar */ - (void)menuNeedsUpdate: (NSMenu *)menu @@ -722,6 +725,11 @@ extern NSString *NSMenuDidBeginTrackingNotification; - (void)fillWithWidgetValue: (void *)wvptr { + [self fillWithWidgetValue: wvptr setDelegate:NO]; +} + +- (void)fillWithWidgetValue: (void *)wvptr setDelegate: (BOOL)set +{ widget_value *wv = (widget_value *)wvptr; /* clear existing contents */ @@ -737,6 +745,9 @@ extern NSString *NSMenuDidBeginTrackingNotification; { EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: [item title]]; +#ifdef NS_IMPL_COCOA + if (set) [submenu setDelegate: submenu]; +#endif [self setSubmenu: submenu forItem: item]; [submenu fillWithWidgetValue: wv->contents]; [submenu release]; |