xquartz: Fold away array_with_strings_and_numbers and simplify with more modern Objective-C
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
This commit is contained in:
parent
87f8fe1f74
commit
39c0e1c0ab
|
@ -901,48 +901,28 @@ cfarray_to_nsarray(CFArrayRef in)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static NSArray *
|
|
||||||
array_with_strings_and_numbers(int nitems, const char **items,
|
|
||||||
const char *numbers)
|
|
||||||
{
|
|
||||||
NSMutableArray *array, *subarray;
|
|
||||||
NSString *string, *number;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
array = [[[NSMutableArray alloc] initWithCapacity:nitems] autorelease];
|
|
||||||
|
|
||||||
for (i = 0; i < nitems; i++) {
|
|
||||||
subarray = [[NSMutableArray alloc] initWithCapacity:2];
|
|
||||||
|
|
||||||
string = [[NSString alloc] initWithUTF8String:items[i]];
|
|
||||||
[subarray addObject:string];
|
|
||||||
[string release];
|
|
||||||
|
|
||||||
if (numbers[i] != 0) {
|
|
||||||
number = [[NSString alloc] initWithFormat:@"%d", numbers[i]];
|
|
||||||
[subarray addObject:number];
|
|
||||||
[number release];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
[subarray addObject:@""];
|
|
||||||
|
|
||||||
[array addObject:subarray];
|
|
||||||
[subarray release];
|
|
||||||
}
|
|
||||||
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
X11ApplicationSetWindowMenu(int nitems, const char **items,
|
X11ApplicationSetWindowMenu(int nitems, const char **items,
|
||||||
const char *shortcuts)
|
const char *shortcuts)
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSArray *array = array_with_strings_and_numbers(nitems, items, shortcuts);
|
NSMutableArray <NSArray <NSString *> *> * const allMenuItems = [NSMutableArray array];
|
||||||
|
|
||||||
|
for (int i = 0; i < nitems; i++) {
|
||||||
|
NSMutableArray <NSString *> * const menuItem = [NSMutableArray array];
|
||||||
|
[menuItem addObject:@(items[i])];
|
||||||
|
|
||||||
|
if (shortcuts[i] == 0) {
|
||||||
|
[menuItem addObject:@""];
|
||||||
|
} else {
|
||||||
|
[menuItem addObject:[NSString stringWithFormat:@"%d", shortcuts[i]]];
|
||||||
|
}
|
||||||
|
|
||||||
|
[allMenuItems addObject:menuItem];
|
||||||
|
}
|
||||||
|
|
||||||
/* Send the array of strings over to the appkit thread */
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[X11App set_window_menu:array];
|
[X11App set_window_menu:allMenuItems];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue