mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 02:32:35 -05:00
Book/externallink (#6215)
* show markdown preview * open external link * addressed Charles' comments
This commit is contained in:
@@ -51,7 +51,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
}
|
||||
}
|
||||
|
||||
async openMarkdown(resource: string): Promise<void> {
|
||||
openMarkdown(resource: string): void {
|
||||
try {
|
||||
vscode.commands.executeCommand('markdown.showPreview', vscode.Uri.file(resource));
|
||||
} catch (e) {
|
||||
@@ -61,6 +61,17 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
}
|
||||
}
|
||||
|
||||
openExternalLink(resource: string): void {
|
||||
try {
|
||||
vscode.env.openExternal(vscode.Uri.parse(resource));
|
||||
} catch (e) {
|
||||
vscode.window.showErrorMessage(localize('openExternalLinkError', 'Open link {0} failed: {1}',
|
||||
resource,
|
||||
e instanceof Error ? e.message : e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getTreeItem(element: BookTreeItem): vscode.TreeItem {
|
||||
return element;
|
||||
}
|
||||
@@ -99,18 +110,27 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
let notebooks: BookTreeItem[] = [];
|
||||
for (let i = 0; i < sec.length; i++) {
|
||||
if (sec[i].url) {
|
||||
let pathToNotebook = path.join(root, 'content', sec[i].url.concat('.ipynb'));
|
||||
let pathToMarkdown = path.join(root, 'content', sec[i].url.concat('.md'));
|
||||
// Note: Currently, if there is an ipynb and a md file with the same name, Jupyter Books only shows the notebook.
|
||||
// Following Jupyter Books behavior for now
|
||||
if (fs.existsSync(pathToNotebook)) {
|
||||
let notebook = new BookTreeItem(sec[i].title, root, sec[i].sections, sec[i].sections ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None, sec[i].url, { command: 'bookTreeView.openNotebook', title: 'Open Notebook', arguments: [pathToNotebook], });
|
||||
notebooks.push(notebook);
|
||||
} else if (fs.existsSync(pathToMarkdown)) {
|
||||
let markdown = new BookTreeItem(sec[i].title, root, sec[i].sections, sec[i].sections ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None, sec[i].url, { command: 'bookTreeView.openMarkdown', title: 'Open Markdown', arguments: [pathToMarkdown], });
|
||||
notebooks.push(markdown);
|
||||
if (sec[i].external) {
|
||||
let externalLink = new BookTreeItem(sec[i].title, root, sec[i].sections, sec[i].sections ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None, sec[i].url, { command: 'bookTreeView.openExternalLink', title: localize('openExternalLinkCommand', 'Open External Link'), arguments: [sec[i].url], });
|
||||
notebooks.push(externalLink);
|
||||
} else {
|
||||
vscode.window.showErrorMessage(localize('missingFileError', 'Missing file : {0}', sec[i].title));
|
||||
let pathToNotebook = path.join(root, 'content', sec[i].url.concat('.ipynb'));
|
||||
let pathToMarkdown = path.join(root, 'content', sec[i].url.concat('.md'));
|
||||
// Note: Currently, if there is an ipynb and a md file with the same name, Jupyter Books only shows the notebook.
|
||||
// Following Jupyter Books behavior for now
|
||||
if (fs.existsSync(pathToNotebook)) {
|
||||
let notebook = new BookTreeItem(sec[i].title, root, sec[i].sections || sec[i].subsections,
|
||||
(sec[i].sections || sec[i].subsections) && sec[i].expand_sections ? vscode.TreeItemCollapsibleState.Expanded : sec[i].sections || sec[i].subsections ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None,
|
||||
sec[i].url, { command: 'bookTreeView.openNotebook', title: localize('openNotebookCommand', 'Open Notebook'), arguments: [pathToNotebook], });
|
||||
notebooks.push(notebook);
|
||||
} else if (fs.existsSync(pathToMarkdown)) {
|
||||
let markdown = new BookTreeItem(sec[i].title, root, sec[i].sections || sec[i].subsections,
|
||||
(sec[i].sections || sec[i].subsections) && sec[i].expand_sections ? vscode.TreeItemCollapsibleState.Expanded : sec[i].sections || sec[i].subsections ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None,
|
||||
sec[i].url, { command: 'bookTreeView.openMarkdown', title: localize('openMarkdownCommand', 'Open Markdown'), arguments: [pathToMarkdown], });
|
||||
notebooks.push(markdown);
|
||||
} else {
|
||||
vscode.window.showErrorMessage(localize('missingFileError', 'Missing file : {0}', sec[i].title));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO: search functionality (#6160)
|
||||
@@ -118,4 +138,4 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
}
|
||||
return notebooks;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
|
||||
vscode.window.registerTreeDataProvider('bookTreeView', bookTreeViewProvider);
|
||||
vscode.commands.registerCommand('bookTreeView.openNotebook', (resource) => bookTreeViewProvider.openNotebook(resource));
|
||||
vscode.commands.registerCommand('bookTreeView.openMarkdown', (resource) => bookTreeViewProvider.openMarkdown(resource));
|
||||
vscode.commands.registerCommand('bookTreeView.openExternalLink', (resource) => bookTreeViewProvider.openExternalLink(resource));
|
||||
|
||||
extensionContext.subscriptions.push(vscode.commands.registerCommand('_notebook.command.new', (context?: azdata.ConnectedContext) => {
|
||||
let connectionProfile: azdata.IConnectionProfile = undefined;
|
||||
|
||||
Reference in New Issue
Block a user