Feat/create book (#9159)

* added secondary action

* create book command

* open as untitled

* create toc.yml and update title

* added comments

* throw error if filenames have unsupported chars

* update prompt message

* remove the toLocaleLower

* added await

* moced createbookpath out of the command handler

* removed tolocalelower and added comments

* moved the formatting and file handling code from core to notebook

* fixes for contents with folders

* collapse the code cell

* remove output

* reused existing command to open book

* comment typu and added await
This commit is contained in:
Maddy
2020-03-02 12:45:53 -08:00
committed by GitHub
parent 01db78f743
commit c1f6a67829
6 changed files with 313 additions and 7 deletions

View File

@@ -149,8 +149,10 @@ export class BookModel implements azdata.nb.NavigationProvider {
notebooks.push(notebook);
}
} else {
if (!this._allNotebooks.get(pathToNotebook)) {
this._allNotebooks.set(pathToNotebook, notebook);
// convert to URI to avoid casing issue with drive letters when getting navigation links
let uriToNotebook: vscode.Uri = vscode.Uri.file(pathToNotebook);
if (!this._allNotebooks.get(uriToNotebook.fsPath)) {
this._allNotebooks.set(uriToNotebook.fsPath, notebook);
notebooks.push(notebook);
}
}
@@ -205,8 +207,7 @@ export class BookModel implements azdata.nb.NavigationProvider {
}
getNavigation(uri: vscode.Uri): Thenable<azdata.nb.NavigationResult> {
let notebook: BookTreeItem =
!this.openAsUntitled ? this._allNotebooks.get(uri.fsPath) : this._allNotebooks.get(path.basename(uri.fsPath));
let notebook = !this.openAsUntitled ? this._allNotebooks.get(uri.fsPath) : this._allNotebooks.get(path.basename(uri.fsPath));
let result: azdata.nb.NavigationResult;
if (notebook) {
result = {

View File

@@ -112,8 +112,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
try {
if (this._openAsUntitled) {
this.openNotebookAsUntitled(resource);
}
else {
} else {
let doc = await vscode.workspace.openTextDocument(resource);
vscode.window.showTextDocument(doc);
}

View File

@@ -7,6 +7,7 @@ import * as vscode from 'vscode';
import * as azdata from 'azdata';
import * as os from 'os';
import * as nls from 'vscode-nls';
import * as path from 'path';
import { JupyterController } from './jupyter/jupyterController';
import { AppContext } from './common/appContext';
@@ -28,6 +29,7 @@ let controller: JupyterController;
type ChooseCellType = { label: string, id: CellType };
export async function activate(extensionContext: vscode.ExtensionContext): Promise<IExtensionApi> {
const createBookPath: string = path.posix.join(extensionContext.extensionPath, 'resources', 'notebooks', 'JupyterBooksCreate.ipynb');
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openBook', (bookPath: string, openAsUntitled: boolean, urlToOpen?: string) => openAsUntitled ? untitledBookTreeViewProvider.openBook(bookPath, urlToOpen) : bookTreeViewProvider.openBook(bookPath, urlToOpen)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openNotebook', (resource) => bookTreeViewProvider.openNotebook(resource)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openUntitledNotebook', (resource) => untitledBookTreeViewProvider.openNotebookAsUntitled(resource)));
@@ -38,6 +40,16 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchUntitledBook', () => untitledBookTreeViewProvider.searchJupyterBooks()));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.openBook', () => bookTreeViewProvider.openNewBook()));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.createBook', async () => {
let untitledFileName: vscode.Uri = vscode.Uri.parse(`untitled:${createBookPath}`);
await vscode.workspace.openTextDocument(createBookPath).then((document) => {
azdata.nb.showNotebookDocument(untitledFileName, {
connectionProfile: null,
initialContent: document.getText(),
initialDirtyState: false
});
});
}));
extensionContext.subscriptions.push(vscode.commands.registerCommand('_notebook.command.new', (context?: azdata.ConnectedContext) => {
let connectionProfile: azdata.IConnectionProfile = undefined;
if (context && context.connectionProfile) {