Show book's notebook TOC title in pinned notebooks view (#15583)

* Show notebook title in pinned notebooks view

* fix test

* change interface name
This commit is contained in:
Barbara Valdez
2021-05-27 14:09:51 -07:00
committed by GitHub
parent 2d71397ffe
commit aef6511ba6
5 changed files with 21 additions and 20 deletions

View File

@@ -13,7 +13,7 @@ import * as fs from 'fs-extra';
import * as loc from '../common/localizedConstants';
import { IJupyterBookToc, JupyterBookSection } from '../contracts/content';
import { convertFrom, getContentPath, BookVersion } from './bookVersionHandler';
import { debounce } from '../common/utils';
import { debounce, IPinnedNotebook } from '../common/utils';
import { Deferred } from '../common/promise';
const fsPromises = fileServices.promises;
const content = 'content';
@@ -39,7 +39,7 @@ export class BookModel {
public readonly isNotebook: boolean,
private _extensionContext: vscode.ExtensionContext,
private _onDidChangeTreeData: vscode.EventEmitter<BookTreeItem | undefined>,
public readonly notebookRootPath?: string) { }
public readonly pinnedNotebookDetails?: IPinnedNotebook) { }
public unwatchTOC(): void {
fs.unwatchFile(this.tableOfContentsPath);
@@ -141,9 +141,9 @@ export class BookModel {
let pathDetails = path.parse(this.bookPath);
let notebookItem = new BookTreeItem({
title: pathDetails.name,
title: this.pinnedNotebookDetails?.title ?? pathDetails.name,
contentPath: this.bookPath,
root: this.notebookRootPath ? this.notebookRootPath : pathDetails.dir,
root: this.pinnedNotebookDetails?.bookPath ?? pathDetails.dir,
tableOfContents: { sections: undefined },
page: { sections: undefined },
type: BookTreeItemType.Notebook,

View File

@@ -6,7 +6,7 @@ import * as path from 'path';
import * as vscode from 'vscode';
import * as constants from './../common/constants';
import { BookTreeItem } from './bookTreeItem';
import { getPinnedNotebooks, setPinnedBookPathsInConfig, IBookNotebook } from '../common/utils';
import { getPinnedNotebooks, setPinnedBookPathsInConfig, IPinnedNotebook } from '../common/utils';
export interface IBookPinManager {
pinNotebook(notebook: BookTreeItem): Promise<boolean>;
@@ -51,14 +51,14 @@ export class BookPinManager implements IBookPinManager {
let modifiedPinnedBooks = false;
let bookPathToChange: string = notebook.book.contentPath;
let pinnedBooks: IBookNotebook[] = getPinnedNotebooks();
let pinnedBooks: IPinnedNotebook[] = getPinnedNotebooks();
let existingBookIndex = pinnedBooks.map(pinnedBookPath => path.normalize(pinnedBookPath?.notebookPath)).indexOf(path.normalize(bookPathToChange));
if (existingBookIndex !== -1 && operation === PinBookOperation.Unpin) {
pinnedBooks.splice(existingBookIndex, 1);
modifiedPinnedBooks = true;
} else if (existingBookIndex === -1 && operation === PinBookOperation.Pin) {
let addNotebook: IBookNotebook = { notebookPath: bookPathToChange, bookPath: notebook.book.root };
let addNotebook: IPinnedNotebook = { notebookPath: bookPathToChange, bookPath: notebook.book.root, title: notebook.book.title };
pinnedBooks.push(addNotebook);
modifiedPinnedBooks = true;
}

View File

@@ -16,7 +16,7 @@ import { Deferred } from '../common/promise';
import { IBookTrustManager, BookTrustManager } from './bookTrustManager';
import * as loc from '../common/localizedConstants';
import * as glob from 'fast-glob';
import { getPinnedNotebooks, confirmMessageDialog, getNotebookType, FileExtension } from '../common/utils';
import { getPinnedNotebooks, confirmMessageDialog, getNotebookType, FileExtension, IPinnedNotebook } from '../common/utils';
import { IBookPinManager, BookPinManager } from './bookPinManager';
import { BookTocManager, IBookTocManager, quickPickResults } from './bookTocManager';
import { CreateBookDialog } from '../dialog/createBookDialog';
@@ -78,7 +78,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
if (this.viewId === constants.PINNED_BOOKS_VIEWID) {
await Promise.all(getPinnedNotebooks().map(async (notebook) => {
try {
await this.createAndAddBookModel(notebook.notebookPath, true, notebook.bookPath);
await this.createAndAddBookModel(notebook.notebookPath, true, notebook);
} catch {
// no-op, not all workspace folders are going to be valid books
}
@@ -254,8 +254,8 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
async addNotebookToPinnedView(bookItem: BookTreeItem): Promise<void> {
let notebookPath: string = bookItem.book.contentPath;
if (notebookPath) {
let rootPath: string = bookItem.book.root ? bookItem.book.root : '';
await this.createAndAddBookModel(notebookPath, true, rootPath);
let notebookDetails: IPinnedNotebook = bookItem.book.root ? { bookPath: bookItem.book.root, notebookPath: notebookPath, title: bookItem.book.title } : { notebookPath: notebookPath };
await this.createAndAddBookModel(notebookPath, true, notebookDetails);
}
}
@@ -318,9 +318,9 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
* @param isNotebook A boolean value to know we are creating a model for a notebook or a book
* @param notebookBookRoot For pinned notebooks we need to know if the notebook is part of a book or it's a standalone notebook
*/
private async createAndAddBookModel(bookPath: string, isNotebook: boolean, notebookBookRoot?: string): Promise<void> {
private async createAndAddBookModel(bookPath: string, isNotebook: boolean, notebookDetails?: IPinnedNotebook): Promise<void> {
if (!this.books.find(x => x.bookPath === bookPath)) {
const book: BookModel = new BookModel(bookPath, this._openAsUntitled, isNotebook, this._extensionContext, this._onDidChangeTreeData, notebookBookRoot);
const book: BookModel = new BookModel(bookPath, this._openAsUntitled, isNotebook, this._extensionContext, this._onDidChangeTreeData, notebookDetails);
await book.initializeContents();
this.books.push(book);
if (!this.currentBook) {