Skip to content

Commit 0eb202b

Browse files
committed
Closes #150 - adds auto view to custom view
1 parent 65736a6 commit 0eb202b

File tree

6 files changed

+49
-24
lines changed

6 files changed

+49
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1414
- Expands to a file-based view of all changed files in the working tree (enabled via `"gitlens.insiders": true`) and/or all files in all commits ahead of the upstream
1515
- Adds `gitlens.gitExplorer.enabled` setting to specify whether or not to show the `GitLens` custom view - closes [#144](https://github.com/eamodio/vscode-gitlens/issues/144)
1616
- Adds `gitlens.gitExplorer.statusFileFormat` setting to the format of the status of a working or committed file in the `GitLens` custom view
17+
- Adds `auto` value to `gitlens.gitExplorer.view` setting - closes [#150](https://github.com/eamodio/vscode-gitlens/issues/150)
1718

1819
### Changed
1920
- Changes the sorting (now alphabetical) of files shown in the `GitLens` custom view
21+
- Changes the default of the `gitlens.gitExplorer.view` setting to `auto`
2022
- Changes the default of the `gitlens.gitExplorer.commitFormat` setting to add parentheses around the commit id
2123
- Removes many menu items from `editor/title` & `editor/title/context` by default -- can be re-enabled via the `gitlens.advanced.menus` setting
2224

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ GitLens is highly customizable and provides many configuration settings to allow
346346
|`gitlens.codeLens.recentChange.command`|Specifies the command to be executed when the `recent change` code lens is clicked<br />`gitlens.toggleFileBlame` - toggles file blame annotations<br />`gitlens.showBlameHistory` - opens the blame history explorer<br />`gitlens.showFileHistory` - opens the file history explorer<br />`gitlens.diffWithPrevious` - compares the current committed file with the previous commit<br />`gitlens.showQuickCommitDetails` - shows a commit details quick pick<br />`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick<br />`gitlens.showQuickFileHistory` - shows a file history quick pick<br />`gitlens.showQuickRepoHistory` - shows a branch history quick pick
347347
|`gitlens.codeLens.authors.enabled`|Specifies whether or not to show an `authors` code lens showing number of authors of the file or code block and the most prominent author (if there is more than one)
348348
|`gitlens.codeLens.authors.command`|Specifies the command to be executed when the `authors` code lens is clicked<br />`gitlens.toggleFileBlame` - toggles file blame annotations<br />`gitlens.showBlameHistory` - opens the blame history explorer<br />`gitlens.showFileHistory` - opens the file history explorer<br />`gitlens.diffWithPrevious` - compares the current committed file with the previous commit<br />`gitlens.showQuickCommitDetails` - shows a commit details quick pick<br />`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick<br />`gitlens.showQuickFileHistory` - shows a file history quick pick<br />`gitlens.showQuickRepoHistory` - shows a branch history quick pick
349-
|`gitlens.codeLens.locations`|Specifies where Git code lens will be shown in the document<br />`document` - adds code lens at the top of the document<br />`containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)<br />`blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines<br />`custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`
349+
|`gitlens.codeLens.locations`|Specifies where Git code lens will be shown in the document<br />`document` - adds code lens at the top of the document<br />`containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)<br />`blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines<br />`custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`
350350
|`gitlens.codeLens.customLocationSymbols`|Specifies the set of document symbols where Git code lens will be shown in the document
351351
|`gitlens.codeLens.perLanguageLocations`|Specifies where Git code lens will be shown in the document for the specified languages
352352

@@ -355,7 +355,7 @@ GitLens is highly customizable and provides many configuration settings to allow
355355
|Name | Description
356356
|-----|------------
357357
|`gitlens.gitExplorer.enabled`|Specifies whether or not to show the `GitLens` custom view"
358-
|`gitlens.gitExplorer.view`|Specifies the starting view (mode) of the `GitLens` custom view<br />`history` - shows the commit history of the active file<br />`repository` - shows a repository explorer"
358+
|`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"
359359
|`gitlens.gitExplorer.showTrackingBranch`|Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens` custom view"
360360
|`gitlens.gitExplorer.commitFormat`|Specifies the format of committed changes in the `GitLens` custom view<br />Available tokens<br /> ${id} - commit id<br /> ${author} - commit author<br /> ${message} - commit message<br /> ${ago} - relative commit date (e.g. 1 day ago)<br /> ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)<br /> ${authorAgo} - commit author, relative commit date<br />See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting
361361
|`gitlens.gitExplorer.commitFileFormat`|Specifies the format of a committed file in the `GitLens` custom view<br />Available tokens<br /> ${file} - file name<br /> ${filePath} - file name and path<br /> ${path} - file path

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@
303303
"minItems": 1,
304304
"maxItems": 4,
305305
"uniqueItems": true,
306-
"description": "Specifies where Git code lens will be shown in the document\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines\n `custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`"
306+
"description": "Specifies where Git code lens will be shown in the document\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines\n `custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`"
307307
},
308308
"gitlens.codeLens.customLocationSymbols": {
309309
"type": "array",
@@ -388,7 +388,7 @@
388388
"minItems": 1,
389389
"maxItems": 4,
390390
"uniqueItems": true,
391-
"description": "Specifies where Git code lens will be shown in the document for the specified language\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines\n `custom` - adds code lens at the start of symbols contained in `customSymbols`"
391+
"description": "Specifies where Git code lens will be shown in the document for the specified language\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines\n `custom` - adds code lens at the start of symbols contained in `customSymbols`"
392392
},
393393
"customSymbols": {
394394
"type": "array",
@@ -450,12 +450,13 @@
450450
},
451451
"gitlens.gitExplorer.view": {
452452
"type": "string",
453-
"default": "repository",
453+
"default": "auto",
454454
"enum": [
455+
"auto",
455456
"history",
456457
"repository"
457458
],
458-
"description": "Specifies the starting view (mode) of the `GitLens` custom view\n `history` - shows the commit history of the active file\n `repository` - shows a repository explorer"
459+
"description": "Specifies the starting view (mode) of the `GitLens` custom view\n `auto` - shows the last selected view, defaults to `repository`\n `history` - shows the commit history of the active file\n `repository` - shows a repository explorer"
459460
},
460461
"gitlens.remotes": {
461462
"type": "array",

src/constants.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ export const GlyphChars = {
109109
ZeroWidthSpace: '\u200b' as GlyphChars
110110
};
111111

112-
export type WorkspaceState = 'gitlensVersion';
112+
export type GlobalState = 'gitlensVersion';
113+
export const GlobalState = {
114+
GitLensVersion: 'gitlensVersion' as GlobalState
115+
};
116+
117+
export type WorkspaceState = 'gitlens:gitExplorer:view';
113118
export const WorkspaceState = {
114-
GitLensVersion: 'gitlensVersion' as WorkspaceState
119+
GitExplorerView: 'gitlens:gitExplorer:view' as WorkspaceState
115120
};

src/extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ShowQuickRepoStatusCommand, ShowQuickStashListCommand } from './command
1616
import { StashApplyCommand, StashDeleteCommand, StashSaveCommand } from './commands';
1717
import { ToggleCodeLensCommand } from './commands';
1818
import { CodeLensLocations, IConfig, LineHighlightLocations } from './configuration';
19-
import { ApplicationInsightsKey, CommandContext, ExtensionKey, QualifiedExtensionId, setCommandContext, WorkspaceState } from './constants';
19+
import { ApplicationInsightsKey, CommandContext, ExtensionKey, GlobalState, QualifiedExtensionId, setCommandContext } from './constants';
2020
import { CodeLensController } from './codeLensController';
2121
import { CurrentLineController, LineAnnotationType } from './currentLineController';
2222
import { RemoteProviderFactory } from './git/remotes/factory';
@@ -71,7 +71,7 @@ export async function activate(context: ExtensionContext) {
7171
notifyOnUnsupportedGitVersion(context, gitVersion);
7272
notifyOnNewGitLensVersion(context, gitlensVersion);
7373

74-
await context.globalState.update(WorkspaceState.GitLensVersion, gitlensVersion);
74+
await context.globalState.update(GlobalState.GitLensVersion, gitlensVersion);
7575

7676
const git = new GitService(repoPath);
7777
context.subscriptions.push(git);
@@ -148,7 +148,7 @@ export async function activate(context: ExtensionContext) {
148148
export function deactivate() { }
149149

150150
async function migrateSettings(context: ExtensionContext) {
151-
const previousVersion = context.globalState.get<string>(WorkspaceState.GitLensVersion);
151+
const previousVersion = context.globalState.get<string>(GlobalState.GitLensVersion);
152152
if (previousVersion === undefined) return;
153153

154154
const [major] = previousVersion.split('.');
@@ -274,7 +274,7 @@ async function migrateSettings(context: ExtensionContext) {
274274
async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string) {
275275
if (context.globalState.get(SuppressedKeys.UpdateNotice, false)) return;
276276

277-
const previousVersion = context.globalState.get<string>(WorkspaceState.GitLensVersion);
277+
const previousVersion = context.globalState.get<string>(GlobalState.GitLensVersion);
278278

279279
if (previousVersion === undefined) {
280280
Logger.log(`GitLens first-time install`);

src/views/gitExplorer.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import { commands, Event, EventEmitter, ExtensionContext, TextDocumentShowOption
44
import { Commands, DiffWithCommandArgs, DiffWithCommandArgsRevision, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands';
55
import { UriComparer } from '../comparers';
66
import { ExtensionKey, IConfig } from '../configuration';
7-
import { CommandContext, setCommandContext } from '../constants';
7+
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';
1010

1111
export * from './explorerNodes';
1212

1313
export type GitExplorerView =
14+
'auto' |
1415
'history' |
1516
'repository';
1617
export const GitExplorerView = {
18+
Auto: 'auto' as GitExplorerView,
1719
History: 'history' as GitExplorerView,
1820
Repository: 'repository' as GitExplorerView
1921
};
@@ -31,7 +33,7 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
3133

3234
private _config: IConfig;
3335
private _root?: ExplorerNode;
34-
private _view: GitExplorerView = GitExplorerView.Repository;
36+
private _view: GitExplorerView | undefined;
3537

3638
private _onDidChangeTreeData = new EventEmitter<ExplorerNode>();
3739
public get onDidChangeTreeData(): Event<ExplorerNode> {
@@ -62,10 +64,6 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
6264
context.subscriptions.push(workspace.onDidChangeConfiguration(this.onConfigurationChanged, this));
6365

6466
this.onConfigurationChanged();
65-
66-
this._view = this._config.gitExplorer.view;
67-
setCommandContext(CommandContext.GitExplorerView, this._view);
68-
this._root = this.getRootNode();
6967
}
7068

7169
async getTreeItem(node: ExplorerNode): Promise<TreeItem> {
@@ -116,16 +114,25 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
116114
private onConfigurationChanged() {
117115
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
118116

117+
let changed = false;
119118
if (!Objects.areEquivalent(cfg.gitExplorer, this._config && this._config.gitExplorer) ||
120119
!Objects.areEquivalent(cfg.insiders, this._config && this._config.insiders)) {
121-
setTimeout(() => {
122-
this._root = this.getRootNode(window.activeTextEditor);
123-
this.refresh();
124-
}, 1);
120+
changed = true;
125121
}
126122

127123
this._config = cfg;
128-
}
124+
125+
if (changed) {
126+
let view = cfg.gitExplorer.view;
127+
if (view === GitExplorerView.Auto) {
128+
view = this.context.workspaceState.get<GitExplorerView>(WorkspaceState.GitExplorerView, GitExplorerView.Repository);
129+
}
130+
131+
this.setView(view);
132+
this._root = this.getRootNode(window.activeTextEditor);
133+
this.refresh();
134+
}
135+
}
129136

130137
private onRepoChanged(reasons: RepoChangedReasons[]) {
131138
if (this._view !== GitExplorerView.Repository) return;
@@ -149,11 +156,21 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
149156
this.refresh(node);
150157
}
151158

152-
switchTo(view: GitExplorerView) {
159+
setView(view: GitExplorerView) {
153160
if (this._view === view) return;
154161

162+
if (this._config.gitExplorer.view === GitExplorerView.Auto) {
163+
this.context.workspaceState.update(WorkspaceState.GitExplorerView, view);
164+
}
165+
155166
this._view = view;
156167
setCommandContext(CommandContext.GitExplorerView, this._view);
168+
}
169+
170+
switchTo(view: GitExplorerView) {
171+
if (this._view === view) return;
172+
173+
this.setView(view);
157174

158175
this._root = this.getRootNode(window.activeTextEditor);
159176
this.refresh();

0 commit comments

Comments
 (0)