diff --git a/CHANGELOG.md b/CHANGELOG.md index 24bf30b..08611bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] ### Added -- Adds a tree layout option to tags in the *GitLens* explorer — closes [#358](https://github.com/eamodio/vscode-gitlens/issues/358) - Adds an icon for the *Compare File with Previous Revision* command (`gitlens.diffWithPrevious`) and moves it into the editor toolbar - Adds an icon for the *Compare File with Next Revision* command (`gitlens.diffWithNext`) and moves it into the editor toolbar +- Adds *Show GitLens Explorer* (`gitlens.showGitExplorer`) command — shows/expands the *GitLens* explorer +- Adds *Show History Explorer* (`gitlens.showHistoryExplorer`) command — shows/expands the *GitLens History* explorer +- Adds *Show Results Explorer* (`gitlens.showResultsExplorer`) command — shows/expands the *GitLens Results* explorer +- Adds a tree layout option to tags in the *GitLens* explorer — closes [#358](https://github.com/eamodio/vscode-gitlens/issues/358) ### Changed - Moves the *GitLens* explorer, *GitLens History* explorer, and *GitLens Results* explorer under the Source Control activity (in the sidebar) 🎉 — closes [#213](https://github.com/eamodio/vscode-gitlens/issues/213) +- Showing results in the *GitLens Results* explorer now properly shows the explorer first - Renames *Compare Line Revision with Previous* command (`gitlens.diffLineWithPrevious`) to *Compare Commit with Previous* for consistency with other commands - Renames *Compare Line Revision with Working File* command (`gitlens.diffLineWithWorking`) to *Compare Commit with Working File* for consistency with other commands - Renames *Show Commit File Details* command (`gitlens.showQuickCommitFileDetails`) to *Show Commit Details* for consistency with other commands diff --git a/package.json b/package.json index 4cfc1c6..1cfe544 100644 --- a/package.json +++ b/package.json @@ -958,7 +958,6 @@ "suppressGitVersionWarning": false, "suppressLineUncommittedWarning": false, "suppressNoRepositoryWarning": false, - "suppressResultsExplorerNotice": false, "suppressShowKeyBindingsNotice": false }, "properties": { @@ -990,10 +989,6 @@ "type": "boolean", "default": false }, - "suppressResultsExplorerNotice": { - "type": "boolean", - "default": false - }, "suppressShowKeyBindingsNotice": { "type": "boolean", "default": false @@ -1099,6 +1094,21 @@ "category": "GitLens" }, { + "command": "gitlens.showGitExplorer", + "title": "Show GitLens Explorer", + "category": "GitLens" + }, + { + "command": "gitlens.showHistoryExplorer", + "title": "Show History Explorer", + "category": "GitLens" + }, + { + "command": "gitlens.showResultsExplorer", + "title": "Show Results Explorer", + "category": "GitLens" + }, + { "command": "gitlens.diffDirectory", "title": "Directory Compare Working Tree with...", "category": "GitLens" @@ -1246,16 +1256,6 @@ "category": "GitLens" }, { - "command": "gitlens.showGitLensExplorer", - "title": "Show GitLens Explorer", - "category": "GitLens" - }, - { - "command": "gitlens.showHistoryExplorer", - "title": "Show History Explorer", - "category": "GitLens" - }, - { "command": "gitlens.showQuickFileHistory", "title": "Show File History", "category": "GitLens" @@ -1738,6 +1738,22 @@ "menus": { "commandPalette": [ { + "command": "gitlens.showGitExplorer", + "when": "gitlens:enabled && gitlens:gitExplorer" + }, + { + "command": "gitlens.showHistoryExplorer", + "when": "gitlens:enabled && gitlens:historyExplorer" + }, + { + "command": "gitlens.showHistoryExplorer", + "when": "gitlens:enabled && !gitlens:historyExplorer && gitlens:gitExplorer" + }, + { + "command": "gitlens.showResultsExplorer", + "when": "gitlens:enabled && gitlens:resultsExplorer" + }, + { "command": "gitlens.diffDirectory", "when": "gitlens:enabled" }, @@ -1822,11 +1838,11 @@ "when": "gitlens:enabled && gitlens:canToggleCodeLens" }, { - "command": "gitlens.showLastQuickPick", + "command": "gitlens.showCommitSearch", "when": "gitlens:enabled" }, { - "command": "gitlens.showCommitSearch", + "command": "gitlens.showLastQuickPick", "when": "gitlens:enabled" }, { diff --git a/src/commands.ts b/src/commands.ts index e771f6b..f517844 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,97 +1,103 @@ -'use strict'; -import { CommandContext, setCommandContext } from './constants'; -import { Container } from './container'; - -export * from './commands/common'; - -export * from './commands/clearFileAnnotations'; -export * from './commands/closeUnchangedFiles'; -export * from './commands/copyMessageToClipboard'; -export * from './commands/copyShaToClipboard'; -export * from './commands/diffBranchWithBranch'; -export * from './commands/diffDirectory'; -export * from './commands/diffLineWithPrevious'; -export * from './commands/diffLineWithWorking'; -export * from './commands/diffWith'; -export * from './commands/diffWithBranch'; -export * from './commands/diffWithNext'; -export * from './commands/diffWithPrevious'; -export * from './commands/diffWithRevision'; -export * from './commands/diffWithWorking'; -export * from './commands/externalDiff'; -export * from './commands/openChangedFiles'; -export * from './commands/openBranchesInRemote'; -export * from './commands/openBranchInRemote'; -export * from './commands/openCommitInRemote'; -export * from './commands/openFileInRemote'; -export * from './commands/openFileRevision'; -export * from './commands/openInRemote'; -export * from './commands/openRepoInRemote'; -export * from './commands/openWorkingFile'; -export * from './commands/resetSuppressedWarnings'; -export * from './commands/showCommitSearch'; -export * from './commands/showLastQuickPick'; -export * from './commands/showQuickBranchHistory'; -export * from './commands/showQuickCommitDetails'; -export * from './commands/showQuickCommitFileDetails'; -export * from './commands/showQuickCurrentBranchHistory'; -export * from './commands/showQuickFileHistory'; -export * from './commands/showQuickRepoStatus'; -export * from './commands/showQuickStashList'; -export * from './commands/stashApply'; -export * from './commands/stashDelete'; -export * from './commands/stashSave'; -export * from './commands/toggleCodeLens'; -export * from './commands/toggleFileBlame'; -export * from './commands/toggleFileHeatmap'; -export * from './commands/toggleFileRecentChanges'; -export * from './commands/toggleLineBlame'; - -import * as Commands from './commands'; - -export function configureCommands(): void { - setCommandContext(CommandContext.KeyMap, Container.config.keymap); - - Container.context.subscriptions.push(new Commands.CloseUnchangedFilesCommand()); - Container.context.subscriptions.push(new Commands.OpenChangedFilesCommand()); - Container.context.subscriptions.push(new Commands.ExternalDiffCommand()); - Container.context.subscriptions.push(new Commands.CopyMessageToClipboardCommand()); - Container.context.subscriptions.push(new Commands.CopyShaToClipboardCommand()); - Container.context.subscriptions.push(new Commands.DiffBranchWithBranchCommand()); - Container.context.subscriptions.push(new Commands.DiffDirectoryCommand()); - Container.context.subscriptions.push(new Commands.DiffLineWithPreviousCommand()); - Container.context.subscriptions.push(new Commands.DiffLineWithWorkingCommand()); - Container.context.subscriptions.push(new Commands.DiffWithCommand()); - Container.context.subscriptions.push(new Commands.DiffWithBranchCommand()); - Container.context.subscriptions.push(new Commands.DiffWithNextCommand()); - Container.context.subscriptions.push(new Commands.DiffWithPreviousCommand()); - Container.context.subscriptions.push(new Commands.DiffWithRevisionCommand()); - Container.context.subscriptions.push(new Commands.DiffWithWorkingCommand()); - Container.context.subscriptions.push(new Commands.OpenBranchesInRemoteCommand()); - Container.context.subscriptions.push(new Commands.OpenBranchInRemoteCommand()); - Container.context.subscriptions.push(new Commands.OpenCommitInRemoteCommand()); - Container.context.subscriptions.push(new Commands.OpenFileInRemoteCommand()); - Container.context.subscriptions.push(new Commands.OpenFileRevisionCommand()); - Container.context.subscriptions.push(new Commands.OpenInRemoteCommand()); - Container.context.subscriptions.push(new Commands.OpenRepoInRemoteCommand()); - Container.context.subscriptions.push(new Commands.OpenWorkingFileCommand()); - Container.context.subscriptions.push(new Commands.ClearFileAnnotationsCommand()); - Container.context.subscriptions.push(new Commands.ToggleFileBlameCommand()); - Container.context.subscriptions.push(new Commands.ToggleFileHeatmapCommand()); - Container.context.subscriptions.push(new Commands.ToggleFileRecentChangesCommand()); - Container.context.subscriptions.push(new Commands.ToggleLineBlameCommand()); - Container.context.subscriptions.push(new Commands.ResetSuppressedWarningsCommand()); - Container.context.subscriptions.push(new Commands.ShowLastQuickPickCommand()); - Container.context.subscriptions.push(new Commands.ShowQuickBranchHistoryCommand()); - Container.context.subscriptions.push(new Commands.ShowQuickCurrentBranchHistoryCommand()); - Container.context.subscriptions.push(new Commands.ShowQuickCommitDetailsCommand()); - Container.context.subscriptions.push(new Commands.ShowQuickCommitFileDetailsCommand()); - Container.context.subscriptions.push(new Commands.ShowCommitSearchCommand()); - Container.context.subscriptions.push(new Commands.ShowQuickFileHistoryCommand()); - Container.context.subscriptions.push(new Commands.ShowQuickRepoStatusCommand()); - Container.context.subscriptions.push(new Commands.ShowQuickStashListCommand()); - Container.context.subscriptions.push(new Commands.StashApplyCommand()); - Container.context.subscriptions.push(new Commands.StashDeleteCommand()); - Container.context.subscriptions.push(new Commands.StashSaveCommand()); - Container.context.subscriptions.push(new Commands.ToggleCodeLensCommand()); +'use strict'; +import { CommandContext, setCommandContext } from './constants'; +import { Container } from './container'; + +export * from './commands/common'; + +export * from './commands/clearFileAnnotations'; +export * from './commands/closeUnchangedFiles'; +export * from './commands/copyMessageToClipboard'; +export * from './commands/copyShaToClipboard'; +export * from './commands/diffBranchWithBranch'; +export * from './commands/diffDirectory'; +export * from './commands/diffLineWithPrevious'; +export * from './commands/diffLineWithWorking'; +export * from './commands/diffWith'; +export * from './commands/diffWithBranch'; +export * from './commands/diffWithNext'; +export * from './commands/diffWithPrevious'; +export * from './commands/diffWithRevision'; +export * from './commands/diffWithWorking'; +export * from './commands/externalDiff'; +export * from './commands/openBranchesInRemote'; +export * from './commands/openBranchInRemote'; +export * from './commands/openChangedFiles'; +export * from './commands/openCommitInRemote'; +export * from './commands/openFileInRemote'; +export * from './commands/openFileRevision'; +export * from './commands/openInRemote'; +export * from './commands/openRepoInRemote'; +export * from './commands/openWorkingFile'; +export * from './commands/resetSuppressedWarnings'; +export * from './commands/showCommitSearch'; +export * from './commands/showGitExplorer'; +export * from './commands/showHistoryExplorer'; +export * from './commands/showLastQuickPick'; +export * from './commands/showQuickBranchHistory'; +export * from './commands/showQuickCommitDetails'; +export * from './commands/showQuickCommitFileDetails'; +export * from './commands/showQuickCurrentBranchHistory'; +export * from './commands/showQuickFileHistory'; +export * from './commands/showQuickRepoStatus'; +export * from './commands/showQuickStashList'; +export * from './commands/showResultsExplorer'; +export * from './commands/stashApply'; +export * from './commands/stashDelete'; +export * from './commands/stashSave'; +export * from './commands/toggleCodeLens'; +export * from './commands/toggleFileBlame'; +export * from './commands/toggleFileHeatmap'; +export * from './commands/toggleFileRecentChanges'; +export * from './commands/toggleLineBlame'; + +import * as Commands from './commands'; + +export function configureCommands(): void { + setCommandContext(CommandContext.KeyMap, Container.config.keymap); + + Container.context.subscriptions.push(new Commands.ClearFileAnnotationsCommand()); + Container.context.subscriptions.push(new Commands.CloseUnchangedFilesCommand()); + Container.context.subscriptions.push(new Commands.CopyMessageToClipboardCommand()); + Container.context.subscriptions.push(new Commands.CopyShaToClipboardCommand()); + Container.context.subscriptions.push(new Commands.DiffBranchWithBranchCommand()); + Container.context.subscriptions.push(new Commands.DiffDirectoryCommand()); + Container.context.subscriptions.push(new Commands.DiffLineWithPreviousCommand()); + Container.context.subscriptions.push(new Commands.DiffLineWithWorkingCommand()); + Container.context.subscriptions.push(new Commands.DiffWithCommand()); + Container.context.subscriptions.push(new Commands.DiffWithBranchCommand()); + Container.context.subscriptions.push(new Commands.DiffWithNextCommand()); + Container.context.subscriptions.push(new Commands.DiffWithPreviousCommand()); + Container.context.subscriptions.push(new Commands.DiffWithRevisionCommand()); + Container.context.subscriptions.push(new Commands.DiffWithWorkingCommand()); + Container.context.subscriptions.push(new Commands.ExternalDiffCommand()); + Container.context.subscriptions.push(new Commands.OpenBranchesInRemoteCommand()); + Container.context.subscriptions.push(new Commands.OpenBranchInRemoteCommand()); + Container.context.subscriptions.push(new Commands.OpenChangedFilesCommand()); + Container.context.subscriptions.push(new Commands.OpenCommitInRemoteCommand()); + Container.context.subscriptions.push(new Commands.OpenFileInRemoteCommand()); + Container.context.subscriptions.push(new Commands.OpenFileRevisionCommand()); + Container.context.subscriptions.push(new Commands.OpenInRemoteCommand()); + Container.context.subscriptions.push(new Commands.OpenRepoInRemoteCommand()); + Container.context.subscriptions.push(new Commands.OpenWorkingFileCommand()); + Container.context.subscriptions.push(new Commands.ResetSuppressedWarningsCommand()); + Container.context.subscriptions.push(new Commands.ShowCommitSearchCommand()); + Container.context.subscriptions.push(new Commands.ShowGitExplorerCommand()); + Container.context.subscriptions.push(new Commands.ShowHistoryExplorerCommand()); + Container.context.subscriptions.push(new Commands.ShowLastQuickPickCommand()); + Container.context.subscriptions.push(new Commands.ShowQuickBranchHistoryCommand()); + Container.context.subscriptions.push(new Commands.ShowQuickCommitDetailsCommand()); + Container.context.subscriptions.push(new Commands.ShowQuickCommitFileDetailsCommand()); + Container.context.subscriptions.push(new Commands.ShowQuickCurrentBranchHistoryCommand()); + Container.context.subscriptions.push(new Commands.ShowQuickFileHistoryCommand()); + Container.context.subscriptions.push(new Commands.ShowQuickRepoStatusCommand()); + Container.context.subscriptions.push(new Commands.ShowQuickStashListCommand()); + Container.context.subscriptions.push(new Commands.ShowResultsExplorerCommand()); + Container.context.subscriptions.push(new Commands.StashApplyCommand()); + Container.context.subscriptions.push(new Commands.StashDeleteCommand()); + Container.context.subscriptions.push(new Commands.StashSaveCommand()); + Container.context.subscriptions.push(new Commands.ToggleCodeLensCommand()); + Container.context.subscriptions.push(new Commands.ToggleFileBlameCommand()); + Container.context.subscriptions.push(new Commands.ToggleFileHeatmapCommand()); + Container.context.subscriptions.push(new Commands.ToggleFileRecentChangesCommand()); + Container.context.subscriptions.push(new Commands.ToggleLineBlameCommand()); } \ No newline at end of file diff --git a/src/commands/common.ts b/src/commands/common.ts index fb1d929..5df23d2 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -41,6 +41,8 @@ export enum Commands { OpenWorkingFile = 'gitlens.openWorkingFile', ResetSuppressedWarnings = 'gitlens.resetSuppressedWarnings', ShowCommitSearch = 'gitlens.showCommitSearch', + ShowGitExplorer = 'gitlens.showGitExplorer', + ShowHistoryExplorer = 'gitlens.showHistoryExplorer', ShowLastQuickPick = 'gitlens.showLastQuickPick', ShowQuickCommitDetails = 'gitlens.showQuickCommitDetails', ShowQuickCommitFileDetails = 'gitlens.showQuickCommitFileDetails', @@ -49,6 +51,7 @@ export enum Commands { ShowQuickCurrentBranchHistory = 'gitlens.showQuickRepoHistory', ShowQuickRepoStatus = 'gitlens.showQuickRepoStatus', ShowQuickStashList = 'gitlens.showQuickStashList', + ShowResultsExplorer = 'gitlens.showResultsExplorer', ShowSettingsPage = 'gitlens.showSettingsPage', ShowWelcomePage = 'gitlens.showWelcomePage', StashApply = 'gitlens.stashApply', diff --git a/src/commands/showGitExplorer.ts b/src/commands/showGitExplorer.ts new file mode 100644 index 0000000..329c7de --- /dev/null +++ b/src/commands/showGitExplorer.ts @@ -0,0 +1,15 @@ +'use strict'; +import { Command, Commands } from './common'; +import { GitExplorerView } from '../configuration'; +import { Container } from '../container'; + +export class ShowGitExplorerCommand extends Command { + + constructor() { + super(Commands.ShowGitExplorer); + } + + execute() { + return Container.gitExplorer.show(GitExplorerView.Repository); + } +} \ No newline at end of file diff --git a/src/commands/showHistoryExplorer.ts b/src/commands/showHistoryExplorer.ts new file mode 100644 index 0000000..05db549 --- /dev/null +++ b/src/commands/showHistoryExplorer.ts @@ -0,0 +1,19 @@ +'use strict'; +import { Command, Commands } from './common'; +import { GitExplorerView } from '../configuration'; +import { Container } from '../container'; + +export class ShowHistoryExplorerCommand extends Command { + + constructor() { + super(Commands.ShowHistoryExplorer); + } + + execute() { + if (Container.config.historyExplorer.enabled) { + return Container.historyExplorer.show(); + } + + return Container.gitExplorer.show(GitExplorerView.History); + } +} \ No newline at end of file diff --git a/src/commands/showResultsExplorer.ts b/src/commands/showResultsExplorer.ts new file mode 100644 index 0000000..9e3b16d --- /dev/null +++ b/src/commands/showResultsExplorer.ts @@ -0,0 +1,14 @@ +'use strict'; +import { Command, Commands } from './common'; +import { Container } from '../container'; + +export class ShowResultsExplorerCommand extends Command { + + constructor() { + super(Commands.ShowResultsExplorer); + } + + execute() { + return Container.resultsExplorer.show(); + } +} \ No newline at end of file diff --git a/src/commands/toggleCodeLens.ts b/src/commands/toggleCodeLens.ts index 583704a..de825ac 100644 --- a/src/commands/toggleCodeLens.ts +++ b/src/commands/toggleCodeLens.ts @@ -1,14 +1,14 @@ -'use strict'; -import { Command, Commands } from './common'; -import { Container } from '../container'; - -export class ToggleCodeLensCommand extends Command { - - constructor() { - super(Commands.ToggleCodeLens); - } - - execute() { - return Container.codeLens.toggleCodeLens(); - } -} \ No newline at end of file +'use strict'; +import { Command, Commands } from './common'; +import { Container } from '../container'; + +export class ToggleCodeLensCommand extends Command { + + constructor() { + super(Commands.ToggleCodeLens); + } + + execute() { + return Container.codeLens.toggleCodeLens(); + } +} diff --git a/src/messages.ts b/src/messages.ts index 9c1a2ed..2f77c8c 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -13,7 +13,6 @@ export enum SuppressedMessages { GitVersionWarning = 'suppressGitVersionWarning', LineUncommittedWarning = 'suppressLineUncommittedWarning', NoRepositoryWarning = 'suppressNoRepositoryWarning', - ResultsExplorerNotice = 'suppressResultsExplorerNotice', ShowKeyBindingsNotice = 'suppressShowKeyBindingsNotice' } @@ -83,10 +82,6 @@ export class Messages { return Messages.showMessage('warn', `${message}. No repository could be found.`, SuppressedMessages.NoRepositoryWarning); } - static showResultExplorerInfoMessage(): Promise { - return Messages.showMessage('info', `If you can't find your results, click on "GITLENS RESULTS" at the bottom of the Explorer view.`, SuppressedMessages.ResultsExplorerNotice, null); - } - private static async showMessage(type: 'info' | 'warn' | 'error', message: string, suppressionKey: SuppressedMessages, dontShowAgain: T | null = { title: 'Don\'t Show Again' } as T, ...actions: T[]): Promise { Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain})`); diff --git a/src/ui/config.ts b/src/ui/config.ts index a0681ce..8e3ecb8 100644 --- a/src/ui/config.ts +++ b/src/ui/config.ts @@ -124,7 +124,6 @@ export interface IAdvancedConfig { suppressGitVersionWarning: boolean; suppressLineUncommittedWarning: boolean; suppressNoRepositoryWarning: boolean; - suppressResultsExplorerNotice: boolean; suppressShowKeyBindingsNotice: boolean; }; diff --git a/src/views/commitResultsNode.ts b/src/views/commitResultsNode.ts index fba8e99..2895bc7 100644 --- a/src/views/commitResultsNode.ts +++ b/src/views/commitResultsNode.ts @@ -1,32 +1,32 @@ -'use strict'; -import { Strings } from '../system'; -import { TreeItem, TreeItemCollapsibleState } from 'vscode'; -import { CommitNode } from './commitNode'; -import { GlyphChars } from '../constants'; -import { Container } from '../container'; -import { Explorer, ExplorerNode, MessageNode, ResourceType } from './explorerNode'; -import { CommitFormatter, GitLogCommit } from '../gitService'; - -export class CommitResultsNode extends ExplorerNode { - - constructor( - readonly commit: GitLogCommit, - private readonly explorer: Explorer, - private readonly contextValue: ResourceType = ResourceType.Results - ) { - super(commit.toGitUri()); - } - - async getChildren(): Promise { - const children = await new CommitNode(this.commit, this.explorer).getChildren(); - children.splice(0, 0, new MessageNode(CommitFormatter.fromTemplate('${message}', this.commit, { truncateMessageAtNewLine: true }), CommitFormatter.fromTemplate('${message}', this.commit))); - return children; - } - - async getTreeItem(): Promise { - const label = CommitFormatter.fromTemplate(`Commit \${sha} ${Strings.pad(GlyphChars.Dash, 1, 1)} \${authorAgo}`, this.commit, Container.config.defaultDateFormat); - const item = new TreeItem(label, TreeItemCollapsibleState.Expanded); - item.contextValue = this.contextValue; - return item; - } +'use strict'; +import { Strings } from '../system'; +import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { CommitNode } from './commitNode'; +import { GlyphChars } from '../constants'; +import { Container } from '../container'; +import { Explorer, ExplorerNode, MessageNode, ResourceType } from './explorerNode'; +import { CommitFormatter, GitLogCommit } from '../gitService'; + +export class CommitResultsNode extends ExplorerNode { + + constructor( + public readonly commit: GitLogCommit, + private readonly explorer: Explorer, + private readonly contextValue: ResourceType = ResourceType.Results + ) { + super(commit.toGitUri()); + } + + async getChildren(): Promise { + const children = await new CommitNode(this.commit, this.explorer).getChildren(); + children.splice(0, 0, new MessageNode(CommitFormatter.fromTemplate('${message}', this.commit, { truncateMessageAtNewLine: true }), CommitFormatter.fromTemplate('${message}', this.commit))); + return children; + } + + async getTreeItem(): Promise { + const label = CommitFormatter.fromTemplate(`Commit \${sha} ${Strings.pad(GlyphChars.Dash, 1, 1)} \${authorAgo}`, this.commit, Container.config.defaultDateFormat); + const item = new TreeItem(label, TreeItemCollapsibleState.Expanded); + item.contextValue = this.contextValue; + return item; + } } \ No newline at end of file diff --git a/src/views/commitsNode.ts b/src/views/commitsNode.ts index faffce4..8a62a43 100644 --- a/src/views/commitsNode.ts +++ b/src/views/commitsNode.ts @@ -1,36 +1,36 @@ -'use strict'; -import { Iterables } from '../system'; -import { TreeItem, TreeItemCollapsibleState } from 'vscode'; -import { CommitNode } from './commitNode'; -import { Explorer, ExplorerNode, ResourceType, ShowAllNode } from './explorerNode'; -import { GitLog, GitUri } from '../gitService'; - -export class CommitsNode extends ExplorerNode { - - readonly supportsPaging: boolean = true; - - constructor( - readonly repoPath: string, - private readonly logFn: (maxCount: number | undefined) => Promise, - private readonly explorer: Explorer - ) { - super(GitUri.fromRepoPath(repoPath)); - } - - async getChildren(): Promise { - const log = await this.logFn(this.maxCount); - if (log === undefined) return []; - - const children: (CommitNode | ShowAllNode)[] = [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.explorer))]; - if (log.truncated) { - children.push(new ShowAllNode('Show All Commits', this, this.explorer)); - } - return children; - } - - async getTreeItem(): Promise { - const item = new TreeItem('Commits', TreeItemCollapsibleState.Collapsed); - item.contextValue = ResourceType.Commits; - return item; - } -} +'use strict'; +import { Iterables } from '../system'; +import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { CommitNode } from './commitNode'; +import { Explorer, ExplorerNode, ResourceType, ShowAllNode } from './explorerNode'; +import { GitLog, GitUri } from '../gitService'; + +export class CommitsNode extends ExplorerNode { + + readonly supportsPaging: boolean = true; + + constructor( + public readonly repoPath: string, + private readonly logFn: (maxCount: number | undefined) => Promise, + private readonly explorer: Explorer + ) { + super(GitUri.fromRepoPath(repoPath)); + } + + async getChildren(): Promise { + const log = await this.logFn(this.maxCount); + if (log === undefined) return []; + + const children: (CommitNode | ShowAllNode)[] = [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.explorer))]; + if (log.truncated) { + children.push(new ShowAllNode('Show All Commits', this, this.explorer)); + } + return children; + } + + async getTreeItem(): Promise { + const item = new TreeItem('Commits', TreeItemCollapsibleState.Collapsed); + item.contextValue = ResourceType.Commits; + return item; + } +} diff --git a/src/views/commitsResultsNode.ts b/src/views/commitsResultsNode.ts index e868493..55340f2 100644 --- a/src/views/commitsResultsNode.ts +++ b/src/views/commitsResultsNode.ts @@ -1,69 +1,69 @@ -'use strict'; -import { Iterables } from '../system'; -import { TreeItem, TreeItemCollapsibleState } from 'vscode'; -import { CommitNode } from './commitNode'; -import { Explorer, ExplorerNode, ResourceType, ShowAllNode } from './explorerNode'; -import { GitLog, GitUri } from '../gitService'; - -export class CommitsResultsNode extends ExplorerNode { - - readonly supportsPaging: boolean = true; - - private _cache: { label: string, log: GitLog | undefined } | undefined; - - constructor( - readonly repoPath: string, - private readonly labelFn: (log: GitLog | undefined) => Promise, - private readonly logFn: (maxCount: number | undefined) => Promise, - private readonly explorer: Explorer, - private readonly contextValue: ResourceType = ResourceType.ResultsCommits - ) { - super(GitUri.fromRepoPath(repoPath)); - } - - async getChildren(): Promise { - const log = await this.getLog(); - if (log === undefined) return []; - - const children: (CommitNode | ShowAllNode)[] = [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.explorer))]; - if (log.truncated) { - children.push(new ShowAllNode('Show All Results', this, this.explorer)); - } - return children; - } - - async getTreeItem(): Promise { - const log = await this.getLog(); - - const item = new TreeItem(await this.getLabel(), log && log.count > 0 ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None); - item.contextValue = this.contextValue; - return item; - } - - refresh() { - this._cache = undefined; - } - - private async ensureCache() { - if (this._cache === undefined) { - const log = await this.logFn(this.maxCount); - - this._cache = { - label: await this.labelFn(log), - log: log - }; - } - - return this._cache; - } - - private async getLabel() { - const cache = await this.ensureCache(); - return cache.label; - } - - private async getLog() { - const cache = await this.ensureCache(); - return cache.log; - } +'use strict'; +import { Iterables } from '../system'; +import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { CommitNode } from './commitNode'; +import { Explorer, ExplorerNode, ResourceType, ShowAllNode } from './explorerNode'; +import { GitLog, GitUri } from '../gitService'; + +export class CommitsResultsNode extends ExplorerNode { + + readonly supportsPaging: boolean = true; + + private _cache: { label: string, log: GitLog | undefined } | undefined; + + constructor( + public readonly repoPath: string, + private readonly labelFn: (log: GitLog | undefined) => Promise, + private readonly logFn: (maxCount: number | undefined) => Promise, + private readonly explorer: Explorer, + private readonly contextValue: ResourceType = ResourceType.ResultsCommits + ) { + super(GitUri.fromRepoPath(repoPath)); + } + + async getChildren(): Promise { + const log = await this.getLog(); + if (log === undefined) return []; + + const children: (CommitNode | ShowAllNode)[] = [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.explorer))]; + if (log.truncated) { + children.push(new ShowAllNode('Show All Results', this, this.explorer)); + } + return children; + } + + async getTreeItem(): Promise { + const log = await this.getLog(); + + const item = new TreeItem(await this.getLabel(), log && log.count > 0 ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None); + item.contextValue = this.contextValue; + return item; + } + + refresh() { + this._cache = undefined; + } + + private async ensureCache() { + if (this._cache === undefined) { + const log = await this.logFn(this.maxCount); + + this._cache = { + label: await this.labelFn(log), + log: log + }; + } + + return this._cache; + } + + private async getLabel() { + const cache = await this.ensureCache(); + return cache.label; + } + + private async getLog() { + const cache = await this.ensureCache(); + return cache.log; + } } \ No newline at end of file diff --git a/src/views/gitExplorer.ts b/src/views/gitExplorer.ts index 46619f7..87e40ce 100644 --- a/src/views/gitExplorer.ts +++ b/src/views/gitExplorer.ts @@ -1,6 +1,6 @@ 'use strict'; import { Functions } from '../system'; -import { commands, ConfigurationChangeEvent, ConfigurationTarget, Disposable, Event, EventEmitter, TextDocumentShowOptions, TextEditor, TreeDataProvider, TreeItem, Uri, window } from 'vscode'; +import { commands, ConfigurationChangeEvent, ConfigurationTarget, Disposable, Event, EventEmitter, TextDocumentShowOptions, TextEditor, TreeDataProvider, TreeItem, TreeView, Uri, window } from 'vscode'; import { UriComparer } from '../comparers'; import { configuration, ExplorerFilesLayout, GitExplorerView, IExplorersConfig, IGitExplorerConfig } from '../configuration'; import { CommandContext, GlyphChars, setCommandContext, WorkspaceState } from '../constants'; @@ -21,6 +21,7 @@ export class GitExplorer extends Disposable implements TreeDataProvider | undefined; private _onDidChangeAutoRefresh = new EventEmitter(); public get onDidChangeAutoRefresh(): Event { @@ -103,7 +104,8 @@ export class GitExplorer extends Disposable implements TreeDataProvider | undefined; async getChildren(node?: ExplorerNode): Promise { @@ -196,6 +202,8 @@ export class GitExplorer extends Disposable implements TreeDataProvider | undefined; private _onDidChangeTreeData = new EventEmitter(); public get onDidChangeTreeData(): Event { @@ -70,7 +71,8 @@ export class HistoryExplorer extends Disposable implements TreeDataProvider { if (this._root === undefined) return [new MessageNode(`No active file ${GlyphChars.Dash} no history to show`)]; @@ -146,6 +152,17 @@ export class HistoryExplorer extends Disposable implements TreeDataProvider { - this.resetChildren(); - - this.children = this.repositories - .sort((a, b) => a.index - b.index) - .map(repo => new RepositoryNode(GitUri.fromRepoPath(repo.path), repo, this.explorer)); - - if (this.children.length > 1) { - this.children.splice(0, 0, new ActiveRepositoryNode(this.explorer)); - } - - return this.children; - } - - getTreeItem(): TreeItem { - const item = new TreeItem(`Repositories`, TreeItemCollapsibleState.Expanded); - item.contextValue = ResourceType.Repositories; - return item; - } +'use strict'; +import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { ActiveRepositoryNode } from './activeRepositoryNode'; +import { ExplorerNode, ResourceType } from './explorerNode'; +import { GitExplorer } from './gitExplorer'; +import { GitUri, Repository } from '../gitService'; +import { RepositoryNode } from './repositoryNode'; + +export class RepositoriesNode extends ExplorerNode { + + constructor( + private readonly repositories: Repository[], + private readonly explorer: GitExplorer + ) { + super(undefined!); + } + + async getChildren(): Promise { + if (this.children === undefined) { + this.children = this.repositories + .sort((a, b) => a.index - b.index) + .map(repo => new RepositoryNode(GitUri.fromRepoPath(repo.path), repo, this.explorer)); + + if (this.children.length > 1) { + this.children.splice(0, 0, new ActiveRepositoryNode(this.explorer)); + } + } + + return this.children; + } + + refresh() { + this.resetChildren(); + } + + getTreeItem(): TreeItem { + const item = new TreeItem(`Repositories`, TreeItemCollapsibleState.Expanded); + item.contextValue = ResourceType.Repositories; + return item; + } } \ No newline at end of file diff --git a/src/views/repositoryNode.ts b/src/views/repositoryNode.ts index 7124bce..d736457 100644 --- a/src/views/repositoryNode.ts +++ b/src/views/repositoryNode.ts @@ -16,7 +16,7 @@ export class RepositoryNode extends ExplorerNode { constructor( uri: GitUri, - readonly repo: Repository, + public readonly repo: Repository, private readonly explorer: GitExplorer, private readonly active: boolean = false, private readonly activeParent?: ExplorerNode @@ -29,16 +29,17 @@ export class RepositoryNode extends ExplorerNode { } async getChildren(): Promise { - this.resetChildren(); - this.updateSubscription(); - - this.children = [ - new StatusNode(this.uri, this.repo, this.explorer, this.active), - new BranchesNode(this.uri, this.repo, this.explorer, this.active), - new RemotesNode(this.uri, this.repo, this.explorer, this.active), - new StashesNode(this.uri, this.repo, this.explorer, this.active), - new TagsNode(this.uri, this.repo, this.explorer, this.active) - ]; + if (this.children === undefined) { + this.updateSubscription(); + + this.children = [ + new StatusNode(this.uri, this.repo, this.explorer, this.active), + new BranchesNode(this.uri, this.repo, this.explorer, this.active), + new RemotesNode(this.uri, this.repo, this.explorer, this.active), + new StashesNode(this.uri, this.repo, this.explorer, this.active), + new TagsNode(this.uri, this.repo, this.explorer, this.active) + ]; + } return this.children; } @@ -55,6 +56,11 @@ export class RepositoryNode extends ExplorerNode { return item; } + refresh() { + this.resetChildren(); + this.updateSubscription(); + } + private updateSubscription() { // We only need to subscribe if auto-refresh is enabled, because if it becomes enabled we will be refreshed if (this.explorer.autoRefresh) { diff --git a/src/views/resultsExplorer.ts b/src/views/resultsExplorer.ts index 22ef4f7..d844990 100644 --- a/src/views/resultsExplorer.ts +++ b/src/views/resultsExplorer.ts @@ -1,6 +1,6 @@ 'use strict'; import { Functions, Strings } from '../system'; -import { commands, ConfigurationChangeEvent, ConfigurationTarget, Disposable, Event, EventEmitter, TreeDataProvider, TreeItem, window } from 'vscode'; +import { commands, ConfigurationChangeEvent, ConfigurationTarget, Disposable, Event, EventEmitter, TreeDataProvider, TreeItem, TreeView, window } from 'vscode'; import { configuration, ExplorerFilesLayout, IExplorersConfig, IResultsExplorerConfig } from '../configuration'; import { CommandContext, GlyphChars, setCommandContext, WorkspaceState } from '../constants'; import { Container } from '../container'; @@ -8,7 +8,7 @@ import { RefreshNodeCommandArgs } from './explorerCommands'; import { CommitResultsNode, CommitsResultsNode, ComparisonResultsNode, ExplorerNode, MessageNode, NamedRef, RefreshReason, ResourceType } from './explorerNodes'; import { GitLog, GitLogCommit } from '../gitService'; import { Logger } from '../logger'; -import { Messages } from '../messages'; +// import { Messages } from '../messages'; export * from './explorerNodes'; @@ -16,6 +16,7 @@ export class ResultsExplorer extends Disposable implements TreeDataProvider | undefined; private _onDidChangeTreeData = new EventEmitter(); public get onDidChangeTreeData(): Event { @@ -63,7 +64,8 @@ export class ResultsExplorer extends Disposable implements TreeDataProvider { if (this._roots.length === 0) return [new MessageNode('No results')]; @@ -125,14 +131,23 @@ export class ResultsExplorer extends Disposable implements TreeDataProvider this._tree!.reveal(results, { select: true }), 250); } - private addResults(results: ExplorerNode): boolean { - if (this._roots.includes(results)) return false; + private addResults(results: ExplorerNode): ExplorerNode { + if (this._roots.includes(results)) return results; if (this._roots.length > 0 && !this.keepResults) { this.clearResults(); @@ -179,7 +193,7 @@ export class ResultsExplorer extends Disposable implements TreeDataProvider { - const diff = await this.getDiff(); - if (diff === undefined) return []; - - let children: IFileExplorerNode[] = [...Iterables.map(diff, s => new StatusFileNode(this.repoPath, s, this.ref1, this.ref2, this.explorer))]; - - if (this.explorer.config.files.layout !== ExplorerFilesLayout.List) { - const hierarchy = Arrays.makeHierarchical(children, n => n.uri.getRelativePath().split('/'), - (...paths: string[]) => Strings.normalizePath(path.join(...paths)), this.explorer.config.files.compact); - - const root = new FolderNode(this.repoPath, '', undefined, hierarchy, this.explorer); - children = await root.getChildren() as IFileExplorerNode[]; - } - else { - children.sort((a, b) => (a.priority ? -1 : 1) - (b.priority ? -1 : 1) || a.label!.localeCompare(b.label!)); - } - - return children; - } - - async getTreeItem(): Promise { - const diff = await this.getDiff(); - - const item = new TreeItem(await this.getLabel(), diff && diff.length > 0 ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None); - item.contextValue = ResourceType.ResultsFiles; - return item; - } - - refresh() { - this._cache = undefined; - } - - private async ensureCache() { - if (this._cache === undefined) { - const diff = await Container.git.getDiffStatus(this.uri.repoPath!, this.ref1, this.ref2); - - const count = diff !== undefined ? diff.length : 0; - const label = `${count === 0 ? 'No' : count} ${count === 1 ? 'file' : 'files'} changed`; - - this._cache = { - label: label, - diff: diff - }; - } - - return this._cache; - } - - private async getDiff() { - const cache = await this.ensureCache(); - return cache.diff; - } - - private async getLabel() { - const cache = await this.ensureCache(); - return cache.label; - } +'use strict'; +import { Arrays, Iterables, Strings } from '../system'; +import { TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { ExplorerFilesLayout } from '../configuration'; +import { Container } from '../container'; +import { Explorer, ExplorerNode, ResourceType } from './explorerNode'; +import { FolderNode, IFileExplorerNode } from './folderNode'; +import { GitStatusFile, GitUri } from '../gitService'; +import { StatusFileNode } from './statusFileNode'; +import * as path from 'path'; + +export class StatusFilesResultsNode extends ExplorerNode { + + readonly supportsPaging: boolean = true; + + private _cache: { label: string, diff: GitStatusFile[] | undefined } | undefined; + + constructor( + public readonly repoPath: string, + private readonly ref1: string, + private readonly ref2: string, + private readonly explorer: Explorer + ) { + super(GitUri.fromRepoPath(repoPath)); + } + + async getChildren(): Promise { + const diff = await this.getDiff(); + if (diff === undefined) return []; + + let children: IFileExplorerNode[] = [...Iterables.map(diff, s => new StatusFileNode(this.repoPath, s, this.ref1, this.ref2, this.explorer))]; + + if (this.explorer.config.files.layout !== ExplorerFilesLayout.List) { + const hierarchy = Arrays.makeHierarchical(children, n => n.uri.getRelativePath().split('/'), + (...paths: string[]) => Strings.normalizePath(path.join(...paths)), this.explorer.config.files.compact); + + const root = new FolderNode(this.repoPath, '', undefined, hierarchy, this.explorer); + children = await root.getChildren() as IFileExplorerNode[]; + } + else { + children.sort((a, b) => (a.priority ? -1 : 1) - (b.priority ? -1 : 1) || a.label!.localeCompare(b.label!)); + } + + return children; + } + + async getTreeItem(): Promise { + const diff = await this.getDiff(); + + const item = new TreeItem(await this.getLabel(), diff && diff.length > 0 ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None); + item.contextValue = ResourceType.ResultsFiles; + return item; + } + + refresh() { + this._cache = undefined; + } + + private async ensureCache() { + if (this._cache === undefined) { + const diff = await Container.git.getDiffStatus(this.uri.repoPath!, this.ref1, this.ref2); + + const count = diff !== undefined ? diff.length : 0; + const label = `${count === 0 ? 'No' : count} ${count === 1 ? 'file' : 'files'} changed`; + + this._cache = { + label: label, + diff: diff + }; + } + + return this._cache; + } + + private async getDiff() { + const cache = await this.ensureCache(); + return cache.diff; + } + + private async getLabel() { + const cache = await this.ensureCache(); + return cache.label; + } } \ No newline at end of file