From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: patches@linaro.org, John Arbuckle <programmingkidx@gmail.com>,
Berkus Decker <berkus@gmail.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Roman Bolshakov <r.bolshakov@yadro.com>
Subject: [Qemu-devel] [RFC 4/5] ui/cocoa: Move console/device menu creation code up in file
Date: Sat, 1 Dec 2018 12:30:55 +0000 [thread overview]
Message-ID: <20181201123056.432-5-peter.maydell@linaro.org> (raw)
In-Reply-To: <20181201123056.432-1-peter.maydell@linaro.org>
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 <peter.maydell@linaro.org>
---
ui/cocoa.m | 184 ++++++++++++++++++++++++++---------------------------
1 file changed, 92 insertions(+), 92 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index da511bfb4fa..2f533c77c47 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1531,6 +1531,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;
@@ -1659,98 +1751,6 @@ static const DisplayChangeListenerOps dcl_ops = {
.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");
--
2.19.2
next prev parent reply other threads:[~2018-12-01 12:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-01 12:30 [Qemu-devel] [RFC 0/5] ui/cocoa: Use OSX's main loop Peter Maydell
2018-12-01 12:30 ` [Qemu-devel] [RFC 1/5] ui/cocoa: Ensure we have the iothread lock when calling into QEMU Peter Maydell
2018-12-01 12:30 ` [Qemu-devel] [RFC 2/5] ui/cocoa: Use the pixman image directly in switchSurface Peter Maydell
2018-12-01 12:30 ` [Qemu-devel] [RFC 3/5] ui/cocoa: Factor out initial menu creation Peter Maydell
2018-12-01 12:30 ` Peter Maydell [this message]
2018-12-01 12:30 ` [Qemu-devel] [RFC 5/5] ui/cocoa: Perform UI operations only on the main thread Peter Maydell
2018-12-03 15:47 ` [Qemu-devel] [RFC 0/5] ui/cocoa: Use OSX's main loop Richard Henderson
2018-12-05 6:51 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181201123056.432-5-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=berkus@gmail.com \
--cc=kraxel@redhat.com \
--cc=patches@linaro.org \
--cc=programmingkidx@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=r.bolshakov@yadro.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).