mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add Open Notebook Folder functionality to Books viewlet. (#9939)
This commit is contained in:
@@ -18,6 +18,7 @@ export enum BookTreeItemType {
|
||||
|
||||
export interface BookTreeItemFormat {
|
||||
title: string;
|
||||
contentPath: string;
|
||||
root: string;
|
||||
tableOfContents: IJupyterBookToc;
|
||||
page: any;
|
||||
@@ -47,6 +48,12 @@ export class BookTreeItem extends vscode.TreeItem {
|
||||
} else {
|
||||
if (book.page && book.page.sections && book.page.sections.length > 0) {
|
||||
this.contextValue = 'section';
|
||||
} else if (book.type === BookTreeItemType.Notebook && !book.tableOfContents.sections) {
|
||||
if (book.isUntitled) {
|
||||
this.contextValue = 'unsavedNotebook';
|
||||
} else {
|
||||
this.contextValue = 'savedNotebook';
|
||||
}
|
||||
}
|
||||
this.setPageVariables();
|
||||
this.setCommand();
|
||||
@@ -63,19 +70,19 @@ export class BookTreeItem extends vscode.TreeItem {
|
||||
this._sections = this.book.page.sections || this.book.page.subsections;
|
||||
this._uri = this.book.page.url;
|
||||
|
||||
let index = (this.book.tableOfContents.sections.indexOf(this.book.page));
|
||||
this.setPreviousUri(index);
|
||||
this.setNextUri(index);
|
||||
if (this.book.tableOfContents.sections) {
|
||||
let index = (this.book.tableOfContents.sections.indexOf(this.book.page));
|
||||
this.setPreviousUri(index);
|
||||
this.setNextUri(index);
|
||||
}
|
||||
}
|
||||
|
||||
private setCommand() {
|
||||
if (this.book.type === BookTreeItemType.Notebook) {
|
||||
// The Notebook editor expects a posix path for the resource (it will still resolve to the correct fsPath based on OS)
|
||||
const pathToNotebook = path.posix.join(this.book.root, 'content', this._uri.concat('.ipynb'));
|
||||
this.command = { command: this.book.isUntitled ? 'bookTreeView.openUntitledNotebook' : 'bookTreeView.openNotebook', title: loc.openNotebookCommand, arguments: [pathToNotebook], };
|
||||
this.command = { command: this.book.isUntitled ? 'bookTreeView.openUntitledNotebook' : 'bookTreeView.openNotebook', title: loc.openNotebookCommand, arguments: [this.book.contentPath], };
|
||||
} else if (this.book.type === BookTreeItemType.Markdown) {
|
||||
let pathToMarkdown = path.join(this.book.root, 'content', this._uri.concat('.md'));
|
||||
this.command = { command: 'bookTreeView.openMarkdown', title: loc.openMarkdownCommand, arguments: [pathToMarkdown], };
|
||||
this.command = { command: 'bookTreeView.openMarkdown', title: loc.openMarkdownCommand, arguments: [this.book.contentPath], };
|
||||
} else if (this.book.type === BookTreeItemType.ExternalLink) {
|
||||
this.command = { command: 'bookTreeView.openExternalLink', title: loc.openExternalLinkCommand, arguments: [this._uri], };
|
||||
}
|
||||
@@ -146,7 +153,7 @@ export class BookTreeItem extends vscode.TreeItem {
|
||||
return `${this._uri}`;
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
return this.book.type === BookTreeItemType.Book ? this.book.root : this.book.contentPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user