diff --git a/package.json b/package.json index 4ad848f..6c8a8e7 100644 --- a/package.json +++ b/package.json @@ -166,6 +166,14 @@ "command": "weAudit.toggleAudited", "title": "weAudit: Mark File as Reviewed" }, + { + "command": "weAudit.toggleFileAudited", + "title": "weAudit: Mark File as Reviewed" + }, + { + "command": "weAudit.toggleFolderAudited", + "title": "weAudit: Mark entire Folder as Reviewed" + }, { "command": "weAudit.addPartiallyAudited", "title": "weAudit: Mark Region as Reviewed" @@ -381,7 +389,7 @@ "editor/context": [ { "command": "weAudit.toggleAudited", - "group": "1_modification@0" + "group": "1_modification" }, { "command": "weAudit.copySelectedCodePermalink", @@ -391,6 +399,18 @@ "command": "weAudit.copySelectedCodeClientPermalink", "group": "9_cutcopypaste@0" } + ], + "explorer/context": [ + { + "command": "weAudit.toggleFileAudited", + "group": "2_workspace", + "when": "!explorerResourceIsFolder && resourceScheme == file" + }, + { + "command": "weAudit.toggleFolderAudited", + "group": "2_workspace", + "when": "explorerResourceIsFolder && resourceScheme == file" + } ] }, "configuration": [ diff --git a/src/codeMarker.ts b/src/codeMarker.ts index 3aedafa..a682484 100644 --- a/src/codeMarker.ts +++ b/src/codeMarker.ts @@ -122,6 +122,14 @@ export class CodeMarker implements vscode.TreeDataProvider { this.toggleAudited(); }); + vscode.commands.registerCommand("weAudit.toggleFileAudited", (uri: vscode.Uri) => { + this.toggleFileAudited(uri); + }); + + vscode.commands.registerCommand("weAudit.toggleFolderAudited", (uri: vscode.Uri) => { + this.toggleFolderAudited(uri); + }); + vscode.commands.registerCommand("weAudit.addPartiallyAudited", () => { this.addPartiallyAudited(); }); @@ -596,6 +604,15 @@ export class CodeMarker implements vscode.TreeDataProvider { return; } const uri = editor.document.uri; + this.toggleFileAudited(uri); + } + + /** + * Toggles a File as audited or not audited. + * @param uri The URI of the file that need to be toggled + */ + toggleFileAudited(uri: vscode.Uri): void { + // get path relative to workspace const relativePath = path.relative(this.workspacePath, uri.fsPath); @@ -627,6 +644,57 @@ export class CodeMarker implements vscode.TreeDataProvider { this.refresh(uri); } + /** + * Toggles a Folder as audited or not audited. + * @param uri The URI of the folder that need to be toggled + */ + toggleFolderAudited(uri: vscode.Uri): void { + // get path relative to workspace + const relativeFolderPath = path.relative(this.workspacePath, uri.fsPath); + // iterate over all the files in the folder + const files = fs.readdirSync(uri.fsPath); + + let relevantUsername; + // check if folder is already in list + const index = this.auditedFiles.findIndex((file) => file.path === relativeFolderPath); + if (index > -1) { + // if it exists, remove it + const auditedEntry = this.auditedFiles.splice(index, 1); + relevantUsername = auditedEntry[0].author; + // remove every contained file + for (const file of files) { + const relativePath = path.relative(this.workspacePath, path.join(uri.fsPath, file)); + const index = this.auditedFiles.findIndex((file) => file.path === relativePath) + this.auditedFiles.splice(index, 1); + } + } else { + // if it doesn't exist, add it + this.auditedFiles.push({ path: relativeFolderPath, author: this.username }); + relevantUsername = this.username; + // add every contained file + for (const file of files) { + const relativePath = path.relative(this.workspacePath, path.join(uri.fsPath, file)); + this.auditedFiles.push({ path: relativePath, author: this.username }); + } + } + + // clean out any partially audited file entries + this.cleanPartialAudits(uri); + + // update day log structure + const isAdd = index === -1; + this.updateDayLog(relativeFolderPath, isAdd); + this.updateSavedData(relevantUsername); + this.refreshAndDecorateFromPath(relativeFolderPath); + + // update decorations for every single file that was affected + for (const file of files) { + const relativePath = path.relative(this.workspacePath, path.join(uri.fsPath, file)); + this.updateDayLog(relativePath, isAdd); + this.refreshAndDecorateFromPath(relativePath) + } + } + addPartiallyAudited(): void { const editor = vscode.window.activeTextEditor; if (editor === undefined) {