From 8d6054d93232f6d3dbf266afa84a15b94ebf0833 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Thu, 23 May 2019 09:21:34 -0700 Subject: [PATCH] update context key --- comment-sample/package.json | 20 +++++----- comment-sample/src/extension.ts | 3 +- .../src/typings/vscode.proposed.d.ts | 40 +++++++++++++++++++ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/comment-sample/package.json b/comment-sample/package.json index 68f699f1..bae17803 100644 --- a/comment-sample/package.json +++ b/comment-sample/package.json @@ -92,29 +92,29 @@ "when": "!commentThreadIsEmpty" } ], - "comments/commentThread/actions": [ + "comments/commentThread/context": [ { "command": "mywiki.createNote", - "group": "navigation", + "group": "inline", "precondition": "!commentIsEmpty", "when": "commentThreadIsEmpty" }, { "command": "mywiki.replyNote", - "group": "navigation", + "group": "inline", "precondition": "!commentIsEmpty", "when": "!commentThreadIsEmpty" }, { "command": "mywiki.startDraft", - "group": "navigation", + "group": "inline", "precondition": "!commentIsEmpty", - "when": "!inDraft" + "when": "commentThread != draft" }, { "command": "mywiki.finishDraft", - "group": "navigation", - "when": "inDraft" + "group": "inline", + "when": "commentThread == draft" } ], "comments/comment/title": [ @@ -127,14 +127,14 @@ "group": "group@2" } ], - "comments/comment/actions": [ + "comments/comment/context": [ { "command": "mywiki.cancelsaveNote", - "group": "group@1" + "group": "inline@1" }, { "command": "mywiki.saveNote", - "group": "group@2" + "group": "inline@2" } ] } diff --git a/comment-sample/src/extension.ts b/comment-sample/src/extension.ts index 9beb9f47..e946c2d3 100644 --- a/comment-sample/src/extension.ts +++ b/comment-sample/src/extension.ts @@ -40,8 +40,8 @@ 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; + thread.contextValue = 'draft'; let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread); newComment.label = 'pending'; thread.comments = [...thread.comments, newComment]; @@ -51,6 +51,7 @@ export function activate(context: vscode.ExtensionContext) { vscode.commands.executeCommand('setContext', 'inDraft', false); let thread = reply.thread; + thread.collapsibleState = undefined; let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread); thread.comments = [...thread.comments, newComment].map(comment => { comment.label = undefined; diff --git a/comment-sample/src/typings/vscode.proposed.d.ts b/comment-sample/src/typings/vscode.proposed.d.ts index 308d5479..39b19ece 100644 --- a/comment-sample/src/typings/vscode.proposed.d.ts +++ b/comment-sample/src/typings/vscode.proposed.d.ts @@ -70,6 +70,26 @@ declare module 'vscode' { * The optional human-readable label describing the [Comment Thread](#CommentThread) */ label?: string; + + /** + * Context value of the comment thread. This can be used to contribute thread specific actions. + * For example, a comment thread is given a context value as `editable`. When contributing actions to `comments/commentThread/title` + * using `menus` extension point, you can specify context value for key `commentThread` in `when` expression like `commentThread == editable`. + * ``` + * "contributes": { + * "menus": { + * "comments/commentThread/title": [ + * { + * "command": "extension.deleteCommentThread", + * "when": "commentThread == editable" + * } + * ] + * } + * } + * ``` + * This will show action `extension.deleteCommentThread` only for comment threads with `contextValue` is `editable`. + */ + contextValue?: string; /** * Dispose this comment thread. @@ -115,6 +135,26 @@ declare module 'vscode' { * Label will be rendered next to authorName if exists. */ label?: string; + + /** + * Context value of the comment. This can be used to contribute comment specific actions. + * For example, a comment is given a context value as `editable`. When contributing actions to `comments/comment/title` + * using `menus` extension point, you can specify context value for key `comment` in `when` expression like `comment == editable`. + * ``` + * "contributes": { + * "menus": { + * "comments/comment/title": [ + * { + * "command": "extension.deleteComment", + * "when": "comment == editable" + * } + * ] + * } + * } + * ``` + * This will show action `extension.deleteComment` only for comments with `contextValue` is `editable`. + */ + contextValue?: string; } export interface CommentReply {