parent
839a751de5
commit
0411c2d2b6
4 changed files with 34 additions and 72 deletions
2
atom.gyp
2
atom.gyp
|
@ -119,8 +119,6 @@
|
||||||
'browser/ui/cocoa/atom_menu_controller.mm',
|
'browser/ui/cocoa/atom_menu_controller.mm',
|
||||||
'browser/ui/cocoa/event_processing_window.h',
|
'browser/ui/cocoa/event_processing_window.h',
|
||||||
'browser/ui/cocoa/event_processing_window.mm',
|
'browser/ui/cocoa/event_processing_window.mm',
|
||||||
'browser/ui/cocoa/nsalert_synchronous_sheet.h',
|
|
||||||
'browser/ui/cocoa/nsalert_synchronous_sheet.mm',
|
|
||||||
'browser/ui/file_dialog.h',
|
'browser/ui/file_dialog.h',
|
||||||
'browser/ui/file_dialog_gtk.cc',
|
'browser/ui/file_dialog_gtk.cc',
|
||||||
'browser/ui/file_dialog_mac.mm',
|
'browser/ui/file_dialog_mac.mm',
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
// 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 NSAlert (SynchronousSheet)
|
|
||||||
-(NSInteger) runModalSheetForWindow:(NSWindow*)aWindow;
|
|
||||||
-(NSInteger) runModalSheet;
|
|
||||||
@end
|
|
|
@ -1,51 +0,0 @@
|
||||||
// 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/ui/cocoa/nsalert_synchronous_sheet.h"
|
|
||||||
|
|
||||||
// Private methods -- use prefixes to avoid collisions with Apple's methods
|
|
||||||
@interface NSAlert (SynchronousSheetPrivate)
|
|
||||||
-(IBAction) BE_stopSynchronousSheet:(id)sender; // hide sheet & stop modal
|
|
||||||
-(void) BE_beginSheetModalForWindow:(NSWindow *)aWindow;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation NSAlert (SynchronousSheet)
|
|
||||||
|
|
||||||
-(NSInteger) runModalSheetForWindow:(NSWindow *)aWindow {
|
|
||||||
// Set ourselves as the target for button clicks
|
|
||||||
for (NSButton *button in [self buttons]) {
|
|
||||||
[button setTarget:self];
|
|
||||||
[button setAction:@selector(BE_stopSynchronousSheet:)];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bring up the sheet and wait until stopSynchronousSheet is triggered by a button click
|
|
||||||
[self performSelectorOnMainThread:@selector(BE_beginSheetModalForWindow:) withObject:aWindow waitUntilDone:YES];
|
|
||||||
NSInteger modalCode = [NSApp runModalForWindow:[self window]];
|
|
||||||
|
|
||||||
// This is called only after stopSynchronousSheet is called (that is,
|
|
||||||
// one of the buttons is clicked)
|
|
||||||
[NSApp performSelectorOnMainThread:@selector(endSheet:) withObject:[self window] waitUntilDone:YES];
|
|
||||||
|
|
||||||
// Remove the sheet from the screen
|
|
||||||
[[self window] performSelectorOnMainThread:@selector(orderOut:) withObject:self waitUntilDone:YES];
|
|
||||||
|
|
||||||
return modalCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
-(NSInteger) runModalSheet {
|
|
||||||
return [self runModalSheetForWindow:[NSApp mainWindow]];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark Private methods
|
|
||||||
|
|
||||||
-(IBAction) BE_stopSynchronousSheet:(id)sender {
|
|
||||||
[NSApp stopModalWithCode:[sender tag]];
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) BE_beginSheetModalForWindow:(NSWindow *)aWindow {
|
|
||||||
[self beginSheetModalForWindow:aWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
|
@ -9,24 +9,27 @@
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#include "browser/native_window.h"
|
#include "browser/native_window.h"
|
||||||
#include "browser/ui/cocoa/nsalert_synchronous_sheet.h"
|
|
||||||
|
|
||||||
@interface ModalDelegate : NSObject {
|
@interface ModalDelegate : NSObject {
|
||||||
@private
|
@private
|
||||||
atom::MessageBoxCallback callback_;
|
atom::MessageBoxCallback callback_;
|
||||||
NSAlert* alert_;
|
NSAlert* alert_;
|
||||||
|
bool callEndModal_;
|
||||||
}
|
}
|
||||||
- (id)initWithCallback:(const atom::MessageBoxCallback&)callback
|
- (id)initWithCallback:(const atom::MessageBoxCallback&)callback
|
||||||
andAlert:(NSAlert*)alert;
|
andAlert:(NSAlert*)alert
|
||||||
|
callEndModal:(bool)flag;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation ModalDelegate
|
@implementation ModalDelegate
|
||||||
|
|
||||||
- (id)initWithCallback:(const atom::MessageBoxCallback&)callback
|
- (id)initWithCallback:(const atom::MessageBoxCallback&)callback
|
||||||
andAlert:(NSAlert*)alert {
|
andAlert:(NSAlert*)alert
|
||||||
|
callEndModal:(bool)flag {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
callback_ = callback;
|
callback_ = callback;
|
||||||
alert_ = alert;
|
alert_ = alert;
|
||||||
|
callEndModal_ = flag;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +40,9 @@
|
||||||
callback_.Run(returnCode);
|
callback_.Run(returnCode);
|
||||||
[alert_ release];
|
[alert_ release];
|
||||||
[self release];
|
[self release];
|
||||||
|
|
||||||
|
if (callEndModal_)
|
||||||
|
[NSApp stopModal];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -76,6 +82,10 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
|
||||||
return alert;
|
return alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetReturnCode(int* ret_code, int result) {
|
||||||
|
*ret_code = result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int ShowMessageBox(NativeWindow* parent_window,
|
int ShowMessageBox(NativeWindow* parent_window,
|
||||||
|
@ -86,12 +96,26 @@ int ShowMessageBox(NativeWindow* parent_window,
|
||||||
const std::string& detail) {
|
const std::string& detail) {
|
||||||
NSAlert* alert = CreateNSAlert(
|
NSAlert* alert = CreateNSAlert(
|
||||||
parent_window, type, buttons, title, message, detail);
|
parent_window, type, buttons, title, message, detail);
|
||||||
[alert autorelease];
|
|
||||||
|
|
||||||
if (parent_window)
|
// Use runModal for synchronous alert without parent, since we don't have a
|
||||||
return [alert runModalSheetForWindow:parent_window->GetNativeWindow()];
|
// window to wait for.
|
||||||
else
|
if (!parent_window)
|
||||||
return [alert runModal];
|
return [[alert autorelease] runModal];
|
||||||
|
|
||||||
|
int ret_code = -1;
|
||||||
|
ModalDelegate* delegate = [[ModalDelegate alloc]
|
||||||
|
initWithCallback:base::Bind(&SetReturnCode, &ret_code)
|
||||||
|
andAlert:alert
|
||||||
|
callEndModal:true];
|
||||||
|
|
||||||
|
NSWindow* window = parent_window->GetNativeWindow();
|
||||||
|
[alert beginSheetModalForWindow:window
|
||||||
|
modalDelegate:delegate
|
||||||
|
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
|
||||||
|
contextInfo:nil];
|
||||||
|
|
||||||
|
[NSApp runModalForWindow:window];
|
||||||
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowMessageBox(NativeWindow* parent_window,
|
void ShowMessageBox(NativeWindow* parent_window,
|
||||||
|
@ -104,7 +128,8 @@ void ShowMessageBox(NativeWindow* parent_window,
|
||||||
NSAlert* alert = CreateNSAlert(
|
NSAlert* alert = CreateNSAlert(
|
||||||
parent_window, type, buttons, title, message, detail);
|
parent_window, type, buttons, title, message, detail);
|
||||||
ModalDelegate* delegate = [[ModalDelegate alloc] initWithCallback:callback
|
ModalDelegate* delegate = [[ModalDelegate alloc] initWithCallback:callback
|
||||||
andAlert:alert];
|
andAlert:alert
|
||||||
|
callEndModal:false];
|
||||||
|
|
||||||
NSWindow* window = parent_window ? parent_window->GetNativeWindow() : nil;
|
NSWindow* window = parent_window ? parent_window->GetNativeWindow() : nil;
|
||||||
[alert beginSheetModalForWindow:window
|
[alert beginSheetModalForWindow:window
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue