mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Open books in VS Code notebooks if the setting is enabled. (#22031)
This commit is contained in:
@@ -19,6 +19,9 @@
|
|||||||
"supported": true
|
"supported": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"enabledApiProposals": [
|
||||||
|
"notebookEditor"
|
||||||
|
],
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"configuration": {
|
"configuration": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|||||||
@@ -395,13 +395,23 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get useVSCodeNotebooks(): boolean {
|
||||||
|
let workbench = vscode.workspace.getConfiguration('workbench');
|
||||||
|
return workbench?.get<boolean>('useVSCodeNotebooks') && workbench?.get<boolean>('enablePreviewFeatures');
|
||||||
|
}
|
||||||
|
|
||||||
async openNotebook(resource: string): Promise<void> {
|
async openNotebook(resource: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await vscode.commands.executeCommand(constants.BuiltInCommands.SetContext, constants.unsavedBooksContextKey, false);
|
await vscode.commands.executeCommand(constants.BuiltInCommands.SetContext, constants.unsavedBooksContextKey, false);
|
||||||
if (this._openAsUntitled) {
|
if (this._openAsUntitled) {
|
||||||
await this.openNotebookAsUntitled(resource);
|
await this.openNotebookAsUntitled(resource);
|
||||||
} else {
|
} else {
|
||||||
await azdata.nb.showNotebookDocument(vscode.Uri.file(resource));
|
if (this.useVSCodeNotebooks) {
|
||||||
|
let doc = await vscode.workspace.openNotebookDocument(vscode.Uri.file(resource));
|
||||||
|
await vscode.window.showNotebookDocument(doc);
|
||||||
|
} else {
|
||||||
|
await azdata.nb.showNotebookDocument(vscode.Uri.file(resource));
|
||||||
|
}
|
||||||
// let us keep a list of already visited notebooks so that we do not trust them again, potentially
|
// let us keep a list of already visited notebooks so that we do not trust them again, potentially
|
||||||
// overriding user changes
|
// overriding user changes
|
||||||
let normalizedResource = path.normalize(resource);
|
let normalizedResource = path.normalize(resource);
|
||||||
@@ -532,13 +542,19 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
|||||||
async openNotebookAsUntitled(resource: string): Promise<void> {
|
async openNotebookAsUntitled(resource: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await vscode.commands.executeCommand(constants.BuiltInCommands.SetContext, constants.unsavedBooksContextKey, true);
|
await vscode.commands.executeCommand(constants.BuiltInCommands.SetContext, constants.unsavedBooksContextKey, true);
|
||||||
let untitledFileName: vscode.Uri = this.getUntitledNotebookUri(resource);
|
let untitledFileUri: vscode.Uri = this.getUntitledNotebookUri(resource);
|
||||||
let document: vscode.TextDocument = await vscode.workspace.openTextDocument(resource);
|
|
||||||
await azdata.nb.showNotebookDocument(untitledFileName, {
|
if (this.useVSCodeNotebooks) {
|
||||||
connectionProfile: null,
|
let doc = await vscode.workspace.openNotebookDocument(untitledFileUri);
|
||||||
initialContent: document.getText(),
|
await vscode.window.showNotebookDocument(doc);
|
||||||
initialDirtyState: false
|
} else {
|
||||||
});
|
let document: vscode.TextDocument = await vscode.workspace.openTextDocument(resource);
|
||||||
|
await azdata.nb.showNotebookDocument(untitledFileUri, {
|
||||||
|
connectionProfile: null,
|
||||||
|
initialContent: document.getText(),
|
||||||
|
initialDirtyState: false
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
void vscode.window.showErrorMessage(loc.openUntitledNotebookError(resource, e instanceof Error ? e.message : e));
|
void vscode.window.showErrorMessage(loc.openUntitledNotebookError(resource, e instanceof Error ? e.message : e));
|
||||||
}
|
}
|
||||||
|
|||||||
1
extensions/notebook/src/typings/refs.d.ts
vendored
1
extensions/notebook/src/typings/refs.d.ts
vendored
@@ -6,4 +6,5 @@
|
|||||||
/// <reference path='../../../../src/sql/azdata.d.ts'/>
|
/// <reference path='../../../../src/sql/azdata.d.ts'/>
|
||||||
/// <reference path='../../../../src/sql/azdata.proposed.d.ts'/>
|
/// <reference path='../../../../src/sql/azdata.proposed.d.ts'/>
|
||||||
/// <reference path='../../../../src/vscode-dts/vscode.d.ts'/>
|
/// <reference path='../../../../src/vscode-dts/vscode.d.ts'/>
|
||||||
|
/// <reference path='../../../../src/vscode-dts/vscode.proposed.notebookEditor.d.ts'/>
|
||||||
/// <reference types='@types/node'/>
|
/// <reference types='@types/node'/>
|
||||||
|
|||||||
Reference in New Issue
Block a user