mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 01:25:36 -05:00
* Merge from vscode 37cb23d3dd4f9433d56d4ba5ea3203580719a0bd * fix issues with merges * bump node version in azpipe * replace license headers * remove duplicate launch task * fix build errors * fix build errors * fix tslint issues * working through package and linux build issues * more work * wip * fix packaged builds * working through linux build errors * wip * wip * wip * fix mac and linux file limits * iterate linux pipeline * disable editor typing * revert series to parallel * remove optimize vscode from linux * fix linting issues * revert testing change * add work round for new node * readd packaging for extensions * fix issue with angular not resolving decorator dependencies
157 lines
4.6 KiB
TypeScript
157 lines
4.6 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as vscode from 'vscode';
|
|
import { Logger } from '../logger';
|
|
import { MarkdownContributionProvider } from '../markdownExtensions';
|
|
import { disposeAll } from '../util/dispose';
|
|
import { MarkdownFileTopmostLineMonitor } from '../util/topmostLineMonitor';
|
|
import { MarkdownPreview, PreviewSettings } from './preview';
|
|
import { MarkdownPreviewConfigurationManager } from './previewConfig';
|
|
import { MarkdownContentProvider } from './previewContentProvider';
|
|
|
|
|
|
export class MarkdownPreviewManager implements vscode.WebviewPanelSerializer {
|
|
private static readonly markdownPreviewActiveContextKey = 'markdownPreviewFocus';
|
|
|
|
private readonly _topmostLineMonitor = new MarkdownFileTopmostLineMonitor();
|
|
private readonly _previewConfigurations = new MarkdownPreviewConfigurationManager();
|
|
private readonly _previews: MarkdownPreview[] = [];
|
|
private _activePreview: MarkdownPreview | undefined = undefined;
|
|
private readonly _disposables: vscode.Disposable[] = [];
|
|
|
|
public constructor(
|
|
private readonly _contentProvider: MarkdownContentProvider,
|
|
private readonly _logger: Logger,
|
|
private readonly _contributions: MarkdownContributionProvider
|
|
) {
|
|
this._disposables.push(vscode.window.registerWebviewPanelSerializer(MarkdownPreview.viewType, this));
|
|
}
|
|
|
|
public dispose(): void {
|
|
disposeAll(this._disposables);
|
|
disposeAll(this._previews);
|
|
}
|
|
|
|
public refresh() {
|
|
for (const preview of this._previews) {
|
|
preview.refresh();
|
|
}
|
|
}
|
|
|
|
public updateConfiguration() {
|
|
for (const preview of this._previews) {
|
|
preview.updateConfiguration();
|
|
}
|
|
}
|
|
|
|
public preview(
|
|
resource: vscode.Uri,
|
|
previewSettings: PreviewSettings
|
|
): void {
|
|
let preview = this.getExistingPreview(resource, previewSettings);
|
|
if (preview) {
|
|
preview.reveal(previewSettings.previewColumn);
|
|
} else {
|
|
preview = this.createNewPreview(resource, previewSettings);
|
|
}
|
|
|
|
preview.update(resource);
|
|
}
|
|
|
|
public get activePreviewResource() {
|
|
return this._activePreview && this._activePreview.resource;
|
|
}
|
|
|
|
public toggleLock() {
|
|
const preview = this._activePreview;
|
|
if (preview) {
|
|
preview.toggleLock();
|
|
|
|
// Close any previews that are now redundant, such as having two dynamic previews in the same editor group
|
|
for (const otherPreview of this._previews) {
|
|
if (otherPreview !== preview && preview.matches(otherPreview)) {
|
|
otherPreview.dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public async deserializeWebviewPanel(
|
|
webview: vscode.WebviewPanel,
|
|
state: any
|
|
): Promise<void> {
|
|
const preview = await MarkdownPreview.revive(
|
|
webview,
|
|
state,
|
|
this._contentProvider,
|
|
this._previewConfigurations,
|
|
this._logger,
|
|
this._topmostLineMonitor,
|
|
this._contributions);
|
|
|
|
this.registerPreview(preview);
|
|
}
|
|
|
|
private getExistingPreview(
|
|
resource: vscode.Uri,
|
|
previewSettings: PreviewSettings
|
|
): MarkdownPreview | undefined {
|
|
return this._previews.find(preview =>
|
|
preview.matchesResource(resource, previewSettings.previewColumn, previewSettings.locked));
|
|
}
|
|
|
|
private createNewPreview(
|
|
resource: vscode.Uri,
|
|
previewSettings: PreviewSettings
|
|
): MarkdownPreview {
|
|
const preview = MarkdownPreview.create(
|
|
resource,
|
|
previewSettings.previewColumn,
|
|
previewSettings.locked,
|
|
this._contentProvider,
|
|
this._previewConfigurations,
|
|
this._logger,
|
|
this._topmostLineMonitor,
|
|
this._contributions);
|
|
|
|
this.setPreviewActiveContext(true);
|
|
this._activePreview = preview;
|
|
return this.registerPreview(preview);
|
|
}
|
|
|
|
private registerPreview(
|
|
preview: MarkdownPreview
|
|
): MarkdownPreview {
|
|
this._previews.push(preview);
|
|
|
|
preview.onDispose(() => {
|
|
const existing = this._previews.indexOf(preview);
|
|
if (existing === -1) {
|
|
return;
|
|
}
|
|
|
|
this._previews.splice(existing, 1);
|
|
if (this._activePreview === preview) {
|
|
this.setPreviewActiveContext(false);
|
|
this._activePreview = undefined;
|
|
}
|
|
});
|
|
|
|
preview.onDidChangeViewState(({ webviewPanel }) => {
|
|
disposeAll(this._previews.filter(otherPreview => preview !== otherPreview && preview!.matches(otherPreview)));
|
|
this.setPreviewActiveContext(webviewPanel.active);
|
|
this._activePreview = webviewPanel.active ? preview : undefined;
|
|
});
|
|
|
|
return preview;
|
|
}
|
|
|
|
private setPreviewActiveContext(value: boolean) {
|
|
vscode.commands.executeCommand('setContext', MarkdownPreviewManager.markdownPreviewActiveContextKey, value);
|
|
}
|
|
}
|
|
|