Refactors commands to use typed args objects

This commit is contained in:
Eric Amodio
2017-05-14 01:48:07 -04:00
parent ee29596d45
commit 1acc183621
43 changed files with 2366 additions and 1761 deletions

View File

@@ -1,9 +1,9 @@
'use strict';
import { Arrays, Iterables } from '../system';
import { CancellationTokenSource, QuickPickOptions, Uri, window } from 'vscode';
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
import { Commands, Keyboard, KeyNoopCommand, ShowCommitSearchCommandArgs, ShowQuickBranchHistoryCommandArgs } from '../commands';
import { CommandQuickPickItem, CommitQuickPickItem, getQuickPickIgnoreFocusOut, showQuickPickProgress } from './common';
import { GitService, GitUri, IGitLog } from '../gitService';
import { GitService, GitUri, IGitLog, RemoteResource } from '../gitService';
import { OpenRemotesCommandQuickPickItem } from './remotes';
export class BranchHistoryQuickPick {
@@ -23,17 +23,33 @@ export class BranchHistoryQuickPick {
const currentCommand = new CommandQuickPickItem({
label: `go back \u21A9`,
description: `\u00a0 \u2014 \u00a0\u00a0 to \u00a0$(git-branch) ${branch} history`
}, Commands.ShowQuickBranchHistory, [uri, branch, log.maxCount, goBackCommand, log]);
}, Commands.ShowQuickBranchHistory, [
uri,
{
branch,
log,
maxCount: log.maxCount,
goBackCommand
} as ShowQuickBranchHistoryCommandArgs
]);
const remotes = Arrays.uniqueBy(await git.getRemotes((uri && uri.repoPath) || git.repoPath), _ => _.url, _ => !!_.provider);
if (remotes.length) {
items.splice(0, 0, new OpenRemotesCommandQuickPickItem(remotes, 'branch', branch, currentCommand));
items.splice(0, 0, new OpenRemotesCommandQuickPickItem(remotes, {
type: 'branch',
branch
} as RemoteResource, currentCommand));
}
items.splice(0, 0, new CommandQuickPickItem({
label: `$(search) Show Commit Search`,
description: `\u00a0 \u2014 \u00a0\u00a0 search for commits by message, author, files, or commit id`
}, Commands.ShowCommitSearch, [new GitUri(Uri.file(log.repoPath), { fileName: '', repoPath: log.repoPath }), undefined, undefined, currentCommand]));
}, Commands.ShowCommitSearch, [
new GitUri(Uri.file(log.repoPath), { fileName: '', repoPath: log.repoPath }),
{
goBackCommand: currentCommand
} as ShowCommitSearchCommandArgs
]));
let previousPageCommand: CommandQuickPickItem | undefined = undefined;
@@ -44,9 +60,11 @@ export class BranchHistoryQuickPick {
description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while`
}, Commands.ShowQuickBranchHistory, [
new GitUri(Uri.file(log.repoPath), { fileName: '', repoPath: log.repoPath }),
branch,
0,
goBackCommand
{
branch,
maxCount: 0,
goBackCommand
} as ShowQuickBranchHistoryCommandArgs
]));
}
else {
@@ -55,9 +73,10 @@ export class BranchHistoryQuickPick {
description: `\u00a0 \u2014 \u00a0\u00a0 shows \u00a0$(git-branch) ${branch} history`
}, Commands.ShowQuickBranchHistory, [
new GitUri(Uri.file(log.repoPath), { fileName: '', repoPath: log.repoPath }),
branch,
undefined,
currentCommand
{
branch,
goBackCommand: currentCommand
} as ShowQuickBranchHistoryCommandArgs
]));
}
@@ -69,14 +88,29 @@ export class BranchHistoryQuickPick {
const npc = new CommandQuickPickItem({
label: `$(arrow-right) Show Next Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} newer commits`
}, Commands.ShowQuickBranchHistory, [uri, branch, log.maxCount, goBackCommand, undefined, nextPageCommand]);
}, Commands.ShowQuickBranchHistory, [
uri,
{
branch,
maxCount: log.maxCount,
nextPageCommand
} as ShowQuickBranchHistoryCommandArgs
]);
const last = Iterables.last(log.commits.values());
if (last != null) {
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
}, Commands.ShowQuickBranchHistory, [new GitUri(uri ? uri : last.uri, last), branch, log.maxCount, goBackCommand, undefined, npc]);
}, Commands.ShowQuickBranchHistory, [
new GitUri(uri ? uri : last.uri, last),
{
branch,
maxCount: log.maxCount,
goBackCommand,
nextPageCommand: npc
} as ShowQuickBranchHistoryCommandArgs
]);
items.splice(0, 0, previousPageCommand);
}