From a3c3dc05dc7572f209002f540a1982a4cb6139d5 Mon Sep 17 00:00:00 2001 From: Taras Novak Date: Wed, 12 Aug 2020 23:49:24 -0500 Subject: [PATCH] #37 wired favorite notebook add and display in tree view --- src/notebook.manager.ts | 3 +++ src/views/notebook.view.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/notebook.manager.ts b/src/notebook.manager.ts index 24cf1ec..e2165f9 100644 --- a/src/notebook.manager.ts +++ b/src/notebook.manager.ts @@ -203,6 +203,9 @@ export class NotebookManager implements INotebookManager { // add a notebook to the favorites stored in global state let collectionNotebooks: Notebook[] = notebookTreeDataProvider.context.globalState.get(notebookCollectionKey); + if (collectionNotebooks === undefined) { + collectionNotebooks = []; + } collectionNotebooks.push(notebook); notebookTreeDataProvider.context.globalState.update(notebookCollectionKey, collectionNotebooks); break; diff --git a/src/views/notebook.view.ts b/src/views/notebook.view.ts index d997962..6fc19ee 100644 --- a/src/views/notebook.view.ts +++ b/src/views/notebook.view.ts @@ -232,6 +232,10 @@ export class NotebookView { // loads notebook view this.refresh(); break; + case 'toggleFavorite': + // update favorite collection + this.toggleFavorite(message.uri); + break; case 'loadView': // launch new view this.loadView(message.viewName, message.uri); @@ -384,6 +388,14 @@ export class NotebookView { } } // end of refreshView() + /** + * Updates favorite collection. + * @param notebookUrl Notebook url to add/remove from favorite notebooks collection. + */ + public async toggleFavorite(notebookUrl: string) { + notebookManager.addNotebook('favorite', this._notebook); + } + /** * Saves notebook in requested file formats. * @param fileType Notebook file type to save.