Skip to content

Commit 4e2808f

Browse files
Copilotalexr00
andcommitted
Add hide viewed files setting and toggle command
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 870ab19 commit 4e2808f

File tree

7 files changed

+63
-6
lines changed

7 files changed

+63
-6
lines changed

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@
283283
"default": "tree",
284284
"description": "%githubPullRequests.fileListLayout.description%"
285285
},
286+
"githubPullRequests.hideViewedFiles": {
287+
"type": "boolean",
288+
"default": false,
289+
"description": "%githubPullRequests.hideViewedFiles.description%"
290+
},
286291
"githubPullRequests.defaultDeletionMethod.selectLocalBranch": {
287292
"type": "boolean",
288293
"default": true,
@@ -1079,6 +1084,12 @@
10791084
"icon": "$(list-flat)",
10801085
"category": "%command.pull.request.category%"
10811086
},
1087+
{
1088+
"command": "pr.toggleHideViewedFiles",
1089+
"title": "%command.pr.toggleHideViewedFiles.title%",
1090+
"icon": "$(eye-closed)",
1091+
"category": "%command.pull.request.category%"
1092+
},
10821093
{
10831094
"command": "pr.refreshChanges",
10841095
"title": "%command.pr.refreshChanges.title%",
@@ -2635,6 +2646,11 @@
26352646
"when": "view == prStatus:github && !fileListLayout:flat",
26362647
"group": "navigation1"
26372648
},
2649+
{
2650+
"command": "pr.toggleHideViewedFiles",
2651+
"when": "view == prStatus:github",
2652+
"group": "navigation1"
2653+
},
26382654
{
26392655
"command": "pr.toggleEditorCommentingOn",
26402656
"when": "view == prStatus:github && !commentingEnabled",

package.nls.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"githubPullRequests.defaultMergeMethod.description": "The method to use when merging pull requests.",
3636
"githubPullRequests.notifications.description": "If GitHub notifications should be shown to the user.",
3737
"githubPullRequests.fileListLayout.description": "The layout to use when displaying changed files list.",
38+
"githubPullRequests.hideViewedFiles.description": "Hide files that have been marked as viewed in the pull request changes tree.",
3839
"githubPullRequests.defaultDeletionMethod.selectLocalBranch.description": "When true, the option to delete the local branch will be selected by default when deleting a branch from a pull request.",
3940
"githubPullRequests.defaultDeletionMethod.selectRemote.description": "When true, the option to delete the remote will be selected by default when deleting a branch from a pull request.",
4041
"githubPullRequests.terminalLinksHandler.description": "Default handler for terminal links.",
@@ -220,6 +221,7 @@
220221
"command.pr.refreshChatSessions.title": "Refresh Chat Sessions",
221222
"command.pr.setFileListLayoutAsTree.title": "View as Tree",
222223
"command.pr.setFileListLayoutAsFlat.title": "View as List",
224+
"command.pr.toggleHideViewedFiles.title": "Toggle Hide Viewed Files",
223225
"command.pr.refreshChanges.title": "Refresh",
224226
"command.pr.configurePRViewlet.title": "Configure...",
225227
"command.pr.deleteLocalBranch.title": "Delete Local Branch",

src/commands.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CommentReply, findActiveHandler, resolveCommentHandler } from './commen
1212
import { commands } from './common/executeCommands';
1313
import Logger from './common/logger';
1414
import * as PersistentState from './common/persistentState';
15-
import { FILE_LIST_LAYOUT, PR_SETTINGS_NAMESPACE } from './common/settingKeys';
15+
import { FILE_LIST_LAYOUT, HIDE_VIEWED_FILES, PR_SETTINGS_NAMESPACE } from './common/settingKeys';
1616
import { editQuery } from './common/settingsUtils';
1717
import { ITelemetry } from './common/telemetry';
1818
import { asTempStorageURI, fromPRUri, fromReviewUri, Schemes, toPRUri } from './common/uri';
@@ -1484,6 +1484,14 @@ ${contents}
14841484
}),
14851485
);
14861486

