diff --git a/src/commands/git/merge.ts b/src/commands/git/merge.ts index f19083d..c33a5ac 100644 --- a/src/commands/git/merge.ts +++ b/src/commands/git/merge.ts @@ -3,7 +3,8 @@ import type { GitBranch } from '../../git/models/branch'; import type { GitLog } from '../../git/models/log'; import { GitReference, GitRevision } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; -import { Directive, DirectiveQuickPickItem } from '../../quickpicks/items/directive'; +import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive'; +import { createDirectiveQuickPickItem , Directive } from '../../quickpicks/items/directive'; import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { pluralize } from '../../system/string'; @@ -215,7 +216,7 @@ export class MergeGitCommand extends QuickCommand { const step: QuickPickStep = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: `Cancel ${this.title}`, detail: `${GitReference.toString(context.destination, { capitalize: true, diff --git a/src/commands/git/pull.ts b/src/commands/git/pull.ts index f59504d..6992673 100644 --- a/src/commands/git/pull.ts +++ b/src/commands/git/pull.ts @@ -4,7 +4,7 @@ import { isBranch } from '../../git/models/branch'; import type { GitBranchReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; -import { Directive, DirectiveQuickPickItem } from '../../quickpicks/items/directive'; +import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive'; import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { isStringArray } from '../../system/array'; @@ -162,7 +162,7 @@ export class PullGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: `Cancel ${this.title}`, detail: 'Cannot pull a remote branch', }), @@ -175,7 +175,7 @@ export class PullGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: `Cancel ${this.title}`, detail: 'Cannot pull a branch until it has been published', }), diff --git a/src/commands/git/push.ts b/src/commands/git/push.ts index 589e9ad..02f59ae 100644 --- a/src/commands/git/push.ts +++ b/src/commands/git/push.ts @@ -5,7 +5,7 @@ import { getRemoteNameFromBranchName } from '../../git/models/branch'; import type { GitBranchReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; -import { Directive, DirectiveQuickPickItem } from '../../quickpicks/items/directive'; +import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive'; import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { isStringArray } from '../../system/array'; @@ -186,7 +186,7 @@ export class PushGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: `Cancel ${this.title}`, detail: 'Cannot push remote branch', }), @@ -219,7 +219,7 @@ export class PushGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle('Confirm Publish', state, context), [], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: 'Cancel Publish', detail: 'Cannot publish; No remotes found', }), @@ -244,7 +244,7 @@ export class PushGitCommand extends QuickCommand { }`, }), ], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: `Cancel ${this.title}`, detail: `Cannot push; ${GitReference.toString( branch, @@ -265,7 +265,7 @@ export class PushGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: `Cancel ${this.title}`, detail: 'No commits found to push', }), @@ -312,7 +312,7 @@ export class PushGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle('Confirm Publish', state, context), [], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: 'Cancel Publish', detail: 'Cannot publish; No remotes found', }), @@ -322,7 +322,7 @@ export class PushGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle('Confirm Push', state, context), [], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: `Cancel ${this.title}`, detail: `Cannot push; No commits ahead of ${getRemoteNameFromBranchName( status.upstream, @@ -379,7 +379,7 @@ export class PushGitCommand extends QuickCommand { }), ], status?.state.behind - ? DirectiveQuickPickItem.create(Directive.Cancel, true, { + ? createDirectiveQuickPickItem(Directive.Cancel, true, { label: `Cancel ${this.title}`, detail: `Cannot push; ${GitReference.toString(branch)} is behind${ status?.upstream ? ` ${getRemoteNameFromBranchName(status.upstream)}` : '' diff --git a/src/commands/git/rebase.ts b/src/commands/git/rebase.ts index 5dddddb..2a32304 100644 --- a/src/commands/git/rebase.ts +++ b/src/commands/git/rebase.ts @@ -3,7 +3,8 @@ import type { GitBranch } from '../../git/models/branch'; import type { GitLog } from '../../git/models/log'; import { GitReference, GitRevision } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; -import { Directive, DirectiveQuickPickItem } from '../../quickpicks/items/directive'; +import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive'; +import { createDirectiveQuickPickItem , Directive } from '../../quickpicks/items/directive'; import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { pluralize } from '../../system/string'; @@ -227,7 +228,7 @@ export class RebaseGitCommand extends QuickCommand { const step: QuickPickStep = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [], - DirectiveQuickPickItem.create(Directive.Cancel, true, { + createDirectiveQuickPickItem(Directive.Cancel, true, { label: `Cancel ${this.title}`, detail: `${GitReference.toString(context.destination, { capitalize: true, diff --git a/src/commands/gitCommands.ts b/src/commands/gitCommands.ts index 82619fa..1429a5d 100644 --- a/src/commands/gitCommands.ts +++ b/src/commands/gitCommands.ts @@ -4,7 +4,7 @@ import { configuration } from '../configuration'; import { Commands } from '../constants'; import { Container } from '../container'; import type { KeyMapping } from '../keyboard'; -import { Directive, DirectiveQuickPickItem, isDirective } from '../quickpicks/items/directive'; +import { Directive, isDirective, isDirectiveQuickPickItem } from '../quickpicks/items/directive'; import { command } from '../system/command'; import { log } from '../system/decorators/log'; import type { Deferred } from '../system/promise'; @@ -482,7 +482,7 @@ export class GitCommandsCommand extends Command { activeIndex = quickpick.items.indexOf(active); // If the active item is the "Load more" directive, then select the previous item - if (DirectiveQuickPickItem.is(active)) { + if (isDirectiveQuickPickItem(active)) { activeIndex--; } } @@ -705,7 +705,7 @@ export class GitCommandsCommand extends Command { if (items.length === 1) { const [item] = items; - if (DirectiveQuickPickItem.is(item)) { + if (isDirectiveQuickPickItem(item)) { switch (item.directive) { case Directive.Cancel: resolve(undefined); diff --git a/src/commands/quickCommand.steps.ts b/src/commands/quickCommand.steps.ts index 65b2e5c..90e78fd 100644 --- a/src/commands/quickCommand.steps.ts +++ b/src/commands/quickCommand.steps.ts @@ -55,7 +55,8 @@ import { OpenChangedFilesCommandQuickPickItem, } from '../quickpicks/items/commits'; import { CommandQuickPickItem, QuickPickSeparator } from '../quickpicks/items/common'; -import { Directive, DirectiveQuickPickItem } from '../quickpicks/items/directive'; +import type { DirectiveQuickPickItem } from '../quickpicks/items/directive'; +import { createDirectiveQuickPickItem, Directive } from '../quickpicks/items/directive'; import type { BranchQuickPickItem, CommitQuickPickItem, @@ -442,7 +443,7 @@ export function getValidateGitReferenceFn( if (!(await Container.instance.git.validateReference(repos.path, value))) { if (inRefMode) { quickpick.items = [ - DirectiveQuickPickItem.create(Directive.Back, true, { + createDirectiveQuickPickItem(Directive.Back, true, { label: 'Enter a reference or commit SHA', }), ]; @@ -680,7 +681,7 @@ export async function* pickBranchStep< matchOnDetail: true, items: branches.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : branches, onDidClickItemButton: (quickpick, button, { item }) => { if (button === QuickCommandButtons.RevealInSideBar) { @@ -736,7 +737,7 @@ export async function* pickBranchesStep< matchOnDetail: true, items: branches.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : branches, onDidClickItemButton: (quickpick, button, { item }) => { if (button === QuickCommandButtons.RevealInSideBar) { @@ -813,7 +814,7 @@ export async function* pickBranchOrTagStep< selectValueWhenShown: true, items: branchesAndOrTags.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : branchesAndOrTags, additionalButtons: [...(additionalButtons ?? []), showTagsButton], onDidClickItemButton: (quickpick, button, { item }) => { @@ -926,7 +927,7 @@ export async function* pickBranchOrTagStepMultiRepo< selectValueWhenShown: true, items: branchesAndOrTags.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : branchesAndOrTags, additionalButtons: [showTagsButton], onDidClickItemButton: (quickpick, button, { item }) => { @@ -1018,7 +1019,7 @@ export async function* pickCommitStep< ): AsyncStepResultGenerator { function getItems(log: GitLog | undefined) { return log == null - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : [ ...map(log.commits.values(), commit => createCommitQuickPickItem( @@ -1032,7 +1033,7 @@ export async function* pickCommitStep< }, ), ), - ...(log?.hasMore ? [DirectiveQuickPickItem.create(Directive.LoadMore)] : []), + ...(log?.hasMore ? [createDirectiveQuickPickItem(Directive.LoadMore)] : []), ]; } @@ -1143,7 +1144,7 @@ export function* pickCommitsStep< ): StepResultGenerator { function getItems(log: GitLog | undefined) { return log == null - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : [ ...map(log.commits.values(), commit => createCommitQuickPickItem( @@ -1287,7 +1288,7 @@ export async function* pickRemoteStep< matchOnDetail: true, items: remotes.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : remotes, onDidClickItemButton: (quickpick, button, { item }) => { if (button === QuickCommandButtons.RevealInSideBar) { @@ -1340,7 +1341,7 @@ export async function* pickRemotesStep< matchOnDetail: true, items: remotes.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : remotes, onDidClickItemButton: (quickpick, button, { item }) => { if (button === QuickCommandButtons.RevealInSideBar) { @@ -1377,7 +1378,7 @@ export async function* pickRepositoryStep< placeholder: placeholder, items: context.repos.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Cancel)] : await Promise.all( context.repos.map(r => createRepositoryQuickPickItem(r, r.id === active?.id, { @@ -1443,7 +1444,7 @@ export async function* pickRepositoriesStep< placeholder: options.placeholder, items: context.repos.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Cancel)] : await Promise.all( context.repos.map(repo => createRepositoryQuickPickItem( @@ -1510,7 +1511,7 @@ export function* pickStashStep< matchOnDetail: true, items: stash == null - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : [ ...map(stash.commits.values(), commit => createCommitQuickPickItem( @@ -1572,7 +1573,7 @@ export async function* pickTagsStep< matchOnDetail: true, items: tags.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : tags, onDidClickItemButton: (quickpick, button, { item }) => { if (button === QuickCommandButtons.RevealInSideBar) { @@ -1631,7 +1632,7 @@ export async function* pickWorktreeStep< matchOnDetail: true, items: worktrees.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : worktrees, onDidClickItemButton: (quickpick, button, { item }) => { switch (button) { @@ -1692,7 +1693,7 @@ export async function* pickWorktreesStep< matchOnDetail: true, items: worktrees.length === 0 - ? [DirectiveQuickPickItem.create(Directive.Back, true), DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] : worktrees, onDidClickItemButton: (quickpick, button, { item }) => { switch (button) { @@ -2282,28 +2283,28 @@ function getShowRepositoryStatusStepItems< if (context.status.upstream) { if (context.status.state.ahead === 0 && context.status.state.behind === 0) { items.push( - DirectiveQuickPickItem.create(Directive.Noop, true, { + createDirectiveQuickPickItem(Directive.Noop, true, { label: `$(git-branch) ${context.status.branch} is up to date with $(git-branch) ${context.status.upstream}`, detail: workingTreeStatus, }), ); } else if (context.status.state.ahead !== 0 && context.status.state.behind !== 0) { items.push( - DirectiveQuickPickItem.create(Directive.Noop, true, { + createDirectiveQuickPickItem(Directive.Noop, true, { label: `$(git-branch) ${context.status.branch} has diverged from $(git-branch) ${context.status.upstream}`, detail: workingTreeStatus, }), ); } else if (context.status.state.ahead !== 0) { items.push( - DirectiveQuickPickItem.create(Directive.Noop, true, { + createDirectiveQuickPickItem(Directive.Noop, true, { label: `$(git-branch) ${context.status.branch} is ahead of $(git-branch) ${context.status.upstream}`, detail: workingTreeStatus, }), ); } else if (context.status.state.behind !== 0) { items.push( - DirectiveQuickPickItem.create(Directive.Noop, true, { + createDirectiveQuickPickItem(Directive.Noop, true, { label: `$(git-branch) ${context.status.branch} is behind $(git-branch) ${context.status.upstream}`, detail: workingTreeStatus, }), @@ -2347,7 +2348,7 @@ function getShowRepositoryStatusStepItems< } } else { items.push( - DirectiveQuickPickItem.create(Directive.Noop, true, { + createDirectiveQuickPickItem(Directive.Noop, true, { label: `$(git-branch) ${context.status.branch} has no upstream`, detail: workingTreeStatus, }), @@ -2395,28 +2396,28 @@ export async function* ensureAccessStep< const directives: DirectiveQuickPickItem[] = []; let placeholder: string; if (access.subscription.current.account?.verified === false) { - directives.push(DirectiveQuickPickItem.create(Directive.RequiresVerification, true)); + directives.push(createDirectiveQuickPickItem(Directive.RequiresVerification, true)); placeholder = 'You must verify your email address before you can continue'; } else { if (access.subscription.required == null) return undefined; placeholder = 'You need GitLens Pro to access GitLens+ features on this repo'; if (isSubscriptionPaidPlan(access.subscription.required) && access.subscription.current.account != null) { - directives.push(DirectiveQuickPickItem.create(Directive.RequiresPaidSubscription, true)); + directives.push(createDirectiveQuickPickItem(Directive.RequiresPaidSubscription, true)); } else if ( access.subscription.current.account == null && !isSubscriptionPreviewTrialExpired(access.subscription.current) ) { - directives.push(DirectiveQuickPickItem.create(Directive.StartPreviewTrial, true)); + directives.push(createDirectiveQuickPickItem(Directive.StartPreviewTrial, true)); } else { - directives.push(DirectiveQuickPickItem.create(Directive.ExtendTrial)); + directives.push(createDirectiveQuickPickItem(Directive.ExtendTrial)); } } const step = QuickCommand.createPickStep({ title: appendReposToTitle(context.title, state, context), placeholder: placeholder, - items: [...directives, DirectiveQuickPickItem.create(Directive.Cancel)], + items: [...directives, createDirectiveQuickPickItem(Directive.Cancel)], }); const selection: StepSelection = yield step; diff --git a/src/commands/quickCommand.ts b/src/commands/quickCommand.ts index 62b590d..4024109 100644 --- a/src/commands/quickCommand.ts +++ b/src/commands/quickCommand.ts @@ -2,7 +2,8 @@ import type { InputBox, QuickInputButton, QuickPick, QuickPickItem } from 'vscod import { configuration } from '../configuration'; import type { Container } from '../container'; import type { Keys } from '../keyboard'; -import { Directive, DirectiveQuickPickItem, isDirective } from '../quickpicks/items/directive'; +import type { DirectiveQuickPickItem } from '../quickpicks/items/directive'; +import { createDirectiveQuickPickItem , Directive, isDirective } from '../quickpicks/items/directive'; export * from './quickCommand.buttons'; export * from './quickCommand.steps'; @@ -332,7 +333,7 @@ export namespace QuickCommand { placeholder: `Confirm ${context.title}`, title: title, ignoreFocusOut: true, - items: [...confirmations, cancel ?? DirectiveQuickPickItem.create(Directive.Cancel)], + items: [...confirmations, cancel ?? createDirectiveQuickPickItem(Directive.Cancel)], selectedItems: [confirmations.find(c => c.picked) ?? confirmations[0]], ...options, }); diff --git a/src/quickpicks/commitPicker.ts b/src/quickpicks/commitPicker.ts index a8f0a97..6bfe37f 100644 --- a/src/quickpicks/commitPicker.ts +++ b/src/quickpicks/commitPicker.ts @@ -10,7 +10,8 @@ import { filter, map } from '../system/iterable'; import { isPromise } from '../system/promise'; import { getQuickPickIgnoreFocusOut } from '../system/utils'; import { CommandQuickPickItem } from './items/common'; -import { Directive, DirectiveQuickPickItem } from './items/directive'; +import type { DirectiveQuickPickItem} from './items/directive'; +import { createDirectiveQuickPickItem, Directive , isDirectiveQuickPickItem } from './items/directive'; import type { CommitQuickPickItem } from './items/gitCommands'; import { createCommitQuickPickItem } from './items/gitCommands'; @@ -53,7 +54,7 @@ export namespace CommitPicker { function getItems(log: GitLog | undefined) { return log == null - ? [DirectiveQuickPickItem.create(Directive.Cancel)] + ? [createDirectiveQuickPickItem(Directive.Cancel)] : [ ...(options?.showOtherReferences ?? []), ...map(log.commits.values(), commit => @@ -62,7 +63,7 @@ export namespace CommitPicker { icon: true, }), ), - ...(log?.hasMore ? [DirectiveQuickPickItem.create(Directive.LoadMore)] : []), + ...(log?.hasMore ? [createDirectiveQuickPickItem(Directive.LoadMore)] : []), ]; } @@ -79,7 +80,7 @@ export namespace CommitPicker { activeIndex = quickpick.items.indexOf(active); // If the active item is the "Load more" directive, then select the previous item - if (DirectiveQuickPickItem.is(active)) { + if (isDirectiveQuickPickItem(active)) { activeIndex--; } } @@ -108,7 +109,7 @@ export namespace CommitPicker { const [item] = quickpick.activeItems; if ( item != null && - !DirectiveQuickPickItem.is(item) && + !isDirectiveQuickPickItem(item) && !CommandQuickPickItem.is(item) ) { void options.onDidPressKey!(key, item); @@ -132,7 +133,7 @@ export namespace CommitPicker { quickpick.onDidAccept(() => { if (quickpick.activeItems.length !== 0) { const [item] = quickpick.activeItems; - if (DirectiveQuickPickItem.is(item)) { + if (isDirectiveQuickPickItem(item)) { switch (item.directive) { case Directive.LoadMore: void loadMore(); @@ -163,7 +164,7 @@ export namespace CommitPicker { quickpick.show(); }); - if (pick == null || DirectiveQuickPickItem.is(pick)) return undefined; + if (pick == null || isDirectiveQuickPickItem(pick)) return undefined; if (pick instanceof CommandQuickPickItem) { void (await pick.execute()); @@ -226,7 +227,7 @@ export namespace StashPicker { if (stash == null || quickpick.items.length <= (options?.showOtherReferences?.length ?? 0)) { quickpick.placeholder = stash == null ? 'No stashes found' : options?.empty ?? `No matching stashes found`; - quickpick.items = [DirectiveQuickPickItem.create(Directive.Cancel)]; + quickpick.items = [createDirectiveQuickPickItem(Directive.Cancel)]; } if (options?.picked) { @@ -247,7 +248,7 @@ export namespace StashPicker { const [item] = quickpick.activeItems; if ( item != null && - !DirectiveQuickPickItem.is(item) && + !isDirectiveQuickPickItem(item) && !CommandQuickPickItem.is(item) ) { void options.onDidPressKey!(key, item); @@ -271,7 +272,7 @@ export namespace StashPicker { quickpick.onDidAccept(() => { if (quickpick.activeItems.length !== 0) { const [item] = quickpick.activeItems; - if (DirectiveQuickPickItem.is(item)) { + if (isDirectiveQuickPickItem(item)) { resolve(undefined); return; } @@ -295,7 +296,7 @@ export namespace StashPicker { quickpick.show(); }); - if (pick == null || DirectiveQuickPickItem.is(pick)) return undefined; + if (pick == null || isDirectiveQuickPickItem(pick)) return undefined; if (pick instanceof CommandQuickPickItem) { void (await pick.execute()); diff --git a/src/quickpicks/items/directive.ts b/src/quickpicks/items/directive.ts index 32c61d0..b3dd3f5 100644 --- a/src/quickpicks/items/directive.ts +++ b/src/quickpicks/items/directive.ts @@ -21,60 +21,58 @@ export interface DirectiveQuickPickItem extends QuickPickItem { directive: Directive; } -export namespace DirectiveQuickPickItem { - export function create( - directive: Directive, - picked?: boolean, - options?: { label?: string; description?: string; detail?: string; subscription?: Subscription }, - ) { - let label = options?.label; - let detail = options?.detail; - if (label == null) { - switch (directive) { - case Directive.Back: - label = 'Back'; - break; - case Directive.Cancel: - label = 'Cancel'; - break; - case Directive.LoadMore: - label = 'Load more'; - break; - case Directive.Noop: - label = 'Try again'; - break; - case Directive.StartPreviewTrial: - label = 'Start a GitLens Pro Trial'; - detail = 'Try GitLens+ features on private repos, free for 3 days, without an account'; - break; - case Directive.ExtendTrial: - label = 'Extend Your GitLens Pro Trial'; - detail = 'To continue to use GitLens+ features on private repos, free for an additional 7-days'; - break; - case Directive.RequiresVerification: - label = 'Resend Verification Email'; - detail = 'You must verify your email address before you can continue'; - break; - case Directive.RequiresPaidSubscription: - label = 'Upgrade to Pro'; - detail = 'To use GitLens+ features on private repos'; - break; - } +export function createDirectiveQuickPickItem( + directive: Directive, + picked?: boolean, + options?: { label?: string; description?: string; detail?: string; subscription?: Subscription }, +) { + let label = options?.label; + let detail = options?.detail; + if (label == null) { + switch (directive) { + case Directive.Back: + label = 'Back'; + break; + case Directive.Cancel: + label = 'Cancel'; + break; + case Directive.LoadMore: + label = 'Load more'; + break; + case Directive.Noop: + label = 'Try again'; + break; + case Directive.StartPreviewTrial: + label = 'Start a GitLens Pro Trial'; + detail = 'Try GitLens+ features on private repos, free for 3 days, without an account'; + break; + case Directive.ExtendTrial: + label = 'Extend Your GitLens Pro Trial'; + detail = 'To continue to use GitLens+ features on private repos, free for an additional 7-days'; + break; + case Directive.RequiresVerification: + label = 'Resend Verification Email'; + detail = 'You must verify your email address before you can continue'; + break; + case Directive.RequiresPaidSubscription: + label = 'Upgrade to Pro'; + detail = 'To use GitLens+ features on private repos'; + break; } + } - const item: DirectiveQuickPickItem = { - label: label, - description: options?.description, - detail: detail, - alwaysShow: true, - picked: picked, - directive: directive, - }; + const item: DirectiveQuickPickItem = { + label: label, + description: options?.description, + detail: detail, + alwaysShow: true, + picked: picked, + directive: directive, + }; - return item; - } + return item; +} - export function is(item: QuickPickItem): item is DirectiveQuickPickItem { - return item != null && 'directive' in item; - } +export function isDirectiveQuickPickItem(item: QuickPickItem): item is DirectiveQuickPickItem { + return item != null && 'directive' in item; }