Skip to content

Commit 908af66

Browse files
committed
Add collapse all button for files
Related to #106 Add a 'Collapse All' button for files in the Git Tree Compare extension. * **package.json** - Add a new command `gitTreeCompare.collapseAll` to the `commands` section. - Add the new command to the `view/title` menu section. * **src/extension.ts** - Register the new command `gitTreeCompare.collapseAll`. - Implement the `collapseAll` command to collapse all tree items. * **README.md** - Update the `README.md` to include the new 'Collapse All' feature. * **src/treeProvider.ts** - Add a new method `collapseAll` to collapse all tree items. - Update the constructor to bind the new `collapseAll` method to the class. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/letmaik/vscode-git-tree-compare/issues/106?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent aa166f1 commit 908af66

File tree

4 files changed

+87
-57
lines changed

4 files changed

+87
-57
lines changed

README.md

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
1-
# Git Tree Compare
2-
3-
This [Visual Studio Code](https://code.visualstudio.com/) extension helps you compare your working tree against a branch, tag, or commit in a natural **folder tree structure** or a flat list.
4-
5-
It is perfect for keeping an eye on what your pull request will look like, a **pull request preview** one could say. You don't have to leave your editor at all anymore!
6-
7-
In bigger projects with many files it also provides **context**, it gives you a quick way to figure out which of those files you have been working on in your feature branch. This comes in handy when you work on several branches in parallel, or simply when you forgot where you left off the following day.
8-
9-
<img src="screenshots/main.png" alt="Screenshot of Git Tree Compare view" width="243" />
10-
11-
## Features
12-
13-
- Working tree comparison against any chosen branch, tag, or commit
14-
15-
- Switch between tree and list view
16-
17-
- Compare in merge or full mode
18-
19-
- Open Changes or Open File
20-
21-
- Discard Changes
22-
23-
- Automatic refresh on file changes
24-
25-
- Remembers the chosen comparison base per repository
26-
27-
- Log output of all git commands run
28-
29-
- Search within changed files
30-
31-
## Location
32-
33-
By default, the tree view is located in its own container accessible from the activity bar on the left. However, it can be freely moved to any other location like Source Control or Explorer by dragging and dropping.
34-
35-
<img src="screenshots/move-view.gif" alt="Moving of Git Tree Compare view between containers" width="256" />
36-
37-
## Settings
38-
39-
`gitTreeCompare.diffMode` Determines how the comparison is performed, either by computing a merge base commit first and then comparing against that (equivalent to pull request diffs, default), or by comparing directly to the given base (useful to see the exact diff).
40-
41-
`gitTreeCompare.autoRefresh` Option to turn off automatic refresh. This can be useful for huge repositories when diff operations take a long time. As a work-around, disabling auto refresh also prevents locking issues when running `git rebase` from the integrated terminal (a stand-alone terminal wouldn't cause issues as auto refresh is stopped while the VS Code window is out of focus). A manual refresh can be triggered via the tree menu. Note that automatic refreshs are not triggered by changes to files outside the workspace folder (which can happen when opening a subdirectory of the repository root as workspace folder).
42-
43-
`gitTreeCompare.refreshIndex` Option to turn off refreshing of the git index each time the tree is refreshed. Keeping this enabled avoids superfluous diff entries for cases when only the file modification date is changed, at the cost of an extra git invocation.
44-
45-
`gitTreeCompare.findRenames` Option to turn off rename detection when invoking `git diff-index`. Leaving this option on may have a performance impact for large diffs, especially when `autoRefresh` is enabled.
46-
47-
`gitTreeCompare.openChanges` Option which decides what should happen when clicking on a file in the tree - either open the changes, or the file itself. Default is to open the changes. The other action can always be accessed via the file's context menu.
48-
49-
`gitTreeCompare.root` Determines what the tree root should be when the workspace folder is not the same as the repository root. Default is to make the workspace folder the tree root. Any changes outside the workspace folder are then displayed in a special `/` node.
50-
51-
`gitTreeCompare.includeFilesOutsideWorkspaceRoot` Determines whether to display the special `/` node when the tree root is not the repository root and there are changes outside the workspace folder. Default is to display the `/` node.
52-
53-
`gitTreeCompare.iconsMinimal` Option which enables a compact icon layout where only files have icons, comparable to the Seti file icon theme.
54-
55-
`gitTreeCompare.collapsed` When enabled, shows folders collapsed instead of expanded. NOTE: Changing this option requires restarting VS Code.
56-
57-
`gitTreeCompare.compactFolders` When enabled, compacts (flattens) single-child folders into a single tree element. Useful for Java package structures, for example. May have a performance impact for large diff trees.
1+
# Git Tree Compare
2+
3+
This [Visual Studio Code](https://code.visualstudio.com/) extension helps you compare your working tree against a branch, tag, or commit in a natural **folder tree structure** or a flat list.
4+
5+
It is perfect for keeping an eye on what your pull request will look like, a **pull request preview** one could say. You don't have to leave your editor at all anymore!
6+
7+
In bigger projects with many files it also provides **context**, it gives you a quick way to figure out which of those files you have been working on in your feature branch. This comes in handy when you work on several branches in parallel, or simply when you forgot where you left off the following day.
8+
9+
<img src="screenshots/main.png" alt="Screenshot of Git Tree Compare view" width="243" />
10+
11+
## Features
12+
13+
- Working tree comparison against any chosen branch, tag, or commit
14+
15+
- Switch between tree and list view
16+
17+
- Compare in merge or full mode
18+
19+
- Open Changes or Open File
20+
21+
- Discard Changes
22+
23+
- Automatic refresh on file changes
24+
25+
- Remembers the chosen comparison base per repository
26+
27+
- Log output of all git commands run
28+
29+
- Search within changed files
30+
31+
- Collapse All
32+
33+
## Location
34+
35+
By default, the tree view is located in its own container accessible from the activity bar on the left. However, it can be freely moved to any other location like Source Control or Explorer by dragging and dropping.
36+
37+
<img src="screenshots/move-view.gif" alt="Moving of Git Tree Compare view between containers" width="256" />
38+
39+
## Settings
40+
41+
`gitTreeCompare.diffMode` Determines how the comparison is performed, either by computing a merge base commit first and then comparing against that (equivalent to pull request diffs, default), or by comparing directly to the given base (useful to see the exact diff).
42+
43+
`gitTreeCompare.autoRefresh` Option to turn off automatic refresh. This can be useful for huge repositories when diff operations take a long time. As a work-around, disabling auto refresh also prevents locking issues when running `git rebase` from the integrated terminal (a stand-alone terminal wouldn't cause issues as auto refresh is stopped while the VS Code window is out of focus). A manual refresh can be triggered via the tree menu. Note that automatic refreshs are not triggered by changes to files outside the workspace folder (which can happen when opening a subdirectory of the repository root as workspace folder).
44+
45+
`gitTreeCompare.refreshIndex` Option to turn off refreshing of the git index each time the tree is refreshed. Keeping this enabled avoids superfluous diff entries for cases when only the file modification date is changed, at the cost of an extra git invocation.
46+
47+
`gitTreeCompare.findRenames` Option to turn off rename detection when invoking `git diff-index`. Leaving this option on may have a performance impact for large diffs, especially when `autoRefresh` is enabled.
48+
49+
`gitTreeCompare.openChanges` Option which decides what should happen when clicking on a file in the tree - either open the changes, or the file itself. Default is to open the changes. The other action can always be accessed via the file's context menu.
50+
51+
`gitTreeCompare.root` Determines what the tree root should be when the workspace folder is not the same as the repository root. Default is to make the workspace folder the tree root. Any changes outside the workspace folder are then displayed in a special `/` node.
52+
53+
`gitTreeCompare.includeFilesOutsideWorkspaceRoot` Determines whether to display the special `/` node when the tree root is not the repository root and there are changes outside the workspace folder. Default is to display the `/` node.
54+
55+
`gitTreeCompare.iconsMinimal` Option which enables a compact icon layout where only files have icons, comparable to the Seti file icon theme.
56+
57+
`gitTreeCompare.collapsed` When enabled, shows folders collapsed instead of expanded. NOTE: Changing this option requires restarting VS Code.
58+
59+
`gitTreeCompare.compactFolders` When enabled, compacts (flattens) single-child folders into a single tree element. Useful for Java package structures, for example. May have a performance impact for large diff trees.

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@
153153
"title": "Search Changes",
154154
"icon": "$(search)",
155155
"category": "Git Tree Compare"
156+
},
157+
{
158+
"command": "gitTreeCompare.collapseAll",
159+
"title": "Collapse All",
160+
"icon": "$(collapse-all)",
161+
"category": "Git Tree Compare"
156162
}
157163
],
158164
"menus": {
@@ -231,6 +237,11 @@
231237
"command": "gitTreeCompare.searchChanges",
232238
"when": "view == gitTreeCompare",
233239
"group": "2_files"
240+
},
241+
{
242+
"command": "gitTreeCompare.collapseAll",
243+
"when": "view == gitTreeCompare",
244+
"group": "navigation@4"
234245
}
235246
],
236247
"view/item/context": [

src/extension.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ export function activate(context: ExtensionContext) {
9393
runAfterInit(() => provider!.searchChanges());
9494
});
9595

96+
commands.registerCommand(NAMESPACE + '.collapseAll', () => {
97+
runAfterInit(() => {
98+
provider!.collapseAll();
99+
});
100+
});
101+
96102
createGit(gitApi, outputChannel).then(async git => {
97103
const onOutput = (str: string) => outputChannel.append(str);
98104
git.onOutput.addListener('log', onOutput);

src/treeProvider.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export class GitTreeCompareProvider implements TreeDataProvider<Element>, Dispos
141141
constructor(private readonly git: Git, private readonly gitApi: GitAPI, private readonly outputChannel: OutputChannel, private readonly globalState: Memento,
142142
private readonly asAbsolutePath: (relPath: string) => string) {
143143
this.readConfig();
144+
this.collapseAll = this.collapseAll.bind(this);
144145
}
145146

146147
async init(treeView: TreeView<Element>) {
@@ -1113,6 +1114,16 @@ export class GitTreeCompareProvider implements TreeDataProvider<Element>, Dispos
11131114
});
11141115
}
11151116

1117+
async collapseAll() {
1118+
const root = this.treeRoot;
1119+
const elements = this.getFileSystemEntries(root, false);
1120+
for (const element of elements) {
1121+
if (element instanceof FolderElement) {
1122+
this.treeView.reveal(element, { expand: false });
1123+
}
1124+
}
1125+
}
1126+
11161127
dispose(): void {
11171128
this.disposables.forEach(d => d.dispose());
11181129
}

0 commit comments

Comments
 (0)