From patchwork Thu Feb 14 10:28:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 158346 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1175267jaa; Thu, 14 Feb 2019 02:28:25 -0800 (PST) X-Received: by 2002:a7b:c413:: with SMTP id k19mr2159439wmi.75.1550140104887; Thu, 14 Feb 2019 02:28:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550140104; cv=none; d=google.com; s=arc-20160816; b=B75MrjGgywbNIK2Oh2QzKaulBriy/APqfY1LJHnm+fZdD9a91ide/mxGsHucQHoqWv VGkDYlWlxDKdzxSF4SezYcZfI4EIqz18xF4MK2EZ3aCMsrvsOlFl5RItWCtmMFWvMJbM 0jiDl/wzM2wR/P1gF9oG9hI5qcV2I1mWuFeVqp+js5Kkpx25st0mTxHHgN/TG9frCZ3B iCYD1jKrZourXGh3MEUnHHXCSvQkW+uOR0huR8E0AQx/3a2OOtZ+VKjv6Q8LtKgmD+T9 SwnlAYtELB6VBYumZFyrMvx1ArRkW+B+sSOdtHyRG2W3Nf38KNImnmrjoUfvw3UIyqrv GV7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=S6NYZnQQZrqoXz0/AWPoW7pHcNDCfRFCnTCPJKk+rd0=; b=rLA077HsUOeQ8b6IVPwo2/DYM15tFQ0RWu38DgiLu10Wq6Xc+mYkWt25HbbZm4K0zZ Bxb1lHSLUhA2MoxLoqTBnZ3X+EcoKTwKyji3mbw4FTwIiFnlEKtaZqAWLh9RcWj/DJDO jtoYaEFRF20aDlwCHXdsUhRg8WoKFRG6OMign+HK/BnOvyhpHubOZd+OGYjIYQdOkVTF z3eTVyOV7u7hj7kWrKMv7RUUF5ed79gnEU7FDEW6ATA8/mWLIcl79ZooUI+yt0g07myR Z6eQbdtLwzVVZppTh4zY+7StK69X3c0JcFj41v4/3rSlx7kFs+/BK45qQrUDNzrgfBjL YPbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d1OVXcoA; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y13sor1319582wru.50.2019.02.14.02.28.24 for (Google Transport Security); Thu, 14 Feb 2019 02:28:24 -0800 (PST) Received-SPF: pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d1OVXcoA; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S6NYZnQQZrqoXz0/AWPoW7pHcNDCfRFCnTCPJKk+rd0=; b=d1OVXcoAwY1aIZvEcmm++wjFN253AV4VQl+rFHGGPUfTVh26PDDT4jlXXkn/ruNpja aaynfghXEUeIlzRzNd7zAqe5TO20Vc9KU6H431eTajTE2tBBzFOPgw5bXKdY2Zq4F864 H/7lDqcjcasXJ1bhXmE71EPouWoel6xIAkNMpgKALmlQu//j35Us/kIiSAhlS3qEiXO2 tthxLbIPNPc9oPOE5ZCkOfM1i1ablJQYy71xxlF5gMHHkDfusDd/rHs7cB5tit4ddNFD vecJAtWvPbTThQDF1HMv58BkmcxH/6Br245v+Ywk0kEQHrzpSJb/gyoO4Uy6/fQ0QBxc YDiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S6NYZnQQZrqoXz0/AWPoW7pHcNDCfRFCnTCPJKk+rd0=; b=EmlIcU9zy5UmOxdnW62P4A1YbP7YdpiOfrw5tfJYxjM6FzrpvMX5I5/OCfVZPIrOx6 Pbed9VgZB/7gsdiR+GJ5XzrSRdWselV/v/OuneeWUENYpBTAqGh1jHoNjB51D8l1FUVz SW7wjcQh5dPtIlJ3GbHLGlE64mZJiUjVOEqTyfV6Z9AVjnrlmk4Q4jnQbTRIFLpuz3Uh N7N8OZorQOPSTuISnzeksxmfUvTaT3EHbgaC564/2sNcMeOA611dJat1jgwmch+UM/+g J97cgP3oT+pL8ALFGPeFWSqywi18CLPuLmt/tRP3CKJsK+yHEFmUIkv/khdXVzW6KcSJ vWrg== X-Gm-Message-State: AHQUAubseIHvxmmD5Zxt3UgolfkCF8/Z/c4Tgp/upDDyg/TOSUfGsxzX Pr6OY3XFzqmC6RhUKMZmE42gVqF0 X-Google-Smtp-Source: AHgI3IbZkxlAoLmQmxqjUvG3U0dxgu2Q73ZRZbp4Y70i+wactXs1zqrm0SErSF7axtE+xK53Iqm66w== X-Received: by 2002:a05:6000:92:: with SMTP id m18mr2224568wrx.258.1550140104379; Thu, 14 Feb 2019 02:28:24 -0800 (PST) Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id o5sm6473817wrh.34.2019.02.14.02.28.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 02:28:23 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, John Arbuckle , Roman Bolshakov , Berkus Decker , Gerd Hoffmann , Ben Hekster , BALATON Zoltan Subject: [PATCH v2 4/7] ui/cocoa: Move console/device menu creation code up in file Date: Thu, 14 Feb 2019 10:28:13 +0000 Message-Id: <20190214102816.3393-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102816.3393-1-peter.maydell@linaro.org> References: <20190214102816.3393-1-peter.maydell@linaro.org> MIME-Version: 1.0 Move the console/device menu creation code functions further up in the source file, next to the code which creates the initial menus. We're going to want to change the location we call these functions from in the next patch. This commit is a pure code move with no other changes. Signed-off-by: Peter Maydell --- ui/cocoa.m | 184 ++++++++++++++++++++++++++--------------------------- 1 file changed, 92 insertions(+), 92 deletions(-) -- 2.17.2 (Apple Git-113) Reviewed-by: BALATON Zoltan Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov diff --git a/ui/cocoa.m b/ui/cocoa.m index 0b1cd31543..2d943b6e2a 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -1548,6 +1548,98 @@ static void create_initial_menus(void) [[NSApp mainMenu] addItem:menuItem]; } +/* Returns a name for a given console */ +static NSString * getConsoleName(QemuConsole * console) +{ + return [NSString stringWithFormat: @"%s", qemu_console_get_label(console)]; +} + +/* Add an entry to the View menu for each console */ +static void add_console_menu_entries(void) +{ + NSMenu *menu; + NSMenuItem *menuItem; + int index = 0; + + menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu]; + + [menu addItem:[NSMenuItem separatorItem]]; + + while (qemu_console_lookup_by_index(index) != NULL) { + menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index)) + action: @selector(displayConsole:) keyEquivalent: @""] autorelease]; + [menuItem setTag: index]; + [menu addItem: menuItem]; + index++; + } +} + +/* Make menu items for all removable devices. + * Each device is given an 'Eject' and 'Change' menu item. + */ +static void addRemovableDevicesMenuItems(void) +{ + NSMenu *menu; + NSMenuItem *menuItem; + BlockInfoList *currentDevice, *pointerToFree; + NSString *deviceName; + + currentDevice = qmp_query_block(NULL); + pointerToFree = currentDevice; + if(currentDevice == NULL) { + NSBeep(); + QEMU_Alert(@"Failed to query for block devices!"); + return; + } + + menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu]; + + // Add a separator between related groups of menu items + [menu addItem:[NSMenuItem separatorItem]]; + + // Set the attributes to the "Removable Media" menu item + NSString *titleString = @"Removable Media"; + NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:titleString]; + NSColor *newColor = [NSColor blackColor]; + NSFontManager *fontManager = [NSFontManager sharedFontManager]; + NSFont *font = [fontManager fontWithFamily:@"Helvetica" + traits:NSBoldFontMask|NSItalicFontMask + weight:0 + size:14]; + [attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [titleString length])]; + [attString addAttribute:NSForegroundColorAttributeName value:newColor range:NSMakeRange(0, [titleString length])]; + [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt: 1] range:NSMakeRange(0, [titleString length])]; + + // Add the "Removable Media" menu item + menuItem = [NSMenuItem new]; + [menuItem setAttributedTitle: attString]; + [menuItem setEnabled: NO]; + [menu addItem: menuItem]; + + /* Loop through all the block devices in the emulator */ + while (currentDevice) { + deviceName = [[NSString stringWithFormat: @"%s", currentDevice->value->device] retain]; + + if(currentDevice->value->removable) { + menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Change %s...", currentDevice->value->device] + action: @selector(changeDeviceMedia:) + keyEquivalent: @""]; + [menu addItem: menuItem]; + [menuItem setRepresentedObject: deviceName]; + [menuItem autorelease]; + + menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Eject %s", currentDevice->value->device] + action: @selector(ejectDeviceMedia:) + keyEquivalent: @""]; + [menu addItem: menuItem]; + [menuItem setRepresentedObject: deviceName]; + [menuItem autorelease]; + } + currentDevice = currentDevice->next; + } + qapi_free_BlockInfoList(pointerToFree); +} + int main (int argc, const char * argv[]) { gArgc = argc; @@ -1676,98 +1768,6 @@ static void cocoa_cleanup(void) .dpy_refresh = cocoa_refresh, }; -/* Returns a name for a given console */ -static NSString * getConsoleName(QemuConsole * console) -{ - return [NSString stringWithFormat: @"%s", qemu_console_get_label(console)]; -} - -/* Add an entry to the View menu for each console */ -static void add_console_menu_entries(void) -{ - NSMenu *menu; - NSMenuItem *menuItem; - int index = 0; - - menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu]; - - [menu addItem:[NSMenuItem separatorItem]]; - - while (qemu_console_lookup_by_index(index) != NULL) { - menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index)) - action: @selector(displayConsole:) keyEquivalent: @""] autorelease]; - [menuItem setTag: index]; - [menu addItem: menuItem]; - index++; - } -} - -/* Make menu items for all removable devices. - * Each device is given an 'Eject' and 'Change' menu item. - */ -static void addRemovableDevicesMenuItems(void) -{ - NSMenu *menu; - NSMenuItem *menuItem; - BlockInfoList *currentDevice, *pointerToFree; - NSString *deviceName; - - currentDevice = qmp_query_block(NULL); - pointerToFree = currentDevice; - if(currentDevice == NULL) { - NSBeep(); - QEMU_Alert(@"Failed to query for block devices!"); - return; - } - - menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu]; - - // Add a separator between related groups of menu items - [menu addItem:[NSMenuItem separatorItem]]; - - // Set the attributes to the "Removable Media" menu item - NSString *titleString = @"Removable Media"; - NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:titleString]; - NSColor *newColor = [NSColor blackColor]; - NSFontManager *fontManager = [NSFontManager sharedFontManager]; - NSFont *font = [fontManager fontWithFamily:@"Helvetica" - traits:NSBoldFontMask|NSItalicFontMask - weight:0 - size:14]; - [attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [titleString length])]; - [attString addAttribute:NSForegroundColorAttributeName value:newColor range:NSMakeRange(0, [titleString length])]; - [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt: 1] range:NSMakeRange(0, [titleString length])]; - - // Add the "Removable Media" menu item - menuItem = [NSMenuItem new]; - [menuItem setAttributedTitle: attString]; - [menuItem setEnabled: NO]; - [menu addItem: menuItem]; - - /* Loop through all the block devices in the emulator */ - while (currentDevice) { - deviceName = [[NSString stringWithFormat: @"%s", currentDevice->value->device] retain]; - - if(currentDevice->value->removable) { - menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Change %s...", currentDevice->value->device] - action: @selector(changeDeviceMedia:) - keyEquivalent: @""]; - [menu addItem: menuItem]; - [menuItem setRepresentedObject: deviceName]; - [menuItem autorelease]; - - menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Eject %s", currentDevice->value->device] - action: @selector(ejectDeviceMedia:) - keyEquivalent: @""]; - [menu addItem: menuItem]; - [menuItem setRepresentedObject: deviceName]; - [menuItem autorelease]; - } - currentDevice = currentDevice->next; - } - qapi_free_BlockInfoList(pointerToFree); -} - static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) { COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");