Selaa lähdekoodia

Centralizes command registrations

main
Eric Amodio 2 vuotta sitten
vanhempi
commit
d0ac7b116f
22 muutettua tiedostoa jossa 335 lisäystä ja 414 poistoa
  1. +4
    -4
      src/api/actionRunners.ts
  2. +3
    -6
      src/commands/base.ts
  3. +3
    -4
      src/keyboard.ts
  4. +13
    -18
      src/plus/subscription/subscriptionService.ts
  5. +5
    -6
      src/plus/webviews/timeline/timelineWebview.ts
  6. +5
    -6
      src/plus/webviews/timeline/timelineWebviewView.ts
  7. +4
    -0
      src/system/command.ts
  8. +15
    -22
      src/views/branchesView.ts
  9. +15
    -22
      src/views/commitsView.ts
  10. +13
    -20
      src/views/contributorsView.ts
  11. +14
    -22
      src/views/fileHistoryView.ts
  12. +8
    -16
      src/views/lineHistoryView.ts
  13. +13
    -20
      src/views/remotesView.ts
  14. +34
    -41
      src/views/repositoriesView.ts
  15. +20
    -31
      src/views/searchAndCompareView.ts
  16. +7
    -6
      src/views/stashesView.ts
  17. +11
    -18
      src/views/tagsView.ts
  18. +122
    -121
      src/views/viewCommands.ts
  19. +15
    -21
      src/views/worktreesView.ts
  20. +5
    -5
      src/webviews/home/homeWebviewView.ts
  21. +3
    -2
      src/webviews/settings/settingsWebview.ts
  22. +3
    -3
      src/webviews/webviewBase.ts

+ 4
- 4
src/api/actionRunners.ts Näytä tiedosto

