Parcourir la source

Fixes #108 - hides stash explorer by default

Adds stash explorer toggle command
main
Eric Amodio il y a 7 ans
Parent
révision
a2cd57cf95
4 fichiers modifiés avec 69 ajouts et 31 suppressions
  1. +10
    -2
      README.md
  2. +17
    -12
      package.json
  3. +2
    -0
      src/configuration.ts
  4. +40
    -17
      src/views/stashExplorer.ts

+ 10
- 2
README.md Voir le fichier

@ -111,9 +111,9 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,
### 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)
![Git Stashes view](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-git-stashes.png)
![Git Stashes explorer](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-git-stashes.png)
- Shows all of the stashed changes in the repository
- 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.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
|Name | Description

+ 17
- 12
package.json Voir le fichier

@ -407,25 +407,20 @@
"default": null,
"description": "Specifies how all absolute dates will be formatted by default\nSee https://momentjs.com/docs/#/displaying/format/ for valid formats"
},
"gitlens.gitExplorer.commitFormat": {
"type": "string",
"default": "${authorAgo} \u00a0\u2022\u00a0 ${message} \u00a0\u2022\u00a0 ${id}",
"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"
},
"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.enabled": {
"type": "boolean",
"default": false,
"description": "Specifies whether or not to show the `Git Stashes` explorer"
},
"gitlens.stashExplorer.stashFormat": {
"type": "string",
"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": {
"type": "string",
"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": {
"type": "boolean",
@ -998,6 +993,11 @@
"command": "gitlens.stashExplorer.openFileInRemote",
"title": "Open File in Remote",
"category": "GitLens"
},
{
"command": "gitlens.stashExplorer.toggle",
"title": "Toggle Git Stashes Explorer",
"category": "GitLens"
}
],
"menus": {
@ -1147,6 +1147,10 @@
"when": "gitlens:enabled"
},
{
"command": "gitlens.stashExplorer.toggle",
"when": "gitlens:enabled"
},
{
"command": "gitlens.stashExplorer.refresh",
"when": "gitlens:enabled"
},
@ -1511,7 +1515,8 @@
"explorer": [
{
"id": "gitlens.stashExplorer",
"name": "Git Stashes"
"name": "Git Stashes",
"when": "gitlens:enabled && config.gitlens.stashExplorer.enabled"
}
]
}

+ 2
- 0
src/configuration.ts Voir le fichier

@ -304,12 +304,14 @@ export interface IConfig {
defaultDateFormat: string | null;
gitExplorer: {
enabled: boolean;
commitFormat: string;
commitFileFormat: string;
// dateFormat: string | null;
};
stashExplorer: {
enabled: boolean;
stashFormat: string;
stashFileFormat: string;
// dateFormat: string | null;

+ 40
- 17
src/views/stashExplorer.ts Voir le fichier

@ -1,7 +1,8 @@
'use strict';
// 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 { ExtensionKey, IConfig } from '../configuration';
import { ExplorerNode, StashCommitNode, StashNode } from './explorerNodes';
import { GitService, GitUri } from '../gitService';
@ -18,18 +19,12 @@ export class StashExplorer implements TreeDataProvider {
}
constructor(private context: ExtensionContext, private git: GitService) {
commands.registerCommand('gitlens.stashExplorer.refresh', () => this.refresh());
commands.registerCommand('gitlens.stashExplorer.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;
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));
commands.registerCommand('gitlens.stashExplorer.refresh', this.refresh, this);
commands.registerCommand('gitlens.stashExplorer.toggle', this.toggle, this);
commands.registerCommand('gitlens.stashExplorer.openChanges', this.openChanges, this);
commands.registerCommand('gitlens.stashExplorer.openFile', this.openFile, this);
commands.registerCommand('gitlens.stashExplorer.openStashedFile', this.openStashedFile, this);
commands.registerCommand('gitlens.stashExplorer.openFileInRemote', this.openFileInRemote, this);
context.subscriptions.push(this.git.onDidChangeRepo(reasons => {
if (!reasons.includes('stash')) return;
@ -61,12 +56,40 @@ export class StashExplorer implements TreeDataProvider {
return node.getChildren();
}
update(uri: GitUri) {
this._node = new StashNode(uri, this.context, this.git);
this.refresh();
}
// update(uri: GitUri) {
// this._node = new StashNode(uri, this.context, this.git);
// this.refresh();
// }
refresh() {
if (!this.git.config.stashExplorer.enabled) return;
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);
}
}

Chargement…
Annuler
Enregistrer