import * as vscode from 'vscode' ; import { Command } from '../util/commandManager' ; import { RSTPreviewManager } from '../preview/previewManager' ; import { PreviewSettings } from '../preview/preview' ; import { Python } from '../util/python' ; interface ShowPreviewSettings { readonly sideBySide ? : boolean ; readonly locked ? : boolean ; } async function showPreview ( webviewManager , python , uri , previewSettings ) { let resource = uri ; if ( ! ( resource instanceof vscode . Uri ) ) { if ( vscode . window . activeTextEditor ) { resource = vscode . window . activeTextEditor . document . uri ; } } if ( ! ( resource instanceof vscode . Uri ) ) { if ( ! vscode . window . activeTextEditor ) { return vscode . commands . executeCommand ( 'restructuredtext.showSource' ) ; } return ; } if ( ! await python . checkPython ( resource ) || ! await python . checkPreviewEngine ( resource ) ) { return ; } const resourceColumn = ( vscode . window . activeTextEditor && vscode . window . activeTextEditor . viewColumn ) || vscode . ViewColumn . One ; webviewManager . preview ( resource , { resourceColumn : resourceColumn , previewColumn : previewSettings . sideBySide ? resourceColumn + 1 : resourceColumn , locked : ! ! previewSettings . locked } ) ; } export class ShowPreviewCommand implements Command { public readonly id = 'restructuredtext.showPreview' ; public constructor ( private readonly webviewManager , private readonly python ) { } public execute ( mainUri ? , allUris ? , previewSettings ? ) { for ( const uri of Array . isArray ( allUris ) ? allUris : [ mainUri ] ) { showPreview ( this . webviewManager , this . python , uri , { sideBySide : false , locked : previewSettings && previewSettings . locked } ) ; } } } export class ShowPreviewToSideCommand implements Command { public readonly id = 'restructuredtext.showPreviewToSide' ; public constructor ( private readonly webviewManager , private readonly python ) { } public execute ( uri ? , previewSettings ? ) { showPreview ( this . webviewManager , this . python , uri , { sideBySide : true , locked : previewSettings && previewSettings . locked } ) ; } } export class ShowLockedPreviewToSideCommand implements Command { public readonly id = 'restructuredtext.showLockedPreviewToSide' ; public constructor ( private readonly webviewManager , private readonly python ) { } public execute ( uri ? ) { showPreview ( this . webviewManager , this . python , uri , { sideBySide : true , locked : true } ) ; } }