Make BrowserWindow inheritable. Fixed #23.

This commit is contained in:
Cheng Zhao 2013-06-18 18:35:08 +08:00
parent eaa03facee
commit 5a0aab2e4f
5 changed files with 87 additions and 28 deletions

View file

@ -2,28 +2,30 @@ EventEmitter = require('events').EventEmitter
v8Util = process.atomBinding 'v8_util'
objectsRegistry = require '../../atom/objects-registry.js'
BrowserWindow = process.atomBinding('window').BrowserWindow
BrowserWindow::__proto__ = EventEmitter.prototype
Window = process.atomBinding('window').Window
Window::__proto__ = EventEmitter.prototype
BrowserWindow::toggleDevTools = ->
opened = v8Util.getHiddenValue this, 'devtoolsOpened'
if opened
@closeDevTools()
v8Util.setHiddenValue this, 'devtoolsOpened', false
else
@openDevTools()
v8Util.setHiddenValue this, 'devtoolsOpened', true
module.exports = class BrowserWindow extends Window
constructor: ->
super
BrowserWindow::restart = ->
@loadUrl(@getUrl())
toggleDevTools: ->
opened = v8Util.getHiddenValue this, 'devtoolsOpened'
if opened
@closeDevTools()
v8Util.setHiddenValue this, 'devtoolsOpened', false
else
@openDevTools()
v8Util.setHiddenValue this, 'devtoolsOpened', true
BrowserWindow.getFocusedWindow = ->
windows = objectsRegistry.getAllWindows()
return window for window in windows when window.isFocused()
restart: ->
@loadUrl @getUrl()
BrowserWindow.fromProcessIdAndRoutingId = (processId, routingId) ->
windows = objectsRegistry.getAllWindows()
return window for window in windows when window.getProcessId() == processId and
window.getRoutingId() == routingId
@getFocusedWindow: ->
windows = objectsRegistry.getAllWindows()
return window for window in windows when window.isFocused()
module.exports = BrowserWindow
@fromProcessIdAndRoutingId = (processId, routingId) ->
windows = objectsRegistry.getAllWindows()
return window for window in windows when window.getProcessId() == processId and
window.getRoutingId() == routingId