Received: from eggs.gnu.org ([2001:4830:134:3::10]:44053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YrpTE-0007AH-ES for qemu-devel@nongnu.org; Mon, 11 May 2015 11:18:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YrpT8-0000Bx-C4 for qemu-devel@nongnu.org; Mon, 11 May 2015 11:18:16 -0400 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]:34768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YrpT8-0000Bs-5p for qemu-devel@nongnu.org; Mon, 11 May 2015 11:18:10 -0400 Received: by qgfi89 with SMTP id i89so69340555qgf.1 for ; Mon, 11 May 2015 08:18:09 -0700 (PDT) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Mon, 11 May 2015 11:18:07 -0400 Message-Id: <30C61AFC-7A08-4F94-A7B1-0DAAA58DC017@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [patch v5] ui/cocoa.m: Adds console items to the View menu List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel qemu-devel Adds any console that is available to the current emulator as a menu = item under the View menu. Signed-off-by: John Arbuckle --- Removed the initConsoleVariables() function. Removed global variables. Rewrote how console menu items are added. ui/cocoa.m | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 42 insertions(+), 8 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index d37c29b..b4b7adb 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -801,6 +801,7 @@ QemuCocoaView *cocoaView; - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)showQEMUTec:(id)sender; +- (void)displayConsole:(id)sender; @end =20 @implementation QemuCocoaAppController @@ -943,8 +944,14 @@ QemuCocoaView *cocoaView; [[NSWorkspace sharedWorkspace] openFile:[NSString = stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help = Viewer"]; } -@end =20 +/* Displays the console on the screen */ +- (void)displayConsole:(id)sender +{ + console_select([sender tag]); +} + +@end =20 =20 int main (int argc, const char * argv[]) { @@ -1003,13 +1010,6 @@ int main (int argc, const char * argv[]) { [[NSApp mainMenu] addItem:menuItem]; [NSApp performSelector:@selector(setAppleMenu:) withObject:menu]; = // Workaround (this method is private since 10.4+) =20 - // View menu - menu =3D [[NSMenu alloc] initWithTitle:@"View"]; - [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter = Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] = autorelease]]; // Fullscreen - menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"View" action:nil = keyEquivalent:@""] autorelease]; - [menuItem setSubmenu:menu]; - [[NSApp mainMenu] addItem:menuItem]; - // Window menu menu =3D [[NSMenu alloc] initWithTitle:@"Window"]; [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" = action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; = // Miniaturize @@ -1116,6 +1116,37 @@ static const DisplayChangeListenerOps dcl_ops =3D = { .dpy_refresh =3D cocoa_refresh, }; =20 +// Returns a name for a given console +static NSString * getConsoleName(QemuConsole * console) +{ + return [NSString stringWithFormat: @"%s", = qemu_console_get_label(console)]; +} + +// Creates the view menu +static void create_view_menu() +{ + NSMenu * menu; + NSMenuItem * menuItem; + int index =3D 0; + + menu =3D [[NSMenu alloc] initWithTitle:@"View"]; + [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter = Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] = autorelease]]; // Fullscreen + [menu addItem:[NSMenuItem separatorItem]]; //Separator + + // Give each console its own menu item in the View menu + while(qemu_console_lookup_by_index(index) !=3D NULL) { + menuItem =3D [[[NSMenuItem alloc] initWithTitle: = getConsoleName(qemu_console_lookup_by_index(index)) + action: = @selector(displayConsole:) keyEquivalent: @""] autorelease]; + [menuItem setTag: index]; + [menu addItem: menuItem]; + index++; + } + + menuItem =3D [[[NSMenuItem alloc] initWithTitle:@"View" action:nil = keyEquivalent:@""] autorelease]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] insertItem: menuItem atIndex: 1]; // insert View = menu after Application menu +} + void cocoa_display_init(DisplayState *ds, int full_screen) { COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); @@ -1128,4 +1159,7 @@ void cocoa_display_init(DisplayState *ds, int = full_screen) =20 // register cleanup function atexit(cocoa_cleanup); + + // QEMU needs to be running first before we can create the view = menu + create_view_menu(); } --=20 1.7.5.4