From c52155b621c3743e825a410791bfa96cb6f1506e Mon Sep 17 00:00:00 2001 From: Barbara Valdez <34872381+barbaravaldez@users.noreply.github.com> Date: Fri, 31 Jul 2020 14:44:45 -0700 Subject: [PATCH] Add setting for collapsing/expanding books at root level (#11543) * Add setting for max number of expanded books * Remove extra commas * Add setting for expanding/collapsing books at root level * Change typo in name of setting * Change default value to false --- extensions/notebook/package.json | 5 +++++ extensions/notebook/package.nls.json | 1 + extensions/notebook/src/book/bookModel.ts | 9 ++++++++- extensions/notebook/src/common/constants.ts | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/extensions/notebook/package.json b/extensions/notebook/package.json index 9e348aa69a..cc47ffa5ae 100644 --- a/extensions/notebook/package.json +++ b/extensions/notebook/package.json @@ -17,6 +17,11 @@ "type": "object", "title": "%notebook.configuration.title%", "properties": { + "notebook.collapseBookItems": { + "type": "boolean", + "default": false, + "description": "%notebook.collapseBookItems.description%" + }, "notebook.maxBookSearchDepth": { "type": "number", "default": 10, diff --git a/extensions/notebook/package.nls.json b/extensions/notebook/package.nls.json index c3ef7cce3f..8de1680e01 100644 --- a/extensions/notebook/package.nls.json +++ b/extensions/notebook/package.nls.json @@ -8,6 +8,7 @@ "notebook.maxTableRows.description": "Maximum number of rows returned per table in the Notebook editor", "notebook.trustedBooks.description": "Notebooks contained in these books will automatically be trusted.", "notebook.maxBookSearchDepth.description": "Maximum depth of subdirectories to search for Books (Enter 0 for infinite)", + "notebook.collapseBookItems.description": "Collapse Book items at root level in the Notebooks Viewlet", "notebook.remoteBookDownloadTimeout.description": "Download timeout in milliseconds for GitHub books", "notebook.command.new": "New Notebook", "notebook.command.open": "Open Notebook", diff --git a/extensions/notebook/src/book/bookModel.ts b/extensions/notebook/src/book/bookModel.ts index 2ad2ce63e7..79b4fe2db3 100644 --- a/extensions/notebook/src/book/bookModel.ts +++ b/extensions/notebook/src/book/bookModel.ts @@ -6,6 +6,7 @@ import * as vscode from 'vscode'; import * as yaml from 'js-yaml'; import { BookTreeItem, BookTreeItemType } from './bookTreeItem'; +import * as constants from '../common/constants'; import * as path from 'path'; import * as fileServices from 'fs'; import * as fs from 'fs-extra'; @@ -102,6 +103,12 @@ export class BookModel { if (this.isNotebook) { return undefined; } + let notebookConfig = vscode.workspace.getConfiguration(constants.notebookConfigKey); + let collapsedItems = notebookConfig[constants.collapseBookItems]; + let collapsibleState = vscode.TreeItemCollapsibleState.Expanded; + if (collapsedItems) { + collapsibleState = vscode.TreeItemCollapsibleState.Collapsed; + } if (this._tableOfContentsPath) { let root: string = path.dirname(path.dirname(this._tableOfContentsPath)); @@ -117,7 +124,7 @@ export class BookModel { tableOfContents: { sections: this.parseJupyterSections(tableOfContents) }, page: tableOfContents, type: BookTreeItemType.Book, - treeItemCollapsibleState: vscode.TreeItemCollapsibleState.Expanded, + treeItemCollapsibleState: collapsibleState, isUntitled: this.openAsUntitled, }, { diff --git a/extensions/notebook/src/common/constants.ts b/extensions/notebook/src/common/constants.ts index c1e6fc80ff..f5c725b5a8 100644 --- a/extensions/notebook/src/common/constants.ts +++ b/extensions/notebook/src/common/constants.ts @@ -19,6 +19,7 @@ export const notebookConfigKey = 'notebook'; export const trustedBooksConfigKey = 'trustedBooks'; export const maxBookSearchDepth = 'maxBookSearchDepth'; export const remoteBookDownloadTimeout = 'remoteBookDownloadTimeout'; +export const collapseBookItems = 'collapseBookItems'; export const winPlatform = 'win32';