Skip to content

Commit 6d09a1a

Browse files
committed
Adds auto-refresh setting to the custom view
Adds auto-refresh toggling commands Adds per-workspace state for toggling auto-refresh on/off Adds layout selection commands
1 parent c8c4b83 commit 6d09a1a

File tree

7 files changed

+144
-7
lines changed

7 files changed

+144
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
88
### Added
99
- Adds `Open All Changes (with difftool)` command (`gitlens.externalDiffAll`) - opens all working changes with the configured git difftool -- closes [#164](https://github.com/eamodio/vscode-gitlens/issues/164)
1010
- Also adds the command to the Source Control group context menu
11+
- Adds `gitlens.gitExplorer.autoRefresh` setting to specify whether or not to automatically refresh the `GitLens` custom view when the repository or the file system changes
12+
- Adds `Enable Automatic Refresh` command (`gitlens.gitExplorer.setAutoRefreshToOn`) to enable the automatic refresh of the `GitLens` custom view
13+
- Adds `Disable Automatic Refresh` command (`gitlens.gitExplorer.setAutoRefreshToOff`) to disable the automatic refresh of the `GitLens` custom view
14+
- Adds `Show Files in Automatic View` command (`gitlens.gitExplorer.setFilesLayoutToAuto`) to change to an automatic layout for the files in the `GitLens` custom view
15+
- Adds `Show Files in List View` command (`gitlens.gitExplorer.setFilesLayoutToList`) to change to a list layout for the files in the `GitLens` custom view
16+
- Adds `Show Files in Tree View` command (`gitlens.gitExplorer.setFilesLayoutToTree`) to change to a tree layout for the files in the `GitLens` custom view
1117

1218
### Changed
1319
- Renames `Directory Compare` command (`gitlens.diffDirectory`) to `Compare Directory with Branch...`
@@ -17,6 +23,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1723

1824
### Fixed
1925
- Fixes [#163](https://github.com/eamodio/vscode-gitlens/issues/163) - GitLens can cause git locking in the background
26+
- Fixes issue where the `GitLens` custom view would refresh more than once when a file system change was detected
27+
- Fixes issue where opening commit search could be filled out with `#00000000`
2028

2129
## [5.6.5] - 2017-10-16
2230
### Removed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ GitLens is highly customizable and provides many configuration settings to allow
371371
|-----|------------
372372
|`gitlens.gitExplorer.enabled`|Specifies whether or not to show the `GitLens` custom view"
373373
|`gitlens.gitExplorer.view`|Specifies the starting view (mode) of the `GitLens` custom view<br /> `auto` - shows the last selected view, defaults to `repository`<br />`history` - shows the commit history of the active file<br />`repository` - shows a repository explorer"
374+
|`gitlens.gitExplorer.autoRefresh`|Specifies whether or not to automatically refresh the `GitLens` custom view when the repository or the file system changes
374375
|`gitlens.gitExplorer.files.layout`|Specifies how the `GitLens` custom view will display files<br /> `auto` - automatically switches between displaying files as a `tree` or `list` based on the `gitlens.gitExplorer.files.threshold` setting and the number of files at each nesting level<br /> `list` - displays files as a list<br /> `tree` - displays files as a tree
375376
|`gitlens.gitExplorer.files.compact`|Specifies whether or not to compact (flatten) unnecessary file nesting in the `GitLens` custom view<br />Only applies when displaying files as a `tree` or `auto`
376377
|`gitlens.gitExplorer.files.threshold`|Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the `GitLens` custom view<br />Only applies when displaying files as `auto`

package.json

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@
417417
"default": null,
418418
"description": "Specifies how all absolute dates will be formatted by default\nSee https://momentjs.com/docs/#/displaying/format/ for valid formats"
419419
},
420+
"gitlens.gitExplorer.autoRefresh": {
421+
"type": "boolean",
422+
"default": true,
423+
"description": "Specifies whether or not to automatically refresh the `GitLens` custom view when the repository or the file system changes"
424+
},
420425
"gitlens.gitExplorer.commitFormat": {
421426
"type": "string",
422427
"default": "${message} \u00a0\u2022\u00a0 ${authorAgo} \u00a0 (${id})",
@@ -1123,6 +1128,16 @@
11231128
"title": "Reset Suppressed Warnings",
11241129
"category": "GitLens"
11251130
},
1131+
{
1132+
"command": "gitlens.gitExplorer.setAutoRefreshToOn",
1133+
"title": "Enable Automatic Refresh",
1134+
"category": "GitLens"
1135+
},
1136+
{
1137+
"command": "gitlens.gitExplorer.setAutoRefreshToOff",
1138+
"title": "Disable Automatic Refresh",
1139+
"category": "GitLens"
1140+
},
11261141
{
11271142
"command": "gitlens.gitExplorer.refresh",
11281143
"title": "Refresh",
@@ -1132,6 +1147,21 @@
11321147
"light": "images/light/icon-refresh.svg"
11331148
}
11341149
},
1150+
{
1151+
"command": "gitlens.gitExplorer.setFilesLayoutToAuto",
1152+
"title": "Show Files in Automatic View",
1153+
"category": "GitLens"
1154+
},
1155+
{
1156+
"command": "gitlens.gitExplorer.setFilesLayoutToList",
1157+
"title": "Show Files in List View",
1158+
"category": "GitLens"
1159+
},
1160+
{
1161+
"command": "gitlens.gitExplorer.setFilesLayoutToTree",
1162+
"title": "Show Files in Tree View",
1163+
"category": "GitLens"
1164+
},
11351165
{
11361166
"command": "gitlens.gitExplorer.switchToHistoryView",
11371167
"title": "Switch to History View",
@@ -1355,6 +1385,26 @@
13551385
"command": "gitlens.resetSuppressedWarnings",
13561386
"when": "gitlens:enabled"
13571387
},
1388+
{
1389+
"command": "gitlens.gitExplorer.setAutoRefreshToOn",
1390+
"when": "false"
1391+
},
1392+
{
1393+
"command": "gitlens.gitExplorer.setAutoRefreshToOff",
1394+
"when": "false"
1395+
},
1396+
{
1397+
"command": "gitlens.gitExplorer.setFilesLayoutToAuto",
1398+
"when": "false"
1399+
},
1400+
{
1401+
"command": "gitlens.gitExplorer.setFilesLayoutToList",
1402+
"when": "false"
1403+
},
1404+
{
1405+
"command": "gitlens.gitExplorer.setFilesLayoutToTree",
1406+
"when": "false"
1407+
},
13581408
{
13591409
"command": "gitlens.gitExplorer.refresh",
13601410
"when": "false"
@@ -1636,6 +1686,31 @@
16361686
"command": "gitlens.gitExplorer.refresh",
16371687
"when": "view == gitlens.gitExplorer",
16381688
"group": "navigation@4"
1689+
},
1690+
{
1691+
"command": "gitlens.gitExplorer.setFilesLayoutToAuto",
1692+
"when": "view == gitlens.gitExplorer && gitlens:gitExplorer:view == repository",
1693+
"group": "1_gitlens"
1694+
},
1695+
{
1696+
"command": "gitlens.gitExplorer.setFilesLayoutToList",
1697+
"when": "view == gitlens.gitExplorer && gitlens:gitExplorer:view == repository",
1698+
"group": "1_gitlens"
1699+
},
1700+
{
1701+
"command": "gitlens.gitExplorer.setFilesLayoutToTree",
1702+
"when": "view == gitlens.gitExplorer && gitlens:gitExplorer:view == repository",
1703+
"group": "1_gitlens"
1704+
},
1705+
{
1706+
"command": "gitlens.gitExplorer.setAutoRefreshToOn",
1707+
"when": "view == gitlens.gitExplorer && gitlens:gitExplorer:view == repository && config.gitlens.gitExplorer.autoRefresh && !gitlens:gitExplorer:autoRefresh",
1708+
"group": "2_gitlens"
1709+
},
1710+
{
1711+
"command": "gitlens.gitExplorer.setAutoRefreshToOff",
1712+
"when": "view == gitlens.gitExplorer && gitlens:gitExplorer:view == repository && config.gitlens.gitExplorer.autoRefresh && gitlens:gitExplorer:autoRefresh",
1713+
"group": "2_gitlens"
16391714
}
16401715
],
16411716
"view/item/context": [

src/configuration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export interface ICodeLensLanguageLocation {
103103

104104
export interface IGitExplorerConfig {
105105
enabled: boolean;
106+
autoRefresh: boolean;
106107
view: GitExplorerView;
107108
files: {
108109
layout: GitExplorerFilesLayout;

src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export enum CommandContext {
2828
AnnotationStatus = 'gitlens:annotationStatus',
2929
CanToggleCodeLens = 'gitlens:canToggleCodeLens',
3030
Enabled = 'gitlens:enabled',
31+
GitExplorerAutoRefresh = 'gitlens:gitExplorer:autoRefresh',
32+
GitExplorerFilesLayout = 'gitlens:gitExplorer:files:layout',
3133
GitExplorerView = 'gitlens:gitExplorer:view',
3234
HasRemotes = 'gitlens:hasRemotes',
3335
IsBlameable = 'gitlens:isBlameable',
@@ -76,5 +78,6 @@ export enum GlobalState {
7678
}
7779

7880
export enum WorkspaceState {
81+
GitExplorerAutoRefresh = 'gitlens:gitExplorer:autoRefresh',
7982
GitExplorerView = 'gitlens:gitExplorer:view'
8083
}

src/views/gitExplorer.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22
import { Functions, Objects } from '../system';
3-
import { commands, Event, EventEmitter, ExtensionContext, TextDocumentShowOptions, TextEditor, TreeDataProvider, TreeItem, Uri, window, workspace } from 'vscode';
3+
import { commands, Disposable, Event, EventEmitter, ExtensionContext, TextDocumentShowOptions, TextEditor, TreeDataProvider, TreeItem, Uri, window, workspace } from 'vscode';
44
import { Commands, DiffWithCommandArgs, DiffWithCommandArgsRevision, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands';
55
import { UriComparer } from '../comparers';
6-
import { ExtensionKey, IConfig } from '../configuration';
6+
import { ExtensionKey, GitExplorerFilesLayout, IConfig } from '../configuration';
77
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
88
import { BranchHistoryNode, CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoryNode, StashNode } from './explorerNodes';
99
import { GitService, GitUri, RepoChangedReasons } from '../gitService';
@@ -37,6 +37,11 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
3737
}
3838

3939
constructor(private readonly context: ExtensionContext, private readonly git: GitService) {
40+
commands.registerCommand('gitlens.gitExplorer.setAutoRefreshToOn', () => this.setAutoRefresh(this.git.config.gitExplorer.autoRefresh, true), this);
41+
commands.registerCommand('gitlens.gitExplorer.setAutoRefreshToOff', () => this.setAutoRefresh(this.git.config.gitExplorer.autoRefresh, true), this);
42+
commands.registerCommand('gitlens.gitExplorer.setFilesLayoutToAuto', () => this.setFilesLayout(GitExplorerFilesLayout.Auto), this);
43+
commands.registerCommand('gitlens.gitExplorer.setFilesLayoutToList', () => this.setFilesLayout(GitExplorerFilesLayout.List), this);
44+
commands.registerCommand('gitlens.gitExplorer.setFilesLayoutToTree', () => this.setFilesLayout(GitExplorerFilesLayout.Tree), this);
4045
commands.registerCommand('gitlens.gitExplorer.switchToHistoryView', () => this.switchTo(GitExplorerView.History), this);
4146
commands.registerCommand('gitlens.gitExplorer.switchToRepositoryView', () => this.switchTo(GitExplorerView.Repository), this);
4247
commands.registerCommand('gitlens.gitExplorer.refresh', this.refresh, this);
@@ -52,9 +57,6 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
5257
commands.registerCommand('gitlens.gitExplorer.openChangedFileRevisions', this.openChangedFileRevisions, this);
5358
commands.registerCommand('gitlens.gitExplorer.applyChanges', this.applyChanges, this);
5459

55-
const repoChangedFn = Functions.debounce(this.onRepoChanged, 250);
56-
context.subscriptions.push(this.git.onDidChangeRepo(repoChangedFn, this));
57-
5860
const editorChangedFn = Functions.debounce(this.onActiveEditorChanged, 500);
5961
context.subscriptions.push(window.onDidChangeActiveTextEditor(editorChangedFn, this));
6062
context.subscriptions.push(workspace.onDidChangeConfiguration(this.onConfigurationChanged, this));
@@ -112,6 +114,14 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
112114

113115
const changed = !Objects.areEquivalent(cfg.gitExplorer, this._config && this._config.gitExplorer);
114116

117+
if (cfg.gitExplorer.autoRefresh !== (this._config && this._config.gitExplorer.autoRefresh)) {
118+
this.setAutoRefresh(cfg.gitExplorer.autoRefresh);
119+
}
120+
121+
if (cfg.gitExplorer.files.layout !== (this._config && this._config.gitExplorer.files.layout)) {
122+
setCommandContext(CommandContext.GitExplorerFilesLayout, cfg.gitExplorer.files.layout);
123+
}
124+
115125
this._config = cfg;
116126

117127
if (changed) {
@@ -259,4 +269,38 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
259269
private async openFileRevisionInRemote(node: CommitNode | StashNode) {
260270
return commands.executeCommand(Commands.OpenFileInRemote, new GitUri(node.commit.uri, node.commit), { range: false } as OpenFileInRemoteCommandArgs);
261271
}
272+
273+
private _autoRefreshDisposable: Disposable | undefined;
274+
275+
private async setAutoRefresh(enabled: boolean, userToggle: boolean = false) {
276+
if (this._autoRefreshDisposable !== undefined) {
277+
this._autoRefreshDisposable.dispose();
278+
this._autoRefreshDisposable = undefined;
279+
}
280+
281+
if (enabled) {
282+
enabled = this.context.workspaceState.get<boolean>(WorkspaceState.GitExplorerAutoRefresh, true);
283+
284+
if (userToggle) {
285+
enabled = !enabled;
286+
await this.context.workspaceState.update(WorkspaceState.GitExplorerAutoRefresh, enabled);
287+
}
288+
289+
if (enabled) {
290+
const repoChangedFn = Functions.debounce(this.onRepoChanged, 250);
291+
this._autoRefreshDisposable = this.git.onDidChangeRepo(repoChangedFn, this);
292+
this.context.subscriptions.push(this._autoRefreshDisposable);
293+
}
294+
}
295+
296+
setCommandContext(CommandContext.GitExplorerAutoRefresh, enabled);
297+
298+
if (userToggle) {
299+
this.refresh();
300+
}
301+
}
302+
303+
private async setFilesLayout(layout: GitExplorerFilesLayout) {
304+
await workspace.getConfiguration(ExtensionKey).update('gitExplorer.files.layout', layout, true);
305+
}
262306
}

src/views/statusNode.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { commands, Disposable, ExtensionContext, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
2+
import { WorkspaceState } from '../constants';
23
import { ExplorerNode, ResourceType } from './explorerNode';
34
import { GitService, GitStatus, GitUri } from '../gitService';
45
import { StatusFilesNode } from './statusFilesNode';
@@ -56,8 +57,12 @@ export class StatusNode extends ExplorerNode {
5657
if (this.includeWorkingTree) {
5758
this._status = status;
5859

59-
_eventDisposable = this.git.onDidChangeFileSystem(this.onFileSystemChanged, this);
60-
this.git.startWatchingFileSystem();
60+
if (this.git.config.gitExplorer.autoRefresh && this.context.workspaceState.get<boolean>(WorkspaceState.GitExplorerAutoRefresh, true)) {
61+
_eventDisposable = this.git.onDidChangeFileSystem(this.onFileSystemChanged, this);
62+
this.context.subscriptions.push(_eventDisposable);
63+
64+
this.git.startWatchingFileSystem();
65+
}
6166
}
6267

6368
let hasChildren = false;

0 commit comments

Comments
 (0)