feat: add width option to dialog.showMessageBox() (#30474)
This commit is contained in:
parent
e39a1d2ea0
commit
77579614e0
5 changed files with 13 additions and 1 deletions
|
@ -234,6 +234,7 @@ expanding and collapsing the dialog.
|
||||||
* `title` String (optional) - Title of the message box, some platforms will not show it.
|
* `title` String (optional) - Title of the message box, some platforms will not show it.
|
||||||
* `detail` String (optional) - Extra information of the message.
|
* `detail` String (optional) - Extra information of the message.
|
||||||
* `icon` ([NativeImage](native-image.md) | String) (optional)
|
* `icon` ([NativeImage](native-image.md) | String) (optional)
|
||||||
|
* `textWidth` Integer (optional) _macOS_ - Custom width of the text in the message box.
|
||||||
* `cancelId` Integer (optional) - The index of the button to be used to cancel the dialog, via
|
* `cancelId` Integer (optional) - The index of the button to be used to cancel the dialog, via
|
||||||
the `Esc` key. By default this is assigned to the first button with "cancel" or "no" as the
|
the `Esc` key. By default this is assigned to the first button with "cancel" or "no" as the
|
||||||
label. If no such labeled buttons exist and this option is not set, `0` will be used as the
|
label. If no such labeled buttons exist and this option is not set, `0` will be used as the
|
||||||
|
@ -285,6 +286,7 @@ If `browserWindow` is not shown dialog will not be attached to it. In such case
|
||||||
* `checkboxChecked` Boolean (optional) - Initial checked state of the
|
* `checkboxChecked` Boolean (optional) - Initial checked state of the
|
||||||
checkbox. `false` by default.
|
checkbox. `false` by default.
|
||||||
* `icon` [NativeImage](native-image.md) (optional)
|
* `icon` [NativeImage](native-image.md) (optional)
|
||||||
|
* `textWidth` Integer (optional) _macOS_ - Custom width of the text in the message box.
|
||||||
* `cancelId` Integer (optional) - The index of the button to be used to cancel the dialog, via
|
* `cancelId` Integer (optional) - The index of the button to be used to cancel the dialog, via
|
||||||
the `Esc` key. By default this is assigned to the first button with "cancel" or "no" as the
|
the `Esc` key. By default this is assigned to the first button with "cancel" or "no" as the
|
||||||
label. If no such labeled buttons exist and this option is not set, `0` will be used as the
|
label. If no such labeled buttons exist and this option is not set, `0` will be used as the
|
||||||
|
|
|
@ -168,6 +168,7 @@ const messageBox = (sync: boolean, window: BrowserWindow | null, options?: Messa
|
||||||
defaultId = -1,
|
defaultId = -1,
|
||||||
detail = '',
|
detail = '',
|
||||||
icon = null,
|
icon = null,
|
||||||
|
textWidth = 0,
|
||||||
noLink = false,
|
noLink = false,
|
||||||
message = '',
|
message = '',
|
||||||
title = '',
|
title = '',
|
||||||
|
@ -225,7 +226,8 @@ const messageBox = (sync: boolean, window: BrowserWindow | null, options?: Messa
|
||||||
detail,
|
detail,
|
||||||
checkboxLabel,
|
checkboxLabel,
|
||||||
checkboxChecked,
|
checkboxChecked,
|
||||||
icon
|
icon,
|
||||||
|
textWidth
|
||||||
};
|
};
|
||||||
|
|
||||||
if (sync) {
|
if (sync) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ struct MessageBoxSettings {
|
||||||
std::string checkbox_label;
|
std::string checkbox_label;
|
||||||
bool checkbox_checked = false;
|
bool checkbox_checked = false;
|
||||||
gfx::ImageSkia icon;
|
gfx::ImageSkia icon;
|
||||||
|
int text_width = 0;
|
||||||
|
|
||||||
MessageBoxSettings();
|
MessageBoxSettings();
|
||||||
MessageBoxSettings(const MessageBoxSettings&);
|
MessageBoxSettings(const MessageBoxSettings&);
|
||||||
|
|
|
@ -98,6 +98,12 @@ NSAlert* CreateNSAlert(const MessageBoxSettings& settings) {
|
||||||
[alert setIcon:image];
|
[alert setIcon:image];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.text_width > 0) {
|
||||||
|
NSRect rect = NSMakeRect(0, 0, settings.text_width, 0);
|
||||||
|
NSView* accessoryView = [[NSView alloc] initWithFrame:rect];
|
||||||
|
[alert setAccessoryView:[accessoryView autorelease]];
|
||||||
|
}
|
||||||
|
|
||||||
return alert;
|
return alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ bool Converter<electron::MessageBoxSettings>::FromV8(
|
||||||
dict.Get("noLink", &out->no_link);
|
dict.Get("noLink", &out->no_link);
|
||||||
dict.Get("checkboxChecked", &out->checkbox_checked);
|
dict.Get("checkboxChecked", &out->checkbox_checked);
|
||||||
dict.Get("icon", &out->icon);
|
dict.Get("icon", &out->icon);
|
||||||
|
dict.Get("textWidth", &out->text_width);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue