提交 2dac869d 编写于 作者: J Joao Moreno

api: WindowState

上级 15e4c723
...@@ -168,19 +168,30 @@ declare module 'vscode' { ...@@ -168,19 +168,30 @@ declare module 'vscode' {
export function deleteSecret(service: string, account: string): Thenable<boolean>; export function deleteSecret(service: string, account: string): Thenable<boolean>;
} }
export namespace window { /**
* Represents the state of a window.
*/
export interface WindowState {
/** /**
* Whether the current window is focused. * Whether the current window is focused.
*/
readonly focused: boolean;
}
export namespace window {
/**
* Represents the current window's state.
* *
* @readonly * @readonly
*/ */
export let isFocused: boolean; export let state: WindowState;
/** /**
* An [event](#Event) which fires when the focus state of the current window * An [event](#Event) which fires when the focus state of the current window
* changes. The value of the event represents whether the window is focused. * changes. The value of the event represents whether the window is focused.
*/ */
export const onDidChangeWindowFocus: Event<boolean>; export const onDidChangeWindowState: Event<WindowState>;
} }
} }
...@@ -310,11 +310,11 @@ export function createApiFactory( ...@@ -310,11 +310,11 @@ export function createApiFactory(
onDidCloseTerminal(listener, thisArg?, disposables?) { onDidCloseTerminal(listener, thisArg?, disposables?) {
return extHostTerminalService.onDidCloseTerminal(listener, thisArg, disposables); return extHostTerminalService.onDidCloseTerminal(listener, thisArg, disposables);
}, },
get isFocused() { get state() {
return extHostWindow.isFocused; return extHostWindow.state;
}, },
onDidChangeWindowFocus: proposedApiFunction(extension, (listener, thisArg?, disposables?) => { onDidChangeWindowState: proposedApiFunction(extension, (listener, thisArg?, disposables?) => {
return extHostWindow.onDidChangeWindowFocus(listener, thisArg, disposables); return extHostWindow.onDidChangeWindowState(listener, thisArg, disposables);
}), }),
showInformationMessage(message, first, ...rest) { showInformationMessage(message, first, ...rest) {
return extHostMessageService.showMessage(Severity.Info, message, first, rest); return extHostMessageService.showMessage(Severity.Info, message, first, rest);
......
...@@ -7,28 +7,33 @@ ...@@ -7,28 +7,33 @@
import Event, { Emitter } from 'vs/base/common/event'; import Event, { Emitter } from 'vs/base/common/event';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService'; import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { ExtHostWindowShape, MainContext, MainThreadWindowShape } from './extHost.protocol'; import { ExtHostWindowShape, MainContext, MainThreadWindowShape } from './extHost.protocol';
import { WindowState } from 'vscode';
export class ExtHostWindow implements ExtHostWindowShape { export class ExtHostWindow implements ExtHostWindowShape {
private static InitialState: WindowState = {
focused: true
};
private _proxy: MainThreadWindowShape; private _proxy: MainThreadWindowShape;
private _onDidChangeWindowFocus = new Emitter<boolean>(); private _onDidChangeWindowState = new Emitter<WindowState>();
readonly onDidChangeWindowFocus: Event<boolean> = this._onDidChangeWindowFocus.event; readonly onDidChangeWindowState: Event<WindowState> = this._onDidChangeWindowState.event;
private _isFocused = true; private _state = ExtHostWindow.InitialState;
get isFocused(): boolean { return this._isFocused; } get state(): WindowState { return this._state; }
constructor(threadService: IThreadService) { constructor(threadService: IThreadService) {
this._proxy = threadService.get(MainContext.MainThreadWindow); this._proxy = threadService.get(MainContext.MainThreadWindow);
this._proxy.$getWindowVisibility().then(isFocused => this.$onDidChangeWindowFocus(isFocused)); this._proxy.$getWindowVisibility().then(isFocused => this.$onDidChangeWindowFocus(isFocused));
} }
$onDidChangeWindowFocus(isFocused: boolean): void { $onDidChangeWindowFocus(focused: boolean): void {
if (isFocused === this._isFocused) { if (focused === this._state.focused) {
return; return;
} }
this._isFocused = isFocused; this._state = { ...this._state, focused };
this._onDidChangeWindowFocus.fire(isFocused); this._onDidChangeWindowState.fire(this._state);
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册