forked from asciidoctor/asciidoctor-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
showPreviewSecuritySelector.ts
30 lines (26 loc) · 1.53 KB
/
showPreviewSecuritySelector.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*---------------------------------------------------------------------------------------------
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode'
import { Command } from '../commandManager'
import { PreviewSecuritySelector } from '../security'
import { isAsciidocFile } from '../util/file'
import { AsciidocPreviewManager } from '../features/previewManager'
export class ShowPreviewSecuritySelectorCommand implements Command {
public readonly id = 'asciidoc.showPreviewSecuritySelector'
constructor (private readonly previewSecuritySelector: PreviewSecuritySelector,
private readonly previewManager: AsciidocPreviewManager) {
this.previewManager = previewManager
this.previewSecuritySelector = previewSecuritySelector
}
public execute (resource: string | undefined) {
if (this.previewManager.activePreviewResource) {
this.previewSecuritySelector.showSecuritySelectorForResource(this.previewManager.activePreviewResource)
} else if (resource) {
const source = vscode.Uri.parse(resource)
this.previewSecuritySelector.showSecuritySelectorForResource(source.query ? vscode.Uri.parse(source.query) : source)
} else if (vscode.window.activeTextEditor && isAsciidocFile(vscode.window.activeTextEditor.document)) {
this.previewSecuritySelector.showSecuritySelectorForResource(vscode.window.activeTextEditor.document.uri)
}
}
}