Skip to content

Commit a2cd57c

Browse files
committed
Fixes #108 - hides stash explorer by default
Adds stash explorer toggle command
1 parent 62a148c commit a2cd57c

File tree

4 files changed

+69
-31
lines changed

4 files changed

+69
-31
lines changed

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,
111111

112112
### Navigate and Explore
113113

114-
- Adds a `Git Stashes` view to the Explorer activity
114+
- Adds a `Git Stashes` explorer to the Explorer activity ([optional](#git-stashes-explorer-settings), off by default)
115115

116-
![Git Stashes view](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-git-stashes.png)
116+
![Git Stashes explorer](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-git-stashes.png)
117117

118118
- Shows all of the stashed changes in the repository
119119
- Provides toolbar buttons to `Stash Changes` and `Refresh`
@@ -289,6 +289,14 @@ GitLens is highly customizable and provides many configuration settings to allow
289289
|`gitlens.codeLens.customLocationSymbols`|Specifies the set of document symbols where Git code lens will be shown in the document
290290
|`gitlens.codeLens.perLanguageLocations`|Specifies where Git code lens will be shown in the document for the specified languages
291291

292+
### Git Stashes Explorer Settings
293+
294+
|Name | Description
295+
|-----|------------
296+
|`gitlens.stashExplorer.enabled`|Specifies whether or not to show the `Git Stashes` explorer
297+
|`gitlens.stashExplorer.stashFormat`|Specifies the format of stashed changes in the `Git Stashes` explorer <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
298+
|`gitlens.stashExplorer.stashFileFormat`|Specifies the format of a stashed file in the `Git Stashes` explorer <br />Available tokens<br /> ${file} - file name<br /> ${path} - file path
299+
292300
### Status Bar Settings
293301

294302
|Name | Description

package.json

+17-12
Original file line numberDiff line numberDiff line change
@@ -407,25 +407,20 @@
407407
"default": null,
408408
"description": "Specifies how all absolute dates will be formatted by default\nSee https://momentjs.com/docs/#/displaying/format/ for valid formats"
409409
},
410-
"gitlens.gitExplorer.commitFormat": {
411-
"type": "string",
412-
"default": "${authorAgo} \u00a0\u2022\u00a0 ${message} \u00a0\u2022\u00a0 ${id}",
413-
"description": "Specifies the format of a commit in the explorer view\nAvailable tokens\n ${id} - commit id\n ${author} - commit author\n ${message} - commit message\n ${ago} - relative commit date (e.g. 1 day ago)\n ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)\n ${authorAgo} - commit author, relative commit date\nSee https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting"
414-
},
415-
"gitlens.gitExplorer.commitFileFormat": {
416-
"type": "string",
417-
"default": "${file} \u00a0\u2022\u00a0 ${path}",
418-
"description": "Specifies the format of a file commit in the explorer view\nAvailable tokens\n ${file} - file name\n ${path} - file path"
410+
"gitlens.stashExplorer.enabled": {
411+
"type": "boolean",
412+
"default": false,
413+
"description": "Specifies whether or not to show the `Git Stashes` explorer"
419414
},
420415
"gitlens.stashExplorer.stashFormat": {
421416
"type": "string",
422417
"default": "${message}",
423-
"description": "Specifies the format of a stash in the explorer view\nAvailable tokens\n ${id} - commit id\n ${author} - commit author\n ${message} - commit message\n ${ago} - relative commit date (e.g. 1 day ago)\n ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)\n ${authorAgo} - commit author, relative commit date\nSee https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting"
418+
"description": "Specifies the format of stashed changes in the `Git Stashes` explorer\nAvailable tokens\n ${id} - commit id\n ${author} - commit author\n ${message} - commit message\n ${ago} - relative commit date (e.g. 1 day ago)\n ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)\n ${authorAgo} - commit author, relative commit date\nSee https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting"
424419
},
425420
"gitlens.stashExplorer.stashFileFormat": {
426421
"type": "string",
427422
"default": "${file} \u00a0\u2022\u00a0 ${path}",
428-
"description": "Specifies the format of a stashed file in the stash explorer view\nAvailable tokens\n ${file} - file name\n ${path} - file path"
423+
"description": "Specifies the format of a stashed file in the `Git Stashes` explorer\nAvailable tokens\n ${file} - file name\n ${path} - file path"
429424
},
430425
"gitlens.statusBar.enabled": {
431426
"type": "boolean",
@@ -998,6 +993,11 @@
998993
"command": "gitlens.stashExplorer.openFileInRemote",
999994
"title": "Open File in Remote",
1000995
"category": "GitLens"
996+
},
997+
{
998+
"command": "gitlens.stashExplorer.toggle",
999+
"title": "Toggle Git Stashes Explorer",
1000+
"category": "GitLens"
10011001
}
10021002
],
10031003
"menus": {
@@ -1146,6 +1146,10 @@
11461146
"command": "gitlens.gitExplorer.refresh",
11471147
"when": "gitlens:enabled"
11481148
},
1149+
{
1150+
"command": "gitlens.stashExplorer.toggle",
1151+
"when": "gitlens:enabled"
1152+
},
11491153
{
11501154
"command": "gitlens.stashExplorer.refresh",
11511155
"when": "gitlens:enabled"
@@ -1511,7 +1515,8 @@
15111515
"explorer": [
15121516
{
15131517
"id": "gitlens.stashExplorer",
1514-
"name": "Git Stashes"
1518+
"name": "Git Stashes",
1519+
"when": "gitlens:enabled && config.gitlens.stashExplorer.enabled"
15151520
}
15161521
]
15171522
}

src/configuration.ts

+2
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,14 @@ export interface IConfig {
304304
defaultDateFormat: string | null;
305305

306306
gitExplorer: {
307+
enabled: boolean;
307308
commitFormat: string;
308309
commitFileFormat: string;
309310
// dateFormat: string | null;
310311
};
311312

312313
stashExplorer: {
314+
enabled: boolean;
313315
stashFormat: string;
314316
stashFileFormat: string;
315317
// dateFormat: string | null;

src/views/stashExplorer.ts

+40-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22
// import { Functions } from '../system';
3-
import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri } from 'vscode';
3+
import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri, workspace } from 'vscode';
44
import { Commands, DiffWithPreviousCommandArgs, openEditor } from '../commands';
5+
import { ExtensionKey, IConfig } from '../configuration';
56
import { ExplorerNode, StashCommitNode, StashNode } from './explorerNodes';
67
import { GitService, GitUri } from '../gitService';
78

@@ -18,18 +19,12 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
1819
}
1920

