diff --git a/README.md b/README.md index a0ec12c..1cd93ac 100644 --- a/README.md +++ b/README.md @@ -146,19 +146,16 @@ For more advanced customizations, refer to the [settings documentation](#gitlens ### GitLens Explorer -A [customizable](#gitlens-explorer-settings 'Jump to the GitLens Explorer settings') explorer to navigate and explore repositories or file histories. The _GitLens_ explorer provides two views (modes) — a Repository view and a File History view. - -- A toolbar provides _Search Commits_, _Switch to Repository View_ or _Switch to File History View_, and _Refresh_ commands - - Quickly switch between views using the _Switch to Repository View_ or _Switch to File History View_ commands - - A context menu provides _Automatic Layout_, _List Layout_, _Tree Layout_, _Enable Automatic Refresh_ or _Disable Automatic Refresh_, and _Follow Renames_ or _Don't Follow Renames_ commands - -#### Repository view -

- GitLens Explorer Repository view + GitLens Explorer

-The repository view provides a full Git repository explorer, which has the following features, +A [customizable](#gitlens-explorer-settings 'Jump to the GitLens Explorer settings') explorer to navigate and explore repositories. + +- A toolbar provides _Search Commits_, and _Refresh_ commands + - A context menu provides _Automatic Layout_, _List Layout_, _Tree Layout_, and _Enable Automatic Refresh_ or _Disable Automatic Refresh_ commands + +The explorer provides a full Git repository explorer, which has the following features, - **Repository Status** @@ -223,20 +220,6 @@ The repository view provides a full Git repository explorer, which has the follo - Revisions (commits) expand to show the set of files changed, complete with status indicators for adds, changes, renames, and deletes - See the _Revisions (commits) expand_ section under **Branches** above for more details -### File History view - -

- GitLens Explorer File History view -

- -The file history view provides the revision history of the current file, which has the following features, - -- Automatically updates to track the current editor -- A context menu provides _Open File_, _Open File in Remote_ (if available), and _Refresh_ commands -- An inline toolbar provides an _Open File_ command -- Context menus for each revision (commit) provides - - _Open Changes_, _Open Changes with Working File_, _Open File_, _Open Revision_, _Open File in Remote_ (if available), _Open Revision in Remote_ (if available), _Apply Changes_, _Compare with Selected_ (when available), _Select for Compare_, and _Show Commit File Details_ commands - --- ### GitLens File History Explorer @@ -245,7 +228,12 @@ The file history view provides the revision history of the current file, which h GitLens File History Explorer

-A [customizable](#gitlens-file-history-explorer-settings 'Jump to the GitLens File History Explorer settings') stand-alone explorer to visualize the history of the current file — undocked version of the _GitLens_ Explorer history view +A [customizable](#gitlens-file-history-explorer-settings 'Jump to the GitLens File History Explorer settings') explorer to visualize the revision history of the current file. + +- A toolbar provides a _Refresh_ command + - A context menu provides a _Follow Renames_ or _Don't Follow Renames_ command + +The file history view provides the revision history of the current file, which has the following features, - Automatically updates to track the current editor - A context menu provides _Open File_, _Open File in Remote_ (if available), and _Refresh_ commands @@ -681,14 +669,13 @@ See also [Explorer Settings](#explorer-settings 'Jump to the Explorer settings') | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `gitlens.gitExplorer.autoRefresh` | Specifies whether to automatically refresh the _GitLens_ explorer when the repository or the file system changes | | `gitlens.gitExplorer.branches.layout` | Specifies how the _GitLens_ explorer will display branches
`list` - displays branches as a list
`tree` - displays branches as a tree when branch names contain slashes `/` | -| `gitlens.gitExplorer.enabled` | Specifies whether to show the _GitLens_ explorer" | +| `gitlens.gitExplorer.enabled` | Specifies whether to show the _GitLens_ explorer | | `gitlens.gitExplorer.files.compact` | Specifies whether to compact (flatten) unnecessary file nesting in the _GitLens_ explorer
Only applies when `gitlens.gitExplorer.files.layout` is set to `tree` or `auto` | | `gitlens.gitExplorer.files.layout` | Specifies how the _GitLens_ explorer will display files
`auto` - automatically switches between displaying files as a `tree` or `list` based on the `gitlens.gitExplorer.files.threshold` value and the number of files at each nesting level
`list` - displays files as a list
`tree` - displays files as a tree | | `gitlens.gitExplorer.files.threshold` | Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the _GitLens_ explorer
Only applies when `gitlens.gitExplorer.files.layout` is set to `auto` | | `gitlens.gitExplorer.includeWorkingTree` | Specifies whether to include working tree files inside the `Repository Status` node of the _GitLens_ explorer | | `gitlens.gitExplorer.location` | Specifies where to show the _GitLens_ explorer
`gitlens` - adds to the GitLens view
`explorer` - adds to the Explorer view
`scm` - adds to the Source Control view | -| `gitlens.gitExplorer.showTrackingBranch` | Specifies whether to show the tracking branch when displaying local branches in the _GitLens_ explorer" | -| `gitlens.gitExplorer.view` | Specifies the starting view of the _GitLens_ explorer
`auto` - shows the last selected view, defaults to `repository`
`history` - shows the commit history of the current file
`repository` - shows a repository explorer" | +| `gitlens.gitExplorer.showTrackingBranch` | Specifies whether to show the tracking branch when displaying local branches in the _GitLens_ explorer | ### GitLens File History Explorer Settings diff --git a/package.json b/package.json index ee63b06..4a01455 100644 --- a/package.json +++ b/package.json @@ -555,22 +555,6 @@ "description": "Specifies whether to show the tracking branch when displaying local branches in the `GitLens` explorer", "scope": "window" }, - "gitlens.gitExplorer.view": { - "type": "string", - "default": "auto", - "enum": [ - "auto", - "history", - "repository" - ], - "enumDescriptions": [ - "Shows the last selected view, defaults to `repository`", - "Shows the commit history of the current file", - "Shows a repository explorer" - ], - "description": "Specifies the starting view of the `GitLens` explorer", - "scope": "window" - }, "gitlens.heatmap.ageThreshold": { "type": "string", "default": "90", @@ -1985,15 +1969,6 @@ "category": "GitLens" }, { - "command": "gitlens.gitExplorer.undockHistory", - "title": "Undock File History from GitLens Explorer", - "category": "GitLens", - "icon": { - "dark": "images/dark/icon-undock.svg", - "light": "images/light/icon-undock.svg" - } - }, - { "command": "gitlens.gitExplorer.refresh", "title": "Refresh", "category": "GitLens", @@ -2033,52 +2008,6 @@ "category": "GitLens" }, { - "command": "gitlens.gitExplorer.setRenameFollowingOn", - "title": "Follow Renames", - "category": "GitLens" - }, - { - "command": "gitlens.gitExplorer.setRenameFollowingOff", - "title": "Don't Follow Renames", - "category": "GitLens" - }, - { - "command": "gitlens.gitExplorer.switchToHistoryView", - "title": "Switch to File History View", - "category": "GitLens", - "icon": { - "dark": "images/dark/icon-history.svg", - "light": "images/light/icon-history.svg" - } - }, - { - "command": "gitlens.gitExplorer.switchToRepositoryView", - "title": "Switch to Repository View", - "category": "GitLens", - "icon": { - "dark": "images/dark/icon-repo.svg", - "light": "images/light/icon-repo.svg" - } - }, - { - "command": "gitlens.historyExplorer.close", - "title": "Close", - "category": "GitLens", - "icon": { - "dark": "images/dark/icon-close.svg", - "light": "images/light/icon-close.svg" - } - }, - { - "command": "gitlens.historyExplorer.dock", - "title": "Dock File History to GitLens Explorer", - "category": "GitLens", - "icon": { - "dark": "images/dark/icon-dock.svg", - "light": "images/light/icon-dock.svg" - } - }, - { "command": "gitlens.historyExplorer.refresh", "title": "Refresh", "category": "GitLens", @@ -2560,34 +2489,6 @@ "when": "false" }, { - "command": "gitlens.gitExplorer.setRenameFollowingOn", - "when": "false" - }, - { - "command": "gitlens.gitExplorer.setRenameFollowingOff", - "when": "false" - }, - { - "command": "gitlens.gitExplorer.switchToHistoryView", - "when": "gitlens:enabled && !gitlens:historyExplorer && gitlens:gitExplorer:view == repository" - }, - { - "command": "gitlens.gitExplorer.switchToRepositoryView", - "when": "gitlens:enabled && !gitlens:historyExplorer && gitlens:gitExplorer:view == history" - }, - { - "command": "gitlens.gitExplorer.undockHistory", - "when": "gitlens:enabled && !gitlens:historyExplorer" - }, - { - "command": "gitlens.historyExplorer.close", - "when": "false" - }, - { - "command": "gitlens.historyExplorer.dock", - "when": "gitlens:enabled && gitlens:historyExplorer" - }, - { "command": "gitlens.historyExplorer.refresh", "when": "false" }, @@ -2876,38 +2777,23 @@ "group": "navigation@1" }, { - "command": "gitlens.gitExplorer.undockHistory", - "when": "view =~ /^gitlens.gitExplorer:/ && gitlens:gitExplorer:view == history && !gitlens:historyExplorer", - "group": "navigation@2" - }, - { - "command": "gitlens.gitExplorer.switchToHistoryView", - "when": "view =~ /^gitlens.gitExplorer:/ && !gitlens:historyExplorer && gitlens:gitExplorer:view == repository", - "group": "navigation@3" - }, - { - "command": "gitlens.gitExplorer.switchToRepositoryView", - "when": "view =~ /^gitlens.gitExplorer:/ && !gitlens:historyExplorer && gitlens:gitExplorer:view == history", - "group": "navigation@3" - }, - { "command": "gitlens.gitExplorer.refresh", "when": "view =~ /^gitlens.gitExplorer:/", "group": "navigation@8" }, { "command": "gitlens.gitExplorer.setFilesLayoutToAuto", - "when": "view =~ /^gitlens.gitExplorer:/ && gitlens:gitExplorer:view == repository", + "when": "view =~ /^gitlens.gitExplorer:/", "group": "1_gitlens" }, { "command": "gitlens.gitExplorer.setFilesLayoutToList", - "when": "view =~ /^gitlens.gitExplorer:/ && gitlens:gitExplorer:view == repository", + "when": "view =~ /^gitlens.gitExplorer:/", "group": "1_gitlens" }, { "command": "gitlens.gitExplorer.setFilesLayoutToTree", - "when": "view =~ /^gitlens.gitExplorer:/ && gitlens:gitExplorer:view == repository", + "when": "view =~ /^gitlens.gitExplorer:/", "group": "1_gitlens" }, { @@ -2921,31 +2807,11 @@ "group": "2_gitlens" }, { - "command": "gitlens.gitExplorer.setRenameFollowingOn", - "when": "view =~ /^gitlens.gitExplorer:/ && gitlens:gitExplorer:view == history && !config.gitlens.advanced.fileHistoryFollowsRenames", - "group": "2_gitlens_1" - }, - { - "command": "gitlens.gitExplorer.setRenameFollowingOff", - "when": "view =~ /^gitlens.gitExplorer:/ && gitlens:gitExplorer:view == history && config.gitlens.advanced.fileHistoryFollowsRenames", - "group": "2_gitlens_1" - }, - { "command": "gitlens.historyExplorer.refresh", "when": "view =~ /^gitlens.historyExplorer:/", "group": "navigation@1" }, { - "command": "gitlens.historyExplorer.dock", - "when": "view =~ /^gitlens.historyExplorer:/ && gitlens:gitExplorer", - "group": "navigation@9" - }, - { - "command": "gitlens.historyExplorer.close", - "when": "view =~ /^gitlens.historyExplorer:/ && !gitlens:gitExplorer", - "group": "navigation@9" - }, - { "command": "gitlens.historyExplorer.setRenameFollowingOn", "when": "view =~ /^gitlens.historyExplorer:/ && !config.gitlens.advanced.fileHistoryFollowsRenames", "group": "1_gitlens" @@ -3204,7 +3070,7 @@ }, { "command": "gitlens.showQuickFileHistory", - "when": "viewItem =~ /gitlens:file\\b/ && gitlens:gitExplorer:view == repository", + "when": "viewItem =~ /gitlens:file\\b/", "group": "8_gitlens@1" }, { diff --git a/src/commands/showGitExplorer.ts b/src/commands/showGitExplorer.ts index 6170f11..9f55969 100644 --- a/src/commands/showGitExplorer.ts +++ b/src/commands/showGitExplorer.ts @@ -1,5 +1,4 @@ 'use strict'; -import { GitExplorerView } from '../configuration'; import { Container } from '../container'; import { Command, Commands } from './common'; @@ -9,6 +8,6 @@ export class ShowGitExplorerCommand extends Command { } execute() { - return Container.gitExplorer.show(GitExplorerView.Repository); + return Container.gitExplorer.show(); } } diff --git a/src/commands/showHistoryExplorer.ts b/src/commands/showHistoryExplorer.ts index c9a037c..8bf6968 100644 --- a/src/commands/showHistoryExplorer.ts +++ b/src/commands/showHistoryExplorer.ts @@ -1,5 +1,4 @@ 'use strict'; -import { GitExplorerView } from '../configuration'; import { Container } from '../container'; import { Command, Commands } from './common'; @@ -9,10 +8,6 @@ export class ShowHistoryExplorerCommand extends Command { } execute() { - if (Container.config.historyExplorer.enabled) { - return Container.historyExplorer.show(); - } - - return Container.gitExplorer.show(GitExplorerView.History); + return Container.historyExplorer.show(); } } diff --git a/src/constants.ts b/src/constants.ts index df65e5f..1b199f8 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -32,7 +32,6 @@ export enum CommandContext { ExplorersCanCompare = 'gitlens:explorers:canCompare', GitExplorer = 'gitlens:gitExplorer', GitExplorerAutoRefresh = 'gitlens:gitExplorer:autoRefresh', - GitExplorerView = 'gitlens:gitExplorer:view', HasRemotes = 'gitlens:hasRemotes', HistoryExplorer = 'gitlens:historyExplorer', Key = 'gitlens:key', @@ -124,6 +123,5 @@ export const ImageMimetypes: { [key: string]: string } = { export enum WorkspaceState { GitExplorerAutoRefresh = 'gitlens:gitExplorer:autoRefresh', - GitExplorerView = 'gitlens:gitExplorer:view', ResultsExplorerKeepResults = 'gitlens:resultsExplorer:keepResults' } diff --git a/src/ui/config.ts b/src/ui/config.ts index 97993da..b6a9219 100644 --- a/src/ui/config.ts +++ b/src/ui/config.ts @@ -56,12 +56,6 @@ export enum FileAnnotationType { RecentChanges = 'recentChanges' } -export enum GitExplorerView { - Auto = 'auto', - History = 'history', - Repository = 'repository' -} - export enum GravatarDefaultStyle { Faces = 'wavatar', Geometric = 'identicon', @@ -191,7 +185,6 @@ export interface IGitExplorerConfig { includeWorkingTree: boolean; location: 'explorer' | 'gitlens' | 'scm'; showTrackingBranch: boolean; - view: GitExplorerView; } export interface IHistoryExplorerConfig { diff --git a/src/ui/images/settings/gitlens-explorer-repository-avatars.png b/src/ui/images/settings/gitlens-explorer-avatars.png similarity index 100% rename from src/ui/images/settings/gitlens-explorer-repository-avatars.png rename to src/ui/images/settings/gitlens-explorer-avatars.png diff --git a/src/ui/images/settings/gitlens-explorer-history.png b/src/ui/images/settings/gitlens-explorer-history.png deleted file mode 100644 index 4b42e49..0000000 Binary files a/src/ui/images/settings/gitlens-explorer-history.png and /dev/null differ diff --git a/src/ui/images/settings/gitlens-explorer-repository-history-docked.png b/src/ui/images/settings/gitlens-explorer-repository-history-docked.png deleted file mode 100644 index 57efcb3..0000000 Binary files a/src/ui/images/settings/gitlens-explorer-repository-history-docked.png and /dev/null differ diff --git a/src/ui/images/settings/gitlens-explorer-repository-history-undocked.png b/src/ui/images/settings/gitlens-explorer-repository-history-undocked.png deleted file mode 100644 index 49de22a..0000000 Binary files a/src/ui/images/settings/gitlens-explorer-repository-history-undocked.png and /dev/null differ diff --git a/src/ui/images/settings/gitlens-explorer-repository-tree-compact.png b/src/ui/images/settings/gitlens-explorer-tree-compact.png similarity index 100% rename from src/ui/images/settings/gitlens-explorer-repository-tree-compact.png rename to src/ui/images/settings/gitlens-explorer-tree-compact.png diff --git a/src/ui/images/settings/gitlens-explorer-repository-tree.png b/src/ui/images/settings/gitlens-explorer-tree.png similarity index 100% rename from src/ui/images/settings/gitlens-explorer-repository-tree.png rename to src/ui/images/settings/gitlens-explorer-tree.png diff --git a/src/ui/images/settings/gitlens-explorer-repository.png b/src/ui/images/settings/gitlens-explorer.png similarity index 100% rename from src/ui/images/settings/gitlens-explorer-repository.png rename to src/ui/images/settings/gitlens-explorer.png diff --git a/src/ui/images/settings/gitlens-explorer-history-avatars.png b/src/ui/images/settings/gitlens-file-history-explorer-avatars.png similarity index 100% rename from src/ui/images/settings/gitlens-explorer-history-avatars.png rename to src/ui/images/settings/gitlens-file-history-explorer-avatars.png diff --git a/src/ui/images/settings/gitlens-history-explorer.png b/src/ui/images/settings/gitlens-file-history-explorer.png similarity index 100% rename from src/ui/images/settings/gitlens-history-explorer.png rename to src/ui/images/settings/gitlens-file-history-explorer.png diff --git a/src/ui/images/settings/gitlens-history-explorer-close.png b/src/ui/images/settings/gitlens-history-explorer-close.png deleted file mode 100644 index cc15427..0000000 Binary files a/src/ui/images/settings/gitlens-history-explorer-close.png and /dev/null differ diff --git a/src/ui/settings/index.html b/src/ui/settings/index.html index ef0ab7f..0ef7ef7 100644 --- a/src/ui/settings/index.html +++ b/src/ui/settings/index.html @@ -272,22 +272,6 @@ -
- - - -
- -
@@ -398,16 +361,9 @@
- - - - - -
diff --git a/src/views/explorer.ts b/src/views/explorer.ts new file mode 100644 index 0000000..017a9db --- /dev/null +++ b/src/views/explorer.ts @@ -0,0 +1,96 @@ +'use strict'; +import { + ConfigurationChangeEvent, + Disposable, + Event, + EventEmitter, + TreeDataProvider, + TreeItem, + TreeView +} from 'vscode'; +// import { configuration } from '../configuration'; +// import { Container } from '../container'; +import { Logger } from '../logger'; +import { RefreshNodeCommandArgs } from './explorerCommands'; +import { ExplorerNode, RefreshReason } from './nodes'; + +export abstract class ExplorerBase implements TreeDataProvider, Disposable { + protected _onDidChangeTreeData = new EventEmitter(); + public get onDidChangeTreeData(): Event { + return this._onDidChangeTreeData.event; + } + + protected _disposable: Disposable | undefined; + protected _roots: ExplorerNode[] = []; + protected _tree: TreeView | undefined; + + constructor() { + this.registerCommands(); + } + + dispose() { + this._disposable && this._disposable.dispose(); + } + + abstract get id(): string; + + protected abstract registerCommands(): void; + protected abstract onConfigurationChanged(e: ConfigurationChangeEvent): void; + + abstract getChildren(node?: ExplorerNode): Promise; + getParent(element: ExplorerNode): ExplorerNode | undefined { + return undefined; + } + abstract getTreeItem(node: ExplorerNode): Promise; + + protected getQualifiedCommand(command: string) { + return `gitlens.${this.id}.${command}`; + } + + refresh(reason?: RefreshReason) { + if (reason === undefined) { + reason = RefreshReason.Command; + } + + Logger.log(`Explorer(${this.id}).refresh`, `reason='${reason}'`); + this._onDidChangeTreeData.fire(); + } + + refreshNode(node: ExplorerNode, args?: RefreshNodeCommandArgs) { + Logger.log(`Explorer(${this.id}).refreshNode(${(node as { id?: string }).id || ''})`); + + if (args !== undefined && node.supportsPaging) { + node.maxCount = args.maxCount; + } + node.refresh(); + + // Since a root node won't actually refresh, force everything + this.updateNode(node); + } + + refreshNodes() { + Logger.log(`Explorer(${this.id}).refreshNodes`); + + this._roots.forEach(n => n.refresh()); + this._onDidChangeTreeData.fire(); + } + + async show() { + if (this._tree === undefined || this._roots === undefined || this._roots.length === 0) return; + + try { + await this._tree.reveal(this._roots[0], { select: false }); + } + catch (ex) { + Logger.error(ex); + } + } + + updateNode(node: ExplorerNode | undefined) { + Logger.log(`Explorer(${this.id}).updateNode`); + if (node !== undefined) { + node = this._roots.includes(node) ? undefined : node; + } + this._onDidChangeTreeData.fire(node); + } +} diff --git a/src/views/gitExplorer.ts b/src/views/gitExplorer.ts index 9d4556c..ed4b236 100644 --- a/src/views/gitExplorer.ts +++ b/src/views/gitExplorer.ts @@ -6,27 +6,19 @@ import { Event, EventEmitter, TextDocumentShowOptions, - TextEditor, TreeDataProvider, TreeItem, TreeView, Uri, window } from 'vscode'; -import { - configuration, - ExplorerFilesLayout, - GitExplorerView, - IExplorersConfig, - IGitExplorerConfig -} from '../configuration'; -import { CommandContext, GlyphChars, setCommandContext, WorkspaceState } from '../constants'; +import { configuration, ExplorerFilesLayout, IExplorersConfig, IGitExplorerConfig } from '../configuration'; +import { CommandContext, setCommandContext, WorkspaceState } from '../constants'; import { Container } from '../container'; import { GitUri } from '../git/gitService'; import { Logger } from '../logger'; import { Functions } from '../system'; import { RefreshNodeCommandArgs } from '../views/explorerCommands'; -import { HistoryExplorer } from './historyExplorer'; import { ExplorerNode, MessageNode, RefreshReason, RepositoriesNode, RepositoryNode } from './nodes'; export * from './nodes'; @@ -36,7 +28,7 @@ export interface OpenFileRevisionCommandArgs { showOptions?: TextDocumentShowOptions; } -export class GitExplorer extends Disposable implements TreeDataProvider { +export class GitExplorer implements TreeDataProvider, Disposable { private _disposable: Disposable | undefined; private _root?: ExplorerNode; private _tree: TreeView | undefined; @@ -52,8 +44,6 @@ export class GitExplorer extends Disposable implements TreeDataProvider this.dispose()); - Container.explorerCommands; commands.registerCommand('gitlens.gitExplorer.refresh', this.refresh, this); commands.registerCommand('gitlens.gitExplorer.refreshNode', this.refreshNode, this); @@ -83,34 +73,8 @@ export class GitExplorer extends Disposable implements TreeDataProvider this.setAutoRefresh(Container.config.gitExplorer.autoRefresh, false), this ); - commands.registerCommand( - 'gitlens.gitExplorer.setRenameFollowingOn', - () => HistoryExplorer.setRenameFollowing(true), - this - ); - commands.registerCommand( - 'gitlens.gitExplorer.setRenameFollowingOff', - () => HistoryExplorer.setRenameFollowing(false), - this - ); - commands.registerCommand( - 'gitlens.gitExplorer.switchToHistoryView', - () => this.switchTo(GitExplorerView.History), - this - ); - commands.registerCommand( - 'gitlens.gitExplorer.switchToRepositoryView', - () => this.switchTo(GitExplorerView.Repository), - this - ); - - commands.registerCommand('gitlens.gitExplorer.undockHistory', this.undockHistory, this); - Container.context.subscriptions.push( - window.onDidChangeActiveTextEditor(Functions.debounce(this.onActiveEditorChanged, 500), this), - window.onDidChangeVisibleTextEditors(Functions.debounce(this.onVisibleEditorsChanged, 500), this), - configuration.onDidChange(this.onConfigurationChanged, this) - ); + Container.context.subscriptions.push(configuration.onDidChange(this.onConfigurationChanged, this)); void this.onConfigurationChanged(configuration.initializingChangeEvent); } @@ -125,8 +89,7 @@ export class GitExplorer extends Disposable implements TreeDataProvider( - WorkspaceState.GitExplorerView, - GitExplorerView.Repository - ); - } - } - if (initializing) { - this.view = view; - setCommandContext(CommandContext.GitExplorerView, this.view); - - this.setRoot(await this.getRootNode(window.activeTextEditor)); + this.setRoot(await this.getRootNode()); } if (initializing || configuration.changed(e, configuration.name('gitExplorer')('location').value)) { @@ -181,46 +120,21 @@ export class GitExplorer extends Disposable implements TreeDataProvider e.document && Container.git.isTrackable(e.document.uri))) { - this.clearRoot(); - - void this.refresh(RefreshReason.VisibleEditorsChanged); - } - } - get autoRefresh() { return ( this.config.autoRefresh && @@ -232,14 +146,6 @@ export class GitExplorer extends Disposable implements TreeDataProvider { - switch (this.view) { - case GitExplorerView.History: { - const promise = this.getHistoryNode(editor || window.activeTextEditor); - this._loading = promise.then(_ => Functions.wait(0)); - return promise; - } - default: { - const promise = Container.git.getRepositories(); - this._loading = promise.then(_ => Functions.wait(0)); - - const repositories = [...(await promise)]; - if (repositories.length === 0) return undefined; + private async getRootNode(): Promise { + const promise = Container.git.getRepositories(); + this._loading = promise.then(_ => Functions.wait(0)); - const openedRepos = repositories.filter(r => !r.closed); - if (openedRepos.length === 0) return undefined; + const repositories = [...(await promise)]; + if (repositories.length === 0) return undefined; - if (openedRepos.length === 1) { - const repo = openedRepos[0]; - return new RepositoryNode(GitUri.fromRepoPath(repo.path), repo, this, true); - } + const openedRepos = repositories.filter(r => !r.closed); + if (openedRepos.length === 0) return undefined; - return new RepositoriesNode(openedRepos, this); - } + if (openedRepos.length === 1) { + const repo = openedRepos[0]; + return new RepositoryNode(GitUri.fromRepoPath(repo.path), repo, this, true); } - } - private getHistoryNode(editor: TextEditor | undefined): Promise { - return HistoryExplorer.getHistoryNode(this, editor, this._root); + return new RepositoriesNode(openedRepos, this); } private setFilesLayout(layout: ExplorerFilesLayout) { @@ -448,8 +294,4 @@ export class GitExplorer extends Disposable implements TreeDataProvider { +export class HistoryExplorer implements TreeDataProvider, Disposable { private _disposable: Disposable | undefined; private _root?: ExplorerNode; private _tree: TreeView | undefined; @@ -36,22 +36,18 @@ export class HistoryExplorer extends Disposable implements TreeDataProvider this.dispose()); - Container.explorerCommands; commands.registerCommand('gitlens.historyExplorer.refresh', this.refresh, this); commands.registerCommand('gitlens.historyExplorer.refreshNode', this.refreshNode, this); - commands.registerCommand('gitlens.historyExplorer.close', () => this.dock(false), this); - commands.registerCommand('gitlens.historyExplorer.dock', this.dock, this); commands.registerCommand( 'gitlens.historyExplorer.setRenameFollowingOn', - () => HistoryExplorer.setRenameFollowing(true), + () => this.setRenameFollowing(true), this ); commands.registerCommand( 'gitlens.historyExplorer.setRenameFollowingOff', - () => HistoryExplorer.setRenameFollowing(false), + () => this.setRenameFollowing(false), this ); @@ -88,15 +84,6 @@ export class HistoryExplorer extends Disposable implements TreeDataProvider { - return HistoryExplorer.getHistoryNode(this, editor, this._root); - } - - private setRoot(root: ExplorerNode | undefined): boolean { - if (this._root === root) return false; - - if (this._root !== undefined) { - this._root.dispose(); - } - - this._root = root; - return true; - } - - static async getHistoryNode( - explorer: Explorer, - editor: TextEditor | undefined, - root: ExplorerNode | undefined - ): Promise { + private async getRootNode(editor: TextEditor | undefined): Promise { // If we have no active editor, or no visible editors, or no trackable visible editors reset the view if ( editor == null || @@ -256,7 +202,7 @@ export class HistoryExplorer extends Disposable implements TreeDataProvider