Quiting the application is now equivalent to close all windows.

This commit is contained in:
Cheng Zhao 2013-05-02 20:09:19 +08:00
parent e7aab096e7
commit 43d42ca57f
8 changed files with 189 additions and 30 deletions

View file

@ -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',

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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();
{

View file

@ -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

View 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">
@ -53,11 +53,11 @@
</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"/>
@ -118,7 +118,7 @@
</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>
@ -154,7 +154,7 @@
</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>
@ -1292,6 +1292,14 @@
</object>
<int key="connectionID">142</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>
@ -1404,14 +1412,6 @@
</object>
<int key="connectionID">368</int>
</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>
@ -2124,13 +2124,13 @@
<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"/>
@ -3107,10 +3107,48 @@
<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">
@ -3133,10 +3171,6 @@
</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">