mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-04 09:45:36 -05:00
Fixes #108 - hides stash explorer by default
Adds stash explorer toggle command
This commit is contained in:
12
README.md
12
README.md
@@ -111,9 +111,9 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,
|
|||||||
|
|
||||||
### Navigate and Explore
|
### Navigate and Explore
|
||||||
|
|
||||||
- Adds a `Git Stashes` view to the Explorer activity
|
- Adds a `Git Stashes` explorer to the Explorer activity ([optional](#git-stashes-explorer-settings), off by default)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
- Shows all of the stashed changes in the repository
|
- Shows all of the stashed changes in the repository
|
||||||
- Provides toolbar buttons to `Stash Changes` and `Refresh`
|
- Provides toolbar buttons to `Stash Changes` and `Refresh`
|
||||||
@@ -289,6 +289,14 @@ GitLens is highly customizable and provides many configuration settings to allow
|
|||||||
|`gitlens.codeLens.customLocationSymbols`|Specifies the set of document symbols where Git code lens will be shown in the document
|
|`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
|
|`gitlens.codeLens.perLanguageLocations`|Specifies where Git code lens will be shown in the document for the specified languages
|
||||||
|
|
||||||
|
### Git Stashes Explorer Settings
|
||||||
|
|
||||||
|
|Name | Description
|
||||||
|
|-----|------------
|
||||||
|
|`gitlens.stashExplorer.enabled`|Specifies whether or not to show the `Git Stashes` explorer
|
||||||
|
|`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
|
||||||
|
|`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
|
||||||
|
|
||||||
### Status Bar Settings
|
### Status Bar Settings
|
||||||
|
|
||||||
|Name | Description
|
|Name | Description
|
||||||
|
|||||||
29
package.json
29
package.json
@@ -407,25 +407,20 @@
|
|||||||
"default": null,
|
"default": null,
|
||||||
"description": "Specifies how all absolute dates will be formatted by default\nSee https://momentjs.com/docs/#/displaying/format/ for valid formats"
|
"description": "Specifies how all absolute dates will be formatted by default\nSee https://momentjs.com/docs/#/displaying/format/ for valid formats"
|
||||||
},
|
},
|
||||||
"gitlens.gitExplorer.commitFormat": {
|
"gitlens.stashExplorer.enabled": {
|
||||||
"type": "string",
|
"type": "boolean",
|
||||||
"default": "${authorAgo} \u00a0\u2022\u00a0 ${message} \u00a0\u2022\u00a0 ${id}",
|
"default": false,
|
||||||
"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"
|
"description": "Specifies whether or not to show the `Git Stashes` explorer"
|
||||||
},
|
|
||||||
"gitlens.gitExplorer.commitFileFormat": {
|
|
||||||
"type": "string",
|
|
||||||
"default": "${file} \u00a0\u2022\u00a0 ${path}",
|
|
||||||
"description": "Specifies the format of a file commit in the explorer view\nAvailable tokens\n ${file} - file name\n ${path} - file path"
|
|
||||||
},
|
},
|
||||||
"gitlens.stashExplorer.stashFormat": {
|
"gitlens.stashExplorer.stashFormat": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "${message}",
|
"default": "${message}",
|
||||||
"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"
|
"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"
|
||||||
},
|
},
|
||||||
"gitlens.stashExplorer.stashFileFormat": {
|
"gitlens.stashExplorer.stashFileFormat": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "${file} \u00a0\u2022\u00a0 ${path}",
|
"default": "${file} \u00a0\u2022\u00a0 ${path}",
|
||||||
"description": "Specifies the format of a stashed file in the stash explorer view\nAvailable tokens\n ${file} - file name\n ${path} - file path"
|
"description": "Specifies the format of a stashed file in the `Git Stashes` explorer\nAvailable tokens\n ${file} - file name\n ${path} - file path"
|
||||||
},
|
},
|
||||||
"gitlens.statusBar.enabled": {
|
"gitlens.statusBar.enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@@ -998,6 +993,11 @@
|
|||||||
"command": "gitlens.stashExplorer.openFileInRemote",
|
"command": "gitlens.stashExplorer.openFileInRemote",
|
||||||
"title": "Open File in Remote",
|
"title": "Open File in Remote",
|
||||||
"category": "GitLens"
|
"category": "GitLens"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "gitlens.stashExplorer.toggle",
|
||||||
|
"title": "Toggle Git Stashes Explorer",
|
||||||
|
"category": "GitLens"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"menus": {
|
"menus": {
|
||||||
@@ -1146,6 +1146,10 @@
|
|||||||
"command": "gitlens.gitExplorer.refresh",
|
"command": "gitlens.gitExplorer.refresh",
|
||||||
"when": "gitlens:enabled"
|
"when": "gitlens:enabled"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "gitlens.stashExplorer.toggle",
|
||||||
|
"when": "gitlens:enabled"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "gitlens.stashExplorer.refresh",
|
"command": "gitlens.stashExplorer.refresh",
|
||||||
"when": "gitlens:enabled"
|
"when": "gitlens:enabled"
|
||||||
@@ -1511,7 +1515,8 @@
|
|||||||
"explorer": [
|
"explorer": [
|
||||||
{
|
{
|
||||||
"id": "gitlens.stashExplorer",
|
"id": "gitlens.stashExplorer",
|
||||||
"name": "Git Stashes"
|
"name": "Git Stashes",
|
||||||
|
"when": "gitlens:enabled && config.gitlens.stashExplorer.enabled"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -304,12 +304,14 @@ export interface IConfig {
|
|||||||
defaultDateFormat: string | null;
|
defaultDateFormat: string | null;
|
||||||
|
|
||||||
gitExplorer: {
|
gitExplorer: {
|
||||||
|
enabled: boolean;
|
||||||
commitFormat: string;
|
commitFormat: string;
|
||||||
commitFileFormat: string;
|
commitFileFormat: string;
|
||||||
// dateFormat: string | null;
|
// dateFormat: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
stashExplorer: {
|
stashExplorer: {
|
||||||
|
enabled: boolean;
|
||||||
stashFormat: string;
|
stashFormat: string;
|
||||||
stashFileFormat: string;
|
stashFileFormat: string;
|
||||||
// dateFormat: string | null;
|
// dateFormat: string | null;
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
// import { Functions } from '../system';
|
// import { Functions } from '../system';
|
||||||
import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri } from 'vscode';
|
import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri, workspace } from 'vscode';
|
||||||
import { Commands, DiffWithPreviousCommandArgs, openEditor } from '../commands';
|
import { Commands, DiffWithPreviousCommandArgs, openEditor } from '../commands';
|
||||||
|
import { ExtensionKey, IConfig } from '../configuration';
|
||||||
import { ExplorerNode, StashCommitNode, StashNode } from './explorerNodes';
|
import { ExplorerNode, StashCommitNode, StashNode } from './explorerNodes';
|
||||||
import { GitService, GitUri } from '../gitService';
|
import { GitService, GitUri } from '../gitService';
|
||||||
|
|
||||||
@@ -18,18 +19,12 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(private context: ExtensionContext, private git: GitService) {
|
constructor(private context: ExtensionContext, private git: GitService) {
|
||||||
commands.registerCommand('gitlens.stashExplorer.refresh', () => this.refresh());
|
commands.registerCommand('gitlens.stashExplorer.refresh', this.refresh, this);
|
||||||
commands.registerCommand('gitlens.stashExplorer.openChanges', (node: StashCommitNode) => {
|
commands.registerCommand('gitlens.stashExplorer.toggle', this.toggle, this);
|
||||||
const command = node.getCommand();
|
commands.registerCommand('gitlens.stashExplorer.openChanges', this.openChanges, this);
|
||||||
if (command === undefined || command.arguments === undefined) return;
|
commands.registerCommand('gitlens.stashExplorer.openFile', this.openFile, this);
|
||||||
|
commands.registerCommand('gitlens.stashExplorer.openStashedFile', this.openStashedFile, this);
|
||||||
const [uri, args] = command.arguments as [Uri, DiffWithPreviousCommandArgs];
|
commands.registerCommand('gitlens.stashExplorer.openFileInRemote', this.openFileInRemote, this);
|
||||||
args.showOptions!.preview = false;
|
|
||||||
commands.executeCommand(command.command, uri, args);
|
|
||||||
});
|
|
||||||
commands.registerCommand('gitlens.stashExplorer.openFile', (node: StashCommitNode) => openEditor(node.uri, { preserveFocus: true, preview: false }));
|
|
||||||
commands.registerCommand('gitlens.stashExplorer.openStashedFile', (node: StashCommitNode) => openEditor(GitService.toGitContentUri(node.uri), { preserveFocus: true, preview: false }));
|
|
||||||
commands.registerCommand('gitlens.stashExplorer.openFileInRemote', (node: StashCommitNode) => commands.executeCommand(Commands.OpenFileInRemote, node.commit.previousUri));
|
|
||||||
|
|
||||||
context.subscriptions.push(this.git.onDidChangeRepo(reasons => {
|
context.subscriptions.push(this.git.onDidChangeRepo(reasons => {
|
||||||
if (!reasons.includes('stash')) return;
|
if (!reasons.includes('stash')) return;
|
||||||
@@ -61,12 +56,40 @@ export class StashExplorer implements TreeDataProvider<ExplorerNode> {
|
|||||||
return node.getChildren();
|
return node.getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
update(uri: GitUri) {
|
// update(uri: GitUri) {
|
||||||
this._node = new StashNode(uri, this.context, this.git);
|
// this._node = new StashNode(uri, this.context, this.git);
|
||||||
this.refresh();
|
// this.refresh();
|
||||||
}
|
// }
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
|
if (!this.git.config.stashExplorer.enabled) return;
|
||||||
|
|
||||||
this._onDidChangeTreeData.fire();
|
this._onDidChangeTreeData.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private toggle() {
|
||||||
|
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||||
|
workspace.getConfiguration(ExtensionKey).update('stashExplorer.enabled', !cfg.stashExplorer.enabled, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private openChanges(node: StashCommitNode) {
|
||||||
|
const command = node.getCommand();
|
||||||
|
if (command === undefined || command.arguments === undefined) return;
|
||||||
|
|
||||||
|
const [uri, args] = command.arguments as [Uri, DiffWithPreviousCommandArgs];
|
||||||
|
args.showOptions!.preview = false;
|
||||||
|
return commands.executeCommand(command.command, uri, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private openFile(node: StashCommitNode) {
|
||||||
|
return openEditor(node.uri, { preserveFocus: true, preview: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
private openStashedFile(node: StashCommitNode) {
|
||||||
|
return openEditor(GitService.toGitContentUri(node.uri), { preserveFocus: true, preview: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
private openFileInRemote(node: StashCommitNode) {
|
||||||
|
return commands.executeCommand(Commands.OpenFileInRemote, node.commit.previousUri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user