[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/ns/refactor f766a85 5/8: Fix GNUstep menu update crashes
From: |
Alan Third |
Subject: |
scratch/ns/refactor f766a85 5/8: Fix GNUstep menu update crashes |
Date: |
Sat, 12 Jun 2021 16:48:53 -0400 (EDT) |
branch: scratch/ns/refactor
commit f766a855b3d946c67c65393f5fd1cc89dfefed74
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>
Fix GNUstep menu update crashes
* src/nsmenu.m (ns_update_menubar): close the submenus before modifying
them.
([EmacsMenu close]): Make sure to close all submenus.
---
src/nsmenu.m | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 1d3e1ac..1b03fe9 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -359,7 +359,11 @@ ns_update_menubar (struct frame *f, bool deep_p)
{
NSString *titleStr = [NSString stringWithUTF8String: wv->name];
NSMenuItem *item = (NSMenuItem *)[menu itemAtIndex:i];
- submenu = (EmacsMenu*)[item submenu];
+ submenu = (EmacsMenu *)[item submenu];
+
+#ifdef NS_IMPL_GNUSTEP
+ [submenu close];
+#endif
[item setTitle:titleStr];
[submenu setTitle:titleStr];
@@ -382,6 +386,12 @@ ns_update_menubar (struct frame *f, bool deep_p)
while (i < [menu numberOfItems])
{
/* Remove any extra items. */
+#ifdef NS_IMPL_GNUSTEP
+ NSMenuItem *item = (NSMenuItem *)[menu itemAtIndex:i];
+ EmacsMenu *submenu = (EmacsMenu *)[item submenu];
+ [submenu close];
+#endif
+
[menu removeItemAtIndex:i];
}
@@ -715,20 +725,38 @@ prettify_key (const char *key)
}
#ifdef NS_IMPL_GNUSTEP
+- (void) close
+{
+ /* Close all the submenus. This has the unfortunate side-effect of
+ breaking tear-off menus, however if we don't do this then we get
+ a crash when the menus are removed during updates. */
+ for (int i = 0 ; i < [self numberOfItems] ; i++)
+ {
+ NSMenuItem *item = [self itemAtIndex:i];
+ if ([item hasSubmenu])
+ [(EmacsMenu *)[item submenu] close];
+ }
+
+ [super close];
+}
+
/* GNUstep seems to have a number of required methods in
NSMenuDelegate that are optional in Cocoa. */
- (void) menuWillOpen:(NSMenu *)menu
{
}
+
- (void) menuDidClose:(NSMenu *)menu
{
}
+
- (NSRect)confinementRectForMenu:(NSMenu *)menu
onScreen:(NSScreen *)screen
{
return NSZeroRect;
}
+
- (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item
{
}
- branch scratch/ns/refactor created (now 06aa958), Alan Third, 2021/06/12
- scratch/ns/refactor f77cdc1 1/8: Simplify macOS drawing code, Alan Third, 2021/06/12
- scratch/ns/refactor 17c9369 2/8: Fix GNUstep build warnings, Alan Third, 2021/06/12
- scratch/ns/refactor 7d71f37 3/8: Tidy up NS port OS window handling, Alan Third, 2021/06/12
- scratch/ns/refactor 27df712 4/8: Change NS port resize detection, Alan Third, 2021/06/12
- scratch/ns/refactor f766a85 5/8: Fix GNUstep menu update crashes,
Alan Third <=
- scratch/ns/refactor 6cbbfa0 6/8: Fix macOS live resize drawing, Alan Third, 2021/06/12
- scratch/ns/refactor 13dd79a 7/8: Move NS port toolbar handling to the window, Alan Third, 2021/06/12
- scratch/ns/refactor 06aa958 8/8: Move parent frame setting code into EmacsWindow, Alan Third, 2021/06/12