docs: modal window is greatly simplified

This commit is contained in:
Cheng Zhao 2016-06-20 16:00:38 +09:00
parent 5674e8d114
commit f7a9b1ae04

View file

@ -72,39 +72,25 @@ The `child` window will always show on top of the `top` window.
### Modal windows ### Modal windows
A modal window is a child window that disables parent window, to turn a child A modal window is a child window that disables parent window, to create a modal
window into modal window, you need to call `win.setModal(true)`: window, you have to set both `parent` and `modal` options:
```javascript ```javascript
let child = new BrowserWindow({parent: top, show: false}) let child = new BrowserWindow({parent: top, modal: true, show: false})
child.loadURL('https://github.com') child.loadURL('https://github.com')
child.setModal(true)
child.once('ready-to-show', () => { child.once('ready-to-show', () => {
child.show() child.show()
}) })
``` ```
### Sheets
On macOS it is uncommon to use modal windows for tasks, a more native way is to
show window as sheet by calling `win.beginSheet(sheet)` API:
```javascript
let child = new BrowserWindow({show: false})
child.loadURL('https://github.com')
child.once('ready-to-show', () => {
top.beginSheet(child)
})
```
### Platform notices ### Platform notices
* On macOS the child window will keep the relative position to parent window * On macOS the child windows will keep the relative position to parent window
when parent window moves, while on Windows and Linux child windows will not when parent window moves, while on Windows and Linux child windows will not
move. move.
* On macOS the `setModal` has to be called before the child window shows.
* On Windows it is not supported to change parent window dynamically. * On Windows it is not supported to change parent window dynamically.
* On Linux the type of modal windows will be changed to `dialog`. * On Linux the type of modal windows will be changed to `dialog`.
* On Linux many desktop environments do not support hiding a modal window.
## Class: BrowserWindow ## Class: BrowserWindow
@ -163,7 +149,9 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
`true`. `true`.
* `frame` Boolean - Specify `false` to create a * `frame` Boolean - Specify `false` to create a
[Frameless Window](frameless-window.md). Default is `true`. [Frameless Window](frameless-window.md). Default is `true`.
* `parent` BrowserWindow - Parent window. * `parent` BrowserWindow - Specify parent window. Default is `null`.
* `modal` Boolean - Whether this is a modal window. This only works when the
window is a child window. Default is `false`.
* `acceptFirstMouse` Boolean - Whether the web view accepts a single * `acceptFirstMouse` Boolean - Whether the web view accepts a single
mouse-down event that simultaneously activates the window. Default is mouse-down event that simultaneously activates the window. Default is
`false`. `false`.
@ -580,33 +568,10 @@ Hides the window.
Returns a boolean, whether the window is visible to the user. Returns a boolean, whether the window is visible to the user.
### `win.setModal(modal)`
* `modal` Boolean
Sets current window as modal window.
It can only be called for child windows.
### `win.isModal()` ### `win.isModal()`
Returns whether current window is a modal window. Returns whether current window is a modal window.
### `win.beginSheet(sheet)` _macOS_
* `sheet` BrowserWindow
Shows `sheet` as a sheet for current window, when there is already a sheet
showing, this call will be queued.
It can only be called for top-level windows.
### `win.endSheet(sheet)` _macOS_
* `sheet` BrowserWindow
Dismisses the `sheet`.
### `win.maximize()` ### `win.maximize()`
Maximizes the window. Maximizes the window.