mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Find all books in workspace with multiple folders (#6613)
* find all books in workspace with multiple flolders * fixed optional parameter
This commit is contained in:
@@ -24,27 +24,29 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
private _throttleTimer: any;
|
||||
private _resource: string;
|
||||
|
||||
constructor(private workspaceRoot: string, extensionContext: vscode.ExtensionContext) {
|
||||
if (workspaceRoot !== '') {
|
||||
this._tableOfContentsPath = this.getTocFiles(this.workspaceRoot);
|
||||
let bookOpened: boolean = this._tableOfContentsPath && this._tableOfContentsPath.length > 0;
|
||||
vscode.commands.executeCommand('setContext', 'bookOpened', bookOpened);
|
||||
}
|
||||
constructor(workspaceFolders: vscode.WorkspaceFolder[], extensionContext: vscode.ExtensionContext) {
|
||||
let workspacePaths: string[] = workspaceFolders.map(a => a.uri.fsPath);
|
||||
this._tableOfContentsPath = this.getTableOfContentFiles(workspacePaths);
|
||||
let bookOpened: boolean = this._tableOfContentsPath && this._tableOfContentsPath.length > 0;
|
||||
vscode.commands.executeCommand('setContext', 'bookOpened', bookOpened);
|
||||
this._extensionContext = extensionContext;
|
||||
}
|
||||
|
||||
private getTocFiles(dir: string): string[] {
|
||||
let allFiles: string[] = [];
|
||||
let files = fs.readdirSync(dir);
|
||||
for (let i in files) {
|
||||
let name = path.join(dir, files[i]);
|
||||
if (fs.statSync(name).isDirectory()) {
|
||||
allFiles = allFiles.concat(this.getTocFiles(name));
|
||||
} else if (files[i] === 'toc.yml') {
|
||||
allFiles.push(name);
|
||||
}
|
||||
}
|
||||
return allFiles;
|
||||
private getTableOfContentFiles(directories: string[]): string[] {
|
||||
let tableOfContentPaths: string[] = [];
|
||||
let paths: string[];
|
||||
directories.forEach(dir => {
|
||||
paths = fs.readdirSync(dir);
|
||||
paths.forEach(filename => {
|
||||
let fullPath = path.join(dir, filename);
|
||||
if (fs.statSync(fullPath).isDirectory()) {
|
||||
tableOfContentPaths = tableOfContentPaths.concat(this.getTableOfContentFiles([fullPath]));
|
||||
} else if (filename === 'toc.yml') {
|
||||
tableOfContentPaths.push(fullPath);
|
||||
}
|
||||
});
|
||||
});
|
||||
return tableOfContentPaths;
|
||||
}
|
||||
|
||||
async openNotebook(resource: string): Promise<void> {
|
||||
@@ -231,4 +233,4 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user