Adds paging support to repo/file quick picks

Adds keyboard support to page in repo/file quick picks
Adds progress indicator for repo/file quick picks
Completely reworks keyboard scopes
This commit is contained in:
Eric Amodio
2017-03-12 01:15:44 -05:00
parent 89a2471736
commit 487fb5197c
11 changed files with 252 additions and 174 deletions

View File

@@ -1,9 +1,9 @@
'use strict';
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
import { Commands, Keyboard } from '../commands';
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
import { GitLogCommit, GitProvider, IGitLog } from '../gitProvider';
import { CommitWithFileStatusQuickPickItem } from './gitQuickPicks';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, KeyNoopCommandQuickPickItem, OpenFilesCommandQuickPickItem } from './quickPicks';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, OpenFilesCommandQuickPickItem } from './quickPicks';
import * as moment from 'moment';
import * as path from 'path';
@@ -72,30 +72,26 @@ export class CommitDetailsQuickPick {
items.splice(0, 0, goBackCommand);
}
const previousCommand = commit.previousSha
? new KeyCommandQuickPickItem(Commands.ShowQuickCommitDetails, [commit.previousUri, commit.previousSha, undefined, goBackCommand, repoLog])
: new KeyNoopCommandQuickPickItem();
const previousCommand = commit.previousSha && new KeyCommandQuickPickItem(Commands.ShowQuickCommitDetails, [commit.previousUri, commit.previousSha, undefined, goBackCommand, repoLog]);
let nextCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>);
if (repoLog) {
nextCommand = commit.nextSha
? new KeyCommandQuickPickItem(Commands.ShowQuickCommitDetails, [commit.nextUri, commit.nextSha, undefined, goBackCommand, repoLog])
: new KeyNoopCommandQuickPickItem();
nextCommand = commit.nextSha && new KeyCommandQuickPickItem(Commands.ShowQuickCommitDetails, [commit.nextUri, commit.nextSha, undefined, goBackCommand, repoLog]);
}
else {
nextCommand = async () => {
const log = await git.getLogForRepo(commit.repoPath, undefined, git.config.advanced.maxQuickHistory);
const c = log && log.commits.get(commit.sha);
if (!c) return new KeyNoopCommandQuickPickItem();
if (!c) return KeyNoopCommand;
return new KeyCommandQuickPickItem(Commands.ShowQuickCommitDetails, [c.nextUri, c.nextSha, undefined, goBackCommand, log]);
};
}
await Keyboard.instance.enterScope(
['left', goBackCommand],
[',', previousCommand],
['.', nextCommand]
);
const scope = await Keyboard.instance.beginScope({
left: goBackCommand,
',': previousCommand,
'.': nextCommand
});
const pick = await window.showQuickPick(items, {
matchOnDescription: true,
@@ -103,11 +99,11 @@ export class CommitDetailsQuickPick {
placeHolder: `${commit.shortSha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`,
ignoreFocusOut: getQuickPickIgnoreFocusOut(),
onDidSelectItem: (item: QuickPickItem) => {
Keyboard.instance.setKeyCommand('right', item);
scope.setKeyCommand('right', item);
}
} as QuickPickOptions);
await Keyboard.instance.exitScope();
await scope.dispose();
return pick;
}

View File

