Skip to content

Commit

Permalink
#37 wired favorite notebook add and display in tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomFractals committed Aug 13, 2020
1 parent 71be803 commit a3c3dc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/notebook.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/views/notebook.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a3c3dc0

Please sign in to comment.