diff --git a/atom.gyp b/atom.gyp index d50255a563ef..f9ad09bc4287 100644 --- a/atom.gyp +++ b/atom.gyp @@ -31,12 +31,17 @@ 'browser/api/atom_api_window.h', 'browser/api/atom_browser_bindings.cc', 'browser/api/atom_browser_bindings.h', + 'browser/atom_application.h', + 'browser/atom_application.mm', + 'browser/atom_application_delegate.h', + 'browser/atom_application_delegate.mm', 'browser/atom_browser_client.cc', 'browser/atom_browser_client.h', 'browser/atom_browser_context.cc', 'browser/atom_browser_context.h', 'browser/atom_browser_main_parts.cc', 'browser/atom_browser_main_parts.h', + 'browser/atom_browser_main_parts_mac.mm', 'browser/atom_event_processing_window.h', 'browser/atom_event_processing_window.mm', 'browser/atom_javascript_dialog_manager.cc', diff --git a/browser/atom_application.h b/browser/atom_application.h new file mode 100644 index 000000000000..b755004b4cef --- /dev/null +++ b/browser/atom_application.h @@ -0,0 +1,23 @@ +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "base/mac/scoped_sending_event.h" + +@interface AtomApplication : NSApplication { + @private + BOOL handlingSendEvent_; +} + +// CrAppProtocol: +- (BOOL)isHandlingSendEvent; + +// CrAppControlProtocol: +- (void)setHandlingSendEvent:(BOOL)handlingSendEvent; + ++ (AtomApplication*)sharedApplication; + +- (IBAction)closeAllWindows:(id)sender; + +@end diff --git a/browser/atom_application.mm b/browser/atom_application.mm new file mode 100644 index 000000000000..3a377bc69222 --- /dev/null +++ b/browser/atom_application.mm @@ -0,0 +1,36 @@ +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "browser/atom_application.h" + +#include "base/auto_reset.h" +#include "base/logging.h" +#include "browser/native_window.h" + +@implementation AtomApplication + +- (BOOL)isHandlingSendEvent { + return handlingSendEvent_; +} + +- (void)sendEvent:(NSEvent*)event { + base::AutoReset scoper(&handlingSendEvent_, YES); + [super sendEvent:event]; +} + +- (void)setHandlingSendEvent:(BOOL)handlingSendEvent { + handlingSendEvent_ = handlingSendEvent; +} + ++ (AtomApplication*)sharedApplication { + return (AtomApplication*)[super sharedApplication]; +} + +- (IBAction)closeAllWindows:(id)sender { + std::vector windows = atom::NativeWindow::windows(); + for (size_t i = 0; i < windows.size(); ++i) + windows[i]->Close(); +} + +@end diff --git a/browser/atom_application_delegate.h b/browser/atom_application_delegate.h new file mode 100644 index 000000000000..ba8bab07b701 --- /dev/null +++ b/browser/atom_application_delegate.h @@ -0,0 +1,13 @@ +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import + +@interface AtomApplicationDelegate : NSObject { +} + +- (void)handleQuitEvent:(NSAppleEventDescriptor*)event + withReplyEvent:(NSAppleEventDescriptor*)replyEvent; + +@end diff --git a/browser/atom_application_delegate.mm b/browser/atom_application_delegate.mm new file mode 100644 index 000000000000..b26199dbef48 --- /dev/null +++ b/browser/atom_application_delegate.mm @@ -0,0 +1,24 @@ +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "browser/atom_application_delegate.h" + +#import "browser/atom_application.h" + +@implementation AtomApplicationDelegate + +- (void)applicationDidFinishLaunching:(NSNotification*)notify { + NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; + [em setEventHandler:self + andSelector:@selector(handleQuitEvent:withReplyEvent:) + forEventClass:kCoreEventClass + andEventID:kAEQuitApplication]; +} + +- (void)handleQuitEvent:(NSAppleEventDescriptor*)event + withReplyEvent:(NSAppleEventDescriptor*)replyEvent { + [[AtomApplication sharedApplication] closeAllWindows:self]; +} + +@end diff --git a/browser/atom_browser_main_parts.cc b/browser/atom_browser_main_parts.cc index ac5d0aff72e5..de11c5698ab8 100644 --- a/browser/atom_browser_main_parts.cc +++ b/browser/atom_browser_main_parts.cc @@ -51,13 +51,9 @@ void AtomBrowserMainParts::PostEarlyInitialization() { atom_bindings_->AfterLoad(); } -void AtomBrowserMainParts::PreMainMessageLoopStart() { - brightray::BrowserMainParts::PreMainMessageLoopStart(); - - node_bindings_->PrepareMessageLoop(); -} - void AtomBrowserMainParts::PreMainMessageLoopRun() { + node_bindings_->PrepareMessageLoop(); + brightray::BrowserMainParts::PreMainMessageLoopRun(); { diff --git a/browser/atom_browser_main_parts_mac.mm b/browser/atom_browser_main_parts_mac.mm new file mode 100644 index 000000000000..2f452e03fd0b --- /dev/null +++ b/browser/atom_browser_main_parts_mac.mm @@ -0,0 +1,28 @@ +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "browser/atom_browser_main_parts.h" + +#import "base/mac/bundle_locations.h" +#import "browser/atom_application.h" +#import "browser/atom_application_delegate.h" + +namespace atom { + +void AtomBrowserMainParts::PreMainMessageLoopStart() { + // Force the NSApplication subclass to be used. + NSApplication* application = [AtomApplication sharedApplication]; + + AtomApplicationDelegate* delegate = [AtomApplicationDelegate alloc]; + [NSApp setDelegate:delegate]; + + auto infoDictionary = base::mac::OuterBundle().infoDictionary; + + NSString *mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"]; + auto mainNib = [[NSNib alloc] initWithNibNamed:mainNibName bundle:base::mac::FrameworkBundle()]; + [mainNib instantiateWithOwner:application topLevelObjects:nil]; + [mainNib release]; +} + +} // namespace atom diff --git a/browser/mac/MainMenu.xib b/browser/mac/MainMenu.xib index 6874c5afb52e..ec44b01fccf9 100644 --- a/browser/mac/MainMenu.xib +++ b/browser/mac/MainMenu.xib @@ -1,11 +1,11 @@ - 1070 - 12C60 + 1080 + 12D78 3084 - 1187.34 - 625.00 + 1187.37 + 626.00 com.apple.InterfaceBuilder.CocoaPlugin 3084 @@ -24,7 +24,7 @@ - BRYApplication + AtomApplication FirstResponder @@ -40,7 +40,7 @@ - Brightray Example + Atom 2147483647 @@ -53,11 +53,11 @@ submenuAction: - Brightray Example + Atom - About Brightray Example + About Atom 2147483647 @@ -118,7 +118,7 @@ - Hide Brightray Example + Hide Atom h 1048576 2147483647 @@ -154,7 +154,7 @@ - Quit Brightray Example + Quit Atom q 1048576 2147483647 @@ -1292,6 +1292,14 @@ 142 + + + closeAllWindows: + + + + 803 + performMiniaturize: @@ -1404,14 +1412,6 @@ 368 - - - terminate: - - - - 369 - unhideAllApplications: @@ -2124,13 +2124,13 @@ - + @@ -3107,10 +3107,48 @@ - 801 + 803 + + AtomApplication + NSApplication + + closeAllWindows: + id + + + closeAllWindows: + + closeAllWindows: + id + + + + IBProjectSource + ./Classes/AtomApplication.h + + + + BRYInspectableWebContentsView + NSView + + showDevTools: + id + + + showDevTools: + + showDevTools: + id + + + + IBProjectSource + ./Classes/BRYInspectableWebContentsView.h + + FirstResponder @@ -3133,10 +3171,6 @@ 0 IBCocoaFramework - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - YES 3