@@ -1,9 +1,9 @@
'use strict';
import { Iterables } from '../system';
import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
import { Commands, Keyboard } from '../commands';
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
import { GitCommit, GitLogCommit, GitProvider, GitUri, IGitLog } from '../gitProvider';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, KeyNoopCommandQuickPickItem, OpenFileCommandQuickPickItem } from './quickPicks';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, OpenFileCommandQuickPickItem } from './quickPicks';
import * as moment from 'moment';
import * as path from 'path';
@@ -93,41 +93,37 @@ export class CommitFileDetailsQuickPick {
items.splice(0, 0, goBackCommand);
}
const previousCommand = commit.previousSha
? new KeyCommandQuickPickItem(Commands.ShowQuickCommitFileDetails, [commit.previousUri, commit.previousSha, undefined, goBackCommand, options, fileLog])
: new KeyNoopCommandQuickPickItem();
const previousCommand = commit.previousSha && new KeyCommandQuickPickItem(Commands.ShowQuickCommitFileDetails, [commit.previousUri, commit.previousSha, undefined, goBackCommand, options, fileLog]);
let nextCommand: CommandQuickPickItem | (() => Promise<CommandQuickPickItem>);
if (fileLog) {
nextCommand = commit.nextSha
? new KeyCommandQuickPickItem(Commands.ShowQuickCommitFileDetails, [commit.nextUri, commit.nextSha, undefined, goBackCommand, options, fileLog])
: new KeyNoopCommandQuickPickItem();
nextCommand = commit.nextSha && new KeyCommandQuickPickItem(Commands.ShowQuickCommitFileDetails, [commit.nextUri, commit.nextSha, undefined, goBackCommand, options, fileLog]);
}
else {
nextCommand = async () => {
const log = await git.getLogForFile(uri.fsPath, undefined, commit.repoPath, undefined, git.config.advanced.maxQuickHistory);
const c = log && log.commits.get(commit.sha);
if (!c) return new KeyNoopCommandQuickPickItem();
if (!c) return KeyNoopCommand;
return new KeyCommandQuickPickItem(Commands.ShowQuickCommitFileDetails, [c.nextUri, c.nextSha, undefined, goBackCommand, options, log]);
};
}
await Keyboard.instance.enterScope(
['left', goBackCommand],
[',', previousCommand],
['.', nextCommand]
);
const scope = await Keyboard.instance.beginScope({
left: goBackCommand,
',': previousCommand,
'.': nextCommand
});
const pick = await window.showQuickPick(items, {
matchOnDescription: true,
placeHolder: `${commit.getFormattedPath()} \u2022 ${isUncommitted ? 'Uncommitted \u21E8 ' : '' }${commit.shortSha} \u2022 ${commit.author}, ${moment(commit.date).fromNow()} \u2022 ${commit.message}`,
ignoreFocusOut: getQuickPickIgnoreFocusOut(),
onDidSelectItem: (item: QuickPickItem) => {
Keyboard.instance.setKeyCommand('right', item);
scope.setKeyCommand('right', item);
}
} as QuickPickOptions);
await Keyboard.instance.exitScope();
await scope.dispose();
return pick;
}

View File

