Skip to content

Commit

Permalink
feat(pro): (incomplete) integrate track changes interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhyc committed Feb 29, 2024
1 parent 8f3dc02 commit 5066953
Show file tree
Hide file tree
Showing 8 changed files with 521 additions and 84 deletions.
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@
{
"command": "overleaf-workshop.collaboration.copyLineRef",
"title": "%commands.collaboration.copyLineRef.title%",
"enablement": "editorTextFocus && resourceScheme == overleaf-workshop",
"enablement": "editorTextFocus && editorHasSelection && resourceScheme == overleaf-workshop",
"category": "%extension.displayName%"
},
{
"command": "overleaf-workshop.collaboration.insertLineRef",
"title": "%commands.collaboration.insertLineRef.title%",
"enablement": "editorTextFocus && resourceScheme == overleaf-workshop",
"enablement": "editorTextFocus && editorHasSelection && resourceScheme == overleaf-workshop",
"category": "%extension.displayName%"
},
{
Expand All @@ -349,6 +349,18 @@
"title": "%commands.collaboration.jumpToUser.title%",
"enablement": "resourceScheme == overleaf-workshop || overleaf-workshop.activate",
"category": "%extension.displayName%"
},
{
"command": "overleaf-workshop.collaboration.addComment",
"title": "%commands.collaboration.addComment.title%",
"enablement": "editorTextFocus && editorHasSelection && resourceScheme == overleaf-workshop",
"category": "%extension.displayName%"
},
{
"command": "overleaf-workshop.collaboration.toggleTrackChanges",
"title": "%commands.collaboration.toggleTrackChanges.title%",
"enablement": "resourceScheme == overleaf-workshop || overleaf-workshop.activate",
"category": "%extension.displayName%"
}
],
"keybindings": [
Expand Down Expand Up @@ -501,6 +513,10 @@
{
"command": "overleaf-workshop.collaboration.insertLineRef",
"when": "resourceScheme == overleaf-workshop || overleaf-workshop.activate"
},
{
"command": "overleaf-workshop.collaboration.addComment",
"when": "resourceScheme == overleaf-workshop || overleaf-workshop.activate"
}
],
"view/title": [
Expand Down
2 changes: 2 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"commands.collaboration.insertLineRef.title": "Overleaf: Insert Line Reference",
"commands.collaboration.revealChatView.title": "Focus on Overleaf Chat View",
"commands.collaboration.jumpToUser.title": "Jump to Collaborator ...",
"commands.collaboration.addComment.title": "Overleaf: Add Comment",
"commands.collaboration.toggleTrackChanges.title": "Overleaf: Toggle Track Changes",

"configuration.compileOnSave.enabled.markdownDescription": "Always update the compiled PDF when a file is saved.",
"configuration.compileOutputFolderName.markdownDescription": "The name of the folder where the compiled output files (e.g., `output.pdf`) is located. (Take effect after restarting VSCode)",
Expand Down
5 changes: 5 additions & 0 deletions src/api/extendedBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ export class ExtendedBaseAPI extends BaseAPI {
return await this.request('POST', `project/${project_id}/thread/${thread_id}/messages/${message_id}/edit`, {content});
}

async toggleTrackChanges(identity: Identity, project_id: string, on_for: boolean | {[userId:string]: boolean}) {
this.setIdentity(identity);
return await this.request('POST', `project/${project_id}/track_changes`, {on_for});
}

async acceptTrackChanges(identity: Identity, project_id: string, doc_id: string, change_ids: string[]) {
this.setIdentity(identity);
return await this.request('POST', `project/${project_id}/doc/${doc_id}/changes/accept`, {change_ids});
Expand Down
6 changes: 6 additions & 0 deletions src/api/socketio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface EventsHandler {
onCommentThreadMessageCreated?: (threadId:string, message:CommentThreadMessageSchema) => void,
onCommentThreadMessageEdited?: (threadId:string, messageId:string, content:string) => void,
onCommentThreadMessageDeleted?: (threadId:string, messageId:string) => void,
onToggleTrackChanges?: (enabling:boolean | {[userId:string]: boolean}) => void,
onAcceptTrackChanges?: (docId:string, tcIds: string[]) => void,
}

Expand Down Expand Up @@ -302,6 +303,11 @@ export class SocketIOAPI {
handler(threadId, messageId);
});
break;
case handlers.onToggleTrackChanges:
this.socket.on('toggle-track-changes', (enabling:boolean | {[userId:string]: boolean}) => {
handler(enabling);
});
break;
case handlers.onAcceptTrackChanges:
this.socket.on('accept-changes', (docId:string, tcIds: string[]) => {
handler(docId, tcIds);
Expand Down
13 changes: 11 additions & 2 deletions src/collaboration/clientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,21 @@ export class ClientManager {
break;
case true:
let prefixText = '';
let tooltip = new vscode.MarkdownString();

// notify track changes state
if (this.vfs.trackChangesState) {
prefixText = prefixText.concat(`$(record-small) `);
tooltip.appendMarkdown(`<h5 align="center">${vscode.l10n.t('Track changes is on.')}</h5><hr>\n\n`);
}

// notify unread messages
if (this.chatViewer.hasUnread) {
prefixText = prefixText.concat(`$(bell-dot) ${this.chatViewer.hasUnread} `);
}
this.status.command = this.chatViewer.hasUnread? `${ROOT_NAME}.collaboration.revealChatView` : `${ROOT_NAME}.collaboration.settings`;
this.status.backgroundColor = this.chatViewer.hasUnread? new vscode.ThemeColor('statusBarItem.warningBackground') : undefined;

// notify unSynced changes
const unSynced = this.socket.unSyncFileChanges;
if (unSynced) {
Expand All @@ -274,12 +283,12 @@ export class ClientManager {
case 0:
this.status.color = undefined;
this.status.text = prefixText + `${onlineIcon} 0`;
this.status.tooltip = `${ELEGANT_NAME}: ${vscode.l10n.t('Online')}`;
tooltip.appendMarkdown(`${ELEGANT_NAME}: ${vscode.l10n.t('Online')}`);
this.status.tooltip = tooltip;
break;
default:
this.status.color = this.activeExists ? this.onlineUsers[this.activeExists].selection?.color : undefined;
this.status.text = prefixText + `${onlineIcon} ${count}`;
const tooltip = new vscode.MarkdownString();
tooltip.appendMarkdown(`${ELEGANT_NAME}: ${this.activeExists? vscode.l10n.t('Active'): vscode.l10n.t('Idle') }\n\n`);

Object.values(this.onlineUsers).forEach(user => {
Expand Down
Loading

0 comments on commit 5066953

Please sign in to comment.