提交 6027927d 编写于 作者: B Benjamin Pasero

adopt browser window and dialog

上级 d6c4086d
......@@ -29,8 +29,8 @@ var build = path.join(root, '.build');
var commit = util.getVersion(root);
var baseModules = [
'applicationinsights', 'assert', 'browser-window',
'child_process', 'chokidar', 'crypto', 'dialog', 'emmet',
'applicationinsights', 'assert',
'child_process', 'chokidar', 'crypto', 'emmet',
'events', 'fs', 'getmac', 'glob', 'graceful-fs', 'http', 'http-proxy-agent',
'https', 'https-proxy-agent', 'iconv-lite', 'electron', 'menu', 'menu-item', 'net',
'os', 'path', 'readline', 'remote', 'sax', 'semver',
......
......@@ -3,9 +3,11 @@
// Definitions by: jedmao <https://github.com/jedmao/>, rhysd <https://rhysd.github.io>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Copied from https://github.com/DefinitelyTyped/DefinitelyTyped/commit/eddede55bd6b42c154eb8e44336d0fa44ca79965
/// <reference path="./node.d.ts" />
declare module GitHubElectron {
declare module Electron {
/**
* This class is used to represent an image.
*/
......@@ -750,6 +752,10 @@ declare module GitHubElectron {
* Returns whether the developer tools are opened.
*/
isDevToolsOpened(): boolean;
/**
* Returns whether the developer tools are focussed.
*/
isDevToolsFocused(): boolean;
/**
* Toggle the developer tools.
*/
......@@ -1181,14 +1187,7 @@ declare module GitHubElectron {
properties?: string|string[];
}
/**
* @param browserWindow
* @param options
* @param callback If supplied, the API call will be asynchronous.
* @returns On success, returns the path of file chosen by the user, otherwise
* returns undefined.
*/
export function showSaveDialog(browserWindow?: BrowserWindow, options?: {
interface SaveDialogOptions {
title?: string;
defaultPath?: string;
/**
......@@ -1199,7 +1198,16 @@ declare module GitHubElectron {
name: string;
extensions: string[];
}[]
}, callback?: (fileName: string) => void): string;
}
/**
* @param browserWindow
* @param options
* @param callback If supplied, the API call will be asynchronous.
* @returns On success, returns the path of file chosen by the user, otherwise
* returns undefined.
*/
export function showSaveDialog(browserWindow?: BrowserWindow, options?: SaveDialogOptions, callback?: (fileName: string) => void): string;
/**
* Shows a message box. It will block until the message box is closed. It returns .
......@@ -1239,6 +1247,7 @@ declare module GitHubElectron {
detail?: string;
icon?: NativeImage;
noLink?: boolean;
cancelId?: number;
}
}
......@@ -1310,11 +1319,11 @@ declare module GitHubElectron {
/**
* @returns The contents of the clipboard as a NativeImage.
*/
readImage: typeof GitHubElectron.Clipboard.readImage;
readImage: typeof Electron.Clipboard.readImage;
/**
* Writes the image into the clipboard.
*/
writeImage: typeof GitHubElectron.Clipboard.writeImage;
writeImage: typeof Electron.Clipboard.writeImage;
/**
* Clears everything in clipboard.
*/
......@@ -1633,19 +1642,19 @@ declare module GitHubElectron {
* @returns On success, returns an array of file paths chosen by the user,
* otherwise returns undefined.
*/
showOpenDialog: typeof GitHubElectron.Dialog.showOpenDialog;
showOpenDialog: typeof Electron.Dialog.showOpenDialog;
/**
* @param callback If supplied, the API call will be asynchronous.
* @returns On success, returns the path of file chosen by the user, otherwise
* returns undefined.
*/
showSaveDialog: typeof GitHubElectron.Dialog.showSaveDialog;
showSaveDialog: typeof Electron.Dialog.showSaveDialog;
/**
* Shows a message box. It will block until the message box is closed. It returns .
* @param callback If supplied, the API call will be asynchronous.
* @returns The index of the clicked button.
*/
showMessageBox: typeof GitHubElectron.Dialog.showMessageBox;
showMessageBox: typeof Electron.Dialog.showMessageBox;
/**
* Runs a modal dialog that shows an error message. This API can be called safely
......@@ -1775,26 +1784,26 @@ declare module GitHubElectron {
}
interface CommonElectron {
clipboard: GitHubElectron.Clipboard;
crashReporter: GitHubElectron.CrashReporter;
nativeImage: typeof GitHubElectron.NativeImage;
shell: GitHubElectron.Shell;
clipboard: Electron.Clipboard;
crashReporter: Electron.CrashReporter;
nativeImage: typeof Electron.NativeImage;
shell: Electron.Shell;
app: GitHubElectron.App;
autoUpdater: GitHubElectron.AutoUpdater;
BrowserWindow: typeof GitHubElectron.BrowserWindow;
contentTracing: GitHubElectron.ContentTracing;
dialog: GitHubElectron.Dialog;
ipcMain: GitHubElectron.IPCMain;
globalShortcut: GitHubElectron.GlobalShortcut;
Menu: typeof GitHubElectron.Menu;
MenuItem: typeof GitHubElectron.MenuItem;
app: Electron.App;
autoUpdater: Electron.AutoUpdater;
BrowserWindow: typeof Electron.BrowserWindow;
contentTracing: Electron.ContentTracing;
dialog: Electron.Dialog;
ipcMain: Electron.IPCMain;
globalShortcut: Electron.GlobalShortcut;
Menu: typeof Electron.Menu;
MenuItem: typeof Electron.MenuItem;
powerMonitor: NodeJS.EventEmitter;
powerSaveBlocker: GitHubElectron.PowerSaveBlocker;
protocol: GitHubElectron.Protocol;
screen: GitHubElectron.Screen;
session: GitHubElectron.Session;
Tray: typeof GitHubElectron.Tray;
powerSaveBlocker: Electron.PowerSaveBlocker;
protocol: Electron.Protocol;
screen: Electron.Screen;
session: Electron.Session;
Tray: typeof Electron.Tray;
hideInternalModules(): void;
}
......@@ -1816,11 +1825,11 @@ declare module GitHubElectron {
getSources(options: any, callback: (error: Error, sources: DesktopCapturerSource[]) => any): void;
}
interface Electron extends CommonElectron {
desktopCapturer: GitHubElectron.DesktopCapturer;
ipcRenderer: GitHubElectron.IpcRenderer;
remote: GitHubElectron.Remote;
webFrame: GitHubElectron.WebFrame;
interface ElectronMainAndRenderer extends CommonElectron {
desktopCapturer: Electron.DesktopCapturer;
ipcRenderer: Electron.IpcRenderer;
remote: Electron.Remote;
webFrame: Electron.WebFrame;
}
}
......@@ -1829,7 +1838,7 @@ interface Window {
* Creates a new window.
* @returns An instance of BrowserWindowProxy class.
*/
open(url: string, frameName?: string, features?: string): GitHubElectron.BrowserWindowProxy;
open(url: string, frameName?: string, features?: string): Electron.BrowserWindowProxy;
}
interface File {
......@@ -1840,10 +1849,10 @@ interface File {
}
declare module 'electron' {
var electron: GitHubElectron.Electron;
var electron: Electron.ElectronMainAndRenderer;
export = electron;
}
// interface NodeRequireFunction {
// (moduleName: 'electron'): GitHubElectron.Electron;
// (moduleName: 'electron'): Electron.Electron;
// }
\ No newline at end of file
......@@ -12,12 +12,13 @@
<!-- Helpers -->
<script type="text/javascript">
var path = require('path');
var remote = require('remote');
var ipc = require('electron').ipcRenderer;
var electron = require('electron');
var remote = electron.remote;
var ipc = electron.ipcRenderer;
function onError(error, enableDeveloperTools) {
if (enableDeveloperTools) {
remote.getCurrentWindow().openDevTools();
remote.getCurrentWindow().webContents.openDevTools();
remote.getCurrentWindow().show();
}
......
......@@ -45,7 +45,7 @@ export class ElectronIntegration {
public integrate(shellContainer: HTMLElement): void {
// Register the active window
let activeWindow = this.instantiationService.createInstance(win.ElectronWindow, remote.getCurrentWindow(), shellContainer);
let activeWindow:any = this.instantiationService.createInstance(<any>win.ElectronWindow, remote.getCurrentWindow(), shellContainer);
this.windowService.registerWindow(activeWindow);
// Support runAction event
......
......@@ -18,10 +18,7 @@ import {IStorageService} from 'vs/platform/storage/common/storage';
import {IEventService} from 'vs/platform/event/common/event';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import remote = require('remote');
import {ipcRenderer as ipc, shell} from 'electron';
const Dialog = remote.require('dialog');
import {ipcRenderer as ipc, shell, remote} from 'electron';
export interface IWindowConfiguration {
window: {
......@@ -32,10 +29,10 @@ export interface IWindowConfiguration {
}
export class ElectronWindow {
private win: remote.BrowserWindow;
private win: Electron.BrowserWindow;
constructor(
win: remote.BrowserWindow,
win: Electron.BrowserWindow,
shellContainer: HTMLElement,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEventService private eventService: IEventService,
......@@ -157,8 +154,8 @@ export class ElectronWindow {
this.win.close();
}
public showMessageBox(options: remote.IMessageBoxOptions): number {
return Dialog.showMessageBox(this.win, options);
public showMessageBox(options: Electron.Dialog.ShowMessageBoxOptions): number {
return remote.dialog.showMessageBox(this.win, options);
}
public setFullScreen(fullscreen: boolean): void {
......@@ -166,7 +163,7 @@ export class ElectronWindow {
}
public openDevTools(): void {
this.win.openDevTools();
this.win.webContents.openDevTools();
}
public isFullScreen(): boolean {
......
......@@ -8,8 +8,7 @@
import Menu = require('menu');
import MenuItem = require('menu-item');
import Dialog = require('dialog');
import {ipcMain as ipc, app, shell} from 'electron';
import {ipcMain as ipc, app, shell, dialog} from 'electron';
import nls = require('vs/nls');
import platform = require('vs/base/common/platform');
......@@ -657,7 +656,7 @@ export class VSCodeMenu {
return;
}
if (windowInFocus.win.isDevToolsFocused()) {
if (windowInFocus.win.webContents.isDevToolsFocused()) {
devToolsFocusedFn(windowInFocus.win.devToolsWebContents);
} else {
windows.manager.sendToFocused('vscode:runAction', actionId);
......@@ -689,7 +688,7 @@ export class VSCodeMenu {
function openAboutDialog(): void {
let lastActiveWindow = windows.manager.getFocusedWindow() || windows.manager.getLastActiveWindow();
Dialog.showMessageBox(lastActiveWindow && lastActiveWindow.win, {
dialog.showMessageBox(lastActiveWindow && lastActiveWindow.win, {
title: env.product.nameLong,
type: 'info',
message: env.product.nameLong,
......@@ -717,7 +716,7 @@ function openUrl(url: string, id: string): void {
function toggleDevTools(): void {
let w = windows.manager.getFocusedWindow();
if (w && w.win) {
w.win.toggleDevTools();
w.win.webContents.toggleDevTools();
}
}
......
......@@ -8,8 +8,7 @@
import path = require('path');
import os = require('os');
import {shell, screen} from 'electron';
import BrowserWindow = require('browser-window');
import {shell, screen, BrowserWindow} from 'electron';
import {TPromise, TValueCallback} from 'vs/base/common/winjs.base';
import platform = require('vs/base/common/platform');
......@@ -138,7 +137,7 @@ export class VSCodeWindow {
private static MIN_HEIGHT = 120;
private showTimeoutHandle: any;
private _win: BrowserWindow;
private _win: Electron.BrowserWindow;
private _lastFocusTime: number;
private _readyState: ReadyState;
private _isPluginDevelopmentHost: boolean;
......@@ -212,7 +211,7 @@ export class VSCodeWindow {
return this.currentConfig;
}
public get win(): BrowserWindow {
public get win(): Electron.BrowserWindow {
return this._win;
}
......@@ -370,7 +369,7 @@ export class VSCodeWindow {
if (this._win && !this._win.isVisible() && !this._win.isMinimized()) {
this._win.show();
this._win.focus();
this._win.openDevTools();
this._win.webContents.openDevTools();
}
}, 10000);
}
......
......@@ -10,9 +10,7 @@ import events = require('events');
import path = require('path');
import fs = require('fs');
import BrowserWindow = require('browser-window');
import Dialog = require('dialog');
import {ipcMain as ipc, app, screen, crashReporter} from 'electron';
import {ipcMain as ipc, app, screen, crashReporter, BrowserWindow, dialog} from 'electron';
import platform = require('vs/base/common/platform');
import env = require('vs/workbench/electron-main/env');
......@@ -408,9 +406,9 @@ export class WindowsManager {
let activeWindow = BrowserWindow.getFocusedWindow();
if (activeWindow) {
Dialog.showMessageBox(activeWindow, options);
dialog.showMessageBox(activeWindow, options);
} else {
Dialog.showMessageBox(options);
dialog.showMessageBox(options);
}
}
......@@ -874,7 +872,7 @@ export class WindowsManager {
pickerProperties = ['multiSelections', isFolder ? 'openDirectory' : 'openFile', 'createDirectory'];
}
Dialog.showOpenDialog(focussedWindow && focussedWindow.win, {
dialog.showOpenDialog(focussedWindow && focussedWindow.win, {
defaultPath: workingDir,
properties: pickerProperties
}, (paths) => {
......@@ -1004,12 +1002,12 @@ export class WindowsManager {
return WindowsManager.WINDOWS.length;
}
private onWindowError(win: BrowserWindow, error: WindowError): void {
private onWindowError(win: Electron.BrowserWindow, error: WindowError): void {
console.error(error === WindowError.CRASHED ? '[VS Code]: render process crashed!' : '[VS Code]: detected unresponsive');
// Unresponsive
if (error === WindowError.UNRESPONSIVE) {
Dialog.showMessageBox(win, {
dialog.showMessageBox(win, {
title: env.product.nameLong,
type: 'warning',
buttons: [nls.localize('exit', "Exit"), nls.localize('wait', "Keep Waiting")],
......@@ -1026,7 +1024,7 @@ export class WindowsManager {
// Crashed
else {
Dialog.showMessageBox(win, {
dialog.showMessageBox(win, {
title: env.product.nameLong,
type: 'warning',
buttons: [nls.localize('exit', "Exit")],
......
......@@ -29,9 +29,7 @@ import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IConfigurationService, IConfigurationServiceEvent, ConfigurationServiceEventTypes} from 'vs/platform/configuration/common/configuration';
import remote = require('remote');
const Dialog = remote.require('dialog');
import {remote} from 'electron';
export class TextFileService extends AbstractTextFileService {
......@@ -182,7 +180,7 @@ export class TextFileService extends AbstractTextFileService {
buttons.push(cancel, dontSave);
}
let opts: remote.IMessageBoxOptions = {
let opts: Electron.Dialog.ShowMessageBoxOptions = {
title: this.contextService.getConfiguration().env.appName,
message: message.join('\n'),
type: 'warning',
......@@ -192,7 +190,7 @@ export class TextFileService extends AbstractTextFileService {
cancelId: buttons.indexOf(cancel)
};
const choice = Dialog.showMessageBox(remote.getCurrentWindow(), opts);
const choice = remote.dialog.showMessageBox(remote.getCurrentWindow(), opts);
return buttons[choice].result;
}
......@@ -365,18 +363,18 @@ export class TextFileService extends AbstractTextFileService {
private promptForPathAsync(defaultPath?: string): TPromise<string> {
return new TPromise<string>((c, e) => {
Dialog.showSaveDialog(remote.getCurrentWindow(), this.getSaveDialogOptions(defaultPath ? paths.normalize(defaultPath, true) : void 0), (path) => {
remote.dialog.showSaveDialog(remote.getCurrentWindow(), this.getSaveDialogOptions(defaultPath ? paths.normalize(defaultPath, true) : void 0), (path) => {
c(path);
});
});
}
private promptForPathSync(defaultPath?: string): string {
return Dialog.showSaveDialog(remote.getCurrentWindow(), this.getSaveDialogOptions(defaultPath ? paths.normalize(defaultPath, true) : void 0));
return remote.dialog.showSaveDialog(remote.getCurrentWindow(), this.getSaveDialogOptions(defaultPath ? paths.normalize(defaultPath, true) : void 0));
}
private getSaveDialogOptions(defaultPath?: string): remote.ISaveDialogOptions {
let options: remote.ISaveDialogOptions = {
private getSaveDialogOptions(defaultPath?: string): Electron.Dialog.SaveDialogOptions {
let options: Electron.Dialog.SaveDialogOptions = {
defaultPath: defaultPath
};
......
......@@ -4,10 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import {ipcMain as ipc} from 'electron';
import { ipcMain as ipc, BrowserWindow} from 'electron';
import platform = require('vs/base/common/platform');
import { TPromise } from 'vs/base/common/winjs.base';
import BrowserWindow = require('browser-window');
export interface ICredentials {
username: string;
......@@ -21,7 +20,7 @@ interface ICredentialsResult {
interface IContext {
credentials: ICredentials;
window: BrowserWindow;
window: Electron.BrowserWindow;
}
export class GitAskpassService {
......
......@@ -10,8 +10,7 @@ import env = require('vs/workbench/electron-main/env');
import events = require('vs/base/common/eventEmitter');
import platform = require('vs/base/common/platform');
import BrowserWindow = require('browser-window');
import {ipcMain as ipc} from 'electron';
import { ipcMain as ipc, BrowserWindow } from 'electron';
interface ICredentialsContext {
id: number;
......@@ -31,7 +30,7 @@ interface ICredentialsResult {
interface IContext {
credentials: ICredentials;
window: BrowserWindow;
window: Electron.BrowserWindow;
}
export function configure(bus: events.EventEmitter): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册