@@ -1,40 +1,66 @@
'use strict';
import { Iterables } from '../system';
import { CancellationTokenSource, QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
import { Commands, Keyboard } from '../commands';
import { CancellationTokenSource, QuickPickOptions, Uri, window } from 'vscode';
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
import { GitUri, IGitLog } from '../gitProvider';
import { CommitQuickPickItem } from './gitQuickPicks';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './quickPicks';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, showQuickPickProgress } from './quickPicks';
import * as path from 'path';
export class FileHistoryQuickPick {
static async show(log: IGitLog, uri: Uri, sha: string, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
static showProgress(maxCount?: number) {
return showQuickPickProgress(`Loading file history \u2014 ${maxCount ? ` limited to ${maxCount} commits` : ` this may take a while`}\u2026`,
{
left: KeyNoopCommand,
',': KeyNoopCommand,
'.': KeyNoopCommand
});
}
static async show(log: IGitLog, uri: GitUri, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))) as (CommitQuickPickItem | CommandQuickPickItem)[];
if (log.truncated) {
let previousPageCommand: CommandQuickPickItem;
let index = 0;
if (log.truncated || uri.sha) {
index++;
items.splice(0, 0, new CommandQuickPickItem({
label: `$(sync) Show All Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${log.maxCount} commits`,
detail: `This may take a while`
}, Commands.ShowQuickFileHistory, [uri, 0, goBackCommand]));
description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while`
}, Commands.ShowQuickFileHistory, [Uri.file(uri.fsPath), 0, goBackCommand]));
const last = Iterables.last(log.commits.values());
items.push(new CommandQuickPickItem({
label: `$(ellipsis) Show More Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 Shows the next ${log.maxCount} commits`
}, Commands.ShowQuickFileHistory, [new GitUri(uri, last), log.maxCount, goBackCommand]));
if (nextPageCommand) {
index++;
items.splice(0, 0, nextPageCommand);
}
if (log.truncated) {
const npc = new CommandQuickPickItem({
label: `$(arrow-right) Show Next Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} newer commits`
}, Commands.ShowQuickFileHistory, [uri, log.maxCount, goBackCommand, undefined, nextPageCommand]);
const last = Iterables.last(log.commits.values());
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
}, Commands.ShowQuickFileHistory, [new GitUri(uri, last), log.maxCount, goBackCommand, undefined, npc]);
index++;
items.splice(0, 0, previousPageCommand);
}
}
// Only show the full repo option if we are the root
if (!goBackCommand) {
items.splice(0, 0, new CommandQuickPickItem({
items.splice(index, 0, new CommandQuickPickItem({
label: `$(repo) Show Repository History`,
description: null,
detail: 'Shows the commit history of the repository'
description: `\u00a0 \u2014 \u00a0\u00a0 shows the repository commit history`
}, Commands.ShowQuickRepoHistory,
[
undefined,
undefined,
undefined,
new CommandQuickPickItem({
@@ -50,7 +76,11 @@ export class FileHistoryQuickPick {
if (progressCancellation.token.isCancellationRequested) return undefined;
await Keyboard.instance.enterScope(['left', goBackCommand]);
const scope = await Keyboard.instance.beginScope({
left: goBackCommand,
',': previousPageCommand,
'.': nextPageCommand
});
const commit = Iterables.first(log.commits.values());
@@ -59,14 +89,14 @@ export class FileHistoryQuickPick {
const pick = await window.showQuickPick(items, {
matchOnDescription: true,
matchOnDetail: true,
placeHolder: `${commit.getFormattedPath()}${sha ? ` \u00a0\u2022\u00a0 ${sha.substring(0, 8)}` : ''}`,
ignoreFocusOut: getQuickPickIgnoreFocusOut(),
onDidSelectItem: (item: QuickPickItem) => {
Keyboard.instance.setKeyCommand('right', item);
}
placeHolder: `${commit.getFormattedPath()}${uri.sha ? ` \u00a0\u2022\u00a0 ${uri.sha.substring(0, 8)}` : ''}`,
ignoreFocusOut: getQuickPickIgnoreFocusOut()
// onDidSelectItem: (item: QuickPickItem) => {
// scope.setKeyCommand('right', item);
// }
} as QuickPickOptions);
await Keyboard.instance.exitScope();
await scope.dispose();
return pick;
}

View File

@@ -1,26 +1,32 @@
'use strict';
import { CancellationTokenSource, commands, QuickPickItem, QuickPickOptions, TextEditor, Uri, window, workspace } from 'vscode';
import { Commands, openEditor } from '../commands';
import { Commands, Keyboard, KeyboardScope, KeyMapping, openEditor } from '../commands';
import { IAdvancedConfig } from '../configuration';
import { Logger } from '../logger';
// import { Logger } from '../logger';
export function getQuickPickIgnoreFocusOut() {
return !workspace.getConfiguration('gitlens').get<IAdvancedConfig>('advanced').quickPick.closeOnFocusOut;
}
export function showQuickPickProgress(message: string): CancellationTokenSource {
export function showQuickPickProgress(message: string, mapping?: KeyMapping): CancellationTokenSource {
const cancellation = new CancellationTokenSource();
_showQuickPickProgress(message, cancellation);
_showQuickPickProgress(message, cancellation, mapping);
return cancellation;
}
async function _showQuickPickProgress(message: string, cancellation: CancellationTokenSource) {
Logger.log(`showQuickPickProgress`, `show`, message);
async function _showQuickPickProgress(message: string, cancellation: CancellationTokenSource, mapping?: KeyMapping) {
// Logger.log(`showQuickPickProgress`, `show`, message);
const scope: KeyboardScope = mapping && await Keyboard.instance.beginScope(mapping);
await window.showQuickPick(_getInfiniteCancellablePromise(cancellation), {
placeHolder: message,
ignoreFocusOut: getQuickPickIgnoreFocusOut()
} as QuickPickOptions, cancellation.token);
Logger.log(`showQuickPickProgress`, `cancel`, message);
// Logger.log(`showQuickPickProgress`, `cancel`, message);
scope && scope.dispose();
cancellation.cancel();
}
@@ -28,7 +34,7 @@ function _getInfiniteCancellablePromise(cancellation: CancellationTokenSource) {
return new Promise((resolve, reject) => {
const disposable = cancellation.token.onCancellationRequested(() => {
disposable.dispose();
reject();
resolve([]);
});
});
}
@@ -55,17 +61,6 @@ export class KeyCommandQuickPickItem extends CommandQuickPickItem {
}
}
export class KeyNoopCommandQuickPickItem extends CommandQuickPickItem {
constructor() {
super({ label: undefined, description: undefined }, undefined, undefined);
}
execute(): Thenable<{}> {
return Promise.resolve(undefined);
}
}
export class OpenFileCommandQuickPickItem extends CommandQuickPickItem {
constructor(public uri: Uri, item: QuickPickItem) {

View File

@@ -1,28 +1,52 @@
'use strict';
import { Iterables } from '../system';
import { CancellationTokenSource, QuickPickItem, QuickPickOptions, Uri, window } from 'vscode';
import { Commands, Keyboard } from '../commands';
import { IGitLog } from '../gitProvider';
import { CancellationTokenSource, QuickPickOptions, Uri, window } from 'vscode';
import { Commands, Keyboard, KeyNoopCommand } from '../commands';
import { GitUri, IGitLog } from '../gitProvider';
import { CommitQuickPickItem } from './gitQuickPicks';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut } from './quickPicks';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, showQuickPickProgress } from './quickPicks';
export class RepoHistoryQuickPick {
static async show(log: IGitLog, uri: Uri, sha: string, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
static showProgress(maxCount?: number) {
return showQuickPickProgress(`Loading repository history \u2014 ${maxCount ? ` limited to ${maxCount} commits` : ` this may take a while`}\u2026`,
{
left: KeyNoopCommand,
',': KeyNoopCommand,
'.': KeyNoopCommand
});
}
static async show(log: IGitLog, uri: GitUri, progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem, nextPageCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
const items = Array.from(Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c, ` \u2014 ${c.fileNames}`))) as (CommitQuickPickItem | CommandQuickPickItem)[];
if (log.truncated) {
let previousPageCommand: CommandQuickPickItem;
if (log.truncated || uri.sha) {
items.splice(0, 0, new CommandQuickPickItem({
label: `$(sync) Show All Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 Currently only showing the first ${log.maxCount} commits`,
detail: `This may take a while`
}, Commands.ShowQuickRepoHistory, [uri, undefined, 0, goBackCommand]));
description: `\u00a0 \u2014 \u00a0\u00a0 this may take a while`
}, Commands.ShowQuickRepoHistory, [Uri.file(uri.fsPath), 0, goBackCommand]));
const last = Iterables.last(log.commits.values());
items.push(new CommandQuickPickItem({
label: `$(ellipsis) Show More Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 Shows the next ${log.maxCount} commits`
}, Commands.ShowQuickRepoHistory, [uri, last.sha, log.maxCount, goBackCommand]));
if (nextPageCommand) {
items.splice(0, 0, nextPageCommand);
}
if (log.truncated) {
const npc = new CommandQuickPickItem({
label: `$(arrow-right) Show Next Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} newer commits`
}, Commands.ShowQuickRepoHistory, [uri, log.maxCount, goBackCommand, undefined, nextPageCommand]);
const last = Iterables.last(log.commits.values());
previousPageCommand = new CommandQuickPickItem({
label: `$(arrow-left) Show Previous Commits`,
description: `\u00a0 \u2014 \u00a0\u00a0 shows ${log.maxCount} older commits`
}, Commands.ShowQuickRepoHistory, [new GitUri(uri, last), log.maxCount, goBackCommand, undefined, npc]);
items.splice(0, 0, previousPageCommand);
}
}
if (goBackCommand) {
@@ -31,7 +55,11 @@ export class RepoHistoryQuickPick {
if (progressCancellation.token.isCancellationRequested) return undefined;
await Keyboard.instance.enterScope(['left', goBackCommand]);
const scope = await Keyboard.instance.beginScope({
left: goBackCommand,
',': previousPageCommand,
'.': nextPageCommand
});
progressCancellation.cancel();
@@ -39,13 +67,13 @@ export class RepoHistoryQuickPick {
matchOnDescription: true,
matchOnDetail: true,
placeHolder: 'Search by commit message, filename, or sha',
ignoreFocusOut: getQuickPickIgnoreFocusOut(),
onDidSelectItem: (item: QuickPickItem) => {
Keyboard.instance.setKeyCommand('right', item);
}
ignoreFocusOut: getQuickPickIgnoreFocusOut()
// onDidSelectItem: (item: QuickPickItem) => {
// scope.setKeyCommand('right', item);
// }
} as QuickPickOptions);
await Keyboard.instance.exitScope();
await scope.dispose();
return pick;
}

View File

@@ -90,18 +90,18 @@ export class RepoStatusQuickPick {
items.splice(0, 0, goBackCommand);
}
await Keyboard.instance.enterScope(['left', goBackCommand]);
const scope = await Keyboard.instance.beginScope({ left: goBackCommand });
const pick = await window.showQuickPick(items, {
matchOnDescription: true,
placeHolder: statuses.length ? 'Repository has changes' : 'Repository has no changes',
ignoreFocusOut: getQuickPickIgnoreFocusOut(),
onDidSelectItem: (item: QuickPickItem) => {
Keyboard.instance.setKeyCommand('right', item);
scope.setKeyCommand('right', item);
}
} as QuickPickOptions);
await Keyboard.instance.exitScope();
await scope.dispose();
return pick;
}