From a2cd57cf95bc369b1ff47e52abaf906ef2dece78 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 3 Jul 2017 09:39:38 -0400 Subject: [PATCH] Fixes #108 - hides stash explorer by default Adds stash explorer toggle command --- README.md | 12 ++++++++-- package.json | 29 +++++++++++++---------- src/configuration.ts | 2 ++ src/views/stashExplorer.ts | 57 ++++++++++++++++++++++++++++++++-------------- 4 files changed, 69 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index f4057d2..31933b0 100644 --- a/README.md +++ b/README.md @@ -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
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.stashExplorer.stashFileFormat`|Specifies the format of a stashed file in the `Git Stashes` explorer
Available tokens
${file} - file name
${path} - file path + ### Status Bar Settings |Name | Description diff --git a/package.json b/package.json index 2e5b5ee..70762fc 100644 --- a/package.json +++ b/package.json @@ -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" } ] } diff --git a/src/configuration.ts b/src/configuration.ts index 33b6eac..f4cc20b 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -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; diff --git a/src/views/stashExplorer.ts b/src/views/stashExplorer.ts index 5b1c017..e086db6 100644 --- a/src/views/stashExplorer.ts +++ b/src/views/stashExplorer.ts @@ -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(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); + } } \ No newline at end of file