1487+
context.subscriptions.push(
1488+
vscode.commands.registerCommand('pr.toggleHideViewedFiles', _ => {
1489+
const config = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE);
1490+
const currentValue = config.get<boolean>(HIDE_VIEWED_FILES, false);
1491+
config.update(HIDE_VIEWED_FILES, !currentValue, true);
1492+
}),
1493+
);
1494+
14871495
context.subscriptions.push(
14881496
vscode.commands.registerCommand('pr.refreshPullRequest', (prNode: PRNode) => {
14891497
const folderManager = reposManager.getManagerForIssueModel(prNode.pullRequestModel);

src/common/settingKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const TERMINAL_LINK_HANDLER = 'terminalLinksHandler';
88
export const BRANCH_PUBLISH = 'createOnPublishBranch';
99
export const USE_REVIEW_MODE = 'useReviewMode';
1010
export const FILE_LIST_LAYOUT = 'fileListLayout';
11+
export const HIDE_VIEWED_FILES = 'hideViewedFiles';
1112
export const ASSIGN_TO = 'assignCreated';
1213
export const PUSH_BRANCH = 'pushBranch';
1314
export const IGNORE_PR_BRANCHES = 'ignoredPullRequestBranches';

src/extension.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Logger from './common/logger';
1717
import * as PersistentState from './common/persistentState';
1818
import { parseRepositoryRemotes } from './common/remote';
1919
import { Resource } from './common/resources';
20-
import { BRANCH_PUBLISH, EXPERIMENTAL_CHAT, FILE_LIST_LAYOUT, GIT, IGNORE_SUBMODULES, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE, SHOW_INLINE_OPEN_FILE_ACTION } from './common/settingKeys';
20+
import { BRANCH_PUBLISH, EXPERIMENTAL_CHAT, FILE_LIST_LAYOUT, GIT, HIDE_VIEWED_FILES, IGNORE_SUBMODULES, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE, SHOW_INLINE_OPEN_FILE_ACTION } from './common/settingKeys';
2121
import { initBasedOnSettingChange } from './common/settingsUtils';
2222
import { TemporaryState } from './common/temporaryState';
2323
import { Schemes } from './common/uri';
@@ -241,6 +241,9 @@ async function init(
241241
const layout = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(FILE_LIST_LAYOUT);
242242
await vscode.commands.executeCommand('setContext', 'fileListLayout:flat', layout === 'flat');
243243

244+
const hideViewedFiles = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(HIDE_VIEWED_FILES, false);
245+
await vscode.commands.executeCommand('setContext', 'hideViewedFiles', hideViewedFiles);
246+
244247
const issuesFeatures = new IssueFeatureRegistrar(git, reposManager, reviewsManager, context, telemetry, copilotRemoteAgentManager);
245248
context.subscriptions.push(issuesFeatures);
246249
await issuesFeatures.initialize();

src/view/prChangesTreeDataProvider.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { GitApiImpl } from '../api/api1';
88
import { commands, contexts } from '../common/executeCommands';
99
import { Disposable } from '../common/lifecycle';
1010
import Logger, { PR_TREE } from '../common/logger';
11-
import { FILE_LIST_LAYOUT, GIT, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
11+
import { FILE_LIST_LAYOUT, GIT, HIDE_VIEWED_FILES, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
1212
import { isDescendant } from '../common/utils';
1313
import { FolderRepositoryManager } from '../github/folderRepositoryManager';
1414
import { PullRequestModel } from '../github/pullRequestModel';
@@ -50,6 +50,12 @@ export class PullRequestChangesTreeDataProvider extends Disposable implements vs
5050
await vscode.commands.executeCommand('setContext', 'fileListLayout:flat', layout === 'flat');
5151
} else if (e.affectsConfiguration(`${GIT}.${OPEN_DIFF_ON_CLICK}`)) {
5252
this._onDidChangeTreeData.fire();
53+
} else if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${HIDE_VIEWED_FILES}`)) {
54+
this._onDidChangeTreeData.fire();
55+
const hideViewedFiles = vscode.workspace
56+
.getConfiguration(PR_SETTINGS_NAMESPACE)
57+
.get<boolean>(HIDE_VIEWED_FILES, false);
58+
await vscode.commands.executeCommand('setContext', 'hideViewedFiles', hideViewedFiles);
5359
}
5460
}),
5561
);

src/view/treeNodes/filesCategoryNode.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import { ViewedState } from '../../common/comment';
78
import Logger, { PR_TREE } from '../../common/logger';
8-
import { FILE_LIST_LAYOUT, PR_SETTINGS_NAMESPACE } from '../../common/settingKeys';
9+
import { FILE_LIST_LAYOUT, HIDE_VIEWED_FILES, PR_SETTINGS_NAMESPACE } from '../../common/settingKeys';
910
import { compareIgnoreCase } from '../../common/utils';
1011
import { PullRequestModel } from '../../github/pullRequestModel';
1112
import { ReviewModel } from '../reviewModel';
@@ -39,6 +40,16 @@ export class FilesCategoryNode extends TreeNode implements vscode.TreeItem {
3940
this.refresh(this);
4041
}
4142
}));
43+
this.childrenDisposables.push(_pullRequestModel.onDidChangeFileViewedState(() => {
44+
Logger.appendLine(`File viewed state has changed, refreshing Files node`, PR_TREE);
45+
this.refresh(this);
46+
}));
47+
this.childrenDisposables.push(vscode.workspace.onDidChangeConfiguration(e => {
48+
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${HIDE_VIEWED_FILES}`)) {
49+
Logger.appendLine(`Hide viewed files setting has changed, refreshing Files node`, PR_TREE);
50+
this.refresh(this);
51+
}
52+
}));
4253
}
4354

4455
getTreeItem(): vscode.TreeItem {
@@ -65,9 +76,19 @@ export class FilesCategoryNode extends TreeNode implements vscode.TreeItem {
6576

6677
let nodes: TreeNode[];
6778
const layout = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string>(FILE_LIST_LAYOUT);
79+
const hideViewedFiles = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(HIDE_VIEWED_FILES, false);
80+
81+
// Filter files based on hideViewedFiles setting
82+
const filesToShow = hideViewedFiles
83+
? this._reviewModel.localFileChanges.filter(f => f.changeModel.viewed !== ViewedState.VIEWED)
84+
: this._reviewModel.localFileChanges;
85+
86+
if (filesToShow.length === 0 && hideViewedFiles) {
87+
return [new LabelOnlyNode(this, vscode.l10n.t('All files viewed'))];
88+
}
6889

6990
const dirNode = new DirectoryTreeNode(this, '');
70-
this._reviewModel.localFileChanges.forEach(f => dirNode.addFile(f));
91+
filesToShow.forEach(f => dirNode.addFile(f));
7192
dirNode.finalize();
7293
if (dirNode.label === '') {
7394
// nothing on the root changed, pull children to parent
@@ -79,7 +100,7 @@ export class FilesCategoryNode extends TreeNode implements vscode.TreeItem {
79100
if (layout === 'tree') {
80101
nodes = this.directories;
81102
} else {
82-
const fileNodes = [...this._reviewModel.localFileChanges];
103+
const fileNodes = [...filesToShow];
83104
fileNodes.sort((a, b) => compareIgnoreCase(a.fileChangeResourceUri.toString(), b.fileChangeResourceUri.toString()));
84105
nodes = fileNodes;
85106
}

0 commit comments

Comments
 (0)