/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; import { TPromise } from 'vs/base/common/winjs.base'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import Event from 'vs/base/common/event'; import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry'; import { IProcessEnvironment } from 'vs/base/common/platform'; import { ParsedArgs } from 'vs/platform/environment/common/environment'; import { IWorkspaceIdentifier, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces'; import { IRecentlyOpened } from 'vs/platform/history/common/history'; import { ICommandAction } from 'vs/platform/actions/common/actions'; import { PerformanceEntry } from 'vs/base/common/performance'; export const IWindowsService = createDecorator('windowsService'); export interface INativeOpenDialogOptions { windowId?: number; forceNewWindow?: boolean; dialogOptions?: OpenDialogOptions; telemetryEventName?: string; telemetryExtraData?: ITelemetryData; } export interface IEnterWorkspaceResult { workspace: IWorkspaceIdentifier; backupPath: string; } export interface CrashReporterStartOptions { companyName?: string; submitURL: string; productName?: string; uploadToServer?: boolean; ignoreSystemCrashHandler?: boolean; extra?: any; crashesDirectory?: string; } export interface OpenDialogOptions { title?: string; defaultPath?: string; buttonLabel?: string; filters?: FileFilter[]; properties?: Array<'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory'>; message?: string; } export interface FileFilter { extensions: string[]; name: string; } export interface MessageBoxOptions { type?: string; buttons?: string[]; defaultId?: number; title?: string; message: string; detail?: string; checkboxLabel?: string; checkboxChecked?: boolean; cancelId?: number; noLink?: boolean; normalizeAccessKeys?: boolean; } export interface SaveDialogOptions { title?: string; defaultPath?: string; buttonLabel?: string; filters?: FileFilter[]; message?: string; nameFieldLabel?: string; showsTagField?: boolean; } export interface OpenDialogOptions { title?: string; defaultPath?: string; buttonLabel?: string; filters?: FileFilter[]; properties?: Array<'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory'>; message?: string; } export interface IWindowsService { _serviceBrand: any; onWindowOpen: Event; onWindowFocus: Event; onWindowBlur: Event; pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise; pickFileAndOpen(options: INativeOpenDialogOptions): TPromise; pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise; pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise; reloadWindow(windowId: number): TPromise; openDevTools(windowId: number): TPromise; toggleDevTools(windowId: number): TPromise; closeWorkspace(windowId: number): TPromise; createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise; saveAndEnterWorkspace(windowId: number, path: string): TPromise; toggleFullScreen(windowId: number): TPromise; setRepresentedFilename(windowId: number, fileName: string): TPromise; addRecentlyOpened(files: string[]): TPromise; removeFromRecentlyOpened(paths: string[]): TPromise; clearRecentlyOpened(): TPromise; getRecentlyOpened(windowId: number): TPromise; focusWindow(windowId: number): TPromise; closeWindow(windowId: number): TPromise; isFocused(windowId: number): TPromise; isMaximized(windowId: number): TPromise; maximizeWindow(windowId: number): TPromise; unmaximizeWindow(windowId: number): TPromise; onWindowTitleDoubleClick(windowId: number): TPromise; setDocumentEdited(windowId: number, flag: boolean): TPromise; quit(): TPromise; relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise; // macOS Native Tabs showPreviousWindowTab(): TPromise; showNextWindowTab(): TPromise; moveWindowTabToNewWindow(): TPromise; mergeAllWindowTabs(): TPromise; toggleWindowTabsBar(): TPromise; // macOS TouchBar updateTouchBar(windowId: number, items: ICommandAction[][]): TPromise; // Shared process whenSharedProcessReady(): TPromise; toggleSharedProcess(): TPromise; // Global methods openWindow(paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean; }): TPromise; openNewWindow(): TPromise; showWindow(windowId: number): TPromise; getWindows(): TPromise<{ id: number; workspace?: IWorkspaceIdentifier; folderPath?: string; title: string; filename?: string; }[]>; getWindowCount(): TPromise; log(severity: string, ...messages: string[]): TPromise; showItemInFolder(path: string): TPromise; // This needs to be handled from browser process to prevent // foreground ordering issues on Windows openExternal(url: string): TPromise; // TODO: this is a bit backwards startCrashReporter(config: CrashReporterStartOptions): TPromise; } export const IWindowService = createDecorator('windowService'); export interface IMessageBoxResult { button: number; checkboxChecked?: boolean; } export interface IWindowService { _serviceBrand: any; onDidChangeFocus: Event; getConfiguration(): IWindowConfiguration; getCurrentWindowId(): number; pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise; pickFileAndOpen(options: INativeOpenDialogOptions): TPromise; pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise; pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise; reloadWindow(): TPromise; openDevTools(): TPromise; toggleDevTools(): TPromise; closeWorkspace(): TPromise; updateTouchBar(items: ICommandAction[][]): TPromise; createAndEnterWorkspace(folders?: IWorkspaceFolderCreationData[], path?: string): TPromise; saveAndEnterWorkspace(path: string): TPromise; toggleFullScreen(): TPromise; setRepresentedFilename(fileName: string): TPromise; getRecentlyOpened(): TPromise; focusWindow(): TPromise; closeWindow(): TPromise; isFocused(): TPromise; setDocumentEdited(flag: boolean): TPromise; onWindowTitleDoubleClick(): TPromise; show(): TPromise; showMessageBox(options: MessageBoxOptions): number; showSaveDialog(options: SaveDialogOptions): string; showOpenDialog(options: OpenDialogOptions): string[]; showMessageBoxWithCheckbox(options: MessageBoxOptions): TPromise; } export type MenuBarVisibility = 'default' | 'visible' | 'toggle' | 'hidden'; export interface IWindowsConfiguration { window: IWindowSettings; } export interface IWindowSettings { openFilesInNewWindow: 'on' | 'off' | 'default'; openFoldersInNewWindow: 'on' | 'off' | 'default'; restoreWindows: 'all' | 'folders' | 'one' | 'none'; restoreFullscreen: boolean; zoomLevel: number; titleBarStyle: 'native' | 'custom'; autoDetectHighContrast: boolean; menuBarVisibility: MenuBarVisibility; newWindowDimensions: 'default' | 'inherit' | 'maximized' | 'fullscreen'; nativeTabs: boolean; enableMenuBarMnemonics: boolean; closeWhenEmpty: boolean; } export enum OpenContext { // opening when running from the command line CLI, // macOS only: opening from the dock (also when opening files to a running instance from desktop) DOCK, // opening from the main application window MENU, // opening from a file or folder dialog DIALOG, // opening from the OS's UI DESKTOP, // opening through the API API } export enum ReadyState { /** * This window has not loaded any HTML yet */ NONE, /** * This window is loading HTML */ LOADING, /** * This window is navigating to another HTML */ NAVIGATING, /** * This window is done loading HTML */ READY } export interface IPath { // the file path to open within a Code instance filePath?: string; // the line number in the file path to open lineNumber?: number; // the column number in the file path to open columnNumber?: number; } export interface IPathsToWaitFor { paths: IPath[]; waitMarkerFilePath: string; } export interface IOpenFileRequest { filesToOpen?: IPath[]; filesToCreate?: IPath[]; filesToDiff?: IPath[]; filesToWait?: IPathsToWaitFor; } export interface IAddFoldersRequest { foldersToAdd: IPath[]; } export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest { machineId: string; windowId: number; appRoot: string; execPath: string; isInitialStartup?: boolean; userEnv: IProcessEnvironment; nodeCachedDataDir: string; backupPath?: string; workspace?: IWorkspaceIdentifier; folderPath?: string; zoomLevel?: number; fullscreen?: boolean; highContrast?: boolean; baseTheme?: string; backgroundColor?: string; accessibilitySupport?: boolean; perfEntries: PerformanceEntry[]; perfStartTime?: number; perfAppReady?: number; perfWindowLoadTime?: number; } export interface IRunActionInWindowRequest { id: string; from: 'menu' | 'touchbar' | 'mouse'; }