electron/atom/browser/atom_browser_main_parts_mac.mm
Electron Bot 164cc43440 chore: bump chromium to bd6aad6a4b37dad7aae42fec349e9 (master) (#18626)
* chore: bump chromium in DEPS to f200986dfaabd6aad6a4b37dad7aae42fec349e9

* chore: BridgedNativeWidgetImpl was renamed to NativeWidgetMacNSWindowHost

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1640804

* refactor: remove MainMenu.xib as Chromium has removed its dependency on xcode and therefore all xibs

As we set default menus in JS land the default native menu is tiny, just
has a Quit button

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1627242

* chore: update zip manifests
2019-06-04 17:27:07 -07:00

80 lines
2.6 KiB
Text

// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/atom_paths.h"
#include "atom/browser/mac/atom_application_delegate.h"
namespace atom {
namespace {
base::scoped_nsobject<NSMenuItem> CreateMenuItem(NSString* title,
SEL action,
NSString* key_equivalent) {
return base::scoped_nsobject<NSMenuItem>([[NSMenuItem alloc]
initWithTitle:title
action:action
keyEquivalent:key_equivalent]);
}
// The App Menu refers to the dropdown titled "Electron".
base::scoped_nsobject<NSMenu> BuildAppMenu() {
// The title is not used, as the title will always be the name of the App.
base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
NSString* app_name = [[[NSBundle mainBundle] infoDictionary]
objectForKey:(id)kCFBundleNameKey];
base::scoped_nsobject<NSMenuItem> item =
CreateMenuItem([NSString stringWithFormat:@"Quit %@", app_name],
@selector(terminate:), @"q");
[menu addItem:item];
return menu;
}
base::scoped_nsobject<NSMenu> BuildEmptyMainMenu() {
base::scoped_nsobject<NSMenu> main_menu([[NSMenu alloc] initWithTitle:@""]);
using Builder = base::scoped_nsobject<NSMenu> (*)();
static const Builder kBuilderFuncs[] = {&BuildAppMenu};
for (auto* builder : kBuilderFuncs) {
NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:@""
action:NULL
keyEquivalent:@""] autorelease];
item.submenu = builder();
[main_menu addItem:item];
}
return main_menu;
}
} // namespace
void AtomBrowserMainParts::PreMainMessageLoopStart() {
// Set our own application delegate.
AtomApplicationDelegate* delegate = [[AtomApplicationDelegate alloc] init];
[NSApp setDelegate:delegate];
PreMainMessageLoopStartCommon();
// Prevent Cocoa from turning command-line arguments into
// |-application:openFiles:|, since we already handle them directly.
[[NSUserDefaults standardUserDefaults]
setObject:@"NO"
forKey:@"NSTreatUnknownArgumentsAsOpen"];
}
void AtomBrowserMainParts::FreeAppDelegate() {
[[NSApp delegate] release];
[NSApp setDelegate:nil];
}
void AtomBrowserMainParts::InitializeEmptyApplicationMenu() {
base::scoped_nsobject<NSMenu> main_menu = BuildEmptyMainMenu();
[[NSApplication sharedApplication] setMainMenu:main_menu];
}
} // namespace atom