diff --git a/extensions/notebook/src/book/bookModel.ts b/extensions/notebook/src/book/bookModel.ts index 407c2a4b7d..20175f10ae 100644 --- a/extensions/notebook/src/book/bookModel.ts +++ b/extensions/notebook/src/book/bookModel.ts @@ -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, - 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, diff --git a/extensions/notebook/src/book/bookPinManager.ts b/extensions/notebook/src/book/bookPinManager.ts index d2e80fef18..3a262ad96f 100644 --- a/extensions/notebook/src/book/bookPinManager.ts +++ b/extensions/notebook/src/book/bookPinManager.ts @@ -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; @@ -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; } diff --git a/extensions/notebook/src/book/bookTreeView.ts b/extensions/notebook/src/book/bookTreeView.ts index 13f6c6aa4c..4a198241c2 100644 --- a/extensions/notebook/src/book/bookTreeView.ts +++ b/extensions/notebook/src/book/bookTreeView.ts @@ -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 { 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 { 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 { + private async createAndAddBookModel(bookPath: string, isNotebook: boolean, notebookDetails?: IPinnedNotebook): Promise { 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) { diff --git a/extensions/notebook/src/common/utils.ts b/extensions/notebook/src/common/utils.ts index 4dc7954d28..7244f89812 100644 --- a/extensions/notebook/src/common/utils.ts +++ b/extensions/notebook/src/common/utils.ts @@ -435,7 +435,7 @@ export async function getRandomToken(size: number = 24): Promise { } export function isBookItemPinned(notebookPath: string): boolean { - let pinnedNotebooks: IBookNotebook[] = getPinnedNotebooks(); + let pinnedNotebooks: IPinnedNotebook[] = getPinnedNotebooks(); if (pinnedNotebooks?.find(x => x.notebookPath === notebookPath)) { return true; } @@ -451,16 +451,16 @@ export function getNotebookType(book: BookTreeItemFormat): BookTreeItemType { } } -export function getPinnedNotebooks(): IBookNotebook[] { +export function getPinnedNotebooks(): IPinnedNotebook[] { let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(notebookConfigKey); let pinnedNotebooks: [] = config.get(pinnedBooksConfigKey); let updateFormat: boolean = false; const pinnedBookDirectories = pinnedNotebooks.map(elem => { if (typeof (elem) === 'string') { updateFormat = true; - return { notebookPath: elem, bookPath: '' }; + return { notebookPath: elem, bookPath: '', title: '' }; } else { - return elem as IBookNotebook; + return elem as IPinnedNotebook; } }); if (updateFormat) { @@ -475,7 +475,7 @@ function hasWorkspaceFolders(): boolean { return workspaceFolders && workspaceFolders.length > 0; } -export async function setPinnedBookPathsInConfig(pinnedNotebookPaths: IBookNotebook[]): Promise { +export async function setPinnedBookPathsInConfig(pinnedNotebookPaths: IPinnedNotebook[]): Promise { let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(notebookConfigKey); let storeInWorspace: boolean = hasWorkspaceFolders(); @@ -483,8 +483,9 @@ export async function setPinnedBookPathsInConfig(pinnedNotebookPaths: IBookNoteb } -export interface IBookNotebook { +export interface IPinnedNotebook { bookPath?: string; + title?: string; notebookPath: string; } diff --git a/extensions/notebook/src/test/common/utils.test.ts b/extensions/notebook/src/test/common/utils.test.ts index f171f91dfd..a438aa41be 100644 --- a/extensions/notebook/src/test/common/utils.test.ts +++ b/extensions/notebook/src/test/common/utils.test.ts @@ -459,7 +459,7 @@ describe('Utils Tests', function () { describe('getPinnedNotebooks', function (): void { it('Should NOT have any pinned notebooks', async function (): Promise { - let pinnedNotebooks: utils.IBookNotebook[] = utils.getPinnedNotebooks(); + let pinnedNotebooks: utils.IPinnedNotebook[] = utils.getPinnedNotebooks(); should(pinnedNotebooks.length).equal(0, 'Should not have any pinned notebooks'); });