Feat/notebooks viewlet (#10170)

* clean up unsavedBooks to providedBooks

* added notebooks viewley contribution

* added notebookExporerAction context

* temp shortcut key B

* remove commenred code

* changes with master merge

* fix comments

* initial tests

* fix casing and description

* merged master and resolved errors

* remove extension point & add custom view container

* merge latest from master

* remove unused files

* move book images to common

* remove notebookExplorer contrib & move to notebook

* build fix

* remove explorer specific sryles from common

* vscode convention to define container actions

* rename notebooks/title
This commit is contained in:
Maddy
2020-06-01 15:47:56 -07:00
committed by GitHub
parent 7305bdaec4
commit 3088c73e2b
18 changed files with 349 additions and 43 deletions

View File

@@ -339,6 +339,12 @@
"when": "false"
}
],
"notebooks/title": [
{
"command": "notebook.command.createBook",
"group": "secondary"
}
],
"touchBar": [
{
"command": "notebook.command.runactivecell",
@@ -376,12 +382,12 @@
},
{
"command": "notebook.command.searchUntitledBook",
"when": "view == unsavedBookTreeView && viewItem == unsavedBook && unsavedBooks",
"when": "view == providedBooksView && viewItem == providedBook && providedBooks",
"group": "inline"
},
{
"command": "notebook.command.saveBook",
"when": "view == unsavedBookTreeView && viewItem == unsavedBook && unsavedBooks",
"when": "view == providedBooksView && viewItem == providedBook && providedBooks",
"group": "inline"
},
{
@@ -400,8 +406,8 @@
"group": "navigation"
},
{
"command": "notebook.command.createBook",
"when": "view == bookTreeView"
"command": "books.sqlserver2019",
"when": "view == providedBooksView"
},
{
"command": "notebook.command.openNotebookFolder",
@@ -416,6 +422,18 @@
}
]
},
"views": {
"notebooks": [
{
"id": "bookTreeView",
"name": "%title.SavedBooks%"
},
{
"id": "providedBooksView",
"name": "%title.ProvidedBooks%"
}
]
},
"keybindings": [
{
"command": "notebook.command.runactivecell",
@@ -507,27 +525,6 @@
"connectionProviderIds": []
}
]
},
"viewsContainers": {
"activitybar": [
{
"id": "books-explorer",
"title": "Notebooks",
"icon": "resources/dark/JupyterBook_2.svg"
}
]
},
"views": {
"books-explorer": [
{
"id": "bookTreeView",
"name": "%title.SavedBooks%"
},
{
"id": "unsavedBookTreeView",
"name": "%title.UnsavedBooks%"
}
]
}
},
"dependencies": {

View File

@@ -34,7 +34,7 @@
"title.trustBook": "Trust Book",
"title.searchJupyterBook": "Search Book",
"title.SavedBooks": "Notebooks",
"title.UnsavedBooks": "Provided Books",
"title.ProvidedBooks": "Provided Books",
"title.PreviewLocalizedBook": "Get localized SQL Server 2019 guide",
"title.openJupyterBook": "Open Jupyter Book",
"title.closeJupyterBook": "Close Jupyter Book",

View File

@@ -1,6 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<title>ADS_jupyterBook</title>
<path d="M22.545,2.25V24H3.8a2.207,2.207,0,0,1-.878-.176,2.238,2.238,0,0,1-1.2-1.2,2.208,2.208,0,0,1-.176-.879V18H1.194c-.141,0-.28-.006-.416-.018a1.077,1.077,0,0,1-.369-.093.617.617,0,0,1-.264-.229.891.891,0,0,1,0-.82.631.631,0,0,1,.264-.229,1.1,1.1,0,0,1,.369-.093c.136-.012.275-.018.416-.018h.351v-3H1.194c-.141,0-.28-.006-.416-.018a1.077,1.077,0,0,1-.369-.093.617.617,0,0,1-.264-.229.891.891,0,0,1,0-.82.631.631,0,0,1,.264-.229,1.1,1.1,0,0,1,.369-.093c.136-.012.275-.018.416-.018h.351V9H1.194c-.141,0-.28-.006-.416-.018a1.077,1.077,0,0,1-.369-.093A.617.617,0,0,1,.145,8.66a.891.891,0,0,1,0-.82.631.631,0,0,1,.264-.229,1.1,1.1,0,0,1,.369-.093c.136-.012.275-.018.416-.018h.351v-3H1.194c-.141,0-.28-.006-.416-.018a1.077,1.077,0,0,1-.369-.093A.617.617,0,0,1,.145,4.16a.742.742,0,0,1-.1-.41.747.747,0,0,1,.1-.41.631.631,0,0,1,.264-.229,1.1,1.1,0,0,1,.369-.093C.914,3.006,1.053,3,1.194,3h.351V2.508c0-.195.008-.387.024-.574a1.689,1.689,0,0,1,.152-.563A2.221,2.221,0,0,1,3.8,0H20.3a2.215,2.215,0,0,1,.879.176,2.248,2.248,0,0,1,.715.48,2.273,2.273,0,0,1,.481.715A2.214,2.214,0,0,1,22.545,2.25Zm-1.5,17.25V2.25a.76.76,0,0,0-.75-.75H3.8a.745.745,0,0,0-.41.1.634.634,0,0,0-.228.257,1.124,1.124,0,0,0-.1.352,3.191,3.191,0,0,0-.023.393c0,.07,0,.139.006.205s0,.131,0,.193H3.4c.133,0,.268.006.4.018a1.088,1.088,0,0,1,.369.093.672.672,0,0,1,.27.229.714.714,0,0,1,.1.41.709.709,0,0,1-.1.41.657.657,0,0,1-.27.229,1.065,1.065,0,0,1-.369.093c-.136.012-.271.018-.4.018H3.045v3H3.4c.133,0,.268.006.4.018a1.088,1.088,0,0,1,.369.093.672.672,0,0,1,.27.229.853.853,0,0,1,0,.82.657.657,0,0,1-.27.229,1.065,1.065,0,0,1-.369.093C3.665,8.994,3.53,9,3.4,9H3.045v3H3.4c.133,0,.268.006.4.018a1.088,1.088,0,0,1,.369.093.672.672,0,0,1,.27.229.853.853,0,0,1,0,.82.657.657,0,0,1-.27.229,1.065,1.065,0,0,1-.369.093c-.136.012-.271.018-.4.018H3.045v3H3.4c.133,0,.268.006.4.018a1.088,1.088,0,0,1,.369.093.672.672,0,0,1,.27.229.853.853,0,0,1,0,.82.657.657,0,0,1-.27.229,1.065,1.065,0,0,1-.369.093c-.136.012-.271.018-.4.018H3.045v1.5Zm0,3V21h-18v.75a.762.762,0,0,0,.75.75Z" fill="#fff"/>
<path d="M16.545,4.5v3h-7.5v-3h7.5m1.5-1.5H7.545V9h10.5V3Z" fill="#fff"/>
<rect x="0.045" width="24" height="24" fill="none"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -1,7 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<title>ADS_jupyterBook</title>
<path d="M4.25,24A2.251,2.251,0,0,1,2,21.75V3.86A2.257,2.257,0,0,1,3.962,1.628L16.462.019A2.251,2.251,0,0,1,19,2.25H17.5a.741.741,0,0,0-.255-.563.755.755,0,0,0-.591-.181l-12.5,1.61A.752.752,0,0,0,3.5,3.86V21.75a.738.738,0,0,0,.255.563.746.746,0,0,0,.59.181l12.5-1.61a.753.753,0,0,0,.655-.744V2.263H19V20.14a2.257,2.257,0,0,1-1.963,2.232l-12.5,1.609A2.139,2.139,0,0,1,4.25,24Z" fill="#fff"/>
<path d="M19.75,24H4.5a.75.75,0,0,1,0-1.5H19.75a.75.75,0,0,0,.75-.75V3.763a.75.75,0,0,0-.75-.75h-1.5a.75.75,0,0,1,0-1.5h1.5A2.252,2.252,0,0,1,22,3.763V21.75A2.252,2.252,0,0,1,19.75,24Z" fill="#fff"/>
<rect width="24" height="24" fill="none"/>
<path d="M7.645,10.966A1.615,1.615,0,0,1,6.022,9.351v-1.8a1.619,1.619,0,0,1,1.411-1.6l5.809-.927a1.615,1.615,0,0,1,1.845,1.6v1.8a1.62,1.62,0,0,1-1.41,1.6l-5.809.927A1.693,1.693,0,0,1,7.645,10.966ZM13.36,5.757l.119.741-5.833.93c-.08.011-.124.06-.124.119v1.8l.228.859-.118-.74,5.831-.93a.126.126,0,0,0,.124-.119v-1.8Z" fill="#fff"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -41,7 +41,7 @@ export class BookTreeItem extends vscode.TreeItem {
this.collapsibleState = book.treeItemCollapsibleState;
this._sections = book.page;
if (book.isUntitled) {
this.contextValue = 'unsavedBook';
this.contextValue = 'providedBook';
} else {
this.contextValue = 'savedBook';
}

View File

@@ -54,7 +54,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
}
private async initialize(workspaceFolders: vscode.WorkspaceFolder[]): Promise<void> {
await vscode.commands.executeCommand('setContext', 'unsavedBooks', this._openAsUntitled);
await vscode.commands.executeCommand('setContext', 'providedBooks', this._openAsUntitled);
await Promise.all(workspaceFolders.map(async (workspaceFolder) => {
try {
await this.loadNotebooksInFolder(workspaceFolder.uri.fsPath);

View File

@@ -24,21 +24,21 @@ const JUPYTER_NOTEBOOK_PROVIDER = 'jupyter';
const msgSampleCodeDataFrame = localize('msgSampleCodeDataFrame', "This sample code loads the file into a data frame and shows the first 10 results.");
const noNotebookVisible = localize('noNotebookVisible', "No notebook editor is active");
const BOOKS_VIEWID = 'bookTreeView';
const READONLY_BOOKS_VIEWID = 'unsavedBookTreeView';
const PROVIDED_BOOKS_VIEWID = 'providedBooksView';
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, true) : bookTreeViewProvider.openBook(bookPath, urlToOpen, true)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openBook', (bookPath: string, openAsUntitled: boolean, urlToOpen?: string) => openAsUntitled ? providedBookTreeViewProvider.openBook(bookPath, urlToOpen, true) : bookTreeViewProvider.openBook(bookPath, urlToOpen, true)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openNotebook', (resource) => bookTreeViewProvider.openNotebook(resource)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openUntitledNotebook', (resource) => untitledBookTreeViewProvider.openNotebookAsUntitled(resource)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openUntitledNotebook', (resource) => providedBookTreeViewProvider.openNotebookAsUntitled(resource)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openMarkdown', (resource) => bookTreeViewProvider.openMarkdown(resource)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openExternalLink', (resource) => bookTreeViewProvider.openExternalLink(resource)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.saveBook', () => untitledBookTreeViewProvider.saveJupyterBooks()));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.saveBook', () => providedBookTreeViewProvider.saveJupyterBooks()));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.trustBook', (resource) => bookTreeViewProvider.trustBook(resource)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchBook', (item) => bookTreeViewProvider.searchJupyterBooks(item)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchUntitledBook', () => untitledBookTreeViewProvider.searchJupyterBooks()));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchUntitledBook', () => providedBookTreeViewProvider.searchJupyterBooks()));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.openBook', () => bookTreeViewProvider.openNewBook()));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.closeBook', (book: any) => bookTreeViewProvider.closeBook(book)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.closeNotebook', (book: any) => bookTreeViewProvider.closeBook(book)));
@@ -114,7 +114,7 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
}));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.revealInBooksViewlet', (uri: vscode.Uri, shouldReveal: boolean) => bookTreeViewProvider.revealActiveDocumentInViewlet(uri, shouldReveal)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.revealInUntitledBooksViewlet', (uri: vscode.Uri, shouldReveal: boolean) => untitledBookTreeViewProvider.revealActiveDocumentInViewlet(uri, shouldReveal)));
extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.revealInUntitledBooksViewlet', (uri: vscode.Uri, shouldReveal: boolean) => providedBookTreeViewProvider.revealActiveDocumentInViewlet(uri, shouldReveal)));
let appContext = new AppContext(extensionContext, new ApiWrapper());
controller = new JupyterController(appContext);
@@ -126,9 +126,12 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
let workspaceFolders = vscode.workspace.workspaceFolders?.slice() ?? [];
const bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, workspaceFolders, extensionContext, false, BOOKS_VIEWID);
await bookTreeViewProvider.initialized;
const untitledBookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], extensionContext, true, READONLY_BOOKS_VIEWID);
await untitledBookTreeViewProvider.initialized;
const providedBookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], extensionContext, true, PROVIDED_BOOKS_VIEWID);
await providedBookTreeViewProvider.initialized;
extensionContext.subscriptions.push(vscode.window.registerTreeDataProvider(BOOKS_VIEWID, bookTreeViewProvider));
extensionContext.subscriptions.push(vscode.window.registerTreeDataProvider(PROVIDED_BOOKS_VIEWID, providedBookTreeViewProvider));
return {
getJupyterController() {
return controller;