diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99034e7..8984edd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,9 +14,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- 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
- 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)
- Adds `gitlens.gitExplorer.statusFileFormat` setting to the format of the status of a working or committed file in the `GitLens` custom view
+- Adds `auto` value to `gitlens.gitExplorer.view` setting - closes [#150](https://github.com/eamodio/vscode-gitlens/issues/150)
### Changed
- Changes the sorting (now alphabetical) of files shown in the `GitLens` custom view
+- Changes the default of the `gitlens.gitExplorer.view` setting to `auto`
- Changes the default of the `gitlens.gitExplorer.commitFormat` setting to add parentheses around the commit id
- Removes many menu items from `editor/title` & `editor/title/context` by default -- can be re-enabled via the `gitlens.advanced.menus` setting
diff --git a/README.md b/README.md
index 5b2f479..f43a069 100644
--- a/README.md
+++ b/README.md
@@ -346,7 +346,7 @@ GitLens is highly customizable and provides many configuration settings to allow
|`gitlens.codeLens.recentChange.command`|Specifies the command to be executed when the `recent change` code lens is clicked
`gitlens.toggleFileBlame` - toggles file blame annotations
`gitlens.showBlameHistory` - opens the blame history explorer
`gitlens.showFileHistory` - opens the file history explorer
`gitlens.diffWithPrevious` - compares the current committed file with the previous commit
`gitlens.showQuickCommitDetails` - shows a commit details quick pick
`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick
`gitlens.showQuickFileHistory` - shows a file history quick pick
`gitlens.showQuickRepoHistory` - shows a branch history quick pick
|`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)
|`gitlens.codeLens.authors.command`|Specifies the command to be executed when the `authors` code lens is clicked
`gitlens.toggleFileBlame` - toggles file blame annotations
`gitlens.showBlameHistory` - opens the blame history explorer
`gitlens.showFileHistory` - opens the file history explorer
`gitlens.diffWithPrevious` - compares the current committed file with the previous commit
`gitlens.showQuickCommitDetails` - shows a commit details quick pick
`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick
`gitlens.showQuickFileHistory` - shows a file history quick pick
`gitlens.showQuickRepoHistory` - shows a branch history quick pick
-|`gitlens.codeLens.locations`|Specifies where Git code lens will be shown in the document
`document` - adds code lens at the top of the document
`containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)
`blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines
`custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`
+|`gitlens.codeLens.locations`|Specifies where Git code lens will be shown in the document
`document` - adds code lens at the top of the document
`containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)
`blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines
`custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`
|`gitlens.codeLens.customLocationSymbols`|Specifies the set of document symbols where Git code lens will be shown in the document
|`gitlens.codeLens.perLanguageLocations`|Specifies where Git code lens will be shown in the document for the specified languages
@@ -355,7 +355,7 @@ GitLens is highly customizable and provides many configuration settings to allow
|Name | Description
|-----|------------
|`gitlens.gitExplorer.enabled`|Specifies whether or not to show the `GitLens` custom view"
-|`gitlens.gitExplorer.view`|Specifies the starting view (mode) of the `GitLens` custom view
`history` - shows the commit history of the active file
`repository` - shows a repository explorer"
+|`gitlens.gitExplorer.view`|Specifies the starting view (mode) of the `GitLens` custom view
`auto` - shows the last selected view, defaults to `repository`
`history` - shows the commit history of the active file
`repository` - shows a repository explorer"
|`gitlens.gitExplorer.showTrackingBranch`|Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens` custom view"
|`gitlens.gitExplorer.commitFormat`|Specifies the format of committed changes in the `GitLens` custom view
Available tokens
${id} - commit id
${author} - commit author
${message} - commit message
${ago} - relative commit date (e.g. 1 day ago)
${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)
${authorAgo} - commit author, relative commit date
See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting
|`gitlens.gitExplorer.commitFileFormat`|Specifies the format of a committed file in the `GitLens` custom view
Available tokens
${file} - file name
${filePath} - file name and path
${path} - file path
diff --git a/package.json b/package.json
index 206d400..d97a085 100644
--- a/package.json
+++ b/package.json
@@ -303,7 +303,7 @@
"minItems": 1,
"maxItems": 4,
"uniqueItems": true,
- "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`"
+ "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`"
},
"gitlens.codeLens.customLocationSymbols": {
"type": "array",
@@ -388,7 +388,7 @@
"minItems": 1,
"maxItems": 4,
"uniqueItems": true,
- "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`"
+ "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`"
},
"customSymbols": {
"type": "array",
@@ -450,12 +450,13 @@
},
"gitlens.gitExplorer.view": {
"type": "string",
- "default": "repository",
+ "default": "auto",
"enum": [
+ "auto",
"history",
"repository"
],
- "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"
+ "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"
},
"gitlens.remotes": {
"type": "array",
diff --git a/src/constants.ts b/src/constants.ts
index 9f433be..014e103 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -109,7 +109,12 @@ export const GlyphChars = {
ZeroWidthSpace: '\u200b' as GlyphChars
};
-export type WorkspaceState = 'gitlensVersion';
+export type GlobalState = 'gitlensVersion';
+export const GlobalState = {
+ GitLensVersion: 'gitlensVersion' as GlobalState
+};
+
+export type WorkspaceState = 'gitlens:gitExplorer:view';
export const WorkspaceState = {
- GitLensVersion: 'gitlensVersion' as WorkspaceState
+ GitExplorerView: 'gitlens:gitExplorer:view' as WorkspaceState
};
\ No newline at end of file
diff --git a/src/extension.ts b/src/extension.ts
index ea4a0e8..10282e4 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -16,7 +16,7 @@ import { ShowQuickRepoStatusCommand, ShowQuickStashListCommand } from './command
import { StashApplyCommand, StashDeleteCommand, StashSaveCommand } from './commands';
import { ToggleCodeLensCommand } from './commands';
import { CodeLensLocations, IConfig, LineHighlightLocations } from './configuration';
-import { ApplicationInsightsKey, CommandContext, ExtensionKey, QualifiedExtensionId, setCommandContext, WorkspaceState } from './constants';
+import { ApplicationInsightsKey, CommandContext, ExtensionKey, GlobalState, QualifiedExtensionId, setCommandContext } from './constants';
import { CodeLensController } from './codeLensController';
import { CurrentLineController, LineAnnotationType } from './currentLineController';
import { RemoteProviderFactory } from './git/remotes/factory';
@@ -71,7 +71,7 @@ export async function activate(context: ExtensionContext) {
notifyOnUnsupportedGitVersion(context, gitVersion);
notifyOnNewGitLensVersion(context, gitlensVersion);
- await context.globalState.update(WorkspaceState.GitLensVersion, gitlensVersion);
+ await context.globalState.update(GlobalState.GitLensVersion, gitlensVersion);
const git = new GitService(repoPath);
context.subscriptions.push(git);
@@ -148,7 +148,7 @@ export async function activate(context: ExtensionContext) {
export function deactivate() { }
async function migrateSettings(context: ExtensionContext) {
- const previousVersion = context.globalState.get(WorkspaceState.GitLensVersion);
+ const previousVersion = context.globalState.get(GlobalState.GitLensVersion);
if (previousVersion === undefined) return;
const [major] = previousVersion.split('.');
@@ -274,7 +274,7 @@ async function migrateSettings(context: ExtensionContext) {
async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string) {
if (context.globalState.get(SuppressedKeys.UpdateNotice, false)) return;
- const previousVersion = context.globalState.get(WorkspaceState.GitLensVersion);
+ const previousVersion = context.globalState.get(GlobalState.GitLensVersion);
if (previousVersion === undefined) {
Logger.log(`GitLens first-time install`);
diff --git a/src/views/gitExplorer.ts b/src/views/gitExplorer.ts
index c8314ae..8e83ba0 100644
--- a/src/views/gitExplorer.ts
+++ b/src/views/gitExplorer.ts
@@ -4,16 +4,18 @@ import { commands, Event, EventEmitter, ExtensionContext, TextDocumentShowOption
import { Commands, DiffWithCommandArgs, DiffWithCommandArgsRevision, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands';
import { UriComparer } from '../comparers';
import { ExtensionKey, IConfig } from '../configuration';
-import { CommandContext, setCommandContext } from '../constants';
+import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { BranchHistoryNode, CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoryNode, StashNode } from './explorerNodes';
import { GitService, GitUri, RepoChangedReasons } from '../gitService';
export * from './explorerNodes';
export type GitExplorerView =
+ 'auto' |
'history' |
'repository';
export const GitExplorerView = {
+ Auto: 'auto' as GitExplorerView,
History: 'history' as GitExplorerView,
Repository: 'repository' as GitExplorerView
};
@@ -31,7 +33,7 @@ export class GitExplorer implements TreeDataProvider {
private _config: IConfig;
private _root?: ExplorerNode;
- private _view: GitExplorerView = GitExplorerView.Repository;
+ private _view: GitExplorerView | undefined;
private _onDidChangeTreeData = new EventEmitter();
public get onDidChangeTreeData(): Event {
@@ -62,10 +64,6 @@ export class GitExplorer implements TreeDataProvider {
context.subscriptions.push(workspace.onDidChangeConfiguration(this.onConfigurationChanged, this));
this.onConfigurationChanged();
-
- this._view = this._config.gitExplorer.view;
- setCommandContext(CommandContext.GitExplorerView, this._view);
- this._root = this.getRootNode();
}
async getTreeItem(node: ExplorerNode): Promise {
@@ -116,16 +114,25 @@ export class GitExplorer implements TreeDataProvider {
private onConfigurationChanged() {
const cfg = workspace.getConfiguration().get(ExtensionKey)!;
+ let changed = false;
if (!Objects.areEquivalent(cfg.gitExplorer, this._config && this._config.gitExplorer) ||
!Objects.areEquivalent(cfg.insiders, this._config && this._config.insiders)) {
- setTimeout(() => {
- this._root = this.getRootNode(window.activeTextEditor);
- this.refresh();
- }, 1);
+ changed = true;
}
this._config = cfg;
- }
+
+ if (changed) {
+ let view = cfg.gitExplorer.view;
+ if (view === GitExplorerView.Auto) {
+ view = this.context.workspaceState.get(WorkspaceState.GitExplorerView, GitExplorerView.Repository);
+ }
+
+ this.setView(view);
+ this._root = this.getRootNode(window.activeTextEditor);
+ this.refresh();
+ }
+}
private onRepoChanged(reasons: RepoChangedReasons[]) {
if (this._view !== GitExplorerView.Repository) return;
@@ -149,11 +156,21 @@ export class GitExplorer implements TreeDataProvider {
this.refresh(node);
}
- switchTo(view: GitExplorerView) {
+ setView(view: GitExplorerView) {
if (this._view === view) return;
+ if (this._config.gitExplorer.view === GitExplorerView.Auto) {
+ this.context.workspaceState.update(WorkspaceState.GitExplorerView, view);
+ }
+
this._view = view;
setCommandContext(CommandContext.GitExplorerView, this._view);
+ }
+
+ switchTo(view: GitExplorerView) {
+ if (this._view === view) return;
+
+ this.setView(view);
this._root = this.getRootNode(window.activeTextEditor);
this.refresh();