[Backend] Editing and creating books (#13089)

* Add interface for modifying the table of contents of books

* Add logic for creating toc

* Fix issue with toc

* Add test for creating toc

* Delete bookTocManager.test.ts

* update allowed extensions

* Fix failing tests and add test

* Add tests for creating books

* Remove unused methods

* add section to section
This commit is contained in:
Barbara Valdez
2020-11-02 14:55:44 -08:00
committed by GitHub
parent 04117b2333
commit 036faeb06d
4 changed files with 583 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ import * as glob from 'fast-glob';
import { IJupyterBookSectionV2, IJupyterBookSectionV1 } from '../contracts/content';
import { debounce, getPinnedNotebooks } from '../common/utils';
import { IBookPinManager, BookPinManager } from './bookPinManager';
import { BookTocManager, IBookTocManager } from './bookTocManager';
const content = 'content';
@@ -36,6 +37,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
private _openAsUntitled: boolean;
private _bookTrustManager: IBookTrustManager;
public bookPinManager: IBookPinManager;
public bookTocManager: IBookTocManager;
private _bookViewer: vscode.TreeView<BookTreeItem>;
public viewId: string;
@@ -47,6 +49,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
this._extensionContext = extensionContext;
this.books = [];
this.bookPinManager = new BookPinManager();
this.bookTocManager = new BookTocManager();
this.viewId = view;
this.initialize(workspaceFolders).catch(e => console.error(e));
this.prompter = new CodeAdapter();
@@ -131,6 +134,16 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
}
}
async createBook(bookPath: string, contentPath: string): Promise<void> {
bookPath = path.normalize(bookPath);
contentPath = path.normalize(contentPath);
await this.bookTocManager.createBook(bookPath, contentPath);
}
async editBook(book: BookTreeItem, section: BookTreeItem): Promise<void> {
await this.bookTocManager.updateBook(section, book);
}
async openBook(bookPath: string, urlToOpen?: string, showPreview?: boolean, isNotebook?: boolean): Promise<void> {
try {
// Convert path to posix style for easier comparisons