2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-02 12:09:19 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/atom_browser_main_parts.h"
|
2013-05-02 12:09:19 +00:00
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/atom_paths.h"
|
|
|
|
#include "shell/browser/mac/atom_application_delegate.h"
|
2013-05-02 12:09:19 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2013-05-02 12:09:19 +00:00
|
|
|
|
2019-06-05 00:27:07 +00:00
|
|
|
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
|
|
|
|
|
2013-05-02 12:09:19 +00:00
|
|
|
void AtomBrowserMainParts::PreMainMessageLoopStart() {
|
2016-01-08 04:06:06 +00:00
|
|
|
// Set our own application delegate.
|
2014-11-16 15:04:31 +00:00
|
|
|
AtomApplicationDelegate* delegate = [[AtomApplicationDelegate alloc] init];
|
2016-08-05 20:57:33 +00:00
|
|
|
[NSApp setDelegate:delegate];
|
2013-05-02 12:09:19 +00:00
|
|
|
|
2018-10-23 20:15:55 +00:00
|
|
|
PreMainMessageLoopStartCommon();
|
2013-05-31 02:17:40 +00:00
|
|
|
|
|
|
|
// Prevent Cocoa from turning command-line arguments into
|
|
|
|
// |-application:openFiles:|, since we already handle them directly.
|
|
|
|
[[NSUserDefaults standardUserDefaults]
|
2018-04-20 18:47:04 +00:00
|
|
|
setObject:@"NO"
|
|
|
|
forKey:@"NSTreatUnknownArgumentsAsOpen"];
|
2013-05-02 12:09:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-04 09:23:27 +00:00
|
|
|
void AtomBrowserMainParts::FreeAppDelegate() {
|
2014-11-17 01:52:24 +00:00
|
|
|
[[NSApp delegate] release];
|
|
|
|
[NSApp setDelegate:nil];
|
2013-05-30 08:03:10 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 00:27:07 +00:00
|
|
|
void AtomBrowserMainParts::InitializeEmptyApplicationMenu() {
|
|
|
|
base::scoped_nsobject<NSMenu> main_menu = BuildEmptyMainMenu();
|
|
|
|
[[NSApplication sharedApplication] setMainMenu:main_menu];
|
2018-10-23 20:15:55 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|