Quiting the application is now equivalent to close all windows.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 2 May 2013 12:09:19 +0000 (20:09 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 2 May 2013 12:09:19 +0000 (20:09 +0800)
atom.gyp
browser/atom_application.h [new file with mode: 0644]
browser/atom_application.mm [new file with mode: 0644]
browser/atom_application_delegate.h [new file with mode: 0644]
browser/atom_application_delegate.mm [new file with mode: 0644]
browser/atom_browser_main_parts.cc
browser/atom_browser_main_parts_mac.mm [new file with mode: 0644]
browser/mac/MainMenu.xib

index d50255a..f9ad09b 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       '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 (file)
index 0000000..b755004
--- /dev/null
@@ -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<CrAppProtocol,
+                                           CrAppControlProtocol> {
+ @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 (file)
index 0000000..3a377bc
--- /dev/null
@@ -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<BOOL> scoper(&handlingSendEvent_, YES);
+  [super sendEvent:event];
+}
+
+- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
+  handlingSendEvent_ = handlingSendEvent;
+}
+
++ (AtomApplication*)sharedApplication {
+  return (AtomApplication*)[super sharedApplication];
+}
+
+- (IBAction)closeAllWindows:(id)sender {
+  std::vector<atom::NativeWindow*> 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 (file)
index 0000000..ba8bab0
--- /dev/null
@@ -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 <Cocoa/Cocoa.h>
+
+@interface AtomApplicationDelegate : NSObject<NSApplicationDelegate> {
+}
+
+- (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 (file)
index 0000000..b26199d
--- /dev/null
@@ -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
index ac5d0af..de11c56 100644 (file)
@@ -51,13 +51,9 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
   atom_bindings_->AfterLoad();
 }
 
-void AtomBrowserMainParts::PreMainMessageLoopStart() {
-  brightray::BrowserMainParts::PreMainMessageLoopStart();
-
+void AtomBrowserMainParts::PreMainMessageLoopRun() {
   node_bindings_->PrepareMessageLoop();
-}
 
-void AtomBrowserMainParts::PreMainMessageLoopRun() {
   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 (file)
index 0000000..2f452e0
--- /dev/null
@@ -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
index 6874c5a..ec44b01 100644 (file)
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
        <data>
-               <int key="IBDocument.SystemTarget">1070</int>
-               <string key="IBDocument.SystemVersion">12C60</string>
+               <int key="IBDocument.SystemTarget">1080</int>
+               <string key="IBDocument.SystemVersion">12D78</string>
                <string key="IBDocument.InterfaceBuilderVersion">3084</string>
-               <string key="IBDocument.AppKitVersion">1187.34</string>
-               <string key="IBDocument.HIToolboxVersion">625.00</string>
+               <string key="IBDocument.AppKitVersion">1187.37</string>
+               <string key="IBDocument.HIToolboxVersion">626.00</string>
                <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
                        <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
                        <string key="NS.object.0">3084</string>
@@ -24,7 +24,7 @@
                </object>
                <array class="NSMutableArray" key="IBDocument.RootObjects" id="1048">
                        <object class="NSCustomObject" id="1021">
-                               <string key="NSClassName">BRYApplication</string>
+                               <string key="NSClassName">AtomApplication</string>
                        </object>
                        <object class="NSCustomObject" id="1014">
                                <string key="NSClassName">FirstResponder</string>
@@ -40,7 +40,7 @@
                                <array class="NSMutableArray" key="NSMenuItems">
                                        <object class="NSMenuItem" id="694149608">
                                                <reference key="NSMenu" ref="649796088"/>
-                                               <string key="NSTitle">Brightray Example</string>
+                                               <string key="NSTitle">Atom</string>
                                                <string key="NSKeyEquiv"/>
                                                <int key="NSMnemonicLoc">2147483647</int>
                                                <object class="NSCustomResource" key="NSOnImage" id="229763992">
                                                </object>
                                                <string key="NSAction">submenuAction:</string>
                                                <object class="NSMenu" key="NSSubmenu" id="110575045">
-                                                       <string key="NSTitle">Brightray Example</string>
+                                                       <string key="NSTitle">Atom</string>
                                                        <array class="NSMutableArray" key="NSMenuItems">
                                                                <object class="NSMenuItem" id="238522557">
                                                                        <reference key="NSMenu" ref="110575045"/>
-                                                                       <string key="NSTitle">About Brightray Example</string>
+                                                                       <string key="NSTitle">About Atom</string>
                                                                        <string key="NSKeyEquiv"/>
                                                                        <int key="NSMnemonicLoc">2147483647</int>
                                                                        <reference key="NSOnImage" ref="229763992"/>
                                                                </object>
                                                                <object class="NSMenuItem" id="755159360">
                                                                        <reference key="NSMenu" ref="110575045"/>
-                                                                       <string key="NSTitle">Hide Brightray Example</string>
+                                                                       <string key="NSTitle">Hide Atom</string>
                                                                        <string key="NSKeyEquiv">h</string>
                                                                        <int key="NSKeyEquivModMask">1048576</int>
                                                                        <int key="NSMnemonicLoc">2147483647</int>
                                                                </object>
                                                                <object class="NSMenuItem" id="632727374">
                                                                        <reference key="NSMenu" ref="110575045"/>
-                                                                       <string key="NSTitle">Quit Brightray Example</string>
+                                                                       <string key="NSTitle">Quit Atom</string>
                                                                        <string key="NSKeyEquiv">q</string>
                                                                        <int key="NSKeyEquivModMask">1048576</int>
                                                                        <int key="NSMnemonicLoc">2147483647</int>
                                </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBActionConnection" key="connection">
+                                               <string key="label">closeAllWindows:</string>
+                                               <reference key="source" ref="1021"/>
+                                               <reference key="destination" ref="632727374"/>
+                                       </object>
+                                       <int key="connectionID">803</int>
+                               </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBActionConnection" key="connection">
                                                <string key="label">performMiniaturize:</string>
                                                <reference key="source" ref="1014"/>
                                                <reference key="destination" ref="1011231497"/>
                                </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBActionConnection" key="connection">
-                                               <string key="label">terminate:</string>
-                                               <reference key="source" ref="1014"/>
-                                               <reference key="destination" ref="632727374"/>
-                                       </object>
-                                       <int key="connectionID">369</int>
-                               </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBActionConnection" key="connection">
                                                <string key="label">unhideAllApplications:</string>
                                                <reference key="source" ref="1014"/>
                                                <reference key="destination" ref="908899353"/>
                                                        <reference ref="238522557"/>
                                                        <reference ref="755159360"/>
                                                        <reference ref="908899353"/>
-                                                       <reference ref="632727374"/>
                                                        <reference ref="646227648"/>
                                                        <reference ref="609285721"/>
                                                        <reference ref="481834944"/>
                                                        <reference ref="304266470"/>
                                                        <reference ref="1046388886"/>
                                                        <reference ref="1056857174"/>
+                                                       <reference ref="632727374"/>
                                                        <reference ref="342932134"/>
                                                </array>
                                                <reference key="parent" ref="694149608"/>
                        <nil key="activeLocalization"/>
                        <dictionary class="NSMutableDictionary" key="localizations"/>
                        <nil key="sourceID"/>
-                       <int key="maxID">801</int>
+                       <int key="maxID">803</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <array class="NSMutableArray" key="referencedPartialClassDescriptions">
                                <object class="IBPartialClassDescription">
+                                       <string key="className">AtomApplication</string>
+                                       <string key="superclassName">NSApplication</string>
+                                       <object class="NSMutableDictionary" key="actions">
+                                               <string key="NS.key.0">closeAllWindows:</string>
+                                               <string key="NS.object.0">id</string>
+                                       </object>
+                                       <object class="NSMutableDictionary" key="actionInfosByName">
+                                               <string key="NS.key.0">closeAllWindows:</string>
+                                               <object class="IBActionInfo" key="NS.object.0">
+                                                       <string key="name">closeAllWindows:</string>
+                                                       <string key="candidateClassName">id</string>
+                                               </object>
+                                       </object>
+                                       <object class="IBClassDescriptionSource" key="sourceIdentifier">
+                                               <string key="majorKey">IBProjectSource</string>
+                                               <string key="minorKey">./Classes/AtomApplication.h</string>
+                                       </object>
+                               </object>
+                               <object class="IBPartialClassDescription">
+                                       <string key="className">BRYInspectableWebContentsView</string>
+                                       <string key="superclassName">NSView</string>
+                                       <object class="NSMutableDictionary" key="actions">
+                                               <string key="NS.key.0">showDevTools:</string>
+                                               <string key="NS.object.0">id</string>
+                                       </object>
+                                       <object class="NSMutableDictionary" key="actionInfosByName">
+                                               <string key="NS.key.0">showDevTools:</string>
+                                               <object class="IBActionInfo" key="NS.object.0">
+                                                       <string key="name">showDevTools:</string>
+                                                       <string key="candidateClassName">id</string>
+                                               </object>
+                                       </object>
+                                       <object class="IBClassDescriptionSource" key="sourceIdentifier">
+                                               <string key="majorKey">IBProjectSource</string>
+                                               <string key="minorKey">./Classes/BRYInspectableWebContentsView.h</string>
+                                       </object>
+                               </object>
+                               <object class="IBPartialClassDescription">
                                        <string key="className">FirstResponder</string>
                                        <object class="NSMutableDictionary" key="actions">
                                                <string key="NS.key.0">showDevTools:</string>
                </object>
                <int key="IBDocument.localizationMode">0</int>
                <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
-               <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
-                       <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
-                       <real value="1070" key="NS.object.0"/>
-               </object>
                <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
                <int key="IBDocument.defaultPropertyAccessControl">3</int>
                <dictionary class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">