From: Cheng Zhao Date: Fri, 17 May 2013 08:09:12 +0000 (+0800) Subject: Simulate the toggleDevTools API. X-Git-Tag: v0.1.0~151 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=1fea283d91f83971f907128141fd641a8c90ac23;p=electron.git Simulate the toggleDevTools API. Currently there is no way to know the devtools's state in brightray, so we have to record the state manually, fix this after patching brightray. --- diff --git a/browser/api/lib/browser_window.coffee b/browser/api/lib/browser_window.coffee index 24810af2..fc18a807 100644 --- a/browser/api/lib/browser_window.coffee +++ b/browser/api/lib/browser_window.coffee @@ -1,8 +1,18 @@ EventEmitter = require('events').EventEmitter +v8Util = process.atomBinding 'v8_util' objectsRegistry = require '../../atom/objects_registry.js' BrowserWindow = process.atomBinding('window').BrowserWindow -BrowserWindow.prototype.__proto__ = EventEmitter.prototype +BrowserWindow::__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 BrowserWindow.getFocusedWindow = -> windows = objectsRegistry.getAllWindows() diff --git a/browser/default_app/main.js b/browser/default_app/main.js index bde619ed..e5be6c92 100644 --- a/browser/default_app/main.js +++ b/browser/default_app/main.js @@ -74,9 +74,9 @@ delegate.browserMainParts.preMainMessageLoopRun = function() { click: function() { BrowserWindow.getFocusedWindow().reloadIgnoringCache(); } }, { - label: 'Show DevTools', + label: 'Toggle DevTools', accelerator: 'Alt+Command+I', - click: function() { BrowserWindow.getFocusedWindow().openDevTools(); } + click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); } }, ] },