r.vscode.api.window
=== window
- dealing with the current window of the editor. That is visible and active editors, as well as, UI elements to show messages, selections, and asking for user input.
properties
visibleTextEditors: TextEditor[]
state: WindowState
events
onDidChangeActiveTextEditor: Event<TextEditor | undefined>
An event which fires when the active editor has changed. Note that the event also fires when the active editor changes to undefined.
- NOTE: text editor passed in is the text editor that will be switched to
onDidCloseTerminal
Extensions can now determine whether terminals have exited and if they did, which exit code was used (if any).
window.onDidCloseTerminal((t) => {
if (t.exitStatus && t.exitStatus.code) {
vscode.window.showInformationMessage(`Exit code: ${t.exitStatus.code}`);
}
});
methods
createInputBox(): InputBox
createOutputChannel(name: string): OutputChannel
createQuickPick
createQuickPick<T extends QuickPickItem>(): QuickPick<T>
createTextEditorDecorationType
const smallNumberDecorationType = vscode.window.createTextEditorDecorationType({
borderWidth: '1px',
borderStyle: 'solid',
overviewRulerColor: 'blue',
overviewRulerLane: vscode.OverviewRulerLane.Right,
light: {
// this color will be used in light color themes
borderColor: 'darkblue'
},
dark: {
// this color will be used in dark color themes
borderColor: 'lightblue'
}
});
const largeNumberDecorationType = vscode.window.createTextEditorDecorationType({
cursor: 'crosshair',
// use a themable color. See package.json for the declaration and default values.
backgroundColor: { id: 'myextension.largeNumberBackground' }
});
createWebviewPanel
(
viewType: string,
title: string,
showOptions: ViewColumn | {preserveFocus: boolean, viewColumn: ViewColumn}, options?: WebviewPanelOptions & WebviewOptions
): WebviewPanel
- webview pr.vscode.api.workspace#web-view-options
showInformationMessage
showInformationMessage(message: string, ...items: string[]): Thenable<string | undefined>
- params:
- items: A set of items that will be rendered as actions in the message.
- return:
- A thenable that resolves to the selected item or undefined when being dismissed.
vscode.window.showInformationMessage('Hello World!');
use button
vscode.window
.showInformationMessage(
`Dendron has been upgraded to ${version} from ${previousVersion}`,
"See what changed"
)
.then((resp) => {
if (resp === "See what changed") {
vscode.commands.executeCommand(
"vscode.open",
vscode.Uri.parse(
"https://dendron.so/notes/9bc92432-a24c-492b-b831-4d5378c1692b.html"
)
);
}
});
}
showInputBox
(options?: InputBoxOptions, token?: CancellationToken): Thenable<string | undefined>
- params:
- options?: InputBoxOptions
- token?: CancellationToken
- InputBoxOptions
validateInput(value: string): string | undefined | null | Thenable<string | undefined | null>
- return:
- A human-readable string which is presented as diagnostic message. Return undefined, null, or the empty string when 'value' is valid.
- return:
- return
- sig: Thenable<string | undefined>
- The returned value will be undefined if the input box was canceled (e.g. pressing ESC). Otherwise the returned value will be the string typed by the user or an empty string if the user did not type anything but dismissed the input box with OK.
showQuickPick
- signature
(
items: string[] | Thenable<string[]>, options: QuickPickOptions & {canPickMany: true}, token?: CancellationToken
): Thenable<string[] | undefined>
showTextDocument
- sig1
(
document: TextDocument, column?: ViewColumn, preserveFocus?: boolean
): Thenable<TextEditor>
- sig2
showTextDocument(document: TextDocument, options?: TextDocumentShowOptions): Thenable<TextEditor>
- sig3
showTextDocument(uri: Uri, options?: TextDocumentShowOptions): Thenable<TextEditor>
- options: TextDocumentShowOptions
- preserveFocus?: boolean
- preview?: boolean
- selection?: Range
- viewColumn?: ViewColumn
withProgress
window.withProgress({
location: ProgressLocation.Notification,
title: "I am long running!",
cancellable: true
}, (progress, token) => {
token.onCancellationRequested(() => {
console.log("User canceled the long running operation");
});
progress.report({ increment: 0 });
setTimeout(() => {
progress.report({ increment: 10, message: "I am long running! - still going..." });
}, 1000);
setTimeout(() => {
progress.report({ increment: 40, message: "I am long running! - still going even more..." });
}, 2000);
setTimeout(() => {
progress.report({ increment: 50, message: "I am long running! - almost there..." });
}, 3000);
const p = new Promise(resolve => {
setTimeout(() => {
resolve();
}, 5000);
});
return p;
});