Merge pull request #4421 from atom/dialog-icon-on-mac
Support configurable dialog icon on Mac
This commit is contained in:
commit
e244d0db0c
1 changed files with 12 additions and 3 deletions
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
|
#include "base/mac/mac_util.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
|
#include "skia/ext/skia_utils_mac.h"
|
||||||
|
|
||||||
@interface ModalDelegate : NSObject {
|
@interface ModalDelegate : NSObject {
|
||||||
@private
|
@private
|
||||||
|
@ -57,7 +59,8 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
|
||||||
int default_id,
|
int default_id,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail) {
|
const std::string& detail,
|
||||||
|
const gfx::ImageSkia& icon) {
|
||||||
// Ignore the title; it's the window title on other platforms and ignorable.
|
// Ignore the title; it's the window title on other platforms and ignorable.
|
||||||
NSAlert* alert = [[NSAlert alloc] init];
|
NSAlert* alert = [[NSAlert alloc] init];
|
||||||
[alert setMessageText:base::SysUTF8ToNSString(message)];
|
[alert setMessageText:base::SysUTF8ToNSString(message)];
|
||||||
|
@ -92,6 +95,12 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
|
||||||
[[ns_buttons objectAtIndex:default_id] setKeyEquivalent:@"\r"];
|
[[ns_buttons objectAtIndex:default_id] setKeyEquivalent:@"\r"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!icon.isNull()) {
|
||||||
|
NSImage* image = gfx::SkBitmapToNSImageWithColorSpace(
|
||||||
|
*icon.bitmap(), base::mac::GetGenericRGBColorSpace());
|
||||||
|
[alert setIcon:image];
|
||||||
|
}
|
||||||
|
|
||||||
return alert;
|
return alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +122,7 @@ int ShowMessageBox(NativeWindow* parent_window,
|
||||||
const gfx::ImageSkia& icon) {
|
const gfx::ImageSkia& icon) {
|
||||||
NSAlert* alert = CreateNSAlert(
|
NSAlert* alert = CreateNSAlert(
|
||||||
parent_window, type, buttons, default_id, title, message,
|
parent_window, type, buttons, default_id, title, message,
|
||||||
detail);
|
detail, icon);
|
||||||
|
|
||||||
// Use runModal for synchronous alert without parent, since we don't have a
|
// Use runModal for synchronous alert without parent, since we don't have a
|
||||||
// window to wait for.
|
// window to wait for.
|
||||||
|
@ -149,7 +158,7 @@ void ShowMessageBox(NativeWindow* parent_window,
|
||||||
const MessageBoxCallback& callback) {
|
const MessageBoxCallback& callback) {
|
||||||
NSAlert* alert = CreateNSAlert(
|
NSAlert* alert = CreateNSAlert(
|
||||||
parent_window, type, buttons, default_id, title, message,
|
parent_window, type, buttons, default_id, title, message,
|
||||||
detail);
|
detail, icon);
|
||||||
ModalDelegate* delegate = [[ModalDelegate alloc] initWithCallback:callback
|
ModalDelegate* delegate = [[ModalDelegate alloc] initWithCallback:callback
|
||||||
andAlert:alert
|
andAlert:alert
|
||||||
callEndModal:false];
|
callEndModal:false];
|
||||||
|
|
Loading…
Reference in a new issue