diff options
| author | Jan Djärv | 2013-08-11 16:57:12 +0200 |
|---|---|---|
| committer | Jan Djärv | 2013-08-11 16:57:12 +0200 |
| commit | d2d699ac519599385b2865627db065c0fbfd38f3 (patch) | |
| tree | 9f21ec7de67b36c79ef5f41259e7d33e90e26b7f /src/nsmenu.m | |
| parent | 7ec326db1dfe07523c8e22fb98f8aed6c8f2ae7e (diff) | |
| download | emacs-d2d699ac519599385b2865627db065c0fbfd38f3.tar.gz emacs-d2d699ac519599385b2865627db065c0fbfd38f3.zip | |
* 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) | |||
| 366 | } | 366 | } |
| 367 | else | 367 | else |
| 368 | { | 368 | { |
| 369 | [menu fillWithWidgetValue: first_wv->contents]; | 369 | [menu fillWithWidgetValue: first_wv->contents setDelegate:YES]; |
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | } | 372 | } |
| @@ -504,21 +504,7 @@ void | |||
| 504 | x_activate_menubar (struct frame *f) | 504 | x_activate_menubar (struct frame *f) |
| 505 | { | 505 | { |
| 506 | #ifdef NS_IMPL_COCOA | 506 | #ifdef NS_IMPL_COCOA |
| 507 | NSArray *a = [[NSApp mainMenu] itemArray]; | 507 | ns_update_menubar (f, true, nil); |
| 508 | /* Update each submenu separately so ns_update_menubar doesn't reset | ||
| 509 | the delegate. */ | ||
| 510 | int i = 0; | ||
| 511 | while (i < [a count]) | ||
| 512 | { | ||
| 513 | EmacsMenu *menu = (EmacsMenu *)[[a objectAtIndex:i] submenu]; | ||
| 514 | const char *title = [[menu title] UTF8String]; | ||
| 515 | if (strcmp (title, ns_get_pending_menu_title ()) == 0) | ||
| 516 | { | ||
| 517 | ns_update_menubar (f, true, menu); | ||
| 518 | break; | ||
| 519 | } | ||
| 520 | ++i; | ||
| 521 | } | ||
| 522 | ns_check_pending_open_menu (); | 508 | ns_check_pending_open_menu (); |
| 523 | #endif | 509 | #endif |
| 524 | } | 510 | } |
| @@ -576,17 +562,34 @@ extern NSString *NSMenuDidBeginTrackingNotification; | |||
| 576 | /* Update menu in menuNeedsUpdate only while tracking menus. */ | 562 | /* Update menu in menuNeedsUpdate only while tracking menus. */ |
| 577 | trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification | 563 | trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification |
| 578 | ? 1 : 0); | 564 | ? 1 : 0); |
| 565 | if (! trackingMenu) ns_check_menu_open (nil); | ||
| 579 | } | 566 | } |
| 580 | 567 | ||
| 581 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 | 568 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 |
| 582 | - (void)menuWillOpen:(NSMenu *)menu | 569 | - (void)menuWillOpen:(NSMenu *)menu |
| 583 | { | 570 | { |
| 584 | ns_check_menu_open (menu); | 571 | ++trackingMenu; |
| 585 | } | ||
| 586 | #endif | ||
| 587 | 572 | ||
| 573 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_6 | ||
| 574 | // On 10.6 we get repeated calls, only the one for NSSystemDefined is "real". | ||
| 575 | if ([[NSApp currentEvent] type] != NSSystemDefined) return; | ||
| 588 | #endif | 576 | #endif |
| 589 | 577 | ||
| 578 | /* When dragging from one menu to another, we get willOpen followed by didClose, | ||
| 579 | i.e. trackingMenu == 3 in willOpen and then 2 after didClose. | ||
| 580 | We have updated all menus, so avoid doing it when trackingMenu == 3. */ | ||
| 581 | if (trackingMenu == 2) | ||
| 582 | ns_check_menu_open (menu); | ||
| 583 | } | ||
| 584 | |||
| 585 | - (void)menuDidClose:(NSMenu *)menu | ||
| 586 | { | ||
| 587 | --trackingMenu; | ||
| 588 | } | ||
| 589 | #endif /* OSX >= 10.5 */ | ||
| 590 | |||
| 591 | #endif /* NS_IMPL_COCOA */ | ||
| 592 | |||
| 590 | /* delegate method called when a submenu is being opened: run a 'deep' call | 593 | /* delegate method called when a submenu is being opened: run a 'deep' call |
| 591 | to set_frame_menubar */ | 594 | to set_frame_menubar */ |
| 592 | - (void)menuNeedsUpdate: (NSMenu *)menu | 595 | - (void)menuNeedsUpdate: (NSMenu *)menu |
| @@ -722,6 +725,11 @@ extern NSString *NSMenuDidBeginTrackingNotification; | |||
| 722 | 725 | ||
| 723 | - (void)fillWithWidgetValue: (void *)wvptr | 726 | - (void)fillWithWidgetValue: (void *)wvptr |
| 724 | { | 727 | { |
| 728 | [self fillWithWidgetValue: wvptr setDelegate:NO]; | ||
| 729 | } | ||
| 730 | |||
| 731 | - (void)fillWithWidgetValue: (void *)wvptr setDelegate: (BOOL)set | ||
| 732 | { | ||
| 725 | widget_value *wv = (widget_value *)wvptr; | 733 | widget_value *wv = (widget_value *)wvptr; |
| 726 | 734 | ||
| 727 | /* clear existing contents */ | 735 | /* clear existing contents */ |
| @@ -737,6 +745,9 @@ extern NSString *NSMenuDidBeginTrackingNotification; | |||
| 737 | { | 745 | { |
| 738 | EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: [item title]]; | 746 | EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: [item title]]; |
| 739 | 747 | ||
| 748 | #ifdef NS_IMPL_COCOA | ||
| 749 | if (set) [submenu setDelegate: submenu]; | ||
| 750 | #endif | ||
| 740 | [self setSubmenu: submenu forItem: item]; | 751 | [self setSubmenu: submenu forItem: item]; |
| 741 | [submenu fillWithWidgetValue: wv->contents]; | 752 | [submenu fillWithWidgetValue: wv->contents]; |
| 742 | [submenu release]; | 753 | [submenu release]; |