diff --git a/comment-sample/package.json b/comment-sample/package.json index 4bda1b02..8222811e 100644 --- a/comment-sample/package.json +++ b/comment-sample/package.json @@ -60,6 +60,10 @@ { "command": "mywiki.startDraft", "title": "Start draft" + }, + { + "command": "mywiki.finishDraft", + "title": "Finish draft" } ], "menus": { @@ -104,7 +108,14 @@ { "command": "mywiki.startDraft", "precondition": "commentIsEmpty", - "group": "navigation" + "group": "navigation", + "when": "!inDraft" + }, + { + "command": "mywiki.finishDraft", + "precondition": "commentIsEmpty", + "group": "navigation", + "when": "inDraft" } ], "comment/title": [ diff --git a/comment-sample/src/extension.ts b/comment-sample/src/extension.ts index 604cfd0f..0c6c0247 100644 --- a/comment-sample/src/extension.ts +++ b/comment-sample/src/extension.ts @@ -21,6 +21,7 @@ export function activate(context: vscode.ExtensionContext) { // A `CommentController` is able to provide comments for documents. const commentController = vscode.comment.createCommentController('comment-sample', 'Comment API Sample'); context.subscriptions.push(commentController); + vscode.commands.executeCommand('setContext', 'inDraft', false); // commenting range provider commentController.commentingRangeProvider = { @@ -43,12 +44,24 @@ export function activate(context: vscode.ExtensionContext) { })); context.subscriptions.push(vscode.commands.registerCommand('mywiki.startDraft', (reply: vscode.CommentReply) => { + vscode.commands.executeCommand('setContext', 'inDraft', true); let thread = reply.thread; let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread); newComment.label = 'pending'; thread.comments = [...thread.comments, newComment]; })); + context.subscriptions.push(vscode.commands.registerCommand('mywiki.finishDraft', (reply: vscode.CommentReply) => { + vscode.commands.executeCommand('setContext', 'inDraft', false); + + let thread = reply.thread; + let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread); + thread.comments = [...thread.comments, newComment].map(comment => { + comment.label = undefined; + return comment; + }); + })); + context.subscriptions.push(vscode.commands.registerCommand('mywiki.deleteNoteComment', (comment: NoteComment) => { let thread = comment.parent; thread.comments = thread.comments.filter((cmt: NoteComment) => cmt.id !== comment.id);