diff --git a/src/views/branchesView.ts b/src/views/branchesView.ts index 252bfc53335b2..3698377d18a04 100644 --- a/src/views/branchesView.ts +++ b/src/views/branchesView.ts @@ -3,6 +3,7 @@ import { CancellationToken, commands, ConfigurationChangeEvent, + Disposable, ProgressLocation, TreeItem, TreeItemCollapsibleState, @@ -149,69 +150,79 @@ export class BranchesView extends ViewBase return new BranchesViewNode(this); } - protected registerCommands() { + protected registerCommands(): Disposable[] { void Container.viewCommands; - commands.registerCommand( - this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('refresh'), - async () => { - await Container.git.resetCaches('branches'); - return this.refresh(true); - }, - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setLayoutToList'), - () => this.setLayout(ViewBranchesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setLayoutToTree'), - () => this.setLayout(ViewBranchesLayout.Tree), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToAuto'), - () => this.setFilesLayout(ViewFilesLayout.Auto), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToList'), - () => this.setFilesLayout(ViewFilesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToTree'), - () => this.setFilesLayout(ViewFilesLayout.Tree), - this, - ); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchComparisonOn'), - () => this.setShowBranchComparison(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchComparisonOff'), - () => this.setShowBranchComparison(false), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchPullRequestOn'), - () => this.setShowBranchPullRequest(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchPullRequestOff'), - () => this.setShowBranchPullRequest(false), - this, - ); + return [ + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('branches'); + return this.refresh(true); + }, + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setLayoutToList'), + () => this.setLayout(ViewBranchesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setLayoutToTree'), + () => this.setLayout(ViewBranchesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToAuto'), + () => this.setFilesLayout(ViewFilesLayout.Auto), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToList'), + () => this.setFilesLayout(ViewFilesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToTree'), + () => this.setFilesLayout(ViewFilesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOn'), + () => this.setShowAvatars(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOff'), + () => this.setShowAvatars(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchComparisonOn'), + () => this.setShowBranchComparison(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchComparisonOff'), + () => this.setShowBranchComparison(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchPullRequestOn'), + () => this.setShowBranchPullRequest(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchPullRequestOff'), + () => this.setShowBranchPullRequest(false), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index b69d4040f49b0..5dc3f942e6143 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -218,69 +218,79 @@ export class CommitsView extends ViewBase { return new CommitsViewNode(this); } - protected registerCommands() { + protected registerCommands(): Disposable[] { void Container.viewCommands; - commands.registerCommand( - this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('refresh'), - async () => { - await Container.git.resetCaches('branches', 'status', 'tags'); - return this.refresh(true); - }, - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToAuto'), - () => this.setFilesLayout(ViewFilesLayout.Auto), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToList'), - () => this.setFilesLayout(ViewFilesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToTree'), - () => this.setFilesLayout(ViewFilesLayout.Tree), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setMyCommitsOnlyOn'), - () => this.setMyCommitsOnly(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setMyCommitsOnlyOff'), - () => this.setMyCommitsOnly(false), - this, - ); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchComparisonOn'), - () => this.setShowBranchComparison(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchComparisonOff'), - () => this.setShowBranchComparison(false), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchPullRequestOn'), - () => this.setShowBranchPullRequest(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchPullRequestOff'), - () => this.setShowBranchPullRequest(false), - this, - ); + return [ + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('branches', 'status', 'tags'); + return this.refresh(true); + }, + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToAuto'), + () => this.setFilesLayout(ViewFilesLayout.Auto), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToList'), + () => this.setFilesLayout(ViewFilesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToTree'), + () => this.setFilesLayout(ViewFilesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setMyCommitsOnlyOn'), + () => this.setMyCommitsOnly(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setMyCommitsOnlyOff'), + () => this.setMyCommitsOnly(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOn'), + () => this.setShowAvatars(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOff'), + () => this.setShowAvatars(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchComparisonOn'), + () => this.setShowBranchComparison(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchComparisonOff'), + () => this.setShowBranchComparison(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchPullRequestOn'), + () => this.setShowBranchPullRequest(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchPullRequestOff'), + () => this.setShowBranchPullRequest(false), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/contributorsView.ts b/src/views/contributorsView.ts index b0c9a3f682dc5..859d4f39251c3 100644 --- a/src/views/contributorsView.ts +++ b/src/views/contributorsView.ts @@ -140,62 +140,72 @@ export class ContributorsView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('refresh'), - async () => { - await Container.git.resetCaches('contributors'); - return this.refresh(true); - }, - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToAuto'), - () => this.setFilesLayout(ViewFilesLayout.Auto), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToList'), - () => this.setFilesLayout(ViewFilesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToTree'), - () => this.setFilesLayout(ViewFilesLayout.Tree), - this, - ); - - commands.registerCommand( - this.getQualifiedCommand('setShowAllBranchesOn'), - () => this.setShowAllBranches(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowAllBranchesOff'), - () => this.setShowAllBranches(false), - this, - ); - - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); - - commands.registerCommand( - this.getQualifiedCommand('setShowStatisticsOn'), - () => this.setShowStatistics(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowStatisticsOff'), - () => this.setShowStatistics(false), - this, - ); + return [ + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('contributors'); + return this.refresh(true); + }, + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToAuto'), + () => this.setFilesLayout(ViewFilesLayout.Auto), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToList'), + () => this.setFilesLayout(ViewFilesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToTree'), + () => this.setFilesLayout(ViewFilesLayout.Tree), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowAllBranchesOn'), + () => this.setShowAllBranches(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAllBranchesOff'), + () => this.setShowAllBranches(false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOn'), + () => this.setShowAvatars(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOff'), + () => this.setShowAvatars(false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowStatisticsOn'), + () => this.setShowStatistics(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowStatisticsOff'), + () => this.setShowStatistics(false), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/fileHistoryView.ts b/src/views/fileHistoryView.ts index 7be8788cf471d..f3356455d9338 100644 --- a/src/views/fileHistoryView.ts +++ b/src/views/fileHistoryView.ts @@ -1,5 +1,5 @@ 'use strict'; -import { commands, ConfigurationChangeEvent } from 'vscode'; +import { commands, ConfigurationChangeEvent, Disposable } from 'vscode'; import { configuration, FileHistoryViewConfig } from '../configuration'; import { ContextKeys, setContext } from '../constants'; import { Container } from '../container'; @@ -30,58 +30,68 @@ export class FileHistoryView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); - commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this); - commands.registerCommand( - this.getQualifiedCommand('setCursorFollowingOn'), - () => this.setCursorFollowing(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setCursorFollowingOff'), - () => this.setCursorFollowing(false), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setEditorFollowingOn'), - () => this.setEditorFollowing(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setEditorFollowingOff'), - () => this.setEditorFollowing(false), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setRenameFollowingOn'), - () => this.setRenameFollowing(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setRenameFollowingOff'), - () => this.setRenameFollowing(false), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowAllBranchesOn'), - () => this.setShowAllBranches(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowAllBranchesOff'), - () => this.setShowAllBranches(false), - this, - ); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); + return [ + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this), + commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this), + commands.registerCommand( + this.getQualifiedCommand('setCursorFollowingOn'), + () => this.setCursorFollowing(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setCursorFollowingOff'), + () => this.setCursorFollowing(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setEditorFollowingOn'), + () => this.setEditorFollowing(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setEditorFollowingOff'), + () => this.setEditorFollowing(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setRenameFollowingOn'), + () => this.setRenameFollowing(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setRenameFollowingOff'), + () => this.setRenameFollowing(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAllBranchesOn'), + () => this.setShowAllBranches(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAllBranchesOff'), + () => this.setShowAllBranches(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOn'), + () => this.setShowAvatars(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOff'), + () => this.setShowAvatars(false), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/lineHistoryView.ts b/src/views/lineHistoryView.ts index 7499024b4cff6..397084d10cc9f 100644 --- a/src/views/lineHistoryView.ts +++ b/src/views/lineHistoryView.ts @@ -1,5 +1,5 @@ 'use strict'; -import { commands, ConfigurationChangeEvent } from 'vscode'; +import { commands, ConfigurationChangeEvent, Disposable } from 'vscode'; import { configuration, LineHistoryViewConfig } from '../configuration'; import { ContextKeys, setContext } from '../constants'; import { Container } from '../container'; @@ -25,28 +25,38 @@ export class LineHistoryView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); - commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this); - commands.registerCommand( - this.getQualifiedCommand('setEditorFollowingOn'), - () => this.setEditorFollowing(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setEditorFollowingOff'), - () => this.setEditorFollowing(false), - this, - ); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); + return [ + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this), + commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this), + commands.registerCommand( + this.getQualifiedCommand('setEditorFollowingOn'), + () => this.setEditorFollowing(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setEditorFollowingOff'), + () => this.setEditorFollowing(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOn'), + () => this.setShowAvatars(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOff'), + () => this.setShowAvatars(false), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/remotesView.ts b/src/views/remotesView.ts index cee2708dadbee..70d2ba9fcffd1 100644 --- a/src/views/remotesView.ts +++ b/src/views/remotesView.ts @@ -3,6 +3,7 @@ import { CancellationToken, commands, ConfigurationChangeEvent, + Disposable, ProgressLocation, TreeItem, TreeItemCollapsibleState, @@ -143,59 +144,69 @@ export class RemotesView extends ViewBase { return new RemotesViewNode(this); } - protected registerCommands() { + protected registerCommands(): Disposable[] { void Container.viewCommands; - commands.registerCommand( - this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('refresh'), - async () => { - await Container.git.resetCaches('branches', 'remotes'); - return this.refresh(true); - }, - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setLayoutToList'), - () => this.setLayout(ViewBranchesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setLayoutToTree'), - () => this.setLayout(ViewBranchesLayout.Tree), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToAuto'), - () => this.setFilesLayout(ViewFilesLayout.Auto), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToList'), - () => this.setFilesLayout(ViewFilesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToTree'), - () => this.setFilesLayout(ViewFilesLayout.Tree), - this, - ); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchPullRequestOn'), - () => this.setShowBranchPullRequest(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchPullRequestOff'), - () => this.setShowBranchPullRequest(false), - this, - ); + return [ + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('branches', 'remotes'); + return this.refresh(true); + }, + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setLayoutToList'), + () => this.setLayout(ViewBranchesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setLayoutToTree'), + () => this.setLayout(ViewBranchesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToAuto'), + () => this.setFilesLayout(ViewFilesLayout.Auto), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToList'), + () => this.setFilesLayout(ViewFilesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToTree'), + () => this.setFilesLayout(ViewFilesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOn'), + () => this.setShowAvatars(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOff'), + () => this.setShowAvatars(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchPullRequestOn'), + () => this.setShowBranchPullRequest(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchPullRequestOff'), + () => this.setShowBranchPullRequest(false), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/repositoriesView.ts b/src/views/repositoriesView.ts index 66fb46f612678..5b7324a9fecd6 100644 --- a/src/views/repositoriesView.ts +++ b/src/views/repositoriesView.ts @@ -3,6 +3,7 @@ import { CancellationToken, commands, ConfigurationChangeEvent, + Disposable, Event, EventEmitter, ProgressLocation, @@ -61,173 +62,183 @@ export class RepositoriesView extends ViewBase commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('refresh'), - async () => { - await Container.git.resetCaches('branches', 'contributors', 'remotes', 'stashes', 'status', 'tags'); - return this.refresh(true); - }, - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setBranchesLayoutToList'), - () => this.setBranchesLayout(ViewBranchesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setBranchesLayoutToTree'), - () => this.setBranchesLayout(ViewBranchesLayout.Tree), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToAuto'), - () => this.setFilesLayout(ViewFilesLayout.Auto), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToList'), - () => this.setFilesLayout(ViewFilesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToTree'), - () => this.setFilesLayout(ViewFilesLayout.Tree), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setAutoRefreshToOn'), - () => this.setAutoRefresh(Container.config.views.repositories.autoRefresh, true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setAutoRefreshToOff'), - () => this.setAutoRefresh(Container.config.views.repositories.autoRefresh, false), - this, - ); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchComparisonOn'), - () => this.setShowBranchComparison(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchComparisonOff'), - () => this.setShowBranchComparison(false), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setBranchesShowBranchComparisonOn'), - () => this.setBranchShowBranchComparison(true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setBranchesShowBranchComparisonOff'), - () => this.setBranchShowBranchComparison(false), - this, - ); - - commands.registerCommand( - this.getQualifiedCommand('setShowBranchesOn'), - () => this.toggleSection('showBranches', true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowBranchesOff'), - () => this.toggleSection('showBranches', false), - this, - ); - - commands.registerCommand( - this.getQualifiedCommand('setShowCommitsOn'), - () => this.toggleSection('showCommits', true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowCommitsOff'), - () => this.toggleSection('showCommits', false), - this, - ); - - commands.registerCommand( - this.getQualifiedCommand('setShowContributorsOn'), - () => this.toggleSection('showContributors', true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowContributorsOff'), - () => this.toggleSection('showContributors', false), - this, - ); - - commands.registerCommand( - this.getQualifiedCommand('setShowRemotesOn'), - () => this.toggleSection('showRemotes', true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowRemotesOff'), - () => this.toggleSection('showRemotes', false), - this, - ); - - commands.registerCommand( - this.getQualifiedCommand('setShowStashesOn'), - () => this.toggleSection('showStashes', true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowStashesOff'), - () => this.toggleSection('showStashes', false), - this, - ); - - commands.registerCommand( - this.getQualifiedCommand('setShowTagsOn'), - () => this.toggleSection('showTags', true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowTagsOff'), - () => this.toggleSection('showTags', false), - this, - ); - - commands.registerCommand( - this.getQualifiedCommand('setShowUpstreamStatusOn'), - () => this.toggleSection('showUpstreamStatus', true), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setShowUpstreamStatusOff'), - () => this.toggleSection('showUpstreamStatus', false), - this, - ); - - commands.registerCommand( - this.getQualifiedCommand('setShowSectionOff'), - ( - node: - | BranchesNode - | BranchNode - | BranchTrackingStatusNode - | CompareBranchNode - | ContributorsNode - | ReflogNode - | RemotesNode - | StashesNode - | TagsNode, - ) => this.toggleSectionByNode(node, false), - this, - ); + return [ + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('branches', 'contributors', 'remotes', 'stashes', 'status', 'tags'); + return this.refresh(true); + }, + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setBranchesLayoutToList'), + () => this.setBranchesLayout(ViewBranchesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setBranchesLayoutToTree'), + () => this.setBranchesLayout(ViewBranchesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToAuto'), + () => this.setFilesLayout(ViewFilesLayout.Auto), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToList'), + () => this.setFilesLayout(ViewFilesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToTree'), + () => this.setFilesLayout(ViewFilesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setAutoRefreshToOn'), + () => this.setAutoRefresh(Container.config.views.repositories.autoRefresh, true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setAutoRefreshToOff'), + () => this.setAutoRefresh(Container.config.views.repositories.autoRefresh, false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOn'), + () => this.setShowAvatars(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOff'), + () => this.setShowAvatars(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchComparisonOn'), + () => this.setShowBranchComparison(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchComparisonOff'), + () => this.setShowBranchComparison(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setBranchesShowBranchComparisonOn'), + () => this.setBranchShowBranchComparison(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setBranchesShowBranchComparisonOff'), + () => this.setBranchShowBranchComparison(false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowBranchesOn'), + () => this.toggleSection('showBranches', true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowBranchesOff'), + () => this.toggleSection('showBranches', false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowCommitsOn'), + () => this.toggleSection('showCommits', true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowCommitsOff'), + () => this.toggleSection('showCommits', false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowContributorsOn'), + () => this.toggleSection('showContributors', true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowContributorsOff'), + () => this.toggleSection('showContributors', false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowRemotesOn'), + () => this.toggleSection('showRemotes', true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowRemotesOff'), + () => this.toggleSection('showRemotes', false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowStashesOn'), + () => this.toggleSection('showStashes', true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowStashesOff'), + () => this.toggleSection('showStashes', false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowTagsOn'), + () => this.toggleSection('showTags', true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowTagsOff'), + () => this.toggleSection('showTags', false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowUpstreamStatusOn'), + () => this.toggleSection('showUpstreamStatus', true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowUpstreamStatusOff'), + () => this.toggleSection('showUpstreamStatus', false), + this, + ), + + commands.registerCommand( + this.getQualifiedCommand('setShowSectionOff'), + ( + node: + | BranchesNode + | BranchNode + | BranchTrackingStatusNode + | CompareBranchNode + | ContributorsNode + | ReflogNode + | RemotesNode + | StashesNode + | TagsNode, + ) => this.toggleSectionByNode(node, false), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/searchAndCompareView.ts b/src/views/searchAndCompareView.ts index d23d8cc72ff29..8ffdd15e6f5a5 100644 --- a/src/views/searchAndCompareView.ts +++ b/src/views/searchAndCompareView.ts @@ -1,5 +1,5 @@ 'use strict'; -import { commands, ConfigurationChangeEvent, TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { commands, ConfigurationChangeEvent, Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { getRepoPathOrPrompt } from '../commands'; import { configuration, SearchAndCompareViewConfig, ViewFilesLayout } from '../configuration'; import { ContextKeys, NamedRef, PinnedItem, PinnedItems, setContext, WorkspaceState } from '../constants'; @@ -264,61 +264,75 @@ export class SearchAndCompareView extends ViewBase this.clear(), this); - commands.registerCommand( - this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToAuto'), - () => this.setFilesLayout(ViewFilesLayout.Auto), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToList'), - () => this.setFilesLayout(ViewFilesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToTree'), - () => this.setFilesLayout(ViewFilesLayout.Tree), - this, - ); - commands.registerCommand(this.getQualifiedCommand('setKeepResultsToOn'), () => this.setKeepResults(true), this); - commands.registerCommand( - this.getQualifiedCommand('setKeepResultsToOff'), - () => this.setKeepResults(false), - this, - ); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); - - commands.registerCommand(this.getQualifiedCommand('pin'), this.pin, this); - commands.registerCommand(this.getQualifiedCommand('unpin'), this.unpin, this); - commands.registerCommand(this.getQualifiedCommand('swapComparison'), this.swapComparison, this); - commands.registerCommand(this.getQualifiedCommand('selectForCompare'), this.selectForCompare, this); - commands.registerCommand(this.getQualifiedCommand('compareWithSelected'), this.compareWithSelected, this); - - commands.registerCommand( - this.getQualifiedCommand('setFilesFilterOnLeft'), - n => this.setFilesFilter(n, 'left'), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesFilterOnRight'), - n => this.setFilesFilter(n, 'right'), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesFilterOff'), - n => this.setFilesFilter(n, false), - this, - ); + return [ + commands.registerCommand(this.getQualifiedCommand('clear'), () => this.clear(), this), + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToAuto'), + () => this.setFilesLayout(ViewFilesLayout.Auto), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToList'), + () => this.setFilesLayout(ViewFilesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToTree'), + () => this.setFilesLayout(ViewFilesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setKeepResultsToOn'), + () => this.setKeepResults(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setKeepResultsToOff'), + () => this.setKeepResults(false), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOn'), + () => this.setShowAvatars(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOff'), + () => this.setShowAvatars(false), + this, + ), + + commands.registerCommand(this.getQualifiedCommand('pin'), this.pin, this), + commands.registerCommand(this.getQualifiedCommand('unpin'), this.unpin, this), + commands.registerCommand(this.getQualifiedCommand('swapComparison'), this.swapComparison, this), + commands.registerCommand(this.getQualifiedCommand('selectForCompare'), this.selectForCompare, this), + commands.registerCommand(this.getQualifiedCommand('compareWithSelected'), this.compareWithSelected, this), + + commands.registerCommand( + this.getQualifiedCommand('setFilesFilterOnLeft'), + n => this.setFilesFilter(n, 'left'), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesFilterOnRight'), + n => this.setFilesFilter(n, 'right'), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesFilterOff'), + n => this.setFilesFilter(n, false), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/stashesView.ts b/src/views/stashesView.ts index 055aa136552c7..a7b1a8d53c860 100644 --- a/src/views/stashesView.ts +++ b/src/views/stashesView.ts @@ -3,6 +3,7 @@ import { CancellationToken, commands, ConfigurationChangeEvent, + Disposable, ProgressLocation, TreeItem, TreeItemCollapsibleState, @@ -124,37 +125,39 @@ export class StashesView extends ViewBase { return new StashesViewNode(this); } - protected registerCommands() { + protected registerCommands(): Disposable[] { void Container.viewCommands; - commands.registerCommand( - this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('refresh'), - async () => { - await Container.git.resetCaches('stashes'); - return this.refresh(true); - }, - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToAuto'), - () => this.setFilesLayout(ViewFilesLayout.Auto), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToList'), - () => this.setFilesLayout(ViewFilesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToTree'), - () => this.setFilesLayout(ViewFilesLayout.Tree), - this, - ); + return [ + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('stashes'); + return this.refresh(true); + }, + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToAuto'), + () => this.setFilesLayout(ViewFilesLayout.Auto), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToList'), + () => this.setFilesLayout(ViewFilesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToTree'), + () => this.setFilesLayout(ViewFilesLayout.Tree), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/tagsView.ts b/src/views/tagsView.ts index b617a51202071..5c37606793a84 100644 --- a/src/views/tagsView.ts +++ b/src/views/tagsView.ts @@ -3,6 +3,7 @@ import { CancellationToken, commands, ConfigurationChangeEvent, + Disposable, ProgressLocation, TreeItem, TreeItemCollapsibleState, @@ -131,49 +132,59 @@ export class TagsView extends ViewBase { return new TagsViewNode(this); } - protected registerCommands() { + protected registerCommands(): Disposable[] { void Container.viewCommands; - commands.registerCommand( - this.getQualifiedCommand('copy'), - () => commands.executeCommand('gitlens.views.copy', this.selection), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('refresh'), - async () => { - await Container.git.resetCaches('tags'); - return this.refresh(true); - }, - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setLayoutToList'), - () => this.setLayout(ViewBranchesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setLayoutToTree'), - () => this.setLayout(ViewBranchesLayout.Tree), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToAuto'), - () => this.setFilesLayout(ViewFilesLayout.Auto), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToList'), - () => this.setFilesLayout(ViewFilesLayout.List), - this, - ); - commands.registerCommand( - this.getQualifiedCommand('setFilesLayoutToTree'), - () => this.setFilesLayout(ViewFilesLayout.Tree), - this, - ); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this); - commands.registerCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this); + return [ + commands.registerCommand( + this.getQualifiedCommand('copy'), + () => commands.executeCommand('gitlens.views.copy', this.selection), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('refresh'), + async () => { + await Container.git.resetCaches('tags'); + return this.refresh(true); + }, + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setLayoutToList'), + () => this.setLayout(ViewBranchesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setLayoutToTree'), + () => this.setLayout(ViewBranchesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToAuto'), + () => this.setFilesLayout(ViewFilesLayout.Auto), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToList'), + () => this.setFilesLayout(ViewFilesLayout.List), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setFilesLayoutToTree'), + () => this.setFilesLayout(ViewFilesLayout.Tree), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOn'), + () => this.setShowAvatars(true), + this, + ), + commands.registerCommand( + this.getQualifiedCommand('setShowAvatarsOff'), + () => this.setShowAvatars(false), + this, + ), + ]; } protected override filterConfigurationChanged(e: ConfigurationChangeEvent) { diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index 747ffecea556e..c4369616dfb09 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -101,7 +101,7 @@ export abstract class ViewBase< return this._onDidChangeNodeCollapsibleState.event; } - protected disposable: Disposable | undefined; + protected disposables: Disposable[] = []; protected root: RootNode | undefined; protected tree: TreeView | undefined; @@ -152,16 +152,7 @@ export abstract class ViewBase< }; } - this.registerCommands(); - - Container.context.subscriptions.push( - configuration.onDidChange(e => { - if (!this.filterConfigurationChanged(e)) return; - - this._config = undefined; - this.onConfigurationChanged(e); - }, this), - ); + this.disposables.push(...this.registerCommands()); this.initialize({ showCollapseAll: this.showCollapseAll }); @@ -184,7 +175,7 @@ export abstract class ViewBase< } dispose() { - this.disposable?.dispose(); + Disposable.from(...this.disposables).dispose(); } private _title: string | undefined; @@ -225,7 +216,7 @@ export abstract class ViewBase< } protected abstract getRoot(): RootNode; - protected abstract registerCommands(): void; + protected abstract registerCommands(): Disposable[]; protected onConfigurationChanged(e?: ConfigurationChangeEvent): void { if (e != null && this.root != null) { void this.refresh(true); @@ -233,16 +224,17 @@ export abstract class ViewBase< } protected initialize(options: { showCollapseAll?: boolean } = {}) { - if (this.disposable != null) { - this.disposable.dispose(); - this._onDidChangeTreeData = new EventEmitter(); - } - this.tree = window.createTreeView>(this.id, { ...options, treeDataProvider: this, }); - this.disposable = Disposable.from( + this.disposables.push( + configuration.onDidChange(e => { + if (!this.filterConfigurationChanged(e)) return; + + this._config = undefined; + this.onConfigurationChanged(e); + }, this), this.tree, this.tree.onDidChangeVisibility(Functions.debounce(this.onVisibilityChanged, 250), this), this.tree.onDidCollapseElement(this.onElementCollapsed, this),