Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit bb6954b

Browse files
[[ Bug 13836 ]] Change the update system to allow the update each time the menubar is clicked
1 parent a46f7a6 commit bb6954b

File tree

2 files changed

+64
-49
lines changed

2 files changed

+64
-49
lines changed

engine/src/desktop-menu.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -903,27 +903,36 @@ void MCPlatformHandleMenuUpdate(MCPlatformMenuRef p_menu)
903903
uindex_t t_parent_menu_index;
904904
MCPlatformGetMenuParent(p_menu, t_parent_menu, t_parent_menu_index);
905905

906-
// If the parent menu is not the menubar, we aren't interested.
907-
if (t_parent_menu != s_menubar)
908-
return;
906+
// SN-2014-11-10: [[ Bug 13836 ]] We can also be the menubar's LiveCode item - in which case an
907+
// update is allowed as well
908+
bool t_update_menubar;
909+
t_update_menubar = p_menu == s_menubar;
910+
911+
// If the parent menu is not the menubar, we aren't interested.
912+
if (t_parent_menu != s_menubar && !t_update_menubar)
913+
return;
909914

910915
// If the button it is 'attached' to still exists, dispatch the menu update
911916
// message (currently mouseDown("")). We do this whilst the menubar is locked
912917
// from updates as we mustn't fiddle about with it too much in this case!
913-
if (s_menubar_targets[t_parent_menu_index] -> Exists())
918+
if (t_update_menubar || s_menubar_targets[t_parent_menu_index] -> Exists())
914919
{
915920
// MW-2014-06-10: [[ Bug 12590 ]] Make sure we lock screen around the menu update message.
916921
MCRedrawLockScreen();
917922
s_menubar_lock_count += 1;
918-
// SN-2014-11-06: [[ Bug 13940 ]] Keep the behaviour as previously: mouseDown "" is sent when updating menus
919-
s_menubar_targets[t_parent_menu_index] -> Get() -> message_with_args(MCM_mouse_down, "");
923+
// SN-2014-11-06: [[ Bug 13836 ]] MCmenubar (or MCdefaultmenubar) should get mouseDown, not the target (it gets menuPick)
924+
if (MCmenubar != nil)
925+
MCmenubar -> message_with_args(MCM_mouse_down, "1");
926+
else if (MCdefaultmenubar != nil)
927+
MCdefaultmenubar -> message_with_args(MCM_mouse_down, "1");
920928
s_menubar_lock_count -= 1;
921929
MCRedrawUnlockScreen();
922930
}
923931

932+
// SN-2014-11-10: [[ Bug 13836 ]] Make sure that
924933
// Now we've got the menu to update, process the new menu spec, but only if the
925934
// menu button still exists!
926-
if (s_menubar_targets[t_parent_menu_index] -> Exists())
935+
if (!t_update_menubar && s_menubar_targets[t_parent_menu_index] -> Exists())
927936
{
928937
MCButton *t_button;
929938
t_button = (MCButton *)s_menubar_targets[t_parent_menu_index] -> Get();

engine/src/mac-menu.mm

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
static uint32_t s_menu_select_lock = 0;
3939
// SN-2014-11-06: [[ Bug 13836 ]] Stores whether a shadowed item got selected
4040
static 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
////////////////////////////////////////////////////////////////////////////////
@@ -64,9 +66,6 @@
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)
519542
void 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

526547
void 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

564579
void 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

575587
void 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

585594
void 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

Comments
 (0)