-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify input capture with back buttons
- Loading branch information
1 parent
9559f65
commit 3c095b1
Showing
8 changed files
with
241 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { CancellationError, QuickInputButtons, window } from 'vscode'; | ||
import { CancellationTokenSource, Disposable } from 'vscode-jsonrpc'; | ||
import { raceCancellationError } from '../cancellation'; | ||
import { disposeAllDisposables } from '../helpers'; | ||
import { Disposables } from '../utils'; | ||
import { createDeferred } from './async'; | ||
|
||
class BackError extends Error {} | ||
export class WorkflowInputValueProvider extends Disposables { | ||
private readonly token = this._register(new CancellationTokenSource()); | ||
public async getValue(options: { | ||
title: string; | ||
value?: string; | ||
ignoreFocusOut?: boolean; | ||
prompt?: string; | ||
validationMessage?: string; | ||
password?: boolean; | ||
}): Promise<{ value: string; navigation?: undefined } | { value?: undefined; navigation: 'cancel' | 'back' }> { | ||
console.error('Why was this called'); | ||
const disposables: Disposable[] = []; | ||
try { | ||
const input = window.createInputBox(); | ||
disposables.push(input); | ||
input.ignoreFocusOut = true; | ||
input.title = options.title; | ||
input.ignoreFocusOut = options.ignoreFocusOut === true; | ||
input.prompt = options.prompt || ''; | ||
input.value = options.value || ''; | ||
input.password = options.password === true; | ||
input.validationMessage = options.validationMessage || ''; | ||
input.buttons = [QuickInputButtons.Back]; | ||
input.show(); | ||
const deferred = createDeferred<string>(); | ||
disposables.push(input.onDidHide(() => deferred.reject(new CancellationError()))); | ||
input.onDidTriggerButton( | ||
(e) => { | ||
if (e === QuickInputButtons.Back) { | ||
deferred.reject(new BackError()); | ||
} | ||
}, | ||
this, | ||
disposables | ||
); | ||
input.onDidAccept(() => deferred.resolve(input.value.trim() || options.value), this, disposables); | ||
const value = await raceCancellationError(this.token.token, deferred.promise); | ||
return { value }; | ||
} catch (ex) { | ||
if (ex instanceof BackError) { | ||
return { navigation: 'back' }; | ||
} | ||
return { navigation: 'cancel' }; | ||
} finally { | ||
disposeAllDisposables(disposables); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.