提交 5a3c4d19 编写于 作者: P Peng Lyu

commentProvider can control collapse state of a thread

上级 e1c6d458
...@@ -214,6 +214,9 @@ export class ReviewMode implements vscode.DecorationProvider { ...@@ -214,6 +214,9 @@ export class ReviewMode implements vscode.DecorationProvider {
// No old threads match this thread, it is new // No old threads match this thread, it is new
if (matchingCommentThread.length === 0) { if (matchingCommentThread.length === 0) {
added.push(thread); added.push(thread);
if (thread.resource.scheme === 'file') {
thread.collapsibleState = vscode.CommentThreadCollapsibleState.Collapsed;
}
} }
// Check if comment has been updated // Check if comment has been updated
...@@ -267,7 +270,7 @@ export class ReviewMode implements vscode.DecorationProvider { ...@@ -267,7 +270,7 @@ export class ReviewMode implements vscode.DecorationProvider {
return Promise.resolve(null); return Promise.resolve(null);
} }
private commentsToCommentThreads(comments: Comment[]): vscode.CommentThread[] { private commentsToCommentThreads(comments: Comment[], collapsibleState: vscode.CommentThreadCollapsibleState = vscode.CommentThreadCollapsibleState.Expanded): vscode.CommentThread[] {
if (!comments || !comments.length) { if (!comments || !comments.length) {
return []; return [];
} }
...@@ -297,6 +300,7 @@ export class ReviewMode implements vscode.DecorationProvider { ...@@ -297,6 +300,7 @@ export class ReviewMode implements vscode.DecorationProvider {
gravatar: comment.user.avatar_url gravatar: comment.user.avatar_url
}; };
}), }),
collapsibleState: collapsibleState,
reply: this._reply reply: this._reply
}); });
} }
...@@ -361,7 +365,7 @@ export class ReviewMode implements vscode.DecorationProvider { ...@@ -361,7 +365,7 @@ export class ReviewMode implements vscode.DecorationProvider {
} }
return { return {
threads: this.commentsToCommentThreads(matchingComments), threads: this.commentsToCommentThreads(matchingComments, document.uri.scheme === 'file' ? vscode.CommentThreadCollapsibleState.Collapsed : vscode.CommentThreadCollapsibleState.Expanded),
commentingRanges: ranges, commentingRanges: ranges,
reply: this._reply reply: this._reply
}; };
......
...@@ -944,12 +944,24 @@ export interface CommentInfo { ...@@ -944,12 +944,24 @@ export interface CommentInfo {
reply?: Command; reply?: Command;
} }
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1
}
export interface CommentThread { export interface CommentThread {
readonly threadId: string; threadId: string;
readonly resource: string; resource: string;
readonly range: IRange; range: IRange;
readonly comments: Comment[]; comments: Comment[];
readonly reply: Command; collapsibleState?: CommentThreadCollapsibleState;
reply?: Command;
} }
export interface NewCommentAction { export interface NewCommentAction {
......
...@@ -793,6 +793,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages { ...@@ -793,6 +793,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
CompletionItemKind: CompletionItemKind, CompletionItemKind: CompletionItemKind,
SymbolKind: modes.SymbolKind, SymbolKind: modes.SymbolKind,
IndentAction: IndentAction, IndentAction: IndentAction,
SuggestTriggerKind: modes.SuggestTriggerKind SuggestTriggerKind: modes.SuggestTriggerKind,
CommentThreadCollapsibleState: modes.CommentThreadCollapsibleState
}; };
} }
...@@ -5035,12 +5035,24 @@ declare namespace monaco.languages { ...@@ -5035,12 +5035,24 @@ declare namespace monaco.languages {
reply?: Command; reply?: Command;
} }
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1,
}
export interface CommentThread { export interface CommentThread {
readonly threadId: string; threadId: string;
readonly resource: string; resource: string;
readonly range: IRange; range: IRange;
readonly comments: Comment[]; comments: Comment[];
readonly reply: Command; collapsibleState?: CommentThreadCollapsibleState;
reply?: Command;
} }
export interface NewCommentAction { export interface NewCommentAction {
......
...@@ -776,11 +776,23 @@ declare module 'vscode' { ...@@ -776,11 +776,23 @@ declare module 'vscode' {
reply?: Command; reply?: Command;
} }
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1
}
interface CommentThread { interface CommentThread {
threadId: string; threadId: string;
resource: Uri; resource: Uri;
range: Range; range: Range;
comments: Comment[]; comments: Comment[];
collapsibleState?: CommentThreadCollapsibleState;
reply?: Command; reply?: Command;
} }
......
...@@ -47,6 +47,10 @@ export class MainThreadComments extends Disposable implements MainThreadComments ...@@ -47,6 +47,10 @@ export class MainThreadComments extends Disposable implements MainThreadComments
return; return;
} }
if (!outerEditor.getModel()) {
return;
}
const outerEditorURI = outerEditor.getModel().uri; const outerEditorURI = outerEditor.getModel().uri;
this.provideComments(outerEditorURI).then(commentInfos => { this.provideComments(outerEditorURI).then(commentInfos => {
this._commentService.setComments(outerEditorURI, commentInfos); this._commentService.setComments(outerEditorURI, commentInfos);
......
...@@ -686,7 +686,9 @@ export function createApiFactory( ...@@ -686,7 +686,9 @@ export function createApiFactory(
FileType: extHostTypes.FileType, FileType: extHostTypes.FileType,
FoldingRangeList: extHostTypes.FoldingRangeList, FoldingRangeList: extHostTypes.FoldingRangeList,
FoldingRange: extHostTypes.FoldingRange, FoldingRange: extHostTypes.FoldingRange,
FoldingRangeType: extHostTypes.FoldingRangeType FoldingRangeType: extHostTypes.FoldingRangeType,
CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState
}; };
}; };
} }
......
...@@ -103,6 +103,7 @@ function convertCommentThread(vscodeCommentThread: vscode.CommentThread, command ...@@ -103,6 +103,7 @@ function convertCommentThread(vscodeCommentThread: vscode.CommentThread, command
resource: vscodeCommentThread.resource.toString(), resource: vscodeCommentThread.resource.toString(),
range: extHostTypeConverter.fromRange(vscodeCommentThread.range), range: extHostTypeConverter.fromRange(vscodeCommentThread.range),
comments: vscodeCommentThread.comments.map(convertComment), comments: vscodeCommentThread.comments.map(convertComment),
collapsibleState: vscodeCommentThread.collapsibleState,
reply: vscodeCommentThread.reply ? commandsConverter.toInternal(vscodeCommentThread.reply) : null reply: vscodeCommentThread.reply ? commandsConverter.toInternal(vscodeCommentThread.reply) : null
}; };
} }
......
...@@ -1868,3 +1868,15 @@ export enum FoldingRangeType { ...@@ -1868,3 +1868,15 @@ export enum FoldingRangeType {
} }
//#endregion //#endregion
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1
}
\ No newline at end of file
...@@ -102,6 +102,9 @@ export class CommentNode { ...@@ -102,6 +102,9 @@ export class CommentNode {
} }
} }
const EXPAND_ACTION_CLASS = 'expand-review-action octicon octicon-chevron-down';
const COLLAPSE_ACTION_CLASS = 'expand-review-action octicon octicon-chevron-up';
export class ReviewZoneWidget extends ZoneWidget { export class ReviewZoneWidget extends ZoneWidget {
private _headElement: HTMLElement; private _headElement: HTMLElement;
protected _primaryHeading: HTMLElement; protected _primaryHeading: HTMLElement;
...@@ -113,7 +116,7 @@ export class ReviewZoneWidget extends ZoneWidget { ...@@ -113,7 +116,7 @@ export class ReviewZoneWidget extends ZoneWidget {
private _commentElements: CommentNode[]; private _commentElements: CommentNode[];
private _resizeObserver: any; private _resizeObserver: any;
private _onDidClose = new Emitter<ReviewZoneWidget>(); private _onDidClose = new Emitter<ReviewZoneWidget>();
private _isCollapsed = true; private _isCollapsed;
private _toggleAction: Action; private _toggleAction: Action;
private _commentThread: modes.CommentThread; private _commentThread: modes.CommentThread;
public get commentThread(): modes.CommentThread { public get commentThread(): modes.CommentThread {
...@@ -139,6 +142,7 @@ export class ReviewZoneWidget extends ZoneWidget { ...@@ -139,6 +142,7 @@ export class ReviewZoneWidget extends ZoneWidget {
this._owner = owner; this._owner = owner;
this._commentThread = commentThread; this._commentThread = commentThread;
this._replyCommand = replyCommand; this._replyCommand = replyCommand;
this._isCollapsed = commentThread.collapsibleState !== modes.CommentThreadCollapsibleState.Expanded;
this.create(); this.create();
this.themeService.onThemeChange(this._applyTheme, this); this.themeService.onThemeChange(this._applyTheme, this);
} }
...@@ -183,15 +187,15 @@ export class ReviewZoneWidget extends ZoneWidget { ...@@ -183,15 +187,15 @@ export class ReviewZoneWidget extends ZoneWidget {
this._actionbarWidget = new ActionBar(actionsContainer.getHTMLElement(), {}); this._actionbarWidget = new ActionBar(actionsContainer.getHTMLElement(), {});
this._disposables.push(this._actionbarWidget); this._disposables.push(this._actionbarWidget);
this._toggleAction = new Action('review.expand', nls.localize('label.expand', "Expand"), 'expand-review-action octicon octicon-chevron-down', true, () => { this._toggleAction = new Action('review.expand', nls.localize('label.expand', "Expand"), this._isCollapsed ? EXPAND_ACTION_CLASS : COLLAPSE_ACTION_CLASS, true, () => {
if (this._isCollapsed) { if (this._isCollapsed) {
this._bodyElement.style.display = 'block'; this._bodyElement.style.display = 'block';
this._toggleAction.class = 'expand-review-action octicon octicon-chevron-up'; this._toggleAction.class = COLLAPSE_ACTION_CLASS;
this._isCollapsed = false; this._isCollapsed = false;
} }
else { else {
this._bodyElement.style.display = 'none'; this._bodyElement.style.display = 'none';
this._toggleAction.class = 'expand-review-action octicon octicon-chevron-down'; this._toggleAction.class = EXPAND_ACTION_CLASS;
this._isCollapsed = true; this._isCollapsed = true;
} }
return null; return null;
...@@ -270,7 +274,7 @@ export class ReviewZoneWidget extends ZoneWidget { ...@@ -270,7 +274,7 @@ export class ReviewZoneWidget extends ZoneWidget {
this._headElement.style.height = `${headHeight}px`; this._headElement.style.height = `${headHeight}px`;
this._headElement.style.lineHeight = this._headElement.style.height; this._headElement.style.lineHeight = this._headElement.style.height;
this._bodyElement.style.display = 'none'; this._bodyElement.style.display = this._isCollapsed ? 'none' : 'block';
this._commentsElement = $('div.comments-container').appendTo(this._bodyElement).getHTMLElement(); this._commentsElement = $('div.comments-container').appendTo(this._bodyElement).getHTMLElement();
this._commentElements = []; this._commentElements = [];
for (let i = 0; i < this._commentThread.comments.length; i++) { for (let i = 0; i < this._commentThread.comments.length; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册