mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Books: Ensure associatedResource is Present for Untitled Notebooks that have a File Associated with them (#9037)
* Conditionally add associatedResource t untitled nb * Fix Jupyter Book notebook titles (#9039) * Fix notebook titles * Fix navigation links for books * Added comments Co-authored-by: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> * PR comment nit Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -67,7 +67,8 @@ export class BookTreeItem extends vscode.TreeItem {
|
||||
|
||||
private setCommand() {
|
||||
if (this.book.type === BookTreeItemType.Notebook) {
|
||||
let pathToNotebook = path.join(this.book.root, 'content', this._uri.concat('.ipynb'));
|
||||
// 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], };
|
||||
} else if (this.book.type === BookTreeItemType.Markdown) {
|
||||
let pathToMarkdown = path.join(this.book.root, 'content', this._uri.concat('.md'));
|
||||
@@ -81,8 +82,8 @@ export class BookTreeItem extends vscode.TreeItem {
|
||||
let i = --index;
|
||||
while (i > -1) {
|
||||
if (this.book.tableOfContents.sections[i].url) {
|
||||
// TODO: Currently only navigating to notebooks. Need to add logic for markdown.
|
||||
let pathToNotebook = path.join(this.book.root, 'content', this.book.tableOfContents.sections[i].url.concat('.ipynb'));
|
||||
// The Notebook editor expects a posix path for the resource (it will still resolve to the correct fsPath based on OS)
|
||||
let pathToNotebook = path.posix.join(this.book.root, 'content', this.book.tableOfContents.sections[i].url.concat('.ipynb'));
|
||||
// eslint-disable-next-line no-sync
|
||||
if (fs.existsSync(pathToNotebook)) {
|
||||
this._previousUri = pathToNotebook;
|
||||
@@ -97,8 +98,8 @@ export class BookTreeItem extends vscode.TreeItem {
|
||||
let i = ++index;
|
||||
while (i < this.book.tableOfContents.sections.length) {
|
||||
if (this.book.tableOfContents.sections[i].url) {
|
||||
// TODO: Currently only navigating to notebooks. Need to add logic for markdown.
|
||||
let pathToNotebook = path.join(this.book.root, 'content', this.book.tableOfContents.sections[i].url.concat('.ipynb'));
|
||||
// The Notebook editor expects a posix path for the resource (it will still resolve to the correct fsPath based on OS)
|
||||
let pathToNotebook = path.posix.join(this.book.root, 'content', this.book.tableOfContents.sections[i].url.concat('.ipynb'));
|
||||
// eslint-disable-next-line no-sync
|
||||
if (fs.existsSync(pathToNotebook)) {
|
||||
this._nextUri = pathToNotebook;
|
||||
|
||||
@@ -10,7 +10,6 @@ import * as fs from 'fs-extra';
|
||||
import { IPrompter, QuestionTypes, IQuestion } from '../prompts/question';
|
||||
import CodeAdapter from '../prompts/adapter';
|
||||
import { BookTreeItem } from './bookTreeItem';
|
||||
import { isEditorTitleFree } from '../common/utils';
|
||||
import { BookModel } from './bookModel';
|
||||
import { Deferred } from '../common/promise';
|
||||
import * as loc from '../common/localizedConstants';
|
||||
@@ -98,7 +97,8 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
const sectionToOpen = bookRoot.findChildSection(urlToOpen);
|
||||
const urlPath = sectionToOpen ? sectionToOpen.url : bookRoot.tableOfContents.sections[0].url;
|
||||
const sectionToOpenMarkdown: string = path.join(this.currentBook.bookPath, 'content', urlPath.concat('.md'));
|
||||
const sectionToOpenNotebook: string = path.join(this.currentBook.bookPath, 'content', urlPath.concat('.ipynb'));
|
||||
// The Notebook editor expects a posix path for the resource (it will still resolve to the correct fsPath based on OS)
|
||||
const sectionToOpenNotebook: string = path.posix.join(this.currentBook.bookPath, 'content', urlPath.concat('.ipynb'));
|
||||
if (await fs.pathExists(sectionToOpenMarkdown)) {
|
||||
this.openMarkdown(sectionToOpenMarkdown);
|
||||
}
|
||||
@@ -297,9 +297,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
}
|
||||
|
||||
getUntitledNotebookUri(resource: string): vscode.Uri {
|
||||
let untitledFileName: vscode.Uri;
|
||||
let nextTitle: string = this.findNextUntitledFileName(resource);
|
||||
untitledFileName = vscode.Uri.parse(`untitled:${nextTitle}`);
|
||||
let untitledFileName = vscode.Uri.parse(`untitled:${resource}`);
|
||||
if (!this.currentBook.getAllBooks().get(untitledFileName.fsPath) && !this.currentBook.getAllBooks().get(path.basename(untitledFileName.fsPath))) {
|
||||
let notebook = this.currentBook.getAllBooks().get(resource);
|
||||
this.currentBook.getAllBooks().set(path.basename(untitledFileName.fsPath), notebook);
|
||||
@@ -307,18 +305,6 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
return untitledFileName;
|
||||
}
|
||||
|
||||
findNextUntitledFileName(filePath: string): string {
|
||||
const baseName = path.basename(filePath);
|
||||
let idx = 0;
|
||||
let title;
|
||||
do {
|
||||
const suffix = idx === 0 ? '' : `-${idx}`;
|
||||
title = `${baseName}${suffix}`;
|
||||
idx++;
|
||||
} while (!isEditorTitleFree(title));
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
//Confirmation message dialog
|
||||
private async confirmReplace(): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user