2021
constructor(private context: ExtensionContext, private git: GitService) {
21-
commands.registerCommand('gitlens.stashExplorer.refresh', () => this.refresh());
22-
commands.registerCommand('gitlens.stashExplorer.openChanges', (node: StashCommitNode) => {
23-
const command = node.getCommand();
24-
if (command === undefined || command.arguments === undefined) return;
25-
26-
const [uri, args] = command.arguments as [Uri, DiffWithPreviousCommandArgs];
27-
args.showOptions!.preview = false;
28-
commands.executeCommand(command.command, uri, args);
29-
});
30-
commands.registerCommand('gitlens.stashExplorer.openFile', (node: StashCommitNode) => openEditor(node.uri, { preserveFocus: true, preview: false }));
31-
commands.registerCommand('gitlens.stashExplorer.openStashedFile', (node: StashCommitNode) => openEditor(GitService.toGitContentUri(node.uri), { preserveFocus: true, preview: false }));
32-
commands.registerCommand('gitlens.stashExplorer.openFileInRemote', (node: StashCommitNode) => commands.executeCommand(Commands.OpenFileInRemote, node.commit.previousUri));
22+
commands.registerCommand('gitlens.stashExplorer.refresh', this.refresh, this);
23+
commands.registerCommand('gitlens.stashExplorer.toggle', this.toggle, this);
24+
commands.registerCommand('gitlens.stashExplorer.openChanges', this.openChanges, this);
25+
commands.registerCommand('gitlens.stashExplorer.openFile', this.openFile, this);
26+
commands.registerCommand('gitlens.stashExplorer.openStashedFile', this.openStashedFile, this);
27+
commands.registerCommand('gitlens.stashExplorer.openFileInRemote', this.openFileInRemote, this);
3328

3429
context.subscriptions.push(this.git.onDidChangeRepo(reasons => {
3530
if (!reasons.includes('stash')) return;
@@ -61,12 +56,40 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
6156
return node.getChildren();
6257
}
6358

64-
update(uri: GitUri) {
65-
this._node = new StashNode(uri, this.context, this.git);
66-
this.refresh();
67-
}
59+
// update(uri: GitUri) {
60+
// this._node = new StashNode(uri, this.context, this.git);
61+
// this.refresh();
62+
// }
6863

6964
refresh() {
65+
if (!this.git.config.stashExplorer.enabled) return;
66+
7067
this._onDidChangeTreeData.fire();
7168
}
69+
70+
private toggle() {
71+
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
72+
workspace.getConfiguration(ExtensionKey).update('stashExplorer.enabled', !cfg.stashExplorer.enabled, true);
73+
}
74+
75+
private openChanges(node: StashCommitNode) {
76+
const command = node.getCommand();
77+
if (command === undefined || command.arguments === undefined) return;
78+
79+
const [uri, args] = command.arguments as [Uri, DiffWithPreviousCommandArgs];
80+
args.showOptions!.preview = false;
81+
return commands.executeCommand(command.command, uri, args);
82+
}
83+
84+
private openFile(node: StashCommitNode) {
85+
return openEditor(node.uri, { preserveFocus: true, preview: false });
86+
}
87+
88+
private openStashedFile(node: StashCommitNode) {
89+
return openEditor(GitService.toGitContentUri(node.uri), { preserveFocus: true, preview: false });
90+
}
91+
92+
private openFileInRemote(node: StashCommitNode) {
93+
return commands.executeCommand(Commands.OpenFileInRemote, node.commit.previousUri);
94+
}
7295
}

0 commit comments

Comments
 (0)