Create book UI (#14210)

* Add dialog for creating books

* create empty book

* add localized constants

* add validation to dialog

* reset the create book command to original

* address pr comments

* change error message

* Init book toc manager in bookTreeView
This commit is contained in:
Barbara Valdez
2021-02-22 13:29:09 -08:00
committed by GitHub
parent 551eb76a42
commit 5ece9b968a
8 changed files with 227 additions and 23 deletions

View File

@@ -8,7 +8,7 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs-extra';
import * as constants from '../common/constants';
import { IPrompter, IQuestion, QuestionTypes } from '../prompts/question';
import { IPrompter } from '../prompts/question';
import CodeAdapter from '../prompts/adapter';
import { BookTreeItem, BookTreeItemType } from './bookTreeItem';
import { BookModel } from './bookModel';
@@ -16,9 +16,10 @@ import { Deferred } from '../common/promise';
import { IBookTrustManager, BookTrustManager } from './bookTrustManager';
import * as loc from '../common/localizedConstants';
import * as glob from 'fast-glob';
import { debounce, getPinnedNotebooks } from '../common/utils';
import { debounce, getPinnedNotebooks, confirmReplace } from '../common/utils';
import { IBookPinManager, BookPinManager } from './bookPinManager';
import { BookTocManager, IBookTocManager, quickPickResults } from './bookTocManager';
import { CreateBookDialog } from '../dialog/createBookDialog';
import { getContentPath } from './bookVersionHandler';
import { TelemetryReporter, BookTelemetryView, NbTelemetryActions } from '../telemetry';
@@ -52,6 +53,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
this.initialize(workspaceFolders).catch(e => console.error(e));
this.prompter = new CodeAdapter();
this._bookTrustManager = new BookTrustManager(this.books);
this.bookTocManager = new BookTocManager();
this._extensionContext.subscriptions.push(azdata.nb.registerNavigationProvider(this));
}
@@ -142,10 +144,9 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
}
}
async createBook(bookPath: string, contentPath: string): Promise<void> {
bookPath = path.normalize(bookPath);
contentPath = path.normalize(contentPath);
await this.bookTocManager.createBook(bookPath, contentPath);
async createBook(): Promise<void> {
const dialog = new CreateBookDialog(this.bookTocManager);
dialog.createDialog();
TelemetryReporter.createActionEvent(BookTelemetryView, NbTelemetryActions.CreateBook).send();
}
@@ -502,7 +503,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
let destinationUri: vscode.Uri = vscode.Uri.file(path.join(pickedFolder.fsPath, path.basename(this.currentBook.bookPath)));
if (destinationUri) {
if (await fs.pathExists(destinationUri.fsPath)) {
let doReplace = await this.confirmReplace();
let doReplace = await confirmReplace(this.prompter);
if (!doReplace) {
return undefined;
}
@@ -676,15 +677,6 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
return untitledFileName;
}
//Confirmation message dialog
private async confirmReplace(): Promise<boolean> {
return await this.prompter.promptSingle<boolean>(<IQuestion>{
type: QuestionTypes.confirm,
message: loc.confirmReplace,
default: false
});
}
getNavigation(uri: vscode.Uri): Thenable<azdata.nb.NavigationResult> {
let result: azdata.nb.NavigationResult;
let notebook = this.currentBook?.getNotebook(uri.fsPath);