3838static uint32_t s_menu_select_lock = 0 ;
3939// SN-2014-11-06: [[ Bug 13836 ]] Stores whether a shadowed item got selected
4040static bool s_shadow_item_selected = false ;
41+ // SN-2014-11-10: [[ Bug 13836 ]] Keeps the track about the open items in the menu bar.
42+ static uint32_t s_open_menubar_items = 0 ;
4143
4244
4345// //////////////////////////////////////////////////////////////////////////////
6466 // SN-2014-11-06: [[ Bu 13940 ]] Add a flag for the presence of a Preferences shortcut
6567 // to allow the menu item to be disabled.
6668 bool preferences_has_accelerator : 1 ;
67-
68- // SN-2014-11-06: [[ Bug 13836 ]] Set to true if the menu needs to be updated.
69- bool needs_update : 1 ;
7069};
7170
7271// //////////////////////////////////////////////////////////////////////////////
@@ -159,23 +158,22 @@ - (void)hideShadowedMenuItem:(NSString *)tag menu:(NSMenu *)menu
159158
160159- (void )menuNeedsUpdate : (NSMenu *)menu
161160{
162- // SN-2014-11-06: [[ Bug 13836 ]] Ensure that the menu is only updated if needed...
163- // SN-2014-11-06: [[ Bug 13849 ]] ...since rebuilding a menubar sends mouseDown to it
164- if (m_menu -> needs_update)
161+ // SN-2014-11-10: [[ Bug 13836 ]] Only allow the menu to refresh the whole menubar if
162+ // it is the first click on the menubar (otherwise, clicking and sliding would refresh
163+ // the menubar each the item hovered changes)...
164+ // SN-2014-11-06: [[ Bug 13849 ]] ...since rebuilding a menubar sends mouseDown to the menubar
165+ if ([menu supermenu ] == nil || !s_open_menubar_items)
165166 {
166167 MCPlatformCallbackSendMenuUpdate (m_menu);
167-
168- // MW-2014-10-29: [[ Bug 13848 ]] Only do the item hiding if this is part of a menubar
169- // (not a popup menu).
170- if ([menu supermenu ] != nil )
171- {
172- [self hideShadowedMenuItem: @" About" menu: menu];
173- [self hideShadowedMenuItem: @" Preferences" menu: menu];
174- [self hideShadowedMenuItem: @" Quit" menu: menu];
175- }
176-
177- // SN-2014-22-06: [[ Bug 13836 ]] This menu is now up-to-date
178- m_menu -> needs_update = false ;
168+ }
169+
170+ // MW-2014-10-29: [[ Bug 13848 ]] Only do the item hiding if this is part of a menubar
171+ // (not a popup menu).
172+ if ([menu supermenu ] != nil )
173+ {
174+ [self hideShadowedMenuItem: @" About" menu: menu];
175+ [self hideShadowedMenuItem: @" Preferences" menu: menu];
176+ [self hideShadowedMenuItem: @" Quit" menu: menu];
179177 }
180178}
181179
@@ -219,6 +217,23 @@ - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id
219217 return NO ;
220218}
221219
220+ // ////////
221+
222+ // SN-2014-11-10: [[ Bug 13836 ]] We want to know how many items are open in the menubar,
223+ // When sliding after having clicked in the menubar, the new item receives menuWillOpen
224+ // before the other one receives menuWillClose.
225+ - (void )menuWillOpen : (NSMenu *)menu
226+ {
227+ if ([s_menubar -> menu isEqualTo: [menu supermenu ]])
228+ s_open_menubar_items++;
229+ }
230+
231+ - (void )menuDidClose : (NSMenu *)menu
232+ {
233+ if ([s_menubar -> menu isEqualTo: [menu supermenu ]])
234+ s_open_menubar_items--;
235+ }
236+
222237@end
223238
224239@implementation com_runrev_livecode_MCAppMenuDelegate
@@ -297,9 +312,11 @@ - (void)quitApplicationSelected: (id)sender
297312 [t_app terminate: t_app];
298313}
299314
300- // SN-2014-11-06 : [[ Bug 13940 ]] menuNeedsUpdate not longer needed at the Application level
315+ // SN-2014-11-10 : [[ Bug 13836 ]] The menubar should be updated if left item is clicked
301316- (void )menuNeedsUpdate : (NSMenu *)menu
302317{
318+ if (!s_open_menubar_items)
319+ MCPlatformCallbackSendMenuUpdate (s_menubar);
303320}
304321
305322- (BOOL )validateMenuItem : (NSMenuItem *)item
@@ -319,6 +336,18 @@ - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id
319336 return NO ;
320337}
321338
339+ // ////////
340+
341+ - (void )menuWillOpen : (NSMenu *)menu
342+ {
343+ s_open_menubar_items++;
344+ }
345+
346+ - (void )menuDidClose : (NSMenu *)menu
347+ {
348+ s_open_menubar_items--;
349+ }
350+
322351@end
323352
324353// //////////////////////////////////////////////////////////////////////////////
@@ -444,9 +473,6 @@ static void MCPlatformDestroyMenuItem(MCPlatformMenuRef p_menu, uindex_t p_index
444473 // Update the submenu pointer (so we don't have any dangling
445474 // refs).
446475 [t_item setSubmenu: nil ];
447-
448- // SN-2014-11-06: [[ Bug 13836 ]] This menu needs to be updated in the next menuNeedsUpdate.
449- p_menu -> needs_update = true ;
450476
451477 // Now release the platform menu.
452478 MCPlatformReleaseMenu (t_submenu_ref);
@@ -481,9 +507,6 @@ void MCPlatformCreateMenu(MCPlatformMenuRef& r_menu)
481507 t_menu -> menu_delegate = [[MCMenuDelegate alloc ] initWithPlatformMenuRef: t_menu];
482508 [t_menu -> menu setDelegate: t_menu -> menu_delegate];
483509 t_menu -> is_menubar = false ;
484-
485- // SN-2014-11-06: [[ Bug 13836 ]] This menu needs to be updated in the next menuNeedsUpdate.
486- t_menu -> needs_update = false ;
487510
488511 // Turn on auto-enablement - this allows dialogs to control the enablement
489512 // of items with appropriate tag.
@@ -519,8 +542,6 @@ void MCPlatformReleaseMenu(MCPlatformMenuRef p_menu)
519542void MCPlatformSetMenuTitle (MCPlatformMenuRef p_menu, const char *p_title)
520543{
521544 [p_menu -> menu setTitle: [NSString stringWithCString: p_title encoding: NSUTF8StringEncoding]];
522- // SN-2014-11-06: [[ Bug 13836 ]] This menu needs to be updated in the next menuNeedsUpdate.
523- p_menu -> needs_update = true ;
524545}
525546
526547void MCPlatformCountMenuItems (MCPlatformMenuRef p_menu, uindex_t & r_count)
@@ -544,9 +565,6 @@ void MCPlatformAddMenuItem(MCPlatformMenuRef p_menu, uindex_t p_where)
544565
545566 // Insert the item in the menu.
546567 [p_menu -> menu insertItem: t_item atIndex: p_where];
547-
548- // SN-2014-11-06: [[ Bug 13836 ]] This menu needs to be updated in the next menuNeedsUpdate.
549- p_menu -> needs_update = true ;
550568
551569 [t_item release ];
552570}
@@ -556,9 +574,6 @@ void MCPlatformAddMenuSeparatorItem(MCPlatformMenuRef p_menu, uindex_t p_where)
556574 MCPlatformClampMenuItemIndex (p_menu, p_where);
557575
558576 [p_menu -> menu insertItem: [NSMenuItem separatorItem ] atIndex: p_where];
559-
560- // SN-2014-11-06: [[ Bug 13836 ]] This menu needs to be updated in the next menuNeedsUpdate.
561- p_menu -> needs_update = true ;
562577}
563578
564579void MCPlatformRemoveMenuItem (MCPlatformMenuRef p_menu, uindex_t p_where)
@@ -567,19 +582,13 @@ void MCPlatformRemoveMenuItem(MCPlatformMenuRef p_menu, uindex_t p_where)
567582
568583 MCPlatformDestroyMenuItem (p_menu, p_where);
569584 [p_menu -> menu removeItemAtIndex: p_where];
570-
571- // SN-2014-11-06: [[ Bug 13836 ]] This menu needs to be updated in the next menuNeedsUpdate.
572- p_menu -> needs_update = true ;
573585}
574586
575587void MCPlatformRemoveAllMenuItems (MCPlatformMenuRef p_menu)
576588{
577589 for (uindex_t i = 0 ; i < [p_menu -> menu numberOfItems ]; i++)
578590 MCPlatformDestroyMenuItem (p_menu, i);
579591 [p_menu -> menu removeAllItems ];
580-
581- // SN-2014-11-06: [[ Bug 13836 ]] This menu needs to be updated in the next menuNeedsUpdate.
582- p_menu -> needs_update = true ;
583592}
584593
585594void MCPlatformGetMenuParent (MCPlatformMenuRef p_menu, MCPlatformMenuRef& r_parent, uindex_t & r_index)
@@ -626,9 +635,6 @@ void MCPlatformSetMenuItemProperty(MCPlatformMenuRef p_menu, uindex_t p_index, M
626635
627636 NSMenuItem *t_item;
628637 t_item = [p_menu -> menu itemAtIndex: p_index];
629-
630- // SN-2014-11-06: [[ Bug 13836 ]] This menu needs to be updated in the next menuNeedsUpdate.
631- p_menu -> needs_update = true ;
632638
633639 switch (p_property)
634640 {
0 commit comments