@ -1,10 +1,11 @@
import type { Event, QuickPickItem } from 'vscode';
import { commands, Disposable, EventEmitter, window } from 'vscode';
import { Disposable, EventEmitter, window } from 'vscode';
import type { Config } from '../configuration';
import { configuration } from '../configuration';
import { Commands, ContextKeys } from '../constants';
import type { Container } from '../container';
import { setContext } from '../context';
import { registerCommand } from '../system/command';
import { sortCompare } from '../system/string';
import { getQuickPickIgnoreFocusOut } from '../system/utils';
import type { Action, ActionContext, ActionRunner } from './gitlens';
@ -143,9 +144,8 @@ export class ActionRunners implements Disposable {
for (const action of actions) {
subscriptions.push(
commands.registerCommand(
`${Commands.ActionPrefix}${action}`,
(context: ActionContext, runnerId?: number) => this.run(context, runnerId),
registerCommand(`${Commands.ActionPrefix}${action}`, (context: ActionContext, runnerId?: number) =>
this.run(context, runnerId),
),
);
}

+ 3
- 6
src/commands/base.ts Näytä tiedosto

@ -20,6 +20,7 @@ import { GitRemote } from '../git/models/remote';
import { Repository } from '../git/models/repository';
import type { GitTag } from '../git/models/tag';
import { isTag } from '../git/models/tag';
import { registerCommand } from '../system/command';
import { sequentialize } from '../system/function';
import { ViewNode, ViewRefNode } from '../views/nodes/viewNode';
@ -239,17 +240,13 @@ export abstract class Command implements Disposable {
constructor(command: Commands | Commands[]) {
if (typeof command === 'string') {
this._disposable = commands.registerCommand(
command,
(...args: any[]) => this._execute(command, ...args),
this,
);
this._disposable = registerCommand(command, (...args: any[]) => this._execute(command, ...args), this);
return;
}
const subscriptions = command.map(cmd =>
commands.registerCommand(cmd, (...args: any[]) => this._execute(cmd, ...args), this),
registerCommand(cmd, (...args: any[]) => this._execute(cmd, ...args), this),
);
this._disposable = Disposable.from(...subscriptions);
}

+ 3
- 4
src/keyboard.ts Näytä tiedosto

@ -1,7 +1,8 @@
import { commands, Disposable } from 'vscode';
import { Disposable } from 'vscode';
import { ContextKeys } from './constants';
import { setContext } from './context';
import { Logger } from './logger';
import { registerCommand } from './system/command';
import { getLogScope, log } from './system/decorators/log';
export declare interface KeyCommand {
@ -151,9 +152,7 @@ export class Keyboard implements Disposable {
private readonly _disposable: Disposable;
constructor() {
const subscriptions = keys.map(key =>
commands.registerCommand(`gitlens.key.${key}`, () => this.execute(key), this),
);
const subscriptions = keys.map(key => registerCommand(`gitlens.key.${key}`, () => this.execute(key), this));
this._disposable = Disposable.from(...subscriptions);
}

+ 13
- 18
src/plus/subscription/subscriptionService.ts Näytä tiedosto

@ -8,7 +8,6 @@ import type {
import {
authentication,
version as codeVersion,
commands,
Disposable,
env,
EventEmitter,
@ -42,7 +41,7 @@ import {
SubscriptionPlanId,
SubscriptionState,
} from '../../subscription';
import { executeCommand } from '../../system/command';
import { executeCommand, registerCommand } from '../../system/command';
import { createFromDateDelta } from '../../system/date';
import { gate } from '../../system/decorators/gate';
import { debug, getLogScope, log } from '../../system/decorators/log';
@ -182,27 +181,23 @@ export class SubscriptionService implements Disposable {
void this.container.viewCommands;
return [
commands.registerCommand(Commands.PlusLearn, openToSide => this.learn(openToSide)),
commands.registerCommand(Commands.PlusLoginOrSignUp, () => this.loginOrSignUp()),
commands.registerCommand(Commands.PlusLogout, () => this.logout()),
registerCommand(Commands.PlusLearn, openToSide => this.learn(openToSide)),
registerCommand(Commands.PlusLoginOrSignUp, () => this.loginOrSignUp()),
registerCommand(Commands.PlusLogout, () => this.logout()),
commands.registerCommand(Commands.PlusStartPreviewTrial, () => this.startPreviewTrial()),
commands.registerCommand(Commands.PlusManage, () => this.manage()),
commands.registerCommand(Commands.PlusPurchase, () => this.purchase()),
registerCommand(Commands.PlusStartPreviewTrial, () => this.startPreviewTrial()),
registerCommand(Commands.PlusManage, () => this.manage()),
registerCommand(Commands.PlusPurchase, () => this.purchase()),
commands.registerCommand(Commands.PlusResendVerification, () => this.resendVerification()),
commands.registerCommand(Commands.PlusValidate, () => this.validate()),
registerCommand(Commands.PlusResendVerification, () => this.resendVerification()),
registerCommand(Commands.PlusValidate, () => this.validate()),
commands.registerCommand(Commands.PlusShowPlans, () => this.showPlans()),
registerCommand(Commands.PlusShowPlans, () => this.showPlans()),
commands.registerCommand(Commands.PlusHide, () =>
configuration.updateEffective('plusFeatures.enabled', false),
),
commands.registerCommand(Commands.PlusRestore, () =>
configuration.updateEffective('plusFeatures.enabled', true),
),
registerCommand(Commands.PlusHide, () => configuration.updateEffective('plusFeatures.enabled', false)),
registerCommand(Commands.PlusRestore, () => configuration.updateEffective('plusFeatures.enabled', true)),
commands.registerCommand('gitlens.plus.reset', () => this.logout(true)),
registerCommand('gitlens.plus.reset', () => this.logout(true)),
];
}

+ 5
- 6
src/plus/webviews/timeline/timelineWebview.ts Näytä tiedosto

@ -1,6 +1,6 @@
'use strict';
import type { Disposable, TextEditor } from 'vscode';
import { commands, Uri, ViewColumn, window } from 'vscode';
import { Uri, ViewColumn, window } from 'vscode';
import type { ShowQuickCommitFileCommandArgs } from '../../../commands';
import { configuration } from '../../../configuration';
import { Commands, ContextKeys } from '../../../constants';
@ -10,6 +10,7 @@ import { PlusFeatures } from '../../../features';
import { GitUri } from '../../../git/gitUri';
import type { RepositoryChangeEvent } from '../../../git/models/repository';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository';
import { executeCommand, registerCommand } from '../../../system/command';
import { createFromDateDelta } from '../../../system/date';
import { debug } from '../../../system/decorators/log';
import type { Deferrable } from '../../../system/function';
@ -106,7 +107,7 @@ export class TimelineWebview extends WebviewBase {
}
protected override registerCommands(): Disposable[] {
return [commands.registerCommand(Commands.RefreshTimelinePage, () => this.refresh())];
return [registerCommand(Commands.RefreshTimelinePage, () => this.refresh())];
}
protected override onFocusChanged(focused: boolean): void {
@ -145,13 +146,11 @@ export class TimelineWebview extends WebviewBase {
const repository = this.container.git.getRepository(this._context.uri);
if (repository == null) return;
const commandArgs: ShowQuickCommitFileCommandArgs = {
void executeCommand<ShowQuickCommitFileCommandArgs>(Commands.ShowQuickCommitFile, {
revisionUri: this.container.git
.getRevisionUri(params.data.id, getBestPath(this._context.uri), repository.uri)
.toString(true),
};
void commands.executeCommand(Commands.ShowQuickCommitFile, commandArgs);
});
// const commandArgs: DiffWithPreviousCommandArgs = {
// line: 0,

+ 5
- 6
src/plus/webviews/timeline/timelineWebviewView.ts Näytä tiedosto

@ -10,6 +10,7 @@ import type { RepositoriesChangeEvent } from '../../../git/gitProviderService';
import { GitUri } from '../../../git/gitUri';
import type { RepositoryChangeEvent } from '../../../git/models/repository';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository';
import { executeCommand, registerCommand } from '../../../system/command';
import { createFromDateDelta } from '../../../system/date';
import { debug } from '../../../system/decorators/log';
import type { Deferrable } from '../../../system/function';
@ -91,8 +92,8 @@ export class TimelineWebviewView extends WebviewViewBase {
protected override registerCommands(): Disposable[] {
return [
commands.registerCommand(`${this.id}.refresh`, () => this.refresh(), this),
commands.registerCommand(`${this.id}.openInTab`, () => this.openInTab(), this),
registerCommand(`${this.id}.refresh`, () => this.refresh(), this),
registerCommand(`${this.id}.openInTab`, () => this.openInTab(), this),
];
}
@ -122,13 +123,11 @@ export class TimelineWebviewView extends WebviewViewBase {
const repository = this.container.git.getRepository(this._context.uri);
if (repository == null) return;
const commandArgs: ShowQuickCommitFileCommandArgs = {
void executeCommand<ShowQuickCommitFileCommandArgs>(Commands.ShowQuickCommitFile, {
revisionUri: this.container.git
.getRevisionUri(params.data.id, getBestPath(this._context.uri), repository.uri)
.toString(true),
};
void commands.executeCommand(Commands.ShowQuickCommitFile, commandArgs);
});
// const commandArgs: DiffWithPreviousCommandArgs = {
// line: 0,

+ 4
- 0
src/system/command.ts Näytä tiedosto

@ -17,6 +17,10 @@ export function command(): ClassDecorator {
};
}
export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable {
return commands.registerCommand(command, callback, thisArg);
}
export function registerCommands(container: Container): Disposable[] {
return registrableCommands.map(c => new c(container));
}

+ 15
- 22
src/views/branchesView.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { CancellationToken, ConfigurationChangeEvent, Disposable } from 'vscode';
import { commands, ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import type { BranchesViewConfig } from '../configuration';
import { configuration, ViewBranchesLayout, ViewFilesLayout, ViewShowBranchComparison } from '../configuration';
import { Commands } from '../constants';
@ -20,6 +20,7 @@ import { RepositoryNode } from './nodes/repositoryNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
export class BranchesRepositoryNode extends RepositoryFolderNode<BranchesView, BranchesNode> {
async getChildren(): Promise<ViewNode[]> {
@ -111,12 +112,12 @@ export class BranchesView extends ViewBase
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('refresh'),
() => {
this.container.git.resetCaches('branches');
@ -124,57 +125,49 @@ export class BranchesView extends ViewBase
},
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setLayoutToList'),
() => this.setLayout(ViewBranchesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setLayoutToTree'),
() => this.setLayout(ViewBranchesLayout.Tree),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
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(
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this),
registerViewCommand(
this.getQualifiedCommand('setShowBranchComparisonOn'),
() => this.setShowBranchComparison(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchComparisonOff'),
() => this.setShowBranchComparison(false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchPullRequestOn'),
() => this.setShowBranchPullRequest(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchPullRequestOff'),
() => this.setShowBranchPullRequest(false),
this,

+ 15
- 22
src/views/commitsView.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { CancellationToken, ConfigurationChangeEvent } from 'vscode';
import { commands, Disposable, ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { Disposable, ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import type { CommitsViewConfig } from '../configuration';
import { configuration, ViewFilesLayout, ViewShowBranchComparison } from '../configuration';
import { Commands, ContextKeys, GlyphChars } from '../constants';
@ -22,6 +22,7 @@ import { RepositoryNode } from './nodes/repositoryNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
export class CommitsRepositoryNode extends RepositoryFolderNode<CommitsView, BranchNode> {
async getChildren(): Promise<ViewNode[]> {
@ -182,12 +183,12 @@ export class CommitsView extends ViewBase {
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('refresh'),
() => {
this.container.git.resetCaches('branches', 'status', 'tags');
@ -195,57 +196,49 @@ export class CommitsView extends ViewBase {
},
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToTree'),
() => this.setFilesLayout(ViewFilesLayout.Tree),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setMyCommitsOnlyOn'),
() => this.setMyCommitsOnly(true),
this,
),
commands.registerCommand(
registerViewCommand(
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(
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this),
registerViewCommand(
this.getQualifiedCommand('setShowBranchComparisonOn'),
() => this.setShowBranchComparison(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchComparisonOff'),
() => this.setShowBranchComparison(false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchPullRequestOn'),
() => this.setShowBranchPullRequest(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchPullRequestOff'),
() => this.setShowBranchPullRequest(false),
this,

+ 13
- 20
src/views/contributorsView.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { CancellationToken, ConfigurationChangeEvent } from 'vscode';
import { commands, Disposable, ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { Disposable, ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { Avatars } from '../avatars';
import type { ContributorsViewConfig } from '../configuration';
import { configuration, ViewFilesLayout } from '../configuration';
@ -18,6 +18,7 @@ import { RepositoryNode } from './nodes/repositoryNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
export class ContributorsRepositoryNode extends RepositoryFolderNode<ContributorsView, ContributorsNode> {
async getChildren(): Promise<ViewNode[]> {
@ -129,12 +130,12 @@ export class ContributorsView extends ViewBase
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('refresh'),
() => {
this.container.git.resetCaches('contributors');
@ -142,50 +143,42 @@ export class ContributorsView extends ViewBase
},
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToTree'),
() => this.setFilesLayout(ViewFilesLayout.Tree),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowAllBranchesOn'),
() => this.setShowAllBranches(true),
this,
),
commands.registerCommand(
registerViewCommand(
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,
),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowStatisticsOn'),
() => this.setShowStatistics(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowStatisticsOff'),
() => this.setShowStatistics(false),
this,

+ 14
- 22
src/views/fileHistoryView.ts Näytä tiedosto

@ -1,5 +1,4 @@
import type { ConfigurationChangeEvent, Disposable } from 'vscode';
import { commands } from 'vscode';
import type { FileHistoryViewConfig } from '../configuration';
import { configuration } from '../configuration';
import { Commands, ContextKeys } from '../constants';
@ -10,6 +9,7 @@ import { executeCommand } from '../system/command';
import { FileHistoryTrackerNode } from './nodes/fileHistoryTrackerNode';
import { LineHistoryTrackerNode } from './nodes/lineHistoryTrackerNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
const pinnedSuffix = ' (pinned)';
@ -38,63 +38,55 @@ export class FileHistoryView extends ViewBase
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this),
commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this),
commands.registerCommand(
registerViewCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this),
registerViewCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this),
registerViewCommand(
this.getQualifiedCommand('setCursorFollowingOn'),
() => this.setCursorFollowing(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setCursorFollowingOff'),
() => this.setCursorFollowing(false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setEditorFollowingOn'),
() => this.setEditorFollowing(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setEditorFollowingOff'),
() => this.setEditorFollowing(false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setRenameFollowingOn'),
() => this.setRenameFollowing(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setRenameFollowingOff'),
() => this.setRenameFollowing(false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowAllBranchesOn'),
() => this.setShowAllBranches(true),
this,
),
commands.registerCommand(
registerViewCommand(
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,
),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this),
];
}

+ 8
- 16
src/views/lineHistoryView.ts Näytä tiedosto

@ -1,5 +1,4 @@
import type { ConfigurationChangeEvent, Disposable } from 'vscode';
import { commands } from 'vscode';
import type { LineHistoryViewConfig } from '../configuration';
import { configuration } from '../configuration';
import { Commands, ContextKeys } from '../constants';
@ -8,6 +7,7 @@ import { setContext } from '../context';
import { executeCommand } from '../system/command';
import { LineHistoryTrackerNode } from './nodes/lineHistoryTrackerNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
const pinnedSuffix = ' (pinned)';
@ -32,33 +32,25 @@ export class LineHistoryView extends ViewBase
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this),
commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this),
commands.registerCommand(
registerViewCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this),
registerViewCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this),
registerViewCommand(
this.getQualifiedCommand('setEditorFollowingOn'),
() => this.setEditorFollowing(true),
this,
),
commands.registerCommand(
registerViewCommand(
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,
),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this),
];
}

+ 13
- 20
src/views/remotesView.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { CancellationToken, ConfigurationChangeEvent, Disposable } from 'vscode';
import { commands, ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import type { RemotesViewConfig } from '../configuration';
import { configuration, ViewBranchesLayout, ViewFilesLayout } from '../configuration';
import { Commands } from '../constants';
@ -23,6 +23,7 @@ import { RepositoryNode } from './nodes/repositoryNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
export class RemotesRepositoryNode extends RepositoryFolderNode<RemotesView, RemotesNode> {
async getChildren(): Promise<ViewNode[]> {
@ -111,12 +112,12 @@ export class RemotesView extends ViewBase {
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('refresh'),
() => {
this.container.git.resetCaches('branches', 'remotes');
@ -124,47 +125,39 @@ export class RemotesView extends ViewBase {
},
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setLayoutToList'),
() => this.setLayout(ViewBranchesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setLayoutToTree'),
() => this.setLayout(ViewBranchesLayout.Tree),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
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(
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this),
registerViewCommand(
this.getQualifiedCommand('setShowBranchPullRequestOn'),
() => this.setShowBranchPullRequest(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchPullRequestOff'),
() => this.setShowBranchPullRequest(false),
this,

+ 34
- 41
src/views/repositoriesView.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { CancellationToken, ConfigurationChangeEvent, Disposable, Event } from 'vscode';
import { commands, EventEmitter, ProgressLocation, window } from 'vscode';
import { EventEmitter, ProgressLocation, window } from 'vscode';
import type { RepositoriesViewConfig } from '../configuration';
import { configuration, ViewBranchesLayout, ViewFilesLayout, ViewShowBranchComparison } from '../configuration';
import { Commands, ContextKeys } from '../constants';
@ -38,6 +38,7 @@ import { TagsNode } from './nodes/tagsNode';
import { WorktreeNode } from './nodes/worktreeNode';
import { WorktreesNode } from './nodes/worktreesNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
export class RepositoriesView extends ViewBase<RepositoriesNode, RepositoriesViewConfig> {
protected readonly configKey = 'repositories';
@ -63,12 +64,12 @@ export class RepositoriesView extends ViewBase
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('refresh'),
() => {
this.container.git.resetCaches('branches', 'contributors', 'remotes', 'stashes', 'status', 'tags');
@ -76,160 +77,152 @@ export class RepositoriesView extends ViewBase
},
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setBranchesLayoutToList'),
() => this.setBranchesLayout(ViewBranchesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setBranchesLayoutToTree'),
() => this.setBranchesLayout(ViewBranchesLayout.Tree),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToTree'),
() => this.setFilesLayout(ViewFilesLayout.Tree),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setAutoRefreshToOn'),
() => this.setAutoRefresh(configuration.get('views.repositories.autoRefresh'), true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setAutoRefreshToOff'),
() => this.setAutoRefresh(configuration.get('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(
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this),
registerViewCommand(
this.getQualifiedCommand('setShowBranchComparisonOn'),
() => this.setShowBranchComparison(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchComparisonOff'),
() => this.setShowBranchComparison(false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setBranchesShowBranchComparisonOn'),
() => this.setBranchShowBranchComparison(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setBranchesShowBranchComparisonOff'),
() => this.setBranchShowBranchComparison(false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchesOn'),
() => this.toggleSection('showBranches', true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchesOff'),
() => this.toggleSection('showBranches', false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowCommitsOn'),
() => this.toggleSection('showCommits', true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowCommitsOff'),
() => this.toggleSection('showCommits', false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowContributorsOn'),
() => this.toggleSection('showContributors', true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowContributorsOff'),
() => this.toggleSection('showContributors', false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowRemotesOn'),
() => this.toggleSection('showRemotes', true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowRemotesOff'),
() => this.toggleSection('showRemotes', false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowStashesOn'),
() => this.toggleSection('showStashes', true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowStashesOff'),
() => this.toggleSection('showStashes', false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowTagsOn'),
() => this.toggleSection('showTags', true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowTagsOff'),
() => this.toggleSection('showTags', false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowWorktreesOn'),
() => this.toggleSection('showWorktrees', true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowWorktreesOff'),
() => this.toggleSection('showWorktrees', false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowUpstreamStatusOn'),
() => this.toggleSection('showUpstreamStatus', true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowUpstreamStatusOff'),
() => this.toggleSection('showUpstreamStatus', false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowSectionOff'),
(
node:

+ 20
- 31
src/views/searchAndCompareView.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { ConfigurationChangeEvent, Disposable } from 'vscode';
import { commands, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import type { SearchAndCompareViewConfig } from '../configuration';
import { configuration, ViewFilesLayout } from '../configuration';
import { Commands, ContextKeys } from '../constants';
@ -23,6 +23,7 @@ import { FilesQueryFilter, ResultsFilesNode } from './nodes/resultsFilesNode';
import { SearchResultsNode } from './nodes/searchResultsNode';
import { ContextValues, RepositoryFolderNode, ViewNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
export class SearchAndCompareViewNode extends ViewNode<SearchAndCompareView> {
protected override splatted = true;
@ -258,66 +259,54 @@ export class SearchAndCompareView extends ViewBase
void this.container.viewCommands;
return [
commands.registerCommand(this.getQualifiedCommand('clear'), () => this.clear(), this),
commands.registerCommand(
registerViewCommand(this.getQualifiedCommand('clear'), () => this.clear(), this),
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this),
commands.registerCommand(
registerViewCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this),
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToTree'),
() => this.setFilesLayout(ViewFilesLayout.Tree),
this,
),
commands.registerCommand(
this.getQualifiedCommand('setKeepResultsToOn'),
() => this.setKeepResults(true),
this,
),
commands.registerCommand(
registerViewCommand(this.getQualifiedCommand('setKeepResultsToOn'), () => this.setKeepResults(true), this),
registerViewCommand(
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,
),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(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),
registerViewCommand(this.getQualifiedCommand('pin'), this.pin, this),
registerViewCommand(this.getQualifiedCommand('unpin'), this.unpin, this),
registerViewCommand(this.getQualifiedCommand('swapComparison'), this.swapComparison, this),
registerViewCommand(this.getQualifiedCommand('selectForCompare'), this.selectForCompare, this),
registerViewCommand(this.getQualifiedCommand('compareWithSelected'), this.compareWithSelected, this),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesFilterOnLeft'),
n => this.setFilesFilter(n, FilesQueryFilter.Left),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesFilterOnRight'),
n => this.setFilesFilter(n, FilesQueryFilter.Right),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesFilterOff'),
n => this.setFilesFilter(n, undefined),
this,

+ 7
- 6
src/views/stashesView.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { CancellationToken, ConfigurationChangeEvent, Disposable } from 'vscode';
import { commands, ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import type { StashesViewConfig } from '../configuration';
import { configuration, ViewFilesLayout } from '../configuration';
import { Commands } from '../constants';
@ -17,6 +17,7 @@ import { StashNode } from './nodes/stashNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
export class StashesRepositoryNode extends RepositoryFolderNode<StashesView, StashesNode> {
async getChildren(): Promise<ViewNode[]> {
@ -99,12 +100,12 @@ export class StashesView extends ViewBase {
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('refresh'),
() => {
this.container.git.resetCaches('stashes');
@ -112,17 +113,17 @@ export class StashesView extends ViewBase {
},
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToTree'),
() => this.setFilesLayout(ViewFilesLayout.Tree),
this,

+ 11
- 18
src/views/tagsView.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { CancellationToken, ConfigurationChangeEvent, Disposable } from 'vscode';
import { commands, ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { ProgressLocation, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import type { TagsViewConfig } from '../configuration';
import { configuration, ViewBranchesLayout, ViewFilesLayout } from '../configuration';
import { Commands } from '../constants';
@ -17,6 +17,7 @@ import { TagsNode } from './nodes/tagsNode';
import type { ViewNode } from './nodes/viewNode';
import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/viewNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
export class TagsRepositoryNode extends RepositoryFolderNode<TagsView, TagsNode> {
async getChildren(): Promise<ViewNode[]> {
@ -99,12 +100,12 @@ export class TagsView extends ViewBase {
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('refresh'),
() => {
this.container.git.resetCaches('tags');
@ -112,41 +113,33 @@ export class TagsView extends ViewBase {
},
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setLayoutToList'),
() => this.setLayout(ViewBranchesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setLayoutToTree'),
() => this.setLayout(ViewBranchesLayout.Tree),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
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,
),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this),
];
}

+ 122
- 121
src/views/viewCommands.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { Disposable, TextDocumentShowOptions } from 'vscode';
import { commands, env, Uri, window } from 'vscode';
import { env, Uri, window } from 'vscode';
import type { CreatePullRequestActionContext, OpenPullRequestActionContext } from '../api/gitlens';
import type {
DiffWithCommandArgs,
@ -21,6 +21,7 @@ import {
executeCoreCommand,
executeCoreGitCommand,
executeEditorCommand,
registerCommand,
} from '../system/command';
import { debug } from '../system/decorators/log';
import { sequentialize } from '../system/function';
@ -76,45 +77,45 @@ const enum ViewCommandMultiSelectMode {
Custom,
}
export class ViewCommands {
private registerCommand(
command: string,
callback: (...args: any[]) => unknown,
thisArg?: any,
multiSelect: ViewCommandMultiSelectMode = ViewCommandMultiSelectMode.Allowed,
): Disposable {
return commands.registerCommand(
command,
(...args: any[]) => {
if (multiSelect !== ViewCommandMultiSelectMode.Disallowed) {
let [node, nodes, ...rest] = args;
// If there is a node followed by an array of nodes, then we want to execute the command for each
if (node instanceof ViewNode && Array.isArray(nodes) && nodes[0] instanceof ViewNode) {
nodes = nodes.filter(n => n?.constructor === node.constructor);
if (multiSelect === ViewCommandMultiSelectMode.Custom) {
return callback.apply(thisArg, [node, nodes, ...rest]);
}
return sequentialize(
callback,
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
(nodes as ViewNode[]).map(n => [n, ...rest]),
thisArg,
);
export function registerViewCommand(
command: string,
callback: (...args: any[]) => unknown,
thisArg?: any,
multiSelect: ViewCommandMultiSelectMode = ViewCommandMultiSelectMode.Allowed,
): Disposable {
return registerCommand(
command,
(...args: any[]) => {
if (multiSelect !== ViewCommandMultiSelectMode.Disallowed) {
let [node, nodes, ...rest] = args;
// If there is a node followed by an array of nodes, then we want to execute the command for each
if (node instanceof ViewNode && Array.isArray(nodes) && nodes[0] instanceof ViewNode) {
nodes = nodes.filter(n => n?.constructor === node.constructor);
if (multiSelect === ViewCommandMultiSelectMode.Custom) {
return callback.apply(thisArg, [node, nodes, ...rest]);
}
return sequentialize(
callback,
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
(nodes as ViewNode[]).map(n => [n, ...rest]),
thisArg,
);
}
}
return callback.apply(thisArg, args);
},
thisArg,
);
}
return callback.apply(thisArg, args);
},
thisArg,
);
}
export class ViewCommands {
constructor(private readonly container: Container) {
this.registerCommand('gitlens.views.clearNode', (n: ViewNode) => canClearNode(n) && n.clear(), this);
registerViewCommand('gitlens.views.clearNode', (n: ViewNode) => canClearNode(n) && n.clear(), this);
// Register independently as it already handles copying multiple nodes
commands.registerCommand(
registerCommand(
Commands.ViewsCopy,
async (active: ViewNode | undefined, selection: ViewNode[]) => {
selection = Array.isArray(selection) ? selection : active != null ? [active] : [];
@ -128,20 +129,20 @@ export class ViewCommands {
},
this,
);
this.registerCommand(
registerViewCommand(
'gitlens.views.dismissNode',
(n: ViewNode) => canViewDismissNode(n.view) && n.view.dismissNode(n),
this,
);
this.registerCommand('gitlens.views.editNode', (n: ViewNode) => canEditNode(n) && n.edit(), this);
this.registerCommand(
registerViewCommand('gitlens.views.editNode', (n: ViewNode) => canEditNode(n) && n.edit(), this);
registerViewCommand(
'gitlens.views.expandNode',
(n: ViewNode) => n.view.reveal(n, { select: false, focus: false, expand: 3 }),
this,
);
this.registerCommand('gitlens.views.loadMoreChildren', (n: PagerNode) => n.loadMore(), this);
this.registerCommand('gitlens.views.loadAllChildren', (n: PagerNode) => n.loadAll(), this);
this.registerCommand(
registerViewCommand('gitlens.views.loadMoreChildren', (n: PagerNode) => n.loadMore(), this);
registerViewCommand('gitlens.views.loadAllChildren', (n: PagerNode) => n.loadAll(), this);
registerViewCommand(
'gitlens.views.refreshNode',
(n: ViewNode, reset?: boolean) => {
if (reset == null && PageableViewNode.is(n)) {
@ -154,127 +155,127 @@ export class ViewCommands {
this,
);
this.registerCommand(
registerViewCommand(
'gitlens.views.setShowRelativeDateMarkersOn',
() => this.setShowRelativeDateMarkers(true),
this,
);
this.registerCommand(
registerViewCommand(
'gitlens.views.setShowRelativeDateMarkersOff',
() => this.setShowRelativeDateMarkers(false),
this,
);
this.registerCommand('gitlens.views.fetch', this.fetch, this);
this.registerCommand('gitlens.views.publishBranch', this.publishBranch, this);
this.registerCommand('gitlens.views.publishRepository', this.publishRepository, this);
this.registerCommand('gitlens.views.pull', this.pull, this);
this.registerCommand('gitlens.views.push', this.push, this);
this.registerCommand('gitlens.views.pushWithForce', n => this.push(n, true), this);
this.registerCommand('gitlens.views.closeRepository', this.closeRepository, this);
registerViewCommand('gitlens.views.fetch', this.fetch, this);
registerViewCommand('gitlens.views.publishBranch', this.publishBranch, this);
registerViewCommand('gitlens.views.publishRepository', this.publishRepository, this);
registerViewCommand('gitlens.views.pull', this.pull, this);
registerViewCommand('gitlens.views.push', this.push, this);
registerViewCommand('gitlens.views.pushWithForce', n => this.push(n, true), this);
registerViewCommand('gitlens.views.closeRepository', this.closeRepository, this);
this.registerCommand('gitlens.views.setAsDefault', this.setAsDefault, this);
this.registerCommand('gitlens.views.unsetAsDefault', this.unsetAsDefault, this);
registerViewCommand('gitlens.views.setAsDefault', this.setAsDefault, this);
registerViewCommand('gitlens.views.unsetAsDefault', this.unsetAsDefault, this);
this.registerCommand('gitlens.views.openInTerminal', this.openInTerminal, this);
this.registerCommand('gitlens.views.star', this.star, this);
this.registerCommand('gitlens.views.unstar', this.unstar, this);
registerViewCommand('gitlens.views.openInTerminal', this.openInTerminal, this);
registerViewCommand('gitlens.views.star', this.star, this);
registerViewCommand('gitlens.views.unstar', this.unstar, this);
this.registerCommand('gitlens.views.browseRepoAtRevision', this.browseRepoAtRevision, this);
this.registerCommand(
registerViewCommand('gitlens.views.browseRepoAtRevision', this.browseRepoAtRevision, this);
registerViewCommand(
'gitlens.views.browseRepoAtRevisionInNewWindow',
n => this.browseRepoAtRevision(n, { openInNewWindow: true }),
this,
);
this.registerCommand(
registerViewCommand(
'gitlens.views.browseRepoBeforeRevision',
n => this.browseRepoAtRevision(n, { before: true }),
this,
);
this.registerCommand(
registerViewCommand(
'gitlens.views.browseRepoBeforeRevisionInNewWindow',
n => this.browseRepoAtRevision(n, { before: true, openInNewWindow: true }),
this,
);
this.registerCommand('gitlens.views.addAuthors', this.addAuthors, this);
this.registerCommand('gitlens.views.addAuthor', this.addAuthors, this);
this.registerCommand('gitlens.views.openChanges', this.openChanges, this);
this.registerCommand('gitlens.views.openChangesWithWorking', this.openChangesWithWorking, this);
this.registerCommand('gitlens.views.openPreviousChangesWithWorking', this.openPreviousChangesWithWorking, this);
this.registerCommand('gitlens.views.openFile', this.openFile, this);
this.registerCommand('gitlens.views.openFileRevision', this.openRevision, this);
this.registerCommand('gitlens.views.openChangedFiles', this.openFiles, this);
this.registerCommand('gitlens.views.openChangedFileDiffs', this.openAllChanges, this);
this.registerCommand('gitlens.views.openChangedFileDiffsWithWorking', this.openAllChangesWithWorking, this);
this.registerCommand('gitlens.views.openChangedFileRevisions', this.openRevisions, this);
this.registerCommand('gitlens.views.applyChanges', this.applyChanges, this);
this.registerCommand('gitlens.views.highlightChanges', this.highlightChanges, this);
this.registerCommand('gitlens.views.highlightRevisionChanges', this.highlightRevisionChanges, this);
this.registerCommand('gitlens.views.restore', this.restore, this);
this.registerCommand('gitlens.views.switchToBranch', this.switch, this);
this.registerCommand('gitlens.views.switchToAnotherBranch', this.switch, this);
this.registerCommand('gitlens.views.switchToCommit', this.switch, this);
this.registerCommand('gitlens.views.switchToTag', this.switch, this);
this.registerCommand('gitlens.views.addRemote', this.addRemote, this);
this.registerCommand('gitlens.views.pruneRemote', this.pruneRemote, this);
this.registerCommand('gitlens.views.stageDirectory', this.stageDirectory, this);
this.registerCommand('gitlens.views.stageFile', this.stageFile, this);
this.registerCommand('gitlens.views.unstageDirectory', this.unstageDirectory, this);
this.registerCommand('gitlens.views.unstageFile', this.unstageFile, this);
this.registerCommand('gitlens.views.compareAncestryWithWorking', this.compareAncestryWithWorking, this);
this.registerCommand('gitlens.views.compareWithHead', this.compareHeadWith, this);
this.registerCommand('gitlens.views.compareWithUpstream', this.compareWithUpstream, this);
this.registerCommand('gitlens.views.compareWithSelected', this.compareWithSelected, this);
this.registerCommand('gitlens.views.selectForCompare', this.selectForCompare, this);
this.registerCommand('gitlens.views.compareFileWithSelected', this.compareFileWithSelected, this);
this.registerCommand('gitlens.views.selectFileForCompare', this.selectFileForCompare, this);
this.registerCommand('gitlens.views.compareWithWorking', this.compareWorkingWith, this);
this.registerCommand(
registerViewCommand('gitlens.views.addAuthors', this.addAuthors, this);
registerViewCommand('gitlens.views.addAuthor', this.addAuthors, this);
registerViewCommand('gitlens.views.openChanges', this.openChanges, this);
registerViewCommand('gitlens.views.openChangesWithWorking', this.openChangesWithWorking, this);
registerViewCommand('gitlens.views.openPreviousChangesWithWorking', this.openPreviousChangesWithWorking, this);
registerViewCommand('gitlens.views.openFile', this.openFile, this);
registerViewCommand('gitlens.views.openFileRevision', this.openRevision, this);
registerViewCommand('gitlens.views.openChangedFiles', this.openFiles, this);
registerViewCommand('gitlens.views.openChangedFileDiffs', this.openAllChanges, this);
registerViewCommand('gitlens.views.openChangedFileDiffsWithWorking', this.openAllChangesWithWorking, this);
registerViewCommand('gitlens.views.openChangedFileRevisions', this.openRevisions, this);
registerViewCommand('gitlens.views.applyChanges', this.applyChanges, this);
registerViewCommand('gitlens.views.highlightChanges', this.highlightChanges, this);
registerViewCommand('gitlens.views.highlightRevisionChanges', this.highlightRevisionChanges, this);
registerViewCommand('gitlens.views.restore', this.restore, this);
registerViewCommand('gitlens.views.switchToBranch', this.switch, this);
registerViewCommand('gitlens.views.switchToAnotherBranch', this.switch, this);
registerViewCommand('gitlens.views.switchToCommit', this.switch, this);
registerViewCommand('gitlens.views.switchToTag', this.switch, this);
registerViewCommand('gitlens.views.addRemote', this.addRemote, this);
registerViewCommand('gitlens.views.pruneRemote', this.pruneRemote, this);
registerViewCommand('gitlens.views.stageDirectory', this.stageDirectory, this);
registerViewCommand('gitlens.views.stageFile', this.stageFile, this);
registerViewCommand('gitlens.views.unstageDirectory', this.unstageDirectory, this);
registerViewCommand('gitlens.views.unstageFile', this.unstageFile, this);
registerViewCommand('gitlens.views.compareAncestryWithWorking', this.compareAncestryWithWorking, this);
registerViewCommand('gitlens.views.compareWithHead', this.compareHeadWith, this);
registerViewCommand('gitlens.views.compareWithUpstream', this.compareWithUpstream, this);
registerViewCommand('gitlens.views.compareWithSelected', this.compareWithSelected, this);
registerViewCommand('gitlens.views.selectForCompare', this.selectForCompare, this);
registerViewCommand('gitlens.views.compareFileWithSelected', this.compareFileWithSelected, this);
registerViewCommand('gitlens.views.selectFileForCompare', this.selectFileForCompare, this);
registerViewCommand('gitlens.views.compareWithWorking', this.compareWorkingWith, this);
registerViewCommand(
'gitlens.views.setBranchComparisonToWorking',
n => this.setBranchComparison(n, ViewShowBranchComparison.Working),
this,
);
this.registerCommand(
registerViewCommand(
'gitlens.views.setBranchComparisonToBranch',
n => this.setBranchComparison(n, ViewShowBranchComparison.Branch),
this,
);
this.registerCommand('gitlens.views.cherryPick', this.cherryPick, this, ViewCommandMultiSelectMode.Custom);
this.registerCommand('gitlens.views.createBranch', this.createBranch, this);
this.registerCommand('gitlens.views.deleteBranch', this.deleteBranch, this);
this.registerCommand('gitlens.views.renameBranch', this.renameBranch, this);
this.registerCommand('gitlens.views.deleteStash', this.deleteStash, this, ViewCommandMultiSelectMode.Custom);
this.registerCommand('gitlens.views.createTag', this.createTag, this);
this.registerCommand('gitlens.views.deleteTag', this.deleteTag, this);
registerViewCommand('gitlens.views.cherryPick', this.cherryPick, this, ViewCommandMultiSelectMode.Custom);
registerViewCommand('gitlens.views.createBranch', this.createBranch, this);
registerViewCommand('gitlens.views.deleteBranch', this.deleteBranch, this);
registerViewCommand('gitlens.views.renameBranch', this.renameBranch, this);
registerViewCommand('gitlens.views.deleteStash', this.deleteStash, this, ViewCommandMultiSelectMode.Custom);
registerViewCommand('gitlens.views.createTag', this.createTag, this);
registerViewCommand('gitlens.views.deleteTag', this.deleteTag, this);
this.registerCommand('gitlens.views.mergeBranchInto', this.merge, this);
this.registerCommand('gitlens.views.pushToCommit', this.pushToCommit, this);
registerViewCommand('gitlens.views.mergeBranchInto', this.merge, this);
registerViewCommand('gitlens.views.pushToCommit', this.pushToCommit, this);
this.registerCommand('gitlens.views.rebaseOntoBranch', this.rebase, this);
this.registerCommand('gitlens.views.rebaseOntoUpstream', this.rebaseToRemote, this);
this.registerCommand('gitlens.views.rebaseOntoCommit', this.rebase, this);
registerViewCommand('gitlens.views.rebaseOntoBranch', this.rebase, this);
registerViewCommand('gitlens.views.rebaseOntoUpstream', this.rebaseToRemote, this);
registerViewCommand('gitlens.views.rebaseOntoCommit', this.rebase, this);
this.registerCommand('gitlens.views.resetCommit', this.resetCommit, this);
this.registerCommand('gitlens.views.resetToCommit', this.resetToCommit, this);
this.registerCommand('gitlens.views.revert', this.revert, this);
this.registerCommand('gitlens.views.undoCommit', this.undoCommit, this);
registerViewCommand('gitlens.views.resetCommit', this.resetCommit, this);
registerViewCommand('gitlens.views.resetToCommit', this.resetToCommit, this);
registerViewCommand('gitlens.views.revert', this.revert, this);
registerViewCommand('gitlens.views.undoCommit', this.undoCommit, this);
this.registerCommand('gitlens.views.terminalRemoveRemote', this.terminalRemoveRemote, this);
registerViewCommand('gitlens.views.terminalRemoveRemote', this.terminalRemoveRemote, this);
this.registerCommand('gitlens.views.createPullRequest', this.createPullRequest, this);
this.registerCommand('gitlens.views.openPullRequest', this.openPullRequest, this);
registerViewCommand('gitlens.views.createPullRequest', this.createPullRequest, this);
registerViewCommand('gitlens.views.openPullRequest', this.openPullRequest, this);
this.registerCommand('gitlens.views.createWorktree', this.createWorktree, this);
this.registerCommand('gitlens.views.deleteWorktree', this.deleteWorktree, this);
this.registerCommand('gitlens.views.openWorktree', this.openWorktree, this);
this.registerCommand('gitlens.views.revealWorktreeInExplorer', this.revealWorktreeInExplorer, this);
this.registerCommand(
registerViewCommand('gitlens.views.createWorktree', this.createWorktree, this);
registerViewCommand('gitlens.views.deleteWorktree', this.deleteWorktree, this);
registerViewCommand('gitlens.views.openWorktree', this.openWorktree, this);
registerViewCommand('gitlens.views.revealWorktreeInExplorer', this.revealWorktreeInExplorer, this);
registerViewCommand(
'gitlens.views.openWorktreeInNewWindow',
n => this.openWorktree(n, { location: OpenWorkspaceLocation.NewWindow }),
this,

+ 15
- 21
src/views/worktreesView.ts Näytä tiedosto

@ -1,5 +1,5 @@
import type { CancellationToken, ConfigurationChangeEvent, Disposable, TreeViewVisibilityChangeEvent } from 'vscode';
import { commands, ProgressLocation, ThemeColor, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { ProgressLocation, ThemeColor, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import type { WorktreesViewConfig } from '../configuration';
import { configuration, ViewFilesLayout, ViewShowBranchComparison } from '../configuration';
import { Commands } from '../constants';
@ -11,6 +11,7 @@ import { RepositoryChange, RepositoryChangeComparisonMode } from '../git/models/
import type { GitWorktree } from '../git/models/worktree';
import { ensurePlusFeaturesEnabled } from '../plus/subscription/utils';
import { getSubscriptionTimeRemaining, SubscriptionState } from '../subscription';
import { executeCommand } from '../system/command';
import { gate } from '../system/decorators/gate';
import { pluralize } from '../system/string';
import { RepositoryNode } from './nodes/repositoryNode';
@ -19,6 +20,7 @@ import { RepositoriesSubscribeableNode, RepositoryFolderNode } from './nodes/vie
import { WorktreeNode } from './nodes/worktreeNode';
import { WorktreesNode } from './nodes/worktreesNode';
import { ViewBase } from './viewBase';
import { registerViewCommand } from './viewCommands';
export class WorktreesRepositoryNode extends RepositoryFolderNode<WorktreesView, WorktreesNode> {
getChildren(): Promise<ViewNode[]> {
@ -173,12 +175,12 @@ export class WorktreesView extends ViewBase
void this.container.viewCommands;
return [
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('copy'),
() => commands.executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
() => executeCommand(Commands.ViewsCopy, this.activeSelection, this.selection),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('refresh'),
async () => {
// this.container.git.resetCaches('worktrees');
@ -186,48 +188,40 @@ export class WorktreesView extends ViewBase
},
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setFilesLayoutToList'),
() => this.setFilesLayout(ViewFilesLayout.List),
this,
),
commands.registerCommand(
registerViewCommand(
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(
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOn'), () => this.setShowAvatars(true), this),
registerViewCommand(this.getQualifiedCommand('setShowAvatarsOff'), () => this.setShowAvatars(false), this),
registerViewCommand(
this.getQualifiedCommand('setShowBranchComparisonOn'),
() => this.setShowBranchComparison(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchComparisonOff'),
() => this.setShowBranchComparison(false),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchPullRequestOn'),
() => this.setShowBranchPullRequest(true),
this,
),
commands.registerCommand(
registerViewCommand(
this.getQualifiedCommand('setShowBranchPullRequestOff'),
() => this.setShowBranchPullRequest(false),
this,

+ 5
- 5
src/webviews/home/homeWebviewView.ts Näytä tiedosto

@ -1,11 +1,11 @@
import type { Disposable } from 'vscode';
import { commands, window } from 'vscode';
import { window } from 'vscode';
import { CoreCommands } from '../../constants';
import type { Container } from '../../container';
import type { SubscriptionChangeEvent } from '../../plus/subscription/subscriptionService';
import { ensurePlusFeaturesEnabled } from '../../plus/subscription/utils';
import type { Subscription } from '../../subscription';
import { executeCoreCommand } from '../../system/command';
import { executeCoreCommand, registerCommand } from '../../system/command';
import { WebviewViewBase } from '../webviewViewBase';
import type { State } from './protocol';
import { CompletedActions, DidChangeSubscriptionNotificationType } from './protocol';
@ -40,8 +40,8 @@ export class HomeWebviewView extends WebviewViewBase {
protected override registerCommands(): Disposable[] {
return [
commands.registerCommand(`${this.id}.refresh`, () => this.refresh(), this),
commands.registerCommand('gitlens.home.toggleWelcome', async () => {
registerCommand(`${this.id}.refresh`, () => this.refresh(), this),
registerCommand('gitlens.home.toggleWelcome', async () => {
const welcomeVisible = !this.welcomeVisible;
await this.container.storage.store('views:welcome:visible', welcomeVisible);
if (welcomeVisible) {
@ -51,7 +51,7 @@ export class HomeWebviewView extends WebviewViewBase {
void this.notifyDidChangeData();
}),
commands.registerCommand('gitlens.home.showSCM', async () => {
registerCommand('gitlens.home.showSCM', async () => {
const completedActions = this.container.storage.get('home:actions:completed', []);
if (!completedActions.includes(CompletedActions.OpenedSCM)) {
completedActions.push(CompletedActions.OpenedSCM);

+ 3
- 2
src/webviews/settings/settingsWebview.ts Näytä tiedosto

@ -1,7 +1,8 @@
import { commands, workspace } from 'vscode';
import { workspace } from 'vscode';
import { configuration } from '../../configuration';
import { Commands } from '../../constants';
import type { Container } from '../../container';
import { registerCommand } from '../../system/command';
import { WebviewWithConfigBase } from '../webviewWithConfigBase';
import type { State } from './protocol';
@ -41,7 +42,7 @@ export class SettingsWebview extends WebviewWithConfigBase {
[, anchor] = match;
}
return commands.registerCommand(c, () => this.onShowCommand(anchor), this);
return registerCommand(c, () => this.onShowCommand(anchor), this);
}),
);
}

+ 3
- 3
src/webviews/webviewBase.ts Näytä tiedosto

@ -1,10 +1,10 @@
import type { Webview, WebviewPanel, WebviewPanelOnDidChangeViewStateEvent } from 'vscode';
import { commands, Disposable, Uri, ViewColumn, window, workspace } from 'vscode';
import { Disposable, Uri, ViewColumn, window, workspace } from 'vscode';
import { getNonce } from '@env/crypto';
import type { Commands } from '../constants';
import type { Container } from '../container';
import { Logger } from '../logger';
import { executeCommand } from '../system/command';
import { executeCommand, registerCommand } from '../system/command';
import type { IpcMessage, IpcMessageParams, IpcNotificationType } from './protocol';
import { ExecuteCommandType, onIpc, WebviewReadyCommandType } from './protocol';
@ -36,7 +36,7 @@ export abstract class WebviewBase implements Disposable {
showCommand: Commands,
) {
this._title = title;
this.disposables.push(commands.registerCommand(showCommand, this.onShowCommand, this));
this.disposables.push(registerCommand(showCommand, this.onShowCommand, this));
}
dispose() {

Ladataan…
Peruuta
Tallenna